2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/netdevice.h>
13 #include <linux/types.h>
14 #include <linux/slab.h>
15 #include <linux/skbuff.h>
16 #include <linux/if_arp.h>
17 #include <linux/timer.h>
18 #include <linux/rtnetlink.h>
20 #include <net/mac80211.h>
21 #include "ieee80211_i.h"
22 #include "driver-ops.h"
25 #include "debugfs_sta.h"
29 * DOC: STA information lifetime rules
31 * STA info structures (&struct sta_info) are managed in a hash table
32 * for faster lookup and a list for iteration. They are managed using
33 * RCU, i.e. access to the list and hash table is protected by RCU.
35 * Upon allocating a STA info structure with sta_info_alloc(), the caller
36 * owns that structure. It must then insert it into the hash table using
37 * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
38 * case (which acquires an rcu read section but must not be called from
39 * within one) will the pointer still be valid after the call. Note that
40 * the caller may not do much with the STA info before inserting it, in
41 * particular, it may not start any mesh peer link management or add
44 * When the insertion fails (sta_info_insert()) returns non-zero), the
45 * structure will have been freed by sta_info_insert()!
47 * Station entries are added by mac80211 when you establish a link with a
48 * peer. This means different things for the different type of interfaces
49 * we support. For a regular station this mean we add the AP sta when we
50 * receive an assocation response from the AP. For IBSS this occurs when
51 * get to know about a peer on the same IBSS. For WDS we add the sta for
52 * the peer imediately upon device open. When using AP mode we add stations
53 * for each respective station upon request from userspace through nl80211.
55 * In order to remove a STA info structure, various sta_info_destroy_*()
56 * calls are available.
58 * There is no concept of ownership on a STA entry, each structure is
59 * owned by the global hash table/list until it is removed. All users of
60 * the structure need to be RCU protected so that the structure won't be
61 * freed before they are done using it.
64 /* Caller must hold local->sta_lock */
65 static int sta_info_hash_del(struct ieee80211_local *local,
70 s = local->sta_hash[STA_HASH(sta->sta.addr)];
74 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)],
79 while (s->hnext && s->hnext != sta)
82 rcu_assign_pointer(s->hnext, sta->hnext);
89 /* protected by RCU */
90 struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
93 struct ieee80211_local *local = sdata->local;
96 sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]);
98 if (sta->sdata == sdata &&
99 memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
101 sta = rcu_dereference(sta->hnext);
107 * Get sta info either from the specified interface
108 * or from one of its vlans
110 struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
113 struct ieee80211_local *local = sdata->local;
114 struct sta_info *sta;
116 sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]);
118 if ((sta->sdata == sdata ||
119 sta->sdata->bss == sdata->bss) &&
120 memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
122 sta = rcu_dereference(sta->hnext);
127 struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
130 struct ieee80211_local *local = sdata->local;
131 struct sta_info *sta;
134 list_for_each_entry_rcu(sta, &local->sta_list, list) {
135 if (sdata != sta->sdata)
148 * __sta_info_free - internal STA free helper
150 * @local: pointer to the global information
151 * @sta: STA info to free
153 * This function must undo everything done by sta_info_alloc()
154 * that may happen before sta_info_insert().
156 static void __sta_info_free(struct ieee80211_local *local,
157 struct sta_info *sta)
159 if (sta->rate_ctrl) {
160 rate_control_free_sta(sta);
161 rate_control_put(sta->rate_ctrl);
164 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
165 printk(KERN_DEBUG "%s: Destroyed STA %pM\n",
166 wiphy_name(local->hw.wiphy), sta->sta.addr);
167 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
172 /* Caller must hold local->sta_lock */
173 static void sta_info_hash_add(struct ieee80211_local *local,
174 struct sta_info *sta)
176 sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
177 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
180 static void sta_unblock(struct work_struct *wk)
182 struct sta_info *sta;
184 sta = container_of(wk, struct sta_info, drv_unblock_wk);
189 if (!test_sta_flags(sta, WLAN_STA_PS_STA))
190 ieee80211_sta_ps_deliver_wakeup(sta);
191 else if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL))
192 ieee80211_sta_ps_deliver_poll_response(sta);
195 static int sta_prepare_rate_control(struct ieee80211_local *local,
196 struct sta_info *sta, gfp_t gfp)
198 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
201 sta->rate_ctrl = rate_control_get(local->rate_ctrl);
202 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
204 if (!sta->rate_ctrl_priv) {
205 rate_control_put(sta->rate_ctrl);
212 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
215 struct ieee80211_local *local = sdata->local;
216 struct sta_info *sta;
219 sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
223 spin_lock_init(&sta->lock);
224 spin_lock_init(&sta->flaglock);
225 INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
227 memcpy(sta->sta.addr, addr, ETH_ALEN);
231 if (sta_prepare_rate_control(local, sta, gfp)) {
236 for (i = 0; i < STA_TID_NUM; i++) {
237 /* timer_to_tid must be initialized with identity mapping to
238 * enable session_timer's data differentiation. refer to
239 * sta_rx_agg_session_timer_expired for useage */
240 sta->timer_to_tid[i] = i;
242 sta->ampdu_mlme.tid_state_tx[i] = HT_AGG_STATE_IDLE;
243 sta->ampdu_mlme.tid_tx[i] = NULL;
244 sta->ampdu_mlme.addba_req_num[i] = 0;
246 skb_queue_head_init(&sta->ps_tx_buf);
247 skb_queue_head_init(&sta->tx_filtered);
249 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
250 sta->last_seq_ctrl[i] = cpu_to_le16(USHORT_MAX);
252 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
253 printk(KERN_DEBUG "%s: Allocated STA %pM\n",
254 wiphy_name(local->hw.wiphy), sta->sta.addr);
255 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
257 #ifdef CONFIG_MAC80211_MESH
258 sta->plink_state = PLINK_LISTEN;
259 init_timer(&sta->plink_timer);
265 static int sta_info_finish_insert(struct sta_info *sta, bool async)
267 struct ieee80211_local *local = sta->local;
268 struct ieee80211_sub_if_data *sdata = sta->sdata;
269 struct station_info sinfo;
273 WARN_ON(!mutex_is_locked(&local->sta_mtx));
276 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
277 sdata = container_of(sdata->bss,
278 struct ieee80211_sub_if_data,
280 err = drv_sta_add(local, sdata, &sta->sta);
284 printk(KERN_DEBUG "%s: failed to add IBSS STA %pM to driver (%d)"
285 " - keeping it anyway.\n",
286 sdata->name, sta->sta.addr, err);
288 sta->uploaded = true;
289 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
291 printk(KERN_DEBUG "%s: Finished adding IBSS STA %pM\n",
292 wiphy_name(local->hw.wiphy), sta->sta.addr);
300 local->sta_generation++;
303 /* make the station visible */
304 spin_lock_irqsave(&local->sta_lock, flags);
305 sta_info_hash_add(local, sta);
306 spin_unlock_irqrestore(&local->sta_lock, flags);
309 list_add(&sta->list, &local->sta_list);
311 ieee80211_sta_debugfs_add(sta);
312 rate_control_add_sta_debugfs(sta);
315 sinfo.generation = local->sta_generation;
316 cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
322 static void sta_info_finish_pending(struct ieee80211_local *local)
324 struct sta_info *sta;
327 spin_lock_irqsave(&local->sta_lock, flags);
328 while (!list_empty(&local->sta_pending_list)) {
329 sta = list_first_entry(&local->sta_pending_list,
330 struct sta_info, list);
331 list_del(&sta->list);
332 spin_unlock_irqrestore(&local->sta_lock, flags);
334 sta_info_finish_insert(sta, true);
336 spin_lock_irqsave(&local->sta_lock, flags);
338 spin_unlock_irqrestore(&local->sta_lock, flags);
341 static void sta_info_finish_work(struct work_struct *work)
343 struct ieee80211_local *local =
344 container_of(work, struct ieee80211_local, sta_finish_work);
346 mutex_lock(&local->sta_mtx);
347 sta_info_finish_pending(local);
348 mutex_unlock(&local->sta_mtx);
351 int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
353 struct ieee80211_local *local = sta->local;
354 struct ieee80211_sub_if_data *sdata = sta->sdata;
359 * Can't be a WARN_ON because it can be triggered through a race:
360 * something inserts a STA (on one CPU) without holding the RTNL
361 * and another CPU turns off the net device.
363 if (unlikely(!ieee80211_sdata_running(sdata))) {
369 if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->vif.addr) == 0 ||
370 is_multicast_ether_addr(sta->sta.addr))) {
377 * In ad-hoc mode, we sometimes need to insert stations
378 * from tasklet context from the RX path. To avoid races,
379 * always do so in that case -- see the comment below.
381 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
382 spin_lock_irqsave(&local->sta_lock, flags);
383 /* check if STA exists already */
384 if (sta_info_get_bss(sdata, sta->sta.addr)) {
385 spin_unlock_irqrestore(&local->sta_lock, flags);
392 local->sta_generation++;
394 sta_info_hash_add(local, sta);
396 list_add_tail(&sta->list, &local->sta_pending_list);
399 spin_unlock_irqrestore(&local->sta_lock, flags);
401 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
402 printk(KERN_DEBUG "%s: Added IBSS STA %pM\n",
403 wiphy_name(local->hw.wiphy), sta->sta.addr);
404 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
406 ieee80211_queue_work(&local->hw, &local->sta_finish_work);
412 * On first glance, this will look racy, because the code
413 * below this point, which inserts a station with sleeping,
414 * unlocks the sta_lock between checking existence in the
415 * hash table and inserting into it.
417 * However, it is not racy against itself because it keeps
418 * the mutex locked. It still seems to race against the
419 * above code that atomically inserts the station... That,
420 * however, is not true because the above code can only
421 * be invoked for IBSS interfaces, and the below code will
422 * not be -- and the two do not race against each other as
423 * the hash table also keys off the interface.
428 mutex_lock(&local->sta_mtx);
430 spin_lock_irqsave(&local->sta_lock, flags);
431 /* check if STA exists already */
432 if (sta_info_get_bss(sdata, sta->sta.addr)) {
433 spin_unlock_irqrestore(&local->sta_lock, flags);
439 spin_unlock_irqrestore(&local->sta_lock, flags);
441 err = sta_info_finish_insert(sta, false);
443 mutex_unlock(&local->sta_mtx);
448 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
449 printk(KERN_DEBUG "%s: Inserted STA %pM\n",
450 wiphy_name(local->hw.wiphy), sta->sta.addr);
451 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
453 /* move reference to rcu-protected */
455 mutex_unlock(&local->sta_mtx);
457 if (ieee80211_vif_is_mesh(&sdata->vif))
458 mesh_accept_plinks_update(sdata);
463 __sta_info_free(local, sta);
467 int sta_info_insert(struct sta_info *sta)
469 int err = sta_info_insert_rcu(sta);
476 static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
479 * This format has been mandated by the IEEE specifications,
480 * so this line may not be changed to use the __set_bit() format.
482 bss->tim[aid / 8] |= (1 << (aid % 8));
485 static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
488 * This format has been mandated by the IEEE specifications,
489 * so this line may not be changed to use the __clear_bit() format.
491 bss->tim[aid / 8] &= ~(1 << (aid % 8));
494 static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
495 struct sta_info *sta)
499 __bss_tim_set(bss, sta->sta.aid);
501 if (sta->local->ops->set_tim) {
502 sta->local->tim_in_locked_section = true;
503 drv_set_tim(sta->local, &sta->sta, true);
504 sta->local->tim_in_locked_section = false;
508 void sta_info_set_tim_bit(struct sta_info *sta)
512 BUG_ON(!sta->sdata->bss);
514 spin_lock_irqsave(&sta->local->sta_lock, flags);
515 __sta_info_set_tim_bit(sta->sdata->bss, sta);
516 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
519 static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
520 struct sta_info *sta)
524 __bss_tim_clear(bss, sta->sta.aid);
526 if (sta->local->ops->set_tim) {
527 sta->local->tim_in_locked_section = true;
528 drv_set_tim(sta->local, &sta->sta, false);
529 sta->local->tim_in_locked_section = false;
533 void sta_info_clear_tim_bit(struct sta_info *sta)
537 BUG_ON(!sta->sdata->bss);
539 spin_lock_irqsave(&sta->local->sta_lock, flags);
540 __sta_info_clear_tim_bit(sta->sdata->bss, sta);
541 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
544 static int sta_info_buffer_expired(struct sta_info *sta,
547 struct ieee80211_tx_info *info;
553 info = IEEE80211_SKB_CB(skb);
555 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
556 timeout = (sta->listen_interval *
557 sta->sdata->vif.bss_conf.beacon_int *
559 if (timeout < STA_TX_BUFFER_EXPIRE)
560 timeout = STA_TX_BUFFER_EXPIRE;
561 return time_after(jiffies, info->control.jiffies + timeout);
565 static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
566 struct sta_info *sta)
570 struct ieee80211_sub_if_data *sdata;
572 if (skb_queue_empty(&sta->ps_tx_buf))
576 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
577 skb = skb_peek(&sta->ps_tx_buf);
578 if (sta_info_buffer_expired(sta, skb))
579 skb = __skb_dequeue(&sta->ps_tx_buf);
582 spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
588 local->total_ps_buffered--;
589 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
590 printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n",
595 if (skb_queue_empty(&sta->ps_tx_buf))
596 sta_info_clear_tim_bit(sta);
600 static int __must_check __sta_info_destroy(struct sta_info *sta)
602 struct ieee80211_local *local;
603 struct ieee80211_sub_if_data *sdata;
617 * Before removing the station from the driver and
618 * rate control, it might still start new aggregation
619 * sessions -- block that to make sure the tear-down
620 * will be sufficient.
622 set_sta_flags(sta, WLAN_STA_BLOCK_BA);
623 ieee80211_sta_tear_down_BA_sessions(sta);
625 spin_lock_irqsave(&local->sta_lock, flags);
626 ret = sta_info_hash_del(local, sta);
627 /* this might still be the pending list ... which is fine */
629 list_del(&sta->list);
630 spin_unlock_irqrestore(&local->sta_lock, flags);
635 ieee80211_key_free(sta->key);
637 * We have only unlinked the key, and actually destroying it
638 * may mean it is removed from hardware which requires that
639 * the key->sta pointer is still valid, so flush the key todo
642 ieee80211_key_todo();
649 if (test_and_clear_sta_flags(sta,
650 WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) {
653 atomic_dec(&sdata->bss->num_sta_ps);
654 __sta_info_clear_tim_bit(sdata->bss, sta);
658 local->sta_generation++;
660 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
661 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
664 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
665 sdata = container_of(sdata->bss,
666 struct ieee80211_sub_if_data,
668 drv_sta_remove(local, sdata, &sta->sta);
673 * At this point, after we wait for an RCU grace period,
674 * neither mac80211 nor the driver can reference this
675 * sta struct any more except by still existing timers
676 * associated with this station that we clean up below.
680 #ifdef CONFIG_MAC80211_MESH
681 if (ieee80211_vif_is_mesh(&sdata->vif))
682 mesh_accept_plinks_update(sdata);
685 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
686 printk(KERN_DEBUG "%s: Removed STA %pM\n",
687 wiphy_name(local->hw.wiphy), sta->sta.addr);
688 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
689 cancel_work_sync(&sta->drv_unblock_wk);
691 rate_control_remove_sta_debugfs(sta);
692 ieee80211_sta_debugfs_remove(sta);
694 #ifdef CONFIG_MAC80211_MESH
695 if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
696 mesh_plink_deactivate(sta);
697 del_timer_sync(&sta->plink_timer);
701 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
702 local->total_ps_buffered--;
703 dev_kfree_skb_any(skb);
706 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL)
707 dev_kfree_skb_any(skb);
709 __sta_info_free(local, sta);
714 int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
716 struct sta_info *sta;
719 mutex_lock(&sdata->local->sta_mtx);
720 sta = sta_info_get(sdata, addr);
721 ret = __sta_info_destroy(sta);
722 mutex_unlock(&sdata->local->sta_mtx);
727 int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
730 struct sta_info *sta;
733 mutex_lock(&sdata->local->sta_mtx);
734 sta = sta_info_get_bss(sdata, addr);
735 ret = __sta_info_destroy(sta);
736 mutex_unlock(&sdata->local->sta_mtx);
741 static void sta_info_cleanup(unsigned long data)
743 struct ieee80211_local *local = (struct ieee80211_local *) data;
744 struct sta_info *sta;
747 list_for_each_entry_rcu(sta, &local->sta_list, list)
748 sta_info_cleanup_expire_buffered(local, sta);
751 if (local->quiescing)
754 local->sta_cleanup.expires =
755 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
756 add_timer(&local->sta_cleanup);
759 void sta_info_init(struct ieee80211_local *local)
761 spin_lock_init(&local->sta_lock);
762 mutex_init(&local->sta_mtx);
763 INIT_LIST_HEAD(&local->sta_list);
764 INIT_LIST_HEAD(&local->sta_pending_list);
765 INIT_WORK(&local->sta_finish_work, sta_info_finish_work);
767 setup_timer(&local->sta_cleanup, sta_info_cleanup,
768 (unsigned long)local);
769 local->sta_cleanup.expires =
770 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
773 int sta_info_start(struct ieee80211_local *local)
775 add_timer(&local->sta_cleanup);
779 void sta_info_stop(struct ieee80211_local *local)
781 del_timer(&local->sta_cleanup);
782 sta_info_flush(local, NULL);
786 * sta_info_flush - flush matching STA entries from the STA table
788 * Returns the number of removed STA entries.
790 * @local: local interface data
791 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
793 int sta_info_flush(struct ieee80211_local *local,
794 struct ieee80211_sub_if_data *sdata)
796 struct sta_info *sta, *tmp;
801 mutex_lock(&local->sta_mtx);
803 sta_info_finish_pending(local);
805 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
806 if (!sdata || sdata == sta->sdata)
807 WARN_ON(__sta_info_destroy(sta));
809 mutex_unlock(&local->sta_mtx);
814 void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
815 unsigned long exp_time)
817 struct ieee80211_local *local = sdata->local;
818 struct sta_info *sta, *tmp;
820 mutex_lock(&local->sta_mtx);
821 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
822 if (time_after(jiffies, sta->last_rx + exp_time)) {
823 #ifdef CONFIG_MAC80211_IBSS_DEBUG
824 printk(KERN_DEBUG "%s: expiring inactive STA %pM\n",
825 sdata->name, sta->sta.addr);
827 WARN_ON(__sta_info_destroy(sta));
829 mutex_unlock(&local->sta_mtx);
832 struct ieee80211_sta *ieee80211_find_sta_by_hw(struct ieee80211_hw *hw,
835 struct sta_info *sta, *nxt;
837 /* Just return a random station ... first in list ... */
838 for_each_sta_info(hw_to_local(hw), addr, sta, nxt)
842 EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_hw);
844 struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
847 struct ieee80211_sub_if_data *sdata;
852 sdata = vif_to_sdata(vif);
854 return ieee80211_find_sta_by_hw(&sdata->local->hw, addr);
856 EXPORT_SYMBOL(ieee80211_find_sta);
858 /* powersave support code */
859 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
861 struct ieee80211_sub_if_data *sdata = sta->sdata;
862 struct ieee80211_local *local = sdata->local;
865 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
867 if (!skb_queue_empty(&sta->ps_tx_buf))
868 sta_info_clear_tim_bit(sta);
870 /* Send all buffered frames to the station */
871 sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered);
872 buffered = ieee80211_add_pending_skbs(local, &sta->ps_tx_buf);
874 local->total_ps_buffered -= buffered;
876 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
877 printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames "
878 "since STA not sleeping anymore\n", sdata->name,
879 sta->sta.addr, sta->sta.aid, sent - buffered, buffered);
880 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
883 void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
885 struct ieee80211_sub_if_data *sdata = sta->sdata;
886 struct ieee80211_local *local = sdata->local;
890 skb = skb_dequeue(&sta->tx_filtered);
892 skb = skb_dequeue(&sta->ps_tx_buf);
894 local->total_ps_buffered--;
896 no_pending_pkts = skb_queue_empty(&sta->tx_filtered) &&
897 skb_queue_empty(&sta->ps_tx_buf);
900 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
901 struct ieee80211_hdr *hdr =
902 (struct ieee80211_hdr *) skb->data;
905 * Tell TX path to send this frame even though the STA may
906 * still remain is PS mode after this frame exchange.
908 info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE;
910 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
911 printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n",
912 sta->sta.addr, sta->sta.aid,
913 skb_queue_len(&sta->ps_tx_buf));
914 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
916 /* Use MoreData flag to indicate whether there are more
917 * buffered frames for this STA */
919 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
921 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
923 ieee80211_add_pending_skb(local, skb);
926 sta_info_clear_tim_bit(sta);
927 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
930 * FIXME: This can be the result of a race condition between
931 * us expiring a frame and the station polling for it.
932 * Should we send it a null-func frame indicating we
933 * have nothing buffered for it?
935 printk(KERN_DEBUG "%s: STA %pM sent PS Poll even "
936 "though there are no buffered frames for it\n",
937 sdata->name, sta->sta.addr);
938 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
942 void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
943 struct ieee80211_sta *pubsta, bool block)
945 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
948 set_sta_flags(sta, WLAN_STA_PS_DRIVER);
950 ieee80211_queue_work(hw, &sta->drv_unblock_wk);
952 EXPORT_SYMBOL(ieee80211_sta_block_awake);