xref: /freebsd/contrib/wpa/wpa_supplicant/hs20_supplicant.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1f05cddf9SRui Paulo /*
2f05cddf9SRui Paulo  * Copyright (c) 2009, Atheros Communications, Inc.
35b9c547cSRui Paulo  * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
4f05cddf9SRui Paulo  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
7f05cddf9SRui Paulo  */
8f05cddf9SRui Paulo 
9f05cddf9SRui Paulo #include "includes.h"
105b9c547cSRui Paulo #include <sys/stat.h>
11f05cddf9SRui Paulo 
12f05cddf9SRui Paulo #include "common.h"
13f05cddf9SRui Paulo #include "eloop.h"
14f05cddf9SRui Paulo #include "common/ieee802_11_common.h"
15f05cddf9SRui Paulo #include "common/ieee802_11_defs.h"
16f05cddf9SRui Paulo #include "common/gas.h"
17f05cddf9SRui Paulo #include "common/wpa_ctrl.h"
185b9c547cSRui Paulo #include "rsn_supp/wpa.h"
19f05cddf9SRui Paulo #include "wpa_supplicant_i.h"
20f05cddf9SRui Paulo #include "driver_i.h"
21f05cddf9SRui Paulo #include "config.h"
225b9c547cSRui Paulo #include "scan.h"
23f05cddf9SRui Paulo #include "bss.h"
24c1d255d3SCy Schubert #include "bssid_ignore.h"
25f05cddf9SRui Paulo #include "gas_query.h"
26f05cddf9SRui Paulo #include "interworking.h"
27f05cddf9SRui Paulo #include "hs20_supplicant.h"
28780fb4a2SCy Schubert #include "base64.h"
29*a90b9d01SCy Schubert #include "notify.h"
30f05cddf9SRui Paulo 
31f05cddf9SRui Paulo 
325b9c547cSRui Paulo #define OSU_MAX_ITEMS 10
335b9c547cSRui Paulo 
345b9c547cSRui Paulo struct osu_lang_string {
355b9c547cSRui Paulo 	char lang[4];
365b9c547cSRui Paulo 	char text[253];
375b9c547cSRui Paulo };
385b9c547cSRui Paulo 
395b9c547cSRui Paulo struct osu_icon {
405b9c547cSRui Paulo 	u16 width;
415b9c547cSRui Paulo 	u16 height;
425b9c547cSRui Paulo 	char lang[4];
435b9c547cSRui Paulo 	char icon_type[256];
445b9c547cSRui Paulo 	char filename[256];
455b9c547cSRui Paulo 	unsigned int id;
465b9c547cSRui Paulo 	unsigned int failed:1;
475b9c547cSRui Paulo };
485b9c547cSRui Paulo 
495b9c547cSRui Paulo struct osu_provider {
505b9c547cSRui Paulo 	u8 bssid[ETH_ALEN];
51325151a3SRui Paulo 	u8 osu_ssid[SSID_MAX_LEN];
525b9c547cSRui Paulo 	u8 osu_ssid_len;
5385732ac8SCy Schubert 	u8 osu_ssid2[SSID_MAX_LEN];
5485732ac8SCy Schubert 	u8 osu_ssid2_len;
555b9c547cSRui Paulo 	char server_uri[256];
565b9c547cSRui Paulo 	u32 osu_methods; /* bit 0 = OMA-DM, bit 1 = SOAP-XML SPP */
575b9c547cSRui Paulo 	char osu_nai[256];
5885732ac8SCy Schubert 	char osu_nai2[256];
595b9c547cSRui Paulo 	struct osu_lang_string friendly_name[OSU_MAX_ITEMS];
605b9c547cSRui Paulo 	size_t friendly_name_count;
615b9c547cSRui Paulo 	struct osu_lang_string serv_desc[OSU_MAX_ITEMS];
625b9c547cSRui Paulo 	size_t serv_desc_count;
635b9c547cSRui Paulo 	struct osu_icon icon[OSU_MAX_ITEMS];
645b9c547cSRui Paulo 	size_t icon_count;
655b9c547cSRui Paulo };
665b9c547cSRui Paulo 
675b9c547cSRui Paulo 
hs20_configure_frame_filters(struct wpa_supplicant * wpa_s)68780fb4a2SCy Schubert void hs20_configure_frame_filters(struct wpa_supplicant *wpa_s)
69780fb4a2SCy Schubert {
70780fb4a2SCy Schubert 	struct wpa_bss *bss = wpa_s->current_bss;
71780fb4a2SCy Schubert 	const u8 *ie;
72780fb4a2SCy Schubert 	const u8 *ext_capa;
73780fb4a2SCy Schubert 	u32 filter = 0;
74780fb4a2SCy Schubert 
75780fb4a2SCy Schubert 	if (!bss || !is_hs20_network(wpa_s, wpa_s->current_ssid, bss)) {
76*a90b9d01SCy Schubert 		/* Not configuring frame filtering - BSS is not a Hotspot 2.0
77*a90b9d01SCy Schubert 		 * network */
78780fb4a2SCy Schubert 		return;
79780fb4a2SCy Schubert 	}
80780fb4a2SCy Schubert 
81780fb4a2SCy Schubert 	ie = wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE);
82780fb4a2SCy Schubert 
83780fb4a2SCy Schubert 	/* Check if DGAF disabled bit is zero (5th byte in the IE) */
84780fb4a2SCy Schubert 	if (!ie || ie[1] < 5)
85780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG,
86780fb4a2SCy Schubert 			   "Not configuring frame filtering - Can't extract DGAF bit");
87780fb4a2SCy Schubert 	else if (!(ie[6] & HS20_DGAF_DISABLED))
88780fb4a2SCy Schubert 		filter |= WPA_DATA_FRAME_FILTER_FLAG_GTK;
89780fb4a2SCy Schubert 
90780fb4a2SCy Schubert 	ext_capa = wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB);
91780fb4a2SCy Schubert 	if (!ext_capa || ext_capa[1] < 2) {
92780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG,
93780fb4a2SCy Schubert 			   "Not configuring frame filtering - Can't extract Proxy ARP bit");
94780fb4a2SCy Schubert 		return;
95780fb4a2SCy Schubert 	}
96780fb4a2SCy Schubert 
974bc52338SCy Schubert 	if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_PROXY_ARP))
98780fb4a2SCy Schubert 		filter |= WPA_DATA_FRAME_FILTER_FLAG_ARP |
99780fb4a2SCy Schubert 			WPA_DATA_FRAME_FILTER_FLAG_NA;
100780fb4a2SCy Schubert 
101780fb4a2SCy Schubert 	wpa_drv_configure_frame_filters(wpa_s, filter);
102780fb4a2SCy Schubert }
103780fb4a2SCy Schubert 
104780fb4a2SCy Schubert 
wpas_hs20_add_indication(struct wpabuf * buf,int pps_mo_id,int ap_release)1054bc52338SCy Schubert void wpas_hs20_add_indication(struct wpabuf *buf, int pps_mo_id, int ap_release)
106f05cddf9SRui Paulo {
1074bc52338SCy Schubert 	int release;
1085b9c547cSRui Paulo 	u8 conf;
1095b9c547cSRui Paulo 
1104bc52338SCy Schubert 	release = (HS20_VERSION >> 4) + 1;
1114bc52338SCy Schubert 	if (ap_release > 0 && release > ap_release)
1124bc52338SCy Schubert 		release = ap_release;
1134bc52338SCy Schubert 	if (release < 2)
1144bc52338SCy Schubert 		pps_mo_id = -1;
1154bc52338SCy Schubert 
116f05cddf9SRui Paulo 	wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
1175b9c547cSRui Paulo 	wpabuf_put_u8(buf, pps_mo_id >= 0 ? 7 : 5);
118f05cddf9SRui Paulo 	wpabuf_put_be24(buf, OUI_WFA);
119f05cddf9SRui Paulo 	wpabuf_put_u8(buf, HS20_INDICATION_OUI_TYPE);
1204bc52338SCy Schubert 	conf = (release - 1) << 4;
1215b9c547cSRui Paulo 	if (pps_mo_id >= 0)
1225b9c547cSRui Paulo 		conf |= HS20_PPS_MO_ID_PRESENT;
1235b9c547cSRui Paulo 	wpabuf_put_u8(buf, conf);
1245b9c547cSRui Paulo 	if (pps_mo_id >= 0)
1255b9c547cSRui Paulo 		wpabuf_put_le16(buf, pps_mo_id);
126f05cddf9SRui Paulo }
127f05cddf9SRui Paulo 
128f05cddf9SRui Paulo 
wpas_hs20_add_roam_cons_sel(struct wpabuf * buf,const struct wpa_ssid * ssid)12985732ac8SCy Schubert void wpas_hs20_add_roam_cons_sel(struct wpabuf *buf,
13085732ac8SCy Schubert 				 const struct wpa_ssid *ssid)
13185732ac8SCy Schubert {
13285732ac8SCy Schubert 	if (!ssid->roaming_consortium_selection ||
13385732ac8SCy Schubert 	    !ssid->roaming_consortium_selection_len)
13485732ac8SCy Schubert 		return;
13585732ac8SCy Schubert 
13685732ac8SCy Schubert 	wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
13785732ac8SCy Schubert 	wpabuf_put_u8(buf, 4 + ssid->roaming_consortium_selection_len);
13885732ac8SCy Schubert 	wpabuf_put_be24(buf, OUI_WFA);
13985732ac8SCy Schubert 	wpabuf_put_u8(buf, HS20_ROAMING_CONS_SEL_OUI_TYPE);
14085732ac8SCy Schubert 	wpabuf_put_data(buf, ssid->roaming_consortium_selection,
14185732ac8SCy Schubert 			ssid->roaming_consortium_selection_len);
14285732ac8SCy Schubert }
14385732ac8SCy Schubert 
14485732ac8SCy Schubert 
get_hs20_version(struct wpa_bss * bss)1454bc52338SCy Schubert int get_hs20_version(struct wpa_bss *bss)
1464bc52338SCy Schubert {
1474bc52338SCy Schubert 	const u8 *ie;
1484bc52338SCy Schubert 
1494bc52338SCy Schubert 	if (!bss)
1504bc52338SCy Schubert 		return 0;
1514bc52338SCy Schubert 
1524bc52338SCy Schubert 	ie = wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE);
1534bc52338SCy Schubert 	if (!ie || ie[1] < 5)
1544bc52338SCy Schubert 		return 0;
1554bc52338SCy Schubert 
1564bc52338SCy Schubert 	return ((ie[6] >> 4) & 0x0f) + 1;
1574bc52338SCy Schubert }
1584bc52338SCy Schubert 
1594bc52338SCy Schubert 
is_hs20_network(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,struct wpa_bss * bss)1605b9c547cSRui Paulo int is_hs20_network(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1615b9c547cSRui Paulo 		    struct wpa_bss *bss)
162f05cddf9SRui Paulo {
1635b9c547cSRui Paulo 	if (!wpa_s->conf->hs20 || !ssid)
1645b9c547cSRui Paulo 		return 0;
1655b9c547cSRui Paulo 
1665b9c547cSRui Paulo 	if (ssid->parent_cred)
1675b9c547cSRui Paulo 		return 1;
1685b9c547cSRui Paulo 
1695b9c547cSRui Paulo 	if (bss && !wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE))
1705b9c547cSRui Paulo 		return 0;
1715b9c547cSRui Paulo 
1725b9c547cSRui Paulo 	/*
1735b9c547cSRui Paulo 	 * This may catch some non-Hotspot 2.0 cases, but it is safer to do that
1745b9c547cSRui Paulo 	 * than cause Hotspot 2.0 connections without indication element getting
1755b9c547cSRui Paulo 	 * added. Non-Hotspot 2.0 APs should ignore the unknown vendor element.
1765b9c547cSRui Paulo 	 */
1775b9c547cSRui Paulo 
1785b9c547cSRui Paulo 	if (!(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X))
1795b9c547cSRui Paulo 		return 0;
1805b9c547cSRui Paulo 	if (!(ssid->pairwise_cipher & WPA_CIPHER_CCMP))
1815b9c547cSRui Paulo 		return 0;
1825b9c547cSRui Paulo 	if (ssid->proto != WPA_PROTO_RSN)
1835b9c547cSRui Paulo 		return 0;
1845b9c547cSRui Paulo 
1855b9c547cSRui Paulo 	return 1;
1865b9c547cSRui Paulo }
1875b9c547cSRui Paulo 
1885b9c547cSRui Paulo 
hs20_get_pps_mo_id(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)1895b9c547cSRui Paulo int hs20_get_pps_mo_id(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
1905b9c547cSRui Paulo {
1915b9c547cSRui Paulo 	struct wpa_cred *cred;
1925b9c547cSRui Paulo 
1935b9c547cSRui Paulo 	if (ssid == NULL)
1945b9c547cSRui Paulo 		return 0;
1955b9c547cSRui Paulo 
1965b9c547cSRui Paulo 	if (ssid->update_identifier)
1975b9c547cSRui Paulo 		return ssid->update_identifier;
1985b9c547cSRui Paulo 
1995b9c547cSRui Paulo 	if (ssid->parent_cred == NULL)
2005b9c547cSRui Paulo 		return 0;
2015b9c547cSRui Paulo 
2025b9c547cSRui Paulo 	for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
2035b9c547cSRui Paulo 		if (ssid->parent_cred == cred)
2045b9c547cSRui Paulo 			return cred->update_identifier;
2055b9c547cSRui Paulo 	}
2065b9c547cSRui Paulo 
2075b9c547cSRui Paulo 	return 0;
2085b9c547cSRui Paulo }
2095b9c547cSRui Paulo 
2105b9c547cSRui Paulo 
hs20_put_anqp_req(u32 stypes,const u8 * payload,size_t payload_len,struct wpabuf * buf)2115b9c547cSRui Paulo void hs20_put_anqp_req(u32 stypes, const u8 *payload, size_t payload_len,
2125b9c547cSRui Paulo 		       struct wpabuf *buf)
2135b9c547cSRui Paulo {
214f05cddf9SRui Paulo 	u8 *len_pos;
215f05cddf9SRui Paulo 
216f05cddf9SRui Paulo 	if (buf == NULL)
2175b9c547cSRui Paulo 		return;
218f05cddf9SRui Paulo 
219f05cddf9SRui Paulo 	len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
220f05cddf9SRui Paulo 	wpabuf_put_be24(buf, OUI_WFA);
221f05cddf9SRui Paulo 	wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
222f05cddf9SRui Paulo 	if (stypes == BIT(HS20_STYPE_NAI_HOME_REALM_QUERY)) {
223f05cddf9SRui Paulo 		wpabuf_put_u8(buf, HS20_STYPE_NAI_HOME_REALM_QUERY);
224f05cddf9SRui Paulo 		wpabuf_put_u8(buf, 0); /* Reserved */
225f05cddf9SRui Paulo 		if (payload)
226f05cddf9SRui Paulo 			wpabuf_put_data(buf, payload, payload_len);
2275b9c547cSRui Paulo 	} else if (stypes == BIT(HS20_STYPE_ICON_REQUEST)) {
2285b9c547cSRui Paulo 		wpabuf_put_u8(buf, HS20_STYPE_ICON_REQUEST);
2295b9c547cSRui Paulo 		wpabuf_put_u8(buf, 0); /* Reserved */
2305b9c547cSRui Paulo 		if (payload)
2315b9c547cSRui Paulo 			wpabuf_put_data(buf, payload, payload_len);
232f05cddf9SRui Paulo 	} else {
233f05cddf9SRui Paulo 		u8 i;
234f05cddf9SRui Paulo 		wpabuf_put_u8(buf, HS20_STYPE_QUERY_LIST);
235f05cddf9SRui Paulo 		wpabuf_put_u8(buf, 0); /* Reserved */
236f05cddf9SRui Paulo 		for (i = 0; i < 32; i++) {
237f05cddf9SRui Paulo 			if (stypes & BIT(i))
238f05cddf9SRui Paulo 				wpabuf_put_u8(buf, i);
239f05cddf9SRui Paulo 		}
240f05cddf9SRui Paulo 	}
241f05cddf9SRui Paulo 	gas_anqp_set_element_len(buf, len_pos);
242f05cddf9SRui Paulo 
243f05cddf9SRui Paulo 	gas_anqp_set_len(buf);
2445b9c547cSRui Paulo }
2455b9c547cSRui Paulo 
2465b9c547cSRui Paulo 
hs20_build_anqp_req(u32 stypes,const u8 * payload,size_t payload_len)247780fb4a2SCy Schubert static struct wpabuf * hs20_build_anqp_req(u32 stypes, const u8 *payload,
2485b9c547cSRui Paulo 					   size_t payload_len)
2495b9c547cSRui Paulo {
2505b9c547cSRui Paulo 	struct wpabuf *buf;
2515b9c547cSRui Paulo 
2525b9c547cSRui Paulo 	buf = gas_anqp_build_initial_req(0, 100 + payload_len);
2535b9c547cSRui Paulo 	if (buf == NULL)
2545b9c547cSRui Paulo 		return NULL;
2555b9c547cSRui Paulo 
2565b9c547cSRui Paulo 	hs20_put_anqp_req(stypes, payload, payload_len, buf);
257f05cddf9SRui Paulo 
258f05cddf9SRui Paulo 	return buf;
259f05cddf9SRui Paulo }
260f05cddf9SRui Paulo 
261f05cddf9SRui Paulo 
hs20_anqp_send_req(struct wpa_supplicant * wpa_s,const u8 * dst,u32 stypes,const u8 * payload,size_t payload_len,int inmem)262f05cddf9SRui Paulo int hs20_anqp_send_req(struct wpa_supplicant *wpa_s, const u8 *dst, u32 stypes,
263780fb4a2SCy Schubert 		       const u8 *payload, size_t payload_len, int inmem)
264f05cddf9SRui Paulo {
265f05cddf9SRui Paulo 	struct wpabuf *buf;
266f05cddf9SRui Paulo 	int ret = 0;
267f05cddf9SRui Paulo 	int freq;
268f05cddf9SRui Paulo 	struct wpa_bss *bss;
269f05cddf9SRui Paulo 	int res;
270780fb4a2SCy Schubert 	struct icon_entry *icon_entry;
271f05cddf9SRui Paulo 
272f05cddf9SRui Paulo 	bss = wpa_bss_get_bssid(wpa_s, dst);
273325151a3SRui Paulo 	if (!bss) {
274325151a3SRui Paulo 		wpa_printf(MSG_WARNING,
275325151a3SRui Paulo 			   "ANQP: Cannot send query to unknown BSS "
276325151a3SRui Paulo 			   MACSTR, MAC2STR(dst));
277325151a3SRui Paulo 		return -1;
278325151a3SRui Paulo 	}
279325151a3SRui Paulo 
280f05cddf9SRui Paulo 	wpa_bss_anqp_unshare_alloc(bss);
281f05cddf9SRui Paulo 	freq = bss->freq;
282f05cddf9SRui Paulo 
283f05cddf9SRui Paulo 	wpa_printf(MSG_DEBUG, "HS20: ANQP Query Request to " MACSTR " for "
284f05cddf9SRui Paulo 		   "subtypes 0x%x", MAC2STR(dst), stypes);
285f05cddf9SRui Paulo 
286f05cddf9SRui Paulo 	buf = hs20_build_anqp_req(stypes, payload, payload_len);
287f05cddf9SRui Paulo 	if (buf == NULL)
288f05cddf9SRui Paulo 		return -1;
289f05cddf9SRui Paulo 
290c1d255d3SCy Schubert 	res = gas_query_req(wpa_s->gas, dst, freq, 0, 0, buf, anqp_resp_cb,
291c1d255d3SCy Schubert 			    wpa_s);
292f05cddf9SRui Paulo 	if (res < 0) {
293f05cddf9SRui Paulo 		wpa_printf(MSG_DEBUG, "ANQP: Failed to send Query Request");
2945b9c547cSRui Paulo 		wpabuf_free(buf);
295780fb4a2SCy Schubert 		return -1;
296f05cddf9SRui Paulo 	} else
297f05cddf9SRui Paulo 		wpa_printf(MSG_DEBUG, "ANQP: Query started with dialog token "
298f05cddf9SRui Paulo 			   "%u", res);
299f05cddf9SRui Paulo 
300780fb4a2SCy Schubert 	if (inmem) {
301780fb4a2SCy Schubert 		icon_entry = os_zalloc(sizeof(struct icon_entry));
302780fb4a2SCy Schubert 		if (!icon_entry)
303780fb4a2SCy Schubert 			return -1;
304780fb4a2SCy Schubert 		os_memcpy(icon_entry->bssid, dst, ETH_ALEN);
305780fb4a2SCy Schubert 		icon_entry->file_name = os_malloc(payload_len + 1);
306780fb4a2SCy Schubert 		if (!icon_entry->file_name) {
307780fb4a2SCy Schubert 			os_free(icon_entry);
308780fb4a2SCy Schubert 			return -1;
309780fb4a2SCy Schubert 		}
310780fb4a2SCy Schubert 		os_memcpy(icon_entry->file_name, payload, payload_len);
311780fb4a2SCy Schubert 		icon_entry->file_name[payload_len] = '\0';
312780fb4a2SCy Schubert 		icon_entry->dialog_token = res;
313780fb4a2SCy Schubert 
314780fb4a2SCy Schubert 		dl_list_add(&wpa_s->icon_head, &icon_entry->list);
315780fb4a2SCy Schubert 	}
316780fb4a2SCy Schubert 
317f05cddf9SRui Paulo 	return ret;
318f05cddf9SRui Paulo }
319f05cddf9SRui Paulo 
320f05cddf9SRui Paulo 
hs20_find_icon(struct wpa_supplicant * wpa_s,const u8 * bssid,const char * file_name)321780fb4a2SCy Schubert static struct icon_entry * hs20_find_icon(struct wpa_supplicant *wpa_s,
322780fb4a2SCy Schubert 					  const u8 *bssid,
323780fb4a2SCy Schubert 					  const char *file_name)
324780fb4a2SCy Schubert {
325780fb4a2SCy Schubert 	struct icon_entry *icon;
326780fb4a2SCy Schubert 
327780fb4a2SCy Schubert 	dl_list_for_each(icon, &wpa_s->icon_head, struct icon_entry, list) {
328*a90b9d01SCy Schubert 		if (ether_addr_equal(icon->bssid, bssid) &&
329780fb4a2SCy Schubert 		    os_strcmp(icon->file_name, file_name) == 0 && icon->image)
330780fb4a2SCy Schubert 			return icon;
331780fb4a2SCy Schubert 	}
332780fb4a2SCy Schubert 
333780fb4a2SCy Schubert 	return NULL;
334780fb4a2SCy Schubert }
335780fb4a2SCy Schubert 
336780fb4a2SCy Schubert 
hs20_get_icon(struct wpa_supplicant * wpa_s,const u8 * bssid,const char * file_name,size_t offset,size_t size,char * reply,size_t buf_len)337780fb4a2SCy Schubert int hs20_get_icon(struct wpa_supplicant *wpa_s, const u8 *bssid,
338780fb4a2SCy Schubert 		  const char *file_name, size_t offset, size_t size,
339780fb4a2SCy Schubert 		  char *reply, size_t buf_len)
340780fb4a2SCy Schubert {
341780fb4a2SCy Schubert 	struct icon_entry *icon;
342780fb4a2SCy Schubert 	size_t out_size;
343c1d255d3SCy Schubert 	char *b64;
344780fb4a2SCy Schubert 	size_t b64_size;
345780fb4a2SCy Schubert 	int reply_size;
346780fb4a2SCy Schubert 
347780fb4a2SCy Schubert 	wpa_printf(MSG_DEBUG, "HS20: Get icon " MACSTR " %s @ %u +%u (%u)",
348780fb4a2SCy Schubert 		   MAC2STR(bssid), file_name, (unsigned int) offset,
349780fb4a2SCy Schubert 		   (unsigned int) size, (unsigned int) buf_len);
350780fb4a2SCy Schubert 
351780fb4a2SCy Schubert 	icon = hs20_find_icon(wpa_s, bssid, file_name);
352780fb4a2SCy Schubert 	if (!icon || !icon->image || offset >= icon->image_len)
353780fb4a2SCy Schubert 		return -1;
354780fb4a2SCy Schubert 	if (size > icon->image_len - offset)
355780fb4a2SCy Schubert 		size = icon->image_len - offset;
356780fb4a2SCy Schubert 	out_size = buf_len - 3 /* max base64 padding */;
357780fb4a2SCy Schubert 	if (size * 4 > out_size * 3)
358780fb4a2SCy Schubert 		size = out_size * 3 / 4;
359780fb4a2SCy Schubert 	if (size == 0)
360780fb4a2SCy Schubert 		return -1;
361780fb4a2SCy Schubert 
362780fb4a2SCy Schubert 	b64 = base64_encode(&icon->image[offset], size, &b64_size);
363780fb4a2SCy Schubert 	if (b64 && buf_len >= b64_size) {
364780fb4a2SCy Schubert 		os_memcpy(reply, b64, b64_size);
365780fb4a2SCy Schubert 		reply_size = b64_size;
366780fb4a2SCy Schubert 	} else {
367780fb4a2SCy Schubert 		reply_size = -1;
368780fb4a2SCy Schubert 	}
369780fb4a2SCy Schubert 	os_free(b64);
370780fb4a2SCy Schubert 	return reply_size;
371780fb4a2SCy Schubert }
372780fb4a2SCy Schubert 
373780fb4a2SCy Schubert 
hs20_free_icon_entry(struct icon_entry * icon)374780fb4a2SCy Schubert static void hs20_free_icon_entry(struct icon_entry *icon)
375780fb4a2SCy Schubert {
376780fb4a2SCy Schubert 	wpa_printf(MSG_DEBUG, "HS20: Free stored icon from " MACSTR
377780fb4a2SCy Schubert 		   " dialog_token=%u file_name=%s image_len=%u",
378780fb4a2SCy Schubert 		   MAC2STR(icon->bssid), icon->dialog_token,
379780fb4a2SCy Schubert 		   icon->file_name ? icon->file_name : "N/A",
380780fb4a2SCy Schubert 		   (unsigned int) icon->image_len);
381780fb4a2SCy Schubert 	os_free(icon->file_name);
382780fb4a2SCy Schubert 	os_free(icon->image);
383780fb4a2SCy Schubert 	os_free(icon);
384780fb4a2SCy Schubert }
385780fb4a2SCy Schubert 
386780fb4a2SCy Schubert 
hs20_del_icon(struct wpa_supplicant * wpa_s,const u8 * bssid,const char * file_name)387780fb4a2SCy Schubert int hs20_del_icon(struct wpa_supplicant *wpa_s, const u8 *bssid,
388780fb4a2SCy Schubert 		  const char *file_name)
389780fb4a2SCy Schubert {
390780fb4a2SCy Schubert 	struct icon_entry *icon, *tmp;
391780fb4a2SCy Schubert 	int count = 0;
392780fb4a2SCy Schubert 
393780fb4a2SCy Schubert 	if (!bssid)
394780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG, "HS20: Delete all stored icons");
395780fb4a2SCy Schubert 	else if (!file_name)
396780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG, "HS20: Delete all stored icons for "
397780fb4a2SCy Schubert 			   MACSTR, MAC2STR(bssid));
398780fb4a2SCy Schubert 	else
399780fb4a2SCy Schubert 		wpa_printf(MSG_DEBUG, "HS20: Delete stored icons for "
400780fb4a2SCy Schubert 			   MACSTR " file name %s", MAC2STR(bssid), file_name);
401780fb4a2SCy Schubert 
402780fb4a2SCy Schubert 	dl_list_for_each_safe(icon, tmp, &wpa_s->icon_head, struct icon_entry,
403780fb4a2SCy Schubert 			      list) {
404*a90b9d01SCy Schubert 		if ((!bssid || ether_addr_equal(icon->bssid, bssid)) &&
405780fb4a2SCy Schubert 		    (!file_name ||
406780fb4a2SCy Schubert 		     os_strcmp(icon->file_name, file_name) == 0)) {
407780fb4a2SCy Schubert 			dl_list_del(&icon->list);
408780fb4a2SCy Schubert 			hs20_free_icon_entry(icon);
409780fb4a2SCy Schubert 			count++;
410780fb4a2SCy Schubert 		}
411780fb4a2SCy Schubert 	}
412780fb4a2SCy Schubert 	return count == 0 ? -1 : 0;
413780fb4a2SCy Schubert }
414780fb4a2SCy Schubert 
415780fb4a2SCy Schubert 
hs20_set_osu_access_permission(const char * osu_dir,const char * fname)4165b9c547cSRui Paulo static void hs20_set_osu_access_permission(const char *osu_dir,
4175b9c547cSRui Paulo 					   const char *fname)
4185b9c547cSRui Paulo {
4195b9c547cSRui Paulo 	struct stat statbuf;
4205b9c547cSRui Paulo 
4215b9c547cSRui Paulo 	/* Get OSU directory information */
4225b9c547cSRui Paulo 	if (stat(osu_dir, &statbuf) < 0) {
4235b9c547cSRui Paulo 		wpa_printf(MSG_WARNING, "Cannot stat the OSU directory %s",
4245b9c547cSRui Paulo 			   osu_dir);
4255b9c547cSRui Paulo 		return;
4265b9c547cSRui Paulo 	}
4275b9c547cSRui Paulo 
4285b9c547cSRui Paulo 	if (chmod(fname, statbuf.st_mode) < 0) {
4295b9c547cSRui Paulo 		wpa_printf(MSG_WARNING,
4305b9c547cSRui Paulo 			   "Cannot change the permissions for %s", fname);
4315b9c547cSRui Paulo 		return;
4325b9c547cSRui Paulo 	}
4335b9c547cSRui Paulo 
4344bc52338SCy Schubert 	if (lchown(fname, statbuf.st_uid, statbuf.st_gid) < 0) {
4355b9c547cSRui Paulo 		wpa_printf(MSG_WARNING, "Cannot change the ownership for %s",
4365b9c547cSRui Paulo 			   fname);
4375b9c547cSRui Paulo 	}
4385b9c547cSRui Paulo }
4395b9c547cSRui Paulo 
440780fb4a2SCy Schubert 
hs20_remove_duplicate_icons(struct wpa_supplicant * wpa_s,struct icon_entry * new_icon)441780fb4a2SCy Schubert static void hs20_remove_duplicate_icons(struct wpa_supplicant *wpa_s,
442780fb4a2SCy Schubert 					struct icon_entry *new_icon)
443780fb4a2SCy Schubert {
444780fb4a2SCy Schubert 	struct icon_entry *icon, *tmp;
445780fb4a2SCy Schubert 
446780fb4a2SCy Schubert 	dl_list_for_each_safe(icon, tmp, &wpa_s->icon_head, struct icon_entry,
447780fb4a2SCy Schubert 			      list) {
448780fb4a2SCy Schubert 		if (icon == new_icon)
449780fb4a2SCy Schubert 			continue;
450*a90b9d01SCy Schubert 		if (ether_addr_equal(icon->bssid, new_icon->bssid) &&
451780fb4a2SCy Schubert 		    os_strcmp(icon->file_name, new_icon->file_name) == 0) {
452780fb4a2SCy Schubert 			dl_list_del(&icon->list);
453780fb4a2SCy Schubert 			hs20_free_icon_entry(icon);
454780fb4a2SCy Schubert 		}
455780fb4a2SCy Schubert 	}
456780fb4a2SCy Schubert }
457780fb4a2SCy Schubert 
458780fb4a2SCy Schubert 
hs20_process_icon_binary_file(struct wpa_supplicant * wpa_s,const u8 * sa,const u8 * pos,size_t slen,u8 dialog_token)4595b9c547cSRui Paulo static int hs20_process_icon_binary_file(struct wpa_supplicant *wpa_s,
4605b9c547cSRui Paulo 					 const u8 *sa, const u8 *pos,
461780fb4a2SCy Schubert 					 size_t slen, u8 dialog_token)
4625b9c547cSRui Paulo {
4635b9c547cSRui Paulo 	char fname[256];
4645b9c547cSRui Paulo 	int png;
4655b9c547cSRui Paulo 	FILE *f;
4665b9c547cSRui Paulo 	u16 data_len;
467780fb4a2SCy Schubert 	struct icon_entry *icon;
4685b9c547cSRui Paulo 
469780fb4a2SCy Schubert 	dl_list_for_each(icon, &wpa_s->icon_head, struct icon_entry, list) {
470780fb4a2SCy Schubert 		if (icon->dialog_token == dialog_token && !icon->image &&
471*a90b9d01SCy Schubert 		    ether_addr_equal(icon->bssid, sa)) {
47285732ac8SCy Schubert 			icon->image = os_memdup(pos, slen);
473780fb4a2SCy Schubert 			if (!icon->image)
474780fb4a2SCy Schubert 				return -1;
475780fb4a2SCy Schubert 			icon->image_len = slen;
476780fb4a2SCy Schubert 			hs20_remove_duplicate_icons(wpa_s, icon);
477780fb4a2SCy Schubert 			wpa_msg(wpa_s, MSG_INFO,
478780fb4a2SCy Schubert 				RX_HS20_ICON MACSTR " %s %u",
479780fb4a2SCy Schubert 				MAC2STR(sa), icon->file_name,
480780fb4a2SCy Schubert 				(unsigned int) icon->image_len);
481780fb4a2SCy Schubert 			return 0;
482780fb4a2SCy Schubert 		}
483780fb4a2SCy Schubert 	}
484780fb4a2SCy Schubert 
485780fb4a2SCy Schubert 	wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR " Icon Binary File",
4865b9c547cSRui Paulo 		MAC2STR(sa));
4875b9c547cSRui Paulo 
4885b9c547cSRui Paulo 	if (slen < 4) {
4895b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
4905b9c547cSRui Paulo 			"value from " MACSTR, MAC2STR(sa));
4915b9c547cSRui Paulo 		return -1;
4925b9c547cSRui Paulo 	}
4935b9c547cSRui Paulo 
4945b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "HS 2.0: Download Status Code %u", *pos);
4955b9c547cSRui Paulo 	if (*pos != 0)
4965b9c547cSRui Paulo 		return -1;
4975b9c547cSRui Paulo 	pos++;
4985b9c547cSRui Paulo 	slen--;
4995b9c547cSRui Paulo 
5005b9c547cSRui Paulo 	if ((size_t) 1 + pos[0] > slen) {
5015b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
5025b9c547cSRui Paulo 			"value from " MACSTR, MAC2STR(sa));
5035b9c547cSRui Paulo 		return -1;
5045b9c547cSRui Paulo 	}
5055b9c547cSRui Paulo 	wpa_hexdump_ascii(MSG_DEBUG, "Icon Type", pos + 1, pos[0]);
5065b9c547cSRui Paulo 	png = os_strncasecmp((char *) pos + 1, "image/png", 9) == 0;
5075b9c547cSRui Paulo 	slen -= 1 + pos[0];
5085b9c547cSRui Paulo 	pos += 1 + pos[0];
5095b9c547cSRui Paulo 
5105b9c547cSRui Paulo 	if (slen < 2) {
5115b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
5125b9c547cSRui Paulo 			"value from " MACSTR, MAC2STR(sa));
5135b9c547cSRui Paulo 		return -1;
5145b9c547cSRui Paulo 	}
5155b9c547cSRui Paulo 	data_len = WPA_GET_LE16(pos);
5165b9c547cSRui Paulo 	pos += 2;
5175b9c547cSRui Paulo 	slen -= 2;
5185b9c547cSRui Paulo 
5195b9c547cSRui Paulo 	if (data_len > slen) {
5205b9c547cSRui Paulo 		wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
5215b9c547cSRui Paulo 			"value from " MACSTR, MAC2STR(sa));
5225b9c547cSRui Paulo 		return -1;
5235b9c547cSRui Paulo 	}
5245b9c547cSRui Paulo 
5255b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "Icon Binary Data: %u bytes", data_len);
5265b9c547cSRui Paulo 	if (wpa_s->conf->osu_dir == NULL)
5275b9c547cSRui Paulo 		return -1;
5285b9c547cSRui Paulo 
5295b9c547cSRui Paulo 	wpa_s->osu_icon_id++;
5305b9c547cSRui Paulo 	if (wpa_s->osu_icon_id == 0)
5315b9c547cSRui Paulo 		wpa_s->osu_icon_id++;
5325b9c547cSRui Paulo 	snprintf(fname, sizeof(fname), "%s/osu-icon-%u.%s",
5335b9c547cSRui Paulo 		 wpa_s->conf->osu_dir, wpa_s->osu_icon_id,
5345b9c547cSRui Paulo 		 png ? "png" : "icon");
5355b9c547cSRui Paulo 	f = fopen(fname, "wb");
5365b9c547cSRui Paulo 	if (f == NULL)
5375b9c547cSRui Paulo 		return -1;
5385b9c547cSRui Paulo 
5395b9c547cSRui Paulo 	hs20_set_osu_access_permission(wpa_s->conf->osu_dir, fname);
5405b9c547cSRui Paulo 
5415b9c547cSRui Paulo 	if (fwrite(pos, slen, 1, f) != 1) {
5425b9c547cSRui Paulo 		fclose(f);
5435b9c547cSRui Paulo 		unlink(fname);
5445b9c547cSRui Paulo 		return -1;
5455b9c547cSRui Paulo 	}
5465b9c547cSRui Paulo 	fclose(f);
5475b9c547cSRui Paulo 
548780fb4a2SCy Schubert 	wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP_ICON "%s", fname);
5495b9c547cSRui Paulo 	return 0;
5505b9c547cSRui Paulo }
5515b9c547cSRui Paulo 
5525b9c547cSRui Paulo 
hs20_continue_icon_fetch(void * eloop_ctx,void * sock_ctx)5535b9c547cSRui Paulo static void hs20_continue_icon_fetch(void *eloop_ctx, void *sock_ctx)
5545b9c547cSRui Paulo {
5555b9c547cSRui Paulo 	struct wpa_supplicant *wpa_s = eloop_ctx;
5565b9c547cSRui Paulo 	if (wpa_s->fetch_osu_icon_in_progress)
5575b9c547cSRui Paulo 		hs20_next_osu_icon(wpa_s);
5585b9c547cSRui Paulo }
5595b9c547cSRui Paulo 
5605b9c547cSRui Paulo 
hs20_osu_icon_fetch_result(struct wpa_supplicant * wpa_s,int res)5615b9c547cSRui Paulo static void hs20_osu_icon_fetch_result(struct wpa_supplicant *wpa_s, int res)
5625b9c547cSRui Paulo {
5635b9c547cSRui Paulo 	size_t i, j;
5645b9c547cSRui Paulo 	struct os_reltime now, tmp;
5655b9c547cSRui Paulo 	int dur;
5665b9c547cSRui Paulo 
5675b9c547cSRui Paulo 	os_get_reltime(&now);
5685b9c547cSRui Paulo 	os_reltime_sub(&now, &wpa_s->osu_icon_fetch_start, &tmp);
5695b9c547cSRui Paulo 	dur = tmp.sec * 1000 + tmp.usec / 1000;
5705b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "HS 2.0: Icon fetch dur=%d ms res=%d",
5715b9c547cSRui Paulo 		   dur, res);
5725b9c547cSRui Paulo 
5735b9c547cSRui Paulo 	for (i = 0; i < wpa_s->osu_prov_count; i++) {
5745b9c547cSRui Paulo 		struct osu_provider *osu = &wpa_s->osu_prov[i];
5755b9c547cSRui Paulo 		for (j = 0; j < osu->icon_count; j++) {
5765b9c547cSRui Paulo 			struct osu_icon *icon = &osu->icon[j];
5775b9c547cSRui Paulo 			if (icon->id || icon->failed)
5785b9c547cSRui Paulo 				continue;
5795b9c547cSRui Paulo 			if (res < 0)
5805b9c547cSRui Paulo 				icon->failed = 1;
5815b9c547cSRui Paulo 			else
5825b9c547cSRui Paulo 				icon->id = wpa_s->osu_icon_id;
5835b9c547cSRui Paulo 			return;
5845b9c547cSRui Paulo 		}
5855b9c547cSRui Paulo 	}
5865b9c547cSRui Paulo }
5875b9c547cSRui Paulo 
5885b9c547cSRui Paulo 
hs20_parse_rx_hs20_anqp_resp(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,const u8 * sa,const u8 * data,size_t slen,u8 dialog_token)589f05cddf9SRui Paulo void hs20_parse_rx_hs20_anqp_resp(struct wpa_supplicant *wpa_s,
5905b9c547cSRui Paulo 				  struct wpa_bss *bss, const u8 *sa,
591780fb4a2SCy Schubert 				  const u8 *data, size_t slen, u8 dialog_token)
592f05cddf9SRui Paulo {
593f05cddf9SRui Paulo 	const u8 *pos = data;
594f05cddf9SRui Paulo 	u8 subtype;
595f05cddf9SRui Paulo 	struct wpa_bss_anqp *anqp = NULL;
5965b9c547cSRui Paulo 	int ret;
597f05cddf9SRui Paulo 
598f05cddf9SRui Paulo 	if (slen < 2)
599f05cddf9SRui Paulo 		return;
600f05cddf9SRui Paulo 
601f05cddf9SRui Paulo 	if (bss)
602f05cddf9SRui Paulo 		anqp = bss->anqp;
603f05cddf9SRui Paulo 
604f05cddf9SRui Paulo 	subtype = *pos++;
605f05cddf9SRui Paulo 	slen--;
606f05cddf9SRui Paulo 
607f05cddf9SRui Paulo 	pos++; /* Reserved */
608f05cddf9SRui Paulo 	slen--;
609f05cddf9SRui Paulo 
610f05cddf9SRui Paulo 	switch (subtype) {
611f05cddf9SRui Paulo 	case HS20_STYPE_CAPABILITY_LIST:
612780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
613f05cddf9SRui Paulo 			" HS Capability List", MAC2STR(sa));
614f05cddf9SRui Paulo 		wpa_hexdump_ascii(MSG_DEBUG, "HS Capability List", pos, slen);
6155b9c547cSRui Paulo 		if (anqp) {
6165b9c547cSRui Paulo 			wpabuf_free(anqp->hs20_capability_list);
6175b9c547cSRui Paulo 			anqp->hs20_capability_list =
6185b9c547cSRui Paulo 				wpabuf_alloc_copy(pos, slen);
6195b9c547cSRui Paulo 		}
620f05cddf9SRui Paulo 		break;
621f05cddf9SRui Paulo 	case HS20_STYPE_OPERATOR_FRIENDLY_NAME:
622780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
623f05cddf9SRui Paulo 			" Operator Friendly Name", MAC2STR(sa));
624f05cddf9SRui Paulo 		wpa_hexdump_ascii(MSG_DEBUG, "oper friendly name", pos, slen);
625f05cddf9SRui Paulo 		if (anqp) {
626f05cddf9SRui Paulo 			wpabuf_free(anqp->hs20_operator_friendly_name);
627f05cddf9SRui Paulo 			anqp->hs20_operator_friendly_name =
628f05cddf9SRui Paulo 				wpabuf_alloc_copy(pos, slen);
629f05cddf9SRui Paulo 		}
630f05cddf9SRui Paulo 		break;
631f05cddf9SRui Paulo 	case HS20_STYPE_WAN_METRICS:
632f05cddf9SRui Paulo 		wpa_hexdump(MSG_DEBUG, "WAN Metrics", pos, slen);
633f05cddf9SRui Paulo 		if (slen < 13) {
634f05cddf9SRui Paulo 			wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short WAN "
635f05cddf9SRui Paulo 				"Metrics value from " MACSTR, MAC2STR(sa));
636f05cddf9SRui Paulo 			break;
637f05cddf9SRui Paulo 		}
638780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
639f05cddf9SRui Paulo 			" WAN Metrics %02x:%u:%u:%u:%u:%u", MAC2STR(sa),
640f05cddf9SRui Paulo 			pos[0], WPA_GET_LE32(pos + 1), WPA_GET_LE32(pos + 5),
641f05cddf9SRui Paulo 			pos[9], pos[10], WPA_GET_LE16(pos + 11));
642f05cddf9SRui Paulo 		if (anqp) {
643f05cddf9SRui Paulo 			wpabuf_free(anqp->hs20_wan_metrics);
644f05cddf9SRui Paulo 			anqp->hs20_wan_metrics = wpabuf_alloc_copy(pos, slen);
645f05cddf9SRui Paulo 		}
646f05cddf9SRui Paulo 		break;
647f05cddf9SRui Paulo 	case HS20_STYPE_CONNECTION_CAPABILITY:
648780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
649f05cddf9SRui Paulo 			" Connection Capability", MAC2STR(sa));
650f05cddf9SRui Paulo 		wpa_hexdump_ascii(MSG_DEBUG, "conn capability", pos, slen);
651f05cddf9SRui Paulo 		if (anqp) {
652f05cddf9SRui Paulo 			wpabuf_free(anqp->hs20_connection_capability);
653f05cddf9SRui Paulo 			anqp->hs20_connection_capability =
654f05cddf9SRui Paulo 				wpabuf_alloc_copy(pos, slen);
655f05cddf9SRui Paulo 		}
656f05cddf9SRui Paulo 		break;
657f05cddf9SRui Paulo 	case HS20_STYPE_OPERATING_CLASS:
658780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
659f05cddf9SRui Paulo 			" Operating Class", MAC2STR(sa));
660f05cddf9SRui Paulo 		wpa_hexdump_ascii(MSG_DEBUG, "Operating Class", pos, slen);
661f05cddf9SRui Paulo 		if (anqp) {
662f05cddf9SRui Paulo 			wpabuf_free(anqp->hs20_operating_class);
663f05cddf9SRui Paulo 			anqp->hs20_operating_class =
664f05cddf9SRui Paulo 				wpabuf_alloc_copy(pos, slen);
665f05cddf9SRui Paulo 		}
666f05cddf9SRui Paulo 		break;
6675b9c547cSRui Paulo 	case HS20_STYPE_OSU_PROVIDERS_LIST:
668780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
6695b9c547cSRui Paulo 			" OSU Providers list", MAC2STR(sa));
6705b9c547cSRui Paulo 		wpa_s->num_prov_found++;
6715b9c547cSRui Paulo 		if (anqp) {
6725b9c547cSRui Paulo 			wpabuf_free(anqp->hs20_osu_providers_list);
6735b9c547cSRui Paulo 			anqp->hs20_osu_providers_list =
6745b9c547cSRui Paulo 				wpabuf_alloc_copy(pos, slen);
6755b9c547cSRui Paulo 		}
6765b9c547cSRui Paulo 		break;
6775b9c547cSRui Paulo 	case HS20_STYPE_ICON_BINARY_FILE:
678780fb4a2SCy Schubert 		ret = hs20_process_icon_binary_file(wpa_s, sa, pos, slen,
679780fb4a2SCy Schubert 						    dialog_token);
6805b9c547cSRui Paulo 		if (wpa_s->fetch_osu_icon_in_progress) {
6815b9c547cSRui Paulo 			hs20_osu_icon_fetch_result(wpa_s, ret);
6825b9c547cSRui Paulo 			eloop_cancel_timeout(hs20_continue_icon_fetch,
6835b9c547cSRui Paulo 					     wpa_s, NULL);
6845b9c547cSRui Paulo 			eloop_register_timeout(0, 0, hs20_continue_icon_fetch,
6855b9c547cSRui Paulo 					       wpa_s, NULL);
6865b9c547cSRui Paulo 		}
6875b9c547cSRui Paulo 		break;
68885732ac8SCy Schubert 	case HS20_STYPE_OPERATOR_ICON_METADATA:
68985732ac8SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
69085732ac8SCy Schubert 			" Operator Icon Metadata", MAC2STR(sa));
69185732ac8SCy Schubert 		wpa_hexdump(MSG_DEBUG, "Operator Icon Metadata", pos, slen);
69285732ac8SCy Schubert 		if (anqp) {
69385732ac8SCy Schubert 			wpabuf_free(anqp->hs20_operator_icon_metadata);
69485732ac8SCy Schubert 			anqp->hs20_operator_icon_metadata =
69585732ac8SCy Schubert 				wpabuf_alloc_copy(pos, slen);
69685732ac8SCy Schubert 		}
69785732ac8SCy Schubert 		break;
69885732ac8SCy Schubert 	case HS20_STYPE_OSU_PROVIDERS_NAI_LIST:
69985732ac8SCy Schubert 		wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
70085732ac8SCy Schubert 			" OSU Providers NAI List", MAC2STR(sa));
70185732ac8SCy Schubert 		if (anqp) {
70285732ac8SCy Schubert 			wpabuf_free(anqp->hs20_osu_providers_nai_list);
70385732ac8SCy Schubert 			anqp->hs20_osu_providers_nai_list =
70485732ac8SCy Schubert 				wpabuf_alloc_copy(pos, slen);
70585732ac8SCy Schubert 		}
70685732ac8SCy Schubert 		break;
707f05cddf9SRui Paulo 	default:
708f05cddf9SRui Paulo 		wpa_printf(MSG_DEBUG, "HS20: Unsupported subtype %u", subtype);
709f05cddf9SRui Paulo 		break;
710f05cddf9SRui Paulo 	}
711f05cddf9SRui Paulo }
7125b9c547cSRui Paulo 
7135b9c547cSRui Paulo 
hs20_notify_parse_done(struct wpa_supplicant * wpa_s)7145b9c547cSRui Paulo void hs20_notify_parse_done(struct wpa_supplicant *wpa_s)
7155b9c547cSRui Paulo {
7165b9c547cSRui Paulo 	if (!wpa_s->fetch_osu_icon_in_progress)
7175b9c547cSRui Paulo 		return;
7185b9c547cSRui Paulo 	if (eloop_is_timeout_registered(hs20_continue_icon_fetch, wpa_s, NULL))
7195b9c547cSRui Paulo 		return;
7205b9c547cSRui Paulo 	/*
7215b9c547cSRui Paulo 	 * We are going through icon fetch, but no icon response was received.
7225b9c547cSRui Paulo 	 * Assume this means the current AP could not provide an answer to avoid
7235b9c547cSRui Paulo 	 * getting stuck in fetch iteration.
7245b9c547cSRui Paulo 	 */
7255b9c547cSRui Paulo 	hs20_icon_fetch_failed(wpa_s);
7265b9c547cSRui Paulo }
7275b9c547cSRui Paulo 
7285b9c547cSRui Paulo 
hs20_free_osu_prov_entry(struct osu_provider * prov)7295b9c547cSRui Paulo static void hs20_free_osu_prov_entry(struct osu_provider *prov)
7305b9c547cSRui Paulo {
7315b9c547cSRui Paulo }
7325b9c547cSRui Paulo 
7335b9c547cSRui Paulo 
hs20_free_osu_prov(struct wpa_supplicant * wpa_s)7345b9c547cSRui Paulo void hs20_free_osu_prov(struct wpa_supplicant *wpa_s)
7355b9c547cSRui Paulo {
7365b9c547cSRui Paulo 	size_t i;
7375b9c547cSRui Paulo 	for (i = 0; i < wpa_s->osu_prov_count; i++)
7385b9c547cSRui Paulo 		hs20_free_osu_prov_entry(&wpa_s->osu_prov[i]);
7395b9c547cSRui Paulo 	os_free(wpa_s->osu_prov);
7405b9c547cSRui Paulo 	wpa_s->osu_prov = NULL;
7415b9c547cSRui Paulo 	wpa_s->osu_prov_count = 0;
7425b9c547cSRui Paulo }
7435b9c547cSRui Paulo 
7445b9c547cSRui Paulo 
hs20_osu_fetch_done(struct wpa_supplicant * wpa_s)7455b9c547cSRui Paulo static void hs20_osu_fetch_done(struct wpa_supplicant *wpa_s)
7465b9c547cSRui Paulo {
7475b9c547cSRui Paulo 	char fname[256];
7485b9c547cSRui Paulo 	FILE *f;
7495b9c547cSRui Paulo 	size_t i, j;
7505b9c547cSRui Paulo 
7515b9c547cSRui Paulo 	wpa_s->fetch_osu_info = 0;
7525b9c547cSRui Paulo 	wpa_s->fetch_osu_icon_in_progress = 0;
7535b9c547cSRui Paulo 
7545b9c547cSRui Paulo 	if (wpa_s->conf->osu_dir == NULL) {
7555b9c547cSRui Paulo 		hs20_free_osu_prov(wpa_s);
7565b9c547cSRui Paulo 		wpa_s->fetch_anqp_in_progress = 0;
7575b9c547cSRui Paulo 		return;
7585b9c547cSRui Paulo 	}
7595b9c547cSRui Paulo 
7605b9c547cSRui Paulo 	snprintf(fname, sizeof(fname), "%s/osu-providers.txt",
7615b9c547cSRui Paulo 		 wpa_s->conf->osu_dir);
7625b9c547cSRui Paulo 	f = fopen(fname, "w");
7635b9c547cSRui Paulo 	if (f == NULL) {
764780fb4a2SCy Schubert 		wpa_msg(wpa_s, MSG_INFO,
765780fb4a2SCy Schubert 			"Could not write OSU provider information");
7665b9c547cSRui Paulo 		hs20_free_osu_prov(wpa_s);
767780fb4a2SCy Schubert 		wpa_s->fetch_anqp_in_progress = 0;
7685b9c547cSRui Paulo 		return;
7695b9c547cSRui Paulo 	}
7705b9c547cSRui Paulo 
7715b9c547cSRui Paulo 	hs20_set_osu_access_permission(wpa_s->conf->osu_dir, fname);
7725b9c547cSRui Paulo 
7735b9c547cSRui Paulo 	for (i = 0; i < wpa_s->osu_prov_count; i++) {
7745b9c547cSRui Paulo 		struct osu_provider *osu = &wpa_s->osu_prov[i];
7755b9c547cSRui Paulo 		if (i > 0)
7765b9c547cSRui Paulo 			fprintf(f, "\n");
7775b9c547cSRui Paulo 		fprintf(f, "OSU-PROVIDER " MACSTR "\n"
7785b9c547cSRui Paulo 			"uri=%s\n"
7795b9c547cSRui Paulo 			"methods=%08x\n",
7805b9c547cSRui Paulo 			MAC2STR(osu->bssid), osu->server_uri, osu->osu_methods);
7815b9c547cSRui Paulo 		if (osu->osu_ssid_len) {
7825b9c547cSRui Paulo 			fprintf(f, "osu_ssid=%s\n",
7835b9c547cSRui Paulo 				wpa_ssid_txt(osu->osu_ssid,
7845b9c547cSRui Paulo 					     osu->osu_ssid_len));
7855b9c547cSRui Paulo 		}
78685732ac8SCy Schubert 		if (osu->osu_ssid2_len) {
78785732ac8SCy Schubert 			fprintf(f, "osu_ssid2=%s\n",
78885732ac8SCy Schubert 				wpa_ssid_txt(osu->osu_ssid2,
78985732ac8SCy Schubert 					     osu->osu_ssid2_len));
79085732ac8SCy Schubert 		}
7915b9c547cSRui Paulo 		if (osu->osu_nai[0])
7925b9c547cSRui Paulo 			fprintf(f, "osu_nai=%s\n", osu->osu_nai);
79385732ac8SCy Schubert 		if (osu->osu_nai2[0])
79485732ac8SCy Schubert 			fprintf(f, "osu_nai2=%s\n", osu->osu_nai2);
7955b9c547cSRui Paulo 		for (j = 0; j < osu->friendly_name_count; j++) {
7965b9c547cSRui Paulo 			fprintf(f, "friendly_name=%s:%s\n",
7975b9c547cSRui Paulo 				osu->friendly_name[j].lang,
7985b9c547cSRui Paulo 				osu->friendly_name[j].text);
7995b9c547cSRui Paulo 		}
8005b9c547cSRui Paulo 		for (j = 0; j < osu->serv_desc_count; j++) {
8015b9c547cSRui Paulo 			fprintf(f, "desc=%s:%s\n",
8025b9c547cSRui Paulo 				osu->serv_desc[j].lang,
8035b9c547cSRui Paulo 				osu->serv_desc[j].text);
8045b9c547cSRui Paulo 		}
8055b9c547cSRui Paulo 		for (j = 0; j < osu->icon_count; j++) {
8065b9c547cSRui Paulo 			struct osu_icon *icon = &osu->icon[j];
8075b9c547cSRui Paulo 			if (icon->failed)
8085b9c547cSRui Paulo 				continue; /* could not fetch icon */
8095b9c547cSRui Paulo 			fprintf(f, "icon=%u:%u:%u:%s:%s:%s\n",
8105b9c547cSRui Paulo 				icon->id, icon->width, icon->height, icon->lang,
8115b9c547cSRui Paulo 				icon->icon_type, icon->filename);
8125b9c547cSRui Paulo 		}
8135b9c547cSRui Paulo 	}
8145b9c547cSRui Paulo 	fclose(f);
8155b9c547cSRui Paulo 	hs20_free_osu_prov(wpa_s);
8165b9c547cSRui Paulo 
8175b9c547cSRui Paulo 	wpa_msg(wpa_s, MSG_INFO, "OSU provider fetch completed");
8185b9c547cSRui Paulo 	wpa_s->fetch_anqp_in_progress = 0;
8195b9c547cSRui Paulo }
8205b9c547cSRui Paulo 
8215b9c547cSRui Paulo 
hs20_next_osu_icon(struct wpa_supplicant * wpa_s)8225b9c547cSRui Paulo void hs20_next_osu_icon(struct wpa_supplicant *wpa_s)
8235b9c547cSRui Paulo {
8245b9c547cSRui Paulo 	size_t i, j;
8255b9c547cSRui Paulo 
8265b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "HS 2.0: Ready to fetch next icon");
8275b9c547cSRui Paulo 
8285b9c547cSRui Paulo 	for (i = 0; i < wpa_s->osu_prov_count; i++) {
8295b9c547cSRui Paulo 		struct osu_provider *osu = &wpa_s->osu_prov[i];
8305b9c547cSRui Paulo 		for (j = 0; j < osu->icon_count; j++) {
8315b9c547cSRui Paulo 			struct osu_icon *icon = &osu->icon[j];
8325b9c547cSRui Paulo 			if (icon->id || icon->failed)
8335b9c547cSRui Paulo 				continue;
8345b9c547cSRui Paulo 
8355b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Try to fetch icon '%s' "
8365b9c547cSRui Paulo 				   "from " MACSTR, icon->filename,
8375b9c547cSRui Paulo 				   MAC2STR(osu->bssid));
8385b9c547cSRui Paulo 			os_get_reltime(&wpa_s->osu_icon_fetch_start);
8395b9c547cSRui Paulo 			if (hs20_anqp_send_req(wpa_s, osu->bssid,
8405b9c547cSRui Paulo 					       BIT(HS20_STYPE_ICON_REQUEST),
8415b9c547cSRui Paulo 					       (u8 *) icon->filename,
842780fb4a2SCy Schubert 					       os_strlen(icon->filename),
843780fb4a2SCy Schubert 					       0) < 0) {
8445b9c547cSRui Paulo 				icon->failed = 1;
8455b9c547cSRui Paulo 				continue;
8465b9c547cSRui Paulo 			}
8475b9c547cSRui Paulo 			return;
8485b9c547cSRui Paulo 		}
8495b9c547cSRui Paulo 	}
8505b9c547cSRui Paulo 
8515b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "HS 2.0: No more icons to fetch");
8525b9c547cSRui Paulo 	hs20_osu_fetch_done(wpa_s);
8535b9c547cSRui Paulo }
8545b9c547cSRui Paulo 
8555b9c547cSRui Paulo 
hs20_osu_add_prov(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,const u8 * osu_ssid,u8 osu_ssid_len,const u8 * osu_ssid2,u8 osu_ssid2_len,const u8 * pos,size_t len)8565b9c547cSRui Paulo static void hs20_osu_add_prov(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
8575b9c547cSRui Paulo 			      const u8 *osu_ssid, u8 osu_ssid_len,
85885732ac8SCy Schubert 			      const u8 *osu_ssid2, u8 osu_ssid2_len,
8595b9c547cSRui Paulo 			      const u8 *pos, size_t len)
8605b9c547cSRui Paulo {
8615b9c547cSRui Paulo 	struct osu_provider *prov;
8625b9c547cSRui Paulo 	const u8 *end = pos + len;
8635b9c547cSRui Paulo 	u16 len2;
8645b9c547cSRui Paulo 	const u8 *pos2;
8655b9c547cSRui Paulo 	u8 uri_len, osu_method_len, osu_nai_len;
8665b9c547cSRui Paulo 
8675b9c547cSRui Paulo 	wpa_hexdump(MSG_DEBUG, "HS 2.0: Parsing OSU Provider", pos, len);
8685b9c547cSRui Paulo 	prov = os_realloc_array(wpa_s->osu_prov,
8695b9c547cSRui Paulo 				wpa_s->osu_prov_count + 1,
8705b9c547cSRui Paulo 				sizeof(*prov));
8715b9c547cSRui Paulo 	if (prov == NULL)
8725b9c547cSRui Paulo 		return;
8735b9c547cSRui Paulo 	wpa_s->osu_prov = prov;
8745b9c547cSRui Paulo 	prov = &prov[wpa_s->osu_prov_count];
8755b9c547cSRui Paulo 	os_memset(prov, 0, sizeof(*prov));
8765b9c547cSRui Paulo 
8775b9c547cSRui Paulo 	os_memcpy(prov->bssid, bss->bssid, ETH_ALEN);
8785b9c547cSRui Paulo 	os_memcpy(prov->osu_ssid, osu_ssid, osu_ssid_len);
8795b9c547cSRui Paulo 	prov->osu_ssid_len = osu_ssid_len;
88085732ac8SCy Schubert 	if (osu_ssid2)
88185732ac8SCy Schubert 		os_memcpy(prov->osu_ssid2, osu_ssid2, osu_ssid2_len);
88285732ac8SCy Schubert 	prov->osu_ssid2_len = osu_ssid2_len;
8835b9c547cSRui Paulo 
8845b9c547cSRui Paulo 	/* OSU Friendly Name Length */
885780fb4a2SCy Schubert 	if (end - pos < 2) {
8865b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
8875b9c547cSRui Paulo 			   "Friendly Name Length");
8885b9c547cSRui Paulo 		return;
8895b9c547cSRui Paulo 	}
8905b9c547cSRui Paulo 	len2 = WPA_GET_LE16(pos);
8915b9c547cSRui Paulo 	pos += 2;
8925b9c547cSRui Paulo 	if (len2 > end - pos) {
8935b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
8945b9c547cSRui Paulo 			   "Friendly Name Duples");
8955b9c547cSRui Paulo 		return;
8965b9c547cSRui Paulo 	}
8975b9c547cSRui Paulo 	pos2 = pos;
8985b9c547cSRui Paulo 	pos += len2;
8995b9c547cSRui Paulo 
9005b9c547cSRui Paulo 	/* OSU Friendly Name Duples */
901780fb4a2SCy Schubert 	while (pos - pos2 >= 4 && prov->friendly_name_count < OSU_MAX_ITEMS) {
9025b9c547cSRui Paulo 		struct osu_lang_string *f;
903c1d255d3SCy Schubert 		u8 slen;
904c1d255d3SCy Schubert 
905c1d255d3SCy Schubert 		slen = pos2[0];
906c1d255d3SCy Schubert 		if (1 + slen > pos - pos2) {
9075b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "Invalid OSU Friendly Name");
9085b9c547cSRui Paulo 			break;
9095b9c547cSRui Paulo 		}
910c1d255d3SCy Schubert 		if (slen < 3) {
911c1d255d3SCy Schubert 			wpa_printf(MSG_DEBUG,
912c1d255d3SCy Schubert 				   "Invalid OSU Friendly Name (no room for language)");
913c1d255d3SCy Schubert 			break;
914c1d255d3SCy Schubert 		}
9155b9c547cSRui Paulo 		f = &prov->friendly_name[prov->friendly_name_count++];
916c1d255d3SCy Schubert 		pos2++;
917c1d255d3SCy Schubert 		os_memcpy(f->lang, pos2, 3);
918c1d255d3SCy Schubert 		pos2 += 3;
919c1d255d3SCy Schubert 		slen -= 3;
920c1d255d3SCy Schubert 		os_memcpy(f->text, pos2, slen);
921c1d255d3SCy Schubert 		pos2 += slen;
9225b9c547cSRui Paulo 	}
9235b9c547cSRui Paulo 
9245b9c547cSRui Paulo 	/* OSU Server URI */
925780fb4a2SCy Schubert 	if (end - pos < 1) {
9265b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG,
9275b9c547cSRui Paulo 			   "HS 2.0: Not enough room for OSU Server URI length");
9285b9c547cSRui Paulo 		return;
9295b9c547cSRui Paulo 	}
9305b9c547cSRui Paulo 	uri_len = *pos++;
9315b9c547cSRui Paulo 	if (uri_len > end - pos) {
9325b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Server "
9335b9c547cSRui Paulo 			   "URI");
9345b9c547cSRui Paulo 		return;
9355b9c547cSRui Paulo 	}
9365b9c547cSRui Paulo 	os_memcpy(prov->server_uri, pos, uri_len);
9375b9c547cSRui Paulo 	pos += uri_len;
9385b9c547cSRui Paulo 
9395b9c547cSRui Paulo 	/* OSU Method list */
940780fb4a2SCy Schubert 	if (end - pos < 1) {
9415b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Method "
9425b9c547cSRui Paulo 			   "list length");
9435b9c547cSRui Paulo 		return;
9445b9c547cSRui Paulo 	}
9455b9c547cSRui Paulo 	osu_method_len = pos[0];
9465b9c547cSRui Paulo 	if (osu_method_len > end - pos - 1) {
9475b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Method "
9485b9c547cSRui Paulo 			   "list");
9495b9c547cSRui Paulo 		return;
9505b9c547cSRui Paulo 	}
9515b9c547cSRui Paulo 	pos2 = pos + 1;
9525b9c547cSRui Paulo 	pos += 1 + osu_method_len;
9535b9c547cSRui Paulo 	while (pos2 < pos) {
9545b9c547cSRui Paulo 		if (*pos2 < 32)
9555b9c547cSRui Paulo 			prov->osu_methods |= BIT(*pos2);
9565b9c547cSRui Paulo 		pos2++;
9575b9c547cSRui Paulo 	}
9585b9c547cSRui Paulo 
9595b9c547cSRui Paulo 	/* Icons Available Length */
960780fb4a2SCy Schubert 	if (end - pos < 2) {
9615b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for Icons "
9625b9c547cSRui Paulo 			   "Available Length");
9635b9c547cSRui Paulo 		return;
9645b9c547cSRui Paulo 	}
9655b9c547cSRui Paulo 	len2 = WPA_GET_LE16(pos);
9665b9c547cSRui Paulo 	pos += 2;
9675b9c547cSRui Paulo 	if (len2 > end - pos) {
9685b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for Icons "
9695b9c547cSRui Paulo 			   "Available");
9705b9c547cSRui Paulo 		return;
9715b9c547cSRui Paulo 	}
9725b9c547cSRui Paulo 	pos2 = pos;
9735b9c547cSRui Paulo 	pos += len2;
9745b9c547cSRui Paulo 
9755b9c547cSRui Paulo 	/* Icons Available */
9765b9c547cSRui Paulo 	while (pos2 < pos) {
9775b9c547cSRui Paulo 		struct osu_icon *icon = &prov->icon[prov->icon_count];
9785b9c547cSRui Paulo 		u8 flen;
9795b9c547cSRui Paulo 
980780fb4a2SCy Schubert 		if (2 + 2 + 3 + 1 + 1 > pos - pos2) {
9815b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Invalid Icon Metadata");
9825b9c547cSRui Paulo 			break;
9835b9c547cSRui Paulo 		}
9845b9c547cSRui Paulo 
9855b9c547cSRui Paulo 		icon->width = WPA_GET_LE16(pos2);
9865b9c547cSRui Paulo 		pos2 += 2;
9875b9c547cSRui Paulo 		icon->height = WPA_GET_LE16(pos2);
9885b9c547cSRui Paulo 		pos2 += 2;
9895b9c547cSRui Paulo 		os_memcpy(icon->lang, pos2, 3);
9905b9c547cSRui Paulo 		pos2 += 3;
9915b9c547cSRui Paulo 
992780fb4a2SCy Schubert 		flen = *pos2++;
993780fb4a2SCy Schubert 		if (flen > pos - pos2) {
9945b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon Type");
9955b9c547cSRui Paulo 			break;
9965b9c547cSRui Paulo 		}
997780fb4a2SCy Schubert 		os_memcpy(icon->icon_type, pos2, flen);
998780fb4a2SCy Schubert 		pos2 += flen;
9995b9c547cSRui Paulo 
1000780fb4a2SCy Schubert 		if (pos - pos2 < 1) {
10015b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon "
10025b9c547cSRui Paulo 				   "Filename length");
10035b9c547cSRui Paulo 			break;
10045b9c547cSRui Paulo 		}
1005780fb4a2SCy Schubert 		flen = *pos2++;
1006780fb4a2SCy Schubert 		if (flen > pos - pos2) {
10075b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon "
10085b9c547cSRui Paulo 				   "Filename");
10095b9c547cSRui Paulo 			break;
10105b9c547cSRui Paulo 		}
1011780fb4a2SCy Schubert 		os_memcpy(icon->filename, pos2, flen);
1012780fb4a2SCy Schubert 		pos2 += flen;
10135b9c547cSRui Paulo 
10145b9c547cSRui Paulo 		prov->icon_count++;
10155b9c547cSRui Paulo 	}
10165b9c547cSRui Paulo 
10175b9c547cSRui Paulo 	/* OSU_NAI */
1018780fb4a2SCy Schubert 	if (end - pos < 1) {
10195b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU_NAI");
10205b9c547cSRui Paulo 		return;
10215b9c547cSRui Paulo 	}
1022780fb4a2SCy Schubert 	osu_nai_len = *pos++;
1023780fb4a2SCy Schubert 	if (osu_nai_len > end - pos) {
10245b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU_NAI");
10255b9c547cSRui Paulo 		return;
10265b9c547cSRui Paulo 	}
1027780fb4a2SCy Schubert 	os_memcpy(prov->osu_nai, pos, osu_nai_len);
1028780fb4a2SCy Schubert 	pos += osu_nai_len;
10295b9c547cSRui Paulo 
10305b9c547cSRui Paulo 	/* OSU Service Description Length */
1031780fb4a2SCy Schubert 	if (end - pos < 2) {
10325b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
10335b9c547cSRui Paulo 			   "Service Description Length");
10345b9c547cSRui Paulo 		return;
10355b9c547cSRui Paulo 	}
10365b9c547cSRui Paulo 	len2 = WPA_GET_LE16(pos);
10375b9c547cSRui Paulo 	pos += 2;
10385b9c547cSRui Paulo 	if (len2 > end - pos) {
10395b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
10405b9c547cSRui Paulo 			   "Service Description Duples");
10415b9c547cSRui Paulo 		return;
10425b9c547cSRui Paulo 	}
10435b9c547cSRui Paulo 	pos2 = pos;
10445b9c547cSRui Paulo 	pos += len2;
10455b9c547cSRui Paulo 
10465b9c547cSRui Paulo 	/* OSU Service Description Duples */
1047780fb4a2SCy Schubert 	while (pos - pos2 >= 4 && prov->serv_desc_count < OSU_MAX_ITEMS) {
10485b9c547cSRui Paulo 		struct osu_lang_string *f;
10495b9c547cSRui Paulo 		u8 descr_len;
10505b9c547cSRui Paulo 
1051780fb4a2SCy Schubert 		descr_len = *pos2++;
1052780fb4a2SCy Schubert 		if (descr_len > pos - pos2 || descr_len < 3) {
10535b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "Invalid OSU Service "
10545b9c547cSRui Paulo 				   "Description");
10555b9c547cSRui Paulo 			break;
10565b9c547cSRui Paulo 		}
10575b9c547cSRui Paulo 		f = &prov->serv_desc[prov->serv_desc_count++];
1058780fb4a2SCy Schubert 		os_memcpy(f->lang, pos2, 3);
1059780fb4a2SCy Schubert 		os_memcpy(f->text, pos2 + 3, descr_len - 3);
1060780fb4a2SCy Schubert 		pos2 += descr_len;
10615b9c547cSRui Paulo 	}
10625b9c547cSRui Paulo 
10635b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "HS 2.0: Added OSU Provider through " MACSTR,
10645b9c547cSRui Paulo 		   MAC2STR(bss->bssid));
10655b9c547cSRui Paulo 	wpa_s->osu_prov_count++;
10665b9c547cSRui Paulo }
10675b9c547cSRui Paulo 
10685b9c547cSRui Paulo 
hs20_osu_icon_fetch(struct wpa_supplicant * wpa_s)10695b9c547cSRui Paulo void hs20_osu_icon_fetch(struct wpa_supplicant *wpa_s)
10705b9c547cSRui Paulo {
10715b9c547cSRui Paulo 	struct wpa_bss *bss;
10725b9c547cSRui Paulo 	struct wpabuf *prov_anqp;
10735b9c547cSRui Paulo 	const u8 *pos, *end;
10745b9c547cSRui Paulo 	u16 len;
107585732ac8SCy Schubert 	const u8 *osu_ssid, *osu_ssid2;
107685732ac8SCy Schubert 	u8 osu_ssid_len, osu_ssid2_len;
10775b9c547cSRui Paulo 	u8 num_providers;
10785b9c547cSRui Paulo 
10795b9c547cSRui Paulo 	hs20_free_osu_prov(wpa_s);
10805b9c547cSRui Paulo 
10815b9c547cSRui Paulo 	dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
108285732ac8SCy Schubert 		struct wpa_ie_data data;
108385732ac8SCy Schubert 		const u8 *ie;
108485732ac8SCy Schubert 
10855b9c547cSRui Paulo 		if (bss->anqp == NULL)
10865b9c547cSRui Paulo 			continue;
10875b9c547cSRui Paulo 		prov_anqp = bss->anqp->hs20_osu_providers_list;
10885b9c547cSRui Paulo 		if (prov_anqp == NULL)
10895b9c547cSRui Paulo 			continue;
109085732ac8SCy Schubert 		ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
109185732ac8SCy Schubert 		if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &data) == 0 &&
109285732ac8SCy Schubert 		    (data.key_mgmt & WPA_KEY_MGMT_OSEN)) {
109385732ac8SCy Schubert 			osu_ssid2 = bss->ssid;
109485732ac8SCy Schubert 			osu_ssid2_len = bss->ssid_len;
109585732ac8SCy Schubert 		} else {
109685732ac8SCy Schubert 			osu_ssid2 = NULL;
109785732ac8SCy Schubert 			osu_ssid2_len = 0;
109885732ac8SCy Schubert 		}
10995b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Parsing OSU Providers list from "
11005b9c547cSRui Paulo 			   MACSTR, MAC2STR(bss->bssid));
11015b9c547cSRui Paulo 		wpa_hexdump_buf(MSG_DEBUG, "HS 2.0: OSU Providers list",
11025b9c547cSRui Paulo 				prov_anqp);
11035b9c547cSRui Paulo 		pos = wpabuf_head(prov_anqp);
11045b9c547cSRui Paulo 		end = pos + wpabuf_len(prov_anqp);
11055b9c547cSRui Paulo 
11065b9c547cSRui Paulo 		/* OSU SSID */
1107780fb4a2SCy Schubert 		if (end - pos < 1)
11085b9c547cSRui Paulo 			continue;
1109780fb4a2SCy Schubert 		if (1 + pos[0] > end - pos) {
11105b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for "
11115b9c547cSRui Paulo 				   "OSU SSID");
11125b9c547cSRui Paulo 			continue;
11135b9c547cSRui Paulo 		}
11145b9c547cSRui Paulo 		osu_ssid_len = *pos++;
1115325151a3SRui Paulo 		if (osu_ssid_len > SSID_MAX_LEN) {
11165b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Invalid OSU SSID "
11175b9c547cSRui Paulo 				   "Length %u", osu_ssid_len);
11185b9c547cSRui Paulo 			continue;
11195b9c547cSRui Paulo 		}
11205b9c547cSRui Paulo 		osu_ssid = pos;
11215b9c547cSRui Paulo 		pos += osu_ssid_len;
11225b9c547cSRui Paulo 
1123780fb4a2SCy Schubert 		if (end - pos < 1) {
11245b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for "
11255b9c547cSRui Paulo 				   "Number of OSU Providers");
11265b9c547cSRui Paulo 			continue;
11275b9c547cSRui Paulo 		}
11285b9c547cSRui Paulo 		num_providers = *pos++;
11295b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Number of OSU Providers: %u",
11305b9c547cSRui Paulo 			   num_providers);
11315b9c547cSRui Paulo 
11325b9c547cSRui Paulo 		/* OSU Providers */
1133780fb4a2SCy Schubert 		while (end - pos > 2 && num_providers > 0) {
11345b9c547cSRui Paulo 			num_providers--;
11355b9c547cSRui Paulo 			len = WPA_GET_LE16(pos);
11365b9c547cSRui Paulo 			pos += 2;
11375b9c547cSRui Paulo 			if (len > (unsigned int) (end - pos))
11385b9c547cSRui Paulo 				break;
11395b9c547cSRui Paulo 			hs20_osu_add_prov(wpa_s, bss, osu_ssid,
114085732ac8SCy Schubert 					  osu_ssid_len, osu_ssid2,
114185732ac8SCy Schubert 					  osu_ssid2_len, pos, len);
11425b9c547cSRui Paulo 			pos += len;
11435b9c547cSRui Paulo 		}
11445b9c547cSRui Paulo 
11455b9c547cSRui Paulo 		if (pos != end) {
11465b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Ignored %d bytes of "
11475b9c547cSRui Paulo 				   "extra data after OSU Providers",
11485b9c547cSRui Paulo 				   (int) (end - pos));
11495b9c547cSRui Paulo 		}
115085732ac8SCy Schubert 
115185732ac8SCy Schubert 		prov_anqp = bss->anqp->hs20_osu_providers_nai_list;
115285732ac8SCy Schubert 		if (!prov_anqp)
115385732ac8SCy Schubert 			continue;
115485732ac8SCy Schubert 		wpa_printf(MSG_DEBUG,
115585732ac8SCy Schubert 			   "HS 2.0: Parsing OSU Providers NAI List from "
115685732ac8SCy Schubert 			   MACSTR, MAC2STR(bss->bssid));
115785732ac8SCy Schubert 		wpa_hexdump_buf(MSG_DEBUG, "HS 2.0: OSU Providers NAI List",
115885732ac8SCy Schubert 				prov_anqp);
115985732ac8SCy Schubert 		pos = wpabuf_head(prov_anqp);
116085732ac8SCy Schubert 		end = pos + wpabuf_len(prov_anqp);
116185732ac8SCy Schubert 		num_providers = 0;
116285732ac8SCy Schubert 		while (end - pos > 0) {
116385732ac8SCy Schubert 			len = *pos++;
116485732ac8SCy Schubert 			if (end - pos < len) {
116585732ac8SCy Schubert 				wpa_printf(MSG_DEBUG,
116685732ac8SCy Schubert 					   "HS 2.0: Not enough room for OSU_NAI");
116785732ac8SCy Schubert 				break;
116885732ac8SCy Schubert 			}
116985732ac8SCy Schubert 			if (num_providers >= wpa_s->osu_prov_count) {
117085732ac8SCy Schubert 				wpa_printf(MSG_DEBUG,
117185732ac8SCy Schubert 					   "HS 2.0: Ignore unexpected OSU Provider NAI List entries");
117285732ac8SCy Schubert 				break;
117385732ac8SCy Schubert 			}
117485732ac8SCy Schubert 			os_memcpy(wpa_s->osu_prov[num_providers].osu_nai2,
117585732ac8SCy Schubert 				  pos, len);
117685732ac8SCy Schubert 			pos += len;
117785732ac8SCy Schubert 			num_providers++;
117885732ac8SCy Schubert 		}
11795b9c547cSRui Paulo 	}
11805b9c547cSRui Paulo 
11815b9c547cSRui Paulo 	wpa_s->fetch_osu_icon_in_progress = 1;
11825b9c547cSRui Paulo 	hs20_next_osu_icon(wpa_s);
11835b9c547cSRui Paulo }
11845b9c547cSRui Paulo 
11855b9c547cSRui Paulo 
hs20_osu_scan_res_handler(struct wpa_supplicant * wpa_s,struct wpa_scan_results * scan_res)11865b9c547cSRui Paulo static void hs20_osu_scan_res_handler(struct wpa_supplicant *wpa_s,
11875b9c547cSRui Paulo 				      struct wpa_scan_results *scan_res)
11885b9c547cSRui Paulo {
11895b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "OSU provisioning fetch scan completed");
11905b9c547cSRui Paulo 	if (!wpa_s->fetch_osu_waiting_scan) {
11915b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "OSU fetch have been canceled");
11925b9c547cSRui Paulo 		return;
11935b9c547cSRui Paulo 	}
11945b9c547cSRui Paulo 	wpa_s->network_select = 0;
11955b9c547cSRui Paulo 	wpa_s->fetch_all_anqp = 1;
11965b9c547cSRui Paulo 	wpa_s->fetch_osu_info = 1;
11975b9c547cSRui Paulo 	wpa_s->fetch_osu_icon_in_progress = 0;
11985b9c547cSRui Paulo 
11995b9c547cSRui Paulo 	interworking_start_fetch_anqp(wpa_s);
12005b9c547cSRui Paulo }
12015b9c547cSRui Paulo 
12025b9c547cSRui Paulo 
hs20_fetch_osu(struct wpa_supplicant * wpa_s,int skip_scan)1203780fb4a2SCy Schubert int hs20_fetch_osu(struct wpa_supplicant *wpa_s, int skip_scan)
12045b9c547cSRui Paulo {
12055b9c547cSRui Paulo 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
12065b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
12075b9c547cSRui Paulo 			   "interface disabled");
12085b9c547cSRui Paulo 		return -1;
12095b9c547cSRui Paulo 	}
12105b9c547cSRui Paulo 
12115b9c547cSRui Paulo 	if (wpa_s->scanning) {
12125b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
12135b9c547cSRui Paulo 			   "scanning");
12145b9c547cSRui Paulo 		return -1;
12155b9c547cSRui Paulo 	}
12165b9c547cSRui Paulo 
12175b9c547cSRui Paulo 	if (wpa_s->conf->osu_dir == NULL) {
12185b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
12195b9c547cSRui Paulo 			   "osu_dir not configured");
12205b9c547cSRui Paulo 		return -1;
12215b9c547cSRui Paulo 	}
12225b9c547cSRui Paulo 
12235b9c547cSRui Paulo 	if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
12245b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
12255b9c547cSRui Paulo 			   "fetch in progress (%d, %d)",
12265b9c547cSRui Paulo 			   wpa_s->fetch_anqp_in_progress,
12275b9c547cSRui Paulo 			   wpa_s->network_select);
12285b9c547cSRui Paulo 		return -1;
12295b9c547cSRui Paulo 	}
12305b9c547cSRui Paulo 
12315b9c547cSRui Paulo 	wpa_msg(wpa_s, MSG_INFO, "Starting OSU provisioning information fetch");
12325b9c547cSRui Paulo 	wpa_s->num_osu_scans = 0;
12335b9c547cSRui Paulo 	wpa_s->num_prov_found = 0;
1234780fb4a2SCy Schubert 	if (skip_scan) {
1235780fb4a2SCy Schubert 		wpa_s->network_select = 0;
1236780fb4a2SCy Schubert 		wpa_s->fetch_all_anqp = 1;
1237780fb4a2SCy Schubert 		wpa_s->fetch_osu_info = 1;
1238780fb4a2SCy Schubert 		wpa_s->fetch_osu_icon_in_progress = 0;
1239780fb4a2SCy Schubert 
1240780fb4a2SCy Schubert 		interworking_start_fetch_anqp(wpa_s);
1241780fb4a2SCy Schubert 	} else {
12425b9c547cSRui Paulo 		hs20_start_osu_scan(wpa_s);
1243780fb4a2SCy Schubert 	}
12445b9c547cSRui Paulo 
12455b9c547cSRui Paulo 	return 0;
12465b9c547cSRui Paulo }
12475b9c547cSRui Paulo 
12485b9c547cSRui Paulo 
hs20_start_osu_scan(struct wpa_supplicant * wpa_s)12495b9c547cSRui Paulo void hs20_start_osu_scan(struct wpa_supplicant *wpa_s)
12505b9c547cSRui Paulo {
12515b9c547cSRui Paulo 	wpa_s->fetch_osu_waiting_scan = 1;
12525b9c547cSRui Paulo 	wpa_s->num_osu_scans++;
12535b9c547cSRui Paulo 	wpa_s->scan_req = MANUAL_SCAN_REQ;
12545b9c547cSRui Paulo 	wpa_s->scan_res_handler = hs20_osu_scan_res_handler;
12555b9c547cSRui Paulo 	wpa_supplicant_req_scan(wpa_s, 0, 0);
12565b9c547cSRui Paulo }
12575b9c547cSRui Paulo 
12585b9c547cSRui Paulo 
hs20_cancel_fetch_osu(struct wpa_supplicant * wpa_s)12595b9c547cSRui Paulo void hs20_cancel_fetch_osu(struct wpa_supplicant *wpa_s)
12605b9c547cSRui Paulo {
12615b9c547cSRui Paulo 	wpa_printf(MSG_DEBUG, "Cancel OSU fetch");
12625b9c547cSRui Paulo 	interworking_stop_fetch_anqp(wpa_s);
12635b9c547cSRui Paulo 	wpa_s->fetch_osu_waiting_scan = 0;
12645b9c547cSRui Paulo 	wpa_s->network_select = 0;
12655b9c547cSRui Paulo 	wpa_s->fetch_osu_info = 0;
12665b9c547cSRui Paulo 	wpa_s->fetch_osu_icon_in_progress = 0;
12675b9c547cSRui Paulo }
12685b9c547cSRui Paulo 
12695b9c547cSRui Paulo 
hs20_icon_fetch_failed(struct wpa_supplicant * wpa_s)12705b9c547cSRui Paulo void hs20_icon_fetch_failed(struct wpa_supplicant *wpa_s)
12715b9c547cSRui Paulo {
12725b9c547cSRui Paulo 	hs20_osu_icon_fetch_result(wpa_s, -1);
12735b9c547cSRui Paulo 	eloop_cancel_timeout(hs20_continue_icon_fetch, wpa_s, NULL);
12745b9c547cSRui Paulo 	eloop_register_timeout(0, 0, hs20_continue_icon_fetch, wpa_s, NULL);
12755b9c547cSRui Paulo }
12765b9c547cSRui Paulo 
12775b9c547cSRui Paulo 
hs20_rx_subscription_remediation(struct wpa_supplicant * wpa_s,const char * url,u8 osu_method)12785b9c547cSRui Paulo void hs20_rx_subscription_remediation(struct wpa_supplicant *wpa_s,
12795b9c547cSRui Paulo 				      const char *url, u8 osu_method)
12805b9c547cSRui Paulo {
12815b9c547cSRui Paulo 	if (url)
12825b9c547cSRui Paulo 		wpa_msg(wpa_s, MSG_INFO, HS20_SUBSCRIPTION_REMEDIATION "%u %s",
12835b9c547cSRui Paulo 			osu_method, url);
12845b9c547cSRui Paulo 	else
12855b9c547cSRui Paulo 		wpa_msg(wpa_s, MSG_INFO, HS20_SUBSCRIPTION_REMEDIATION);
12865b9c547cSRui Paulo }
12875b9c547cSRui Paulo 
12885b9c547cSRui Paulo 
hs20_rx_deauth_imminent_notice(struct wpa_supplicant * wpa_s,u8 code,u16 reauth_delay,const char * url)12895b9c547cSRui Paulo void hs20_rx_deauth_imminent_notice(struct wpa_supplicant *wpa_s, u8 code,
12905b9c547cSRui Paulo 				    u16 reauth_delay, const char *url)
12915b9c547cSRui Paulo {
12925b9c547cSRui Paulo 	if (!wpa_sm_pmf_enabled(wpa_s->wpa)) {
12935b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Ignore deauthentication imminent notice since PMF was not enabled");
12945b9c547cSRui Paulo 		return;
12955b9c547cSRui Paulo 	}
12965b9c547cSRui Paulo 
12975b9c547cSRui Paulo 	wpa_msg(wpa_s, MSG_INFO, HS20_DEAUTH_IMMINENT_NOTICE "%u %u %s",
12985b9c547cSRui Paulo 		code, reauth_delay, url);
12995b9c547cSRui Paulo 
13005b9c547cSRui Paulo 	if (code == HS20_DEAUTH_REASON_CODE_BSS) {
1301c1d255d3SCy Schubert 		wpa_printf(MSG_DEBUG, "HS 2.0: Add BSS to ignore list");
1302c1d255d3SCy Schubert 		wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
13035b9c547cSRui Paulo 		/* TODO: For now, disable full ESS since some drivers may not
13045b9c547cSRui Paulo 		 * support disabling per BSS. */
13055b9c547cSRui Paulo 		if (wpa_s->current_ssid) {
13065b9c547cSRui Paulo 			struct os_reltime now;
13075b9c547cSRui Paulo 			os_get_reltime(&now);
13085b9c547cSRui Paulo 			if (now.sec + reauth_delay <=
13095b9c547cSRui Paulo 			    wpa_s->current_ssid->disabled_until.sec)
13105b9c547cSRui Paulo 				return;
13115b9c547cSRui Paulo 			wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds (BSS)",
13125b9c547cSRui Paulo 				   reauth_delay);
13135b9c547cSRui Paulo 			wpa_s->current_ssid->disabled_until.sec =
13145b9c547cSRui Paulo 				now.sec + reauth_delay;
13155b9c547cSRui Paulo 		}
13165b9c547cSRui Paulo 	}
13175b9c547cSRui Paulo 
13185b9c547cSRui Paulo 	if (code == HS20_DEAUTH_REASON_CODE_ESS && wpa_s->current_ssid) {
13195b9c547cSRui Paulo 		struct os_reltime now;
13205b9c547cSRui Paulo 		os_get_reltime(&now);
13215b9c547cSRui Paulo 		if (now.sec + reauth_delay <=
13225b9c547cSRui Paulo 		    wpa_s->current_ssid->disabled_until.sec)
13235b9c547cSRui Paulo 			return;
13245b9c547cSRui Paulo 		wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds",
13255b9c547cSRui Paulo 			   reauth_delay);
13265b9c547cSRui Paulo 		wpa_s->current_ssid->disabled_until.sec =
13275b9c547cSRui Paulo 			now.sec + reauth_delay;
13285b9c547cSRui Paulo 	}
13295b9c547cSRui Paulo }
13305b9c547cSRui Paulo 
13315b9c547cSRui Paulo 
hs20_rx_t_c_acceptance(struct wpa_supplicant * wpa_s,const char * url)133285732ac8SCy Schubert void hs20_rx_t_c_acceptance(struct wpa_supplicant *wpa_s, const char *url)
133385732ac8SCy Schubert {
133485732ac8SCy Schubert 	if (!wpa_sm_pmf_enabled(wpa_s->wpa)) {
133585732ac8SCy Schubert 		wpa_printf(MSG_DEBUG,
133685732ac8SCy Schubert 			   "HS 2.0: Ignore Terms and Conditions Acceptance since PMF was not enabled");
133785732ac8SCy Schubert 		return;
133885732ac8SCy Schubert 	}
133985732ac8SCy Schubert 
1340*a90b9d01SCy Schubert 	wpas_notify_hs20_t_c_acceptance(wpa_s, url);
134185732ac8SCy Schubert }
134285732ac8SCy Schubert 
134385732ac8SCy Schubert 
hs20_init(struct wpa_supplicant * wpa_s)1344780fb4a2SCy Schubert void hs20_init(struct wpa_supplicant *wpa_s)
1345780fb4a2SCy Schubert {
1346780fb4a2SCy Schubert 	dl_list_init(&wpa_s->icon_head);
1347780fb4a2SCy Schubert }
1348780fb4a2SCy Schubert 
1349780fb4a2SCy Schubert 
hs20_deinit(struct wpa_supplicant * wpa_s)13505b9c547cSRui Paulo void hs20_deinit(struct wpa_supplicant *wpa_s)
13515b9c547cSRui Paulo {
13525b9c547cSRui Paulo 	eloop_cancel_timeout(hs20_continue_icon_fetch, wpa_s, NULL);
13535b9c547cSRui Paulo 	hs20_free_osu_prov(wpa_s);
1354780fb4a2SCy Schubert 	if (wpa_s->icon_head.next)
1355780fb4a2SCy Schubert 		hs20_del_icon(wpa_s, NULL, NULL);
13565b9c547cSRui Paulo }
1357