util.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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/wireless.h>
  21. #include <linux/bitmap.h>
  22. #include <net/net_namespace.h>
  23. #include <net/cfg80211.h>
  24. #include <net/rtnetlink.h>
  25. #include "ieee80211_i.h"
  26. #include "rate.h"
  27. #include "mesh.h"
  28. #include "wme.h"
  29. /* privid for wiphys to determine whether they belong to us or not */
  30. void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
  31. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  32. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  33. const unsigned char rfc1042_header[] __aligned(2) =
  34. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  35. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  36. const unsigned char bridge_tunnel_header[] __aligned(2) =
  37. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  38. u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
  39. enum nl80211_iftype type)
  40. {
  41. __le16 fc = hdr->frame_control;
  42. /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
  43. if (len < 16)
  44. return NULL;
  45. if (ieee80211_is_data(fc)) {
  46. if (len < 24) /* drop incorrect hdr len (data) */
  47. return NULL;
  48. if (ieee80211_has_a4(fc))
  49. return NULL;
  50. if (ieee80211_has_tods(fc))
  51. return hdr->addr1;
  52. if (ieee80211_has_fromds(fc))
  53. return hdr->addr2;
  54. return hdr->addr3;
  55. }
  56. if (ieee80211_is_mgmt(fc)) {
  57. if (len < 24) /* drop incorrect hdr len (mgmt) */
  58. return NULL;
  59. return hdr->addr3;
  60. }
  61. if (ieee80211_is_ctl(fc)) {
  62. if(ieee80211_is_pspoll(fc))
  63. return hdr->addr1;
  64. if (ieee80211_is_back_req(fc)) {
  65. switch (type) {
  66. case NL80211_IFTYPE_STATION:
  67. return hdr->addr2;
  68. case NL80211_IFTYPE_AP:
  69. case NL80211_IFTYPE_AP_VLAN:
  70. return hdr->addr1;
  71. default:
  72. break; /* fall through to the return */
  73. }
  74. }
  75. }
  76. return NULL;
  77. }
  78. unsigned int ieee80211_hdrlen(__le16 fc)
  79. {
  80. unsigned int hdrlen = 24;
  81. if (ieee80211_is_data(fc)) {
  82. if (ieee80211_has_a4(fc))
  83. hdrlen = 30;
  84. if (ieee80211_is_data_qos(fc))
  85. hdrlen += IEEE80211_QOS_CTL_LEN;
  86. goto out;
  87. }
  88. if (ieee80211_is_ctl(fc)) {
  89. /*
  90. * ACK and CTS are 10 bytes, all others 16. To see how
  91. * to get this condition consider
  92. * subtype mask: 0b0000000011110000 (0x00F0)
  93. * ACK subtype: 0b0000000011010000 (0x00D0)
  94. * CTS subtype: 0b0000000011000000 (0x00C0)
  95. * bits that matter: ^^^ (0x00E0)
  96. * value of those: 0b0000000011000000 (0x00C0)
  97. */
  98. if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
  99. hdrlen = 10;
  100. else
  101. hdrlen = 16;
  102. }
  103. out:
  104. return hdrlen;
  105. }
  106. EXPORT_SYMBOL(ieee80211_hdrlen);
  107. unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
  108. {
  109. const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data;
  110. unsigned int hdrlen;
  111. if (unlikely(skb->len < 10))
  112. return 0;
  113. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  114. if (unlikely(hdrlen > skb->len))
  115. return 0;
  116. return hdrlen;
  117. }
  118. EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
  119. int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
  120. {
  121. int ae = meshhdr->flags & IEEE80211S_FLAGS_AE;
  122. /* 7.1.3.5a.2 */
  123. switch (ae) {
  124. case 0:
  125. return 6;
  126. case 1:
  127. return 12;
  128. case 2:
  129. return 18;
  130. case 3:
  131. return 24;
  132. default:
  133. return 6;
  134. }
  135. }
  136. void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
  137. {
  138. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
  139. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  140. if (tx->extra_frag) {
  141. struct ieee80211_hdr *fhdr;
  142. int i;
  143. for (i = 0; i < tx->num_extra_frag; i++) {
  144. fhdr = (struct ieee80211_hdr *)
  145. tx->extra_frag[i]->data;
  146. fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  147. }
  148. }
  149. }
  150. int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
  151. int rate, int erp, int short_preamble)
  152. {
  153. int dur;
  154. /* calculate duration (in microseconds, rounded up to next higher
  155. * integer if it includes a fractional microsecond) to send frame of
  156. * len bytes (does not include FCS) at the given rate. Duration will
  157. * also include SIFS.
  158. *
  159. * rate is in 100 kbps, so divident is multiplied by 10 in the
  160. * DIV_ROUND_UP() operations.
  161. */
  162. if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
  163. /*
  164. * OFDM:
  165. *
  166. * N_DBPS = DATARATE x 4
  167. * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
  168. * (16 = SIGNAL time, 6 = tail bits)
  169. * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
  170. *
  171. * T_SYM = 4 usec
  172. * 802.11a - 17.5.2: aSIFSTime = 16 usec
  173. * 802.11g - 19.8.4: aSIFSTime = 10 usec +
  174. * signal ext = 6 usec
  175. */
  176. dur = 16; /* SIFS + signal ext */
  177. dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
  178. dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
  179. dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
  180. 4 * rate); /* T_SYM x N_SYM */
  181. } else {
  182. /*
  183. * 802.11b or 802.11g with 802.11b compatibility:
  184. * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
  185. * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
  186. *
  187. * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
  188. * aSIFSTime = 10 usec
  189. * aPreambleLength = 144 usec or 72 usec with short preamble
  190. * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
  191. */
  192. dur = 10; /* aSIFSTime = 10 usec */
  193. dur += short_preamble ? (72 + 24) : (144 + 48);
  194. dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
  195. }
  196. return dur;
  197. }
  198. /* Exported duration function for driver use */
  199. __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
  200. struct ieee80211_vif *vif,
  201. size_t frame_len,
  202. struct ieee80211_rate *rate)
  203. {
  204. struct ieee80211_local *local = hw_to_local(hw);
  205. struct ieee80211_sub_if_data *sdata;
  206. u16 dur;
  207. int erp;
  208. bool short_preamble = false;
  209. erp = 0;
  210. if (vif) {
  211. sdata = vif_to_sdata(vif);
  212. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  213. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  214. erp = rate->flags & IEEE80211_RATE_ERP_G;
  215. }
  216. dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
  217. short_preamble);
  218. return cpu_to_le16(dur);
  219. }
  220. EXPORT_SYMBOL(ieee80211_generic_frame_duration);
  221. __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
  222. struct ieee80211_vif *vif, size_t frame_len,
  223. const struct ieee80211_tx_info *frame_txctl)
  224. {
  225. struct ieee80211_local *local = hw_to_local(hw);
  226. struct ieee80211_rate *rate;
  227. struct ieee80211_sub_if_data *sdata;
  228. bool short_preamble;
  229. int erp;
  230. u16 dur;
  231. struct ieee80211_supported_band *sband;
  232. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  233. short_preamble = false;
  234. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  235. erp = 0;
  236. if (vif) {
  237. sdata = vif_to_sdata(vif);
  238. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  239. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  240. erp = rate->flags & IEEE80211_RATE_ERP_G;
  241. }
  242. /* CTS duration */
  243. dur = ieee80211_frame_duration(local, 10, rate->bitrate,
  244. erp, short_preamble);
  245. /* Data frame duration */
  246. dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
  247. erp, short_preamble);
  248. /* ACK duration */
  249. dur += ieee80211_frame_duration(local, 10, rate->bitrate,
  250. erp, short_preamble);
  251. return cpu_to_le16(dur);
  252. }
  253. EXPORT_SYMBOL(ieee80211_rts_duration);
  254. __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
  255. struct ieee80211_vif *vif,
  256. size_t frame_len,
  257. const struct ieee80211_tx_info *frame_txctl)
  258. {
  259. struct ieee80211_local *local = hw_to_local(hw);
  260. struct ieee80211_rate *rate;
  261. struct ieee80211_sub_if_data *sdata;
  262. bool short_preamble;
  263. int erp;
  264. u16 dur;
  265. struct ieee80211_supported_band *sband;
  266. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  267. short_preamble = false;
  268. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  269. erp = 0;
  270. if (vif) {
  271. sdata = vif_to_sdata(vif);
  272. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  273. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  274. erp = rate->flags & IEEE80211_RATE_ERP_G;
  275. }
  276. /* Data frame duration */
  277. dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
  278. erp, short_preamble);
  279. if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
  280. /* ACK duration */
  281. dur += ieee80211_frame_duration(local, 10, rate->bitrate,
  282. erp, short_preamble);
  283. }
  284. return cpu_to_le16(dur);
  285. }
  286. EXPORT_SYMBOL(ieee80211_ctstoself_duration);
  287. static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
  288. enum queue_stop_reason reason)
  289. {
  290. struct ieee80211_local *local = hw_to_local(hw);
  291. /* we don't need to track ampdu queues */
  292. if (queue < ieee80211_num_regular_queues(hw)) {
  293. __clear_bit(reason, &local->queue_stop_reasons[queue]);
  294. if (local->queue_stop_reasons[queue] != 0)
  295. /* someone still has this queue stopped */
  296. return;
  297. }
  298. if (test_bit(queue, local->queues_pending)) {
  299. set_bit(queue, local->queues_pending_run);
  300. tasklet_schedule(&local->tx_pending_tasklet);
  301. } else {
  302. netif_wake_subqueue(local->mdev, queue);
  303. }
  304. }
  305. void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
  306. enum queue_stop_reason reason)
  307. {
  308. struct ieee80211_local *local = hw_to_local(hw);
  309. unsigned long flags;
  310. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  311. __ieee80211_wake_queue(hw, queue, reason);
  312. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  313. }
  314. void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
  315. {
  316. ieee80211_wake_queue_by_reason(hw, queue,
  317. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  318. }
  319. EXPORT_SYMBOL(ieee80211_wake_queue);
  320. static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
  321. enum queue_stop_reason reason)
  322. {
  323. struct ieee80211_local *local = hw_to_local(hw);
  324. /* we don't need to track ampdu queues */
  325. if (queue < ieee80211_num_regular_queues(hw))
  326. __set_bit(reason, &local->queue_stop_reasons[queue]);
  327. netif_stop_subqueue(local->mdev, queue);
  328. }
  329. void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
  330. enum queue_stop_reason reason)
  331. {
  332. struct ieee80211_local *local = hw_to_local(hw);
  333. unsigned long flags;
  334. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  335. __ieee80211_stop_queue(hw, queue, reason);
  336. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  337. }
  338. void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
  339. {
  340. ieee80211_stop_queue_by_reason(hw, queue,
  341. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  342. }
  343. EXPORT_SYMBOL(ieee80211_stop_queue);
  344. void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
  345. enum queue_stop_reason reason)
  346. {
  347. struct ieee80211_local *local = hw_to_local(hw);
  348. unsigned long flags;
  349. int i;
  350. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  351. for (i = 0; i < ieee80211_num_queues(hw); i++)
  352. __ieee80211_stop_queue(hw, i, reason);
  353. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  354. }
  355. void ieee80211_stop_queues(struct ieee80211_hw *hw)
  356. {
  357. ieee80211_stop_queues_by_reason(hw,
  358. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  359. }
  360. EXPORT_SYMBOL(ieee80211_stop_queues);
  361. int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
  362. {
  363. struct ieee80211_local *local = hw_to_local(hw);
  364. return __netif_subqueue_stopped(local->mdev, queue);
  365. }
  366. EXPORT_SYMBOL(ieee80211_queue_stopped);
  367. void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
  368. enum queue_stop_reason reason)
  369. {
  370. struct ieee80211_local *local = hw_to_local(hw);
  371. unsigned long flags;
  372. int i;
  373. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  374. for (i = 0; i < hw->queues + hw->ampdu_queues; i++)
  375. __ieee80211_wake_queue(hw, i, reason);
  376. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  377. }
  378. void ieee80211_wake_queues(struct ieee80211_hw *hw)
  379. {
  380. ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
  381. }
  382. EXPORT_SYMBOL(ieee80211_wake_queues);
  383. void ieee80211_iterate_active_interfaces(
  384. struct ieee80211_hw *hw,
  385. void (*iterator)(void *data, u8 *mac,
  386. struct ieee80211_vif *vif),
  387. void *data)
  388. {
  389. struct ieee80211_local *local = hw_to_local(hw);
  390. struct ieee80211_sub_if_data *sdata;
  391. rtnl_lock();
  392. list_for_each_entry(sdata, &local->interfaces, list) {
  393. switch (sdata->vif.type) {
  394. case __NL80211_IFTYPE_AFTER_LAST:
  395. case NL80211_IFTYPE_UNSPECIFIED:
  396. case NL80211_IFTYPE_MONITOR:
  397. case NL80211_IFTYPE_AP_VLAN:
  398. continue;
  399. case NL80211_IFTYPE_AP:
  400. case NL80211_IFTYPE_STATION:
  401. case NL80211_IFTYPE_ADHOC:
  402. case NL80211_IFTYPE_WDS:
  403. case NL80211_IFTYPE_MESH_POINT:
  404. break;
  405. }
  406. if (netif_running(sdata->dev))
  407. iterator(data, sdata->dev->dev_addr,
  408. &sdata->vif);
  409. }
  410. rtnl_unlock();
  411. }
  412. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
  413. void ieee80211_iterate_active_interfaces_atomic(
  414. struct ieee80211_hw *hw,
  415. void (*iterator)(void *data, u8 *mac,
  416. struct ieee80211_vif *vif),
  417. void *data)
  418. {
  419. struct ieee80211_local *local = hw_to_local(hw);
  420. struct ieee80211_sub_if_data *sdata;
  421. rcu_read_lock();
  422. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  423. switch (sdata->vif.type) {
  424. case __NL80211_IFTYPE_AFTER_LAST:
  425. case NL80211_IFTYPE_UNSPECIFIED:
  426. case NL80211_IFTYPE_MONITOR:
  427. case NL80211_IFTYPE_AP_VLAN:
  428. continue;
  429. case NL80211_IFTYPE_AP:
  430. case NL80211_IFTYPE_STATION:
  431. case NL80211_IFTYPE_ADHOC:
  432. case NL80211_IFTYPE_WDS:
  433. case NL80211_IFTYPE_MESH_POINT:
  434. break;
  435. }
  436. if (netif_running(sdata->dev))
  437. iterator(data, sdata->dev->dev_addr,
  438. &sdata->vif);
  439. }
  440. rcu_read_unlock();
  441. }
  442. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
  443. void ieee802_11_parse_elems(u8 *start, size_t len,
  444. struct ieee802_11_elems *elems)
  445. {
  446. size_t left = len;
  447. u8 *pos = start;
  448. memset(elems, 0, sizeof(*elems));
  449. elems->ie_start = start;
  450. elems->total_len = len;
  451. while (left >= 2) {
  452. u8 id, elen;
  453. id = *pos++;
  454. elen = *pos++;
  455. left -= 2;
  456. if (elen > left)
  457. return;
  458. switch (id) {
  459. case WLAN_EID_SSID:
  460. elems->ssid = pos;
  461. elems->ssid_len = elen;
  462. break;
  463. case WLAN_EID_SUPP_RATES:
  464. elems->supp_rates = pos;
  465. elems->supp_rates_len = elen;
  466. break;
  467. case WLAN_EID_FH_PARAMS:
  468. elems->fh_params = pos;
  469. elems->fh_params_len = elen;
  470. break;
  471. case WLAN_EID_DS_PARAMS:
  472. elems->ds_params = pos;
  473. elems->ds_params_len = elen;
  474. break;
  475. case WLAN_EID_CF_PARAMS:
  476. elems->cf_params = pos;
  477. elems->cf_params_len = elen;
  478. break;
  479. case WLAN_EID_TIM:
  480. elems->tim = pos;
  481. elems->tim_len = elen;
  482. break;
  483. case WLAN_EID_IBSS_PARAMS:
  484. elems->ibss_params = pos;
  485. elems->ibss_params_len = elen;
  486. break;
  487. case WLAN_EID_CHALLENGE:
  488. elems->challenge = pos;
  489. elems->challenge_len = elen;
  490. break;
  491. case WLAN_EID_WPA:
  492. if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
  493. pos[2] == 0xf2) {
  494. /* Microsoft OUI (00:50:F2) */
  495. if (pos[3] == 1) {
  496. /* OUI Type 1 - WPA IE */
  497. elems->wpa = pos;
  498. elems->wpa_len = elen;
  499. } else if (elen >= 5 && pos[3] == 2) {
  500. if (pos[4] == 0) {
  501. elems->wmm_info = pos;
  502. elems->wmm_info_len = elen;
  503. } else if (pos[4] == 1) {
  504. elems->wmm_param = pos;
  505. elems->wmm_param_len = elen;
  506. }
  507. }
  508. }
  509. break;
  510. case WLAN_EID_RSN:
  511. elems->rsn = pos;
  512. elems->rsn_len = elen;
  513. break;
  514. case WLAN_EID_ERP_INFO:
  515. elems->erp_info = pos;
  516. elems->erp_info_len = elen;
  517. break;
  518. case WLAN_EID_EXT_SUPP_RATES:
  519. elems->ext_supp_rates = pos;
  520. elems->ext_supp_rates_len = elen;
  521. break;
  522. case WLAN_EID_HT_CAPABILITY:
  523. if (elen >= sizeof(struct ieee80211_ht_cap))
  524. elems->ht_cap_elem = (void *)pos;
  525. break;
  526. case WLAN_EID_HT_INFORMATION:
  527. if (elen >= sizeof(struct ieee80211_ht_info))
  528. elems->ht_info_elem = (void *)pos;
  529. break;
  530. case WLAN_EID_MESH_ID:
  531. elems->mesh_id = pos;
  532. elems->mesh_id_len = elen;
  533. break;
  534. case WLAN_EID_MESH_CONFIG:
  535. elems->mesh_config = pos;
  536. elems->mesh_config_len = elen;
  537. break;
  538. case WLAN_EID_PEER_LINK:
  539. elems->peer_link = pos;
  540. elems->peer_link_len = elen;
  541. break;
  542. case WLAN_EID_PREQ:
  543. elems->preq = pos;
  544. elems->preq_len = elen;
  545. break;
  546. case WLAN_EID_PREP:
  547. elems->prep = pos;
  548. elems->prep_len = elen;
  549. break;
  550. case WLAN_EID_PERR:
  551. elems->perr = pos;
  552. elems->perr_len = elen;
  553. break;
  554. case WLAN_EID_CHANNEL_SWITCH:
  555. elems->ch_switch_elem = pos;
  556. elems->ch_switch_elem_len = elen;
  557. break;
  558. case WLAN_EID_QUIET:
  559. if (!elems->quiet_elem) {
  560. elems->quiet_elem = pos;
  561. elems->quiet_elem_len = elen;
  562. }
  563. elems->num_of_quiet_elem++;
  564. break;
  565. case WLAN_EID_COUNTRY:
  566. elems->country_elem = pos;
  567. elems->country_elem_len = elen;
  568. break;
  569. case WLAN_EID_PWR_CONSTRAINT:
  570. elems->pwr_constr_elem = pos;
  571. elems->pwr_constr_elem_len = elen;
  572. break;
  573. default:
  574. break;
  575. }
  576. left -= elen;
  577. pos += elen;
  578. }
  579. }
  580. void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
  581. {
  582. struct ieee80211_local *local = sdata->local;
  583. struct ieee80211_tx_queue_params qparam;
  584. int i;
  585. if (!local->ops->conf_tx)
  586. return;
  587. memset(&qparam, 0, sizeof(qparam));
  588. qparam.aifs = 2;
  589. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  590. !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
  591. qparam.cw_min = 31;
  592. else
  593. qparam.cw_min = 15;
  594. qparam.cw_max = 1023;
  595. qparam.txop = 0;
  596. for (i = 0; i < local_to_hw(local)->queues; i++)
  597. local->ops->conf_tx(local_to_hw(local), i, &qparam);
  598. }
  599. void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  600. int encrypt)
  601. {
  602. skb->dev = sdata->local->mdev;
  603. skb_set_mac_header(skb, 0);
  604. skb_set_network_header(skb, 0);
  605. skb_set_transport_header(skb, 0);
  606. skb->iif = sdata->dev->ifindex;
  607. skb->do_not_encrypt = !encrypt;
  608. dev_queue_xmit(skb);
  609. }
  610. int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
  611. {
  612. int ret = -EINVAL;
  613. struct ieee80211_channel *chan;
  614. struct ieee80211_local *local = sdata->local;
  615. chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
  616. if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
  617. if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
  618. chan->flags & IEEE80211_CHAN_NO_IBSS)
  619. return ret;
  620. local->oper_channel = chan;
  621. local->oper_channel_type = NL80211_CHAN_NO_HT;
  622. if (local->sw_scanning || local->hw_scanning)
  623. ret = 0;
  624. else
  625. ret = ieee80211_hw_config(
  626. local, IEEE80211_CONF_CHANGE_CHANNEL);
  627. }
  628. return ret;
  629. }
  630. u64 ieee80211_mandatory_rates(struct ieee80211_local *local,
  631. enum ieee80211_band band)
  632. {
  633. struct ieee80211_supported_band *sband;
  634. struct ieee80211_rate *bitrates;
  635. u64 mandatory_rates;
  636. enum ieee80211_rate_flags mandatory_flag;
  637. int i;
  638. sband = local->hw.wiphy->bands[band];
  639. if (!sband) {
  640. WARN_ON(1);
  641. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  642. }
  643. if (band == IEEE80211_BAND_2GHZ)
  644. mandatory_flag = IEEE80211_RATE_MANDATORY_B;
  645. else
  646. mandatory_flag = IEEE80211_RATE_MANDATORY_A;
  647. bitrates = sband->bitrates;
  648. mandatory_rates = 0;
  649. for (i = 0; i < sband->n_bitrates; i++)
  650. if (bitrates[i].flags & mandatory_flag)
  651. mandatory_rates |= BIT(i);
  652. return mandatory_rates;
  653. }