Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Wireless utility functions |
| 3 | * |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 4 | * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5 | */ |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 6 | #include <linux/export.h> |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 7 | #include <linux/bitops.h> |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 8 | #include <linux/etherdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 10 | #include <net/cfg80211.h> |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 11 | #include <net/ip.h> |
Dave Täht | b156579 | 2011-12-22 12:55:08 -0800 | [diff] [blame] | 12 | #include <net/dsfield.h> |
cedric Voncken | c6ca5e2 | 2013-08-26 14:04:52 +0200 | [diff] [blame] | 13 | #include <linux/if_vlan.h> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 14 | #include "core.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 15 | #include "rdev-ops.h" |
| 16 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 17 | |
Johannes Berg | bd81525 | 2008-10-29 20:00:45 +0100 | [diff] [blame] | 18 | struct ieee80211_rate * |
| 19 | ieee80211_get_response_rate(struct ieee80211_supported_band *sband, |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 20 | u32 basic_rates, int bitrate) |
Johannes Berg | bd81525 | 2008-10-29 20:00:45 +0100 | [diff] [blame] | 21 | { |
| 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 | } |
| 35 | EXPORT_SYMBOL(ieee80211_get_response_rate); |
| 36 | |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 37 | u32 ieee80211_mandatory_rates(struct ieee80211_supported_band *sband, |
| 38 | enum nl80211_bss_scan_width scan_width) |
Ashok Nagarajan | b422c6c | 2013-05-10 17:50:51 -0700 | [diff] [blame] | 39 | { |
| 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 Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 48 | 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 Nagarajan | b422c6c | 2013-05-10 17:50:51 -0700 | [diff] [blame] | 55 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
Simon Wunderlich | 74608ac | 2013-07-08 16:55:54 +0200 | [diff] [blame] | 56 | } |
Ashok Nagarajan | b422c6c | 2013-05-10 17:50:51 -0700 | [diff] [blame] | 57 | |
| 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 | } |
| 64 | EXPORT_SYMBOL(ieee80211_mandatory_rates); |
| 65 | |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 66 | int ieee80211_channel_to_frequency(int chan, enum ieee80211_band band) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 67 | { |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 68 | /* see 802.11 17.3.8.3.2 and Annex J |
| 69 | * there are overlapping channel numbers in 5GHz and 2GHz bands */ |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 70 | if (chan <= 0) |
| 71 | return 0; /* not supported */ |
| 72 | switch (band) { |
| 73 | case IEEE80211_BAND_2GHZ: |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 74 | if (chan == 14) |
| 75 | return 2484; |
| 76 | else if (chan < 14) |
| 77 | return 2407 + chan * 5; |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 78 | break; |
| 79 | case IEEE80211_BAND_5GHZ: |
| 80 | if (chan >= 182 && chan <= 196) |
| 81 | return 4000 + chan * 5; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 82 | else |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 83 | 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 Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 91 | } |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 92 | return 0; /* not supported */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 93 | } |
| 94 | EXPORT_SYMBOL(ieee80211_channel_to_frequency); |
| 95 | |
| 96 | int ieee80211_frequency_to_channel(int freq) |
| 97 | { |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 98 | /* see 802.11 17.3.8.3.2 and Annex J */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 99 | if (freq == 2484) |
| 100 | return 14; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 101 | else if (freq < 2484) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 102 | return (freq - 2407) / 5; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 103 | else if (freq >= 4910 && freq <= 4980) |
| 104 | return (freq - 4000) / 5; |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 105 | else if (freq <= 45000) /* DMG band lower limit */ |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 106 | return (freq - 5000) / 5; |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 107 | else if (freq >= 58320 && freq <= 64800) |
| 108 | return (freq - 56160) / 2160; |
| 109 | else |
| 110 | return 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 111 | } |
| 112 | EXPORT_SYMBOL(ieee80211_frequency_to_channel); |
| 113 | |
Johannes Berg | 6c507cd | 2008-03-26 14:14:55 +0100 | [diff] [blame] | 114 | struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy, |
| 115 | int freq) |
Johannes Berg | 906c730 | 2008-03-16 18:34:33 +0100 | [diff] [blame] | 116 | { |
| 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 Berg | 6c507cd | 2008-03-26 14:14:55 +0100 | [diff] [blame] | 135 | EXPORT_SYMBOL(__ieee80211_get_channel); |
Johannes Berg | 906c730 | 2008-03-16 18:34:33 +0100 | [diff] [blame] | 136 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 137 | static 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 Berg | aac09fb | 2008-01-30 17:36:10 +0100 | [diff] [blame] | 177 | 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 Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 181 | sband->bitrates[i].flags |= |
| 182 | IEEE80211_RATE_ERP_G; |
| 183 | } |
Ivo van Doorn | 406f238 | 2008-02-02 23:53:10 +0100 | [diff] [blame] | 184 | WARN_ON(want != 0 && want != 3 && want != 6); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 185 | break; |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 186 | 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 Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 191 | case IEEE80211_NUM_BANDS: |
| 192 | WARN_ON(1); |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | void 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 Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 205 | |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 206 | bool 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 Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 215 | int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, |
| 216 | struct key_params *params, int key_idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 217 | bool pairwise, const u8 *mac_addr) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 218 | { |
| 219 | if (key_idx > 5) |
| 220 | return -EINVAL; |
| 221 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 222 | 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 Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 228 | /* |
| 229 | * Disallow pairwise keys with non-zero index unless it's WEP |
Juuso Oikarinen | 45cbad6 | 2011-01-25 12:21:22 +0200 | [diff] [blame] | 230 | * 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 Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 234 | */ |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 235 | if (pairwise && key_idx && |
Juuso Oikarinen | 45cbad6 | 2011-01-25 12:21:22 +0200 | [diff] [blame] | 236 | ((params->cipher == WLAN_CIPHER_SUITE_TKIP) || |
| 237 | (params->cipher == WLAN_CIPHER_SUITE_CCMP) || |
| 238 | (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC))) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 239 | return -EINVAL; |
| 240 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 241 | switch (params->cipher) { |
| 242 | case WLAN_CIPHER_SUITE_WEP40: |
Johannes Berg | 8fc0fee | 2009-05-24 16:57:19 +0200 | [diff] [blame] | 243 | if (params->key_len != WLAN_KEY_LEN_WEP40) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 244 | return -EINVAL; |
| 245 | break; |
| 246 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 8fc0fee | 2009-05-24 16:57:19 +0200 | [diff] [blame] | 247 | if (params->key_len != WLAN_KEY_LEN_TKIP) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | break; |
| 250 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | 8fc0fee | 2009-05-24 16:57:19 +0200 | [diff] [blame] | 251 | if (params->key_len != WLAN_KEY_LEN_CCMP) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 252 | return -EINVAL; |
| 253 | break; |
| 254 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | 8fc0fee | 2009-05-24 16:57:19 +0200 | [diff] [blame] | 255 | if (params->key_len != WLAN_KEY_LEN_WEP104) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 256 | return -EINVAL; |
| 257 | break; |
| 258 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Johannes Berg | 8fc0fee | 2009-05-24 16:57:19 +0200 | [diff] [blame] | 259 | if (params->key_len != WLAN_KEY_LEN_AES_CMAC) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 260 | return -EINVAL; |
| 261 | break; |
| 262 | default: |
Johannes Berg | 7d64b7c | 2010-08-27 14:26:51 +0300 | [diff] [blame] | 263 | /* |
| 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 Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 273 | 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 Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 288 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher)) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 289 | return -EINVAL; |
| 290 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 291 | return 0; |
| 292 | } |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 293 | |
Johannes Berg | 633adf1 | 2010-08-12 14:49:58 +0200 | [diff] [blame] | 294 | unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc) |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 295 | { |
| 296 | unsigned int hdrlen = 24; |
| 297 | |
| 298 | if (ieee80211_is_data(fc)) { |
| 299 | if (ieee80211_has_a4(fc)) |
| 300 | hdrlen = 30; |
Andriy Tkachuk | d0dd2de | 2010-01-20 13:55:06 +0200 | [diff] [blame] | 301 | if (ieee80211_is_data_qos(fc)) { |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 302 | hdrlen += IEEE80211_QOS_CTL_LEN; |
Andriy Tkachuk | d0dd2de | 2010-01-20 13:55:06 +0200 | [diff] [blame] | 303 | if (ieee80211_has_order(fc)) |
| 304 | hdrlen += IEEE80211_HT_CTL_LEN; |
| 305 | } |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 306 | 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 | } |
| 324 | out: |
| 325 | return hdrlen; |
| 326 | } |
| 327 | EXPORT_SYMBOL(ieee80211_hdrlen); |
| 328 | |
| 329 | unsigned 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 | } |
| 342 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); |
| 343 | |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 344 | unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 345 | { |
| 346 | int ae = meshhdr->flags & MESH_FLAGS_AE; |
Johannes Berg | 7dd111e | 2012-10-25 21:51:59 +0200 | [diff] [blame] | 347 | /* 802.11-2012, 8.2.4.7.3 */ |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 348 | switch (ae) { |
Johannes Berg | 7dd111e | 2012-10-25 21:51:59 +0200 | [diff] [blame] | 349 | default: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 350 | case 0: |
| 351 | return 6; |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 352 | case MESH_FLAGS_AE_A4: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 353 | return 12; |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 354 | case MESH_FLAGS_AE_A5_A6: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 355 | return 18; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 356 | } |
| 357 | } |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 358 | EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen); |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 359 | |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 360 | int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr, |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 361 | 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 Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 390 | iftype != NL80211_IFTYPE_AP_VLAN && |
| 391 | iftype != NL80211_IFTYPE_P2P_GO)) |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 392 | return -1; |
| 393 | break; |
| 394 | case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): |
| 395 | if (unlikely(iftype != NL80211_IFTYPE_WDS && |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 396 | iftype != NL80211_IFTYPE_MESH_POINT && |
| 397 | iftype != NL80211_IFTYPE_AP_VLAN && |
| 398 | iftype != NL80211_IFTYPE_STATION)) |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 399 | return -1; |
| 400 | if (iftype == NL80211_IFTYPE_MESH_POINT) { |
| 401 | struct ieee80211s_hdr *meshdr = |
| 402 | (struct ieee80211s_hdr *) (skb->data + hdrlen); |
Zhu Yi | e3cf8b3 | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 403 | /* make sure meshdr->flags is on the linear part */ |
| 404 | if (!pskb_may_pull(skb, hdrlen + 1)) |
| 405 | return -1; |
Johannes Berg | 7dd111e | 2012-10-25 21:51:59 +0200 | [diff] [blame] | 406 | if (meshdr->flags & MESH_FLAGS_AE_A4) |
| 407 | return -1; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 408 | if (meshdr->flags & MESH_FLAGS_AE_A5_A6) { |
Zhu Yi | e3cf8b3 | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 409 | 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 Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 415 | } |
Zhu Yi | e3cf8b3 | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 416 | hdrlen += ieee80211_get_mesh_hdrlen(meshdr); |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 417 | } |
| 418 | break; |
| 419 | case cpu_to_le16(IEEE80211_FCTL_FROMDS): |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 420 | if ((iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 421 | iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 422 | iftype != NL80211_IFTYPE_MESH_POINT) || |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 423 | (is_multicast_ether_addr(dst) && |
Joe Perches | 4c76472 | 2012-05-08 18:56:56 +0000 | [diff] [blame] | 424 | ether_addr_equal(src, addr))) |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 425 | return -1; |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 426 | if (iftype == NL80211_IFTYPE_MESH_POINT) { |
| 427 | struct ieee80211s_hdr *meshdr = |
| 428 | (struct ieee80211s_hdr *) (skb->data + hdrlen); |
Zhu Yi | e3cf8b3 | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 429 | /* make sure meshdr->flags is on the linear part */ |
| 430 | if (!pskb_may_pull(skb, hdrlen + 1)) |
| 431 | return -1; |
Johannes Berg | 7dd111e | 2012-10-25 21:51:59 +0200 | [diff] [blame] | 432 | if (meshdr->flags & MESH_FLAGS_AE_A5_A6) |
| 433 | return -1; |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 434 | if (meshdr->flags & MESH_FLAGS_AE_A4) |
Zhu Yi | e3cf8b3 | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 435 | skb_copy_bits(skb, hdrlen + |
| 436 | offsetof(struct ieee80211s_hdr, eaddr1), |
| 437 | src, ETH_ALEN); |
| 438 | hdrlen += ieee80211_get_mesh_hdrlen(meshdr); |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 439 | } |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 440 | break; |
| 441 | case cpu_to_le16(0): |
Arik Nemtsov | 941c93c | 2011-09-28 14:12:54 +0300 | [diff] [blame] | 442 | if (iftype != NL80211_IFTYPE_ADHOC && |
| 443 | iftype != NL80211_IFTYPE_STATION) |
| 444 | return -1; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 445 | break; |
| 446 | } |
| 447 | |
Zhu Yi | e3cf8b3 | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 448 | if (!pskb_may_pull(skb, hdrlen + 8)) |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 449 | return -1; |
| 450 | |
| 451 | payload = skb->data + hdrlen; |
| 452 | ethertype = (payload[6] << 8) | payload[7]; |
| 453 | |
Joe Perches | 4c76472 | 2012-05-08 18:56:56 +0000 | [diff] [blame] | 454 | if (likely((ether_addr_equal(payload, rfc1042_header) && |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 455 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
Joe Perches | 4c76472 | 2012-05-08 18:56:56 +0000 | [diff] [blame] | 456 | ether_addr_equal(payload, bridge_tunnel_header))) { |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 457 | /* 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 | } |
| 475 | EXPORT_SYMBOL(ieee80211_data_to_8023); |
| 476 | |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 477 | int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr, |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 478 | 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 Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 502 | case NL80211_IFTYPE_P2P_GO: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 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: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 511 | case NL80211_IFTYPE_P2P_CLIENT: |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 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_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 Horman | e5c5d22 | 2013-03-28 13:38:25 +0900 | [diff] [blame] | 544 | } else if (ethertype >= ETH_P_802_3_MIN) { |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 545 | 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 Perches | 2461615 | 2011-08-29 14:17:41 -0700 | [diff] [blame] | 564 | if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 565 | return -ENOMEM; |
Joe Perches | 2461615 | 2011-08-29 14:17:41 -0700 | [diff] [blame] | 566 | |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 567 | 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 | } |
| 590 | EXPORT_SYMBOL(ieee80211_data_from_8023); |
| 591 | |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 592 | |
| 593 | void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list, |
| 594 | const u8 *addr, enum nl80211_iftype iftype, |
Yogesh Ashok Powar | 8b3beca | 2011-05-13 11:22:31 -0700 | [diff] [blame] | 595 | const unsigned int extra_headroom, |
| 596 | bool has_80211_header) |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 597 | { |
| 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 Powar | 8b3beca | 2011-05-13 11:22:31 -0700 | [diff] [blame] | 605 | if (has_80211_header) { |
| 606 | err = ieee80211_data_to_8023(skb, addr, iftype); |
| 607 | if (err) |
| 608 | goto out; |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 609 | |
Yogesh Ashok Powar | 8b3beca | 2011-05-13 11:22:31 -0700 | [diff] [blame] | 610 | /* 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 Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 617 | |
| 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 Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 665 | if (likely((ether_addr_equal(payload, rfc1042_header) && |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 666 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
Joe Perches | ac422d3 | 2012-05-08 18:56:55 +0000 | [diff] [blame] | 667 | ether_addr_equal(payload, bridge_tunnel_header))) { |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 668 | /* 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 | } |
| 689 | EXPORT_SYMBOL(ieee80211_amsdu_to_8023s); |
| 690 | |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 691 | /* Given a data frame determine the 802.1p/1d tag to use. */ |
| 692 | unsigned int cfg80211_classify8021d(struct sk_buff *skb) |
| 693 | { |
| 694 | unsigned int dscp; |
cedric Voncken | c6ca5e2 | 2013-08-26 14:04:52 +0200 | [diff] [blame] | 695 | unsigned char vlan_priority; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 696 | |
| 697 | /* skb->priority values from 256->263 are magic values to |
| 698 | * directly indicate a specific 802.1d priority. This is used |
| 699 | * to allow 802.1d priority to be passed directly in from VLAN |
| 700 | * tags, etc. |
| 701 | */ |
| 702 | if (skb->priority >= 256 && skb->priority <= 263) |
| 703 | return skb->priority - 256; |
| 704 | |
cedric Voncken | c6ca5e2 | 2013-08-26 14:04:52 +0200 | [diff] [blame] | 705 | if (vlan_tx_tag_present(skb)) { |
| 706 | vlan_priority = (vlan_tx_tag_get(skb) & VLAN_PRIO_MASK) |
| 707 | >> VLAN_PRIO_SHIFT; |
| 708 | if (vlan_priority > 0) |
| 709 | return vlan_priority; |
| 710 | } |
| 711 | |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 712 | switch (skb->protocol) { |
| 713 | case htons(ETH_P_IP): |
Dave Täht | b156579 | 2011-12-22 12:55:08 -0800 | [diff] [blame] | 714 | dscp = ipv4_get_dsfield(ip_hdr(skb)) & 0xfc; |
| 715 | break; |
| 716 | case htons(ETH_P_IPV6): |
| 717 | dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & 0xfc; |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 718 | break; |
| 719 | default: |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | return dscp >> 5; |
| 724 | } |
| 725 | EXPORT_SYMBOL(cfg80211_classify8021d); |
Johannes Berg | 517357c | 2009-07-02 17:18:40 +0200 | [diff] [blame] | 726 | |
| 727 | const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie) |
| 728 | { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 729 | const struct cfg80211_bss_ies *ies; |
| 730 | |
| 731 | ies = rcu_dereference(bss->ies); |
| 732 | if (!ies) |
Johannes Berg | 517357c | 2009-07-02 17:18:40 +0200 | [diff] [blame] | 733 | return NULL; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 734 | |
| 735 | return cfg80211_find_ie(ie, ies->data, ies->len); |
Johannes Berg | 517357c | 2009-07-02 17:18:40 +0200 | [diff] [blame] | 736 | } |
| 737 | EXPORT_SYMBOL(ieee80211_bss_get_ie); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 738 | |
| 739 | void cfg80211_upload_connect_keys(struct wireless_dev *wdev) |
| 740 | { |
| 741 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 742 | struct net_device *dev = wdev->netdev; |
| 743 | int i; |
| 744 | |
| 745 | if (!wdev->connect_keys) |
| 746 | return; |
| 747 | |
| 748 | for (i = 0; i < 6; i++) { |
| 749 | if (!wdev->connect_keys->params[i].cipher) |
| 750 | continue; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 751 | if (rdev_add_key(rdev, dev, i, false, NULL, |
| 752 | &wdev->connect_keys->params[i])) { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 753 | netdev_err(dev, "failed to set key %d\n", i); |
Zhu Yi | 1e05666 | 2009-07-20 16:12:57 +0800 | [diff] [blame] | 754 | continue; |
| 755 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 756 | if (wdev->connect_keys->def == i) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 757 | if (rdev_set_default_key(rdev, dev, i, true, true)) { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 758 | netdev_err(dev, "failed to set defkey %d\n", i); |
Zhu Yi | 1e05666 | 2009-07-20 16:12:57 +0800 | [diff] [blame] | 759 | continue; |
| 760 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 761 | if (wdev->connect_keys->defmgmt == i) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 762 | if (rdev_set_default_mgmt_key(rdev, dev, i)) |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 763 | netdev_err(dev, "failed to set mgtdef %d\n", i); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | kfree(wdev->connect_keys); |
| 767 | wdev->connect_keys = NULL; |
| 768 | } |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 769 | |
Daniel Drake | 1f6fc43 | 2012-08-02 18:41:48 +0100 | [diff] [blame] | 770 | void cfg80211_process_wdev_events(struct wireless_dev *wdev) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 771 | { |
| 772 | struct cfg80211_event *ev; |
| 773 | unsigned long flags; |
| 774 | const u8 *bssid = NULL; |
| 775 | |
| 776 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 777 | while (!list_empty(&wdev->event_list)) { |
| 778 | ev = list_first_entry(&wdev->event_list, |
| 779 | struct cfg80211_event, list); |
| 780 | list_del(&ev->list); |
| 781 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 782 | |
| 783 | wdev_lock(wdev); |
| 784 | switch (ev->type) { |
| 785 | case EVENT_CONNECT_RESULT: |
| 786 | if (!is_zero_ether_addr(ev->cr.bssid)) |
| 787 | bssid = ev->cr.bssid; |
| 788 | __cfg80211_connect_result( |
| 789 | wdev->netdev, bssid, |
| 790 | ev->cr.req_ie, ev->cr.req_ie_len, |
| 791 | ev->cr.resp_ie, ev->cr.resp_ie_len, |
| 792 | ev->cr.status, |
| 793 | ev->cr.status == WLAN_STATUS_SUCCESS, |
| 794 | NULL); |
| 795 | break; |
| 796 | case EVENT_ROAMED: |
Vasanthakumar Thiagarajan | adbde34 | 2011-12-08 14:28:47 +0530 | [diff] [blame] | 797 | __cfg80211_roamed(wdev, ev->rm.bss, ev->rm.req_ie, |
| 798 | ev->rm.req_ie_len, ev->rm.resp_ie, |
| 799 | ev->rm.resp_ie_len); |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 800 | break; |
| 801 | case EVENT_DISCONNECTED: |
| 802 | __cfg80211_disconnected(wdev->netdev, |
| 803 | ev->dc.ie, ev->dc.ie_len, |
| 804 | ev->dc.reason, true); |
| 805 | break; |
| 806 | case EVENT_IBSS_JOINED: |
| 807 | __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid); |
| 808 | break; |
| 809 | } |
| 810 | wdev_unlock(wdev); |
| 811 | |
| 812 | kfree(ev); |
| 813 | |
| 814 | spin_lock_irqsave(&wdev->event_lock, flags); |
| 815 | } |
| 816 | spin_unlock_irqrestore(&wdev->event_lock, flags); |
| 817 | } |
| 818 | |
| 819 | void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev) |
| 820 | { |
| 821 | struct wireless_dev *wdev; |
| 822 | |
| 823 | ASSERT_RTNL(); |
| 824 | ASSERT_RDEV_LOCK(rdev); |
| 825 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 826 | list_for_each_entry(wdev, &rdev->wdev_list, list) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 827 | cfg80211_process_wdev_events(wdev); |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | int cfg80211_change_iface(struct cfg80211_registered_device *rdev, |
| 831 | struct net_device *dev, enum nl80211_iftype ntype, |
| 832 | u32 *flags, struct vif_params *params) |
| 833 | { |
| 834 | int err; |
| 835 | enum nl80211_iftype otype = dev->ieee80211_ptr->iftype; |
| 836 | |
| 837 | ASSERT_RDEV_LOCK(rdev); |
| 838 | |
| 839 | /* don't support changing VLANs, you just re-create them */ |
| 840 | if (otype == NL80211_IFTYPE_AP_VLAN) |
| 841 | return -EOPNOTSUPP; |
| 842 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 843 | /* cannot change into P2P device type */ |
| 844 | if (ntype == NL80211_IFTYPE_P2P_DEVICE) |
| 845 | return -EOPNOTSUPP; |
| 846 | |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 847 | if (!rdev->ops->change_virtual_intf || |
| 848 | !(rdev->wiphy.interface_modes & (1 << ntype))) |
| 849 | return -EOPNOTSUPP; |
| 850 | |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 851 | /* if it's part of a bridge, reject changing type to station/ibss */ |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 852 | if ((dev->priv_flags & IFF_BRIDGE_PORT) && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 853 | (ntype == NL80211_IFTYPE_ADHOC || |
| 854 | ntype == NL80211_IFTYPE_STATION || |
| 855 | ntype == NL80211_IFTYPE_P2P_CLIENT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 856 | return -EBUSY; |
| 857 | |
Michal Kazior | f8cdddb | 2012-06-08 10:55:44 +0200 | [diff] [blame] | 858 | if (ntype != otype && netif_running(dev)) { |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 859 | err = cfg80211_can_change_interface(rdev, dev->ieee80211_ptr, |
| 860 | ntype); |
| 861 | if (err) |
| 862 | return err; |
| 863 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 864 | dev->ieee80211_ptr->use_4addr = false; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 865 | dev->ieee80211_ptr->mesh_id_up_len = 0; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 866 | |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 867 | switch (otype) { |
Michal Kazior | ac80014 | 2012-06-29 12:46:57 +0200 | [diff] [blame] | 868 | case NL80211_IFTYPE_AP: |
| 869 | cfg80211_stop_ap(rdev, dev); |
| 870 | break; |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 871 | case NL80211_IFTYPE_ADHOC: |
| 872 | cfg80211_leave_ibss(rdev, dev, false); |
| 873 | break; |
| 874 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 875 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 876 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 877 | cfg80211_disconnect(rdev, dev, |
| 878 | WLAN_REASON_DEAUTH_LEAVING, true); |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 879 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 880 | break; |
| 881 | case NL80211_IFTYPE_MESH_POINT: |
| 882 | /* mesh should be handled? */ |
| 883 | break; |
| 884 | default: |
| 885 | break; |
| 886 | } |
| 887 | |
| 888 | cfg80211_process_rdev_events(rdev); |
| 889 | } |
| 890 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 891 | err = rdev_change_virtual_intf(rdev, dev, ntype, flags, params); |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 892 | |
| 893 | WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype); |
| 894 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 895 | if (!err && params && params->use_4addr != -1) |
| 896 | dev->ieee80211_ptr->use_4addr = params->use_4addr; |
| 897 | |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 898 | if (!err) { |
| 899 | dev->priv_flags &= ~IFF_DONT_BRIDGE; |
| 900 | switch (ntype) { |
| 901 | case NL80211_IFTYPE_STATION: |
| 902 | if (dev->ieee80211_ptr->use_4addr) |
| 903 | break; |
| 904 | /* fall through */ |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 905 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 906 | case NL80211_IFTYPE_ADHOC: |
| 907 | dev->priv_flags |= IFF_DONT_BRIDGE; |
| 908 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 909 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 910 | case NL80211_IFTYPE_AP: |
| 911 | case NL80211_IFTYPE_AP_VLAN: |
| 912 | case NL80211_IFTYPE_WDS: |
| 913 | case NL80211_IFTYPE_MESH_POINT: |
| 914 | /* bridging OK */ |
| 915 | break; |
| 916 | case NL80211_IFTYPE_MONITOR: |
| 917 | /* monitor can't bridge anyway */ |
| 918 | break; |
| 919 | case NL80211_IFTYPE_UNSPECIFIED: |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 920 | case NUM_NL80211_IFTYPES: |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 921 | /* not happening */ |
| 922 | break; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 923 | case NL80211_IFTYPE_P2P_DEVICE: |
| 924 | WARN_ON(1); |
| 925 | break; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 926 | } |
| 927 | } |
| 928 | |
Michal Kazior | dbbae26 | 2012-06-29 12:47:01 +0200 | [diff] [blame] | 929 | if (!err && ntype != otype && netif_running(dev)) { |
| 930 | cfg80211_update_iface_num(rdev, ntype, 1); |
| 931 | cfg80211_update_iface_num(rdev, otype, -1); |
| 932 | } |
| 933 | |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 934 | return err; |
| 935 | } |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 936 | |
Vladimir Kondratiev | 95ddc1f | 2012-07-05 14:25:50 +0300 | [diff] [blame] | 937 | static u32 cfg80211_calculate_bitrate_60g(struct rate_info *rate) |
| 938 | { |
| 939 | static const u32 __mcs2bitrate[] = { |
| 940 | /* control PHY */ |
| 941 | [0] = 275, |
| 942 | /* SC PHY */ |
| 943 | [1] = 3850, |
| 944 | [2] = 7700, |
| 945 | [3] = 9625, |
| 946 | [4] = 11550, |
| 947 | [5] = 12512, /* 1251.25 mbps */ |
| 948 | [6] = 15400, |
| 949 | [7] = 19250, |
| 950 | [8] = 23100, |
| 951 | [9] = 25025, |
| 952 | [10] = 30800, |
| 953 | [11] = 38500, |
| 954 | [12] = 46200, |
| 955 | /* OFDM PHY */ |
| 956 | [13] = 6930, |
| 957 | [14] = 8662, /* 866.25 mbps */ |
| 958 | [15] = 13860, |
| 959 | [16] = 17325, |
| 960 | [17] = 20790, |
| 961 | [18] = 27720, |
| 962 | [19] = 34650, |
| 963 | [20] = 41580, |
| 964 | [21] = 45045, |
| 965 | [22] = 51975, |
| 966 | [23] = 62370, |
| 967 | [24] = 67568, /* 6756.75 mbps */ |
| 968 | /* LP-SC PHY */ |
| 969 | [25] = 6260, |
| 970 | [26] = 8340, |
| 971 | [27] = 11120, |
| 972 | [28] = 12510, |
| 973 | [29] = 16680, |
| 974 | [30] = 22240, |
| 975 | [31] = 25030, |
| 976 | }; |
| 977 | |
| 978 | if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate))) |
| 979 | return 0; |
| 980 | |
| 981 | return __mcs2bitrate[rate->mcs]; |
| 982 | } |
| 983 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 984 | static u32 cfg80211_calculate_bitrate_vht(struct rate_info *rate) |
| 985 | { |
| 986 | static const u32 base[4][10] = { |
| 987 | { 6500000, |
| 988 | 13000000, |
| 989 | 19500000, |
| 990 | 26000000, |
| 991 | 39000000, |
| 992 | 52000000, |
| 993 | 58500000, |
| 994 | 65000000, |
| 995 | 78000000, |
| 996 | 0, |
| 997 | }, |
| 998 | { 13500000, |
| 999 | 27000000, |
| 1000 | 40500000, |
| 1001 | 54000000, |
| 1002 | 81000000, |
| 1003 | 108000000, |
| 1004 | 121500000, |
| 1005 | 135000000, |
| 1006 | 162000000, |
| 1007 | 180000000, |
| 1008 | }, |
| 1009 | { 29300000, |
| 1010 | 58500000, |
| 1011 | 87800000, |
| 1012 | 117000000, |
| 1013 | 175500000, |
| 1014 | 234000000, |
| 1015 | 263300000, |
| 1016 | 292500000, |
| 1017 | 351000000, |
| 1018 | 390000000, |
| 1019 | }, |
| 1020 | { 58500000, |
| 1021 | 117000000, |
| 1022 | 175500000, |
| 1023 | 234000000, |
| 1024 | 351000000, |
| 1025 | 468000000, |
| 1026 | 526500000, |
| 1027 | 585000000, |
| 1028 | 702000000, |
| 1029 | 780000000, |
| 1030 | }, |
| 1031 | }; |
| 1032 | u32 bitrate; |
| 1033 | int idx; |
| 1034 | |
| 1035 | if (WARN_ON_ONCE(rate->mcs > 9)) |
| 1036 | return 0; |
| 1037 | |
| 1038 | idx = rate->flags & (RATE_INFO_FLAGS_160_MHZ_WIDTH | |
| 1039 | RATE_INFO_FLAGS_80P80_MHZ_WIDTH) ? 3 : |
| 1040 | rate->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH ? 2 : |
| 1041 | rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH ? 1 : 0; |
| 1042 | |
| 1043 | bitrate = base[idx][rate->mcs]; |
| 1044 | bitrate *= rate->nss; |
| 1045 | |
| 1046 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1047 | bitrate = (bitrate / 9) * 10; |
| 1048 | |
| 1049 | /* do NOT round down here */ |
| 1050 | return (bitrate + 50000) / 100000; |
| 1051 | } |
| 1052 | |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 1053 | u32 cfg80211_calculate_bitrate(struct rate_info *rate) |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 1054 | { |
| 1055 | int modulation, streams, bitrate; |
| 1056 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 1057 | if (!(rate->flags & RATE_INFO_FLAGS_MCS) && |
| 1058 | !(rate->flags & RATE_INFO_FLAGS_VHT_MCS)) |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 1059 | return rate->legacy; |
Vladimir Kondratiev | 95ddc1f | 2012-07-05 14:25:50 +0300 | [diff] [blame] | 1060 | if (rate->flags & RATE_INFO_FLAGS_60G) |
| 1061 | return cfg80211_calculate_bitrate_60g(rate); |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 1062 | if (rate->flags & RATE_INFO_FLAGS_VHT_MCS) |
| 1063 | return cfg80211_calculate_bitrate_vht(rate); |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 1064 | |
| 1065 | /* the formula below does only work for MCS values smaller than 32 */ |
Johannes Berg | 2615f37 | 2012-05-08 21:36:20 +0200 | [diff] [blame] | 1066 | if (WARN_ON_ONCE(rate->mcs >= 32)) |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 1067 | return 0; |
| 1068 | |
| 1069 | modulation = rate->mcs & 7; |
| 1070 | streams = (rate->mcs >> 3) + 1; |
| 1071 | |
| 1072 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? |
| 1073 | 13500000 : 6500000; |
| 1074 | |
| 1075 | if (modulation < 4) |
| 1076 | bitrate *= (modulation + 1); |
| 1077 | else if (modulation == 4) |
| 1078 | bitrate *= (modulation + 2); |
| 1079 | else |
| 1080 | bitrate *= (modulation + 3); |
| 1081 | |
| 1082 | bitrate *= streams; |
| 1083 | |
| 1084 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1085 | bitrate = (bitrate / 9) * 10; |
| 1086 | |
| 1087 | /* do NOT round down here */ |
| 1088 | return (bitrate + 50000) / 100000; |
| 1089 | } |
Thomas Pedersen | 8097e14 | 2012-03-05 15:31:47 -0800 | [diff] [blame] | 1090 | EXPORT_SYMBOL(cfg80211_calculate_bitrate); |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1091 | |
Arend van Spriel | c216e64 | 2012-11-25 19:13:28 +0100 | [diff] [blame] | 1092 | int cfg80211_get_p2p_attr(const u8 *ies, unsigned int len, |
| 1093 | enum ieee80211_p2p_attr_id attr, |
| 1094 | u8 *buf, unsigned int bufsize) |
Johannes Berg | 0ee4535 | 2012-10-29 19:48:40 +0100 | [diff] [blame] | 1095 | { |
| 1096 | u8 *out = buf; |
| 1097 | u16 attr_remaining = 0; |
| 1098 | bool desired_attr = false; |
| 1099 | u16 desired_len = 0; |
| 1100 | |
| 1101 | while (len > 0) { |
| 1102 | unsigned int iedatalen; |
| 1103 | unsigned int copy; |
| 1104 | const u8 *iedata; |
| 1105 | |
| 1106 | if (len < 2) |
| 1107 | return -EILSEQ; |
| 1108 | iedatalen = ies[1]; |
| 1109 | if (iedatalen + 2 > len) |
| 1110 | return -EILSEQ; |
| 1111 | |
| 1112 | if (ies[0] != WLAN_EID_VENDOR_SPECIFIC) |
| 1113 | goto cont; |
| 1114 | |
| 1115 | if (iedatalen < 4) |
| 1116 | goto cont; |
| 1117 | |
| 1118 | iedata = ies + 2; |
| 1119 | |
| 1120 | /* check WFA OUI, P2P subtype */ |
| 1121 | if (iedata[0] != 0x50 || iedata[1] != 0x6f || |
| 1122 | iedata[2] != 0x9a || iedata[3] != 0x09) |
| 1123 | goto cont; |
| 1124 | |
| 1125 | iedatalen -= 4; |
| 1126 | iedata += 4; |
| 1127 | |
| 1128 | /* check attribute continuation into this IE */ |
| 1129 | copy = min_t(unsigned int, attr_remaining, iedatalen); |
| 1130 | if (copy && desired_attr) { |
| 1131 | desired_len += copy; |
| 1132 | if (out) { |
| 1133 | memcpy(out, iedata, min(bufsize, copy)); |
| 1134 | out += min(bufsize, copy); |
| 1135 | bufsize -= min(bufsize, copy); |
| 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | if (copy == attr_remaining) |
| 1140 | return desired_len; |
| 1141 | } |
| 1142 | |
| 1143 | attr_remaining -= copy; |
| 1144 | if (attr_remaining) |
| 1145 | goto cont; |
| 1146 | |
| 1147 | iedatalen -= copy; |
| 1148 | iedata += copy; |
| 1149 | |
| 1150 | while (iedatalen > 0) { |
| 1151 | u16 attr_len; |
| 1152 | |
| 1153 | /* P2P attribute ID & size must fit */ |
| 1154 | if (iedatalen < 3) |
| 1155 | return -EILSEQ; |
| 1156 | desired_attr = iedata[0] == attr; |
| 1157 | attr_len = get_unaligned_le16(iedata + 1); |
| 1158 | iedatalen -= 3; |
| 1159 | iedata += 3; |
| 1160 | |
| 1161 | copy = min_t(unsigned int, attr_len, iedatalen); |
| 1162 | |
| 1163 | if (desired_attr) { |
| 1164 | desired_len += copy; |
| 1165 | if (out) { |
| 1166 | memcpy(out, iedata, min(bufsize, copy)); |
| 1167 | out += min(bufsize, copy); |
| 1168 | bufsize -= min(bufsize, copy); |
| 1169 | } |
| 1170 | |
| 1171 | if (copy == attr_len) |
| 1172 | return desired_len; |
| 1173 | } |
| 1174 | |
| 1175 | iedata += copy; |
| 1176 | iedatalen -= copy; |
| 1177 | attr_remaining = attr_len - copy; |
| 1178 | } |
| 1179 | |
| 1180 | cont: |
| 1181 | len -= ies[1] + 2; |
| 1182 | ies += ies[1] + 2; |
| 1183 | } |
| 1184 | |
| 1185 | if (attr_remaining && desired_attr) |
| 1186 | return -EILSEQ; |
| 1187 | |
| 1188 | return -ENOENT; |
| 1189 | } |
| 1190 | EXPORT_SYMBOL(cfg80211_get_p2p_attr); |
| 1191 | |
Johannes Berg | 1ce3e82 | 2012-08-01 17:00:55 +0200 | [diff] [blame] | 1192 | bool ieee80211_operating_class_to_band(u8 operating_class, |
| 1193 | enum ieee80211_band *band) |
| 1194 | { |
| 1195 | switch (operating_class) { |
| 1196 | case 112: |
| 1197 | case 115 ... 127: |
| 1198 | *band = IEEE80211_BAND_5GHZ; |
| 1199 | return true; |
| 1200 | case 81: |
| 1201 | case 82: |
| 1202 | case 83: |
| 1203 | case 84: |
| 1204 | *band = IEEE80211_BAND_2GHZ; |
| 1205 | return true; |
Vladimir Kondratiev | 55300a1 | 2013-04-23 09:54:21 +0300 | [diff] [blame] | 1206 | case 180: |
| 1207 | *band = IEEE80211_BAND_60GHZ; |
| 1208 | return true; |
Johannes Berg | 1ce3e82 | 2012-08-01 17:00:55 +0200 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | return false; |
| 1212 | } |
| 1213 | EXPORT_SYMBOL(ieee80211_operating_class_to_band); |
| 1214 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1215 | int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev, |
| 1216 | u32 beacon_int) |
| 1217 | { |
| 1218 | struct wireless_dev *wdev; |
| 1219 | int res = 0; |
| 1220 | |
| 1221 | if (!beacon_int) |
| 1222 | return -EINVAL; |
| 1223 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1224 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1225 | if (!wdev->beacon_interval) |
| 1226 | continue; |
| 1227 | if (wdev->beacon_interval != beacon_int) { |
| 1228 | res = -EINVAL; |
| 1229 | break; |
| 1230 | } |
| 1231 | } |
| 1232 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 1233 | return res; |
| 1234 | } |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1235 | |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1236 | int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev, |
| 1237 | struct wireless_dev *wdev, |
| 1238 | enum nl80211_iftype iftype, |
| 1239 | struct ieee80211_channel *chan, |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1240 | enum cfg80211_chan_mode chanmode, |
| 1241 | u8 radar_detect) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1242 | { |
| 1243 | struct wireless_dev *wdev_iter; |
Johannes Berg | 463454b | 2012-06-05 12:16:50 +0200 | [diff] [blame] | 1244 | u32 used_iftypes = BIT(iftype); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1245 | int num[NUM_NL80211_IFTYPES]; |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1246 | struct ieee80211_channel |
| 1247 | *used_channels[CFG80211_MAX_NUM_DIFFERENT_CHANNELS]; |
| 1248 | struct ieee80211_channel *ch; |
| 1249 | enum cfg80211_chan_mode chmode; |
| 1250 | int num_different_channels = 0; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1251 | int total = 1; |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1252 | bool radar_required; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1253 | int i, j; |
| 1254 | |
| 1255 | ASSERT_RTNL(); |
| 1256 | |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1257 | if (WARN_ON(hweight32(radar_detect) > 1)) |
| 1258 | return -EINVAL; |
| 1259 | |
| 1260 | switch (iftype) { |
| 1261 | case NL80211_IFTYPE_ADHOC: |
| 1262 | case NL80211_IFTYPE_AP: |
| 1263 | case NL80211_IFTYPE_AP_VLAN: |
| 1264 | case NL80211_IFTYPE_MESH_POINT: |
| 1265 | case NL80211_IFTYPE_P2P_GO: |
| 1266 | case NL80211_IFTYPE_WDS: |
Simon Wunderlich | 683d41a | 2013-01-23 15:15:57 +0100 | [diff] [blame] | 1267 | radar_required = !!(chan && |
| 1268 | (chan->flags & IEEE80211_CHAN_RADAR)); |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1269 | break; |
| 1270 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1271 | case NL80211_IFTYPE_STATION: |
Ilan Peer | bba87ff | 2013-02-03 08:28:27 +0200 | [diff] [blame] | 1272 | case NL80211_IFTYPE_P2P_DEVICE: |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1273 | case NL80211_IFTYPE_MONITOR: |
| 1274 | radar_required = false; |
| 1275 | break; |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1276 | case NUM_NL80211_IFTYPES: |
| 1277 | case NL80211_IFTYPE_UNSPECIFIED: |
| 1278 | default: |
| 1279 | return -EINVAL; |
| 1280 | } |
| 1281 | |
| 1282 | if (radar_required && !radar_detect) |
| 1283 | return -EINVAL; |
| 1284 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1285 | /* Always allow software iftypes */ |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1286 | if (rdev->wiphy.software_iftypes & BIT(iftype)) { |
| 1287 | if (radar_detect) |
| 1288 | return -EINVAL; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1289 | return 0; |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1290 | } |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1291 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1292 | memset(num, 0, sizeof(num)); |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1293 | memset(used_channels, 0, sizeof(used_channels)); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1294 | |
| 1295 | num[iftype] = 1; |
| 1296 | |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1297 | switch (chanmode) { |
| 1298 | case CHAN_MODE_UNDEFINED: |
| 1299 | break; |
| 1300 | case CHAN_MODE_SHARED: |
| 1301 | WARN_ON(!chan); |
| 1302 | used_channels[0] = chan; |
| 1303 | num_different_channels++; |
| 1304 | break; |
| 1305 | case CHAN_MODE_EXCLUSIVE: |
| 1306 | num_different_channels++; |
| 1307 | break; |
| 1308 | } |
| 1309 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 1310 | list_for_each_entry(wdev_iter, &rdev->wdev_list, list) { |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1311 | if (wdev_iter == wdev) |
| 1312 | continue; |
Johannes Berg | 6e3ab55 | 2013-04-19 12:19:39 +0200 | [diff] [blame] | 1313 | if (wdev_iter->iftype == NL80211_IFTYPE_P2P_DEVICE) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1314 | if (!wdev_iter->p2p_started) |
| 1315 | continue; |
Johannes Berg | 6e3ab55 | 2013-04-19 12:19:39 +0200 | [diff] [blame] | 1316 | } else if (wdev_iter->netdev) { |
| 1317 | if (!netif_running(wdev_iter->netdev)) |
| 1318 | continue; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 1319 | } else { |
| 1320 | WARN_ON(1); |
| 1321 | } |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1322 | |
| 1323 | if (rdev->wiphy.software_iftypes & BIT(wdev_iter->iftype)) |
| 1324 | continue; |
| 1325 | |
Johannes Berg | 8e95ea4 | 2012-07-10 19:39:02 +0200 | [diff] [blame] | 1326 | /* |
| 1327 | * We may be holding the "wdev" mutex, but now need to lock |
| 1328 | * wdev_iter. This is OK because once we get here wdev_iter |
| 1329 | * is not wdev (tested above), but we need to use the nested |
| 1330 | * locking for lockdep. |
| 1331 | */ |
| 1332 | mutex_lock_nested(&wdev_iter->mtx, 1); |
| 1333 | __acquire(wdev_iter->mtx); |
| 1334 | cfg80211_get_chan_state(wdev_iter, &ch, &chmode); |
| 1335 | wdev_unlock(wdev_iter); |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1336 | |
| 1337 | switch (chmode) { |
| 1338 | case CHAN_MODE_UNDEFINED: |
| 1339 | break; |
| 1340 | case CHAN_MODE_SHARED: |
| 1341 | for (i = 0; i < CFG80211_MAX_NUM_DIFFERENT_CHANNELS; i++) |
| 1342 | if (!used_channels[i] || used_channels[i] == ch) |
| 1343 | break; |
| 1344 | |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 1345 | if (i == CFG80211_MAX_NUM_DIFFERENT_CHANNELS) |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1346 | return -EBUSY; |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1347 | |
| 1348 | if (used_channels[i] == NULL) { |
| 1349 | used_channels[i] = ch; |
| 1350 | num_different_channels++; |
| 1351 | } |
| 1352 | break; |
| 1353 | case CHAN_MODE_EXCLUSIVE: |
| 1354 | num_different_channels++; |
| 1355 | break; |
| 1356 | } |
| 1357 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1358 | num[wdev_iter->iftype]++; |
| 1359 | total++; |
Johannes Berg | 463454b | 2012-06-05 12:16:50 +0200 | [diff] [blame] | 1360 | used_iftypes |= BIT(wdev_iter->iftype); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1361 | } |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1362 | |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1363 | if (total == 1 && !radar_detect) |
Johannes Berg | 8e8b41f | 2012-03-15 10:16:16 +0100 | [diff] [blame] | 1364 | return 0; |
| 1365 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1366 | for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) { |
| 1367 | const struct ieee80211_iface_combination *c; |
| 1368 | struct ieee80211_iface_limit *limits; |
Johannes Berg | 463454b | 2012-06-05 12:16:50 +0200 | [diff] [blame] | 1369 | u32 all_iftypes = 0; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1370 | |
| 1371 | c = &rdev->wiphy.iface_combinations[i]; |
| 1372 | |
Michal Kazior | d4e50c5 | 2012-06-29 12:47:07 +0200 | [diff] [blame] | 1373 | if (total > c->max_interfaces) |
| 1374 | continue; |
| 1375 | if (num_different_channels > c->num_different_channels) |
| 1376 | continue; |
| 1377 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1378 | limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits, |
| 1379 | GFP_KERNEL); |
| 1380 | if (!limits) |
| 1381 | return -ENOMEM; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1382 | |
| 1383 | for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) { |
| 1384 | if (rdev->wiphy.software_iftypes & BIT(iftype)) |
| 1385 | continue; |
| 1386 | for (j = 0; j < c->n_limits; j++) { |
Johannes Berg | 463454b | 2012-06-05 12:16:50 +0200 | [diff] [blame] | 1387 | all_iftypes |= limits[j].types; |
Lukasz Kucharczyk | e55a404 | 2012-04-11 14:55:10 +0200 | [diff] [blame] | 1388 | if (!(limits[j].types & BIT(iftype))) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1389 | continue; |
| 1390 | if (limits[j].max < num[iftype]) |
| 1391 | goto cont; |
| 1392 | limits[j].max -= num[iftype]; |
| 1393 | } |
| 1394 | } |
Johannes Berg | 463454b | 2012-06-05 12:16:50 +0200 | [diff] [blame] | 1395 | |
Simon Wunderlich | 11c4a07 | 2013-01-08 14:04:07 +0100 | [diff] [blame] | 1396 | if (radar_detect && !(c->radar_detect_widths & radar_detect)) |
| 1397 | goto cont; |
| 1398 | |
Johannes Berg | 463454b | 2012-06-05 12:16:50 +0200 | [diff] [blame] | 1399 | /* |
| 1400 | * Finally check that all iftypes that we're currently |
| 1401 | * using are actually part of this combination. If they |
| 1402 | * aren't then we can't use this combination and have |
| 1403 | * to continue to the next. |
| 1404 | */ |
| 1405 | if ((all_iftypes & used_iftypes) != used_iftypes) |
| 1406 | goto cont; |
| 1407 | |
| 1408 | /* |
| 1409 | * This combination covered all interface types and |
| 1410 | * supported the requested numbers, so we're good. |
| 1411 | */ |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1412 | kfree(limits); |
| 1413 | return 0; |
| 1414 | cont: |
| 1415 | kfree(limits); |
| 1416 | } |
| 1417 | |
| 1418 | return -EBUSY; |
| 1419 | } |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 1420 | |
| 1421 | int ieee80211_get_ratemask(struct ieee80211_supported_band *sband, |
| 1422 | const u8 *rates, unsigned int n_rates, |
| 1423 | u32 *mask) |
| 1424 | { |
| 1425 | int i, j; |
| 1426 | |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 1427 | if (!sband) |
| 1428 | return -EINVAL; |
| 1429 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 1430 | if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES) |
| 1431 | return -EINVAL; |
| 1432 | |
| 1433 | *mask = 0; |
| 1434 | |
| 1435 | for (i = 0; i < n_rates; i++) { |
| 1436 | int rate = (rates[i] & 0x7f) * 5; |
| 1437 | bool found = false; |
| 1438 | |
| 1439 | for (j = 0; j < sband->n_bitrates; j++) { |
| 1440 | if (sband->bitrates[j].bitrate == rate) { |
| 1441 | found = true; |
| 1442 | *mask |= BIT(j); |
| 1443 | break; |
| 1444 | } |
| 1445 | } |
| 1446 | if (!found) |
| 1447 | return -EINVAL; |
| 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | * mask must have at least one bit set here since we |
| 1452 | * didn't accept a 0-length rates array nor allowed |
| 1453 | * entries in the array that didn't exist |
| 1454 | */ |
| 1455 | |
| 1456 | return 0; |
| 1457 | } |
Johannes Berg | 11a2a35 | 2011-11-21 11:09:22 +0100 | [diff] [blame] | 1458 | |
| 1459 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 1460 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
| 1461 | const unsigned char rfc1042_header[] __aligned(2) = |
| 1462 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 1463 | EXPORT_SYMBOL(rfc1042_header); |
| 1464 | |
| 1465 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
| 1466 | const unsigned char bridge_tunnel_header[] __aligned(2) = |
| 1467 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
| 1468 | EXPORT_SYMBOL(bridge_tunnel_header); |