sta_info.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  4. *
  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.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/types.h>
  13. #include <linux/slab.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/if_arp.h>
  16. #include <linux/timer.h>
  17. #include <linux/rtnetlink.h>
  18. #include <net/mac80211.h>
  19. #include "ieee80211_i.h"
  20. #include "ieee80211_rate.h"
  21. #include "sta_info.h"
  22. #include "debugfs_sta.h"
  23. #include "mesh.h"
  24. /**
  25. * DOC: STA information lifetime rules
  26. *
  27. * STA info structures (&struct sta_info) are managed in a hash table
  28. * for faster lookup and a list for iteration. They are managed using
  29. * RCU, i.e. access to the list and hash table is protected by RCU.
  30. *
  31. * Upon allocating a STA info structure with sta_info_alloc(), the caller owns
  32. * that structure. It must then either destroy it using sta_info_destroy()
  33. * (which is pretty useless) or insert it into the hash table using
  34. * sta_info_insert() which demotes the reference from ownership to a regular
  35. * RCU-protected reference; if the function is called without protection by an
  36. * RCU critical section the reference is instantly invalidated.
  37. *
  38. * Because there are debugfs entries for each station, and adding those
  39. * must be able to sleep, it is also possible to "pin" a station entry,
  40. * that means it can be removed from the hash table but not be freed.
  41. * See the comment in __sta_info_unlink() for more information.
  42. *
  43. * In order to remove a STA info structure, the caller needs to first
  44. * unlink it (sta_info_unlink()) from the list and hash tables and
  45. * then wait for an RCU synchronisation before it can be freed. Due to
  46. * the pinning and the possibility of multiple callers trying to remove
  47. * the same STA info at the same time, sta_info_unlink() can clear the
  48. * STA info pointer it is passed to indicate that the STA info is owned
  49. * by somebody else now.
  50. *
  51. * If sta_info_unlink() did not clear the pointer then the caller owns
  52. * the STA info structure now and is responsible of destroying it with
  53. * a call to sta_info_destroy(), not before RCU synchronisation, of
  54. * course. Note that sta_info_destroy() must be protected by the RTNL.
  55. *
  56. * In all other cases, there is no concept of ownership on a STA entry,
  57. * each structure is owned by the global hash table/list until it is
  58. * removed. All users of the structure need to be RCU protected so that
  59. * the structure won't be freed before they are done using it.
  60. */
  61. /* Caller must hold local->sta_lock */
  62. static int sta_info_hash_del(struct ieee80211_local *local,
  63. struct sta_info *sta)
  64. {
  65. struct sta_info *s;
  66. s = local->sta_hash[STA_HASH(sta->addr)];
  67. if (!s)
  68. return -ENOENT;
  69. if (s == sta) {
  70. rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)],
  71. s->hnext);
  72. return 0;
  73. }
  74. while (s->hnext && s->hnext != sta)
  75. s = s->hnext;
  76. if (s->hnext) {
  77. rcu_assign_pointer(s->hnext, sta->hnext);
  78. return 0;
  79. }
  80. return -ENOENT;
  81. }
  82. /* protected by RCU */
  83. static struct sta_info *__sta_info_find(struct ieee80211_local *local,
  84. u8 *addr)
  85. {
  86. struct sta_info *sta;
  87. sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]);
  88. while (sta) {
  89. if (compare_ether_addr(sta->addr, addr) == 0)
  90. break;
  91. sta = rcu_dereference(sta->hnext);
  92. }
  93. return sta;
  94. }
  95. struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
  96. {
  97. return __sta_info_find(local, addr);
  98. }
  99. EXPORT_SYMBOL(sta_info_get);
  100. struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
  101. struct net_device *dev)
  102. {
  103. struct sta_info *sta;
  104. int i = 0;
  105. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  106. if (dev && dev != sta->sdata->dev)
  107. continue;
  108. if (i < idx) {
  109. ++i;
  110. continue;
  111. }
  112. return sta;
  113. }
  114. return NULL;
  115. }
  116. void sta_info_destroy(struct sta_info *sta)
  117. {
  118. struct ieee80211_local *local;
  119. struct sk_buff *skb;
  120. int i;
  121. DECLARE_MAC_BUF(mbuf);
  122. ASSERT_RTNL();
  123. might_sleep();
  124. if (!sta)
  125. return;
  126. local = sta->local;
  127. rate_control_remove_sta_debugfs(sta);
  128. ieee80211_sta_debugfs_remove(sta);
  129. #ifdef CONFIG_MAC80211_MESH
  130. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  131. mesh_plink_deactivate(sta);
  132. #endif
  133. /*
  134. * NOTE: This will call synchronize_rcu() internally to
  135. * make sure no key references can be in use. We rely on
  136. * that here for the mesh code!
  137. */
  138. ieee80211_key_free(sta->key);
  139. WARN_ON(sta->key);
  140. #ifdef CONFIG_MAC80211_MESH
  141. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  142. del_timer_sync(&sta->plink_timer);
  143. #endif
  144. while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
  145. local->total_ps_buffered--;
  146. dev_kfree_skb_any(skb);
  147. }
  148. while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL)
  149. dev_kfree_skb_any(skb);
  150. for (i = 0; i < STA_TID_NUM; i++) {
  151. spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
  152. if (sta->ampdu_mlme.tid_rx[i])
  153. del_timer_sync(&sta->ampdu_mlme.tid_rx[i]->session_timer);
  154. spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
  155. spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
  156. if (sta->ampdu_mlme.tid_tx[i])
  157. del_timer_sync(&sta->ampdu_mlme.tid_tx[i]->addba_resp_timer);
  158. spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
  159. }
  160. rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
  161. rate_control_put(sta->rate_ctrl);
  162. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  163. printk(KERN_DEBUG "%s: Destroyed STA %s\n",
  164. wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
  165. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  166. kfree(sta);
  167. }
  168. /* Caller must hold local->sta_lock */
  169. static void sta_info_hash_add(struct ieee80211_local *local,
  170. struct sta_info *sta)
  171. {
  172. sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
  173. rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta);
  174. }
  175. struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
  176. u8 *addr, gfp_t gfp)
  177. {
  178. struct ieee80211_local *local = sdata->local;
  179. struct sta_info *sta;
  180. int i;
  181. DECLARE_MAC_BUF(mbuf);
  182. sta = kzalloc(sizeof(*sta), gfp);
  183. if (!sta)
  184. return NULL;
  185. memcpy(sta->addr, addr, ETH_ALEN);
  186. sta->local = local;
  187. sta->sdata = sdata;
  188. sta->rate_ctrl = rate_control_get(local->rate_ctrl);
  189. sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
  190. gfp);
  191. if (!sta->rate_ctrl_priv) {
  192. rate_control_put(sta->rate_ctrl);
  193. kfree(sta);
  194. return NULL;
  195. }
  196. spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
  197. spin_lock_init(&sta->ampdu_mlme.ampdu_tx);
  198. for (i = 0; i < STA_TID_NUM; i++) {
  199. /* timer_to_tid must be initialized with identity mapping to
  200. * enable session_timer's data differentiation. refer to
  201. * sta_rx_agg_session_timer_expired for useage */
  202. sta->timer_to_tid[i] = i;
  203. /* tid to tx queue: initialize according to HW (0 is valid) */
  204. sta->tid_to_tx_q[i] = local->hw.queues;
  205. /* rx */
  206. sta->ampdu_mlme.tid_state_rx[i] = HT_AGG_STATE_IDLE;
  207. sta->ampdu_mlme.tid_rx[i] = NULL;
  208. /* tx */
  209. sta->ampdu_mlme.tid_state_tx[i] = HT_AGG_STATE_IDLE;
  210. sta->ampdu_mlme.tid_tx[i] = NULL;
  211. sta->ampdu_mlme.addba_req_num[i] = 0;
  212. }
  213. skb_queue_head_init(&sta->ps_tx_buf);
  214. skb_queue_head_init(&sta->tx_filtered);
  215. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  216. printk(KERN_DEBUG "%s: Allocated STA %s\n",
  217. wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
  218. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  219. #ifdef CONFIG_MAC80211_MESH
  220. sta->plink_state = PLINK_LISTEN;
  221. spin_lock_init(&sta->plink_lock);
  222. init_timer(&sta->plink_timer);
  223. #endif
  224. return sta;
  225. }
  226. int sta_info_insert(struct sta_info *sta)
  227. {
  228. struct ieee80211_local *local = sta->local;
  229. struct ieee80211_sub_if_data *sdata = sta->sdata;
  230. unsigned long flags;
  231. DECLARE_MAC_BUF(mac);
  232. /*
  233. * Can't be a WARN_ON because it can be triggered through a race:
  234. * something inserts a STA (on one CPU) without holding the RTNL
  235. * and another CPU turns off the net device.
  236. */
  237. if (unlikely(!netif_running(sdata->dev)))
  238. return -ENETDOWN;
  239. if (WARN_ON(compare_ether_addr(sta->addr, sdata->dev->dev_addr) == 0))
  240. return -EINVAL;
  241. if (WARN_ON(is_multicast_ether_addr(sta->addr)))
  242. return -EINVAL;
  243. spin_lock_irqsave(&local->sta_lock, flags);
  244. /* check if STA exists already */
  245. if (__sta_info_find(local, sta->addr)) {
  246. spin_unlock_irqrestore(&local->sta_lock, flags);
  247. return -EEXIST;
  248. }
  249. list_add(&sta->list, &local->sta_list);
  250. local->num_sta++;
  251. sta_info_hash_add(local, sta);
  252. /* notify driver */
  253. if (local->ops->sta_notify) {
  254. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
  255. sdata = sdata->u.vlan.ap;
  256. local->ops->sta_notify(local_to_hw(local), &sdata->vif,
  257. STA_NOTIFY_ADD, sta->addr);
  258. }
  259. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  260. printk(KERN_DEBUG "%s: Inserted STA %s\n",
  261. wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
  262. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  263. spin_unlock_irqrestore(&local->sta_lock, flags);
  264. #ifdef CONFIG_MAC80211_DEBUGFS
  265. /* debugfs entry adding might sleep, so schedule process
  266. * context task for adding entry for STAs that do not yet
  267. * have one. */
  268. queue_work(local->hw.workqueue, &local->sta_debugfs_add);
  269. #endif
  270. if (ieee80211_vif_is_mesh(&sdata->vif))
  271. mesh_accept_plinks_update(sdata);
  272. return 0;
  273. }
  274. static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
  275. {
  276. /*
  277. * This format has been mandated by the IEEE specifications,
  278. * so this line may not be changed to use the __set_bit() format.
  279. */
  280. bss->tim[aid / 8] |= (1 << (aid % 8));
  281. }
  282. static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
  283. {
  284. /*
  285. * This format has been mandated by the IEEE specifications,
  286. * so this line may not be changed to use the __clear_bit() format.
  287. */
  288. bss->tim[aid / 8] &= ~(1 << (aid % 8));
  289. }
  290. static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
  291. struct sta_info *sta)
  292. {
  293. if (bss)
  294. __bss_tim_set(bss, sta->aid);
  295. if (sta->local->ops->set_tim) {
  296. sta->local->tim_in_locked_section = true;
  297. sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1);
  298. sta->local->tim_in_locked_section = false;
  299. }
  300. }
  301. void sta_info_set_tim_bit(struct sta_info *sta)
  302. {
  303. unsigned long flags;
  304. spin_lock_irqsave(&sta->local->sta_lock, flags);
  305. __sta_info_set_tim_bit(sta->sdata->bss, sta);
  306. spin_unlock_irqrestore(&sta->local->sta_lock, flags);
  307. }
  308. static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
  309. struct sta_info *sta)
  310. {
  311. if (bss)
  312. __bss_tim_clear(bss, sta->aid);
  313. if (sta->local->ops->set_tim) {
  314. sta->local->tim_in_locked_section = true;
  315. sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0);
  316. sta->local->tim_in_locked_section = false;
  317. }
  318. }
  319. void sta_info_clear_tim_bit(struct sta_info *sta)
  320. {
  321. unsigned long flags;
  322. spin_lock_irqsave(&sta->local->sta_lock, flags);
  323. __sta_info_clear_tim_bit(sta->sdata->bss, sta);
  324. spin_unlock_irqrestore(&sta->local->sta_lock, flags);
  325. }
  326. /*
  327. * See comment in __sta_info_unlink,
  328. * caller must hold local->sta_lock.
  329. */
  330. static void __sta_info_pin(struct sta_info *sta)
  331. {
  332. WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_NORMAL);
  333. sta->pin_status = STA_INFO_PIN_STAT_PINNED;
  334. }
  335. /*
  336. * See comment in __sta_info_unlink, returns sta if it
  337. * needs to be destroyed.
  338. */
  339. static struct sta_info *__sta_info_unpin(struct sta_info *sta)
  340. {
  341. struct sta_info *ret = NULL;
  342. unsigned long flags;
  343. spin_lock_irqsave(&sta->local->sta_lock, flags);
  344. WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_DESTROY &&
  345. sta->pin_status != STA_INFO_PIN_STAT_PINNED);
  346. if (sta->pin_status == STA_INFO_PIN_STAT_DESTROY)
  347. ret = sta;
  348. sta->pin_status = STA_INFO_PIN_STAT_NORMAL;
  349. spin_unlock_irqrestore(&sta->local->sta_lock, flags);
  350. return ret;
  351. }
  352. static void __sta_info_unlink(struct sta_info **sta)
  353. {
  354. struct ieee80211_local *local = (*sta)->local;
  355. struct ieee80211_sub_if_data *sdata = (*sta)->sdata;
  356. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  357. DECLARE_MAC_BUF(mbuf);
  358. #endif
  359. /*
  360. * pull caller's reference if we're already gone.
  361. */
  362. if (sta_info_hash_del(local, *sta)) {
  363. *sta = NULL;
  364. return;
  365. }
  366. /*
  367. * Also pull caller's reference if the STA is pinned by the
  368. * task that is adding the debugfs entries. In that case, we
  369. * leave the STA "to be freed".
  370. *
  371. * The rules are not trivial, but not too complex either:
  372. * (1) pin_status is only modified under the sta_lock
  373. * (2) sta_info_debugfs_add_work() will set the status
  374. * to PINNED when it found an item that needs a new
  375. * debugfs directory created. In that case, that item
  376. * must not be freed although all *RCU* users are done
  377. * with it. Hence, we tell the caller of _unlink()
  378. * that the item is already gone (as can happen when
  379. * two tasks try to unlink/destroy at the same time)
  380. * (3) We set the pin_status to DESTROY here when we
  381. * find such an item.
  382. * (4) sta_info_debugfs_add_work() will reset the pin_status
  383. * from PINNED to NORMAL when it is done with the item,
  384. * but will check for DESTROY before resetting it in
  385. * which case it will free the item.
  386. */
  387. if ((*sta)->pin_status == STA_INFO_PIN_STAT_PINNED) {
  388. (*sta)->pin_status = STA_INFO_PIN_STAT_DESTROY;
  389. *sta = NULL;
  390. return;
  391. }
  392. list_del(&(*sta)->list);
  393. if ((*sta)->flags & WLAN_STA_PS) {
  394. (*sta)->flags &= ~WLAN_STA_PS;
  395. if (sdata->bss)
  396. atomic_dec(&sdata->bss->num_sta_ps);
  397. __sta_info_clear_tim_bit(sdata->bss, *sta);
  398. }
  399. local->num_sta--;
  400. if (local->ops->sta_notify) {
  401. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
  402. sdata = sdata->u.vlan.ap;
  403. local->ops->sta_notify(local_to_hw(local), &sdata->vif,
  404. STA_NOTIFY_REMOVE, (*sta)->addr);
  405. }
  406. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  407. mesh_accept_plinks_update(sdata);
  408. #ifdef CONFIG_MAC80211_MESH
  409. del_timer(&(*sta)->plink_timer);
  410. #endif
  411. }
  412. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  413. printk(KERN_DEBUG "%s: Removed STA %s\n",
  414. wiphy_name(local->hw.wiphy), print_mac(mbuf, (*sta)->addr));
  415. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  416. }
  417. void sta_info_unlink(struct sta_info **sta)
  418. {
  419. struct ieee80211_local *local = (*sta)->local;
  420. unsigned long flags;
  421. spin_lock_irqsave(&local->sta_lock, flags);
  422. __sta_info_unlink(sta);
  423. spin_unlock_irqrestore(&local->sta_lock, flags);
  424. }
  425. static inline int sta_info_buffer_expired(struct ieee80211_local *local,
  426. struct sta_info *sta,
  427. struct sk_buff *skb)
  428. {
  429. struct ieee80211_tx_packet_data *pkt_data;
  430. int timeout;
  431. if (!skb)
  432. return 0;
  433. pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
  434. /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
  435. timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
  436. 15625) * HZ;
  437. if (timeout < STA_TX_BUFFER_EXPIRE)
  438. timeout = STA_TX_BUFFER_EXPIRE;
  439. return time_after(jiffies, pkt_data->jiffies + timeout);
  440. }
  441. static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
  442. struct sta_info *sta)
  443. {
  444. unsigned long flags;
  445. struct sk_buff *skb;
  446. struct ieee80211_sub_if_data *sdata;
  447. DECLARE_MAC_BUF(mac);
  448. if (skb_queue_empty(&sta->ps_tx_buf))
  449. return;
  450. for (;;) {
  451. spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
  452. skb = skb_peek(&sta->ps_tx_buf);
  453. if (sta_info_buffer_expired(local, sta, skb))
  454. skb = __skb_dequeue(&sta->ps_tx_buf);
  455. else
  456. skb = NULL;
  457. spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
  458. if (!skb)
  459. break;
  460. sdata = sta->sdata;
  461. local->total_ps_buffered--;
  462. printk(KERN_DEBUG "Buffered frame expired (STA "
  463. "%s)\n", print_mac(mac, sta->addr));
  464. dev_kfree_skb(skb);
  465. if (skb_queue_empty(&sta->ps_tx_buf))
  466. sta_info_clear_tim_bit(sta);
  467. }
  468. }
  469. static void sta_info_cleanup(unsigned long data)
  470. {
  471. struct ieee80211_local *local = (struct ieee80211_local *) data;
  472. struct sta_info *sta;
  473. rcu_read_lock();
  474. list_for_each_entry_rcu(sta, &local->sta_list, list)
  475. sta_info_cleanup_expire_buffered(local, sta);
  476. rcu_read_unlock();
  477. local->sta_cleanup.expires =
  478. round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
  479. add_timer(&local->sta_cleanup);
  480. }
  481. #ifdef CONFIG_MAC80211_DEBUGFS
  482. static void sta_info_debugfs_add_work(struct work_struct *work)
  483. {
  484. struct ieee80211_local *local =
  485. container_of(work, struct ieee80211_local, sta_debugfs_add);
  486. struct sta_info *sta, *tmp;
  487. unsigned long flags;
  488. while (1) {
  489. sta = NULL;
  490. spin_lock_irqsave(&local->sta_lock, flags);
  491. list_for_each_entry(tmp, &local->sta_list, list) {
  492. if (!tmp->debugfs.dir) {
  493. sta = tmp;
  494. __sta_info_pin(sta);
  495. break;
  496. }
  497. }
  498. spin_unlock_irqrestore(&local->sta_lock, flags);
  499. if (!sta)
  500. break;
  501. ieee80211_sta_debugfs_add(sta);
  502. rate_control_add_sta_debugfs(sta);
  503. sta = __sta_info_unpin(sta);
  504. if (sta) {
  505. synchronize_rcu();
  506. sta_info_destroy(sta);
  507. }
  508. }
  509. }
  510. #endif
  511. void sta_info_init(struct ieee80211_local *local)
  512. {
  513. spin_lock_init(&local->sta_lock);
  514. INIT_LIST_HEAD(&local->sta_list);
  515. setup_timer(&local->sta_cleanup, sta_info_cleanup,
  516. (unsigned long)local);
  517. local->sta_cleanup.expires =
  518. round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
  519. #ifdef CONFIG_MAC80211_DEBUGFS
  520. INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_work);
  521. #endif
  522. }
  523. int sta_info_start(struct ieee80211_local *local)
  524. {
  525. add_timer(&local->sta_cleanup);
  526. return 0;
  527. }
  528. void sta_info_stop(struct ieee80211_local *local)
  529. {
  530. del_timer(&local->sta_cleanup);
  531. sta_info_flush(local, NULL);
  532. }
  533. /**
  534. * sta_info_flush - flush matching STA entries from the STA table
  535. *
  536. * Returns the number of removed STA entries.
  537. *
  538. * @local: local interface data
  539. * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
  540. */
  541. int sta_info_flush(struct ieee80211_local *local,
  542. struct ieee80211_sub_if_data *sdata)
  543. {
  544. struct sta_info *sta, *tmp;
  545. LIST_HEAD(tmp_list);
  546. int ret = 0;
  547. unsigned long flags;
  548. might_sleep();
  549. spin_lock_irqsave(&local->sta_lock, flags);
  550. list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
  551. if (!sdata || sdata == sta->sdata) {
  552. __sta_info_unlink(&sta);
  553. if (sta) {
  554. list_add_tail(&sta->list, &tmp_list);
  555. ret++;
  556. }
  557. }
  558. }
  559. spin_unlock_irqrestore(&local->sta_lock, flags);
  560. synchronize_rcu();
  561. list_for_each_entry_safe(sta, tmp, &tmp_list, list)
  562. sta_info_destroy(sta);
  563. return ret;
  564. }