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