sta_info.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  4. * Copyright 2013-2014 Intel Mobile Communications GmbH
  5. * Copyright (C) 2015 - 2016 Intel Deutschland GmbH
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/types.h>
  16. #include <linux/slab.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/timer.h>
  20. #include <linux/rtnetlink.h>
  21. #include <net/mac80211.h>
  22. #include "ieee80211_i.h"
  23. #include "driver-ops.h"
  24. #include "rate.h"
  25. #include "sta_info.h"
  26. #include "debugfs_sta.h"
  27. #include "mesh.h"
  28. #include "wme.h"
  29. /**
  30. * DOC: STA information lifetime rules
  31. *
  32. * STA info structures (&struct sta_info) are managed in a hash table
  33. * for faster lookup and a list for iteration. They are managed using
  34. * RCU, i.e. access to the list and hash table is protected by RCU.
  35. *
  36. * Upon allocating a STA info structure with sta_info_alloc(), the caller
  37. * owns that structure. It must then insert it into the hash table using
  38. * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
  39. * case (which acquires an rcu read section but must not be called from
  40. * within one) will the pointer still be valid after the call. Note that
  41. * the caller may not do much with the STA info before inserting it, in
  42. * particular, it may not start any mesh peer link management or add
  43. * encryption keys.
  44. *
  45. * When the insertion fails (sta_info_insert()) returns non-zero), the
  46. * structure will have been freed by sta_info_insert()!
  47. *
  48. * Station entries are added by mac80211 when you establish a link with a
  49. * peer. This means different things for the different type of interfaces
  50. * we support. For a regular station this mean we add the AP sta when we
  51. * receive an association response from the AP. For IBSS this occurs when
  52. * get to know about a peer on the same IBSS. For WDS we add the sta for
  53. * the peer immediately upon device open. When using AP mode we add stations
  54. * for each respective station upon request from userspace through nl80211.
  55. *
  56. * In order to remove a STA info structure, various sta_info_destroy_*()
  57. * calls are available.
  58. *
  59. * There is no concept of ownership on a STA entry, each structure is
  60. * owned by the global hash table/list until it is removed. All users of
  61. * the structure need to be RCU protected so that the structure won't be
  62. * freed before they are done using it.
  63. */
  64. static const struct rhashtable_params sta_rht_params = {
  65. .nelem_hint = 3, /* start small */
  66. .automatic_shrinking = true,
  67. .head_offset = offsetof(struct sta_info, hash_node),
  68. .key_offset = offsetof(struct sta_info, addr),
  69. .key_len = ETH_ALEN,
  70. .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
  71. };
  72. /* Caller must hold local->sta_mtx */
  73. static int sta_info_hash_del(struct ieee80211_local *local,
  74. struct sta_info *sta)
  75. {
  76. return rhltable_remove(&local->sta_hash, &sta->hash_node,
  77. sta_rht_params);
  78. }
  79. static void __cleanup_single_sta(struct sta_info *sta)
  80. {
  81. int ac, i;
  82. struct tid_ampdu_tx *tid_tx;
  83. struct ieee80211_sub_if_data *sdata = sta->sdata;
  84. struct ieee80211_local *local = sdata->local;
  85. struct fq *fq = &local->fq;
  86. struct ps_data *ps;
  87. if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
  88. test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
  89. test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
  90. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  91. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  92. ps = &sdata->bss->ps;
  93. else if (ieee80211_vif_is_mesh(&sdata->vif))
  94. ps = &sdata->u.mesh.ps;
  95. else
  96. return;
  97. clear_sta_flag(sta, WLAN_STA_PS_STA);
  98. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  99. clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
  100. atomic_dec(&ps->num_sta_ps);
  101. }
  102. if (sta->sta.txq[0]) {
  103. for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
  104. struct txq_info *txqi = to_txq_info(sta->sta.txq[i]);
  105. spin_lock_bh(&fq->lock);
  106. ieee80211_txq_purge(local, txqi);
  107. spin_unlock_bh(&fq->lock);
  108. }
  109. }
  110. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  111. local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
  112. ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
  113. ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
  114. }
  115. if (ieee80211_vif_is_mesh(&sdata->vif))
  116. mesh_sta_cleanup(sta);
  117. cancel_work_sync(&sta->drv_deliver_wk);
  118. /*
  119. * Destroy aggregation state here. It would be nice to wait for the
  120. * driver to finish aggregation stop and then clean up, but for now
  121. * drivers have to handle aggregation stop being requested, followed
  122. * directly by station destruction.
  123. */
  124. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  125. kfree(sta->ampdu_mlme.tid_start_tx[i]);
  126. tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
  127. if (!tid_tx)
  128. continue;
  129. ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
  130. kfree(tid_tx);
  131. }
  132. }
  133. static void cleanup_single_sta(struct sta_info *sta)
  134. {
  135. struct ieee80211_sub_if_data *sdata = sta->sdata;
  136. struct ieee80211_local *local = sdata->local;
  137. __cleanup_single_sta(sta);
  138. sta_info_free(local, sta);
  139. }
  140. struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
  141. const u8 *addr)
  142. {
  143. return rhltable_lookup(&local->sta_hash, addr, sta_rht_params);
  144. }
  145. /* protected by RCU */
  146. struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
  147. const u8 *addr)
  148. {
  149. struct ieee80211_local *local = sdata->local;
  150. struct rhlist_head *tmp;
  151. struct sta_info *sta;
  152. rcu_read_lock();
  153. for_each_sta_info(local, addr, sta, tmp) {
  154. if (sta->sdata == sdata) {
  155. rcu_read_unlock();
  156. /* this is safe as the caller must already hold
  157. * another rcu read section or the mutex
  158. */
  159. return sta;
  160. }
  161. }
  162. rcu_read_unlock();
  163. return NULL;
  164. }
  165. /*
  166. * Get sta info either from the specified interface
  167. * or from one of its vlans
  168. */
  169. struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
  170. const u8 *addr)
  171. {
  172. struct ieee80211_local *local = sdata->local;
  173. struct rhlist_head *tmp;
  174. struct sta_info *sta;
  175. rcu_read_lock();
  176. for_each_sta_info(local, addr, sta, tmp) {
  177. if (sta->sdata == sdata ||
  178. (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
  179. rcu_read_unlock();
  180. /* this is safe as the caller must already hold
  181. * another rcu read section or the mutex
  182. */
  183. return sta;
  184. }
  185. }
  186. rcu_read_unlock();
  187. return NULL;
  188. }
  189. struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
  190. int idx)
  191. {
  192. struct ieee80211_local *local = sdata->local;
  193. struct sta_info *sta;
  194. int i = 0;
  195. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  196. if (sdata != sta->sdata)
  197. continue;
  198. if (i < idx) {
  199. ++i;
  200. continue;
  201. }
  202. return sta;
  203. }
  204. return NULL;
  205. }
  206. /**
  207. * sta_info_free - free STA
  208. *
  209. * @local: pointer to the global information
  210. * @sta: STA info to free
  211. *
  212. * This function must undo everything done by sta_info_alloc()
  213. * that may happen before sta_info_insert(). It may only be
  214. * called when sta_info_insert() has not been attempted (and
  215. * if that fails, the station is freed anyway.)
  216. */
  217. void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
  218. {
  219. if (sta->rate_ctrl)
  220. rate_control_free_sta(sta);
  221. sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
  222. if (sta->sta.txq[0])
  223. kfree(to_txq_info(sta->sta.txq[0]));
  224. kfree(rcu_dereference_raw(sta->sta.rates));
  225. #ifdef CONFIG_MAC80211_MESH
  226. kfree(sta->mesh);
  227. #endif
  228. free_percpu(sta->pcpu_rx_stats);
  229. kfree(sta);
  230. }
  231. /* Caller must hold local->sta_mtx */
  232. static int sta_info_hash_add(struct ieee80211_local *local,
  233. struct sta_info *sta)
  234. {
  235. return rhltable_insert(&local->sta_hash, &sta->hash_node,
  236. sta_rht_params);
  237. }
  238. static void sta_deliver_ps_frames(struct work_struct *wk)
  239. {
  240. struct sta_info *sta;
  241. sta = container_of(wk, struct sta_info, drv_deliver_wk);
  242. if (sta->dead)
  243. return;
  244. local_bh_disable();
  245. if (!test_sta_flag(sta, WLAN_STA_PS_STA))
  246. ieee80211_sta_ps_deliver_wakeup(sta);
  247. else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
  248. ieee80211_sta_ps_deliver_poll_response(sta);
  249. else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
  250. ieee80211_sta_ps_deliver_uapsd(sta);
  251. local_bh_enable();
  252. }
  253. static int sta_prepare_rate_control(struct ieee80211_local *local,
  254. struct sta_info *sta, gfp_t gfp)
  255. {
  256. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
  257. return 0;
  258. sta->rate_ctrl = local->rate_ctrl;
  259. sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
  260. sta, gfp);
  261. if (!sta->rate_ctrl_priv)
  262. return -ENOMEM;
  263. return 0;
  264. }
  265. struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
  266. const u8 *addr, gfp_t gfp)
  267. {
  268. struct ieee80211_local *local = sdata->local;
  269. struct ieee80211_hw *hw = &local->hw;
  270. struct sta_info *sta;
  271. int i;
  272. sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
  273. if (!sta)
  274. return NULL;
  275. if (ieee80211_hw_check(hw, USES_RSS)) {
  276. sta->pcpu_rx_stats =
  277. alloc_percpu(struct ieee80211_sta_rx_stats);
  278. if (!sta->pcpu_rx_stats)
  279. goto free;
  280. }
  281. spin_lock_init(&sta->lock);
  282. spin_lock_init(&sta->ps_lock);
  283. INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
  284. INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
  285. mutex_init(&sta->ampdu_mlme.mtx);
  286. #ifdef CONFIG_MAC80211_MESH
  287. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  288. sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
  289. if (!sta->mesh)
  290. goto free;
  291. spin_lock_init(&sta->mesh->plink_lock);
  292. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  293. !sdata->u.mesh.user_mpm)
  294. init_timer(&sta->mesh->plink_timer);
  295. sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
  296. }
  297. #endif
  298. memcpy(sta->addr, addr, ETH_ALEN);
  299. memcpy(sta->sta.addr, addr, ETH_ALEN);
  300. sta->sta.max_rx_aggregation_subframes =
  301. local->hw.max_rx_aggregation_subframes;
  302. sta->local = local;
  303. sta->sdata = sdata;
  304. sta->rx_stats.last_rx = jiffies;
  305. u64_stats_init(&sta->rx_stats.syncp);
  306. sta->sta_state = IEEE80211_STA_NONE;
  307. /* Mark TID as unreserved */
  308. sta->reserved_tid = IEEE80211_TID_UNRESERVED;
  309. sta->last_connected = ktime_get_seconds();
  310. ewma_signal_init(&sta->rx_stats_avg.signal);
  311. for (i = 0; i < ARRAY_SIZE(sta->rx_stats_avg.chain_signal); i++)
  312. ewma_signal_init(&sta->rx_stats_avg.chain_signal[i]);
  313. if (local->ops->wake_tx_queue) {
  314. void *txq_data;
  315. int size = sizeof(struct txq_info) +
  316. ALIGN(hw->txq_data_size, sizeof(void *));
  317. txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
  318. if (!txq_data)
  319. goto free;
  320. for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
  321. struct txq_info *txq = txq_data + i * size;
  322. ieee80211_txq_init(sdata, sta, txq, i);
  323. }
  324. }
  325. if (sta_prepare_rate_control(local, sta, gfp))
  326. goto free_txq;
  327. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  328. /*
  329. * timer_to_tid must be initialized with identity mapping
  330. * to enable session_timer's data differentiation. See
  331. * sta_rx_agg_session_timer_expired for usage.
  332. */
  333. sta->timer_to_tid[i] = i;
  334. }
  335. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  336. skb_queue_head_init(&sta->ps_tx_buf[i]);
  337. skb_queue_head_init(&sta->tx_filtered[i]);
  338. }
  339. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  340. sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
  341. sta->sta.smps_mode = IEEE80211_SMPS_OFF;
  342. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  343. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  344. struct ieee80211_supported_band *sband =
  345. hw->wiphy->bands[ieee80211_get_sdata_band(sdata)];
  346. u8 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
  347. IEEE80211_HT_CAP_SM_PS_SHIFT;
  348. /*
  349. * Assume that hostapd advertises our caps in the beacon and
  350. * this is the known_smps_mode for a station that just assciated
  351. */
  352. switch (smps) {
  353. case WLAN_HT_SMPS_CONTROL_DISABLED:
  354. sta->known_smps_mode = IEEE80211_SMPS_OFF;
  355. break;
  356. case WLAN_HT_SMPS_CONTROL_STATIC:
  357. sta->known_smps_mode = IEEE80211_SMPS_STATIC;
  358. break;
  359. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  360. sta->known_smps_mode = IEEE80211_SMPS_DYNAMIC;
  361. break;
  362. default:
  363. WARN_ON(1);
  364. }
  365. }
  366. sta->sta.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
  367. sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
  368. return sta;
  369. free_txq:
  370. if (sta->sta.txq[0])
  371. kfree(to_txq_info(sta->sta.txq[0]));
  372. free:
  373. #ifdef CONFIG_MAC80211_MESH
  374. kfree(sta->mesh);
  375. #endif
  376. kfree(sta);
  377. return NULL;
  378. }
  379. static int sta_info_insert_check(struct sta_info *sta)
  380. {
  381. struct ieee80211_sub_if_data *sdata = sta->sdata;
  382. /*
  383. * Can't be a WARN_ON because it can be triggered through a race:
  384. * something inserts a STA (on one CPU) without holding the RTNL
  385. * and another CPU turns off the net device.
  386. */
  387. if (unlikely(!ieee80211_sdata_running(sdata)))
  388. return -ENETDOWN;
  389. if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
  390. is_multicast_ether_addr(sta->sta.addr)))
  391. return -EINVAL;
  392. /* The RCU read lock is required by rhashtable due to
  393. * asynchronous resize/rehash. We also require the mutex
  394. * for correctness.
  395. */
  396. rcu_read_lock();
  397. lockdep_assert_held(&sdata->local->sta_mtx);
  398. if (ieee80211_hw_check(&sdata->local->hw, NEEDS_UNIQUE_STA_ADDR) &&
  399. ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
  400. rcu_read_unlock();
  401. return -ENOTUNIQ;
  402. }
  403. rcu_read_unlock();
  404. return 0;
  405. }
  406. static int sta_info_insert_drv_state(struct ieee80211_local *local,
  407. struct ieee80211_sub_if_data *sdata,
  408. struct sta_info *sta)
  409. {
  410. enum ieee80211_sta_state state;
  411. int err = 0;
  412. for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
  413. err = drv_sta_state(local, sdata, sta, state, state + 1);
  414. if (err)
  415. break;
  416. }
  417. if (!err) {
  418. /*
  419. * Drivers using legacy sta_add/sta_remove callbacks only
  420. * get uploaded set to true after sta_add is called.
  421. */
  422. if (!local->ops->sta_add)
  423. sta->uploaded = true;
  424. return 0;
  425. }
  426. if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  427. sdata_info(sdata,
  428. "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
  429. sta->sta.addr, state + 1, err);
  430. err = 0;
  431. }
  432. /* unwind on error */
  433. for (; state > IEEE80211_STA_NOTEXIST; state--)
  434. WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
  435. return err;
  436. }
  437. /*
  438. * should be called with sta_mtx locked
  439. * this function replaces the mutex lock
  440. * with a RCU lock
  441. */
  442. static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
  443. {
  444. struct ieee80211_local *local = sta->local;
  445. struct ieee80211_sub_if_data *sdata = sta->sdata;
  446. struct station_info *sinfo;
  447. int err = 0;
  448. lockdep_assert_held(&local->sta_mtx);
  449. sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
  450. if (!sinfo) {
  451. err = -ENOMEM;
  452. goto out_err;
  453. }
  454. /* check if STA exists already */
  455. if (sta_info_get_bss(sdata, sta->sta.addr)) {
  456. err = -EEXIST;
  457. goto out_err;
  458. }
  459. local->num_sta++;
  460. local->sta_generation++;
  461. smp_mb();
  462. /* simplify things and don't accept BA sessions yet */
  463. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  464. /* make the station visible */
  465. err = sta_info_hash_add(local, sta);
  466. if (err)
  467. goto out_drop_sta;
  468. list_add_tail_rcu(&sta->list, &local->sta_list);
  469. /* notify driver */
  470. err = sta_info_insert_drv_state(local, sdata, sta);
  471. if (err)
  472. goto out_remove;
  473. set_sta_flag(sta, WLAN_STA_INSERTED);
  474. /* accept BA sessions now */
  475. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  476. ieee80211_sta_debugfs_add(sta);
  477. rate_control_add_sta_debugfs(sta);
  478. sinfo->generation = local->sta_generation;
  479. cfg80211_new_sta(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
  480. kfree(sinfo);
  481. sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
  482. /* move reference to rcu-protected */
  483. rcu_read_lock();
  484. mutex_unlock(&local->sta_mtx);
  485. if (ieee80211_vif_is_mesh(&sdata->vif))
  486. mesh_accept_plinks_update(sdata);
  487. return 0;
  488. out_remove:
  489. sta_info_hash_del(local, sta);
  490. list_del_rcu(&sta->list);
  491. out_drop_sta:
  492. local->num_sta--;
  493. synchronize_net();
  494. __cleanup_single_sta(sta);
  495. out_err:
  496. mutex_unlock(&local->sta_mtx);
  497. kfree(sinfo);
  498. rcu_read_lock();
  499. return err;
  500. }
  501. int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
  502. {
  503. struct ieee80211_local *local = sta->local;
  504. int err;
  505. might_sleep();
  506. mutex_lock(&local->sta_mtx);
  507. err = sta_info_insert_check(sta);
  508. if (err) {
  509. mutex_unlock(&local->sta_mtx);
  510. rcu_read_lock();
  511. goto out_free;
  512. }
  513. err = sta_info_insert_finish(sta);
  514. if (err)
  515. goto out_free;
  516. return 0;
  517. out_free:
  518. sta_info_free(local, sta);
  519. return err;
  520. }
  521. int sta_info_insert(struct sta_info *sta)
  522. {
  523. int err = sta_info_insert_rcu(sta);
  524. rcu_read_unlock();
  525. return err;
  526. }
  527. static inline void __bss_tim_set(u8 *tim, u16 id)
  528. {
  529. /*
  530. * This format has been mandated by the IEEE specifications,
  531. * so this line may not be changed to use the __set_bit() format.
  532. */
  533. tim[id / 8] |= (1 << (id % 8));
  534. }
  535. static inline void __bss_tim_clear(u8 *tim, u16 id)
  536. {
  537. /*
  538. * This format has been mandated by the IEEE specifications,
  539. * so this line may not be changed to use the __clear_bit() format.
  540. */
  541. tim[id / 8] &= ~(1 << (id % 8));
  542. }
  543. static inline bool __bss_tim_get(u8 *tim, u16 id)
  544. {
  545. /*
  546. * This format has been mandated by the IEEE specifications,
  547. * so this line may not be changed to use the test_bit() format.
  548. */
  549. return tim[id / 8] & (1 << (id % 8));
  550. }
  551. static unsigned long ieee80211_tids_for_ac(int ac)
  552. {
  553. /* If we ever support TIDs > 7, this obviously needs to be adjusted */
  554. switch (ac) {
  555. case IEEE80211_AC_VO:
  556. return BIT(6) | BIT(7);
  557. case IEEE80211_AC_VI:
  558. return BIT(4) | BIT(5);
  559. case IEEE80211_AC_BE:
  560. return BIT(0) | BIT(3);
  561. case IEEE80211_AC_BK:
  562. return BIT(1) | BIT(2);
  563. default:
  564. WARN_ON(1);
  565. return 0;
  566. }
  567. }
  568. static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
  569. {
  570. struct ieee80211_local *local = sta->local;
  571. struct ps_data *ps;
  572. bool indicate_tim = false;
  573. u8 ignore_for_tim = sta->sta.uapsd_queues;
  574. int ac;
  575. u16 id = sta->sta.aid;
  576. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  577. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  578. if (WARN_ON_ONCE(!sta->sdata->bss))
  579. return;
  580. ps = &sta->sdata->bss->ps;
  581. #ifdef CONFIG_MAC80211_MESH
  582. } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
  583. ps = &sta->sdata->u.mesh.ps;
  584. #endif
  585. } else {
  586. return;
  587. }
  588. /* No need to do anything if the driver does all */
  589. if (ieee80211_hw_check(&local->hw, AP_LINK_PS) && !local->ops->set_tim)
  590. return;
  591. if (sta->dead)
  592. goto done;
  593. /*
  594. * If all ACs are delivery-enabled then we should build
  595. * the TIM bit for all ACs anyway; if only some are then
  596. * we ignore those and build the TIM bit using only the
  597. * non-enabled ones.
  598. */
  599. if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
  600. ignore_for_tim = 0;
  601. if (ignore_pending)
  602. ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
  603. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  604. unsigned long tids;
  605. if (ignore_for_tim & BIT(ac))
  606. continue;
  607. indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
  608. !skb_queue_empty(&sta->ps_tx_buf[ac]);
  609. if (indicate_tim)
  610. break;
  611. tids = ieee80211_tids_for_ac(ac);
  612. indicate_tim |=
  613. sta->driver_buffered_tids & tids;
  614. indicate_tim |=
  615. sta->txq_buffered_tids & tids;
  616. }
  617. done:
  618. spin_lock_bh(&local->tim_lock);
  619. if (indicate_tim == __bss_tim_get(ps->tim, id))
  620. goto out_unlock;
  621. if (indicate_tim)
  622. __bss_tim_set(ps->tim, id);
  623. else
  624. __bss_tim_clear(ps->tim, id);
  625. if (local->ops->set_tim && !WARN_ON(sta->dead)) {
  626. local->tim_in_locked_section = true;
  627. drv_set_tim(local, &sta->sta, indicate_tim);
  628. local->tim_in_locked_section = false;
  629. }
  630. out_unlock:
  631. spin_unlock_bh(&local->tim_lock);
  632. }
  633. void sta_info_recalc_tim(struct sta_info *sta)
  634. {
  635. __sta_info_recalc_tim(sta, false);
  636. }
  637. static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
  638. {
  639. struct ieee80211_tx_info *info;
  640. int timeout;
  641. if (!skb)
  642. return false;
  643. info = IEEE80211_SKB_CB(skb);
  644. /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
  645. timeout = (sta->listen_interval *
  646. sta->sdata->vif.bss_conf.beacon_int *
  647. 32 / 15625) * HZ;
  648. if (timeout < STA_TX_BUFFER_EXPIRE)
  649. timeout = STA_TX_BUFFER_EXPIRE;
  650. return time_after(jiffies, info->control.jiffies + timeout);
  651. }
  652. static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
  653. struct sta_info *sta, int ac)
  654. {
  655. unsigned long flags;
  656. struct sk_buff *skb;
  657. /*
  658. * First check for frames that should expire on the filtered
  659. * queue. Frames here were rejected by the driver and are on
  660. * a separate queue to avoid reordering with normal PS-buffered
  661. * frames. They also aren't accounted for right now in the
  662. * total_ps_buffered counter.
  663. */
  664. for (;;) {
  665. spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
  666. skb = skb_peek(&sta->tx_filtered[ac]);
  667. if (sta_info_buffer_expired(sta, skb))
  668. skb = __skb_dequeue(&sta->tx_filtered[ac]);
  669. else
  670. skb = NULL;
  671. spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
  672. /*
  673. * Frames are queued in order, so if this one
  674. * hasn't expired yet we can stop testing. If
  675. * we actually reached the end of the queue we
  676. * also need to stop, of course.
  677. */
  678. if (!skb)
  679. break;
  680. ieee80211_free_txskb(&local->hw, skb);
  681. }
  682. /*
  683. * Now also check the normal PS-buffered queue, this will
  684. * only find something if the filtered queue was emptied
  685. * since the filtered frames are all before the normal PS
  686. * buffered frames.
  687. */
  688. for (;;) {
  689. spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
  690. skb = skb_peek(&sta->ps_tx_buf[ac]);
  691. if (sta_info_buffer_expired(sta, skb))
  692. skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
  693. else
  694. skb = NULL;
  695. spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
  696. /*
  697. * frames are queued in order, so if this one
  698. * hasn't expired yet (or we reached the end of
  699. * the queue) we can stop testing
  700. */
  701. if (!skb)
  702. break;
  703. local->total_ps_buffered--;
  704. ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
  705. sta->sta.addr);
  706. ieee80211_free_txskb(&local->hw, skb);
  707. }
  708. /*
  709. * Finally, recalculate the TIM bit for this station -- it might
  710. * now be clear because the station was too slow to retrieve its
  711. * frames.
  712. */
  713. sta_info_recalc_tim(sta);
  714. /*
  715. * Return whether there are any frames still buffered, this is
  716. * used to check whether the cleanup timer still needs to run,
  717. * if there are no frames we don't need to rearm the timer.
  718. */
  719. return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
  720. skb_queue_empty(&sta->tx_filtered[ac]));
  721. }
  722. static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
  723. struct sta_info *sta)
  724. {
  725. bool have_buffered = false;
  726. int ac;
  727. /* This is only necessary for stations on BSS/MBSS interfaces */
  728. if (!sta->sdata->bss &&
  729. !ieee80211_vif_is_mesh(&sta->sdata->vif))
  730. return false;
  731. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  732. have_buffered |=
  733. sta_info_cleanup_expire_buffered_ac(local, sta, ac);
  734. return have_buffered;
  735. }
  736. static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
  737. {
  738. struct ieee80211_local *local;
  739. struct ieee80211_sub_if_data *sdata;
  740. int ret;
  741. might_sleep();
  742. if (!sta)
  743. return -ENOENT;
  744. local = sta->local;
  745. sdata = sta->sdata;
  746. lockdep_assert_held(&local->sta_mtx);
  747. /*
  748. * Before removing the station from the driver and
  749. * rate control, it might still start new aggregation
  750. * sessions -- block that to make sure the tear-down
  751. * will be sufficient.
  752. */
  753. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  754. ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
  755. /*
  756. * Before removing the station from the driver there might be pending
  757. * rx frames on RSS queues sent prior to the disassociation - wait for
  758. * all such frames to be processed.
  759. */
  760. drv_sync_rx_queues(local, sta);
  761. ret = sta_info_hash_del(local, sta);
  762. if (WARN_ON(ret))
  763. return ret;
  764. /*
  765. * for TDLS peers, make sure to return to the base channel before
  766. * removal.
  767. */
  768. if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
  769. drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
  770. clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
  771. }
  772. list_del_rcu(&sta->list);
  773. sta->removed = true;
  774. drv_sta_pre_rcu_remove(local, sta->sdata, sta);
  775. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  776. rcu_access_pointer(sdata->u.vlan.sta) == sta)
  777. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  778. return 0;
  779. }
  780. static void __sta_info_destroy_part2(struct sta_info *sta)
  781. {
  782. struct ieee80211_local *local = sta->local;
  783. struct ieee80211_sub_if_data *sdata = sta->sdata;
  784. struct station_info *sinfo;
  785. int ret;
  786. /*
  787. * NOTE: This assumes at least synchronize_net() was done
  788. * after _part1 and before _part2!
  789. */
  790. might_sleep();
  791. lockdep_assert_held(&local->sta_mtx);
  792. /* now keys can no longer be reached */
  793. ieee80211_free_sta_keys(local, sta);
  794. /* disable TIM bit - last chance to tell driver */
  795. __sta_info_recalc_tim(sta, true);
  796. sta->dead = true;
  797. local->num_sta--;
  798. local->sta_generation++;
  799. while (sta->sta_state > IEEE80211_STA_NONE) {
  800. ret = sta_info_move_state(sta, sta->sta_state - 1);
  801. if (ret) {
  802. WARN_ON_ONCE(1);
  803. break;
  804. }
  805. }
  806. if (sta->uploaded) {
  807. ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
  808. IEEE80211_STA_NOTEXIST);
  809. WARN_ON_ONCE(ret != 0);
  810. }
  811. sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
  812. sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
  813. if (sinfo)
  814. sta_set_sinfo(sta, sinfo);
  815. cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
  816. kfree(sinfo);
  817. rate_control_remove_sta_debugfs(sta);
  818. ieee80211_sta_debugfs_remove(sta);
  819. cleanup_single_sta(sta);
  820. }
  821. int __must_check __sta_info_destroy(struct sta_info *sta)
  822. {
  823. int err = __sta_info_destroy_part1(sta);
  824. if (err)
  825. return err;
  826. synchronize_net();
  827. __sta_info_destroy_part2(sta);
  828. return 0;
  829. }
  830. int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
  831. {
  832. struct sta_info *sta;
  833. int ret;
  834. mutex_lock(&sdata->local->sta_mtx);
  835. sta = sta_info_get(sdata, addr);
  836. ret = __sta_info_destroy(sta);
  837. mutex_unlock(&sdata->local->sta_mtx);
  838. return ret;
  839. }
  840. int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
  841. const u8 *addr)
  842. {
  843. struct sta_info *sta;
  844. int ret;
  845. mutex_lock(&sdata->local->sta_mtx);
  846. sta = sta_info_get_bss(sdata, addr);
  847. ret = __sta_info_destroy(sta);
  848. mutex_unlock(&sdata->local->sta_mtx);
  849. return ret;
  850. }
  851. static void sta_info_cleanup(unsigned long data)
  852. {
  853. struct ieee80211_local *local = (struct ieee80211_local *) data;
  854. struct sta_info *sta;
  855. bool timer_needed = false;
  856. rcu_read_lock();
  857. list_for_each_entry_rcu(sta, &local->sta_list, list)
  858. if (sta_info_cleanup_expire_buffered(local, sta))
  859. timer_needed = true;
  860. rcu_read_unlock();
  861. if (local->quiescing)
  862. return;
  863. if (!timer_needed)
  864. return;
  865. mod_timer(&local->sta_cleanup,
  866. round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
  867. }
  868. int sta_info_init(struct ieee80211_local *local)
  869. {
  870. int err;
  871. err = rhltable_init(&local->sta_hash, &sta_rht_params);
  872. if (err)
  873. return err;
  874. spin_lock_init(&local->tim_lock);
  875. mutex_init(&local->sta_mtx);
  876. INIT_LIST_HEAD(&local->sta_list);
  877. setup_timer(&local->sta_cleanup, sta_info_cleanup,
  878. (unsigned long)local);
  879. return 0;
  880. }
  881. void sta_info_stop(struct ieee80211_local *local)
  882. {
  883. del_timer_sync(&local->sta_cleanup);
  884. rhltable_destroy(&local->sta_hash);
  885. }
  886. int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
  887. {
  888. struct ieee80211_local *local = sdata->local;
  889. struct sta_info *sta, *tmp;
  890. LIST_HEAD(free_list);
  891. int ret = 0;
  892. might_sleep();
  893. WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
  894. WARN_ON(vlans && !sdata->bss);
  895. mutex_lock(&local->sta_mtx);
  896. list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
  897. if (sdata == sta->sdata ||
  898. (vlans && sdata->bss == sta->sdata->bss)) {
  899. if (!WARN_ON(__sta_info_destroy_part1(sta)))
  900. list_add(&sta->free_list, &free_list);
  901. ret++;
  902. }
  903. }
  904. if (!list_empty(&free_list)) {
  905. synchronize_net();
  906. list_for_each_entry_safe(sta, tmp, &free_list, free_list)
  907. __sta_info_destroy_part2(sta);
  908. }
  909. mutex_unlock(&local->sta_mtx);
  910. return ret;
  911. }
  912. void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
  913. unsigned long exp_time)
  914. {
  915. struct ieee80211_local *local = sdata->local;
  916. struct sta_info *sta, *tmp;
  917. mutex_lock(&local->sta_mtx);
  918. list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
  919. unsigned long last_active = ieee80211_sta_last_active(sta);
  920. if (sdata != sta->sdata)
  921. continue;
  922. if (time_is_before_jiffies(last_active + exp_time)) {
  923. sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
  924. sta->sta.addr);
  925. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  926. test_sta_flag(sta, WLAN_STA_PS_STA))
  927. atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
  928. WARN_ON(__sta_info_destroy(sta));
  929. }
  930. }
  931. mutex_unlock(&local->sta_mtx);
  932. }
  933. struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
  934. const u8 *addr,
  935. const u8 *localaddr)
  936. {
  937. struct ieee80211_local *local = hw_to_local(hw);
  938. struct rhlist_head *tmp;
  939. struct sta_info *sta;
  940. /*
  941. * Just return a random station if localaddr is NULL
  942. * ... first in list.
  943. */
  944. for_each_sta_info(local, addr, sta, tmp) {
  945. if (localaddr &&
  946. !ether_addr_equal(sta->sdata->vif.addr, localaddr))
  947. continue;
  948. if (!sta->uploaded)
  949. return NULL;
  950. return &sta->sta;
  951. }
  952. return NULL;
  953. }
  954. EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
  955. struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
  956. const u8 *addr)
  957. {
  958. struct sta_info *sta;
  959. if (!vif)
  960. return NULL;
  961. sta = sta_info_get_bss(vif_to_sdata(vif), addr);
  962. if (!sta)
  963. return NULL;
  964. if (!sta->uploaded)
  965. return NULL;
  966. return &sta->sta;
  967. }
  968. EXPORT_SYMBOL(ieee80211_find_sta);
  969. /* powersave support code */
  970. void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
  971. {
  972. struct ieee80211_sub_if_data *sdata = sta->sdata;
  973. struct ieee80211_local *local = sdata->local;
  974. struct sk_buff_head pending;
  975. int filtered = 0, buffered = 0, ac, i;
  976. unsigned long flags;
  977. struct ps_data *ps;
  978. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  979. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  980. u.ap);
  981. if (sdata->vif.type == NL80211_IFTYPE_AP)
  982. ps = &sdata->bss->ps;
  983. else if (ieee80211_vif_is_mesh(&sdata->vif))
  984. ps = &sdata->u.mesh.ps;
  985. else
  986. return;
  987. clear_sta_flag(sta, WLAN_STA_SP);
  988. BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
  989. sta->driver_buffered_tids = 0;
  990. sta->txq_buffered_tids = 0;
  991. if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
  992. drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
  993. if (sta->sta.txq[0]) {
  994. for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
  995. if (!txq_has_queue(sta->sta.txq[i]))
  996. continue;
  997. drv_wake_tx_queue(local, to_txq_info(sta->sta.txq[i]));
  998. }
  999. }
  1000. skb_queue_head_init(&pending);
  1001. /* sync with ieee80211_tx_h_unicast_ps_buf */
  1002. spin_lock(&sta->ps_lock);
  1003. /* Send all buffered frames to the station */
  1004. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1005. int count = skb_queue_len(&pending), tmp;
  1006. spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
  1007. skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
  1008. spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
  1009. tmp = skb_queue_len(&pending);
  1010. filtered += tmp - count;
  1011. count = tmp;
  1012. spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
  1013. skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
  1014. spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
  1015. tmp = skb_queue_len(&pending);
  1016. buffered += tmp - count;
  1017. }
  1018. ieee80211_add_pending_skbs(local, &pending);
  1019. /* now we're no longer in the deliver code */
  1020. clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
  1021. /* The station might have polled and then woken up before we responded,
  1022. * so clear these flags now to avoid them sticking around.
  1023. */
  1024. clear_sta_flag(sta, WLAN_STA_PSPOLL);
  1025. clear_sta_flag(sta, WLAN_STA_UAPSD);
  1026. spin_unlock(&sta->ps_lock);
  1027. atomic_dec(&ps->num_sta_ps);
  1028. /* This station just woke up and isn't aware of our SMPS state */
  1029. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  1030. !ieee80211_smps_is_restrictive(sta->known_smps_mode,
  1031. sdata->smps_mode) &&
  1032. sta->known_smps_mode != sdata->bss->req_smps &&
  1033. sta_info_tx_streams(sta) != 1) {
  1034. ht_dbg(sdata,
  1035. "%pM just woke up and MIMO capable - update SMPS\n",
  1036. sta->sta.addr);
  1037. ieee80211_send_smps_action(sdata, sdata->bss->req_smps,
  1038. sta->sta.addr,
  1039. sdata->vif.bss_conf.bssid);
  1040. }
  1041. local->total_ps_buffered -= buffered;
  1042. sta_info_recalc_tim(sta);
  1043. ps_dbg(sdata,
  1044. "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
  1045. sta->sta.addr, sta->sta.aid, filtered, buffered);
  1046. ieee80211_check_fast_xmit(sta);
  1047. }
  1048. static void ieee80211_send_null_response(struct sta_info *sta, int tid,
  1049. enum ieee80211_frame_release_type reason,
  1050. bool call_driver, bool more_data)
  1051. {
  1052. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1053. struct ieee80211_local *local = sdata->local;
  1054. struct ieee80211_qos_hdr *nullfunc;
  1055. struct sk_buff *skb;
  1056. int size = sizeof(*nullfunc);
  1057. __le16 fc;
  1058. bool qos = sta->sta.wme;
  1059. struct ieee80211_tx_info *info;
  1060. struct ieee80211_chanctx_conf *chanctx_conf;
  1061. if (qos) {
  1062. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  1063. IEEE80211_STYPE_QOS_NULLFUNC |
  1064. IEEE80211_FCTL_FROMDS);
  1065. } else {
  1066. size -= 2;
  1067. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  1068. IEEE80211_STYPE_NULLFUNC |
  1069. IEEE80211_FCTL_FROMDS);
  1070. }
  1071. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  1072. if (!skb)
  1073. return;
  1074. skb_reserve(skb, local->hw.extra_tx_headroom);
  1075. nullfunc = (void *) skb_put(skb, size);
  1076. nullfunc->frame_control = fc;
  1077. nullfunc->duration_id = 0;
  1078. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  1079. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  1080. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  1081. nullfunc->seq_ctrl = 0;
  1082. skb->priority = tid;
  1083. skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
  1084. if (qos) {
  1085. nullfunc->qos_ctrl = cpu_to_le16(tid);
  1086. if (reason == IEEE80211_FRAME_RELEASE_UAPSD) {
  1087. nullfunc->qos_ctrl |=
  1088. cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
  1089. if (more_data)
  1090. nullfunc->frame_control |=
  1091. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1092. }
  1093. }
  1094. info = IEEE80211_SKB_CB(skb);
  1095. /*
  1096. * Tell TX path to send this frame even though the
  1097. * STA may still remain is PS mode after this frame
  1098. * exchange. Also set EOSP to indicate this packet
  1099. * ends the poll/service period.
  1100. */
  1101. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
  1102. IEEE80211_TX_STATUS_EOSP |
  1103. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1104. info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
  1105. if (call_driver)
  1106. drv_allow_buffered_frames(local, sta, BIT(tid), 1,
  1107. reason, false);
  1108. skb->dev = sdata->dev;
  1109. rcu_read_lock();
  1110. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1111. if (WARN_ON(!chanctx_conf)) {
  1112. rcu_read_unlock();
  1113. kfree_skb(skb);
  1114. return;
  1115. }
  1116. info->band = chanctx_conf->def.chan->band;
  1117. ieee80211_xmit(sdata, sta, skb);
  1118. rcu_read_unlock();
  1119. }
  1120. static int find_highest_prio_tid(unsigned long tids)
  1121. {
  1122. /* lower 3 TIDs aren't ordered perfectly */
  1123. if (tids & 0xF8)
  1124. return fls(tids) - 1;
  1125. /* TID 0 is BE just like TID 3 */
  1126. if (tids & BIT(0))
  1127. return 0;
  1128. return fls(tids) - 1;
  1129. }
  1130. /* Indicates if the MORE_DATA bit should be set in the last
  1131. * frame obtained by ieee80211_sta_ps_get_frames.
  1132. * Note that driver_release_tids is relevant only if
  1133. * reason = IEEE80211_FRAME_RELEASE_PSPOLL
  1134. */
  1135. static bool
  1136. ieee80211_sta_ps_more_data(struct sta_info *sta, u8 ignored_acs,
  1137. enum ieee80211_frame_release_type reason,
  1138. unsigned long driver_release_tids)
  1139. {
  1140. int ac;
  1141. /* If the driver has data on more than one TID then
  1142. * certainly there's more data if we release just a
  1143. * single frame now (from a single TID). This will
  1144. * only happen for PS-Poll.
  1145. */
  1146. if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
  1147. hweight16(driver_release_tids) > 1)
  1148. return true;
  1149. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1150. if (ignored_acs & BIT(ac))
  1151. continue;
  1152. if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
  1153. !skb_queue_empty(&sta->ps_tx_buf[ac]))
  1154. return true;
  1155. }
  1156. return false;
  1157. }
  1158. static void
  1159. ieee80211_sta_ps_get_frames(struct sta_info *sta, int n_frames, u8 ignored_acs,
  1160. enum ieee80211_frame_release_type reason,
  1161. struct sk_buff_head *frames,
  1162. unsigned long *driver_release_tids)
  1163. {
  1164. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1165. struct ieee80211_local *local = sdata->local;
  1166. int ac;
  1167. /* Get response frame(s) and more data bit for the last one. */
  1168. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1169. unsigned long tids;
  1170. if (ignored_acs & BIT(ac))
  1171. continue;
  1172. tids = ieee80211_tids_for_ac(ac);
  1173. /* if we already have frames from software, then we can't also
  1174. * release from hardware queues
  1175. */
  1176. if (skb_queue_empty(frames)) {
  1177. *driver_release_tids |=
  1178. sta->driver_buffered_tids & tids;
  1179. *driver_release_tids |= sta->txq_buffered_tids & tids;
  1180. }
  1181. if (!*driver_release_tids) {
  1182. struct sk_buff *skb;
  1183. while (n_frames > 0) {
  1184. skb = skb_dequeue(&sta->tx_filtered[ac]);
  1185. if (!skb) {
  1186. skb = skb_dequeue(
  1187. &sta->ps_tx_buf[ac]);
  1188. if (skb)
  1189. local->total_ps_buffered--;
  1190. }
  1191. if (!skb)
  1192. break;
  1193. n_frames--;
  1194. __skb_queue_tail(frames, skb);
  1195. }
  1196. }
  1197. /* If we have more frames buffered on this AC, then abort the
  1198. * loop since we can't send more data from other ACs before
  1199. * the buffered frames from this.
  1200. */
  1201. if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
  1202. !skb_queue_empty(&sta->ps_tx_buf[ac]))
  1203. break;
  1204. }
  1205. }
  1206. static void
  1207. ieee80211_sta_ps_deliver_response(struct sta_info *sta,
  1208. int n_frames, u8 ignored_acs,
  1209. enum ieee80211_frame_release_type reason)
  1210. {
  1211. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1212. struct ieee80211_local *local = sdata->local;
  1213. unsigned long driver_release_tids = 0;
  1214. struct sk_buff_head frames;
  1215. bool more_data;
  1216. /* Service or PS-Poll period starts */
  1217. set_sta_flag(sta, WLAN_STA_SP);
  1218. __skb_queue_head_init(&frames);
  1219. ieee80211_sta_ps_get_frames(sta, n_frames, ignored_acs, reason,
  1220. &frames, &driver_release_tids);
  1221. more_data = ieee80211_sta_ps_more_data(sta, ignored_acs, reason, driver_release_tids);
  1222. if (driver_release_tids && reason == IEEE80211_FRAME_RELEASE_PSPOLL)
  1223. driver_release_tids =
  1224. BIT(find_highest_prio_tid(driver_release_tids));
  1225. if (skb_queue_empty(&frames) && !driver_release_tids) {
  1226. int tid;
  1227. /*
  1228. * For PS-Poll, this can only happen due to a race condition
  1229. * when we set the TIM bit and the station notices it, but
  1230. * before it can poll for the frame we expire it.
  1231. *
  1232. * For uAPSD, this is said in the standard (11.2.1.5 h):
  1233. * At each unscheduled SP for a non-AP STA, the AP shall
  1234. * attempt to transmit at least one MSDU or MMPDU, but no
  1235. * more than the value specified in the Max SP Length field
  1236. * in the QoS Capability element from delivery-enabled ACs,
  1237. * that are destined for the non-AP STA.
  1238. *
  1239. * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
  1240. */
  1241. /* This will evaluate to 1, 3, 5 or 7. */
  1242. tid = 7 - ((ffs(~ignored_acs) - 1) << 1);
  1243. ieee80211_send_null_response(sta, tid, reason, true, false);
  1244. } else if (!driver_release_tids) {
  1245. struct sk_buff_head pending;
  1246. struct sk_buff *skb;
  1247. int num = 0;
  1248. u16 tids = 0;
  1249. bool need_null = false;
  1250. skb_queue_head_init(&pending);
  1251. while ((skb = __skb_dequeue(&frames))) {
  1252. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1253. struct ieee80211_hdr *hdr = (void *) skb->data;
  1254. u8 *qoshdr = NULL;
  1255. num++;
  1256. /*
  1257. * Tell TX path to send this frame even though the
  1258. * STA may still remain is PS mode after this frame
  1259. * exchange.
  1260. */
  1261. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
  1262. info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
  1263. /*
  1264. * Use MoreData flag to indicate whether there are
  1265. * more buffered frames for this STA
  1266. */
  1267. if (more_data || !skb_queue_empty(&frames))
  1268. hdr->frame_control |=
  1269. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1270. else
  1271. hdr->frame_control &=
  1272. cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  1273. if (ieee80211_is_data_qos(hdr->frame_control) ||
  1274. ieee80211_is_qos_nullfunc(hdr->frame_control))
  1275. qoshdr = ieee80211_get_qos_ctl(hdr);
  1276. tids |= BIT(skb->priority);
  1277. __skb_queue_tail(&pending, skb);
  1278. /* end service period after last frame or add one */
  1279. if (!skb_queue_empty(&frames))
  1280. continue;
  1281. if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
  1282. /* for PS-Poll, there's only one frame */
  1283. info->flags |= IEEE80211_TX_STATUS_EOSP |
  1284. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1285. break;
  1286. }
  1287. /* For uAPSD, things are a bit more complicated. If the
  1288. * last frame has a QoS header (i.e. is a QoS-data or
  1289. * QoS-nulldata frame) then just set the EOSP bit there
  1290. * and be done.
  1291. * If the frame doesn't have a QoS header (which means
  1292. * it should be a bufferable MMPDU) then we can't set
  1293. * the EOSP bit in the QoS header; add a QoS-nulldata
  1294. * frame to the list to send it after the MMPDU.
  1295. *
  1296. * Note that this code is only in the mac80211-release
  1297. * code path, we assume that the driver will not buffer
  1298. * anything but QoS-data frames, or if it does, will
  1299. * create the QoS-nulldata frame by itself if needed.
  1300. *
  1301. * Cf. 802.11-2012 10.2.1.10 (c).
  1302. */
  1303. if (qoshdr) {
  1304. *qoshdr |= IEEE80211_QOS_CTL_EOSP;
  1305. info->flags |= IEEE80211_TX_STATUS_EOSP |
  1306. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1307. } else {
  1308. /* The standard isn't completely clear on this
  1309. * as it says the more-data bit should be set
  1310. * if there are more BUs. The QoS-Null frame
  1311. * we're about to send isn't buffered yet, we
  1312. * only create it below, but let's pretend it
  1313. * was buffered just in case some clients only
  1314. * expect more-data=0 when eosp=1.
  1315. */
  1316. hdr->frame_control |=
  1317. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1318. need_null = true;
  1319. num++;
  1320. }
  1321. break;
  1322. }
  1323. drv_allow_buffered_frames(local, sta, tids, num,
  1324. reason, more_data);
  1325. ieee80211_add_pending_skbs(local, &pending);
  1326. if (need_null)
  1327. ieee80211_send_null_response(
  1328. sta, find_highest_prio_tid(tids),
  1329. reason, false, false);
  1330. sta_info_recalc_tim(sta);
  1331. } else {
  1332. int tid;
  1333. /*
  1334. * We need to release a frame that is buffered somewhere in the
  1335. * driver ... it'll have to handle that.
  1336. * Note that the driver also has to check the number of frames
  1337. * on the TIDs we're releasing from - if there are more than
  1338. * n_frames it has to set the more-data bit (if we didn't ask
  1339. * it to set it anyway due to other buffered frames); if there
  1340. * are fewer than n_frames it has to make sure to adjust that
  1341. * to allow the service period to end properly.
  1342. */
  1343. drv_release_buffered_frames(local, sta, driver_release_tids,
  1344. n_frames, reason, more_data);
  1345. /*
  1346. * Note that we don't recalculate the TIM bit here as it would
  1347. * most likely have no effect at all unless the driver told us
  1348. * that the TID(s) became empty before returning here from the
  1349. * release function.
  1350. * Either way, however, when the driver tells us that the TID(s)
  1351. * became empty or we find that a txq became empty, we'll do the
  1352. * TIM recalculation.
  1353. */
  1354. if (!sta->sta.txq[0])
  1355. return;
  1356. for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
  1357. if (!(driver_release_tids & BIT(tid)) ||
  1358. txq_has_queue(sta->sta.txq[tid]))
  1359. continue;
  1360. sta_info_recalc_tim(sta);
  1361. break;
  1362. }
  1363. }
  1364. }
  1365. void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
  1366. {
  1367. u8 ignore_for_response = sta->sta.uapsd_queues;
  1368. /*
  1369. * If all ACs are delivery-enabled then we should reply
  1370. * from any of them, if only some are enabled we reply
  1371. * only from the non-enabled ones.
  1372. */
  1373. if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
  1374. ignore_for_response = 0;
  1375. ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
  1376. IEEE80211_FRAME_RELEASE_PSPOLL);
  1377. }
  1378. void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
  1379. {
  1380. int n_frames = sta->sta.max_sp;
  1381. u8 delivery_enabled = sta->sta.uapsd_queues;
  1382. /*
  1383. * If we ever grow support for TSPEC this might happen if
  1384. * the TSPEC update from hostapd comes in between a trigger
  1385. * frame setting WLAN_STA_UAPSD in the RX path and this
  1386. * actually getting called.
  1387. */
  1388. if (!delivery_enabled)
  1389. return;
  1390. switch (sta->sta.max_sp) {
  1391. case 1:
  1392. n_frames = 2;
  1393. break;
  1394. case 2:
  1395. n_frames = 4;
  1396. break;
  1397. case 3:
  1398. n_frames = 6;
  1399. break;
  1400. case 0:
  1401. /* XXX: what is a good value? */
  1402. n_frames = 128;
  1403. break;
  1404. }
  1405. ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
  1406. IEEE80211_FRAME_RELEASE_UAPSD);
  1407. }
  1408. void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
  1409. struct ieee80211_sta *pubsta, bool block)
  1410. {
  1411. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1412. trace_api_sta_block_awake(sta->local, pubsta, block);
  1413. if (block) {
  1414. set_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1415. ieee80211_clear_fast_xmit(sta);
  1416. return;
  1417. }
  1418. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1419. return;
  1420. if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1421. set_sta_flag(sta, WLAN_STA_PS_DELIVER);
  1422. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1423. ieee80211_queue_work(hw, &sta->drv_deliver_wk);
  1424. } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
  1425. test_sta_flag(sta, WLAN_STA_UAPSD)) {
  1426. /* must be asleep in this case */
  1427. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1428. ieee80211_queue_work(hw, &sta->drv_deliver_wk);
  1429. } else {
  1430. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1431. ieee80211_check_fast_xmit(sta);
  1432. }
  1433. }
  1434. EXPORT_SYMBOL(ieee80211_sta_block_awake);
  1435. void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
  1436. {
  1437. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1438. struct ieee80211_local *local = sta->local;
  1439. trace_api_eosp(local, pubsta);
  1440. clear_sta_flag(sta, WLAN_STA_SP);
  1441. }
  1442. EXPORT_SYMBOL(ieee80211_sta_eosp);
  1443. void ieee80211_send_eosp_nullfunc(struct ieee80211_sta *pubsta, int tid)
  1444. {
  1445. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1446. enum ieee80211_frame_release_type reason;
  1447. bool more_data;
  1448. trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
  1449. reason = IEEE80211_FRAME_RELEASE_UAPSD;
  1450. more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
  1451. reason, 0);
  1452. ieee80211_send_null_response(sta, tid, reason, false, more_data);
  1453. }
  1454. EXPORT_SYMBOL(ieee80211_send_eosp_nullfunc);
  1455. void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
  1456. u8 tid, bool buffered)
  1457. {
  1458. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1459. if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
  1460. return;
  1461. trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
  1462. if (buffered)
  1463. set_bit(tid, &sta->driver_buffered_tids);
  1464. else
  1465. clear_bit(tid, &sta->driver_buffered_tids);
  1466. sta_info_recalc_tim(sta);
  1467. }
  1468. EXPORT_SYMBOL(ieee80211_sta_set_buffered);
  1469. static void
  1470. ieee80211_recalc_p2p_go_ps_allowed(struct ieee80211_sub_if_data *sdata)
  1471. {
  1472. struct ieee80211_local *local = sdata->local;
  1473. bool allow_p2p_go_ps = sdata->vif.p2p;
  1474. struct sta_info *sta;
  1475. rcu_read_lock();
  1476. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  1477. if (sdata != sta->sdata ||
  1478. !test_sta_flag(sta, WLAN_STA_ASSOC))
  1479. continue;
  1480. if (!sta->sta.support_p2p_ps) {
  1481. allow_p2p_go_ps = false;
  1482. break;
  1483. }
  1484. }
  1485. rcu_read_unlock();
  1486. if (allow_p2p_go_ps != sdata->vif.bss_conf.allow_p2p_go_ps) {
  1487. sdata->vif.bss_conf.allow_p2p_go_ps = allow_p2p_go_ps;
  1488. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_P2P_PS);
  1489. }
  1490. }
  1491. int sta_info_move_state(struct sta_info *sta,
  1492. enum ieee80211_sta_state new_state)
  1493. {
  1494. might_sleep();
  1495. if (sta->sta_state == new_state)
  1496. return 0;
  1497. /* check allowed transitions first */
  1498. switch (new_state) {
  1499. case IEEE80211_STA_NONE:
  1500. if (sta->sta_state != IEEE80211_STA_AUTH)
  1501. return -EINVAL;
  1502. break;
  1503. case IEEE80211_STA_AUTH:
  1504. if (sta->sta_state != IEEE80211_STA_NONE &&
  1505. sta->sta_state != IEEE80211_STA_ASSOC)
  1506. return -EINVAL;
  1507. break;
  1508. case IEEE80211_STA_ASSOC:
  1509. if (sta->sta_state != IEEE80211_STA_AUTH &&
  1510. sta->sta_state != IEEE80211_STA_AUTHORIZED)
  1511. return -EINVAL;
  1512. break;
  1513. case IEEE80211_STA_AUTHORIZED:
  1514. if (sta->sta_state != IEEE80211_STA_ASSOC)
  1515. return -EINVAL;
  1516. break;
  1517. default:
  1518. WARN(1, "invalid state %d", new_state);
  1519. return -EINVAL;
  1520. }
  1521. sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
  1522. sta->sta.addr, new_state);
  1523. /*
  1524. * notify the driver before the actual changes so it can
  1525. * fail the transition
  1526. */
  1527. if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
  1528. int err = drv_sta_state(sta->local, sta->sdata, sta,
  1529. sta->sta_state, new_state);
  1530. if (err)
  1531. return err;
  1532. }
  1533. /* reflect the change in all state variables */
  1534. switch (new_state) {
  1535. case IEEE80211_STA_NONE:
  1536. if (sta->sta_state == IEEE80211_STA_AUTH)
  1537. clear_bit(WLAN_STA_AUTH, &sta->_flags);
  1538. break;
  1539. case IEEE80211_STA_AUTH:
  1540. if (sta->sta_state == IEEE80211_STA_NONE) {
  1541. set_bit(WLAN_STA_AUTH, &sta->_flags);
  1542. } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
  1543. clear_bit(WLAN_STA_ASSOC, &sta->_flags);
  1544. ieee80211_recalc_min_chandef(sta->sdata);
  1545. if (!sta->sta.support_p2p_ps)
  1546. ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
  1547. }
  1548. break;
  1549. case IEEE80211_STA_ASSOC:
  1550. if (sta->sta_state == IEEE80211_STA_AUTH) {
  1551. set_bit(WLAN_STA_ASSOC, &sta->_flags);
  1552. ieee80211_recalc_min_chandef(sta->sdata);
  1553. if (!sta->sta.support_p2p_ps)
  1554. ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
  1555. } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
  1556. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  1557. (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1558. !sta->sdata->u.vlan.sta))
  1559. atomic_dec(&sta->sdata->bss->num_mcast_sta);
  1560. clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
  1561. ieee80211_clear_fast_xmit(sta);
  1562. ieee80211_clear_fast_rx(sta);
  1563. }
  1564. break;
  1565. case IEEE80211_STA_AUTHORIZED:
  1566. if (sta->sta_state == IEEE80211_STA_ASSOC) {
  1567. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  1568. (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1569. !sta->sdata->u.vlan.sta))
  1570. atomic_inc(&sta->sdata->bss->num_mcast_sta);
  1571. set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
  1572. ieee80211_check_fast_xmit(sta);
  1573. ieee80211_check_fast_rx(sta);
  1574. }
  1575. break;
  1576. default:
  1577. break;
  1578. }
  1579. sta->sta_state = new_state;
  1580. return 0;
  1581. }
  1582. u8 sta_info_tx_streams(struct sta_info *sta)
  1583. {
  1584. struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
  1585. u8 rx_streams;
  1586. if (!sta->sta.ht_cap.ht_supported)
  1587. return 1;
  1588. if (sta->sta.vht_cap.vht_supported) {
  1589. int i;
  1590. u16 tx_mcs_map =
  1591. le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
  1592. for (i = 7; i >= 0; i--)
  1593. if ((tx_mcs_map & (0x3 << (i * 2))) !=
  1594. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  1595. return i + 1;
  1596. }
  1597. if (ht_cap->mcs.rx_mask[3])
  1598. rx_streams = 4;
  1599. else if (ht_cap->mcs.rx_mask[2])
  1600. rx_streams = 3;
  1601. else if (ht_cap->mcs.rx_mask[1])
  1602. rx_streams = 2;
  1603. else
  1604. rx_streams = 1;
  1605. if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
  1606. return rx_streams;
  1607. return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1608. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
  1609. }
  1610. static struct ieee80211_sta_rx_stats *
  1611. sta_get_last_rx_stats(struct sta_info *sta)
  1612. {
  1613. struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
  1614. struct ieee80211_local *local = sta->local;
  1615. int cpu;
  1616. if (!ieee80211_hw_check(&local->hw, USES_RSS))
  1617. return stats;
  1618. for_each_possible_cpu(cpu) {
  1619. struct ieee80211_sta_rx_stats *cpustats;
  1620. cpustats = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1621. if (time_after(cpustats->last_rx, stats->last_rx))
  1622. stats = cpustats;
  1623. }
  1624. return stats;
  1625. }
  1626. static void sta_stats_decode_rate(struct ieee80211_local *local, u16 rate,
  1627. struct rate_info *rinfo)
  1628. {
  1629. rinfo->bw = (rate & STA_STATS_RATE_BW_MASK) >>
  1630. STA_STATS_RATE_BW_SHIFT;
  1631. if (rate & STA_STATS_RATE_VHT) {
  1632. rinfo->flags = RATE_INFO_FLAGS_VHT_MCS;
  1633. rinfo->mcs = rate & 0xf;
  1634. rinfo->nss = (rate & 0xf0) >> 4;
  1635. } else if (rate & STA_STATS_RATE_HT) {
  1636. rinfo->flags = RATE_INFO_FLAGS_MCS;
  1637. rinfo->mcs = rate & 0xff;
  1638. } else if (rate & STA_STATS_RATE_LEGACY) {
  1639. struct ieee80211_supported_band *sband;
  1640. u16 brate;
  1641. unsigned int shift;
  1642. sband = local->hw.wiphy->bands[(rate >> 4) & 0xf];
  1643. brate = sband->bitrates[rate & 0xf].bitrate;
  1644. if (rinfo->bw == RATE_INFO_BW_5)
  1645. shift = 2;
  1646. else if (rinfo->bw == RATE_INFO_BW_10)
  1647. shift = 1;
  1648. else
  1649. shift = 0;
  1650. rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
  1651. }
  1652. if (rate & STA_STATS_RATE_SGI)
  1653. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  1654. }
  1655. static void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
  1656. {
  1657. u16 rate = ACCESS_ONCE(sta_get_last_rx_stats(sta)->last_rate);
  1658. if (rate == STA_STATS_RATE_INVALID)
  1659. rinfo->flags = 0;
  1660. else
  1661. sta_stats_decode_rate(sta->local, rate, rinfo);
  1662. }
  1663. static void sta_set_tidstats(struct sta_info *sta,
  1664. struct cfg80211_tid_stats *tidstats,
  1665. int tid)
  1666. {
  1667. struct ieee80211_local *local = sta->local;
  1668. if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
  1669. unsigned int start;
  1670. do {
  1671. start = u64_stats_fetch_begin(&sta->rx_stats.syncp);
  1672. tidstats->rx_msdu = sta->rx_stats.msdu[tid];
  1673. } while (u64_stats_fetch_retry(&sta->rx_stats.syncp, start));
  1674. tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
  1675. }
  1676. if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
  1677. tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
  1678. tidstats->tx_msdu = sta->tx_stats.msdu[tid];
  1679. }
  1680. if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
  1681. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  1682. tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
  1683. tidstats->tx_msdu_retries = sta->status_stats.msdu_retries[tid];
  1684. }
  1685. if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
  1686. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  1687. tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
  1688. tidstats->tx_msdu_failed = sta->status_stats.msdu_failed[tid];
  1689. }
  1690. }
  1691. static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
  1692. {
  1693. unsigned int start;
  1694. u64 value;
  1695. do {
  1696. start = u64_stats_fetch_begin(&rxstats->syncp);
  1697. value = rxstats->bytes;
  1698. } while (u64_stats_fetch_retry(&rxstats->syncp, start));
  1699. return value;
  1700. }
  1701. void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  1702. {
  1703. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1704. struct ieee80211_local *local = sdata->local;
  1705. struct rate_control_ref *ref = NULL;
  1706. u32 thr = 0;
  1707. int i, ac, cpu;
  1708. struct ieee80211_sta_rx_stats *last_rxstats;
  1709. last_rxstats = sta_get_last_rx_stats(sta);
  1710. if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  1711. ref = local->rate_ctrl;
  1712. sinfo->generation = sdata->local->sta_generation;
  1713. /* do before driver, so beacon filtering drivers have a
  1714. * chance to e.g. just add the number of filtered beacons
  1715. * (or just modify the value entirely, of course)
  1716. */
  1717. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1718. sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
  1719. drv_sta_statistics(local, sdata, &sta->sta, sinfo);
  1720. sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
  1721. BIT(NL80211_STA_INFO_STA_FLAGS) |
  1722. BIT(NL80211_STA_INFO_BSS_PARAM) |
  1723. BIT(NL80211_STA_INFO_CONNECTED_TIME) |
  1724. BIT(NL80211_STA_INFO_RX_DROP_MISC);
  1725. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  1726. sinfo->beacon_loss_count = sdata->u.mgd.beacon_loss_count;
  1727. sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_LOSS);
  1728. }
  1729. sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
  1730. sinfo->inactive_time =
  1731. jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
  1732. if (!(sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES64) |
  1733. BIT(NL80211_STA_INFO_TX_BYTES)))) {
  1734. sinfo->tx_bytes = 0;
  1735. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  1736. sinfo->tx_bytes += sta->tx_stats.bytes[ac];
  1737. sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES64);
  1738. }
  1739. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_PACKETS))) {
  1740. sinfo->tx_packets = 0;
  1741. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  1742. sinfo->tx_packets += sta->tx_stats.packets[ac];
  1743. sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
  1744. }
  1745. if (!(sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES64) |
  1746. BIT(NL80211_STA_INFO_RX_BYTES)))) {
  1747. sinfo->rx_bytes += sta_get_stats_bytes(&sta->rx_stats);
  1748. if (sta->pcpu_rx_stats) {
  1749. for_each_possible_cpu(cpu) {
  1750. struct ieee80211_sta_rx_stats *cpurxs;
  1751. cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1752. sinfo->rx_bytes += sta_get_stats_bytes(cpurxs);
  1753. }
  1754. }
  1755. sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES64);
  1756. }
  1757. if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_PACKETS))) {
  1758. sinfo->rx_packets = sta->rx_stats.packets;
  1759. if (sta->pcpu_rx_stats) {
  1760. for_each_possible_cpu(cpu) {
  1761. struct ieee80211_sta_rx_stats *cpurxs;
  1762. cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1763. sinfo->rx_packets += cpurxs->packets;
  1764. }
  1765. }
  1766. sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
  1767. }
  1768. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_RETRIES))) {
  1769. sinfo->tx_retries = sta->status_stats.retry_count;
  1770. sinfo->filled |= BIT(NL80211_STA_INFO_TX_RETRIES);
  1771. }
  1772. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_FAILED))) {
  1773. sinfo->tx_failed = sta->status_stats.retry_failed;
  1774. sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
  1775. }
  1776. sinfo->rx_dropped_misc = sta->rx_stats.dropped;
  1777. if (sta->pcpu_rx_stats) {
  1778. for_each_possible_cpu(cpu) {
  1779. struct ieee80211_sta_rx_stats *cpurxs;
  1780. cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1781. sinfo->rx_dropped_misc += cpurxs->dropped;
  1782. }
  1783. }
  1784. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1785. !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
  1786. sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX) |
  1787. BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
  1788. sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
  1789. }
  1790. if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
  1791. ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
  1792. if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL))) {
  1793. sinfo->signal = (s8)last_rxstats->last_signal;
  1794. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
  1795. }
  1796. if (!sta->pcpu_rx_stats &&
  1797. !(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))) {
  1798. sinfo->signal_avg =
  1799. -ewma_signal_read(&sta->rx_stats_avg.signal);
  1800. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
  1801. }
  1802. }
  1803. /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
  1804. * the sta->rx_stats struct, so the check here is fine with and without
  1805. * pcpu statistics
  1806. */
  1807. if (last_rxstats->chains &&
  1808. !(sinfo->filled & (BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
  1809. BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
  1810. sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL);
  1811. if (!sta->pcpu_rx_stats)
  1812. sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
  1813. sinfo->chains = last_rxstats->chains;
  1814. for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
  1815. sinfo->chain_signal[i] =
  1816. last_rxstats->chain_signal_last[i];
  1817. sinfo->chain_signal_avg[i] =
  1818. -ewma_signal_read(&sta->rx_stats_avg.chain_signal[i]);
  1819. }
  1820. }
  1821. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE))) {
  1822. sta_set_rate_info_tx(sta, &sta->tx_stats.last_rate,
  1823. &sinfo->txrate);
  1824. sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
  1825. }
  1826. if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE))) {
  1827. sta_set_rate_info_rx(sta, &sinfo->rxrate);
  1828. sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
  1829. }
  1830. sinfo->filled |= BIT(NL80211_STA_INFO_TID_STATS);
  1831. for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
  1832. struct cfg80211_tid_stats *tidstats = &sinfo->pertid[i];
  1833. sta_set_tidstats(sta, tidstats, i);
  1834. }
  1835. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1836. #ifdef CONFIG_MAC80211_MESH
  1837. sinfo->filled |= BIT(NL80211_STA_INFO_LLID) |
  1838. BIT(NL80211_STA_INFO_PLID) |
  1839. BIT(NL80211_STA_INFO_PLINK_STATE) |
  1840. BIT(NL80211_STA_INFO_LOCAL_PM) |
  1841. BIT(NL80211_STA_INFO_PEER_PM) |
  1842. BIT(NL80211_STA_INFO_NONPEER_PM);
  1843. sinfo->llid = sta->mesh->llid;
  1844. sinfo->plid = sta->mesh->plid;
  1845. sinfo->plink_state = sta->mesh->plink_state;
  1846. if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
  1847. sinfo->filled |= BIT(NL80211_STA_INFO_T_OFFSET);
  1848. sinfo->t_offset = sta->mesh->t_offset;
  1849. }
  1850. sinfo->local_pm = sta->mesh->local_pm;
  1851. sinfo->peer_pm = sta->mesh->peer_pm;
  1852. sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
  1853. #endif
  1854. }
  1855. sinfo->bss_param.flags = 0;
  1856. if (sdata->vif.bss_conf.use_cts_prot)
  1857. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  1858. if (sdata->vif.bss_conf.use_short_preamble)
  1859. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  1860. if (sdata->vif.bss_conf.use_short_slot)
  1861. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  1862. sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
  1863. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  1864. sinfo->sta_flags.set = 0;
  1865. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  1866. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  1867. BIT(NL80211_STA_FLAG_WME) |
  1868. BIT(NL80211_STA_FLAG_MFP) |
  1869. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1870. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  1871. BIT(NL80211_STA_FLAG_TDLS_PEER);
  1872. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1873. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  1874. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  1875. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  1876. if (sta->sta.wme)
  1877. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  1878. if (test_sta_flag(sta, WLAN_STA_MFP))
  1879. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  1880. if (test_sta_flag(sta, WLAN_STA_AUTH))
  1881. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  1882. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  1883. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1884. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  1885. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  1886. thr = sta_get_expected_throughput(sta);
  1887. if (thr != 0) {
  1888. sinfo->filled |= BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
  1889. sinfo->expected_throughput = thr;
  1890. }
  1891. }
  1892. u32 sta_get_expected_throughput(struct sta_info *sta)
  1893. {
  1894. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1895. struct ieee80211_local *local = sdata->local;
  1896. struct rate_control_ref *ref = NULL;
  1897. u32 thr = 0;
  1898. if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  1899. ref = local->rate_ctrl;
  1900. /* check if the driver has a SW RC implementation */
  1901. if (ref && ref->ops->get_expected_throughput)
  1902. thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
  1903. else
  1904. thr = drv_get_expected_throughput(local, sta);
  1905. return thr;
  1906. }
  1907. unsigned long ieee80211_sta_last_active(struct sta_info *sta)
  1908. {
  1909. struct ieee80211_sta_rx_stats *stats = sta_get_last_rx_stats(sta);
  1910. if (time_after(stats->last_rx, sta->status_stats.last_ack))
  1911. return stats->last_rx;
  1912. return sta->status_stats.last_ack;
  1913. }