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 "common/gas.h"
18 #include "rsn_supp/wpa.h"
19 #include "config.h"
20 #include "wpa_supplicant_i.h"
21 #include "driver_i.h"
22 #include "bss.h"
23 #include "scan.h"
24
25 /* type + length + oui + oui type */
26 #define MBO_IE_HEADER 6
27
28
wpas_mbo_validate_non_pref_chan(u8 oper_class,u8 chan,u8 reason)29 static int wpas_mbo_validate_non_pref_chan(u8 oper_class, u8 chan, u8 reason)
30 {
31 if (reason > MBO_NON_PREF_CHAN_REASON_INT_INTERFERENCE)
32 return -1;
33
34 /* Only checking the validity of the channel and oper_class */
35 if (ieee80211_chan_to_freq(NULL, oper_class, chan) == -1)
36 return -1;
37
38 return 0;
39 }
40
41
mbo_attr_from_mbo_ie(const u8 * mbo_ie,enum mbo_attr_id attr)42 const u8 * mbo_attr_from_mbo_ie(const u8 *mbo_ie, enum mbo_attr_id attr)
43 {
44 const u8 *mbo;
45 u8 ie_len = mbo_ie[1];
46
47 if (ie_len < MBO_IE_HEADER - 2)
48 return NULL;
49 mbo = mbo_ie + MBO_IE_HEADER;
50
51 return get_ie(mbo, 2 + ie_len - MBO_IE_HEADER, attr);
52 }
53
54
mbo_get_attr_from_ies(const u8 * ies,size_t ies_len,enum mbo_attr_id attr)55 const u8 * mbo_get_attr_from_ies(const u8 *ies, size_t ies_len,
56 enum mbo_attr_id attr)
57 {
58 const u8 *mbo_ie;
59
60 mbo_ie = get_vendor_ie(ies, ies_len, MBO_IE_VENDOR_TYPE);
61 if (!mbo_ie)
62 return NULL;
63
64 return mbo_attr_from_mbo_ie(mbo_ie, attr);
65 }
66
67
wpas_mbo_get_bss_attr(struct wpa_bss * bss,enum mbo_attr_id attr,bool beacon)68 static const u8 * wpas_mbo_get_bss_attr(struct wpa_bss *bss,
69 enum mbo_attr_id attr, bool beacon)
70 {
71 const u8 *mbo, *end;
72
73 if (!bss)
74 return NULL;
75
76 if (beacon)
77 mbo = wpa_bss_get_vendor_ie_beacon(bss, MBO_IE_VENDOR_TYPE);
78 else
79 mbo = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE);
80 if (!mbo)
81 return NULL;
82
83 end = mbo + 2 + mbo[1];
84 mbo += MBO_IE_HEADER;
85
86 return get_ie(mbo, end - mbo, attr);
87 }
88
89
wpas_mbo_check_assoc_disallow(struct wpa_bss * bss)90 const u8 * wpas_mbo_check_assoc_disallow(struct wpa_bss *bss)
91 {
92 const u8 *assoc_disallow;
93
94 assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW,
95 bss->beacon_newer);
96 if (assoc_disallow && assoc_disallow[1] >= 1)
97 return assoc_disallow;
98
99 return NULL;
100 }
101
102
wpas_mbo_check_pmf(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,struct wpa_ssid * ssid)103 void wpas_mbo_check_pmf(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
104 struct wpa_ssid *ssid)
105 {
106 const u8 *rsne, *mbo, *oce;
107 struct wpa_ie_data ie;
108
109 wpa_s->disable_mbo_oce = 0;
110 if (!bss)
111 return;
112 mbo = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND, false);
113 oce = wpas_mbo_get_bss_attr(bss, OCE_ATTR_ID_CAPA_IND, false);
114 if (!mbo && !oce)
115 return;
116 if (oce && oce[1] >= 1 && (oce[2] & OCE_IS_STA_CFON))
117 return; /* STA-CFON is not required to enable PMF */
118 rsne = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
119 if (!rsne || wpa_parse_wpa_ie(rsne, 2 + rsne[1], &ie) < 0)
120 return; /* AP is not using RSN */
121
122 if (!(ie.capabilities & WPA_CAPABILITY_MFPC))
123 wpa_s->disable_mbo_oce = 1; /* AP uses RSN without PMF */
124 if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION)
125 wpa_s->disable_mbo_oce = 1; /* STA uses RSN without PMF */
126 if (wpa_s->disable_mbo_oce)
127 wpa_printf(MSG_INFO,
128 "MBO: Disable MBO/OCE due to misbehaving AP not having enabled PMF");
129 }
130
131
wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,u8 start,u8 end)132 static void wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant *wpa_s,
133 struct wpabuf *mbo,
134 u8 start, u8 end)
135 {
136 u8 i;
137
138 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].oper_class);
139
140 for (i = start; i < end; i++)
141 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[i].chan);
142
143 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].preference);
144 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason);
145 }
146
147
wpas_mbo_non_pref_chan_attr_hdr(struct wpabuf * mbo,size_t size)148 static void wpas_mbo_non_pref_chan_attr_hdr(struct wpabuf *mbo, size_t size)
149 {
150 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
151 wpabuf_put_u8(mbo, size); /* Length */
152 }
153
154
wpas_mbo_non_pref_chan_attr(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,u8 start,u8 end)155 static void wpas_mbo_non_pref_chan_attr(struct wpa_supplicant *wpa_s,
156 struct wpabuf *mbo, u8 start, u8 end)
157 {
158 size_t size = end - start + 3;
159
160 if (size + 2 > wpabuf_tailroom(mbo))
161 return;
162
163 wpas_mbo_non_pref_chan_attr_hdr(mbo, size);
164 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
165 }
166
167
wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf * mbo,u8 len)168 static void wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf *mbo, u8 len)
169 {
170 wpabuf_put_u8(mbo, WLAN_EID_VENDOR_SPECIFIC);
171 wpabuf_put_u8(mbo, len); /* Length */
172 wpabuf_put_be24(mbo, OUI_WFA);
173 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
174 }
175
176
wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,u8 start,u8 end)177 static void wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant *wpa_s,
178 struct wpabuf *mbo, u8 start,
179 u8 end)
180 {
181 size_t size = end - start + 7;
182
183 if (size + 2 > wpabuf_tailroom(mbo))
184 return;
185
186 wpas_mbo_non_pref_chan_subelem_hdr(mbo, size);
187 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
188 }
189
190
wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,int subelement)191 static void wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant *wpa_s,
192 struct wpabuf *mbo, int subelement)
193 {
194 u8 i, start = 0;
195 struct wpa_mbo_non_pref_channel *start_pref;
196
197 if (!wpa_s->non_pref_chan || !wpa_s->non_pref_chan_num) {
198 if (subelement)
199 wpas_mbo_non_pref_chan_subelem_hdr(mbo, 4);
200 else
201 wpas_mbo_non_pref_chan_attr_hdr(mbo, 0);
202 return;
203 }
204 start_pref = &wpa_s->non_pref_chan[0];
205
206 for (i = 1; i <= wpa_s->non_pref_chan_num; i++) {
207 struct wpa_mbo_non_pref_channel *non_pref = NULL;
208
209 if (i < wpa_s->non_pref_chan_num)
210 non_pref = &wpa_s->non_pref_chan[i];
211 if (!non_pref ||
212 non_pref->oper_class != start_pref->oper_class ||
213 non_pref->reason != start_pref->reason ||
214 non_pref->preference != start_pref->preference) {
215 if (subelement)
216 wpas_mbo_non_pref_chan_subelement(wpa_s, mbo,
217 start, i);
218 else
219 wpas_mbo_non_pref_chan_attr(wpa_s, mbo, start,
220 i);
221
222 if (!non_pref)
223 return;
224
225 start = i;
226 start_pref = non_pref;
227 }
228 }
229 }
230
231
wpas_mbo_ie(struct wpa_supplicant * wpa_s,u8 * buf,size_t len,int add_oce_capa)232 int wpas_mbo_ie(struct wpa_supplicant *wpa_s, u8 *buf, size_t len,
233 int add_oce_capa)
234 {
235 struct wpabuf *mbo;
236 int res;
237
238 if (len < MBO_IE_HEADER + 3 + 7 +
239 ((wpa_s->enable_oce & OCE_STA) ? 3 : 0))
240 return 0;
241
242 /* Leave room for the MBO IE header */
243 mbo = wpabuf_alloc(len - MBO_IE_HEADER);
244 if (!mbo)
245 return 0;
246
247 /* Add non-preferred channels attribute */
248 wpas_mbo_non_pref_chan_attrs(wpa_s, mbo, 0);
249
250 /*
251 * Send cellular capabilities attribute even if AP does not advertise
252 * cellular capabilities.
253 */
254 wpabuf_put_u8(mbo, MBO_ATTR_ID_CELL_DATA_CAPA);
255 wpabuf_put_u8(mbo, 1);
256 wpabuf_put_u8(mbo, wpa_s->conf->mbo_cell_capa);
257
258 /* Add OCE capability indication attribute if OCE is enabled */
259 if ((wpa_s->enable_oce & OCE_STA) && add_oce_capa) {
260 wpabuf_put_u8(mbo, OCE_ATTR_ID_CAPA_IND);
261 wpabuf_put_u8(mbo, 1);
262 wpabuf_put_u8(mbo, OCE_RELEASE);
263 }
264
265 res = mbo_add_ie(buf, len, wpabuf_head_u8(mbo), wpabuf_len(mbo));
266 if (!res)
267 wpa_printf(MSG_ERROR, "Failed to add MBO/OCE IE");
268
269 wpabuf_free(mbo);
270 return res;
271 }
272
273
274 #ifdef CONFIG_WNM
wpas_mbo_send_wnm_notification(struct wpa_supplicant * wpa_s,const u8 * data,size_t len)275 static void wpas_mbo_send_wnm_notification(struct wpa_supplicant *wpa_s,
276 const u8 *data, size_t len)
277 {
278 struct wpabuf *buf;
279 int res;
280
281 /*
282 * Send WNM-Notification Request frame only in case of a change in
283 * non-preferred channels list during association, if the AP supports
284 * MBO.
285 */
286 if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_bss ||
287 !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
288 return;
289
290 buf = wpabuf_alloc(4 + len);
291 if (!buf)
292 return;
293
294 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
295 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
296 wpa_s->mbo_wnm_token++;
297 if (wpa_s->mbo_wnm_token == 0)
298 wpa_s->mbo_wnm_token++;
299 wpabuf_put_u8(buf, wpa_s->mbo_wnm_token);
300 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); /* Type */
301
302 wpabuf_put_data(buf, data, len);
303
304 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
305 wpa_s->own_addr, wpa_s->bssid,
306 wpabuf_head(buf), wpabuf_len(buf), 0);
307 if (res < 0)
308 wpa_printf(MSG_DEBUG,
309 "Failed to send WNM-Notification Request frame with non-preferred channel list");
310
311 wpabuf_free(buf);
312 }
313 #endif /* CONFIG_WNM */
314
315
wpas_mbo_non_pref_chan_changed(struct wpa_supplicant * wpa_s)316 static void wpas_mbo_non_pref_chan_changed(struct wpa_supplicant *wpa_s)
317 {
318 struct wpabuf *buf;
319
320 buf = wpabuf_alloc(512);
321 if (!buf)
322 return;
323
324 wpas_mbo_non_pref_chan_attrs(wpa_s, buf, 1);
325 #ifdef CONFIG_WNM
326 wpas_mbo_send_wnm_notification(wpa_s, wpabuf_head_u8(buf),
327 wpabuf_len(buf));
328 #endif /* CONFIG_WNM */
329 wpas_update_mbo_connect_params(wpa_s);
330 wpabuf_free(buf);
331 }
332
333
wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel * a,struct wpa_mbo_non_pref_channel * b)334 static int wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel *a,
335 struct wpa_mbo_non_pref_channel *b)
336 {
337 return a->oper_class == b->oper_class && a->chan == b->chan;
338 }
339
340
341 /*
342 * wpa_non_pref_chan_cmp - Compare two channels for sorting
343 *
344 * In MBO IE non-preferred channel subelement we can put many channels in an
345 * attribute if they are in the same operating class and have the same
346 * preference and reason. To make it easy for the functions that build
347 * the IE attributes and WNM Request subelements, save the channels sorted
348 * by their oper_class and reason.
349 */
wpa_non_pref_chan_cmp(const void * _a,const void * _b)350 static int wpa_non_pref_chan_cmp(const void *_a, const void *_b)
351 {
352 const struct wpa_mbo_non_pref_channel *a = _a, *b = _b;
353
354 if (a->oper_class != b->oper_class)
355 return (int) a->oper_class - (int) b->oper_class;
356 if (a->reason != b->reason)
357 return (int) a->reason - (int) b->reason;
358 return (int) a->preference - (int) b->preference;
359 }
360
361
wpas_mbo_update_non_pref_chan(struct wpa_supplicant * wpa_s,const char * non_pref_chan)362 int wpas_mbo_update_non_pref_chan(struct wpa_supplicant *wpa_s,
363 const char *non_pref_chan)
364 {
365 char *cmd, *token, *context = NULL;
366 struct wpa_mbo_non_pref_channel *chans = NULL, *tmp_chans;
367 size_t num = 0, size = 0;
368 unsigned i;
369
370 wpa_printf(MSG_DEBUG, "MBO: Update non-preferred channels, non_pref_chan=%s",
371 non_pref_chan ? non_pref_chan : "N/A");
372
373 /*
374 * The shortest channel configuration is 7 characters - 3 colons and
375 * 4 values.
376 */
377 if (!non_pref_chan || os_strlen(non_pref_chan) < 7)
378 goto update;
379
380 cmd = os_strdup(non_pref_chan);
381 if (!cmd)
382 return -1;
383
384 while ((token = str_token(cmd, " ", &context))) {
385 struct wpa_mbo_non_pref_channel *chan;
386 int ret;
387 unsigned int _oper_class;
388 unsigned int _chan;
389 unsigned int _preference;
390 unsigned int _reason;
391
392 if (num == size) {
393 size = size ? size * 2 : 1;
394 tmp_chans = os_realloc_array(chans, size,
395 sizeof(*chans));
396 if (!tmp_chans) {
397 wpa_printf(MSG_ERROR,
398 "Couldn't reallocate non_pref_chan");
399 goto fail;
400 }
401 chans = tmp_chans;
402 }
403
404 chan = &chans[num];
405
406 ret = sscanf(token, "%u:%u:%u:%u", &_oper_class,
407 &_chan, &_preference, &_reason);
408 if (ret != 4 ||
409 _oper_class > 255 || _chan > 255 ||
410 _preference > 255 || _reason > 65535 ) {
411 wpa_printf(MSG_ERROR, "Invalid non-pref chan input %s",
412 token);
413 goto fail;
414 }
415 chan->oper_class = _oper_class;
416 chan->chan = _chan;
417 chan->preference = _preference;
418 chan->reason = _reason;
419
420 if (wpas_mbo_validate_non_pref_chan(chan->oper_class,
421 chan->chan, chan->reason)) {
422 wpa_printf(MSG_ERROR,
423 "Invalid non_pref_chan: oper class %d chan %d reason %d",
424 chan->oper_class, chan->chan, chan->reason);
425 goto fail;
426 }
427
428 for (i = 0; i < num; i++)
429 if (wpa_non_pref_chan_is_eq(chan, &chans[i]))
430 break;
431 if (i != num) {
432 wpa_printf(MSG_ERROR,
433 "oper class %d chan %d is duplicated",
434 chan->oper_class, chan->chan);
435 goto fail;
436 }
437
438 num++;
439 }
440
441 os_free(cmd);
442
443 if (chans) {
444 qsort(chans, num, sizeof(struct wpa_mbo_non_pref_channel),
445 wpa_non_pref_chan_cmp);
446 }
447
448 update:
449 os_free(wpa_s->non_pref_chan);
450 wpa_s->non_pref_chan = chans;
451 wpa_s->non_pref_chan_num = num;
452 wpas_mbo_non_pref_chan_changed(wpa_s);
453
454 return 0;
455
456 fail:
457 os_free(chans);
458 os_free(cmd);
459 return -1;
460 }
461
462
wpas_mbo_scan_ie(struct wpa_supplicant * wpa_s,struct wpabuf * ie)463 void wpas_mbo_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ie)
464 {
465 u8 *len;
466
467 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
468 len = wpabuf_put(ie, 1);
469
470 wpabuf_put_be24(ie, OUI_WFA);
471 wpabuf_put_u8(ie, MBO_OUI_TYPE);
472
473 wpabuf_put_u8(ie, MBO_ATTR_ID_CELL_DATA_CAPA);
474 wpabuf_put_u8(ie, 1);
475 wpabuf_put_u8(ie, wpa_s->conf->mbo_cell_capa);
476 if (wpa_s->enable_oce & OCE_STA) {
477 wpabuf_put_u8(ie, OCE_ATTR_ID_CAPA_IND);
478 wpabuf_put_u8(ie, 1);
479 wpabuf_put_u8(ie, OCE_RELEASE);
480 }
481 *len = (u8 *) wpabuf_put(ie, 0) - len - 1;
482 }
483
484
wpas_mbo_ie_trans_req(struct wpa_supplicant * wpa_s,const u8 * mbo_ie,size_t len)485 void wpas_mbo_ie_trans_req(struct wpa_supplicant *wpa_s, const u8 *mbo_ie,
486 size_t len)
487 {
488 const u8 *pos, *cell_pref = NULL;
489 u8 id, elen;
490 u16 disallowed_sec = 0;
491
492 if (len <= 4 || WPA_GET_BE24(mbo_ie) != OUI_WFA ||
493 mbo_ie[3] != MBO_OUI_TYPE)
494 return;
495
496 pos = mbo_ie + 4;
497 len -= 4;
498
499 while (len >= 2) {
500 id = *pos++;
501 elen = *pos++;
502 len -= 2;
503
504 if (elen > len)
505 goto fail;
506
507 switch (id) {
508 case MBO_ATTR_ID_CELL_DATA_PREF:
509 if (elen != 1)
510 goto fail;
511
512 if (wpa_s->conf->mbo_cell_capa ==
513 MBO_CELL_CAPA_AVAILABLE)
514 cell_pref = pos;
515 else
516 wpa_printf(MSG_DEBUG,
517 "MBO: Station does not support Cellular data connection");
518 break;
519 #ifdef CONFIG_WNM
520 case MBO_ATTR_ID_TRANSITION_REASON:
521 if (elen != 1)
522 goto fail;
523
524 wpa_s->wnm_mbo_trans_reason_present = 1;
525 wpa_s->wnm_mbo_transition_reason = *pos;
526 break;
527 case MBO_ATTR_ID_ASSOC_RETRY_DELAY:
528 if (elen != 2)
529 goto fail;
530
531 if (wpa_s->wnm_mode &
532 WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
533 wpa_printf(MSG_DEBUG,
534 "MBO: Unexpected association retry delay, BSS is terminating");
535 goto fail;
536 } else if (wpa_s->wnm_mode &
537 WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
538 disallowed_sec = WPA_GET_LE16(pos);
539 wpa_printf(MSG_DEBUG,
540 "MBO: Association retry delay: %u",
541 disallowed_sec);
542 } else {
543 wpa_printf(MSG_DEBUG,
544 "MBO: Association retry delay attribute not in disassoc imminent mode");
545 }
546
547 break;
548 #endif /* CONFIG_WNM */
549 case MBO_ATTR_ID_AP_CAPA_IND:
550 case MBO_ATTR_ID_NON_PREF_CHAN_REPORT:
551 case MBO_ATTR_ID_CELL_DATA_CAPA:
552 case MBO_ATTR_ID_ASSOC_DISALLOW:
553 case MBO_ATTR_ID_TRANSITION_REJECT_REASON:
554 wpa_printf(MSG_DEBUG,
555 "MBO: Attribute %d should not be included in BTM Request frame",
556 id);
557 break;
558 default:
559 wpa_printf(MSG_DEBUG, "MBO: Unknown attribute id %u",
560 id);
561 return;
562 }
563
564 pos += elen;
565 len -= elen;
566 }
567
568 if (cell_pref)
569 wpa_msg(wpa_s, MSG_INFO, MBO_CELL_PREFERENCE "preference=%u",
570 *cell_pref);
571
572 #ifdef CONFIG_WNM
573 if (wpa_s->wnm_mbo_trans_reason_present)
574 wpa_msg(wpa_s, MSG_INFO, MBO_TRANSITION_REASON "reason=%u",
575 wpa_s->wnm_mbo_transition_reason);
576 #endif
577
578 if (disallowed_sec && wpa_s->current_bss)
579 wpa_bss_tmp_disallow(wpa_s, wpa_s->current_bss->bssid,
580 disallowed_sec, 0);
581
582 return;
583 fail:
584 wpa_printf(MSG_DEBUG, "MBO IE parsing failed (id=%u len=%u left=%zu)",
585 id, elen, len);
586 }
587
588
wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant * wpa_s,u8 * pos,size_t len,enum mbo_transition_reject_reason reason)589 size_t wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant *wpa_s, u8 *pos,
590 size_t len,
591 enum mbo_transition_reject_reason reason)
592 {
593 u8 reject_attr[3];
594
595 reject_attr[0] = MBO_ATTR_ID_TRANSITION_REJECT_REASON;
596 reject_attr[1] = 1;
597 reject_attr[2] = reason;
598
599 return mbo_add_ie(pos, len, reject_attr, sizeof(reject_attr));
600 }
601
602
wpas_mbo_update_cell_capa(struct wpa_supplicant * wpa_s,u8 mbo_cell_capa)603 void wpas_mbo_update_cell_capa(struct wpa_supplicant *wpa_s, u8 mbo_cell_capa)
604 {
605 u8 cell_capa[7];
606
607 if (wpa_s->conf->mbo_cell_capa == mbo_cell_capa) {
608 wpa_printf(MSG_DEBUG,
609 "MBO: Cellular capability already set to %u",
610 mbo_cell_capa);
611 return;
612 }
613
614 wpa_s->conf->mbo_cell_capa = mbo_cell_capa;
615
616 cell_capa[0] = WLAN_EID_VENDOR_SPECIFIC;
617 cell_capa[1] = 5; /* Length */
618 WPA_PUT_BE24(cell_capa + 2, OUI_WFA);
619 cell_capa[5] = MBO_ATTR_ID_CELL_DATA_CAPA;
620 cell_capa[6] = mbo_cell_capa;
621
622 #ifdef CONFIG_WNM
623 wpas_mbo_send_wnm_notification(wpa_s, cell_capa, 7);
624 #endif /* CONFIG_WNM */
625 wpa_supplicant_set_default_scan_ies(wpa_s);
626 wpas_update_mbo_connect_params(wpa_s);
627 }
628
629 #ifdef CONFIG_GAS
mbo_build_anqp_buf(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,u32 mbo_subtypes)630 struct wpabuf * mbo_build_anqp_buf(struct wpa_supplicant *wpa_s,
631 struct wpa_bss *bss, u32 mbo_subtypes)
632 {
633 struct wpabuf *anqp_buf;
634 u8 *len_pos;
635 u8 i;
636
637 if (!wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE)) {
638 wpa_printf(MSG_INFO, "MBO: " MACSTR
639 " does not support MBO - cannot request MBO ANQP elements from it",
640 MAC2STR(bss->bssid));
641 return NULL;
642 }
643
644 /* Allocate size for the maximum case - all MBO subtypes are set */
645 anqp_buf = wpabuf_alloc(9 + MAX_MBO_ANQP_SUBTYPE);
646 if (!anqp_buf)
647 return NULL;
648
649 len_pos = gas_anqp_add_element(anqp_buf, ANQP_VENDOR_SPECIFIC);
650 wpabuf_put_be24(anqp_buf, OUI_WFA);
651 wpabuf_put_u8(anqp_buf, MBO_ANQP_OUI_TYPE);
652
653 wpabuf_put_u8(anqp_buf, MBO_ANQP_SUBTYPE_QUERY_LIST);
654
655 /* The first valid MBO subtype is 1 */
656 for (i = 1; i <= MAX_MBO_ANQP_SUBTYPE; i++) {
657 if (mbo_subtypes & BIT(i))
658 wpabuf_put_u8(anqp_buf, i);
659 }
660
661 gas_anqp_set_element_len(anqp_buf, len_pos);
662
663 return anqp_buf;
664 }
665 #endif /* CONFIG_GAS */
666
mbo_parse_rx_anqp_resp(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,const u8 * sa,const u8 * data,size_t slen)667 void mbo_parse_rx_anqp_resp(struct wpa_supplicant *wpa_s,
668 struct wpa_bss *bss, const u8 *sa,
669 const u8 *data, size_t slen)
670 {
671 const u8 *pos = data;
672 u8 subtype;
673
674 if (slen < 1)
675 return;
676
677 subtype = *pos++;
678 slen--;
679
680 switch (subtype) {
681 case MBO_ANQP_SUBTYPE_CELL_CONN_PREF:
682 if (slen < 1)
683 break;
684 wpa_msg(wpa_s, MSG_INFO, RX_MBO_ANQP MACSTR
685 " cell_conn_pref=%u", MAC2STR(sa), *pos);
686 break;
687 default:
688 wpa_printf(MSG_DEBUG, "MBO: Unsupported ANQP subtype %u",
689 subtype);
690 break;
691 }
692 }
693