xref: /freebsd/contrib/wpa/wpa_supplicant/mbo.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1780fb4a2SCy Schubert /*
2780fb4a2SCy Schubert  * wpa_supplicant - MBO
3780fb4a2SCy Schubert  *
4780fb4a2SCy Schubert  * Copyright(c) 2015 Intel Deutschland GmbH
5780fb4a2SCy Schubert  * Contact Information:
6780fb4a2SCy Schubert  * Intel Linux Wireless <ilw@linux.intel.com>
7780fb4a2SCy Schubert  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
8780fb4a2SCy Schubert  *
9780fb4a2SCy Schubert  * This software may be distributed under the terms of the BSD license.
10780fb4a2SCy Schubert  * See README for more details.
11780fb4a2SCy Schubert  */
12780fb4a2SCy Schubert 
13780fb4a2SCy Schubert #include "utils/includes.h"
14780fb4a2SCy Schubert 
15780fb4a2SCy Schubert #include "utils/common.h"
16780fb4a2SCy Schubert #include "common/ieee802_11_defs.h"
17780fb4a2SCy Schubert #include "common/gas.h"
18c1d255d3SCy Schubert #include "rsn_supp/wpa.h"
19780fb4a2SCy Schubert #include "config.h"
20780fb4a2SCy Schubert #include "wpa_supplicant_i.h"
21780fb4a2SCy Schubert #include "driver_i.h"
22780fb4a2SCy Schubert #include "bss.h"
23780fb4a2SCy Schubert #include "scan.h"
24780fb4a2SCy Schubert 
25780fb4a2SCy Schubert /* type + length + oui + oui type */
26780fb4a2SCy Schubert #define MBO_IE_HEADER 6
27780fb4a2SCy Schubert 
28780fb4a2SCy Schubert 
wpas_mbo_validate_non_pref_chan(u8 oper_class,u8 chan,u8 reason)29780fb4a2SCy Schubert static int wpas_mbo_validate_non_pref_chan(u8 oper_class, u8 chan, u8 reason)
30780fb4a2SCy Schubert {
31780fb4a2SCy Schubert 	if (reason > MBO_NON_PREF_CHAN_REASON_INT_INTERFERENCE)
32780fb4a2SCy Schubert 		return -1;
33780fb4a2SCy Schubert 
34780fb4a2SCy Schubert 	/* Only checking the validity of the channel and oper_class */
35780fb4a2SCy Schubert 	if (ieee80211_chan_to_freq(NULL, oper_class, chan) == -1)
36780fb4a2SCy Schubert 		return -1;
37780fb4a2SCy Schubert 
38780fb4a2SCy Schubert 	return 0;
39780fb4a2SCy Schubert }
40780fb4a2SCy Schubert 
41780fb4a2SCy Schubert 
mbo_attr_from_mbo_ie(const u8 * mbo_ie,enum mbo_attr_id attr)4285732ac8SCy Schubert const u8 * mbo_attr_from_mbo_ie(const u8 *mbo_ie, enum mbo_attr_id attr)
4385732ac8SCy Schubert {
4485732ac8SCy Schubert 	const u8 *mbo;
4585732ac8SCy Schubert 	u8 ie_len = mbo_ie[1];
4685732ac8SCy Schubert 
4785732ac8SCy Schubert 	if (ie_len < MBO_IE_HEADER - 2)
4885732ac8SCy Schubert 		return NULL;
4985732ac8SCy Schubert 	mbo = mbo_ie + MBO_IE_HEADER;
5085732ac8SCy Schubert 
5185732ac8SCy Schubert 	return get_ie(mbo, 2 + ie_len - MBO_IE_HEADER, attr);
5285732ac8SCy Schubert }
5385732ac8SCy Schubert 
5485732ac8SCy Schubert 
mbo_get_attr_from_ies(const u8 * ies,size_t ies_len,enum mbo_attr_id attr)554bc52338SCy Schubert const u8 * mbo_get_attr_from_ies(const u8 *ies, size_t ies_len,
564bc52338SCy Schubert 				 enum mbo_attr_id attr)
574bc52338SCy Schubert {
584bc52338SCy Schubert 	const u8 *mbo_ie;
594bc52338SCy Schubert 
604bc52338SCy Schubert 	mbo_ie = get_vendor_ie(ies, ies_len, MBO_IE_VENDOR_TYPE);
614bc52338SCy Schubert 	if (!mbo_ie)
624bc52338SCy Schubert 		return NULL;
634bc52338SCy Schubert 
644bc52338SCy Schubert 	return mbo_attr_from_mbo_ie(mbo_ie, attr);
654bc52338SCy Schubert }
664bc52338SCy Schubert 
674bc52338SCy Schubert 
wpas_mbo_get_bss_attr(struct wpa_bss * bss,enum mbo_attr_id attr,bool beacon)68*a90b9d01SCy Schubert static const u8 * wpas_mbo_get_bss_attr(struct wpa_bss *bss,
69*a90b9d01SCy Schubert 					enum mbo_attr_id attr, bool beacon)
70780fb4a2SCy Schubert {
71780fb4a2SCy Schubert 	const u8 *mbo, *end;
72780fb4a2SCy Schubert 
73780fb4a2SCy Schubert 	if (!bss)
74780fb4a2SCy Schubert 		return NULL;
75780fb4a2SCy Schubert 
76*a90b9d01SCy Schubert 	if (beacon)
77*a90b9d01SCy Schubert 		mbo = wpa_bss_get_vendor_ie_beacon(bss, MBO_IE_VENDOR_TYPE);
78*a90b9d01SCy Schubert 	else
79780fb4a2SCy Schubert 		mbo = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE);
80780fb4a2SCy Schubert 	if (!mbo)
81780fb4a2SCy Schubert 		return NULL;
82780fb4a2SCy Schubert 
83780fb4a2SCy Schubert 	end = mbo + 2 + mbo[1];
84780fb4a2SCy Schubert 	mbo += MBO_IE_HEADER;
85780fb4a2SCy Schubert 
86780fb4a2SCy Schubert 	return get_ie(mbo, end - mbo, attr);
87780fb4a2SCy Schubert }
88780fb4a2SCy Schubert 
89780fb4a2SCy Schubert 
wpas_mbo_check_assoc_disallow(struct wpa_bss * bss)90*a90b9d01SCy Schubert const u8 * wpas_mbo_check_assoc_disallow(struct wpa_bss *bss)
91*a90b9d01SCy Schubert {
92*a90b9d01SCy Schubert 	const u8 *assoc_disallow;
93*a90b9d01SCy Schubert 
94*a90b9d01SCy Schubert 	assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW,
95*a90b9d01SCy Schubert 					       bss->beacon_newer);
96*a90b9d01SCy Schubert 	if (assoc_disallow && assoc_disallow[1] >= 1)
97*a90b9d01SCy Schubert 		return assoc_disallow;
98*a90b9d01SCy Schubert 
99*a90b9d01SCy Schubert 	return NULL;
100*a90b9d01SCy Schubert }
101*a90b9d01SCy Schubert 
102*a90b9d01SCy Schubert 
wpas_mbo_check_pmf(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,struct wpa_ssid * ssid)103c1d255d3SCy Schubert void wpas_mbo_check_pmf(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
104c1d255d3SCy Schubert 			struct wpa_ssid *ssid)
105c1d255d3SCy Schubert {
106c1d255d3SCy Schubert 	const u8 *rsne, *mbo, *oce;
107c1d255d3SCy Schubert 	struct wpa_ie_data ie;
108c1d255d3SCy Schubert 
109c1d255d3SCy Schubert 	wpa_s->disable_mbo_oce = 0;
110c1d255d3SCy Schubert 	if (!bss)
111c1d255d3SCy Schubert 		return;
112*a90b9d01SCy Schubert 	mbo = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND, false);
113*a90b9d01SCy Schubert 	oce = wpas_mbo_get_bss_attr(bss, OCE_ATTR_ID_CAPA_IND, false);
114c1d255d3SCy Schubert 	if (!mbo && !oce)
115c1d255d3SCy Schubert 		return;
116c1d255d3SCy Schubert 	if (oce && oce[1] >= 1 && (oce[2] & OCE_IS_STA_CFON))
117c1d255d3SCy Schubert 		return; /* STA-CFON is not required to enable PMF */
118c1d255d3SCy Schubert 	rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
119c1d255d3SCy Schubert 	if (!rsne || wpa_parse_wpa_ie(rsne, 2 + rsne[1], &ie) < 0)
120c1d255d3SCy Schubert 		return; /* AP is not using RSN */
121c1d255d3SCy Schubert 
122c1d255d3SCy Schubert 	if (!(ie.capabilities & WPA_CAPABILITY_MFPC))
123c1d255d3SCy Schubert 		wpa_s->disable_mbo_oce = 1; /* AP uses RSN without PMF */
124c1d255d3SCy Schubert 	if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION)
125c1d255d3SCy Schubert 		wpa_s->disable_mbo_oce = 1; /* STA uses RSN without PMF */
126c1d255d3SCy Schubert 	if (wpa_s->disable_mbo_oce)
127c1d255d3SCy Schubert 		wpa_printf(MSG_INFO,
128c1d255d3SCy Schubert 			   "MBO: Disable MBO/OCE due to misbehaving AP not having enabled PMF");
129c1d255d3SCy Schubert }
130c1d255d3SCy Schubert 
131c1d255d3SCy Schubert 
wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,u8 start,u8 end)132780fb4a2SCy Schubert static void wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant *wpa_s,
133780fb4a2SCy Schubert 					     struct wpabuf *mbo,
134780fb4a2SCy Schubert 					     u8 start, u8 end)
135780fb4a2SCy Schubert {
136780fb4a2SCy Schubert 	u8 i;
137780fb4a2SCy Schubert 
138780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].oper_class);
139780fb4a2SCy Schubert 
140780fb4a2SCy Schubert 	for (i = start; i < end; i++)
141780fb4a2SCy Schubert 		wpabuf_put_u8(mbo, wpa_s->non_pref_chan[i].chan);
142780fb4a2SCy Schubert 
143780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].preference);
144780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason);
145780fb4a2SCy Schubert }
146780fb4a2SCy Schubert 
147780fb4a2SCy Schubert 
wpas_mbo_non_pref_chan_attr_hdr(struct wpabuf * mbo,size_t size)1484bc52338SCy Schubert static void wpas_mbo_non_pref_chan_attr_hdr(struct wpabuf *mbo, size_t size)
1494bc52338SCy Schubert {
1504bc52338SCy Schubert 	wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
1514bc52338SCy Schubert 	wpabuf_put_u8(mbo, size); /* Length */
1524bc52338SCy Schubert }
1534bc52338SCy Schubert 
1544bc52338SCy Schubert 
wpas_mbo_non_pref_chan_attr(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,u8 start,u8 end)155780fb4a2SCy Schubert static void wpas_mbo_non_pref_chan_attr(struct wpa_supplicant *wpa_s,
156780fb4a2SCy Schubert 					struct wpabuf *mbo, u8 start, u8 end)
157780fb4a2SCy Schubert {
158780fb4a2SCy Schubert 	size_t size = end - start + 3;
159780fb4a2SCy Schubert 
160780fb4a2SCy Schubert 	if (size + 2 > wpabuf_tailroom(mbo))
161780fb4a2SCy Schubert 		return;
162780fb4a2SCy Schubert 
1634bc52338SCy Schubert 	wpas_mbo_non_pref_chan_attr_hdr(mbo, size);
164780fb4a2SCy Schubert 	wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
165780fb4a2SCy Schubert }
166780fb4a2SCy Schubert 
167780fb4a2SCy Schubert 
wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf * mbo,u8 len)168780fb4a2SCy Schubert static void wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf *mbo, u8 len)
169780fb4a2SCy Schubert {
170780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, WLAN_EID_VENDOR_SPECIFIC);
171780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, len); /* Length */
172780fb4a2SCy Schubert 	wpabuf_put_be24(mbo, OUI_WFA);
173780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
174780fb4a2SCy Schubert }
175780fb4a2SCy Schubert 
176780fb4a2SCy Schubert 
wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,u8 start,u8 end)177780fb4a2SCy Schubert static void wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant *wpa_s,
178780fb4a2SCy Schubert 					      struct wpabuf *mbo, u8 start,
179780fb4a2SCy Schubert 					      u8 end)
180780fb4a2SCy Schubert {
181780fb4a2SCy Schubert 	size_t size = end - start + 7;
182780fb4a2SCy Schubert 
183780fb4a2SCy Schubert 	if (size + 2 > wpabuf_tailroom(mbo))
184780fb4a2SCy Schubert 		return;
185780fb4a2SCy Schubert 
186780fb4a2SCy Schubert 	wpas_mbo_non_pref_chan_subelem_hdr(mbo, size);
187780fb4a2SCy Schubert 	wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
188780fb4a2SCy Schubert }
189780fb4a2SCy Schubert 
190780fb4a2SCy Schubert 
wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant * wpa_s,struct wpabuf * mbo,int subelement)191780fb4a2SCy Schubert static void wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant *wpa_s,
192780fb4a2SCy Schubert 					 struct wpabuf *mbo, int subelement)
193780fb4a2SCy Schubert {
194780fb4a2SCy Schubert 	u8 i, start = 0;
195780fb4a2SCy Schubert 	struct wpa_mbo_non_pref_channel *start_pref;
196780fb4a2SCy Schubert 
197780fb4a2SCy Schubert 	if (!wpa_s->non_pref_chan || !wpa_s->non_pref_chan_num) {
198780fb4a2SCy Schubert 		if (subelement)
199780fb4a2SCy Schubert 			wpas_mbo_non_pref_chan_subelem_hdr(mbo, 4);
2004bc52338SCy Schubert 		else
2014bc52338SCy Schubert 			wpas_mbo_non_pref_chan_attr_hdr(mbo, 0);
202780fb4a2SCy Schubert 		return;
203780fb4a2SCy Schubert 	}
204780fb4a2SCy Schubert 	start_pref = &wpa_s->non_pref_chan[0];
205780fb4a2SCy Schubert 
206780fb4a2SCy Schubert 	for (i = 1; i <= wpa_s->non_pref_chan_num; i++) {
207780fb4a2SCy Schubert 		struct wpa_mbo_non_pref_channel *non_pref = NULL;
208780fb4a2SCy Schubert 
209780fb4a2SCy Schubert 		if (i < wpa_s->non_pref_chan_num)
210780fb4a2SCy Schubert 			non_pref = &wpa_s->non_pref_chan[i];
211780fb4a2SCy Schubert 		if (!non_pref ||
212780fb4a2SCy Schubert 		    non_pref->oper_class != start_pref->oper_class ||
213780fb4a2SCy Schubert 		    non_pref->reason != start_pref->reason ||
214780fb4a2SCy Schubert 		    non_pref->preference != start_pref->preference) {
215780fb4a2SCy Schubert 			if (subelement)
216780fb4a2SCy Schubert 				wpas_mbo_non_pref_chan_subelement(wpa_s, mbo,
217780fb4a2SCy Schubert 								  start, i);
218780fb4a2SCy Schubert 			else
219780fb4a2SCy Schubert 				wpas_mbo_non_pref_chan_attr(wpa_s, mbo, start,
220780fb4a2SCy Schubert 							    i);
221780fb4a2SCy Schubert 
222780fb4a2SCy Schubert 			if (!non_pref)
223780fb4a2SCy Schubert 				return;
224780fb4a2SCy Schubert 
225780fb4a2SCy Schubert 			start = i;
226780fb4a2SCy Schubert 			start_pref = non_pref;
227780fb4a2SCy Schubert 		}
228780fb4a2SCy Schubert 	}
229780fb4a2SCy Schubert }
230780fb4a2SCy Schubert 
231780fb4a2SCy Schubert 
wpas_mbo_ie(struct wpa_supplicant * wpa_s,u8 * buf,size_t len,int add_oce_capa)23285732ac8SCy Schubert int wpas_mbo_ie(struct wpa_supplicant *wpa_s, u8 *buf, size_t len,
23385732ac8SCy Schubert 		int add_oce_capa)
234780fb4a2SCy Schubert {
235780fb4a2SCy Schubert 	struct wpabuf *mbo;
236780fb4a2SCy Schubert 	int res;
237780fb4a2SCy Schubert 
23885732ac8SCy Schubert 	if (len < MBO_IE_HEADER + 3 + 7 +
23985732ac8SCy Schubert 	    ((wpa_s->enable_oce & OCE_STA) ? 3 : 0))
240780fb4a2SCy Schubert 		return 0;
241780fb4a2SCy Schubert 
242780fb4a2SCy Schubert 	/* Leave room for the MBO IE header */
243780fb4a2SCy Schubert 	mbo = wpabuf_alloc(len - MBO_IE_HEADER);
244780fb4a2SCy Schubert 	if (!mbo)
245780fb4a2SCy Schubert 		return 0;
246780fb4a2SCy Schubert 
247780fb4a2SCy Schubert 	/* Add non-preferred channels attribute */
248780fb4a2SCy Schubert 	wpas_mbo_non_pref_chan_attrs(wpa_s, mbo, 0);
249780fb4a2SCy Schubert 
250780fb4a2SCy Schubert 	/*
251780fb4a2SCy Schubert 	 * Send cellular capabilities attribute even if AP does not advertise
252780fb4a2SCy Schubert 	 * cellular capabilities.
253780fb4a2SCy Schubert 	 */
254780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, MBO_ATTR_ID_CELL_DATA_CAPA);
255780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, 1);
256780fb4a2SCy Schubert 	wpabuf_put_u8(mbo, wpa_s->conf->mbo_cell_capa);
257780fb4a2SCy Schubert 
25885732ac8SCy Schubert 	/* Add OCE capability indication attribute if OCE is enabled */
25985732ac8SCy Schubert 	if ((wpa_s->enable_oce & OCE_STA) && add_oce_capa) {
26085732ac8SCy Schubert 		wpabuf_put_u8(mbo, OCE_ATTR_ID_CAPA_IND);
26185732ac8SCy Schubert 		wpabuf_put_u8(mbo, 1);
26285732ac8SCy Schubert 		wpabuf_put_u8(mbo, OCE_RELEASE);
26385732ac8SCy Schubert 	}
26485732ac8SCy Schubert 
265780fb4a2SCy Schubert 	res = mbo_add_ie(buf, len, wpabuf_head_u8(mbo), wpabuf_len(mbo));
266780fb4a2SCy Schubert 	if (!res)
26785732ac8SCy Schubert 		wpa_printf(MSG_ERROR, "Failed to add MBO/OCE IE");
268780fb4a2SCy Schubert 
269780fb4a2SCy Schubert 	wpabuf_free(mbo);
270780fb4a2SCy Schubert 	return res;
271780fb4a2SCy Schubert }
272780fb4a2SCy Schubert 
273780fb4a2SCy Schubert 
wpas_mbo_send_wnm_notification(struct wpa_supplicant * wpa_s,const u8 * data,size_t len)274780fb4a2SCy Schubert static void wpas_mbo_send_wnm_notification(struct wpa_supplicant *wpa_s,
275780fb4a2SCy Schubert 					   const u8 *data, size_t len)
276780fb4a2SCy Schubert {
277780fb4a2SCy Schubert 	struct wpabuf *buf;
278780fb4a2SCy Schubert 	int res;
279780fb4a2SCy Schubert 
280780fb4a2SCy Schubert 	/*
281780fb4a2SCy Schubert 	 * Send WNM-Notification Request frame only in case of a change in
282780fb4a2SCy Schubert 	 * non-preferred channels list during association, if the AP supports
283780fb4a2SCy Schubert 	 * MBO.
284780fb4a2SCy Schubert 	 */
285780fb4a2SCy Schubert 	if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_bss ||
286780fb4a2SCy Schubert 	    !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
287780fb4a2SCy Schubert 		return;
288780fb4a2SCy Schubert 
289780fb4a2SCy Schubert 	buf = wpabuf_alloc(4 + len);
290780fb4a2SCy Schubert 	if (!buf)
291780fb4a2SCy Schubert 		return;
292780fb4a2SCy Schubert 
293780fb4a2SCy Schubert 	wpabuf_put_u8(buf, WLAN_ACTION_WNM);
294780fb4a2SCy Schubert 	wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
295780fb4a2SCy Schubert 	wpa_s->mbo_wnm_token++;
296780fb4a2SCy Schubert 	if (wpa_s->mbo_wnm_token == 0)
297780fb4a2SCy Schubert 		wpa_s->mbo_wnm_token++;
298780fb4a2SCy Schubert 	wpabuf_put_u8(buf, wpa_s->mbo_wnm_token);
299780fb4a2SCy Schubert 	wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); /* Type */
300780fb4a2SCy Schubert 
301780fb4a2SCy Schubert 	wpabuf_put_data(buf, data, len);
302780fb4a2SCy Schubert 
303780fb4a2SCy Schubert 	res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
304780fb4a2SCy Schubert 				  wpa_s->own_addr, wpa_s->bssid,
305780fb4a2SCy Schubert 				  wpabuf_head(buf), wpabuf_len(buf), 0);
306780fb4a2SCy Schubert 	if (res < 0)
307780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG,
308780fb4a2SCy Schubert 			   "Failed to send WNM-Notification Request frame with non-preferred channel list");
309780fb4a2SCy Schubert 
310780fb4a2SCy Schubert 	wpabuf_free(buf);
311780fb4a2SCy Schubert }
312780fb4a2SCy Schubert 
313780fb4a2SCy Schubert 
wpas_mbo_non_pref_chan_changed(struct wpa_supplicant * wpa_s)314780fb4a2SCy Schubert static void wpas_mbo_non_pref_chan_changed(struct wpa_supplicant *wpa_s)
315780fb4a2SCy Schubert {
316780fb4a2SCy Schubert 	struct wpabuf *buf;
317780fb4a2SCy Schubert 
318780fb4a2SCy Schubert 	buf = wpabuf_alloc(512);
319780fb4a2SCy Schubert 	if (!buf)
320780fb4a2SCy Schubert 		return;
321780fb4a2SCy Schubert 
322780fb4a2SCy Schubert 	wpas_mbo_non_pref_chan_attrs(wpa_s, buf, 1);
323780fb4a2SCy Schubert 	wpas_mbo_send_wnm_notification(wpa_s, wpabuf_head_u8(buf),
324780fb4a2SCy Schubert 				       wpabuf_len(buf));
3254bc52338SCy Schubert 	wpas_update_mbo_connect_params(wpa_s);
326780fb4a2SCy Schubert 	wpabuf_free(buf);
327780fb4a2SCy Schubert }
328780fb4a2SCy Schubert 
329780fb4a2SCy Schubert 
wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel * a,struct wpa_mbo_non_pref_channel * b)330780fb4a2SCy Schubert static int wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel *a,
331780fb4a2SCy Schubert 				   struct wpa_mbo_non_pref_channel *b)
332780fb4a2SCy Schubert {
333780fb4a2SCy Schubert 	return a->oper_class == b->oper_class && a->chan == b->chan;
334780fb4a2SCy Schubert }
335780fb4a2SCy Schubert 
336780fb4a2SCy Schubert 
337780fb4a2SCy Schubert /*
338780fb4a2SCy Schubert  * wpa_non_pref_chan_cmp - Compare two channels for sorting
339780fb4a2SCy Schubert  *
340780fb4a2SCy Schubert  * In MBO IE non-preferred channel subelement we can put many channels in an
341780fb4a2SCy Schubert  * attribute if they are in the same operating class and have the same
342780fb4a2SCy Schubert  * preference and reason. To make it easy for the functions that build
343780fb4a2SCy Schubert  * the IE attributes and WNM Request subelements, save the channels sorted
344780fb4a2SCy Schubert  * by their oper_class and reason.
345780fb4a2SCy Schubert  */
wpa_non_pref_chan_cmp(const void * _a,const void * _b)346780fb4a2SCy Schubert static int wpa_non_pref_chan_cmp(const void *_a, const void *_b)
347780fb4a2SCy Schubert {
348780fb4a2SCy Schubert 	const struct wpa_mbo_non_pref_channel *a = _a, *b = _b;
349780fb4a2SCy Schubert 
350780fb4a2SCy Schubert 	if (a->oper_class != b->oper_class)
3514bc52338SCy Schubert 		return (int) a->oper_class - (int) b->oper_class;
352780fb4a2SCy Schubert 	if (a->reason != b->reason)
3534bc52338SCy Schubert 		return (int) a->reason - (int) b->reason;
3544bc52338SCy Schubert 	return (int) a->preference - (int) b->preference;
355780fb4a2SCy Schubert }
356780fb4a2SCy Schubert 
357780fb4a2SCy Schubert 
wpas_mbo_update_non_pref_chan(struct wpa_supplicant * wpa_s,const char * non_pref_chan)358780fb4a2SCy Schubert int wpas_mbo_update_non_pref_chan(struct wpa_supplicant *wpa_s,
359780fb4a2SCy Schubert 				  const char *non_pref_chan)
360780fb4a2SCy Schubert {
361780fb4a2SCy Schubert 	char *cmd, *token, *context = NULL;
362780fb4a2SCy Schubert 	struct wpa_mbo_non_pref_channel *chans = NULL, *tmp_chans;
363780fb4a2SCy Schubert 	size_t num = 0, size = 0;
364780fb4a2SCy Schubert 	unsigned i;
365780fb4a2SCy Schubert 
366780fb4a2SCy Schubert 	wpa_printf(MSG_DEBUG, "MBO: Update non-preferred channels, non_pref_chan=%s",
367780fb4a2SCy Schubert 		   non_pref_chan ? non_pref_chan : "N/A");
368780fb4a2SCy Schubert 
369780fb4a2SCy Schubert 	/*
37085732ac8SCy Schubert 	 * The shortest channel configuration is 7 characters - 3 colons and
37185732ac8SCy Schubert 	 * 4 values.
372780fb4a2SCy Schubert 	 */
37385732ac8SCy Schubert 	if (!non_pref_chan || os_strlen(non_pref_chan) < 7)
374780fb4a2SCy Schubert 		goto update;
375780fb4a2SCy Schubert 
376780fb4a2SCy Schubert 	cmd = os_strdup(non_pref_chan);
377780fb4a2SCy Schubert 	if (!cmd)
378780fb4a2SCy Schubert 		return -1;
379780fb4a2SCy Schubert 
380780fb4a2SCy Schubert 	while ((token = str_token(cmd, " ", &context))) {
381780fb4a2SCy Schubert 		struct wpa_mbo_non_pref_channel *chan;
382780fb4a2SCy Schubert 		int ret;
383780fb4a2SCy Schubert 		unsigned int _oper_class;
384780fb4a2SCy Schubert 		unsigned int _chan;
385780fb4a2SCy Schubert 		unsigned int _preference;
386780fb4a2SCy Schubert 		unsigned int _reason;
387780fb4a2SCy Schubert 
388780fb4a2SCy Schubert 		if (num == size) {
389780fb4a2SCy Schubert 			size = size ? size * 2 : 1;
390780fb4a2SCy Schubert 			tmp_chans = os_realloc_array(chans, size,
391780fb4a2SCy Schubert 						     sizeof(*chans));
392780fb4a2SCy Schubert 			if (!tmp_chans) {
393780fb4a2SCy Schubert 				wpa_printf(MSG_ERROR,
394780fb4a2SCy Schubert 					   "Couldn't reallocate non_pref_chan");
395780fb4a2SCy Schubert 				goto fail;
396780fb4a2SCy Schubert 			}
397780fb4a2SCy Schubert 			chans = tmp_chans;
398780fb4a2SCy Schubert 		}
399780fb4a2SCy Schubert 
400780fb4a2SCy Schubert 		chan = &chans[num];
401780fb4a2SCy Schubert 
402780fb4a2SCy Schubert 		ret = sscanf(token, "%u:%u:%u:%u", &_oper_class,
403780fb4a2SCy Schubert 			     &_chan, &_preference, &_reason);
404780fb4a2SCy Schubert 		if (ret != 4 ||
405780fb4a2SCy Schubert 		    _oper_class > 255 || _chan > 255 ||
406780fb4a2SCy Schubert 		    _preference > 255 || _reason > 65535 ) {
407780fb4a2SCy Schubert 			wpa_printf(MSG_ERROR, "Invalid non-pref chan input %s",
408780fb4a2SCy Schubert 				   token);
409780fb4a2SCy Schubert 			goto fail;
410780fb4a2SCy Schubert 		}
411780fb4a2SCy Schubert 		chan->oper_class = _oper_class;
412780fb4a2SCy Schubert 		chan->chan = _chan;
413780fb4a2SCy Schubert 		chan->preference = _preference;
414780fb4a2SCy Schubert 		chan->reason = _reason;
415780fb4a2SCy Schubert 
416780fb4a2SCy Schubert 		if (wpas_mbo_validate_non_pref_chan(chan->oper_class,
417780fb4a2SCy Schubert 						    chan->chan, chan->reason)) {
418780fb4a2SCy Schubert 			wpa_printf(MSG_ERROR,
419780fb4a2SCy Schubert 				   "Invalid non_pref_chan: oper class %d chan %d reason %d",
420780fb4a2SCy Schubert 				   chan->oper_class, chan->chan, chan->reason);
421780fb4a2SCy Schubert 			goto fail;
422780fb4a2SCy Schubert 		}
423780fb4a2SCy Schubert 
424780fb4a2SCy Schubert 		for (i = 0; i < num; i++)
425780fb4a2SCy Schubert 			if (wpa_non_pref_chan_is_eq(chan, &chans[i]))
426780fb4a2SCy Schubert 				break;
427780fb4a2SCy Schubert 		if (i != num) {
428780fb4a2SCy Schubert 			wpa_printf(MSG_ERROR,
429780fb4a2SCy Schubert 				   "oper class %d chan %d is duplicated",
430780fb4a2SCy Schubert 				   chan->oper_class, chan->chan);
431780fb4a2SCy Schubert 			goto fail;
432780fb4a2SCy Schubert 		}
433780fb4a2SCy Schubert 
434780fb4a2SCy Schubert 		num++;
435780fb4a2SCy Schubert 	}
436780fb4a2SCy Schubert 
437780fb4a2SCy Schubert 	os_free(cmd);
438780fb4a2SCy Schubert 
439780fb4a2SCy Schubert 	if (chans) {
440780fb4a2SCy Schubert 		qsort(chans, num, sizeof(struct wpa_mbo_non_pref_channel),
441780fb4a2SCy Schubert 		      wpa_non_pref_chan_cmp);
442780fb4a2SCy Schubert 	}
443780fb4a2SCy Schubert 
444780fb4a2SCy Schubert update:
445780fb4a2SCy Schubert 	os_free(wpa_s->non_pref_chan);
446780fb4a2SCy Schubert 	wpa_s->non_pref_chan = chans;
447780fb4a2SCy Schubert 	wpa_s->non_pref_chan_num = num;
448780fb4a2SCy Schubert 	wpas_mbo_non_pref_chan_changed(wpa_s);
449780fb4a2SCy Schubert 
450780fb4a2SCy Schubert 	return 0;
451780fb4a2SCy Schubert 
452780fb4a2SCy Schubert fail:
453780fb4a2SCy Schubert 	os_free(chans);
454780fb4a2SCy Schubert 	os_free(cmd);
455780fb4a2SCy Schubert 	return -1;
456780fb4a2SCy Schubert }
457780fb4a2SCy Schubert 
458780fb4a2SCy Schubert 
wpas_mbo_scan_ie(struct wpa_supplicant * wpa_s,struct wpabuf * ie)459780fb4a2SCy Schubert void wpas_mbo_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ie)
460780fb4a2SCy Schubert {
46185732ac8SCy Schubert 	u8 *len;
46285732ac8SCy Schubert 
463780fb4a2SCy Schubert 	wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
46485732ac8SCy Schubert 	len = wpabuf_put(ie, 1);
46585732ac8SCy Schubert 
466780fb4a2SCy Schubert 	wpabuf_put_be24(ie, OUI_WFA);
467780fb4a2SCy Schubert 	wpabuf_put_u8(ie, MBO_OUI_TYPE);
468780fb4a2SCy Schubert 
469780fb4a2SCy Schubert 	wpabuf_put_u8(ie, MBO_ATTR_ID_CELL_DATA_CAPA);
470780fb4a2SCy Schubert 	wpabuf_put_u8(ie, 1);
471780fb4a2SCy Schubert 	wpabuf_put_u8(ie, wpa_s->conf->mbo_cell_capa);
47285732ac8SCy Schubert 	if (wpa_s->enable_oce & OCE_STA) {
47385732ac8SCy Schubert 		wpabuf_put_u8(ie, OCE_ATTR_ID_CAPA_IND);
47485732ac8SCy Schubert 		wpabuf_put_u8(ie, 1);
47585732ac8SCy Schubert 		wpabuf_put_u8(ie, OCE_RELEASE);
476780fb4a2SCy Schubert 	}
47785732ac8SCy Schubert 	*len = (u8 *) wpabuf_put(ie, 0) - len - 1;
478780fb4a2SCy Schubert }
479780fb4a2SCy Schubert 
480780fb4a2SCy Schubert 
wpas_mbo_ie_trans_req(struct wpa_supplicant * wpa_s,const u8 * mbo_ie,size_t len)481780fb4a2SCy Schubert void wpas_mbo_ie_trans_req(struct wpa_supplicant *wpa_s, const u8 *mbo_ie,
482780fb4a2SCy Schubert 			   size_t len)
483780fb4a2SCy Schubert {
48485732ac8SCy Schubert 	const u8 *pos, *cell_pref = NULL;
485780fb4a2SCy Schubert 	u8 id, elen;
486780fb4a2SCy Schubert 	u16 disallowed_sec = 0;
487780fb4a2SCy Schubert 
488780fb4a2SCy Schubert 	if (len <= 4 || WPA_GET_BE24(mbo_ie) != OUI_WFA ||
489780fb4a2SCy Schubert 	    mbo_ie[3] != MBO_OUI_TYPE)
490780fb4a2SCy Schubert 		return;
491780fb4a2SCy Schubert 
492780fb4a2SCy Schubert 	pos = mbo_ie + 4;
493780fb4a2SCy Schubert 	len -= 4;
494780fb4a2SCy Schubert 
495780fb4a2SCy Schubert 	while (len >= 2) {
496780fb4a2SCy Schubert 		id = *pos++;
497780fb4a2SCy Schubert 		elen = *pos++;
498780fb4a2SCy Schubert 		len -= 2;
499780fb4a2SCy Schubert 
500780fb4a2SCy Schubert 		if (elen > len)
501780fb4a2SCy Schubert 			goto fail;
502780fb4a2SCy Schubert 
503780fb4a2SCy Schubert 		switch (id) {
504780fb4a2SCy Schubert 		case MBO_ATTR_ID_CELL_DATA_PREF:
505780fb4a2SCy Schubert 			if (elen != 1)
506780fb4a2SCy Schubert 				goto fail;
507780fb4a2SCy Schubert 
508780fb4a2SCy Schubert 			if (wpa_s->conf->mbo_cell_capa ==
509780fb4a2SCy Schubert 			    MBO_CELL_CAPA_AVAILABLE)
510780fb4a2SCy Schubert 				cell_pref = pos;
511780fb4a2SCy Schubert 			else
512780fb4a2SCy Schubert 				wpa_printf(MSG_DEBUG,
513780fb4a2SCy Schubert 					   "MBO: Station does not support Cellular data connection");
514780fb4a2SCy Schubert 			break;
515780fb4a2SCy Schubert 		case MBO_ATTR_ID_TRANSITION_REASON:
516780fb4a2SCy Schubert 			if (elen != 1)
517780fb4a2SCy Schubert 				goto fail;
518780fb4a2SCy Schubert 
51985732ac8SCy Schubert 			wpa_s->wnm_mbo_trans_reason_present = 1;
52085732ac8SCy Schubert 			wpa_s->wnm_mbo_transition_reason = *pos;
521780fb4a2SCy Schubert 			break;
522780fb4a2SCy Schubert 		case MBO_ATTR_ID_ASSOC_RETRY_DELAY:
523780fb4a2SCy Schubert 			if (elen != 2)
524780fb4a2SCy Schubert 				goto fail;
525780fb4a2SCy Schubert 
526780fb4a2SCy Schubert 			if (wpa_s->wnm_mode &
527780fb4a2SCy Schubert 			    WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
528780fb4a2SCy Schubert 				wpa_printf(MSG_DEBUG,
529780fb4a2SCy Schubert 					   "MBO: Unexpected association retry delay, BSS is terminating");
530780fb4a2SCy Schubert 				goto fail;
531780fb4a2SCy Schubert 			} else if (wpa_s->wnm_mode &
532780fb4a2SCy Schubert 				   WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
533780fb4a2SCy Schubert 				disallowed_sec = WPA_GET_LE16(pos);
53485732ac8SCy Schubert 				wpa_printf(MSG_DEBUG,
53585732ac8SCy Schubert 					   "MBO: Association retry delay: %u",
53685732ac8SCy Schubert 					   disallowed_sec);
537780fb4a2SCy Schubert 			} else {
538780fb4a2SCy Schubert 				wpa_printf(MSG_DEBUG,
539780fb4a2SCy Schubert 					   "MBO: Association retry delay attribute not in disassoc imminent mode");
540780fb4a2SCy Schubert 			}
541780fb4a2SCy Schubert 
542780fb4a2SCy Schubert 			break;
543780fb4a2SCy Schubert 		case MBO_ATTR_ID_AP_CAPA_IND:
544780fb4a2SCy Schubert 		case MBO_ATTR_ID_NON_PREF_CHAN_REPORT:
545780fb4a2SCy Schubert 		case MBO_ATTR_ID_CELL_DATA_CAPA:
546780fb4a2SCy Schubert 		case MBO_ATTR_ID_ASSOC_DISALLOW:
547780fb4a2SCy Schubert 		case MBO_ATTR_ID_TRANSITION_REJECT_REASON:
548780fb4a2SCy Schubert 			wpa_printf(MSG_DEBUG,
549780fb4a2SCy Schubert 				   "MBO: Attribute %d should not be included in BTM Request frame",
550780fb4a2SCy Schubert 				   id);
551780fb4a2SCy Schubert 			break;
552780fb4a2SCy Schubert 		default:
553780fb4a2SCy Schubert 			wpa_printf(MSG_DEBUG, "MBO: Unknown attribute id %u",
554780fb4a2SCy Schubert 				   id);
555780fb4a2SCy Schubert 			return;
556780fb4a2SCy Schubert 		}
557780fb4a2SCy Schubert 
558780fb4a2SCy Schubert 		pos += elen;
559780fb4a2SCy Schubert 		len -= elen;
560780fb4a2SCy Schubert 	}
561780fb4a2SCy Schubert 
562780fb4a2SCy Schubert 	if (cell_pref)
563780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, MBO_CELL_PREFERENCE "preference=%u",
564780fb4a2SCy Schubert 			*cell_pref);
565780fb4a2SCy Schubert 
56685732ac8SCy Schubert 	if (wpa_s->wnm_mbo_trans_reason_present)
567780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, MBO_TRANSITION_REASON "reason=%u",
56885732ac8SCy Schubert 			wpa_s->wnm_mbo_transition_reason);
569780fb4a2SCy Schubert 
570780fb4a2SCy Schubert 	if (disallowed_sec && wpa_s->current_bss)
571780fb4a2SCy Schubert 		wpa_bss_tmp_disallow(wpa_s, wpa_s->current_bss->bssid,
5724bc52338SCy Schubert 				     disallowed_sec, 0);
573780fb4a2SCy Schubert 
574780fb4a2SCy Schubert 	return;
575780fb4a2SCy Schubert fail:
576780fb4a2SCy Schubert 	wpa_printf(MSG_DEBUG, "MBO IE parsing failed (id=%u len=%u left=%zu)",
577780fb4a2SCy Schubert 		   id, elen, len);
578780fb4a2SCy Schubert }
579780fb4a2SCy Schubert 
580780fb4a2SCy Schubert 
wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant * wpa_s,u8 * pos,size_t len,enum mbo_transition_reject_reason reason)581780fb4a2SCy Schubert size_t wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant *wpa_s, u8 *pos,
582780fb4a2SCy Schubert 				    size_t len,
583780fb4a2SCy Schubert 				    enum mbo_transition_reject_reason reason)
584780fb4a2SCy Schubert {
585780fb4a2SCy Schubert 	u8 reject_attr[3];
586780fb4a2SCy Schubert 
587780fb4a2SCy Schubert 	reject_attr[0] = MBO_ATTR_ID_TRANSITION_REJECT_REASON;
588780fb4a2SCy Schubert 	reject_attr[1] = 1;
589780fb4a2SCy Schubert 	reject_attr[2] = reason;
590780fb4a2SCy Schubert 
591780fb4a2SCy Schubert 	return mbo_add_ie(pos, len, reject_attr, sizeof(reject_attr));
592780fb4a2SCy Schubert }
593780fb4a2SCy Schubert 
594780fb4a2SCy Schubert 
wpas_mbo_update_cell_capa(struct wpa_supplicant * wpa_s,u8 mbo_cell_capa)595780fb4a2SCy Schubert void wpas_mbo_update_cell_capa(struct wpa_supplicant *wpa_s, u8 mbo_cell_capa)
596780fb4a2SCy Schubert {
597780fb4a2SCy Schubert 	u8 cell_capa[7];
598780fb4a2SCy Schubert 
599780fb4a2SCy Schubert 	if (wpa_s->conf->mbo_cell_capa == mbo_cell_capa) {
600780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG,
601780fb4a2SCy Schubert 			   "MBO: Cellular capability already set to %u",
602780fb4a2SCy Schubert 			   mbo_cell_capa);
603780fb4a2SCy Schubert 		return;
604780fb4a2SCy Schubert 	}
605780fb4a2SCy Schubert 
606780fb4a2SCy Schubert 	wpa_s->conf->mbo_cell_capa = mbo_cell_capa;
607780fb4a2SCy Schubert 
608780fb4a2SCy Schubert 	cell_capa[0] = WLAN_EID_VENDOR_SPECIFIC;
609780fb4a2SCy Schubert 	cell_capa[1] = 5; /* Length */
610780fb4a2SCy Schubert 	WPA_PUT_BE24(cell_capa + 2, OUI_WFA);
611780fb4a2SCy Schubert 	cell_capa[5] = MBO_ATTR_ID_CELL_DATA_CAPA;
612780fb4a2SCy Schubert 	cell_capa[6] = mbo_cell_capa;
613780fb4a2SCy Schubert 
614780fb4a2SCy Schubert 	wpas_mbo_send_wnm_notification(wpa_s, cell_capa, 7);
615780fb4a2SCy Schubert 	wpa_supplicant_set_default_scan_ies(wpa_s);
6164bc52338SCy Schubert 	wpas_update_mbo_connect_params(wpa_s);
617780fb4a2SCy Schubert }
618780fb4a2SCy Schubert 
619780fb4a2SCy Schubert 
mbo_build_anqp_buf(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,u32 mbo_subtypes)620780fb4a2SCy Schubert struct wpabuf * mbo_build_anqp_buf(struct wpa_supplicant *wpa_s,
62185732ac8SCy Schubert 				   struct wpa_bss *bss, u32 mbo_subtypes)
622780fb4a2SCy Schubert {
623780fb4a2SCy Schubert 	struct wpabuf *anqp_buf;
624780fb4a2SCy Schubert 	u8 *len_pos;
62585732ac8SCy Schubert 	u8 i;
626780fb4a2SCy Schubert 
627780fb4a2SCy Schubert 	if (!wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE)) {
628780fb4a2SCy Schubert 		wpa_printf(MSG_INFO, "MBO: " MACSTR
629780fb4a2SCy Schubert 			   " does not support MBO - cannot request MBO ANQP elements from it",
630780fb4a2SCy Schubert 			   MAC2STR(bss->bssid));
631780fb4a2SCy Schubert 		return NULL;
632780fb4a2SCy Schubert 	}
633780fb4a2SCy Schubert 
63485732ac8SCy Schubert 	/* Allocate size for the maximum case - all MBO subtypes are set */
63585732ac8SCy Schubert 	anqp_buf = wpabuf_alloc(9 + MAX_MBO_ANQP_SUBTYPE);
636780fb4a2SCy Schubert 	if (!anqp_buf)
637780fb4a2SCy Schubert 		return NULL;
638780fb4a2SCy Schubert 
639780fb4a2SCy Schubert 	len_pos = gas_anqp_add_element(anqp_buf, ANQP_VENDOR_SPECIFIC);
640780fb4a2SCy Schubert 	wpabuf_put_be24(anqp_buf, OUI_WFA);
641780fb4a2SCy Schubert 	wpabuf_put_u8(anqp_buf, MBO_ANQP_OUI_TYPE);
642780fb4a2SCy Schubert 
64385732ac8SCy Schubert 	wpabuf_put_u8(anqp_buf, MBO_ANQP_SUBTYPE_QUERY_LIST);
64485732ac8SCy Schubert 
64585732ac8SCy Schubert 	/* The first valid MBO subtype is 1 */
64685732ac8SCy Schubert 	for (i = 1; i <= MAX_MBO_ANQP_SUBTYPE; i++) {
64785732ac8SCy Schubert 		if (mbo_subtypes & BIT(i))
64885732ac8SCy Schubert 			wpabuf_put_u8(anqp_buf, i);
64985732ac8SCy Schubert 	}
65085732ac8SCy Schubert 
651780fb4a2SCy Schubert 	gas_anqp_set_element_len(anqp_buf, len_pos);
652780fb4a2SCy Schubert 
653780fb4a2SCy Schubert 	return anqp_buf;
654780fb4a2SCy Schubert }
65585732ac8SCy Schubert 
65685732ac8SCy Schubert 
mbo_parse_rx_anqp_resp(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,const u8 * sa,const u8 * data,size_t slen)65785732ac8SCy Schubert void mbo_parse_rx_anqp_resp(struct wpa_supplicant *wpa_s,
65885732ac8SCy Schubert 			    struct wpa_bss *bss, const u8 *sa,
65985732ac8SCy Schubert 			    const u8 *data, size_t slen)
66085732ac8SCy Schubert {
66185732ac8SCy Schubert 	const u8 *pos = data;
66285732ac8SCy Schubert 	u8 subtype;
66385732ac8SCy Schubert 
66485732ac8SCy Schubert 	if (slen < 1)
66585732ac8SCy Schubert 		return;
66685732ac8SCy Schubert 
66785732ac8SCy Schubert 	subtype = *pos++;
66885732ac8SCy Schubert 	slen--;
66985732ac8SCy Schubert 
67085732ac8SCy Schubert 	switch (subtype) {
67185732ac8SCy Schubert 	case MBO_ANQP_SUBTYPE_CELL_CONN_PREF:
67285732ac8SCy Schubert 		if (slen < 1)
67385732ac8SCy Schubert 			break;
67485732ac8SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_MBO_ANQP MACSTR
67585732ac8SCy Schubert 			" cell_conn_pref=%u", MAC2STR(sa), *pos);
67685732ac8SCy Schubert 		break;
67785732ac8SCy Schubert 	default:
67885732ac8SCy Schubert 		wpa_printf(MSG_DEBUG, "MBO: Unsupported ANQP subtype %u",
67985732ac8SCy Schubert 			   subtype);
68085732ac8SCy Schubert 		break;
68185732ac8SCy Schubert 	}
68285732ac8SCy Schubert }
683