util.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. /*
  2. * Wireless utility functions
  3. *
  4. * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. */
  7. #include <linux/export.h>
  8. #include <linux/bitops.h>
  9. #include <linux/etherdevice.h>
  10. #include <linux/slab.h>
  11. #include <net/cfg80211.h>
  12. #include <net/ip.h>
  13. #include <net/dsfield.h>
  14. #include <linux/if_vlan.h>
  15. #include <linux/mpls.h>
  16. #include <linux/gcd.h>
  17. #include "core.h"
  18. #include "rdev-ops.h"
  19. struct ieee80211_rate *
  20. ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
  21. u32 basic_rates, int bitrate)
  22. {
  23. struct ieee80211_rate *result = &sband->bitrates[0];
  24. int i;
  25. for (i = 0; i < sband->n_bitrates; i++) {
  26. if (!(basic_rates & BIT(i)))
  27. continue;
  28. if (sband->bitrates[i].bitrate > bitrate)
  29. continue;
  30. result = &sband->bitrates[i];
  31. }
  32. return result;
  33. }
  34. EXPORT_SYMBOL(ieee80211_get_response_rate);
  35. u32 ieee80211_mandatory_rates(struct ieee80211_supported_band *sband,
  36. enum nl80211_bss_scan_width scan_width)
  37. {
  38. struct ieee80211_rate *bitrates;
  39. u32 mandatory_rates = 0;
  40. enum ieee80211_rate_flags mandatory_flag;
  41. int i;
  42. if (WARN_ON(!sband))
  43. return 1;
  44. if (sband->band == NL80211_BAND_2GHZ) {
  45. if (scan_width == NL80211_BSS_CHAN_WIDTH_5 ||
  46. scan_width == NL80211_BSS_CHAN_WIDTH_10)
  47. mandatory_flag = IEEE80211_RATE_MANDATORY_G;
  48. else
  49. mandatory_flag = IEEE80211_RATE_MANDATORY_B;
  50. } else {
  51. mandatory_flag = IEEE80211_RATE_MANDATORY_A;
  52. }
  53. bitrates = sband->bitrates;
  54. for (i = 0; i < sband->n_bitrates; i++)
  55. if (bitrates[i].flags & mandatory_flag)
  56. mandatory_rates |= BIT(i);
  57. return mandatory_rates;
  58. }
  59. EXPORT_SYMBOL(ieee80211_mandatory_rates);
  60. int ieee80211_channel_to_frequency(int chan, enum nl80211_band band)
  61. {
  62. /* see 802.11 17.3.8.3.2 and Annex J
  63. * there are overlapping channel numbers in 5GHz and 2GHz bands */
  64. if (chan <= 0)
  65. return 0; /* not supported */
  66. switch (band) {
  67. case NL80211_BAND_2GHZ:
  68. if (chan == 14)
  69. return 2484;
  70. else if (chan < 14)
  71. return 2407 + chan * 5;
  72. break;
  73. case NL80211_BAND_5GHZ:
  74. if (chan >= 182 && chan <= 196)
  75. return 4000 + chan * 5;
  76. else
  77. return 5000 + chan * 5;
  78. break;
  79. case NL80211_BAND_60GHZ:
  80. if (chan < 5)
  81. return 56160 + chan * 2160;
  82. break;
  83. default:
  84. ;
  85. }
  86. return 0; /* not supported */
  87. }
  88. EXPORT_SYMBOL(ieee80211_channel_to_frequency);
  89. int ieee80211_frequency_to_channel(int freq)
  90. {
  91. /* see 802.11 17.3.8.3.2 and Annex J */
  92. if (freq == 2484)
  93. return 14;
  94. else if (freq < 2484)
  95. return (freq - 2407) / 5;
  96. else if (freq >= 4910 && freq <= 4980)
  97. return (freq - 4000) / 5;
  98. else if (freq <= 45000) /* DMG band lower limit */
  99. return (freq - 5000) / 5;
  100. else if (freq >= 58320 && freq <= 64800)
  101. return (freq - 56160) / 2160;
  102. else
  103. return 0;
  104. }
  105. EXPORT_SYMBOL(ieee80211_frequency_to_channel);
  106. struct ieee80211_channel *ieee80211_get_channel(struct wiphy *wiphy, int freq)
  107. {
  108. enum nl80211_band band;
  109. struct ieee80211_supported_band *sband;
  110. int i;
  111. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  112. sband = wiphy->bands[band];
  113. if (!sband)
  114. continue;
  115. for (i = 0; i < sband->n_channels; i++) {
  116. if (sband->channels[i].center_freq == freq)
  117. return &sband->channels[i];
  118. }
  119. }
  120. return NULL;
  121. }
  122. EXPORT_SYMBOL(ieee80211_get_channel);
  123. static void set_mandatory_flags_band(struct ieee80211_supported_band *sband)
  124. {
  125. int i, want;
  126. switch (sband->band) {
  127. case NL80211_BAND_5GHZ:
  128. want = 3;
  129. for (i = 0; i < sband->n_bitrates; i++) {
  130. if (sband->bitrates[i].bitrate == 60 ||
  131. sband->bitrates[i].bitrate == 120 ||
  132. sband->bitrates[i].bitrate == 240) {
  133. sband->bitrates[i].flags |=
  134. IEEE80211_RATE_MANDATORY_A;
  135. want--;
  136. }
  137. }
  138. WARN_ON(want);
  139. break;
  140. case NL80211_BAND_2GHZ:
  141. want = 7;
  142. for (i = 0; i < sband->n_bitrates; i++) {
  143. if (sband->bitrates[i].bitrate == 10) {
  144. sband->bitrates[i].flags |=
  145. IEEE80211_RATE_MANDATORY_B |
  146. IEEE80211_RATE_MANDATORY_G;
  147. want--;
  148. }
  149. if (sband->bitrates[i].bitrate == 20 ||
  150. sband->bitrates[i].bitrate == 55 ||
  151. sband->bitrates[i].bitrate == 110 ||
  152. sband->bitrates[i].bitrate == 60 ||
  153. sband->bitrates[i].bitrate == 120 ||
  154. sband->bitrates[i].bitrate == 240) {
  155. sband->bitrates[i].flags |=
  156. IEEE80211_RATE_MANDATORY_G;
  157. want--;
  158. }
  159. if (sband->bitrates[i].bitrate != 10 &&
  160. sband->bitrates[i].bitrate != 20 &&
  161. sband->bitrates[i].bitrate != 55 &&
  162. sband->bitrates[i].bitrate != 110)
  163. sband->bitrates[i].flags |=
  164. IEEE80211_RATE_ERP_G;
  165. }
  166. WARN_ON(want != 0 && want != 3 && want != 6);
  167. break;
  168. case NL80211_BAND_60GHZ:
  169. /* check for mandatory HT MCS 1..4 */
  170. WARN_ON(!sband->ht_cap.ht_supported);
  171. WARN_ON((sband->ht_cap.mcs.rx_mask[0] & 0x1e) != 0x1e);
  172. break;
  173. case NUM_NL80211_BANDS:
  174. default:
  175. WARN_ON(1);
  176. break;
  177. }
  178. }
  179. void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
  180. {
  181. enum nl80211_band band;
  182. for (band = 0; band < NUM_NL80211_BANDS; band++)
  183. if (wiphy->bands[band])
  184. set_mandatory_flags_band(wiphy->bands[band]);
  185. }
  186. bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher)
  187. {
  188. int i;
  189. for (i = 0; i < wiphy->n_cipher_suites; i++)
  190. if (cipher == wiphy->cipher_suites[i])
  191. return true;
  192. return false;
  193. }
  194. int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
  195. struct key_params *params, int key_idx,
  196. bool pairwise, const u8 *mac_addr)
  197. {
  198. if (key_idx < 0 || key_idx > 5)
  199. return -EINVAL;
  200. if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  201. return -EINVAL;
  202. if (pairwise && !mac_addr)
  203. return -EINVAL;
  204. switch (params->cipher) {
  205. case WLAN_CIPHER_SUITE_TKIP:
  206. case WLAN_CIPHER_SUITE_CCMP:
  207. case WLAN_CIPHER_SUITE_CCMP_256:
  208. case WLAN_CIPHER_SUITE_GCMP:
  209. case WLAN_CIPHER_SUITE_GCMP_256:
  210. /* Disallow pairwise keys with non-zero index unless it's WEP
  211. * or a vendor specific cipher (because current deployments use
  212. * pairwise WEP keys with non-zero indices and for vendor
  213. * specific ciphers this should be validated in the driver or
  214. * hardware level - but 802.11i clearly specifies to use zero)
  215. */
  216. if (pairwise && key_idx)
  217. return -EINVAL;
  218. break;
  219. case WLAN_CIPHER_SUITE_AES_CMAC:
  220. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  221. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  222. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  223. /* Disallow BIP (group-only) cipher as pairwise cipher */
  224. if (pairwise)
  225. return -EINVAL;
  226. if (key_idx < 4)
  227. return -EINVAL;
  228. break;
  229. case WLAN_CIPHER_SUITE_WEP40:
  230. case WLAN_CIPHER_SUITE_WEP104:
  231. if (key_idx > 3)
  232. return -EINVAL;
  233. default:
  234. break;
  235. }
  236. switch (params->cipher) {
  237. case WLAN_CIPHER_SUITE_WEP40:
  238. if (params->key_len != WLAN_KEY_LEN_WEP40)
  239. return -EINVAL;
  240. break;
  241. case WLAN_CIPHER_SUITE_TKIP:
  242. if (params->key_len != WLAN_KEY_LEN_TKIP)
  243. return -EINVAL;
  244. break;
  245. case WLAN_CIPHER_SUITE_CCMP:
  246. if (params->key_len != WLAN_KEY_LEN_CCMP)
  247. return -EINVAL;
  248. break;
  249. case WLAN_CIPHER_SUITE_CCMP_256:
  250. if (params->key_len != WLAN_KEY_LEN_CCMP_256)
  251. return -EINVAL;
  252. break;
  253. case WLAN_CIPHER_SUITE_GCMP:
  254. if (params->key_len != WLAN_KEY_LEN_GCMP)
  255. return -EINVAL;
  256. break;
  257. case WLAN_CIPHER_SUITE_GCMP_256:
  258. if (params->key_len != WLAN_KEY_LEN_GCMP_256)
  259. return -EINVAL;
  260. break;
  261. case WLAN_CIPHER_SUITE_WEP104:
  262. if (params->key_len != WLAN_KEY_LEN_WEP104)
  263. return -EINVAL;
  264. break;
  265. case WLAN_CIPHER_SUITE_AES_CMAC:
  266. if (params->key_len != WLAN_KEY_LEN_AES_CMAC)
  267. return -EINVAL;
  268. break;
  269. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  270. if (params->key_len != WLAN_KEY_LEN_BIP_CMAC_256)
  271. return -EINVAL;
  272. break;
  273. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  274. if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_128)
  275. return -EINVAL;
  276. break;
  277. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  278. if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_256)
  279. return -EINVAL;
  280. break;
  281. default:
  282. /*
  283. * We don't know anything about this algorithm,
  284. * allow using it -- but the driver must check
  285. * all parameters! We still check below whether
  286. * or not the driver supports this algorithm,
  287. * of course.
  288. */
  289. break;
  290. }
  291. if (params->seq) {
  292. switch (params->cipher) {
  293. case WLAN_CIPHER_SUITE_WEP40:
  294. case WLAN_CIPHER_SUITE_WEP104:
  295. /* These ciphers do not use key sequence */
  296. return -EINVAL;
  297. case WLAN_CIPHER_SUITE_TKIP:
  298. case WLAN_CIPHER_SUITE_CCMP:
  299. case WLAN_CIPHER_SUITE_CCMP_256:
  300. case WLAN_CIPHER_SUITE_GCMP:
  301. case WLAN_CIPHER_SUITE_GCMP_256:
  302. case WLAN_CIPHER_SUITE_AES_CMAC:
  303. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  304. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  305. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  306. if (params->seq_len != 6)
  307. return -EINVAL;
  308. break;
  309. }
  310. }
  311. if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher))
  312. return -EINVAL;
  313. return 0;
  314. }
  315. unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc)
  316. {
  317. unsigned int hdrlen = 24;
  318. if (ieee80211_is_data(fc)) {
  319. if (ieee80211_has_a4(fc))
  320. hdrlen = 30;
  321. if (ieee80211_is_data_qos(fc)) {
  322. hdrlen += IEEE80211_QOS_CTL_LEN;
  323. if (ieee80211_has_order(fc))
  324. hdrlen += IEEE80211_HT_CTL_LEN;
  325. }
  326. goto out;
  327. }
  328. if (ieee80211_is_mgmt(fc)) {
  329. if (ieee80211_has_order(fc))
  330. hdrlen += IEEE80211_HT_CTL_LEN;
  331. goto out;
  332. }
  333. if (ieee80211_is_ctl(fc)) {
  334. /*
  335. * ACK and CTS are 10 bytes, all others 16. To see how
  336. * to get this condition consider
  337. * subtype mask: 0b0000000011110000 (0x00F0)
  338. * ACK subtype: 0b0000000011010000 (0x00D0)
  339. * CTS subtype: 0b0000000011000000 (0x00C0)
  340. * bits that matter: ^^^ (0x00E0)
  341. * value of those: 0b0000000011000000 (0x00C0)
  342. */
  343. if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
  344. hdrlen = 10;
  345. else
  346. hdrlen = 16;
  347. }
  348. out:
  349. return hdrlen;
  350. }
  351. EXPORT_SYMBOL(ieee80211_hdrlen);
  352. unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
  353. {
  354. const struct ieee80211_hdr *hdr =
  355. (const struct ieee80211_hdr *)skb->data;
  356. unsigned int hdrlen;
  357. if (unlikely(skb->len < 10))
  358. return 0;
  359. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  360. if (unlikely(hdrlen > skb->len))
  361. return 0;
  362. return hdrlen;
  363. }
  364. EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
  365. static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags)
  366. {
  367. int ae = flags & MESH_FLAGS_AE;
  368. /* 802.11-2012, 8.2.4.7.3 */
  369. switch (ae) {
  370. default:
  371. case 0:
  372. return 6;
  373. case MESH_FLAGS_AE_A4:
  374. return 12;
  375. case MESH_FLAGS_AE_A5_A6:
  376. return 18;
  377. }
  378. }
  379. unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
  380. {
  381. return __ieee80211_get_mesh_hdrlen(meshhdr->flags);
  382. }
  383. EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
  384. int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
  385. const u8 *addr, enum nl80211_iftype iftype)
  386. {
  387. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  388. struct {
  389. u8 hdr[ETH_ALEN] __aligned(2);
  390. __be16 proto;
  391. } payload;
  392. struct ethhdr tmp;
  393. u16 hdrlen;
  394. u8 mesh_flags = 0;
  395. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  396. return -1;
  397. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  398. if (skb->len < hdrlen + 8)
  399. return -1;
  400. /* convert IEEE 802.11 header + possible LLC headers into Ethernet
  401. * header
  402. * IEEE 802.11 address fields:
  403. * ToDS FromDS Addr1 Addr2 Addr3 Addr4
  404. * 0 0 DA SA BSSID n/a
  405. * 0 1 DA BSSID SA n/a
  406. * 1 0 BSSID SA DA n/a
  407. * 1 1 RA TA DA SA
  408. */
  409. memcpy(tmp.h_dest, ieee80211_get_DA(hdr), ETH_ALEN);
  410. memcpy(tmp.h_source, ieee80211_get_SA(hdr), ETH_ALEN);
  411. if (iftype == NL80211_IFTYPE_MESH_POINT)
  412. skb_copy_bits(skb, hdrlen, &mesh_flags, 1);
  413. switch (hdr->frame_control &
  414. cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
  415. case cpu_to_le16(IEEE80211_FCTL_TODS):
  416. if (unlikely(iftype != NL80211_IFTYPE_AP &&
  417. iftype != NL80211_IFTYPE_AP_VLAN &&
  418. iftype != NL80211_IFTYPE_P2P_GO))
  419. return -1;
  420. break;
  421. case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
  422. if (unlikely(iftype != NL80211_IFTYPE_WDS &&
  423. iftype != NL80211_IFTYPE_MESH_POINT &&
  424. iftype != NL80211_IFTYPE_AP_VLAN &&
  425. iftype != NL80211_IFTYPE_STATION))
  426. return -1;
  427. if (iftype == NL80211_IFTYPE_MESH_POINT) {
  428. if (mesh_flags & MESH_FLAGS_AE_A4)
  429. return -1;
  430. if (mesh_flags & MESH_FLAGS_AE_A5_A6) {
  431. skb_copy_bits(skb, hdrlen +
  432. offsetof(struct ieee80211s_hdr, eaddr1),
  433. tmp.h_dest, 2 * ETH_ALEN);
  434. }
  435. hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
  436. }
  437. break;
  438. case cpu_to_le16(IEEE80211_FCTL_FROMDS):
  439. if ((iftype != NL80211_IFTYPE_STATION &&
  440. iftype != NL80211_IFTYPE_P2P_CLIENT &&
  441. iftype != NL80211_IFTYPE_MESH_POINT) ||
  442. (is_multicast_ether_addr(tmp.h_dest) &&
  443. ether_addr_equal(tmp.h_source, addr)))
  444. return -1;
  445. if (iftype == NL80211_IFTYPE_MESH_POINT) {
  446. if (mesh_flags & MESH_FLAGS_AE_A5_A6)
  447. return -1;
  448. if (mesh_flags & MESH_FLAGS_AE_A4)
  449. skb_copy_bits(skb, hdrlen +
  450. offsetof(struct ieee80211s_hdr, eaddr1),
  451. tmp.h_source, ETH_ALEN);
  452. hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
  453. }
  454. break;
  455. case cpu_to_le16(0):
  456. if (iftype != NL80211_IFTYPE_ADHOC &&
  457. iftype != NL80211_IFTYPE_STATION &&
  458. iftype != NL80211_IFTYPE_OCB)
  459. return -1;
  460. break;
  461. }
  462. skb_copy_bits(skb, hdrlen, &payload, sizeof(payload));
  463. tmp.h_proto = payload.proto;
  464. if (likely((ether_addr_equal(payload.hdr, rfc1042_header) &&
  465. tmp.h_proto != htons(ETH_P_AARP) &&
  466. tmp.h_proto != htons(ETH_P_IPX)) ||
  467. ether_addr_equal(payload.hdr, bridge_tunnel_header)))
  468. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  469. * replace EtherType */
  470. hdrlen += ETH_ALEN + 2;
  471. else
  472. tmp.h_proto = htons(skb->len - hdrlen);
  473. pskb_pull(skb, hdrlen);
  474. if (!ehdr)
  475. ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
  476. memcpy(ehdr, &tmp, sizeof(tmp));
  477. return 0;
  478. }
  479. EXPORT_SYMBOL(ieee80211_data_to_8023_exthdr);
  480. int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
  481. enum nl80211_iftype iftype,
  482. const u8 *bssid, bool qos)
  483. {
  484. struct ieee80211_hdr hdr;
  485. u16 hdrlen, ethertype;
  486. __le16 fc;
  487. const u8 *encaps_data;
  488. int encaps_len, skip_header_bytes;
  489. int nh_pos, h_pos;
  490. int head_need;
  491. if (unlikely(skb->len < ETH_HLEN))
  492. return -EINVAL;
  493. nh_pos = skb_network_header(skb) - skb->data;
  494. h_pos = skb_transport_header(skb) - skb->data;
  495. /* convert Ethernet header to proper 802.11 header (based on
  496. * operation mode) */
  497. ethertype = (skb->data[12] << 8) | skb->data[13];
  498. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  499. switch (iftype) {
  500. case NL80211_IFTYPE_AP:
  501. case NL80211_IFTYPE_AP_VLAN:
  502. case NL80211_IFTYPE_P2P_GO:
  503. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  504. /* DA BSSID SA */
  505. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  506. memcpy(hdr.addr2, addr, ETH_ALEN);
  507. memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
  508. hdrlen = 24;
  509. break;
  510. case NL80211_IFTYPE_STATION:
  511. case NL80211_IFTYPE_P2P_CLIENT:
  512. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  513. /* BSSID SA DA */
  514. memcpy(hdr.addr1, bssid, ETH_ALEN);
  515. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  516. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  517. hdrlen = 24;
  518. break;
  519. case NL80211_IFTYPE_OCB:
  520. case NL80211_IFTYPE_ADHOC:
  521. /* DA SA BSSID */
  522. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  523. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  524. memcpy(hdr.addr3, bssid, ETH_ALEN);
  525. hdrlen = 24;
  526. break;
  527. default:
  528. return -EOPNOTSUPP;
  529. }
  530. if (qos) {
  531. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  532. hdrlen += 2;
  533. }
  534. hdr.frame_control = fc;
  535. hdr.duration_id = 0;
  536. hdr.seq_ctrl = 0;
  537. skip_header_bytes = ETH_HLEN;
  538. if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
  539. encaps_data = bridge_tunnel_header;
  540. encaps_len = sizeof(bridge_tunnel_header);
  541. skip_header_bytes -= 2;
  542. } else if (ethertype >= ETH_P_802_3_MIN) {
  543. encaps_data = rfc1042_header;
  544. encaps_len = sizeof(rfc1042_header);
  545. skip_header_bytes -= 2;
  546. } else {
  547. encaps_data = NULL;
  548. encaps_len = 0;
  549. }
  550. skb_pull(skb, skip_header_bytes);
  551. nh_pos -= skip_header_bytes;
  552. h_pos -= skip_header_bytes;
  553. head_need = hdrlen + encaps_len - skb_headroom(skb);
  554. if (head_need > 0 || skb_cloned(skb)) {
  555. head_need = max(head_need, 0);
  556. if (head_need)
  557. skb_orphan(skb);
  558. if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC))
  559. return -ENOMEM;
  560. }
  561. if (encaps_data) {
  562. memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
  563. nh_pos += encaps_len;
  564. h_pos += encaps_len;
  565. }
  566. memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
  567. nh_pos += hdrlen;
  568. h_pos += hdrlen;
  569. /* Update skb pointers to various headers since this modified frame
  570. * is going to go through Linux networking code that may potentially
  571. * need things like pointer to IP header. */
  572. skb_reset_mac_header(skb);
  573. skb_set_network_header(skb, nh_pos);
  574. skb_set_transport_header(skb, h_pos);
  575. return 0;
  576. }
  577. EXPORT_SYMBOL(ieee80211_data_from_8023);
  578. static void
  579. __frame_add_frag(struct sk_buff *skb, struct page *page,
  580. void *ptr, int len, int size)
  581. {
  582. struct skb_shared_info *sh = skb_shinfo(skb);
  583. int page_offset;
  584. page_ref_inc(page);
  585. page_offset = ptr - page_address(page);
  586. skb_add_rx_frag(skb, sh->nr_frags, page, page_offset, len, size);
  587. }
  588. static void
  589. __ieee80211_amsdu_copy_frag(struct sk_buff *skb, struct sk_buff *frame,
  590. int offset, int len)
  591. {
  592. struct skb_shared_info *sh = skb_shinfo(skb);
  593. const skb_frag_t *frag = &sh->frags[-1];
  594. struct page *frag_page;
  595. void *frag_ptr;
  596. int frag_len, frag_size;
  597. int head_size = skb->len - skb->data_len;
  598. int cur_len;
  599. frag_page = virt_to_head_page(skb->head);
  600. frag_ptr = skb->data;
  601. frag_size = head_size;
  602. while (offset >= frag_size) {
  603. offset -= frag_size;
  604. frag++;
  605. frag_page = skb_frag_page(frag);
  606. frag_ptr = skb_frag_address(frag);
  607. frag_size = skb_frag_size(frag);
  608. }
  609. frag_ptr += offset;
  610. frag_len = frag_size - offset;
  611. cur_len = min(len, frag_len);
  612. __frame_add_frag(frame, frag_page, frag_ptr, cur_len, frag_size);
  613. len -= cur_len;
  614. while (len > 0) {
  615. frag++;
  616. frag_len = skb_frag_size(frag);
  617. cur_len = min(len, frag_len);
  618. __frame_add_frag(frame, skb_frag_page(frag),
  619. skb_frag_address(frag), cur_len, frag_len);
  620. len -= cur_len;
  621. }
  622. }
  623. static struct sk_buff *
  624. __ieee80211_amsdu_copy(struct sk_buff *skb, unsigned int hlen,
  625. int offset, int len, bool reuse_frag)
  626. {
  627. struct sk_buff *frame;
  628. int cur_len = len;
  629. if (skb->len - offset < len)
  630. return NULL;
  631. /*
  632. * When reusing framents, copy some data to the head to simplify
  633. * ethernet header handling and speed up protocol header processing
  634. * in the stack later.
  635. */
  636. if (reuse_frag)
  637. cur_len = min_t(int, len, 32);
  638. /*
  639. * Allocate and reserve two bytes more for payload
  640. * alignment since sizeof(struct ethhdr) is 14.
  641. */
  642. frame = dev_alloc_skb(hlen + sizeof(struct ethhdr) + 2 + cur_len);
  643. if (!frame)
  644. return NULL;
  645. skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
  646. skb_copy_bits(skb, offset, skb_put(frame, cur_len), cur_len);
  647. len -= cur_len;
  648. if (!len)
  649. return frame;
  650. offset += cur_len;
  651. __ieee80211_amsdu_copy_frag(skb, frame, offset, len);
  652. return frame;
  653. }
  654. void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
  655. const u8 *addr, enum nl80211_iftype iftype,
  656. const unsigned int extra_headroom,
  657. const u8 *check_da, const u8 *check_sa)
  658. {
  659. unsigned int hlen = ALIGN(extra_headroom, 4);
  660. struct sk_buff *frame = NULL;
  661. u16 ethertype;
  662. u8 *payload;
  663. int offset = 0, remaining;
  664. struct ethhdr eth;
  665. bool reuse_frag = skb->head_frag && !skb_has_frag_list(skb);
  666. bool reuse_skb = false;
  667. bool last = false;
  668. while (!last) {
  669. unsigned int subframe_len;
  670. int len;
  671. u8 padding;
  672. skb_copy_bits(skb, offset, &eth, sizeof(eth));
  673. len = ntohs(eth.h_proto);
  674. subframe_len = sizeof(struct ethhdr) + len;
  675. padding = (4 - subframe_len) & 0x3;
  676. /* the last MSDU has no padding */
  677. remaining = skb->len - offset;
  678. if (subframe_len > remaining)
  679. goto purge;
  680. offset += sizeof(struct ethhdr);
  681. last = remaining <= subframe_len + padding;
  682. /* FIXME: should we really accept multicast DA? */
  683. if ((check_da && !is_multicast_ether_addr(eth.h_dest) &&
  684. !ether_addr_equal(check_da, eth.h_dest)) ||
  685. (check_sa && !ether_addr_equal(check_sa, eth.h_source))) {
  686. offset += len + padding;
  687. continue;
  688. }
  689. /* reuse skb for the last subframe */
  690. if (!skb_is_nonlinear(skb) && !reuse_frag && last) {
  691. skb_pull(skb, offset);
  692. frame = skb;
  693. reuse_skb = true;
  694. } else {
  695. frame = __ieee80211_amsdu_copy(skb, hlen, offset, len,
  696. reuse_frag);
  697. if (!frame)
  698. goto purge;
  699. offset += len + padding;
  700. }
  701. skb_reset_network_header(frame);
  702. frame->dev = skb->dev;
  703. frame->priority = skb->priority;
  704. payload = frame->data;
  705. ethertype = (payload[6] << 8) | payload[7];
  706. if (likely((ether_addr_equal(payload, rfc1042_header) &&
  707. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  708. ether_addr_equal(payload, bridge_tunnel_header))) {
  709. eth.h_proto = htons(ethertype);
  710. skb_pull(frame, ETH_ALEN + 2);
  711. }
  712. memcpy(skb_push(frame, sizeof(eth)), &eth, sizeof(eth));
  713. __skb_queue_tail(list, frame);
  714. }
  715. if (!reuse_skb)
  716. dev_kfree_skb(skb);
  717. return;
  718. purge:
  719. __skb_queue_purge(list);
  720. dev_kfree_skb(skb);
  721. }
  722. EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
  723. /* Given a data frame determine the 802.1p/1d tag to use. */
  724. unsigned int cfg80211_classify8021d(struct sk_buff *skb,
  725. struct cfg80211_qos_map *qos_map)
  726. {
  727. unsigned int dscp;
  728. unsigned char vlan_priority;
  729. /* skb->priority values from 256->263 are magic values to
  730. * directly indicate a specific 802.1d priority. This is used
  731. * to allow 802.1d priority to be passed directly in from VLAN
  732. * tags, etc.
  733. */
  734. if (skb->priority >= 256 && skb->priority <= 263)
  735. return skb->priority - 256;
  736. if (skb_vlan_tag_present(skb)) {
  737. vlan_priority = (skb_vlan_tag_get(skb) & VLAN_PRIO_MASK)
  738. >> VLAN_PRIO_SHIFT;
  739. if (vlan_priority > 0)
  740. return vlan_priority;
  741. }
  742. switch (skb->protocol) {
  743. case htons(ETH_P_IP):
  744. dscp = ipv4_get_dsfield(ip_hdr(skb)) & 0xfc;
  745. break;
  746. case htons(ETH_P_IPV6):
  747. dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & 0xfc;
  748. break;
  749. case htons(ETH_P_MPLS_UC):
  750. case htons(ETH_P_MPLS_MC): {
  751. struct mpls_label mpls_tmp, *mpls;
  752. mpls = skb_header_pointer(skb, sizeof(struct ethhdr),
  753. sizeof(*mpls), &mpls_tmp);
  754. if (!mpls)
  755. return 0;
  756. return (ntohl(mpls->entry) & MPLS_LS_TC_MASK)
  757. >> MPLS_LS_TC_SHIFT;
  758. }
  759. case htons(ETH_P_80221):
  760. /* 802.21 is always network control traffic */
  761. return 7;
  762. default:
  763. return 0;
  764. }
  765. if (qos_map) {
  766. unsigned int i, tmp_dscp = dscp >> 2;
  767. for (i = 0; i < qos_map->num_des; i++) {
  768. if (tmp_dscp == qos_map->dscp_exception[i].dscp)
  769. return qos_map->dscp_exception[i].up;
  770. }
  771. for (i = 0; i < 8; i++) {
  772. if (tmp_dscp >= qos_map->up[i].low &&
  773. tmp_dscp <= qos_map->up[i].high)
  774. return i;
  775. }
  776. }
  777. return dscp >> 5;
  778. }
  779. EXPORT_SYMBOL(cfg80211_classify8021d);
  780. const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
  781. {
  782. const struct cfg80211_bss_ies *ies;
  783. ies = rcu_dereference(bss->ies);
  784. if (!ies)
  785. return NULL;
  786. return cfg80211_find_ie(ie, ies->data, ies->len);
  787. }
  788. EXPORT_SYMBOL(ieee80211_bss_get_ie);
  789. void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
  790. {
  791. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  792. struct net_device *dev = wdev->netdev;
  793. int i;
  794. if (!wdev->connect_keys)
  795. return;
  796. for (i = 0; i < CFG80211_MAX_WEP_KEYS; i++) {
  797. if (!wdev->connect_keys->params[i].cipher)
  798. continue;
  799. if (rdev_add_key(rdev, dev, i, false, NULL,
  800. &wdev->connect_keys->params[i])) {
  801. netdev_err(dev, "failed to set key %d\n", i);
  802. continue;
  803. }
  804. if (wdev->connect_keys->def == i &&
  805. rdev_set_default_key(rdev, dev, i, true, true)) {
  806. netdev_err(dev, "failed to set defkey %d\n", i);
  807. continue;
  808. }
  809. }
  810. kzfree(wdev->connect_keys);
  811. wdev->connect_keys = NULL;
  812. }
  813. void cfg80211_process_wdev_events(struct wireless_dev *wdev)
  814. {
  815. struct cfg80211_event *ev;
  816. unsigned long flags;
  817. const u8 *bssid = NULL;
  818. spin_lock_irqsave(&wdev->event_lock, flags);
  819. while (!list_empty(&wdev->event_list)) {
  820. ev = list_first_entry(&wdev->event_list,
  821. struct cfg80211_event, list);
  822. list_del(&ev->list);
  823. spin_unlock_irqrestore(&wdev->event_lock, flags);
  824. wdev_lock(wdev);
  825. switch (ev->type) {
  826. case EVENT_CONNECT_RESULT:
  827. if (!is_zero_ether_addr(ev->cr.bssid))
  828. bssid = ev->cr.bssid;
  829. __cfg80211_connect_result(
  830. wdev->netdev, bssid,
  831. ev->cr.req_ie, ev->cr.req_ie_len,
  832. ev->cr.resp_ie, ev->cr.resp_ie_len,
  833. ev->cr.status,
  834. ev->cr.status == WLAN_STATUS_SUCCESS,
  835. ev->cr.bss, ev->cr.timeout_reason);
  836. break;
  837. case EVENT_ROAMED:
  838. __cfg80211_roamed(wdev, ev->rm.bss, ev->rm.req_ie,
  839. ev->rm.req_ie_len, ev->rm.resp_ie,
  840. ev->rm.resp_ie_len);
  841. break;
  842. case EVENT_DISCONNECTED:
  843. __cfg80211_disconnected(wdev->netdev,
  844. ev->dc.ie, ev->dc.ie_len,
  845. ev->dc.reason,
  846. !ev->dc.locally_generated);
  847. break;
  848. case EVENT_IBSS_JOINED:
  849. __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid,
  850. ev->ij.channel);
  851. break;
  852. case EVENT_STOPPED:
  853. __cfg80211_leave(wiphy_to_rdev(wdev->wiphy), wdev);
  854. break;
  855. }
  856. wdev_unlock(wdev);
  857. kfree(ev);
  858. spin_lock_irqsave(&wdev->event_lock, flags);
  859. }
  860. spin_unlock_irqrestore(&wdev->event_lock, flags);
  861. }
  862. void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
  863. {
  864. struct wireless_dev *wdev;
  865. ASSERT_RTNL();
  866. list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list)
  867. cfg80211_process_wdev_events(wdev);
  868. }
  869. int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
  870. struct net_device *dev, enum nl80211_iftype ntype,
  871. u32 *flags, struct vif_params *params)
  872. {
  873. int err;
  874. enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
  875. ASSERT_RTNL();
  876. /* don't support changing VLANs, you just re-create them */
  877. if (otype == NL80211_IFTYPE_AP_VLAN)
  878. return -EOPNOTSUPP;
  879. /* cannot change into P2P device or NAN */
  880. if (ntype == NL80211_IFTYPE_P2P_DEVICE ||
  881. ntype == NL80211_IFTYPE_NAN)
  882. return -EOPNOTSUPP;
  883. if (!rdev->ops->change_virtual_intf ||
  884. !(rdev->wiphy.interface_modes & (1 << ntype)))
  885. return -EOPNOTSUPP;
  886. /* if it's part of a bridge, reject changing type to station/ibss */
  887. if ((dev->priv_flags & IFF_BRIDGE_PORT) &&
  888. (ntype == NL80211_IFTYPE_ADHOC ||
  889. ntype == NL80211_IFTYPE_STATION ||
  890. ntype == NL80211_IFTYPE_P2P_CLIENT))
  891. return -EBUSY;
  892. if (ntype != otype) {
  893. dev->ieee80211_ptr->use_4addr = false;
  894. dev->ieee80211_ptr->mesh_id_up_len = 0;
  895. wdev_lock(dev->ieee80211_ptr);
  896. rdev_set_qos_map(rdev, dev, NULL);
  897. wdev_unlock(dev->ieee80211_ptr);
  898. switch (otype) {
  899. case NL80211_IFTYPE_AP:
  900. cfg80211_stop_ap(rdev, dev, true);
  901. break;
  902. case NL80211_IFTYPE_ADHOC:
  903. cfg80211_leave_ibss(rdev, dev, false);
  904. break;
  905. case NL80211_IFTYPE_STATION:
  906. case NL80211_IFTYPE_P2P_CLIENT:
  907. wdev_lock(dev->ieee80211_ptr);
  908. cfg80211_disconnect(rdev, dev,
  909. WLAN_REASON_DEAUTH_LEAVING, true);
  910. wdev_unlock(dev->ieee80211_ptr);
  911. break;
  912. case NL80211_IFTYPE_MESH_POINT:
  913. /* mesh should be handled? */
  914. break;
  915. default:
  916. break;
  917. }
  918. cfg80211_process_rdev_events(rdev);
  919. }
  920. err = rdev_change_virtual_intf(rdev, dev, ntype, flags, params);
  921. WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
  922. if (!err && params && params->use_4addr != -1)
  923. dev->ieee80211_ptr->use_4addr = params->use_4addr;
  924. if (!err) {
  925. dev->priv_flags &= ~IFF_DONT_BRIDGE;
  926. switch (ntype) {
  927. case NL80211_IFTYPE_STATION:
  928. if (dev->ieee80211_ptr->use_4addr)
  929. break;
  930. /* fall through */
  931. case NL80211_IFTYPE_OCB:
  932. case NL80211_IFTYPE_P2P_CLIENT:
  933. case NL80211_IFTYPE_ADHOC:
  934. dev->priv_flags |= IFF_DONT_BRIDGE;
  935. break;
  936. case NL80211_IFTYPE_P2P_GO:
  937. case NL80211_IFTYPE_AP:
  938. case NL80211_IFTYPE_AP_VLAN:
  939. case NL80211_IFTYPE_WDS:
  940. case NL80211_IFTYPE_MESH_POINT:
  941. /* bridging OK */
  942. break;
  943. case NL80211_IFTYPE_MONITOR:
  944. /* monitor can't bridge anyway */
  945. break;
  946. case NL80211_IFTYPE_UNSPECIFIED:
  947. case NUM_NL80211_IFTYPES:
  948. /* not happening */
  949. break;
  950. case NL80211_IFTYPE_P2P_DEVICE:
  951. case NL80211_IFTYPE_NAN:
  952. WARN_ON(1);
  953. break;
  954. }
  955. }
  956. if (!err && ntype != otype && netif_running(dev)) {
  957. cfg80211_update_iface_num(rdev, ntype, 1);
  958. cfg80211_update_iface_num(rdev, otype, -1);
  959. }
  960. return err;
  961. }
  962. static u32 cfg80211_calculate_bitrate_ht(struct rate_info *rate)
  963. {
  964. int modulation, streams, bitrate;
  965. /* the formula below does only work for MCS values smaller than 32 */
  966. if (WARN_ON_ONCE(rate->mcs >= 32))
  967. return 0;
  968. modulation = rate->mcs & 7;
  969. streams = (rate->mcs >> 3) + 1;
  970. bitrate = (rate->bw == RATE_INFO_BW_40) ? 13500000 : 6500000;
  971. if (modulation < 4)
  972. bitrate *= (modulation + 1);
  973. else if (modulation == 4)
  974. bitrate *= (modulation + 2);
  975. else
  976. bitrate *= (modulation + 3);
  977. bitrate *= streams;
  978. if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
  979. bitrate = (bitrate / 9) * 10;
  980. /* do NOT round down here */
  981. return (bitrate + 50000) / 100000;
  982. }
  983. static u32 cfg80211_calculate_bitrate_60g(struct rate_info *rate)
  984. {
  985. static const u32 __mcs2bitrate[] = {
  986. /* control PHY */
  987. [0] = 275,
  988. /* SC PHY */
  989. [1] = 3850,
  990. [2] = 7700,
  991. [3] = 9625,
  992. [4] = 11550,
  993. [5] = 12512, /* 1251.25 mbps */
  994. [6] = 15400,
  995. [7] = 19250,
  996. [8] = 23100,
  997. [9] = 25025,
  998. [10] = 30800,
  999. [11] = 38500,
  1000. [12] = 46200,
  1001. /* OFDM PHY */
  1002. [13] = 6930,
  1003. [14] = 8662, /* 866.25 mbps */
  1004. [15] = 13860,
  1005. [16] = 17325,
  1006. [17] = 20790,
  1007. [18] = 27720,
  1008. [19] = 34650,
  1009. [20] = 41580,
  1010. [21] = 45045,
  1011. [22] = 51975,
  1012. [23] = 62370,
  1013. [24] = 67568, /* 6756.75 mbps */
  1014. /* LP-SC PHY */
  1015. [25] = 6260,
  1016. [26] = 8340,
  1017. [27] = 11120,
  1018. [28] = 12510,
  1019. [29] = 16680,
  1020. [30] = 22240,
  1021. [31] = 25030,
  1022. };
  1023. if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate)))
  1024. return 0;
  1025. return __mcs2bitrate[rate->mcs];
  1026. }
  1027. static u32 cfg80211_calculate_bitrate_vht(struct rate_info *rate)
  1028. {
  1029. static const u32 base[4][10] = {
  1030. { 6500000,
  1031. 13000000,
  1032. 19500000,
  1033. 26000000,
  1034. 39000000,
  1035. 52000000,
  1036. 58500000,
  1037. 65000000,
  1038. 78000000,
  1039. /* not in the spec, but some devices use this: */
  1040. 86500000,
  1041. },
  1042. { 13500000,
  1043. 27000000,
  1044. 40500000,
  1045. 54000000,
  1046. 81000000,
  1047. 108000000,
  1048. 121500000,
  1049. 135000000,
  1050. 162000000,
  1051. 180000000,
  1052. },
  1053. { 29300000,
  1054. 58500000,
  1055. 87800000,
  1056. 117000000,
  1057. 175500000,
  1058. 234000000,
  1059. 263300000,
  1060. 292500000,
  1061. 351000000,
  1062. 390000000,
  1063. },
  1064. { 58500000,
  1065. 117000000,
  1066. 175500000,
  1067. 234000000,
  1068. 351000000,
  1069. 468000000,
  1070. 526500000,
  1071. 585000000,
  1072. 702000000,
  1073. 780000000,
  1074. },
  1075. };
  1076. u32 bitrate;
  1077. int idx;
  1078. if (WARN_ON_ONCE(rate->mcs > 9))
  1079. return 0;
  1080. switch (rate->bw) {
  1081. case RATE_INFO_BW_160:
  1082. idx = 3;
  1083. break;
  1084. case RATE_INFO_BW_80:
  1085. idx = 2;
  1086. break;
  1087. case RATE_INFO_BW_40:
  1088. idx = 1;
  1089. break;
  1090. case RATE_INFO_BW_5:
  1091. case RATE_INFO_BW_10:
  1092. default:
  1093. WARN_ON(1);
  1094. /* fall through */
  1095. case RATE_INFO_BW_20:
  1096. idx = 0;
  1097. }
  1098. bitrate = base[idx][rate->mcs];
  1099. bitrate *= rate->nss;
  1100. if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
  1101. bitrate = (bitrate / 9) * 10;
  1102. /* do NOT round down here */
  1103. return (bitrate + 50000) / 100000;
  1104. }
  1105. u32 cfg80211_calculate_bitrate(struct rate_info *rate)
  1106. {
  1107. if (rate->flags & RATE_INFO_FLAGS_MCS)
  1108. return cfg80211_calculate_bitrate_ht(rate);
  1109. if (rate->flags & RATE_INFO_FLAGS_60G)
  1110. return cfg80211_calculate_bitrate_60g(rate);
  1111. if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
  1112. return cfg80211_calculate_bitrate_vht(rate);
  1113. return rate->legacy;
  1114. }
  1115. EXPORT_SYMBOL(cfg80211_calculate_bitrate);
  1116. int cfg80211_get_p2p_attr(const u8 *ies, unsigned int len,
  1117. enum ieee80211_p2p_attr_id attr,
  1118. u8 *buf, unsigned int bufsize)
  1119. {
  1120. u8 *out = buf;
  1121. u16 attr_remaining = 0;
  1122. bool desired_attr = false;
  1123. u16 desired_len = 0;
  1124. while (len > 0) {
  1125. unsigned int iedatalen;
  1126. unsigned int copy;
  1127. const u8 *iedata;
  1128. if (len < 2)
  1129. return -EILSEQ;
  1130. iedatalen = ies[1];
  1131. if (iedatalen + 2 > len)
  1132. return -EILSEQ;
  1133. if (ies[0] != WLAN_EID_VENDOR_SPECIFIC)
  1134. goto cont;
  1135. if (iedatalen < 4)
  1136. goto cont;
  1137. iedata = ies + 2;
  1138. /* check WFA OUI, P2P subtype */
  1139. if (iedata[0] != 0x50 || iedata[1] != 0x6f ||
  1140. iedata[2] != 0x9a || iedata[3] != 0x09)
  1141. goto cont;
  1142. iedatalen -= 4;
  1143. iedata += 4;
  1144. /* check attribute continuation into this IE */
  1145. copy = min_t(unsigned int, attr_remaining, iedatalen);
  1146. if (copy && desired_attr) {
  1147. desired_len += copy;
  1148. if (out) {
  1149. memcpy(out, iedata, min(bufsize, copy));
  1150. out += min(bufsize, copy);
  1151. bufsize -= min(bufsize, copy);
  1152. }
  1153. if (copy == attr_remaining)
  1154. return desired_len;
  1155. }
  1156. attr_remaining -= copy;
  1157. if (attr_remaining)
  1158. goto cont;
  1159. iedatalen -= copy;
  1160. iedata += copy;
  1161. while (iedatalen > 0) {
  1162. u16 attr_len;
  1163. /* P2P attribute ID & size must fit */
  1164. if (iedatalen < 3)
  1165. return -EILSEQ;
  1166. desired_attr = iedata[0] == attr;
  1167. attr_len = get_unaligned_le16(iedata + 1);
  1168. iedatalen -= 3;
  1169. iedata += 3;
  1170. copy = min_t(unsigned int, attr_len, iedatalen);
  1171. if (desired_attr) {
  1172. desired_len += copy;
  1173. if (out) {
  1174. memcpy(out, iedata, min(bufsize, copy));
  1175. out += min(bufsize, copy);
  1176. bufsize -= min(bufsize, copy);
  1177. }
  1178. if (copy == attr_len)
  1179. return desired_len;
  1180. }
  1181. iedata += copy;
  1182. iedatalen -= copy;
  1183. attr_remaining = attr_len - copy;
  1184. }
  1185. cont:
  1186. len -= ies[1] + 2;
  1187. ies += ies[1] + 2;
  1188. }
  1189. if (attr_remaining && desired_attr)
  1190. return -EILSEQ;
  1191. return -ENOENT;
  1192. }
  1193. EXPORT_SYMBOL(cfg80211_get_p2p_attr);
  1194. static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
  1195. {
  1196. int i;
  1197. for (i = 0; i < n_ids; i++)
  1198. if (ids[i] == id)
  1199. return true;
  1200. return false;
  1201. }
  1202. static size_t skip_ie(const u8 *ies, size_t ielen, size_t pos)
  1203. {
  1204. /* we assume a validly formed IEs buffer */
  1205. u8 len = ies[pos + 1];
  1206. pos += 2 + len;
  1207. /* the IE itself must have 255 bytes for fragments to follow */
  1208. if (len < 255)
  1209. return pos;
  1210. while (pos < ielen && ies[pos] == WLAN_EID_FRAGMENT) {
  1211. len = ies[pos + 1];
  1212. pos += 2 + len;
  1213. }
  1214. return pos;
  1215. }
  1216. size_t ieee80211_ie_split_ric(const u8 *ies, size_t ielen,
  1217. const u8 *ids, int n_ids,
  1218. const u8 *after_ric, int n_after_ric,
  1219. size_t offset)
  1220. {
  1221. size_t pos = offset;
  1222. while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos])) {
  1223. if (ies[pos] == WLAN_EID_RIC_DATA && n_after_ric) {
  1224. pos = skip_ie(ies, ielen, pos);
  1225. while (pos < ielen &&
  1226. !ieee80211_id_in_list(after_ric, n_after_ric,
  1227. ies[pos]))
  1228. pos = skip_ie(ies, ielen, pos);
  1229. } else {
  1230. pos = skip_ie(ies, ielen, pos);
  1231. }
  1232. }
  1233. return pos;
  1234. }
  1235. EXPORT_SYMBOL(ieee80211_ie_split_ric);
  1236. bool ieee80211_operating_class_to_band(u8 operating_class,
  1237. enum nl80211_band *band)
  1238. {
  1239. switch (operating_class) {
  1240. case 112:
  1241. case 115 ... 127:
  1242. case 128 ... 130:
  1243. *band = NL80211_BAND_5GHZ;
  1244. return true;
  1245. case 81:
  1246. case 82:
  1247. case 83:
  1248. case 84:
  1249. *band = NL80211_BAND_2GHZ;
  1250. return true;
  1251. case 180:
  1252. *band = NL80211_BAND_60GHZ;
  1253. return true;
  1254. }
  1255. return false;
  1256. }
  1257. EXPORT_SYMBOL(ieee80211_operating_class_to_band);
  1258. bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
  1259. u8 *op_class)
  1260. {
  1261. u8 vht_opclass;
  1262. u16 freq = chandef->center_freq1;
  1263. if (freq >= 2412 && freq <= 2472) {
  1264. if (chandef->width > NL80211_CHAN_WIDTH_40)
  1265. return false;
  1266. /* 2.407 GHz, channels 1..13 */
  1267. if (chandef->width == NL80211_CHAN_WIDTH_40) {
  1268. if (freq > chandef->chan->center_freq)
  1269. *op_class = 83; /* HT40+ */
  1270. else
  1271. *op_class = 84; /* HT40- */
  1272. } else {
  1273. *op_class = 81;
  1274. }
  1275. return true;
  1276. }
  1277. if (freq == 2484) {
  1278. if (chandef->width > NL80211_CHAN_WIDTH_40)
  1279. return false;
  1280. *op_class = 82; /* channel 14 */
  1281. return true;
  1282. }
  1283. switch (chandef->width) {
  1284. case NL80211_CHAN_WIDTH_80:
  1285. vht_opclass = 128;
  1286. break;
  1287. case NL80211_CHAN_WIDTH_160:
  1288. vht_opclass = 129;
  1289. break;
  1290. case NL80211_CHAN_WIDTH_80P80:
  1291. vht_opclass = 130;
  1292. break;
  1293. case NL80211_CHAN_WIDTH_10:
  1294. case NL80211_CHAN_WIDTH_5:
  1295. return false; /* unsupported for now */
  1296. default:
  1297. vht_opclass = 0;
  1298. break;
  1299. }
  1300. /* 5 GHz, channels 36..48 */
  1301. if (freq >= 5180 && freq <= 5240) {
  1302. if (vht_opclass) {
  1303. *op_class = vht_opclass;
  1304. } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
  1305. if (freq > chandef->chan->center_freq)
  1306. *op_class = 116;
  1307. else
  1308. *op_class = 117;
  1309. } else {
  1310. *op_class = 115;
  1311. }
  1312. return true;
  1313. }
  1314. /* 5 GHz, channels 52..64 */
  1315. if (freq >= 5260 && freq <= 5320) {
  1316. if (vht_opclass) {
  1317. *op_class = vht_opclass;
  1318. } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
  1319. if (freq > chandef->chan->center_freq)
  1320. *op_class = 119;
  1321. else
  1322. *op_class = 120;
  1323. } else {
  1324. *op_class = 118;
  1325. }
  1326. return true;
  1327. }
  1328. /* 5 GHz, channels 100..144 */
  1329. if (freq >= 5500 && freq <= 5720) {
  1330. if (vht_opclass) {
  1331. *op_class = vht_opclass;
  1332. } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
  1333. if (freq > chandef->chan->center_freq)
  1334. *op_class = 122;
  1335. else
  1336. *op_class = 123;
  1337. } else {
  1338. *op_class = 121;
  1339. }
  1340. return true;
  1341. }
  1342. /* 5 GHz, channels 149..169 */
  1343. if (freq >= 5745 && freq <= 5845) {
  1344. if (vht_opclass) {
  1345. *op_class = vht_opclass;
  1346. } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
  1347. if (freq > chandef->chan->center_freq)
  1348. *op_class = 126;
  1349. else
  1350. *op_class = 127;
  1351. } else if (freq <= 5805) {
  1352. *op_class = 124;
  1353. } else {
  1354. *op_class = 125;
  1355. }
  1356. return true;
  1357. }
  1358. /* 56.16 GHz, channel 1..4 */
  1359. if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 4) {
  1360. if (chandef->width >= NL80211_CHAN_WIDTH_40)
  1361. return false;
  1362. *op_class = 180;
  1363. return true;
  1364. }
  1365. /* not supported yet */
  1366. return false;
  1367. }
  1368. EXPORT_SYMBOL(ieee80211_chandef_to_operating_class);
  1369. static void cfg80211_calculate_bi_data(struct wiphy *wiphy, u32 new_beacon_int,
  1370. u32 *beacon_int_gcd,
  1371. bool *beacon_int_different)
  1372. {
  1373. struct wireless_dev *wdev;
  1374. *beacon_int_gcd = 0;
  1375. *beacon_int_different = false;
  1376. list_for_each_entry(wdev, &wiphy->wdev_list, list) {
  1377. if (!wdev->beacon_interval)
  1378. continue;
  1379. if (!*beacon_int_gcd) {
  1380. *beacon_int_gcd = wdev->beacon_interval;
  1381. continue;
  1382. }
  1383. if (wdev->beacon_interval == *beacon_int_gcd)
  1384. continue;
  1385. *beacon_int_different = true;
  1386. *beacon_int_gcd = gcd(*beacon_int_gcd, wdev->beacon_interval);
  1387. }
  1388. if (new_beacon_int && *beacon_int_gcd != new_beacon_int) {
  1389. if (*beacon_int_gcd)
  1390. *beacon_int_different = true;
  1391. *beacon_int_gcd = gcd(*beacon_int_gcd, new_beacon_int);
  1392. }
  1393. }
  1394. int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
  1395. enum nl80211_iftype iftype, u32 beacon_int)
  1396. {
  1397. /*
  1398. * This is just a basic pre-condition check; if interface combinations
  1399. * are possible the driver must already be checking those with a call
  1400. * to cfg80211_check_combinations(), in which case we'll validate more
  1401. * through the cfg80211_calculate_bi_data() call and code in
  1402. * cfg80211_iter_combinations().
  1403. */
  1404. if (beacon_int < 10 || beacon_int > 10000)
  1405. return -EINVAL;
  1406. return 0;
  1407. }
  1408. int cfg80211_iter_combinations(struct wiphy *wiphy,
  1409. struct iface_combination_params *params,
  1410. void (*iter)(const struct ieee80211_iface_combination *c,
  1411. void *data),
  1412. void *data)
  1413. {
  1414. const struct ieee80211_regdomain *regdom;
  1415. enum nl80211_dfs_regions region = 0;
  1416. int i, j, iftype;
  1417. int num_interfaces = 0;
  1418. u32 used_iftypes = 0;
  1419. u32 beacon_int_gcd;
  1420. bool beacon_int_different;
  1421. /*
  1422. * This is a bit strange, since the iteration used to rely only on
  1423. * the data given by the driver, but here it now relies on context,
  1424. * in form of the currently operating interfaces.
  1425. * This is OK for all current users, and saves us from having to
  1426. * push the GCD calculations into all the drivers.
  1427. * In the future, this should probably rely more on data that's in
  1428. * cfg80211 already - the only thing not would appear to be any new
  1429. * interfaces (while being brought up) and channel/radar data.
  1430. */
  1431. cfg80211_calculate_bi_data(wiphy, params->new_beacon_int,
  1432. &beacon_int_gcd, &beacon_int_different);
  1433. if (params->radar_detect) {
  1434. rcu_read_lock();
  1435. regdom = rcu_dereference(cfg80211_regdomain);
  1436. if (regdom)
  1437. region = regdom->dfs_region;
  1438. rcu_read_unlock();
  1439. }
  1440. for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
  1441. num_interfaces += params->iftype_num[iftype];
  1442. if (params->iftype_num[iftype] > 0 &&
  1443. !(wiphy->software_iftypes & BIT(iftype)))
  1444. used_iftypes |= BIT(iftype);
  1445. }
  1446. for (i = 0; i < wiphy->n_iface_combinations; i++) {
  1447. const struct ieee80211_iface_combination *c;
  1448. struct ieee80211_iface_limit *limits;
  1449. u32 all_iftypes = 0;
  1450. c = &wiphy->iface_combinations[i];
  1451. if (num_interfaces > c->max_interfaces)
  1452. continue;
  1453. if (params->num_different_channels > c->num_different_channels)
  1454. continue;
  1455. limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
  1456. GFP_KERNEL);
  1457. if (!limits)
  1458. return -ENOMEM;
  1459. for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
  1460. if (wiphy->software_iftypes & BIT(iftype))
  1461. continue;
  1462. for (j = 0; j < c->n_limits; j++) {
  1463. all_iftypes |= limits[j].types;
  1464. if (!(limits[j].types & BIT(iftype)))
  1465. continue;
  1466. if (limits[j].max < params->iftype_num[iftype])
  1467. goto cont;
  1468. limits[j].max -= params->iftype_num[iftype];
  1469. }
  1470. }
  1471. if (params->radar_detect !=
  1472. (c->radar_detect_widths & params->radar_detect))
  1473. goto cont;
  1474. if (params->radar_detect && c->radar_detect_regions &&
  1475. !(c->radar_detect_regions & BIT(region)))
  1476. goto cont;
  1477. /* Finally check that all iftypes that we're currently
  1478. * using are actually part of this combination. If they
  1479. * aren't then we can't use this combination and have
  1480. * to continue to the next.
  1481. */
  1482. if ((all_iftypes & used_iftypes) != used_iftypes)
  1483. goto cont;
  1484. if (beacon_int_gcd) {
  1485. if (c->beacon_int_min_gcd &&
  1486. beacon_int_gcd < c->beacon_int_min_gcd)
  1487. goto cont;
  1488. if (!c->beacon_int_min_gcd && beacon_int_different)
  1489. goto cont;
  1490. }
  1491. /* This combination covered all interface types and
  1492. * supported the requested numbers, so we're good.
  1493. */
  1494. (*iter)(c, data);
  1495. cont:
  1496. kfree(limits);
  1497. }
  1498. return 0;
  1499. }
  1500. EXPORT_SYMBOL(cfg80211_iter_combinations);
  1501. static void
  1502. cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination *c,
  1503. void *data)
  1504. {
  1505. int *num = data;
  1506. (*num)++;
  1507. }
  1508. int cfg80211_check_combinations(struct wiphy *wiphy,
  1509. struct iface_combination_params *params)
  1510. {
  1511. int err, num = 0;
  1512. err = cfg80211_iter_combinations(wiphy, params,
  1513. cfg80211_iter_sum_ifcombs, &num);
  1514. if (err)
  1515. return err;
  1516. if (num == 0)
  1517. return -EBUSY;
  1518. return 0;
  1519. }
  1520. EXPORT_SYMBOL(cfg80211_check_combinations);
  1521. int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
  1522. const u8 *rates, unsigned int n_rates,
  1523. u32 *mask)
  1524. {
  1525. int i, j;
  1526. if (!sband)
  1527. return -EINVAL;
  1528. if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES)
  1529. return -EINVAL;
  1530. *mask = 0;
  1531. for (i = 0; i < n_rates; i++) {
  1532. int rate = (rates[i] & 0x7f) * 5;
  1533. bool found = false;
  1534. for (j = 0; j < sband->n_bitrates; j++) {
  1535. if (sband->bitrates[j].bitrate == rate) {
  1536. found = true;
  1537. *mask |= BIT(j);
  1538. break;
  1539. }
  1540. }
  1541. if (!found)
  1542. return -EINVAL;
  1543. }
  1544. /*
  1545. * mask must have at least one bit set here since we
  1546. * didn't accept a 0-length rates array nor allowed
  1547. * entries in the array that didn't exist
  1548. */
  1549. return 0;
  1550. }
  1551. unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy)
  1552. {
  1553. enum nl80211_band band;
  1554. unsigned int n_channels = 0;
  1555. for (band = 0; band < NUM_NL80211_BANDS; band++)
  1556. if (wiphy->bands[band])
  1557. n_channels += wiphy->bands[band]->n_channels;
  1558. return n_channels;
  1559. }
  1560. EXPORT_SYMBOL(ieee80211_get_num_supported_channels);
  1561. int cfg80211_get_station(struct net_device *dev, const u8 *mac_addr,
  1562. struct station_info *sinfo)
  1563. {
  1564. struct cfg80211_registered_device *rdev;
  1565. struct wireless_dev *wdev;
  1566. wdev = dev->ieee80211_ptr;
  1567. if (!wdev)
  1568. return -EOPNOTSUPP;
  1569. rdev = wiphy_to_rdev(wdev->wiphy);
  1570. if (!rdev->ops->get_station)
  1571. return -EOPNOTSUPP;
  1572. return rdev_get_station(rdev, dev, mac_addr, sinfo);
  1573. }
  1574. EXPORT_SYMBOL(cfg80211_get_station);
  1575. void cfg80211_free_nan_func(struct cfg80211_nan_func *f)
  1576. {
  1577. int i;
  1578. if (!f)
  1579. return;
  1580. kfree(f->serv_spec_info);
  1581. kfree(f->srf_bf);
  1582. kfree(f->srf_macs);
  1583. for (i = 0; i < f->num_rx_filters; i++)
  1584. kfree(f->rx_filters[i].filter);
  1585. for (i = 0; i < f->num_tx_filters; i++)
  1586. kfree(f->tx_filters[i].filter);
  1587. kfree(f->rx_filters);
  1588. kfree(f->tx_filters);
  1589. kfree(f);
  1590. }
  1591. EXPORT_SYMBOL(cfg80211_free_nan_func);
  1592. bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range,
  1593. u32 center_freq_khz, u32 bw_khz)
  1594. {
  1595. u32 start_freq_khz, end_freq_khz;
  1596. start_freq_khz = center_freq_khz - (bw_khz / 2);
  1597. end_freq_khz = center_freq_khz + (bw_khz / 2);
  1598. if (start_freq_khz >= freq_range->start_freq_khz &&
  1599. end_freq_khz <= freq_range->end_freq_khz)
  1600. return true;
  1601. return false;
  1602. }
  1603. /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
  1604. /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
  1605. const unsigned char rfc1042_header[] __aligned(2) =
  1606. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  1607. EXPORT_SYMBOL(rfc1042_header);
  1608. /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
  1609. const unsigned char bridge_tunnel_header[] __aligned(2) =
  1610. { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
  1611. EXPORT_SYMBOL(bridge_tunnel_header);