Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Operating classes |
| 3 | * Copyright(c) 2015 Intel Deutschland GmbH |
| 4 | * Contact Information: |
| 5 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 6 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 7 | * |
| 8 | * This software may be distributed under the terms of the BSD license. |
| 9 | * See README for more details. |
| 10 | */ |
| 11 | |
| 12 | #include "utils/includes.h" |
| 13 | |
| 14 | #include "utils/common.h" |
| 15 | #include "common/ieee802_11_common.h" |
| 16 | #include "wpa_supplicant_i.h" |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 17 | #include "bss.h" |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 18 | |
| 19 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 20 | static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode, |
| 21 | u8 op_class, u8 chan, |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 22 | unsigned int *flags) |
| 23 | { |
| 24 | int i; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 25 | bool is_6ghz = op_class >= 131 && op_class <= 136; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 26 | |
| 27 | for (i = 0; i < mode->num_channels; i++) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 28 | bool chan_is_6ghz; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 29 | |
Kai Shi | c174534 | 2020-09-09 11:31:57 -0700 | [diff] [blame] | 30 | chan_is_6ghz = mode->channels[i].freq >= 5935 && |
| 31 | mode->channels[i].freq <= 7115; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 32 | if (is_6ghz == chan_is_6ghz && mode->channels[i].chan == chan) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 33 | break; |
| 34 | } |
| 35 | |
| 36 | if (i == mode->num_channels || |
| 37 | (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)) |
| 38 | return NOT_ALLOWED; |
| 39 | |
| 40 | if (flags) |
| 41 | *flags = mode->channels[i].flag; |
| 42 | |
| 43 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) |
| 44 | return NO_IR; |
| 45 | |
| 46 | return ALLOWED; |
| 47 | } |
| 48 | |
| 49 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 50 | static int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel, |
| 51 | const u8 *center_channels, size_t num_chan) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 52 | { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 53 | size_t i; |
| 54 | |
| 55 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 56 | return 0; |
| 57 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 58 | for (i = 0; i < num_chan; i++) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 59 | /* |
| 60 | * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48), |
| 61 | * so the center channel is 6 channels away from the start/end. |
| 62 | */ |
| 63 | if (channel >= center_channels[i] - 6 && |
| 64 | channel <= center_channels[i] + 6) |
| 65 | return center_channels[i]; |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 72 | static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode, |
| 73 | u8 op_class, u8 channel) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 74 | { |
| 75 | u8 center_chan; |
| 76 | unsigned int i; |
| 77 | unsigned int no_ir = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 78 | const u8 *center_channels; |
| 79 | size_t num_chan; |
| 80 | const u8 center_channels_5ghz[] = { 42, 58, 106, 122, 138, 155, 171 }; |
| 81 | const u8 center_channels_6ghz[] = { 7, 23, 39, 55, 71, 87, 103, 119, |
| 82 | 135, 151, 167, 183, 199, 215 }; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 83 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 84 | if (is_6ghz_op_class(op_class)) { |
| 85 | center_channels = center_channels_6ghz; |
| 86 | num_chan = ARRAY_SIZE(center_channels_6ghz); |
| 87 | } else { |
| 88 | center_channels = center_channels_5ghz; |
| 89 | num_chan = ARRAY_SIZE(center_channels_5ghz); |
| 90 | } |
| 91 | |
| 92 | center_chan = get_center_80mhz(mode, channel, center_channels, |
| 93 | num_chan); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 94 | if (!center_chan) |
| 95 | return NOT_ALLOWED; |
| 96 | |
| 97 | /* check all the channels are available */ |
| 98 | for (i = 0; i < 4; i++) { |
| 99 | unsigned int flags; |
| 100 | u8 adj_chan = center_chan - 6 + i * 4; |
| 101 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 102 | if (allow_channel(mode, op_class, adj_chan, &flags) == |
| 103 | NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 104 | return NOT_ALLOWED; |
| 105 | |
| 106 | if ((i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70)) || |
| 107 | (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50)) || |
| 108 | (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30)) || |
| 109 | (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10))) |
| 110 | return NOT_ALLOWED; |
| 111 | |
| 112 | if (flags & HOSTAPD_CHAN_NO_IR) |
| 113 | no_ir = 1; |
| 114 | } |
| 115 | |
| 116 | if (no_ir) |
| 117 | return NO_IR; |
| 118 | |
| 119 | return ALLOWED; |
| 120 | } |
| 121 | |
| 122 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 123 | static int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel, |
| 124 | const u8 *center_channels, size_t num_chan) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 125 | { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 126 | unsigned int i; |
| 127 | |
| 128 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 129 | return 0; |
| 130 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 131 | for (i = 0; i < num_chan; i++) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 132 | /* |
| 133 | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), |
| 134 | * so the center channel is 14 channels away from the start/end. |
| 135 | */ |
| 136 | if (channel >= center_channels[i] - 14 && |
| 137 | channel <= center_channels[i] + 14) |
| 138 | return center_channels[i]; |
| 139 | } |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 146 | u8 op_class, u8 channel) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 147 | { |
| 148 | u8 center_chan; |
| 149 | unsigned int i; |
| 150 | unsigned int no_ir = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 151 | const u8 *center_channels; |
| 152 | size_t num_chan; |
| 153 | const u8 center_channels_5ghz[] = { 50, 114, 163 }; |
| 154 | const u8 center_channels_6ghz[] = { 15, 47, 79, 111, 143, 175, 207 }; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 155 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 156 | if (is_6ghz_op_class(op_class)) { |
| 157 | center_channels = center_channels_6ghz; |
| 158 | num_chan = ARRAY_SIZE(center_channels_6ghz); |
| 159 | } else { |
| 160 | center_channels = center_channels_5ghz; |
| 161 | num_chan = ARRAY_SIZE(center_channels_5ghz); |
| 162 | } |
| 163 | |
| 164 | center_chan = get_center_160mhz(mode, channel, center_channels, |
| 165 | num_chan); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 166 | if (!center_chan) |
| 167 | return NOT_ALLOWED; |
| 168 | |
| 169 | /* Check all the channels are available */ |
| 170 | for (i = 0; i < 8; i++) { |
| 171 | unsigned int flags; |
| 172 | u8 adj_chan = center_chan - 14 + i * 4; |
| 173 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 174 | if (allow_channel(mode, op_class, adj_chan, &flags) == |
| 175 | NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 176 | return NOT_ALLOWED; |
| 177 | |
| 178 | if ((i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_150)) || |
| 179 | (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_130)) || |
| 180 | (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_110)) || |
| 181 | (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_90)) || |
| 182 | (i == 4 && !(flags & HOSTAPD_CHAN_VHT_90_70)) || |
| 183 | (i == 5 && !(flags & HOSTAPD_CHAN_VHT_110_50)) || |
| 184 | (i == 6 && !(flags & HOSTAPD_CHAN_VHT_130_30)) || |
| 185 | (i == 7 && !(flags & HOSTAPD_CHAN_VHT_150_10))) |
| 186 | return NOT_ALLOWED; |
| 187 | |
| 188 | if (flags & HOSTAPD_CHAN_NO_IR) |
| 189 | no_ir = 1; |
| 190 | } |
| 191 | |
| 192 | if (no_ir) |
| 193 | return NO_IR; |
| 194 | |
| 195 | return ALLOWED; |
| 196 | } |
| 197 | |
| 198 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 199 | enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 op_class, |
| 200 | u8 channel, u8 bw) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 201 | { |
| 202 | unsigned int flag = 0; |
| 203 | enum chan_allowed res, res2; |
| 204 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 205 | res2 = res = allow_channel(mode, op_class, channel, &flag); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 206 | if (bw == BW40MINUS || (bw == BW40 && (((channel - 1) / 4) % 2))) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 207 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) |
| 208 | return NOT_ALLOWED; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 209 | res2 = allow_channel(mode, op_class, channel - 4, NULL); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 210 | } else if (bw == BW40PLUS || |
| 211 | (bw == BW40 && !(((channel - 1) / 4) % 2))) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 212 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
| 213 | return NOT_ALLOWED; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 214 | res2 = allow_channel(mode, op_class, channel + 4, NULL); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 215 | } else if (bw == BW80) { |
| 216 | /* |
| 217 | * channel is a center channel and as such, not necessarily a |
| 218 | * valid 20 MHz channels. Override earlier allow_channel() |
| 219 | * result and use only the 80 MHz specific version. |
| 220 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 221 | res2 = res = verify_80mhz(mode, op_class, channel); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 222 | } else if (bw == BW160) { |
| 223 | /* |
| 224 | * channel is a center channel and as such, not necessarily a |
| 225 | * valid 20 MHz channels. Override earlier allow_channel() |
| 226 | * result and use only the 160 MHz specific version. |
| 227 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 228 | res2 = res = verify_160mhz(mode, op_class, channel); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 229 | } else if (bw == BW80P80) { |
| 230 | /* |
| 231 | * channel is a center channel and as such, not necessarily a |
| 232 | * valid 20 MHz channels. Override earlier allow_channel() |
| 233 | * result and use only the 80 MHz specific version. |
| 234 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 235 | res2 = res = verify_80mhz(mode, op_class, channel); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
| 239 | return NOT_ALLOWED; |
| 240 | |
| 241 | if (res == NO_IR || res2 == NO_IR) |
| 242 | return NO_IR; |
| 243 | |
| 244 | return ALLOWED; |
| 245 | } |
| 246 | |
| 247 | |
| 248 | static int wpas_op_class_supported(struct wpa_supplicant *wpa_s, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 249 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 250 | const struct oper_class_map *op_class) |
| 251 | { |
| 252 | int chan; |
| 253 | size_t i; |
| 254 | struct hostapd_hw_modes *mode; |
| 255 | int found; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 256 | int z; |
| 257 | int freq2 = 0; |
| 258 | int freq5 = 0; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 259 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 260 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, op_class->mode, |
| 261 | is_6ghz_op_class(op_class->op_class)); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 262 | if (!mode) |
| 263 | return 0; |
| 264 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 265 | /* If we are configured to disable certain things, take that into |
| 266 | * account here. */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 267 | if (ssid && ssid->freq_list && ssid->freq_list[0]) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 268 | for (z = 0; ; z++) { |
| 269 | int f = ssid->freq_list[z]; |
| 270 | |
| 271 | if (f == 0) |
| 272 | break; /* end of list */ |
| 273 | if (f > 4000 && f < 6000) |
| 274 | freq5 = 1; |
| 275 | else if (f > 2400 && f < 2500) |
| 276 | freq2 = 1; |
| 277 | } |
| 278 | } else { |
| 279 | /* No frequencies specified, can use anything hardware supports. |
| 280 | */ |
| 281 | freq2 = freq5 = 1; |
| 282 | } |
| 283 | |
| 284 | if (op_class->op_class >= 115 && op_class->op_class <= 130 && !freq5) |
| 285 | return 0; |
| 286 | if (op_class->op_class >= 81 && op_class->op_class <= 84 && !freq2) |
| 287 | return 0; |
| 288 | |
| 289 | #ifdef CONFIG_HT_OVERRIDES |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 290 | if (ssid && ssid->disable_ht) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 291 | switch (op_class->op_class) { |
| 292 | case 83: |
| 293 | case 84: |
| 294 | case 104: |
| 295 | case 105: |
| 296 | case 116: |
| 297 | case 117: |
| 298 | case 119: |
| 299 | case 120: |
| 300 | case 122: |
| 301 | case 123: |
| 302 | case 126: |
| 303 | case 127: |
| 304 | case 128: |
| 305 | case 129: |
| 306 | case 130: |
| 307 | /* Disable >= 40 MHz channels if HT is disabled */ |
| 308 | return 0; |
| 309 | } |
| 310 | } |
| 311 | #endif /* CONFIG_HT_OVERRIDES */ |
| 312 | |
| 313 | #ifdef CONFIG_VHT_OVERRIDES |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 314 | if (ssid && ssid->disable_vht) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 315 | if (op_class->op_class >= 128 && op_class->op_class <= 130) { |
| 316 | /* Disable >= 80 MHz channels if VHT is disabled */ |
| 317 | return 0; |
| 318 | } |
| 319 | } |
| 320 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 321 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 322 | if (op_class->op_class == 128) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 323 | u8 channels[] = { 42, 58, 106, 122, 138, 155, 171 }; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 324 | |
| 325 | for (i = 0; i < ARRAY_SIZE(channels); i++) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 326 | if (verify_channel(mode, op_class->op_class, |
| 327 | channels[i], op_class->bw) != |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 328 | NOT_ALLOWED) |
| 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | if (op_class->op_class == 129) { |
| 336 | /* Check if either 160 MHz channels is allowed */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 337 | return verify_channel(mode, op_class->op_class, 50, |
| 338 | op_class->bw) != NOT_ALLOWED || |
| 339 | verify_channel(mode, op_class->op_class, 114, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 340 | op_class->bw) != NOT_ALLOWED || |
| 341 | verify_channel(mode, op_class->op_class, 163, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 342 | op_class->bw) != NOT_ALLOWED; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | if (op_class->op_class == 130) { |
| 346 | /* Need at least two non-contiguous 80 MHz segments */ |
| 347 | found = 0; |
| 348 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 349 | if (verify_channel(mode, op_class->op_class, 42, |
| 350 | op_class->bw) != NOT_ALLOWED || |
| 351 | verify_channel(mode, op_class->op_class, 58, |
| 352 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 353 | found++; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 354 | if (verify_channel(mode, op_class->op_class, 106, |
| 355 | op_class->bw) != NOT_ALLOWED || |
| 356 | verify_channel(mode, op_class->op_class, 122, |
| 357 | op_class->bw) != NOT_ALLOWED || |
| 358 | verify_channel(mode, op_class->op_class, 138, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 359 | op_class->bw) != NOT_ALLOWED || |
| 360 | verify_channel(mode, op_class->op_class, 155, |
| 361 | op_class->bw) != NOT_ALLOWED || |
| 362 | verify_channel(mode, op_class->op_class, 171, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 363 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 364 | found++; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 365 | if (verify_channel(mode, op_class->op_class, 106, |
| 366 | op_class->bw) != NOT_ALLOWED && |
| 367 | verify_channel(mode, op_class->op_class, 138, |
| 368 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 369 | found++; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 370 | if (verify_channel(mode, op_class->op_class, 122, |
| 371 | op_class->bw) != NOT_ALLOWED && |
| 372 | verify_channel(mode, op_class->op_class, 155, |
| 373 | op_class->bw) != NOT_ALLOWED) |
| 374 | found++; |
| 375 | if (verify_channel(mode, op_class->op_class, 138, |
| 376 | op_class->bw) != NOT_ALLOWED && |
| 377 | verify_channel(mode, op_class->op_class, 171, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 378 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 379 | found++; |
| 380 | |
| 381 | if (found >= 2) |
| 382 | return 1; |
| 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 387 | if (op_class->op_class == 135) { |
| 388 | /* Need at least two 80 MHz segments which do not fall under the |
| 389 | * same 160 MHz segment to support 80+80 in 6 GHz. |
| 390 | */ |
| 391 | int first_seg = 0; |
| 392 | int curr_seg = 0; |
| 393 | |
| 394 | for (chan = op_class->min_chan; chan <= op_class->max_chan; |
| 395 | chan += op_class->inc) { |
| 396 | curr_seg++; |
| 397 | if (verify_channel(mode, op_class->op_class, chan, |
| 398 | op_class->bw) != NOT_ALLOWED) { |
| 399 | if (!first_seg) { |
| 400 | first_seg = curr_seg; |
| 401 | continue; |
| 402 | } |
| 403 | |
| 404 | /* Supported if at least two non-consecutive 80 |
| 405 | * MHz segments allowed. |
| 406 | */ |
| 407 | if ((curr_seg - first_seg) > 1) |
| 408 | return 1; |
| 409 | |
| 410 | /* Supported even if the 80 MHz segments are |
| 411 | * consecutive when they do not fall under the |
| 412 | * same 160 MHz segment. |
| 413 | */ |
| 414 | if ((first_seg % 2) == 0) |
| 415 | return 1; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 422 | found = 0; |
| 423 | for (chan = op_class->min_chan; chan <= op_class->max_chan; |
| 424 | chan += op_class->inc) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 425 | if (verify_channel(mode, op_class->op_class, chan, |
| 426 | op_class->bw) != NOT_ALLOWED) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 427 | found = 1; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | return found; |
| 433 | } |
| 434 | |
| 435 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 436 | static int wpas_sta_secondary_channel_offset(struct wpa_bss *bss, u8 *current, |
| 437 | u8 *channel) |
| 438 | { |
| 439 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 440 | const u8 *ies; |
| 441 | u8 phy_type; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 442 | size_t ies_len; |
| 443 | |
| 444 | if (!bss) |
| 445 | return -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 446 | ies = wpa_bss_ie_ptr(bss); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 447 | ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
| 448 | return wpas_get_op_chan_phy(bss->freq, ies, ies_len, current, |
| 449 | channel, &phy_type); |
| 450 | } |
| 451 | |
| 452 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 453 | size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s, |
| 454 | struct wpa_ssid *ssid, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 455 | struct wpa_bss *bss, u8 *pos, size_t len) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 456 | { |
| 457 | struct wpabuf *buf; |
| 458 | u8 op, current, chan; |
| 459 | u8 *ie_len; |
| 460 | size_t res; |
| 461 | |
| 462 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 463 | * Determine the current operating class correct mode based on |
| 464 | * advertised BSS capabilities, if available. Fall back to a less |
| 465 | * accurate guess based on frequency if the needed IEs are not available |
| 466 | * or used. |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 467 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 468 | if (wpas_sta_secondary_channel_offset(bss, ¤t, &chan) < 0 && |
| 469 | ieee80211_freq_to_channel_ext(bss->freq, 0, CHANWIDTH_USE_HT, |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 470 | ¤t, &chan) == NUM_HOSTAPD_MODES) |
| 471 | return 0; |
| 472 | |
| 473 | /* |
| 474 | * Need 3 bytes for EID, length, and current operating class, plus |
| 475 | * 1 byte for every other supported operating class. |
| 476 | */ |
| 477 | buf = wpabuf_alloc(global_op_class_size + 3); |
| 478 | if (!buf) |
| 479 | return 0; |
| 480 | |
| 481 | wpabuf_put_u8(buf, WLAN_EID_SUPPORTED_OPERATING_CLASSES); |
| 482 | /* Will set the length later, putting a placeholder */ |
| 483 | ie_len = wpabuf_put(buf, 1); |
| 484 | wpabuf_put_u8(buf, current); |
| 485 | |
| 486 | for (op = 0; global_op_class[op].op_class; op++) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 487 | if (wpas_op_class_supported(wpa_s, ssid, &global_op_class[op])) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 488 | wpabuf_put_u8(buf, global_op_class[op].op_class); |
| 489 | } |
| 490 | |
| 491 | *ie_len = wpabuf_len(buf) - 2; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 492 | if (*ie_len < 2) { |
| 493 | wpa_printf(MSG_DEBUG, |
| 494 | "No supported operating classes IE to add"); |
| 495 | res = 0; |
| 496 | } else if (wpabuf_len(buf) > len) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 497 | wpa_printf(MSG_ERROR, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 498 | "Supported operating classes IE exceeds maximum buffer length"); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 499 | res = 0; |
| 500 | } else { |
| 501 | os_memcpy(pos, wpabuf_head(buf), wpabuf_len(buf)); |
| 502 | res = wpabuf_len(buf); |
| 503 | wpa_hexdump_buf(MSG_DEBUG, |
| 504 | "Added supported operating classes IE", buf); |
| 505 | } |
| 506 | |
| 507 | wpabuf_free(buf); |
| 508 | return res; |
| 509 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 510 | |
| 511 | |
| 512 | int * wpas_supp_op_classes(struct wpa_supplicant *wpa_s) |
| 513 | { |
| 514 | int op; |
| 515 | unsigned int pos, max_num = 0; |
| 516 | int *classes; |
| 517 | |
| 518 | for (op = 0; global_op_class[op].op_class; op++) |
| 519 | max_num++; |
| 520 | classes = os_zalloc((max_num + 1) * sizeof(int)); |
| 521 | if (!classes) |
| 522 | return NULL; |
| 523 | |
| 524 | for (op = 0, pos = 0; global_op_class[op].op_class; op++) { |
| 525 | if (wpas_op_class_supported(wpa_s, NULL, &global_op_class[op])) |
| 526 | classes[pos++] = global_op_class[op].op_class; |
| 527 | } |
| 528 | |
| 529 | return classes; |
| 530 | } |