1f0706e82SJiri Benc /* 2f0706e82SJiri Benc * Copyright 2002-2005, Instant802 Networks, Inc. 3f0706e82SJiri Benc * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 4f0706e82SJiri Benc * 5f0706e82SJiri Benc * This program is free software; you can redistribute it and/or modify 6f0706e82SJiri Benc * it under the terms of the GNU General Public License version 2 as 7f0706e82SJiri Benc * published by the Free Software Foundation. 8f0706e82SJiri Benc */ 9f0706e82SJiri Benc 10f0706e82SJiri Benc #include <linux/module.h> 11f0706e82SJiri Benc #include <linux/init.h> 12f0706e82SJiri Benc #include <linux/netdevice.h> 13f0706e82SJiri Benc #include <linux/types.h> 14f0706e82SJiri Benc #include <linux/slab.h> 15f0706e82SJiri Benc #include <linux/skbuff.h> 16f0706e82SJiri Benc #include <linux/if_arp.h> 170d174406SJohannes Berg #include <linux/timer.h> 18d0709a65SJohannes Berg #include <linux/rtnetlink.h> 19f0706e82SJiri Benc 20f0706e82SJiri Benc #include <net/mac80211.h> 21f0706e82SJiri Benc #include "ieee80211_i.h" 2224487981SJohannes Berg #include "driver-ops.h" 232c8dccc7SJohannes Berg #include "rate.h" 24f0706e82SJiri Benc #include "sta_info.h" 25e9f207f0SJiri Benc #include "debugfs_sta.h" 26ee385855SLuis Carlos Cobo #include "mesh.h" 27f0706e82SJiri Benc 28d0709a65SJohannes Berg /** 29d0709a65SJohannes Berg * DOC: STA information lifetime rules 30d0709a65SJohannes Berg * 31d0709a65SJohannes Berg * STA info structures (&struct sta_info) are managed in a hash table 32d0709a65SJohannes Berg * for faster lookup and a list for iteration. They are managed using 33d0709a65SJohannes Berg * RCU, i.e. access to the list and hash table is protected by RCU. 34d0709a65SJohannes Berg * 3503e4497eSJohannes Berg * Upon allocating a STA info structure with sta_info_alloc(), the caller owns 3603e4497eSJohannes Berg * that structure. It must then either destroy it using sta_info_destroy() 3703e4497eSJohannes Berg * (which is pretty useless) or insert it into the hash table using 3803e4497eSJohannes Berg * sta_info_insert() which demotes the reference from ownership to a regular 3903e4497eSJohannes Berg * RCU-protected reference; if the function is called without protection by an 4093e5deb1SJohannes Berg * RCU critical section the reference is instantly invalidated. Note that the 4193e5deb1SJohannes Berg * caller may not do much with the STA info before inserting it, in particular, 4293e5deb1SJohannes Berg * it may not start any mesh peer link management or add encryption keys. 4393e5deb1SJohannes Berg * 4493e5deb1SJohannes Berg * When the insertion fails (sta_info_insert()) returns non-zero), the 4593e5deb1SJohannes Berg * structure will have been freed by sta_info_insert()! 46d0709a65SJohannes Berg * 47d0709a65SJohannes Berg * Because there are debugfs entries for each station, and adding those 48d0709a65SJohannes Berg * must be able to sleep, it is also possible to "pin" a station entry, 49d0709a65SJohannes Berg * that means it can be removed from the hash table but not be freed. 5093e5deb1SJohannes Berg * See the comment in __sta_info_unlink() for more information, this is 5193e5deb1SJohannes Berg * an internal capability only. 52d0709a65SJohannes Berg * 53d0709a65SJohannes Berg * In order to remove a STA info structure, the caller needs to first 54dbbea671SJohannes Berg * unlink it (sta_info_unlink()) from the list and hash tables and 553b96766fSJohannes Berg * then destroy it; sta_info_destroy() will wait for an RCU grace period 563b96766fSJohannes Berg * to elapse before actually freeing it. Due to the pinning and the 573b96766fSJohannes Berg * possibility of multiple callers trying to remove the same STA info at 583b96766fSJohannes Berg * the same time, sta_info_unlink() can clear the STA info pointer it is 593b96766fSJohannes Berg * passed to indicate that the STA info is owned by somebody else now. 60d0709a65SJohannes Berg * 61dbbea671SJohannes Berg * If sta_info_unlink() did not clear the pointer then the caller owns 62d0709a65SJohannes Berg * the STA info structure now and is responsible of destroying it with 633b96766fSJohannes Berg * a call to sta_info_destroy(). 64d0709a65SJohannes Berg * 65d0709a65SJohannes Berg * In all other cases, there is no concept of ownership on a STA entry, 66d0709a65SJohannes Berg * each structure is owned by the global hash table/list until it is 67d0709a65SJohannes Berg * removed. All users of the structure need to be RCU protected so that 68d0709a65SJohannes Berg * the structure won't be freed before they are done using it. 69d0709a65SJohannes Berg */ 70f0706e82SJiri Benc 71f0706e82SJiri Benc /* Caller must hold local->sta_lock */ 72be8755e1SMichael Wu static int sta_info_hash_del(struct ieee80211_local *local, 73f0706e82SJiri Benc struct sta_info *sta) 74f0706e82SJiri Benc { 75f0706e82SJiri Benc struct sta_info *s; 76f0706e82SJiri Benc 7717741cdcSJohannes Berg s = local->sta_hash[STA_HASH(sta->sta.addr)]; 78f0706e82SJiri Benc if (!s) 79be8755e1SMichael Wu return -ENOENT; 80be8755e1SMichael Wu if (s == sta) { 8117741cdcSJohannes Berg rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], 82d0709a65SJohannes Berg s->hnext); 83be8755e1SMichael Wu return 0; 84f0706e82SJiri Benc } 85f0706e82SJiri Benc 86be8755e1SMichael Wu while (s->hnext && s->hnext != sta) 87f0706e82SJiri Benc s = s->hnext; 88be8755e1SMichael Wu if (s->hnext) { 89d0709a65SJohannes Berg rcu_assign_pointer(s->hnext, sta->hnext); 90be8755e1SMichael Wu return 0; 91f0706e82SJiri Benc } 92f0706e82SJiri Benc 93be8755e1SMichael Wu return -ENOENT; 94f0706e82SJiri Benc } 95f0706e82SJiri Benc 96d0709a65SJohannes Berg /* protected by RCU */ 974b7679a5SJohannes Berg struct sta_info *sta_info_get(struct ieee80211_local *local, const u8 *addr) 9843ba7e95SJohannes Berg { 9943ba7e95SJohannes Berg struct sta_info *sta; 10043ba7e95SJohannes Berg 101d0709a65SJohannes Berg sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]); 10243ba7e95SJohannes Berg while (sta) { 1035cf12e8dSShaddy Baddah if (memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) 10443ba7e95SJohannes Berg break; 105d0709a65SJohannes Berg sta = rcu_dereference(sta->hnext); 10643ba7e95SJohannes Berg } 10743ba7e95SJohannes Berg return sta; 10843ba7e95SJohannes Berg } 10943ba7e95SJohannes Berg 110ee385855SLuis Carlos Cobo struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx, 111ee385855SLuis Carlos Cobo struct net_device *dev) 112ee385855SLuis Carlos Cobo { 113ee385855SLuis Carlos Cobo struct sta_info *sta; 114ee385855SLuis Carlos Cobo int i = 0; 115ee385855SLuis Carlos Cobo 116d0709a65SJohannes Berg list_for_each_entry_rcu(sta, &local->sta_list, list) { 1172a8ca29aSLuis Carlos Cobo if (dev && dev != sta->sdata->dev) 1182a8ca29aSLuis Carlos Cobo continue; 119ee385855SLuis Carlos Cobo if (i < idx) { 120ee385855SLuis Carlos Cobo ++i; 121ee385855SLuis Carlos Cobo continue; 122ee385855SLuis Carlos Cobo } 1232a8ca29aSLuis Carlos Cobo return sta; 124ee385855SLuis Carlos Cobo } 125ee385855SLuis Carlos Cobo 126ee385855SLuis Carlos Cobo return NULL; 127ee385855SLuis Carlos Cobo } 128f0706e82SJiri Benc 12993e5deb1SJohannes Berg /** 13093e5deb1SJohannes Berg * __sta_info_free - internal STA free helper 13193e5deb1SJohannes Berg * 1326ef307bcSRandy Dunlap * @local: pointer to the global information 13393e5deb1SJohannes Berg * @sta: STA info to free 13493e5deb1SJohannes Berg * 13593e5deb1SJohannes Berg * This function must undo everything done by sta_info_alloc() 13693e5deb1SJohannes Berg * that may happen before sta_info_insert(). 13793e5deb1SJohannes Berg */ 13893e5deb1SJohannes Berg static void __sta_info_free(struct ieee80211_local *local, 13993e5deb1SJohannes Berg struct sta_info *sta) 14093e5deb1SJohannes Berg { 1414b7679a5SJohannes Berg rate_control_free_sta(sta); 14293e5deb1SJohannes Berg rate_control_put(sta->rate_ctrl); 14393e5deb1SJohannes Berg 14493e5deb1SJohannes Berg #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1450c68ae26SJohannes Berg printk(KERN_DEBUG "%s: Destroyed STA %pM\n", 1460c68ae26SJohannes Berg wiphy_name(local->hw.wiphy), sta->sta.addr); 14793e5deb1SJohannes Berg #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 14893e5deb1SJohannes Berg 14993e5deb1SJohannes Berg kfree(sta); 15093e5deb1SJohannes Berg } 15193e5deb1SJohannes Berg 152d0709a65SJohannes Berg void sta_info_destroy(struct sta_info *sta) 153f0706e82SJiri Benc { 15497bff8ecSJohannes Berg struct ieee80211_local *local; 155f0706e82SJiri Benc struct sk_buff *skb; 15607db2183SRon Rindjunsky int i; 15773651ee6SJohannes Berg 15897bff8ecSJohannes Berg might_sleep(); 15997bff8ecSJohannes Berg 16073651ee6SJohannes Berg if (!sta) 16173651ee6SJohannes Berg return; 162f0706e82SJiri Benc 16397bff8ecSJohannes Berg local = sta->local; 164d0709a65SJohannes Berg 165d0709a65SJohannes Berg rate_control_remove_sta_debugfs(sta); 166d0709a65SJohannes Berg ieee80211_sta_debugfs_remove(sta); 167d0709a65SJohannes Berg 168d0709a65SJohannes Berg #ifdef CONFIG_MAC80211_MESH 169d0709a65SJohannes Berg if (ieee80211_vif_is_mesh(&sta->sdata->vif)) 170d0709a65SJohannes Berg mesh_plink_deactivate(sta); 171d0709a65SJohannes Berg #endif 172d0709a65SJohannes Berg 173d0709a65SJohannes Berg /* 1743b96766fSJohannes Berg * We have only unlinked the key, and actually destroying it 1753b96766fSJohannes Berg * may mean it is removed from hardware which requires that 1763b96766fSJohannes Berg * the key->sta pointer is still valid, so flush the key todo 1773b96766fSJohannes Berg * list here. 1783b96766fSJohannes Berg * 1793b96766fSJohannes Berg * ieee80211_key_todo() will synchronize_rcu() so after this 1803b96766fSJohannes Berg * nothing can reference this sta struct any more. 181d0709a65SJohannes Berg */ 1823b96766fSJohannes Berg ieee80211_key_todo(); 183d0709a65SJohannes Berg 184d0709a65SJohannes Berg #ifdef CONFIG_MAC80211_MESH 185d0709a65SJohannes Berg if (ieee80211_vif_is_mesh(&sta->sdata->vif)) 186d0709a65SJohannes Berg del_timer_sync(&sta->plink_timer); 187d0709a65SJohannes Berg #endif 188d0709a65SJohannes Berg 189f0706e82SJiri Benc while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { 190f0706e82SJiri Benc local->total_ps_buffered--; 191f0706e82SJiri Benc dev_kfree_skb_any(skb); 192f0706e82SJiri Benc } 193d0709a65SJohannes Berg 194d0709a65SJohannes Berg while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) 195f0706e82SJiri Benc dev_kfree_skb_any(skb); 196d0709a65SJohannes Berg 197fe3bf0f5SRon Rindjunsky for (i = 0; i < STA_TID_NUM; i++) { 19855687e38SJohannes Berg struct tid_ampdu_rx *tid_rx; 19955687e38SJohannes Berg struct tid_ampdu_tx *tid_tx; 20055687e38SJohannes Berg 20107346f81SJohannes Berg spin_lock_bh(&sta->lock); 20255687e38SJohannes Berg tid_rx = sta->ampdu_mlme.tid_rx[i]; 20355687e38SJohannes Berg /* Make sure timer won't free the tid_rx struct, see below */ 20455687e38SJohannes Berg if (tid_rx) 20555687e38SJohannes Berg tid_rx->shutdown = true; 20696f5e66eSJohannes Berg 20707346f81SJohannes Berg spin_unlock_bh(&sta->lock); 20855687e38SJohannes Berg 20955687e38SJohannes Berg /* 21055687e38SJohannes Berg * Outside spinlock - shutdown is true now so that the timer 21155687e38SJohannes Berg * won't free tid_rx, we have to do that now. Can't let the 21255687e38SJohannes Berg * timer do it because we have to sync the timer outside the 21355687e38SJohannes Berg * lock that it takes itself. 21455687e38SJohannes Berg */ 21555687e38SJohannes Berg if (tid_rx) { 21655687e38SJohannes Berg del_timer_sync(&tid_rx->session_timer); 21755687e38SJohannes Berg kfree(tid_rx); 21855687e38SJohannes Berg } 21955687e38SJohannes Berg 22055687e38SJohannes Berg /* 22155687e38SJohannes Berg * No need to do such complications for TX agg sessions, the 22255687e38SJohannes Berg * path leading to freeing the tid_tx struct goes via a call 22355687e38SJohannes Berg * from the driver, and thus needs to look up the sta struct 22455687e38SJohannes Berg * again, which cannot be found when we get here. Hence, we 22555687e38SJohannes Berg * just need to delete the timer and free the aggregation 22655687e38SJohannes Berg * info; we won't be telling the peer about it then but that 22755687e38SJohannes Berg * doesn't matter if we're not talking to it again anyway. 22855687e38SJohannes Berg */ 22955687e38SJohannes Berg tid_tx = sta->ampdu_mlme.tid_tx[i]; 23055687e38SJohannes Berg if (tid_tx) { 23155687e38SJohannes Berg del_timer_sync(&tid_tx->addba_resp_timer); 232cd8ffc80SJohannes Berg /* 233cd8ffc80SJohannes Berg * STA removed while aggregation session being 234cd8ffc80SJohannes Berg * started? Bit odd, but purge frames anyway. 235cd8ffc80SJohannes Berg */ 236cd8ffc80SJohannes Berg skb_queue_purge(&tid_tx->pending); 23755687e38SJohannes Berg kfree(tid_tx); 23855687e38SJohannes Berg } 239fe3bf0f5SRon Rindjunsky } 240cee24a3eSRon Rindjunsky 24193e5deb1SJohannes Berg __sta_info_free(local, sta); 242f0706e82SJiri Benc } 243f0706e82SJiri Benc 244f0706e82SJiri Benc 245d0709a65SJohannes Berg /* Caller must hold local->sta_lock */ 246d0709a65SJohannes Berg static void sta_info_hash_add(struct ieee80211_local *local, 247d0709a65SJohannes Berg struct sta_info *sta) 248f0706e82SJiri Benc { 24917741cdcSJohannes Berg sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; 25017741cdcSJohannes Berg rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta); 251f0706e82SJiri Benc } 252f0706e82SJiri Benc 25373651ee6SJohannes Berg struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, 25473651ee6SJohannes Berg u8 *addr, gfp_t gfp) 255f0706e82SJiri Benc { 256d0709a65SJohannes Berg struct ieee80211_local *local = sdata->local; 257f0706e82SJiri Benc struct sta_info *sta; 25816c5f15cSRon Rindjunsky int i; 259f0706e82SJiri Benc 26017741cdcSJohannes Berg sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); 261f0706e82SJiri Benc if (!sta) 26273651ee6SJohannes Berg return NULL; 263f0706e82SJiri Benc 26407346f81SJohannes Berg spin_lock_init(&sta->lock); 2655a9f7b04SJohannes Berg spin_lock_init(&sta->flaglock); 26607346f81SJohannes Berg 26717741cdcSJohannes Berg memcpy(sta->sta.addr, addr, ETH_ALEN); 268d0709a65SJohannes Berg sta->local = local; 269d0709a65SJohannes Berg sta->sdata = sdata; 270f0706e82SJiri Benc 271f0706e82SJiri Benc sta->rate_ctrl = rate_control_get(local->rate_ctrl); 272d0709a65SJohannes Berg sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, 2734b7679a5SJohannes Berg &sta->sta, gfp); 274f0706e82SJiri Benc if (!sta->rate_ctrl_priv) { 275f0706e82SJiri Benc rate_control_put(sta->rate_ctrl); 276f0706e82SJiri Benc kfree(sta); 27773651ee6SJohannes Berg return NULL; 278f0706e82SJiri Benc } 279f0706e82SJiri Benc 28016c5f15cSRon Rindjunsky for (i = 0; i < STA_TID_NUM; i++) { 28116c5f15cSRon Rindjunsky /* timer_to_tid must be initialized with identity mapping to 28216c5f15cSRon Rindjunsky * enable session_timer's data differentiation. refer to 28316c5f15cSRon Rindjunsky * sta_rx_agg_session_timer_expired for useage */ 28416c5f15cSRon Rindjunsky sta->timer_to_tid[i] = i; 285cee24a3eSRon Rindjunsky /* rx */ 286cee24a3eSRon Rindjunsky sta->ampdu_mlme.tid_state_rx[i] = HT_AGG_STATE_IDLE; 287cee24a3eSRon Rindjunsky sta->ampdu_mlme.tid_rx[i] = NULL; 288cee24a3eSRon Rindjunsky /* tx */ 289cee24a3eSRon Rindjunsky sta->ampdu_mlme.tid_state_tx[i] = HT_AGG_STATE_IDLE; 290cee24a3eSRon Rindjunsky sta->ampdu_mlme.tid_tx[i] = NULL; 291cee24a3eSRon Rindjunsky sta->ampdu_mlme.addba_req_num[i] = 0; 29216c5f15cSRon Rindjunsky } 293f0706e82SJiri Benc skb_queue_head_init(&sta->ps_tx_buf); 294f0706e82SJiri Benc skb_queue_head_init(&sta->tx_filtered); 29573651ee6SJohannes Berg 296cccaec98SSenthil Balasubramanian for (i = 0; i < NUM_RX_DATA_QUEUES; i++) 297cccaec98SSenthil Balasubramanian sta->last_seq_ctrl[i] = cpu_to_le16(USHORT_MAX); 298cccaec98SSenthil Balasubramanian 29973651ee6SJohannes Berg #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 3000c68ae26SJohannes Berg printk(KERN_DEBUG "%s: Allocated STA %pM\n", 3010c68ae26SJohannes Berg wiphy_name(local->hw.wiphy), sta->sta.addr); 30273651ee6SJohannes Berg #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 30373651ee6SJohannes Berg 30403e4497eSJohannes Berg #ifdef CONFIG_MAC80211_MESH 305b4e08ea1SLuis Carlos Cobo sta->plink_state = PLINK_LISTEN; 30603e4497eSJohannes Berg init_timer(&sta->plink_timer); 30703e4497eSJohannes Berg #endif 30803e4497eSJohannes Berg 30973651ee6SJohannes Berg return sta; 31073651ee6SJohannes Berg } 31173651ee6SJohannes Berg 31273651ee6SJohannes Berg int sta_info_insert(struct sta_info *sta) 31373651ee6SJohannes Berg { 31473651ee6SJohannes Berg struct ieee80211_local *local = sta->local; 31573651ee6SJohannes Berg struct ieee80211_sub_if_data *sdata = sta->sdata; 31673651ee6SJohannes Berg unsigned long flags; 31793e5deb1SJohannes Berg int err = 0; 31873651ee6SJohannes Berg 31903e4497eSJohannes Berg /* 32003e4497eSJohannes Berg * Can't be a WARN_ON because it can be triggered through a race: 32103e4497eSJohannes Berg * something inserts a STA (on one CPU) without holding the RTNL 32203e4497eSJohannes Berg * and another CPU turns off the net device. 32303e4497eSJohannes Berg */ 32493e5deb1SJohannes Berg if (unlikely(!netif_running(sdata->dev))) { 32593e5deb1SJohannes Berg err = -ENETDOWN; 32693e5deb1SJohannes Berg goto out_free; 32793e5deb1SJohannes Berg } 32803e4497eSJohannes Berg 32917741cdcSJohannes Berg if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->dev->dev_addr) == 0 || 33017741cdcSJohannes Berg is_multicast_ether_addr(sta->sta.addr))) { 33193e5deb1SJohannes Berg err = -EINVAL; 33293e5deb1SJohannes Berg goto out_free; 33393e5deb1SJohannes Berg } 33444213b5eSJohannes Berg 335d0709a65SJohannes Berg spin_lock_irqsave(&local->sta_lock, flags); 33643ba7e95SJohannes Berg /* check if STA exists already */ 3374b7679a5SJohannes Berg if (sta_info_get(local, sta->sta.addr)) { 338d0709a65SJohannes Berg spin_unlock_irqrestore(&local->sta_lock, flags); 33993e5deb1SJohannes Berg err = -EEXIST; 34093e5deb1SJohannes Berg goto out_free; 34143ba7e95SJohannes Berg } 342f0706e82SJiri Benc list_add(&sta->list, &local->sta_list); 343f0706e82SJiri Benc local->num_sta++; 344f0706e82SJiri Benc sta_info_hash_add(local, sta); 34532bfd35dSJohannes Berg 346d0709a65SJohannes Berg /* notify driver */ 347d0709a65SJohannes Berg if (local->ops->sta_notify) { 34805c914feSJohannes Berg if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 3493e122be0SJohannes Berg sdata = container_of(sdata->bss, 3503e122be0SJohannes Berg struct ieee80211_sub_if_data, 3513e122be0SJohannes Berg u.ap); 35232bfd35dSJohannes Berg 35324487981SJohannes Berg drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, &sta->sta); 35432bfd35dSJohannes Berg } 355d0709a65SJohannes Berg 356f0706e82SJiri Benc #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 3570c68ae26SJohannes Berg printk(KERN_DEBUG "%s: Inserted STA %pM\n", 3580c68ae26SJohannes Berg wiphy_name(local->hw.wiphy), sta->sta.addr); 359f0706e82SJiri Benc #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 360f0706e82SJiri Benc 36173651ee6SJohannes Berg spin_unlock_irqrestore(&local->sta_lock, flags); 36273651ee6SJohannes Berg 363e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS 36493e5deb1SJohannes Berg /* 36593e5deb1SJohannes Berg * Debugfs entry adding might sleep, so schedule process 366e9f207f0SJiri Benc * context task for adding entry for STAs that do not yet 36793e5deb1SJohannes Berg * have one. 36893e5deb1SJohannes Berg * NOTE: due to auto-freeing semantics this may only be done 36993e5deb1SJohannes Berg * if the insertion is successful! 37093e5deb1SJohannes Berg */ 37149ec6fa2SJohannes Berg schedule_work(&local->sta_debugfs_add); 372e9f207f0SJiri Benc #endif 373e9f207f0SJiri Benc 37473651ee6SJohannes Berg if (ieee80211_vif_is_mesh(&sdata->vif)) 37573651ee6SJohannes Berg mesh_accept_plinks_update(sdata); 37673651ee6SJohannes Berg 37773651ee6SJohannes Berg return 0; 37893e5deb1SJohannes Berg out_free: 37993e5deb1SJohannes Berg BUG_ON(!err); 38093e5deb1SJohannes Berg __sta_info_free(local, sta); 38193e5deb1SJohannes Berg return err; 382f0706e82SJiri Benc } 383f0706e82SJiri Benc 384004c872eSJohannes Berg static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) 385004c872eSJohannes Berg { 386004c872eSJohannes Berg /* 387004c872eSJohannes Berg * This format has been mandated by the IEEE specifications, 388004c872eSJohannes Berg * so this line may not be changed to use the __set_bit() format. 389004c872eSJohannes Berg */ 390004c872eSJohannes Berg bss->tim[aid / 8] |= (1 << (aid % 8)); 391004c872eSJohannes Berg } 392004c872eSJohannes Berg 393004c872eSJohannes Berg static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) 394004c872eSJohannes Berg { 395004c872eSJohannes Berg /* 396004c872eSJohannes Berg * This format has been mandated by the IEEE specifications, 397004c872eSJohannes Berg * so this line may not be changed to use the __clear_bit() format. 398004c872eSJohannes Berg */ 399004c872eSJohannes Berg bss->tim[aid / 8] &= ~(1 << (aid % 8)); 400004c872eSJohannes Berg } 401004c872eSJohannes Berg 402004c872eSJohannes Berg static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss, 403004c872eSJohannes Berg struct sta_info *sta) 404004c872eSJohannes Berg { 4053e122be0SJohannes Berg BUG_ON(!bss); 4063e122be0SJohannes Berg 40717741cdcSJohannes Berg __bss_tim_set(bss, sta->sta.aid); 4083e122be0SJohannes Berg 409d0709a65SJohannes Berg if (sta->local->ops->set_tim) { 410d0709a65SJohannes Berg sta->local->tim_in_locked_section = true; 41124487981SJohannes Berg drv_set_tim(sta->local, &sta->sta, true); 412d0709a65SJohannes Berg sta->local->tim_in_locked_section = false; 413d0709a65SJohannes Berg } 414004c872eSJohannes Berg } 415004c872eSJohannes Berg 416004c872eSJohannes Berg void sta_info_set_tim_bit(struct sta_info *sta) 417004c872eSJohannes Berg { 418d0709a65SJohannes Berg unsigned long flags; 419004c872eSJohannes Berg 4203e122be0SJohannes Berg BUG_ON(!sta->sdata->bss); 4213e122be0SJohannes Berg 422d0709a65SJohannes Berg spin_lock_irqsave(&sta->local->sta_lock, flags); 423d0709a65SJohannes Berg __sta_info_set_tim_bit(sta->sdata->bss, sta); 424d0709a65SJohannes Berg spin_unlock_irqrestore(&sta->local->sta_lock, flags); 425004c872eSJohannes Berg } 426004c872eSJohannes Berg 427004c872eSJohannes Berg static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss, 428004c872eSJohannes Berg struct sta_info *sta) 429004c872eSJohannes Berg { 4303e122be0SJohannes Berg BUG_ON(!bss); 4313e122be0SJohannes Berg 43217741cdcSJohannes Berg __bss_tim_clear(bss, sta->sta.aid); 4333e122be0SJohannes Berg 434d0709a65SJohannes Berg if (sta->local->ops->set_tim) { 435d0709a65SJohannes Berg sta->local->tim_in_locked_section = true; 43624487981SJohannes Berg drv_set_tim(sta->local, &sta->sta, false); 437d0709a65SJohannes Berg sta->local->tim_in_locked_section = false; 438d0709a65SJohannes Berg } 439004c872eSJohannes Berg } 440004c872eSJohannes Berg 441004c872eSJohannes Berg void sta_info_clear_tim_bit(struct sta_info *sta) 442004c872eSJohannes Berg { 443d0709a65SJohannes Berg unsigned long flags; 444004c872eSJohannes Berg 4453e122be0SJohannes Berg BUG_ON(!sta->sdata->bss); 4463e122be0SJohannes Berg 447d0709a65SJohannes Berg spin_lock_irqsave(&sta->local->sta_lock, flags); 448d0709a65SJohannes Berg __sta_info_clear_tim_bit(sta->sdata->bss, sta); 449d0709a65SJohannes Berg spin_unlock_irqrestore(&sta->local->sta_lock, flags); 450004c872eSJohannes Berg } 451004c872eSJohannes Berg 45224723d1bSJohannes Berg static void __sta_info_unlink(struct sta_info **sta) 453d0709a65SJohannes Berg { 454d0709a65SJohannes Berg struct ieee80211_local *local = (*sta)->local; 455d0709a65SJohannes Berg struct ieee80211_sub_if_data *sdata = (*sta)->sdata; 456d0709a65SJohannes Berg /* 457d0709a65SJohannes Berg * pull caller's reference if we're already gone. 458d0709a65SJohannes Berg */ 459d0709a65SJohannes Berg if (sta_info_hash_del(local, *sta)) { 460d0709a65SJohannes Berg *sta = NULL; 461be8755e1SMichael Wu return; 462d0709a65SJohannes Berg } 463be8755e1SMichael Wu 4643b96766fSJohannes Berg if ((*sta)->key) { 4653b96766fSJohannes Berg ieee80211_key_free((*sta)->key); 4663b96766fSJohannes Berg WARN_ON((*sta)->key); 4673b96766fSJohannes Berg } 4683b96766fSJohannes Berg 4697d1559f1SJohannes Berg list_del(&(*sta)->list); 4707d1559f1SJohannes Berg 47107346f81SJohannes Berg if (test_and_clear_sta_flags(*sta, WLAN_STA_PS)) { 4723e122be0SJohannes Berg BUG_ON(!sdata->bss); 4733e122be0SJohannes Berg 4747d1559f1SJohannes Berg atomic_dec(&sdata->bss->num_sta_ps); 4757d1559f1SJohannes Berg __sta_info_clear_tim_bit(sdata->bss, *sta); 4767d1559f1SJohannes Berg } 4777d1559f1SJohannes Berg 4787d1559f1SJohannes Berg local->num_sta--; 4797d1559f1SJohannes Berg 4807d1559f1SJohannes Berg if (local->ops->sta_notify) { 48105c914feSJohannes Berg if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 4823e122be0SJohannes Berg sdata = container_of(sdata->bss, 4833e122be0SJohannes Berg struct ieee80211_sub_if_data, 4843e122be0SJohannes Berg u.ap); 4857d1559f1SJohannes Berg 48624487981SJohannes Berg drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE, 48724487981SJohannes Berg &(*sta)->sta); 4887d1559f1SJohannes Berg } 4897d1559f1SJohannes Berg 4907d1559f1SJohannes Berg if (ieee80211_vif_is_mesh(&sdata->vif)) { 4917d1559f1SJohannes Berg mesh_accept_plinks_update(sdata); 4927d1559f1SJohannes Berg #ifdef CONFIG_MAC80211_MESH 4937d1559f1SJohannes Berg del_timer(&(*sta)->plink_timer); 4947d1559f1SJohannes Berg #endif 4957d1559f1SJohannes Berg } 4967d1559f1SJohannes Berg 4977d1559f1SJohannes Berg #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 4980c68ae26SJohannes Berg printk(KERN_DEBUG "%s: Removed STA %pM\n", 4990c68ae26SJohannes Berg wiphy_name(local->hw.wiphy), (*sta)->sta.addr); 5007d1559f1SJohannes Berg #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 5017d1559f1SJohannes Berg 502d0709a65SJohannes Berg /* 5037d1559f1SJohannes Berg * Finally, pull caller's reference if the STA is pinned by the 504d0709a65SJohannes Berg * task that is adding the debugfs entries. In that case, we 505d0709a65SJohannes Berg * leave the STA "to be freed". 506d0709a65SJohannes Berg * 507d0709a65SJohannes Berg * The rules are not trivial, but not too complex either: 508d0709a65SJohannes Berg * (1) pin_status is only modified under the sta_lock 50949ec6fa2SJohannes Berg * (2) STAs may only be pinned under the RTNL so that 51049ec6fa2SJohannes Berg * sta_info_flush() is guaranteed to actually destroy 51149ec6fa2SJohannes Berg * all STAs that are active for a given interface, this 51249ec6fa2SJohannes Berg * is required for correctness because otherwise we 51349ec6fa2SJohannes Berg * could notify a driver that an interface is going 51449ec6fa2SJohannes Berg * away and only after that (!) notify it about a STA 51549ec6fa2SJohannes Berg * on that interface going away. 51649ec6fa2SJohannes Berg * (3) sta_info_debugfs_add_work() will set the status 517d0709a65SJohannes Berg * to PINNED when it found an item that needs a new 518d0709a65SJohannes Berg * debugfs directory created. In that case, that item 519d0709a65SJohannes Berg * must not be freed although all *RCU* users are done 520d0709a65SJohannes Berg * with it. Hence, we tell the caller of _unlink() 521d0709a65SJohannes Berg * that the item is already gone (as can happen when 522d0709a65SJohannes Berg * two tasks try to unlink/destroy at the same time) 52349ec6fa2SJohannes Berg * (4) We set the pin_status to DESTROY here when we 524d0709a65SJohannes Berg * find such an item. 52549ec6fa2SJohannes Berg * (5) sta_info_debugfs_add_work() will reset the pin_status 526d0709a65SJohannes Berg * from PINNED to NORMAL when it is done with the item, 527d0709a65SJohannes Berg * but will check for DESTROY before resetting it in 528d0709a65SJohannes Berg * which case it will free the item. 529d0709a65SJohannes Berg */ 530d0709a65SJohannes Berg if ((*sta)->pin_status == STA_INFO_PIN_STAT_PINNED) { 531d0709a65SJohannes Berg (*sta)->pin_status = STA_INFO_PIN_STAT_DESTROY; 532d0709a65SJohannes Berg *sta = NULL; 533d0709a65SJohannes Berg return; 534d0709a65SJohannes Berg } 535d0709a65SJohannes Berg } 536d0709a65SJohannes Berg 537d0709a65SJohannes Berg void sta_info_unlink(struct sta_info **sta) 538d0709a65SJohannes Berg { 539d0709a65SJohannes Berg struct ieee80211_local *local = (*sta)->local; 540d0709a65SJohannes Berg unsigned long flags; 541d0709a65SJohannes Berg 542d0709a65SJohannes Berg spin_lock_irqsave(&local->sta_lock, flags); 543d0709a65SJohannes Berg __sta_info_unlink(sta); 544d0709a65SJohannes Berg spin_unlock_irqrestore(&local->sta_lock, flags); 545d0709a65SJohannes Berg } 546f0706e82SJiri Benc 54757c4d7b4SJohannes Berg static int sta_info_buffer_expired(struct sta_info *sta, 548f0706e82SJiri Benc struct sk_buff *skb) 549f0706e82SJiri Benc { 550e039fa4aSJohannes Berg struct ieee80211_tx_info *info; 551f0706e82SJiri Benc int timeout; 552f0706e82SJiri Benc 553f0706e82SJiri Benc if (!skb) 554f0706e82SJiri Benc return 0; 555f0706e82SJiri Benc 556e039fa4aSJohannes Berg info = IEEE80211_SKB_CB(skb); 557f0706e82SJiri Benc 558f0706e82SJiri Benc /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ 55957c4d7b4SJohannes Berg timeout = (sta->listen_interval * 56057c4d7b4SJohannes Berg sta->sdata->vif.bss_conf.beacon_int * 56157c4d7b4SJohannes Berg 32 / 15625) * HZ; 562f0706e82SJiri Benc if (timeout < STA_TX_BUFFER_EXPIRE) 563f0706e82SJiri Benc timeout = STA_TX_BUFFER_EXPIRE; 564e039fa4aSJohannes Berg return time_after(jiffies, info->control.jiffies + timeout); 565f0706e82SJiri Benc } 566f0706e82SJiri Benc 567f0706e82SJiri Benc 568f0706e82SJiri Benc static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local, 569f0706e82SJiri Benc struct sta_info *sta) 570f0706e82SJiri Benc { 571f0706e82SJiri Benc unsigned long flags; 572f0706e82SJiri Benc struct sk_buff *skb; 573836341a7SJohannes Berg struct ieee80211_sub_if_data *sdata; 574f0706e82SJiri Benc 575f0706e82SJiri Benc if (skb_queue_empty(&sta->ps_tx_buf)) 576f0706e82SJiri Benc return; 577f0706e82SJiri Benc 578f0706e82SJiri Benc for (;;) { 579f0706e82SJiri Benc spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); 580f0706e82SJiri Benc skb = skb_peek(&sta->ps_tx_buf); 58157c4d7b4SJohannes Berg if (sta_info_buffer_expired(sta, skb)) 582f0706e82SJiri Benc skb = __skb_dequeue(&sta->ps_tx_buf); 583836341a7SJohannes Berg else 584f0706e82SJiri Benc skb = NULL; 585f0706e82SJiri Benc spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags); 586f0706e82SJiri Benc 587836341a7SJohannes Berg if (!skb) 588836341a7SJohannes Berg break; 589836341a7SJohannes Berg 590d0709a65SJohannes Berg sdata = sta->sdata; 591f0706e82SJiri Benc local->total_ps_buffered--; 592f4ea83ddSJohannes Berg #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 5930c68ae26SJohannes Berg printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n", 5940c68ae26SJohannes Berg sta->sta.addr); 595f4ea83ddSJohannes Berg #endif 596f0706e82SJiri Benc dev_kfree_skb(skb); 597836341a7SJohannes Berg 598004c872eSJohannes Berg if (skb_queue_empty(&sta->ps_tx_buf)) 599004c872eSJohannes Berg sta_info_clear_tim_bit(sta); 600f0706e82SJiri Benc } 601f0706e82SJiri Benc } 602f0706e82SJiri Benc 603f0706e82SJiri Benc 604f0706e82SJiri Benc static void sta_info_cleanup(unsigned long data) 605f0706e82SJiri Benc { 606f0706e82SJiri Benc struct ieee80211_local *local = (struct ieee80211_local *) data; 607f0706e82SJiri Benc struct sta_info *sta; 608f0706e82SJiri Benc 609d0709a65SJohannes Berg rcu_read_lock(); 610d0709a65SJohannes Berg list_for_each_entry_rcu(sta, &local->sta_list, list) 611f0706e82SJiri Benc sta_info_cleanup_expire_buffered(local, sta); 612d0709a65SJohannes Berg rcu_read_unlock(); 613f0706e82SJiri Benc 614*5bb644a0SJohannes Berg if (local->quiescing) 615*5bb644a0SJohannes Berg return; 616*5bb644a0SJohannes Berg 6170d174406SJohannes Berg local->sta_cleanup.expires = 6180d174406SJohannes Berg round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); 619f0706e82SJiri Benc add_timer(&local->sta_cleanup); 620f0706e82SJiri Benc } 621f0706e82SJiri Benc 622e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS 6234d6141c3SJiri Slaby /* 6244d6141c3SJiri Slaby * See comment in __sta_info_unlink, 6254d6141c3SJiri Slaby * caller must hold local->sta_lock. 6264d6141c3SJiri Slaby */ 6274d6141c3SJiri Slaby static void __sta_info_pin(struct sta_info *sta) 6284d6141c3SJiri Slaby { 6294d6141c3SJiri Slaby WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_NORMAL); 6304d6141c3SJiri Slaby sta->pin_status = STA_INFO_PIN_STAT_PINNED; 6314d6141c3SJiri Slaby } 6324d6141c3SJiri Slaby 6334d6141c3SJiri Slaby /* 6344d6141c3SJiri Slaby * See comment in __sta_info_unlink, returns sta if it 6354d6141c3SJiri Slaby * needs to be destroyed. 6364d6141c3SJiri Slaby */ 6374d6141c3SJiri Slaby static struct sta_info *__sta_info_unpin(struct sta_info *sta) 6384d6141c3SJiri Slaby { 6394d6141c3SJiri Slaby struct sta_info *ret = NULL; 6404d6141c3SJiri Slaby unsigned long flags; 6414d6141c3SJiri Slaby 6424d6141c3SJiri Slaby spin_lock_irqsave(&sta->local->sta_lock, flags); 6434d6141c3SJiri Slaby WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_DESTROY && 6444d6141c3SJiri Slaby sta->pin_status != STA_INFO_PIN_STAT_PINNED); 6454d6141c3SJiri Slaby if (sta->pin_status == STA_INFO_PIN_STAT_DESTROY) 6464d6141c3SJiri Slaby ret = sta; 6474d6141c3SJiri Slaby sta->pin_status = STA_INFO_PIN_STAT_NORMAL; 6484d6141c3SJiri Slaby spin_unlock_irqrestore(&sta->local->sta_lock, flags); 6494d6141c3SJiri Slaby 6504d6141c3SJiri Slaby return ret; 6514d6141c3SJiri Slaby } 6524d6141c3SJiri Slaby 653d0709a65SJohannes Berg static void sta_info_debugfs_add_work(struct work_struct *work) 654e9f207f0SJiri Benc { 655e9f207f0SJiri Benc struct ieee80211_local *local = 656e9f207f0SJiri Benc container_of(work, struct ieee80211_local, sta_debugfs_add); 657e9f207f0SJiri Benc struct sta_info *sta, *tmp; 658d0709a65SJohannes Berg unsigned long flags; 659e9f207f0SJiri Benc 66049ec6fa2SJohannes Berg /* We need to keep the RTNL across the whole pinned status. */ 66149ec6fa2SJohannes Berg rtnl_lock(); 662e9f207f0SJiri Benc while (1) { 663e9f207f0SJiri Benc sta = NULL; 664d0709a65SJohannes Berg 665d0709a65SJohannes Berg spin_lock_irqsave(&local->sta_lock, flags); 666e9f207f0SJiri Benc list_for_each_entry(tmp, &local->sta_list, list) { 66763044e9fSJohannes Berg /* 66863044e9fSJohannes Berg * debugfs.add_has_run will be set by 66963044e9fSJohannes Berg * ieee80211_sta_debugfs_add regardless 67063044e9fSJohannes Berg * of what else it does. 67163044e9fSJohannes Berg */ 67263044e9fSJohannes Berg if (!tmp->debugfs.add_has_run) { 673e9f207f0SJiri Benc sta = tmp; 674d0709a65SJohannes Berg __sta_info_pin(sta); 675e9f207f0SJiri Benc break; 676e9f207f0SJiri Benc } 677e9f207f0SJiri Benc } 678d0709a65SJohannes Berg spin_unlock_irqrestore(&local->sta_lock, flags); 679e9f207f0SJiri Benc 680e9f207f0SJiri Benc if (!sta) 681e9f207f0SJiri Benc break; 682e9f207f0SJiri Benc 683e9f207f0SJiri Benc ieee80211_sta_debugfs_add(sta); 684e9f207f0SJiri Benc rate_control_add_sta_debugfs(sta); 685d0709a65SJohannes Berg 686d0709a65SJohannes Berg sta = __sta_info_unpin(sta); 687d0709a65SJohannes Berg sta_info_destroy(sta); 688e9f207f0SJiri Benc } 68949ec6fa2SJohannes Berg rtnl_unlock(); 690e9f207f0SJiri Benc } 691e9f207f0SJiri Benc #endif 692e9f207f0SJiri Benc 693f0706e82SJiri Benc void sta_info_init(struct ieee80211_local *local) 694f0706e82SJiri Benc { 695d0709a65SJohannes Berg spin_lock_init(&local->sta_lock); 696f0706e82SJiri Benc INIT_LIST_HEAD(&local->sta_list); 697f0706e82SJiri Benc 698b24b8a24SPavel Emelyanov setup_timer(&local->sta_cleanup, sta_info_cleanup, 699b24b8a24SPavel Emelyanov (unsigned long)local); 7000d174406SJohannes Berg local->sta_cleanup.expires = 7010d174406SJohannes Berg round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); 702e9f207f0SJiri Benc 703e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS 704d0709a65SJohannes Berg INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_work); 705e9f207f0SJiri Benc #endif 706f0706e82SJiri Benc } 707f0706e82SJiri Benc 708f0706e82SJiri Benc int sta_info_start(struct ieee80211_local *local) 709f0706e82SJiri Benc { 710f0706e82SJiri Benc add_timer(&local->sta_cleanup); 711f0706e82SJiri Benc return 0; 712f0706e82SJiri Benc } 713f0706e82SJiri Benc 714f0706e82SJiri Benc void sta_info_stop(struct ieee80211_local *local) 715f0706e82SJiri Benc { 716f0706e82SJiri Benc del_timer(&local->sta_cleanup); 71749ec6fa2SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS 71849ec6fa2SJohannes Berg /* 71949ec6fa2SJohannes Berg * Make sure the debugfs adding work isn't pending after this 72049ec6fa2SJohannes Berg * because we're about to be destroyed. It doesn't matter 72149ec6fa2SJohannes Berg * whether it ran or not since we're going to flush all STAs 72249ec6fa2SJohannes Berg * anyway. 72349ec6fa2SJohannes Berg */ 72449ec6fa2SJohannes Berg cancel_work_sync(&local->sta_debugfs_add); 72549ec6fa2SJohannes Berg #endif 726dc6676b7SJohannes Berg 727be8755e1SMichael Wu sta_info_flush(local, NULL); 728f0706e82SJiri Benc } 729f0706e82SJiri Benc 730f0706e82SJiri Benc /** 731f0706e82SJiri Benc * sta_info_flush - flush matching STA entries from the STA table 73244213b5eSJohannes Berg * 73344213b5eSJohannes Berg * Returns the number of removed STA entries. 73444213b5eSJohannes Berg * 735f0706e82SJiri Benc * @local: local interface data 736d0709a65SJohannes Berg * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs 737f0706e82SJiri Benc */ 73844213b5eSJohannes Berg int sta_info_flush(struct ieee80211_local *local, 739d0709a65SJohannes Berg struct ieee80211_sub_if_data *sdata) 740f0706e82SJiri Benc { 741f0706e82SJiri Benc struct sta_info *sta, *tmp; 742be8755e1SMichael Wu LIST_HEAD(tmp_list); 74344213b5eSJohannes Berg int ret = 0; 744d0709a65SJohannes Berg unsigned long flags; 745f0706e82SJiri Benc 746d0709a65SJohannes Berg might_sleep(); 747d0709a65SJohannes Berg 748d0709a65SJohannes Berg spin_lock_irqsave(&local->sta_lock, flags); 749d0709a65SJohannes Berg list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 750d0709a65SJohannes Berg if (!sdata || sdata == sta->sdata) { 751d0709a65SJohannes Berg __sta_info_unlink(&sta); 75244213b5eSJohannes Berg if (sta) { 753be8755e1SMichael Wu list_add_tail(&sta->list, &tmp_list); 75444213b5eSJohannes Berg ret++; 75544213b5eSJohannes Berg } 756be8755e1SMichael Wu } 757be8755e1SMichael Wu } 758d0709a65SJohannes Berg spin_unlock_irqrestore(&local->sta_lock, flags); 759d0709a65SJohannes Berg 760d0709a65SJohannes Berg list_for_each_entry_safe(sta, tmp, &tmp_list, list) 761d0709a65SJohannes Berg sta_info_destroy(sta); 76244213b5eSJohannes Berg 76344213b5eSJohannes Berg return ret; 764f0706e82SJiri Benc } 765dc6676b7SJohannes Berg 76624723d1bSJohannes Berg void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 76724723d1bSJohannes Berg unsigned long exp_time) 76824723d1bSJohannes Berg { 76924723d1bSJohannes Berg struct ieee80211_local *local = sdata->local; 77024723d1bSJohannes Berg struct sta_info *sta, *tmp; 77124723d1bSJohannes Berg LIST_HEAD(tmp_list); 77224723d1bSJohannes Berg unsigned long flags; 77324723d1bSJohannes Berg 77424723d1bSJohannes Berg spin_lock_irqsave(&local->sta_lock, flags); 77524723d1bSJohannes Berg list_for_each_entry_safe(sta, tmp, &local->sta_list, list) 77624723d1bSJohannes Berg if (time_after(jiffies, sta->last_rx + exp_time)) { 77724723d1bSJohannes Berg #ifdef CONFIG_MAC80211_IBSS_DEBUG 7780c68ae26SJohannes Berg printk(KERN_DEBUG "%s: expiring inactive STA %pM\n", 7790c68ae26SJohannes Berg sdata->dev->name, sta->sta.addr); 78024723d1bSJohannes Berg #endif 78124723d1bSJohannes Berg __sta_info_unlink(&sta); 78224723d1bSJohannes Berg if (sta) 78324723d1bSJohannes Berg list_add(&sta->list, &tmp_list); 78424723d1bSJohannes Berg } 78524723d1bSJohannes Berg spin_unlock_irqrestore(&local->sta_lock, flags); 78624723d1bSJohannes Berg 78724723d1bSJohannes Berg list_for_each_entry_safe(sta, tmp, &tmp_list, list) 78824723d1bSJohannes Berg sta_info_destroy(sta); 78924723d1bSJohannes Berg } 79017741cdcSJohannes Berg 79117741cdcSJohannes Berg struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_hw *hw, 79217741cdcSJohannes Berg const u8 *addr) 79317741cdcSJohannes Berg { 7944b7679a5SJohannes Berg struct sta_info *sta = sta_info_get(hw_to_local(hw), addr); 79517741cdcSJohannes Berg 79617741cdcSJohannes Berg if (!sta) 79717741cdcSJohannes Berg return NULL; 79817741cdcSJohannes Berg return &sta->sta; 79917741cdcSJohannes Berg } 80017741cdcSJohannes Berg EXPORT_SYMBOL(ieee80211_find_sta); 801