sta_info.c 49 KB

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