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