Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
8318d78a JB |
2 | /* |
3 | * Wireless utility functions | |
4 | * | |
d3236553 | 5 | * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net> |
2740f0cf | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
c4cbaf79 | 7 | * Copyright 2017 Intel Deutschland GmbH |
b5c16227 | 8 | * Copyright (C) 2018-2023, 2025 Intel Corporation |
8318d78a | 9 | */ |
bc3b2d7f | 10 | #include <linux/export.h> |
d3236553 | 11 | #include <linux/bitops.h> |
e31a16d6 | 12 | #include <linux/etherdevice.h> |
5a0e3ad6 | 13 | #include <linux/slab.h> |
b0aa75f0 | 14 | #include <linux/ieee80211.h> |
d3236553 | 15 | #include <net/cfg80211.h> |
e31a16d6 | 16 | #include <net/ip.h> |
b156579b | 17 | #include <net/dsfield.h> |
c6ca5e28 | 18 | #include <linux/if_vlan.h> |
960d97f9 | 19 | #include <linux/mpls.h> |
4c8dea63 | 20 | #include <linux/gcd.h> |
b0aa75f0 | 21 | #include <linux/bitfield.h> |
1fc9b725 | 22 | #include <linux/nospec.h> |
8318d78a | 23 | #include "core.h" |
e35e4d28 HG |
24 | #include "rdev-ops.h" |
25 | ||
8318d78a | 26 | |
623b988f | 27 | const struct ieee80211_rate * |
bd815252 | 28 | ieee80211_get_response_rate(struct ieee80211_supported_band *sband, |
881d948c | 29 | u32 basic_rates, int bitrate) |
bd815252 JB |
30 | { |
31 | struct ieee80211_rate *result = &sband->bitrates[0]; | |
32 | int i; | |
33 | ||
34 | for (i = 0; i < sband->n_bitrates; i++) { | |
35 | if (!(basic_rates & BIT(i))) | |
36 | continue; | |
37 | if (sband->bitrates[i].bitrate > bitrate) | |
38 | continue; | |
39 | result = &sband->bitrates[i]; | |
40 | } | |
41 | ||
42 | return result; | |
43 | } | |
44 | EXPORT_SYMBOL(ieee80211_get_response_rate); | |
45 | ||
5add321c | 46 | u32 ieee80211_mandatory_rates(struct ieee80211_supported_band *sband) |
b422c6cd AN |
47 | { |
48 | struct ieee80211_rate *bitrates; | |
49 | u32 mandatory_rates = 0; | |
50 | enum ieee80211_rate_flags mandatory_flag; | |
51 | int i; | |
52 | ||
53 | if (WARN_ON(!sband)) | |
54 | return 1; | |
55 | ||
5add321c JB |
56 | if (sband->band == NL80211_BAND_2GHZ) |
57 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; | |
58 | else | |
b422c6cd AN |
59 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
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 | ||
934f4c7d | 69 | u32 ieee80211_channel_to_freq_khz(int chan, enum nl80211_band band) |
8318d78a | 70 | { |
59eb21a6 BR |
71 | /* see 802.11 17.3.8.3.2 and Annex J |
72 | * there are overlapping channel numbers in 5GHz and 2GHz bands */ | |
3a0c52a6 VK |
73 | if (chan <= 0) |
74 | return 0; /* not supported */ | |
75 | switch (band) { | |
57fbcce3 | 76 | case NL80211_BAND_2GHZ: |
63fa0426 | 77 | case NL80211_BAND_LC: |
59eb21a6 | 78 | if (chan == 14) |
934f4c7d | 79 | return MHZ_TO_KHZ(2484); |
59eb21a6 | 80 | else if (chan < 14) |
934f4c7d | 81 | return MHZ_TO_KHZ(2407 + chan * 5); |
3a0c52a6 | 82 | break; |
57fbcce3 | 83 | case NL80211_BAND_5GHZ: |
3a0c52a6 | 84 | if (chan >= 182 && chan <= 196) |
934f4c7d | 85 | return MHZ_TO_KHZ(4000 + chan * 5); |
59eb21a6 | 86 | else |
934f4c7d | 87 | return MHZ_TO_KHZ(5000 + chan * 5); |
3a0c52a6 | 88 | break; |
fa1f1085 | 89 | case NL80211_BAND_6GHZ: |
d1a1646c AVS |
90 | /* see 802.11ax D6.1 27.3.23.2 */ |
91 | if (chan == 2) | |
92 | return MHZ_TO_KHZ(5935); | |
c0de8776 | 93 | if (chan <= 233) |
d1a1646c | 94 | return MHZ_TO_KHZ(5950 + chan * 5); |
fa1f1085 | 95 | break; |
57fbcce3 | 96 | case NL80211_BAND_60GHZ: |
9cf0a0b4 | 97 | if (chan < 7) |
934f4c7d | 98 | return MHZ_TO_KHZ(56160 + chan * 2160); |
3a0c52a6 | 99 | break; |
df78a0c0 TP |
100 | case NL80211_BAND_S1GHZ: |
101 | return 902000 + chan * 500; | |
3a0c52a6 VK |
102 | default: |
103 | ; | |
59eb21a6 | 104 | } |
3a0c52a6 | 105 | return 0; /* not supported */ |
8318d78a | 106 | } |
934f4c7d | 107 | EXPORT_SYMBOL(ieee80211_channel_to_freq_khz); |
8318d78a | 108 | |
11b34737 TP |
109 | enum nl80211_chan_width |
110 | ieee80211_s1g_channel_width(const struct ieee80211_channel *chan) | |
111 | { | |
112 | if (WARN_ON(!chan || chan->band != NL80211_BAND_S1GHZ)) | |
113 | return NL80211_CHAN_WIDTH_20_NOHT; | |
114 | ||
115 | /*S1G defines a single allowed channel width per channel. | |
116 | * Extract that width here. | |
117 | */ | |
118 | if (chan->flags & IEEE80211_CHAN_1MHZ) | |
119 | return NL80211_CHAN_WIDTH_1; | |
120 | else if (chan->flags & IEEE80211_CHAN_2MHZ) | |
121 | return NL80211_CHAN_WIDTH_2; | |
122 | else if (chan->flags & IEEE80211_CHAN_4MHZ) | |
123 | return NL80211_CHAN_WIDTH_4; | |
124 | else if (chan->flags & IEEE80211_CHAN_8MHZ) | |
125 | return NL80211_CHAN_WIDTH_8; | |
126 | else if (chan->flags & IEEE80211_CHAN_16MHZ) | |
127 | return NL80211_CHAN_WIDTH_16; | |
128 | ||
129 | pr_err("unknown channel width for channel at %dKHz?\n", | |
130 | ieee80211_channel_to_khz(chan)); | |
131 | ||
132 | return NL80211_CHAN_WIDTH_1; | |
133 | } | |
134 | EXPORT_SYMBOL(ieee80211_s1g_channel_width); | |
135 | ||
934f4c7d | 136 | int ieee80211_freq_khz_to_channel(u32 freq) |
8318d78a | 137 | { |
934f4c7d TP |
138 | /* TODO: just handle MHz for now */ |
139 | freq = KHZ_TO_MHZ(freq); | |
140 | ||
59eb21a6 | 141 | /* see 802.11 17.3.8.3.2 and Annex J */ |
8318d78a JB |
142 | if (freq == 2484) |
143 | return 14; | |
59eb21a6 | 144 | else if (freq < 2484) |
8318d78a | 145 | return (freq - 2407) / 5; |
59eb21a6 BR |
146 | else if (freq >= 4910 && freq <= 4980) |
147 | return (freq - 4000) / 5; | |
2d9b5550 | 148 | else if (freq < 5925) |
59eb21a6 | 149 | return (freq - 5000) / 5; |
2d9b5550 AS |
150 | else if (freq == 5935) |
151 | return 2; | |
fa1f1085 | 152 | else if (freq <= 45000) /* DMG band lower limit */ |
2d9b5550 AS |
153 | /* see 802.11ax D6.1 27.3.22.2 */ |
154 | return (freq - 5950) / 5; | |
9cf0a0b4 | 155 | else if (freq >= 58320 && freq <= 70200) |
3a0c52a6 VK |
156 | return (freq - 56160) / 2160; |
157 | else | |
158 | return 0; | |
8318d78a | 159 | } |
934f4c7d | 160 | EXPORT_SYMBOL(ieee80211_freq_khz_to_channel); |
8318d78a | 161 | |
934f4c7d TP |
162 | struct ieee80211_channel *ieee80211_get_channel_khz(struct wiphy *wiphy, |
163 | u32 freq) | |
906c730a | 164 | { |
57fbcce3 | 165 | enum nl80211_band band; |
906c730a JB |
166 | struct ieee80211_supported_band *sband; |
167 | int i; | |
168 | ||
57fbcce3 | 169 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
906c730a JB |
170 | sband = wiphy->bands[band]; |
171 | ||
172 | if (!sband) | |
173 | continue; | |
174 | ||
175 | for (i = 0; i < sband->n_channels; i++) { | |
934f4c7d TP |
176 | struct ieee80211_channel *chan = &sband->channels[i]; |
177 | ||
178 | if (ieee80211_channel_to_khz(chan) == freq) | |
179 | return chan; | |
906c730a JB |
180 | } |
181 | } | |
182 | ||
183 | return NULL; | |
184 | } | |
934f4c7d | 185 | EXPORT_SYMBOL(ieee80211_get_channel_khz); |
906c730a | 186 | |
343884c8 | 187 | static void set_mandatory_flags_band(struct ieee80211_supported_band *sband) |
8318d78a JB |
188 | { |
189 | int i, want; | |
190 | ||
343884c8 | 191 | switch (sband->band) { |
57fbcce3 | 192 | case NL80211_BAND_5GHZ: |
62524a58 | 193 | case NL80211_BAND_6GHZ: |
8318d78a JB |
194 | want = 3; |
195 | for (i = 0; i < sband->n_bitrates; i++) { | |
196 | if (sband->bitrates[i].bitrate == 60 || | |
197 | sband->bitrates[i].bitrate == 120 || | |
198 | sband->bitrates[i].bitrate == 240) { | |
199 | sband->bitrates[i].flags |= | |
200 | IEEE80211_RATE_MANDATORY_A; | |
201 | want--; | |
202 | } | |
203 | } | |
204 | WARN_ON(want); | |
205 | break; | |
57fbcce3 | 206 | case NL80211_BAND_2GHZ: |
63fa0426 | 207 | case NL80211_BAND_LC: |
8318d78a JB |
208 | want = 7; |
209 | for (i = 0; i < sband->n_bitrates; i++) { | |
1bd773c0 RS |
210 | switch (sband->bitrates[i].bitrate) { |
211 | case 10: | |
212 | case 20: | |
213 | case 55: | |
214 | case 110: | |
8318d78a JB |
215 | sband->bitrates[i].flags |= |
216 | IEEE80211_RATE_MANDATORY_B | | |
217 | IEEE80211_RATE_MANDATORY_G; | |
218 | want--; | |
1bd773c0 RS |
219 | break; |
220 | case 60: | |
221 | case 120: | |
222 | case 240: | |
8318d78a JB |
223 | sband->bitrates[i].flags |= |
224 | IEEE80211_RATE_MANDATORY_G; | |
225 | want--; | |
df561f66 | 226 | fallthrough; |
1bd773c0 | 227 | default: |
8318d78a JB |
228 | sband->bitrates[i].flags |= |
229 | IEEE80211_RATE_ERP_G; | |
1bd773c0 RS |
230 | break; |
231 | } | |
8318d78a | 232 | } |
1bd773c0 | 233 | WARN_ON(want != 0 && want != 3); |
8318d78a | 234 | break; |
57fbcce3 | 235 | case NL80211_BAND_60GHZ: |
3a0c52a6 VK |
236 | /* check for mandatory HT MCS 1..4 */ |
237 | WARN_ON(!sband->ht_cap.ht_supported); | |
238 | WARN_ON((sband->ht_cap.mcs.rx_mask[0] & 0x1e) != 0x1e); | |
239 | break; | |
df78a0c0 TP |
240 | case NL80211_BAND_S1GHZ: |
241 | /* Figure 9-589bd: 3 means unsupported, so != 3 means at least | |
242 | * mandatory is ok. | |
243 | */ | |
244 | WARN_ON((sband->s1g_cap.nss_mcs[0] & 0x3) == 0x3); | |
245 | break; | |
57fbcce3 | 246 | case NUM_NL80211_BANDS: |
343884c8 | 247 | default: |
8318d78a JB |
248 | WARN_ON(1); |
249 | break; | |
250 | } | |
251 | } | |
252 | ||
253 | void ieee80211_set_bitrate_flags(struct wiphy *wiphy) | |
254 | { | |
57fbcce3 | 255 | enum nl80211_band band; |
8318d78a | 256 | |
57fbcce3 | 257 | for (band = 0; band < NUM_NL80211_BANDS; band++) |
8318d78a | 258 | if (wiphy->bands[band]) |
343884c8 | 259 | set_mandatory_flags_band(wiphy->bands[band]); |
8318d78a | 260 | } |
08645126 | 261 | |
38ba3c57 JM |
262 | bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher) |
263 | { | |
264 | int i; | |
265 | for (i = 0; i < wiphy->n_cipher_suites; i++) | |
266 | if (cipher == wiphy->cipher_suites[i]) | |
267 | return true; | |
268 | return false; | |
269 | } | |
270 | ||
2d946308 AT |
271 | static bool |
272 | cfg80211_igtk_cipher_supported(struct cfg80211_registered_device *rdev) | |
273 | { | |
274 | struct wiphy *wiphy = &rdev->wiphy; | |
275 | int i; | |
276 | ||
277 | for (i = 0; i < wiphy->n_cipher_suites; i++) { | |
278 | switch (wiphy->cipher_suites[i]) { | |
279 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
280 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: | |
281 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: | |
282 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
283 | return true; | |
284 | } | |
285 | } | |
286 | ||
287 | return false; | |
288 | } | |
289 | ||
290 | bool cfg80211_valid_key_idx(struct cfg80211_registered_device *rdev, | |
291 | int key_idx, bool pairwise) | |
08645126 | 292 | { |
2d946308 | 293 | int max_key_idx; |
56be393f | 294 | |
2d946308 AT |
295 | if (pairwise) |
296 | max_key_idx = 3; | |
297 | else if (wiphy_ext_feature_isset(&rdev->wiphy, | |
298 | NL80211_EXT_FEATURE_BEACON_PROTECTION) || | |
299 | wiphy_ext_feature_isset(&rdev->wiphy, | |
300 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) | |
56be393f | 301 | max_key_idx = 7; |
2d946308 AT |
302 | else if (cfg80211_igtk_cipher_supported(rdev)) |
303 | max_key_idx = 5; | |
304 | else | |
305 | max_key_idx = 3; | |
306 | ||
56be393f | 307 | if (key_idx < 0 || key_idx > max_key_idx) |
2d946308 AT |
308 | return false; |
309 | ||
310 | return true; | |
311 | } | |
312 | ||
313 | int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, | |
314 | struct key_params *params, int key_idx, | |
315 | bool pairwise, const u8 *mac_addr) | |
316 | { | |
317 | if (!cfg80211_valid_key_idx(rdev, key_idx, pairwise)) | |
08645126 JB |
318 | return -EINVAL; |
319 | ||
e31b8213 JB |
320 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
321 | return -EINVAL; | |
322 | ||
323 | if (pairwise && !mac_addr) | |
324 | return -EINVAL; | |
325 | ||
37720569 JM |
326 | switch (params->cipher) { |
327 | case WLAN_CIPHER_SUITE_TKIP: | |
b67fd72e AW |
328 | /* Extended Key ID can only be used with CCMP/GCMP ciphers */ |
329 | if ((pairwise && key_idx) || | |
330 | params->mode != NL80211_KEY_RX_TX) | |
331 | return -EINVAL; | |
332 | break; | |
37720569 | 333 | case WLAN_CIPHER_SUITE_CCMP: |
cfcf1682 JM |
334 | case WLAN_CIPHER_SUITE_CCMP_256: |
335 | case WLAN_CIPHER_SUITE_GCMP: | |
336 | case WLAN_CIPHER_SUITE_GCMP_256: | |
b67fd72e AW |
337 | /* IEEE802.11-2016 allows only 0 and - when supporting |
338 | * Extended Key ID - 1 as index for pairwise keys. | |
6cdd3979 AW |
339 | * @NL80211_KEY_NO_TX is only allowed for pairwise keys when |
340 | * the driver supports Extended Key ID. | |
341 | * @NL80211_KEY_SET_TX can't be set when installing and | |
342 | * validating a key. | |
37720569 | 343 | */ |
b67fd72e AW |
344 | if ((params->mode == NL80211_KEY_NO_TX && !pairwise) || |
345 | params->mode == NL80211_KEY_SET_TX) | |
346 | return -EINVAL; | |
347 | if (wiphy_ext_feature_isset(&rdev->wiphy, | |
348 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { | |
349 | if (pairwise && (key_idx < 0 || key_idx > 1)) | |
6cdd3979 | 350 | return -EINVAL; |
b67fd72e | 351 | } else if (pairwise && key_idx) { |
37720569 | 352 | return -EINVAL; |
6cdd3979 | 353 | } |
37720569 JM |
354 | break; |
355 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
cfcf1682 JM |
356 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
357 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: | |
358 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
37720569 JM |
359 | /* Disallow BIP (group-only) cipher as pairwise cipher */ |
360 | if (pairwise) | |
361 | return -EINVAL; | |
e9c8f8d3 JB |
362 | if (key_idx < 4) |
363 | return -EINVAL; | |
37720569 | 364 | break; |
e9c8f8d3 JB |
365 | case WLAN_CIPHER_SUITE_WEP40: |
366 | case WLAN_CIPHER_SUITE_WEP104: | |
367 | if (key_idx > 3) | |
368 | return -EINVAL; | |
01c9c0ab | 369 | break; |
37720569 JM |
370 | default: |
371 | break; | |
372 | } | |
08645126 | 373 | |
08645126 JB |
374 | switch (params->cipher) { |
375 | case WLAN_CIPHER_SUITE_WEP40: | |
8fc0fee0 | 376 | if (params->key_len != WLAN_KEY_LEN_WEP40) |
08645126 JB |
377 | return -EINVAL; |
378 | break; | |
379 | case WLAN_CIPHER_SUITE_TKIP: | |
8fc0fee0 | 380 | if (params->key_len != WLAN_KEY_LEN_TKIP) |
08645126 JB |
381 | return -EINVAL; |
382 | break; | |
383 | case WLAN_CIPHER_SUITE_CCMP: | |
8fc0fee0 | 384 | if (params->key_len != WLAN_KEY_LEN_CCMP) |
08645126 JB |
385 | return -EINVAL; |
386 | break; | |
cfcf1682 JM |
387 | case WLAN_CIPHER_SUITE_CCMP_256: |
388 | if (params->key_len != WLAN_KEY_LEN_CCMP_256) | |
389 | return -EINVAL; | |
390 | break; | |
391 | case WLAN_CIPHER_SUITE_GCMP: | |
392 | if (params->key_len != WLAN_KEY_LEN_GCMP) | |
393 | return -EINVAL; | |
394 | break; | |
395 | case WLAN_CIPHER_SUITE_GCMP_256: | |
396 | if (params->key_len != WLAN_KEY_LEN_GCMP_256) | |
397 | return -EINVAL; | |
398 | break; | |
08645126 | 399 | case WLAN_CIPHER_SUITE_WEP104: |
8fc0fee0 | 400 | if (params->key_len != WLAN_KEY_LEN_WEP104) |
08645126 JB |
401 | return -EINVAL; |
402 | break; | |
403 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
8fc0fee0 | 404 | if (params->key_len != WLAN_KEY_LEN_AES_CMAC) |
08645126 JB |
405 | return -EINVAL; |
406 | break; | |
cfcf1682 JM |
407 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
408 | if (params->key_len != WLAN_KEY_LEN_BIP_CMAC_256) | |
409 | return -EINVAL; | |
410 | break; | |
411 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: | |
412 | if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_128) | |
413 | return -EINVAL; | |
414 | break; | |
415 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
416 | if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_256) | |
417 | return -EINVAL; | |
418 | break; | |
08645126 | 419 | default: |
7d64b7cc JB |
420 | /* |
421 | * We don't know anything about this algorithm, | |
422 | * allow using it -- but the driver must check | |
423 | * all parameters! We still check below whether | |
424 | * or not the driver supports this algorithm, | |
425 | * of course. | |
426 | */ | |
427 | break; | |
08645126 JB |
428 | } |
429 | ||
9f26a952 JM |
430 | if (params->seq) { |
431 | switch (params->cipher) { | |
432 | case WLAN_CIPHER_SUITE_WEP40: | |
433 | case WLAN_CIPHER_SUITE_WEP104: | |
434 | /* These ciphers do not use key sequence */ | |
435 | return -EINVAL; | |
436 | case WLAN_CIPHER_SUITE_TKIP: | |
437 | case WLAN_CIPHER_SUITE_CCMP: | |
cfcf1682 JM |
438 | case WLAN_CIPHER_SUITE_CCMP_256: |
439 | case WLAN_CIPHER_SUITE_GCMP: | |
440 | case WLAN_CIPHER_SUITE_GCMP_256: | |
9f26a952 | 441 | case WLAN_CIPHER_SUITE_AES_CMAC: |
cfcf1682 JM |
442 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
443 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: | |
444 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
9f26a952 JM |
445 | if (params->seq_len != 6) |
446 | return -EINVAL; | |
447 | break; | |
448 | } | |
449 | } | |
450 | ||
38ba3c57 | 451 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher)) |
fffd0934 JB |
452 | return -EINVAL; |
453 | ||
08645126 JB |
454 | return 0; |
455 | } | |
e31a16d6 | 456 | |
633adf1a | 457 | unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc) |
e31a16d6 ZY |
458 | { |
459 | unsigned int hdrlen = 24; | |
460 | ||
1d47f119 TP |
461 | if (ieee80211_is_ext(fc)) { |
462 | hdrlen = 4; | |
463 | goto out; | |
464 | } | |
465 | ||
e31a16d6 ZY |
466 | if (ieee80211_is_data(fc)) { |
467 | if (ieee80211_has_a4(fc)) | |
468 | hdrlen = 30; | |
d0dd2de0 | 469 | if (ieee80211_is_data_qos(fc)) { |
e31a16d6 | 470 | hdrlen += IEEE80211_QOS_CTL_LEN; |
d0dd2de0 AT |
471 | if (ieee80211_has_order(fc)) |
472 | hdrlen += IEEE80211_HT_CTL_LEN; | |
473 | } | |
e31a16d6 ZY |
474 | goto out; |
475 | } | |
476 | ||
fb142f4b FC |
477 | if (ieee80211_is_mgmt(fc)) { |
478 | if (ieee80211_has_order(fc)) | |
479 | hdrlen += IEEE80211_HT_CTL_LEN; | |
480 | goto out; | |
481 | } | |
482 | ||
e31a16d6 ZY |
483 | if (ieee80211_is_ctl(fc)) { |
484 | /* | |
485 | * ACK and CTS are 10 bytes, all others 16. To see how | |
486 | * to get this condition consider | |
487 | * subtype mask: 0b0000000011110000 (0x00F0) | |
488 | * ACK subtype: 0b0000000011010000 (0x00D0) | |
489 | * CTS subtype: 0b0000000011000000 (0x00C0) | |
490 | * bits that matter: ^^^ (0x00E0) | |
491 | * value of those: 0b0000000011000000 (0x00C0) | |
492 | */ | |
493 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) | |
494 | hdrlen = 10; | |
495 | else | |
496 | hdrlen = 16; | |
497 | } | |
498 | out: | |
499 | return hdrlen; | |
500 | } | |
501 | EXPORT_SYMBOL(ieee80211_hdrlen); | |
502 | ||
503 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) | |
504 | { | |
505 | const struct ieee80211_hdr *hdr = | |
506 | (const struct ieee80211_hdr *)skb->data; | |
507 | unsigned int hdrlen; | |
508 | ||
509 | if (unlikely(skb->len < 10)) | |
510 | return 0; | |
511 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
512 | if (unlikely(hdrlen > skb->len)) | |
513 | return 0; | |
514 | return hdrlen; | |
515 | } | |
516 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); | |
517 | ||
2d1c304c | 518 | static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags) |
e31a16d6 | 519 | { |
2d1c304c | 520 | int ae = flags & MESH_FLAGS_AE; |
7dd111e8 | 521 | /* 802.11-2012, 8.2.4.7.3 */ |
e31a16d6 | 522 | switch (ae) { |
7dd111e8 | 523 | default: |
e31a16d6 ZY |
524 | case 0: |
525 | return 6; | |
3c5772a5 | 526 | case MESH_FLAGS_AE_A4: |
e31a16d6 | 527 | return 12; |
3c5772a5 | 528 | case MESH_FLAGS_AE_A5_A6: |
e31a16d6 | 529 | return 18; |
e31a16d6 ZY |
530 | } |
531 | } | |
2d1c304c FF |
532 | |
533 | unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) | |
534 | { | |
535 | return __ieee80211_get_mesh_hdrlen(meshhdr->flags); | |
536 | } | |
9b395bc3 | 537 | EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen); |
e31a16d6 | 538 | |
986e43b1 | 539 | bool ieee80211_get_8023_tunnel_proto(const void *hdr, __be16 *proto) |
9f718554 FF |
540 | { |
541 | const __be16 *hdr_proto = hdr + ETH_ALEN; | |
542 | ||
543 | if (!(ether_addr_equal(hdr, rfc1042_header) && | |
544 | *hdr_proto != htons(ETH_P_AARP) && | |
545 | *hdr_proto != htons(ETH_P_IPX)) && | |
546 | !ether_addr_equal(hdr, bridge_tunnel_header)) | |
547 | return false; | |
548 | ||
549 | *proto = *hdr_proto; | |
550 | ||
551 | return true; | |
552 | } | |
986e43b1 FF |
553 | EXPORT_SYMBOL(ieee80211_get_8023_tunnel_proto); |
554 | ||
555 | int ieee80211_strip_8023_mesh_hdr(struct sk_buff *skb) | |
556 | { | |
557 | const void *mesh_addr; | |
558 | struct { | |
559 | struct ethhdr eth; | |
560 | u8 flags; | |
561 | } payload; | |
562 | int hdrlen; | |
563 | int ret; | |
564 | ||
565 | ret = skb_copy_bits(skb, 0, &payload, sizeof(payload)); | |
566 | if (ret) | |
567 | return ret; | |
568 | ||
569 | hdrlen = sizeof(payload.eth) + __ieee80211_get_mesh_hdrlen(payload.flags); | |
570 | ||
571 | if (likely(pskb_may_pull(skb, hdrlen + 8) && | |
572 | ieee80211_get_8023_tunnel_proto(skb->data + hdrlen, | |
573 | &payload.eth.h_proto))) | |
574 | hdrlen += ETH_ALEN + 2; | |
575 | else if (!pskb_may_pull(skb, hdrlen)) | |
576 | return -EINVAL; | |
fec3ebb5 FF |
577 | else |
578 | payload.eth.h_proto = htons(skb->len - hdrlen); | |
986e43b1 FF |
579 | |
580 | mesh_addr = skb->data + sizeof(payload.eth) + ETH_ALEN; | |
581 | switch (payload.flags & MESH_FLAGS_AE) { | |
582 | case MESH_FLAGS_AE_A4: | |
583 | memcpy(&payload.eth.h_source, mesh_addr, ETH_ALEN); | |
584 | break; | |
585 | case MESH_FLAGS_AE_A5_A6: | |
586 | memcpy(&payload.eth, mesh_addr, 2 * ETH_ALEN); | |
587 | break; | |
588 | default: | |
589 | break; | |
590 | } | |
591 | ||
592 | pskb_pull(skb, hdrlen - sizeof(payload.eth)); | |
593 | memcpy(skb->data, &payload.eth, sizeof(payload.eth)); | |
594 | ||
595 | return 0; | |
596 | } | |
597 | EXPORT_SYMBOL(ieee80211_strip_8023_mesh_hdr); | |
9f718554 | 598 | |
7f6990c8 | 599 | int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr, |
24bba078 | 600 | const u8 *addr, enum nl80211_iftype iftype, |
a1d5ff56 | 601 | u8 data_offset, bool is_amsdu) |
e31a16d6 ZY |
602 | { |
603 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
2d1c304c FF |
604 | struct { |
605 | u8 hdr[ETH_ALEN] __aligned(2); | |
606 | __be16 proto; | |
607 | } payload; | |
608 | struct ethhdr tmp; | |
609 | u16 hdrlen; | |
e31a16d6 ZY |
610 | |
611 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) | |
612 | return -1; | |
613 | ||
24bba078 | 614 | hdrlen = ieee80211_hdrlen(hdr->frame_control) + data_offset; |
d9e24970 | 615 | if (skb->len < hdrlen) |
2d1c304c | 616 | return -1; |
e31a16d6 ZY |
617 | |
618 | /* convert IEEE 802.11 header + possible LLC headers into Ethernet | |
619 | * header | |
620 | * IEEE 802.11 address fields: | |
621 | * ToDS FromDS Addr1 Addr2 Addr3 Addr4 | |
622 | * 0 0 DA SA BSSID n/a | |
623 | * 0 1 DA BSSID SA n/a | |
624 | * 1 0 BSSID SA DA n/a | |
625 | * 1 1 RA TA DA SA | |
626 | */ | |
2d1c304c FF |
627 | memcpy(tmp.h_dest, ieee80211_get_DA(hdr), ETH_ALEN); |
628 | memcpy(tmp.h_source, ieee80211_get_SA(hdr), ETH_ALEN); | |
629 | ||
e31a16d6 ZY |
630 | switch (hdr->frame_control & |
631 | cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { | |
632 | case cpu_to_le16(IEEE80211_FCTL_TODS): | |
633 | if (unlikely(iftype != NL80211_IFTYPE_AP && | |
074ac8df JB |
634 | iftype != NL80211_IFTYPE_AP_VLAN && |
635 | iftype != NL80211_IFTYPE_P2P_GO)) | |
e31a16d6 ZY |
636 | return -1; |
637 | break; | |
638 | case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): | |
e7e0517c | 639 | if (unlikely(iftype != NL80211_IFTYPE_MESH_POINT && |
f14543ee FF |
640 | iftype != NL80211_IFTYPE_AP_VLAN && |
641 | iftype != NL80211_IFTYPE_STATION)) | |
e31a16d6 | 642 | return -1; |
e31a16d6 ZY |
643 | break; |
644 | case cpu_to_le16(IEEE80211_FCTL_FROMDS): | |
3c5772a5 | 645 | if ((iftype != NL80211_IFTYPE_STATION && |
074ac8df JB |
646 | iftype != NL80211_IFTYPE_P2P_CLIENT && |
647 | iftype != NL80211_IFTYPE_MESH_POINT) || | |
2d1c304c FF |
648 | (is_multicast_ether_addr(tmp.h_dest) && |
649 | ether_addr_equal(tmp.h_source, addr))) | |
e31a16d6 ZY |
650 | return -1; |
651 | break; | |
652 | case cpu_to_le16(0): | |
941c93cd | 653 | if (iftype != NL80211_IFTYPE_ADHOC && |
6e0bd6c3 RL |
654 | iftype != NL80211_IFTYPE_STATION && |
655 | iftype != NL80211_IFTYPE_OCB) | |
941c93cd | 656 | return -1; |
e31a16d6 ZY |
657 | break; |
658 | } | |
659 | ||
986e43b1 | 660 | if (likely(!is_amsdu && iftype != NL80211_IFTYPE_MESH_POINT && |
0f690e6b | 661 | skb_copy_bits(skb, hdrlen, &payload, sizeof(payload)) == 0 && |
9f718554 FF |
662 | ieee80211_get_8023_tunnel_proto(&payload, &tmp.h_proto))) { |
663 | /* remove RFC1042 or Bridge-Tunnel encapsulation */ | |
2d1c304c | 664 | hdrlen += ETH_ALEN + 2; |
667aa742 JB |
665 | skb_postpull_rcsum(skb, &payload, ETH_ALEN + 2); |
666 | } else { | |
c041778c | 667 | tmp.h_proto = htons(skb->len - hdrlen); |
667aa742 | 668 | } |
2d1c304c FF |
669 | |
670 | pskb_pull(skb, hdrlen); | |
e31a16d6 | 671 | |
2d1c304c | 672 | if (!ehdr) |
d58ff351 | 673 | ehdr = skb_push(skb, sizeof(struct ethhdr)); |
2d1c304c FF |
674 | memcpy(ehdr, &tmp, sizeof(tmp)); |
675 | ||
e31a16d6 ZY |
676 | return 0; |
677 | } | |
7f6990c8 | 678 | EXPORT_SYMBOL(ieee80211_data_to_8023_exthdr); |
e31a16d6 | 679 | |
2b67f944 FF |
680 | static void |
681 | __frame_add_frag(struct sk_buff *skb, struct page *page, | |
682 | void *ptr, int len, int size) | |
683 | { | |
684 | struct skb_shared_info *sh = skb_shinfo(skb); | |
685 | int page_offset; | |
686 | ||
81c044fc | 687 | get_page(page); |
2b67f944 FF |
688 | page_offset = ptr - page_address(page); |
689 | skb_add_rx_frag(skb, sh->nr_frags, page, page_offset, len, size); | |
690 | } | |
691 | ||
692 | static void | |
693 | __ieee80211_amsdu_copy_frag(struct sk_buff *skb, struct sk_buff *frame, | |
694 | int offset, int len) | |
695 | { | |
696 | struct skb_shared_info *sh = skb_shinfo(skb); | |
aa1702dd | 697 | const skb_frag_t *frag = &sh->frags[0]; |
2b67f944 FF |
698 | struct page *frag_page; |
699 | void *frag_ptr; | |
700 | int frag_len, frag_size; | |
701 | int head_size = skb->len - skb->data_len; | |
702 | int cur_len; | |
703 | ||
704 | frag_page = virt_to_head_page(skb->head); | |
705 | frag_ptr = skb->data; | |
706 | frag_size = head_size; | |
707 | ||
708 | while (offset >= frag_size) { | |
709 | offset -= frag_size; | |
2b67f944 FF |
710 | frag_page = skb_frag_page(frag); |
711 | frag_ptr = skb_frag_address(frag); | |
712 | frag_size = skb_frag_size(frag); | |
aa1702dd | 713 | frag++; |
2b67f944 FF |
714 | } |
715 | ||
716 | frag_ptr += offset; | |
717 | frag_len = frag_size - offset; | |
718 | ||
719 | cur_len = min(len, frag_len); | |
720 | ||
721 | __frame_add_frag(frame, frag_page, frag_ptr, cur_len, frag_size); | |
722 | len -= cur_len; | |
723 | ||
724 | while (len > 0) { | |
2b67f944 FF |
725 | frag_len = skb_frag_size(frag); |
726 | cur_len = min(len, frag_len); | |
727 | __frame_add_frag(frame, skb_frag_page(frag), | |
728 | skb_frag_address(frag), cur_len, frag_len); | |
729 | len -= cur_len; | |
aa1702dd | 730 | frag++; |
2b67f944 FF |
731 | } |
732 | } | |
733 | ||
230fd28a FF |
734 | static struct sk_buff * |
735 | __ieee80211_amsdu_copy(struct sk_buff *skb, unsigned int hlen, | |
986e43b1 FF |
736 | int offset, int len, bool reuse_frag, |
737 | int min_len) | |
230fd28a FF |
738 | { |
739 | struct sk_buff *frame; | |
2b67f944 | 740 | int cur_len = len; |
230fd28a FF |
741 | |
742 | if (skb->len - offset < len) | |
743 | return NULL; | |
744 | ||
2b67f944 | 745 | /* |
4b482281 | 746 | * When reusing fragments, copy some data to the head to simplify |
2b67f944 FF |
747 | * ethernet header handling and speed up protocol header processing |
748 | * in the stack later. | |
749 | */ | |
750 | if (reuse_frag) | |
986e43b1 | 751 | cur_len = min_t(int, len, min_len); |
2b67f944 | 752 | |
230fd28a FF |
753 | /* |
754 | * Allocate and reserve two bytes more for payload | |
755 | * alignment since sizeof(struct ethhdr) is 14. | |
756 | */ | |
2b67f944 | 757 | frame = dev_alloc_skb(hlen + sizeof(struct ethhdr) + 2 + cur_len); |
16a910a6 GG |
758 | if (!frame) |
759 | return NULL; | |
230fd28a | 760 | |
986e43b1 | 761 | frame->priority = skb->priority; |
230fd28a | 762 | skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2); |
2b67f944 FF |
763 | skb_copy_bits(skb, offset, skb_put(frame, cur_len), cur_len); |
764 | ||
765 | len -= cur_len; | |
766 | if (!len) | |
767 | return frame; | |
768 | ||
769 | offset += cur_len; | |
770 | __ieee80211_amsdu_copy_frag(skb, frame, offset, len); | |
230fd28a FF |
771 | |
772 | return frame; | |
773 | } | |
eaf85ca7 | 774 | |
fe4a6d2d FF |
775 | static u16 |
776 | ieee80211_amsdu_subframe_length(void *field, u8 mesh_flags, u8 hdr_type) | |
777 | { | |
778 | __le16 *field_le = field; | |
779 | __be16 *field_be = field; | |
780 | u16 len; | |
781 | ||
782 | if (hdr_type >= 2) | |
783 | len = le16_to_cpu(*field_le); | |
784 | else | |
785 | len = be16_to_cpu(*field_be); | |
786 | if (hdr_type) | |
787 | len += __ieee80211_get_mesh_hdrlen(mesh_flags); | |
788 | ||
789 | return len; | |
790 | } | |
791 | ||
792 | bool ieee80211_is_valid_amsdu(struct sk_buff *skb, u8 mesh_hdr) | |
6e4c0d04 | 793 | { |
9ad79748 | 794 | int offset = 0, subframe_len, padding; |
6e4c0d04 FF |
795 | |
796 | for (offset = 0; offset < skb->len; offset += subframe_len + padding) { | |
9ad79748 | 797 | int remaining = skb->len - offset; |
6e4c0d04 FF |
798 | struct { |
799 | __be16 len; | |
800 | u8 mesh_flags; | |
801 | } hdr; | |
802 | u16 len; | |
803 | ||
9ad79748 JB |
804 | if (sizeof(hdr) > remaining) |
805 | return false; | |
806 | ||
6e4c0d04 FF |
807 | if (skb_copy_bits(skb, offset + 2 * ETH_ALEN, &hdr, sizeof(hdr)) < 0) |
808 | return false; | |
809 | ||
fe4a6d2d FF |
810 | len = ieee80211_amsdu_subframe_length(&hdr.len, hdr.mesh_flags, |
811 | mesh_hdr); | |
6e4c0d04 FF |
812 | subframe_len = sizeof(struct ethhdr) + len; |
813 | padding = (4 - subframe_len) & 0x3; | |
6e4c0d04 FF |
814 | |
815 | if (subframe_len > remaining) | |
816 | return false; | |
817 | } | |
818 | ||
819 | return true; | |
820 | } | |
821 | EXPORT_SYMBOL(ieee80211_is_valid_amsdu); | |
822 | ||
eaf85ca7 ZY |
823 | void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list, |
824 | const u8 *addr, enum nl80211_iftype iftype, | |
8b3becad | 825 | const unsigned int extra_headroom, |
986e43b1 | 826 | const u8 *check_da, const u8 *check_sa, |
fe4a6d2d | 827 | u8 mesh_control) |
eaf85ca7 | 828 | { |
230fd28a | 829 | unsigned int hlen = ALIGN(extra_headroom, 4); |
eaf85ca7 | 830 | struct sk_buff *frame = NULL; |
9ad79748 | 831 | int offset = 0; |
986e43b1 FF |
832 | struct { |
833 | struct ethhdr eth; | |
834 | uint8_t flags; | |
835 | } hdr; | |
2b67f944 | 836 | bool reuse_frag = skb->head_frag && !skb_has_frag_list(skb); |
2bf0ccc7 | 837 | bool reuse_skb = false; |
230fd28a | 838 | bool last = false; |
986e43b1 FF |
839 | int copy_len = sizeof(hdr.eth); |
840 | ||
841 | if (iftype == NL80211_IFTYPE_MESH_POINT) | |
842 | copy_len = sizeof(hdr); | |
88665f5a | 843 | |
230fd28a | 844 | while (!last) { |
9ad79748 | 845 | int remaining = skb->len - offset; |
230fd28a | 846 | unsigned int subframe_len; |
986e43b1 | 847 | int len, mesh_len = 0; |
eaf85ca7 | 848 | u8 padding; |
eaf85ca7 | 849 | |
9ad79748 JB |
850 | if (copy_len > remaining) |
851 | goto purge; | |
852 | ||
986e43b1 FF |
853 | skb_copy_bits(skb, offset, &hdr, copy_len); |
854 | if (iftype == NL80211_IFTYPE_MESH_POINT) | |
855 | mesh_len = __ieee80211_get_mesh_hdrlen(hdr.flags); | |
fe4a6d2d FF |
856 | len = ieee80211_amsdu_subframe_length(&hdr.eth.h_proto, hdr.flags, |
857 | mesh_control); | |
230fd28a | 858 | subframe_len = sizeof(struct ethhdr) + len; |
eaf85ca7 | 859 | padding = (4 - subframe_len) & 0x3; |
230fd28a | 860 | |
eaf85ca7 ZY |
861 | /* the last MSDU has no padding */ |
862 | if (subframe_len > remaining) | |
863 | goto purge; | |
2b8a1fee | 864 | /* mitigate A-MSDU aggregation injection attacks */ |
986e43b1 | 865 | if (ether_addr_equal(hdr.eth.h_dest, rfc1042_header)) |
2b8a1fee | 866 | goto purge; |
eaf85ca7 | 867 | |
230fd28a | 868 | offset += sizeof(struct ethhdr); |
230fd28a | 869 | last = remaining <= subframe_len + padding; |
8b935ee2 JB |
870 | |
871 | /* FIXME: should we really accept multicast DA? */ | |
986e43b1 FF |
872 | if ((check_da && !is_multicast_ether_addr(hdr.eth.h_dest) && |
873 | !ether_addr_equal(check_da, hdr.eth.h_dest)) || | |
874 | (check_sa && !ether_addr_equal(check_sa, hdr.eth.h_source))) { | |
8b935ee2 JB |
875 | offset += len + padding; |
876 | continue; | |
877 | } | |
878 | ||
879 | /* reuse skb for the last subframe */ | |
2b67f944 | 880 | if (!skb_is_nonlinear(skb) && !reuse_frag && last) { |
230fd28a | 881 | skb_pull(skb, offset); |
eaf85ca7 | 882 | frame = skb; |
230fd28a FF |
883 | reuse_skb = true; |
884 | } else { | |
2b67f944 | 885 | frame = __ieee80211_amsdu_copy(skb, hlen, offset, len, |
986e43b1 | 886 | reuse_frag, 32 + mesh_len); |
eaf85ca7 ZY |
887 | if (!frame) |
888 | goto purge; | |
889 | ||
230fd28a | 890 | offset += len + padding; |
eaf85ca7 ZY |
891 | } |
892 | ||
893 | skb_reset_network_header(frame); | |
894 | frame->dev = skb->dev; | |
895 | frame->priority = skb->priority; | |
896 | ||
986e43b1 FF |
897 | if (likely(iftype != NL80211_IFTYPE_MESH_POINT && |
898 | ieee80211_get_8023_tunnel_proto(frame->data, &hdr.eth.h_proto))) | |
230fd28a | 899 | skb_pull(frame, ETH_ALEN + 2); |
230fd28a | 900 | |
986e43b1 | 901 | memcpy(skb_push(frame, sizeof(hdr.eth)), &hdr.eth, sizeof(hdr.eth)); |
eaf85ca7 ZY |
902 | __skb_queue_tail(list, frame); |
903 | } | |
904 | ||
230fd28a FF |
905 | if (!reuse_skb) |
906 | dev_kfree_skb(skb); | |
907 | ||
eaf85ca7 ZY |
908 | return; |
909 | ||
910 | purge: | |
911 | __skb_queue_purge(list); | |
eaf85ca7 ZY |
912 | dev_kfree_skb(skb); |
913 | } | |
914 | EXPORT_SYMBOL(ieee80211_amsdu_to_8023s); | |
915 | ||
e31a16d6 | 916 | /* Given a data frame determine the 802.1p/1d tag to use. */ |
fa9ffc74 KP |
917 | unsigned int cfg80211_classify8021d(struct sk_buff *skb, |
918 | struct cfg80211_qos_map *qos_map) | |
e31a16d6 ZY |
919 | { |
920 | unsigned int dscp; | |
c6ca5e28 | 921 | unsigned char vlan_priority; |
1fc9b725 | 922 | unsigned int ret; |
e31a16d6 ZY |
923 | |
924 | /* skb->priority values from 256->263 are magic values to | |
925 | * directly indicate a specific 802.1d priority. This is used | |
926 | * to allow 802.1d priority to be passed directly in from VLAN | |
927 | * tags, etc. | |
928 | */ | |
1fc9b725 JB |
929 | if (skb->priority >= 256 && skb->priority <= 263) { |
930 | ret = skb->priority - 256; | |
931 | goto out; | |
932 | } | |
e31a16d6 | 933 | |
df8a39de JP |
934 | if (skb_vlan_tag_present(skb)) { |
935 | vlan_priority = (skb_vlan_tag_get(skb) & VLAN_PRIO_MASK) | |
c6ca5e28 | 936 | >> VLAN_PRIO_SHIFT; |
1fc9b725 JB |
937 | if (vlan_priority > 0) { |
938 | ret = vlan_priority; | |
939 | goto out; | |
940 | } | |
c6ca5e28 V |
941 | } |
942 | ||
e31a16d6 ZY |
943 | switch (skb->protocol) { |
944 | case htons(ETH_P_IP): | |
b156579b DT |
945 | dscp = ipv4_get_dsfield(ip_hdr(skb)) & 0xfc; |
946 | break; | |
947 | case htons(ETH_P_IPV6): | |
948 | dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & 0xfc; | |
e31a16d6 | 949 | break; |
960d97f9 SW |
950 | case htons(ETH_P_MPLS_UC): |
951 | case htons(ETH_P_MPLS_MC): { | |
952 | struct mpls_label mpls_tmp, *mpls; | |
953 | ||
954 | mpls = skb_header_pointer(skb, sizeof(struct ethhdr), | |
955 | sizeof(*mpls), &mpls_tmp); | |
956 | if (!mpls) | |
957 | return 0; | |
958 | ||
1fc9b725 | 959 | ret = (ntohl(mpls->entry) & MPLS_LS_TC_MASK) |
960d97f9 | 960 | >> MPLS_LS_TC_SHIFT; |
1fc9b725 | 961 | goto out; |
960d97f9 SW |
962 | } |
963 | case htons(ETH_P_80221): | |
964 | /* 802.21 is always network control traffic */ | |
965 | return 7; | |
e31a16d6 ZY |
966 | default: |
967 | return 0; | |
968 | } | |
969 | ||
fa9ffc74 KP |
970 | if (qos_map) { |
971 | unsigned int i, tmp_dscp = dscp >> 2; | |
972 | ||
973 | for (i = 0; i < qos_map->num_des; i++) { | |
1fc9b725 JB |
974 | if (tmp_dscp == qos_map->dscp_exception[i].dscp) { |
975 | ret = qos_map->dscp_exception[i].up; | |
976 | goto out; | |
977 | } | |
fa9ffc74 KP |
978 | } |
979 | ||
980 | for (i = 0; i < 8; i++) { | |
981 | if (tmp_dscp >= qos_map->up[i].low && | |
1fc9b725 JB |
982 | tmp_dscp <= qos_map->up[i].high) { |
983 | ret = i; | |
984 | goto out; | |
985 | } | |
fa9ffc74 KP |
986 | } |
987 | } | |
988 | ||
6fdb8b87 IP |
989 | /* The default mapping as defined Section 2.3 in RFC8325: The three |
990 | * Most Significant Bits (MSBs) of the DSCP are used as the | |
991 | * corresponding L2 markings. | |
992 | */ | |
1fc9b725 | 993 | ret = dscp >> 5; |
6fdb8b87 IP |
994 | |
995 | /* Handle specific DSCP values for which the default mapping (as | |
996 | * described above) doesn't adhere to the intended usage of the DSCP | |
997 | * value. See section 4 in RFC8325. Specifically, for the following | |
998 | * Diffserv Service Classes no update is needed: | |
999 | * - Standard: DF | |
1000 | * - Low Priority Data: CS1 | |
6fdb8b87 IP |
1001 | * - Multimedia Conferencing: AF41, AF42, AF43 |
1002 | * - Network Control Traffic: CS7 | |
1003 | * - Real-Time Interactive: CS4 | |
a68b22e2 | 1004 | * - Signaling: CS5 |
6fdb8b87 IP |
1005 | */ |
1006 | switch (dscp >> 2) { | |
1007 | case 10: | |
1008 | case 12: | |
1009 | case 14: | |
1010 | /* High throughput data: AF11, AF12, AF13 */ | |
1011 | ret = 0; | |
1012 | break; | |
1013 | case 16: | |
1014 | /* Operations, Administration, and Maintenance and Provisioning: | |
1015 | * CS2 | |
1016 | */ | |
1017 | ret = 0; | |
1018 | break; | |
1019 | case 18: | |
1020 | case 20: | |
1021 | case 22: | |
1022 | /* Low latency data: AF21, AF22, AF23 */ | |
1023 | ret = 3; | |
1024 | break; | |
1025 | case 24: | |
1026 | /* Broadcasting video: CS3 */ | |
1027 | ret = 4; | |
1028 | break; | |
a68b22e2 | 1029 | case 26: |
1030 | case 28: | |
1031 | case 30: | |
1032 | /* Multimedia Streaming: AF31, AF32, AF33 */ | |
1033 | ret = 4; | |
6fdb8b87 IP |
1034 | break; |
1035 | case 44: | |
1036 | /* Voice Admit: VA */ | |
1037 | ret = 6; | |
1038 | break; | |
1039 | case 46: | |
1040 | /* Telephony traffic: EF */ | |
1041 | ret = 6; | |
1042 | break; | |
1043 | case 48: | |
1044 | /* Network Control Traffic: CS6 */ | |
1045 | ret = 7; | |
1046 | break; | |
1047 | } | |
1fc9b725 JB |
1048 | out: |
1049 | return array_index_nospec(ret, IEEE80211_NUM_TIDS); | |
e31a16d6 ZY |
1050 | } |
1051 | EXPORT_SYMBOL(cfg80211_classify8021d); | |
517357c6 | 1052 | |
49a68e0d | 1053 | const struct element *ieee80211_bss_get_elem(struct cfg80211_bss *bss, u8 id) |
517357c6 | 1054 | { |
9caf0364 JB |
1055 | const struct cfg80211_bss_ies *ies; |
1056 | ||
1057 | ies = rcu_dereference(bss->ies); | |
1058 | if (!ies) | |
517357c6 | 1059 | return NULL; |
9caf0364 | 1060 | |
49a68e0d | 1061 | return cfg80211_find_elem(id, ies->data, ies->len); |
517357c6 | 1062 | } |
49a68e0d | 1063 | EXPORT_SYMBOL(ieee80211_bss_get_elem); |
fffd0934 JB |
1064 | |
1065 | void cfg80211_upload_connect_keys(struct wireless_dev *wdev) | |
1066 | { | |
f26cbf40 | 1067 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
fffd0934 JB |
1068 | struct net_device *dev = wdev->netdev; |
1069 | int i; | |
1070 | ||
1071 | if (!wdev->connect_keys) | |
1072 | return; | |
1073 | ||
585b6e13 | 1074 | for (i = 0; i < 4; i++) { |
fffd0934 JB |
1075 | if (!wdev->connect_keys->params[i].cipher) |
1076 | continue; | |
e7a7b84e | 1077 | if (rdev_add_key(rdev, dev, -1, i, false, NULL, |
e35e4d28 | 1078 | &wdev->connect_keys->params[i])) { |
e9c0268f | 1079 | netdev_err(dev, "failed to set key %d\n", i); |
1e056665 ZY |
1080 | continue; |
1081 | } | |
d4f29978 | 1082 | if (wdev->connect_keys->def == i && |
e7a7b84e | 1083 | rdev_set_default_key(rdev, dev, -1, i, true, true)) { |
d4f29978 JB |
1084 | netdev_err(dev, "failed to set defkey %d\n", i); |
1085 | continue; | |
1086 | } | |
fffd0934 JB |
1087 | } |
1088 | ||
453431a5 | 1089 | kfree_sensitive(wdev->connect_keys); |
fffd0934 JB |
1090 | wdev->connect_keys = NULL; |
1091 | } | |
3d54d255 | 1092 | |
1f6fc43e | 1093 | void cfg80211_process_wdev_events(struct wireless_dev *wdev) |
3d54d255 JB |
1094 | { |
1095 | struct cfg80211_event *ev; | |
1096 | unsigned long flags; | |
3d54d255 JB |
1097 | |
1098 | spin_lock_irqsave(&wdev->event_lock, flags); | |
1099 | while (!list_empty(&wdev->event_list)) { | |
1100 | ev = list_first_entry(&wdev->event_list, | |
1101 | struct cfg80211_event, list); | |
1102 | list_del(&ev->list); | |
1103 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
1104 | ||
3d54d255 JB |
1105 | switch (ev->type) { |
1106 | case EVENT_CONNECT_RESULT: | |
3d54d255 | 1107 | __cfg80211_connect_result( |
5349a0f7 VK |
1108 | wdev->netdev, |
1109 | &ev->cr, | |
1110 | ev->cr.status == WLAN_STATUS_SUCCESS); | |
3d54d255 JB |
1111 | break; |
1112 | case EVENT_ROAMED: | |
29ce6ecb | 1113 | __cfg80211_roamed(wdev, &ev->rm); |
3d54d255 JB |
1114 | break; |
1115 | case EVENT_DISCONNECTED: | |
1116 | __cfg80211_disconnected(wdev->netdev, | |
1117 | ev->dc.ie, ev->dc.ie_len, | |
80279fb7 JB |
1118 | ev->dc.reason, |
1119 | !ev->dc.locally_generated); | |
3d54d255 JB |
1120 | break; |
1121 | case EVENT_IBSS_JOINED: | |
fe94f3a4 AQ |
1122 | __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid, |
1123 | ev->ij.channel); | |
3d54d255 | 1124 | break; |
f04c2203 | 1125 | case EVENT_STOPPED: |
076fc877 | 1126 | cfg80211_leave(wiphy_to_rdev(wdev->wiphy), wdev); |
f04c2203 | 1127 | break; |
503c1fb9 | 1128 | case EVENT_PORT_AUTHORIZED: |
e4e7e3af | 1129 | __cfg80211_port_authorized(wdev, ev->pa.peer_addr, |
0ff57171 VY |
1130 | ev->pa.td_bitmap, |
1131 | ev->pa.td_bitmap_len); | |
503c1fb9 | 1132 | break; |
3d54d255 | 1133 | } |
3d54d255 JB |
1134 | |
1135 | kfree(ev); | |
1136 | ||
1137 | spin_lock_irqsave(&wdev->event_lock, flags); | |
1138 | } | |
1139 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
1140 | } | |
1141 | ||
1142 | void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev) | |
1143 | { | |
1144 | struct wireless_dev *wdev; | |
1145 | ||
a05829a7 | 1146 | lockdep_assert_held(&rdev->wiphy.mtx); |
3d54d255 | 1147 | |
53873f13 | 1148 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) |
3d54d255 | 1149 | cfg80211_process_wdev_events(wdev); |
3d54d255 JB |
1150 | } |
1151 | ||
1152 | int cfg80211_change_iface(struct cfg80211_registered_device *rdev, | |
1153 | struct net_device *dev, enum nl80211_iftype ntype, | |
818a986e | 1154 | struct vif_params *params) |
3d54d255 JB |
1155 | { |
1156 | int err; | |
1157 | enum nl80211_iftype otype = dev->ieee80211_ptr->iftype; | |
1158 | ||
a05829a7 | 1159 | lockdep_assert_held(&rdev->wiphy.mtx); |
3d54d255 JB |
1160 | |
1161 | /* don't support changing VLANs, you just re-create them */ | |
1162 | if (otype == NL80211_IFTYPE_AP_VLAN) | |
1163 | return -EOPNOTSUPP; | |
1164 | ||
cb3b7d87 AB |
1165 | /* cannot change into P2P device or NAN */ |
1166 | if (ntype == NL80211_IFTYPE_P2P_DEVICE || | |
1167 | ntype == NL80211_IFTYPE_NAN) | |
98104fde JB |
1168 | return -EOPNOTSUPP; |
1169 | ||
3d54d255 JB |
1170 | if (!rdev->ops->change_virtual_intf || |
1171 | !(rdev->wiphy.interface_modes & (1 << ntype))) | |
1172 | return -EOPNOTSUPP; | |
1173 | ||
6cbfb1bb | 1174 | if (ntype != otype) { |
689a0a9f JD |
1175 | /* if it's part of a bridge, reject changing type to station/ibss */ |
1176 | if (netif_is_bridge_port(dev) && | |
1177 | (ntype == NL80211_IFTYPE_ADHOC || | |
1178 | ntype == NL80211_IFTYPE_STATION || | |
1179 | ntype == NL80211_IFTYPE_P2P_CLIENT)) | |
1180 | return -EBUSY; | |
1181 | ||
9bc383de | 1182 | dev->ieee80211_ptr->use_4addr = false; |
fa9ffc74 | 1183 | rdev_set_qos_map(rdev, dev, NULL); |
9bc383de | 1184 | |
3d54d255 | 1185 | switch (otype) { |
ac800140 | 1186 | case NL80211_IFTYPE_AP: |
563fbefe | 1187 | case NL80211_IFTYPE_P2P_GO: |
7b0a0e3c | 1188 | cfg80211_stop_ap(rdev, dev, -1, true); |
ac800140 | 1189 | break; |
3d54d255 JB |
1190 | case NL80211_IFTYPE_ADHOC: |
1191 | cfg80211_leave_ibss(rdev, dev, false); | |
1192 | break; | |
1193 | case NL80211_IFTYPE_STATION: | |
074ac8df | 1194 | case NL80211_IFTYPE_P2P_CLIENT: |
3d54d255 JB |
1195 | cfg80211_disconnect(rdev, dev, |
1196 | WLAN_REASON_DEAUTH_LEAVING, true); | |
1197 | break; | |
1198 | case NL80211_IFTYPE_MESH_POINT: | |
1199 | /* mesh should be handled? */ | |
1200 | break; | |
a64b6a25 DC |
1201 | case NL80211_IFTYPE_OCB: |
1202 | cfg80211_leave_ocb(rdev, dev); | |
1203 | break; | |
3d54d255 JB |
1204 | default: |
1205 | break; | |
1206 | } | |
1207 | ||
1208 | cfg80211_process_rdev_events(rdev); | |
c1d3ad84 | 1209 | cfg80211_mlme_purge_registrations(dev->ieee80211_ptr); |
7b0a0e3c JB |
1210 | |
1211 | memset(&dev->ieee80211_ptr->u, 0, | |
1212 | sizeof(dev->ieee80211_ptr->u)); | |
1213 | memset(&dev->ieee80211_ptr->links, 0, | |
1214 | sizeof(dev->ieee80211_ptr->links)); | |
3d54d255 JB |
1215 | } |
1216 | ||
818a986e | 1217 | err = rdev_change_virtual_intf(rdev, dev, ntype, params); |
3d54d255 JB |
1218 | |
1219 | WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype); | |
1220 | ||
9bc383de JB |
1221 | if (!err && params && params->use_4addr != -1) |
1222 | dev->ieee80211_ptr->use_4addr = params->use_4addr; | |
1223 | ||
ad4bb6f8 JB |
1224 | if (!err) { |
1225 | dev->priv_flags &= ~IFF_DONT_BRIDGE; | |
1226 | switch (ntype) { | |
1227 | case NL80211_IFTYPE_STATION: | |
1228 | if (dev->ieee80211_ptr->use_4addr) | |
1229 | break; | |
df561f66 | 1230 | fallthrough; |
6e0bd6c3 | 1231 | case NL80211_IFTYPE_OCB: |
074ac8df | 1232 | case NL80211_IFTYPE_P2P_CLIENT: |
ad4bb6f8 JB |
1233 | case NL80211_IFTYPE_ADHOC: |
1234 | dev->priv_flags |= IFF_DONT_BRIDGE; | |
1235 | break; | |
074ac8df | 1236 | case NL80211_IFTYPE_P2P_GO: |
ad4bb6f8 JB |
1237 | case NL80211_IFTYPE_AP: |
1238 | case NL80211_IFTYPE_AP_VLAN: | |
ad4bb6f8 JB |
1239 | case NL80211_IFTYPE_MESH_POINT: |
1240 | /* bridging OK */ | |
1241 | break; | |
1242 | case NL80211_IFTYPE_MONITOR: | |
1243 | /* monitor can't bridge anyway */ | |
1244 | break; | |
1245 | case NL80211_IFTYPE_UNSPECIFIED: | |
2e161f78 | 1246 | case NUM_NL80211_IFTYPES: |
ad4bb6f8 JB |
1247 | /* not happening */ |
1248 | break; | |
98104fde | 1249 | case NL80211_IFTYPE_P2P_DEVICE: |
e7e0517c | 1250 | case NL80211_IFTYPE_WDS: |
cb3b7d87 | 1251 | case NL80211_IFTYPE_NAN: |
98104fde JB |
1252 | WARN_ON(1); |
1253 | break; | |
ad4bb6f8 JB |
1254 | } |
1255 | } | |
1256 | ||
dbbae26a MK |
1257 | if (!err && ntype != otype && netif_running(dev)) { |
1258 | cfg80211_update_iface_num(rdev, ntype, 1); | |
1259 | cfg80211_update_iface_num(rdev, otype, -1); | |
1260 | } | |
1261 | ||
3d54d255 JB |
1262 | return err; |
1263 | } | |
254416aa | 1264 | |
0c1eca4e JB |
1265 | static u32 cfg80211_calculate_bitrate_ht(struct rate_info *rate) |
1266 | { | |
1267 | int modulation, streams, bitrate; | |
1268 | ||
1269 | /* the formula below does only work for MCS values smaller than 32 */ | |
1270 | if (WARN_ON_ONCE(rate->mcs >= 32)) | |
1271 | return 0; | |
1272 | ||
1273 | modulation = rate->mcs & 7; | |
1274 | streams = (rate->mcs >> 3) + 1; | |
1275 | ||
1276 | bitrate = (rate->bw == RATE_INFO_BW_40) ? 13500000 : 6500000; | |
1277 | ||
1278 | if (modulation < 4) | |
1279 | bitrate *= (modulation + 1); | |
1280 | else if (modulation == 4) | |
1281 | bitrate *= (modulation + 2); | |
1282 | else | |
1283 | bitrate *= (modulation + 3); | |
1284 | ||
1285 | bitrate *= streams; | |
1286 | ||
1287 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | |
1288 | bitrate = (bitrate / 9) * 10; | |
1289 | ||
1290 | /* do NOT round down here */ | |
1291 | return (bitrate + 50000) / 100000; | |
1292 | } | |
1293 | ||
2a38075c | 1294 | static u32 cfg80211_calculate_bitrate_dmg(struct rate_info *rate) |
95ddc1fc VK |
1295 | { |
1296 | static const u32 __mcs2bitrate[] = { | |
1297 | /* control PHY */ | |
1298 | [0] = 275, | |
1299 | /* SC PHY */ | |
1300 | [1] = 3850, | |
1301 | [2] = 7700, | |
1302 | [3] = 9625, | |
1303 | [4] = 11550, | |
1304 | [5] = 12512, /* 1251.25 mbps */ | |
1305 | [6] = 15400, | |
1306 | [7] = 19250, | |
1307 | [8] = 23100, | |
1308 | [9] = 25025, | |
1309 | [10] = 30800, | |
1310 | [11] = 38500, | |
1311 | [12] = 46200, | |
1312 | /* OFDM PHY */ | |
1313 | [13] = 6930, | |
1314 | [14] = 8662, /* 866.25 mbps */ | |
1315 | [15] = 13860, | |
1316 | [16] = 17325, | |
1317 | [17] = 20790, | |
1318 | [18] = 27720, | |
1319 | [19] = 34650, | |
1320 | [20] = 41580, | |
1321 | [21] = 45045, | |
1322 | [22] = 51975, | |
1323 | [23] = 62370, | |
1324 | [24] = 67568, /* 6756.75 mbps */ | |
1325 | /* LP-SC PHY */ | |
1326 | [25] = 6260, | |
1327 | [26] = 8340, | |
1328 | [27] = 11120, | |
1329 | [28] = 12510, | |
1330 | [29] = 16680, | |
1331 | [30] = 22240, | |
1332 | [31] = 25030, | |
1333 | }; | |
1334 | ||
1335 | if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate))) | |
1336 | return 0; | |
1337 | ||
1338 | return __mcs2bitrate[rate->mcs]; | |
1339 | } | |
1340 | ||
d9c85e24 MC |
1341 | static u32 cfg80211_calculate_bitrate_extended_sc_dmg(struct rate_info *rate) |
1342 | { | |
1343 | static const u32 __mcs2bitrate[] = { | |
1344 | [6 - 6] = 26950, /* MCS 9.1 : 2695.0 mbps */ | |
1345 | [7 - 6] = 50050, /* MCS 12.1 */ | |
1346 | [8 - 6] = 53900, | |
1347 | [9 - 6] = 57750, | |
1348 | [10 - 6] = 63900, | |
1349 | [11 - 6] = 75075, | |
1350 | [12 - 6] = 80850, | |
1351 | }; | |
1352 | ||
1353 | /* Extended SC MCS not defined for base MCS below 6 or above 12 */ | |
1354 | if (WARN_ON_ONCE(rate->mcs < 6 || rate->mcs > 12)) | |
1355 | return 0; | |
1356 | ||
1357 | return __mcs2bitrate[rate->mcs - 6]; | |
1358 | } | |
1359 | ||
2a38075c AAL |
1360 | static u32 cfg80211_calculate_bitrate_edmg(struct rate_info *rate) |
1361 | { | |
1362 | static const u32 __mcs2bitrate[] = { | |
1363 | /* control PHY */ | |
1364 | [0] = 275, | |
1365 | /* SC PHY */ | |
1366 | [1] = 3850, | |
1367 | [2] = 7700, | |
1368 | [3] = 9625, | |
1369 | [4] = 11550, | |
1370 | [5] = 12512, /* 1251.25 mbps */ | |
1371 | [6] = 13475, | |
1372 | [7] = 15400, | |
1373 | [8] = 19250, | |
1374 | [9] = 23100, | |
1375 | [10] = 25025, | |
1376 | [11] = 26950, | |
1377 | [12] = 30800, | |
1378 | [13] = 38500, | |
1379 | [14] = 46200, | |
1380 | [15] = 50050, | |
1381 | [16] = 53900, | |
1382 | [17] = 57750, | |
1383 | [18] = 69300, | |
1384 | [19] = 75075, | |
1385 | [20] = 80850, | |
1386 | }; | |
1387 | ||
1388 | if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate))) | |
1389 | return 0; | |
1390 | ||
1391 | return __mcs2bitrate[rate->mcs] * rate->n_bonded_ch; | |
1392 | } | |
1393 | ||
db9c64cf JB |
1394 | static u32 cfg80211_calculate_bitrate_vht(struct rate_info *rate) |
1395 | { | |
c27aa56a | 1396 | static const u32 base[4][12] = { |
db9c64cf JB |
1397 | { 6500000, |
1398 | 13000000, | |
1399 | 19500000, | |
1400 | 26000000, | |
1401 | 39000000, | |
1402 | 52000000, | |
1403 | 58500000, | |
1404 | 65000000, | |
1405 | 78000000, | |
8fdd136f | 1406 | /* not in the spec, but some devices use this: */ |
c27aa56a AS |
1407 | 86700000, |
1408 | 97500000, | |
1409 | 108300000, | |
db9c64cf JB |
1410 | }, |
1411 | { 13500000, | |
1412 | 27000000, | |
1413 | 40500000, | |
1414 | 54000000, | |
1415 | 81000000, | |
1416 | 108000000, | |
1417 | 121500000, | |
1418 | 135000000, | |
1419 | 162000000, | |
1420 | 180000000, | |
c27aa56a AS |
1421 | 202500000, |
1422 | 225000000, | |
db9c64cf JB |
1423 | }, |
1424 | { 29300000, | |
1425 | 58500000, | |
1426 | 87800000, | |
1427 | 117000000, | |
1428 | 175500000, | |
1429 | 234000000, | |
1430 | 263300000, | |
1431 | 292500000, | |
1432 | 351000000, | |
1433 | 390000000, | |
c27aa56a AS |
1434 | 438800000, |
1435 | 487500000, | |
db9c64cf JB |
1436 | }, |
1437 | { 58500000, | |
1438 | 117000000, | |
1439 | 175500000, | |
1440 | 234000000, | |
1441 | 351000000, | |
1442 | 468000000, | |
1443 | 526500000, | |
1444 | 585000000, | |
1445 | 702000000, | |
1446 | 780000000, | |
c27aa56a AS |
1447 | 877500000, |
1448 | 975000000, | |
db9c64cf JB |
1449 | }, |
1450 | }; | |
1451 | u32 bitrate; | |
1452 | int idx; | |
1453 | ||
c27aa56a | 1454 | if (rate->mcs > 11) |
ca8fe250 | 1455 | goto warn; |
db9c64cf | 1456 | |
b51f3bee JB |
1457 | switch (rate->bw) { |
1458 | case RATE_INFO_BW_160: | |
1459 | idx = 3; | |
1460 | break; | |
1461 | case RATE_INFO_BW_80: | |
1462 | idx = 2; | |
1463 | break; | |
1464 | case RATE_INFO_BW_40: | |
1465 | idx = 1; | |
1466 | break; | |
1467 | case RATE_INFO_BW_5: | |
1468 | case RATE_INFO_BW_10: | |
1469 | default: | |
ca8fe250 | 1470 | goto warn; |
b51f3bee JB |
1471 | case RATE_INFO_BW_20: |
1472 | idx = 0; | |
1473 | } | |
db9c64cf JB |
1474 | |
1475 | bitrate = base[idx][rate->mcs]; | |
1476 | bitrate *= rate->nss; | |
1477 | ||
1478 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | |
1479 | bitrate = (bitrate / 9) * 10; | |
1480 | ||
1481 | /* do NOT round down here */ | |
1482 | return (bitrate + 50000) / 100000; | |
ca8fe250 JB |
1483 | warn: |
1484 | WARN_ONCE(1, "invalid rate bw=%d, mcs=%d, nss=%d\n", | |
1485 | rate->bw, rate->mcs, rate->nss); | |
1486 | return 0; | |
db9c64cf JB |
1487 | } |
1488 | ||
c4cbaf79 LC |
1489 | static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate) |
1490 | { | |
9c97c88d VK |
1491 | #define SCALE 6144 |
1492 | u32 mcs_divisors[14] = { | |
1493 | 102399, /* 16.666666... */ | |
1494 | 51201, /* 8.333333... */ | |
1495 | 34134, /* 5.555555... */ | |
1496 | 25599, /* 4.166666... */ | |
1497 | 17067, /* 2.777777... */ | |
1498 | 12801, /* 2.083333... */ | |
64e966d1 | 1499 | 11377, /* 1.851725... */ |
9c97c88d VK |
1500 | 10239, /* 1.666666... */ |
1501 | 8532, /* 1.388888... */ | |
1502 | 7680, /* 1.250000... */ | |
1503 | 6828, /* 1.111111... */ | |
1504 | 6144, /* 1.000000... */ | |
1505 | 5690, /* 0.926106... */ | |
1506 | 5120, /* 0.833333... */ | |
c4cbaf79 LC |
1507 | }; |
1508 | u32 rates_160M[3] = { 960777777, 907400000, 816666666 }; | |
9ee0d44f | 1509 | u32 rates_996[3] = { 480388888, 453700000, 408333333 }; |
c4cbaf79 LC |
1510 | u32 rates_484[3] = { 229411111, 216666666, 195000000 }; |
1511 | u32 rates_242[3] = { 114711111, 108333333, 97500000 }; | |
1512 | u32 rates_106[3] = { 40000000, 37777777, 34000000 }; | |
1513 | u32 rates_52[3] = { 18820000, 17777777, 16000000 }; | |
1514 | u32 rates_26[3] = { 9411111, 8888888, 8000000 }; | |
1515 | u64 tmp; | |
1516 | u32 result; | |
1517 | ||
9c97c88d | 1518 | if (WARN_ON_ONCE(rate->mcs > 13)) |
c4cbaf79 LC |
1519 | return 0; |
1520 | ||
1521 | if (WARN_ON_ONCE(rate->he_gi > NL80211_RATE_INFO_HE_GI_3_2)) | |
1522 | return 0; | |
1523 | if (WARN_ON_ONCE(rate->he_ru_alloc > | |
1524 | NL80211_RATE_INFO_HE_RU_ALLOC_2x996)) | |
1525 | return 0; | |
1526 | if (WARN_ON_ONCE(rate->nss < 1 || rate->nss > 8)) | |
1527 | return 0; | |
1528 | ||
bcbd771c BQ |
1529 | if (rate->bw == RATE_INFO_BW_160 || |
1530 | (rate->bw == RATE_INFO_BW_HE_RU && | |
1531 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_2x996)) | |
c4cbaf79 LC |
1532 | result = rates_160M[rate->he_gi]; |
1533 | else if (rate->bw == RATE_INFO_BW_80 || | |
1534 | (rate->bw == RATE_INFO_BW_HE_RU && | |
1535 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_996)) | |
9ee0d44f | 1536 | result = rates_996[rate->he_gi]; |
c4cbaf79 LC |
1537 | else if (rate->bw == RATE_INFO_BW_40 || |
1538 | (rate->bw == RATE_INFO_BW_HE_RU && | |
1539 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_484)) | |
1540 | result = rates_484[rate->he_gi]; | |
1541 | else if (rate->bw == RATE_INFO_BW_20 || | |
1542 | (rate->bw == RATE_INFO_BW_HE_RU && | |
1543 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_242)) | |
1544 | result = rates_242[rate->he_gi]; | |
1545 | else if (rate->bw == RATE_INFO_BW_HE_RU && | |
1546 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_106) | |
1547 | result = rates_106[rate->he_gi]; | |
1548 | else if (rate->bw == RATE_INFO_BW_HE_RU && | |
1549 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_52) | |
1550 | result = rates_52[rate->he_gi]; | |
1551 | else if (rate->bw == RATE_INFO_BW_HE_RU && | |
1552 | rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26) | |
1553 | result = rates_26[rate->he_gi]; | |
344c9719 NC |
1554 | else { |
1555 | WARN(1, "invalid HE MCS: bw:%d, ru:%d\n", | |
1556 | rate->bw, rate->he_ru_alloc); | |
c4cbaf79 | 1557 | return 0; |
344c9719 | 1558 | } |
c4cbaf79 LC |
1559 | |
1560 | /* now scale to the appropriate MCS */ | |
1561 | tmp = result; | |
1562 | tmp *= SCALE; | |
1563 | do_div(tmp, mcs_divisors[rate->mcs]); | |
1564 | result = tmp; | |
1565 | ||
1566 | /* and take NSS, DCM into account */ | |
1567 | result = (result * rate->nss) / 8; | |
1568 | if (rate->he_dcm) | |
1569 | result /= 2; | |
1570 | ||
25d16d12 | 1571 | return result / 10000; |
c4cbaf79 LC |
1572 | } |
1573 | ||
cfb14110 VJ |
1574 | static u32 cfg80211_calculate_bitrate_eht(struct rate_info *rate) |
1575 | { | |
1576 | #define SCALE 6144 | |
1577 | static const u32 mcs_divisors[16] = { | |
1578 | 102399, /* 16.666666... */ | |
1579 | 51201, /* 8.333333... */ | |
1580 | 34134, /* 5.555555... */ | |
1581 | 25599, /* 4.166666... */ | |
1582 | 17067, /* 2.777777... */ | |
1583 | 12801, /* 2.083333... */ | |
64e966d1 | 1584 | 11377, /* 1.851725... */ |
cfb14110 VJ |
1585 | 10239, /* 1.666666... */ |
1586 | 8532, /* 1.388888... */ | |
1587 | 7680, /* 1.250000... */ | |
1588 | 6828, /* 1.111111... */ | |
1589 | 6144, /* 1.000000... */ | |
1590 | 5690, /* 0.926106... */ | |
1591 | 5120, /* 0.833333... */ | |
1592 | 409600, /* 66.666666... */ | |
1593 | 204800, /* 33.333333... */ | |
1594 | }; | |
1595 | static const u32 rates_996[3] = { 480388888, 453700000, 408333333 }; | |
1596 | static const u32 rates_484[3] = { 229411111, 216666666, 195000000 }; | |
1597 | static const u32 rates_242[3] = { 114711111, 108333333, 97500000 }; | |
1598 | static const u32 rates_106[3] = { 40000000, 37777777, 34000000 }; | |
1599 | static const u32 rates_52[3] = { 18820000, 17777777, 16000000 }; | |
1600 | static const u32 rates_26[3] = { 9411111, 8888888, 8000000 }; | |
1601 | u64 tmp; | |
1602 | u32 result; | |
1603 | ||
1604 | if (WARN_ON_ONCE(rate->mcs > 15)) | |
1605 | return 0; | |
1606 | if (WARN_ON_ONCE(rate->eht_gi > NL80211_RATE_INFO_EHT_GI_3_2)) | |
1607 | return 0; | |
1608 | if (WARN_ON_ONCE(rate->eht_ru_alloc > | |
1609 | NL80211_RATE_INFO_EHT_RU_ALLOC_4x996)) | |
1610 | return 0; | |
1611 | if (WARN_ON_ONCE(rate->nss < 1 || rate->nss > 8)) | |
1612 | return 0; | |
1613 | ||
1614 | /* Bandwidth checks for MCS 14 */ | |
1615 | if (rate->mcs == 14) { | |
1616 | if ((rate->bw != RATE_INFO_BW_EHT_RU && | |
1617 | rate->bw != RATE_INFO_BW_80 && | |
1618 | rate->bw != RATE_INFO_BW_160 && | |
1619 | rate->bw != RATE_INFO_BW_320) || | |
1620 | (rate->bw == RATE_INFO_BW_EHT_RU && | |
1621 | rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_996 && | |
1622 | rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_2x996 && | |
1623 | rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_4x996)) { | |
1624 | WARN(1, "invalid EHT BW for MCS 14: bw:%d, ru:%d\n", | |
1625 | rate->bw, rate->eht_ru_alloc); | |
1626 | return 0; | |
1627 | } | |
1628 | } | |
1629 | ||
1630 | if (rate->bw == RATE_INFO_BW_320 || | |
1631 | (rate->bw == RATE_INFO_BW_EHT_RU && | |
1632 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_4x996)) | |
1633 | result = 4 * rates_996[rate->eht_gi]; | |
1634 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1635 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484) | |
1636 | result = 3 * rates_996[rate->eht_gi] + rates_484[rate->eht_gi]; | |
1637 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1638 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_3x996) | |
1639 | result = 3 * rates_996[rate->eht_gi]; | |
1640 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1641 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484) | |
1642 | result = 2 * rates_996[rate->eht_gi] + rates_484[rate->eht_gi]; | |
1643 | else if (rate->bw == RATE_INFO_BW_160 || | |
1644 | (rate->bw == RATE_INFO_BW_EHT_RU && | |
1645 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_2x996)) | |
1646 | result = 2 * rates_996[rate->eht_gi]; | |
1647 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1648 | rate->eht_ru_alloc == | |
1649 | NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242) | |
1650 | result = rates_996[rate->eht_gi] + rates_484[rate->eht_gi] | |
1651 | + rates_242[rate->eht_gi]; | |
1652 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1653 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_996P484) | |
1654 | result = rates_996[rate->eht_gi] + rates_484[rate->eht_gi]; | |
1655 | else if (rate->bw == RATE_INFO_BW_80 || | |
1656 | (rate->bw == RATE_INFO_BW_EHT_RU && | |
1657 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_996)) | |
1658 | result = rates_996[rate->eht_gi]; | |
1659 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1660 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_484P242) | |
1661 | result = rates_484[rate->eht_gi] + rates_242[rate->eht_gi]; | |
1662 | else if (rate->bw == RATE_INFO_BW_40 || | |
1663 | (rate->bw == RATE_INFO_BW_EHT_RU && | |
1664 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_484)) | |
1665 | result = rates_484[rate->eht_gi]; | |
1666 | else if (rate->bw == RATE_INFO_BW_20 || | |
1667 | (rate->bw == RATE_INFO_BW_EHT_RU && | |
1668 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_242)) | |
1669 | result = rates_242[rate->eht_gi]; | |
1670 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1671 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_106P26) | |
1672 | result = rates_106[rate->eht_gi] + rates_26[rate->eht_gi]; | |
1673 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1674 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_106) | |
1675 | result = rates_106[rate->eht_gi]; | |
1676 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1677 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_52P26) | |
1678 | result = rates_52[rate->eht_gi] + rates_26[rate->eht_gi]; | |
1679 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1680 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_52) | |
1681 | result = rates_52[rate->eht_gi]; | |
1682 | else if (rate->bw == RATE_INFO_BW_EHT_RU && | |
1683 | rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_26) | |
1684 | result = rates_26[rate->eht_gi]; | |
1685 | else { | |
1686 | WARN(1, "invalid EHT MCS: bw:%d, ru:%d\n", | |
1687 | rate->bw, rate->eht_ru_alloc); | |
1688 | return 0; | |
1689 | } | |
1690 | ||
1691 | /* now scale to the appropriate MCS */ | |
1692 | tmp = result; | |
1693 | tmp *= SCALE; | |
1694 | do_div(tmp, mcs_divisors[rate->mcs]); | |
cfb14110 VJ |
1695 | |
1696 | /* and take NSS */ | |
18429c51 PZ |
1697 | tmp *= rate->nss; |
1698 | do_div(tmp, 8); | |
1699 | ||
1700 | result = tmp; | |
cfb14110 VJ |
1701 | |
1702 | return result / 10000; | |
1703 | } | |
1704 | ||
2ad66fcb GI |
1705 | static u32 cfg80211_calculate_bitrate_s1g(struct rate_info *rate) |
1706 | { | |
1707 | /* For 1, 2, 4, 8 and 16 MHz channels */ | |
1708 | static const u32 base[5][11] = { | |
1709 | { 300000, | |
1710 | 600000, | |
1711 | 900000, | |
1712 | 1200000, | |
1713 | 1800000, | |
1714 | 2400000, | |
1715 | 2700000, | |
1716 | 3000000, | |
1717 | 3600000, | |
1718 | 4000000, | |
1719 | /* MCS 10 supported in 1 MHz only */ | |
1720 | 150000, | |
1721 | }, | |
1722 | { 650000, | |
1723 | 1300000, | |
1724 | 1950000, | |
1725 | 2600000, | |
1726 | 3900000, | |
1727 | 5200000, | |
1728 | 5850000, | |
1729 | 6500000, | |
1730 | 7800000, | |
1731 | /* MCS 9 not valid */ | |
1732 | }, | |
1733 | { 1350000, | |
1734 | 2700000, | |
1735 | 4050000, | |
1736 | 5400000, | |
1737 | 8100000, | |
1738 | 10800000, | |
1739 | 12150000, | |
1740 | 13500000, | |
1741 | 16200000, | |
1742 | 18000000, | |
1743 | }, | |
1744 | { 2925000, | |
1745 | 5850000, | |
1746 | 8775000, | |
1747 | 11700000, | |
1748 | 17550000, | |
1749 | 23400000, | |
1750 | 26325000, | |
1751 | 29250000, | |
1752 | 35100000, | |
1753 | 39000000, | |
1754 | }, | |
1755 | { 8580000, | |
1756 | 11700000, | |
1757 | 17550000, | |
1758 | 23400000, | |
1759 | 35100000, | |
1760 | 46800000, | |
1761 | 52650000, | |
1762 | 58500000, | |
1763 | 70200000, | |
1764 | 78000000, | |
1765 | }, | |
1766 | }; | |
1767 | u32 bitrate; | |
1768 | /* default is 1 MHz index */ | |
1769 | int idx = 0; | |
1770 | ||
1771 | if (rate->mcs >= 11) | |
1772 | goto warn; | |
1773 | ||
1774 | switch (rate->bw) { | |
1775 | case RATE_INFO_BW_16: | |
1776 | idx = 4; | |
1777 | break; | |
1778 | case RATE_INFO_BW_8: | |
1779 | idx = 3; | |
1780 | break; | |
1781 | case RATE_INFO_BW_4: | |
1782 | idx = 2; | |
1783 | break; | |
1784 | case RATE_INFO_BW_2: | |
1785 | idx = 1; | |
1786 | break; | |
1787 | case RATE_INFO_BW_1: | |
1788 | idx = 0; | |
1789 | break; | |
1790 | case RATE_INFO_BW_5: | |
1791 | case RATE_INFO_BW_10: | |
1792 | case RATE_INFO_BW_20: | |
1793 | case RATE_INFO_BW_40: | |
1794 | case RATE_INFO_BW_80: | |
1795 | case RATE_INFO_BW_160: | |
1796 | default: | |
1797 | goto warn; | |
1798 | } | |
1799 | ||
1800 | bitrate = base[idx][rate->mcs]; | |
1801 | bitrate *= rate->nss; | |
1802 | ||
1803 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | |
1804 | bitrate = (bitrate / 9) * 10; | |
1805 | /* do NOT round down here */ | |
1806 | return (bitrate + 50000) / 100000; | |
1807 | warn: | |
1808 | WARN_ONCE(1, "invalid rate bw=%d, mcs=%d, nss=%d\n", | |
1809 | rate->bw, rate->mcs, rate->nss); | |
1810 | return 0; | |
1811 | } | |
1812 | ||
8eb41c8d | 1813 | u32 cfg80211_calculate_bitrate(struct rate_info *rate) |
254416aa | 1814 | { |
0c1eca4e JB |
1815 | if (rate->flags & RATE_INFO_FLAGS_MCS) |
1816 | return cfg80211_calculate_bitrate_ht(rate); | |
2a38075c AAL |
1817 | if (rate->flags & RATE_INFO_FLAGS_DMG) |
1818 | return cfg80211_calculate_bitrate_dmg(rate); | |
d9c85e24 MC |
1819 | if (rate->flags & RATE_INFO_FLAGS_EXTENDED_SC_DMG) |
1820 | return cfg80211_calculate_bitrate_extended_sc_dmg(rate); | |
2a38075c AAL |
1821 | if (rate->flags & RATE_INFO_FLAGS_EDMG) |
1822 | return cfg80211_calculate_bitrate_edmg(rate); | |
db9c64cf JB |
1823 | if (rate->flags & RATE_INFO_FLAGS_VHT_MCS) |
1824 | return cfg80211_calculate_bitrate_vht(rate); | |
c4cbaf79 LC |
1825 | if (rate->flags & RATE_INFO_FLAGS_HE_MCS) |
1826 | return cfg80211_calculate_bitrate_he(rate); | |
cfb14110 VJ |
1827 | if (rate->flags & RATE_INFO_FLAGS_EHT_MCS) |
1828 | return cfg80211_calculate_bitrate_eht(rate); | |
2ad66fcb GI |
1829 | if (rate->flags & RATE_INFO_FLAGS_S1G_MCS) |
1830 | return cfg80211_calculate_bitrate_s1g(rate); | |
254416aa | 1831 | |
0c1eca4e | 1832 | return rate->legacy; |
254416aa | 1833 | } |
8097e149 | 1834 | EXPORT_SYMBOL(cfg80211_calculate_bitrate); |
56d1893d | 1835 | |
c216e641 AS |
1836 | int cfg80211_get_p2p_attr(const u8 *ies, unsigned int len, |
1837 | enum ieee80211_p2p_attr_id attr, | |
1838 | u8 *buf, unsigned int bufsize) | |
0ee45355 JB |
1839 | { |
1840 | u8 *out = buf; | |
1841 | u16 attr_remaining = 0; | |
1842 | bool desired_attr = false; | |
1843 | u16 desired_len = 0; | |
1844 | ||
1845 | while (len > 0) { | |
1846 | unsigned int iedatalen; | |
1847 | unsigned int copy; | |
1848 | const u8 *iedata; | |
1849 | ||
1850 | if (len < 2) | |
1851 | return -EILSEQ; | |
1852 | iedatalen = ies[1]; | |
1853 | if (iedatalen + 2 > len) | |
1854 | return -EILSEQ; | |
1855 | ||
1856 | if (ies[0] != WLAN_EID_VENDOR_SPECIFIC) | |
1857 | goto cont; | |
1858 | ||
1859 | if (iedatalen < 4) | |
1860 | goto cont; | |
1861 | ||
1862 | iedata = ies + 2; | |
1863 | ||
1864 | /* check WFA OUI, P2P subtype */ | |
1865 | if (iedata[0] != 0x50 || iedata[1] != 0x6f || | |
1866 | iedata[2] != 0x9a || iedata[3] != 0x09) | |
1867 | goto cont; | |
1868 | ||
1869 | iedatalen -= 4; | |
1870 | iedata += 4; | |
1871 | ||
1872 | /* check attribute continuation into this IE */ | |
1873 | copy = min_t(unsigned int, attr_remaining, iedatalen); | |
1874 | if (copy && desired_attr) { | |
1875 | desired_len += copy; | |
1876 | if (out) { | |
1877 | memcpy(out, iedata, min(bufsize, copy)); | |
1878 | out += min(bufsize, copy); | |
1879 | bufsize -= min(bufsize, copy); | |
1880 | } | |
1881 | ||
1882 | ||
1883 | if (copy == attr_remaining) | |
1884 | return desired_len; | |
1885 | } | |
1886 | ||
1887 | attr_remaining -= copy; | |
1888 | if (attr_remaining) | |
1889 | goto cont; | |
1890 | ||
1891 | iedatalen -= copy; | |
1892 | iedata += copy; | |
1893 | ||
1894 | while (iedatalen > 0) { | |
1895 | u16 attr_len; | |
1896 | ||
1897 | /* P2P attribute ID & size must fit */ | |
1898 | if (iedatalen < 3) | |
1899 | return -EILSEQ; | |
1900 | desired_attr = iedata[0] == attr; | |
1901 | attr_len = get_unaligned_le16(iedata + 1); | |
1902 | iedatalen -= 3; | |
1903 | iedata += 3; | |
1904 | ||
1905 | copy = min_t(unsigned int, attr_len, iedatalen); | |
1906 | ||
1907 | if (desired_attr) { | |
1908 | desired_len += copy; | |
1909 | if (out) { | |
1910 | memcpy(out, iedata, min(bufsize, copy)); | |
1911 | out += min(bufsize, copy); | |
1912 | bufsize -= min(bufsize, copy); | |
1913 | } | |
1914 | ||
1915 | if (copy == attr_len) | |
1916 | return desired_len; | |
1917 | } | |
1918 | ||
1919 | iedata += copy; | |
1920 | iedatalen -= copy; | |
1921 | attr_remaining = attr_len - copy; | |
1922 | } | |
1923 | ||
1924 | cont: | |
1925 | len -= ies[1] + 2; | |
1926 | ies += ies[1] + 2; | |
1927 | } | |
1928 | ||
1929 | if (attr_remaining && desired_attr) | |
1930 | return -EILSEQ; | |
1931 | ||
1932 | return -ENOENT; | |
1933 | } | |
1934 | EXPORT_SYMBOL(cfg80211_get_p2p_attr); | |
1935 | ||
2512b1b1 | 1936 | static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id, bool id_ext) |
29464ccc JB |
1937 | { |
1938 | int i; | |
1939 | ||
2512b1b1 LK |
1940 | /* Make sure array values are legal */ |
1941 | if (WARN_ON(ids[n_ids - 1] == WLAN_EID_EXTENSION)) | |
1942 | return false; | |
1943 | ||
1944 | i = 0; | |
1945 | while (i < n_ids) { | |
1946 | if (ids[i] == WLAN_EID_EXTENSION) { | |
1947 | if (id_ext && (ids[i + 1] == id)) | |
1948 | return true; | |
1949 | ||
1950 | i += 2; | |
1951 | continue; | |
1952 | } | |
1953 | ||
1954 | if (ids[i] == id && !id_ext) | |
29464ccc | 1955 | return true; |
2512b1b1 LK |
1956 | |
1957 | i++; | |
1958 | } | |
29464ccc JB |
1959 | return false; |
1960 | } | |
1961 | ||
8ac63448 JB |
1962 | static size_t skip_ie(const u8 *ies, size_t ielen, size_t pos) |
1963 | { | |
1964 | /* we assume a validly formed IEs buffer */ | |
1965 | u8 len = ies[pos + 1]; | |
1966 | ||
1967 | pos += 2 + len; | |
1968 | ||
1969 | /* the IE itself must have 255 bytes for fragments to follow */ | |
1970 | if (len < 255) | |
1971 | return pos; | |
1972 | ||
1973 | while (pos < ielen && ies[pos] == WLAN_EID_FRAGMENT) { | |
1974 | len = ies[pos + 1]; | |
1975 | pos += 2 + len; | |
1976 | } | |
1977 | ||
1978 | return pos; | |
1979 | } | |
1980 | ||
29464ccc JB |
1981 | size_t ieee80211_ie_split_ric(const u8 *ies, size_t ielen, |
1982 | const u8 *ids, int n_ids, | |
1983 | const u8 *after_ric, int n_after_ric, | |
1984 | size_t offset) | |
1985 | { | |
1986 | size_t pos = offset; | |
1987 | ||
2512b1b1 LK |
1988 | while (pos < ielen) { |
1989 | u8 ext = 0; | |
1990 | ||
1991 | if (ies[pos] == WLAN_EID_EXTENSION) | |
1992 | ext = 2; | |
1993 | if ((pos + ext) >= ielen) | |
1994 | break; | |
1995 | ||
1996 | if (!ieee80211_id_in_list(ids, n_ids, ies[pos + ext], | |
1997 | ies[pos] == WLAN_EID_EXTENSION)) | |
1998 | break; | |
1999 | ||
29464ccc | 2000 | if (ies[pos] == WLAN_EID_RIC_DATA && n_after_ric) { |
8ac63448 | 2001 | pos = skip_ie(ies, ielen, pos); |
29464ccc | 2002 | |
2512b1b1 LK |
2003 | while (pos < ielen) { |
2004 | if (ies[pos] == WLAN_EID_EXTENSION) | |
2005 | ext = 2; | |
2006 | else | |
2007 | ext = 0; | |
2008 | ||
2009 | if ((pos + ext) >= ielen) | |
2010 | break; | |
2011 | ||
2012 | if (!ieee80211_id_in_list(after_ric, | |
2013 | n_after_ric, | |
2014 | ies[pos + ext], | |
2015 | ext == 2)) | |
2016 | pos = skip_ie(ies, ielen, pos); | |
312ca38d JM |
2017 | else |
2018 | break; | |
2512b1b1 | 2019 | } |
29464ccc | 2020 | } else { |
8ac63448 | 2021 | pos = skip_ie(ies, ielen, pos); |
29464ccc JB |
2022 | } |
2023 | } | |
2024 | ||
2025 | return pos; | |
2026 | } | |
2027 | EXPORT_SYMBOL(ieee80211_ie_split_ric); | |
2028 | ||
5806ef25 BB |
2029 | void ieee80211_fragment_element(struct sk_buff *skb, u8 *len_pos, u8 frag_id) |
2030 | { | |
2031 | unsigned int elem_len; | |
2032 | ||
2033 | if (!len_pos) | |
2034 | return; | |
2035 | ||
2036 | elem_len = skb->data + skb->len - len_pos - 1; | |
2037 | ||
2038 | while (elem_len > 255) { | |
2039 | /* this one is 255 */ | |
2040 | *len_pos = 255; | |
2041 | /* remaining data gets smaller */ | |
2042 | elem_len -= 255; | |
2043 | /* make space for the fragment ID/len in SKB */ | |
2044 | skb_put(skb, 2); | |
2045 | /* shift back the remaining data to place fragment ID/len */ | |
2046 | memmove(len_pos + 255 + 3, len_pos + 255 + 1, elem_len); | |
2047 | /* place the fragment ID */ | |
2048 | len_pos += 255 + 1; | |
2049 | *len_pos = frag_id; | |
2050 | /* and point to fragment length to update later */ | |
2051 | len_pos++; | |
2052 | } | |
2053 | ||
2054 | *len_pos = elem_len; | |
2055 | } | |
2056 | EXPORT_SYMBOL(ieee80211_fragment_element); | |
2057 | ||
1ce3e82b | 2058 | bool ieee80211_operating_class_to_band(u8 operating_class, |
57fbcce3 | 2059 | enum nl80211_band *band) |
1ce3e82b JB |
2060 | { |
2061 | switch (operating_class) { | |
2062 | case 112: | |
2063 | case 115 ... 127: | |
954a86ef | 2064 | case 128 ... 130: |
57fbcce3 | 2065 | *band = NL80211_BAND_5GHZ; |
1ce3e82b | 2066 | return true; |
852f0462 | 2067 | case 131 ... 135: |
256caff2 | 2068 | case 137: |
852f0462 AS |
2069 | *band = NL80211_BAND_6GHZ; |
2070 | return true; | |
1ce3e82b JB |
2071 | case 81: |
2072 | case 82: | |
2073 | case 83: | |
2074 | case 84: | |
57fbcce3 | 2075 | *band = NL80211_BAND_2GHZ; |
1ce3e82b | 2076 | return true; |
55300a13 | 2077 | case 180: |
57fbcce3 | 2078 | *band = NL80211_BAND_60GHZ; |
55300a13 | 2079 | return true; |
1ce3e82b JB |
2080 | } |
2081 | ||
2082 | return false; | |
2083 | } | |
2084 | EXPORT_SYMBOL(ieee80211_operating_class_to_band); | |
2085 | ||
68de1302 MCL |
2086 | bool ieee80211_operating_class_to_chandef(u8 operating_class, |
2087 | struct ieee80211_channel *chan, | |
2088 | struct cfg80211_chan_def *chandef) | |
2089 | { | |
2090 | u32 control_freq, offset = 0; | |
2091 | enum nl80211_band band; | |
2092 | ||
2093 | if (!ieee80211_operating_class_to_band(operating_class, &band) || | |
2094 | !chan || band != chan->band) | |
2095 | return false; | |
2096 | ||
2097 | control_freq = chan->center_freq; | |
2098 | chandef->chan = chan; | |
2099 | ||
2100 | if (control_freq >= 5955) | |
2101 | offset = control_freq - 5955; | |
2102 | else if (control_freq >= 5745) | |
2103 | offset = control_freq - 5745; | |
2104 | else if (control_freq >= 5180) | |
2105 | offset = control_freq - 5180; | |
2106 | offset /= 20; | |
2107 | ||
2108 | switch (operating_class) { | |
2109 | case 81: /* 2 GHz band; 20 MHz; channels 1..13 */ | |
2110 | case 82: /* 2 GHz band; 20 MHz; channel 14 */ | |
2111 | case 115: /* 5 GHz band; 20 MHz; channels 36,40,44,48 */ | |
2112 | case 118: /* 5 GHz band; 20 MHz; channels 52,56,60,64 */ | |
2113 | case 121: /* 5 GHz band; 20 MHz; channels 100..144 */ | |
2114 | case 124: /* 5 GHz band; 20 MHz; channels 149,153,157,161 */ | |
2115 | case 125: /* 5 GHz band; 20 MHz; channels 149..177 */ | |
2116 | case 131: /* 6 GHz band; 20 MHz; channels 1..233*/ | |
2117 | case 136: /* 6 GHz band; 20 MHz; channel 2 */ | |
2118 | chandef->center_freq1 = control_freq; | |
2119 | chandef->width = NL80211_CHAN_WIDTH_20; | |
2120 | return true; | |
2121 | case 83: /* 2 GHz band; 40 MHz; channels 1..9 */ | |
2122 | case 116: /* 5 GHz band; 40 MHz; channels 36,44 */ | |
2123 | case 119: /* 5 GHz band; 40 MHz; channels 52,60 */ | |
2124 | case 122: /* 5 GHz band; 40 MHz; channels 100,108,116,124,132,140 */ | |
2125 | case 126: /* 5 GHz band; 40 MHz; channels 149,157,165,173 */ | |
2126 | chandef->center_freq1 = control_freq + 10; | |
2127 | chandef->width = NL80211_CHAN_WIDTH_40; | |
2128 | return true; | |
2129 | case 84: /* 2 GHz band; 40 MHz; channels 5..13 */ | |
2130 | case 117: /* 5 GHz band; 40 MHz; channels 40,48 */ | |
2131 | case 120: /* 5 GHz band; 40 MHz; channels 56,64 */ | |
2132 | case 123: /* 5 GHz band; 40 MHz; channels 104,112,120,128,136,144 */ | |
2133 | case 127: /* 5 GHz band; 40 MHz; channels 153,161,169,177 */ | |
2134 | chandef->center_freq1 = control_freq - 10; | |
2135 | chandef->width = NL80211_CHAN_WIDTH_40; | |
2136 | return true; | |
2137 | case 132: /* 6 GHz band; 40 MHz; channels 1,5,..,229*/ | |
2138 | chandef->center_freq1 = control_freq + 10 - (offset & 1) * 20; | |
2139 | chandef->width = NL80211_CHAN_WIDTH_40; | |
2140 | return true; | |
2141 | case 128: /* 5 GHz band; 80 MHz; channels 36..64,100..144,149..177 */ | |
2142 | case 133: /* 6 GHz band; 80 MHz; channels 1,5,..,229 */ | |
2143 | chandef->center_freq1 = control_freq + 30 - (offset & 3) * 20; | |
2144 | chandef->width = NL80211_CHAN_WIDTH_80; | |
2145 | return true; | |
2146 | case 129: /* 5 GHz band; 160 MHz; channels 36..64,100..144,149..177 */ | |
2147 | case 134: /* 6 GHz band; 160 MHz; channels 1,5,..,229 */ | |
2148 | chandef->center_freq1 = control_freq + 70 - (offset & 7) * 20; | |
2149 | chandef->width = NL80211_CHAN_WIDTH_160; | |
2150 | return true; | |
2151 | case 130: /* 5 GHz band; 80+80 MHz; channels 36..64,100..144,149..177 */ | |
2152 | case 135: /* 6 GHz band; 80+80 MHz; channels 1,5,..,229 */ | |
2153 | /* The center_freq2 of 80+80 MHz is unknown */ | |
2154 | case 137: /* 6 GHz band; 320 MHz; channels 1,5,..,229 */ | |
2155 | /* 320-1 or 320-2 channelization is unknown */ | |
2156 | default: | |
2157 | return false; | |
2158 | } | |
2159 | } | |
2160 | EXPORT_SYMBOL(ieee80211_operating_class_to_chandef); | |
2161 | ||
a38700dd AN |
2162 | bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef, |
2163 | u8 *op_class) | |
2164 | { | |
2165 | u8 vht_opclass; | |
8442938c | 2166 | u32 freq = chandef->center_freq1; |
a38700dd AN |
2167 | |
2168 | if (freq >= 2412 && freq <= 2472) { | |
2169 | if (chandef->width > NL80211_CHAN_WIDTH_40) | |
2170 | return false; | |
2171 | ||
2172 | /* 2.407 GHz, channels 1..13 */ | |
2173 | if (chandef->width == NL80211_CHAN_WIDTH_40) { | |
2174 | if (freq > chandef->chan->center_freq) | |
2175 | *op_class = 83; /* HT40+ */ | |
2176 | else | |
2177 | *op_class = 84; /* HT40- */ | |
2178 | } else { | |
2179 | *op_class = 81; | |
2180 | } | |
2181 | ||
2182 | return true; | |
2183 | } | |
2184 | ||
2185 | if (freq == 2484) { | |
ec649fed MH |
2186 | /* channel 14 is only for IEEE 802.11b */ |
2187 | if (chandef->width != NL80211_CHAN_WIDTH_20_NOHT) | |
a38700dd AN |
2188 | return false; |
2189 | ||
2190 | *op_class = 82; /* channel 14 */ | |
2191 | return true; | |
2192 | } | |
2193 | ||
2194 | switch (chandef->width) { | |
2195 | case NL80211_CHAN_WIDTH_80: | |
2196 | vht_opclass = 128; | |
2197 | break; | |
2198 | case NL80211_CHAN_WIDTH_160: | |
2199 | vht_opclass = 129; | |
2200 | break; | |
2201 | case NL80211_CHAN_WIDTH_80P80: | |
2202 | vht_opclass = 130; | |
2203 | break; | |
2204 | case NL80211_CHAN_WIDTH_10: | |
2205 | case NL80211_CHAN_WIDTH_5: | |
2206 | return false; /* unsupported for now */ | |
2207 | default: | |
2208 | vht_opclass = 0; | |
2209 | break; | |
2210 | } | |
2211 | ||
2212 | /* 5 GHz, channels 36..48 */ | |
2213 | if (freq >= 5180 && freq <= 5240) { | |
2214 | if (vht_opclass) { | |
2215 | *op_class = vht_opclass; | |
2216 | } else if (chandef->width == NL80211_CHAN_WIDTH_40) { | |
2217 | if (freq > chandef->chan->center_freq) | |
2218 | *op_class = 116; | |
2219 | else | |
2220 | *op_class = 117; | |
2221 | } else { | |
2222 | *op_class = 115; | |
2223 | } | |
2224 | ||
2225 | return true; | |
2226 | } | |
2227 | ||
2228 | /* 5 GHz, channels 52..64 */ | |
2229 | if (freq >= 5260 && freq <= 5320) { | |
2230 | if (vht_opclass) { | |
2231 | *op_class = vht_opclass; | |
2232 | } else if (chandef->width == NL80211_CHAN_WIDTH_40) { | |
2233 | if (freq > chandef->chan->center_freq) | |
2234 | *op_class = 119; | |
2235 | else | |
2236 | *op_class = 120; | |
2237 | } else { | |
2238 | *op_class = 118; | |
2239 | } | |
2240 | ||
2241 | return true; | |
2242 | } | |
2243 | ||
2244 | /* 5 GHz, channels 100..144 */ | |
2245 | if (freq >= 5500 && freq <= 5720) { | |
2246 | if (vht_opclass) { | |
2247 | *op_class = vht_opclass; | |
2248 | } else if (chandef->width == NL80211_CHAN_WIDTH_40) { | |
2249 | if (freq > chandef->chan->center_freq) | |
2250 | *op_class = 122; | |
2251 | else | |
2252 | *op_class = 123; | |
2253 | } else { | |
2254 | *op_class = 121; | |
2255 | } | |
2256 | ||
2257 | return true; | |
2258 | } | |
2259 | ||
2260 | /* 5 GHz, channels 149..169 */ | |
2261 | if (freq >= 5745 && freq <= 5845) { | |
2262 | if (vht_opclass) { | |
2263 | *op_class = vht_opclass; | |
2264 | } else if (chandef->width == NL80211_CHAN_WIDTH_40) { | |
2265 | if (freq > chandef->chan->center_freq) | |
2266 | *op_class = 126; | |
2267 | else | |
2268 | *op_class = 127; | |
2269 | } else if (freq <= 5805) { | |
2270 | *op_class = 124; | |
2271 | } else { | |
2272 | *op_class = 125; | |
2273 | } | |
2274 | ||
2275 | return true; | |
2276 | } | |
2277 | ||
2278 | /* 56.16 GHz, channel 1..4 */ | |
9cf0a0b4 | 2279 | if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 6) { |
a38700dd AN |
2280 | if (chandef->width >= NL80211_CHAN_WIDTH_40) |
2281 | return false; | |
2282 | ||
2283 | *op_class = 180; | |
2284 | return true; | |
2285 | } | |
2286 | ||
2287 | /* not supported yet */ | |
2288 | return false; | |
2289 | } | |
2290 | EXPORT_SYMBOL(ieee80211_chandef_to_operating_class); | |
2291 | ||
7b0a0e3c JB |
2292 | static int cfg80211_wdev_bi(struct wireless_dev *wdev) |
2293 | { | |
2294 | switch (wdev->iftype) { | |
2295 | case NL80211_IFTYPE_AP: | |
2296 | case NL80211_IFTYPE_P2P_GO: | |
2297 | WARN_ON(wdev->valid_links); | |
2298 | return wdev->links[0].ap.beacon_interval; | |
2299 | case NL80211_IFTYPE_MESH_POINT: | |
2300 | return wdev->u.mesh.beacon_interval; | |
2301 | case NL80211_IFTYPE_ADHOC: | |
2302 | return wdev->u.ibss.beacon_interval; | |
2303 | default: | |
2304 | break; | |
2305 | } | |
2306 | ||
2307 | return 0; | |
2308 | } | |
2309 | ||
4c8dea63 JB |
2310 | static void cfg80211_calculate_bi_data(struct wiphy *wiphy, u32 new_beacon_int, |
2311 | u32 *beacon_int_gcd, | |
abb4cfe3 FF |
2312 | bool *beacon_int_different, |
2313 | int radio_idx) | |
56d1893d | 2314 | { |
abb4cfe3 | 2315 | struct cfg80211_registered_device *rdev; |
56d1893d | 2316 | struct wireless_dev *wdev; |
56d1893d | 2317 | |
4c8dea63 JB |
2318 | *beacon_int_gcd = 0; |
2319 | *beacon_int_different = false; | |
56d1893d | 2320 | |
abb4cfe3 | 2321 | rdev = wiphy_to_rdev(wiphy); |
4c8dea63 | 2322 | list_for_each_entry(wdev, &wiphy->wdev_list, list) { |
7b0a0e3c JB |
2323 | int wdev_bi; |
2324 | ||
2325 | /* this feature isn't supported with MLO */ | |
2326 | if (wdev->valid_links) | |
2327 | continue; | |
2328 | ||
abb4cfe3 FF |
2329 | /* skip wdevs not active on the given wiphy radio */ |
2330 | if (radio_idx >= 0 && | |
2331 | !(rdev_get_radio_mask(rdev, wdev->netdev) & BIT(radio_idx))) | |
2332 | continue; | |
2333 | ||
7b0a0e3c JB |
2334 | wdev_bi = cfg80211_wdev_bi(wdev); |
2335 | ||
2336 | if (!wdev_bi) | |
56d1893d | 2337 | continue; |
0c317a02 | 2338 | |
4c8dea63 | 2339 | if (!*beacon_int_gcd) { |
7b0a0e3c | 2340 | *beacon_int_gcd = wdev_bi; |
0c317a02 | 2341 | continue; |
4c8dea63 | 2342 | } |
0c317a02 | 2343 | |
7b0a0e3c | 2344 | if (wdev_bi == *beacon_int_gcd) |
0c317a02 PK |
2345 | continue; |
2346 | ||
4c8dea63 | 2347 | *beacon_int_different = true; |
7b0a0e3c | 2348 | *beacon_int_gcd = gcd(*beacon_int_gcd, wdev_bi); |
4c8dea63 | 2349 | } |
0c317a02 | 2350 | |
4c8dea63 JB |
2351 | if (new_beacon_int && *beacon_int_gcd != new_beacon_int) { |
2352 | if (*beacon_int_gcd) | |
2353 | *beacon_int_different = true; | |
2354 | *beacon_int_gcd = gcd(*beacon_int_gcd, new_beacon_int); | |
56d1893d | 2355 | } |
4c8dea63 | 2356 | } |
56d1893d | 2357 | |
4c8dea63 JB |
2358 | int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev, |
2359 | enum nl80211_iftype iftype, u32 beacon_int) | |
2360 | { | |
2361 | /* | |
2362 | * This is just a basic pre-condition check; if interface combinations | |
2363 | * are possible the driver must already be checking those with a call | |
2364 | * to cfg80211_check_combinations(), in which case we'll validate more | |
2365 | * through the cfg80211_calculate_bi_data() call and code in | |
2366 | * cfg80211_iter_combinations(). | |
2367 | */ | |
2368 | ||
2369 | if (beacon_int < 10 || beacon_int > 10000) | |
2370 | return -EINVAL; | |
2371 | ||
2372 | return 0; | |
56d1893d | 2373 | } |
7527a782 | 2374 | |
65a124dd | 2375 | int cfg80211_iter_combinations(struct wiphy *wiphy, |
e227300c | 2376 | struct iface_combination_params *params, |
65a124dd MK |
2377 | void (*iter)(const struct ieee80211_iface_combination *c, |
2378 | void *data), | |
2379 | void *data) | |
cb2d956d | 2380 | { |
abb4cfe3 FF |
2381 | const struct wiphy_radio *radio = NULL; |
2382 | const struct ieee80211_iface_combination *c, *cs; | |
8c48b50a FF |
2383 | const struct ieee80211_regdomain *regdom; |
2384 | enum nl80211_dfs_regions region = 0; | |
abb4cfe3 | 2385 | int i, j, n, iftype; |
cb2d956d LC |
2386 | int num_interfaces = 0; |
2387 | u32 used_iftypes = 0; | |
4c8dea63 JB |
2388 | u32 beacon_int_gcd; |
2389 | bool beacon_int_different; | |
2390 | ||
abb4cfe3 FF |
2391 | if (params->radio_idx >= 0) |
2392 | radio = &wiphy->radio[params->radio_idx]; | |
2393 | ||
4c8dea63 JB |
2394 | /* |
2395 | * This is a bit strange, since the iteration used to rely only on | |
2396 | * the data given by the driver, but here it now relies on context, | |
2397 | * in form of the currently operating interfaces. | |
2398 | * This is OK for all current users, and saves us from having to | |
2399 | * push the GCD calculations into all the drivers. | |
2400 | * In the future, this should probably rely more on data that's in | |
2401 | * cfg80211 already - the only thing not would appear to be any new | |
2402 | * interfaces (while being brought up) and channel/radar data. | |
2403 | */ | |
2404 | cfg80211_calculate_bi_data(wiphy, params->new_beacon_int, | |
abb4cfe3 FF |
2405 | &beacon_int_gcd, &beacon_int_different, |
2406 | params->radio_idx); | |
cb2d956d | 2407 | |
e227300c | 2408 | if (params->radar_detect) { |
8c48b50a FF |
2409 | rcu_read_lock(); |
2410 | regdom = rcu_dereference(cfg80211_regdomain); | |
2411 | if (regdom) | |
2412 | region = regdom->dfs_region; | |
2413 | rcu_read_unlock(); | |
2414 | } | |
2415 | ||
cb2d956d | 2416 | for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) { |
e227300c PK |
2417 | num_interfaces += params->iftype_num[iftype]; |
2418 | if (params->iftype_num[iftype] > 0 && | |
e6f40511 | 2419 | !cfg80211_iftype_allowed(wiphy, iftype, 0, 1)) |
cb2d956d LC |
2420 | used_iftypes |= BIT(iftype); |
2421 | } | |
2422 | ||
abb4cfe3 FF |
2423 | if (radio) { |
2424 | cs = radio->iface_combinations; | |
2425 | n = radio->n_iface_combinations; | |
2426 | } else { | |
2427 | cs = wiphy->iface_combinations; | |
2428 | n = wiphy->n_iface_combinations; | |
2429 | } | |
2430 | for (i = 0; i < n; i++) { | |
cb2d956d LC |
2431 | struct ieee80211_iface_limit *limits; |
2432 | u32 all_iftypes = 0; | |
2433 | ||
abb4cfe3 | 2434 | c = &cs[i]; |
cb2d956d LC |
2435 | if (num_interfaces > c->max_interfaces) |
2436 | continue; | |
e227300c | 2437 | if (params->num_different_channels > c->num_different_channels) |
cb2d956d LC |
2438 | continue; |
2439 | ||
32bf7729 YJ |
2440 | limits = kmemdup_array(c->limits, c->n_limits, sizeof(*limits), |
2441 | GFP_KERNEL); | |
cb2d956d LC |
2442 | if (!limits) |
2443 | return -ENOMEM; | |
2444 | ||
2445 | for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) { | |
e6f40511 | 2446 | if (cfg80211_iftype_allowed(wiphy, iftype, 0, 1)) |
cb2d956d LC |
2447 | continue; |
2448 | for (j = 0; j < c->n_limits; j++) { | |
2449 | all_iftypes |= limits[j].types; | |
2450 | if (!(limits[j].types & BIT(iftype))) | |
2451 | continue; | |
e227300c | 2452 | if (limits[j].max < params->iftype_num[iftype]) |
cb2d956d | 2453 | goto cont; |
e227300c | 2454 | limits[j].max -= params->iftype_num[iftype]; |
cb2d956d LC |
2455 | } |
2456 | } | |
2457 | ||
e227300c PK |
2458 | if (params->radar_detect != |
2459 | (c->radar_detect_widths & params->radar_detect)) | |
cb2d956d LC |
2460 | goto cont; |
2461 | ||
e227300c | 2462 | if (params->radar_detect && c->radar_detect_regions && |
8c48b50a FF |
2463 | !(c->radar_detect_regions & BIT(region))) |
2464 | goto cont; | |
2465 | ||
cb2d956d LC |
2466 | /* Finally check that all iftypes that we're currently |
2467 | * using are actually part of this combination. If they | |
2468 | * aren't then we can't use this combination and have | |
2469 | * to continue to the next. | |
2470 | */ | |
2471 | if ((all_iftypes & used_iftypes) != used_iftypes) | |
2472 | goto cont; | |
2473 | ||
4c8dea63 | 2474 | if (beacon_int_gcd) { |
0c317a02 | 2475 | if (c->beacon_int_min_gcd && |
4c8dea63 | 2476 | beacon_int_gcd < c->beacon_int_min_gcd) |
0507a3ac | 2477 | goto cont; |
4c8dea63 | 2478 | if (!c->beacon_int_min_gcd && beacon_int_different) |
0c317a02 PK |
2479 | goto cont; |
2480 | } | |
2481 | ||
cb2d956d LC |
2482 | /* This combination covered all interface types and |
2483 | * supported the requested numbers, so we're good. | |
2484 | */ | |
65a124dd MK |
2485 | |
2486 | (*iter)(c, data); | |
cb2d956d LC |
2487 | cont: |
2488 | kfree(limits); | |
2489 | } | |
2490 | ||
65a124dd MK |
2491 | return 0; |
2492 | } | |
2493 | EXPORT_SYMBOL(cfg80211_iter_combinations); | |
2494 | ||
2495 | static void | |
2496 | cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination *c, | |
2497 | void *data) | |
2498 | { | |
2499 | int *num = data; | |
2500 | (*num)++; | |
2501 | } | |
2502 | ||
2503 | int cfg80211_check_combinations(struct wiphy *wiphy, | |
e227300c | 2504 | struct iface_combination_params *params) |
65a124dd MK |
2505 | { |
2506 | int err, num = 0; | |
2507 | ||
e227300c | 2508 | err = cfg80211_iter_combinations(wiphy, params, |
65a124dd MK |
2509 | cfg80211_iter_sum_ifcombs, &num); |
2510 | if (err) | |
2511 | return err; | |
2512 | if (num == 0) | |
2513 | return -EBUSY; | |
2514 | ||
2515 | return 0; | |
cb2d956d LC |
2516 | } |
2517 | EXPORT_SYMBOL(cfg80211_check_combinations); | |
2518 | ||
34850ab2 JB |
2519 | int ieee80211_get_ratemask(struct ieee80211_supported_band *sband, |
2520 | const u8 *rates, unsigned int n_rates, | |
2521 | u32 *mask) | |
2522 | { | |
2523 | int i, j; | |
2524 | ||
a401d2bb JB |
2525 | if (!sband) |
2526 | return -EINVAL; | |
2527 | ||
34850ab2 JB |
2528 | if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES) |
2529 | return -EINVAL; | |
2530 | ||
2531 | *mask = 0; | |
2532 | ||
2533 | for (i = 0; i < n_rates; i++) { | |
2534 | int rate = (rates[i] & 0x7f) * 5; | |
2535 | bool found = false; | |
2536 | ||
2537 | for (j = 0; j < sband->n_bitrates; j++) { | |
2538 | if (sband->bitrates[j].bitrate == rate) { | |
2539 | found = true; | |
2540 | *mask |= BIT(j); | |
2541 | break; | |
2542 | } | |
2543 | } | |
2544 | if (!found) | |
2545 | return -EINVAL; | |
2546 | } | |
2547 | ||
2548 | /* | |
2549 | * mask must have at least one bit set here since we | |
2550 | * didn't accept a 0-length rates array nor allowed | |
2551 | * entries in the array that didn't exist | |
2552 | */ | |
2553 | ||
2554 | return 0; | |
2555 | } | |
11a2a357 | 2556 | |
bdfbec2d IP |
2557 | unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy) |
2558 | { | |
57fbcce3 | 2559 | enum nl80211_band band; |
bdfbec2d IP |
2560 | unsigned int n_channels = 0; |
2561 | ||
57fbcce3 | 2562 | for (band = 0; band < NUM_NL80211_BANDS; band++) |
bdfbec2d IP |
2563 | if (wiphy->bands[band]) |
2564 | n_channels += wiphy->bands[band]->n_channels; | |
2565 | ||
2566 | return n_channels; | |
2567 | } | |
2568 | EXPORT_SYMBOL(ieee80211_get_num_supported_channels); | |
2569 | ||
7406353d AQ |
2570 | int cfg80211_get_station(struct net_device *dev, const u8 *mac_addr, |
2571 | struct station_info *sinfo) | |
2572 | { | |
2573 | struct cfg80211_registered_device *rdev; | |
2574 | struct wireless_dev *wdev; | |
2575 | ||
2576 | wdev = dev->ieee80211_ptr; | |
2577 | if (!wdev) | |
2578 | return -EOPNOTSUPP; | |
2579 | ||
2580 | rdev = wiphy_to_rdev(wdev->wiphy); | |
2581 | if (!rdev->ops->get_station) | |
2582 | return -EOPNOTSUPP; | |
2583 | ||
3c12d048 SE |
2584 | memset(sinfo, 0, sizeof(*sinfo)); |
2585 | ||
f42d22d3 | 2586 | guard(wiphy)(&rdev->wiphy); |
642f89da | 2587 | |
f42d22d3 | 2588 | return rdev_get_station(rdev, dev, mac_addr, sinfo); |
7406353d AQ |
2589 | } |
2590 | EXPORT_SYMBOL(cfg80211_get_station); | |
2591 | ||
a442b761 AB |
2592 | void cfg80211_free_nan_func(struct cfg80211_nan_func *f) |
2593 | { | |
2594 | int i; | |
2595 | ||
2596 | if (!f) | |
2597 | return; | |
2598 | ||
2599 | kfree(f->serv_spec_info); | |
2600 | kfree(f->srf_bf); | |
2601 | kfree(f->srf_macs); | |
2602 | for (i = 0; i < f->num_rx_filters; i++) | |
2603 | kfree(f->rx_filters[i].filter); | |
2604 | ||
2605 | for (i = 0; i < f->num_tx_filters; i++) | |
2606 | kfree(f->tx_filters[i].filter); | |
2607 | ||
2608 | kfree(f->rx_filters); | |
2609 | kfree(f->tx_filters); | |
2610 | kfree(f); | |
2611 | } | |
2612 | EXPORT_SYMBOL(cfg80211_free_nan_func); | |
2613 | ||
4787cfa0 RM |
2614 | bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range, |
2615 | u32 center_freq_khz, u32 bw_khz) | |
2616 | { | |
2617 | u32 start_freq_khz, end_freq_khz; | |
2618 | ||
2619 | start_freq_khz = center_freq_khz - (bw_khz / 2); | |
2620 | end_freq_khz = center_freq_khz + (bw_khz / 2); | |
2621 | ||
2622 | if (start_freq_khz >= freq_range->start_freq_khz && | |
2623 | end_freq_khz <= freq_range->end_freq_khz) | |
2624 | return true; | |
2625 | ||
2626 | return false; | |
2627 | } | |
2628 | ||
8689c051 AS |
2629 | int cfg80211_sinfo_alloc_tid_stats(struct station_info *sinfo, gfp_t gfp) |
2630 | { | |
1d211d43 JB |
2631 | sinfo->pertid = kcalloc(IEEE80211_NUM_TIDS + 1, |
2632 | sizeof(*(sinfo->pertid)), | |
2633 | gfp); | |
8689c051 AS |
2634 | if (!sinfo->pertid) |
2635 | return -ENOMEM; | |
2636 | ||
2637 | return 0; | |
2638 | } | |
2639 | EXPORT_SYMBOL(cfg80211_sinfo_alloc_tid_stats); | |
2640 | ||
11a2a357 JB |
2641 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
2642 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ | |
2643 | const unsigned char rfc1042_header[] __aligned(2) = | |
2644 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
2645 | EXPORT_SYMBOL(rfc1042_header); | |
2646 | ||
2647 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ | |
2648 | const unsigned char bridge_tunnel_header[] __aligned(2) = | |
2649 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; | |
2650 | EXPORT_SYMBOL(bridge_tunnel_header); | |
30ca1aa5 DL |
2651 | |
2652 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ | |
2653 | struct iapp_layer2_update { | |
2654 | u8 da[ETH_ALEN]; /* broadcast */ | |
2655 | u8 sa[ETH_ALEN]; /* STA addr */ | |
2656 | __be16 len; /* 6 */ | |
2657 | u8 dsap; /* 0 */ | |
2658 | u8 ssap; /* 0 */ | |
2659 | u8 control; | |
2660 | u8 xid_info[3]; | |
2661 | } __packed; | |
2662 | ||
2663 | void cfg80211_send_layer2_update(struct net_device *dev, const u8 *addr) | |
2664 | { | |
2665 | struct iapp_layer2_update *msg; | |
2666 | struct sk_buff *skb; | |
2667 | ||
2668 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 | |
2669 | * bridge devices */ | |
2670 | ||
2671 | skb = dev_alloc_skb(sizeof(*msg)); | |
2672 | if (!skb) | |
2673 | return; | |
2674 | msg = skb_put(skb, sizeof(*msg)); | |
2675 | ||
2676 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) | |
2677 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ | |
2678 | ||
2679 | eth_broadcast_addr(msg->da); | |
2680 | ether_addr_copy(msg->sa, addr); | |
2681 | msg->len = htons(6); | |
2682 | msg->dsap = 0; | |
2683 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ | |
2684 | msg->control = 0xaf; /* XID response lsb.1111F101. | |
2685 | * F=0 (no poll command; unsolicited frame) */ | |
2686 | msg->xid_info[0] = 0x81; /* XID format identifier */ | |
2687 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ | |
2688 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ | |
2689 | ||
2690 | skb->dev = dev; | |
2691 | skb->protocol = eth_type_trans(skb, dev); | |
2692 | memset(skb->cb, 0, sizeof(skb->cb)); | |
f9834dbd | 2693 | netif_rx(skb); |
30ca1aa5 DL |
2694 | } |
2695 | EXPORT_SYMBOL(cfg80211_send_layer2_update); | |
b0aa75f0 JB |
2696 | |
2697 | int ieee80211_get_vht_max_nss(struct ieee80211_vht_cap *cap, | |
2698 | enum ieee80211_vht_chanwidth bw, | |
9166cc49 JB |
2699 | int mcs, bool ext_nss_bw_capable, |
2700 | unsigned int max_vht_nss) | |
b0aa75f0 JB |
2701 | { |
2702 | u16 map = le16_to_cpu(cap->supp_mcs.rx_mcs_map); | |
b0aa75f0 JB |
2703 | int ext_nss_bw; |
2704 | int supp_width; | |
2705 | int i, mcs_encoding; | |
2706 | ||
2707 | if (map == 0xffff) | |
2708 | return 0; | |
2709 | ||
9166cc49 | 2710 | if (WARN_ON(mcs > 9 || max_vht_nss > 8)) |
b0aa75f0 JB |
2711 | return 0; |
2712 | if (mcs <= 7) | |
2713 | mcs_encoding = 0; | |
2714 | else if (mcs == 8) | |
2715 | mcs_encoding = 1; | |
2716 | else | |
2717 | mcs_encoding = 2; | |
2718 | ||
9166cc49 JB |
2719 | if (!max_vht_nss) { |
2720 | /* find max_vht_nss for the given MCS */ | |
2721 | for (i = 7; i >= 0; i--) { | |
2722 | int supp = (map >> (2 * i)) & 3; | |
b0aa75f0 | 2723 | |
9166cc49 JB |
2724 | if (supp == 3) |
2725 | continue; | |
b0aa75f0 | 2726 | |
9166cc49 JB |
2727 | if (supp >= mcs_encoding) { |
2728 | max_vht_nss = i + 1; | |
2729 | break; | |
2730 | } | |
b0aa75f0 JB |
2731 | } |
2732 | } | |
2733 | ||
2734 | if (!(cap->supp_mcs.tx_mcs_map & | |
2735 | cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE))) | |
2736 | return max_vht_nss; | |
2737 | ||
2738 | ext_nss_bw = le32_get_bits(cap->vht_cap_info, | |
2739 | IEEE80211_VHT_CAP_EXT_NSS_BW_MASK); | |
2740 | supp_width = le32_get_bits(cap->vht_cap_info, | |
2741 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK); | |
2742 | ||
2743 | /* if not capable, treat ext_nss_bw as 0 */ | |
2744 | if (!ext_nss_bw_capable) | |
2745 | ext_nss_bw = 0; | |
2746 | ||
2747 | /* This is invalid */ | |
2748 | if (supp_width == 3) | |
2749 | return 0; | |
2750 | ||
2751 | /* This is an invalid combination so pretend nothing is supported */ | |
2752 | if (supp_width == 2 && (ext_nss_bw == 1 || ext_nss_bw == 2)) | |
2753 | return 0; | |
2754 | ||
2755 | /* | |
2756 | * Cover all the special cases according to IEEE 802.11-2016 | |
2757 | * Table 9-250. All other cases are either factor of 1 or not | |
2758 | * valid/supported. | |
2759 | */ | |
2760 | switch (bw) { | |
2761 | case IEEE80211_VHT_CHANWIDTH_USE_HT: | |
2762 | case IEEE80211_VHT_CHANWIDTH_80MHZ: | |
2763 | if ((supp_width == 1 || supp_width == 2) && | |
2764 | ext_nss_bw == 3) | |
2765 | return 2 * max_vht_nss; | |
2766 | break; | |
2767 | case IEEE80211_VHT_CHANWIDTH_160MHZ: | |
2768 | if (supp_width == 0 && | |
2769 | (ext_nss_bw == 1 || ext_nss_bw == 2)) | |
93bc8ac4 | 2770 | return max_vht_nss / 2; |
b0aa75f0 JB |
2771 | if (supp_width == 0 && |
2772 | ext_nss_bw == 3) | |
93bc8ac4 | 2773 | return (3 * max_vht_nss) / 4; |
b0aa75f0 JB |
2774 | if (supp_width == 1 && |
2775 | ext_nss_bw == 3) | |
2776 | return 2 * max_vht_nss; | |
2777 | break; | |
2778 | case IEEE80211_VHT_CHANWIDTH_80P80MHZ: | |
93bc8ac4 | 2779 | if (supp_width == 0 && ext_nss_bw == 1) |
b0aa75f0 JB |
2780 | return 0; /* not possible */ |
2781 | if (supp_width == 0 && | |
2782 | ext_nss_bw == 2) | |
93bc8ac4 | 2783 | return max_vht_nss / 2; |
b0aa75f0 JB |
2784 | if (supp_width == 0 && |
2785 | ext_nss_bw == 3) | |
93bc8ac4 | 2786 | return (3 * max_vht_nss) / 4; |
b0aa75f0 JB |
2787 | if (supp_width == 1 && |
2788 | ext_nss_bw == 0) | |
2789 | return 0; /* not possible */ | |
2790 | if (supp_width == 1 && | |
2791 | ext_nss_bw == 1) | |
93bc8ac4 | 2792 | return max_vht_nss / 2; |
b0aa75f0 JB |
2793 | if (supp_width == 1 && |
2794 | ext_nss_bw == 2) | |
93bc8ac4 | 2795 | return (3 * max_vht_nss) / 4; |
b0aa75f0 JB |
2796 | break; |
2797 | } | |
2798 | ||
2799 | /* not covered or invalid combination received */ | |
2800 | return max_vht_nss; | |
2801 | } | |
2802 | EXPORT_SYMBOL(ieee80211_get_vht_max_nss); | |
e6f40511 MP |
2803 | |
2804 | bool cfg80211_iftype_allowed(struct wiphy *wiphy, enum nl80211_iftype iftype, | |
2805 | bool is_4addr, u8 check_swif) | |
2806 | ||
2807 | { | |
2808 | bool is_vlan = iftype == NL80211_IFTYPE_AP_VLAN; | |
2809 | ||
2810 | switch (check_swif) { | |
2811 | case 0: | |
2812 | if (is_vlan && is_4addr) | |
2813 | return wiphy->flags & WIPHY_FLAG_4ADDR_AP; | |
2814 | return wiphy->interface_modes & BIT(iftype); | |
2815 | case 1: | |
2816 | if (!(wiphy->software_iftypes & BIT(iftype)) && is_vlan) | |
2817 | return wiphy->flags & WIPHY_FLAG_4ADDR_AP; | |
2818 | return wiphy->software_iftypes & BIT(iftype); | |
2819 | default: | |
2820 | break; | |
2821 | } | |
2822 | ||
2823 | return false; | |
2824 | } | |
2825 | EXPORT_SYMBOL(cfg80211_iftype_allowed); | |
cdf0a0a8 JB |
2826 | |
2827 | void cfg80211_remove_link(struct wireless_dev *wdev, unsigned int link_id) | |
2828 | { | |
2829 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
2830 | ||
076fc877 | 2831 | lockdep_assert_wiphy(wdev->wiphy); |
cdf0a0a8 JB |
2832 | |
2833 | switch (wdev->iftype) { | |
2834 | case NL80211_IFTYPE_AP: | |
2835 | case NL80211_IFTYPE_P2P_GO: | |
076fc877 | 2836 | cfg80211_stop_ap(rdev, wdev->netdev, link_id, true); |
cdf0a0a8 JB |
2837 | break; |
2838 | default: | |
2839 | /* per-link not relevant */ | |
2840 | break; | |
2841 | } | |
2842 | ||
cdf0a0a8 JB |
2843 | rdev_del_intf_link(rdev, wdev, link_id); |
2844 | ||
b5c32ff6 | 2845 | wdev->valid_links &= ~BIT(link_id); |
cdf0a0a8 JB |
2846 | eth_zero_addr(wdev->links[link_id].addr); |
2847 | } | |
2848 | ||
2849 | void cfg80211_remove_links(struct wireless_dev *wdev) | |
2850 | { | |
2851 | unsigned int link_id; | |
2852 | ||
34d4e3eb JB |
2853 | /* |
2854 | * links are controlled by upper layers (userspace/cfg) | |
2855 | * only for AP mode, so only remove them here for AP | |
2856 | */ | |
2857 | if (wdev->iftype != NL80211_IFTYPE_AP) | |
2858 | return; | |
2859 | ||
cdf0a0a8 JB |
2860 | if (wdev->valid_links) { |
2861 | for_each_valid_link(wdev, link_id) | |
2862 | cfg80211_remove_link(wdev, link_id); | |
2863 | } | |
cdf0a0a8 JB |
2864 | } |
2865 | ||
2866 | int cfg80211_remove_virtual_intf(struct cfg80211_registered_device *rdev, | |
2867 | struct wireless_dev *wdev) | |
2868 | { | |
2869 | cfg80211_remove_links(wdev); | |
2870 | ||
2871 | return rdev_del_virtual_intf(rdev, wdev); | |
2872 | } | |
7464f665 JB |
2873 | |
2874 | const struct wiphy_iftype_ext_capab * | |
2875 | cfg80211_get_iftype_ext_capa(struct wiphy *wiphy, enum nl80211_iftype type) | |
2876 | { | |
2877 | int i; | |
2878 | ||
2879 | for (i = 0; i < wiphy->num_iftype_ext_capab; i++) { | |
2880 | if (wiphy->iftype_ext_capab[i].iftype == type) | |
2881 | return &wiphy->iftype_ext_capab[i]; | |
2882 | } | |
2883 | ||
2884 | return NULL; | |
2885 | } | |
2886 | EXPORT_SYMBOL(cfg80211_get_iftype_ext_capa); | |
510dba80 FF |
2887 | |
2888 | static bool | |
2889 | ieee80211_radio_freq_range_valid(const struct wiphy_radio *radio, | |
2890 | u32 freq, u32 width) | |
2891 | { | |
2892 | const struct wiphy_radio_freq_range *r; | |
2893 | int i; | |
2894 | ||
2895 | for (i = 0; i < radio->n_freq_range; i++) { | |
2896 | r = &radio->freq_range[i]; | |
2897 | if (freq - width / 2 >= r->start_freq && | |
2898 | freq + width / 2 <= r->end_freq) | |
2899 | return true; | |
2900 | } | |
2901 | ||
2902 | return false; | |
2903 | } | |
2904 | ||
2905 | bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio, | |
2906 | const struct cfg80211_chan_def *chandef) | |
2907 | { | |
2908 | u32 freq, width; | |
2909 | ||
2910 | freq = ieee80211_chandef_to_khz(chandef); | |
b5c16227 | 2911 | width = cfg80211_chandef_get_width(chandef); |
510dba80 FF |
2912 | if (!ieee80211_radio_freq_range_valid(radio, freq, width)) |
2913 | return false; | |
2914 | ||
2915 | freq = MHZ_TO_KHZ(chandef->center_freq2); | |
2916 | if (freq && !ieee80211_radio_freq_range_valid(radio, freq, width)) | |
2917 | return false; | |
2918 | ||
2919 | return true; | |
2920 | } | |
2921 | EXPORT_SYMBOL(cfg80211_radio_chandef_valid); | |
3607798a FF |
2922 | |
2923 | bool cfg80211_wdev_channel_allowed(struct wireless_dev *wdev, | |
2924 | struct ieee80211_channel *chan) | |
2925 | { | |
2926 | struct wiphy *wiphy = wdev->wiphy; | |
2927 | const struct wiphy_radio *radio; | |
2928 | struct cfg80211_chan_def chandef; | |
2929 | u32 radio_mask; | |
2930 | int i; | |
2931 | ||
2932 | radio_mask = wdev->radio_mask; | |
2933 | if (!wiphy->n_radio || radio_mask == BIT(wiphy->n_radio) - 1) | |
2934 | return true; | |
2935 | ||
2936 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20); | |
2937 | for (i = 0; i < wiphy->n_radio; i++) { | |
2938 | if (!(radio_mask & BIT(i))) | |
2939 | continue; | |
2940 | ||
2941 | radio = &wiphy->radio[i]; | |
2942 | if (!cfg80211_radio_chandef_valid(radio, &chandef)) | |
2943 | continue; | |
2944 | ||
2945 | return true; | |
2946 | } | |
2947 | ||
2948 | return false; | |
2949 | } | |
2950 | EXPORT_SYMBOL(cfg80211_wdev_channel_allowed); |