blob: 5adf61e58bd0b4e1e32f505f45d99cd7267f06a3 [file] [log] [blame]
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001/*
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"
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080017#include "common/gas.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080018#include "config.h"
19#include "wpa_supplicant_i.h"
20#include "driver_i.h"
21#include "bss.h"
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070022#include "scan.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080023
24/* type + length + oui + oui type */
25#define MBO_IE_HEADER 6
26
27
28static int wpas_mbo_validate_non_pref_chan(u8 oper_class, u8 chan, u8 reason)
29{
30 if (reason > MBO_NON_PREF_CHAN_REASON_INT_INTERFERENCE)
31 return -1;
32
33 /* Only checking the validity of the channel and oper_class */
34 if (ieee80211_chan_to_freq(NULL, oper_class, chan) == -1)
35 return -1;
36
37 return 0;
38}
39
40
Hai Shalomce48b4a2018-09-05 11:41:35 -070041const u8 * mbo_attr_from_mbo_ie(const u8 *mbo_ie, enum mbo_attr_id attr)
42{
43 const u8 *mbo;
44 u8 ie_len = mbo_ie[1];
45
46 if (ie_len < MBO_IE_HEADER - 2)
47 return NULL;
48 mbo = mbo_ie + MBO_IE_HEADER;
49
50 return get_ie(mbo, 2 + ie_len - MBO_IE_HEADER, attr);
51}
52
53
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080054const u8 * wpas_mbo_get_bss_attr(struct wpa_bss *bss, enum mbo_attr_id attr)
55{
56 const u8 *mbo, *end;
57
58 if (!bss)
59 return NULL;
60
61 mbo = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE);
62 if (!mbo)
63 return NULL;
64
65 end = mbo + 2 + mbo[1];
66 mbo += MBO_IE_HEADER;
67
68 return get_ie(mbo, end - mbo, attr);
69}
70
71
72static void wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant *wpa_s,
73 struct wpabuf *mbo,
74 u8 start, u8 end)
75{
76 u8 i;
77
78 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].oper_class);
79
80 for (i = start; i < end; i++)
81 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[i].chan);
82
83 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].preference);
84 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080085}
86
87
88static void wpas_mbo_non_pref_chan_attr(struct wpa_supplicant *wpa_s,
89 struct wpabuf *mbo, u8 start, u8 end)
90{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -070091 size_t size = end - start + 3;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080092
93 if (size + 2 > wpabuf_tailroom(mbo))
94 return;
95
96 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
97 wpabuf_put_u8(mbo, size); /* Length */
98
99 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
100}
101
102
103static void wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf *mbo, u8 len)
104{
105 wpabuf_put_u8(mbo, WLAN_EID_VENDOR_SPECIFIC);
106 wpabuf_put_u8(mbo, len); /* Length */
107 wpabuf_put_be24(mbo, OUI_WFA);
108 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
109}
110
111
112static void wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant *wpa_s,
113 struct wpabuf *mbo, u8 start,
114 u8 end)
115{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700116 size_t size = end - start + 7;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800117
118 if (size + 2 > wpabuf_tailroom(mbo))
119 return;
120
121 wpas_mbo_non_pref_chan_subelem_hdr(mbo, size);
122 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
123}
124
125
126static void wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant *wpa_s,
127 struct wpabuf *mbo, int subelement)
128{
129 u8 i, start = 0;
130 struct wpa_mbo_non_pref_channel *start_pref;
131
132 if (!wpa_s->non_pref_chan || !wpa_s->non_pref_chan_num) {
133 if (subelement)
134 wpas_mbo_non_pref_chan_subelem_hdr(mbo, 4);
135 return;
136 }
137 start_pref = &wpa_s->non_pref_chan[0];
138
139 for (i = 1; i <= wpa_s->non_pref_chan_num; i++) {
140 struct wpa_mbo_non_pref_channel *non_pref = NULL;
141
142 if (i < wpa_s->non_pref_chan_num)
143 non_pref = &wpa_s->non_pref_chan[i];
144 if (!non_pref ||
145 non_pref->oper_class != start_pref->oper_class ||
146 non_pref->reason != start_pref->reason ||
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800147 non_pref->preference != start_pref->preference) {
148 if (subelement)
149 wpas_mbo_non_pref_chan_subelement(wpa_s, mbo,
150 start, i);
151 else
152 wpas_mbo_non_pref_chan_attr(wpa_s, mbo, start,
153 i);
154
155 if (!non_pref)
156 return;
157
158 start = i;
159 start_pref = non_pref;
160 }
161 }
162}
163
164
Hai Shalomce48b4a2018-09-05 11:41:35 -0700165int wpas_mbo_ie(struct wpa_supplicant *wpa_s, u8 *buf, size_t len,
166 int add_oce_capa)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800167{
168 struct wpabuf *mbo;
169 int res;
170
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700171 if (len < MBO_IE_HEADER + 3 + 7 +
172 ((wpa_s->enable_oce & OCE_STA) ? 3 : 0))
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800173 return 0;
174
175 /* Leave room for the MBO IE header */
176 mbo = wpabuf_alloc(len - MBO_IE_HEADER);
177 if (!mbo)
178 return 0;
179
180 /* Add non-preferred channels attribute */
181 wpas_mbo_non_pref_chan_attrs(wpa_s, mbo, 0);
182
183 /*
184 * Send cellular capabilities attribute even if AP does not advertise
185 * cellular capabilities.
186 */
187 wpabuf_put_u8(mbo, MBO_ATTR_ID_CELL_DATA_CAPA);
188 wpabuf_put_u8(mbo, 1);
189 wpabuf_put_u8(mbo, wpa_s->conf->mbo_cell_capa);
190
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700191 /* Add OCE capability indication attribute if OCE is enabled */
Hai Shalomce48b4a2018-09-05 11:41:35 -0700192 if ((wpa_s->enable_oce & OCE_STA) && add_oce_capa) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700193 wpabuf_put_u8(mbo, OCE_ATTR_ID_CAPA_IND);
194 wpabuf_put_u8(mbo, 1);
195 wpabuf_put_u8(mbo, OCE_RELEASE);
196 }
197
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800198 res = mbo_add_ie(buf, len, wpabuf_head_u8(mbo), wpabuf_len(mbo));
199 if (!res)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700200 wpa_printf(MSG_ERROR, "Failed to add MBO/OCE IE");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800201
202 wpabuf_free(mbo);
203 return res;
204}
205
206
207static void wpas_mbo_send_wnm_notification(struct wpa_supplicant *wpa_s,
208 const u8 *data, size_t len)
209{
210 struct wpabuf *buf;
211 int res;
212
213 /*
214 * Send WNM-Notification Request frame only in case of a change in
215 * non-preferred channels list during association, if the AP supports
216 * MBO.
217 */
218 if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_bss ||
219 !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
220 return;
221
222 buf = wpabuf_alloc(4 + len);
223 if (!buf)
224 return;
225
226 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
227 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
228 wpa_s->mbo_wnm_token++;
229 if (wpa_s->mbo_wnm_token == 0)
230 wpa_s->mbo_wnm_token++;
231 wpabuf_put_u8(buf, wpa_s->mbo_wnm_token);
232 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); /* Type */
233
234 wpabuf_put_data(buf, data, len);
235
236 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
237 wpa_s->own_addr, wpa_s->bssid,
238 wpabuf_head(buf), wpabuf_len(buf), 0);
239 if (res < 0)
240 wpa_printf(MSG_DEBUG,
241 "Failed to send WNM-Notification Request frame with non-preferred channel list");
242
243 wpabuf_free(buf);
244}
245
246
247static void wpas_mbo_non_pref_chan_changed(struct wpa_supplicant *wpa_s)
248{
249 struct wpabuf *buf;
250
251 buf = wpabuf_alloc(512);
252 if (!buf)
253 return;
254
255 wpas_mbo_non_pref_chan_attrs(wpa_s, buf, 1);
256 wpas_mbo_send_wnm_notification(wpa_s, wpabuf_head_u8(buf),
257 wpabuf_len(buf));
258 wpabuf_free(buf);
259}
260
261
262static int wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel *a,
263 struct wpa_mbo_non_pref_channel *b)
264{
265 return a->oper_class == b->oper_class && a->chan == b->chan;
266}
267
268
269/*
270 * wpa_non_pref_chan_cmp - Compare two channels for sorting
271 *
272 * In MBO IE non-preferred channel subelement we can put many channels in an
273 * attribute if they are in the same operating class and have the same
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700274 * preference and reason. To make it easy for the functions that build
275 * the IE attributes and WNM Request subelements, save the channels sorted
276 * by their oper_class and reason.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800277 */
278static int wpa_non_pref_chan_cmp(const void *_a, const void *_b)
279{
280 const struct wpa_mbo_non_pref_channel *a = _a, *b = _b;
281
282 if (a->oper_class != b->oper_class)
283 return a->oper_class - b->oper_class;
284 if (a->reason != b->reason)
285 return a->reason - b->reason;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800286 return a->preference - b->preference;
287}
288
289
290int wpas_mbo_update_non_pref_chan(struct wpa_supplicant *wpa_s,
291 const char *non_pref_chan)
292{
293 char *cmd, *token, *context = NULL;
294 struct wpa_mbo_non_pref_channel *chans = NULL, *tmp_chans;
295 size_t num = 0, size = 0;
296 unsigned i;
297
298 wpa_printf(MSG_DEBUG, "MBO: Update non-preferred channels, non_pref_chan=%s",
299 non_pref_chan ? non_pref_chan : "N/A");
300
301 /*
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700302 * The shortest channel configuration is 7 characters - 3 colons and
303 * 4 values.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800304 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700305 if (!non_pref_chan || os_strlen(non_pref_chan) < 7)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800306 goto update;
307
308 cmd = os_strdup(non_pref_chan);
309 if (!cmd)
310 return -1;
311
312 while ((token = str_token(cmd, " ", &context))) {
313 struct wpa_mbo_non_pref_channel *chan;
314 int ret;
315 unsigned int _oper_class;
316 unsigned int _chan;
317 unsigned int _preference;
318 unsigned int _reason;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800319
320 if (num == size) {
321 size = size ? size * 2 : 1;
322 tmp_chans = os_realloc_array(chans, size,
323 sizeof(*chans));
324 if (!tmp_chans) {
325 wpa_printf(MSG_ERROR,
326 "Couldn't reallocate non_pref_chan");
327 goto fail;
328 }
329 chans = tmp_chans;
330 }
331
332 chan = &chans[num];
333
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700334 ret = sscanf(token, "%u:%u:%u:%u", &_oper_class,
335 &_chan, &_preference, &_reason);
336 if (ret != 4 ||
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800337 _oper_class > 255 || _chan > 255 ||
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700338 _preference > 255 || _reason > 65535 ) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800339 wpa_printf(MSG_ERROR, "Invalid non-pref chan input %s",
340 token);
341 goto fail;
342 }
343 chan->oper_class = _oper_class;
344 chan->chan = _chan;
345 chan->preference = _preference;
346 chan->reason = _reason;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800347
348 if (wpas_mbo_validate_non_pref_chan(chan->oper_class,
349 chan->chan, chan->reason)) {
350 wpa_printf(MSG_ERROR,
351 "Invalid non_pref_chan: oper class %d chan %d reason %d",
352 chan->oper_class, chan->chan, chan->reason);
353 goto fail;
354 }
355
356 for (i = 0; i < num; i++)
357 if (wpa_non_pref_chan_is_eq(chan, &chans[i]))
358 break;
359 if (i != num) {
360 wpa_printf(MSG_ERROR,
361 "oper class %d chan %d is duplicated",
362 chan->oper_class, chan->chan);
363 goto fail;
364 }
365
366 num++;
367 }
368
369 os_free(cmd);
370
371 if (chans) {
372 qsort(chans, num, sizeof(struct wpa_mbo_non_pref_channel),
373 wpa_non_pref_chan_cmp);
374 }
375
376update:
377 os_free(wpa_s->non_pref_chan);
378 wpa_s->non_pref_chan = chans;
379 wpa_s->non_pref_chan_num = num;
380 wpas_mbo_non_pref_chan_changed(wpa_s);
381
382 return 0;
383
384fail:
385 os_free(chans);
386 os_free(cmd);
387 return -1;
388}
389
390
391void wpas_mbo_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ie)
392{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700393 u8 *len;
394
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800395 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700396 len = wpabuf_put(ie, 1);
397
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800398 wpabuf_put_be24(ie, OUI_WFA);
399 wpabuf_put_u8(ie, MBO_OUI_TYPE);
400
401 wpabuf_put_u8(ie, MBO_ATTR_ID_CELL_DATA_CAPA);
402 wpabuf_put_u8(ie, 1);
403 wpabuf_put_u8(ie, wpa_s->conf->mbo_cell_capa);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700404 if (wpa_s->enable_oce & OCE_STA) {
405 wpabuf_put_u8(ie, OCE_ATTR_ID_CAPA_IND);
406 wpabuf_put_u8(ie, 1);
407 wpabuf_put_u8(ie, OCE_RELEASE);
408 }
409 *len = (u8 *) wpabuf_put(ie, 0) - len - 1;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800410}
411
412
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800413void wpas_mbo_ie_trans_req(struct wpa_supplicant *wpa_s, const u8 *mbo_ie,
414 size_t len)
415{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700416 const u8 *pos, *cell_pref = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800417 u8 id, elen;
418 u16 disallowed_sec = 0;
419
420 if (len <= 4 || WPA_GET_BE24(mbo_ie) != OUI_WFA ||
421 mbo_ie[3] != MBO_OUI_TYPE)
422 return;
423
424 pos = mbo_ie + 4;
425 len -= 4;
426
427 while (len >= 2) {
428 id = *pos++;
429 elen = *pos++;
430 len -= 2;
431
432 if (elen > len)
433 goto fail;
434
435 switch (id) {
436 case MBO_ATTR_ID_CELL_DATA_PREF:
437 if (elen != 1)
438 goto fail;
439
440 if (wpa_s->conf->mbo_cell_capa ==
441 MBO_CELL_CAPA_AVAILABLE)
442 cell_pref = pos;
443 else
444 wpa_printf(MSG_DEBUG,
445 "MBO: Station does not support Cellular data connection");
446 break;
447 case MBO_ATTR_ID_TRANSITION_REASON:
448 if (elen != 1)
449 goto fail;
450
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700451 wpa_s->wnm_mbo_trans_reason_present = 1;
452 wpa_s->wnm_mbo_transition_reason = *pos;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800453 break;
454 case MBO_ATTR_ID_ASSOC_RETRY_DELAY:
455 if (elen != 2)
456 goto fail;
457
458 if (wpa_s->wnm_mode &
459 WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
460 wpa_printf(MSG_DEBUG,
461 "MBO: Unexpected association retry delay, BSS is terminating");
462 goto fail;
463 } else if (wpa_s->wnm_mode &
464 WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
465 disallowed_sec = WPA_GET_LE16(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700466 wpa_printf(MSG_DEBUG,
467 "MBO: Association retry delay: %u",
468 disallowed_sec);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800469 } else {
470 wpa_printf(MSG_DEBUG,
471 "MBO: Association retry delay attribute not in disassoc imminent mode");
472 }
473
474 break;
475 case MBO_ATTR_ID_AP_CAPA_IND:
476 case MBO_ATTR_ID_NON_PREF_CHAN_REPORT:
477 case MBO_ATTR_ID_CELL_DATA_CAPA:
478 case MBO_ATTR_ID_ASSOC_DISALLOW:
479 case MBO_ATTR_ID_TRANSITION_REJECT_REASON:
480 wpa_printf(MSG_DEBUG,
481 "MBO: Attribute %d should not be included in BTM Request frame",
482 id);
483 break;
484 default:
485 wpa_printf(MSG_DEBUG, "MBO: Unknown attribute id %u",
486 id);
487 return;
488 }
489
490 pos += elen;
491 len -= elen;
492 }
493
494 if (cell_pref)
495 wpa_msg(wpa_s, MSG_INFO, MBO_CELL_PREFERENCE "preference=%u",
496 *cell_pref);
497
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700498 if (wpa_s->wnm_mbo_trans_reason_present)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800499 wpa_msg(wpa_s, MSG_INFO, MBO_TRANSITION_REASON "reason=%u",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700500 wpa_s->wnm_mbo_transition_reason);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800501
502 if (disallowed_sec && wpa_s->current_bss)
503 wpa_bss_tmp_disallow(wpa_s, wpa_s->current_bss->bssid,
504 disallowed_sec);
505
506 return;
507fail:
508 wpa_printf(MSG_DEBUG, "MBO IE parsing failed (id=%u len=%u left=%zu)",
509 id, elen, len);
510}
511
512
513size_t wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant *wpa_s, u8 *pos,
514 size_t len,
515 enum mbo_transition_reject_reason reason)
516{
517 u8 reject_attr[3];
518
519 reject_attr[0] = MBO_ATTR_ID_TRANSITION_REJECT_REASON;
520 reject_attr[1] = 1;
521 reject_attr[2] = reason;
522
523 return mbo_add_ie(pos, len, reject_attr, sizeof(reject_attr));
524}
525
526
527void wpas_mbo_update_cell_capa(struct wpa_supplicant *wpa_s, u8 mbo_cell_capa)
528{
529 u8 cell_capa[7];
530
531 if (wpa_s->conf->mbo_cell_capa == mbo_cell_capa) {
532 wpa_printf(MSG_DEBUG,
533 "MBO: Cellular capability already set to %u",
534 mbo_cell_capa);
535 return;
536 }
537
538 wpa_s->conf->mbo_cell_capa = mbo_cell_capa;
539
540 cell_capa[0] = WLAN_EID_VENDOR_SPECIFIC;
541 cell_capa[1] = 5; /* Length */
542 WPA_PUT_BE24(cell_capa + 2, OUI_WFA);
543 cell_capa[5] = MBO_ATTR_ID_CELL_DATA_CAPA;
544 cell_capa[6] = mbo_cell_capa;
545
546 wpas_mbo_send_wnm_notification(wpa_s, cell_capa, 7);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700547 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800548}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800549
550
551struct wpabuf * mbo_build_anqp_buf(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700552 struct wpa_bss *bss, u32 mbo_subtypes)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800553{
554 struct wpabuf *anqp_buf;
555 u8 *len_pos;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700556 u8 i;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800557
558 if (!wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE)) {
559 wpa_printf(MSG_INFO, "MBO: " MACSTR
560 " does not support MBO - cannot request MBO ANQP elements from it",
561 MAC2STR(bss->bssid));
562 return NULL;
563 }
564
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700565 /* Allocate size for the maximum case - all MBO subtypes are set */
566 anqp_buf = wpabuf_alloc(9 + MAX_MBO_ANQP_SUBTYPE);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800567 if (!anqp_buf)
568 return NULL;
569
570 len_pos = gas_anqp_add_element(anqp_buf, ANQP_VENDOR_SPECIFIC);
571 wpabuf_put_be24(anqp_buf, OUI_WFA);
572 wpabuf_put_u8(anqp_buf, MBO_ANQP_OUI_TYPE);
573
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700574 wpabuf_put_u8(anqp_buf, MBO_ANQP_SUBTYPE_QUERY_LIST);
575
576 /* The first valid MBO subtype is 1 */
577 for (i = 1; i <= MAX_MBO_ANQP_SUBTYPE; i++) {
578 if (mbo_subtypes & BIT(i))
579 wpabuf_put_u8(anqp_buf, i);
580 }
581
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800582 gas_anqp_set_element_len(anqp_buf, len_pos);
583
584 return anqp_buf;
585}
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700586
587
588void mbo_parse_rx_anqp_resp(struct wpa_supplicant *wpa_s,
589 struct wpa_bss *bss, const u8 *sa,
590 const u8 *data, size_t slen)
591{
592 const u8 *pos = data;
593 u8 subtype;
594
595 if (slen < 1)
596 return;
597
598 subtype = *pos++;
599 slen--;
600
601 switch (subtype) {
602 case MBO_ANQP_SUBTYPE_CELL_CONN_PREF:
603 if (slen < 1)
604 break;
605 wpa_msg(wpa_s, MSG_INFO, RX_MBO_ANQP MACSTR
606 " cell_conn_pref=%u", MAC2STR(sa), *pos);
607 break;
608 default:
609 wpa_printf(MSG_DEBUG, "MBO: Unsupported ANQP subtype %u",
610 subtype);
611 break;
612 }
613}