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