/src/hostap/wpa_supplicant/op_classes.c
Line | Count | Source (jump to first uncovered line) |
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" |
17 | | #include "bss.h" |
18 | | #include "config.h" |
19 | | |
20 | | |
21 | | static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode, |
22 | | u8 op_class, u8 chan, |
23 | | unsigned int *flags) |
24 | 0 | { |
25 | 0 | int i; |
26 | 0 | bool is_6ghz = is_6ghz_op_class(op_class); |
27 | |
|
28 | 0 | for (i = 0; i < mode->num_channels; i++) { |
29 | 0 | bool chan_is_6ghz; |
30 | |
|
31 | 0 | chan_is_6ghz = is_6ghz_freq(mode->channels[i].freq); |
32 | 0 | if (is_6ghz == chan_is_6ghz && mode->channels[i].chan == chan) |
33 | 0 | break; |
34 | 0 | } |
35 | |
|
36 | 0 | if (i == mode->num_channels || |
37 | 0 | (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)) |
38 | 0 | return NOT_ALLOWED; |
39 | | |
40 | 0 | if (flags) |
41 | 0 | *flags = mode->channels[i].flag; |
42 | |
|
43 | 0 | if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR) |
44 | 0 | return NO_IR; |
45 | | |
46 | 0 | return ALLOWED; |
47 | 0 | } |
48 | | |
49 | | |
50 | | static int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel, |
51 | | const u8 *center_channels, size_t num_chan) |
52 | 0 | { |
53 | 0 | size_t i; |
54 | |
|
55 | 0 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
56 | 0 | return 0; |
57 | | |
58 | 0 | for (i = 0; i < num_chan; i++) { |
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 | 0 | if (channel >= center_channels[i] - 6 && |
64 | 0 | channel <= center_channels[i] + 6) |
65 | 0 | return center_channels[i]; |
66 | 0 | } |
67 | | |
68 | 0 | return 0; |
69 | 0 | } |
70 | | |
71 | | |
72 | | static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode, |
73 | | u8 op_class, u8 channel) |
74 | 0 | { |
75 | 0 | u8 center_chan; |
76 | 0 | unsigned int i; |
77 | 0 | unsigned int no_ir = 0; |
78 | 0 | const u8 *center_channels; |
79 | 0 | size_t num_chan; |
80 | 0 | const u8 center_channels_5ghz[] = { 42, 58, 106, 122, 138, 155, 171 }; |
81 | 0 | const u8 center_channels_6ghz[] = { 7, 23, 39, 55, 71, 87, 103, 119, |
82 | 0 | 135, 151, 167, 183, 199, 215 }; |
83 | |
|
84 | 0 | if (is_6ghz_op_class(op_class)) { |
85 | 0 | center_channels = center_channels_6ghz; |
86 | 0 | num_chan = ARRAY_SIZE(center_channels_6ghz); |
87 | 0 | } else { |
88 | 0 | center_channels = center_channels_5ghz; |
89 | 0 | num_chan = ARRAY_SIZE(center_channels_5ghz); |
90 | 0 | } |
91 | |
|
92 | 0 | center_chan = get_center_80mhz(mode, channel, center_channels, |
93 | 0 | num_chan); |
94 | 0 | if (!center_chan) |
95 | 0 | return NOT_ALLOWED; |
96 | | |
97 | | /* check all the channels are available */ |
98 | 0 | for (i = 0; i < 4; i++) { |
99 | 0 | unsigned int flags; |
100 | 0 | u8 adj_chan = center_chan - 6 + i * 4; |
101 | |
|
102 | 0 | if (allow_channel(mode, op_class, adj_chan, &flags) == |
103 | 0 | NOT_ALLOWED) |
104 | 0 | return NOT_ALLOWED; |
105 | | |
106 | 0 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL)) |
107 | 0 | return NOT_ALLOWED; |
108 | | |
109 | 0 | if (flags & HOSTAPD_CHAN_NO_IR) |
110 | 0 | no_ir = 1; |
111 | 0 | } |
112 | | |
113 | 0 | if (no_ir) |
114 | 0 | return NO_IR; |
115 | | |
116 | 0 | return ALLOWED; |
117 | 0 | } |
118 | | |
119 | | |
120 | | static int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel, |
121 | | const u8 *center_channels, size_t num_chan) |
122 | 0 | { |
123 | 0 | unsigned int i; |
124 | |
|
125 | 0 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
126 | 0 | return 0; |
127 | | |
128 | 0 | for (i = 0; i < num_chan; i++) { |
129 | | /* |
130 | | * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64), |
131 | | * so the center channel is 14 channels away from the start/end. |
132 | | */ |
133 | 0 | if (channel >= center_channels[i] - 14 && |
134 | 0 | channel <= center_channels[i] + 14) |
135 | 0 | return center_channels[i]; |
136 | 0 | } |
137 | | |
138 | 0 | return 0; |
139 | 0 | } |
140 | | |
141 | | |
142 | | static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode, |
143 | | u8 op_class, u8 channel) |
144 | 0 | { |
145 | 0 | u8 center_chan; |
146 | 0 | unsigned int i; |
147 | 0 | unsigned int no_ir = 0; |
148 | 0 | const u8 *center_channels; |
149 | 0 | size_t num_chan; |
150 | 0 | const u8 center_channels_5ghz[] = { 50, 114, 163 }; |
151 | 0 | const u8 center_channels_6ghz[] = { 15, 47, 79, 111, 143, 175, 207 }; |
152 | |
|
153 | 0 | if (is_6ghz_op_class(op_class)) { |
154 | 0 | center_channels = center_channels_6ghz; |
155 | 0 | num_chan = ARRAY_SIZE(center_channels_6ghz); |
156 | 0 | } else { |
157 | 0 | center_channels = center_channels_5ghz; |
158 | 0 | num_chan = ARRAY_SIZE(center_channels_5ghz); |
159 | 0 | } |
160 | |
|
161 | 0 | center_chan = get_center_160mhz(mode, channel, center_channels, |
162 | 0 | num_chan); |
163 | 0 | if (!center_chan) |
164 | 0 | return NOT_ALLOWED; |
165 | | |
166 | | /* Check all the channels are available */ |
167 | 0 | for (i = 0; i < 8; i++) { |
168 | 0 | unsigned int flags; |
169 | 0 | u8 adj_chan = center_chan - 14 + i * 4; |
170 | |
|
171 | 0 | if (allow_channel(mode, op_class, adj_chan, &flags) == |
172 | 0 | NOT_ALLOWED) |
173 | 0 | return NOT_ALLOWED; |
174 | | |
175 | 0 | if (!(flags & HOSTAPD_CHAN_VHT_80MHZ_SUBCHANNEL) || |
176 | 0 | (!(flags & HOSTAPD_CHAN_VHT_160MHZ_SUBCHANNEL) && |
177 | 0 | !(flags & HOSTAPD_CHAN_AUTO_BW))) |
178 | 0 | return NOT_ALLOWED; |
179 | | |
180 | 0 | if (flags & HOSTAPD_CHAN_NO_IR) |
181 | 0 | no_ir = 1; |
182 | 0 | } |
183 | | |
184 | 0 | if (no_ir) |
185 | 0 | return NO_IR; |
186 | | |
187 | 0 | return ALLOWED; |
188 | 0 | } |
189 | | |
190 | | |
191 | | static int get_center_320mhz(struct hostapd_hw_modes *mode, u8 channel, |
192 | | const u8 *center_channels, size_t num_chan) |
193 | 0 | { |
194 | 0 | unsigned int i; |
195 | |
|
196 | 0 | if (mode->mode != HOSTAPD_MODE_IEEE80211A || !mode->is_6ghz) |
197 | 0 | return 0; |
198 | | |
199 | 0 | for (i = 0; i < num_chan; i++) { |
200 | | /* |
201 | | * In 320 MHz, the bandwidth "spans" 60 channels (e.g., 65-125), |
202 | | * so the center channel is 30 channels away from the start/end. |
203 | | */ |
204 | 0 | if (channel >= center_channels[i] - 30 && |
205 | 0 | channel <= center_channels[i] + 30) |
206 | 0 | return center_channels[i]; |
207 | 0 | } |
208 | | |
209 | 0 | return 0; |
210 | 0 | } |
211 | | |
212 | | |
213 | | static enum chan_allowed verify_320mhz(struct hostapd_hw_modes *mode, |
214 | | u8 op_class, u8 channel) |
215 | 0 | { |
216 | 0 | u8 center_chan; |
217 | 0 | unsigned int i; |
218 | 0 | bool no_ir = false; |
219 | 0 | const u8 *center_channels; |
220 | 0 | size_t num_chan; |
221 | 0 | const u8 center_channels_6ghz[] = { 31, 63, 95, 127, 159, 191 }; |
222 | |
|
223 | 0 | center_channels = center_channels_6ghz; |
224 | 0 | num_chan = ARRAY_SIZE(center_channels_6ghz); |
225 | |
|
226 | 0 | center_chan = get_center_320mhz(mode, channel, center_channels, |
227 | 0 | num_chan); |
228 | 0 | if (!center_chan) |
229 | 0 | return NOT_ALLOWED; |
230 | | |
231 | | /* Check all the channels are available */ |
232 | 0 | for (i = 0; i < 16; i++) { |
233 | 0 | unsigned int flags; |
234 | 0 | u8 adj_chan = center_chan - 30 + i * 4; |
235 | |
|
236 | 0 | if (allow_channel(mode, op_class, adj_chan, &flags) == |
237 | 0 | NOT_ALLOWED) |
238 | 0 | return NOT_ALLOWED; |
239 | | |
240 | 0 | if (!(flags & HOSTAPD_CHAN_EHT_320MHZ_SUBCHANNEL)) |
241 | 0 | return NOT_ALLOWED; |
242 | | |
243 | 0 | if (flags & HOSTAPD_CHAN_NO_IR) |
244 | 0 | no_ir = true; |
245 | 0 | } |
246 | | |
247 | 0 | if (no_ir) |
248 | 0 | return NO_IR; |
249 | | |
250 | 0 | return ALLOWED; |
251 | 0 | } |
252 | | |
253 | | |
254 | | enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 op_class, |
255 | | u8 channel, u8 bw) |
256 | 0 | { |
257 | 0 | unsigned int flag = 0; |
258 | 0 | enum chan_allowed res, res2; |
259 | |
|
260 | 0 | res2 = res = allow_channel(mode, op_class, channel, &flag); |
261 | 0 | if (bw == BW40MINUS || (bw == BW40 && (((channel - 1) / 4) % 2))) { |
262 | 0 | if (!(flag & HOSTAPD_CHAN_HT40MINUS)) |
263 | 0 | return NOT_ALLOWED; |
264 | 0 | res2 = allow_channel(mode, op_class, channel - 4, NULL); |
265 | 0 | } else if (bw == BW40PLUS) { |
266 | 0 | if (!(flag & HOSTAPD_CHAN_HT40PLUS)) |
267 | 0 | return NOT_ALLOWED; |
268 | 0 | res2 = allow_channel(mode, op_class, channel + 4, NULL); |
269 | 0 | } else if (is_6ghz_op_class(op_class) && bw == BW40) { |
270 | 0 | if (get_6ghz_sec_channel(channel) < 0) |
271 | 0 | res2 = allow_channel(mode, op_class, channel - 4, NULL); |
272 | 0 | else |
273 | 0 | res2 = allow_channel(mode, op_class, channel + 4, NULL); |
274 | 0 | } else if (bw == BW80) { |
275 | | /* |
276 | | * channel is a center channel and as such, not necessarily a |
277 | | * valid 20 MHz channels. Override earlier allow_channel() |
278 | | * result and use only the 80 MHz specific version. |
279 | | */ |
280 | 0 | res2 = res = verify_80mhz(mode, op_class, channel); |
281 | 0 | } else if (bw == BW160) { |
282 | | /* |
283 | | * channel is a center channel and as such, not necessarily a |
284 | | * valid 20 MHz channels. Override earlier allow_channel() |
285 | | * result and use only the 160 MHz specific version. |
286 | | */ |
287 | 0 | res2 = res = verify_160mhz(mode, op_class, channel); |
288 | 0 | } else if (bw == BW80P80) { |
289 | | /* |
290 | | * channel is a center channel and as such, not necessarily a |
291 | | * valid 20 MHz channels. Override earlier allow_channel() |
292 | | * result and use only the 80 MHz specific version. |
293 | | */ |
294 | 0 | res2 = res = verify_80mhz(mode, op_class, channel); |
295 | 0 | } else if (bw == BW320) { |
296 | | /* |
297 | | * channel is a center channel and as such, not necessarily a |
298 | | * valid 20 MHz channels. Override earlier allow_channel() |
299 | | * result and use only the 320 MHz specific version. |
300 | | */ |
301 | 0 | res2= res = verify_320mhz(mode, op_class, channel); |
302 | 0 | } |
303 | | |
304 | 0 | if (res == NOT_ALLOWED || res2 == NOT_ALLOWED) |
305 | 0 | return NOT_ALLOWED; |
306 | | |
307 | 0 | if (res == NO_IR || res2 == NO_IR) |
308 | 0 | return NO_IR; |
309 | | |
310 | 0 | return ALLOWED; |
311 | 0 | } |
312 | | |
313 | | |
314 | | static int wpas_op_class_supported(struct wpa_supplicant *wpa_s, |
315 | | struct wpa_ssid *ssid, |
316 | | const struct oper_class_map *op_class) |
317 | 0 | { |
318 | 0 | int chan; |
319 | 0 | size_t i; |
320 | 0 | struct hostapd_hw_modes *mode; |
321 | 0 | int found; |
322 | 0 | int z; |
323 | 0 | int freq2 = 0; |
324 | 0 | int freq5 = 0; |
325 | 0 | bool freq6 = false; |
326 | |
|
327 | 0 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, op_class->mode, |
328 | 0 | is_6ghz_op_class(op_class->op_class)); |
329 | 0 | if (!mode) |
330 | 0 | return 0; |
331 | | |
332 | | /* If we are configured to disable certain things, take that into |
333 | | * account here. */ |
334 | 0 | if (ssid && ssid->freq_list && ssid->freq_list[0]) { |
335 | 0 | for (z = 0; ; z++) { |
336 | 0 | int f = ssid->freq_list[z]; |
337 | |
|
338 | 0 | if (f == 0) |
339 | 0 | break; /* end of list */ |
340 | 0 | if (is_6ghz_freq(f)) |
341 | 0 | freq6 = true; |
342 | 0 | else if (f > 4000 && f < 6000) |
343 | 0 | freq5 = 1; |
344 | 0 | else if (f > 2400 && f < 2500) |
345 | 0 | freq2 = 1; |
346 | 0 | } |
347 | 0 | } else { |
348 | | /* No frequencies specified, can use anything hardware supports. |
349 | | */ |
350 | 0 | freq2 = freq5 = 1; |
351 | 0 | freq6 = true; |
352 | 0 | } |
353 | |
|
354 | 0 | if (is_6ghz_op_class(op_class->op_class) && !freq6) |
355 | 0 | return 0; |
356 | 0 | if (op_class->op_class >= 115 && op_class->op_class <= 130 && !freq5) |
357 | 0 | return 0; |
358 | 0 | if (op_class->op_class >= 81 && op_class->op_class <= 84 && !freq2) |
359 | 0 | return 0; |
360 | | |
361 | | #ifdef CONFIG_HT_OVERRIDES |
362 | | if (ssid && ssid->disable_ht) { |
363 | | switch (op_class->op_class) { |
364 | | case 83: |
365 | | case 84: |
366 | | case 104: |
367 | | case 105: |
368 | | case 116: |
369 | | case 117: |
370 | | case 119: |
371 | | case 120: |
372 | | case 122: |
373 | | case 123: |
374 | | case 126: |
375 | | case 127: |
376 | | case 128: |
377 | | case 129: |
378 | | case 130: |
379 | | /* Disable >= 40 MHz channels if HT is disabled */ |
380 | | return 0; |
381 | | } |
382 | | } |
383 | | #endif /* CONFIG_HT_OVERRIDES */ |
384 | | |
385 | | #ifdef CONFIG_VHT_OVERRIDES |
386 | | if (ssid && ssid->disable_vht) { |
387 | | if (op_class->op_class >= 128 && op_class->op_class <= 130) { |
388 | | /* Disable >= 80 MHz channels if VHT is disabled */ |
389 | | return 0; |
390 | | } |
391 | | } |
392 | | #endif /* CONFIG_VHT_OVERRIDES */ |
393 | | |
394 | 0 | if (op_class->op_class == 128) { |
395 | 0 | u8 channels[] = { 42, 58, 106, 122, 138, 155, 171 }; |
396 | |
|
397 | 0 | for (i = 0; i < ARRAY_SIZE(channels); i++) { |
398 | 0 | if (verify_channel(mode, op_class->op_class, |
399 | 0 | channels[i], op_class->bw) != |
400 | 0 | NOT_ALLOWED) |
401 | 0 | return 1; |
402 | 0 | } |
403 | | |
404 | 0 | return 0; |
405 | 0 | } |
406 | | |
407 | 0 | if (op_class->op_class == 129) { |
408 | | /* Check if either 160 MHz channels is allowed */ |
409 | 0 | return verify_channel(mode, op_class->op_class, 50, |
410 | 0 | op_class->bw) != NOT_ALLOWED || |
411 | 0 | verify_channel(mode, op_class->op_class, 114, |
412 | 0 | op_class->bw) != NOT_ALLOWED || |
413 | 0 | verify_channel(mode, op_class->op_class, 163, |
414 | 0 | op_class->bw) != NOT_ALLOWED; |
415 | 0 | } |
416 | | |
417 | 0 | if (op_class->op_class == 130) { |
418 | | /* Need at least two non-contiguous 80 MHz segments */ |
419 | 0 | found = 0; |
420 | |
|
421 | 0 | if (verify_channel(mode, op_class->op_class, 42, |
422 | 0 | op_class->bw) != NOT_ALLOWED || |
423 | 0 | verify_channel(mode, op_class->op_class, 58, |
424 | 0 | op_class->bw) != NOT_ALLOWED) |
425 | 0 | found++; |
426 | 0 | if (verify_channel(mode, op_class->op_class, 106, |
427 | 0 | op_class->bw) != NOT_ALLOWED || |
428 | 0 | verify_channel(mode, op_class->op_class, 122, |
429 | 0 | op_class->bw) != NOT_ALLOWED || |
430 | 0 | verify_channel(mode, op_class->op_class, 138, |
431 | 0 | op_class->bw) != NOT_ALLOWED || |
432 | 0 | verify_channel(mode, op_class->op_class, 155, |
433 | 0 | op_class->bw) != NOT_ALLOWED || |
434 | 0 | verify_channel(mode, op_class->op_class, 171, |
435 | 0 | op_class->bw) != NOT_ALLOWED) |
436 | 0 | found++; |
437 | 0 | if (verify_channel(mode, op_class->op_class, 106, |
438 | 0 | op_class->bw) != NOT_ALLOWED && |
439 | 0 | verify_channel(mode, op_class->op_class, 138, |
440 | 0 | op_class->bw) != NOT_ALLOWED) |
441 | 0 | found++; |
442 | 0 | if (verify_channel(mode, op_class->op_class, 122, |
443 | 0 | op_class->bw) != NOT_ALLOWED && |
444 | 0 | verify_channel(mode, op_class->op_class, 155, |
445 | 0 | op_class->bw) != NOT_ALLOWED) |
446 | 0 | found++; |
447 | 0 | if (verify_channel(mode, op_class->op_class, 138, |
448 | 0 | op_class->bw) != NOT_ALLOWED && |
449 | 0 | verify_channel(mode, op_class->op_class, 171, |
450 | 0 | op_class->bw) != NOT_ALLOWED) |
451 | 0 | found++; |
452 | |
|
453 | 0 | if (found >= 2) |
454 | 0 | return 1; |
455 | | |
456 | 0 | return 0; |
457 | 0 | } |
458 | | |
459 | 0 | if (op_class->op_class == 135) { |
460 | | /* Need at least two 80 MHz segments which do not fall under the |
461 | | * same 160 MHz segment to support 80+80 in 6 GHz. |
462 | | */ |
463 | 0 | int first_seg = 0; |
464 | 0 | int curr_seg = 0; |
465 | |
|
466 | 0 | for (chan = op_class->min_chan; chan <= op_class->max_chan; |
467 | 0 | chan += op_class->inc) { |
468 | 0 | curr_seg++; |
469 | 0 | if (verify_channel(mode, op_class->op_class, chan, |
470 | 0 | op_class->bw) != NOT_ALLOWED) { |
471 | 0 | if (!first_seg) { |
472 | 0 | first_seg = curr_seg; |
473 | 0 | continue; |
474 | 0 | } |
475 | | |
476 | | /* Supported if at least two non-consecutive 80 |
477 | | * MHz segments allowed. |
478 | | */ |
479 | 0 | if ((curr_seg - first_seg) > 1) |
480 | 0 | return 1; |
481 | | |
482 | | /* Supported even if the 80 MHz segments are |
483 | | * consecutive when they do not fall under the |
484 | | * same 160 MHz segment. |
485 | | */ |
486 | 0 | if ((first_seg % 2) == 0) |
487 | 0 | return 1; |
488 | 0 | } |
489 | 0 | } |
490 | | |
491 | 0 | return 0; |
492 | 0 | } |
493 | | |
494 | 0 | found = 0; |
495 | 0 | for (chan = op_class->min_chan; chan <= op_class->max_chan; |
496 | 0 | chan += op_class->inc) { |
497 | 0 | if (verify_channel(mode, op_class->op_class, chan, |
498 | 0 | op_class->bw) != NOT_ALLOWED) { |
499 | 0 | found = 1; |
500 | 0 | break; |
501 | 0 | } |
502 | 0 | } |
503 | |
|
504 | 0 | return found; |
505 | 0 | } |
506 | | |
507 | | |
508 | | static int wpas_sta_secondary_channel_offset(struct wpa_bss *bss, u8 *current, |
509 | | u8 *channel) |
510 | 0 | { |
511 | |
|
512 | 0 | const u8 *ies; |
513 | 0 | u8 phy_type; |
514 | 0 | size_t ies_len; |
515 | |
|
516 | 0 | if (!bss) |
517 | 0 | return -1; |
518 | 0 | ies = wpa_bss_ie_ptr(bss); |
519 | 0 | ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
520 | 0 | return wpas_get_op_chan_phy(bss->freq, ies, ies_len, current, |
521 | 0 | channel, &phy_type); |
522 | 0 | } |
523 | | |
524 | | |
525 | | size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s, |
526 | | struct wpa_ssid *ssid, |
527 | | struct wpa_bss *bss, u8 *pos, size_t len) |
528 | 0 | { |
529 | 0 | struct wpabuf *buf; |
530 | 0 | u8 op, current, chan; |
531 | 0 | u8 *ie_len; |
532 | 0 | size_t res; |
533 | 0 | bool op128 = false, op130 = false, op133 = false, op135 = false; |
534 | 0 | bool disable_op_classes_80_80_mhz = wpa_s->conf ? |
535 | 0 | wpa_s->conf->disable_op_classes_80_80_mhz : false; |
536 | | |
537 | | /* |
538 | | * Determine the current operating class correct mode based on |
539 | | * advertised BSS capabilities, if available. Fall back to a less |
540 | | * accurate guess based on frequency if the needed IEs are not available |
541 | | * or used. |
542 | | */ |
543 | 0 | if (wpas_sta_secondary_channel_offset(bss, ¤t, &chan) < 0 && |
544 | 0 | ieee80211_freq_to_channel_ext(bss->freq, 0, |
545 | 0 | CONF_OPER_CHWIDTH_USE_HT, ¤t, |
546 | 0 | &chan) == NUM_HOSTAPD_MODES) |
547 | 0 | return 0; |
548 | | |
549 | | /* |
550 | | * Need 3 bytes for EID, length, and current operating class, plus |
551 | | * 1 byte for every other supported operating class. |
552 | | */ |
553 | 0 | buf = wpabuf_alloc(global_op_class_size + 3); |
554 | 0 | if (!buf) |
555 | 0 | return 0; |
556 | | |
557 | 0 | wpabuf_put_u8(buf, WLAN_EID_SUPPORTED_OPERATING_CLASSES); |
558 | | /* Will set the length later, putting a placeholder */ |
559 | 0 | ie_len = wpabuf_put(buf, 1); |
560 | 0 | wpabuf_put_u8(buf, current); |
561 | |
|
562 | 0 | for (op = 0; global_op_class[op].op_class; op++) { |
563 | 0 | bool supp; |
564 | 0 | u8 op_class = global_op_class[op].op_class; |
565 | |
|
566 | 0 | supp = wpas_op_class_supported(wpa_s, ssid, |
567 | 0 | &global_op_class[op]); |
568 | 0 | if (!supp) |
569 | 0 | continue; |
570 | 0 | switch (op_class) { |
571 | 0 | case 128: |
572 | 0 | op128 = true; |
573 | 0 | break; |
574 | 0 | case 130: |
575 | 0 | op130 = true; |
576 | 0 | break; |
577 | 0 | case 133: |
578 | 0 | op133 = true; |
579 | 0 | break; |
580 | 0 | case 135: |
581 | 0 | op135 = true; |
582 | 0 | break; |
583 | 0 | } |
584 | 0 | if (is_80plus_op_class(op_class)) |
585 | 0 | continue; |
586 | | |
587 | | /* Add a 1-octet operating class to the Operating Class field */ |
588 | 0 | wpabuf_put_u8(buf, global_op_class[op].op_class); |
589 | 0 | } |
590 | | |
591 | | /* Add the 2-octet operating classes (i.e., 80+80 MHz cases), if any */ |
592 | 0 | if (!disable_op_classes_80_80_mhz && |
593 | 0 | ((op128 && op130) || (op133 && op135))) { |
594 | | /* Operating Class Duple Sequence field */ |
595 | | |
596 | | /* Zero Delimiter */ |
597 | 0 | wpabuf_put_u8(buf, 0); |
598 | | |
599 | | /* Operating Class Duple List */ |
600 | 0 | if (op128 && op130) { |
601 | 0 | wpabuf_put_u8(buf, 130); |
602 | 0 | wpabuf_put_u8(buf, 128); |
603 | 0 | } |
604 | 0 | if (op133 && op135) { |
605 | 0 | wpabuf_put_u8(buf, 135); |
606 | 0 | wpabuf_put_u8(buf, 133); |
607 | 0 | } |
608 | 0 | } |
609 | |
|
610 | 0 | *ie_len = wpabuf_len(buf) - 2; |
611 | 0 | if (*ie_len < 2) { |
612 | 0 | wpa_printf(MSG_DEBUG, |
613 | 0 | "No supported operating classes IE to add"); |
614 | 0 | res = 0; |
615 | 0 | } else if (wpabuf_len(buf) > len) { |
616 | 0 | wpa_printf(MSG_ERROR, |
617 | 0 | "Supported operating classes IE exceeds maximum buffer length"); |
618 | 0 | res = 0; |
619 | 0 | } else { |
620 | 0 | os_memcpy(pos, wpabuf_head(buf), wpabuf_len(buf)); |
621 | 0 | res = wpabuf_len(buf); |
622 | 0 | wpa_hexdump_buf(MSG_DEBUG, |
623 | 0 | "Added supported operating classes IE", buf); |
624 | 0 | } |
625 | |
|
626 | 0 | wpabuf_free(buf); |
627 | 0 | return res; |
628 | 0 | } |
629 | | |
630 | | |
631 | | int * wpas_supp_op_classes(struct wpa_supplicant *wpa_s) |
632 | 0 | { |
633 | 0 | int op; |
634 | 0 | unsigned int pos, max_num = 0; |
635 | 0 | int *classes; |
636 | |
|
637 | 0 | for (op = 0; global_op_class[op].op_class; op++) |
638 | 0 | max_num++; |
639 | 0 | classes = os_zalloc((max_num + 1) * sizeof(int)); |
640 | 0 | if (!classes) |
641 | 0 | return NULL; |
642 | | |
643 | 0 | for (op = 0, pos = 0; global_op_class[op].op_class; op++) { |
644 | 0 | if (wpas_op_class_supported(wpa_s, NULL, &global_op_class[op])) |
645 | 0 | classes[pos++] = global_op_class[op].op_class; |
646 | 0 | } |
647 | |
|
648 | 0 | return classes; |
649 | 0 | } |