util.c 47 KB

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