Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Atheros Communications, Inc. |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2013, Qualcomm Atheros, Inc. |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4 | * |
| 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
| 7 | */ |
| 8 | |
| 9 | #include "includes.h" |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 10 | #include <sys/stat.h> |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11 | |
| 12 | #include "common.h" |
| 13 | #include "eloop.h" |
| 14 | #include "common/ieee802_11_common.h" |
| 15 | #include "common/ieee802_11_defs.h" |
| 16 | #include "common/gas.h" |
| 17 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 18 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 19 | #include "wpa_supplicant_i.h" |
| 20 | #include "driver_i.h" |
| 21 | #include "config.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 22 | #include "scan.h" |
Roshan Pius | 04a9d74 | 2016-12-12 12:40:46 -0800 | [diff] [blame] | 23 | #include "notify.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 24 | #include "bss.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 25 | #include "blacklist.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 26 | #include "gas_query.h" |
| 27 | #include "interworking.h" |
| 28 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 29 | #include "base64.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 30 | |
| 31 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 32 | #define OSU_MAX_ITEMS 10 |
| 33 | |
| 34 | struct osu_lang_string { |
| 35 | char lang[4]; |
| 36 | char text[253]; |
| 37 | }; |
| 38 | |
| 39 | struct osu_icon { |
| 40 | u16 width; |
| 41 | u16 height; |
| 42 | char lang[4]; |
| 43 | char icon_type[256]; |
| 44 | char filename[256]; |
| 45 | unsigned int id; |
| 46 | unsigned int failed:1; |
| 47 | }; |
| 48 | |
| 49 | struct osu_provider { |
| 50 | u8 bssid[ETH_ALEN]; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 51 | u8 osu_ssid[SSID_MAX_LEN]; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 52 | u8 osu_ssid_len; |
| 53 | char server_uri[256]; |
| 54 | u32 osu_methods; /* bit 0 = OMA-DM, bit 1 = SOAP-XML SPP */ |
| 55 | char osu_nai[256]; |
| 56 | struct osu_lang_string friendly_name[OSU_MAX_ITEMS]; |
| 57 | size_t friendly_name_count; |
| 58 | struct osu_lang_string serv_desc[OSU_MAX_ITEMS]; |
| 59 | size_t serv_desc_count; |
| 60 | struct osu_icon icon[OSU_MAX_ITEMS]; |
| 61 | size_t icon_count; |
| 62 | }; |
| 63 | |
| 64 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 65 | void hs20_configure_frame_filters(struct wpa_supplicant *wpa_s) |
| 66 | { |
| 67 | struct wpa_bss *bss = wpa_s->current_bss; |
| 68 | u8 *bssid = wpa_s->bssid; |
| 69 | const u8 *ie; |
| 70 | const u8 *ext_capa; |
| 71 | u32 filter = 0; |
| 72 | |
| 73 | if (!bss || !is_hs20_network(wpa_s, wpa_s->current_ssid, bss)) { |
| 74 | wpa_printf(MSG_DEBUG, |
| 75 | "Not configuring frame filtering - BSS " MACSTR |
| 76 | " is not a Hotspot 2.0 network", MAC2STR(bssid)); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | ie = wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE); |
| 81 | |
| 82 | /* Check if DGAF disabled bit is zero (5th byte in the IE) */ |
| 83 | if (!ie || ie[1] < 5) |
| 84 | wpa_printf(MSG_DEBUG, |
| 85 | "Not configuring frame filtering - Can't extract DGAF bit"); |
| 86 | else if (!(ie[6] & HS20_DGAF_DISABLED)) |
| 87 | filter |= WPA_DATA_FRAME_FILTER_FLAG_GTK; |
| 88 | |
| 89 | ext_capa = wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB); |
| 90 | if (!ext_capa || ext_capa[1] < 2) { |
| 91 | wpa_printf(MSG_DEBUG, |
| 92 | "Not configuring frame filtering - Can't extract Proxy ARP bit"); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | /* Check if Proxy ARP is enabled (2nd byte in the IE) */ |
| 97 | if (ext_capa[3] & BIT(4)) |
| 98 | filter |= WPA_DATA_FRAME_FILTER_FLAG_ARP | |
| 99 | WPA_DATA_FRAME_FILTER_FLAG_NA; |
| 100 | |
| 101 | wpa_drv_configure_frame_filters(wpa_s, filter); |
| 102 | } |
| 103 | |
| 104 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 105 | void wpas_hs20_add_indication(struct wpabuf *buf, int pps_mo_id) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 106 | { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 107 | u8 conf; |
| 108 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 109 | wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 110 | wpabuf_put_u8(buf, pps_mo_id >= 0 ? 7 : 5); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 111 | wpabuf_put_be24(buf, OUI_WFA); |
| 112 | wpabuf_put_u8(buf, HS20_INDICATION_OUI_TYPE); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 113 | conf = HS20_VERSION; |
| 114 | if (pps_mo_id >= 0) |
| 115 | conf |= HS20_PPS_MO_ID_PRESENT; |
| 116 | wpabuf_put_u8(buf, conf); |
| 117 | if (pps_mo_id >= 0) |
| 118 | wpabuf_put_le16(buf, pps_mo_id); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame^] | 122 | void wpas_hs20_add_roam_cons_sel(struct wpabuf *buf, |
| 123 | const struct wpa_ssid *ssid) |
| 124 | { |
| 125 | if (!ssid->roaming_consortium_selection || |
| 126 | !ssid->roaming_consortium_selection_len) |
| 127 | return; |
| 128 | |
| 129 | wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); |
| 130 | wpabuf_put_u8(buf, 4 + ssid->roaming_consortium_selection_len); |
| 131 | wpabuf_put_be24(buf, OUI_WFA); |
| 132 | wpabuf_put_u8(buf, HS20_ROAMING_CONS_SEL_OUI_TYPE); |
| 133 | wpabuf_put_data(buf, ssid->roaming_consortium_selection, |
| 134 | ssid->roaming_consortium_selection_len); |
| 135 | } |
| 136 | |
| 137 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 138 | int is_hs20_network(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 139 | struct wpa_bss *bss) |
| 140 | { |
| 141 | if (!wpa_s->conf->hs20 || !ssid) |
| 142 | return 0; |
| 143 | |
| 144 | if (ssid->parent_cred) |
| 145 | return 1; |
| 146 | |
| 147 | if (bss && !wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) |
| 148 | return 0; |
| 149 | |
| 150 | /* |
| 151 | * This may catch some non-Hotspot 2.0 cases, but it is safer to do that |
| 152 | * than cause Hotspot 2.0 connections without indication element getting |
| 153 | * added. Non-Hotspot 2.0 APs should ignore the unknown vendor element. |
| 154 | */ |
| 155 | |
| 156 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X)) |
| 157 | return 0; |
| 158 | if (!(ssid->pairwise_cipher & WPA_CIPHER_CCMP)) |
| 159 | return 0; |
| 160 | if (ssid->proto != WPA_PROTO_RSN) |
| 161 | return 0; |
| 162 | |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 167 | int hs20_get_pps_mo_id(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
| 168 | { |
| 169 | struct wpa_cred *cred; |
| 170 | |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 171 | if (ssid == NULL) |
| 172 | return 0; |
| 173 | |
| 174 | if (ssid->update_identifier) |
| 175 | return ssid->update_identifier; |
| 176 | |
| 177 | if (ssid->parent_cred == NULL) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 178 | return 0; |
| 179 | |
| 180 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| 181 | if (ssid->parent_cred == cred) |
| 182 | return cred->update_identifier; |
| 183 | } |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 189 | void hs20_put_anqp_req(u32 stypes, const u8 *payload, size_t payload_len, |
| 190 | struct wpabuf *buf) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 191 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 192 | u8 *len_pos; |
| 193 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 194 | if (buf == NULL) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 195 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 196 | |
| 197 | len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC); |
| 198 | wpabuf_put_be24(buf, OUI_WFA); |
| 199 | wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE); |
| 200 | if (stypes == BIT(HS20_STYPE_NAI_HOME_REALM_QUERY)) { |
| 201 | wpabuf_put_u8(buf, HS20_STYPE_NAI_HOME_REALM_QUERY); |
| 202 | wpabuf_put_u8(buf, 0); /* Reserved */ |
| 203 | if (payload) |
| 204 | wpabuf_put_data(buf, payload, payload_len); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 205 | } else if (stypes == BIT(HS20_STYPE_ICON_REQUEST)) { |
| 206 | wpabuf_put_u8(buf, HS20_STYPE_ICON_REQUEST); |
| 207 | wpabuf_put_u8(buf, 0); /* Reserved */ |
| 208 | if (payload) |
| 209 | wpabuf_put_data(buf, payload, payload_len); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 210 | } else { |
| 211 | u8 i; |
| 212 | wpabuf_put_u8(buf, HS20_STYPE_QUERY_LIST); |
| 213 | wpabuf_put_u8(buf, 0); /* Reserved */ |
| 214 | for (i = 0; i < 32; i++) { |
| 215 | if (stypes & BIT(i)) |
| 216 | wpabuf_put_u8(buf, i); |
| 217 | } |
| 218 | } |
| 219 | gas_anqp_set_element_len(buf, len_pos); |
| 220 | |
| 221 | gas_anqp_set_len(buf); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 225 | static struct wpabuf * hs20_build_anqp_req(u32 stypes, const u8 *payload, |
| 226 | size_t payload_len) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 227 | { |
| 228 | struct wpabuf *buf; |
| 229 | |
| 230 | buf = gas_anqp_build_initial_req(0, 100 + payload_len); |
| 231 | if (buf == NULL) |
| 232 | return NULL; |
| 233 | |
| 234 | hs20_put_anqp_req(stypes, payload, payload_len, buf); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 235 | |
| 236 | return buf; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | int hs20_anqp_send_req(struct wpa_supplicant *wpa_s, const u8 *dst, u32 stypes, |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 241 | const u8 *payload, size_t payload_len, int inmem) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 242 | { |
| 243 | struct wpabuf *buf; |
| 244 | int ret = 0; |
| 245 | int freq; |
| 246 | struct wpa_bss *bss; |
| 247 | int res; |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 248 | struct icon_entry *icon_entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 249 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 250 | bss = wpa_bss_get_bssid(wpa_s, dst); |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 251 | if (!bss) { |
| 252 | wpa_printf(MSG_WARNING, |
| 253 | "ANQP: Cannot send query to unknown BSS " |
| 254 | MACSTR, MAC2STR(dst)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 255 | return -1; |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | wpa_bss_anqp_unshare_alloc(bss); |
| 259 | freq = bss->freq; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 260 | |
| 261 | wpa_printf(MSG_DEBUG, "HS20: ANQP Query Request to " MACSTR " for " |
| 262 | "subtypes 0x%x", MAC2STR(dst), stypes); |
| 263 | |
| 264 | buf = hs20_build_anqp_req(stypes, payload, payload_len); |
| 265 | if (buf == NULL) |
| 266 | return -1; |
| 267 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame^] | 268 | res = gas_query_req(wpa_s->gas, dst, freq, 0, buf, anqp_resp_cb, wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 269 | if (res < 0) { |
| 270 | wpa_printf(MSG_DEBUG, "ANQP: Failed to send Query Request"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 271 | wpabuf_free(buf); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 272 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 273 | } else |
| 274 | wpa_printf(MSG_DEBUG, "ANQP: Query started with dialog token " |
| 275 | "%u", res); |
| 276 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 277 | if (inmem) { |
| 278 | icon_entry = os_zalloc(sizeof(struct icon_entry)); |
| 279 | if (!icon_entry) |
| 280 | return -1; |
| 281 | os_memcpy(icon_entry->bssid, dst, ETH_ALEN); |
| 282 | icon_entry->file_name = os_malloc(payload_len + 1); |
| 283 | if (!icon_entry->file_name) { |
| 284 | os_free(icon_entry); |
| 285 | return -1; |
| 286 | } |
| 287 | os_memcpy(icon_entry->file_name, payload, payload_len); |
| 288 | icon_entry->file_name[payload_len] = '\0'; |
| 289 | icon_entry->dialog_token = res; |
| 290 | |
| 291 | dl_list_add(&wpa_s->icon_head, &icon_entry->list); |
| 292 | } |
| 293 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 298 | static struct icon_entry * hs20_find_icon(struct wpa_supplicant *wpa_s, |
| 299 | const u8 *bssid, |
| 300 | const char *file_name) |
| 301 | { |
| 302 | struct icon_entry *icon; |
| 303 | |
| 304 | dl_list_for_each(icon, &wpa_s->icon_head, struct icon_entry, list) { |
| 305 | if (os_memcmp(icon->bssid, bssid, ETH_ALEN) == 0 && |
| 306 | os_strcmp(icon->file_name, file_name) == 0 && icon->image) |
| 307 | return icon; |
| 308 | } |
| 309 | |
| 310 | return NULL; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | int hs20_get_icon(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 315 | const char *file_name, size_t offset, size_t size, |
| 316 | char *reply, size_t buf_len) |
| 317 | { |
| 318 | struct icon_entry *icon; |
| 319 | size_t out_size; |
| 320 | unsigned char *b64; |
| 321 | size_t b64_size; |
| 322 | int reply_size; |
| 323 | |
| 324 | wpa_printf(MSG_DEBUG, "HS20: Get icon " MACSTR " %s @ %u +%u (%u)", |
| 325 | MAC2STR(bssid), file_name, (unsigned int) offset, |
| 326 | (unsigned int) size, (unsigned int) buf_len); |
| 327 | |
| 328 | icon = hs20_find_icon(wpa_s, bssid, file_name); |
| 329 | if (!icon || !icon->image || offset >= icon->image_len) |
| 330 | return -1; |
| 331 | if (size > icon->image_len - offset) |
| 332 | size = icon->image_len - offset; |
| 333 | out_size = buf_len - 3 /* max base64 padding */; |
| 334 | if (size * 4 > out_size * 3) |
| 335 | size = out_size * 3 / 4; |
| 336 | if (size == 0) |
| 337 | return -1; |
| 338 | |
| 339 | b64 = base64_encode(&icon->image[offset], size, &b64_size); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 340 | if (b64 && buf_len >= b64_size) { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 341 | os_memcpy(reply, b64, b64_size); |
| 342 | reply_size = b64_size; |
| 343 | } else { |
| 344 | reply_size = -1; |
| 345 | } |
| 346 | os_free(b64); |
| 347 | return reply_size; |
| 348 | } |
| 349 | |
| 350 | |
| 351 | static void hs20_free_icon_entry(struct icon_entry *icon) |
| 352 | { |
| 353 | wpa_printf(MSG_DEBUG, "HS20: Free stored icon from " MACSTR |
| 354 | " dialog_token=%u file_name=%s image_len=%u", |
| 355 | MAC2STR(icon->bssid), icon->dialog_token, |
| 356 | icon->file_name ? icon->file_name : "N/A", |
| 357 | (unsigned int) icon->image_len); |
| 358 | os_free(icon->file_name); |
| 359 | os_free(icon->image); |
| 360 | os_free(icon); |
| 361 | } |
| 362 | |
| 363 | |
| 364 | int hs20_del_icon(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 365 | const char *file_name) |
| 366 | { |
| 367 | struct icon_entry *icon, *tmp; |
| 368 | int count = 0; |
| 369 | |
| 370 | if (!bssid) |
| 371 | wpa_printf(MSG_DEBUG, "HS20: Delete all stored icons"); |
| 372 | else if (!file_name) |
| 373 | wpa_printf(MSG_DEBUG, "HS20: Delete all stored icons for " |
| 374 | MACSTR, MAC2STR(bssid)); |
| 375 | else |
| 376 | wpa_printf(MSG_DEBUG, "HS20: Delete stored icons for " |
| 377 | MACSTR " file name %s", MAC2STR(bssid), file_name); |
| 378 | |
| 379 | dl_list_for_each_safe(icon, tmp, &wpa_s->icon_head, struct icon_entry, |
| 380 | list) { |
| 381 | if ((!bssid || os_memcmp(icon->bssid, bssid, ETH_ALEN) == 0) && |
| 382 | (!file_name || |
| 383 | os_strcmp(icon->file_name, file_name) == 0)) { |
| 384 | dl_list_del(&icon->list); |
| 385 | hs20_free_icon_entry(icon); |
| 386 | count++; |
| 387 | } |
| 388 | } |
| 389 | return count == 0 ? -1 : 0; |
| 390 | } |
| 391 | |
| 392 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 393 | static void hs20_set_osu_access_permission(const char *osu_dir, |
| 394 | const char *fname) |
| 395 | { |
| 396 | struct stat statbuf; |
| 397 | |
| 398 | /* Get OSU directory information */ |
| 399 | if (stat(osu_dir, &statbuf) < 0) { |
| 400 | wpa_printf(MSG_WARNING, "Cannot stat the OSU directory %s", |
| 401 | osu_dir); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | if (chmod(fname, statbuf.st_mode) < 0) { |
| 406 | wpa_printf(MSG_WARNING, |
| 407 | "Cannot change the permissions for %s", fname); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | if (chown(fname, statbuf.st_uid, statbuf.st_gid) < 0) { |
| 412 | wpa_printf(MSG_WARNING, "Cannot change the ownership for %s", |
| 413 | fname); |
| 414 | } |
| 415 | } |
| 416 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 417 | |
| 418 | static void hs20_remove_duplicate_icons(struct wpa_supplicant *wpa_s, |
| 419 | struct icon_entry *new_icon) |
| 420 | { |
| 421 | struct icon_entry *icon, *tmp; |
| 422 | |
| 423 | dl_list_for_each_safe(icon, tmp, &wpa_s->icon_head, struct icon_entry, |
| 424 | list) { |
| 425 | if (icon == new_icon) |
| 426 | continue; |
| 427 | if (os_memcmp(icon->bssid, new_icon->bssid, ETH_ALEN) == 0 && |
| 428 | os_strcmp(icon->file_name, new_icon->file_name) == 0) { |
| 429 | dl_list_del(&icon->list); |
| 430 | hs20_free_icon_entry(icon); |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 436 | static int hs20_process_icon_binary_file(struct wpa_supplicant *wpa_s, |
| 437 | const u8 *sa, const u8 *pos, |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 438 | size_t slen, u8 dialog_token) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 439 | { |
| 440 | char fname[256]; |
| 441 | int png; |
| 442 | FILE *f; |
| 443 | u16 data_len; |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 444 | struct icon_entry *icon; |
| 445 | |
| 446 | dl_list_for_each(icon, &wpa_s->icon_head, struct icon_entry, list) { |
| 447 | if (icon->dialog_token == dialog_token && !icon->image && |
| 448 | os_memcmp(icon->bssid, sa, ETH_ALEN) == 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 449 | icon->image = os_memdup(pos, slen); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 450 | if (!icon->image) |
| 451 | return -1; |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 452 | icon->image_len = slen; |
| 453 | hs20_remove_duplicate_icons(wpa_s, icon); |
| 454 | wpa_msg(wpa_s, MSG_INFO, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 455 | RX_HS20_ICON MACSTR " %s %u", |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 456 | MAC2STR(sa), icon->file_name, |
| 457 | (unsigned int) icon->image_len); |
Roshan Pius | 04a9d74 | 2016-12-12 12:40:46 -0800 | [diff] [blame] | 458 | wpas_notify_hs20_icon_query_done(wpa_s, sa, |
| 459 | icon->file_name, |
| 460 | icon->image, |
| 461 | icon->image_len); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 465 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 466 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR " Icon Binary File", |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 467 | MAC2STR(sa)); |
| 468 | |
| 469 | if (slen < 4) { |
| 470 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File " |
| 471 | "value from " MACSTR, MAC2STR(sa)); |
| 472 | return -1; |
| 473 | } |
| 474 | |
| 475 | wpa_printf(MSG_DEBUG, "HS 2.0: Download Status Code %u", *pos); |
| 476 | if (*pos != 0) |
| 477 | return -1; |
| 478 | pos++; |
| 479 | slen--; |
| 480 | |
| 481 | if ((size_t) 1 + pos[0] > slen) { |
| 482 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File " |
| 483 | "value from " MACSTR, MAC2STR(sa)); |
| 484 | return -1; |
| 485 | } |
| 486 | wpa_hexdump_ascii(MSG_DEBUG, "Icon Type", pos + 1, pos[0]); |
| 487 | png = os_strncasecmp((char *) pos + 1, "image/png", 9) == 0; |
| 488 | slen -= 1 + pos[0]; |
| 489 | pos += 1 + pos[0]; |
| 490 | |
| 491 | if (slen < 2) { |
| 492 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File " |
| 493 | "value from " MACSTR, MAC2STR(sa)); |
| 494 | return -1; |
| 495 | } |
| 496 | data_len = WPA_GET_LE16(pos); |
| 497 | pos += 2; |
| 498 | slen -= 2; |
| 499 | |
| 500 | if (data_len > slen) { |
| 501 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File " |
| 502 | "value from " MACSTR, MAC2STR(sa)); |
| 503 | return -1; |
| 504 | } |
| 505 | |
| 506 | wpa_printf(MSG_DEBUG, "Icon Binary Data: %u bytes", data_len); |
| 507 | if (wpa_s->conf->osu_dir == NULL) |
| 508 | return -1; |
| 509 | |
| 510 | wpa_s->osu_icon_id++; |
| 511 | if (wpa_s->osu_icon_id == 0) |
| 512 | wpa_s->osu_icon_id++; |
| 513 | snprintf(fname, sizeof(fname), "%s/osu-icon-%u.%s", |
| 514 | wpa_s->conf->osu_dir, wpa_s->osu_icon_id, |
| 515 | png ? "png" : "icon"); |
| 516 | f = fopen(fname, "wb"); |
| 517 | if (f == NULL) |
| 518 | return -1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 519 | |
| 520 | hs20_set_osu_access_permission(wpa_s->conf->osu_dir, fname); |
| 521 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 522 | if (fwrite(pos, slen, 1, f) != 1) { |
| 523 | fclose(f); |
| 524 | unlink(fname); |
| 525 | return -1; |
| 526 | } |
| 527 | fclose(f); |
| 528 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 529 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP_ICON "%s", fname); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | static void hs20_continue_icon_fetch(void *eloop_ctx, void *sock_ctx) |
| 535 | { |
| 536 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 537 | if (wpa_s->fetch_osu_icon_in_progress) |
| 538 | hs20_next_osu_icon(wpa_s); |
| 539 | } |
| 540 | |
| 541 | |
| 542 | static void hs20_osu_icon_fetch_result(struct wpa_supplicant *wpa_s, int res) |
| 543 | { |
| 544 | size_t i, j; |
| 545 | struct os_reltime now, tmp; |
| 546 | int dur; |
| 547 | |
| 548 | os_get_reltime(&now); |
| 549 | os_reltime_sub(&now, &wpa_s->osu_icon_fetch_start, &tmp); |
| 550 | dur = tmp.sec * 1000 + tmp.usec / 1000; |
| 551 | wpa_printf(MSG_DEBUG, "HS 2.0: Icon fetch dur=%d ms res=%d", |
| 552 | dur, res); |
| 553 | |
| 554 | for (i = 0; i < wpa_s->osu_prov_count; i++) { |
| 555 | struct osu_provider *osu = &wpa_s->osu_prov[i]; |
| 556 | for (j = 0; j < osu->icon_count; j++) { |
| 557 | struct osu_icon *icon = &osu->icon[j]; |
| 558 | if (icon->id || icon->failed) |
| 559 | continue; |
| 560 | if (res < 0) |
| 561 | icon->failed = 1; |
| 562 | else |
| 563 | icon->id = wpa_s->osu_icon_id; |
| 564 | return; |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 570 | void hs20_parse_rx_hs20_anqp_resp(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 571 | struct wpa_bss *bss, const u8 *sa, |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 572 | const u8 *data, size_t slen, u8 dialog_token) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 573 | { |
| 574 | const u8 *pos = data; |
| 575 | u8 subtype; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 576 | struct wpa_bss_anqp *anqp = NULL; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 577 | int ret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 578 | |
| 579 | if (slen < 2) |
| 580 | return; |
| 581 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 582 | if (bss) |
| 583 | anqp = bss->anqp; |
| 584 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 585 | subtype = *pos++; |
| 586 | slen--; |
| 587 | |
| 588 | pos++; /* Reserved */ |
| 589 | slen--; |
| 590 | |
| 591 | switch (subtype) { |
| 592 | case HS20_STYPE_CAPABILITY_LIST: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 593 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 594 | " HS Capability List", MAC2STR(sa)); |
| 595 | wpa_hexdump_ascii(MSG_DEBUG, "HS Capability List", pos, slen); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 596 | if (anqp) { |
| 597 | wpabuf_free(anqp->hs20_capability_list); |
| 598 | anqp->hs20_capability_list = |
| 599 | wpabuf_alloc_copy(pos, slen); |
| 600 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 601 | break; |
| 602 | case HS20_STYPE_OPERATOR_FRIENDLY_NAME: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 603 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 604 | " Operator Friendly Name", MAC2STR(sa)); |
| 605 | wpa_hexdump_ascii(MSG_DEBUG, "oper friendly name", pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 606 | if (anqp) { |
| 607 | wpabuf_free(anqp->hs20_operator_friendly_name); |
| 608 | anqp->hs20_operator_friendly_name = |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 609 | wpabuf_alloc_copy(pos, slen); |
| 610 | } |
| 611 | break; |
| 612 | case HS20_STYPE_WAN_METRICS: |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 613 | wpa_hexdump(MSG_DEBUG, "WAN Metrics", pos, slen); |
| 614 | if (slen < 13) { |
| 615 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short WAN " |
| 616 | "Metrics value from " MACSTR, MAC2STR(sa)); |
| 617 | break; |
| 618 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 619 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 620 | " WAN Metrics %02x:%u:%u:%u:%u:%u", MAC2STR(sa), |
| 621 | pos[0], WPA_GET_LE32(pos + 1), WPA_GET_LE32(pos + 5), |
| 622 | pos[9], pos[10], WPA_GET_LE16(pos + 11)); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 623 | if (anqp) { |
| 624 | wpabuf_free(anqp->hs20_wan_metrics); |
| 625 | anqp->hs20_wan_metrics = wpabuf_alloc_copy(pos, slen); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 626 | } |
| 627 | break; |
| 628 | case HS20_STYPE_CONNECTION_CAPABILITY: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 629 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 630 | " Connection Capability", MAC2STR(sa)); |
| 631 | wpa_hexdump_ascii(MSG_DEBUG, "conn capability", pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 632 | if (anqp) { |
| 633 | wpabuf_free(anqp->hs20_connection_capability); |
| 634 | anqp->hs20_connection_capability = |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 635 | wpabuf_alloc_copy(pos, slen); |
| 636 | } |
| 637 | break; |
| 638 | case HS20_STYPE_OPERATING_CLASS: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 639 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 640 | " Operating Class", MAC2STR(sa)); |
| 641 | wpa_hexdump_ascii(MSG_DEBUG, "Operating Class", pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 642 | if (anqp) { |
| 643 | wpabuf_free(anqp->hs20_operating_class); |
| 644 | anqp->hs20_operating_class = |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 645 | wpabuf_alloc_copy(pos, slen); |
| 646 | } |
| 647 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 648 | case HS20_STYPE_OSU_PROVIDERS_LIST: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 649 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 650 | " OSU Providers list", MAC2STR(sa)); |
| 651 | wpa_s->num_prov_found++; |
| 652 | if (anqp) { |
| 653 | wpabuf_free(anqp->hs20_osu_providers_list); |
| 654 | anqp->hs20_osu_providers_list = |
| 655 | wpabuf_alloc_copy(pos, slen); |
| 656 | } |
| 657 | break; |
| 658 | case HS20_STYPE_ICON_BINARY_FILE: |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 659 | ret = hs20_process_icon_binary_file(wpa_s, sa, pos, slen, |
| 660 | dialog_token); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 661 | if (wpa_s->fetch_osu_icon_in_progress) { |
| 662 | hs20_osu_icon_fetch_result(wpa_s, ret); |
| 663 | eloop_cancel_timeout(hs20_continue_icon_fetch, |
| 664 | wpa_s, NULL); |
| 665 | eloop_register_timeout(0, 0, hs20_continue_icon_fetch, |
| 666 | wpa_s, NULL); |
| 667 | } |
| 668 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame^] | 669 | case HS20_STYPE_OPERATOR_ICON_METADATA: |
| 670 | wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR |
| 671 | " Operator Icon Metadata", MAC2STR(sa)); |
| 672 | wpa_hexdump(MSG_DEBUG, "Operator Icon Metadata", pos, slen); |
| 673 | if (anqp) { |
| 674 | wpabuf_free(anqp->hs20_operator_icon_metadata); |
| 675 | anqp->hs20_operator_icon_metadata = |
| 676 | wpabuf_alloc_copy(pos, slen); |
| 677 | } |
| 678 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 679 | default: |
| 680 | wpa_printf(MSG_DEBUG, "HS20: Unsupported subtype %u", subtype); |
| 681 | break; |
| 682 | } |
| 683 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 684 | |
| 685 | |
| 686 | void hs20_notify_parse_done(struct wpa_supplicant *wpa_s) |
| 687 | { |
| 688 | if (!wpa_s->fetch_osu_icon_in_progress) |
| 689 | return; |
| 690 | if (eloop_is_timeout_registered(hs20_continue_icon_fetch, wpa_s, NULL)) |
| 691 | return; |
| 692 | /* |
| 693 | * We are going through icon fetch, but no icon response was received. |
| 694 | * Assume this means the current AP could not provide an answer to avoid |
| 695 | * getting stuck in fetch iteration. |
| 696 | */ |
| 697 | hs20_icon_fetch_failed(wpa_s); |
| 698 | } |
| 699 | |
| 700 | |
| 701 | static void hs20_free_osu_prov_entry(struct osu_provider *prov) |
| 702 | { |
| 703 | } |
| 704 | |
| 705 | |
| 706 | void hs20_free_osu_prov(struct wpa_supplicant *wpa_s) |
| 707 | { |
| 708 | size_t i; |
| 709 | for (i = 0; i < wpa_s->osu_prov_count; i++) |
| 710 | hs20_free_osu_prov_entry(&wpa_s->osu_prov[i]); |
| 711 | os_free(wpa_s->osu_prov); |
| 712 | wpa_s->osu_prov = NULL; |
| 713 | wpa_s->osu_prov_count = 0; |
| 714 | } |
| 715 | |
| 716 | |
| 717 | static void hs20_osu_fetch_done(struct wpa_supplicant *wpa_s) |
| 718 | { |
| 719 | char fname[256]; |
| 720 | FILE *f; |
| 721 | size_t i, j; |
| 722 | |
| 723 | wpa_s->fetch_osu_info = 0; |
| 724 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 725 | |
| 726 | if (wpa_s->conf->osu_dir == NULL) { |
| 727 | hs20_free_osu_prov(wpa_s); |
| 728 | wpa_s->fetch_anqp_in_progress = 0; |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | snprintf(fname, sizeof(fname), "%s/osu-providers.txt", |
| 733 | wpa_s->conf->osu_dir); |
| 734 | f = fopen(fname, "w"); |
| 735 | if (f == NULL) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 736 | wpa_msg(wpa_s, MSG_INFO, |
| 737 | "Could not write OSU provider information"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 738 | hs20_free_osu_prov(wpa_s); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 739 | wpa_s->fetch_anqp_in_progress = 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 740 | return; |
| 741 | } |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 742 | |
| 743 | hs20_set_osu_access_permission(wpa_s->conf->osu_dir, fname); |
| 744 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 745 | for (i = 0; i < wpa_s->osu_prov_count; i++) { |
| 746 | struct osu_provider *osu = &wpa_s->osu_prov[i]; |
| 747 | if (i > 0) |
| 748 | fprintf(f, "\n"); |
| 749 | fprintf(f, "OSU-PROVIDER " MACSTR "\n" |
| 750 | "uri=%s\n" |
| 751 | "methods=%08x\n", |
| 752 | MAC2STR(osu->bssid), osu->server_uri, osu->osu_methods); |
| 753 | if (osu->osu_ssid_len) { |
| 754 | fprintf(f, "osu_ssid=%s\n", |
| 755 | wpa_ssid_txt(osu->osu_ssid, |
| 756 | osu->osu_ssid_len)); |
| 757 | } |
| 758 | if (osu->osu_nai[0]) |
| 759 | fprintf(f, "osu_nai=%s\n", osu->osu_nai); |
| 760 | for (j = 0; j < osu->friendly_name_count; j++) { |
| 761 | fprintf(f, "friendly_name=%s:%s\n", |
| 762 | osu->friendly_name[j].lang, |
| 763 | osu->friendly_name[j].text); |
| 764 | } |
| 765 | for (j = 0; j < osu->serv_desc_count; j++) { |
| 766 | fprintf(f, "desc=%s:%s\n", |
| 767 | osu->serv_desc[j].lang, |
| 768 | osu->serv_desc[j].text); |
| 769 | } |
| 770 | for (j = 0; j < osu->icon_count; j++) { |
| 771 | struct osu_icon *icon = &osu->icon[j]; |
| 772 | if (icon->failed) |
| 773 | continue; /* could not fetch icon */ |
| 774 | fprintf(f, "icon=%u:%u:%u:%s:%s:%s\n", |
| 775 | icon->id, icon->width, icon->height, icon->lang, |
| 776 | icon->icon_type, icon->filename); |
| 777 | } |
| 778 | } |
| 779 | fclose(f); |
| 780 | hs20_free_osu_prov(wpa_s); |
| 781 | |
| 782 | wpa_msg(wpa_s, MSG_INFO, "OSU provider fetch completed"); |
| 783 | wpa_s->fetch_anqp_in_progress = 0; |
| 784 | } |
| 785 | |
| 786 | |
| 787 | void hs20_next_osu_icon(struct wpa_supplicant *wpa_s) |
| 788 | { |
| 789 | size_t i, j; |
| 790 | |
| 791 | wpa_printf(MSG_DEBUG, "HS 2.0: Ready to fetch next icon"); |
| 792 | |
| 793 | for (i = 0; i < wpa_s->osu_prov_count; i++) { |
| 794 | struct osu_provider *osu = &wpa_s->osu_prov[i]; |
| 795 | for (j = 0; j < osu->icon_count; j++) { |
| 796 | struct osu_icon *icon = &osu->icon[j]; |
| 797 | if (icon->id || icon->failed) |
| 798 | continue; |
| 799 | |
| 800 | wpa_printf(MSG_DEBUG, "HS 2.0: Try to fetch icon '%s' " |
| 801 | "from " MACSTR, icon->filename, |
| 802 | MAC2STR(osu->bssid)); |
| 803 | os_get_reltime(&wpa_s->osu_icon_fetch_start); |
| 804 | if (hs20_anqp_send_req(wpa_s, osu->bssid, |
| 805 | BIT(HS20_STYPE_ICON_REQUEST), |
| 806 | (u8 *) icon->filename, |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 807 | os_strlen(icon->filename), |
| 808 | 0) < 0) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 809 | icon->failed = 1; |
| 810 | continue; |
| 811 | } |
| 812 | return; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | wpa_printf(MSG_DEBUG, "HS 2.0: No more icons to fetch"); |
| 817 | hs20_osu_fetch_done(wpa_s); |
| 818 | } |
| 819 | |
| 820 | |
| 821 | static void hs20_osu_add_prov(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 822 | const u8 *osu_ssid, u8 osu_ssid_len, |
| 823 | const u8 *pos, size_t len) |
| 824 | { |
| 825 | struct osu_provider *prov; |
| 826 | const u8 *end = pos + len; |
| 827 | u16 len2; |
| 828 | const u8 *pos2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 829 | u8 uri_len, osu_method_len, osu_nai_len; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 830 | |
| 831 | wpa_hexdump(MSG_DEBUG, "HS 2.0: Parsing OSU Provider", pos, len); |
| 832 | prov = os_realloc_array(wpa_s->osu_prov, |
| 833 | wpa_s->osu_prov_count + 1, |
| 834 | sizeof(*prov)); |
| 835 | if (prov == NULL) |
| 836 | return; |
| 837 | wpa_s->osu_prov = prov; |
| 838 | prov = &prov[wpa_s->osu_prov_count]; |
| 839 | os_memset(prov, 0, sizeof(*prov)); |
| 840 | |
| 841 | os_memcpy(prov->bssid, bss->bssid, ETH_ALEN); |
| 842 | os_memcpy(prov->osu_ssid, osu_ssid, osu_ssid_len); |
| 843 | prov->osu_ssid_len = osu_ssid_len; |
| 844 | |
| 845 | /* OSU Friendly Name Length */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 846 | if (end - pos < 2) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 847 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU " |
| 848 | "Friendly Name Length"); |
| 849 | return; |
| 850 | } |
| 851 | len2 = WPA_GET_LE16(pos); |
| 852 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 853 | if (len2 > end - pos) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 854 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU " |
| 855 | "Friendly Name Duples"); |
| 856 | return; |
| 857 | } |
| 858 | pos2 = pos; |
| 859 | pos += len2; |
| 860 | |
| 861 | /* OSU Friendly Name Duples */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 862 | while (pos - pos2 >= 4 && prov->friendly_name_count < OSU_MAX_ITEMS) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 863 | struct osu_lang_string *f; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 864 | if (1 + pos2[0] > pos - pos2 || pos2[0] < 3) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 865 | wpa_printf(MSG_DEBUG, "Invalid OSU Friendly Name"); |
| 866 | break; |
| 867 | } |
| 868 | f = &prov->friendly_name[prov->friendly_name_count++]; |
| 869 | os_memcpy(f->lang, pos2 + 1, 3); |
| 870 | os_memcpy(f->text, pos2 + 1 + 3, pos2[0] - 3); |
| 871 | pos2 += 1 + pos2[0]; |
| 872 | } |
| 873 | |
| 874 | /* OSU Server URI */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 875 | if (end - pos < 1) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 876 | wpa_printf(MSG_DEBUG, |
| 877 | "HS 2.0: Not enough room for OSU Server URI length"); |
| 878 | return; |
| 879 | } |
| 880 | uri_len = *pos++; |
| 881 | if (uri_len > end - pos) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 882 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Server " |
| 883 | "URI"); |
| 884 | return; |
| 885 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 886 | os_memcpy(prov->server_uri, pos, uri_len); |
| 887 | pos += uri_len; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 888 | |
| 889 | /* OSU Method list */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 890 | if (end - pos < 1) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 891 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Method " |
| 892 | "list length"); |
| 893 | return; |
| 894 | } |
| 895 | osu_method_len = pos[0]; |
| 896 | if (osu_method_len > end - pos - 1) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 897 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Method " |
| 898 | "list"); |
| 899 | return; |
| 900 | } |
| 901 | pos2 = pos + 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 902 | pos += 1 + osu_method_len; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 903 | while (pos2 < pos) { |
| 904 | if (*pos2 < 32) |
| 905 | prov->osu_methods |= BIT(*pos2); |
| 906 | pos2++; |
| 907 | } |
| 908 | |
| 909 | /* Icons Available Length */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 910 | if (end - pos < 2) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 911 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for Icons " |
| 912 | "Available Length"); |
| 913 | return; |
| 914 | } |
| 915 | len2 = WPA_GET_LE16(pos); |
| 916 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 917 | if (len2 > end - pos) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 918 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for Icons " |
| 919 | "Available"); |
| 920 | return; |
| 921 | } |
| 922 | pos2 = pos; |
| 923 | pos += len2; |
| 924 | |
| 925 | /* Icons Available */ |
| 926 | while (pos2 < pos) { |
| 927 | struct osu_icon *icon = &prov->icon[prov->icon_count]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 928 | u8 flen; |
| 929 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 930 | if (2 + 2 + 3 + 1 + 1 > pos - pos2) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 931 | wpa_printf(MSG_DEBUG, "HS 2.0: Invalid Icon Metadata"); |
| 932 | break; |
| 933 | } |
| 934 | |
| 935 | icon->width = WPA_GET_LE16(pos2); |
| 936 | pos2 += 2; |
| 937 | icon->height = WPA_GET_LE16(pos2); |
| 938 | pos2 += 2; |
| 939 | os_memcpy(icon->lang, pos2, 3); |
| 940 | pos2 += 3; |
| 941 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 942 | flen = *pos2++; |
| 943 | if (flen > pos - pos2) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 944 | wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon Type"); |
| 945 | break; |
| 946 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 947 | os_memcpy(icon->icon_type, pos2, flen); |
| 948 | pos2 += flen; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 949 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 950 | if (pos - pos2 < 1) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 951 | wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon " |
| 952 | "Filename length"); |
| 953 | break; |
| 954 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 955 | flen = *pos2++; |
| 956 | if (flen > pos - pos2) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 957 | wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon " |
| 958 | "Filename"); |
| 959 | break; |
| 960 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 961 | os_memcpy(icon->filename, pos2, flen); |
| 962 | pos2 += flen; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 963 | |
| 964 | prov->icon_count++; |
| 965 | } |
| 966 | |
| 967 | /* OSU_NAI */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 968 | if (end - pos < 1) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 969 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU_NAI"); |
| 970 | return; |
| 971 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 972 | osu_nai_len = *pos++; |
| 973 | if (osu_nai_len > end - pos) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 974 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU_NAI"); |
| 975 | return; |
| 976 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 977 | os_memcpy(prov->osu_nai, pos, osu_nai_len); |
| 978 | pos += osu_nai_len; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 979 | |
| 980 | /* OSU Service Description Length */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 981 | if (end - pos < 2) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 982 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU " |
| 983 | "Service Description Length"); |
| 984 | return; |
| 985 | } |
| 986 | len2 = WPA_GET_LE16(pos); |
| 987 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 988 | if (len2 > end - pos) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 989 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU " |
| 990 | "Service Description Duples"); |
| 991 | return; |
| 992 | } |
| 993 | pos2 = pos; |
| 994 | pos += len2; |
| 995 | |
| 996 | /* OSU Service Description Duples */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 997 | while (pos - pos2 >= 4 && prov->serv_desc_count < OSU_MAX_ITEMS) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 998 | struct osu_lang_string *f; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 999 | u8 descr_len; |
| 1000 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1001 | descr_len = *pos2++; |
| 1002 | if (descr_len > pos - pos2 || descr_len < 3) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1003 | wpa_printf(MSG_DEBUG, "Invalid OSU Service " |
| 1004 | "Description"); |
| 1005 | break; |
| 1006 | } |
| 1007 | f = &prov->serv_desc[prov->serv_desc_count++]; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1008 | os_memcpy(f->lang, pos2, 3); |
| 1009 | os_memcpy(f->text, pos2 + 3, descr_len - 3); |
| 1010 | pos2 += descr_len; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | wpa_printf(MSG_DEBUG, "HS 2.0: Added OSU Provider through " MACSTR, |
| 1014 | MAC2STR(bss->bssid)); |
| 1015 | wpa_s->osu_prov_count++; |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | void hs20_osu_icon_fetch(struct wpa_supplicant *wpa_s) |
| 1020 | { |
| 1021 | struct wpa_bss *bss; |
| 1022 | struct wpabuf *prov_anqp; |
| 1023 | const u8 *pos, *end; |
| 1024 | u16 len; |
| 1025 | const u8 *osu_ssid; |
| 1026 | u8 osu_ssid_len; |
| 1027 | u8 num_providers; |
| 1028 | |
| 1029 | hs20_free_osu_prov(wpa_s); |
| 1030 | |
| 1031 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1032 | if (bss->anqp == NULL) |
| 1033 | continue; |
| 1034 | prov_anqp = bss->anqp->hs20_osu_providers_list; |
| 1035 | if (prov_anqp == NULL) |
| 1036 | continue; |
| 1037 | wpa_printf(MSG_DEBUG, "HS 2.0: Parsing OSU Providers list from " |
| 1038 | MACSTR, MAC2STR(bss->bssid)); |
| 1039 | wpa_hexdump_buf(MSG_DEBUG, "HS 2.0: OSU Providers list", |
| 1040 | prov_anqp); |
| 1041 | pos = wpabuf_head(prov_anqp); |
| 1042 | end = pos + wpabuf_len(prov_anqp); |
| 1043 | |
| 1044 | /* OSU SSID */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1045 | if (end - pos < 1) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1046 | continue; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1047 | if (1 + pos[0] > end - pos) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1048 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for " |
| 1049 | "OSU SSID"); |
| 1050 | continue; |
| 1051 | } |
| 1052 | osu_ssid_len = *pos++; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1053 | if (osu_ssid_len > SSID_MAX_LEN) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1054 | wpa_printf(MSG_DEBUG, "HS 2.0: Invalid OSU SSID " |
| 1055 | "Length %u", osu_ssid_len); |
| 1056 | continue; |
| 1057 | } |
| 1058 | osu_ssid = pos; |
| 1059 | pos += osu_ssid_len; |
| 1060 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1061 | if (end - pos < 1) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1062 | wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for " |
| 1063 | "Number of OSU Providers"); |
| 1064 | continue; |
| 1065 | } |
| 1066 | num_providers = *pos++; |
| 1067 | wpa_printf(MSG_DEBUG, "HS 2.0: Number of OSU Providers: %u", |
| 1068 | num_providers); |
| 1069 | |
| 1070 | /* OSU Providers */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1071 | while (end - pos > 2 && num_providers > 0) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1072 | num_providers--; |
| 1073 | len = WPA_GET_LE16(pos); |
| 1074 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1075 | if (len > (unsigned int) (end - pos)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1076 | break; |
| 1077 | hs20_osu_add_prov(wpa_s, bss, osu_ssid, |
| 1078 | osu_ssid_len, pos, len); |
| 1079 | pos += len; |
| 1080 | } |
| 1081 | |
| 1082 | if (pos != end) { |
| 1083 | wpa_printf(MSG_DEBUG, "HS 2.0: Ignored %d bytes of " |
| 1084 | "extra data after OSU Providers", |
| 1085 | (int) (end - pos)); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | wpa_s->fetch_osu_icon_in_progress = 1; |
| 1090 | hs20_next_osu_icon(wpa_s); |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | static void hs20_osu_scan_res_handler(struct wpa_supplicant *wpa_s, |
| 1095 | struct wpa_scan_results *scan_res) |
| 1096 | { |
| 1097 | wpa_printf(MSG_DEBUG, "OSU provisioning fetch scan completed"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1098 | if (!wpa_s->fetch_osu_waiting_scan) { |
| 1099 | wpa_printf(MSG_DEBUG, "OSU fetch have been canceled"); |
| 1100 | return; |
| 1101 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1102 | wpa_s->network_select = 0; |
| 1103 | wpa_s->fetch_all_anqp = 1; |
| 1104 | wpa_s->fetch_osu_info = 1; |
| 1105 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 1106 | |
| 1107 | interworking_start_fetch_anqp(wpa_s); |
| 1108 | } |
| 1109 | |
| 1110 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1111 | int hs20_fetch_osu(struct wpa_supplicant *wpa_s, int skip_scan) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1112 | { |
| 1113 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 1114 | wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - " |
| 1115 | "interface disabled"); |
| 1116 | return -1; |
| 1117 | } |
| 1118 | |
| 1119 | if (wpa_s->scanning) { |
| 1120 | wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - " |
| 1121 | "scanning"); |
| 1122 | return -1; |
| 1123 | } |
| 1124 | |
| 1125 | if (wpa_s->conf->osu_dir == NULL) { |
| 1126 | wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - " |
| 1127 | "osu_dir not configured"); |
| 1128 | return -1; |
| 1129 | } |
| 1130 | |
| 1131 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) { |
| 1132 | wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - " |
| 1133 | "fetch in progress (%d, %d)", |
| 1134 | wpa_s->fetch_anqp_in_progress, |
| 1135 | wpa_s->network_select); |
| 1136 | return -1; |
| 1137 | } |
| 1138 | |
| 1139 | wpa_msg(wpa_s, MSG_INFO, "Starting OSU provisioning information fetch"); |
| 1140 | wpa_s->num_osu_scans = 0; |
| 1141 | wpa_s->num_prov_found = 0; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1142 | if (skip_scan) { |
| 1143 | wpa_s->network_select = 0; |
| 1144 | wpa_s->fetch_all_anqp = 1; |
| 1145 | wpa_s->fetch_osu_info = 1; |
| 1146 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 1147 | |
| 1148 | interworking_start_fetch_anqp(wpa_s); |
| 1149 | } else { |
| 1150 | hs20_start_osu_scan(wpa_s); |
| 1151 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | void hs20_start_osu_scan(struct wpa_supplicant *wpa_s) |
| 1158 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1159 | wpa_s->fetch_osu_waiting_scan = 1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1160 | wpa_s->num_osu_scans++; |
| 1161 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 1162 | wpa_s->scan_res_handler = hs20_osu_scan_res_handler; |
| 1163 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | void hs20_cancel_fetch_osu(struct wpa_supplicant *wpa_s) |
| 1168 | { |
| 1169 | wpa_printf(MSG_DEBUG, "Cancel OSU fetch"); |
| 1170 | interworking_stop_fetch_anqp(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1171 | wpa_s->fetch_osu_waiting_scan = 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1172 | wpa_s->network_select = 0; |
| 1173 | wpa_s->fetch_osu_info = 0; |
| 1174 | wpa_s->fetch_osu_icon_in_progress = 0; |
| 1175 | } |
| 1176 | |
| 1177 | |
| 1178 | void hs20_icon_fetch_failed(struct wpa_supplicant *wpa_s) |
| 1179 | { |
| 1180 | hs20_osu_icon_fetch_result(wpa_s, -1); |
| 1181 | eloop_cancel_timeout(hs20_continue_icon_fetch, wpa_s, NULL); |
| 1182 | eloop_register_timeout(0, 0, hs20_continue_icon_fetch, wpa_s, NULL); |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | void hs20_rx_subscription_remediation(struct wpa_supplicant *wpa_s, |
| 1187 | const char *url, u8 osu_method) |
| 1188 | { |
| 1189 | if (url) |
| 1190 | wpa_msg(wpa_s, MSG_INFO, HS20_SUBSCRIPTION_REMEDIATION "%u %s", |
| 1191 | osu_method, url); |
| 1192 | else |
| 1193 | wpa_msg(wpa_s, MSG_INFO, HS20_SUBSCRIPTION_REMEDIATION); |
Roshan Pius | 04a9d74 | 2016-12-12 12:40:46 -0800 | [diff] [blame] | 1194 | wpas_notify_hs20_rx_subscription_remediation(wpa_s, url, osu_method); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | void hs20_rx_deauth_imminent_notice(struct wpa_supplicant *wpa_s, u8 code, |
| 1199 | u16 reauth_delay, const char *url) |
| 1200 | { |
| 1201 | if (!wpa_sm_pmf_enabled(wpa_s->wpa)) { |
| 1202 | wpa_printf(MSG_DEBUG, "HS 2.0: Ignore deauthentication imminent notice since PMF was not enabled"); |
| 1203 | return; |
| 1204 | } |
| 1205 | |
| 1206 | wpa_msg(wpa_s, MSG_INFO, HS20_DEAUTH_IMMINENT_NOTICE "%u %u %s", |
| 1207 | code, reauth_delay, url); |
Roshan Pius | 04a9d74 | 2016-12-12 12:40:46 -0800 | [diff] [blame] | 1208 | wpas_notify_hs20_rx_deauth_imminent_notice(wpa_s, code, reauth_delay, url); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1209 | |
| 1210 | if (code == HS20_DEAUTH_REASON_CODE_BSS) { |
| 1211 | wpa_printf(MSG_DEBUG, "HS 2.0: Add BSS to blacklist"); |
| 1212 | wpa_blacklist_add(wpa_s, wpa_s->bssid); |
| 1213 | /* TODO: For now, disable full ESS since some drivers may not |
| 1214 | * support disabling per BSS. */ |
| 1215 | if (wpa_s->current_ssid) { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1216 | struct os_reltime now; |
| 1217 | os_get_reltime(&now); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1218 | if (now.sec + reauth_delay <= |
| 1219 | wpa_s->current_ssid->disabled_until.sec) |
| 1220 | return; |
| 1221 | wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds (BSS)", |
| 1222 | reauth_delay); |
| 1223 | wpa_s->current_ssid->disabled_until.sec = |
| 1224 | now.sec + reauth_delay; |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | if (code == HS20_DEAUTH_REASON_CODE_ESS && wpa_s->current_ssid) { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1229 | struct os_reltime now; |
| 1230 | os_get_reltime(&now); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1231 | if (now.sec + reauth_delay <= |
| 1232 | wpa_s->current_ssid->disabled_until.sec) |
| 1233 | return; |
| 1234 | wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds", |
| 1235 | reauth_delay); |
| 1236 | wpa_s->current_ssid->disabled_until.sec = |
| 1237 | now.sec + reauth_delay; |
| 1238 | } |
| 1239 | } |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 1240 | |
| 1241 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame^] | 1242 | void hs20_rx_t_c_acceptance(struct wpa_supplicant *wpa_s, const char *url) |
| 1243 | { |
| 1244 | if (!wpa_sm_pmf_enabled(wpa_s->wpa)) { |
| 1245 | wpa_printf(MSG_DEBUG, |
| 1246 | "HS 2.0: Ignore Terms and Conditions Acceptance since PMF was not enabled"); |
| 1247 | return; |
| 1248 | } |
| 1249 | |
| 1250 | wpa_msg(wpa_s, MSG_INFO, HS20_T_C_ACCEPTANCE "%s", url); |
| 1251 | } |
| 1252 | |
| 1253 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1254 | void hs20_init(struct wpa_supplicant *wpa_s) |
| 1255 | { |
| 1256 | dl_list_init(&wpa_s->icon_head); |
| 1257 | } |
| 1258 | |
| 1259 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 1260 | void hs20_deinit(struct wpa_supplicant *wpa_s) |
| 1261 | { |
| 1262 | eloop_cancel_timeout(hs20_continue_icon_fetch, wpa_s, NULL); |
| 1263 | hs20_free_osu_prov(wpa_s); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1264 | if (wpa_s->icon_head.next) |
| 1265 | hs20_del_icon(wpa_s, NULL, NULL); |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 1266 | } |