util.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  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/types.h>
  16. #include <linux/slab.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/bitmap.h>
  21. #include <linux/crc32.h>
  22. #include <net/net_namespace.h>
  23. #include <net/cfg80211.h>
  24. #include <net/rtnetlink.h>
  25. #include "ieee80211_i.h"
  26. #include "driver-ops.h"
  27. #include "rate.h"
  28. #include "mesh.h"
  29. #include "wme.h"
  30. #include "led.h"
  31. #include "wep.h"
  32. /* privid for wiphys to determine whether they belong to us or not */
  33. void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
  34. struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
  35. {
  36. struct ieee80211_local *local;
  37. BUG_ON(!wiphy);
  38. local = wiphy_priv(wiphy);
  39. return &local->hw;
  40. }
  41. EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
  42. u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
  43. enum nl80211_iftype type)
  44. {
  45. __le16 fc = hdr->frame_control;
  46. /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
  47. if (len < 16)
  48. return NULL;
  49. if (ieee80211_is_data(fc)) {
  50. if (len < 24) /* drop incorrect hdr len (data) */
  51. return NULL;
  52. if (ieee80211_has_a4(fc))
  53. return NULL;
  54. if (ieee80211_has_tods(fc))
  55. return hdr->addr1;
  56. if (ieee80211_has_fromds(fc))
  57. return hdr->addr2;
  58. return hdr->addr3;
  59. }
  60. if (ieee80211_is_mgmt(fc)) {
  61. if (len < 24) /* drop incorrect hdr len (mgmt) */
  62. return NULL;
  63. return hdr->addr3;
  64. }
  65. if (ieee80211_is_ctl(fc)) {
  66. if(ieee80211_is_pspoll(fc))
  67. return hdr->addr1;
  68. if (ieee80211_is_back_req(fc)) {
  69. switch (type) {
  70. case NL80211_IFTYPE_STATION:
  71. return hdr->addr2;
  72. case NL80211_IFTYPE_AP:
  73. case NL80211_IFTYPE_AP_VLAN:
  74. return hdr->addr1;
  75. default:
  76. break; /* fall through to the return */
  77. }
  78. }
  79. }
  80. return NULL;
  81. }
  82. void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
  83. {
  84. struct sk_buff *skb = tx->skb;
  85. struct ieee80211_hdr *hdr;
  86. do {
  87. hdr = (struct ieee80211_hdr *) skb->data;
  88. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  89. } while ((skb = skb->next));
  90. }
  91. int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
  92. int rate, int erp, int short_preamble)
  93. {
  94. int dur;
  95. /* calculate duration (in microseconds, rounded up to next higher
  96. * integer if it includes a fractional microsecond) to send frame of
  97. * len bytes (does not include FCS) at the given rate. Duration will
  98. * also include SIFS.
  99. *
  100. * rate is in 100 kbps, so divident is multiplied by 10 in the
  101. * DIV_ROUND_UP() operations.
  102. */
  103. if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
  104. /*
  105. * OFDM:
  106. *
  107. * N_DBPS = DATARATE x 4
  108. * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
  109. * (16 = SIGNAL time, 6 = tail bits)
  110. * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
  111. *
  112. * T_SYM = 4 usec
  113. * 802.11a - 17.5.2: aSIFSTime = 16 usec
  114. * 802.11g - 19.8.4: aSIFSTime = 10 usec +
  115. * signal ext = 6 usec
  116. */
  117. dur = 16; /* SIFS + signal ext */
  118. dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
  119. dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
  120. dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
  121. 4 * rate); /* T_SYM x N_SYM */
  122. } else {
  123. /*
  124. * 802.11b or 802.11g with 802.11b compatibility:
  125. * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
  126. * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
  127. *
  128. * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
  129. * aSIFSTime = 10 usec
  130. * aPreambleLength = 144 usec or 72 usec with short preamble
  131. * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
  132. */
  133. dur = 10; /* aSIFSTime = 10 usec */
  134. dur += short_preamble ? (72 + 24) : (144 + 48);
  135. dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
  136. }
  137. return dur;
  138. }
  139. /* Exported duration function for driver use */
  140. __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
  141. struct ieee80211_vif *vif,
  142. size_t frame_len,
  143. struct ieee80211_rate *rate)
  144. {
  145. struct ieee80211_local *local = hw_to_local(hw);
  146. struct ieee80211_sub_if_data *sdata;
  147. u16 dur;
  148. int erp;
  149. bool short_preamble = false;
  150. erp = 0;
  151. if (vif) {
  152. sdata = vif_to_sdata(vif);
  153. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  154. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  155. erp = rate->flags & IEEE80211_RATE_ERP_G;
  156. }
  157. dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
  158. short_preamble);
  159. return cpu_to_le16(dur);
  160. }
  161. EXPORT_SYMBOL(ieee80211_generic_frame_duration);
  162. __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
  163. struct ieee80211_vif *vif, size_t frame_len,
  164. const struct ieee80211_tx_info *frame_txctl)
  165. {
  166. struct ieee80211_local *local = hw_to_local(hw);
  167. struct ieee80211_rate *rate;
  168. struct ieee80211_sub_if_data *sdata;
  169. bool short_preamble;
  170. int erp;
  171. u16 dur;
  172. struct ieee80211_supported_band *sband;
  173. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  174. short_preamble = false;
  175. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  176. erp = 0;
  177. if (vif) {
  178. sdata = vif_to_sdata(vif);
  179. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  180. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  181. erp = rate->flags & IEEE80211_RATE_ERP_G;
  182. }
  183. /* CTS duration */
  184. dur = ieee80211_frame_duration(local, 10, rate->bitrate,
  185. erp, short_preamble);
  186. /* Data frame duration */
  187. dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
  188. erp, short_preamble);
  189. /* ACK duration */
  190. dur += ieee80211_frame_duration(local, 10, rate->bitrate,
  191. erp, short_preamble);
  192. return cpu_to_le16(dur);
  193. }
  194. EXPORT_SYMBOL(ieee80211_rts_duration);
  195. __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
  196. struct ieee80211_vif *vif,
  197. size_t frame_len,
  198. const struct ieee80211_tx_info *frame_txctl)
  199. {
  200. struct ieee80211_local *local = hw_to_local(hw);
  201. struct ieee80211_rate *rate;
  202. struct ieee80211_sub_if_data *sdata;
  203. bool short_preamble;
  204. int erp;
  205. u16 dur;
  206. struct ieee80211_supported_band *sband;
  207. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  208. short_preamble = false;
  209. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  210. erp = 0;
  211. if (vif) {
  212. sdata = vif_to_sdata(vif);
  213. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  214. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  215. erp = rate->flags & IEEE80211_RATE_ERP_G;
  216. }
  217. /* Data frame duration */
  218. dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
  219. erp, short_preamble);
  220. if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
  221. /* ACK duration */
  222. dur += ieee80211_frame_duration(local, 10, rate->bitrate,
  223. erp, short_preamble);
  224. }
  225. return cpu_to_le16(dur);
  226. }
  227. EXPORT_SYMBOL(ieee80211_ctstoself_duration);
  228. static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
  229. enum queue_stop_reason reason)
  230. {
  231. struct ieee80211_local *local = hw_to_local(hw);
  232. struct ieee80211_sub_if_data *sdata;
  233. trace_wake_queue(local, queue, reason);
  234. if (WARN_ON(queue >= hw->queues))
  235. return;
  236. __clear_bit(reason, &local->queue_stop_reasons[queue]);
  237. if (local->queue_stop_reasons[queue] != 0)
  238. /* someone still has this queue stopped */
  239. return;
  240. if (skb_queue_empty(&local->pending[queue])) {
  241. rcu_read_lock();
  242. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  243. if (test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
  244. continue;
  245. netif_wake_subqueue(sdata->dev, queue);
  246. }
  247. rcu_read_unlock();
  248. } else
  249. tasklet_schedule(&local->tx_pending_tasklet);
  250. }
  251. void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
  252. enum queue_stop_reason reason)
  253. {
  254. struct ieee80211_local *local = hw_to_local(hw);
  255. unsigned long flags;
  256. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  257. __ieee80211_wake_queue(hw, queue, reason);
  258. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  259. }
  260. void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
  261. {
  262. ieee80211_wake_queue_by_reason(hw, queue,
  263. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  264. }
  265. EXPORT_SYMBOL(ieee80211_wake_queue);
  266. static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
  267. enum queue_stop_reason reason)
  268. {
  269. struct ieee80211_local *local = hw_to_local(hw);
  270. struct ieee80211_sub_if_data *sdata;
  271. trace_stop_queue(local, queue, reason);
  272. if (WARN_ON(queue >= hw->queues))
  273. return;
  274. __set_bit(reason, &local->queue_stop_reasons[queue]);
  275. rcu_read_lock();
  276. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  277. netif_stop_subqueue(sdata->dev, queue);
  278. rcu_read_unlock();
  279. }
  280. void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
  281. enum queue_stop_reason reason)
  282. {
  283. struct ieee80211_local *local = hw_to_local(hw);
  284. unsigned long flags;
  285. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  286. __ieee80211_stop_queue(hw, queue, reason);
  287. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  288. }
  289. void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
  290. {
  291. ieee80211_stop_queue_by_reason(hw, queue,
  292. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  293. }
  294. EXPORT_SYMBOL(ieee80211_stop_queue);
  295. void ieee80211_add_pending_skb(struct ieee80211_local *local,
  296. struct sk_buff *skb)
  297. {
  298. struct ieee80211_hw *hw = &local->hw;
  299. unsigned long flags;
  300. int queue = skb_get_queue_mapping(skb);
  301. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  302. if (WARN_ON(!info->control.vif)) {
  303. kfree_skb(skb);
  304. return;
  305. }
  306. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  307. __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  308. __skb_queue_tail(&local->pending[queue], skb);
  309. __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  310. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  311. }
  312. int ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
  313. struct sk_buff_head *skbs,
  314. void (*fn)(void *data), void *data)
  315. {
  316. struct ieee80211_hw *hw = &local->hw;
  317. struct sk_buff *skb;
  318. unsigned long flags;
  319. int queue, ret = 0, i;
  320. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  321. for (i = 0; i < hw->queues; i++)
  322. __ieee80211_stop_queue(hw, i,
  323. IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  324. while ((skb = skb_dequeue(skbs))) {
  325. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  326. if (WARN_ON(!info->control.vif)) {
  327. kfree_skb(skb);
  328. continue;
  329. }
  330. ret++;
  331. queue = skb_get_queue_mapping(skb);
  332. __skb_queue_tail(&local->pending[queue], skb);
  333. }
  334. if (fn)
  335. fn(data);
  336. for (i = 0; i < hw->queues; i++)
  337. __ieee80211_wake_queue(hw, i,
  338. IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  339. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  340. return ret;
  341. }
  342. int ieee80211_add_pending_skbs(struct ieee80211_local *local,
  343. struct sk_buff_head *skbs)
  344. {
  345. return ieee80211_add_pending_skbs_fn(local, skbs, NULL, NULL);
  346. }
  347. void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
  348. enum queue_stop_reason reason)
  349. {
  350. struct ieee80211_local *local = hw_to_local(hw);
  351. unsigned long flags;
  352. int i;
  353. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  354. for (i = 0; i < hw->queues; i++)
  355. __ieee80211_stop_queue(hw, i, reason);
  356. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  357. }
  358. void ieee80211_stop_queues(struct ieee80211_hw *hw)
  359. {
  360. ieee80211_stop_queues_by_reason(hw,
  361. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  362. }
  363. EXPORT_SYMBOL(ieee80211_stop_queues);
  364. int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
  365. {
  366. struct ieee80211_local *local = hw_to_local(hw);
  367. unsigned long flags;
  368. int ret;
  369. if (WARN_ON(queue >= hw->queues))
  370. return true;
  371. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  372. ret = !!local->queue_stop_reasons[queue];
  373. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  374. return ret;
  375. }
  376. EXPORT_SYMBOL(ieee80211_queue_stopped);
  377. void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
  378. enum queue_stop_reason reason)
  379. {
  380. struct ieee80211_local *local = hw_to_local(hw);
  381. unsigned long flags;
  382. int i;
  383. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  384. for (i = 0; i < hw->queues; i++)
  385. __ieee80211_wake_queue(hw, i, reason);
  386. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  387. }
  388. void ieee80211_wake_queues(struct ieee80211_hw *hw)
  389. {
  390. ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
  391. }
  392. EXPORT_SYMBOL(ieee80211_wake_queues);
  393. void ieee80211_iterate_active_interfaces(
  394. struct ieee80211_hw *hw,
  395. void (*iterator)(void *data, u8 *mac,
  396. struct ieee80211_vif *vif),
  397. void *data)
  398. {
  399. struct ieee80211_local *local = hw_to_local(hw);
  400. struct ieee80211_sub_if_data *sdata;
  401. mutex_lock(&local->iflist_mtx);
  402. list_for_each_entry(sdata, &local->interfaces, list) {
  403. switch (sdata->vif.type) {
  404. case NL80211_IFTYPE_MONITOR:
  405. case NL80211_IFTYPE_AP_VLAN:
  406. continue;
  407. default:
  408. break;
  409. }
  410. if (ieee80211_sdata_running(sdata))
  411. iterator(data, sdata->vif.addr,
  412. &sdata->vif);
  413. }
  414. mutex_unlock(&local->iflist_mtx);
  415. }
  416. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
  417. void ieee80211_iterate_active_interfaces_atomic(
  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. rcu_read_lock();
  426. list_for_each_entry_rcu(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. rcu_read_unlock();
  439. }
  440. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
  441. /*
  442. * Nothing should have been stuffed into the workqueue during
  443. * the suspend->resume cycle. If this WARN is seen then there
  444. * is a bug with either the driver suspend or something in
  445. * mac80211 stuffing into the workqueue which we haven't yet
  446. * cleared during mac80211's suspend cycle.
  447. */
  448. static bool ieee80211_can_queue_work(struct ieee80211_local *local)
  449. {
  450. if (WARN(local->suspended && !local->resuming,
  451. "queueing ieee80211 work while going to suspend\n"))
  452. return false;
  453. return true;
  454. }
  455. void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
  456. {
  457. struct ieee80211_local *local = hw_to_local(hw);
  458. if (!ieee80211_can_queue_work(local))
  459. return;
  460. queue_work(local->workqueue, work);
  461. }
  462. EXPORT_SYMBOL(ieee80211_queue_work);
  463. void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
  464. struct delayed_work *dwork,
  465. unsigned long delay)
  466. {
  467. struct ieee80211_local *local = hw_to_local(hw);
  468. if (!ieee80211_can_queue_work(local))
  469. return;
  470. queue_delayed_work(local->workqueue, dwork, delay);
  471. }
  472. EXPORT_SYMBOL(ieee80211_queue_delayed_work);
  473. void ieee802_11_parse_elems(u8 *start, size_t len,
  474. struct ieee802_11_elems *elems)
  475. {
  476. ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
  477. }
  478. u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
  479. struct ieee802_11_elems *elems,
  480. u64 filter, u32 crc)
  481. {
  482. size_t left = len;
  483. u8 *pos = start;
  484. bool calc_crc = filter != 0;
  485. memset(elems, 0, sizeof(*elems));
  486. elems->ie_start = start;
  487. elems->total_len = len;
  488. while (left >= 2) {
  489. u8 id, elen;
  490. id = *pos++;
  491. elen = *pos++;
  492. left -= 2;
  493. if (elen > left)
  494. break;
  495. if (calc_crc && id < 64 && (filter & (1ULL << id)))
  496. crc = crc32_be(crc, pos - 2, elen + 2);
  497. switch (id) {
  498. case WLAN_EID_SSID:
  499. elems->ssid = pos;
  500. elems->ssid_len = elen;
  501. break;
  502. case WLAN_EID_SUPP_RATES:
  503. elems->supp_rates = pos;
  504. elems->supp_rates_len = elen;
  505. break;
  506. case WLAN_EID_FH_PARAMS:
  507. elems->fh_params = pos;
  508. elems->fh_params_len = elen;
  509. break;
  510. case WLAN_EID_DS_PARAMS:
  511. elems->ds_params = pos;
  512. elems->ds_params_len = elen;
  513. break;
  514. case WLAN_EID_CF_PARAMS:
  515. elems->cf_params = pos;
  516. elems->cf_params_len = elen;
  517. break;
  518. case WLAN_EID_TIM:
  519. if (elen >= sizeof(struct ieee80211_tim_ie)) {
  520. elems->tim = (void *)pos;
  521. elems->tim_len = elen;
  522. }
  523. break;
  524. case WLAN_EID_IBSS_PARAMS:
  525. elems->ibss_params = pos;
  526. elems->ibss_params_len = elen;
  527. break;
  528. case WLAN_EID_CHALLENGE:
  529. elems->challenge = pos;
  530. elems->challenge_len = elen;
  531. break;
  532. case WLAN_EID_VENDOR_SPECIFIC:
  533. if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
  534. pos[2] == 0xf2) {
  535. /* Microsoft OUI (00:50:F2) */
  536. if (calc_crc)
  537. crc = crc32_be(crc, pos - 2, elen + 2);
  538. if (pos[3] == 1) {
  539. /* OUI Type 1 - WPA IE */
  540. elems->wpa = pos;
  541. elems->wpa_len = elen;
  542. } else if (elen >= 5 && pos[3] == 2) {
  543. /* OUI Type 2 - WMM IE */
  544. if (pos[4] == 0) {
  545. elems->wmm_info = pos;
  546. elems->wmm_info_len = elen;
  547. } else if (pos[4] == 1) {
  548. elems->wmm_param = pos;
  549. elems->wmm_param_len = elen;
  550. }
  551. }
  552. }
  553. break;
  554. case WLAN_EID_RSN:
  555. elems->rsn = pos;
  556. elems->rsn_len = elen;
  557. break;
  558. case WLAN_EID_ERP_INFO:
  559. elems->erp_info = pos;
  560. elems->erp_info_len = elen;
  561. break;
  562. case WLAN_EID_EXT_SUPP_RATES:
  563. elems->ext_supp_rates = pos;
  564. elems->ext_supp_rates_len = elen;
  565. break;
  566. case WLAN_EID_HT_CAPABILITY:
  567. if (elen >= sizeof(struct ieee80211_ht_cap))
  568. elems->ht_cap_elem = (void *)pos;
  569. break;
  570. case WLAN_EID_HT_INFORMATION:
  571. if (elen >= sizeof(struct ieee80211_ht_info))
  572. elems->ht_info_elem = (void *)pos;
  573. break;
  574. case WLAN_EID_MESH_ID:
  575. elems->mesh_id = pos;
  576. elems->mesh_id_len = elen;
  577. break;
  578. case WLAN_EID_MESH_CONFIG:
  579. if (elen >= sizeof(struct ieee80211_meshconf_ie))
  580. elems->mesh_config = (void *)pos;
  581. break;
  582. case WLAN_EID_PEER_LINK:
  583. elems->peer_link = pos;
  584. elems->peer_link_len = elen;
  585. break;
  586. case WLAN_EID_PREQ:
  587. elems->preq = pos;
  588. elems->preq_len = elen;
  589. break;
  590. case WLAN_EID_PREP:
  591. elems->prep = pos;
  592. elems->prep_len = elen;
  593. break;
  594. case WLAN_EID_PERR:
  595. elems->perr = pos;
  596. elems->perr_len = elen;
  597. break;
  598. case WLAN_EID_RANN:
  599. if (elen >= sizeof(struct ieee80211_rann_ie))
  600. elems->rann = (void *)pos;
  601. break;
  602. case WLAN_EID_CHANNEL_SWITCH:
  603. elems->ch_switch_elem = pos;
  604. elems->ch_switch_elem_len = elen;
  605. break;
  606. case WLAN_EID_QUIET:
  607. if (!elems->quiet_elem) {
  608. elems->quiet_elem = pos;
  609. elems->quiet_elem_len = elen;
  610. }
  611. elems->num_of_quiet_elem++;
  612. break;
  613. case WLAN_EID_COUNTRY:
  614. elems->country_elem = pos;
  615. elems->country_elem_len = elen;
  616. break;
  617. case WLAN_EID_PWR_CONSTRAINT:
  618. elems->pwr_constr_elem = pos;
  619. elems->pwr_constr_elem_len = elen;
  620. break;
  621. case WLAN_EID_TIMEOUT_INTERVAL:
  622. elems->timeout_int = pos;
  623. elems->timeout_int_len = elen;
  624. break;
  625. default:
  626. break;
  627. }
  628. left -= elen;
  629. pos += elen;
  630. }
  631. return crc;
  632. }
  633. void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
  634. {
  635. struct ieee80211_local *local = sdata->local;
  636. struct ieee80211_tx_queue_params qparam;
  637. int queue;
  638. bool use_11b;
  639. int aCWmin, aCWmax;
  640. if (!local->ops->conf_tx)
  641. return;
  642. memset(&qparam, 0, sizeof(qparam));
  643. use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) &&
  644. !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
  645. for (queue = 0; queue < local_to_hw(local)->queues; queue++) {
  646. /* Set defaults according to 802.11-2007 Table 7-37 */
  647. aCWmax = 1023;
  648. if (use_11b)
  649. aCWmin = 31;
  650. else
  651. aCWmin = 15;
  652. switch (queue) {
  653. case 3: /* AC_BK */
  654. qparam.cw_max = aCWmax;
  655. qparam.cw_min = aCWmin;
  656. qparam.txop = 0;
  657. qparam.aifs = 7;
  658. break;
  659. default: /* never happens but let's not leave undefined */
  660. case 2: /* AC_BE */
  661. qparam.cw_max = aCWmax;
  662. qparam.cw_min = aCWmin;
  663. qparam.txop = 0;
  664. qparam.aifs = 3;
  665. break;
  666. case 1: /* AC_VI */
  667. qparam.cw_max = aCWmin;
  668. qparam.cw_min = (aCWmin + 1) / 2 - 1;
  669. if (use_11b)
  670. qparam.txop = 6016/32;
  671. else
  672. qparam.txop = 3008/32;
  673. qparam.aifs = 2;
  674. break;
  675. case 0: /* AC_VO */
  676. qparam.cw_max = (aCWmin + 1) / 2 - 1;
  677. qparam.cw_min = (aCWmin + 1) / 4 - 1;
  678. if (use_11b)
  679. qparam.txop = 3264/32;
  680. else
  681. qparam.txop = 1504/32;
  682. qparam.aifs = 2;
  683. break;
  684. }
  685. qparam.uapsd = false;
  686. drv_conf_tx(local, queue, &qparam);
  687. }
  688. /* after reinitialize QoS TX queues setting to default,
  689. * disable QoS at all */
  690. if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
  691. sdata->vif.bss_conf.qos =
  692. sdata->vif.type != NL80211_IFTYPE_STATION;
  693. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  694. }
  695. }
  696. void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
  697. const size_t supp_rates_len,
  698. const u8 *supp_rates)
  699. {
  700. struct ieee80211_local *local = sdata->local;
  701. int i, have_higher_than_11mbit = 0;
  702. /* cf. IEEE 802.11 9.2.12 */
  703. for (i = 0; i < supp_rates_len; i++)
  704. if ((supp_rates[i] & 0x7f) * 5 > 110)
  705. have_higher_than_11mbit = 1;
  706. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  707. have_higher_than_11mbit)
  708. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  709. else
  710. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  711. ieee80211_set_wmm_default(sdata);
  712. }
  713. u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
  714. enum ieee80211_band band)
  715. {
  716. struct ieee80211_supported_band *sband;
  717. struct ieee80211_rate *bitrates;
  718. u32 mandatory_rates;
  719. enum ieee80211_rate_flags mandatory_flag;
  720. int i;
  721. sband = local->hw.wiphy->bands[band];
  722. if (!sband) {
  723. WARN_ON(1);
  724. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  725. }
  726. if (band == IEEE80211_BAND_2GHZ)
  727. mandatory_flag = IEEE80211_RATE_MANDATORY_B;
  728. else
  729. mandatory_flag = IEEE80211_RATE_MANDATORY_A;
  730. bitrates = sband->bitrates;
  731. mandatory_rates = 0;
  732. for (i = 0; i < sband->n_bitrates; i++)
  733. if (bitrates[i].flags & mandatory_flag)
  734. mandatory_rates |= BIT(i);
  735. return mandatory_rates;
  736. }
  737. void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  738. u16 transaction, u16 auth_alg,
  739. u8 *extra, size_t extra_len, const u8 *bssid,
  740. const u8 *key, u8 key_len, u8 key_idx)
  741. {
  742. struct ieee80211_local *local = sdata->local;
  743. struct sk_buff *skb;
  744. struct ieee80211_mgmt *mgmt;
  745. int err;
  746. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  747. sizeof(*mgmt) + 6 + extra_len);
  748. if (!skb) {
  749. printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
  750. "frame\n", sdata->name);
  751. return;
  752. }
  753. skb_reserve(skb, local->hw.extra_tx_headroom);
  754. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
  755. memset(mgmt, 0, 24 + 6);
  756. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  757. IEEE80211_STYPE_AUTH);
  758. memcpy(mgmt->da, bssid, ETH_ALEN);
  759. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  760. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  761. mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
  762. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  763. mgmt->u.auth.status_code = cpu_to_le16(0);
  764. if (extra)
  765. memcpy(skb_put(skb, extra_len), extra, extra_len);
  766. if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
  767. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  768. err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
  769. WARN_ON(err);
  770. }
  771. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  772. ieee80211_tx_skb(sdata, skb);
  773. }
  774. int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
  775. const u8 *ie, size_t ie_len,
  776. enum ieee80211_band band, u32 rate_mask,
  777. u8 channel)
  778. {
  779. struct ieee80211_supported_band *sband;
  780. u8 *pos;
  781. size_t offset = 0, noffset;
  782. int supp_rates_len, i;
  783. u8 rates[32];
  784. int num_rates;
  785. int ext_rates_len;
  786. sband = local->hw.wiphy->bands[band];
  787. pos = buffer;
  788. num_rates = 0;
  789. for (i = 0; i < sband->n_bitrates; i++) {
  790. if ((BIT(i) & rate_mask) == 0)
  791. continue; /* skip rate */
  792. rates[num_rates++] = (u8) (sband->bitrates[i].bitrate / 5);
  793. }
  794. supp_rates_len = min_t(int, num_rates, 8);
  795. *pos++ = WLAN_EID_SUPP_RATES;
  796. *pos++ = supp_rates_len;
  797. memcpy(pos, rates, supp_rates_len);
  798. pos += supp_rates_len;
  799. /* insert "request information" if in custom IEs */
  800. if (ie && ie_len) {
  801. static const u8 before_extrates[] = {
  802. WLAN_EID_SSID,
  803. WLAN_EID_SUPP_RATES,
  804. WLAN_EID_REQUEST,
  805. };
  806. noffset = ieee80211_ie_split(ie, ie_len,
  807. before_extrates,
  808. ARRAY_SIZE(before_extrates),
  809. offset);
  810. memcpy(pos, ie + offset, noffset - offset);
  811. pos += noffset - offset;
  812. offset = noffset;
  813. }
  814. ext_rates_len = num_rates - supp_rates_len;
  815. if (ext_rates_len > 0) {
  816. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  817. *pos++ = ext_rates_len;
  818. memcpy(pos, rates + supp_rates_len, ext_rates_len);
  819. pos += ext_rates_len;
  820. }
  821. if (channel && sband->band == IEEE80211_BAND_2GHZ) {
  822. *pos++ = WLAN_EID_DS_PARAMS;
  823. *pos++ = 1;
  824. *pos++ = channel;
  825. }
  826. /* insert custom IEs that go before HT */
  827. if (ie && ie_len) {
  828. static const u8 before_ht[] = {
  829. WLAN_EID_SSID,
  830. WLAN_EID_SUPP_RATES,
  831. WLAN_EID_REQUEST,
  832. WLAN_EID_EXT_SUPP_RATES,
  833. WLAN_EID_DS_PARAMS,
  834. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  835. };
  836. noffset = ieee80211_ie_split(ie, ie_len,
  837. before_ht, ARRAY_SIZE(before_ht),
  838. offset);
  839. memcpy(pos, ie + offset, noffset - offset);
  840. pos += noffset - offset;
  841. offset = noffset;
  842. }
  843. if (sband->ht_cap.ht_supported) {
  844. u16 cap = sband->ht_cap.cap;
  845. __le16 tmp;
  846. *pos++ = WLAN_EID_HT_CAPABILITY;
  847. *pos++ = sizeof(struct ieee80211_ht_cap);
  848. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  849. tmp = cpu_to_le16(cap);
  850. memcpy(pos, &tmp, sizeof(u16));
  851. pos += sizeof(u16);
  852. *pos++ = sband->ht_cap.ampdu_factor |
  853. (sband->ht_cap.ampdu_density <<
  854. IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
  855. memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
  856. pos += sizeof(sband->ht_cap.mcs);
  857. pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
  858. }
  859. /*
  860. * If adding more here, adjust code in main.c
  861. * that calculates local->scan_ies_len.
  862. */
  863. /* add any remaining custom IEs */
  864. if (ie && ie_len) {
  865. noffset = ie_len;
  866. memcpy(pos, ie + offset, noffset - offset);
  867. pos += noffset - offset;
  868. }
  869. return pos - buffer;
  870. }
  871. struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
  872. u8 *dst,
  873. const u8 *ssid, size_t ssid_len,
  874. const u8 *ie, size_t ie_len)
  875. {
  876. struct ieee80211_local *local = sdata->local;
  877. struct sk_buff *skb;
  878. struct ieee80211_mgmt *mgmt;
  879. size_t buf_len;
  880. u8 *buf;
  881. u8 chan;
  882. /* FIXME: come up with a proper value */
  883. buf = kmalloc(200 + ie_len, GFP_KERNEL);
  884. if (!buf) {
  885. printk(KERN_DEBUG "%s: failed to allocate temporary IE "
  886. "buffer\n", sdata->name);
  887. return NULL;
  888. }
  889. chan = ieee80211_frequency_to_channel(
  890. local->hw.conf.channel->center_freq);
  891. buf_len = ieee80211_build_preq_ies(local, buf, ie, ie_len,
  892. local->hw.conf.channel->band,
  893. sdata->rc_rateidx_mask
  894. [local->hw.conf.channel->band],
  895. chan);
  896. skb = ieee80211_probereq_get(&local->hw, &sdata->vif,
  897. ssid, ssid_len,
  898. buf, buf_len);
  899. if (!skb)
  900. goto out;
  901. if (dst) {
  902. mgmt = (struct ieee80211_mgmt *) skb->data;
  903. memcpy(mgmt->da, dst, ETH_ALEN);
  904. memcpy(mgmt->bssid, dst, ETH_ALEN);
  905. }
  906. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  907. out:
  908. kfree(buf);
  909. return skb;
  910. }
  911. void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
  912. const u8 *ssid, size_t ssid_len,
  913. const u8 *ie, size_t ie_len)
  914. {
  915. struct sk_buff *skb;
  916. skb = ieee80211_build_probe_req(sdata, dst, ssid, ssid_len, ie, ie_len);
  917. if (skb)
  918. ieee80211_tx_skb(sdata, skb);
  919. }
  920. u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
  921. struct ieee802_11_elems *elems,
  922. enum ieee80211_band band)
  923. {
  924. struct ieee80211_supported_band *sband;
  925. struct ieee80211_rate *bitrates;
  926. size_t num_rates;
  927. u32 supp_rates;
  928. int i, j;
  929. sband = local->hw.wiphy->bands[band];
  930. if (!sband) {
  931. WARN_ON(1);
  932. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  933. }
  934. bitrates = sband->bitrates;
  935. num_rates = sband->n_bitrates;
  936. supp_rates = 0;
  937. for (i = 0; i < elems->supp_rates_len +
  938. elems->ext_supp_rates_len; i++) {
  939. u8 rate = 0;
  940. int own_rate;
  941. if (i < elems->supp_rates_len)
  942. rate = elems->supp_rates[i];
  943. else if (elems->ext_supp_rates)
  944. rate = elems->ext_supp_rates
  945. [i - elems->supp_rates_len];
  946. own_rate = 5 * (rate & 0x7f);
  947. for (j = 0; j < num_rates; j++)
  948. if (bitrates[j].bitrate == own_rate)
  949. supp_rates |= BIT(j);
  950. }
  951. return supp_rates;
  952. }
  953. void ieee80211_stop_device(struct ieee80211_local *local)
  954. {
  955. ieee80211_led_radio(local, false);
  956. ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO);
  957. cancel_work_sync(&local->reconfig_filter);
  958. flush_workqueue(local->workqueue);
  959. drv_stop(local);
  960. }
  961. int ieee80211_reconfig(struct ieee80211_local *local)
  962. {
  963. struct ieee80211_hw *hw = &local->hw;
  964. struct ieee80211_sub_if_data *sdata;
  965. struct sta_info *sta;
  966. int res;
  967. #ifdef CONFIG_PM
  968. if (local->suspended)
  969. local->resuming = true;
  970. if (local->wowlan) {
  971. local->wowlan = false;
  972. res = drv_resume(local);
  973. if (res < 0) {
  974. local->resuming = false;
  975. return res;
  976. }
  977. if (res == 0)
  978. goto wake_up;
  979. WARN_ON(res > 1);
  980. /*
  981. * res is 1, which means the driver requested
  982. * to go through a regular reset on wakeup.
  983. */
  984. }
  985. #endif
  986. /* restart hardware */
  987. if (local->open_count) {
  988. /*
  989. * Upon resume hardware can sometimes be goofy due to
  990. * various platform / driver / bus issues, so restarting
  991. * the device may at times not work immediately. Propagate
  992. * the error.
  993. */
  994. res = drv_start(local);
  995. if (res) {
  996. WARN(local->suspended, "Hardware became unavailable "
  997. "upon resume. This could be a software issue "
  998. "prior to suspend or a hardware issue.\n");
  999. return res;
  1000. }
  1001. ieee80211_led_radio(local, true);
  1002. ieee80211_mod_tpt_led_trig(local,
  1003. IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
  1004. }
  1005. /* add interfaces */
  1006. list_for_each_entry(sdata, &local->interfaces, list) {
  1007. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1008. sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1009. ieee80211_sdata_running(sdata))
  1010. res = drv_add_interface(local, &sdata->vif);
  1011. }
  1012. /* add STAs back */
  1013. mutex_lock(&local->sta_mtx);
  1014. list_for_each_entry(sta, &local->sta_list, list) {
  1015. if (sta->uploaded) {
  1016. sdata = sta->sdata;
  1017. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1018. sdata = container_of(sdata->bss,
  1019. struct ieee80211_sub_if_data,
  1020. u.ap);
  1021. WARN_ON(drv_sta_add(local, sdata, &sta->sta));
  1022. }
  1023. }
  1024. mutex_unlock(&local->sta_mtx);
  1025. /* setup fragmentation threshold */
  1026. drv_set_frag_threshold(local, hw->wiphy->frag_threshold);
  1027. /* setup RTS threshold */
  1028. drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
  1029. /* reconfigure hardware */
  1030. ieee80211_hw_config(local, ~0);
  1031. ieee80211_configure_filter(local);
  1032. /* Finally also reconfigure all the BSS information */
  1033. list_for_each_entry(sdata, &local->interfaces, list) {
  1034. u32 changed;
  1035. if (!ieee80211_sdata_running(sdata))
  1036. continue;
  1037. /* common change flags for all interface types */
  1038. changed = BSS_CHANGED_ERP_CTS_PROT |
  1039. BSS_CHANGED_ERP_PREAMBLE |
  1040. BSS_CHANGED_ERP_SLOT |
  1041. BSS_CHANGED_HT |
  1042. BSS_CHANGED_BASIC_RATES |
  1043. BSS_CHANGED_BEACON_INT |
  1044. BSS_CHANGED_BSSID |
  1045. BSS_CHANGED_CQM |
  1046. BSS_CHANGED_QOS;
  1047. switch (sdata->vif.type) {
  1048. case NL80211_IFTYPE_STATION:
  1049. changed |= BSS_CHANGED_ASSOC;
  1050. mutex_lock(&sdata->u.mgd.mtx);
  1051. ieee80211_bss_info_change_notify(sdata, changed);
  1052. mutex_unlock(&sdata->u.mgd.mtx);
  1053. break;
  1054. case NL80211_IFTYPE_ADHOC:
  1055. changed |= BSS_CHANGED_IBSS;
  1056. /* fall through */
  1057. case NL80211_IFTYPE_AP:
  1058. case NL80211_IFTYPE_MESH_POINT:
  1059. changed |= BSS_CHANGED_BEACON |
  1060. BSS_CHANGED_BEACON_ENABLED;
  1061. ieee80211_bss_info_change_notify(sdata, changed);
  1062. break;
  1063. case NL80211_IFTYPE_WDS:
  1064. break;
  1065. case NL80211_IFTYPE_AP_VLAN:
  1066. case NL80211_IFTYPE_MONITOR:
  1067. /* ignore virtual */
  1068. break;
  1069. case NL80211_IFTYPE_UNSPECIFIED:
  1070. case NUM_NL80211_IFTYPES:
  1071. case NL80211_IFTYPE_P2P_CLIENT:
  1072. case NL80211_IFTYPE_P2P_GO:
  1073. WARN_ON(1);
  1074. break;
  1075. }
  1076. }
  1077. /*
  1078. * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
  1079. * sessions can be established after a resume.
  1080. *
  1081. * Also tear down aggregation sessions since reconfiguring
  1082. * them in a hardware restart scenario is not easily done
  1083. * right now, and the hardware will have lost information
  1084. * about the sessions, but we and the AP still think they
  1085. * are active. This is really a workaround though.
  1086. */
  1087. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  1088. mutex_lock(&local->sta_mtx);
  1089. list_for_each_entry(sta, &local->sta_list, list) {
  1090. ieee80211_sta_tear_down_BA_sessions(sta, true);
  1091. clear_sta_flags(sta, WLAN_STA_BLOCK_BA);
  1092. }
  1093. mutex_unlock(&local->sta_mtx);
  1094. }
  1095. /* add back keys */
  1096. list_for_each_entry(sdata, &local->interfaces, list)
  1097. if (ieee80211_sdata_running(sdata))
  1098. ieee80211_enable_keys(sdata);
  1099. wake_up:
  1100. ieee80211_wake_queues_by_reason(hw,
  1101. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  1102. /*
  1103. * If this is for hw restart things are still running.
  1104. * We may want to change that later, however.
  1105. */
  1106. if (!local->suspended)
  1107. return 0;
  1108. #ifdef CONFIG_PM
  1109. /* first set suspended false, then resuming */
  1110. local->suspended = false;
  1111. mb();
  1112. local->resuming = false;
  1113. list_for_each_entry(sdata, &local->interfaces, list) {
  1114. switch(sdata->vif.type) {
  1115. case NL80211_IFTYPE_STATION:
  1116. ieee80211_sta_restart(sdata);
  1117. break;
  1118. case NL80211_IFTYPE_ADHOC:
  1119. ieee80211_ibss_restart(sdata);
  1120. break;
  1121. case NL80211_IFTYPE_MESH_POINT:
  1122. ieee80211_mesh_restart(sdata);
  1123. break;
  1124. default:
  1125. break;
  1126. }
  1127. }
  1128. mod_timer(&local->sta_cleanup, jiffies + 1);
  1129. mutex_lock(&local->sta_mtx);
  1130. list_for_each_entry(sta, &local->sta_list, list)
  1131. mesh_plink_restart(sta);
  1132. mutex_unlock(&local->sta_mtx);
  1133. #else
  1134. WARN_ON(1);
  1135. #endif
  1136. return 0;
  1137. }
  1138. static int check_mgd_smps(struct ieee80211_if_managed *ifmgd,
  1139. enum ieee80211_smps_mode *smps_mode)
  1140. {
  1141. if (ifmgd->associated) {
  1142. *smps_mode = ifmgd->ap_smps;
  1143. if (*smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1144. if (ifmgd->powersave)
  1145. *smps_mode = IEEE80211_SMPS_DYNAMIC;
  1146. else
  1147. *smps_mode = IEEE80211_SMPS_OFF;
  1148. }
  1149. return 1;
  1150. }
  1151. return 0;
  1152. }
  1153. /* must hold iflist_mtx */
  1154. void ieee80211_recalc_smps(struct ieee80211_local *local)
  1155. {
  1156. struct ieee80211_sub_if_data *sdata;
  1157. enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_OFF;
  1158. int count = 0;
  1159. lockdep_assert_held(&local->iflist_mtx);
  1160. /*
  1161. * This function could be improved to handle multiple
  1162. * interfaces better, but right now it makes any
  1163. * non-station interfaces force SM PS to be turned
  1164. * off. If there are multiple station interfaces it
  1165. * could also use the best possible mode, e.g. if
  1166. * one is in static and the other in dynamic then
  1167. * dynamic is ok.
  1168. */
  1169. list_for_each_entry(sdata, &local->interfaces, list) {
  1170. if (!ieee80211_sdata_running(sdata))
  1171. continue;
  1172. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1173. goto set;
  1174. count += check_mgd_smps(&sdata->u.mgd, &smps_mode);
  1175. if (count > 1) {
  1176. smps_mode = IEEE80211_SMPS_OFF;
  1177. break;
  1178. }
  1179. }
  1180. if (smps_mode == local->smps_mode)
  1181. return;
  1182. set:
  1183. local->smps_mode = smps_mode;
  1184. /* changed flag is auto-detected for this */
  1185. ieee80211_hw_config(local, 0);
  1186. }
  1187. static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
  1188. {
  1189. int i;
  1190. for (i = 0; i < n_ids; i++)
  1191. if (ids[i] == id)
  1192. return true;
  1193. return false;
  1194. }
  1195. /**
  1196. * ieee80211_ie_split - split an IE buffer according to ordering
  1197. *
  1198. * @ies: the IE buffer
  1199. * @ielen: the length of the IE buffer
  1200. * @ids: an array with element IDs that are allowed before
  1201. * the split
  1202. * @n_ids: the size of the element ID array
  1203. * @offset: offset where to start splitting in the buffer
  1204. *
  1205. * This function splits an IE buffer by updating the @offset
  1206. * variable to point to the location where the buffer should be
  1207. * split.
  1208. *
  1209. * It assumes that the given IE buffer is well-formed, this
  1210. * has to be guaranteed by the caller!
  1211. *
  1212. * It also assumes that the IEs in the buffer are ordered
  1213. * correctly, if not the result of using this function will not
  1214. * be ordered correctly either, i.e. it does no reordering.
  1215. *
  1216. * The function returns the offset where the next part of the
  1217. * buffer starts, which may be @ielen if the entire (remainder)
  1218. * of the buffer should be used.
  1219. */
  1220. size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
  1221. const u8 *ids, int n_ids, size_t offset)
  1222. {
  1223. size_t pos = offset;
  1224. while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos]))
  1225. pos += 2 + ies[pos + 1];
  1226. return pos;
  1227. }
  1228. size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
  1229. {
  1230. size_t pos = offset;
  1231. while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
  1232. pos += 2 + ies[pos + 1];
  1233. return pos;
  1234. }