blob: a448b80f70ea966092dc0fc384f9642cc7b4c0f7 [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>
Johannes Berg8318d782008-01-24 19:38:38 +010013#include "core.h"
14
Johannes Bergbd815252008-10-29 20:00:45 +010015struct ieee80211_rate *
16ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +010017 u32 basic_rates, int bitrate)
Johannes Bergbd815252008-10-29 20:00:45 +010018{
19 struct ieee80211_rate *result = &sband->bitrates[0];
20 int i;
21
22 for (i = 0; i < sband->n_bitrates; i++) {
23 if (!(basic_rates & BIT(i)))
24 continue;
25 if (sband->bitrates[i].bitrate > bitrate)
26 continue;
27 result = &sband->bitrates[i];
28 }
29
30 return result;
31}
32EXPORT_SYMBOL(ieee80211_get_response_rate);
33
Bruno Randolf59eb21a2011-01-17 13:37:28 +090034int ieee80211_channel_to_frequency(int chan, enum ieee80211_band band)
Johannes Berg8318d782008-01-24 19:38:38 +010035{
Bruno Randolf59eb21a2011-01-17 13:37:28 +090036 /* see 802.11 17.3.8.3.2 and Annex J
37 * there are overlapping channel numbers in 5GHz and 2GHz bands */
38 if (band == IEEE80211_BAND_5GHZ) {
39 if (chan >= 182 && chan <= 196)
40 return 4000 + chan * 5;
41 else
42 return 5000 + chan * 5;
43 } else { /* IEEE80211_BAND_2GHZ */
44 if (chan == 14)
45 return 2484;
46 else if (chan < 14)
47 return 2407 + chan * 5;
48 else
49 return 0; /* not supported */
50 }
Johannes Berg8318d782008-01-24 19:38:38 +010051}
52EXPORT_SYMBOL(ieee80211_channel_to_frequency);
53
54int ieee80211_frequency_to_channel(int freq)
55{
Bruno Randolf59eb21a2011-01-17 13:37:28 +090056 /* see 802.11 17.3.8.3.2 and Annex J */
Johannes Berg8318d782008-01-24 19:38:38 +010057 if (freq == 2484)
58 return 14;
Bruno Randolf59eb21a2011-01-17 13:37:28 +090059 else if (freq < 2484)
Johannes Berg8318d782008-01-24 19:38:38 +010060 return (freq - 2407) / 5;
Bruno Randolf59eb21a2011-01-17 13:37:28 +090061 else if (freq >= 4910 && freq <= 4980)
62 return (freq - 4000) / 5;
63 else
64 return (freq - 5000) / 5;
Johannes Berg8318d782008-01-24 19:38:38 +010065}
66EXPORT_SYMBOL(ieee80211_frequency_to_channel);
67
Johannes Berg6c507cd2008-03-26 14:14:55 +010068struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
69 int freq)
Johannes Berg906c7302008-03-16 18:34:33 +010070{
71 enum ieee80211_band band;
72 struct ieee80211_supported_band *sband;
73 int i;
74
75 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
76 sband = wiphy->bands[band];
77
78 if (!sband)
79 continue;
80
81 for (i = 0; i < sband->n_channels; i++) {
82 if (sband->channels[i].center_freq == freq)
83 return &sband->channels[i];
84 }
85 }
86
87 return NULL;
88}
Johannes Berg6c507cd2008-03-26 14:14:55 +010089EXPORT_SYMBOL(__ieee80211_get_channel);
Johannes Berg906c7302008-03-16 18:34:33 +010090
Johannes Berg8318d782008-01-24 19:38:38 +010091static void set_mandatory_flags_band(struct ieee80211_supported_band *sband,
92 enum ieee80211_band band)
93{
94 int i, want;
95
96 switch (band) {
97 case IEEE80211_BAND_5GHZ:
98 want = 3;
99 for (i = 0; i < sband->n_bitrates; i++) {
100 if (sband->bitrates[i].bitrate == 60 ||
101 sband->bitrates[i].bitrate == 120 ||
102 sband->bitrates[i].bitrate == 240) {
103 sband->bitrates[i].flags |=
104 IEEE80211_RATE_MANDATORY_A;
105 want--;
106 }
107 }
108 WARN_ON(want);
109 break;
110 case IEEE80211_BAND_2GHZ:
111 want = 7;
112 for (i = 0; i < sband->n_bitrates; i++) {
113 if (sband->bitrates[i].bitrate == 10) {
114 sband->bitrates[i].flags |=
115 IEEE80211_RATE_MANDATORY_B |
116 IEEE80211_RATE_MANDATORY_G;
117 want--;
118 }
119
120 if (sband->bitrates[i].bitrate == 20 ||
121 sband->bitrates[i].bitrate == 55 ||
122 sband->bitrates[i].bitrate == 110 ||
123 sband->bitrates[i].bitrate == 60 ||
124 sband->bitrates[i].bitrate == 120 ||
125 sband->bitrates[i].bitrate == 240) {
126 sband->bitrates[i].flags |=
127 IEEE80211_RATE_MANDATORY_G;
128 want--;
129 }
130
Johannes Bergaac09fb2008-01-30 17:36:10 +0100131 if (sband->bitrates[i].bitrate != 10 &&
132 sband->bitrates[i].bitrate != 20 &&
133 sband->bitrates[i].bitrate != 55 &&
134 sband->bitrates[i].bitrate != 110)
Johannes Berg8318d782008-01-24 19:38:38 +0100135 sband->bitrates[i].flags |=
136 IEEE80211_RATE_ERP_G;
137 }
Ivo van Doorn406f2382008-02-02 23:53:10 +0100138 WARN_ON(want != 0 && want != 3 && want != 6);
Johannes Berg8318d782008-01-24 19:38:38 +0100139 break;
140 case IEEE80211_NUM_BANDS:
141 WARN_ON(1);
142 break;
143 }
144}
145
146void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
147{
148 enum ieee80211_band band;
149
150 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
151 if (wiphy->bands[band])
152 set_mandatory_flags_band(wiphy->bands[band], band);
153}
Johannes Berg08645122009-05-11 13:54:58 +0200154
Jouni Malinen38ba3c52011-09-21 18:14:56 +0300155bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher)
156{
157 int i;
158 for (i = 0; i < wiphy->n_cipher_suites; i++)
159 if (cipher == wiphy->cipher_suites[i])
160 return true;
161 return false;
162}
163
Johannes Bergfffd0932009-07-08 14:22:54 +0200164int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
165 struct key_params *params, int key_idx,
Johannes Berge31b8212010-10-05 19:39:30 +0200166 bool pairwise, const u8 *mac_addr)
Johannes Berg08645122009-05-11 13:54:58 +0200167{
168 if (key_idx > 5)
169 return -EINVAL;
170
Johannes Berge31b8212010-10-05 19:39:30 +0200171 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
172 return -EINVAL;
173
174 if (pairwise && !mac_addr)
175 return -EINVAL;
176
Johannes Berg08645122009-05-11 13:54:58 +0200177 /*
178 * Disallow pairwise keys with non-zero index unless it's WEP
Juuso Oikarinen45cbad62011-01-25 12:21:22 +0200179 * or a vendor specific cipher (because current deployments use
180 * pairwise WEP keys with non-zero indices and for vendor specific
181 * ciphers this should be validated in the driver or hardware level
182 * - but 802.11i clearly specifies to use zero)
Johannes Berg08645122009-05-11 13:54:58 +0200183 */
Johannes Berge31b8212010-10-05 19:39:30 +0200184 if (pairwise && key_idx &&
Juuso Oikarinen45cbad62011-01-25 12:21:22 +0200185 ((params->cipher == WLAN_CIPHER_SUITE_TKIP) ||
186 (params->cipher == WLAN_CIPHER_SUITE_CCMP) ||
187 (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC)))
Johannes Berg08645122009-05-11 13:54:58 +0200188 return -EINVAL;
189
Johannes Berg08645122009-05-11 13:54:58 +0200190 switch (params->cipher) {
191 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200192 if (params->key_len != WLAN_KEY_LEN_WEP40)
Johannes Berg08645122009-05-11 13:54:58 +0200193 return -EINVAL;
194 break;
195 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200196 if (params->key_len != WLAN_KEY_LEN_TKIP)
Johannes Berg08645122009-05-11 13:54:58 +0200197 return -EINVAL;
198 break;
199 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200200 if (params->key_len != WLAN_KEY_LEN_CCMP)
Johannes Berg08645122009-05-11 13:54:58 +0200201 return -EINVAL;
202 break;
203 case WLAN_CIPHER_SUITE_WEP104:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200204 if (params->key_len != WLAN_KEY_LEN_WEP104)
Johannes Berg08645122009-05-11 13:54:58 +0200205 return -EINVAL;
206 break;
207 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg8fc0fee2009-05-24 16:57:19 +0200208 if (params->key_len != WLAN_KEY_LEN_AES_CMAC)
Johannes Berg08645122009-05-11 13:54:58 +0200209 return -EINVAL;
210 break;
Deepthi Gowri5b26a952011-11-29 11:22:42 +0530211 case WLAN_CIPHER_SUITE_SMS4:
212 if (params->key_len != WLAN_KEY_LEN_WAPI_SMS4)
213 return -EINVAL;
214 break;
Johannes Berg08645122009-05-11 13:54:58 +0200215 default:
Johannes Berg7d64b7c2010-08-27 14:26:51 +0300216 /*
217 * We don't know anything about this algorithm,
218 * allow using it -- but the driver must check
219 * all parameters! We still check below whether
220 * or not the driver supports this algorithm,
221 * of course.
222 */
223 break;
Johannes Berg08645122009-05-11 13:54:58 +0200224 }
225
Jouni Malinen9f26a952009-05-15 12:38:32 +0300226 if (params->seq) {
227 switch (params->cipher) {
228 case WLAN_CIPHER_SUITE_WEP40:
229 case WLAN_CIPHER_SUITE_WEP104:
230 /* These ciphers do not use key sequence */
231 return -EINVAL;
232 case WLAN_CIPHER_SUITE_TKIP:
233 case WLAN_CIPHER_SUITE_CCMP:
234 case WLAN_CIPHER_SUITE_AES_CMAC:
235 if (params->seq_len != 6)
236 return -EINVAL;
237 break;
238 }
239 }
240
Jouni Malinen38ba3c52011-09-21 18:14:56 +0300241 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher))
Johannes Bergfffd0932009-07-08 14:22:54 +0200242 return -EINVAL;
243
Johannes Berg08645122009-05-11 13:54:58 +0200244 return 0;
245}
Zhu Yie31a16d2009-05-21 21:47:03 +0800246
Johannes Berg633adf12010-08-12 14:49:58 +0200247unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc)
Zhu Yie31a16d2009-05-21 21:47:03 +0800248{
249 unsigned int hdrlen = 24;
250
251 if (ieee80211_is_data(fc)) {
252 if (ieee80211_has_a4(fc))
253 hdrlen = 30;
Andriy Tkachukd0dd2de2010-01-20 13:55:06 +0200254 if (ieee80211_is_data_qos(fc)) {
Zhu Yie31a16d2009-05-21 21:47:03 +0800255 hdrlen += IEEE80211_QOS_CTL_LEN;
Andriy Tkachukd0dd2de2010-01-20 13:55:06 +0200256 if (ieee80211_has_order(fc))
257 hdrlen += IEEE80211_HT_CTL_LEN;
258 }
Zhu Yie31a16d2009-05-21 21:47:03 +0800259 goto out;
260 }
261
262 if (ieee80211_is_ctl(fc)) {
263 /*
264 * ACK and CTS are 10 bytes, all others 16. To see how
265 * to get this condition consider
266 * subtype mask: 0b0000000011110000 (0x00F0)
267 * ACK subtype: 0b0000000011010000 (0x00D0)
268 * CTS subtype: 0b0000000011000000 (0x00C0)
269 * bits that matter: ^^^ (0x00E0)
270 * value of those: 0b0000000011000000 (0x00C0)
271 */
272 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
273 hdrlen = 10;
274 else
275 hdrlen = 16;
276 }
277out:
278 return hdrlen;
279}
280EXPORT_SYMBOL(ieee80211_hdrlen);
281
282unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
283{
284 const struct ieee80211_hdr *hdr =
285 (const struct ieee80211_hdr *)skb->data;
286 unsigned int hdrlen;
287
288 if (unlikely(skb->len < 10))
289 return 0;
290 hdrlen = ieee80211_hdrlen(hdr->frame_control);
291 if (unlikely(hdrlen > skb->len))
292 return 0;
293 return hdrlen;
294}
295EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
296
Luis R. Rodriguez60fd2b62009-06-02 16:31:10 -0400297static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
Zhu Yie31a16d2009-05-21 21:47:03 +0800298{
299 int ae = meshhdr->flags & MESH_FLAGS_AE;
300 /* 7.1.3.5a.2 */
301 switch (ae) {
302 case 0:
303 return 6;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700304 case MESH_FLAGS_AE_A4:
Zhu Yie31a16d2009-05-21 21:47:03 +0800305 return 12;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700306 case MESH_FLAGS_AE_A5_A6:
Zhu Yie31a16d2009-05-21 21:47:03 +0800307 return 18;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700308 case (MESH_FLAGS_AE_A4 | MESH_FLAGS_AE_A5_A6):
Zhu Yie31a16d2009-05-21 21:47:03 +0800309 return 24;
310 default:
311 return 6;
312 }
313}
314
Zhu Yieaf85ca2009-12-01 10:18:37 +0800315int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
Zhu Yie31a16d2009-05-21 21:47:03 +0800316 enum nl80211_iftype iftype)
317{
318 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
319 u16 hdrlen, ethertype;
320 u8 *payload;
321 u8 dst[ETH_ALEN];
322 u8 src[ETH_ALEN] __aligned(2);
323
324 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
325 return -1;
326
327 hdrlen = ieee80211_hdrlen(hdr->frame_control);
328
329 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
330 * header
331 * IEEE 802.11 address fields:
332 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
333 * 0 0 DA SA BSSID n/a
334 * 0 1 DA BSSID SA n/a
335 * 1 0 BSSID SA DA n/a
336 * 1 1 RA TA DA SA
337 */
338 memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
339 memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
340
341 switch (hdr->frame_control &
342 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
343 case cpu_to_le16(IEEE80211_FCTL_TODS):
344 if (unlikely(iftype != NL80211_IFTYPE_AP &&
Johannes Berg074ac8d2010-09-16 14:58:22 +0200345 iftype != NL80211_IFTYPE_AP_VLAN &&
346 iftype != NL80211_IFTYPE_P2P_GO))
Zhu Yie31a16d2009-05-21 21:47:03 +0800347 return -1;
348 break;
349 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
350 if (unlikely(iftype != NL80211_IFTYPE_WDS &&
Felix Fietkauf14543e2009-11-10 20:10:05 +0100351 iftype != NL80211_IFTYPE_MESH_POINT &&
352 iftype != NL80211_IFTYPE_AP_VLAN &&
353 iftype != NL80211_IFTYPE_STATION))
Zhu Yie31a16d2009-05-21 21:47:03 +0800354 return -1;
355 if (iftype == NL80211_IFTYPE_MESH_POINT) {
356 struct ieee80211s_hdr *meshdr =
357 (struct ieee80211s_hdr *) (skb->data + hdrlen);
Zhu Yie3cf8b32010-03-29 17:35:07 +0800358 /* make sure meshdr->flags is on the linear part */
359 if (!pskb_may_pull(skb, hdrlen + 1))
360 return -1;
Zhu Yie31a16d2009-05-21 21:47:03 +0800361 if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
Zhu Yie3cf8b32010-03-29 17:35:07 +0800362 skb_copy_bits(skb, hdrlen +
363 offsetof(struct ieee80211s_hdr, eaddr1),
364 dst, ETH_ALEN);
365 skb_copy_bits(skb, hdrlen +
366 offsetof(struct ieee80211s_hdr, eaddr2),
367 src, ETH_ALEN);
Zhu Yie31a16d2009-05-21 21:47:03 +0800368 }
Zhu Yie3cf8b32010-03-29 17:35:07 +0800369 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
Zhu Yie31a16d2009-05-21 21:47:03 +0800370 }
371 break;
372 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
Javier Cardona3c5772a2009-08-10 12:15:48 -0700373 if ((iftype != NL80211_IFTYPE_STATION &&
Johannes Berg074ac8d2010-09-16 14:58:22 +0200374 iftype != NL80211_IFTYPE_P2P_CLIENT &&
375 iftype != NL80211_IFTYPE_MESH_POINT) ||
Zhu Yie31a16d2009-05-21 21:47:03 +0800376 (is_multicast_ether_addr(dst) &&
377 !compare_ether_addr(src, addr)))
378 return -1;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700379 if (iftype == NL80211_IFTYPE_MESH_POINT) {
380 struct ieee80211s_hdr *meshdr =
381 (struct ieee80211s_hdr *) (skb->data + hdrlen);
Zhu Yie3cf8b32010-03-29 17:35:07 +0800382 /* make sure meshdr->flags is on the linear part */
383 if (!pskb_may_pull(skb, hdrlen + 1))
384 return -1;
Javier Cardona3c5772a2009-08-10 12:15:48 -0700385 if (meshdr->flags & MESH_FLAGS_AE_A4)
Zhu Yie3cf8b32010-03-29 17:35:07 +0800386 skb_copy_bits(skb, hdrlen +
387 offsetof(struct ieee80211s_hdr, eaddr1),
388 src, ETH_ALEN);
389 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
Javier Cardona3c5772a2009-08-10 12:15:48 -0700390 }
Zhu Yie31a16d2009-05-21 21:47:03 +0800391 break;
392 case cpu_to_le16(0):
Arik Nemtsov941c93c2011-09-28 14:12:54 +0300393 if (iftype != NL80211_IFTYPE_ADHOC &&
394 iftype != NL80211_IFTYPE_STATION)
395 return -1;
Zhu Yie31a16d2009-05-21 21:47:03 +0800396 break;
397 }
398
Zhu Yie3cf8b32010-03-29 17:35:07 +0800399 if (!pskb_may_pull(skb, hdrlen + 8))
Zhu Yie31a16d2009-05-21 21:47:03 +0800400 return -1;
401
402 payload = skb->data + hdrlen;
403 ethertype = (payload[6] << 8) | payload[7];
404
405 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
406 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
407 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
408 /* remove RFC1042 or Bridge-Tunnel encapsulation and
409 * replace EtherType */
410 skb_pull(skb, hdrlen + 6);
411 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
412 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
413 } else {
414 struct ethhdr *ehdr;
415 __be16 len;
416
417 skb_pull(skb, hdrlen);
418 len = htons(skb->len);
419 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
420 memcpy(ehdr->h_dest, dst, ETH_ALEN);
421 memcpy(ehdr->h_source, src, ETH_ALEN);
422 ehdr->h_proto = len;
423 }
424 return 0;
425}
426EXPORT_SYMBOL(ieee80211_data_to_8023);
427
Zhu Yieaf85ca2009-12-01 10:18:37 +0800428int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
Zhu Yie31a16d2009-05-21 21:47:03 +0800429 enum nl80211_iftype iftype, u8 *bssid, bool qos)
430{
431 struct ieee80211_hdr hdr;
432 u16 hdrlen, ethertype;
433 __le16 fc;
434 const u8 *encaps_data;
435 int encaps_len, skip_header_bytes;
436 int nh_pos, h_pos;
437 int head_need;
438
439 if (unlikely(skb->len < ETH_HLEN))
440 return -EINVAL;
441
442 nh_pos = skb_network_header(skb) - skb->data;
443 h_pos = skb_transport_header(skb) - skb->data;
444
445 /* convert Ethernet header to proper 802.11 header (based on
446 * operation mode) */
447 ethertype = (skb->data[12] << 8) | skb->data[13];
448 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
449
450 switch (iftype) {
451 case NL80211_IFTYPE_AP:
452 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200453 case NL80211_IFTYPE_P2P_GO:
Zhu Yie31a16d2009-05-21 21:47:03 +0800454 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
455 /* DA BSSID SA */
456 memcpy(hdr.addr1, skb->data, ETH_ALEN);
457 memcpy(hdr.addr2, addr, ETH_ALEN);
458 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
459 hdrlen = 24;
460 break;
461 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200462 case NL80211_IFTYPE_P2P_CLIENT:
Zhu Yie31a16d2009-05-21 21:47:03 +0800463 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
464 /* BSSID SA DA */
465 memcpy(hdr.addr1, bssid, ETH_ALEN);
466 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
467 memcpy(hdr.addr3, skb->data, ETH_ALEN);
468 hdrlen = 24;
469 break;
470 case NL80211_IFTYPE_ADHOC:
471 /* DA SA BSSID */
472 memcpy(hdr.addr1, skb->data, ETH_ALEN);
473 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
474 memcpy(hdr.addr3, bssid, ETH_ALEN);
475 hdrlen = 24;
476 break;
477 default:
478 return -EOPNOTSUPP;
479 }
480
481 if (qos) {
482 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
483 hdrlen += 2;
484 }
485
486 hdr.frame_control = fc;
487 hdr.duration_id = 0;
488 hdr.seq_ctrl = 0;
489
490 skip_header_bytes = ETH_HLEN;
491 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
492 encaps_data = bridge_tunnel_header;
493 encaps_len = sizeof(bridge_tunnel_header);
494 skip_header_bytes -= 2;
495 } else if (ethertype > 0x600) {
496 encaps_data = rfc1042_header;
497 encaps_len = sizeof(rfc1042_header);
498 skip_header_bytes -= 2;
499 } else {
500 encaps_data = NULL;
501 encaps_len = 0;
502 }
503
504 skb_pull(skb, skip_header_bytes);
505 nh_pos -= skip_header_bytes;
506 h_pos -= skip_header_bytes;
507
508 head_need = hdrlen + encaps_len - skb_headroom(skb);
509
510 if (head_need > 0 || skb_cloned(skb)) {
511 head_need = max(head_need, 0);
512 if (head_need)
513 skb_orphan(skb);
514
Joe Perches24616152011-08-29 14:17:41 -0700515 if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC))
Zhu Yie31a16d2009-05-21 21:47:03 +0800516 return -ENOMEM;
Joe Perches24616152011-08-29 14:17:41 -0700517
Zhu Yie31a16d2009-05-21 21:47:03 +0800518 skb->truesize += head_need;
519 }
520
521 if (encaps_data) {
522 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
523 nh_pos += encaps_len;
524 h_pos += encaps_len;
525 }
526
527 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
528
529 nh_pos += hdrlen;
530 h_pos += hdrlen;
531
532 /* Update skb pointers to various headers since this modified frame
533 * is going to go through Linux networking code that may potentially
534 * need things like pointer to IP header. */
535 skb_set_mac_header(skb, 0);
536 skb_set_network_header(skb, nh_pos);
537 skb_set_transport_header(skb, h_pos);
538
539 return 0;
540}
541EXPORT_SYMBOL(ieee80211_data_from_8023);
542
Zhu Yieaf85ca2009-12-01 10:18:37 +0800543
544void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
545 const u8 *addr, enum nl80211_iftype iftype,
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -0700546 const unsigned int extra_headroom,
547 bool has_80211_header)
Zhu Yieaf85ca2009-12-01 10:18:37 +0800548{
549 struct sk_buff *frame = NULL;
550 u16 ethertype;
551 u8 *payload;
552 const struct ethhdr *eth;
553 int remaining, err;
554 u8 dst[ETH_ALEN], src[ETH_ALEN];
555
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -0700556 if (has_80211_header) {
557 err = ieee80211_data_to_8023(skb, addr, iftype);
558 if (err)
559 goto out;
Zhu Yieaf85ca2009-12-01 10:18:37 +0800560
Yogesh Ashok Powar8b3beca2011-05-13 11:22:31 -0700561 /* skip the wrapping header */
562 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
563 if (!eth)
564 goto out;
565 } else {
566 eth = (struct ethhdr *) skb->data;
567 }
Zhu Yieaf85ca2009-12-01 10:18:37 +0800568
569 while (skb != frame) {
570 u8 padding;
571 __be16 len = eth->h_proto;
572 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
573
574 remaining = skb->len;
575 memcpy(dst, eth->h_dest, ETH_ALEN);
576 memcpy(src, eth->h_source, ETH_ALEN);
577
578 padding = (4 - subframe_len) & 0x3;
579 /* the last MSDU has no padding */
580 if (subframe_len > remaining)
581 goto purge;
582
583 skb_pull(skb, sizeof(struct ethhdr));
584 /* reuse skb for the last subframe */
585 if (remaining <= subframe_len + padding)
586 frame = skb;
587 else {
588 unsigned int hlen = ALIGN(extra_headroom, 4);
589 /*
590 * Allocate and reserve two bytes more for payload
591 * alignment since sizeof(struct ethhdr) is 14.
592 */
593 frame = dev_alloc_skb(hlen + subframe_len + 2);
594 if (!frame)
595 goto purge;
596
597 skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
598 memcpy(skb_put(frame, ntohs(len)), skb->data,
599 ntohs(len));
600
601 eth = (struct ethhdr *)skb_pull(skb, ntohs(len) +
602 padding);
603 if (!eth) {
604 dev_kfree_skb(frame);
605 goto purge;
606 }
607 }
608
609 skb_reset_network_header(frame);
610 frame->dev = skb->dev;
611 frame->priority = skb->priority;
612
613 payload = frame->data;
614 ethertype = (payload[6] << 8) | payload[7];
615
616 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
617 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
618 compare_ether_addr(payload,
619 bridge_tunnel_header) == 0)) {
620 /* remove RFC1042 or Bridge-Tunnel
621 * encapsulation and replace EtherType */
622 skb_pull(frame, 6);
623 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
624 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
625 } else {
626 memcpy(skb_push(frame, sizeof(__be16)), &len,
627 sizeof(__be16));
628 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
629 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
630 }
631 __skb_queue_tail(list, frame);
632 }
633
634 return;
635
636 purge:
637 __skb_queue_purge(list);
638 out:
639 dev_kfree_skb(skb);
640}
641EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
642
Zhu Yie31a16d2009-05-21 21:47:03 +0800643/* Given a data frame determine the 802.1p/1d tag to use. */
644unsigned int cfg80211_classify8021d(struct sk_buff *skb)
645{
646 unsigned int dscp;
647
648 /* skb->priority values from 256->263 are magic values to
649 * directly indicate a specific 802.1d priority. This is used
650 * to allow 802.1d priority to be passed directly in from VLAN
651 * tags, etc.
652 */
653 if (skb->priority >= 256 && skb->priority <= 263)
654 return skb->priority - 256;
655
656 switch (skb->protocol) {
657 case htons(ETH_P_IP):
Dave Tähtb1565792011-12-22 12:55:08 -0800658 dscp = ipv4_get_dsfield(ip_hdr(skb)) & 0xfc;
659 break;
660 case htons(ETH_P_IPV6):
661 dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & 0xfc;
Zhu Yie31a16d2009-05-21 21:47:03 +0800662 break;
663 default:
664 return 0;
665 }
666
667 return dscp >> 5;
668}
669EXPORT_SYMBOL(cfg80211_classify8021d);
Johannes Berg517357c2009-07-02 17:18:40 +0200670
671const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
672{
673 u8 *end, *pos;
674
675 pos = bss->information_elements;
676 if (pos == NULL)
677 return NULL;
678 end = pos + bss->len_information_elements;
679
680 while (pos + 1 < end) {
681 if (pos + 2 + pos[1] > end)
682 break;
683 if (pos[0] == ie)
684 return pos;
685 pos += 2 + pos[1];
686 }
687
688 return NULL;
689}
690EXPORT_SYMBOL(ieee80211_bss_get_ie);
Johannes Bergfffd0932009-07-08 14:22:54 +0200691
692void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
693{
694 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
695 struct net_device *dev = wdev->netdev;
696 int i;
697
698 if (!wdev->connect_keys)
699 return;
700
701 for (i = 0; i < 6; i++) {
702 if (!wdev->connect_keys->params[i].cipher)
703 continue;
Johannes Berge31b8212010-10-05 19:39:30 +0200704 if (rdev->ops->add_key(wdev->wiphy, dev, i, false, NULL,
Zhu Yi1e056662009-07-20 16:12:57 +0800705 &wdev->connect_keys->params[i])) {
Joe Perchese9c02682010-11-16 19:56:49 -0800706 netdev_err(dev, "failed to set key %d\n", i);
Zhu Yi1e056662009-07-20 16:12:57 +0800707 continue;
708 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200709 if (wdev->connect_keys->def == i)
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100710 if (rdev->ops->set_default_key(wdev->wiphy, dev,
711 i, true, true)) {
Joe Perchese9c02682010-11-16 19:56:49 -0800712 netdev_err(dev, "failed to set defkey %d\n", i);
Zhu Yi1e056662009-07-20 16:12:57 +0800713 continue;
714 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200715 if (wdev->connect_keys->defmgmt == i)
716 if (rdev->ops->set_default_mgmt_key(wdev->wiphy, dev, i))
Joe Perchese9c02682010-11-16 19:56:49 -0800717 netdev_err(dev, "failed to set mgtdef %d\n", i);
Johannes Bergfffd0932009-07-08 14:22:54 +0200718 }
719
720 kfree(wdev->connect_keys);
721 wdev->connect_keys = NULL;
722}
Johannes Berg3d54d252009-08-21 14:51:05 +0200723
724static void cfg80211_process_wdev_events(struct wireless_dev *wdev)
725{
726 struct cfg80211_event *ev;
727 unsigned long flags;
728 const u8 *bssid = NULL;
729
730 spin_lock_irqsave(&wdev->event_lock, flags);
731 while (!list_empty(&wdev->event_list)) {
732 ev = list_first_entry(&wdev->event_list,
733 struct cfg80211_event, list);
734 list_del(&ev->list);
735 spin_unlock_irqrestore(&wdev->event_lock, flags);
736
737 wdev_lock(wdev);
738 switch (ev->type) {
739 case EVENT_CONNECT_RESULT:
740 if (!is_zero_ether_addr(ev->cr.bssid))
741 bssid = ev->cr.bssid;
742 __cfg80211_connect_result(
743 wdev->netdev, bssid,
744 ev->cr.req_ie, ev->cr.req_ie_len,
745 ev->cr.resp_ie, ev->cr.resp_ie_len,
746 ev->cr.status,
747 ev->cr.status == WLAN_STATUS_SUCCESS,
748 NULL);
749 break;
750 case EVENT_ROAMED:
Vasanthakumar Thiagarajanadbde342011-12-08 14:28:47 +0530751 __cfg80211_roamed(wdev, ev->rm.bss, ev->rm.req_ie,
752 ev->rm.req_ie_len, ev->rm.resp_ie,
753 ev->rm.resp_ie_len);
Johannes Berg3d54d252009-08-21 14:51:05 +0200754 break;
755 case EVENT_DISCONNECTED:
756 __cfg80211_disconnected(wdev->netdev,
757 ev->dc.ie, ev->dc.ie_len,
758 ev->dc.reason, true);
759 break;
760 case EVENT_IBSS_JOINED:
761 __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
762 break;
763 }
764 wdev_unlock(wdev);
765
766 kfree(ev);
767
768 spin_lock_irqsave(&wdev->event_lock, flags);
769 }
770 spin_unlock_irqrestore(&wdev->event_lock, flags);
771}
772
773void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
774{
775 struct wireless_dev *wdev;
776
777 ASSERT_RTNL();
778 ASSERT_RDEV_LOCK(rdev);
779
780 mutex_lock(&rdev->devlist_mtx);
781
782 list_for_each_entry(wdev, &rdev->netdev_list, list)
783 cfg80211_process_wdev_events(wdev);
784
785 mutex_unlock(&rdev->devlist_mtx);
786}
787
788int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
789 struct net_device *dev, enum nl80211_iftype ntype,
790 u32 *flags, struct vif_params *params)
791{
792 int err;
793 enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
794
795 ASSERT_RDEV_LOCK(rdev);
796
797 /* don't support changing VLANs, you just re-create them */
798 if (otype == NL80211_IFTYPE_AP_VLAN)
799 return -EOPNOTSUPP;
800
801 if (!rdev->ops->change_virtual_intf ||
802 !(rdev->wiphy.interface_modes & (1 << ntype)))
803 return -EOPNOTSUPP;
804
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100805 /* if it's part of a bridge, reject changing type to station/ibss */
Jiri Pirkof350a0a2010-06-15 06:50:45 +0000806 if ((dev->priv_flags & IFF_BRIDGE_PORT) &&
Johannes Berg074ac8d2010-09-16 14:58:22 +0200807 (ntype == NL80211_IFTYPE_ADHOC ||
808 ntype == NL80211_IFTYPE_STATION ||
809 ntype == NL80211_IFTYPE_P2P_CLIENT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100810 return -EBUSY;
811
Johannes Berg3d54d252009-08-21 14:51:05 +0200812 if (ntype != otype) {
Johannes Berg7527a782011-05-13 10:58:57 +0200813 err = cfg80211_can_change_interface(rdev, dev->ieee80211_ptr,
814 ntype);
815 if (err)
816 return err;
817
Johannes Berg9bc383d2009-11-19 11:55:19 +0100818 dev->ieee80211_ptr->use_4addr = false;
Johannes Berg29cbe682010-12-03 09:20:44 +0100819 dev->ieee80211_ptr->mesh_id_up_len = 0;
Johannes Berg9bc383d2009-11-19 11:55:19 +0100820
Johannes Berg3d54d252009-08-21 14:51:05 +0200821 switch (otype) {
822 case NL80211_IFTYPE_ADHOC:
823 cfg80211_leave_ibss(rdev, dev, false);
824 break;
825 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200826 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg3d54d252009-08-21 14:51:05 +0200827 cfg80211_disconnect(rdev, dev,
828 WLAN_REASON_DEAUTH_LEAVING, true);
829 break;
830 case NL80211_IFTYPE_MESH_POINT:
831 /* mesh should be handled? */
832 break;
833 default:
834 break;
835 }
836
837 cfg80211_process_rdev_events(rdev);
838 }
839
840 err = rdev->ops->change_virtual_intf(&rdev->wiphy, dev,
841 ntype, flags, params);
842
843 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
844
Johannes Berg9bc383d2009-11-19 11:55:19 +0100845 if (!err && params && params->use_4addr != -1)
846 dev->ieee80211_ptr->use_4addr = params->use_4addr;
847
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100848 if (!err) {
849 dev->priv_flags &= ~IFF_DONT_BRIDGE;
850 switch (ntype) {
851 case NL80211_IFTYPE_STATION:
852 if (dev->ieee80211_ptr->use_4addr)
853 break;
854 /* fall through */
Johannes Berg074ac8d2010-09-16 14:58:22 +0200855 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100856 case NL80211_IFTYPE_ADHOC:
857 dev->priv_flags |= IFF_DONT_BRIDGE;
858 break;
Johannes Berg074ac8d2010-09-16 14:58:22 +0200859 case NL80211_IFTYPE_P2P_GO:
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100860 case NL80211_IFTYPE_AP:
861 case NL80211_IFTYPE_AP_VLAN:
862 case NL80211_IFTYPE_WDS:
863 case NL80211_IFTYPE_MESH_POINT:
864 /* bridging OK */
865 break;
866 case NL80211_IFTYPE_MONITOR:
867 /* monitor can't bridge anyway */
868 break;
869 case NL80211_IFTYPE_UNSPECIFIED:
Johannes Berg2e161f72010-08-12 15:38:38 +0200870 case NUM_NL80211_IFTYPES:
Johannes Bergad4bb6f2009-11-19 00:56:30 +0100871 /* not happening */
872 break;
873 }
874 }
875
Johannes Berg3d54d252009-08-21 14:51:05 +0200876 return err;
877}
John W. Linville254416a2009-12-09 16:43:52 -0500878
879u16 cfg80211_calculate_bitrate(struct rate_info *rate)
880{
881 int modulation, streams, bitrate;
882
883 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
884 return rate->legacy;
885
886 /* the formula below does only work for MCS values smaller than 32 */
887 if (rate->mcs >= 32)
888 return 0;
889
890 modulation = rate->mcs & 7;
891 streams = (rate->mcs >> 3) + 1;
892
893 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
894 13500000 : 6500000;
895
896 if (modulation < 4)
897 bitrate *= (modulation + 1);
898 else if (modulation == 4)
899 bitrate *= (modulation + 2);
900 else
901 bitrate *= (modulation + 3);
902
903 bitrate *= streams;
904
905 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
906 bitrate = (bitrate / 9) * 10;
907
908 /* do NOT round down here */
909 return (bitrate + 50000) / 100000;
910}
Thomas Pedersen8097e142012-03-05 15:31:47 -0800911EXPORT_SYMBOL(cfg80211_calculate_bitrate);
Johannes Berg56d18932011-05-09 18:41:15 +0200912
913int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
914 u32 beacon_int)
915{
916 struct wireless_dev *wdev;
917 int res = 0;
918
919 if (!beacon_int)
920 return -EINVAL;
921
922 mutex_lock(&rdev->devlist_mtx);
923
924 list_for_each_entry(wdev, &rdev->netdev_list, list) {
925 if (!wdev->beacon_interval)
926 continue;
927 if (wdev->beacon_interval != beacon_int) {
928 res = -EINVAL;
929 break;
930 }
931 }
932
933 mutex_unlock(&rdev->devlist_mtx);
934
935 return res;
936}
Johannes Berg7527a782011-05-13 10:58:57 +0200937
938int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
939 struct wireless_dev *wdev,
940 enum nl80211_iftype iftype)
941{
942 struct wireless_dev *wdev_iter;
943 int num[NUM_NL80211_IFTYPES];
944 int total = 1;
945 int i, j;
946
947 ASSERT_RTNL();
948
949 /* Always allow software iftypes */
950 if (rdev->wiphy.software_iftypes & BIT(iftype))
951 return 0;
952
953 /*
954 * Drivers will gradually all set this flag, until all
955 * have it we only enforce for those that set it.
956 */
957 if (!(rdev->wiphy.flags & WIPHY_FLAG_ENFORCE_COMBINATIONS))
958 return 0;
959
960 memset(num, 0, sizeof(num));
961
962 num[iftype] = 1;
963
964 mutex_lock(&rdev->devlist_mtx);
965 list_for_each_entry(wdev_iter, &rdev->netdev_list, list) {
966 if (wdev_iter == wdev)
967 continue;
968 if (!netif_running(wdev_iter->netdev))
969 continue;
970
971 if (rdev->wiphy.software_iftypes & BIT(wdev_iter->iftype))
972 continue;
973
974 num[wdev_iter->iftype]++;
975 total++;
976 }
977 mutex_unlock(&rdev->devlist_mtx);
978
979 for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) {
980 const struct ieee80211_iface_combination *c;
981 struct ieee80211_iface_limit *limits;
982
983 c = &rdev->wiphy.iface_combinations[i];
984
985 limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
986 GFP_KERNEL);
987 if (!limits)
988 return -ENOMEM;
989 if (total > c->max_interfaces)
990 goto cont;
991
992 for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
993 if (rdev->wiphy.software_iftypes & BIT(iftype))
994 continue;
995 for (j = 0; j < c->n_limits; j++) {
Lukasz Kucharczyke55a4042012-04-11 14:55:10 +0200996 if (!(limits[j].types & BIT(iftype)))
Johannes Berg7527a782011-05-13 10:58:57 +0200997 continue;
998 if (limits[j].max < num[iftype])
999 goto cont;
1000 limits[j].max -= num[iftype];
1001 }
1002 }
1003 /* yay, it fits */
1004 kfree(limits);
1005 return 0;
1006 cont:
1007 kfree(limits);
1008 }
1009
1010 return -EBUSY;
1011}
Johannes Berg34850ab2011-07-18 18:08:35 +02001012
1013int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
1014 const u8 *rates, unsigned int n_rates,
1015 u32 *mask)
1016{
1017 int i, j;
1018
Johannes Berga401d2b2011-07-20 00:52:16 +02001019 if (!sband)
1020 return -EINVAL;
1021
Johannes Berg34850ab2011-07-18 18:08:35 +02001022 if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES)
1023 return -EINVAL;
1024
1025 *mask = 0;
1026
1027 for (i = 0; i < n_rates; i++) {
1028 int rate = (rates[i] & 0x7f) * 5;
1029 bool found = false;
1030
1031 for (j = 0; j < sband->n_bitrates; j++) {
1032 if (sband->bitrates[j].bitrate == rate) {
1033 found = true;
1034 *mask |= BIT(j);
1035 break;
1036 }
1037 }
1038 if (!found)
1039 return -EINVAL;
1040 }
Johannes Berg34850ab2011-07-18 18:08:35 +02001041 /*
1042 * mask must have at least one bit set here since we
1043 * didn't accept a 0-length rates array nor allowed
1044 * entries in the array that didn't exist
1045 */
1046
1047 return 0;
1048}
Johannes Berg11a2a352011-11-21 11:09:22 +01001049
1050/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
1051/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
1052const unsigned char rfc1042_header[] __aligned(2) =
1053 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1054EXPORT_SYMBOL(rfc1042_header);
1055
1056/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
1057const unsigned char bridge_tunnel_header[] __aligned(2) =
1058 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
1059EXPORT_SYMBOL(bridge_tunnel_header);