sta_info.c 61 KB

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