sta_info.c 49 KB

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