util.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * utilities for mac80211
  12. */
  13. #include <net/mac80211.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/export.h>
  16. #include <linux/types.h>
  17. #include <linux/slab.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/if_arp.h>
  21. #include <linux/bitmap.h>
  22. #include <linux/crc32.h>
  23. #include <net/net_namespace.h>
  24. #include <net/cfg80211.h>
  25. #include <net/rtnetlink.h>
  26. #include "ieee80211_i.h"
  27. #include "driver-ops.h"
  28. #include "rate.h"
  29. #include "mesh.h"
  30. #include "wme.h"
  31. #include "led.h"
  32. #include "wep.h"
  33. /* privid for wiphys to determine whether they belong to us or not */
  34. void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
  35. struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
  36. {
  37. struct ieee80211_local *local;
  38. BUG_ON(!wiphy);
  39. local = wiphy_priv(wiphy);
  40. return &local->hw;
  41. }
  42. EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
  43. u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
  44. enum nl80211_iftype type)
  45. {
  46. __le16 fc = hdr->frame_control;
  47. /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
  48. if (len < 16)
  49. return NULL;
  50. if (ieee80211_is_data(fc)) {
  51. if (len < 24) /* drop incorrect hdr len (data) */
  52. return NULL;
  53. if (ieee80211_has_a4(fc))
  54. return NULL;
  55. if (ieee80211_has_tods(fc))
  56. return hdr->addr1;
  57. if (ieee80211_has_fromds(fc))
  58. return hdr->addr2;
  59. return hdr->addr3;
  60. }
  61. if (ieee80211_is_mgmt(fc)) {
  62. if (len < 24) /* drop incorrect hdr len (mgmt) */
  63. return NULL;
  64. return hdr->addr3;
  65. }
  66. if (ieee80211_is_ctl(fc)) {
  67. if(ieee80211_is_pspoll(fc))
  68. return hdr->addr1;
  69. if (ieee80211_is_back_req(fc)) {
  70. switch (type) {
  71. case NL80211_IFTYPE_STATION:
  72. return hdr->addr2;
  73. case NL80211_IFTYPE_AP:
  74. case NL80211_IFTYPE_AP_VLAN:
  75. return hdr->addr1;
  76. default:
  77. break; /* fall through to the return */
  78. }
  79. }
  80. }
  81. return NULL;
  82. }
  83. void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
  84. {
  85. struct sk_buff *skb;
  86. struct ieee80211_hdr *hdr;
  87. skb_queue_walk(&tx->skbs, skb) {
  88. hdr = (struct ieee80211_hdr *) skb->data;
  89. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  90. }
  91. }
  92. int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
  93. int rate, int erp, int short_preamble)
  94. {
  95. int dur;
  96. /* calculate duration (in microseconds, rounded up to next higher
  97. * integer if it includes a fractional microsecond) to send frame of
  98. * len bytes (does not include FCS) at the given rate. Duration will
  99. * also include SIFS.
  100. *
  101. * rate is in 100 kbps, so divident is multiplied by 10 in the
  102. * DIV_ROUND_UP() operations.
  103. */
  104. if (band == IEEE80211_BAND_5GHZ || erp) {
  105. /*
  106. * OFDM:
  107. *
  108. * N_DBPS = DATARATE x 4
  109. * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
  110. * (16 = SIGNAL time, 6 = tail bits)
  111. * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
  112. *
  113. * T_SYM = 4 usec
  114. * 802.11a - 17.5.2: aSIFSTime = 16 usec
  115. * 802.11g - 19.8.4: aSIFSTime = 10 usec +
  116. * signal ext = 6 usec
  117. */
  118. dur = 16; /* SIFS + signal ext */
  119. dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
  120. dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
  121. dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
  122. 4 * rate); /* T_SYM x N_SYM */
  123. } else {
  124. /*
  125. * 802.11b or 802.11g with 802.11b compatibility:
  126. * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
  127. * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
  128. *
  129. * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
  130. * aSIFSTime = 10 usec
  131. * aPreambleLength = 144 usec or 72 usec with short preamble
  132. * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
  133. */
  134. dur = 10; /* aSIFSTime = 10 usec */
  135. dur += short_preamble ? (72 + 24) : (144 + 48);
  136. dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
  137. }
  138. return dur;
  139. }
  140. /* Exported duration function for driver use */
  141. __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
  142. struct ieee80211_vif *vif,
  143. enum ieee80211_band band,
  144. size_t frame_len,
  145. struct ieee80211_rate *rate)
  146. {
  147. struct ieee80211_sub_if_data *sdata;
  148. u16 dur;
  149. int erp;
  150. bool short_preamble = false;
  151. erp = 0;
  152. if (vif) {
  153. sdata = vif_to_sdata(vif);
  154. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  155. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  156. erp = rate->flags & IEEE80211_RATE_ERP_G;
  157. }
  158. dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
  159. short_preamble);
  160. return cpu_to_le16(dur);
  161. }
  162. EXPORT_SYMBOL(ieee80211_generic_frame_duration);
  163. __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
  164. struct ieee80211_vif *vif, size_t frame_len,
  165. const struct ieee80211_tx_info *frame_txctl)
  166. {
  167. struct ieee80211_local *local = hw_to_local(hw);
  168. struct ieee80211_rate *rate;
  169. struct ieee80211_sub_if_data *sdata;
  170. bool short_preamble;
  171. int erp;
  172. u16 dur;
  173. struct ieee80211_supported_band *sband;
  174. sband = local->hw.wiphy->bands[frame_txctl->band];
  175. short_preamble = false;
  176. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  177. erp = 0;
  178. if (vif) {
  179. sdata = vif_to_sdata(vif);
  180. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  181. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  182. erp = rate->flags & IEEE80211_RATE_ERP_G;
  183. }
  184. /* CTS duration */
  185. dur = ieee80211_frame_duration(sband->band, 10, rate->bitrate,
  186. erp, short_preamble);
  187. /* Data frame duration */
  188. dur += ieee80211_frame_duration(sband->band, frame_len, rate->bitrate,
  189. erp, short_preamble);
  190. /* ACK duration */
  191. dur += ieee80211_frame_duration(sband->band, 10, rate->bitrate,
  192. erp, short_preamble);
  193. return cpu_to_le16(dur);
  194. }
  195. EXPORT_SYMBOL(ieee80211_rts_duration);
  196. __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
  197. struct ieee80211_vif *vif,
  198. size_t frame_len,
  199. const struct ieee80211_tx_info *frame_txctl)
  200. {
  201. struct ieee80211_local *local = hw_to_local(hw);
  202. struct ieee80211_rate *rate;
  203. struct ieee80211_sub_if_data *sdata;
  204. bool short_preamble;
  205. int erp;
  206. u16 dur;
  207. struct ieee80211_supported_band *sband;
  208. sband = local->hw.wiphy->bands[frame_txctl->band];
  209. short_preamble = false;
  210. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  211. erp = 0;
  212. if (vif) {
  213. sdata = vif_to_sdata(vif);
  214. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  215. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  216. erp = rate->flags & IEEE80211_RATE_ERP_G;
  217. }
  218. /* Data frame duration */
  219. dur = ieee80211_frame_duration(sband->band, frame_len, rate->bitrate,
  220. erp, short_preamble);
  221. if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
  222. /* ACK duration */
  223. dur += ieee80211_frame_duration(sband->band, 10, rate->bitrate,
  224. erp, short_preamble);
  225. }
  226. return cpu_to_le16(dur);
  227. }
  228. EXPORT_SYMBOL(ieee80211_ctstoself_duration);
  229. void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
  230. {
  231. struct ieee80211_sub_if_data *sdata;
  232. int n_acs = IEEE80211_NUM_ACS;
  233. if (local->hw.queues < IEEE80211_NUM_ACS)
  234. n_acs = 1;
  235. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  236. int ac;
  237. if (test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
  238. continue;
  239. if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE &&
  240. local->queue_stop_reasons[sdata->vif.cab_queue] != 0)
  241. continue;
  242. for (ac = 0; ac < n_acs; ac++) {
  243. int ac_queue = sdata->vif.hw_queue[ac];
  244. if (ac_queue == queue ||
  245. (sdata->vif.cab_queue == queue &&
  246. local->queue_stop_reasons[ac_queue] == 0 &&
  247. skb_queue_empty(&local->pending[ac_queue])))
  248. netif_wake_subqueue(sdata->dev, ac);
  249. }
  250. }
  251. }
  252. static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
  253. enum queue_stop_reason reason)
  254. {
  255. struct ieee80211_local *local = hw_to_local(hw);
  256. trace_wake_queue(local, queue, reason);
  257. if (WARN_ON(queue >= hw->queues))
  258. return;
  259. if (!test_bit(reason, &local->queue_stop_reasons[queue]))
  260. return;
  261. __clear_bit(reason, &local->queue_stop_reasons[queue]);
  262. if (local->queue_stop_reasons[queue] != 0)
  263. /* someone still has this queue stopped */
  264. return;
  265. if (skb_queue_empty(&local->pending[queue])) {
  266. rcu_read_lock();
  267. ieee80211_propagate_queue_wake(local, queue);
  268. rcu_read_unlock();
  269. } else
  270. tasklet_schedule(&local->tx_pending_tasklet);
  271. }
  272. void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
  273. enum queue_stop_reason reason)
  274. {
  275. struct ieee80211_local *local = hw_to_local(hw);
  276. unsigned long flags;
  277. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  278. __ieee80211_wake_queue(hw, queue, reason);
  279. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  280. }
  281. void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
  282. {
  283. ieee80211_wake_queue_by_reason(hw, queue,
  284. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  285. }
  286. EXPORT_SYMBOL(ieee80211_wake_queue);
  287. static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
  288. enum queue_stop_reason reason)
  289. {
  290. struct ieee80211_local *local = hw_to_local(hw);
  291. struct ieee80211_sub_if_data *sdata;
  292. int n_acs = IEEE80211_NUM_ACS;
  293. trace_stop_queue(local, queue, reason);
  294. if (WARN_ON(queue >= hw->queues))
  295. return;
  296. if (test_bit(reason, &local->queue_stop_reasons[queue]))
  297. return;
  298. __set_bit(reason, &local->queue_stop_reasons[queue]);
  299. if (local->hw.queues < IEEE80211_NUM_ACS)
  300. n_acs = 1;
  301. rcu_read_lock();
  302. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  303. int ac;
  304. for (ac = 0; ac < n_acs; ac++) {
  305. if (sdata->vif.hw_queue[ac] == queue ||
  306. sdata->vif.cab_queue == queue)
  307. netif_stop_subqueue(sdata->dev, ac);
  308. }
  309. }
  310. rcu_read_unlock();
  311. }
  312. void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
  313. enum queue_stop_reason reason)
  314. {
  315. struct ieee80211_local *local = hw_to_local(hw);
  316. unsigned long flags;
  317. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  318. __ieee80211_stop_queue(hw, queue, reason);
  319. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  320. }
  321. void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
  322. {
  323. ieee80211_stop_queue_by_reason(hw, queue,
  324. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  325. }
  326. EXPORT_SYMBOL(ieee80211_stop_queue);
  327. void ieee80211_add_pending_skb(struct ieee80211_local *local,
  328. struct sk_buff *skb)
  329. {
  330. struct ieee80211_hw *hw = &local->hw;
  331. unsigned long flags;
  332. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  333. int queue = info->hw_queue;
  334. if (WARN_ON(!info->control.vif)) {
  335. kfree_skb(skb);
  336. return;
  337. }
  338. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  339. __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  340. __skb_queue_tail(&local->pending[queue], skb);
  341. __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  342. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  343. }
  344. void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
  345. struct sk_buff_head *skbs,
  346. void (*fn)(void *data), void *data)
  347. {
  348. struct ieee80211_hw *hw = &local->hw;
  349. struct sk_buff *skb;
  350. unsigned long flags;
  351. int queue, i;
  352. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  353. while ((skb = skb_dequeue(skbs))) {
  354. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  355. if (WARN_ON(!info->control.vif)) {
  356. kfree_skb(skb);
  357. continue;
  358. }
  359. queue = info->hw_queue;
  360. __ieee80211_stop_queue(hw, queue,
  361. IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  362. __skb_queue_tail(&local->pending[queue], skb);
  363. }
  364. if (fn)
  365. fn(data);
  366. for (i = 0; i < hw->queues; i++)
  367. __ieee80211_wake_queue(hw, i,
  368. IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  369. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  370. }
  371. void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
  372. enum queue_stop_reason reason)
  373. {
  374. struct ieee80211_local *local = hw_to_local(hw);
  375. unsigned long flags;
  376. int i;
  377. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  378. for (i = 0; i < hw->queues; i++)
  379. __ieee80211_stop_queue(hw, i, reason);
  380. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  381. }
  382. void ieee80211_stop_queues(struct ieee80211_hw *hw)
  383. {
  384. ieee80211_stop_queues_by_reason(hw,
  385. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  386. }
  387. EXPORT_SYMBOL(ieee80211_stop_queues);
  388. int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
  389. {
  390. struct ieee80211_local *local = hw_to_local(hw);
  391. unsigned long flags;
  392. int ret;
  393. if (WARN_ON(queue >= hw->queues))
  394. return true;
  395. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  396. ret = !!local->queue_stop_reasons[queue];
  397. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  398. return ret;
  399. }
  400. EXPORT_SYMBOL(ieee80211_queue_stopped);
  401. void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
  402. enum queue_stop_reason reason)
  403. {
  404. struct ieee80211_local *local = hw_to_local(hw);
  405. unsigned long flags;
  406. int i;
  407. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  408. for (i = 0; i < hw->queues; i++)
  409. __ieee80211_wake_queue(hw, i, reason);
  410. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  411. }
  412. void ieee80211_wake_queues(struct ieee80211_hw *hw)
  413. {
  414. ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
  415. }
  416. EXPORT_SYMBOL(ieee80211_wake_queues);
  417. void ieee80211_iterate_active_interfaces(
  418. struct ieee80211_hw *hw,
  419. void (*iterator)(void *data, u8 *mac,
  420. struct ieee80211_vif *vif),
  421. void *data)
  422. {
  423. struct ieee80211_local *local = hw_to_local(hw);
  424. struct ieee80211_sub_if_data *sdata;
  425. mutex_lock(&local->iflist_mtx);
  426. list_for_each_entry(sdata, &local->interfaces, list) {
  427. switch (sdata->vif.type) {
  428. case NL80211_IFTYPE_MONITOR:
  429. case NL80211_IFTYPE_AP_VLAN:
  430. continue;
  431. default:
  432. break;
  433. }
  434. if (ieee80211_sdata_running(sdata))
  435. iterator(data, sdata->vif.addr,
  436. &sdata->vif);
  437. }
  438. mutex_unlock(&local->iflist_mtx);
  439. }
  440. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
  441. void ieee80211_iterate_active_interfaces_atomic(
  442. struct ieee80211_hw *hw,
  443. void (*iterator)(void *data, u8 *mac,
  444. struct ieee80211_vif *vif),
  445. void *data)
  446. {
  447. struct ieee80211_local *local = hw_to_local(hw);
  448. struct ieee80211_sub_if_data *sdata;
  449. rcu_read_lock();
  450. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  451. switch (sdata->vif.type) {
  452. case NL80211_IFTYPE_MONITOR:
  453. case NL80211_IFTYPE_AP_VLAN:
  454. continue;
  455. default:
  456. break;
  457. }
  458. if (ieee80211_sdata_running(sdata))
  459. iterator(data, sdata->vif.addr,
  460. &sdata->vif);
  461. }
  462. rcu_read_unlock();
  463. }
  464. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
  465. /*
  466. * Nothing should have been stuffed into the workqueue during
  467. * the suspend->resume cycle. If this WARN is seen then there
  468. * is a bug with either the driver suspend or something in
  469. * mac80211 stuffing into the workqueue which we haven't yet
  470. * cleared during mac80211's suspend cycle.
  471. */
  472. static bool ieee80211_can_queue_work(struct ieee80211_local *local)
  473. {
  474. if (WARN(local->suspended && !local->resuming,
  475. "queueing ieee80211 work while going to suspend\n"))
  476. return false;
  477. return true;
  478. }
  479. void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
  480. {
  481. struct ieee80211_local *local = hw_to_local(hw);
  482. if (!ieee80211_can_queue_work(local))
  483. return;
  484. queue_work(local->workqueue, work);
  485. }
  486. EXPORT_SYMBOL(ieee80211_queue_work);
  487. void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
  488. struct delayed_work *dwork,
  489. unsigned long delay)
  490. {
  491. struct ieee80211_local *local = hw_to_local(hw);
  492. if (!ieee80211_can_queue_work(local))
  493. return;
  494. queue_delayed_work(local->workqueue, dwork, delay);
  495. }
  496. EXPORT_SYMBOL(ieee80211_queue_delayed_work);
  497. u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
  498. struct ieee802_11_elems *elems,
  499. u64 filter, u32 crc)
  500. {
  501. size_t left = len;
  502. u8 *pos = start;
  503. bool calc_crc = filter != 0;
  504. DECLARE_BITMAP(seen_elems, 256);
  505. bitmap_zero(seen_elems, 256);
  506. memset(elems, 0, sizeof(*elems));
  507. elems->ie_start = start;
  508. elems->total_len = len;
  509. while (left >= 2) {
  510. u8 id, elen;
  511. bool elem_parse_failed;
  512. id = *pos++;
  513. elen = *pos++;
  514. left -= 2;
  515. if (elen > left) {
  516. elems->parse_error = true;
  517. break;
  518. }
  519. if (id != WLAN_EID_VENDOR_SPECIFIC &&
  520. id != WLAN_EID_QUIET &&
  521. test_bit(id, seen_elems)) {
  522. elems->parse_error = true;
  523. left -= elen;
  524. pos += elen;
  525. continue;
  526. }
  527. if (calc_crc && id < 64 && (filter & (1ULL << id)))
  528. crc = crc32_be(crc, pos - 2, elen + 2);
  529. elem_parse_failed = false;
  530. switch (id) {
  531. case WLAN_EID_SSID:
  532. elems->ssid = pos;
  533. elems->ssid_len = elen;
  534. break;
  535. case WLAN_EID_SUPP_RATES:
  536. elems->supp_rates = pos;
  537. elems->supp_rates_len = elen;
  538. break;
  539. case WLAN_EID_FH_PARAMS:
  540. elems->fh_params = pos;
  541. elems->fh_params_len = elen;
  542. break;
  543. case WLAN_EID_DS_PARAMS:
  544. elems->ds_params = pos;
  545. elems->ds_params_len = elen;
  546. break;
  547. case WLAN_EID_CF_PARAMS:
  548. elems->cf_params = pos;
  549. elems->cf_params_len = elen;
  550. break;
  551. case WLAN_EID_TIM:
  552. if (elen >= sizeof(struct ieee80211_tim_ie)) {
  553. elems->tim = (void *)pos;
  554. elems->tim_len = elen;
  555. } else
  556. elem_parse_failed = true;
  557. break;
  558. case WLAN_EID_IBSS_PARAMS:
  559. elems->ibss_params = pos;
  560. elems->ibss_params_len = elen;
  561. break;
  562. case WLAN_EID_CHALLENGE:
  563. elems->challenge = pos;
  564. elems->challenge_len = elen;
  565. break;
  566. case WLAN_EID_VENDOR_SPECIFIC:
  567. if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
  568. pos[2] == 0xf2) {
  569. /* Microsoft OUI (00:50:F2) */
  570. if (calc_crc)
  571. crc = crc32_be(crc, pos - 2, elen + 2);
  572. if (pos[3] == 1) {
  573. /* OUI Type 1 - WPA IE */
  574. elems->wpa = pos;
  575. elems->wpa_len = elen;
  576. } else if (elen >= 5 && pos[3] == 2) {
  577. /* OUI Type 2 - WMM IE */
  578. if (pos[4] == 0) {
  579. elems->wmm_info = pos;
  580. elems->wmm_info_len = elen;
  581. } else if (pos[4] == 1) {
  582. elems->wmm_param = pos;
  583. elems->wmm_param_len = elen;
  584. }
  585. }
  586. }
  587. break;
  588. case WLAN_EID_RSN:
  589. elems->rsn = pos;
  590. elems->rsn_len = elen;
  591. break;
  592. case WLAN_EID_ERP_INFO:
  593. elems->erp_info = pos;
  594. elems->erp_info_len = elen;
  595. break;
  596. case WLAN_EID_EXT_SUPP_RATES:
  597. elems->ext_supp_rates = pos;
  598. elems->ext_supp_rates_len = elen;
  599. break;
  600. case WLAN_EID_HT_CAPABILITY:
  601. if (elen >= sizeof(struct ieee80211_ht_cap))
  602. elems->ht_cap_elem = (void *)pos;
  603. else
  604. elem_parse_failed = true;
  605. break;
  606. case WLAN_EID_HT_OPERATION:
  607. if (elen >= sizeof(struct ieee80211_ht_operation))
  608. elems->ht_operation = (void *)pos;
  609. else
  610. elem_parse_failed = true;
  611. break;
  612. case WLAN_EID_MESH_ID:
  613. elems->mesh_id = pos;
  614. elems->mesh_id_len = elen;
  615. break;
  616. case WLAN_EID_MESH_CONFIG:
  617. if (elen >= sizeof(struct ieee80211_meshconf_ie))
  618. elems->mesh_config = (void *)pos;
  619. else
  620. elem_parse_failed = true;
  621. break;
  622. case WLAN_EID_PEER_MGMT:
  623. elems->peering = pos;
  624. elems->peering_len = elen;
  625. break;
  626. case WLAN_EID_PREQ:
  627. elems->preq = pos;
  628. elems->preq_len = elen;
  629. break;
  630. case WLAN_EID_PREP:
  631. elems->prep = pos;
  632. elems->prep_len = elen;
  633. break;
  634. case WLAN_EID_PERR:
  635. elems->perr = pos;
  636. elems->perr_len = elen;
  637. break;
  638. case WLAN_EID_RANN:
  639. if (elen >= sizeof(struct ieee80211_rann_ie))
  640. elems->rann = (void *)pos;
  641. else
  642. elem_parse_failed = true;
  643. break;
  644. case WLAN_EID_CHANNEL_SWITCH:
  645. elems->ch_switch_elem = pos;
  646. elems->ch_switch_elem_len = elen;
  647. break;
  648. case WLAN_EID_QUIET:
  649. if (!elems->quiet_elem) {
  650. elems->quiet_elem = pos;
  651. elems->quiet_elem_len = elen;
  652. }
  653. elems->num_of_quiet_elem++;
  654. break;
  655. case WLAN_EID_COUNTRY:
  656. elems->country_elem = pos;
  657. elems->country_elem_len = elen;
  658. break;
  659. case WLAN_EID_PWR_CONSTRAINT:
  660. elems->pwr_constr_elem = pos;
  661. elems->pwr_constr_elem_len = elen;
  662. break;
  663. case WLAN_EID_TIMEOUT_INTERVAL:
  664. elems->timeout_int = pos;
  665. elems->timeout_int_len = elen;
  666. break;
  667. default:
  668. break;
  669. }
  670. if (elem_parse_failed)
  671. elems->parse_error = true;
  672. else
  673. set_bit(id, seen_elems);
  674. left -= elen;
  675. pos += elen;
  676. }
  677. if (left != 0)
  678. elems->parse_error = true;
  679. return crc;
  680. }
  681. void ieee802_11_parse_elems(u8 *start, size_t len,
  682. struct ieee802_11_elems *elems)
  683. {
  684. ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
  685. }
  686. void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
  687. bool bss_notify)
  688. {
  689. struct ieee80211_local *local = sdata->local;
  690. struct ieee80211_tx_queue_params qparam;
  691. int ac;
  692. bool use_11b, enable_qos;
  693. int aCWmin, aCWmax;
  694. if (!local->ops->conf_tx)
  695. return;
  696. if (local->hw.queues < IEEE80211_NUM_ACS)
  697. return;
  698. memset(&qparam, 0, sizeof(qparam));
  699. use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) &&
  700. !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
  701. /*
  702. * By default disable QoS in STA mode for old access points, which do
  703. * not support 802.11e. New APs will provide proper queue parameters,
  704. * that we will configure later.
  705. */
  706. enable_qos = (sdata->vif.type != NL80211_IFTYPE_STATION);
  707. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  708. /* Set defaults according to 802.11-2007 Table 7-37 */
  709. aCWmax = 1023;
  710. if (use_11b)
  711. aCWmin = 31;
  712. else
  713. aCWmin = 15;
  714. if (enable_qos) {
  715. switch (ac) {
  716. case IEEE80211_AC_BK:
  717. qparam.cw_max = aCWmax;
  718. qparam.cw_min = aCWmin;
  719. qparam.txop = 0;
  720. qparam.aifs = 7;
  721. break;
  722. /* never happens but let's not leave undefined */
  723. default:
  724. case IEEE80211_AC_BE:
  725. qparam.cw_max = aCWmax;
  726. qparam.cw_min = aCWmin;
  727. qparam.txop = 0;
  728. qparam.aifs = 3;
  729. break;
  730. case IEEE80211_AC_VI:
  731. qparam.cw_max = aCWmin;
  732. qparam.cw_min = (aCWmin + 1) / 2 - 1;
  733. if (use_11b)
  734. qparam.txop = 6016/32;
  735. else
  736. qparam.txop = 3008/32;
  737. qparam.aifs = 2;
  738. break;
  739. case IEEE80211_AC_VO:
  740. qparam.cw_max = (aCWmin + 1) / 2 - 1;
  741. qparam.cw_min = (aCWmin + 1) / 4 - 1;
  742. if (use_11b)
  743. qparam.txop = 3264/32;
  744. else
  745. qparam.txop = 1504/32;
  746. qparam.aifs = 2;
  747. break;
  748. }
  749. } else {
  750. /* Confiure old 802.11b/g medium access rules. */
  751. qparam.cw_max = aCWmax;
  752. qparam.cw_min = aCWmin;
  753. qparam.txop = 0;
  754. qparam.aifs = 2;
  755. }
  756. qparam.uapsd = false;
  757. sdata->tx_conf[ac] = qparam;
  758. drv_conf_tx(local, sdata, ac, &qparam);
  759. }
  760. if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
  761. sdata->vif.bss_conf.qos = enable_qos;
  762. if (bss_notify)
  763. ieee80211_bss_info_change_notify(sdata,
  764. BSS_CHANGED_QOS);
  765. }
  766. }
  767. void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
  768. const size_t supp_rates_len,
  769. const u8 *supp_rates)
  770. {
  771. struct ieee80211_local *local = sdata->local;
  772. int i, have_higher_than_11mbit = 0;
  773. /* cf. IEEE 802.11 9.2.12 */
  774. for (i = 0; i < supp_rates_len; i++)
  775. if ((supp_rates[i] & 0x7f) * 5 > 110)
  776. have_higher_than_11mbit = 1;
  777. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  778. have_higher_than_11mbit)
  779. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  780. else
  781. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  782. ieee80211_set_wmm_default(sdata, true);
  783. }
  784. u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
  785. enum ieee80211_band band)
  786. {
  787. struct ieee80211_supported_band *sband;
  788. struct ieee80211_rate *bitrates;
  789. u32 mandatory_rates;
  790. enum ieee80211_rate_flags mandatory_flag;
  791. int i;
  792. sband = local->hw.wiphy->bands[band];
  793. if (WARN_ON(!sband))
  794. return 1;
  795. if (band == IEEE80211_BAND_2GHZ)
  796. mandatory_flag = IEEE80211_RATE_MANDATORY_B;
  797. else
  798. mandatory_flag = IEEE80211_RATE_MANDATORY_A;
  799. bitrates = sband->bitrates;
  800. mandatory_rates = 0;
  801. for (i = 0; i < sband->n_bitrates; i++)
  802. if (bitrates[i].flags & mandatory_flag)
  803. mandatory_rates |= BIT(i);
  804. return mandatory_rates;
  805. }
  806. void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  807. u16 transaction, u16 auth_alg,
  808. u8 *extra, size_t extra_len, const u8 *da,
  809. const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx)
  810. {
  811. struct ieee80211_local *local = sdata->local;
  812. struct sk_buff *skb;
  813. struct ieee80211_mgmt *mgmt;
  814. int err;
  815. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  816. sizeof(*mgmt) + 6 + extra_len);
  817. if (!skb)
  818. return;
  819. skb_reserve(skb, local->hw.extra_tx_headroom);
  820. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
  821. memset(mgmt, 0, 24 + 6);
  822. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  823. IEEE80211_STYPE_AUTH);
  824. memcpy(mgmt->da, da, ETH_ALEN);
  825. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  826. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  827. mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
  828. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  829. mgmt->u.auth.status_code = cpu_to_le16(0);
  830. if (extra)
  831. memcpy(skb_put(skb, extra_len), extra, extra_len);
  832. if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
  833. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  834. err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
  835. WARN_ON(err);
  836. }
  837. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  838. ieee80211_tx_skb(sdata, skb);
  839. }
  840. int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
  841. const u8 *ie, size_t ie_len,
  842. enum ieee80211_band band, u32 rate_mask,
  843. u8 channel)
  844. {
  845. struct ieee80211_supported_band *sband;
  846. u8 *pos;
  847. size_t offset = 0, noffset;
  848. int supp_rates_len, i;
  849. u8 rates[32];
  850. int num_rates;
  851. int ext_rates_len;
  852. sband = local->hw.wiphy->bands[band];
  853. if (WARN_ON_ONCE(!sband))
  854. return 0;
  855. pos = buffer;
  856. num_rates = 0;
  857. for (i = 0; i < sband->n_bitrates; i++) {
  858. if ((BIT(i) & rate_mask) == 0)
  859. continue; /* skip rate */
  860. rates[num_rates++] = (u8) (sband->bitrates[i].bitrate / 5);
  861. }
  862. supp_rates_len = min_t(int, num_rates, 8);
  863. *pos++ = WLAN_EID_SUPP_RATES;
  864. *pos++ = supp_rates_len;
  865. memcpy(pos, rates, supp_rates_len);
  866. pos += supp_rates_len;
  867. /* insert "request information" if in custom IEs */
  868. if (ie && ie_len) {
  869. static const u8 before_extrates[] = {
  870. WLAN_EID_SSID,
  871. WLAN_EID_SUPP_RATES,
  872. WLAN_EID_REQUEST,
  873. };
  874. noffset = ieee80211_ie_split(ie, ie_len,
  875. before_extrates,
  876. ARRAY_SIZE(before_extrates),
  877. offset);
  878. memcpy(pos, ie + offset, noffset - offset);
  879. pos += noffset - offset;
  880. offset = noffset;
  881. }
  882. ext_rates_len = num_rates - supp_rates_len;
  883. if (ext_rates_len > 0) {
  884. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  885. *pos++ = ext_rates_len;
  886. memcpy(pos, rates + supp_rates_len, ext_rates_len);
  887. pos += ext_rates_len;
  888. }
  889. if (channel && sband->band == IEEE80211_BAND_2GHZ) {
  890. *pos++ = WLAN_EID_DS_PARAMS;
  891. *pos++ = 1;
  892. *pos++ = channel;
  893. }
  894. /* insert custom IEs that go before HT */
  895. if (ie && ie_len) {
  896. static const u8 before_ht[] = {
  897. WLAN_EID_SSID,
  898. WLAN_EID_SUPP_RATES,
  899. WLAN_EID_REQUEST,
  900. WLAN_EID_EXT_SUPP_RATES,
  901. WLAN_EID_DS_PARAMS,
  902. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  903. };
  904. noffset = ieee80211_ie_split(ie, ie_len,
  905. before_ht, ARRAY_SIZE(before_ht),
  906. offset);
  907. memcpy(pos, ie + offset, noffset - offset);
  908. pos += noffset - offset;
  909. offset = noffset;
  910. }
  911. if (sband->ht_cap.ht_supported)
  912. pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
  913. sband->ht_cap.cap);
  914. /*
  915. * If adding more here, adjust code in main.c
  916. * that calculates local->scan_ies_len.
  917. */
  918. /* add any remaining custom IEs */
  919. if (ie && ie_len) {
  920. noffset = ie_len;
  921. memcpy(pos, ie + offset, noffset - offset);
  922. pos += noffset - offset;
  923. }
  924. if (sband->vht_cap.vht_supported)
  925. pos = ieee80211_ie_build_vht_cap(pos, &sband->vht_cap,
  926. sband->vht_cap.cap);
  927. return pos - buffer;
  928. }
  929. struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
  930. u8 *dst, u32 ratemask,
  931. const u8 *ssid, size_t ssid_len,
  932. const u8 *ie, size_t ie_len,
  933. bool directed)
  934. {
  935. struct ieee80211_local *local = sdata->local;
  936. struct sk_buff *skb;
  937. struct ieee80211_mgmt *mgmt;
  938. size_t buf_len;
  939. u8 *buf;
  940. u8 chan;
  941. /* FIXME: come up with a proper value */
  942. buf = kmalloc(200 + ie_len, GFP_KERNEL);
  943. if (!buf)
  944. return NULL;
  945. /*
  946. * Do not send DS Channel parameter for directed probe requests
  947. * in order to maximize the chance that we get a response. Some
  948. * badly-behaved APs don't respond when this parameter is included.
  949. */
  950. if (directed)
  951. chan = 0;
  952. else
  953. chan = ieee80211_frequency_to_channel(
  954. local->hw.conf.channel->center_freq);
  955. buf_len = ieee80211_build_preq_ies(local, buf, ie, ie_len,
  956. local->hw.conf.channel->band,
  957. ratemask, chan);
  958. skb = ieee80211_probereq_get(&local->hw, &sdata->vif,
  959. ssid, ssid_len,
  960. buf, buf_len);
  961. if (!skb)
  962. goto out;
  963. if (dst) {
  964. mgmt = (struct ieee80211_mgmt *) skb->data;
  965. memcpy(mgmt->da, dst, ETH_ALEN);
  966. memcpy(mgmt->bssid, dst, ETH_ALEN);
  967. }
  968. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  969. out:
  970. kfree(buf);
  971. return skb;
  972. }
  973. void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
  974. const u8 *ssid, size_t ssid_len,
  975. const u8 *ie, size_t ie_len,
  976. u32 ratemask, bool directed, bool no_cck)
  977. {
  978. struct sk_buff *skb;
  979. skb = ieee80211_build_probe_req(sdata, dst, ratemask, ssid, ssid_len,
  980. ie, ie_len, directed);
  981. if (skb) {
  982. if (no_cck)
  983. IEEE80211_SKB_CB(skb)->flags |=
  984. IEEE80211_TX_CTL_NO_CCK_RATE;
  985. ieee80211_tx_skb(sdata, skb);
  986. }
  987. }
  988. u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
  989. struct ieee802_11_elems *elems,
  990. enum ieee80211_band band, u32 *basic_rates)
  991. {
  992. struct ieee80211_supported_band *sband;
  993. struct ieee80211_rate *bitrates;
  994. size_t num_rates;
  995. u32 supp_rates;
  996. int i, j;
  997. sband = local->hw.wiphy->bands[band];
  998. if (WARN_ON(!sband))
  999. return 1;
  1000. bitrates = sband->bitrates;
  1001. num_rates = sband->n_bitrates;
  1002. supp_rates = 0;
  1003. for (i = 0; i < elems->supp_rates_len +
  1004. elems->ext_supp_rates_len; i++) {
  1005. u8 rate = 0;
  1006. int own_rate;
  1007. bool is_basic;
  1008. if (i < elems->supp_rates_len)
  1009. rate = elems->supp_rates[i];
  1010. else if (elems->ext_supp_rates)
  1011. rate = elems->ext_supp_rates
  1012. [i - elems->supp_rates_len];
  1013. own_rate = 5 * (rate & 0x7f);
  1014. is_basic = !!(rate & 0x80);
  1015. if (is_basic && (rate & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
  1016. continue;
  1017. for (j = 0; j < num_rates; j++) {
  1018. if (bitrates[j].bitrate == own_rate) {
  1019. supp_rates |= BIT(j);
  1020. if (basic_rates && is_basic)
  1021. *basic_rates |= BIT(j);
  1022. }
  1023. }
  1024. }
  1025. return supp_rates;
  1026. }
  1027. void ieee80211_stop_device(struct ieee80211_local *local)
  1028. {
  1029. ieee80211_led_radio(local, false);
  1030. ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO);
  1031. cancel_work_sync(&local->reconfig_filter);
  1032. flush_workqueue(local->workqueue);
  1033. drv_stop(local);
  1034. }
  1035. int ieee80211_reconfig(struct ieee80211_local *local)
  1036. {
  1037. struct ieee80211_hw *hw = &local->hw;
  1038. struct ieee80211_sub_if_data *sdata;
  1039. struct sta_info *sta;
  1040. int res, i;
  1041. #ifdef CONFIG_PM
  1042. if (local->suspended)
  1043. local->resuming = true;
  1044. if (local->wowlan) {
  1045. local->wowlan = false;
  1046. res = drv_resume(local);
  1047. if (res < 0) {
  1048. local->resuming = false;
  1049. return res;
  1050. }
  1051. if (res == 0)
  1052. goto wake_up;
  1053. WARN_ON(res > 1);
  1054. /*
  1055. * res is 1, which means the driver requested
  1056. * to go through a regular reset on wakeup.
  1057. */
  1058. }
  1059. #endif
  1060. /* everything else happens only if HW was up & running */
  1061. if (!local->open_count)
  1062. goto wake_up;
  1063. /*
  1064. * Upon resume hardware can sometimes be goofy due to
  1065. * various platform / driver / bus issues, so restarting
  1066. * the device may at times not work immediately. Propagate
  1067. * the error.
  1068. */
  1069. res = drv_start(local);
  1070. if (res) {
  1071. WARN(local->suspended, "Hardware became unavailable "
  1072. "upon resume. This could be a software issue "
  1073. "prior to suspend or a hardware issue.\n");
  1074. return res;
  1075. }
  1076. /* setup fragmentation threshold */
  1077. drv_set_frag_threshold(local, hw->wiphy->frag_threshold);
  1078. /* setup RTS threshold */
  1079. drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
  1080. /* reset coverage class */
  1081. drv_set_coverage_class(local, hw->wiphy->coverage_class);
  1082. ieee80211_led_radio(local, true);
  1083. ieee80211_mod_tpt_led_trig(local,
  1084. IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
  1085. /* add interfaces */
  1086. sdata = rtnl_dereference(local->monitor_sdata);
  1087. if (sdata) {
  1088. res = drv_add_interface(local, sdata);
  1089. if (WARN_ON(res)) {
  1090. rcu_assign_pointer(local->monitor_sdata, NULL);
  1091. synchronize_net();
  1092. kfree(sdata);
  1093. }
  1094. }
  1095. list_for_each_entry(sdata, &local->interfaces, list) {
  1096. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1097. sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1098. ieee80211_sdata_running(sdata))
  1099. res = drv_add_interface(local, sdata);
  1100. }
  1101. /* add STAs back */
  1102. mutex_lock(&local->sta_mtx);
  1103. list_for_each_entry(sta, &local->sta_list, list) {
  1104. enum ieee80211_sta_state state;
  1105. if (!sta->uploaded)
  1106. continue;
  1107. /* AP-mode stations will be added later */
  1108. if (sta->sdata->vif.type == NL80211_IFTYPE_AP)
  1109. continue;
  1110. for (state = IEEE80211_STA_NOTEXIST;
  1111. state < sta->sta_state; state++)
  1112. WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
  1113. state + 1));
  1114. }
  1115. mutex_unlock(&local->sta_mtx);
  1116. /* reconfigure tx conf */
  1117. if (hw->queues >= IEEE80211_NUM_ACS) {
  1118. list_for_each_entry(sdata, &local->interfaces, list) {
  1119. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1120. sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  1121. !ieee80211_sdata_running(sdata))
  1122. continue;
  1123. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1124. drv_conf_tx(local, sdata, i,
  1125. &sdata->tx_conf[i]);
  1126. }
  1127. }
  1128. /* reconfigure hardware */
  1129. ieee80211_hw_config(local, ~0);
  1130. ieee80211_configure_filter(local);
  1131. /* Finally also reconfigure all the BSS information */
  1132. list_for_each_entry(sdata, &local->interfaces, list) {
  1133. u32 changed;
  1134. if (!ieee80211_sdata_running(sdata))
  1135. continue;
  1136. /* common change flags for all interface types */
  1137. changed = BSS_CHANGED_ERP_CTS_PROT |
  1138. BSS_CHANGED_ERP_PREAMBLE |
  1139. BSS_CHANGED_ERP_SLOT |
  1140. BSS_CHANGED_HT |
  1141. BSS_CHANGED_BASIC_RATES |
  1142. BSS_CHANGED_BEACON_INT |
  1143. BSS_CHANGED_BSSID |
  1144. BSS_CHANGED_CQM |
  1145. BSS_CHANGED_QOS |
  1146. BSS_CHANGED_IDLE;
  1147. switch (sdata->vif.type) {
  1148. case NL80211_IFTYPE_STATION:
  1149. changed |= BSS_CHANGED_ASSOC |
  1150. BSS_CHANGED_ARP_FILTER;
  1151. mutex_lock(&sdata->u.mgd.mtx);
  1152. ieee80211_bss_info_change_notify(sdata, changed);
  1153. mutex_unlock(&sdata->u.mgd.mtx);
  1154. break;
  1155. case NL80211_IFTYPE_ADHOC:
  1156. changed |= BSS_CHANGED_IBSS;
  1157. /* fall through */
  1158. case NL80211_IFTYPE_AP:
  1159. changed |= BSS_CHANGED_SSID;
  1160. if (sdata->vif.type == NL80211_IFTYPE_AP)
  1161. changed |= BSS_CHANGED_AP_PROBE_RESP;
  1162. /* fall through */
  1163. case NL80211_IFTYPE_MESH_POINT:
  1164. changed |= BSS_CHANGED_BEACON |
  1165. BSS_CHANGED_BEACON_ENABLED;
  1166. ieee80211_bss_info_change_notify(sdata, changed);
  1167. break;
  1168. case NL80211_IFTYPE_WDS:
  1169. break;
  1170. case NL80211_IFTYPE_AP_VLAN:
  1171. case NL80211_IFTYPE_MONITOR:
  1172. /* ignore virtual */
  1173. break;
  1174. case NL80211_IFTYPE_UNSPECIFIED:
  1175. case NUM_NL80211_IFTYPES:
  1176. case NL80211_IFTYPE_P2P_CLIENT:
  1177. case NL80211_IFTYPE_P2P_GO:
  1178. WARN_ON(1);
  1179. break;
  1180. }
  1181. }
  1182. ieee80211_recalc_ps(local, -1);
  1183. /*
  1184. * The sta might be in psm against the ap (e.g. because
  1185. * this was the state before a hw restart), so we
  1186. * explicitly send a null packet in order to make sure
  1187. * it'll sync against the ap (and get out of psm).
  1188. */
  1189. if (!(local->hw.conf.flags & IEEE80211_CONF_PS)) {
  1190. list_for_each_entry(sdata, &local->interfaces, list) {
  1191. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1192. continue;
  1193. ieee80211_send_nullfunc(local, sdata, 0);
  1194. }
  1195. }
  1196. /* APs are now beaconing, add back stations */
  1197. mutex_lock(&local->sta_mtx);
  1198. list_for_each_entry(sta, &local->sta_list, list) {
  1199. enum ieee80211_sta_state state;
  1200. if (!sta->uploaded)
  1201. continue;
  1202. if (sta->sdata->vif.type != NL80211_IFTYPE_AP)
  1203. continue;
  1204. for (state = IEEE80211_STA_NOTEXIST;
  1205. state < sta->sta_state; state++)
  1206. WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
  1207. state + 1));
  1208. }
  1209. mutex_unlock(&local->sta_mtx);
  1210. /* add back keys */
  1211. list_for_each_entry(sdata, &local->interfaces, list)
  1212. if (ieee80211_sdata_running(sdata))
  1213. ieee80211_enable_keys(sdata);
  1214. wake_up:
  1215. local->in_reconfig = false;
  1216. barrier();
  1217. /*
  1218. * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
  1219. * sessions can be established after a resume.
  1220. *
  1221. * Also tear down aggregation sessions since reconfiguring
  1222. * them in a hardware restart scenario is not easily done
  1223. * right now, and the hardware will have lost information
  1224. * about the sessions, but we and the AP still think they
  1225. * are active. This is really a workaround though.
  1226. */
  1227. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  1228. mutex_lock(&local->sta_mtx);
  1229. list_for_each_entry(sta, &local->sta_list, list) {
  1230. ieee80211_sta_tear_down_BA_sessions(sta, true);
  1231. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  1232. }
  1233. mutex_unlock(&local->sta_mtx);
  1234. }
  1235. ieee80211_wake_queues_by_reason(hw,
  1236. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  1237. /*
  1238. * If this is for hw restart things are still running.
  1239. * We may want to change that later, however.
  1240. */
  1241. if (!local->suspended)
  1242. return 0;
  1243. #ifdef CONFIG_PM
  1244. /* first set suspended false, then resuming */
  1245. local->suspended = false;
  1246. mb();
  1247. local->resuming = false;
  1248. list_for_each_entry(sdata, &local->interfaces, list) {
  1249. switch(sdata->vif.type) {
  1250. case NL80211_IFTYPE_STATION:
  1251. ieee80211_sta_restart(sdata);
  1252. break;
  1253. case NL80211_IFTYPE_ADHOC:
  1254. ieee80211_ibss_restart(sdata);
  1255. break;
  1256. case NL80211_IFTYPE_MESH_POINT:
  1257. ieee80211_mesh_restart(sdata);
  1258. break;
  1259. default:
  1260. break;
  1261. }
  1262. }
  1263. mod_timer(&local->sta_cleanup, jiffies + 1);
  1264. mutex_lock(&local->sta_mtx);
  1265. list_for_each_entry(sta, &local->sta_list, list)
  1266. mesh_plink_restart(sta);
  1267. mutex_unlock(&local->sta_mtx);
  1268. #else
  1269. WARN_ON(1);
  1270. #endif
  1271. return 0;
  1272. }
  1273. void ieee80211_resume_disconnect(struct ieee80211_vif *vif)
  1274. {
  1275. struct ieee80211_sub_if_data *sdata;
  1276. struct ieee80211_local *local;
  1277. struct ieee80211_key *key;
  1278. if (WARN_ON(!vif))
  1279. return;
  1280. sdata = vif_to_sdata(vif);
  1281. local = sdata->local;
  1282. if (WARN_ON(!local->resuming))
  1283. return;
  1284. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  1285. return;
  1286. sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME;
  1287. mutex_lock(&local->key_mtx);
  1288. list_for_each_entry(key, &sdata->key_list, list)
  1289. key->flags |= KEY_FLAG_TAINTED;
  1290. mutex_unlock(&local->key_mtx);
  1291. }
  1292. EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect);
  1293. static int check_mgd_smps(struct ieee80211_if_managed *ifmgd,
  1294. enum ieee80211_smps_mode *smps_mode)
  1295. {
  1296. if (ifmgd->associated) {
  1297. *smps_mode = ifmgd->ap_smps;
  1298. if (*smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1299. if (ifmgd->powersave)
  1300. *smps_mode = IEEE80211_SMPS_DYNAMIC;
  1301. else
  1302. *smps_mode = IEEE80211_SMPS_OFF;
  1303. }
  1304. return 1;
  1305. }
  1306. return 0;
  1307. }
  1308. /* must hold iflist_mtx */
  1309. void ieee80211_recalc_smps(struct ieee80211_local *local)
  1310. {
  1311. struct ieee80211_sub_if_data *sdata;
  1312. enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_OFF;
  1313. int count = 0;
  1314. lockdep_assert_held(&local->iflist_mtx);
  1315. /*
  1316. * This function could be improved to handle multiple
  1317. * interfaces better, but right now it makes any
  1318. * non-station interfaces force SM PS to be turned
  1319. * off. If there are multiple station interfaces it
  1320. * could also use the best possible mode, e.g. if
  1321. * one is in static and the other in dynamic then
  1322. * dynamic is ok.
  1323. */
  1324. list_for_each_entry(sdata, &local->interfaces, list) {
  1325. if (!ieee80211_sdata_running(sdata))
  1326. continue;
  1327. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1328. goto set;
  1329. count += check_mgd_smps(&sdata->u.mgd, &smps_mode);
  1330. if (count > 1) {
  1331. smps_mode = IEEE80211_SMPS_OFF;
  1332. break;
  1333. }
  1334. }
  1335. if (smps_mode == local->smps_mode)
  1336. return;
  1337. set:
  1338. local->smps_mode = smps_mode;
  1339. /* changed flag is auto-detected for this */
  1340. ieee80211_hw_config(local, 0);
  1341. }
  1342. static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
  1343. {
  1344. int i;
  1345. for (i = 0; i < n_ids; i++)
  1346. if (ids[i] == id)
  1347. return true;
  1348. return false;
  1349. }
  1350. /**
  1351. * ieee80211_ie_split - split an IE buffer according to ordering
  1352. *
  1353. * @ies: the IE buffer
  1354. * @ielen: the length of the IE buffer
  1355. * @ids: an array with element IDs that are allowed before
  1356. * the split
  1357. * @n_ids: the size of the element ID array
  1358. * @offset: offset where to start splitting in the buffer
  1359. *
  1360. * This function splits an IE buffer by updating the @offset
  1361. * variable to point to the location where the buffer should be
  1362. * split.
  1363. *
  1364. * It assumes that the given IE buffer is well-formed, this
  1365. * has to be guaranteed by the caller!
  1366. *
  1367. * It also assumes that the IEs in the buffer are ordered
  1368. * correctly, if not the result of using this function will not
  1369. * be ordered correctly either, i.e. it does no reordering.
  1370. *
  1371. * The function returns the offset where the next part of the
  1372. * buffer starts, which may be @ielen if the entire (remainder)
  1373. * of the buffer should be used.
  1374. */
  1375. size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
  1376. const u8 *ids, int n_ids, size_t offset)
  1377. {
  1378. size_t pos = offset;
  1379. while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos]))
  1380. pos += 2 + ies[pos + 1];
  1381. return pos;
  1382. }
  1383. size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
  1384. {
  1385. size_t pos = offset;
  1386. while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
  1387. pos += 2 + ies[pos + 1];
  1388. return pos;
  1389. }
  1390. static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
  1391. int rssi_min_thold,
  1392. int rssi_max_thold)
  1393. {
  1394. trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
  1395. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1396. return;
  1397. /*
  1398. * Scale up threshold values before storing it, as the RSSI averaging
  1399. * algorithm uses a scaled up value as well. Change this scaling
  1400. * factor if the RSSI averaging algorithm changes.
  1401. */
  1402. sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
  1403. sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
  1404. }
  1405. void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
  1406. int rssi_min_thold,
  1407. int rssi_max_thold)
  1408. {
  1409. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1410. WARN_ON(rssi_min_thold == rssi_max_thold ||
  1411. rssi_min_thold > rssi_max_thold);
  1412. _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
  1413. rssi_max_thold);
  1414. }
  1415. EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
  1416. void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
  1417. {
  1418. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1419. _ieee80211_enable_rssi_reports(sdata, 0, 0);
  1420. }
  1421. EXPORT_SYMBOL(ieee80211_disable_rssi_reports);
  1422. u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  1423. u16 cap)
  1424. {
  1425. __le16 tmp;
  1426. *pos++ = WLAN_EID_HT_CAPABILITY;
  1427. *pos++ = sizeof(struct ieee80211_ht_cap);
  1428. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  1429. /* capability flags */
  1430. tmp = cpu_to_le16(cap);
  1431. memcpy(pos, &tmp, sizeof(u16));
  1432. pos += sizeof(u16);
  1433. /* AMPDU parameters */
  1434. *pos++ = ht_cap->ampdu_factor |
  1435. (ht_cap->ampdu_density <<
  1436. IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
  1437. /* MCS set */
  1438. memcpy(pos, &ht_cap->mcs, sizeof(ht_cap->mcs));
  1439. pos += sizeof(ht_cap->mcs);
  1440. /* extended capabilities */
  1441. pos += sizeof(__le16);
  1442. /* BF capabilities */
  1443. pos += sizeof(__le32);
  1444. /* antenna selection */
  1445. pos += sizeof(u8);
  1446. return pos;
  1447. }
  1448. u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
  1449. u32 cap)
  1450. {
  1451. __le32 tmp;
  1452. *pos++ = WLAN_EID_VHT_CAPABILITY;
  1453. *pos++ = sizeof(struct ieee80211_vht_capabilities);
  1454. memset(pos, 0, sizeof(struct ieee80211_vht_capabilities));
  1455. /* capability flags */
  1456. tmp = cpu_to_le32(cap);
  1457. memcpy(pos, &tmp, sizeof(u32));
  1458. pos += sizeof(u32);
  1459. /* VHT MCS set */
  1460. memcpy(pos, &vht_cap->vht_mcs, sizeof(vht_cap->vht_mcs));
  1461. pos += sizeof(vht_cap->vht_mcs);
  1462. return pos;
  1463. }
  1464. u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  1465. struct ieee80211_channel *channel,
  1466. enum nl80211_channel_type channel_type,
  1467. u16 prot_mode)
  1468. {
  1469. struct ieee80211_ht_operation *ht_oper;
  1470. /* Build HT Information */
  1471. *pos++ = WLAN_EID_HT_OPERATION;
  1472. *pos++ = sizeof(struct ieee80211_ht_operation);
  1473. ht_oper = (struct ieee80211_ht_operation *)pos;
  1474. ht_oper->primary_chan =
  1475. ieee80211_frequency_to_channel(channel->center_freq);
  1476. switch (channel_type) {
  1477. case NL80211_CHAN_HT40MINUS:
  1478. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  1479. break;
  1480. case NL80211_CHAN_HT40PLUS:
  1481. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  1482. break;
  1483. case NL80211_CHAN_HT20:
  1484. default:
  1485. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  1486. break;
  1487. }
  1488. if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  1489. channel_type != NL80211_CHAN_NO_HT &&
  1490. channel_type != NL80211_CHAN_HT20)
  1491. ht_oper->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
  1492. ht_oper->operation_mode = cpu_to_le16(prot_mode);
  1493. ht_oper->stbc_param = 0x0000;
  1494. /* It seems that Basic MCS set and Supported MCS set
  1495. are identical for the first 10 bytes */
  1496. memset(&ht_oper->basic_set, 0, 16);
  1497. memcpy(&ht_oper->basic_set, &ht_cap->mcs, 10);
  1498. return pos + sizeof(struct ieee80211_ht_operation);
  1499. }
  1500. enum nl80211_channel_type
  1501. ieee80211_ht_oper_to_channel_type(struct ieee80211_ht_operation *ht_oper)
  1502. {
  1503. enum nl80211_channel_type channel_type;
  1504. if (!ht_oper)
  1505. return NL80211_CHAN_NO_HT;
  1506. switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  1507. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  1508. channel_type = NL80211_CHAN_HT20;
  1509. break;
  1510. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  1511. channel_type = NL80211_CHAN_HT40PLUS;
  1512. break;
  1513. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  1514. channel_type = NL80211_CHAN_HT40MINUS;
  1515. break;
  1516. default:
  1517. channel_type = NL80211_CHAN_NO_HT;
  1518. }
  1519. return channel_type;
  1520. }
  1521. int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
  1522. struct sk_buff *skb, bool need_basic)
  1523. {
  1524. struct ieee80211_local *local = sdata->local;
  1525. struct ieee80211_supported_band *sband;
  1526. int rate;
  1527. u8 i, rates, *pos;
  1528. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  1529. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1530. rates = sband->n_bitrates;
  1531. if (rates > 8)
  1532. rates = 8;
  1533. if (skb_tailroom(skb) < rates + 2)
  1534. return -ENOMEM;
  1535. pos = skb_put(skb, rates + 2);
  1536. *pos++ = WLAN_EID_SUPP_RATES;
  1537. *pos++ = rates;
  1538. for (i = 0; i < rates; i++) {
  1539. u8 basic = 0;
  1540. if (need_basic && basic_rates & BIT(i))
  1541. basic = 0x80;
  1542. rate = sband->bitrates[i].bitrate;
  1543. *pos++ = basic | (u8) (rate / 5);
  1544. }
  1545. return 0;
  1546. }
  1547. int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
  1548. struct sk_buff *skb, bool need_basic)
  1549. {
  1550. struct ieee80211_local *local = sdata->local;
  1551. struct ieee80211_supported_band *sband;
  1552. int rate;
  1553. u8 i, exrates, *pos;
  1554. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  1555. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1556. exrates = sband->n_bitrates;
  1557. if (exrates > 8)
  1558. exrates -= 8;
  1559. else
  1560. exrates = 0;
  1561. if (skb_tailroom(skb) < exrates + 2)
  1562. return -ENOMEM;
  1563. if (exrates) {
  1564. pos = skb_put(skb, exrates + 2);
  1565. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1566. *pos++ = exrates;
  1567. for (i = 8; i < sband->n_bitrates; i++) {
  1568. u8 basic = 0;
  1569. if (need_basic && basic_rates & BIT(i))
  1570. basic = 0x80;
  1571. rate = sband->bitrates[i].bitrate;
  1572. *pos++ = basic | (u8) (rate / 5);
  1573. }
  1574. }
  1575. return 0;
  1576. }
  1577. int ieee80211_ave_rssi(struct ieee80211_vif *vif)
  1578. {
  1579. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1580. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1581. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) {
  1582. /* non-managed type inferfaces */
  1583. return 0;
  1584. }
  1585. return ifmgd->ave_beacon_signal;
  1586. }
  1587. EXPORT_SYMBOL_GPL(ieee80211_ave_rssi);