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