sta_info.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  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 "driver-ops.h"
  21. #include "rate.h"
  22. #include "sta_info.h"
  23. #include "debugfs_sta.h"
  24. #include "mesh.h"
  25. /**
  26. * DOC: STA information lifetime rules
  27. *
  28. * STA info structures (&struct sta_info) are managed in a hash table
  29. * for faster lookup and a list for iteration. They are managed using
  30. * RCU, i.e. access to the list and hash table is protected by RCU.
  31. *
  32. * Upon allocating a STA info structure with sta_info_alloc(), the caller
  33. * owns that structure. It must then insert it into the hash table using
  34. * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
  35. * case (which acquires an rcu read section but must not be called from
  36. * within one) will the pointer still be valid after the call. Note that
  37. * the caller may not do much with the STA info before inserting it, in
  38. * particular, it may not start any mesh peer link management or add
  39. * encryption keys.
  40. *
  41. * When the insertion fails (sta_info_insert()) returns non-zero), the
  42. * structure will have been freed by sta_info_insert()!
  43. *
  44. * Station entries are added by mac80211 when you establish a link with a
  45. * peer. This means different things for the different type of interfaces
  46. * we support. For a regular station this mean we add the AP sta when we
  47. * receive an association response from the AP. For IBSS this occurs when
  48. * get to know about a peer on the same IBSS. For WDS we add the sta for
  49. * the peer immediately upon device open. When using AP mode we add stations
  50. * for each respective station upon request from userspace through nl80211.
  51. *
  52. * In order to remove a STA info structure, various sta_info_destroy_*()
  53. * calls are available.
  54. *
  55. * There is no concept of ownership on a STA entry, each structure is
  56. * owned by the global hash table/list until it is removed. All users of
  57. * the structure need to be RCU protected so that the structure won't be
  58. * freed before they are done using it.
  59. */
  60. /* Caller must hold local->sta_lock */
  61. static int sta_info_hash_del(struct ieee80211_local *local,
  62. struct sta_info *sta)
  63. {
  64. struct sta_info *s;
  65. s = rcu_dereference_protected(local->sta_hash[STA_HASH(sta->sta.addr)],
  66. lockdep_is_held(&local->sta_lock));
  67. if (!s)
  68. return -ENOENT;
  69. if (s == sta) {
  70. rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)],
  71. s->hnext);
  72. return 0;
  73. }
  74. while (rcu_access_pointer(s->hnext) &&
  75. rcu_access_pointer(s->hnext) != sta)
  76. s = rcu_dereference_protected(s->hnext,
  77. lockdep_is_held(&local->sta_lock));
  78. if (rcu_access_pointer(s->hnext)) {
  79. rcu_assign_pointer(s->hnext, sta->hnext);
  80. return 0;
  81. }
  82. return -ENOENT;
  83. }
  84. /* protected by RCU */
  85. struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
  86. const u8 *addr)
  87. {
  88. struct ieee80211_local *local = sdata->local;
  89. struct sta_info *sta;
  90. sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
  91. lockdep_is_held(&local->sta_lock) ||
  92. lockdep_is_held(&local->sta_mtx));
  93. while (sta) {
  94. if (sta->sdata == sdata && !sta->dummy &&
  95. memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
  96. break;
  97. sta = rcu_dereference_check(sta->hnext,
  98. lockdep_is_held(&local->sta_lock) ||
  99. lockdep_is_held(&local->sta_mtx));
  100. }
  101. return sta;
  102. }
  103. /* get a station info entry even if it is a dummy station*/
  104. struct sta_info *sta_info_get_rx(struct ieee80211_sub_if_data *sdata,
  105. const u8 *addr)
  106. {
  107. struct ieee80211_local *local = sdata->local;
  108. struct sta_info *sta;
  109. sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
  110. lockdep_is_held(&local->sta_lock) ||
  111. lockdep_is_held(&local->sta_mtx));
  112. while (sta) {
  113. if (sta->sdata == sdata &&
  114. memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
  115. break;
  116. sta = rcu_dereference_check(sta->hnext,
  117. lockdep_is_held(&local->sta_lock) ||
  118. lockdep_is_held(&local->sta_mtx));
  119. }
  120. return sta;
  121. }
  122. /*
  123. * Get sta info either from the specified interface
  124. * or from one of its vlans
  125. */
  126. struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
  127. const u8 *addr)
  128. {
  129. struct ieee80211_local *local = sdata->local;
  130. struct sta_info *sta;
  131. sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
  132. lockdep_is_held(&local->sta_lock) ||
  133. lockdep_is_held(&local->sta_mtx));
  134. while (sta) {
  135. if ((sta->sdata == sdata ||
  136. (sta->sdata->bss && sta->sdata->bss == sdata->bss)) &&
  137. !sta->dummy &&
  138. memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
  139. break;
  140. sta = rcu_dereference_check(sta->hnext,
  141. lockdep_is_held(&local->sta_lock) ||
  142. lockdep_is_held(&local->sta_mtx));
  143. }
  144. return sta;
  145. }
  146. /*
  147. * Get sta info either from the specified interface
  148. * or from one of its vlans (including dummy stations)
  149. */
  150. struct sta_info *sta_info_get_bss_rx(struct ieee80211_sub_if_data *sdata,
  151. const u8 *addr)
  152. {
  153. struct ieee80211_local *local = sdata->local;
  154. struct sta_info *sta;
  155. sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
  156. lockdep_is_held(&local->sta_lock) ||
  157. lockdep_is_held(&local->sta_mtx));
  158. while (sta) {
  159. if ((sta->sdata == sdata ||
  160. (sta->sdata->bss && sta->sdata->bss == sdata->bss)) &&
  161. memcmp(sta->sta.addr, addr, ETH_ALEN) == 0)
  162. break;
  163. sta = rcu_dereference_check(sta->hnext,
  164. lockdep_is_held(&local->sta_lock) ||
  165. lockdep_is_held(&local->sta_mtx));
  166. }
  167. return sta;
  168. }
  169. struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
  170. int idx)
  171. {
  172. struct ieee80211_local *local = sdata->local;
  173. struct sta_info *sta;
  174. int i = 0;
  175. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  176. if (sdata != sta->sdata)
  177. continue;
  178. if (i < idx) {
  179. ++i;
  180. continue;
  181. }
  182. return sta;
  183. }
  184. return NULL;
  185. }
  186. /**
  187. * __sta_info_free - internal STA free helper
  188. *
  189. * @local: pointer to the global information
  190. * @sta: STA info to free
  191. *
  192. * This function must undo everything done by sta_info_alloc()
  193. * that may happen before sta_info_insert().
  194. */
  195. static void __sta_info_free(struct ieee80211_local *local,
  196. struct sta_info *sta)
  197. {
  198. if (sta->rate_ctrl) {
  199. rate_control_free_sta(sta);
  200. rate_control_put(sta->rate_ctrl);
  201. }
  202. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  203. wiphy_debug(local->hw.wiphy, "Destroyed STA %pM\n", sta->sta.addr);
  204. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  205. kfree(sta);
  206. }
  207. /* Caller must hold local->sta_lock */
  208. static void sta_info_hash_add(struct ieee80211_local *local,
  209. struct sta_info *sta)
  210. {
  211. sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
  212. rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
  213. }
  214. static void sta_unblock(struct work_struct *wk)
  215. {
  216. struct sta_info *sta;
  217. sta = container_of(wk, struct sta_info, drv_unblock_wk);
  218. if (sta->dead)
  219. return;
  220. if (!test_sta_flags(sta, WLAN_STA_PS_STA))
  221. ieee80211_sta_ps_deliver_wakeup(sta);
  222. else if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) {
  223. clear_sta_flags(sta, WLAN_STA_PS_DRIVER);
  224. ieee80211_sta_ps_deliver_poll_response(sta);
  225. } else
  226. clear_sta_flags(sta, WLAN_STA_PS_DRIVER);
  227. }
  228. static int sta_prepare_rate_control(struct ieee80211_local *local,
  229. struct sta_info *sta, gfp_t gfp)
  230. {
  231. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  232. return 0;
  233. sta->rate_ctrl = rate_control_get(local->rate_ctrl);
  234. sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
  235. &sta->sta, gfp);
  236. if (!sta->rate_ctrl_priv) {
  237. rate_control_put(sta->rate_ctrl);
  238. return -ENOMEM;
  239. }
  240. return 0;
  241. }
  242. struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
  243. u8 *addr, gfp_t gfp)
  244. {
  245. struct ieee80211_local *local = sdata->local;
  246. struct sta_info *sta;
  247. struct timespec uptime;
  248. int i;
  249. sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
  250. if (!sta)
  251. return NULL;
  252. spin_lock_init(&sta->lock);
  253. spin_lock_init(&sta->flaglock);
  254. INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
  255. INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
  256. mutex_init(&sta->ampdu_mlme.mtx);
  257. memcpy(sta->sta.addr, addr, ETH_ALEN);
  258. sta->local = local;
  259. sta->sdata = sdata;
  260. sta->last_rx = jiffies;
  261. do_posix_clock_monotonic_gettime(&uptime);
  262. sta->last_connected = uptime.tv_sec;
  263. ewma_init(&sta->avg_signal, 1024, 8);
  264. if (sta_prepare_rate_control(local, sta, gfp)) {
  265. kfree(sta);
  266. return NULL;
  267. }
  268. for (i = 0; i < STA_TID_NUM; i++) {
  269. /*
  270. * timer_to_tid must be initialized with identity mapping
  271. * to enable session_timer's data differentiation. See
  272. * sta_rx_agg_session_timer_expired for usage.
  273. */
  274. sta->timer_to_tid[i] = i;
  275. }
  276. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  277. skb_queue_head_init(&sta->ps_tx_buf[i]);
  278. skb_queue_head_init(&sta->tx_filtered[i]);
  279. }
  280. for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
  281. sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
  282. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  283. wiphy_debug(local->hw.wiphy, "Allocated STA %pM\n", sta->sta.addr);
  284. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  285. #ifdef CONFIG_MAC80211_MESH
  286. sta->plink_state = NL80211_PLINK_LISTEN;
  287. init_timer(&sta->plink_timer);
  288. #endif
  289. return sta;
  290. }
  291. static int sta_info_finish_insert(struct sta_info *sta,
  292. bool async, bool dummy_reinsert)
  293. {
  294. struct ieee80211_local *local = sta->local;
  295. struct ieee80211_sub_if_data *sdata = sta->sdata;
  296. struct station_info sinfo;
  297. unsigned long flags;
  298. int err = 0;
  299. lockdep_assert_held(&local->sta_mtx);
  300. if (!sta->dummy || dummy_reinsert) {
  301. /* notify driver */
  302. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  303. sdata = container_of(sdata->bss,
  304. struct ieee80211_sub_if_data,
  305. u.ap);
  306. err = drv_sta_add(local, sdata, &sta->sta);
  307. if (err) {
  308. if (!async)
  309. return err;
  310. printk(KERN_DEBUG "%s: failed to add IBSS STA %pM to "
  311. "driver (%d) - keeping it anyway.\n",
  312. sdata->name, sta->sta.addr, err);
  313. } else {
  314. sta->uploaded = true;
  315. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  316. if (async)
  317. wiphy_debug(local->hw.wiphy,
  318. "Finished adding IBSS STA %pM\n",
  319. sta->sta.addr);
  320. #endif
  321. }
  322. sdata = sta->sdata;
  323. }
  324. if (!dummy_reinsert) {
  325. if (!async) {
  326. local->num_sta++;
  327. local->sta_generation++;
  328. smp_mb();
  329. /* make the station visible */
  330. spin_lock_irqsave(&local->sta_lock, flags);
  331. sta_info_hash_add(local, sta);
  332. spin_unlock_irqrestore(&local->sta_lock, flags);
  333. }
  334. list_add(&sta->list, &local->sta_list);
  335. } else {
  336. sta->dummy = false;
  337. }
  338. if (!sta->dummy) {
  339. ieee80211_sta_debugfs_add(sta);
  340. rate_control_add_sta_debugfs(sta);
  341. memset(&sinfo, 0, sizeof(sinfo));
  342. sinfo.filled = 0;
  343. sinfo.generation = local->sta_generation;
  344. cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
  345. }
  346. return 0;
  347. }
  348. static void sta_info_finish_pending(struct ieee80211_local *local)
  349. {
  350. struct sta_info *sta;
  351. unsigned long flags;
  352. spin_lock_irqsave(&local->sta_lock, flags);
  353. while (!list_empty(&local->sta_pending_list)) {
  354. sta = list_first_entry(&local->sta_pending_list,
  355. struct sta_info, list);
  356. list_del(&sta->list);
  357. spin_unlock_irqrestore(&local->sta_lock, flags);
  358. sta_info_finish_insert(sta, true, false);
  359. spin_lock_irqsave(&local->sta_lock, flags);
  360. }
  361. spin_unlock_irqrestore(&local->sta_lock, flags);
  362. }
  363. static void sta_info_finish_work(struct work_struct *work)
  364. {
  365. struct ieee80211_local *local =
  366. container_of(work, struct ieee80211_local, sta_finish_work);
  367. mutex_lock(&local->sta_mtx);
  368. sta_info_finish_pending(local);
  369. mutex_unlock(&local->sta_mtx);
  370. }
  371. static int sta_info_insert_check(struct sta_info *sta)
  372. {
  373. struct ieee80211_sub_if_data *sdata = sta->sdata;
  374. /*
  375. * Can't be a WARN_ON because it can be triggered through a race:
  376. * something inserts a STA (on one CPU) without holding the RTNL
  377. * and another CPU turns off the net device.
  378. */
  379. if (unlikely(!ieee80211_sdata_running(sdata)))
  380. return -ENETDOWN;
  381. if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->vif.addr) == 0 ||
  382. is_multicast_ether_addr(sta->sta.addr)))
  383. return -EINVAL;
  384. return 0;
  385. }
  386. static int sta_info_insert_ibss(struct sta_info *sta) __acquires(RCU)
  387. {
  388. struct ieee80211_local *local = sta->local;
  389. struct ieee80211_sub_if_data *sdata = sta->sdata;
  390. unsigned long flags;
  391. spin_lock_irqsave(&local->sta_lock, flags);
  392. /* check if STA exists already */
  393. if (sta_info_get_bss_rx(sdata, sta->sta.addr)) {
  394. spin_unlock_irqrestore(&local->sta_lock, flags);
  395. rcu_read_lock();
  396. return -EEXIST;
  397. }
  398. local->num_sta++;
  399. local->sta_generation++;
  400. smp_mb();
  401. sta_info_hash_add(local, sta);
  402. list_add_tail(&sta->list, &local->sta_pending_list);
  403. rcu_read_lock();
  404. spin_unlock_irqrestore(&local->sta_lock, flags);
  405. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  406. wiphy_debug(local->hw.wiphy, "Added IBSS STA %pM\n",
  407. sta->sta.addr);
  408. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  409. ieee80211_queue_work(&local->hw, &local->sta_finish_work);
  410. return 0;
  411. }
  412. /*
  413. * should be called with sta_mtx locked
  414. * this function replaces the mutex lock
  415. * with a RCU lock
  416. */
  417. static int sta_info_insert_non_ibss(struct sta_info *sta) __acquires(RCU)
  418. {
  419. struct ieee80211_local *local = sta->local;
  420. struct ieee80211_sub_if_data *sdata = sta->sdata;
  421. unsigned long flags;
  422. struct sta_info *exist_sta;
  423. bool dummy_reinsert = false;
  424. int err = 0;
  425. lockdep_assert_held(&local->sta_mtx);
  426. /*
  427. * On first glance, this will look racy, because the code
  428. * in this function, which inserts a station with sleeping,
  429. * unlocks the sta_lock between checking existence in the
  430. * hash table and inserting into it.
  431. *
  432. * However, it is not racy against itself because it keeps
  433. * the mutex locked.
  434. */
  435. spin_lock_irqsave(&local->sta_lock, flags);
  436. /*
  437. * check if STA exists already.
  438. * only accept a scenario of a second call to sta_info_insert_non_ibss
  439. * with a dummy station entry that was inserted earlier
  440. * in that case - assume that the dummy station flag should
  441. * be removed.
  442. */
  443. exist_sta = sta_info_get_bss_rx(sdata, sta->sta.addr);
  444. if (exist_sta) {
  445. if (exist_sta == sta && sta->dummy) {
  446. dummy_reinsert = true;
  447. } else {
  448. spin_unlock_irqrestore(&local->sta_lock, flags);
  449. mutex_unlock(&local->sta_mtx);
  450. rcu_read_lock();
  451. return -EEXIST;
  452. }
  453. }
  454. spin_unlock_irqrestore(&local->sta_lock, flags);
  455. err = sta_info_finish_insert(sta, false, dummy_reinsert);
  456. if (err) {
  457. mutex_unlock(&local->sta_mtx);
  458. rcu_read_lock();
  459. return err;
  460. }
  461. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  462. wiphy_debug(local->hw.wiphy, "Inserted %sSTA %pM\n",
  463. sta->dummy ? "dummy " : "", sta->sta.addr);
  464. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  465. /* move reference to rcu-protected */
  466. rcu_read_lock();
  467. mutex_unlock(&local->sta_mtx);
  468. if (ieee80211_vif_is_mesh(&sdata->vif))
  469. mesh_accept_plinks_update(sdata);
  470. return 0;
  471. }
  472. int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
  473. {
  474. struct ieee80211_local *local = sta->local;
  475. struct ieee80211_sub_if_data *sdata = sta->sdata;
  476. int err = 0;
  477. err = sta_info_insert_check(sta);
  478. if (err) {
  479. rcu_read_lock();
  480. goto out_free;
  481. }
  482. /*
  483. * In ad-hoc mode, we sometimes need to insert stations
  484. * from tasklet context from the RX path. To avoid races,
  485. * always do so in that case -- see the comment below.
  486. */
  487. if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  488. err = sta_info_insert_ibss(sta);
  489. if (err)
  490. goto out_free;
  491. return 0;
  492. }
  493. /*
  494. * It might seem that the function called below is in race against
  495. * the function call above that atomically inserts the station... That,
  496. * however, is not true because the above code can only
  497. * be invoked for IBSS interfaces, and the below code will
  498. * not be -- and the two do not race against each other as
  499. * the hash table also keys off the interface.
  500. */
  501. might_sleep();
  502. mutex_lock(&local->sta_mtx);
  503. err = sta_info_insert_non_ibss(sta);
  504. if (err)
  505. goto out_free;
  506. return 0;
  507. out_free:
  508. BUG_ON(!err);
  509. __sta_info_free(local, sta);
  510. return err;
  511. }
  512. int sta_info_insert(struct sta_info *sta)
  513. {
  514. int err = sta_info_insert_rcu(sta);
  515. rcu_read_unlock();
  516. return err;
  517. }
  518. /* Caller must hold sta->local->sta_mtx */
  519. int sta_info_reinsert(struct sta_info *sta)
  520. {
  521. struct ieee80211_local *local = sta->local;
  522. int err = 0;
  523. err = sta_info_insert_check(sta);
  524. if (err) {
  525. mutex_unlock(&local->sta_mtx);
  526. return err;
  527. }
  528. might_sleep();
  529. err = sta_info_insert_non_ibss(sta);
  530. rcu_read_unlock();
  531. return err;
  532. }
  533. static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
  534. {
  535. /*
  536. * This format has been mandated by the IEEE specifications,
  537. * so this line may not be changed to use the __set_bit() format.
  538. */
  539. bss->tim[aid / 8] |= (1 << (aid % 8));
  540. }
  541. static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
  542. {
  543. /*
  544. * This format has been mandated by the IEEE specifications,
  545. * so this line may not be changed to use the __clear_bit() format.
  546. */
  547. bss->tim[aid / 8] &= ~(1 << (aid % 8));
  548. }
  549. static unsigned long ieee80211_tids_for_ac(int ac)
  550. {
  551. /* If we ever support TIDs > 7, this obviously needs to be adjusted */
  552. switch (ac) {
  553. case IEEE80211_AC_VO:
  554. return BIT(6) | BIT(7);
  555. case IEEE80211_AC_VI:
  556. return BIT(4) | BIT(5);
  557. case IEEE80211_AC_BE:
  558. return BIT(0) | BIT(3);
  559. case IEEE80211_AC_BK:
  560. return BIT(1) | BIT(2);
  561. default:
  562. WARN_ON(1);
  563. return 0;
  564. }
  565. }
  566. void sta_info_recalc_tim(struct sta_info *sta)
  567. {
  568. struct ieee80211_local *local = sta->local;
  569. struct ieee80211_if_ap *bss = sta->sdata->bss;
  570. unsigned long flags;
  571. bool indicate_tim = false;
  572. u8 ignore_for_tim = sta->sta.uapsd_queues;
  573. int ac;
  574. if (WARN_ON_ONCE(!sta->sdata->bss))
  575. return;
  576. /* No need to do anything if the driver does all */
  577. if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
  578. return;
  579. if (sta->dead)
  580. goto done;
  581. /*
  582. * If all ACs are delivery-enabled then we should build
  583. * the TIM bit for all ACs anyway; if only some are then
  584. * we ignore those and build the TIM bit using only the
  585. * non-enabled ones.
  586. */
  587. if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
  588. ignore_for_tim = 0;
  589. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  590. unsigned long tids;
  591. if (ignore_for_tim & BIT(ac))
  592. continue;
  593. indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
  594. !skb_queue_empty(&sta->ps_tx_buf[ac]);
  595. if (indicate_tim)
  596. break;
  597. tids = ieee80211_tids_for_ac(ac);
  598. indicate_tim |=
  599. sta->driver_buffered_tids & tids;
  600. }
  601. done:
  602. spin_lock_irqsave(&local->sta_lock, flags);
  603. if (indicate_tim)
  604. __bss_tim_set(bss, sta->sta.aid);
  605. else
  606. __bss_tim_clear(bss, sta->sta.aid);
  607. if (local->ops->set_tim) {
  608. local->tim_in_locked_section = true;
  609. drv_set_tim(local, &sta->sta, indicate_tim);
  610. local->tim_in_locked_section = false;
  611. }
  612. spin_unlock_irqrestore(&local->sta_lock, flags);
  613. }
  614. static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
  615. {
  616. struct ieee80211_tx_info *info;
  617. int timeout;
  618. if (!skb)
  619. return false;
  620. info = IEEE80211_SKB_CB(skb);
  621. /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
  622. timeout = (sta->listen_interval *
  623. sta->sdata->vif.bss_conf.beacon_int *
  624. 32 / 15625) * HZ;
  625. if (timeout < STA_TX_BUFFER_EXPIRE)
  626. timeout = STA_TX_BUFFER_EXPIRE;
  627. return time_after(jiffies, info->control.jiffies + timeout);
  628. }
  629. static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
  630. struct sta_info *sta, int ac)
  631. {
  632. unsigned long flags;
  633. struct sk_buff *skb;
  634. /*
  635. * First check for frames that should expire on the filtered
  636. * queue. Frames here were rejected by the driver and are on
  637. * a separate queue to avoid reordering with normal PS-buffered
  638. * frames. They also aren't accounted for right now in the
  639. * total_ps_buffered counter.
  640. */
  641. for (;;) {
  642. spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
  643. skb = skb_peek(&sta->tx_filtered[ac]);
  644. if (sta_info_buffer_expired(sta, skb))
  645. skb = __skb_dequeue(&sta->tx_filtered[ac]);
  646. else
  647. skb = NULL;
  648. spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
  649. /*
  650. * Frames are queued in order, so if this one
  651. * hasn't expired yet we can stop testing. If
  652. * we actually reached the end of the queue we
  653. * also need to stop, of course.
  654. */
  655. if (!skb)
  656. break;
  657. dev_kfree_skb(skb);
  658. }
  659. /*
  660. * Now also check the normal PS-buffered queue, this will
  661. * only find something if the filtered queue was emptied
  662. * since the filtered frames are all before the normal PS
  663. * buffered frames.
  664. */
  665. for (;;) {
  666. spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
  667. skb = skb_peek(&sta->ps_tx_buf[ac]);
  668. if (sta_info_buffer_expired(sta, skb))
  669. skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
  670. else
  671. skb = NULL;
  672. spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
  673. /*
  674. * frames are queued in order, so if this one
  675. * hasn't expired yet (or we reached the end of
  676. * the queue) we can stop testing
  677. */
  678. if (!skb)
  679. break;
  680. local->total_ps_buffered--;
  681. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  682. printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n",
  683. sta->sta.addr);
  684. #endif
  685. dev_kfree_skb(skb);
  686. }
  687. /*
  688. * Finally, recalculate the TIM bit for this station -- it might
  689. * now be clear because the station was too slow to retrieve its
  690. * frames.
  691. */
  692. sta_info_recalc_tim(sta);
  693. /*
  694. * Return whether there are any frames still buffered, this is
  695. * used to check whether the cleanup timer still needs to run,
  696. * if there are no frames we don't need to rearm the timer.
  697. */
  698. return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
  699. skb_queue_empty(&sta->tx_filtered[ac]));
  700. }
  701. static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
  702. struct sta_info *sta)
  703. {
  704. bool have_buffered = false;
  705. int ac;
  706. /* This is only necessary for stations on BSS interfaces */
  707. if (!sta->sdata->bss)
  708. return false;
  709. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  710. have_buffered |=
  711. sta_info_cleanup_expire_buffered_ac(local, sta, ac);
  712. return have_buffered;
  713. }
  714. static int __must_check __sta_info_destroy(struct sta_info *sta)
  715. {
  716. struct ieee80211_local *local;
  717. struct ieee80211_sub_if_data *sdata;
  718. unsigned long flags;
  719. int ret, i, ac;
  720. might_sleep();
  721. if (!sta)
  722. return -ENOENT;
  723. local = sta->local;
  724. sdata = sta->sdata;
  725. /*
  726. * Before removing the station from the driver and
  727. * rate control, it might still start new aggregation
  728. * sessions -- block that to make sure the tear-down
  729. * will be sufficient.
  730. */
  731. set_sta_flags(sta, WLAN_STA_BLOCK_BA);
  732. ieee80211_sta_tear_down_BA_sessions(sta, true);
  733. spin_lock_irqsave(&local->sta_lock, flags);
  734. ret = sta_info_hash_del(local, sta);
  735. /* this might still be the pending list ... which is fine */
  736. if (!ret)
  737. list_del(&sta->list);
  738. spin_unlock_irqrestore(&local->sta_lock, flags);
  739. if (ret)
  740. return ret;
  741. mutex_lock(&local->key_mtx);
  742. for (i = 0; i < NUM_DEFAULT_KEYS; i++)
  743. __ieee80211_key_free(key_mtx_dereference(local, sta->gtk[i]));
  744. if (sta->ptk)
  745. __ieee80211_key_free(key_mtx_dereference(local, sta->ptk));
  746. mutex_unlock(&local->key_mtx);
  747. sta->dead = true;
  748. if (test_and_clear_sta_flags(sta,
  749. WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) {
  750. BUG_ON(!sdata->bss);
  751. atomic_dec(&sdata->bss->num_sta_ps);
  752. sta_info_recalc_tim(sta);
  753. }
  754. local->num_sta--;
  755. local->sta_generation++;
  756. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  757. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  758. if (sta->uploaded) {
  759. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  760. sdata = container_of(sdata->bss,
  761. struct ieee80211_sub_if_data,
  762. u.ap);
  763. drv_sta_remove(local, sdata, &sta->sta);
  764. sdata = sta->sdata;
  765. }
  766. /*
  767. * At this point, after we wait for an RCU grace period,
  768. * neither mac80211 nor the driver can reference this
  769. * sta struct any more except by still existing timers
  770. * associated with this station that we clean up below.
  771. */
  772. synchronize_rcu();
  773. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  774. local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
  775. __skb_queue_purge(&sta->ps_tx_buf[ac]);
  776. __skb_queue_purge(&sta->tx_filtered[ac]);
  777. }
  778. #ifdef CONFIG_MAC80211_MESH
  779. if (ieee80211_vif_is_mesh(&sdata->vif))
  780. mesh_accept_plinks_update(sdata);
  781. #endif
  782. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  783. wiphy_debug(local->hw.wiphy, "Removed STA %pM\n", sta->sta.addr);
  784. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  785. cancel_work_sync(&sta->drv_unblock_wk);
  786. cfg80211_del_sta(sdata->dev, sta->sta.addr, GFP_KERNEL);
  787. rate_control_remove_sta_debugfs(sta);
  788. ieee80211_sta_debugfs_remove(sta);
  789. #ifdef CONFIG_MAC80211_MESH
  790. if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
  791. mesh_plink_deactivate(sta);
  792. del_timer_sync(&sta->plink_timer);
  793. }
  794. #endif
  795. __sta_info_free(local, sta);
  796. return 0;
  797. }
  798. int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
  799. {
  800. struct sta_info *sta;
  801. int ret;
  802. mutex_lock(&sdata->local->sta_mtx);
  803. sta = sta_info_get_rx(sdata, addr);
  804. ret = __sta_info_destroy(sta);
  805. mutex_unlock(&sdata->local->sta_mtx);
  806. return ret;
  807. }
  808. int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
  809. const u8 *addr)
  810. {
  811. struct sta_info *sta;
  812. int ret;
  813. mutex_lock(&sdata->local->sta_mtx);
  814. sta = sta_info_get_bss_rx(sdata, addr);
  815. ret = __sta_info_destroy(sta);
  816. mutex_unlock(&sdata->local->sta_mtx);
  817. return ret;
  818. }
  819. static void sta_info_cleanup(unsigned long data)
  820. {
  821. struct ieee80211_local *local = (struct ieee80211_local *) data;
  822. struct sta_info *sta;
  823. bool timer_needed = false;
  824. rcu_read_lock();
  825. list_for_each_entry_rcu(sta, &local->sta_list, list)
  826. if (sta_info_cleanup_expire_buffered(local, sta))
  827. timer_needed = true;
  828. rcu_read_unlock();
  829. if (local->quiescing)
  830. return;
  831. if (!timer_needed)
  832. return;
  833. mod_timer(&local->sta_cleanup,
  834. round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
  835. }
  836. void sta_info_init(struct ieee80211_local *local)
  837. {
  838. spin_lock_init(&local->sta_lock);
  839. mutex_init(&local->sta_mtx);
  840. INIT_LIST_HEAD(&local->sta_list);
  841. INIT_LIST_HEAD(&local->sta_pending_list);
  842. INIT_WORK(&local->sta_finish_work, sta_info_finish_work);
  843. setup_timer(&local->sta_cleanup, sta_info_cleanup,
  844. (unsigned long)local);
  845. }
  846. void sta_info_stop(struct ieee80211_local *local)
  847. {
  848. del_timer(&local->sta_cleanup);
  849. sta_info_flush(local, NULL);
  850. }
  851. /**
  852. * sta_info_flush - flush matching STA entries from the STA table
  853. *
  854. * Returns the number of removed STA entries.
  855. *
  856. * @local: local interface data
  857. * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
  858. */
  859. int sta_info_flush(struct ieee80211_local *local,
  860. struct ieee80211_sub_if_data *sdata)
  861. {
  862. struct sta_info *sta, *tmp;
  863. int ret = 0;
  864. might_sleep();
  865. mutex_lock(&local->sta_mtx);
  866. sta_info_finish_pending(local);
  867. list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
  868. if (!sdata || sdata == sta->sdata)
  869. WARN_ON(__sta_info_destroy(sta));
  870. }
  871. mutex_unlock(&local->sta_mtx);
  872. return ret;
  873. }
  874. void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
  875. unsigned long exp_time)
  876. {
  877. struct ieee80211_local *local = sdata->local;
  878. struct sta_info *sta, *tmp;
  879. mutex_lock(&local->sta_mtx);
  880. list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
  881. if (time_after(jiffies, sta->last_rx + exp_time)) {
  882. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  883. printk(KERN_DEBUG "%s: expiring inactive STA %pM\n",
  884. sdata->name, sta->sta.addr);
  885. #endif
  886. WARN_ON(__sta_info_destroy(sta));
  887. }
  888. mutex_unlock(&local->sta_mtx);
  889. }
  890. struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
  891. const u8 *addr,
  892. const u8 *localaddr)
  893. {
  894. struct sta_info *sta, *nxt;
  895. /*
  896. * Just return a random station if localaddr is NULL
  897. * ... first in list.
  898. */
  899. for_each_sta_info(hw_to_local(hw), addr, sta, nxt) {
  900. if (localaddr &&
  901. compare_ether_addr(sta->sdata->vif.addr, localaddr) != 0)
  902. continue;
  903. if (!sta->uploaded)
  904. return NULL;
  905. return &sta->sta;
  906. }
  907. return NULL;
  908. }
  909. EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
  910. struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
  911. const u8 *addr)
  912. {
  913. struct sta_info *sta;
  914. if (!vif)
  915. return NULL;
  916. sta = sta_info_get_bss(vif_to_sdata(vif), addr);
  917. if (!sta)
  918. return NULL;
  919. if (!sta->uploaded)
  920. return NULL;
  921. return &sta->sta;
  922. }
  923. EXPORT_SYMBOL(ieee80211_find_sta);
  924. static void clear_sta_ps_flags(void *_sta)
  925. {
  926. struct sta_info *sta = _sta;
  927. clear_sta_flags(sta, WLAN_STA_PS_DRIVER | WLAN_STA_PS_STA);
  928. }
  929. /* powersave support code */
  930. void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
  931. {
  932. struct ieee80211_sub_if_data *sdata = sta->sdata;
  933. struct ieee80211_local *local = sdata->local;
  934. struct sk_buff_head pending;
  935. int filtered = 0, buffered = 0, ac;
  936. BUILD_BUG_ON(BITS_TO_LONGS(STA_TID_NUM) > 1);
  937. sta->driver_buffered_tids = 0;
  938. if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
  939. drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
  940. skb_queue_head_init(&pending);
  941. /* Send all buffered frames to the station */
  942. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  943. int count = skb_queue_len(&pending), tmp;
  944. skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
  945. tmp = skb_queue_len(&pending);
  946. filtered += tmp - count;
  947. count = tmp;
  948. skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
  949. tmp = skb_queue_len(&pending);
  950. buffered += tmp - count;
  951. }
  952. ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta);
  953. local->total_ps_buffered -= buffered;
  954. sta_info_recalc_tim(sta);
  955. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  956. printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames "
  957. "since STA not sleeping anymore\n", sdata->name,
  958. sta->sta.addr, sta->sta.aid, filtered, buffered);
  959. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  960. }
  961. void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
  962. {
  963. struct ieee80211_sub_if_data *sdata = sta->sdata;
  964. struct ieee80211_local *local = sdata->local;
  965. struct sk_buff *skb = NULL;
  966. bool more_data = false;
  967. int ac;
  968. u8 ignore_for_response = sta->sta.uapsd_queues;
  969. /*
  970. * If all ACs are delivery-enabled then we should reply
  971. * from any of them, if only some are enabled we reply
  972. * only from the non-enabled ones.
  973. */
  974. if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
  975. ignore_for_response = 0;
  976. /*
  977. * Get response frame and more data bit for it.
  978. */
  979. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  980. if (ignore_for_response & BIT(ac))
  981. continue;
  982. if (!skb) {
  983. skb = skb_dequeue(&sta->tx_filtered[ac]);
  984. if (!skb) {
  985. skb = skb_dequeue(&sta->ps_tx_buf[ac]);
  986. if (skb)
  987. local->total_ps_buffered--;
  988. }
  989. }
  990. /* FIXME: take into account driver-buffered frames */
  991. if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
  992. !skb_queue_empty(&sta->ps_tx_buf[ac])) {
  993. more_data = true;
  994. break;
  995. }
  996. }
  997. if (skb) {
  998. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  999. struct ieee80211_hdr *hdr =
  1000. (struct ieee80211_hdr *) skb->data;
  1001. /*
  1002. * Tell TX path to send this frame even though the STA may
  1003. * still remain is PS mode after this frame exchange.
  1004. */
  1005. info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE;
  1006. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  1007. printk(KERN_DEBUG "STA %pM aid %d: PS Poll\n",
  1008. sta->sta.addr, sta->sta.aid);
  1009. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  1010. /* Use MoreData flag to indicate whether there are more
  1011. * buffered frames for this STA */
  1012. if (!more_data)
  1013. hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  1014. else
  1015. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1016. ieee80211_add_pending_skb(local, skb);
  1017. sta_info_recalc_tim(sta);
  1018. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  1019. } else {
  1020. /*
  1021. * FIXME: This can be the result of a race condition between
  1022. * us expiring a frame and the station polling for it.
  1023. * Should we send it a null-func frame indicating we
  1024. * have nothing buffered for it?
  1025. */
  1026. printk(KERN_DEBUG "%s: STA %pM sent PS Poll even "
  1027. "though there are no buffered frames for it\n",
  1028. sdata->name, sta->sta.addr);
  1029. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  1030. }
  1031. }
  1032. void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
  1033. struct ieee80211_sta *pubsta, bool block)
  1034. {
  1035. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1036. trace_api_sta_block_awake(sta->local, pubsta, block);
  1037. if (block)
  1038. set_sta_flags(sta, WLAN_STA_PS_DRIVER);
  1039. else if (test_sta_flags(sta, WLAN_STA_PS_DRIVER))
  1040. ieee80211_queue_work(hw, &sta->drv_unblock_wk);
  1041. }
  1042. EXPORT_SYMBOL(ieee80211_sta_block_awake);
  1043. void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
  1044. u8 tid, bool buffered)
  1045. {
  1046. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1047. if (WARN_ON(tid >= STA_TID_NUM))
  1048. return;
  1049. if (buffered)
  1050. set_bit(tid, &sta->driver_buffered_tids);
  1051. else
  1052. clear_bit(tid, &sta->driver_buffered_tids);
  1053. sta_info_recalc_tim(sta);
  1054. }
  1055. EXPORT_SYMBOL(ieee80211_sta_set_buffered);