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