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 | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame^] | 210 | } else if (bw == BW40PLUS) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 211 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
| 212 | return NOT_ALLOWED; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 213 | res2 = allow_channel(mode, op_class, channel + 4, NULL); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame^] | 214 | } else if (is_6ghz_op_class(op_class) && bw == BW40) { |
| 215 | if (get_6ghz_sec_channel(channel) < 0) |
| 216 | res2 = allow_channel(mode, op_class, channel - 4, NULL); |
| 217 | else |
| 218 | res2 = allow_channel(mode, op_class, channel + 4, NULL); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 219 | } else if (bw == BW80) { |
| 220 | /* |
| 221 | * channel is a center channel and as such, not necessarily a |
| 222 | * valid 20 MHz channels. Override earlier allow_channel() |
| 223 | * result and use only the 80 MHz specific version. |
| 224 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 225 | res2 = res = verify_80mhz(mode, op_class, channel); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 226 | } else if (bw == BW160) { |
| 227 | /* |
| 228 | * channel is a center channel and as such, not necessarily a |
| 229 | * valid 20 MHz channels. Override earlier allow_channel() |
| 230 | * result and use only the 160 MHz specific version. |
| 231 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 232 | res2 = res = verify_160mhz(mode, op_class, channel); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 233 | } else if (bw == BW80P80) { |
| 234 | /* |
| 235 | * channel is a center channel and as such, not necessarily a |
| 236 | * valid 20 MHz channels. Override earlier allow_channel() |
| 237 | * result and use only the 80 MHz specific version. |
| 238 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 239 | res2 = res = verify_80mhz(mode, op_class, channel); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
| 243 | return NOT_ALLOWED; |
| 244 | |
| 245 | if (res == NO_IR || res2 == NO_IR) |
| 246 | return NO_IR; |
| 247 | |
| 248 | return ALLOWED; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | static int wpas_op_class_supported(struct wpa_supplicant *wpa_s, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 253 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 254 | const struct oper_class_map *op_class) |
| 255 | { |
| 256 | int chan; |
| 257 | size_t i; |
| 258 | struct hostapd_hw_modes *mode; |
| 259 | int found; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 260 | int z; |
| 261 | int freq2 = 0; |
| 262 | int freq5 = 0; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 263 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 264 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, op_class->mode, |
| 265 | is_6ghz_op_class(op_class->op_class)); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 266 | if (!mode) |
| 267 | return 0; |
| 268 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 269 | /* If we are configured to disable certain things, take that into |
| 270 | * account here. */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 271 | if (ssid && ssid->freq_list && ssid->freq_list[0]) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 272 | for (z = 0; ; z++) { |
| 273 | int f = ssid->freq_list[z]; |
| 274 | |
| 275 | if (f == 0) |
| 276 | break; /* end of list */ |
| 277 | if (f > 4000 && f < 6000) |
| 278 | freq5 = 1; |
| 279 | else if (f > 2400 && f < 2500) |
| 280 | freq2 = 1; |
| 281 | } |
| 282 | } else { |
| 283 | /* No frequencies specified, can use anything hardware supports. |
| 284 | */ |
| 285 | freq2 = freq5 = 1; |
| 286 | } |
| 287 | |
| 288 | if (op_class->op_class >= 115 && op_class->op_class <= 130 && !freq5) |
| 289 | return 0; |
| 290 | if (op_class->op_class >= 81 && op_class->op_class <= 84 && !freq2) |
| 291 | return 0; |
| 292 | |
| 293 | #ifdef CONFIG_HT_OVERRIDES |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 294 | if (ssid && ssid->disable_ht) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 295 | switch (op_class->op_class) { |
| 296 | case 83: |
| 297 | case 84: |
| 298 | case 104: |
| 299 | case 105: |
| 300 | case 116: |
| 301 | case 117: |
| 302 | case 119: |
| 303 | case 120: |
| 304 | case 122: |
| 305 | case 123: |
| 306 | case 126: |
| 307 | case 127: |
| 308 | case 128: |
| 309 | case 129: |
| 310 | case 130: |
| 311 | /* Disable >= 40 MHz channels if HT is disabled */ |
| 312 | return 0; |
| 313 | } |
| 314 | } |
| 315 | #endif /* CONFIG_HT_OVERRIDES */ |
| 316 | |
| 317 | #ifdef CONFIG_VHT_OVERRIDES |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 318 | if (ssid && ssid->disable_vht) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 319 | if (op_class->op_class >= 128 && op_class->op_class <= 130) { |
| 320 | /* Disable >= 80 MHz channels if VHT is disabled */ |
| 321 | return 0; |
| 322 | } |
| 323 | } |
| 324 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 325 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 326 | if (op_class->op_class == 128) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 327 | u8 channels[] = { 42, 58, 106, 122, 138, 155, 171 }; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 328 | |
| 329 | for (i = 0; i < ARRAY_SIZE(channels); i++) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 330 | if (verify_channel(mode, op_class->op_class, |
| 331 | channels[i], op_class->bw) != |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 332 | NOT_ALLOWED) |
| 333 | return 1; |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | if (op_class->op_class == 129) { |
| 340 | /* Check if either 160 MHz channels is allowed */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 341 | return verify_channel(mode, op_class->op_class, 50, |
| 342 | op_class->bw) != NOT_ALLOWED || |
| 343 | verify_channel(mode, op_class->op_class, 114, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 344 | op_class->bw) != NOT_ALLOWED || |
| 345 | verify_channel(mode, op_class->op_class, 163, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 346 | op_class->bw) != NOT_ALLOWED; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | if (op_class->op_class == 130) { |
| 350 | /* Need at least two non-contiguous 80 MHz segments */ |
| 351 | found = 0; |
| 352 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 353 | if (verify_channel(mode, op_class->op_class, 42, |
| 354 | op_class->bw) != NOT_ALLOWED || |
| 355 | verify_channel(mode, op_class->op_class, 58, |
| 356 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 357 | found++; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 358 | if (verify_channel(mode, op_class->op_class, 106, |
| 359 | op_class->bw) != NOT_ALLOWED || |
| 360 | verify_channel(mode, op_class->op_class, 122, |
| 361 | op_class->bw) != NOT_ALLOWED || |
| 362 | verify_channel(mode, op_class->op_class, 138, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 363 | op_class->bw) != NOT_ALLOWED || |
| 364 | verify_channel(mode, op_class->op_class, 155, |
| 365 | op_class->bw) != NOT_ALLOWED || |
| 366 | verify_channel(mode, op_class->op_class, 171, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 367 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 368 | found++; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 369 | if (verify_channel(mode, op_class->op_class, 106, |
| 370 | op_class->bw) != NOT_ALLOWED && |
| 371 | verify_channel(mode, op_class->op_class, 138, |
| 372 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 373 | found++; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 374 | if (verify_channel(mode, op_class->op_class, 122, |
| 375 | op_class->bw) != NOT_ALLOWED && |
| 376 | verify_channel(mode, op_class->op_class, 155, |
| 377 | op_class->bw) != NOT_ALLOWED) |
| 378 | found++; |
| 379 | if (verify_channel(mode, op_class->op_class, 138, |
| 380 | op_class->bw) != NOT_ALLOWED && |
| 381 | verify_channel(mode, op_class->op_class, 171, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 382 | op_class->bw) != NOT_ALLOWED) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 383 | found++; |
| 384 | |
| 385 | if (found >= 2) |
| 386 | return 1; |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 391 | if (op_class->op_class == 135) { |
| 392 | /* Need at least two 80 MHz segments which do not fall under the |
| 393 | * same 160 MHz segment to support 80+80 in 6 GHz. |
| 394 | */ |
| 395 | int first_seg = 0; |
| 396 | int curr_seg = 0; |
| 397 | |
| 398 | for (chan = op_class->min_chan; chan <= op_class->max_chan; |
| 399 | chan += op_class->inc) { |
| 400 | curr_seg++; |
| 401 | if (verify_channel(mode, op_class->op_class, chan, |
| 402 | op_class->bw) != NOT_ALLOWED) { |
| 403 | if (!first_seg) { |
| 404 | first_seg = curr_seg; |
| 405 | continue; |
| 406 | } |
| 407 | |
| 408 | /* Supported if at least two non-consecutive 80 |
| 409 | * MHz segments allowed. |
| 410 | */ |
| 411 | if ((curr_seg - first_seg) > 1) |
| 412 | return 1; |
| 413 | |
| 414 | /* Supported even if the 80 MHz segments are |
| 415 | * consecutive when they do not fall under the |
| 416 | * same 160 MHz segment. |
| 417 | */ |
| 418 | if ((first_seg % 2) == 0) |
| 419 | return 1; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 426 | found = 0; |
| 427 | for (chan = op_class->min_chan; chan <= op_class->max_chan; |
| 428 | chan += op_class->inc) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 429 | if (verify_channel(mode, op_class->op_class, chan, |
| 430 | op_class->bw) != NOT_ALLOWED) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 431 | found = 1; |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | return found; |
| 437 | } |
| 438 | |
| 439 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 440 | static int wpas_sta_secondary_channel_offset(struct wpa_bss *bss, u8 *current, |
| 441 | u8 *channel) |
| 442 | { |
| 443 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 444 | const u8 *ies; |
| 445 | u8 phy_type; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 446 | size_t ies_len; |
| 447 | |
| 448 | if (!bss) |
| 449 | return -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 450 | ies = wpa_bss_ie_ptr(bss); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 451 | ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
| 452 | return wpas_get_op_chan_phy(bss->freq, ies, ies_len, current, |
| 453 | channel, &phy_type); |
| 454 | } |
| 455 | |
| 456 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 457 | size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s, |
| 458 | struct wpa_ssid *ssid, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 459 | struct wpa_bss *bss, u8 *pos, size_t len) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 460 | { |
| 461 | struct wpabuf *buf; |
| 462 | u8 op, current, chan; |
| 463 | u8 *ie_len; |
| 464 | size_t res; |
| 465 | |
| 466 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 467 | * Determine the current operating class correct mode based on |
| 468 | * advertised BSS capabilities, if available. Fall back to a less |
| 469 | * accurate guess based on frequency if the needed IEs are not available |
| 470 | * or used. |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 471 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 472 | if (wpas_sta_secondary_channel_offset(bss, ¤t, &chan) < 0 && |
| 473 | ieee80211_freq_to_channel_ext(bss->freq, 0, CHANWIDTH_USE_HT, |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 474 | ¤t, &chan) == NUM_HOSTAPD_MODES) |
| 475 | return 0; |
| 476 | |
| 477 | /* |
| 478 | * Need 3 bytes for EID, length, and current operating class, plus |
| 479 | * 1 byte for every other supported operating class. |
| 480 | */ |
| 481 | buf = wpabuf_alloc(global_op_class_size + 3); |
| 482 | if (!buf) |
| 483 | return 0; |
| 484 | |
| 485 | wpabuf_put_u8(buf, WLAN_EID_SUPPORTED_OPERATING_CLASSES); |
| 486 | /* Will set the length later, putting a placeholder */ |
| 487 | ie_len = wpabuf_put(buf, 1); |
| 488 | wpabuf_put_u8(buf, current); |
| 489 | |
| 490 | for (op = 0; global_op_class[op].op_class; op++) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 491 | if (wpas_op_class_supported(wpa_s, ssid, &global_op_class[op])) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 492 | wpabuf_put_u8(buf, global_op_class[op].op_class); |
| 493 | } |
| 494 | |
| 495 | *ie_len = wpabuf_len(buf) - 2; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 496 | if (*ie_len < 2) { |
| 497 | wpa_printf(MSG_DEBUG, |
| 498 | "No supported operating classes IE to add"); |
| 499 | res = 0; |
| 500 | } else if (wpabuf_len(buf) > len) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 501 | wpa_printf(MSG_ERROR, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 502 | "Supported operating classes IE exceeds maximum buffer length"); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 503 | res = 0; |
| 504 | } else { |
| 505 | os_memcpy(pos, wpabuf_head(buf), wpabuf_len(buf)); |
| 506 | res = wpabuf_len(buf); |
| 507 | wpa_hexdump_buf(MSG_DEBUG, |
| 508 | "Added supported operating classes IE", buf); |
| 509 | } |
| 510 | |
| 511 | wpabuf_free(buf); |
| 512 | return res; |
| 513 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 514 | |
| 515 | |
| 516 | int * wpas_supp_op_classes(struct wpa_supplicant *wpa_s) |
| 517 | { |
| 518 | int op; |
| 519 | unsigned int pos, max_num = 0; |
| 520 | int *classes; |
| 521 | |
| 522 | for (op = 0; global_op_class[op].op_class; op++) |
| 523 | max_num++; |
| 524 | classes = os_zalloc((max_num + 1) * sizeof(int)); |
| 525 | if (!classes) |
| 526 | return NULL; |
| 527 | |
| 528 | for (op = 0, pos = 0; global_op_class[op].op_class; op++) { |
| 529 | if (wpas_op_class_supported(wpa_s, NULL, &global_op_class[op])) |
| 530 | classes[pos++] = global_op_class[op].op_class; |
| 531 | } |
| 532 | |
| 533 | return classes; |
| 534 | } |