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