sta_info.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304
  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))
  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 & ieee80211_ac_to_qos_mask[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 & ieee80211_ac_to_qos_mask[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 & ieee80211_ac_to_qos_mask[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, ac;
  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. for (ac = IEEE80211_AC_VO; ac < IEEE80211_NUM_ACS; ac++)
  1243. if (!(ignored_acs & ieee80211_ac_to_qos_mask[ac]))
  1244. break;
  1245. tid = 7 - 2 * ac;
  1246. ieee80211_send_null_response(sta, tid, reason, true, false);
  1247. } else if (!driver_release_tids) {
  1248. struct sk_buff_head pending;
  1249. struct sk_buff *skb;
  1250. int num = 0;
  1251. u16 tids = 0;
  1252. bool need_null = false;
  1253. skb_queue_head_init(&pending);
  1254. while ((skb = __skb_dequeue(&frames))) {
  1255. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1256. struct ieee80211_hdr *hdr = (void *) skb->data;
  1257. u8 *qoshdr = NULL;
  1258. num++;
  1259. /*
  1260. * Tell TX path to send this frame even though the
  1261. * STA may still remain is PS mode after this frame
  1262. * exchange.
  1263. */
  1264. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
  1265. info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
  1266. /*
  1267. * Use MoreData flag to indicate whether there are
  1268. * more buffered frames for this STA
  1269. */
  1270. if (more_data || !skb_queue_empty(&frames))
  1271. hdr->frame_control |=
  1272. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1273. else
  1274. hdr->frame_control &=
  1275. cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  1276. if (ieee80211_is_data_qos(hdr->frame_control) ||
  1277. ieee80211_is_qos_nullfunc(hdr->frame_control))
  1278. qoshdr = ieee80211_get_qos_ctl(hdr);
  1279. tids |= BIT(skb->priority);
  1280. __skb_queue_tail(&pending, skb);
  1281. /* end service period after last frame or add one */
  1282. if (!skb_queue_empty(&frames))
  1283. continue;
  1284. if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
  1285. /* for PS-Poll, there's only one frame */
  1286. info->flags |= IEEE80211_TX_STATUS_EOSP |
  1287. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1288. break;
  1289. }
  1290. /* For uAPSD, things are a bit more complicated. If the
  1291. * last frame has a QoS header (i.e. is a QoS-data or
  1292. * QoS-nulldata frame) then just set the EOSP bit there
  1293. * and be done.
  1294. * If the frame doesn't have a QoS header (which means
  1295. * it should be a bufferable MMPDU) then we can't set
  1296. * the EOSP bit in the QoS header; add a QoS-nulldata
  1297. * frame to the list to send it after the MMPDU.
  1298. *
  1299. * Note that this code is only in the mac80211-release
  1300. * code path, we assume that the driver will not buffer
  1301. * anything but QoS-data frames, or if it does, will
  1302. * create the QoS-nulldata frame by itself if needed.
  1303. *
  1304. * Cf. 802.11-2012 10.2.1.10 (c).
  1305. */
  1306. if (qoshdr) {
  1307. *qoshdr |= IEEE80211_QOS_CTL_EOSP;
  1308. info->flags |= IEEE80211_TX_STATUS_EOSP |
  1309. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1310. } else {
  1311. /* The standard isn't completely clear on this
  1312. * as it says the more-data bit should be set
  1313. * if there are more BUs. The QoS-Null frame
  1314. * we're about to send isn't buffered yet, we
  1315. * only create it below, but let's pretend it
  1316. * was buffered just in case some clients only
  1317. * expect more-data=0 when eosp=1.
  1318. */
  1319. hdr->frame_control |=
  1320. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1321. need_null = true;
  1322. num++;
  1323. }
  1324. break;
  1325. }
  1326. drv_allow_buffered_frames(local, sta, tids, num,
  1327. reason, more_data);
  1328. ieee80211_add_pending_skbs(local, &pending);
  1329. if (need_null)
  1330. ieee80211_send_null_response(
  1331. sta, find_highest_prio_tid(tids),
  1332. reason, false, false);
  1333. sta_info_recalc_tim(sta);
  1334. } else {
  1335. int tid;
  1336. /*
  1337. * We need to release a frame that is buffered somewhere in the
  1338. * driver ... it'll have to handle that.
  1339. * Note that the driver also has to check the number of frames
  1340. * on the TIDs we're releasing from - if there are more than
  1341. * n_frames it has to set the more-data bit (if we didn't ask
  1342. * it to set it anyway due to other buffered frames); if there
  1343. * are fewer than n_frames it has to make sure to adjust that
  1344. * to allow the service period to end properly.
  1345. */
  1346. drv_release_buffered_frames(local, sta, driver_release_tids,
  1347. n_frames, reason, more_data);
  1348. /*
  1349. * Note that we don't recalculate the TIM bit here as it would
  1350. * most likely have no effect at all unless the driver told us
  1351. * that the TID(s) became empty before returning here from the
  1352. * release function.
  1353. * Either way, however, when the driver tells us that the TID(s)
  1354. * became empty or we find that a txq became empty, we'll do the
  1355. * TIM recalculation.
  1356. */
  1357. if (!sta->sta.txq[0])
  1358. return;
  1359. for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
  1360. if (!(driver_release_tids & BIT(tid)) ||
  1361. txq_has_queue(sta->sta.txq[tid]))
  1362. continue;
  1363. sta_info_recalc_tim(sta);
  1364. break;
  1365. }
  1366. }
  1367. }
  1368. void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
  1369. {
  1370. u8 ignore_for_response = sta->sta.uapsd_queues;
  1371. /*
  1372. * If all ACs are delivery-enabled then we should reply
  1373. * from any of them, if only some are enabled we reply
  1374. * only from the non-enabled ones.
  1375. */
  1376. if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
  1377. ignore_for_response = 0;
  1378. ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
  1379. IEEE80211_FRAME_RELEASE_PSPOLL);
  1380. }
  1381. void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
  1382. {
  1383. int n_frames = sta->sta.max_sp;
  1384. u8 delivery_enabled = sta->sta.uapsd_queues;
  1385. /*
  1386. * If we ever grow support for TSPEC this might happen if
  1387. * the TSPEC update from hostapd comes in between a trigger
  1388. * frame setting WLAN_STA_UAPSD in the RX path and this
  1389. * actually getting called.
  1390. */
  1391. if (!delivery_enabled)
  1392. return;
  1393. switch (sta->sta.max_sp) {
  1394. case 1:
  1395. n_frames = 2;
  1396. break;
  1397. case 2:
  1398. n_frames = 4;
  1399. break;
  1400. case 3:
  1401. n_frames = 6;
  1402. break;
  1403. case 0:
  1404. /* XXX: what is a good value? */
  1405. n_frames = 128;
  1406. break;
  1407. }
  1408. ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
  1409. IEEE80211_FRAME_RELEASE_UAPSD);
  1410. }
  1411. void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
  1412. struct ieee80211_sta *pubsta, bool block)
  1413. {
  1414. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1415. trace_api_sta_block_awake(sta->local, pubsta, block);
  1416. if (block) {
  1417. set_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1418. ieee80211_clear_fast_xmit(sta);
  1419. return;
  1420. }
  1421. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1422. return;
  1423. if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1424. set_sta_flag(sta, WLAN_STA_PS_DELIVER);
  1425. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1426. ieee80211_queue_work(hw, &sta->drv_deliver_wk);
  1427. } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
  1428. test_sta_flag(sta, WLAN_STA_UAPSD)) {
  1429. /* must be asleep in this case */
  1430. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1431. ieee80211_queue_work(hw, &sta->drv_deliver_wk);
  1432. } else {
  1433. clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
  1434. ieee80211_check_fast_xmit(sta);
  1435. }
  1436. }
  1437. EXPORT_SYMBOL(ieee80211_sta_block_awake);
  1438. void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
  1439. {
  1440. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1441. struct ieee80211_local *local = sta->local;
  1442. trace_api_eosp(local, pubsta);
  1443. clear_sta_flag(sta, WLAN_STA_SP);
  1444. }
  1445. EXPORT_SYMBOL(ieee80211_sta_eosp);
  1446. void ieee80211_send_eosp_nullfunc(struct ieee80211_sta *pubsta, int tid)
  1447. {
  1448. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1449. enum ieee80211_frame_release_type reason;
  1450. bool more_data;
  1451. trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
  1452. reason = IEEE80211_FRAME_RELEASE_UAPSD;
  1453. more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
  1454. reason, 0);
  1455. ieee80211_send_null_response(sta, tid, reason, false, more_data);
  1456. }
  1457. EXPORT_SYMBOL(ieee80211_send_eosp_nullfunc);
  1458. void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
  1459. u8 tid, bool buffered)
  1460. {
  1461. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1462. if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
  1463. return;
  1464. trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
  1465. if (buffered)
  1466. set_bit(tid, &sta->driver_buffered_tids);
  1467. else
  1468. clear_bit(tid, &sta->driver_buffered_tids);
  1469. sta_info_recalc_tim(sta);
  1470. }
  1471. EXPORT_SYMBOL(ieee80211_sta_set_buffered);
  1472. static void
  1473. ieee80211_recalc_p2p_go_ps_allowed(struct ieee80211_sub_if_data *sdata)
  1474. {
  1475. struct ieee80211_local *local = sdata->local;
  1476. bool allow_p2p_go_ps = sdata->vif.p2p;
  1477. struct sta_info *sta;
  1478. rcu_read_lock();
  1479. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  1480. if (sdata != sta->sdata ||
  1481. !test_sta_flag(sta, WLAN_STA_ASSOC))
  1482. continue;
  1483. if (!sta->sta.support_p2p_ps) {
  1484. allow_p2p_go_ps = false;
  1485. break;
  1486. }
  1487. }
  1488. rcu_read_unlock();
  1489. if (allow_p2p_go_ps != sdata->vif.bss_conf.allow_p2p_go_ps) {
  1490. sdata->vif.bss_conf.allow_p2p_go_ps = allow_p2p_go_ps;
  1491. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_P2P_PS);
  1492. }
  1493. }
  1494. int sta_info_move_state(struct sta_info *sta,
  1495. enum ieee80211_sta_state new_state)
  1496. {
  1497. might_sleep();
  1498. if (sta->sta_state == new_state)
  1499. return 0;
  1500. /* check allowed transitions first */
  1501. switch (new_state) {
  1502. case IEEE80211_STA_NONE:
  1503. if (sta->sta_state != IEEE80211_STA_AUTH)
  1504. return -EINVAL;
  1505. break;
  1506. case IEEE80211_STA_AUTH:
  1507. if (sta->sta_state != IEEE80211_STA_NONE &&
  1508. sta->sta_state != IEEE80211_STA_ASSOC)
  1509. return -EINVAL;
  1510. break;
  1511. case IEEE80211_STA_ASSOC:
  1512. if (sta->sta_state != IEEE80211_STA_AUTH &&
  1513. sta->sta_state != IEEE80211_STA_AUTHORIZED)
  1514. return -EINVAL;
  1515. break;
  1516. case IEEE80211_STA_AUTHORIZED:
  1517. if (sta->sta_state != IEEE80211_STA_ASSOC)
  1518. return -EINVAL;
  1519. break;
  1520. default:
  1521. WARN(1, "invalid state %d", new_state);
  1522. return -EINVAL;
  1523. }
  1524. sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
  1525. sta->sta.addr, new_state);
  1526. /*
  1527. * notify the driver before the actual changes so it can
  1528. * fail the transition
  1529. */
  1530. if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
  1531. int err = drv_sta_state(sta->local, sta->sdata, sta,
  1532. sta->sta_state, new_state);
  1533. if (err)
  1534. return err;
  1535. }
  1536. /* reflect the change in all state variables */
  1537. switch (new_state) {
  1538. case IEEE80211_STA_NONE:
  1539. if (sta->sta_state == IEEE80211_STA_AUTH)
  1540. clear_bit(WLAN_STA_AUTH, &sta->_flags);
  1541. break;
  1542. case IEEE80211_STA_AUTH:
  1543. if (sta->sta_state == IEEE80211_STA_NONE) {
  1544. set_bit(WLAN_STA_AUTH, &sta->_flags);
  1545. } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
  1546. clear_bit(WLAN_STA_ASSOC, &sta->_flags);
  1547. ieee80211_recalc_min_chandef(sta->sdata);
  1548. if (!sta->sta.support_p2p_ps)
  1549. ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
  1550. }
  1551. break;
  1552. case IEEE80211_STA_ASSOC:
  1553. if (sta->sta_state == IEEE80211_STA_AUTH) {
  1554. set_bit(WLAN_STA_ASSOC, &sta->_flags);
  1555. ieee80211_recalc_min_chandef(sta->sdata);
  1556. if (!sta->sta.support_p2p_ps)
  1557. ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
  1558. } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
  1559. ieee80211_vif_dec_num_mcast(sta->sdata);
  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. ieee80211_vif_inc_num_mcast(sta->sdata);
  1568. set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
  1569. ieee80211_check_fast_xmit(sta);
  1570. ieee80211_check_fast_rx(sta);
  1571. }
  1572. break;
  1573. default:
  1574. break;
  1575. }
  1576. sta->sta_state = new_state;
  1577. return 0;
  1578. }
  1579. u8 sta_info_tx_streams(struct sta_info *sta)
  1580. {
  1581. struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
  1582. u8 rx_streams;
  1583. if (!sta->sta.ht_cap.ht_supported)
  1584. return 1;
  1585. if (sta->sta.vht_cap.vht_supported) {
  1586. int i;
  1587. u16 tx_mcs_map =
  1588. le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
  1589. for (i = 7; i >= 0; i--)
  1590. if ((tx_mcs_map & (0x3 << (i * 2))) !=
  1591. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  1592. return i + 1;
  1593. }
  1594. if (ht_cap->mcs.rx_mask[3])
  1595. rx_streams = 4;
  1596. else if (ht_cap->mcs.rx_mask[2])
  1597. rx_streams = 3;
  1598. else if (ht_cap->mcs.rx_mask[1])
  1599. rx_streams = 2;
  1600. else
  1601. rx_streams = 1;
  1602. if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
  1603. return rx_streams;
  1604. return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  1605. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
  1606. }
  1607. static struct ieee80211_sta_rx_stats *
  1608. sta_get_last_rx_stats(struct sta_info *sta)
  1609. {
  1610. struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
  1611. struct ieee80211_local *local = sta->local;
  1612. int cpu;
  1613. if (!ieee80211_hw_check(&local->hw, USES_RSS))
  1614. return stats;
  1615. for_each_possible_cpu(cpu) {
  1616. struct ieee80211_sta_rx_stats *cpustats;
  1617. cpustats = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1618. if (time_after(cpustats->last_rx, stats->last_rx))
  1619. stats = cpustats;
  1620. }
  1621. return stats;
  1622. }
  1623. static void sta_stats_decode_rate(struct ieee80211_local *local, u16 rate,
  1624. struct rate_info *rinfo)
  1625. {
  1626. rinfo->bw = (rate & STA_STATS_RATE_BW_MASK) >>
  1627. STA_STATS_RATE_BW_SHIFT;
  1628. if (rate & STA_STATS_RATE_VHT) {
  1629. rinfo->flags = RATE_INFO_FLAGS_VHT_MCS;
  1630. rinfo->mcs = rate & 0xf;
  1631. rinfo->nss = (rate & 0xf0) >> 4;
  1632. } else if (rate & STA_STATS_RATE_HT) {
  1633. rinfo->flags = RATE_INFO_FLAGS_MCS;
  1634. rinfo->mcs = rate & 0xff;
  1635. } else if (rate & STA_STATS_RATE_LEGACY) {
  1636. struct ieee80211_supported_band *sband;
  1637. u16 brate;
  1638. unsigned int shift;
  1639. rinfo->flags = 0;
  1640. sband = local->hw.wiphy->bands[(rate >> 4) & 0xf];
  1641. brate = sband->bitrates[rate & 0xf].bitrate;
  1642. if (rinfo->bw == RATE_INFO_BW_5)
  1643. shift = 2;
  1644. else if (rinfo->bw == RATE_INFO_BW_10)
  1645. shift = 1;
  1646. else
  1647. shift = 0;
  1648. rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
  1649. }
  1650. if (rate & STA_STATS_RATE_SGI)
  1651. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  1652. }
  1653. static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
  1654. {
  1655. u16 rate = ACCESS_ONCE(sta_get_last_rx_stats(sta)->last_rate);
  1656. if (rate == STA_STATS_RATE_INVALID)
  1657. return -EINVAL;
  1658. sta_stats_decode_rate(sta->local, rate, rinfo);
  1659. return 0;
  1660. }
  1661. static void sta_set_tidstats(struct sta_info *sta,
  1662. struct cfg80211_tid_stats *tidstats,
  1663. int tid)
  1664. {
  1665. struct ieee80211_local *local = sta->local;
  1666. if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
  1667. unsigned int start;
  1668. do {
  1669. start = u64_stats_fetch_begin(&sta->rx_stats.syncp);
  1670. tidstats->rx_msdu = sta->rx_stats.msdu[tid];
  1671. } while (u64_stats_fetch_retry(&sta->rx_stats.syncp, start));
  1672. tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
  1673. }
  1674. if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
  1675. tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
  1676. tidstats->tx_msdu = sta->tx_stats.msdu[tid];
  1677. }
  1678. if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
  1679. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  1680. tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
  1681. tidstats->tx_msdu_retries = sta->status_stats.msdu_retries[tid];
  1682. }
  1683. if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
  1684. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  1685. tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
  1686. tidstats->tx_msdu_failed = sta->status_stats.msdu_failed[tid];
  1687. }
  1688. }
  1689. static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
  1690. {
  1691. unsigned int start;
  1692. u64 value;
  1693. do {
  1694. start = u64_stats_fetch_begin(&rxstats->syncp);
  1695. value = rxstats->bytes;
  1696. } while (u64_stats_fetch_retry(&rxstats->syncp, start));
  1697. return value;
  1698. }
  1699. void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  1700. {
  1701. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1702. struct ieee80211_local *local = sdata->local;
  1703. struct rate_control_ref *ref = NULL;
  1704. u32 thr = 0;
  1705. int i, ac, cpu;
  1706. struct ieee80211_sta_rx_stats *last_rxstats;
  1707. last_rxstats = sta_get_last_rx_stats(sta);
  1708. if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  1709. ref = local->rate_ctrl;
  1710. sinfo->generation = sdata->local->sta_generation;
  1711. /* do before driver, so beacon filtering drivers have a
  1712. * chance to e.g. just add the number of filtered beacons
  1713. * (or just modify the value entirely, of course)
  1714. */
  1715. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1716. sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
  1717. drv_sta_statistics(local, sdata, &sta->sta, sinfo);
  1718. sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME) |
  1719. BIT(NL80211_STA_INFO_STA_FLAGS) |
  1720. BIT(NL80211_STA_INFO_BSS_PARAM) |
  1721. BIT(NL80211_STA_INFO_CONNECTED_TIME) |
  1722. BIT(NL80211_STA_INFO_RX_DROP_MISC);
  1723. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  1724. sinfo->beacon_loss_count = sdata->u.mgd.beacon_loss_count;
  1725. sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_LOSS);
  1726. }
  1727. sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
  1728. sinfo->inactive_time =
  1729. jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
  1730. if (!(sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES64) |
  1731. BIT(NL80211_STA_INFO_TX_BYTES)))) {
  1732. sinfo->tx_bytes = 0;
  1733. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  1734. sinfo->tx_bytes += sta->tx_stats.bytes[ac];
  1735. sinfo->filled |= BIT(NL80211_STA_INFO_TX_BYTES64);
  1736. }
  1737. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_PACKETS))) {
  1738. sinfo->tx_packets = 0;
  1739. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  1740. sinfo->tx_packets += sta->tx_stats.packets[ac];
  1741. sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS);
  1742. }
  1743. if (!(sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES64) |
  1744. BIT(NL80211_STA_INFO_RX_BYTES)))) {
  1745. sinfo->rx_bytes += sta_get_stats_bytes(&sta->rx_stats);
  1746. if (sta->pcpu_rx_stats) {
  1747. for_each_possible_cpu(cpu) {
  1748. struct ieee80211_sta_rx_stats *cpurxs;
  1749. cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1750. sinfo->rx_bytes += sta_get_stats_bytes(cpurxs);
  1751. }
  1752. }
  1753. sinfo->filled |= BIT(NL80211_STA_INFO_RX_BYTES64);
  1754. }
  1755. if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_PACKETS))) {
  1756. sinfo->rx_packets = sta->rx_stats.packets;
  1757. if (sta->pcpu_rx_stats) {
  1758. for_each_possible_cpu(cpu) {
  1759. struct ieee80211_sta_rx_stats *cpurxs;
  1760. cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1761. sinfo->rx_packets += cpurxs->packets;
  1762. }
  1763. }
  1764. sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS);
  1765. }
  1766. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_RETRIES))) {
  1767. sinfo->tx_retries = sta->status_stats.retry_count;
  1768. sinfo->filled |= BIT(NL80211_STA_INFO_TX_RETRIES);
  1769. }
  1770. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_FAILED))) {
  1771. sinfo->tx_failed = sta->status_stats.retry_failed;
  1772. sinfo->filled |= BIT(NL80211_STA_INFO_TX_FAILED);
  1773. }
  1774. sinfo->rx_dropped_misc = sta->rx_stats.dropped;
  1775. if (sta->pcpu_rx_stats) {
  1776. for_each_possible_cpu(cpu) {
  1777. struct ieee80211_sta_rx_stats *cpurxs;
  1778. cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
  1779. sinfo->rx_packets += cpurxs->dropped;
  1780. }
  1781. }
  1782. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1783. !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
  1784. sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX) |
  1785. BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
  1786. sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
  1787. }
  1788. if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
  1789. ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
  1790. if (!(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL))) {
  1791. sinfo->signal = (s8)last_rxstats->last_signal;
  1792. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
  1793. }
  1794. if (!sta->pcpu_rx_stats &&
  1795. !(sinfo->filled & BIT(NL80211_STA_INFO_SIGNAL_AVG))) {
  1796. sinfo->signal_avg =
  1797. -ewma_signal_read(&sta->rx_stats_avg.signal);
  1798. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
  1799. }
  1800. }
  1801. /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
  1802. * the sta->rx_stats struct, so the check here is fine with and without
  1803. * pcpu statistics
  1804. */
  1805. if (last_rxstats->chains &&
  1806. !(sinfo->filled & (BIT(NL80211_STA_INFO_CHAIN_SIGNAL) |
  1807. BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
  1808. sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL);
  1809. if (!sta->pcpu_rx_stats)
  1810. sinfo->filled |= BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
  1811. sinfo->chains = last_rxstats->chains;
  1812. for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
  1813. sinfo->chain_signal[i] =
  1814. last_rxstats->chain_signal_last[i];
  1815. sinfo->chain_signal_avg[i] =
  1816. -ewma_signal_read(&sta->rx_stats_avg.chain_signal[i]);
  1817. }
  1818. }
  1819. if (!(sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE))) {
  1820. sta_set_rate_info_tx(sta, &sta->tx_stats.last_rate,
  1821. &sinfo->txrate);
  1822. sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
  1823. }
  1824. if (!(sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE))) {
  1825. if (sta_set_rate_info_rx(sta, &sinfo->rxrate) == 0)
  1826. sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE);
  1827. }
  1828. sinfo->filled |= BIT(NL80211_STA_INFO_TID_STATS);
  1829. for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++) {
  1830. struct cfg80211_tid_stats *tidstats = &sinfo->pertid[i];
  1831. sta_set_tidstats(sta, tidstats, i);
  1832. }
  1833. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1834. #ifdef CONFIG_MAC80211_MESH
  1835. sinfo->filled |= BIT(NL80211_STA_INFO_LLID) |
  1836. BIT(NL80211_STA_INFO_PLID) |
  1837. BIT(NL80211_STA_INFO_PLINK_STATE) |
  1838. BIT(NL80211_STA_INFO_LOCAL_PM) |
  1839. BIT(NL80211_STA_INFO_PEER_PM) |
  1840. BIT(NL80211_STA_INFO_NONPEER_PM);
  1841. sinfo->llid = sta->mesh->llid;
  1842. sinfo->plid = sta->mesh->plid;
  1843. sinfo->plink_state = sta->mesh->plink_state;
  1844. if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
  1845. sinfo->filled |= BIT(NL80211_STA_INFO_T_OFFSET);
  1846. sinfo->t_offset = sta->mesh->t_offset;
  1847. }
  1848. sinfo->local_pm = sta->mesh->local_pm;
  1849. sinfo->peer_pm = sta->mesh->peer_pm;
  1850. sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
  1851. #endif
  1852. }
  1853. sinfo->bss_param.flags = 0;
  1854. if (sdata->vif.bss_conf.use_cts_prot)
  1855. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  1856. if (sdata->vif.bss_conf.use_short_preamble)
  1857. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  1858. if (sdata->vif.bss_conf.use_short_slot)
  1859. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  1860. sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
  1861. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  1862. sinfo->sta_flags.set = 0;
  1863. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  1864. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  1865. BIT(NL80211_STA_FLAG_WME) |
  1866. BIT(NL80211_STA_FLAG_MFP) |
  1867. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1868. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  1869. BIT(NL80211_STA_FLAG_TDLS_PEER);
  1870. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1871. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  1872. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  1873. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  1874. if (sta->sta.wme)
  1875. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  1876. if (test_sta_flag(sta, WLAN_STA_MFP))
  1877. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  1878. if (test_sta_flag(sta, WLAN_STA_AUTH))
  1879. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  1880. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  1881. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1882. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  1883. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  1884. thr = sta_get_expected_throughput(sta);
  1885. if (thr != 0) {
  1886. sinfo->filled |= BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
  1887. sinfo->expected_throughput = thr;
  1888. }
  1889. }
  1890. u32 sta_get_expected_throughput(struct sta_info *sta)
  1891. {
  1892. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1893. struct ieee80211_local *local = sdata->local;
  1894. struct rate_control_ref *ref = NULL;
  1895. u32 thr = 0;
  1896. if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  1897. ref = local->rate_ctrl;
  1898. /* check if the driver has a SW RC implementation */
  1899. if (ref && ref->ops->get_expected_throughput)
  1900. thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
  1901. else
  1902. thr = drv_get_expected_throughput(local, sta);
  1903. return thr;
  1904. }
  1905. unsigned long ieee80211_sta_last_active(struct sta_info *sta)
  1906. {
  1907. struct ieee80211_sta_rx_stats *stats = sta_get_last_rx_stats(sta);
  1908. if (time_after(stats->last_rx, sta->status_stats.last_ack))
  1909. return stats->last_rx;
  1910. return sta->status_stats.last_ack;
  1911. }