util.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * Wireless utility functions
  3. *
  4. * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
  5. */
  6. #include <linux/bitops.h>
  7. #include <linux/etherdevice.h>
  8. #include <net/cfg80211.h>
  9. #include <net/ip.h>
  10. #include "core.h"
  11. struct ieee80211_rate *
  12. ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
  13. u32 basic_rates, int bitrate)
  14. {
  15. struct ieee80211_rate *result = &sband->bitrates[0];
  16. int i;
  17. for (i = 0; i < sband->n_bitrates; i++) {
  18. if (!(basic_rates & BIT(i)))
  19. continue;
  20. if (sband->bitrates[i].bitrate > bitrate)
  21. continue;
  22. result = &sband->bitrates[i];
  23. }
  24. return result;
  25. }
  26. EXPORT_SYMBOL(ieee80211_get_response_rate);
  27. int ieee80211_channel_to_frequency(int chan)
  28. {
  29. if (chan < 14)
  30. return 2407 + chan * 5;
  31. if (chan == 14)
  32. return 2484;
  33. /* FIXME: 802.11j 17.3.8.3.2 */
  34. return (chan + 1000) * 5;
  35. }
  36. EXPORT_SYMBOL(ieee80211_channel_to_frequency);
  37. int ieee80211_frequency_to_channel(int freq)
  38. {
  39. if (freq == 2484)
  40. return 14;
  41. if (freq < 2484)
  42. return (freq - 2407) / 5;
  43. /* FIXME: 802.11j 17.3.8.3.2 */
  44. return freq/5 - 1000;
  45. }
  46. EXPORT_SYMBOL(ieee80211_frequency_to_channel);
  47. struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
  48. int freq)
  49. {
  50. enum ieee80211_band band;
  51. struct ieee80211_supported_band *sband;
  52. int i;
  53. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  54. sband = wiphy->bands[band];
  55. if (!sband)
  56. continue;
  57. for (i = 0; i < sband->n_channels; i++) {
  58. if (sband->channels[i].center_freq == freq)
  59. return &sband->channels[i];
  60. }
  61. }
  62. return NULL;
  63. }
  64. EXPORT_SYMBOL(__ieee80211_get_channel);
  65. static void set_mandatory_flags_band(struct ieee80211_supported_band *sband,
  66. enum ieee80211_band band)
  67. {
  68. int i, want;
  69. switch (band) {
  70. case IEEE80211_BAND_5GHZ:
  71. want = 3;
  72. for (i = 0; i < sband->n_bitrates; i++) {
  73. if (sband->bitrates[i].bitrate == 60 ||
  74. sband->bitrates[i].bitrate == 120 ||
  75. sband->bitrates[i].bitrate == 240) {
  76. sband->bitrates[i].flags |=
  77. IEEE80211_RATE_MANDATORY_A;
  78. want--;
  79. }
  80. }
  81. WARN_ON(want);
  82. break;
  83. case IEEE80211_BAND_2GHZ:
  84. want = 7;
  85. for (i = 0; i < sband->n_bitrates; i++) {
  86. if (sband->bitrates[i].bitrate == 10) {
  87. sband->bitrates[i].flags |=
  88. IEEE80211_RATE_MANDATORY_B |
  89. IEEE80211_RATE_MANDATORY_G;
  90. want--;
  91. }
  92. if (sband->bitrates[i].bitrate == 20 ||
  93. sband->bitrates[i].bitrate == 55 ||
  94. sband->bitrates[i].bitrate == 110 ||
  95. sband->bitrates[i].bitrate == 60 ||
  96. sband->bitrates[i].bitrate == 120 ||
  97. sband->bitrates[i].bitrate == 240) {
  98. sband->bitrates[i].flags |=
  99. IEEE80211_RATE_MANDATORY_G;
  100. want--;
  101. }
  102. if (sband->bitrates[i].bitrate != 10 &&
  103. sband->bitrates[i].bitrate != 20 &&
  104. sband->bitrates[i].bitrate != 55 &&
  105. sband->bitrates[i].bitrate != 110)
  106. sband->bitrates[i].flags |=
  107. IEEE80211_RATE_ERP_G;
  108. }
  109. WARN_ON(want != 0 && want != 3 && want != 6);
  110. break;
  111. case IEEE80211_NUM_BANDS:
  112. WARN_ON(1);
  113. break;
  114. }
  115. }
  116. void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
  117. {
  118. enum ieee80211_band band;
  119. for (band = 0; band < IEEE80211_NUM_BANDS; band++)
  120. if (wiphy->bands[band])
  121. set_mandatory_flags_band(wiphy->bands[band], band);
  122. }
  123. int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
  124. struct key_params *params, int key_idx,
  125. const u8 *mac_addr)
  126. {
  127. int i;
  128. if (key_idx > 5)
  129. return -EINVAL;
  130. /*
  131. * Disallow pairwise keys with non-zero index unless it's WEP
  132. * (because current deployments use pairwise WEP keys with
  133. * non-zero indizes but 802.11i clearly specifies to use zero)
  134. */
  135. if (mac_addr && key_idx &&
  136. params->cipher != WLAN_CIPHER_SUITE_WEP40 &&
  137. params->cipher != WLAN_CIPHER_SUITE_WEP104)
  138. return -EINVAL;
  139. switch (params->cipher) {
  140. case WLAN_CIPHER_SUITE_WEP40:
  141. if (params->key_len != WLAN_KEY_LEN_WEP40)
  142. return -EINVAL;
  143. break;
  144. case WLAN_CIPHER_SUITE_TKIP:
  145. if (params->key_len != WLAN_KEY_LEN_TKIP)
  146. return -EINVAL;
  147. break;
  148. case WLAN_CIPHER_SUITE_CCMP:
  149. if (params->key_len != WLAN_KEY_LEN_CCMP)
  150. return -EINVAL;
  151. break;
  152. case WLAN_CIPHER_SUITE_WEP104:
  153. if (params->key_len != WLAN_KEY_LEN_WEP104)
  154. return -EINVAL;
  155. break;
  156. case WLAN_CIPHER_SUITE_AES_CMAC:
  157. if (params->key_len != WLAN_KEY_LEN_AES_CMAC)
  158. return -EINVAL;
  159. break;
  160. default:
  161. return -EINVAL;
  162. }
  163. if (params->seq) {
  164. switch (params->cipher) {
  165. case WLAN_CIPHER_SUITE_WEP40:
  166. case WLAN_CIPHER_SUITE_WEP104:
  167. /* These ciphers do not use key sequence */
  168. return -EINVAL;
  169. case WLAN_CIPHER_SUITE_TKIP:
  170. case WLAN_CIPHER_SUITE_CCMP:
  171. case WLAN_CIPHER_SUITE_AES_CMAC:
  172. if (params->seq_len != 6)
  173. return -EINVAL;
  174. break;
  175. }
  176. }
  177. for (i = 0; i < rdev->wiphy.n_cipher_suites; i++)
  178. if (params->cipher == rdev->wiphy.cipher_suites[i])
  179. break;
  180. if (i == rdev->wiphy.n_cipher_suites)
  181. return -EINVAL;
  182. return 0;
  183. }
  184. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  185. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  186. const unsigned char rfc1042_header[] __aligned(2) =
  187. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  188. EXPORT_SYMBOL(rfc1042_header);
  189. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  190. const unsigned char bridge_tunnel_header[] __aligned(2) =
  191. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  192. EXPORT_SYMBOL(bridge_tunnel_header);
  193. unsigned int ieee80211_hdrlen(__le16 fc)
  194. {
  195. unsigned int hdrlen = 24;
  196. if (ieee80211_is_data(fc)) {
  197. if (ieee80211_has_a4(fc))
  198. hdrlen = 30;
  199. if (ieee80211_is_data_qos(fc))
  200. hdrlen += IEEE80211_QOS_CTL_LEN;
  201. goto out;
  202. }
  203. if (ieee80211_is_ctl(fc)) {
  204. /*
  205. * ACK and CTS are 10 bytes, all others 16. To see how
  206. * to get this condition consider
  207. * subtype mask: 0b0000000011110000 (0x00F0)
  208. * ACK subtype: 0b0000000011010000 (0x00D0)
  209. * CTS subtype: 0b0000000011000000 (0x00C0)
  210. * bits that matter: ^^^ (0x00E0)
  211. * value of those: 0b0000000011000000 (0x00C0)
  212. */
  213. if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
  214. hdrlen = 10;
  215. else
  216. hdrlen = 16;
  217. }
  218. out:
  219. return hdrlen;
  220. }
  221. EXPORT_SYMBOL(ieee80211_hdrlen);
  222. unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
  223. {
  224. const struct ieee80211_hdr *hdr =
  225. (const struct ieee80211_hdr *)skb->data;
  226. unsigned int hdrlen;
  227. if (unlikely(skb->len < 10))
  228. return 0;
  229. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  230. if (unlikely(hdrlen > skb->len))
  231. return 0;
  232. return hdrlen;
  233. }
  234. EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
  235. static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
  236. {
  237. int ae = meshhdr->flags & MESH_FLAGS_AE;
  238. /* 7.1.3.5a.2 */
  239. switch (ae) {
  240. case 0:
  241. return 6;
  242. case MESH_FLAGS_AE_A4:
  243. return 12;
  244. case MESH_FLAGS_AE_A5_A6:
  245. return 18;
  246. case (MESH_FLAGS_AE_A4 | MESH_FLAGS_AE_A5_A6):
  247. return 24;
  248. default:
  249. return 6;
  250. }
  251. }
  252. int ieee80211_data_to_8023(struct sk_buff *skb, u8 *addr,
  253. enum nl80211_iftype iftype)
  254. {
  255. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  256. u16 hdrlen, ethertype;
  257. u8 *payload;
  258. u8 dst[ETH_ALEN];
  259. u8 src[ETH_ALEN] __aligned(2);
  260. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  261. return -1;
  262. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  263. /* convert IEEE 802.11 header + possible LLC headers into Ethernet
  264. * header
  265. * IEEE 802.11 address fields:
  266. * ToDS FromDS Addr1 Addr2 Addr3 Addr4
  267. * 0 0 DA SA BSSID n/a
  268. * 0 1 DA BSSID SA n/a
  269. * 1 0 BSSID SA DA n/a
  270. * 1 1 RA TA DA SA
  271. */
  272. memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
  273. memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
  274. switch (hdr->frame_control &
  275. cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
  276. case cpu_to_le16(IEEE80211_FCTL_TODS):
  277. if (unlikely(iftype != NL80211_IFTYPE_AP &&
  278. iftype != NL80211_IFTYPE_AP_VLAN))
  279. return -1;
  280. break;
  281. case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
  282. if (unlikely(iftype != NL80211_IFTYPE_WDS &&
  283. iftype != NL80211_IFTYPE_MESH_POINT))
  284. return -1;
  285. if (iftype == NL80211_IFTYPE_MESH_POINT) {
  286. struct ieee80211s_hdr *meshdr =
  287. (struct ieee80211s_hdr *) (skb->data + hdrlen);
  288. hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
  289. if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
  290. memcpy(dst, meshdr->eaddr1, ETH_ALEN);
  291. memcpy(src, meshdr->eaddr2, ETH_ALEN);
  292. }
  293. }
  294. break;
  295. case cpu_to_le16(IEEE80211_FCTL_FROMDS):
  296. if ((iftype != NL80211_IFTYPE_STATION &&
  297. iftype != NL80211_IFTYPE_MESH_POINT) ||
  298. (is_multicast_ether_addr(dst) &&
  299. !compare_ether_addr(src, addr)))
  300. return -1;
  301. if (iftype == NL80211_IFTYPE_MESH_POINT) {
  302. struct ieee80211s_hdr *meshdr =
  303. (struct ieee80211s_hdr *) (skb->data + hdrlen);
  304. hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
  305. if (meshdr->flags & MESH_FLAGS_AE_A4)
  306. memcpy(src, meshdr->eaddr1, ETH_ALEN);
  307. }
  308. break;
  309. case cpu_to_le16(0):
  310. if (iftype != NL80211_IFTYPE_ADHOC)
  311. return -1;
  312. break;
  313. }
  314. if (unlikely(skb->len - hdrlen < 8))
  315. return -1;
  316. payload = skb->data + hdrlen;
  317. ethertype = (payload[6] << 8) | payload[7];
  318. if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
  319. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  320. compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
  321. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  322. * replace EtherType */
  323. skb_pull(skb, hdrlen + 6);
  324. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  325. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  326. } else {
  327. struct ethhdr *ehdr;
  328. __be16 len;
  329. skb_pull(skb, hdrlen);
  330. len = htons(skb->len);
  331. ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
  332. memcpy(ehdr->h_dest, dst, ETH_ALEN);
  333. memcpy(ehdr->h_source, src, ETH_ALEN);
  334. ehdr->h_proto = len;
  335. }
  336. return 0;
  337. }
  338. EXPORT_SYMBOL(ieee80211_data_to_8023);
  339. int ieee80211_data_from_8023(struct sk_buff *skb, u8 *addr,
  340. enum nl80211_iftype iftype, u8 *bssid, bool qos)
  341. {
  342. struct ieee80211_hdr hdr;
  343. u16 hdrlen, ethertype;
  344. __le16 fc;
  345. const u8 *encaps_data;
  346. int encaps_len, skip_header_bytes;
  347. int nh_pos, h_pos;
  348. int head_need;
  349. if (unlikely(skb->len < ETH_HLEN))
  350. return -EINVAL;
  351. nh_pos = skb_network_header(skb) - skb->data;
  352. h_pos = skb_transport_header(skb) - skb->data;
  353. /* convert Ethernet header to proper 802.11 header (based on
  354. * operation mode) */
  355. ethertype = (skb->data[12] << 8) | skb->data[13];
  356. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  357. switch (iftype) {
  358. case NL80211_IFTYPE_AP:
  359. case NL80211_IFTYPE_AP_VLAN:
  360. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  361. /* DA BSSID SA */
  362. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  363. memcpy(hdr.addr2, addr, ETH_ALEN);
  364. memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
  365. hdrlen = 24;
  366. break;
  367. case NL80211_IFTYPE_STATION:
  368. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  369. /* BSSID SA DA */
  370. memcpy(hdr.addr1, bssid, ETH_ALEN);
  371. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  372. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  373. hdrlen = 24;
  374. break;
  375. case NL80211_IFTYPE_ADHOC:
  376. /* DA SA BSSID */
  377. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  378. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  379. memcpy(hdr.addr3, bssid, ETH_ALEN);
  380. hdrlen = 24;
  381. break;
  382. default:
  383. return -EOPNOTSUPP;
  384. }
  385. if (qos) {
  386. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  387. hdrlen += 2;
  388. }
  389. hdr.frame_control = fc;
  390. hdr.duration_id = 0;
  391. hdr.seq_ctrl = 0;
  392. skip_header_bytes = ETH_HLEN;
  393. if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
  394. encaps_data = bridge_tunnel_header;
  395. encaps_len = sizeof(bridge_tunnel_header);
  396. skip_header_bytes -= 2;
  397. } else if (ethertype > 0x600) {
  398. encaps_data = rfc1042_header;
  399. encaps_len = sizeof(rfc1042_header);
  400. skip_header_bytes -= 2;
  401. } else {
  402. encaps_data = NULL;
  403. encaps_len = 0;
  404. }
  405. skb_pull(skb, skip_header_bytes);
  406. nh_pos -= skip_header_bytes;
  407. h_pos -= skip_header_bytes;
  408. head_need = hdrlen + encaps_len - skb_headroom(skb);
  409. if (head_need > 0 || skb_cloned(skb)) {
  410. head_need = max(head_need, 0);
  411. if (head_need)
  412. skb_orphan(skb);
  413. if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) {
  414. printk(KERN_ERR "failed to reallocate Tx buffer\n");
  415. return -ENOMEM;
  416. }
  417. skb->truesize += head_need;
  418. }
  419. if (encaps_data) {
  420. memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
  421. nh_pos += encaps_len;
  422. h_pos += encaps_len;
  423. }
  424. memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
  425. nh_pos += hdrlen;
  426. h_pos += hdrlen;
  427. /* Update skb pointers to various headers since this modified frame
  428. * is going to go through Linux networking code that may potentially
  429. * need things like pointer to IP header. */
  430. skb_set_mac_header(skb, 0);
  431. skb_set_network_header(skb, nh_pos);
  432. skb_set_transport_header(skb, h_pos);
  433. return 0;
  434. }
  435. EXPORT_SYMBOL(ieee80211_data_from_8023);
  436. /* Given a data frame determine the 802.1p/1d tag to use. */
  437. unsigned int cfg80211_classify8021d(struct sk_buff *skb)
  438. {
  439. unsigned int dscp;
  440. /* skb->priority values from 256->263 are magic values to
  441. * directly indicate a specific 802.1d priority. This is used
  442. * to allow 802.1d priority to be passed directly in from VLAN
  443. * tags, etc.
  444. */
  445. if (skb->priority >= 256 && skb->priority <= 263)
  446. return skb->priority - 256;
  447. switch (skb->protocol) {
  448. case htons(ETH_P_IP):
  449. dscp = ip_hdr(skb)->tos & 0xfc;
  450. break;
  451. default:
  452. return 0;
  453. }
  454. return dscp >> 5;
  455. }
  456. EXPORT_SYMBOL(cfg80211_classify8021d);
  457. const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
  458. {
  459. u8 *end, *pos;
  460. pos = bss->information_elements;
  461. if (pos == NULL)
  462. return NULL;
  463. end = pos + bss->len_information_elements;
  464. while (pos + 1 < end) {
  465. if (pos + 2 + pos[1] > end)
  466. break;
  467. if (pos[0] == ie)
  468. return pos;
  469. pos += 2 + pos[1];
  470. }
  471. return NULL;
  472. }
  473. EXPORT_SYMBOL(ieee80211_bss_get_ie);
  474. void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
  475. {
  476. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  477. struct net_device *dev = wdev->netdev;
  478. int i;
  479. if (!wdev->connect_keys)
  480. return;
  481. for (i = 0; i < 6; i++) {
  482. if (!wdev->connect_keys->params[i].cipher)
  483. continue;
  484. if (rdev->ops->add_key(wdev->wiphy, dev, i, NULL,
  485. &wdev->connect_keys->params[i])) {
  486. printk(KERN_ERR "%s: failed to set key %d\n",
  487. dev->name, i);
  488. continue;
  489. }
  490. if (wdev->connect_keys->def == i)
  491. if (rdev->ops->set_default_key(wdev->wiphy, dev, i)) {
  492. printk(KERN_ERR "%s: failed to set defkey %d\n",
  493. dev->name, i);
  494. continue;
  495. }
  496. if (wdev->connect_keys->defmgmt == i)
  497. if (rdev->ops->set_default_mgmt_key(wdev->wiphy, dev, i))
  498. printk(KERN_ERR "%s: failed to set mgtdef %d\n",
  499. dev->name, i);
  500. }
  501. kfree(wdev->connect_keys);
  502. wdev->connect_keys = NULL;
  503. }
  504. static void cfg80211_process_wdev_events(struct wireless_dev *wdev)
  505. {
  506. struct cfg80211_event *ev;
  507. unsigned long flags;
  508. const u8 *bssid = NULL;
  509. spin_lock_irqsave(&wdev->event_lock, flags);
  510. while (!list_empty(&wdev->event_list)) {
  511. ev = list_first_entry(&wdev->event_list,
  512. struct cfg80211_event, list);
  513. list_del(&ev->list);
  514. spin_unlock_irqrestore(&wdev->event_lock, flags);
  515. wdev_lock(wdev);
  516. switch (ev->type) {
  517. case EVENT_CONNECT_RESULT:
  518. if (!is_zero_ether_addr(ev->cr.bssid))
  519. bssid = ev->cr.bssid;
  520. __cfg80211_connect_result(
  521. wdev->netdev, bssid,
  522. ev->cr.req_ie, ev->cr.req_ie_len,
  523. ev->cr.resp_ie, ev->cr.resp_ie_len,
  524. ev->cr.status,
  525. ev->cr.status == WLAN_STATUS_SUCCESS,
  526. NULL);
  527. break;
  528. case EVENT_ROAMED:
  529. __cfg80211_roamed(wdev, ev->rm.bssid,
  530. ev->rm.req_ie, ev->rm.req_ie_len,
  531. ev->rm.resp_ie, ev->rm.resp_ie_len);
  532. break;
  533. case EVENT_DISCONNECTED:
  534. __cfg80211_disconnected(wdev->netdev,
  535. ev->dc.ie, ev->dc.ie_len,
  536. ev->dc.reason, true);
  537. break;
  538. case EVENT_IBSS_JOINED:
  539. __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
  540. break;
  541. }
  542. wdev_unlock(wdev);
  543. kfree(ev);
  544. spin_lock_irqsave(&wdev->event_lock, flags);
  545. }
  546. spin_unlock_irqrestore(&wdev->event_lock, flags);
  547. }
  548. void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
  549. {
  550. struct wireless_dev *wdev;
  551. ASSERT_RTNL();
  552. ASSERT_RDEV_LOCK(rdev);
  553. mutex_lock(&rdev->devlist_mtx);
  554. list_for_each_entry(wdev, &rdev->netdev_list, list)
  555. cfg80211_process_wdev_events(wdev);
  556. mutex_unlock(&rdev->devlist_mtx);
  557. }
  558. int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
  559. struct net_device *dev, enum nl80211_iftype ntype,
  560. u32 *flags, struct vif_params *params)
  561. {
  562. int err;
  563. enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
  564. ASSERT_RDEV_LOCK(rdev);
  565. /* don't support changing VLANs, you just re-create them */
  566. if (otype == NL80211_IFTYPE_AP_VLAN)
  567. return -EOPNOTSUPP;
  568. if (!rdev->ops->change_virtual_intf ||
  569. !(rdev->wiphy.interface_modes & (1 << ntype)))
  570. return -EOPNOTSUPP;
  571. if (ntype != otype) {
  572. switch (otype) {
  573. case NL80211_IFTYPE_ADHOC:
  574. cfg80211_leave_ibss(rdev, dev, false);
  575. break;
  576. case NL80211_IFTYPE_STATION:
  577. cfg80211_disconnect(rdev, dev,
  578. WLAN_REASON_DEAUTH_LEAVING, true);
  579. break;
  580. case NL80211_IFTYPE_MESH_POINT:
  581. /* mesh should be handled? */
  582. break;
  583. default:
  584. break;
  585. }
  586. cfg80211_process_rdev_events(rdev);
  587. }
  588. err = rdev->ops->change_virtual_intf(&rdev->wiphy, dev,
  589. ntype, flags, params);
  590. WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
  591. return err;
  592. }