]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/mbo.c
Fix a typo in QCA vendor attribution documentation
[thirdparty/hostap.git] / wpa_supplicant / mbo.c
CommitLineData
92c6e2e3
DS
1/*
2 * wpa_supplicant - MBO
3 *
4 * Copyright(c) 2015 Intel Deutschland GmbH
5 * Contact Information:
6 * Intel Linux Wireless <ilw@linux.intel.com>
7 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
8 *
9 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
11 */
12
13#include "utils/includes.h"
14
15#include "utils/common.h"
16#include "common/ieee802_11_defs.h"
17#include "config.h"
18#include "wpa_supplicant_i.h"
19#include "driver_i.h"
20#include "bss.h"
21
22/* type + length + oui + oui type */
23#define MBO_IE_HEADER 6
24
25
26static int wpas_mbo_validate_non_pref_chan(u8 oper_class, u8 chan, u8 reason)
27{
28 if (reason > MBO_NON_PREF_CHAN_REASON_INT_INTERFERENCE)
29 return -1;
30
31 /* Only checking the validity of the channel and oper_class */
32 if (ieee80211_chan_to_freq(NULL, oper_class, chan) == -1)
33 return -1;
34
35 return 0;
36}
37
38
cb06cf34
DS
39const u8 * wpas_mbo_get_bss_attr(struct wpa_bss *bss, enum mbo_attr_id attr)
40{
41 const u8 *mbo, *end;
42
43 if (!bss)
44 return NULL;
45
46 mbo = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE);
47 if (!mbo)
48 return NULL;
49
50 end = mbo + 2 + mbo[1];
51 mbo += MBO_IE_HEADER;
52
53 return get_ie(mbo, end - mbo, attr);
54}
55
56
92c6e2e3
DS
57static void wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant *wpa_s,
58 struct wpabuf *mbo,
59 u8 start, u8 end)
60{
61 u8 i;
62
63 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].oper_class);
64
65 for (i = start; i < end; i++)
66 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[i].chan);
67
68 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].preference);
69 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason);
70 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason_detail);
71}
72
73
74static void wpas_mbo_non_pref_chan_attr(struct wpa_supplicant *wpa_s,
75 struct wpabuf *mbo, u8 start, u8 end)
76{
77 size_t size = end - start + 4;
78
79 if (size + 2 > wpabuf_tailroom(mbo))
80 return;
81
82 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
83 wpabuf_put_u8(mbo, size); /* Length */
84
85 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
86}
87
88
2d5b8614
DS
89static void wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf *mbo, u8 len)
90{
91 wpabuf_put_u8(mbo, WLAN_EID_VENDOR_SPECIFIC);
92 wpabuf_put_u8(mbo, len); /* Length */
93 wpabuf_put_be24(mbo, OUI_WFA);
94 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
95}
96
97
98static void wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant *wpa_s,
99 struct wpabuf *mbo, u8 start,
100 u8 end)
101{
102 size_t size = end - start + 8;
103
104 if (size + 2 > wpabuf_tailroom(mbo))
105 return;
106
107 wpas_mbo_non_pref_chan_subelem_hdr(mbo, size);
108 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
109}
110
92c6e2e3 111
2d5b8614
DS
112static void wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant *wpa_s,
113 struct wpabuf *mbo, int subelement)
92c6e2e3
DS
114{
115 u8 i, start = 0;
116 struct wpa_mbo_non_pref_channel *start_pref;
117
2d5b8614
DS
118 if (!wpa_s->non_pref_chan || !wpa_s->non_pref_chan_num) {
119 if (subelement)
120 wpas_mbo_non_pref_chan_subelem_hdr(mbo, 4);
92c6e2e3 121 return;
2d5b8614 122 }
92c6e2e3
DS
123 start_pref = &wpa_s->non_pref_chan[0];
124
125 for (i = 1; i <= wpa_s->non_pref_chan_num; i++) {
126 struct wpa_mbo_non_pref_channel *non_pref = NULL;
127
128 if (i < wpa_s->non_pref_chan_num)
129 non_pref = &wpa_s->non_pref_chan[i];
130 if (!non_pref ||
131 non_pref->oper_class != start_pref->oper_class ||
132 non_pref->reason != start_pref->reason ||
133 non_pref->reason_detail != start_pref->reason_detail ||
134 non_pref->preference != start_pref->preference) {
2d5b8614
DS
135 if (subelement)
136 wpas_mbo_non_pref_chan_subelement(wpa_s, mbo,
137 start, i);
138 else
139 wpas_mbo_non_pref_chan_attr(wpa_s, mbo, start,
140 i);
92c6e2e3
DS
141
142 if (!non_pref)
143 return;
144
145 start = i;
146 start_pref = non_pref;
147 }
148 }
149}
150
151
152int wpas_mbo_ie(struct wpa_supplicant *wpa_s, u8 *buf, size_t len)
153{
154 struct wpabuf *mbo;
155 int res;
156
c5d193d7 157 if (len < MBO_IE_HEADER + 3 + 7)
92c6e2e3
DS
158 return 0;
159
160 /* Leave room for the MBO IE header */
161 mbo = wpabuf_alloc(len - MBO_IE_HEADER);
162 if (!mbo)
163 return 0;
164
165 /* Add non-preferred channels attribute */
2d5b8614 166 wpas_mbo_non_pref_chan_attrs(wpa_s, mbo, 0);
92c6e2e3 167
c5d193d7
DS
168 /*
169 * Send cellular capabilities attribute even if AP does not advertise
170 * cellular capabilities.
171 */
172 wpabuf_put_u8(mbo, MBO_ATTR_ID_CELL_DATA_CAPA);
173 wpabuf_put_u8(mbo, 1);
174 wpabuf_put_u8(mbo, wpa_s->conf->mbo_cell_capa);
175
92c6e2e3
DS
176 res = mbo_add_ie(buf, len, wpabuf_head_u8(mbo), wpabuf_len(mbo));
177 if (!res)
178 wpa_printf(MSG_ERROR, "Failed to add MBO IE");
179
180 wpabuf_free(mbo);
181 return res;
182}
183
184
016082e9
AS
185static void wpas_mbo_send_wnm_notification(struct wpa_supplicant *wpa_s,
186 const u8 *data, size_t len)
2d5b8614
DS
187{
188 struct wpabuf *buf;
189 int res;
190
191 /*
192 * Send WNM-Notification Request frame only in case of a change in
193 * non-preferred channels list during association, if the AP supports
194 * MBO.
195 */
196 if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_bss ||
197 !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
198 return;
199
016082e9 200 buf = wpabuf_alloc(4 + len);
2d5b8614
DS
201 if (!buf)
202 return;
203
204 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
205 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
206 wpa_s->mbo_wnm_token++;
207 if (wpa_s->mbo_wnm_token == 0)
208 wpa_s->mbo_wnm_token++;
209 wpabuf_put_u8(buf, wpa_s->mbo_wnm_token);
210 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); /* Type */
211
016082e9 212 wpabuf_put_data(buf, data, len);
2d5b8614
DS
213
214 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
215 wpa_s->own_addr, wpa_s->bssid,
216 wpabuf_head(buf), wpabuf_len(buf), 0);
217 if (res < 0)
218 wpa_printf(MSG_DEBUG,
219 "Failed to send WNM-Notification Request frame with non-preferred channel list");
220
221 wpabuf_free(buf);
222}
223
224
016082e9
AS
225static void wpas_mbo_non_pref_chan_changed(struct wpa_supplicant *wpa_s)
226{
227 struct wpabuf *buf;
228
229 buf = wpabuf_alloc(512);
230 if (!buf)
231 return;
232
233 wpas_mbo_non_pref_chan_attrs(wpa_s, buf, 1);
234 wpas_mbo_send_wnm_notification(wpa_s, wpabuf_head_u8(buf),
235 wpabuf_len(buf));
236 wpabuf_free(buf);
237}
238
239
92c6e2e3
DS
240static int wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel *a,
241 struct wpa_mbo_non_pref_channel *b)
242{
243 return a->oper_class == b->oper_class && a->chan == b->chan;
244}
245
246
247/*
248 * wpa_non_pref_chan_cmp - Compare two channels for sorting
249 *
250 * In MBO IE non-preferred channel subelement we can put many channels in an
251 * attribute if they are in the same operating class and have the same
252 * preference, reason, and reason detail. To make it easy for the functions that
253 * build the IE attributes and WNM Request subelements, save the channels sorted
254 * by their oper_class, reason, and reason_detail.
255 */
256static int wpa_non_pref_chan_cmp(const void *_a, const void *_b)
257{
258 const struct wpa_mbo_non_pref_channel *a = _a, *b = _b;
259
260 if (a->oper_class != b->oper_class)
261 return a->oper_class - b->oper_class;
262 if (a->reason != b->reason)
263 return a->reason - b->reason;
264 if (a->reason_detail != b->reason_detail)
265 return a->reason_detail - b->reason_detail;
266 return a->preference - b->preference;
267}
268
269
270int wpas_mbo_update_non_pref_chan(struct wpa_supplicant *wpa_s,
271 const char *non_pref_chan)
272{
273 char *cmd, *token, *context = NULL;
274 struct wpa_mbo_non_pref_channel *chans = NULL, *tmp_chans;
275 size_t num = 0, size = 0;
276 unsigned i;
277
278 wpa_printf(MSG_DEBUG, "MBO: Update non-preferred channels, non_pref_chan=%s",
279 non_pref_chan ? non_pref_chan : "N/A");
280
281 /*
282 * The shortest channel configuration is 10 characters - commas, 3
283 * colons, and 4 values that one of them (oper_class) is 2 digits or
284 * more.
285 */
286 if (!non_pref_chan || os_strlen(non_pref_chan) < 10)
287 goto update;
288
289 cmd = os_strdup(non_pref_chan);
290 if (!cmd)
291 return -1;
292
293 while ((token = str_token(cmd, " ", &context))) {
294 struct wpa_mbo_non_pref_channel *chan;
295 int ret;
296 unsigned int _oper_class;
297 unsigned int _chan;
298 unsigned int _preference;
299 unsigned int _reason;
300 unsigned int _reason_detail;
301
302 if (num == size) {
303 size = size ? size * 2 : 1;
304 tmp_chans = os_realloc_array(chans, size,
305 sizeof(*chans));
306 if (!tmp_chans) {
307 wpa_printf(MSG_ERROR,
308 "Couldn't reallocate non_pref_chan");
309 goto fail;
310 }
311 chans = tmp_chans;
312 }
313
314 chan = &chans[num];
315
316 ret = sscanf(token, "%u:%u:%u:%u:%u", &_oper_class,
317 &_chan, &_preference, &_reason,
318 &_reason_detail);
319 if ((ret != 4 && ret != 5) ||
320 _oper_class > 255 || _chan > 255 ||
321 _preference > 255 || _reason > 65535 ||
322 (ret == 5 && _reason_detail > 255)) {
323 wpa_printf(MSG_ERROR, "Invalid non-pref chan input %s",
324 token);
325 goto fail;
326 }
327 chan->oper_class = _oper_class;
328 chan->chan = _chan;
329 chan->preference = _preference;
330 chan->reason = _reason;
331 chan->reason_detail = ret == 4 ? 0 : _reason_detail;
332
333 if (wpas_mbo_validate_non_pref_chan(chan->oper_class,
334 chan->chan, chan->reason)) {
335 wpa_printf(MSG_ERROR,
336 "Invalid non_pref_chan: oper class %d chan %d reason %d",
337 chan->oper_class, chan->chan, chan->reason);
338 goto fail;
339 }
340
341 for (i = 0; i < num; i++)
342 if (wpa_non_pref_chan_is_eq(chan, &chans[i]))
343 break;
344 if (i != num) {
345 wpa_printf(MSG_ERROR,
346 "oper class %d chan %d is duplicated",
347 chan->oper_class, chan->chan);
348 goto fail;
349 }
350
351 num++;
352 }
353
354 os_free(cmd);
355
356 if (chans) {
357 qsort(chans, num, sizeof(struct wpa_mbo_non_pref_channel),
358 wpa_non_pref_chan_cmp);
359 }
360
361update:
362 os_free(wpa_s->non_pref_chan);
363 wpa_s->non_pref_chan = chans;
364 wpa_s->non_pref_chan_num = num;
016082e9 365 wpas_mbo_non_pref_chan_changed(wpa_s);
92c6e2e3
DS
366
367 return 0;
368
369fail:
370 os_free(chans);
371 os_free(cmd);
372 return -1;
373}
c5d193d7
DS
374
375
376void wpas_mbo_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ie)
377{
378 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
379 wpabuf_put_u8(ie, 7);
380 wpabuf_put_be24(ie, OUI_WFA);
381 wpabuf_put_u8(ie, MBO_OUI_TYPE);
382
383 wpabuf_put_u8(ie, MBO_ATTR_ID_CELL_DATA_CAPA);
384 wpabuf_put_u8(ie, 1);
385 wpabuf_put_u8(ie, wpa_s->conf->mbo_cell_capa);
386}
5e57ba25
AS
387
388
389enum chan_allowed {
390 NOT_ALLOWED, ALLOWED
391};
392
393static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode, u8 chan,
394 unsigned int *flags)
395{
396 int i;
397
398 for (i = 0; i < mode->num_channels; i++) {
399 if (mode->channels[i].chan == chan)
400 break;
401 }
402
403 if (i == mode->num_channels ||
404 (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED))
405 return NOT_ALLOWED;
406
407 if (flags)
408 *flags = mode->channels[i].flag;
409
410 return ALLOWED;
411}
412
413
414static int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel)
415{
416 u8 center_channels[] = {42, 58, 106, 122, 138, 155};
417 size_t i;
418
419 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
420 return 0;
421
422 for (i = 0; i < ARRAY_SIZE(center_channels); i++) {
423 /*
424 * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48),
425 * so the center channel is 6 channels away from the start/end.
426 */
427 if (channel >= center_channels[i] - 6 &&
428 channel <= center_channels[i] + 6)
429 return center_channels[i];
430 }
431
432 return 0;
433}
434
435
436static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode, u8 channel)
437{
438 u8 center_chan;
439 unsigned int i;
440
441 center_chan = get_center_80mhz(mode, channel);
442 if (!center_chan)
443 return NOT_ALLOWED;
444
445 /* check all the channels are available */
446 for (i = 0; i < 4; i++) {
447 unsigned int flags;
448 u8 adj_chan = center_chan - 6 + i * 4;
449
450 if (allow_channel(mode, adj_chan, &flags) == NOT_ALLOWED)
451 return NOT_ALLOWED;
452
453 if ((i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70)) ||
454 (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50)) ||
455 (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30)) ||
456 (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10)))
457 return NOT_ALLOWED;
458 }
459
460 return ALLOWED;
461}
462
463
464static int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel)
465{
466 u8 center_channels[] = { 50, 114 };
467 unsigned int i;
468
469 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
470 return 0;
471
472 for (i = 0; i < ARRAY_SIZE(center_channels); i++) {
473 /*
474 * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64),
475 * so the center channel is 14 channels away from the start/end.
476 */
477 if (channel >= center_channels[i] - 14 &&
478 channel <= center_channels[i] + 14)
479 return center_channels[i];
480 }
481
482 return 0;
483}
484
485
486static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode,
487 u8 channel)
488{
489 u8 center_chan;
490 unsigned int i;
491
492 center_chan = get_center_160mhz(mode, channel);
493 if (!center_chan)
494 return NOT_ALLOWED;
495
496 /* Check all the channels are available */
497 for (i = 0; i < 8; i++) {
498 unsigned int flags;
499 u8 adj_chan = center_chan - 14 + i * 4;
500
501 if (allow_channel(mode, adj_chan, &flags) == NOT_ALLOWED)
502 return NOT_ALLOWED;
503
504 if ((i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_150)) ||
505 (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_130)) ||
506 (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_110)) ||
507 (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_90)) ||
508 (i == 4 && !(flags & HOSTAPD_CHAN_VHT_90_70)) ||
509 (i == 5 && !(flags & HOSTAPD_CHAN_VHT_110_50)) ||
510 (i == 6 && !(flags & HOSTAPD_CHAN_VHT_130_30)) ||
511 (i == 7 && !(flags & HOSTAPD_CHAN_VHT_150_10)))
512 return NOT_ALLOWED;
513 }
514
515 return ALLOWED;
516}
517
518
0558bec1
JM
519static enum chan_allowed verify_channel(struct hostapd_hw_modes *mode,
520 u8 channel, u8 bw)
5e57ba25
AS
521{
522 unsigned int flag = 0;
523 enum chan_allowed res, res2;
524
525 res2 = res = allow_channel(mode, channel, &flag);
526 if (bw == BW40MINUS) {
527 if (!(flag & HOSTAPD_CHAN_HT40MINUS))
528 return NOT_ALLOWED;
529 res2 = allow_channel(mode, channel - 4, NULL);
530 } else if (bw == BW40PLUS) {
531 if (!(flag & HOSTAPD_CHAN_HT40PLUS))
532 return NOT_ALLOWED;
533 res2 = allow_channel(mode, channel + 4, NULL);
534 } else if (bw == BW80) {
653d227e
JM
535 /*
536 * channel is a center channel and as such, not necessarily a
537 * valid 20 MHz channels. Override earlier allow_channel()
538 * result and use only the 80 MHz specific version.
539 */
540 res2 = res = verify_80mhz(mode, channel);
5e57ba25 541 } else if (bw == BW160) {
653d227e
JM
542 /*
543 * channel is a center channel and as such, not necessarily a
544 * valid 20 MHz channels. Override earlier allow_channel()
545 * result and use only the 160 MHz specific version.
546 */
547 res2 = res = verify_160mhz(mode, channel);
548 } else if (bw == BW80P80) {
549 /*
550 * channel is a center channel and as such, not necessarily a
551 * valid 20 MHz channels. Override earlier allow_channel()
552 * result and use only the 80 MHz specific version.
553 */
554 res2 = res = verify_80mhz(mode, channel);
5e57ba25
AS
555 }
556
557 if (res == NOT_ALLOWED || res2 == NOT_ALLOWED)
558 return NOT_ALLOWED;
559
560 return ALLOWED;
561}
562
563
564static int wpas_op_class_supported(struct wpa_supplicant *wpa_s,
565 const struct oper_class_map *op_class)
566{
567 int chan;
568 size_t i;
569 struct hostapd_hw_modes *mode;
653d227e 570 int found;
5e57ba25
AS
571
572 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, op_class->mode);
573 if (!mode)
574 return 0;
575
653d227e 576 if (op_class->op_class == 128) {
5e57ba25
AS
577 u8 channels[] = { 42, 58, 106, 122, 138, 155 };
578
579 for (i = 0; i < ARRAY_SIZE(channels); i++) {
580 if (verify_channel(mode, channels[i], op_class->bw) ==
653d227e
JM
581 ALLOWED)
582 return 1;
5e57ba25
AS
583 }
584
653d227e 585 return 0;
5e57ba25
AS
586 }
587
588 if (op_class->op_class == 129) {
653d227e
JM
589 /* Check if either 160 MHz channels is allowed */
590 return verify_channel(mode, 50, op_class->bw) == ALLOWED ||
591 verify_channel(mode, 114, op_class->bw) == ALLOWED;
592 }
593
594 if (op_class->op_class == 130) {
595 /* Need at least two non-contiguous 80 MHz segments */
596 found = 0;
597
598 if (verify_channel(mode, 42, op_class->bw) == ALLOWED ||
599 verify_channel(mode, 58, op_class->bw) == ALLOWED)
600 found++;
601 if (verify_channel(mode, 106, op_class->bw) == ALLOWED ||
602 verify_channel(mode, 122, op_class->bw) == ALLOWED ||
603 verify_channel(mode, 138, op_class->bw) == ALLOWED)
604 found++;
605 if (verify_channel(mode, 106, op_class->bw) == ALLOWED &&
606 verify_channel(mode, 138, op_class->bw) == ALLOWED)
607 found++;
608 if (verify_channel(mode, 155, op_class->bw) == ALLOWED)
609 found++;
610
611 if (found >= 2)
612 return 1;
5e57ba25 613
653d227e 614 return 0;
5e57ba25
AS
615 }
616
653d227e 617 found = 0;
5e57ba25
AS
618 for (chan = op_class->min_chan; chan <= op_class->max_chan;
619 chan += op_class->inc) {
653d227e
JM
620 if (verify_channel(mode, chan, op_class->bw) == ALLOWED) {
621 found = 1;
622 break;
623 }
5e57ba25
AS
624 }
625
653d227e 626 return found;
5e57ba25
AS
627}
628
629
630int wpas_mbo_supp_op_class_ie(struct wpa_supplicant *wpa_s, int freq, u8 *pos,
631 size_t len)
632{
633 struct wpabuf *buf;
634 u8 op, current, chan;
635 u8 *ie_len;
636 int res;
637
638 /*
639 * Assume 20 MHz channel for now.
640 * TODO: Use the secondary channel and VHT channel width that will be
641 * used after association.
642 */
643 if (ieee80211_freq_to_channel_ext(freq, 0, VHT_CHANWIDTH_USE_HT,
644 &current, &chan) == NUM_HOSTAPD_MODES)
645 return 0;
646
647 /*
648 * Need 3 bytes for EID, length, and current operating class, plus
649 * 1 byte for every other supported operating class.
650 */
651 buf = wpabuf_alloc(global_op_class_size + 3);
652 if (!buf)
653 return 0;
654
655 wpabuf_put_u8(buf, WLAN_EID_SUPPORTED_OPERATING_CLASSES);
656 /* Will set the length later, putting a placeholder */
657 ie_len = wpabuf_put(buf, 1);
658 wpabuf_put_u8(buf, current);
659
660 for (op = 0; global_op_class[op].op_class; op++) {
661 if (wpas_op_class_supported(wpa_s, &global_op_class[op]))
662 wpabuf_put_u8(buf, global_op_class[op].op_class);
663 }
664
665 *ie_len = wpabuf_len(buf) - 2;
666 if (*ie_len < 2 || wpabuf_len(buf) > len) {
667 wpa_printf(MSG_ERROR,
668 "Failed to add supported operating classes IE");
669 res = 0;
670 } else {
671 os_memcpy(pos, wpabuf_head(buf), wpabuf_len(buf));
672 res = wpabuf_len(buf);
673 wpa_hexdump_buf(MSG_DEBUG,
674 "MBO: Added supported operating classes IE",
675 buf);
676 }
677
678 wpabuf_free(buf);
679 return res;
680}
dd599908
AS
681
682
683void wpas_mbo_ie_trans_req(struct wpa_supplicant *wpa_s, const u8 *mbo_ie,
684 size_t len)
685{
686 const u8 *pos, *cell_pref = NULL, *reason = NULL;
687 u8 id, elen;
688 u16 disallowed_sec = 0;
689
690 if (len <= 4 || WPA_GET_BE24(mbo_ie) != OUI_WFA ||
691 mbo_ie[3] != MBO_OUI_TYPE)
692 return;
693
694 pos = mbo_ie + 4;
695 len -= 4;
696
697 while (len >= 2) {
698 id = *pos++;
699 elen = *pos++;
700 len -= 2;
701
702 if (elen > len)
703 goto fail;
704
705 switch (id) {
706 case MBO_ATTR_ID_CELL_DATA_PREF:
707 if (elen != 1)
708 goto fail;
709
710 if (wpa_s->conf->mbo_cell_capa ==
711 MBO_CELL_CAPA_AVAILABLE)
712 cell_pref = pos;
713 else
714 wpa_printf(MSG_DEBUG,
715 "MBO: Station does not support Cellular data connection");
716 break;
717 case MBO_ATTR_ID_TRANSITION_REASON:
718 if (elen != 1)
719 goto fail;
720
721 reason = pos;
722 break;
723 case MBO_ATTR_ID_ASSOC_RETRY_DELAY:
724 if (elen != 2)
725 goto fail;
726
727 if (wpa_s->wnm_mode &
728 WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
729 wpa_printf(MSG_DEBUG,
730 "MBO: Unexpected association retry delay, BSS is terminating");
731 goto fail;
732 } else if (wpa_s->wnm_mode &
733 WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
734 disallowed_sec = WPA_GET_LE16(pos);
735 } else {
736 wpa_printf(MSG_DEBUG,
737 "MBO: Association retry delay attribute not in disassoc imminent mode");
738 }
739
740 break;
741 case MBO_ATTR_ID_AP_CAPA_IND:
742 case MBO_ATTR_ID_NON_PREF_CHAN_REPORT:
743 case MBO_ATTR_ID_CELL_DATA_CAPA:
744 case MBO_ATTR_ID_ASSOC_DISALLOW:
745 case MBO_ATTR_ID_TRANSITION_REJECT_REASON:
746 wpa_printf(MSG_DEBUG,
747 "MBO: Attribute %d should not be included in BTM Request frame",
748 id);
749 break;
750 default:
751 wpa_printf(MSG_DEBUG, "MBO: Unknown attribute id %u",
752 id);
753 return;
754 }
755
756 pos += elen;
757 len -= elen;
758 }
759
760 if (cell_pref)
761 wpa_msg(wpa_s, MSG_INFO, MBO_CELL_PREFERENCE "preference=%u",
762 *cell_pref);
763
764 if (reason)
765 wpa_msg(wpa_s, MSG_INFO, MBO_TRANSITION_REASON "reason=%u",
766 *reason);
767
768 if (disallowed_sec && wpa_s->current_bss)
769 wpa_bss_tmp_disallow(wpa_s, wpa_s->current_bss->bssid,
770 disallowed_sec);
771
772 return;
773fail:
774 wpa_printf(MSG_DEBUG, "MBO IE parsing failed (id=%u len=%u left=%zu)",
775 id, elen, len);
776}
c8082d2b
AS
777
778
779size_t wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant *wpa_s, u8 *pos,
780 size_t len,
781 enum mbo_transition_reject_reason reason)
782{
783 u8 reject_attr[3];
784
785 reject_attr[0] = MBO_ATTR_ID_TRANSITION_REJECT_REASON;
786 reject_attr[1] = 1;
787 reject_attr[2] = reason;
788
789 return mbo_add_ie(pos, len, reject_attr, sizeof(reject_attr));
790}
016082e9
AS
791
792
793void wpas_mbo_update_cell_capa(struct wpa_supplicant *wpa_s, u8 mbo_cell_capa)
794{
795 u8 cell_capa[7];
796
797 if (wpa_s->conf->mbo_cell_capa == mbo_cell_capa) {
798 wpa_printf(MSG_DEBUG,
799 "MBO: Cellular capability already set to %u",
800 mbo_cell_capa);
801 return;
802 }
803
804 wpa_s->conf->mbo_cell_capa = mbo_cell_capa;
805
806 cell_capa[0] = WLAN_EID_VENDOR_SPECIFIC;
807 cell_capa[1] = 5; /* Length */
808 WPA_PUT_BE24(cell_capa + 2, OUI_WFA);
809 cell_capa[5] = MBO_ATTR_ID_CELL_DATA_CAPA;
810 cell_capa[6] = mbo_cell_capa;
811
812 wpas_mbo_send_wnm_notification(wpa_s, cell_capa, 7);
813}