blob: bd5020a80d5c17ce80a180e472534de403d8ecea [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
Hai Shalom74f70d42019-02-11 14:42:39 -080054const u8 * mbo_get_attr_from_ies(const u8 *ies, size_t ies_len,
55 enum mbo_attr_id attr)
56{
57 const u8 *mbo_ie;
58
59 mbo_ie = get_vendor_ie(ies, ies_len, MBO_IE_VENDOR_TYPE);
60 if (!mbo_ie)
61 return NULL;
62
63 return mbo_attr_from_mbo_ie(mbo_ie, attr);
64}
65
66
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080067const u8 * wpas_mbo_get_bss_attr(struct wpa_bss *bss, enum mbo_attr_id attr)
68{
69 const u8 *mbo, *end;
70
71 if (!bss)
72 return NULL;
73
74 mbo = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE);
75 if (!mbo)
76 return NULL;
77
78 end = mbo + 2 + mbo[1];
79 mbo += MBO_IE_HEADER;
80
81 return get_ie(mbo, end - mbo, attr);
82}
83
84
85static void wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant *wpa_s,
86 struct wpabuf *mbo,
87 u8 start, u8 end)
88{
89 u8 i;
90
91 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].oper_class);
92
93 for (i = start; i < end; i++)
94 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[i].chan);
95
96 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].preference);
97 wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080098}
99
100
101static void wpas_mbo_non_pref_chan_attr(struct wpa_supplicant *wpa_s,
102 struct wpabuf *mbo, u8 start, u8 end)
103{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700104 size_t size = end - start + 3;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800105
106 if (size + 2 > wpabuf_tailroom(mbo))
107 return;
108
109 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
110 wpabuf_put_u8(mbo, size); /* Length */
111
112 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
113}
114
115
116static void wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf *mbo, u8 len)
117{
118 wpabuf_put_u8(mbo, WLAN_EID_VENDOR_SPECIFIC);
119 wpabuf_put_u8(mbo, len); /* Length */
120 wpabuf_put_be24(mbo, OUI_WFA);
121 wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
122}
123
124
125static void wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant *wpa_s,
126 struct wpabuf *mbo, u8 start,
127 u8 end)
128{
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700129 size_t size = end - start + 7;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800130
131 if (size + 2 > wpabuf_tailroom(mbo))
132 return;
133
134 wpas_mbo_non_pref_chan_subelem_hdr(mbo, size);
135 wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
136}
137
138
139static void wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant *wpa_s,
140 struct wpabuf *mbo, int subelement)
141{
142 u8 i, start = 0;
143 struct wpa_mbo_non_pref_channel *start_pref;
144
145 if (!wpa_s->non_pref_chan || !wpa_s->non_pref_chan_num) {
146 if (subelement)
147 wpas_mbo_non_pref_chan_subelem_hdr(mbo, 4);
148 return;
149 }
150 start_pref = &wpa_s->non_pref_chan[0];
151
152 for (i = 1; i <= wpa_s->non_pref_chan_num; i++) {
153 struct wpa_mbo_non_pref_channel *non_pref = NULL;
154
155 if (i < wpa_s->non_pref_chan_num)
156 non_pref = &wpa_s->non_pref_chan[i];
157 if (!non_pref ||
158 non_pref->oper_class != start_pref->oper_class ||
159 non_pref->reason != start_pref->reason ||
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800160 non_pref->preference != start_pref->preference) {
161 if (subelement)
162 wpas_mbo_non_pref_chan_subelement(wpa_s, mbo,
163 start, i);
164 else
165 wpas_mbo_non_pref_chan_attr(wpa_s, mbo, start,
166 i);
167
168 if (!non_pref)
169 return;
170
171 start = i;
172 start_pref = non_pref;
173 }
174 }
175}
176
177
Hai Shalomce48b4a2018-09-05 11:41:35 -0700178int wpas_mbo_ie(struct wpa_supplicant *wpa_s, u8 *buf, size_t len,
179 int add_oce_capa)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800180{
181 struct wpabuf *mbo;
182 int res;
183
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700184 if (len < MBO_IE_HEADER + 3 + 7 +
185 ((wpa_s->enable_oce & OCE_STA) ? 3 : 0))
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800186 return 0;
187
188 /* Leave room for the MBO IE header */
189 mbo = wpabuf_alloc(len - MBO_IE_HEADER);
190 if (!mbo)
191 return 0;
192
193 /* Add non-preferred channels attribute */
194 wpas_mbo_non_pref_chan_attrs(wpa_s, mbo, 0);
195
196 /*
197 * Send cellular capabilities attribute even if AP does not advertise
198 * cellular capabilities.
199 */
200 wpabuf_put_u8(mbo, MBO_ATTR_ID_CELL_DATA_CAPA);
201 wpabuf_put_u8(mbo, 1);
202 wpabuf_put_u8(mbo, wpa_s->conf->mbo_cell_capa);
203
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700204 /* Add OCE capability indication attribute if OCE is enabled */
Hai Shalomce48b4a2018-09-05 11:41:35 -0700205 if ((wpa_s->enable_oce & OCE_STA) && add_oce_capa) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700206 wpabuf_put_u8(mbo, OCE_ATTR_ID_CAPA_IND);
207 wpabuf_put_u8(mbo, 1);
208 wpabuf_put_u8(mbo, OCE_RELEASE);
209 }
210
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800211 res = mbo_add_ie(buf, len, wpabuf_head_u8(mbo), wpabuf_len(mbo));
212 if (!res)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700213 wpa_printf(MSG_ERROR, "Failed to add MBO/OCE IE");
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800214
215 wpabuf_free(mbo);
216 return res;
217}
218
219
220static void wpas_mbo_send_wnm_notification(struct wpa_supplicant *wpa_s,
221 const u8 *data, size_t len)
222{
223 struct wpabuf *buf;
224 int res;
225
226 /*
227 * Send WNM-Notification Request frame only in case of a change in
228 * non-preferred channels list during association, if the AP supports
229 * MBO.
230 */
231 if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_bss ||
232 !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
233 return;
234
235 buf = wpabuf_alloc(4 + len);
236 if (!buf)
237 return;
238
239 wpabuf_put_u8(buf, WLAN_ACTION_WNM);
240 wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
241 wpa_s->mbo_wnm_token++;
242 if (wpa_s->mbo_wnm_token == 0)
243 wpa_s->mbo_wnm_token++;
244 wpabuf_put_u8(buf, wpa_s->mbo_wnm_token);
245 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); /* Type */
246
247 wpabuf_put_data(buf, data, len);
248
249 res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
250 wpa_s->own_addr, wpa_s->bssid,
251 wpabuf_head(buf), wpabuf_len(buf), 0);
252 if (res < 0)
253 wpa_printf(MSG_DEBUG,
254 "Failed to send WNM-Notification Request frame with non-preferred channel list");
255
256 wpabuf_free(buf);
257}
258
259
260static void wpas_mbo_non_pref_chan_changed(struct wpa_supplicant *wpa_s)
261{
262 struct wpabuf *buf;
263
264 buf = wpabuf_alloc(512);
265 if (!buf)
266 return;
267
268 wpas_mbo_non_pref_chan_attrs(wpa_s, buf, 1);
269 wpas_mbo_send_wnm_notification(wpa_s, wpabuf_head_u8(buf),
270 wpabuf_len(buf));
271 wpabuf_free(buf);
272}
273
274
275static int wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel *a,
276 struct wpa_mbo_non_pref_channel *b)
277{
278 return a->oper_class == b->oper_class && a->chan == b->chan;
279}
280
281
282/*
283 * wpa_non_pref_chan_cmp - Compare two channels for sorting
284 *
285 * In MBO IE non-preferred channel subelement we can put many channels in an
286 * attribute if they are in the same operating class and have the same
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700287 * preference and reason. To make it easy for the functions that build
288 * the IE attributes and WNM Request subelements, save the channels sorted
289 * by their oper_class and reason.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800290 */
291static int wpa_non_pref_chan_cmp(const void *_a, const void *_b)
292{
293 const struct wpa_mbo_non_pref_channel *a = _a, *b = _b;
294
295 if (a->oper_class != b->oper_class)
296 return a->oper_class - b->oper_class;
297 if (a->reason != b->reason)
298 return a->reason - b->reason;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800299 return a->preference - b->preference;
300}
301
302
303int wpas_mbo_update_non_pref_chan(struct wpa_supplicant *wpa_s,
304 const char *non_pref_chan)
305{
306 char *cmd, *token, *context = NULL;
307 struct wpa_mbo_non_pref_channel *chans = NULL, *tmp_chans;
308 size_t num = 0, size = 0;
309 unsigned i;
310
311 wpa_printf(MSG_DEBUG, "MBO: Update non-preferred channels, non_pref_chan=%s",
312 non_pref_chan ? non_pref_chan : "N/A");
313
314 /*
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700315 * The shortest channel configuration is 7 characters - 3 colons and
316 * 4 values.
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800317 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700318 if (!non_pref_chan || os_strlen(non_pref_chan) < 7)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800319 goto update;
320
321 cmd = os_strdup(non_pref_chan);
322 if (!cmd)
323 return -1;
324
325 while ((token = str_token(cmd, " ", &context))) {
326 struct wpa_mbo_non_pref_channel *chan;
327 int ret;
328 unsigned int _oper_class;
329 unsigned int _chan;
330 unsigned int _preference;
331 unsigned int _reason;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800332
333 if (num == size) {
334 size = size ? size * 2 : 1;
335 tmp_chans = os_realloc_array(chans, size,
336 sizeof(*chans));
337 if (!tmp_chans) {
338 wpa_printf(MSG_ERROR,
339 "Couldn't reallocate non_pref_chan");
340 goto fail;
341 }
342 chans = tmp_chans;
343 }
344
345 chan = &chans[num];
346
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700347 ret = sscanf(token, "%u:%u:%u:%u", &_oper_class,
348 &_chan, &_preference, &_reason);
349 if (ret != 4 ||
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800350 _oper_class > 255 || _chan > 255 ||
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700351 _preference > 255 || _reason > 65535 ) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800352 wpa_printf(MSG_ERROR, "Invalid non-pref chan input %s",
353 token);
354 goto fail;
355 }
356 chan->oper_class = _oper_class;
357 chan->chan = _chan;
358 chan->preference = _preference;
359 chan->reason = _reason;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800360
361 if (wpas_mbo_validate_non_pref_chan(chan->oper_class,
362 chan->chan, chan->reason)) {
363 wpa_printf(MSG_ERROR,
364 "Invalid non_pref_chan: oper class %d chan %d reason %d",
365 chan->oper_class, chan->chan, chan->reason);
366 goto fail;
367 }
368
369 for (i = 0; i < num; i++)
370 if (wpa_non_pref_chan_is_eq(chan, &chans[i]))
371 break;
372 if (i != num) {
373 wpa_printf(MSG_ERROR,
374 "oper class %d chan %d is duplicated",
375 chan->oper_class, chan->chan);
376 goto fail;
377 }
378
379 num++;
380 }
381
382 os_free(cmd);
383
384 if (chans) {
385 qsort(chans, num, sizeof(struct wpa_mbo_non_pref_channel),
386 wpa_non_pref_chan_cmp);
387 }
388
389update:
390 os_free(wpa_s->non_pref_chan);
391 wpa_s->non_pref_chan = chans;
392 wpa_s->non_pref_chan_num = num;
393 wpas_mbo_non_pref_chan_changed(wpa_s);
394
395 return 0;
396
397fail:
398 os_free(chans);
399 os_free(cmd);
400 return -1;
401}
402
403
404void wpas_mbo_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ie)
405{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700406 u8 *len;
407
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800408 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700409 len = wpabuf_put(ie, 1);
410
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800411 wpabuf_put_be24(ie, OUI_WFA);
412 wpabuf_put_u8(ie, MBO_OUI_TYPE);
413
414 wpabuf_put_u8(ie, MBO_ATTR_ID_CELL_DATA_CAPA);
415 wpabuf_put_u8(ie, 1);
416 wpabuf_put_u8(ie, wpa_s->conf->mbo_cell_capa);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700417 if (wpa_s->enable_oce & OCE_STA) {
418 wpabuf_put_u8(ie, OCE_ATTR_ID_CAPA_IND);
419 wpabuf_put_u8(ie, 1);
420 wpabuf_put_u8(ie, OCE_RELEASE);
421 }
422 *len = (u8 *) wpabuf_put(ie, 0) - len - 1;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800423}
424
425
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800426void wpas_mbo_ie_trans_req(struct wpa_supplicant *wpa_s, const u8 *mbo_ie,
427 size_t len)
428{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700429 const u8 *pos, *cell_pref = NULL;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800430 u8 id, elen;
431 u16 disallowed_sec = 0;
432
433 if (len <= 4 || WPA_GET_BE24(mbo_ie) != OUI_WFA ||
434 mbo_ie[3] != MBO_OUI_TYPE)
435 return;
436
437 pos = mbo_ie + 4;
438 len -= 4;
439
440 while (len >= 2) {
441 id = *pos++;
442 elen = *pos++;
443 len -= 2;
444
445 if (elen > len)
446 goto fail;
447
448 switch (id) {
449 case MBO_ATTR_ID_CELL_DATA_PREF:
450 if (elen != 1)
451 goto fail;
452
453 if (wpa_s->conf->mbo_cell_capa ==
454 MBO_CELL_CAPA_AVAILABLE)
455 cell_pref = pos;
456 else
457 wpa_printf(MSG_DEBUG,
458 "MBO: Station does not support Cellular data connection");
459 break;
460 case MBO_ATTR_ID_TRANSITION_REASON:
461 if (elen != 1)
462 goto fail;
463
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700464 wpa_s->wnm_mbo_trans_reason_present = 1;
465 wpa_s->wnm_mbo_transition_reason = *pos;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800466 break;
467 case MBO_ATTR_ID_ASSOC_RETRY_DELAY:
468 if (elen != 2)
469 goto fail;
470
471 if (wpa_s->wnm_mode &
472 WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
473 wpa_printf(MSG_DEBUG,
474 "MBO: Unexpected association retry delay, BSS is terminating");
475 goto fail;
476 } else if (wpa_s->wnm_mode &
477 WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
478 disallowed_sec = WPA_GET_LE16(pos);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700479 wpa_printf(MSG_DEBUG,
480 "MBO: Association retry delay: %u",
481 disallowed_sec);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800482 } else {
483 wpa_printf(MSG_DEBUG,
484 "MBO: Association retry delay attribute not in disassoc imminent mode");
485 }
486
487 break;
488 case MBO_ATTR_ID_AP_CAPA_IND:
489 case MBO_ATTR_ID_NON_PREF_CHAN_REPORT:
490 case MBO_ATTR_ID_CELL_DATA_CAPA:
491 case MBO_ATTR_ID_ASSOC_DISALLOW:
492 case MBO_ATTR_ID_TRANSITION_REJECT_REASON:
493 wpa_printf(MSG_DEBUG,
494 "MBO: Attribute %d should not be included in BTM Request frame",
495 id);
496 break;
497 default:
498 wpa_printf(MSG_DEBUG, "MBO: Unknown attribute id %u",
499 id);
500 return;
501 }
502
503 pos += elen;
504 len -= elen;
505 }
506
507 if (cell_pref)
508 wpa_msg(wpa_s, MSG_INFO, MBO_CELL_PREFERENCE "preference=%u",
509 *cell_pref);
510
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700511 if (wpa_s->wnm_mbo_trans_reason_present)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800512 wpa_msg(wpa_s, MSG_INFO, MBO_TRANSITION_REASON "reason=%u",
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700513 wpa_s->wnm_mbo_transition_reason);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800514
515 if (disallowed_sec && wpa_s->current_bss)
516 wpa_bss_tmp_disallow(wpa_s, wpa_s->current_bss->bssid,
Hai Shalom74f70d42019-02-11 14:42:39 -0800517 disallowed_sec, 0);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800518
519 return;
520fail:
521 wpa_printf(MSG_DEBUG, "MBO IE parsing failed (id=%u len=%u left=%zu)",
522 id, elen, len);
523}
524
525
526size_t wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant *wpa_s, u8 *pos,
527 size_t len,
528 enum mbo_transition_reject_reason reason)
529{
530 u8 reject_attr[3];
531
532 reject_attr[0] = MBO_ATTR_ID_TRANSITION_REJECT_REASON;
533 reject_attr[1] = 1;
534 reject_attr[2] = reason;
535
536 return mbo_add_ie(pos, len, reject_attr, sizeof(reject_attr));
537}
538
539
540void wpas_mbo_update_cell_capa(struct wpa_supplicant *wpa_s, u8 mbo_cell_capa)
541{
542 u8 cell_capa[7];
543
544 if (wpa_s->conf->mbo_cell_capa == mbo_cell_capa) {
545 wpa_printf(MSG_DEBUG,
546 "MBO: Cellular capability already set to %u",
547 mbo_cell_capa);
548 return;
549 }
550
551 wpa_s->conf->mbo_cell_capa = mbo_cell_capa;
552
553 cell_capa[0] = WLAN_EID_VENDOR_SPECIFIC;
554 cell_capa[1] = 5; /* Length */
555 WPA_PUT_BE24(cell_capa + 2, OUI_WFA);
556 cell_capa[5] = MBO_ATTR_ID_CELL_DATA_CAPA;
557 cell_capa[6] = mbo_cell_capa;
558
559 wpas_mbo_send_wnm_notification(wpa_s, cell_capa, 7);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700560 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800561}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800562
563
564struct wpabuf * mbo_build_anqp_buf(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700565 struct wpa_bss *bss, u32 mbo_subtypes)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800566{
567 struct wpabuf *anqp_buf;
568 u8 *len_pos;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700569 u8 i;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800570
571 if (!wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE)) {
572 wpa_printf(MSG_INFO, "MBO: " MACSTR
573 " does not support MBO - cannot request MBO ANQP elements from it",
574 MAC2STR(bss->bssid));
575 return NULL;
576 }
577
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700578 /* Allocate size for the maximum case - all MBO subtypes are set */
579 anqp_buf = wpabuf_alloc(9 + MAX_MBO_ANQP_SUBTYPE);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800580 if (!anqp_buf)
581 return NULL;
582
583 len_pos = gas_anqp_add_element(anqp_buf, ANQP_VENDOR_SPECIFIC);
584 wpabuf_put_be24(anqp_buf, OUI_WFA);
585 wpabuf_put_u8(anqp_buf, MBO_ANQP_OUI_TYPE);
586
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700587 wpabuf_put_u8(anqp_buf, MBO_ANQP_SUBTYPE_QUERY_LIST);
588
589 /* The first valid MBO subtype is 1 */
590 for (i = 1; i <= MAX_MBO_ANQP_SUBTYPE; i++) {
591 if (mbo_subtypes & BIT(i))
592 wpabuf_put_u8(anqp_buf, i);
593 }
594
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800595 gas_anqp_set_element_len(anqp_buf, len_pos);
596
597 return anqp_buf;
598}
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700599
600
601void mbo_parse_rx_anqp_resp(struct wpa_supplicant *wpa_s,
602 struct wpa_bss *bss, const u8 *sa,
603 const u8 *data, size_t slen)
604{
605 const u8 *pos = data;
606 u8 subtype;
607
608 if (slen < 1)
609 return;
610
611 subtype = *pos++;
612 slen--;
613
614 switch (subtype) {
615 case MBO_ANQP_SUBTYPE_CELL_CONN_PREF:
616 if (slen < 1)
617 break;
618 wpa_msg(wpa_s, MSG_INFO, RX_MBO_ANQP MACSTR
619 " cell_conn_pref=%u", MAC2STR(sa), *pos);
620 break;
621 default:
622 wpa_printf(MSG_DEBUG, "MBO: Unsupported ANQP subtype %u",
623 subtype);
624 break;
625 }
626}