sta_info.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861
  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/etherdevice.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/types.h>
  14. #include <linux/slab.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/timer.h>
  18. #include <linux/rtnetlink.h>
  19. #include <net/mac80211.h>
  20. #include "ieee80211_i.h"
  21. #include "driver-ops.h"
  22. #include "rate.h"
  23. #include "sta_info.h"
  24. #include "debugfs_sta.h"
  25. #include "mesh.h"
  26. #include "wme.h"
  27. /**
  28. * DOC: STA information lifetime rules
  29. *
  30. * STA info structures (&struct sta_info) are managed in a hash table
  31. * for faster lookup and a list for iteration. They are managed using
  32. * RCU, i.e. access to the list and hash table is protected by RCU.
  33. *
  34. * Upon allocating a STA info structure with sta_info_alloc(), the caller
  35. * owns that structure. It must then insert it into the hash table using
  36. * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
  37. * case (which acquires an rcu read section but must not be called from
  38. * within one) will the pointer still be valid after the call. Note that
  39. * the caller may not do much with the STA info before inserting it, in
  40. * particular, it may not start any mesh peer link management or add
  41. * encryption keys.
  42. *
  43. * When the insertion fails (sta_info_insert()) returns non-zero), the
  44. * structure will have been freed by sta_info_insert()!
  45. *
  46. * Station entries are added by mac80211 when you establish a link with a
  47. * peer. This means different things for the different type of interfaces
  48. * we support. For a regular station this mean we add the AP sta when we
  49. * receive an association response from the AP. For IBSS this occurs when
  50. * get to know about a peer on the same IBSS. For WDS we add the sta for
  51. * the peer immediately upon device open. When using AP mode we add stations
  52. * for each respective station upon request from userspace through nl80211.
  53. *
  54. * In order to remove a STA info structure, various sta_info_destroy_*()
  55. * calls are available.
  56. *
  57. * There is no concept of ownership on a STA entry, each structure is
  58. * owned by the global hash table/list until it is removed. All users of
  59. * the structure need to be RCU protected so that the structure won't be
  60. * freed before they are done using it.
  61. */
  62. /* Caller must hold local->sta_mtx */
  63. static int sta_info_hash_del(struct ieee80211_local *local,
  64. struct sta_info *sta)
  65. {
  66. struct sta_info *s;
  67. s = rcu_dereference_protected(local->sta_hash[STA_HASH(sta->sta.addr)],
  68. lockdep_is_held(&local->sta_mtx));
  69. if (!s)
  70. return -ENOENT;
  71. if (s == sta) {
  72. rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)],
  73. s->hnext);
  74. return 0;
  75. }
  76. while (rcu_access_pointer(s->hnext) &&
  77. rcu_access_pointer(s->hnext) != sta)
  78. s = rcu_dereference_protected(s->hnext,
  79. lockdep_is_held(&local->sta_mtx));
  80. if (rcu_access_pointer(s->hnext)) {
  81. rcu_assign_pointer(s->hnext, sta->hnext);
  82. return 0;
  83. }
  84. return -ENOENT;
  85. }
  86. static void __cleanup_single_sta(struct sta_info *sta)
  87. {
  88. int ac, i;
  89. struct tid_ampdu_tx *tid_tx;
  90. struct ieee80211_sub_if_data *sdata = sta->sdata;
  91. struct ieee80211_local *local = sdata->local;
  92. struct ps_data *ps;
  93. if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
  94. test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
  95. test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
  96. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  97. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  98. ps = &sdata->bss->ps;
  99. else if (ieee80211_vif_is_mesh(&sdata->vif))
  100. ps = &sdata->u.mesh.ps;
  101. else
  102. return;
  103. clear_sta_flag(sta, WLAN_STA_PS_STA);
  104. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  105. clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
  106. atomic_dec(&ps->num_sta_ps);
  107. sta_info_recalc_tim(sta);
  108. }
  109. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  110. local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
  111. ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
  112. ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
  113. }
  114. if (ieee80211_vif_is_mesh(&sdata->vif))
  115. mesh_sta_cleanup(sta);
  116. cancel_work_sync(&sta->drv_deliver_wk);
  117. /*
  118. * Destroy aggregation state here. It would be nice to wait for the
  119. * driver to finish aggregation stop and then clean up, but for now
  120. * drivers have to handle aggregation stop being requested, followed
  121. * directly by station destruction.
  122. */
  123. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  124. kfree(sta->ampdu_mlme.tid_start_tx[i]);
  125. tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
  126. if (!tid_tx)
  127. continue;
  128. ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
  129. kfree(tid_tx);
  130. }
  131. }
  132. static void cleanup_single_sta(struct sta_info *sta)
  133. {
  134. struct ieee80211_sub_if_data *sdata = sta->sdata;
  135. struct ieee80211_local *local = sdata->local;
  136. __cleanup_single_sta(sta);
  137. sta_info_free(local, sta);
  138. }
  139. /* protected by RCU */
  140. struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
  141. const u8 *addr)
  142. {
  143. struct ieee80211_local *local = sdata->local;
  144. struct sta_info *sta;
  145. sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
  146. lockdep_is_held(&local->sta_mtx));
  147. while (sta) {
  148. if (sta->sdata == sdata &&
  149. ether_addr_equal(sta->sta.addr, addr))
  150. break;
  151. sta = rcu_dereference_check(sta->hnext,
  152. lockdep_is_held(&local->sta_mtx));
  153. }
  154. return sta;
  155. }
  156. /*
  157. * Get sta info either from the specified interface
  158. * or from one of its vlans
  159. */
  160. struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
  161. const u8 *addr)
  162. {
  163. struct ieee80211_local *local = sdata->local;
  164. struct sta_info *sta;
  165. sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
  166. lockdep_is_held(&local->sta_mtx));
  167. while (sta) {
  168. if ((sta->sdata == sdata ||
  169. (sta->sdata->bss && sta->sdata->bss == sdata->bss)) &&
  170. ether_addr_equal(sta->sta.addr, addr))
  171. break;
  172. sta = rcu_dereference_check(sta->hnext,
  173. lockdep_is_held(&local->sta_mtx));
  174. }
  175. return sta;
  176. }
  177. struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
  178. int idx)
  179. {
  180. struct ieee80211_local *local = sdata->local;
  181. struct sta_info *sta;
  182. int i = 0;
  183. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  184. if (sdata != sta->sdata)
  185. continue;
  186. if (i < idx) {
  187. ++i;
  188. continue;
  189. }
  190. return sta;
  191. }
  192. return NULL;
  193. }
  194. /**
  195. * sta_info_free - free STA
  196. *
  197. * @local: pointer to the global information
  198. * @sta: STA info to free
  199. *
  200. * This function must undo everything done by sta_info_alloc()
  201. * that may happen before sta_info_insert(). It may only be
  202. * called when sta_info_insert() has not been attempted (and
  203. * if that fails, the station is freed anyway.)
  204. */
  205. void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
  206. {
  207. int i;
  208. if (sta->rate_ctrl)
  209. rate_control_free_sta(sta);
  210. if (sta->tx_lat) {
  211. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  212. kfree(sta->tx_lat[i].bins);
  213. kfree(sta->tx_lat);
  214. }
  215. sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
  216. kfree(rcu_dereference_raw(sta->sta.rates));
  217. kfree(sta);
  218. }
  219. /* Caller must hold local->sta_mtx */
  220. static void sta_info_hash_add(struct ieee80211_local *local,
  221. struct sta_info *sta)
  222. {
  223. lockdep_assert_held(&local->sta_mtx);
  224. sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
  225. rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
  226. }
  227. static void sta_deliver_ps_frames(struct work_struct *wk)
  228. {
  229. struct sta_info *sta;
  230. sta = container_of(wk, struct sta_info, drv_deliver_wk);
  231. if (sta->dead)
  232. return;
  233. local_bh_disable();
  234. if (!test_sta_flag(sta, WLAN_STA_PS_STA))
  235. ieee80211_sta_ps_deliver_wakeup(sta);
  236. else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
  237. ieee80211_sta_ps_deliver_poll_response(sta);
  238. else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
  239. ieee80211_sta_ps_deliver_uapsd(sta);
  240. local_bh_enable();
  241. }
  242. static int sta_prepare_rate_control(struct ieee80211_local *local,
  243. struct sta_info *sta, gfp_t gfp)
  244. {
  245. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  246. return 0;
  247. sta->rate_ctrl = local->rate_ctrl;
  248. sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
  249. &sta->sta, gfp);
  250. if (!sta->rate_ctrl_priv)
  251. return -ENOMEM;
  252. return 0;
  253. }
  254. struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
  255. const u8 *addr, gfp_t gfp)
  256. {
  257. struct ieee80211_local *local = sdata->local;
  258. struct sta_info *sta;
  259. struct timespec uptime;
  260. struct ieee80211_tx_latency_bin_ranges *tx_latency;
  261. int i;
  262. sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
  263. if (!sta)
  264. return NULL;
  265. rcu_read_lock();
  266. tx_latency = rcu_dereference(local->tx_latency);
  267. /* init stations Tx latency statistics && TID bins */
  268. if (tx_latency) {
  269. sta->tx_lat = kzalloc(IEEE80211_NUM_TIDS *
  270. sizeof(struct ieee80211_tx_latency_stat),
  271. GFP_ATOMIC);
  272. if (!sta->tx_lat) {
  273. rcu_read_unlock();
  274. goto free;
  275. }
  276. if (tx_latency->n_ranges) {
  277. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  278. /* size of bins is size of the ranges +1 */
  279. sta->tx_lat[i].bin_count =
  280. tx_latency->n_ranges + 1;
  281. sta->tx_lat[i].bins =
  282. kcalloc(sta->tx_lat[i].bin_count,
  283. sizeof(u32), GFP_ATOMIC);
  284. if (!sta->tx_lat[i].bins) {
  285. rcu_read_unlock();
  286. goto free;
  287. }
  288. }
  289. }
  290. }
  291. rcu_read_unlock();
  292. spin_lock_init(&sta->lock);
  293. spin_lock_init(&sta->ps_lock);
  294. INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
  295. INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
  296. mutex_init(&sta->ampdu_mlme.mtx);
  297. #ifdef CONFIG_MAC80211_MESH
  298. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  299. !sdata->u.mesh.user_mpm)
  300. init_timer(&sta->plink_timer);
  301. sta->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
  302. #endif
  303. memcpy(sta->sta.addr, addr, ETH_ALEN);
  304. sta->local = local;
  305. sta->sdata = sdata;
  306. sta->last_rx = jiffies;
  307. sta->sta_state = IEEE80211_STA_NONE;
  308. ktime_get_ts(&uptime);
  309. sta->last_connected = uptime.tv_sec;
  310. ewma_init(&sta->avg_signal, 1024, 8);
  311. for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
  312. ewma_init(&sta->chain_signal_avg[i], 1024, 8);
  313. if (sta_prepare_rate_control(local, sta, gfp))
  314. goto free;
  315. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  316. /*
  317. * timer_to_tid must be initialized with identity mapping
  318. * to enable session_timer's data differentiation. See
  319. * sta_rx_agg_session_timer_expired for usage.
  320. */
  321. sta->timer_to_tid[i] = i;
  322. }
  323. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  324. skb_queue_head_init(&sta->ps_tx_buf[i]);
  325. skb_queue_head_init(&sta->tx_filtered[i]);
  326. }
  327. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  328. sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
  329. sta->sta.smps_mode = IEEE80211_SMPS_OFF;
  330. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  331. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  332. struct ieee80211_supported_band *sband =
  333. local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)];
  334. u8 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
  335. IEEE80211_HT_CAP_SM_PS_SHIFT;
  336. /*
  337. * Assume that hostapd advertises our caps in the beacon and
  338. * this is the known_smps_mode for a station that just assciated
  339. */
  340. switch (smps) {
  341. case WLAN_HT_SMPS_CONTROL_DISABLED:
  342. sta->known_smps_mode = IEEE80211_SMPS_OFF;
  343. break;
  344. case WLAN_HT_SMPS_CONTROL_STATIC:
  345. sta->known_smps_mode = IEEE80211_SMPS_STATIC;
  346. break;
  347. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  348. sta->known_smps_mode = IEEE80211_SMPS_DYNAMIC;
  349. break;
  350. default:
  351. WARN_ON(1);
  352. }
  353. }
  354. sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
  355. return sta;
  356. free:
  357. if (sta->tx_lat) {
  358. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  359. kfree(sta->tx_lat[i].bins);
  360. kfree(sta->tx_lat);
  361. }
  362. kfree(sta);
  363. return NULL;
  364. }
  365. static int sta_info_insert_check(struct sta_info *sta)
  366. {
  367. struct ieee80211_sub_if_data *sdata = sta->sdata;
  368. /*
  369. * Can't be a WARN_ON because it can be triggered through a race:
  370. * something inserts a STA (on one CPU) without holding the RTNL
  371. * and another CPU turns off the net device.
  372. */
  373. if (unlikely(!ieee80211_sdata_running(sdata)))
  374. return -ENETDOWN;
  375. if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
  376. is_multicast_ether_addr(sta->sta.addr)))
  377. return -EINVAL;
  378. return 0;
  379. }
  380. static int sta_info_insert_drv_state(struct ieee80211_local *local,
  381. struct ieee80211_sub_if_data *sdata,
  382. struct sta_info *sta)
  383. {
  384. enum ieee80211_sta_state state;
  385. int err = 0;
  386. for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
  387. err = drv_sta_state(local, sdata, sta, state, state + 1);
  388. if (err)
  389. break;
  390. }
  391. if (!err) {
  392. /*
  393. * Drivers using legacy sta_add/sta_remove callbacks only
  394. * get uploaded set to true after sta_add is called.
  395. */
  396. if (!local->ops->sta_add)
  397. sta->uploaded = true;
  398. return 0;
  399. }
  400. if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  401. sdata_info(sdata,
  402. "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
  403. sta->sta.addr, state + 1, err);
  404. err = 0;
  405. }
  406. /* unwind on error */
  407. for (; state > IEEE80211_STA_NOTEXIST; state--)
  408. WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
  409. return err;
  410. }
  411. /*
  412. * should be called with sta_mtx locked
  413. * this function replaces the mutex lock
  414. * with a RCU lock
  415. */
  416. static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
  417. {
  418. struct ieee80211_local *local = sta->local;
  419. struct ieee80211_sub_if_data *sdata = sta->sdata;
  420. struct station_info sinfo;
  421. int err = 0;
  422. lockdep_assert_held(&local->sta_mtx);
  423. /* check if STA exists already */
  424. if (sta_info_get_bss(sdata, sta->sta.addr)) {
  425. err = -EEXIST;
  426. goto out_err;
  427. }
  428. local->num_sta++;
  429. local->sta_generation++;
  430. smp_mb();
  431. /* simplify things and don't accept BA sessions yet */
  432. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  433. /* make the station visible */
  434. sta_info_hash_add(local, sta);
  435. list_add_rcu(&sta->list, &local->sta_list);
  436. /* notify driver */
  437. err = sta_info_insert_drv_state(local, sdata, sta);
  438. if (err)
  439. goto out_remove;
  440. set_sta_flag(sta, WLAN_STA_INSERTED);
  441. /* accept BA sessions now */
  442. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  443. ieee80211_recalc_min_chandef(sdata);
  444. ieee80211_sta_debugfs_add(sta);
  445. rate_control_add_sta_debugfs(sta);
  446. memset(&sinfo, 0, sizeof(sinfo));
  447. sinfo.filled = 0;
  448. sinfo.generation = local->sta_generation;
  449. cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
  450. sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
  451. /* move reference to rcu-protected */
  452. rcu_read_lock();
  453. mutex_unlock(&local->sta_mtx);
  454. if (ieee80211_vif_is_mesh(&sdata->vif))
  455. mesh_accept_plinks_update(sdata);
  456. return 0;
  457. out_remove:
  458. sta_info_hash_del(local, sta);
  459. list_del_rcu(&sta->list);
  460. local->num_sta--;
  461. synchronize_net();
  462. __cleanup_single_sta(sta);
  463. out_err:
  464. mutex_unlock(&local->sta_mtx);
  465. rcu_read_lock();
  466. return err;
  467. }
  468. int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
  469. {
  470. struct ieee80211_local *local = sta->local;
  471. int err;
  472. might_sleep();
  473. err = sta_info_insert_check(sta);
  474. if (err) {
  475. rcu_read_lock();
  476. goto out_free;
  477. }
  478. mutex_lock(&local->sta_mtx);
  479. err = sta_info_insert_finish(sta);
  480. if (err)
  481. goto out_free;
  482. return 0;
  483. out_free:
  484. sta_info_free(local, sta);
  485. return err;
  486. }
  487. int sta_info_insert(struct sta_info *sta)
  488. {
  489. int err = sta_info_insert_rcu(sta);
  490. rcu_read_unlock();
  491. return err;
  492. }
  493. static inline void __bss_tim_set(u8 *tim, u16 id)
  494. {
  495. /*
  496. * This format has been mandated by the IEEE specifications,
  497. * so this line may not be changed to use the __set_bit() format.
  498. */
  499. tim[id / 8] |= (1 << (id % 8));
  500. }
  501. static inline void __bss_tim_clear(u8 *tim, u16 id)
  502. {
  503. /*
  504. * This format has been mandated by the IEEE specifications,
  505. * so this line may not be changed to use the __clear_bit() format.
  506. */
  507. tim[id / 8] &= ~(1 << (id % 8));
  508. }
  509. static inline bool __bss_tim_get(u8 *tim, u16 id)
  510. {
  511. /*
  512. * This format has been mandated by the IEEE specifications,
  513. * so this line may not be changed to use the test_bit() format.
  514. */
  515. return tim[id / 8] & (1 << (id % 8));
  516. }
  517. static unsigned long ieee80211_tids_for_ac(int ac)
  518. {
  519. /* If we ever support TIDs > 7, this obviously needs to be adjusted */
  520. switch (ac) {
  521. case IEEE80211_AC_VO:
  522. return BIT(6) | BIT(7);
  523. case IEEE80211_AC_VI:
  524. return BIT(4) | BIT(5);
  525. case IEEE80211_AC_BE:
  526. return BIT(0) | BIT(3);
  527. case IEEE80211_AC_BK:
  528. return BIT(1) | BIT(2);
  529. default:
  530. WARN_ON(1);
  531. return 0;
  532. }
  533. }
  534. void sta_info_recalc_tim(struct sta_info *sta)
  535. {
  536. struct ieee80211_local *local = sta->local;
  537. struct ps_data *ps;
  538. bool indicate_tim = false;
  539. u8 ignore_for_tim = sta->sta.uapsd_queues;
  540. int ac;
  541. u16 id;
  542. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  543. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  544. if (WARN_ON_ONCE(!sta->sdata->bss))
  545. return;
  546. ps = &sta->sdata->bss->ps;
  547. id = sta->sta.aid;
  548. #ifdef CONFIG_MAC80211_MESH
  549. } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
  550. ps = &sta->sdata->u.mesh.ps;
  551. /* TIM map only for 1 <= PLID <= IEEE80211_MAX_AID */
  552. id = sta->plid % (IEEE80211_MAX_AID + 1);
  553. #endif
  554. } else {
  555. return;
  556. }
  557. /* No need to do anything if the driver does all */
  558. if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
  559. return;
  560. if (sta->dead)
  561. goto done;
  562. /*
  563. * If all ACs are delivery-enabled then we should build
  564. * the TIM bit for all ACs anyway; if only some are then
  565. * we ignore those and build the TIM bit using only the
  566. * non-enabled ones.
  567. */
  568. if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
  569. ignore_for_tim = 0;
  570. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  571. unsigned long tids;
  572. if (ignore_for_tim & BIT(ac))
  573. continue;
  574. indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
  575. !skb_queue_empty(&sta->ps_tx_buf[ac]);
  576. if (indicate_tim)
  577. break;
  578. tids = ieee80211_tids_for_ac(ac);
  579. indicate_tim |=
  580. sta->driver_buffered_tids & tids;
  581. }
  582. done:
  583. spin_lock_bh(&local->tim_lock);
  584. if (indicate_tim == __bss_tim_get(ps->tim, id))
  585. goto out_unlock;
  586. if (indicate_tim)
  587. __bss_tim_set(ps->tim, id);
  588. else
  589. __bss_tim_clear(ps->tim, id);
  590. if (local->ops->set_tim) {
  591. local->tim_in_locked_section = true;
  592. drv_set_tim(local, &sta->sta, indicate_tim);
  593. local->tim_in_locked_section = false;
  594. }
  595. out_unlock:
  596. spin_unlock_bh(&local->tim_lock);
  597. }
  598. static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
  599. {
  600. struct ieee80211_tx_info *info;
  601. int timeout;
  602. if (!skb)
  603. return false;
  604. info = IEEE80211_SKB_CB(skb);
  605. /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
  606. timeout = (sta->listen_interval *
  607. sta->sdata->vif.bss_conf.beacon_int *
  608. 32 / 15625) * HZ;
  609. if (timeout < STA_TX_BUFFER_EXPIRE)
  610. timeout = STA_TX_BUFFER_EXPIRE;
  611. return time_after(jiffies, info->control.jiffies + timeout);
  612. }
  613. static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
  614. struct sta_info *sta, int ac)
  615. {
  616. unsigned long flags;
  617. struct sk_buff *skb;
  618. /*
  619. * First check for frames that should expire on the filtered
  620. * queue. Frames here were rejected by the driver and are on
  621. * a separate queue to avoid reordering with normal PS-buffered
  622. * frames. They also aren't accounted for right now in the
  623. * total_ps_buffered counter.
  624. */
  625. for (;;) {
  626. spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
  627. skb = skb_peek(&sta->tx_filtered[ac]);
  628. if (sta_info_buffer_expired(sta, skb))
  629. skb = __skb_dequeue(&sta->tx_filtered[ac]);
  630. else
  631. skb = NULL;
  632. spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
  633. /*
  634. * Frames are queued in order, so if this one
  635. * hasn't expired yet we can stop testing. If
  636. * we actually reached the end of the queue we
  637. * also need to stop, of course.
  638. */
  639. if (!skb)
  640. break;
  641. ieee80211_free_txskb(&local->hw, skb);
  642. }
  643. /*
  644. * Now also check the normal PS-buffered queue, this will
  645. * only find something if the filtered queue was emptied
  646. * since the filtered frames are all before the normal PS
  647. * buffered frames.
  648. */
  649. for (;;) {
  650. spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
  651. skb = skb_peek(&sta->ps_tx_buf[ac]);
  652. if (sta_info_buffer_expired(sta, skb))
  653. skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
  654. else
  655. skb = NULL;
  656. spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
  657. /*
  658. * frames are queued in order, so if this one
  659. * hasn't expired yet (or we reached the end of
  660. * the queue) we can stop testing
  661. */
  662. if (!skb)
  663. break;
  664. local->total_ps_buffered--;
  665. ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
  666. sta->sta.addr);
  667. ieee80211_free_txskb(&local->hw, skb);
  668. }
  669. /*
  670. * Finally, recalculate the TIM bit for this station -- it might
  671. * now be clear because the station was too slow to retrieve its
  672. * frames.
  673. */
  674. sta_info_recalc_tim(sta);
  675. /*
  676. * Return whether there are any frames still buffered, this is
  677. * used to check whether the cleanup timer still needs to run,
  678. * if there are no frames we don't need to rearm the timer.
  679. */
  680. return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
  681. skb_queue_empty(&sta->tx_filtered[ac]));
  682. }
  683. static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
  684. struct sta_info *sta)
  685. {
  686. bool have_buffered = false;
  687. int ac;
  688. /* This is only necessary for stations on BSS/MBSS interfaces */
  689. if (!sta->sdata->bss &&
  690. !ieee80211_vif_is_mesh(&sta->sdata->vif))
  691. return false;
  692. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  693. have_buffered |=
  694. sta_info_cleanup_expire_buffered_ac(local, sta, ac);
  695. return have_buffered;
  696. }
  697. static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
  698. {
  699. struct ieee80211_local *local;
  700. struct ieee80211_sub_if_data *sdata;
  701. int ret;
  702. might_sleep();
  703. if (!sta)
  704. return -ENOENT;
  705. local = sta->local;
  706. sdata = sta->sdata;
  707. lockdep_assert_held(&local->sta_mtx);
  708. /*
  709. * Before removing the station from the driver and
  710. * rate control, it might still start new aggregation
  711. * sessions -- block that to make sure the tear-down
  712. * will be sufficient.
  713. */
  714. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  715. ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
  716. ret = sta_info_hash_del(local, sta);
  717. if (WARN_ON(ret))
  718. return ret;
  719. list_del_rcu(&sta->list);
  720. drv_sta_pre_rcu_remove(local, sta->sdata, sta);
  721. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  722. rcu_access_pointer(sdata->u.vlan.sta) == sta)
  723. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  724. return 0;
  725. }
  726. static void __sta_info_destroy_part2(struct sta_info *sta)
  727. {
  728. struct ieee80211_local *local = sta->local;
  729. struct ieee80211_sub_if_data *sdata = sta->sdata;
  730. int ret;
  731. /*
  732. * NOTE: This assumes at least synchronize_net() was done
  733. * after _part1 and before _part2!
  734. */
  735. might_sleep();
  736. lockdep_assert_held(&local->sta_mtx);
  737. /* now keys can no longer be reached */
  738. ieee80211_free_sta_keys(local, sta);
  739. sta->dead = true;
  740. local->num_sta--;
  741. local->sta_generation++;
  742. while (sta->sta_state > IEEE80211_STA_NONE) {
  743. ret = sta_info_move_state(sta, sta->sta_state - 1);
  744. if (ret) {
  745. WARN_ON_ONCE(1);
  746. break;
  747. }
  748. }
  749. if (sta->uploaded) {
  750. ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
  751. IEEE80211_STA_NOTEXIST);
  752. WARN_ON_ONCE(ret != 0);
  753. }
  754. sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
  755. cfg80211_del_sta(sdata->dev, sta->sta.addr, GFP_KERNEL);
  756. rate_control_remove_sta_debugfs(sta);
  757. ieee80211_sta_debugfs_remove(sta);
  758. ieee80211_recalc_min_chandef(sdata);
  759. cleanup_single_sta(sta);
  760. }
  761. int __must_check __sta_info_destroy(struct sta_info *sta)
  762. {
  763. int err = __sta_info_destroy_part1(sta);
  764. if (err)
  765. return err;
  766. synchronize_net();
  767. __sta_info_destroy_part2(sta);
  768. return 0;
  769. }
  770. int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
  771. {
  772. struct sta_info *sta;
  773. int ret;
  774. mutex_lock(&sdata->local->sta_mtx);
  775. sta = sta_info_get(sdata, addr);
  776. ret = __sta_info_destroy(sta);
  777. mutex_unlock(&sdata->local->sta_mtx);
  778. return ret;
  779. }
  780. int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
  781. const u8 *addr)
  782. {
  783. struct sta_info *sta;
  784. int ret;
  785. mutex_lock(&sdata->local->sta_mtx);
  786. sta = sta_info_get_bss(sdata, addr);
  787. ret = __sta_info_destroy(sta);
  788. mutex_unlock(&sdata->local->sta_mtx);
  789. return ret;
  790. }
  791. static void sta_info_cleanup(unsigned long data)
  792. {
  793. struct ieee80211_local *local = (struct ieee80211_local *) data;
  794. struct sta_info *sta;
  795. bool timer_needed = false;
  796. rcu_read_lock();
  797. list_for_each_entry_rcu(sta, &local->sta_list, list)
  798. if (sta_info_cleanup_expire_buffered(local, sta))
  799. timer_needed = true;
  800. rcu_read_unlock();
  801. if (local->quiescing)
  802. return;
  803. if (!timer_needed)
  804. return;
  805. mod_timer(&local->sta_cleanup,
  806. round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
  807. }
  808. void sta_info_init(struct ieee80211_local *local)
  809. {
  810. spin_lock_init(&local->tim_lock);
  811. mutex_init(&local->sta_mtx);
  812. INIT_LIST_HEAD(&local->sta_list);
  813. setup_timer(&local->sta_cleanup, sta_info_cleanup,
  814. (unsigned long)local);
  815. }
  816. void sta_info_stop(struct ieee80211_local *local)
  817. {
  818. del_timer_sync(&local->sta_cleanup);
  819. }
  820. int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
  821. {
  822. struct ieee80211_local *local = sdata->local;
  823. struct sta_info *sta, *tmp;
  824. LIST_HEAD(free_list);
  825. int ret = 0;
  826. might_sleep();
  827. WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
  828. WARN_ON(vlans && !sdata->bss);
  829. mutex_lock(&local->sta_mtx);
  830. list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
  831. if (sdata == sta->sdata ||
  832. (vlans && sdata->bss == sta->sdata->bss)) {
  833. if (!WARN_ON(__sta_info_destroy_part1(sta)))
  834. list_add(&sta->free_list, &free_list);
  835. ret++;
  836. }
  837. }
  838. if (!list_empty(&free_list)) {
  839. synchronize_net();
  840. list_for_each_entry_safe(sta, tmp, &free_list, free_list)
  841. __sta_info_destroy_part2(sta);
  842. }
  843. mutex_unlock(&local->sta_mtx);
  844. return ret;
  845. }
  846. void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
  847. unsigned long exp_time)
  848. {
  849. struct ieee80211_local *local = sdata->local;
  850. struct sta_info *sta, *tmp;
  851. mutex_lock(&local->sta_mtx);
  852. list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
  853. if (sdata != sta->sdata)
  854. continue;
  855. if (time_after(jiffies, sta->last_rx + exp_time)) {
  856. sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
  857. sta->sta.addr);
  858. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  859. test_sta_flag(sta, WLAN_STA_PS_STA))
  860. atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
  861. WARN_ON(__sta_info_destroy(sta));
  862. }
  863. }
  864. mutex_unlock(&local->sta_mtx);
  865. }
  866. struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
  867. const u8 *addr,
  868. const u8 *localaddr)
  869. {
  870. struct sta_info *sta, *nxt;
  871. /*
  872. * Just return a random station if localaddr is NULL
  873. * ... first in list.
  874. */
  875. for_each_sta_info(hw_to_local(hw), addr, sta, nxt) {
  876. if (localaddr &&
  877. !ether_addr_equal(sta->sdata->vif.addr, localaddr))
  878. continue;
  879. if (!sta->uploaded)
  880. return NULL;
  881. return &sta->sta;
  882. }
  883. return NULL;
  884. }
  885. EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
  886. struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
  887. const u8 *addr)
  888. {
  889. struct sta_info *sta;
  890. if (!vif)
  891. return NULL;
  892. sta = sta_info_get_bss(vif_to_sdata(vif), addr);
  893. if (!sta)
  894. return NULL;
  895. if (!sta->uploaded)
  896. return NULL;
  897. return &sta->sta;
  898. }
  899. EXPORT_SYMBOL(ieee80211_find_sta);
  900. /* powersave support code */
  901. void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
  902. {
  903. struct ieee80211_sub_if_data *sdata = sta->sdata;
  904. struct ieee80211_local *local = sdata->local;
  905. struct sk_buff_head pending;
  906. int filtered = 0, buffered = 0, ac;
  907. unsigned long flags;
  908. struct ps_data *ps;
  909. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  910. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  911. u.ap);
  912. if (sdata->vif.type == NL80211_IFTYPE_AP)
  913. ps = &sdata->bss->ps;
  914. else if (ieee80211_vif_is_mesh(&sdata->vif))
  915. ps = &sdata->u.mesh.ps;
  916. else
  917. return;
  918. clear_sta_flag(sta, WLAN_STA_SP);
  919. BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
  920. sta->driver_buffered_tids = 0;
  921. if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
  922. drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
  923. skb_queue_head_init(&pending);
  924. /* sync with ieee80211_tx_h_unicast_ps_buf */
  925. spin_lock(&sta->ps_lock);
  926. /* Send all buffered frames to the station */
  927. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  928. int count = skb_queue_len(&pending), tmp;
  929. spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
  930. skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
  931. spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
  932. tmp = skb_queue_len(&pending);
  933. filtered += tmp - count;
  934. count = tmp;
  935. spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
  936. skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
  937. spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
  938. tmp = skb_queue_len(&pending);
  939. buffered += tmp - count;
  940. }
  941. ieee80211_add_pending_skbs(local, &pending);
  942. /* now we're no longer in the deliver code */
  943. clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
  944. /* The station might have polled and then woken up before we responded,
  945. * so clear these flags now to avoid them sticking around.
  946. */
  947. clear_sta_flag(sta, WLAN_STA_PSPOLL);
  948. clear_sta_flag(sta, WLAN_STA_UAPSD);
  949. spin_unlock(&sta->ps_lock);
  950. atomic_dec(&ps->num_sta_ps);
  951. /* This station just woke up and isn't aware of our SMPS state */
  952. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  953. !ieee80211_smps_is_restrictive(sta->known_smps_mode,
  954. sdata->smps_mode) &&
  955. sta->known_smps_mode != sdata->bss->req_smps &&
  956. sta_info_tx_streams(sta) != 1) {
  957. ht_dbg(sdata,
  958. "%pM just woke up and MIMO capable - update SMPS\n",
  959. sta->sta.addr);
  960. ieee80211_send_smps_action(sdata, sdata->bss->req_smps,
  961. sta->sta.addr,
  962. sdata->vif.bss_conf.bssid);
  963. }
  964. local->total_ps_buffered -= buffered;
  965. sta_info_recalc_tim(sta);
  966. ps_dbg(sdata,
  967. "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
  968. sta->sta.addr, sta->sta.aid, filtered, buffered);
  969. }
  970. static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
  971. struct sta_info *sta, int tid,
  972. enum ieee80211_frame_release_type reason,
  973. bool call_driver)
  974. {
  975. struct ieee80211_local *local = sdata->local;
  976. struct ieee80211_qos_hdr *nullfunc;
  977. struct sk_buff *skb;
  978. int size = sizeof(*nullfunc);
  979. __le16 fc;
  980. bool qos = test_sta_flag(sta, WLAN_STA_WME);
  981. struct ieee80211_tx_info *info;
  982. struct ieee80211_chanctx_conf *chanctx_conf;
  983. if (qos) {
  984. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  985. IEEE80211_STYPE_QOS_NULLFUNC |
  986. IEEE80211_FCTL_FROMDS);
  987. } else {
  988. size -= 2;
  989. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  990. IEEE80211_STYPE_NULLFUNC |
  991. IEEE80211_FCTL_FROMDS);
  992. }
  993. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  994. if (!skb)
  995. return;
  996. skb_reserve(skb, local->hw.extra_tx_headroom);
  997. nullfunc = (void *) skb_put(skb, size);
  998. nullfunc->frame_control = fc;
  999. nullfunc->duration_id = 0;
  1000. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  1001. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  1002. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  1003. nullfunc->seq_ctrl = 0;
  1004. skb->priority = tid;
  1005. skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
  1006. if (qos) {
  1007. nullfunc->qos_ctrl = cpu_to_le16(tid);
  1008. if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
  1009. nullfunc->qos_ctrl |=
  1010. cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
  1011. }
  1012. info = IEEE80211_SKB_CB(skb);
  1013. /*
  1014. * Tell TX path to send this frame even though the
  1015. * STA may still remain is PS mode after this frame
  1016. * exchange. Also set EOSP to indicate this packet
  1017. * ends the poll/service period.
  1018. */
  1019. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
  1020. IEEE80211_TX_CTL_PS_RESPONSE |
  1021. IEEE80211_TX_STATUS_EOSP |
  1022. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1023. if (call_driver)
  1024. drv_allow_buffered_frames(local, sta, BIT(tid), 1,
  1025. reason, false);
  1026. skb->dev = sdata->dev;
  1027. rcu_read_lock();
  1028. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1029. if (WARN_ON(!chanctx_conf)) {
  1030. rcu_read_unlock();
  1031. kfree_skb(skb);
  1032. return;
  1033. }
  1034. ieee80211_xmit(sdata, skb, chanctx_conf->def.chan->band);
  1035. rcu_read_unlock();
  1036. }
  1037. static int find_highest_prio_tid(unsigned long tids)
  1038. {
  1039. /* lower 3 TIDs aren't ordered perfectly */
  1040. if (tids & 0xF8)
  1041. return fls(tids) - 1;
  1042. /* TID 0 is BE just like TID 3 */
  1043. if (tids & BIT(0))
  1044. return 0;
  1045. return fls(tids) - 1;
  1046. }
  1047. static void
  1048. ieee80211_sta_ps_deliver_response(struct sta_info *sta,
  1049. int n_frames, u8 ignored_acs,
  1050. enum ieee80211_frame_release_type reason)
  1051. {
  1052. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1053. struct ieee80211_local *local = sdata->local;
  1054. bool more_data = false;
  1055. int ac;
  1056. unsigned long driver_release_tids = 0;
  1057. struct sk_buff_head frames;
  1058. /* Service or PS-Poll period starts */
  1059. set_sta_flag(sta, WLAN_STA_SP);
  1060. __skb_queue_head_init(&frames);
  1061. /* Get response frame(s) and more data bit for the last one. */
  1062. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1063. unsigned long tids;
  1064. if (ignored_acs & BIT(ac))
  1065. continue;
  1066. tids = ieee80211_tids_for_ac(ac);
  1067. /* if we already have frames from software, then we can't also
  1068. * release from hardware queues
  1069. */
  1070. if (skb_queue_empty(&frames))
  1071. driver_release_tids |= sta->driver_buffered_tids & tids;
  1072. if (driver_release_tids) {
  1073. /* If the driver has data on more than one TID then
  1074. * certainly there's more data if we release just a
  1075. * single frame now (from a single TID). This will
  1076. * only happen for PS-Poll.
  1077. */
  1078. if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
  1079. hweight16(driver_release_tids) > 1) {
  1080. more_data = true;
  1081. driver_release_tids =
  1082. BIT(find_highest_prio_tid(
  1083. driver_release_tids));
  1084. break;
  1085. }
  1086. } else {
  1087. struct sk_buff *skb;
  1088. while (n_frames > 0) {
  1089. skb = skb_dequeue(&sta->tx_filtered[ac]);
  1090. if (!skb) {
  1091. skb = skb_dequeue(
  1092. &sta->ps_tx_buf[ac]);
  1093. if (skb)
  1094. local->total_ps_buffered--;
  1095. }
  1096. if (!skb)
  1097. break;
  1098. n_frames--;
  1099. __skb_queue_tail(&frames, skb);
  1100. }
  1101. }
  1102. /* If we have more frames buffered on this AC, then set the
  1103. * more-data bit and abort the loop since we can't send more
  1104. * data from other ACs before the buffered frames from this.
  1105. */
  1106. if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
  1107. !skb_queue_empty(&sta->ps_tx_buf[ac])) {
  1108. more_data = true;
  1109. break;
  1110. }
  1111. }
  1112. if (skb_queue_empty(&frames) && !driver_release_tids) {
  1113. int tid;
  1114. /*
  1115. * For PS-Poll, this can only happen due to a race condition
  1116. * when we set the TIM bit and the station notices it, but
  1117. * before it can poll for the frame we expire it.
  1118. *
  1119. * For uAPSD, this is said in the standard (11.2.1.5 h):
  1120. * At each unscheduled SP for a non-AP STA, the AP shall
  1121. * attempt to transmit at least one MSDU or MMPDU, but no
  1122. * more than the value specified in the Max SP Length field
  1123. * in the QoS Capability element from delivery-enabled ACs,
  1124. * that are destined for the non-AP STA.
  1125. *
  1126. * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
  1127. */
  1128. /* This will evaluate to 1, 3, 5 or 7. */
  1129. tid = 7 - ((ffs(~ignored_acs) - 1) << 1);
  1130. ieee80211_send_null_response(sdata, sta, tid, reason, true);
  1131. } else if (!driver_release_tids) {
  1132. struct sk_buff_head pending;
  1133. struct sk_buff *skb;
  1134. int num = 0;
  1135. u16 tids = 0;
  1136. bool need_null = false;
  1137. skb_queue_head_init(&pending);
  1138. while ((skb = __skb_dequeue(&frames))) {
  1139. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1140. struct ieee80211_hdr *hdr = (void *) skb->data;
  1141. u8 *qoshdr = NULL;
  1142. num++;
  1143. /*
  1144. * Tell TX path to send this frame even though the
  1145. * STA may still remain is PS mode after this frame
  1146. * exchange.
  1147. */
  1148. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
  1149. IEEE80211_TX_CTL_PS_RESPONSE;
  1150. /*
  1151. * Use MoreData flag to indicate whether there are
  1152. * more buffered frames for this STA
  1153. */
  1154. if (more_data || !skb_queue_empty(&frames))
  1155. hdr->frame_control |=
  1156. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1157. else
  1158. hdr->frame_control &=
  1159. cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  1160. if (ieee80211_is_data_qos(hdr->frame_control) ||
  1161. ieee80211_is_qos_nullfunc(hdr->frame_control))
  1162. qoshdr = ieee80211_get_qos_ctl(hdr);
  1163. tids |= BIT(skb->priority);
  1164. __skb_queue_tail(&pending, skb);
  1165. /* end service period after last frame or add one */
  1166. if (!skb_queue_empty(&frames))
  1167. continue;
  1168. if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
  1169. /* for PS-Poll, there's only one frame */
  1170. info->flags |= IEEE80211_TX_STATUS_EOSP |
  1171. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1172. break;
  1173. }
  1174. /* For uAPSD, things are a bit more complicated. If the
  1175. * last frame has a QoS header (i.e. is a QoS-data or
  1176. * QoS-nulldata frame) then just set the EOSP bit there
  1177. * and be done.
  1178. * If the frame doesn't have a QoS header (which means
  1179. * it should be a bufferable MMPDU) then we can't set
  1180. * the EOSP bit in the QoS header; add a QoS-nulldata
  1181. * frame to the list to send it after the MMPDU.
  1182. *
  1183. * Note that this code is only in the mac80211-release
  1184. * code path, we assume that the driver will not buffer
  1185. * anything but QoS-data frames, or if it does, will
  1186. * create the QoS-nulldata frame by itself if needed.
  1187. *
  1188. * Cf. 802.11-2012 10.2.1.10 (c).
  1189. */
  1190. if (qoshdr) {
  1191. *qoshdr |= IEEE80211_QOS_CTL_EOSP;
  1192. info->flags |= IEEE80211_TX_STATUS_EOSP |
  1193. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1194. } else {
  1195. /* The standard isn't completely clear on this
  1196. * as it says the more-data bit should be set
  1197. * if there are more BUs. The QoS-Null frame
  1198. * we're about to send isn't buffered yet, we
  1199. * only create it below, but let's pretend it
  1200. * was buffered just in case some clients only
  1201. * expect more-data=0 when eosp=1.
  1202. */
  1203. hdr->frame_control |=
  1204. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1205. need_null = true;
  1206. num++;
  1207. }
  1208. break;
  1209. }
  1210. drv_allow_buffered_frames(local, sta, tids, num,
  1211. reason, more_data);
  1212. ieee80211_add_pending_skbs(local, &pending);
  1213. if (need_null)
  1214. ieee80211_send_null_response(
  1215. sdata, sta, find_highest_prio_tid(tids),
  1216. reason, false);
  1217. sta_info_recalc_tim(sta);
  1218. } else {
  1219. /*
  1220. * We need to release a frame that is buffered somewhere in the
  1221. * driver ... it'll have to handle that.
  1222. * Note that the driver also has to check the number of frames
  1223. * on the TIDs we're releasing from - if there are more than
  1224. * n_frames it has to set the more-data bit (if we didn't ask
  1225. * it to set it anyway due to other buffered frames); if there
  1226. * are fewer than n_frames it has to make sure to adjust that
  1227. * to allow the service period to end properly.
  1228. */
  1229. drv_release_buffered_frames(local, sta, driver_release_tids,
  1230. n_frames, reason, more_data);
  1231. /*
  1232. * Note that we don't recalculate the TIM bit here as it would
  1233. * most likely have no effect at all unless the driver told us
  1234. * that the TID(s) became empty before returning here from the
  1235. * release function.
  1236. * Either way, however, when the driver tells us that the TID(s)
  1237. * became empty we'll do the TIM recalculation.
  1238. */
  1239. }
  1240. }
  1241. void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
  1242. {
  1243. u8 ignore_for_response = sta->sta.uapsd_queues;
  1244. /*
  1245. * If all ACs are delivery-enabled then we should reply
  1246. * from any of them, if only some are enabled we reply
  1247. * only from the non-enabled ones.
  1248. */
  1249. if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
  1250. ignore_for_response = 0;
  1251. ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
  1252. IEEE80211_FRAME_RELEASE_PSPOLL);
  1253. }
  1254. void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
  1255. {
  1256. int n_frames = sta->sta.max_sp;
  1257. u8 delivery_enabled = sta->sta.uapsd_queues;
  1258. /*
  1259. * If we ever grow support for TSPEC this might happen if
  1260. * the TSPEC update from hostapd comes in between a trigger
  1261. * frame setting WLAN_STA_UAPSD in the RX path and this
  1262. * actually getting called.
  1263. */
  1264. if (!delivery_enabled)
  1265. return;
  1266. switch (sta->sta.max_sp) {
  1267. case 1:
  1268. n_frames = 2;
  1269. break;
  1270. case 2:
  1271. n_frames = 4;
  1272. break;
  1273. case 3:
  1274. n_frames = 6;
  1275. break;
  1276. case 0:
  1277. /* XXX: what is a good value? */
  1278. n_frames = 8;
  1279. break;
  1280. }
  1281. ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
  1282. IEEE80211_FRAME_RELEASE_UAPSD);
  1283. }
  1284. void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
  1285. struct ieee80211_sta *pubsta, bool block)
  1286. {
  1287. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1288. trace_api_sta_block_awake(sta->local, pubsta, block);
  1289. if (block) {
  1290. set_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1291. return;
  1292. }
  1293. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1294. return;
  1295. if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1296. set_sta_flag(sta, WLAN_STA_PS_DELIVER);
  1297. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1298. ieee80211_queue_work(hw, &sta->drv_deliver_wk);
  1299. } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
  1300. test_sta_flag(sta, WLAN_STA_UAPSD)) {
  1301. /* must be asleep in this case */
  1302. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1303. ieee80211_queue_work(hw, &sta->drv_deliver_wk);
  1304. } else {
  1305. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1306. }
  1307. }
  1308. EXPORT_SYMBOL(ieee80211_sta_block_awake);
  1309. void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
  1310. {
  1311. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1312. struct ieee80211_local *local = sta->local;
  1313. trace_api_eosp(local, pubsta);
  1314. clear_sta_flag(sta, WLAN_STA_SP);
  1315. }
  1316. EXPORT_SYMBOL(ieee80211_sta_eosp);
  1317. void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
  1318. u8 tid, bool buffered)
  1319. {
  1320. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1321. if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
  1322. return;
  1323. trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
  1324. if (buffered)
  1325. set_bit(tid, &sta->driver_buffered_tids);
  1326. else
  1327. clear_bit(tid, &sta->driver_buffered_tids);
  1328. sta_info_recalc_tim(sta);
  1329. }
  1330. EXPORT_SYMBOL(ieee80211_sta_set_buffered);
  1331. int sta_info_move_state(struct sta_info *sta,
  1332. enum ieee80211_sta_state new_state)
  1333. {
  1334. might_sleep();
  1335. if (sta->sta_state == new_state)
  1336. return 0;
  1337. /* check allowed transitions first */
  1338. switch (new_state) {
  1339. case IEEE80211_STA_NONE:
  1340. if (sta->sta_state != IEEE80211_STA_AUTH)
  1341. return -EINVAL;
  1342. break;
  1343. case IEEE80211_STA_AUTH:
  1344. if (sta->sta_state != IEEE80211_STA_NONE &&
  1345. sta->sta_state != IEEE80211_STA_ASSOC)
  1346. return -EINVAL;
  1347. break;
  1348. case IEEE80211_STA_ASSOC:
  1349. if (sta->sta_state != IEEE80211_STA_AUTH &&
  1350. sta->sta_state != IEEE80211_STA_AUTHORIZED)
  1351. return -EINVAL;
  1352. break;
  1353. case IEEE80211_STA_AUTHORIZED:
  1354. if (sta->sta_state != IEEE80211_STA_ASSOC)
  1355. return -EINVAL;
  1356. break;
  1357. default:
  1358. WARN(1, "invalid state %d", new_state);
  1359. return -EINVAL;
  1360. }
  1361. sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
  1362. sta->sta.addr, new_state);
  1363. /*
  1364. * notify the driver before the actual changes so it can
  1365. * fail the transition
  1366. */
  1367. if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
  1368. int err = drv_sta_state(sta->local, sta->sdata, sta,
  1369. sta->sta_state, new_state);
  1370. if (err)
  1371. return err;
  1372. }
  1373. /* reflect the change in all state variables */
  1374. switch (new_state) {
  1375. case IEEE80211_STA_NONE:
  1376. if (sta->sta_state == IEEE80211_STA_AUTH)
  1377. clear_bit(WLAN_STA_AUTH, &sta->_flags);
  1378. break;
  1379. case IEEE80211_STA_AUTH:
  1380. if (sta->sta_state == IEEE80211_STA_NONE)
  1381. set_bit(WLAN_STA_AUTH, &sta->_flags);
  1382. else if (sta->sta_state == IEEE80211_STA_ASSOC)
  1383. clear_bit(WLAN_STA_ASSOC, &sta->_flags);
  1384. break;
  1385. case IEEE80211_STA_ASSOC:
  1386. if (sta->sta_state == IEEE80211_STA_AUTH) {
  1387. set_bit(WLAN_STA_ASSOC, &sta->_flags);
  1388. } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
  1389. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  1390. (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1391. !sta->sdata->u.vlan.sta))
  1392. atomic_dec(&sta->sdata->bss->num_mcast_sta);
  1393. clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
  1394. }
  1395. break;
  1396. case IEEE80211_STA_AUTHORIZED:
  1397. if (sta->sta_state == IEEE80211_STA_ASSOC) {
  1398. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  1399. (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1400. !sta->sdata->u.vlan.sta))
  1401. atomic_inc(&sta->sdata->bss->num_mcast_sta);
  1402. set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
  1403. }
  1404. break;
  1405. default:
  1406. break;
  1407. }
  1408. sta->sta_state = new_state;
  1409. return 0;
  1410. }
  1411. u8 sta_info_tx_streams(struct sta_info *sta)
  1412. {
  1413. struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
  1414. u8 rx_streams;
  1415. if (!sta->sta.ht_cap.ht_supported)
  1416. return 1;
  1417. if (sta->sta.vht_cap.vht_supported) {
  1418. int i;
  1419. u16 tx_mcs_map =
  1420. le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
  1421. for (i = 7; i >= 0; i--)
  1422. if ((tx_mcs_map & (0x3 << (i * 2))) !=
  1423. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  1424. return i + 1;
  1425. }
  1426. if (ht_cap->mcs.rx_mask[3])
  1427. rx_streams = 4;
  1428. else if (ht_cap->mcs.rx_mask[2])
  1429. rx_streams = 3;
  1430. else if (ht_cap->mcs.rx_mask[1])
  1431. rx_streams = 2;
  1432. else
  1433. rx_streams = 1;
  1434. if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
  1435. return rx_streams;
  1436. return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1437. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
  1438. }
  1439. void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  1440. {
  1441. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1442. struct ieee80211_local *local = sdata->local;
  1443. struct rate_control_ref *ref = NULL;
  1444. struct timespec uptime;
  1445. u64 packets = 0;
  1446. u32 thr = 0;
  1447. int i, ac;
  1448. if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  1449. ref = local->rate_ctrl;
  1450. sinfo->generation = sdata->local->sta_generation;
  1451. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  1452. STATION_INFO_RX_BYTES64 |
  1453. STATION_INFO_TX_BYTES64 |
  1454. STATION_INFO_RX_PACKETS |
  1455. STATION_INFO_TX_PACKETS |
  1456. STATION_INFO_TX_RETRIES |
  1457. STATION_INFO_TX_FAILED |
  1458. STATION_INFO_TX_BITRATE |
  1459. STATION_INFO_RX_BITRATE |
  1460. STATION_INFO_RX_DROP_MISC |
  1461. STATION_INFO_BSS_PARAM |
  1462. STATION_INFO_CONNECTED_TIME |
  1463. STATION_INFO_STA_FLAGS |
  1464. STATION_INFO_BEACON_LOSS_COUNT;
  1465. ktime_get_ts(&uptime);
  1466. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  1467. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  1468. sinfo->tx_bytes = 0;
  1469. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1470. sinfo->tx_bytes += sta->tx_bytes[ac];
  1471. packets += sta->tx_packets[ac];
  1472. }
  1473. sinfo->tx_packets = packets;
  1474. sinfo->rx_bytes = sta->rx_bytes;
  1475. sinfo->rx_packets = sta->rx_packets;
  1476. sinfo->tx_retries = sta->tx_retry_count;
  1477. sinfo->tx_failed = sta->tx_retry_failed;
  1478. sinfo->rx_dropped_misc = sta->rx_dropped;
  1479. sinfo->beacon_loss_count = sta->beacon_loss_count;
  1480. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  1481. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  1482. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  1483. if (!local->ops->get_rssi ||
  1484. drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
  1485. sinfo->signal = (s8)sta->last_signal;
  1486. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  1487. }
  1488. if (sta->chains) {
  1489. sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
  1490. STATION_INFO_CHAIN_SIGNAL_AVG;
  1491. sinfo->chains = sta->chains;
  1492. for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
  1493. sinfo->chain_signal[i] = sta->chain_signal_last[i];
  1494. sinfo->chain_signal_avg[i] =
  1495. (s8) -ewma_read(&sta->chain_signal_avg[i]);
  1496. }
  1497. }
  1498. sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
  1499. sta_set_rate_info_rx(sta, &sinfo->rxrate);
  1500. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1501. #ifdef CONFIG_MAC80211_MESH
  1502. sinfo->filled |= STATION_INFO_LLID |
  1503. STATION_INFO_PLID |
  1504. STATION_INFO_PLINK_STATE |
  1505. STATION_INFO_LOCAL_PM |
  1506. STATION_INFO_PEER_PM |
  1507. STATION_INFO_NONPEER_PM;
  1508. sinfo->llid = sta->llid;
  1509. sinfo->plid = sta->plid;
  1510. sinfo->plink_state = sta->plink_state;
  1511. if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
  1512. sinfo->filled |= STATION_INFO_T_OFFSET;
  1513. sinfo->t_offset = sta->t_offset;
  1514. }
  1515. sinfo->local_pm = sta->local_pm;
  1516. sinfo->peer_pm = sta->peer_pm;
  1517. sinfo->nonpeer_pm = sta->nonpeer_pm;
  1518. #endif
  1519. }
  1520. sinfo->bss_param.flags = 0;
  1521. if (sdata->vif.bss_conf.use_cts_prot)
  1522. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  1523. if (sdata->vif.bss_conf.use_short_preamble)
  1524. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  1525. if (sdata->vif.bss_conf.use_short_slot)
  1526. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  1527. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  1528. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  1529. sinfo->sta_flags.set = 0;
  1530. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  1531. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  1532. BIT(NL80211_STA_FLAG_WME) |
  1533. BIT(NL80211_STA_FLAG_MFP) |
  1534. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1535. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  1536. BIT(NL80211_STA_FLAG_TDLS_PEER);
  1537. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1538. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  1539. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  1540. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  1541. if (test_sta_flag(sta, WLAN_STA_WME))
  1542. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  1543. if (test_sta_flag(sta, WLAN_STA_MFP))
  1544. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  1545. if (test_sta_flag(sta, WLAN_STA_AUTH))
  1546. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  1547. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  1548. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1549. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  1550. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  1551. /* check if the driver has a SW RC implementation */
  1552. if (ref && ref->ops->get_expected_throughput)
  1553. thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
  1554. else
  1555. thr = drv_get_expected_throughput(local, &sta->sta);
  1556. if (thr != 0) {
  1557. sinfo->filled |= STATION_INFO_EXPECTED_THROUGHPUT;
  1558. sinfo->expected_throughput = thr;
  1559. }
  1560. }