blob: 5618888853b24ffdac2853509a1528f70ac1661b [file] [log] [blame]
Johannes Berg8318d782008-01-24 19:38:38 +01001/*
2 * Wireless utility functions
3 *
Johannes Bergd3236552009-04-20 14:31:42 +02004 * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg8318d782008-01-24 19:38:38 +01005 */
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -04006#include <linux/export.h>
Johannes Bergd3236552009-04-20 14:31:42 +02007#include <linux/bitops.h>
Zhu Yie31a16d2009-05-21 21:47:03 +08008#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Johannes Bergd3236552009-04-20 14:31:42 +020010#include <net/cfg80211.h>
Zhu Yie31a16d2009-05-21 21:47:03 +080011#include <net/ip.h>
Dave Tähtb1565792011-12-22 12:55:08 -080012#include <net/dsfield.h>
cedric Vonckenc6ca5e22013-08-26 14:04:52 +020013#include <linux/if_vlan.h>
Johannes Berg8318d782008-01-24 19:38:38 +010014#include "core.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030015#include "rdev-ops.h"
16
Johannes Berg8318d782008-01-24 19:38:38 +010017
Johannes Bergbd815252008-10-29 20:00:45 +010018struct ieee80211_rate *
19ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +010020 u32 basic_rates, int bitrate)
Johannes Bergbd815252008-10-29 20:00:45 +010021{
22 struct ieee80211_rate *result = &sband->bitrates[0];
23 int i;
24
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
33 return result;
34}
35EXPORT_SYMBOL(ieee80211_get_response_rate);
36
Simon Wunderlich74608ac2013-07-08 16:55:54 +020037u32 ieee80211_mandatory_rates(struct ieee80211_supported_band *sband,
38 enum nl80211_bss_scan_width scan_width)
Ashok Nagarajanb422c6c2013-05-10 17:50:51 -070039{
40 struct ieee80211_rate *bitrates;
41 u32 mandatory_rates = 0;
42 enum ieee80211_rate_flags mandatory_flag;
43 int i;
44
45 if (WARN_ON(!sband))
46 return 1;
47
Simon Wunderlich74608ac2013-07-08 16:55:54 +020048 if (sband->band == IEEE80211_BAND_2GHZ) {
49 if (scan_width == NL80211_BSS_CHAN_WIDTH_5 ||
50 scan_width == NL80211_BSS_CHAN_WIDTH_10)
51 mandatory_flag = IEEE80211_RATE_MANDATORY_G;
52 else
53 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
54 } else {
Ashok Nagarajanb422c6c2013-05-10 17:50:51 -070055 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
Simon Wunderlich74608ac2013-07-08 16:55:54 +020056 }
Ashok Nagarajanb422c6c2013-05-10 17:50:51 -070057
58 bitrates = sband->bitrates;
59 for (i = 0; i < sband->n_bitrates; i++)
60 if (bitrates[i].flags & mandatory_flag)
61 mandatory_rates |= BIT(i);
62 return mandatory_rates;
63}
64EXPORT_SYMBOL(ieee80211_mandatory_rates);
65
Bruno Randolf59eb21a2011-01-17 13:37:28 +090066int ieee80211_channel_to_frequency(int chan, enum ieee80211_band band)
Johannes Berg8318d782008-01-24 19:38:38 +010067{
Bruno Randolf59eb21a2011-01-17 13:37:28 +090068 /* see 802.11 17.3.8.3.2 and Annex J
69 * there are overlapping channel numbers in 5GHz and 2GHz bands */
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +030070 if (chan <= 0)
71 return 0; /* not supported */
72 switch (band) {
73 case IEEE80211_BAND_2GHZ:
Bruno Randolf59eb21a2011-01-17 13:37:28 +090074 if (chan == 14)
75 return 2484;
76 else if (chan < 14)
77 return 2407 + chan * 5;
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +030078 break;
79 case IEEE80211_BAND_5GHZ:
80 if (chan >= 182 && chan <= 196)
81 return 4000 + chan * 5;
Bruno Randolf59eb21a2011-01-17 13:37:28 +090082 else
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +030083 return 5000 + chan * 5;
84 break;
85 case IEEE80211_BAND_60GHZ:
86 if (chan < 5)
87 return 56160 + chan * 2160;
88 break;
89 default:
90 ;
Bruno Randolf59eb21a2011-01-17 13:37:28 +090091 }
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +030092 return 0; /* not supported */
Johannes Berg8318d782008-01-24 19:38:38 +010093}
94EXPORT_SYMBOL(ieee80211_channel_to_frequency);
95
96int ieee80211_frequency_to_channel(int freq)
97{
Bruno Randolf59eb21a2011-01-17 13:37:28 +090098 /* see 802.11 17.3.8.3.2 and Annex J */
Johannes Berg8318d782008-01-24 19:38:38 +010099 if (freq == 2484)
100 return 14;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900101 else if (freq < 2484)
Johannes Berg8318d782008-01-24 19:38:38 +0100102 return (freq - 2407) / 5;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900103 else if (freq >= 4910 && freq <= 4980)
104 return (freq - 4000) / 5;
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +0300105 else if (freq <= 45000) /* DMG band lower limit */
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900106 return (freq - 5000) / 5;
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +0300107 else if (freq >= 58320 && freq <= 64800)
108 return (freq - 56160) / 2160;
109 else
110 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100111}
112EXPORT_SYMBOL(ieee80211_frequency_to_channel);
113
Johannes Berg6c507cd2008-03-26 14:14:55 +0100114struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
115 int freq)
Johannes Berg906c7302008-03-16 18:34:33 +0100116{
117 enum ieee80211_band band;
118 struct ieee80211_supported_band *sband;
119 int i;
120
121 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
122 sband = wiphy->bands[band];
123
124 if (!sband)
125 continue;
126
127 for (i = 0; i < sband->n_channels; i++) {
128 if (sband->channels[i].center_freq == freq)
129 return &sband->channels[i];
130 }
131 }
132
133 return NULL;
134}
Johannes Berg6c507cd2008-03-26 14:14:55 +0100135EXPORT_SYMBOL(__ieee80211_get_channel);
Johannes Berg906c7302008-03-16 18:34:33 +0100136
Johannes Berg8318d782008-01-24 19:38:38 +0100137static void set_mandatory_flags_band(struct ieee80211_supported_band *sband,
138 enum ieee80211_band band)
139{
140 int i, want;
141
142 switch (band) {
143 case IEEE80211_BAND_5GHZ:
144 want = 3;
145 for (i = 0; i < sband->n_bitrates; i++) {
146 if (sband->bitrates[i].bitrate == 60 ||
147 sband->bitrates[i].bitrate == 120 ||
148 sband->bitrates[i].bitrate == 240) {
149 sband->bitrates[i].flags |=
150 IEEE80211_RATE_MANDATORY_A;
151 want--;
152 }
153 }
154 WARN_ON(want);
155 break;
156 case IEEE80211_BAND_2GHZ:
157 want = 7;
158 for (i = 0; i < sband->n_bitrates; i++) {
159 if (sband->bitrates[i].bitrate == 10) {
160 sband->bitrates[i].flags |=
161 IEEE80211_RATE_MANDATORY_B |
162 IEEE80211_RATE_MANDATORY_G;
163 want--;
164 }
165
166 if (sband->bitrates[i].bitrate == 20 ||
167 sband->bitrates[i].bitrate == 55 ||
168 sband->bitrates[i].bitrate == 110 ||
169 sband->bitrates[i].bitrate == 60 ||
170 sband->bitrates[i].bitrate == 120 ||
171 sband->bitrates[i].bitrate == 240) {
172 sband->bitrates[i].flags |=
173 IEEE80211_RATE_MANDATORY_G;
174 want--;
175 }
176
Johannes Bergaac09fb2008-01-30 17:36:10 +0100177 if (sband->bitrates[i].bitrate != 10 &&
178 sband->bitrates[i].bitrate != 20 &&
179 sband->bitrates[i].bitrate != 55 &&
180 sband->bitrates[i].bitrate != 110)
Johannes Berg8318d782008-01-24 19:38:38 +0100181 sband->bitrates[i].flags |=
182 IEEE80211_RATE_ERP_G;
183 }
Ivo van Doorn406f2382008-02-02 23:53:10 +0100184 WARN_ON(want != 0 && want != 3 && want != 6);
Johannes Berg8318d782008-01-24 19:38:38 +0100185 break;
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +0300186 case IEEE80211_BAND_60GHZ:
187 /* check for mandatory HT MCS 1..4 */
188 WARN_ON(!sband->ht_cap.ht_supported);
189 WARN_ON((sband->ht_cap.mcs.rx_mask[0] & 0x1e) != 0x1e);
190 break;
Johannes Berg8318d782008-01-24 19:38:38 +0100191 case IEEE80211_NUM_BANDS:
192 WARN_ON(1);
193 break;
194 }
195}
196
197void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
198{
199 enum ieee80211_band band;
200
201 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
202 if (wiphy->bands[band])
203 set_mandatory_flags_band(wiphy->bands[band], band);
204}
Johannes Berg08645122009-05-11 13:54:58 +0200205
Jouni Malinen38ba3c52011-09-21 18:14:56 +0300206bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher)
207{
208 int i;
209 for (i = 0; i < wiphy->n_cipher_suites; i++)
210 if (cipher == wiphy->cipher_suites[i])
211 return true;
212 return false;
213}
214
Johannes Bergfffd0932009-07-08 14:22:54 +0200215int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
216 struct key_params *params, int key_idx,
Johannes Berge31b8212010-10-05 19:39:30 +0200217 bool pairwise, const u8 *mac_addr)
Johannes Berg08645122009-05-11 13:54:58 +0200218{
219 if (key_idx > 5)
220 return -EINVAL;
221
Johannes Berge31b8212010-10-05 19:39:30 +0200222 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
223 return -EINVAL;
224
225 if (pairwise && !mac_addr)
226 return -EINVAL;
227
Johannes Berg08645122009-05-11 13:54:58 +0200228 /*
229 * Disallow pairwise keys with non-zero index unless it's WEP
Juuso Oikarinen45cbad62011-01-25 12:21:22 +0200230 * or a vendor specific cipher (because current deployments use
231 * pairwise WEP keys with non-zero indices and for vendor specific
232 * ciphers this should be validated in the driver or hardware level
233 * - but 802.11i clearly specifies to use zero)
Johannes Berg08645122009-05-11 13:54:58 +0200234 */
Johannes Berge31b8212010-10-05 19:39:30 +0200235 if (pairwise && key_idx &&
Juuso Oikarinen45cbad62011-01-25 12:21:22 +0200236 ((params->cipher == WLAN_CIPHER_SUITE_TKIP) ||
237 (params->cipher == WLAN_CIPHER_SUITE_CCMP) ||
238 (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC)))
Johannes Berg08645122009-05-11 13:54:58 +0200239 return -EINVAL;
240
Johannes Berg08645122009-05-11 13:54:58 +0200241 switch (params->cipher) {
242 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200243 if (params->key_len != WLAN_KEY_LEN_WEP40)
Johannes Berg08645122009-05-11 13:54:58 +0200244 return -EINVAL;
245 break;
246 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200247 if (params->key_len != WLAN_KEY_LEN_TKIP)
Johannes Berg08645122009-05-11 13:54:58 +0200248 return -EINVAL;
249 break;
250 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200251 if (params->key_len != WLAN_KEY_LEN_CCMP)
Johannes Berg08645122009-05-11 13:54:58 +0200252 return -EINVAL;
253 break;
254 case WLAN_CIPHER_SUITE_WEP104:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200255 if (params->key_len != WLAN_KEY_LEN_WEP104)
Johannes Berg08645122009-05-11 13:54:58 +0200256 return -EINVAL;
257 break;
258 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200259 if (params->key_len != WLAN_KEY_LEN_AES_CMAC)
Johannes Berg08645122009-05-11 13:54:58 +0200260 return -EINVAL;
261 break;
262 default:
Johannes Berg7d64b7c2010-08-27 14:26:51 +0300263 /*
264 * We don't know anything about this algorithm,
265 * allow using it -- but the driver must check
266 * all parameters! We still check below whether
267 * or not the driver supports this algorithm,
268 * of course.
269 */
270 break;
Johannes Berg08645122009-05-11 13:54:58 +0200271 }
272
Jouni Malinen9f26a952009-05-15 12:38:32 +0300273 if (params->seq) {
274 switch (params->cipher) {
275 case WLAN_CIPHER_SUITE_WEP40:
276 case WLAN_CIPHER_SUITE_WEP104:
277 /* These ciphers do not use key sequence */
278 return -EINVAL;
279 case WLAN_CIPHER_SUITE_TKIP:
280 case WLAN_CIPHER_SUITE_CCMP:
281 case WLAN_CIPHER_SUITE_AES_CMAC:
282 if (params->seq_len != 6)
283 return -EINVAL;
284 break;
285 }
286 }
287
Jouni Malinen38ba3c52011-09-21 18:14:56 +0300288 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher))
Johannes Bergfffd0932009-07-08 14:22:54 +0200289 return -EINVAL;
290
Johannes Berg08645122009-05-11 13:54:58 +0200291 return 0;
292}
Zhu Yie31a16d2009-05-21 21:47:03 +0800293
Johannes Berg633adf12010-08-12 14:49:58 +0200294unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc)
Zhu Yie31a16d2009-05-21 21:47:03 +0800295{
296 unsigned int hdrlen = 24;
297
298 if (ieee80211_is_data(fc)) {
299 if (ieee80211_has_a4(fc))
300 hdrlen = 30;
Andriy Tkachukd0dd2de2010-01-20 13:55:06 +0200301 if (ieee80211_is_data_qos(fc)) {
Zhu Yie31a16d2009-05-21 21:47:03 +0800302 hdrlen += IEEE80211_QOS_CTL_LEN;
Andriy Tkachukd0dd2de2010-01-20 13:55:06 +0200303 if (ieee80211_has_order(fc))
304 hdrlen += IEEE80211_HT_CTL_LEN;
305 }
Zhu Yie31a16d2009-05-21 21:47:03 +0800306 goto out;
307 }
308
309 if (ieee80211_is_ctl(fc)) {
310 /*
311 * ACK and CTS are 10 bytes, all others 16. To see how
312 * to get this condition consider
313 * subtype mask: 0b0000000011110000 (0x00F0)
314 * ACK subtype: 0b0000000011010000 (0x00D0)
315 * CTS subtype: 0b0000000011000000 (0x00C0)
316 * bits that matter: ^^^ (0x00E0)
317 * value of those: 0b0000000011000000 (0x00C0)
318 */
319 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
320 hdrlen = 10;
321 else
322 hdrlen = 16;
323 }
324out:
325 return hdrlen;
326}
327EXPORT_SYMBOL(ieee80211_hdrlen);
328
329unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
330{
331 const struct ieee80211_hdr *hdr =
332 (const struct ieee80211_hdr *)skb->data;
333 unsigned int hdrlen;
334
335 if (unlikely(skb->len < 10))
336 return 0;
337 hdrlen = ieee80211_hdrlen(hdr->frame_control);
338 if (unlikely(hdrlen > skb->len))
339 return 0;
340 return hdrlen;
341}
342EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
343
Johannes Berg9b395bc2012-10-26 00:36:40 +0200344unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
Zhu Yie31a16d2009-05-21 21:47:03 +0800345{
346 int ae = meshhdr->flags & MESH_FLAGS_AE;
Johannes Berg7dd111e2012-10-25 21:51:59 +0200347 /* 802.11-2012, 8.2.4.7.3 */
Zhu Yie31a16d2009-05-21 21:47:03 +0800348 switch (ae) {
Johannes Berg7dd111e2012-10-25 21:51:59 +0200349 default:
Zhu Yie31a16d2009-05-21 21:47:03 +0800350 case 0:
351 return 6;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700352 case MESH_FLAGS_AE_A4:
Zhu Yie31a16d2009-05-21 21:47:03 +0800353 return 12;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700354 case MESH_FLAGS_AE_A5_A6:
Zhu Yie31a16d2009-05-21 21:47:03 +0800355 return 18;
Zhu Yie31a16d2009-05-21 21:47:03 +0800356 }
357}
Johannes Berg9b395bc2012-10-26 00:36:40 +0200358EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
Zhu Yie31a16d2009-05-21 21:47:03 +0800359
Zhu Yieaf85ca2009-12-01 10:18:37 +0800360int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
Zhu Yie31a16d2009-05-21 21:47:03 +0800361 enum nl80211_iftype iftype)
362{
363 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
364 u16 hdrlen, ethertype;
365 u8 *payload;
366 u8 dst[ETH_ALEN];
367 u8 src[ETH_ALEN] __aligned(2);
368
369 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
370 return -1;
371
372 hdrlen = ieee80211_hdrlen(hdr->frame_control);
373
374 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
375 * header
376 * IEEE 802.11 address fields:
377 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
378 * 0 0 DA SA BSSID n/a
379 * 0 1 DA BSSID SA n/a
380 * 1 0 BSSID SA DA n/a
381 * 1 1 RA TA DA SA
382 */
383 memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
384 memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
385
386 switch (hdr->frame_control &
387 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
388 case cpu_to_le16(IEEE80211_FCTL_TODS):
389 if (unlikely(iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +0200390 iftype != NL80211_IFTYPE_AP_VLAN &&
391 iftype != NL80211_IFTYPE_P2P_GO))
Zhu Yie31a16d2009-05-21 21:47:03 +0800392 return -1;
393 break;
394 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
395 if (unlikely(iftype != NL80211_IFTYPE_WDS &&
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100396 iftype != NL80211_IFTYPE_MESH_POINT &&
397 iftype != NL80211_IFTYPE_AP_VLAN &&
398 iftype != NL80211_IFTYPE_STATION))
Zhu Yie31a16d2009-05-21 21:47:03 +0800399 return -1;
400 if (iftype == NL80211_IFTYPE_MESH_POINT) {
401 struct ieee80211s_hdr *meshdr =
402 (struct ieee80211s_hdr *) (skb->data + hdrlen);
Zhu Yie3cf8b32010-03-29 17:35:07 +0800403 /* make sure meshdr->flags is on the linear part */
404 if (!pskb_may_pull(skb, hdrlen + 1))
405 return -1;
Johannes Berg7dd111e2012-10-25 21:51:59 +0200406 if (meshdr->flags & MESH_FLAGS_AE_A4)
407 return -1;
Zhu Yie31a16d2009-05-21 21:47:03 +0800408 if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
Zhu Yie3cf8b32010-03-29 17:35:07 +0800409 skb_copy_bits(skb, hdrlen +
410 offsetof(struct ieee80211s_hdr, eaddr1),
411 dst, ETH_ALEN);
412 skb_copy_bits(skb, hdrlen +
413 offsetof(struct ieee80211s_hdr, eaddr2),
414 src, ETH_ALEN);
Zhu Yie31a16d2009-05-21 21:47:03 +0800415 }
Zhu Yie3cf8b32010-03-29 17:35:07 +0800416 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
Zhu Yie31a16d2009-05-21 21:47:03 +0800417 }
418 break;
419 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
Javier Cardona3c5772a2009-08-10 12:15:48 -0700420 if ((iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +0200421 iftype != NL80211_IFTYPE_P2P_CLIENT &&
422 iftype != NL80211_IFTYPE_MESH_POINT) ||
Zhu Yie31a16d2009-05-21 21:47:03 +0800423 (is_multicast_ether_addr(dst) &&
Joe Perches4c764722012-05-08 18:56:56 +0000424 ether_addr_equal(src, addr)))
Zhu Yie31a16d2009-05-21 21:47:03 +0800425 return -1;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700426 if (iftype == NL80211_IFTYPE_MESH_POINT) {
427 struct ieee80211s_hdr *meshdr =
428 (struct ieee80211s_hdr *) (skb->data + hdrlen);
Zhu Yie3cf8b32010-03-29 17:35:07 +0800429 /* make sure meshdr->flags is on the linear part */
430 if (!pskb_may_pull(skb, hdrlen + 1))
431 return -1;
Johannes Berg7dd111e2012-10-25 21:51:59 +0200432 if (meshdr->flags & MESH_FLAGS_AE_A5_A6)
433 return -1;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700434 if (meshdr->flags & MESH_FLAGS_AE_A4)
Zhu Yie3cf8b32010-03-29 17:35:07 +0800435 skb_copy_bits(skb, hdrlen +
436 offsetof(struct ieee80211s_hdr, eaddr1),
437 src, ETH_ALEN);
438 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
Javier Cardona3c5772a2009-08-10 12:15:48 -0700439 }
Zhu Yie31a16d2009-05-21 21:47:03 +0800440 break;
441 case cpu_to_le16(0):
Arik Nemtsov941c93c2011-09-28 14:12:54 +0300442 if (iftype != NL80211_IFTYPE_ADHOC &&
443 iftype != NL80211_IFTYPE_STATION)
444 return -1;
Zhu Yie31a16d2009-05-21 21:47:03 +0800445 break;
446 }
447
Zhu Yie3cf8b32010-03-29 17:35:07 +0800448 if (!pskb_may_pull(skb, hdrlen + 8))
Zhu Yie31a16d2009-05-21 21:47:03 +0800449 return -1;
450
451 payload = skb->data + hdrlen;
452 ethertype = (payload[6] << 8) | payload[7];
453
Joe Perches4c764722012-05-08 18:56:56 +0000454 if (likely((ether_addr_equal(payload, rfc1042_header) &&
Zhu Yie31a16d2009-05-21 21:47:03 +0800455 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
Joe Perches4c764722012-05-08 18:56:56 +0000456 ether_addr_equal(payload, bridge_tunnel_header))) {
Zhu Yie31a16d2009-05-21 21:47:03 +0800457 /* remove RFC1042 or Bridge-Tunnel encapsulation and
458 * replace EtherType */
459 skb_pull(skb, hdrlen + 6);
460 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
461 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
462 } else {
463 struct ethhdr *ehdr;
464 __be16 len;
465
466 skb_pull(skb, hdrlen);
467 len = htons(skb->len);
468 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
469 memcpy(ehdr->h_dest, dst, ETH_ALEN);
470 memcpy(ehdr->h_source, src, ETH_ALEN);
471 ehdr->h_proto = len;
472 }
473 return 0;
474}
475EXPORT_SYMBOL(ieee80211_data_to_8023);
476
Zhu Yieaf85ca2009-12-01 10:18:37 +0800477int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
Zhu Yie31a16d2009-05-21 21:47:03 +0800478 enum nl80211_iftype iftype, u8 *bssid, bool qos)
479{
480 struct ieee80211_hdr hdr;
481 u16 hdrlen, ethertype;
482 __le16 fc;
483 const u8 *encaps_data;
484 int encaps_len, skip_header_bytes;
485 int nh_pos, h_pos;
486 int head_need;
487
488 if (unlikely(skb->len < ETH_HLEN))
489 return -EINVAL;
490
491 nh_pos = skb_network_header(skb) - skb->data;
492 h_pos = skb_transport_header(skb) - skb->data;
493
494 /* convert Ethernet header to proper 802.11 header (based on
495 * operation mode) */
496 ethertype = (skb->data[12] << 8) | skb->data[13];
497 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
498
499 switch (iftype) {
500 case NL80211_IFTYPE_AP:
501 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200502 case NL80211_IFTYPE_P2P_GO:
Zhu Yie31a16d2009-05-21 21:47:03 +0800503 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:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200511 case NL80211_IFTYPE_P2P_CLIENT:
Zhu Yie31a16d2009-05-21 21:47:03 +0800512 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_ADHOC:
520 /* DA SA BSSID */
521 memcpy(hdr.addr1, skb->data, ETH_ALEN);
522 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
523 memcpy(hdr.addr3, bssid, ETH_ALEN);
524 hdrlen = 24;
525 break;
526 default:
527 return -EOPNOTSUPP;
528 }
529
530 if (qos) {
531 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
532 hdrlen += 2;
533 }
534
535 hdr.frame_control = fc;
536 hdr.duration_id = 0;
537 hdr.seq_ctrl = 0;
538
539 skip_header_bytes = ETH_HLEN;
540 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
541 encaps_data = bridge_tunnel_header;
542 encaps_len = sizeof(bridge_tunnel_header);
543 skip_header_bytes -= 2;
Simon Hormane5c5d222013-03-28 13:38:25 +0900544 } else if (ethertype >= ETH_P_802_3_MIN) {
Zhu Yie31a16d2009-05-21 21:47:03 +0800545 encaps_data = rfc1042_header;
546 encaps_len = sizeof(rfc1042_header);
547 skip_header_bytes -= 2;
548 } else {
549 encaps_data = NULL;
550 encaps_len = 0;
551 }
552
553 skb_pull(skb, skip_header_bytes);
554 nh_pos -= skip_header_bytes;
555 h_pos -= skip_header_bytes;
556
557 head_need = hdrlen + encaps_len - skb_headroom(skb);
558
559 if (head_need > 0 || skb_cloned(skb)) {
560 head_need = max(head_need, 0);
561 if (head_need)
562 skb_orphan(skb);
563
Joe Perches24616152011-08-29 14:17:41 -0700564 if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC))
Zhu Yie31a16d2009-05-21 21:47:03 +0800565 return -ENOMEM;
Joe Perches24616152011-08-29 14:17:41 -0700566
Zhu Yie31a16d2009-05-21 21:47:03 +0800567 skb->truesize += head_need;
568 }
569
570 if (encaps_data) {
571 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
572 nh_pos += encaps_len;
573 h_pos += encaps_len;
574 }
575
576 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
577
578 nh_pos += hdrlen;
579 h_pos += hdrlen;
580
581 /* Update skb pointers to various headers since this modified frame
582 * is going to go through Linux networking code that may potentially
583 * need things like pointer to IP header. */
584 skb_set_mac_header(skb, 0);
585 skb_set_network_header(skb, nh_pos);
586 skb_set_transport_header(skb, h_pos);
587
588 return 0;
589}
590EXPORT_SYMBOL(ieee80211_data_from_8023);
591
Zhu Yieaf85ca2009-12-01 10:18:37 +0800592
593void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
594 const u8 *addr, enum nl80211_iftype iftype,
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -0700595 const unsigned int extra_headroom,
596 bool has_80211_header)
Zhu Yieaf85ca2009-12-01 10:18:37 +0800597{
598 struct sk_buff *frame = NULL;
599 u16 ethertype;
600 u8 *payload;
601 const struct ethhdr *eth;
602 int remaining, err;
603 u8 dst[ETH_ALEN], src[ETH_ALEN];
604
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -0700605 if (has_80211_header) {
606 err = ieee80211_data_to_8023(skb, addr, iftype);
607 if (err)
608 goto out;
Zhu Yieaf85ca2009-12-01 10:18:37 +0800609
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -0700610 /* skip the wrapping header */
611 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
612 if (!eth)
613 goto out;
614 } else {
615 eth = (struct ethhdr *) skb->data;
616 }
Zhu Yieaf85ca2009-12-01 10:18:37 +0800617
618 while (skb != frame) {
619 u8 padding;
620 __be16 len = eth->h_proto;
621 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
622
623 remaining = skb->len;
624 memcpy(dst, eth->h_dest, ETH_ALEN);
625 memcpy(src, eth->h_source, ETH_ALEN);
626
627 padding = (4 - subframe_len) & 0x3;
628 /* the last MSDU has no padding */
629 if (subframe_len > remaining)
630 goto purge;
631
632 skb_pull(skb, sizeof(struct ethhdr));
633 /* reuse skb for the last subframe */
634 if (remaining <= subframe_len + padding)
635 frame = skb;
636 else {
637 unsigned int hlen = ALIGN(extra_headroom, 4);
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 + subframe_len + 2);
643 if (!frame)
644 goto purge;
645
646 skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
647 memcpy(skb_put(frame, ntohs(len)), skb->data,
648 ntohs(len));
649
650 eth = (struct ethhdr *)skb_pull(skb, ntohs(len) +
651 padding);
652 if (!eth) {
653 dev_kfree_skb(frame);
654 goto purge;
655 }
656 }
657
658 skb_reset_network_header(frame);
659 frame->dev = skb->dev;
660 frame->priority = skb->priority;
661
662 payload = frame->data;
663 ethertype = (payload[6] << 8) | payload[7];
664
Joe Perchesac422d32012-05-08 18:56:55 +0000665 if (likely((ether_addr_equal(payload, rfc1042_header) &&
Zhu Yieaf85ca2009-12-01 10:18:37 +0800666 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
Joe Perchesac422d32012-05-08 18:56:55 +0000667 ether_addr_equal(payload, bridge_tunnel_header))) {
Zhu Yieaf85ca2009-12-01 10:18:37 +0800668 /* remove RFC1042 or Bridge-Tunnel
669 * encapsulation and replace EtherType */
670 skb_pull(frame, 6);
671 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
672 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
673 } else {
674 memcpy(skb_push(frame, sizeof(__be16)), &len,
675 sizeof(__be16));
676 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
677 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
678 }
679 __skb_queue_tail(list, frame);
680 }
681
682 return;
683
684 purge:
685 __skb_queue_purge(list);
686 out:
687 dev_kfree_skb(skb);
688}
689EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
690
Zhu Yie31a16d2009-05-21 21:47:03 +0800691/* Given a data frame determine the 802.1p/1d tag to use. */
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800692unsigned int cfg80211_classify8021d(struct sk_buff *skb,
693 struct cfg80211_qos_map *qos_map)
Zhu Yie31a16d2009-05-21 21:47:03 +0800694{
695 unsigned int dscp;
cedric Vonckenc6ca5e22013-08-26 14:04:52 +0200696 unsigned char vlan_priority;
Zhu Yie31a16d2009-05-21 21:47:03 +0800697
698 /* skb->priority values from 256->263 are magic values to
699 * directly indicate a specific 802.1d priority. This is used
700 * to allow 802.1d priority to be passed directly in from VLAN
701 * tags, etc.
702 */
703 if (skb->priority >= 256 && skb->priority <= 263)
704 return skb->priority - 256;
705
cedric Vonckenc6ca5e22013-08-26 14:04:52 +0200706 if (vlan_tx_tag_present(skb)) {
707 vlan_priority = (vlan_tx_tag_get(skb) & VLAN_PRIO_MASK)
708 >> VLAN_PRIO_SHIFT;
709 if (vlan_priority > 0)
710 return vlan_priority;
711 }
712
Zhu Yie31a16d2009-05-21 21:47:03 +0800713 switch (skb->protocol) {
714 case htons(ETH_P_IP):
Dave Tähtb1565792011-12-22 12:55:08 -0800715 dscp = ipv4_get_dsfield(ip_hdr(skb)) & 0xfc;
716 break;
717 case htons(ETH_P_IPV6):
718 dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & 0xfc;
Zhu Yie31a16d2009-05-21 21:47:03 +0800719 break;
720 default:
721 return 0;
722 }
723
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800724 if (qos_map) {
725 unsigned int i, tmp_dscp = dscp >> 2;
726
727 for (i = 0; i < qos_map->num_des; i++) {
728 if (tmp_dscp == qos_map->dscp_exception[i].dscp)
729 return qos_map->dscp_exception[i].up;
730 }
731
732 for (i = 0; i < 8; i++) {
733 if (tmp_dscp >= qos_map->up[i].low &&
734 tmp_dscp <= qos_map->up[i].high)
735 return i;
736 }
737 }
738
Zhu Yie31a16d2009-05-21 21:47:03 +0800739 return dscp >> 5;
740}
741EXPORT_SYMBOL(cfg80211_classify8021d);
Johannes Berg517357c2009-07-02 17:18:40 +0200742
743const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
744{
Johannes Berg9caf0362012-11-29 01:25:20 +0100745 const struct cfg80211_bss_ies *ies;
746
747 ies = rcu_dereference(bss->ies);
748 if (!ies)
Johannes Berg517357c2009-07-02 17:18:40 +0200749 return NULL;
Johannes Berg9caf0362012-11-29 01:25:20 +0100750
751 return cfg80211_find_ie(ie, ies->data, ies->len);
Johannes Berg517357c2009-07-02 17:18:40 +0200752}
753EXPORT_SYMBOL(ieee80211_bss_get_ie);
Johannes Bergfffd0932009-07-08 14:22:54 +0200754
755void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
756{
757 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
758 struct net_device *dev = wdev->netdev;
759 int i;
760
761 if (!wdev->connect_keys)
762 return;
763
764 for (i = 0; i < 6; i++) {
765 if (!wdev->connect_keys->params[i].cipher)
766 continue;
Hila Gonene35e4d22012-06-27 17:19:42 +0300767 if (rdev_add_key(rdev, dev, i, false, NULL,
768 &wdev->connect_keys->params[i])) {
Joe Perchese9c02682010-11-16 19:56:49 -0800769 netdev_err(dev, "failed to set key %d\n", i);
Zhu Yi1e056662009-07-20 16:12:57 +0800770 continue;
771 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200772 if (wdev->connect_keys->def == i)
Hila Gonene35e4d22012-06-27 17:19:42 +0300773 if (rdev_set_default_key(rdev, dev, i, true, true)) {
Joe Perchese9c02682010-11-16 19:56:49 -0800774 netdev_err(dev, "failed to set defkey %d\n", i);
Zhu Yi1e056662009-07-20 16:12:57 +0800775 continue;
776 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200777 if (wdev->connect_keys->defmgmt == i)
Hila Gonene35e4d22012-06-27 17:19:42 +0300778 if (rdev_set_default_mgmt_key(rdev, dev, i))
Joe Perchese9c02682010-11-16 19:56:49 -0800779 netdev_err(dev, "failed to set mgtdef %d\n", i);
Johannes Bergfffd0932009-07-08 14:22:54 +0200780 }
781
782 kfree(wdev->connect_keys);
783 wdev->connect_keys = NULL;
784}
Johannes Berg3d54d252009-08-21 14:51:05 +0200785
Daniel Drake1f6fc432012-08-02 18:41:48 +0100786void cfg80211_process_wdev_events(struct wireless_dev *wdev)
Johannes Berg3d54d252009-08-21 14:51:05 +0200787{
788 struct cfg80211_event *ev;
789 unsigned long flags;
790 const u8 *bssid = NULL;
791
792 spin_lock_irqsave(&wdev->event_lock, flags);
793 while (!list_empty(&wdev->event_list)) {
794 ev = list_first_entry(&wdev->event_list,
795 struct cfg80211_event, list);
796 list_del(&ev->list);
797 spin_unlock_irqrestore(&wdev->event_lock, flags);
798
799 wdev_lock(wdev);
800 switch (ev->type) {
801 case EVENT_CONNECT_RESULT:
802 if (!is_zero_ether_addr(ev->cr.bssid))
803 bssid = ev->cr.bssid;
804 __cfg80211_connect_result(
805 wdev->netdev, bssid,
806 ev->cr.req_ie, ev->cr.req_ie_len,
807 ev->cr.resp_ie, ev->cr.resp_ie_len,
808 ev->cr.status,
809 ev->cr.status == WLAN_STATUS_SUCCESS,
810 NULL);
811 break;
812 case EVENT_ROAMED:
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530813 __cfg80211_roamed(wdev, ev->rm.bss, ev->rm.req_ie,
814 ev->rm.req_ie_len, ev->rm.resp_ie,
815 ev->rm.resp_ie_len);
Johannes Berg3d54d252009-08-21 14:51:05 +0200816 break;
817 case EVENT_DISCONNECTED:
818 __cfg80211_disconnected(wdev->netdev,
819 ev->dc.ie, ev->dc.ie_len,
820 ev->dc.reason, true);
821 break;
822 case EVENT_IBSS_JOINED:
823 __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
824 break;
825 }
826 wdev_unlock(wdev);
827
828 kfree(ev);
829
830 spin_lock_irqsave(&wdev->event_lock, flags);
831 }
832 spin_unlock_irqrestore(&wdev->event_lock, flags);
833}
834
835void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
836{
837 struct wireless_dev *wdev;
838
839 ASSERT_RTNL();
840 ASSERT_RDEV_LOCK(rdev);
841
Johannes Berg89a54e42012-06-15 14:33:17 +0200842 list_for_each_entry(wdev, &rdev->wdev_list, list)
Johannes Berg3d54d252009-08-21 14:51:05 +0200843 cfg80211_process_wdev_events(wdev);
Johannes Berg3d54d252009-08-21 14:51:05 +0200844}
845
846int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
847 struct net_device *dev, enum nl80211_iftype ntype,
848 u32 *flags, struct vif_params *params)
849{
850 int err;
851 enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
852
853 ASSERT_RDEV_LOCK(rdev);
854
855 /* don't support changing VLANs, you just re-create them */
856 if (otype == NL80211_IFTYPE_AP_VLAN)
857 return -EOPNOTSUPP;
858
Johannes Berg98104fde2012-06-16 00:19:54 +0200859 /* cannot change into P2P device type */
860 if (ntype == NL80211_IFTYPE_P2P_DEVICE)
861 return -EOPNOTSUPP;
862
Johannes Berg3d54d252009-08-21 14:51:05 +0200863 if (!rdev->ops->change_virtual_intf ||
864 !(rdev->wiphy.interface_modes & (1 << ntype)))
865 return -EOPNOTSUPP;
866
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100867 /* if it's part of a bridge, reject changing type to station/ibss */
Jiri Pirkof350a0a82010-06-15 06:50:45 +0000868 if ((dev->priv_flags & IFF_BRIDGE_PORT) &&
Johannes Berg074ac8d2010-09-16 14:58:22 +0200869 (ntype == NL80211_IFTYPE_ADHOC ||
870 ntype == NL80211_IFTYPE_STATION ||
871 ntype == NL80211_IFTYPE_P2P_CLIENT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100872 return -EBUSY;
873
Michal Kaziorf8cdddb2012-06-08 10:55:44 +0200874 if (ntype != otype && netif_running(dev)) {
Johannes Berg7527a782011-05-13 10:58:57 +0200875 err = cfg80211_can_change_interface(rdev, dev->ieee80211_ptr,
876 ntype);
877 if (err)
878 return err;
879
Johannes Berg9bc383d2009-11-19 11:55:19 +0100880 dev->ieee80211_ptr->use_4addr = false;
Johannes Berg29cbe682010-12-03 09:20:44 +0100881 dev->ieee80211_ptr->mesh_id_up_len = 0;
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800882 rdev_set_qos_map(rdev, dev, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +0100883
Johannes Berg3d54d252009-08-21 14:51:05 +0200884 switch (otype) {
Michal Kaziorac800142012-06-29 12:46:57 +0200885 case NL80211_IFTYPE_AP:
886 cfg80211_stop_ap(rdev, dev);
887 break;
Johannes Berg3d54d252009-08-21 14:51:05 +0200888 case NL80211_IFTYPE_ADHOC:
889 cfg80211_leave_ibss(rdev, dev, false);
890 break;
891 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200892 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg83739b02013-05-15 17:44:01 +0200893 wdev_lock(dev->ieee80211_ptr);
Johannes Berg3d54d252009-08-21 14:51:05 +0200894 cfg80211_disconnect(rdev, dev,
895 WLAN_REASON_DEAUTH_LEAVING, true);
Johannes Berg83739b02013-05-15 17:44:01 +0200896 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg3d54d252009-08-21 14:51:05 +0200897 break;
898 case NL80211_IFTYPE_MESH_POINT:
899 /* mesh should be handled? */
900 break;
901 default:
902 break;
903 }
904
905 cfg80211_process_rdev_events(rdev);
906 }
907
Hila Gonene35e4d22012-06-27 17:19:42 +0300908 err = rdev_change_virtual_intf(rdev, dev, ntype, flags, params);
Johannes Berg3d54d252009-08-21 14:51:05 +0200909
910 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
911
Johannes Berg9bc383d2009-11-19 11:55:19 +0100912 if (!err && params && params->use_4addr != -1)
913 dev->ieee80211_ptr->use_4addr = params->use_4addr;
914
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100915 if (!err) {
916 dev->priv_flags &= ~IFF_DONT_BRIDGE;
917 switch (ntype) {
918 case NL80211_IFTYPE_STATION:
919 if (dev->ieee80211_ptr->use_4addr)
920 break;
921 /* fall through */
Johannes Berg074ac8d2010-09-16 14:58:22 +0200922 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100923 case NL80211_IFTYPE_ADHOC:
924 dev->priv_flags |= IFF_DONT_BRIDGE;
925 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +0200926 case NL80211_IFTYPE_P2P_GO:
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100927 case NL80211_IFTYPE_AP:
928 case NL80211_IFTYPE_AP_VLAN:
929 case NL80211_IFTYPE_WDS:
930 case NL80211_IFTYPE_MESH_POINT:
931 /* bridging OK */
932 break;
933 case NL80211_IFTYPE_MONITOR:
934 /* monitor can't bridge anyway */
935 break;
936 case NL80211_IFTYPE_UNSPECIFIED:
Johannes Berg2e161f72010-08-12 15:38:38 +0200937 case NUM_NL80211_IFTYPES:
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100938 /* not happening */
939 break;
Johannes Berg98104fde2012-06-16 00:19:54 +0200940 case NL80211_IFTYPE_P2P_DEVICE:
941 WARN_ON(1);
942 break;
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100943 }
944 }
945
Michal Kaziordbbae262012-06-29 12:47:01 +0200946 if (!err && ntype != otype && netif_running(dev)) {
947 cfg80211_update_iface_num(rdev, ntype, 1);
948 cfg80211_update_iface_num(rdev, otype, -1);
949 }
950
Johannes Berg3d54d252009-08-21 14:51:05 +0200951 return err;
952}
John W. Linville254416a2009-12-09 16:43:52 -0500953
Vladimir Kondratiev95ddc1f2012-07-05 14:25:50 +0300954static u32 cfg80211_calculate_bitrate_60g(struct rate_info *rate)
955{
956 static const u32 __mcs2bitrate[] = {
957 /* control PHY */
958 [0] = 275,
959 /* SC PHY */
960 [1] = 3850,
961 [2] = 7700,
962 [3] = 9625,
963 [4] = 11550,
964 [5] = 12512, /* 1251.25 mbps */
965 [6] = 15400,
966 [7] = 19250,
967 [8] = 23100,
968 [9] = 25025,
969 [10] = 30800,
970 [11] = 38500,
971 [12] = 46200,
972 /* OFDM PHY */
973 [13] = 6930,
974 [14] = 8662, /* 866.25 mbps */
975 [15] = 13860,
976 [16] = 17325,
977 [17] = 20790,
978 [18] = 27720,
979 [19] = 34650,
980 [20] = 41580,
981 [21] = 45045,
982 [22] = 51975,
983 [23] = 62370,
984 [24] = 67568, /* 6756.75 mbps */
985 /* LP-SC PHY */
986 [25] = 6260,
987 [26] = 8340,
988 [27] = 11120,
989 [28] = 12510,
990 [29] = 16680,
991 [30] = 22240,
992 [31] = 25030,
993 };
994
995 if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate)))
996 return 0;
997
998 return __mcs2bitrate[rate->mcs];
999}
1000
Johannes Bergdb9c64c2012-11-09 14:56:41 +01001001static u32 cfg80211_calculate_bitrate_vht(struct rate_info *rate)
1002{
1003 static const u32 base[4][10] = {
1004 { 6500000,
1005 13000000,
1006 19500000,
1007 26000000,
1008 39000000,
1009 52000000,
1010 58500000,
1011 65000000,
1012 78000000,
1013 0,
1014 },
1015 { 13500000,
1016 27000000,
1017 40500000,
1018 54000000,
1019 81000000,
1020 108000000,
1021 121500000,
1022 135000000,
1023 162000000,
1024 180000000,
1025 },
1026 { 29300000,
1027 58500000,
1028 87800000,
1029 117000000,
1030 175500000,
1031 234000000,
1032 263300000,
1033 292500000,
1034 351000000,
1035 390000000,
1036 },
1037 { 58500000,
1038 117000000,
1039 175500000,
1040 234000000,
1041 351000000,
1042 468000000,
1043 526500000,
1044 585000000,
1045 702000000,
1046 780000000,
1047 },
1048 };
1049 u32 bitrate;
1050 int idx;
1051
1052 if (WARN_ON_ONCE(rate->mcs > 9))
1053 return 0;
1054
1055 idx = rate->flags & (RATE_INFO_FLAGS_160_MHZ_WIDTH |
1056 RATE_INFO_FLAGS_80P80_MHZ_WIDTH) ? 3 :
1057 rate->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH ? 2 :
1058 rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH ? 1 : 0;
1059
1060 bitrate = base[idx][rate->mcs];
1061 bitrate *= rate->nss;
1062
1063 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1064 bitrate = (bitrate / 9) * 10;
1065
1066 /* do NOT round down here */
1067 return (bitrate + 50000) / 100000;
1068}
1069
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03001070u32 cfg80211_calculate_bitrate(struct rate_info *rate)
John W. Linville254416a2009-12-09 16:43:52 -05001071{
1072 int modulation, streams, bitrate;
1073
Johannes Bergdb9c64c2012-11-09 14:56:41 +01001074 if (!(rate->flags & RATE_INFO_FLAGS_MCS) &&
1075 !(rate->flags & RATE_INFO_FLAGS_VHT_MCS))
John W. Linville254416a2009-12-09 16:43:52 -05001076 return rate->legacy;
Vladimir Kondratiev95ddc1f2012-07-05 14:25:50 +03001077 if (rate->flags & RATE_INFO_FLAGS_60G)
1078 return cfg80211_calculate_bitrate_60g(rate);
Johannes Bergdb9c64c2012-11-09 14:56:41 +01001079 if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
1080 return cfg80211_calculate_bitrate_vht(rate);
John W. Linville254416a2009-12-09 16:43:52 -05001081
1082 /* the formula below does only work for MCS values smaller than 32 */
Johannes Berg2615f372012-05-08 21:36:20 +02001083 if (WARN_ON_ONCE(rate->mcs >= 32))
John W. Linville254416a2009-12-09 16:43:52 -05001084 return 0;
1085
1086 modulation = rate->mcs & 7;
1087 streams = (rate->mcs >> 3) + 1;
1088
1089 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1090 13500000 : 6500000;
1091
1092 if (modulation < 4)
1093 bitrate *= (modulation + 1);
1094 else if (modulation == 4)
1095 bitrate *= (modulation + 2);
1096 else
1097 bitrate *= (modulation + 3);
1098
1099 bitrate *= streams;
1100
1101 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1102 bitrate = (bitrate / 9) * 10;
1103
1104 /* do NOT round down here */
1105 return (bitrate + 50000) / 100000;
1106}
Thomas Pedersen8097e142012-03-05 15:31:47 -08001107EXPORT_SYMBOL(cfg80211_calculate_bitrate);
Johannes Berg56d18932011-05-09 18:41:15 +02001108
Arend van Sprielc216e642012-11-25 19:13:28 +01001109int cfg80211_get_p2p_attr(const u8 *ies, unsigned int len,
1110 enum ieee80211_p2p_attr_id attr,
1111 u8 *buf, unsigned int bufsize)
Johannes Berg0ee45352012-10-29 19:48:40 +01001112{
1113 u8 *out = buf;
1114 u16 attr_remaining = 0;
1115 bool desired_attr = false;
1116 u16 desired_len = 0;
1117
1118 while (len > 0) {
1119 unsigned int iedatalen;
1120 unsigned int copy;
1121 const u8 *iedata;
1122
1123 if (len < 2)
1124 return -EILSEQ;
1125 iedatalen = ies[1];
1126 if (iedatalen + 2 > len)
1127 return -EILSEQ;
1128
1129 if (ies[0] != WLAN_EID_VENDOR_SPECIFIC)
1130 goto cont;
1131
1132 if (iedatalen < 4)
1133 goto cont;
1134
1135 iedata = ies + 2;
1136
1137 /* check WFA OUI, P2P subtype */
1138 if (iedata[0] != 0x50 || iedata[1] != 0x6f ||
1139 iedata[2] != 0x9a || iedata[3] != 0x09)
1140 goto cont;
1141
1142 iedatalen -= 4;
1143 iedata += 4;
1144
1145 /* check attribute continuation into this IE */
1146 copy = min_t(unsigned int, attr_remaining, iedatalen);
1147 if (copy && desired_attr) {
1148 desired_len += copy;
1149 if (out) {
1150 memcpy(out, iedata, min(bufsize, copy));
1151 out += min(bufsize, copy);
1152 bufsize -= min(bufsize, copy);
1153 }
1154
1155
1156 if (copy == attr_remaining)
1157 return desired_len;
1158 }
1159
1160 attr_remaining -= copy;
1161 if (attr_remaining)
1162 goto cont;
1163
1164 iedatalen -= copy;
1165 iedata += copy;
1166
1167 while (iedatalen > 0) {
1168 u16 attr_len;
1169
1170 /* P2P attribute ID & size must fit */
1171 if (iedatalen < 3)
1172 return -EILSEQ;
1173 desired_attr = iedata[0] == attr;
1174 attr_len = get_unaligned_le16(iedata + 1);
1175 iedatalen -= 3;
1176 iedata += 3;
1177
1178 copy = min_t(unsigned int, attr_len, iedatalen);
1179
1180 if (desired_attr) {
1181 desired_len += copy;
1182 if (out) {
1183 memcpy(out, iedata, min(bufsize, copy));
1184 out += min(bufsize, copy);
1185 bufsize -= min(bufsize, copy);
1186 }
1187
1188 if (copy == attr_len)
1189 return desired_len;
1190 }
1191
1192 iedata += copy;
1193 iedatalen -= copy;
1194 attr_remaining = attr_len - copy;
1195 }
1196
1197 cont:
1198 len -= ies[1] + 2;
1199 ies += ies[1] + 2;
1200 }
1201
1202 if (attr_remaining && desired_attr)
1203 return -EILSEQ;
1204
1205 return -ENOENT;
1206}
1207EXPORT_SYMBOL(cfg80211_get_p2p_attr);
1208
Johannes Berg1ce3e822012-08-01 17:00:55 +02001209bool ieee80211_operating_class_to_band(u8 operating_class,
1210 enum ieee80211_band *band)
1211{
1212 switch (operating_class) {
1213 case 112:
1214 case 115 ... 127:
1215 *band = IEEE80211_BAND_5GHZ;
1216 return true;
1217 case 81:
1218 case 82:
1219 case 83:
1220 case 84:
1221 *band = IEEE80211_BAND_2GHZ;
1222 return true;
Vladimir Kondratiev55300a12013-04-23 09:54:21 +03001223 case 180:
1224 *band = IEEE80211_BAND_60GHZ;
1225 return true;
Johannes Berg1ce3e822012-08-01 17:00:55 +02001226 }
1227
1228 return false;
1229}
1230EXPORT_SYMBOL(ieee80211_operating_class_to_band);
1231
Johannes Berg56d18932011-05-09 18:41:15 +02001232int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
1233 u32 beacon_int)
1234{
1235 struct wireless_dev *wdev;
1236 int res = 0;
1237
1238 if (!beacon_int)
1239 return -EINVAL;
1240
Johannes Berg89a54e42012-06-15 14:33:17 +02001241 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Berg56d18932011-05-09 18:41:15 +02001242 if (!wdev->beacon_interval)
1243 continue;
1244 if (wdev->beacon_interval != beacon_int) {
1245 res = -EINVAL;
1246 break;
1247 }
1248 }
1249
Johannes Berg56d18932011-05-09 18:41:15 +02001250 return res;
1251}
Johannes Berg7527a782011-05-13 10:58:57 +02001252
Michal Kaziord4e50c52012-06-29 12:47:07 +02001253int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
1254 struct wireless_dev *wdev,
1255 enum nl80211_iftype iftype,
1256 struct ieee80211_channel *chan,
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001257 enum cfg80211_chan_mode chanmode,
1258 u8 radar_detect)
Johannes Berg7527a782011-05-13 10:58:57 +02001259{
1260 struct wireless_dev *wdev_iter;
Johannes Berg463454b2012-06-05 12:16:50 +02001261 u32 used_iftypes = BIT(iftype);
Johannes Berg7527a782011-05-13 10:58:57 +02001262 int num[NUM_NL80211_IFTYPES];
Michal Kaziord4e50c52012-06-29 12:47:07 +02001263 struct ieee80211_channel
1264 *used_channels[CFG80211_MAX_NUM_DIFFERENT_CHANNELS];
1265 struct ieee80211_channel *ch;
1266 enum cfg80211_chan_mode chmode;
1267 int num_different_channels = 0;
Johannes Berg7527a782011-05-13 10:58:57 +02001268 int total = 1;
Simon Wunderlich5336fa82013-10-07 18:41:05 +02001269 bool radar_required = false;
Johannes Berg7527a782011-05-13 10:58:57 +02001270 int i, j;
1271
1272 ASSERT_RTNL();
1273
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001274 if (WARN_ON(hweight32(radar_detect) > 1))
1275 return -EINVAL;
1276
1277 switch (iftype) {
1278 case NL80211_IFTYPE_ADHOC:
1279 case NL80211_IFTYPE_AP:
1280 case NL80211_IFTYPE_AP_VLAN:
1281 case NL80211_IFTYPE_MESH_POINT:
1282 case NL80211_IFTYPE_P2P_GO:
1283 case NL80211_IFTYPE_WDS:
Simon Wunderlich5336fa82013-10-07 18:41:05 +02001284 /* if the interface could potentially choose a DFS channel,
1285 * then mark DFS as required.
1286 */
1287 if (!chan) {
1288 if (chanmode != CHAN_MODE_UNDEFINED && radar_detect)
1289 radar_required = true;
1290 break;
1291 }
1292 radar_required = !!(chan->flags & IEEE80211_CHAN_RADAR);
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001293 break;
1294 case NL80211_IFTYPE_P2P_CLIENT:
1295 case NL80211_IFTYPE_STATION:
Ilan Peerbba87ff2013-02-03 08:28:27 +02001296 case NL80211_IFTYPE_P2P_DEVICE:
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001297 case NL80211_IFTYPE_MONITOR:
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001298 break;
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001299 case NUM_NL80211_IFTYPES:
1300 case NL80211_IFTYPE_UNSPECIFIED:
1301 default:
1302 return -EINVAL;
1303 }
1304
1305 if (radar_required && !radar_detect)
1306 return -EINVAL;
1307
Johannes Berg7527a782011-05-13 10:58:57 +02001308 /* Always allow software iftypes */
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001309 if (rdev->wiphy.software_iftypes & BIT(iftype)) {
1310 if (radar_detect)
1311 return -EINVAL;
Johannes Berg7527a782011-05-13 10:58:57 +02001312 return 0;
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001313 }
Johannes Berg7527a782011-05-13 10:58:57 +02001314
Johannes Berg7527a782011-05-13 10:58:57 +02001315 memset(num, 0, sizeof(num));
Michal Kaziord4e50c52012-06-29 12:47:07 +02001316 memset(used_channels, 0, sizeof(used_channels));
Johannes Berg7527a782011-05-13 10:58:57 +02001317
1318 num[iftype] = 1;
1319
Michal Kaziord4e50c52012-06-29 12:47:07 +02001320 switch (chanmode) {
1321 case CHAN_MODE_UNDEFINED:
1322 break;
1323 case CHAN_MODE_SHARED:
1324 WARN_ON(!chan);
1325 used_channels[0] = chan;
1326 num_different_channels++;
1327 break;
1328 case CHAN_MODE_EXCLUSIVE:
1329 num_different_channels++;
1330 break;
1331 }
1332
Johannes Berg89a54e42012-06-15 14:33:17 +02001333 list_for_each_entry(wdev_iter, &rdev->wdev_list, list) {
Johannes Berg7527a782011-05-13 10:58:57 +02001334 if (wdev_iter == wdev)
1335 continue;
Johannes Berg6e3ab552013-04-19 12:19:39 +02001336 if (wdev_iter->iftype == NL80211_IFTYPE_P2P_DEVICE) {
Johannes Berg98104fde2012-06-16 00:19:54 +02001337 if (!wdev_iter->p2p_started)
1338 continue;
Johannes Berg6e3ab552013-04-19 12:19:39 +02001339 } else if (wdev_iter->netdev) {
1340 if (!netif_running(wdev_iter->netdev))
1341 continue;
Johannes Berg98104fde2012-06-16 00:19:54 +02001342 } else {
1343 WARN_ON(1);
1344 }
Johannes Berg7527a782011-05-13 10:58:57 +02001345
1346 if (rdev->wiphy.software_iftypes & BIT(wdev_iter->iftype))
1347 continue;
1348
Johannes Berg8e95ea42012-07-10 19:39:02 +02001349 /*
1350 * We may be holding the "wdev" mutex, but now need to lock
1351 * wdev_iter. This is OK because once we get here wdev_iter
1352 * is not wdev (tested above), but we need to use the nested
1353 * locking for lockdep.
1354 */
1355 mutex_lock_nested(&wdev_iter->mtx, 1);
1356 __acquire(wdev_iter->mtx);
1357 cfg80211_get_chan_state(wdev_iter, &ch, &chmode);
1358 wdev_unlock(wdev_iter);
Michal Kaziord4e50c52012-06-29 12:47:07 +02001359
1360 switch (chmode) {
1361 case CHAN_MODE_UNDEFINED:
1362 break;
1363 case CHAN_MODE_SHARED:
1364 for (i = 0; i < CFG80211_MAX_NUM_DIFFERENT_CHANNELS; i++)
1365 if (!used_channels[i] || used_channels[i] == ch)
1366 break;
1367
Michal Kaziore4e32452012-06-29 12:47:08 +02001368 if (i == CFG80211_MAX_NUM_DIFFERENT_CHANNELS)
Michal Kaziord4e50c52012-06-29 12:47:07 +02001369 return -EBUSY;
Michal Kaziord4e50c52012-06-29 12:47:07 +02001370
1371 if (used_channels[i] == NULL) {
1372 used_channels[i] = ch;
1373 num_different_channels++;
1374 }
1375 break;
1376 case CHAN_MODE_EXCLUSIVE:
1377 num_different_channels++;
1378 break;
1379 }
1380
Johannes Berg7527a782011-05-13 10:58:57 +02001381 num[wdev_iter->iftype]++;
1382 total++;
Johannes Berg463454b2012-06-05 12:16:50 +02001383 used_iftypes |= BIT(wdev_iter->iftype);
Johannes Berg7527a782011-05-13 10:58:57 +02001384 }
Johannes Berg7527a782011-05-13 10:58:57 +02001385
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001386 if (total == 1 && !radar_detect)
Johannes Berg8e8b41f2012-03-15 10:16:16 +01001387 return 0;
1388
Johannes Berg7527a782011-05-13 10:58:57 +02001389 for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) {
1390 const struct ieee80211_iface_combination *c;
1391 struct ieee80211_iface_limit *limits;
Johannes Berg463454b2012-06-05 12:16:50 +02001392 u32 all_iftypes = 0;
Johannes Berg7527a782011-05-13 10:58:57 +02001393
1394 c = &rdev->wiphy.iface_combinations[i];
1395
Michal Kaziord4e50c52012-06-29 12:47:07 +02001396 if (total > c->max_interfaces)
1397 continue;
1398 if (num_different_channels > c->num_different_channels)
1399 continue;
1400
Johannes Berg7527a782011-05-13 10:58:57 +02001401 limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
1402 GFP_KERNEL);
1403 if (!limits)
1404 return -ENOMEM;
Johannes Berg7527a782011-05-13 10:58:57 +02001405
1406 for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
1407 if (rdev->wiphy.software_iftypes & BIT(iftype))
1408 continue;
1409 for (j = 0; j < c->n_limits; j++) {
Johannes Berg463454b2012-06-05 12:16:50 +02001410 all_iftypes |= limits[j].types;
Lukasz Kucharczyke55a4042012-04-11 14:55:10 +02001411 if (!(limits[j].types & BIT(iftype)))
Johannes Berg7527a782011-05-13 10:58:57 +02001412 continue;
1413 if (limits[j].max < num[iftype])
1414 goto cont;
1415 limits[j].max -= num[iftype];
1416 }
1417 }
Johannes Berg463454b2012-06-05 12:16:50 +02001418
Simon Wunderlich11c4a072013-01-08 14:04:07 +01001419 if (radar_detect && !(c->radar_detect_widths & radar_detect))
1420 goto cont;
1421
Johannes Berg463454b2012-06-05 12:16:50 +02001422 /*
1423 * Finally check that all iftypes that we're currently
1424 * using are actually part of this combination. If they
1425 * aren't then we can't use this combination and have
1426 * to continue to the next.
1427 */
1428 if ((all_iftypes & used_iftypes) != used_iftypes)
1429 goto cont;
1430
1431 /*
1432 * This combination covered all interface types and
1433 * supported the requested numbers, so we're good.
1434 */
Johannes Berg7527a782011-05-13 10:58:57 +02001435 kfree(limits);
1436 return 0;
1437 cont:
1438 kfree(limits);
1439 }
1440
1441 return -EBUSY;
1442}
Johannes Berg34850ab2011-07-18 18:08:35 +02001443
1444int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
1445 const u8 *rates, unsigned int n_rates,
1446 u32 *mask)
1447{
1448 int i, j;
1449
Johannes Berga401d2b2011-07-20 00:52:16 +02001450 if (!sband)
1451 return -EINVAL;
1452
Johannes Berg34850ab2011-07-18 18:08:35 +02001453 if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES)
1454 return -EINVAL;
1455
1456 *mask = 0;
1457
1458 for (i = 0; i < n_rates; i++) {
1459 int rate = (rates[i] & 0x7f) * 5;
1460 bool found = false;
1461
1462 for (j = 0; j < sband->n_bitrates; j++) {
1463 if (sband->bitrates[j].bitrate == rate) {
1464 found = true;
1465 *mask |= BIT(j);
1466 break;
1467 }
1468 }
1469 if (!found)
1470 return -EINVAL;
1471 }
1472
1473 /*
1474 * mask must have at least one bit set here since we
1475 * didn't accept a 0-length rates array nor allowed
1476 * entries in the array that didn't exist
1477 */
1478
1479 return 0;
1480}
Johannes Berg11a2a352011-11-21 11:09:22 +01001481
1482/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
1483/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
1484const unsigned char rfc1042_header[] __aligned(2) =
1485 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1486EXPORT_SYMBOL(rfc1042_header);
1487
1488/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
1489const unsigned char bridge_tunnel_header[] __aligned(2) =
1490 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
1491EXPORT_SYMBOL(bridge_tunnel_header);