sta_info.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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 = sta->local;
  119. struct sk_buff *skb;
  120. int i;
  121. DECLARE_MAC_BUF(mbuf);
  122. if (!sta)
  123. return;
  124. ASSERT_RTNL();
  125. might_sleep();
  126. rate_control_remove_sta_debugfs(sta);
  127. ieee80211_sta_debugfs_remove(sta);
  128. #ifdef CONFIG_MAC80211_MESH
  129. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  130. mesh_plink_deactivate(sta);
  131. #endif
  132. /*
  133. * NOTE: This will call synchronize_rcu() internally to
  134. * make sure no key references can be in use. We rely on
  135. * that here for the mesh code!
  136. */
  137. ieee80211_key_free(sta->key);
  138. WARN_ON(sta->key);
  139. #ifdef CONFIG_MAC80211_MESH
  140. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  141. del_timer_sync(&sta->plink_timer);
  142. #endif
  143. while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
  144. local->total_ps_buffered--;
  145. dev_kfree_skb_any(skb);
  146. }
  147. while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL)
  148. dev_kfree_skb_any(skb);
  149. for (i = 0; i < STA_TID_NUM; i++) {
  150. spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
  151. if (sta->ampdu_mlme.tid_rx[i])
  152. del_timer_sync(&sta->ampdu_mlme.tid_rx[i]->session_timer);
  153. spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
  154. spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
  155. if (sta->ampdu_mlme.tid_tx[i])
  156. del_timer_sync(&sta->ampdu_mlme.tid_tx[i]->addba_resp_timer);
  157. spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
  158. }
  159. rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
  160. rate_control_put(sta->rate_ctrl);
  161. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  162. printk(KERN_DEBUG "%s: Destroyed STA %s\n",
  163. wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
  164. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  165. kfree(sta);
  166. }
  167. /* Caller must hold local->sta_lock */
  168. static void sta_info_hash_add(struct ieee80211_local *local,
  169. struct sta_info *sta)
  170. {
  171. sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
  172. rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta);
  173. }
  174. struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
  175. u8 *addr, gfp_t gfp)
  176. {
  177. struct ieee80211_local *local = sdata->local;
  178. struct sta_info *sta;
  179. int i;
  180. DECLARE_MAC_BUF(mbuf);
  181. sta = kzalloc(sizeof(*sta), gfp);
  182. if (!sta)
  183. return NULL;
  184. memcpy(sta->addr, addr, ETH_ALEN);
  185. sta->local = local;
  186. sta->sdata = sdata;
  187. sta->rate_ctrl = rate_control_get(local->rate_ctrl);
  188. sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
  189. gfp);
  190. if (!sta->rate_ctrl_priv) {
  191. rate_control_put(sta->rate_ctrl);
  192. kfree(sta);
  193. return NULL;
  194. }
  195. spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
  196. spin_lock_init(&sta->ampdu_mlme.ampdu_tx);
  197. for (i = 0; i < STA_TID_NUM; i++) {
  198. /* timer_to_tid must be initialized with identity mapping to
  199. * enable session_timer's data differentiation. refer to
  200. * sta_rx_agg_session_timer_expired for useage */
  201. sta->timer_to_tid[i] = i;
  202. /* tid to tx queue: initialize according to HW (0 is valid) */
  203. sta->tid_to_tx_q[i] = local->hw.queues;
  204. /* rx */
  205. sta->ampdu_mlme.tid_state_rx[i] = HT_AGG_STATE_IDLE;
  206. sta->ampdu_mlme.tid_rx[i] = NULL;
  207. /* tx */
  208. sta->ampdu_mlme.tid_state_tx[i] = HT_AGG_STATE_IDLE;
  209. sta->ampdu_mlme.tid_tx[i] = NULL;
  210. sta->ampdu_mlme.addba_req_num[i] = 0;
  211. }
  212. skb_queue_head_init(&sta->ps_tx_buf);
  213. skb_queue_head_init(&sta->tx_filtered);
  214. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  215. printk(KERN_DEBUG "%s: Allocated STA %s\n",
  216. wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
  217. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  218. #ifdef CONFIG_MAC80211_MESH
  219. sta->plink_state = PLINK_LISTEN;
  220. spin_lock_init(&sta->plink_lock);
  221. init_timer(&sta->plink_timer);
  222. #endif
  223. return sta;
  224. }
  225. int sta_info_insert(struct sta_info *sta)
  226. {
  227. struct ieee80211_local *local = sta->local;
  228. struct ieee80211_sub_if_data *sdata = sta->sdata;
  229. unsigned long flags;
  230. DECLARE_MAC_BUF(mac);
  231. /*
  232. * Can't be a WARN_ON because it can be triggered through a race:
  233. * something inserts a STA (on one CPU) without holding the RTNL
  234. * and another CPU turns off the net device.
  235. */
  236. if (unlikely(!netif_running(sdata->dev)))
  237. return -ENETDOWN;
  238. if (WARN_ON(compare_ether_addr(sta->addr, sdata->dev->dev_addr) == 0))
  239. return -EINVAL;
  240. if (WARN_ON(is_multicast_ether_addr(sta->addr)))
  241. return -EINVAL;
  242. spin_lock_irqsave(&local->sta_lock, flags);
  243. /* check if STA exists already */
  244. if (__sta_info_find(local, sta->addr)) {
  245. spin_unlock_irqrestore(&local->sta_lock, flags);
  246. return -EEXIST;
  247. }
  248. list_add(&sta->list, &local->sta_list);
  249. local->num_sta++;
  250. sta_info_hash_add(local, sta);
  251. /* notify driver */
  252. if (local->ops->sta_notify) {
  253. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
  254. sdata = sdata->u.vlan.ap;
  255. local->ops->sta_notify(local_to_hw(local), &sdata->vif,
  256. STA_NOTIFY_ADD, sta->addr);
  257. }
  258. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  259. printk(KERN_DEBUG "%s: Inserted STA %s\n",
  260. wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
  261. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  262. spin_unlock_irqrestore(&local->sta_lock, flags);
  263. #ifdef CONFIG_MAC80211_DEBUGFS
  264. /* debugfs entry adding might sleep, so schedule process
  265. * context task for adding entry for STAs that do not yet
  266. * have one. */
  267. queue_work(local->hw.workqueue, &local->sta_debugfs_add);
  268. #endif
  269. if (ieee80211_vif_is_mesh(&sdata->vif))
  270. mesh_accept_plinks_update(sdata);
  271. return 0;
  272. }
  273. static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
  274. {
  275. /*
  276. * This format has been mandated by the IEEE specifications,
  277. * so this line may not be changed to use the __set_bit() format.
  278. */
  279. bss->tim[aid / 8] |= (1 << (aid % 8));
  280. }
  281. static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
  282. {
  283. /*
  284. * This format has been mandated by the IEEE specifications,
  285. * so this line may not be changed to use the __clear_bit() format.
  286. */
  287. bss->tim[aid / 8] &= ~(1 << (aid % 8));
  288. }
  289. static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
  290. struct sta_info *sta)
  291. {
  292. if (bss)
  293. __bss_tim_set(bss, sta->aid);
  294. if (sta->local->ops->set_tim) {
  295. sta->local->tim_in_locked_section = true;
  296. sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1);
  297. sta->local->tim_in_locked_section = false;
  298. }
  299. }
  300. void sta_info_set_tim_bit(struct sta_info *sta)
  301. {
  302. unsigned long flags;
  303. spin_lock_irqsave(&sta->local->sta_lock, flags);
  304. __sta_info_set_tim_bit(sta->sdata->bss, sta);
  305. spin_unlock_irqrestore(&sta->local->sta_lock, flags);
  306. }
  307. static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
  308. struct sta_info *sta)
  309. {
  310. if (bss)
  311. __bss_tim_clear(bss, sta->aid);
  312. if (sta->local->ops->set_tim) {
  313. sta->local->tim_in_locked_section = true;
  314. sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0);
  315. sta->local->tim_in_locked_section = false;
  316. }
  317. }
  318. void sta_info_clear_tim_bit(struct sta_info *sta)
  319. {
  320. unsigned long flags;
  321. spin_lock_irqsave(&sta->local->sta_lock, flags);
  322. __sta_info_clear_tim_bit(sta->sdata->bss, sta);
  323. spin_unlock_irqrestore(&sta->local->sta_lock, flags);
  324. }
  325. /*
  326. * See comment in __sta_info_unlink,
  327. * caller must hold local->sta_lock.
  328. */
  329. static void __sta_info_pin(struct sta_info *sta)
  330. {
  331. WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_NORMAL);
  332. sta->pin_status = STA_INFO_PIN_STAT_PINNED;
  333. }
  334. /*
  335. * See comment in __sta_info_unlink, returns sta if it
  336. * needs to be destroyed.
  337. */
  338. static struct sta_info *__sta_info_unpin(struct sta_info *sta)
  339. {
  340. struct sta_info *ret = NULL;
  341. unsigned long flags;
  342. spin_lock_irqsave(&sta->local->sta_lock, flags);
  343. WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_DESTROY &&
  344. sta->pin_status != STA_INFO_PIN_STAT_PINNED);
  345. if (sta->pin_status == STA_INFO_PIN_STAT_DESTROY)
  346. ret = sta;
  347. sta->pin_status = STA_INFO_PIN_STAT_NORMAL;
  348. spin_unlock_irqrestore(&sta->local->sta_lock, flags);
  349. return ret;
  350. }
  351. static void __sta_info_unlink(struct sta_info **sta)
  352. {
  353. struct ieee80211_local *local = (*sta)->local;
  354. struct ieee80211_sub_if_data *sdata = (*sta)->sdata;
  355. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  356. DECLARE_MAC_BUF(mbuf);
  357. #endif
  358. /*
  359. * pull caller's reference if we're already gone.
  360. */
  361. if (sta_info_hash_del(local, *sta)) {
  362. *sta = NULL;
  363. return;
  364. }
  365. /*
  366. * Also pull caller's reference if the STA is pinned by the
  367. * task that is adding the debugfs entries. In that case, we
  368. * leave the STA "to be freed".
  369. *
  370. * The rules are not trivial, but not too complex either:
  371. * (1) pin_status is only modified under the sta_lock
  372. * (2) sta_info_debugfs_add_work() will set the status
  373. * to PINNED when it found an item that needs a new
  374. * debugfs directory created. In that case, that item
  375. * must not be freed although all *RCU* users are done
  376. * with it. Hence, we tell the caller of _unlink()
  377. * that the item is already gone (as can happen when
  378. * two tasks try to unlink/destroy at the same time)
  379. * (3) We set the pin_status to DESTROY here when we
  380. * find such an item.
  381. * (4) sta_info_debugfs_add_work() will reset the pin_status
  382. * from PINNED to NORMAL when it is done with the item,
  383. * but will check for DESTROY before resetting it in
  384. * which case it will free the item.
  385. */
  386. if ((*sta)->pin_status == STA_INFO_PIN_STAT_PINNED) {
  387. (*sta)->pin_status = STA_INFO_PIN_STAT_DESTROY;
  388. *sta = NULL;
  389. return;
  390. }
  391. list_del(&(*sta)->list);
  392. if ((*sta)->flags & WLAN_STA_PS) {
  393. (*sta)->flags &= ~WLAN_STA_PS;
  394. if (sdata->bss)
  395. atomic_dec(&sdata->bss->num_sta_ps);
  396. __sta_info_clear_tim_bit(sdata->bss, *sta);
  397. }
  398. local->num_sta--;
  399. if (local->ops->sta_notify) {
  400. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
  401. sdata = sdata->u.vlan.ap;
  402. local->ops->sta_notify(local_to_hw(local), &sdata->vif,
  403. STA_NOTIFY_REMOVE, (*sta)->addr);
  404. }
  405. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  406. mesh_accept_plinks_update(sdata);
  407. #ifdef CONFIG_MAC80211_MESH
  408. del_timer(&(*sta)->plink_timer);
  409. #endif
  410. }
  411. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  412. printk(KERN_DEBUG "%s: Removed STA %s\n",
  413. wiphy_name(local->hw.wiphy), print_mac(mbuf, (*sta)->addr));
  414. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  415. }
  416. void sta_info_unlink(struct sta_info **sta)
  417. {
  418. struct ieee80211_local *local = (*sta)->local;
  419. unsigned long flags;
  420. spin_lock_irqsave(&local->sta_lock, flags);
  421. __sta_info_unlink(sta);
  422. spin_unlock_irqrestore(&local->sta_lock, flags);
  423. }
  424. static inline int sta_info_buffer_expired(struct ieee80211_local *local,
  425. struct sta_info *sta,
  426. struct sk_buff *skb)
  427. {
  428. struct ieee80211_tx_packet_data *pkt_data;
  429. int timeout;
  430. if (!skb)
  431. return 0;
  432. pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
  433. /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
  434. timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
  435. 15625) * HZ;
  436. if (timeout < STA_TX_BUFFER_EXPIRE)
  437. timeout = STA_TX_BUFFER_EXPIRE;
  438. return time_after(jiffies, pkt_data->jiffies + timeout);
  439. }
  440. static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
  441. struct sta_info *sta)
  442. {
  443. unsigned long flags;
  444. struct sk_buff *skb;
  445. struct ieee80211_sub_if_data *sdata;
  446. DECLARE_MAC_BUF(mac);
  447. if (skb_queue_empty(&sta->ps_tx_buf))
  448. return;
  449. for (;;) {
  450. spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
  451. skb = skb_peek(&sta->ps_tx_buf);
  452. if (sta_info_buffer_expired(local, sta, skb))
  453. skb = __skb_dequeue(&sta->ps_tx_buf);
  454. else
  455. skb = NULL;
  456. spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
  457. if (!skb)
  458. break;
  459. sdata = sta->sdata;
  460. local->total_ps_buffered--;
  461. printk(KERN_DEBUG "Buffered frame expired (STA "
  462. "%s)\n", print_mac(mac, sta->addr));
  463. dev_kfree_skb(skb);
  464. if (skb_queue_empty(&sta->ps_tx_buf))
  465. sta_info_clear_tim_bit(sta);
  466. }
  467. }
  468. static void sta_info_cleanup(unsigned long data)
  469. {
  470. struct ieee80211_local *local = (struct ieee80211_local *) data;
  471. struct sta_info *sta;
  472. rcu_read_lock();
  473. list_for_each_entry_rcu(sta, &local->sta_list, list)
  474. sta_info_cleanup_expire_buffered(local, sta);
  475. rcu_read_unlock();
  476. local->sta_cleanup.expires =
  477. round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
  478. add_timer(&local->sta_cleanup);
  479. }
  480. #ifdef CONFIG_MAC80211_DEBUGFS
  481. static void sta_info_debugfs_add_work(struct work_struct *work)
  482. {
  483. struct ieee80211_local *local =
  484. container_of(work, struct ieee80211_local, sta_debugfs_add);
  485. struct sta_info *sta, *tmp;
  486. unsigned long flags;
  487. while (1) {
  488. sta = NULL;
  489. spin_lock_irqsave(&local->sta_lock, flags);
  490. list_for_each_entry(tmp, &local->sta_list, list) {
  491. if (!tmp->debugfs.dir) {
  492. sta = tmp;
  493. __sta_info_pin(sta);
  494. break;
  495. }
  496. }
  497. spin_unlock_irqrestore(&local->sta_lock, flags);
  498. if (!sta)
  499. break;
  500. ieee80211_sta_debugfs_add(sta);
  501. rate_control_add_sta_debugfs(sta);
  502. sta = __sta_info_unpin(sta);
  503. if (sta) {
  504. synchronize_rcu();
  505. sta_info_destroy(sta);
  506. }
  507. }
  508. }
  509. #endif
  510. void sta_info_init(struct ieee80211_local *local)
  511. {
  512. spin_lock_init(&local->sta_lock);
  513. INIT_LIST_HEAD(&local->sta_list);
  514. setup_timer(&local->sta_cleanup, sta_info_cleanup,
  515. (unsigned long)local);
  516. local->sta_cleanup.expires =
  517. round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
  518. #ifdef CONFIG_MAC80211_DEBUGFS
  519. INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_work);
  520. #endif
  521. }
  522. int sta_info_start(struct ieee80211_local *local)
  523. {
  524. add_timer(&local->sta_cleanup);
  525. return 0;
  526. }
  527. void sta_info_stop(struct ieee80211_local *local)
  528. {
  529. del_timer(&local->sta_cleanup);
  530. sta_info_flush(local, NULL);
  531. }
  532. /**
  533. * sta_info_flush - flush matching STA entries from the STA table
  534. *
  535. * Returns the number of removed STA entries.
  536. *
  537. * @local: local interface data
  538. * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
  539. */
  540. int sta_info_flush(struct ieee80211_local *local,
  541. struct ieee80211_sub_if_data *sdata)
  542. {
  543. struct sta_info *sta, *tmp;
  544. LIST_HEAD(tmp_list);
  545. int ret = 0;
  546. unsigned long flags;
  547. might_sleep();
  548. spin_lock_irqsave(&local->sta_lock, flags);
  549. list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
  550. if (!sdata || sdata == sta->sdata) {
  551. __sta_info_unlink(&sta);
  552. if (sta) {
  553. list_add_tail(&sta->list, &tmp_list);
  554. ret++;
  555. }
  556. }
  557. }
  558. spin_unlock_irqrestore(&local->sta_lock, flags);
  559. synchronize_rcu();
  560. list_for_each_entry_safe(sta, tmp, &tmp_list, list)
  561. sta_info_destroy(sta);
  562. return ret;
  563. }