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