sta_info.c 61 KB

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