blob: bd53c5ceceafe2eeccc6d53902ccae4f18237a77 [file] [log] [blame]
Dmitry Shmidt29333592017-01-09 12:27:11 -08001/*
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 Shalomfdcde762020-04-02 11:19:20 -070017#include "bss.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080018
19
Hai Shalomc3565922019-10-28 11:58:20 -070020static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode,
21 u8 op_class, u8 chan,
Dmitry Shmidt29333592017-01-09 12:27:11 -080022 unsigned int *flags)
23{
24 int i;
Hai Shalom60840252021-02-19 19:02:11 -080025 bool is_6ghz = op_class >= 131 && op_class <= 136;
Dmitry Shmidt29333592017-01-09 12:27:11 -080026
27 for (i = 0; i < mode->num_channels; i++) {
Hai Shalom60840252021-02-19 19:02:11 -080028 bool chan_is_6ghz;
Hai Shalomc3565922019-10-28 11:58:20 -070029
Kai Shic1745342020-09-09 11:31:57 -070030 chan_is_6ghz = mode->channels[i].freq >= 5935 &&
31 mode->channels[i].freq <= 7115;
Hai Shalomc3565922019-10-28 11:58:20 -070032 if (is_6ghz == chan_is_6ghz && mode->channels[i].chan == chan)
Dmitry Shmidt29333592017-01-09 12:27:11 -080033 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 Shalom60840252021-02-19 19:02:11 -080050static int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel,
51 const u8 *center_channels, size_t num_chan)
Dmitry Shmidt29333592017-01-09 12:27:11 -080052{
Dmitry Shmidt29333592017-01-09 12:27:11 -080053 size_t i;
54
55 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
56 return 0;
57
Hai Shalom60840252021-02-19 19:02:11 -080058 for (i = 0; i < num_chan; i++) {
Dmitry Shmidt29333592017-01-09 12:27:11 -080059 /*
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 Shalomc3565922019-10-28 11:58:20 -070072static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode,
73 u8 op_class, u8 channel)
Dmitry Shmidt29333592017-01-09 12:27:11 -080074{
75 u8 center_chan;
76 unsigned int i;
77 unsigned int no_ir = 0;
Hai Shalom60840252021-02-19 19:02:11 -080078 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 Shmidt29333592017-01-09 12:27:11 -080083
Hai Shalom60840252021-02-19 19:02:11 -080084 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 Shmidt29333592017-01-09 12:27:11 -080094 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 Shalomc3565922019-10-28 11:58:20 -0700102 if (allow_channel(mode, op_class, adj_chan, &flags) ==
103 NOT_ALLOWED)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800104 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 Shalom60840252021-02-19 19:02:11 -0800123static int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel,
124 const u8 *center_channels, size_t num_chan)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800125{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800126 unsigned int i;
127
128 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
129 return 0;
130
Hai Shalom60840252021-02-19 19:02:11 -0800131 for (i = 0; i < num_chan; i++) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800132 /*
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
145static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode,
Hai Shalomc3565922019-10-28 11:58:20 -0700146 u8 op_class, u8 channel)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800147{
148 u8 center_chan;
149 unsigned int i;
150 unsigned int no_ir = 0;
Hai Shalom60840252021-02-19 19:02:11 -0800151 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 Shmidt29333592017-01-09 12:27:11 -0800155
Hai Shalom60840252021-02-19 19:02:11 -0800156 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 Shmidt29333592017-01-09 12:27:11 -0800166 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 Shalomc3565922019-10-28 11:58:20 -0700174 if (allow_channel(mode, op_class, adj_chan, &flags) ==
175 NOT_ALLOWED)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800176 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 Shalomc3565922019-10-28 11:58:20 -0700199enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 op_class,
200 u8 channel, u8 bw)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800201{
202 unsigned int flag = 0;
203 enum chan_allowed res, res2;
204
Hai Shalomc3565922019-10-28 11:58:20 -0700205 res2 = res = allow_channel(mode, op_class, channel, &flag);
Hai Shalom60840252021-02-19 19:02:11 -0800206 if (bw == BW40MINUS || (bw == BW40 && (((channel - 1) / 4) % 2))) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800207 if (!(flag & HOSTAPD_CHAN_HT40MINUS))
208 return NOT_ALLOWED;
Hai Shalomc3565922019-10-28 11:58:20 -0700209 res2 = allow_channel(mode, op_class, channel - 4, NULL);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800210 } else if (bw == BW40PLUS) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800211 if (!(flag & HOSTAPD_CHAN_HT40PLUS))
212 return NOT_ALLOWED;
Hai Shalomc3565922019-10-28 11:58:20 -0700213 res2 = allow_channel(mode, op_class, channel + 4, NULL);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800214 } 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 Shmidt29333592017-01-09 12:27:11 -0800219 } 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 Shalomc3565922019-10-28 11:58:20 -0700225 res2 = res = verify_80mhz(mode, op_class, channel);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800226 } 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 Shalomc3565922019-10-28 11:58:20 -0700232 res2 = res = verify_160mhz(mode, op_class, channel);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800233 } 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 Shalomc3565922019-10-28 11:58:20 -0700239 res2 = res = verify_80mhz(mode, op_class, channel);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800240 }
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
252static int wpas_op_class_supported(struct wpa_supplicant *wpa_s,
Hai Shalom74f70d42019-02-11 14:42:39 -0800253 struct wpa_ssid *ssid,
Dmitry Shmidt29333592017-01-09 12:27:11 -0800254 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 Shalom74f70d42019-02-11 14:42:39 -0800260 int z;
261 int freq2 = 0;
262 int freq5 = 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800263
Hai Shalomfdcde762020-04-02 11:19:20 -0700264 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 Shmidt29333592017-01-09 12:27:11 -0800266 if (!mode)
267 return 0;
268
Hai Shalom74f70d42019-02-11 14:42:39 -0800269 /* If we are configured to disable certain things, take that into
270 * account here. */
Hai Shalomc3565922019-10-28 11:58:20 -0700271 if (ssid && ssid->freq_list && ssid->freq_list[0]) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800272 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 Shalomc3565922019-10-28 11:58:20 -0700294 if (ssid && ssid->disable_ht) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800295 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 Shalomc3565922019-10-28 11:58:20 -0700318 if (ssid && ssid->disable_vht) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800319 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 Shmidt29333592017-01-09 12:27:11 -0800326 if (op_class->op_class == 128) {
Hai Shalom60840252021-02-19 19:02:11 -0800327 u8 channels[] = { 42, 58, 106, 122, 138, 155, 171 };
Dmitry Shmidt29333592017-01-09 12:27:11 -0800328
329 for (i = 0; i < ARRAY_SIZE(channels); i++) {
Hai Shalomc3565922019-10-28 11:58:20 -0700330 if (verify_channel(mode, op_class->op_class,
331 channels[i], op_class->bw) !=
Dmitry Shmidt29333592017-01-09 12:27:11 -0800332 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 Shalomc3565922019-10-28 11:58:20 -0700341 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 Shalom60840252021-02-19 19:02:11 -0800344 op_class->bw) != NOT_ALLOWED ||
345 verify_channel(mode, op_class->op_class, 163,
Hai Shalomc3565922019-10-28 11:58:20 -0700346 op_class->bw) != NOT_ALLOWED;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800347 }
348
349 if (op_class->op_class == 130) {
350 /* Need at least two non-contiguous 80 MHz segments */
351 found = 0;
352
Hai Shalomc3565922019-10-28 11:58:20 -0700353 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 Shmidt29333592017-01-09 12:27:11 -0800357 found++;
Hai Shalomc3565922019-10-28 11:58:20 -0700358 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 Shalom60840252021-02-19 19:02:11 -0800363 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 Shalomc3565922019-10-28 11:58:20 -0700367 op_class->bw) != NOT_ALLOWED)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800368 found++;
Hai Shalomc3565922019-10-28 11:58:20 -0700369 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 Shmidt29333592017-01-09 12:27:11 -0800373 found++;
Hai Shalom60840252021-02-19 19:02:11 -0800374 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 Shalomc3565922019-10-28 11:58:20 -0700382 op_class->bw) != NOT_ALLOWED)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800383 found++;
384
385 if (found >= 2)
386 return 1;
387
388 return 0;
389 }
390
Hai Shalom60840252021-02-19 19:02:11 -0800391 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 Shmidt29333592017-01-09 12:27:11 -0800426 found = 0;
427 for (chan = op_class->min_chan; chan <= op_class->max_chan;
428 chan += op_class->inc) {
Hai Shalomc3565922019-10-28 11:58:20 -0700429 if (verify_channel(mode, op_class->op_class, chan,
430 op_class->bw) != NOT_ALLOWED) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800431 found = 1;
432 break;
433 }
434 }
435
436 return found;
437}
438
439
Hai Shalomfdcde762020-04-02 11:19:20 -0700440static int wpas_sta_secondary_channel_offset(struct wpa_bss *bss, u8 *current,
441 u8 *channel)
442{
443
Hai Shalom60840252021-02-19 19:02:11 -0800444 const u8 *ies;
445 u8 phy_type;
Hai Shalomfdcde762020-04-02 11:19:20 -0700446 size_t ies_len;
447
448 if (!bss)
449 return -1;
Hai Shalom60840252021-02-19 19:02:11 -0800450 ies = wpa_bss_ie_ptr(bss);
Hai Shalomfdcde762020-04-02 11:19:20 -0700451 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 Shalom74f70d42019-02-11 14:42:39 -0800457size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s,
458 struct wpa_ssid *ssid,
Hai Shalomfdcde762020-04-02 11:19:20 -0700459 struct wpa_bss *bss, u8 *pos, size_t len)
Dmitry Shmidt29333592017-01-09 12:27:11 -0800460{
461 struct wpabuf *buf;
462 u8 op, current, chan;
463 u8 *ie_len;
464 size_t res;
465
466 /*
Hai Shalomfdcde762020-04-02 11:19:20 -0700467 * 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 Shmidt29333592017-01-09 12:27:11 -0800471 */
Hai Shalomfdcde762020-04-02 11:19:20 -0700472 if (wpas_sta_secondary_channel_offset(bss, &current, &chan) < 0 &&
473 ieee80211_freq_to_channel_ext(bss->freq, 0, CHANWIDTH_USE_HT,
Dmitry Shmidt29333592017-01-09 12:27:11 -0800474 &current, &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 Shalom74f70d42019-02-11 14:42:39 -0800491 if (wpas_op_class_supported(wpa_s, ssid, &global_op_class[op]))
Dmitry Shmidt29333592017-01-09 12:27:11 -0800492 wpabuf_put_u8(buf, global_op_class[op].op_class);
493 }
494
495 *ie_len = wpabuf_len(buf) - 2;
Hai Shalom899fcc72020-10-19 14:38:18 -0700496 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 Shmidt29333592017-01-09 12:27:11 -0800501 wpa_printf(MSG_ERROR,
Hai Shalom899fcc72020-10-19 14:38:18 -0700502 "Supported operating classes IE exceeds maximum buffer length");
Dmitry Shmidt29333592017-01-09 12:27:11 -0800503 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 Shalomc3565922019-10-28 11:58:20 -0700514
515
516int * 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}