10 #include <linux/module.h>
13 #include <linux/netdevice.h>
14 #include <linux/types.h>
15 #include <linux/slab.h>
17 #include <linux/if_arp.h>
19 #include <linux/rtnetlink.h>
73 lockdep_is_held(&local->
sta_mtx));
85 lockdep_is_held(&local->
sta_mtx));
124 #ifdef CONFIG_MAC80211_MESH
125 if (ieee80211_vif_is_mesh(&sdata->
vif)) {
151 static void free_sta_rcu(
struct rcu_head *
h)
166 lockdep_is_held(&local->
sta_mtx));
168 if (sta->
sdata == sdata &&
169 ether_addr_equal(sta->
sta.addr, addr))
172 lockdep_is_held(&local->
sta_mtx));
188 lockdep_is_held(&local->
sta_mtx));
190 if ((sta->
sdata == sdata ||
192 ether_addr_equal(sta->
sta.addr, addr))
195 lockdep_is_held(&local->
sta_mtx));
208 if (sdata != sta->
sdata)
234 rate_control_free_sta(sta);
302 sta = kzalloc(
sizeof(*sta) + local->
hw.sta_data_size, gfp);
323 if (sta_prepare_rate_control(local, sta, gfp)) {
344 sta_dbg(sdata,
"Allocated STA %pM\n", sta->
sta.addr);
346 #ifdef CONFIG_MAC80211_MESH
354 static int sta_info_insert_check(
struct sta_info *sta)
363 if (
unlikely(!ieee80211_sdata_running(sdata)))
366 if (
WARN_ON(ether_addr_equal(sta->
sta.addr, sdata->
vif.addr) ||
367 is_multicast_ether_addr(sta->
sta.addr)))
381 err = drv_sta_state(local, sdata, sta, state, state + 1);
391 if (!local->
ops->sta_add)
398 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
399 sta->
sta.addr, state + 1, err);
405 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
431 err = sta_info_insert_drv_state(local, sdata, sta);
440 sta_info_hash_add(local, sta);
447 rate_control_add_sta_debugfs(sta);
454 sta_dbg(sdata,
"Inserted STA %pM\n", sta->
sta.addr);
460 if (ieee80211_vif_is_mesh(&sdata->
vif))
477 err = sta_info_insert_check(sta);
485 err = sta_info_insert_finish(sta);
511 bss->
tim[aid / 8] |= (1 << (aid % 8));
520 bss->
tim[aid / 8] &= ~(1 << (aid % 8));
523 static unsigned long ieee80211_tids_for_ac(
int ac)
546 bool indicate_tim =
false;
547 u8 ignore_for_tim = sta->
sta.uapsd_queues;
566 if (ignore_for_tim ==
BIT(IEEE80211_NUM_ACS) - 1)
572 if (ignore_for_tim &
BIT(ac))
575 indicate_tim |= !skb_queue_empty(&sta->
tx_filtered[ac]) ||
580 tids = ieee80211_tids_for_ac(ac);
590 __bss_tim_set(bss, sta->
sta.aid);
592 __bss_tim_clear(bss, sta->
sta.aid);
594 if (local->
ops->set_tim) {
596 drv_set_tim(local, &sta->
sta, indicate_tim);
600 spin_unlock_irqrestore(&local->
tim_lock, flags);
611 info = IEEE80211_SKB_CB(skb);
615 sta->
sdata->vif.bss_conf.beacon_int *
623 static bool sta_info_cleanup_expire_buffered_ac(
struct ieee80211_local *local,
639 if (sta_info_buffer_expired(sta, skb))
643 spin_unlock_irqrestore(&sta->
tx_filtered[ac].lock, flags);
665 if (sta_info_buffer_expired(sta, skb))
666 skb = __skb_dequeue(&sta->
ps_tx_buf[ac]);
669 spin_unlock_irqrestore(&sta->
ps_tx_buf[ac].lock, flags);
680 ps_dbg(sta->
sdata,
"Buffered frame expired (STA %pM)\n",
697 return !(skb_queue_empty(&sta->
ps_tx_buf[ac]) &&
701 static bool sta_info_cleanup_expire_buffered(
struct ieee80211_local *local,
704 bool have_buffered =
false;
708 if (!sta->
sdata->bss)
713 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
715 return have_buffered;
743 ret = sta_info_hash_del(local, sta);
747 list_del_rcu(&sta->
list);
774 IEEE80211_STA_NOTEXIST);
778 sta_dbg(sdata,
"Removed STA %pM\n", sta->
sta.addr);
782 rate_control_remove_sta_debugfs(sta);
817 static void sta_info_cleanup(
unsigned long data)
821 bool timer_needed =
false;
825 if (sta_info_cleanup_expire_buffered(local, sta))
829 if (local->quiescing)
843 INIT_LIST_HEAD(&local->sta_list);
846 (
unsigned long)local);
873 if (!sdata || sdata == sta->
sdata) {
884 unsigned long exp_time)
892 if (sdata != sta->
sdata)
896 ibss_dbg(sdata,
"expiring inactive STA %pM\n",
917 !ether_addr_equal(sta->
sdata->vif.addr, localaddr))
947 static void clear_sta_ps_flags(
void *_sta)
963 int filtered = 0, buffered = 0,
ac;
974 skb_queue_head_init(&pending);
978 int count = skb_queue_len(&pending),
tmp;
981 skb_queue_splice_tail_init(&sta->
tx_filtered[ac], &pending);
982 spin_unlock_irqrestore(&sta->
tx_filtered[ac].lock, flags);
983 tmp = skb_queue_len(&pending);
988 skb_queue_splice_tail_init(&sta->
ps_tx_buf[ac], &pending);
989 spin_unlock_irqrestore(&sta->
ps_tx_buf[ac].lock, flags);
990 tmp = skb_queue_len(&pending);
1001 "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
1002 sta->
sta.addr, sta->
sta.aid, filtered, buffered);
1012 int size =
sizeof(*nullfunc);
1028 skb = dev_alloc_skb(local->
hw.extra_tx_headroom + size);
1032 skb_reserve(skb, local->
hw.extra_tx_headroom);
1034 nullfunc = (
void *)
skb_put(skb, size);
1051 info = IEEE80211_SKB_CB(skb);
1063 drv_allow_buffered_frames(local, sta,
BIT(tid), 1, reason,
false);
1069 ieee80211_sta_ps_deliver_response(
struct sta_info *sta,
1070 int n_frames,
u8 ignored_acs,
1076 bool more_data =
false;
1078 unsigned long driver_release_tids = 0;
1084 __skb_queue_head_init(&frames);
1092 if (ignored_acs &
BIT(ac))
1095 tids = ieee80211_tids_for_ac(ac);
1099 if (driver_release_tids) {
1104 while (n_frames > 0) {
1116 __skb_queue_tail(&frames, skb);
1128 driver_release_tids =
1129 BIT(
ffs(driver_release_tids) - 1);
1135 !skb_queue_empty(&sta->
ps_tx_buf[ac])) {
1160 tid = 7 - ((
ffs(~ignored_acs) - 1) << 1);
1162 ieee80211_send_null_response(sdata, sta, tid, reason);
1166 if (!driver_release_tids) {
1172 skb_queue_head_init(&pending);
1174 while ((skb = __skb_dequeue(&frames))) {
1192 if (more_data || !skb_queue_empty(&frames))
1201 qoshdr = ieee80211_get_qos_ctl(hdr);
1204 if (skb_queue_empty(&frames)) {
1218 __skb_queue_tail(&pending, skb);
1221 drv_allow_buffered_frames(local, sta, tids, num,
1224 ieee80211_add_pending_skbs(local, &pending);
1238 drv_release_buffered_frames(local, sta, driver_release_tids,
1239 n_frames, reason, more_data);
1254 u8 ignore_for_response = sta->
sta.uapsd_queues;
1261 if (ignore_for_response ==
BIT(IEEE80211_NUM_ACS) - 1)
1262 ignore_for_response = 0;
1264 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
1270 int n_frames = sta->
sta.max_sp;
1271 u8 delivery_enabled = sta->
sta.uapsd_queues;
1279 if (!delivery_enabled)
1282 switch (sta->
sta.max_sp) {
1298 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
1307 trace_api_sta_block_awake(sta->
local, pubsta, block);
1323 trace_api_eosp(local, pubsta);
1332 data = (
void *)skb->cb;
1337 tasklet_schedule(&local->
tasklet);
1342 u8 tid,
bool buffered)
1346 if (
WARN_ON(tid >= STA_TID_NUM))
1368 switch (new_state) {
1388 WARN(1,
"invalid state %d", new_state);
1393 sta->
sta.addr, new_state);
1400 int err = drv_sta_state(sta->
local, sta->
sdata, sta,
1408 switch (new_state) {
1425 !sta->
sdata->u.vlan.sta))
1434 !sta->
sdata->u.vlan.sta))