blob: d287b708e1cf382a751b81abdab1235814c5e35f [file] [log] [blame]
Dmitry Shmidt04949592012-07-19 12:16:46 -07001/*
2 * Copyright (c) 2009, Atheros Communications, Inc.
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003 * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
Dmitry Shmidt04949592012-07-19 12:16:46 -07004 *
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 Shmidt2f74e362015-01-21 13:19:05 -080010#include <sys/stat.h>
Dmitry Shmidt04949592012-07-19 12:16:46 -070011
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 Shmidtf21452a2014-02-26 10:55:25 -080018#include "rsn_supp/wpa.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070019#include "wpa_supplicant_i.h"
20#include "driver_i.h"
21#include "config.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080022#include "scan.h"
Roshan Pius04a9d742016-12-12 12:40:46 -080023#include "notify.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070024#include "bss.h"
Hai Shalom60840252021-02-19 19:02:11 -080025#include "bssid_ignore.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070026#include "gas_query.h"
27#include "interworking.h"
28#include "hs20_supplicant.h"
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080029#include "base64.h"
Sunil Ravib0ac25f2024-07-12 01:42:03 +000030#include "notify.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070031
32
Dmitry Shmidt849734c2016-05-27 09:59:01 -070033void hs20_configure_frame_filters(struct wpa_supplicant *wpa_s)
34{
35 struct wpa_bss *bss = wpa_s->current_bss;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070036 const u8 *ie;
37 const u8 *ext_capa;
38 u32 filter = 0;
39
Hai Shalom2cbbcd12021-03-08 18:33:38 -080040 if (!bss || !is_hs20_network(wpa_s, wpa_s->current_ssid, bss)
41#ifndef ANDROID
42 // HS 2.0 Configuration is not used in AOSP
43 || !is_hs20_config(wpa_s)
44#endif
45 ) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000046 /* Not configuring frame filtering - BSS is not a Hotspot 2.0
47 * network */
Dmitry Shmidt849734c2016-05-27 09:59:01 -070048 return;
49 }
50
51 ie = wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE);
52
53 /* Check if DGAF disabled bit is zero (5th byte in the IE) */
54 if (!ie || ie[1] < 5)
55 wpa_printf(MSG_DEBUG,
56 "Not configuring frame filtering - Can't extract DGAF bit");
57 else if (!(ie[6] & HS20_DGAF_DISABLED))
58 filter |= WPA_DATA_FRAME_FILTER_FLAG_GTK;
59
60 ext_capa = wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB);
61 if (!ext_capa || ext_capa[1] < 2) {
62 wpa_printf(MSG_DEBUG,
63 "Not configuring frame filtering - Can't extract Proxy ARP bit");
64 return;
65 }
66
Hai Shalom74f70d42019-02-11 14:42:39 -080067 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_PROXY_ARP))
Dmitry Shmidt849734c2016-05-27 09:59:01 -070068 filter |= WPA_DATA_FRAME_FILTER_FLAG_ARP |
69 WPA_DATA_FRAME_FILTER_FLAG_NA;
70
71 wpa_drv_configure_frame_filters(wpa_s, filter);
72}
73
74
Hai Shalom74f70d42019-02-11 14:42:39 -080075void wpas_hs20_add_indication(struct wpabuf *buf, int pps_mo_id, int ap_release)
Dmitry Shmidt04949592012-07-19 12:16:46 -070076{
Hai Shalom74f70d42019-02-11 14:42:39 -080077 int release;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080078 u8 conf;
79
Hai Shalom74f70d42019-02-11 14:42:39 -080080 release = (HS20_VERSION >> 4) + 1;
81 if (ap_release > 0 && release > ap_release)
82 release = ap_release;
83 if (release < 2)
84 pps_mo_id = -1;
85
Dmitry Shmidt04949592012-07-19 12:16:46 -070086 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080087 wpabuf_put_u8(buf, pps_mo_id >= 0 ? 7 : 5);
Dmitry Shmidt04949592012-07-19 12:16:46 -070088 wpabuf_put_be24(buf, OUI_WFA);
89 wpabuf_put_u8(buf, HS20_INDICATION_OUI_TYPE);
Hai Shalom74f70d42019-02-11 14:42:39 -080090 conf = (release - 1) << 4;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080091 if (pps_mo_id >= 0)
92 conf |= HS20_PPS_MO_ID_PRESENT;
93 wpabuf_put_u8(buf, conf);
94 if (pps_mo_id >= 0)
95 wpabuf_put_le16(buf, pps_mo_id);
Dmitry Shmidt04949592012-07-19 12:16:46 -070096}
97
98
Roshan Pius3a1667e2018-07-03 15:17:14 -070099void wpas_hs20_add_roam_cons_sel(struct wpabuf *buf,
100 const struct wpa_ssid *ssid)
101{
102 if (!ssid->roaming_consortium_selection ||
103 !ssid->roaming_consortium_selection_len)
104 return;
105
106 wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
107 wpabuf_put_u8(buf, 4 + ssid->roaming_consortium_selection_len);
108 wpabuf_put_be24(buf, OUI_WFA);
109 wpabuf_put_u8(buf, HS20_ROAMING_CONS_SEL_OUI_TYPE);
110 wpabuf_put_data(buf, ssid->roaming_consortium_selection,
111 ssid->roaming_consortium_selection_len);
112}
113
114
Hai Shalom74f70d42019-02-11 14:42:39 -0800115int get_hs20_version(struct wpa_bss *bss)
116{
117 const u8 *ie;
118
119 if (!bss)
120 return 0;
121
122 ie = wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE);
123 if (!ie || ie[1] < 5)
124 return 0;
125
126 return ((ie[6] >> 4) & 0x0f) + 1;
127}
128
Hai Shalom2cbbcd12021-03-08 18:33:38 -0800129int is_hs20_config(struct wpa_supplicant *wpa_s)
130{
131 return wpa_s->conf->hs20;
132}
Hai Shalom74f70d42019-02-11 14:42:39 -0800133
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700134int is_hs20_network(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
135 struct wpa_bss *bss)
136{
Hai Shalom2cbbcd12021-03-08 18:33:38 -0800137 if (!ssid)
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700138 return 0;
139
140 if (ssid->parent_cred)
141 return 1;
142
143 if (bss && !wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE))
144 return 0;
145
146 /*
147 * This may catch some non-Hotspot 2.0 cases, but it is safer to do that
148 * than cause Hotspot 2.0 connections without indication element getting
149 * added. Non-Hotspot 2.0 APs should ignore the unknown vendor element.
150 */
151
152 if (!(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X))
153 return 0;
154 if (!(ssid->pairwise_cipher & WPA_CIPHER_CCMP))
155 return 0;
156 if (ssid->proto != WPA_PROTO_RSN)
157 return 0;
158
159 return 1;
160}
161
162
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800163int hs20_get_pps_mo_id(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
164{
165 struct wpa_cred *cred;
166
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700167 if (ssid == NULL)
168 return 0;
169
170 if (ssid->update_identifier)
171 return ssid->update_identifier;
172
173 if (ssid->parent_cred == NULL)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800174 return 0;
175
176 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
177 if (ssid->parent_cred == cred)
178 return cred->update_identifier;
179 }
180
181 return 0;
182}
183
184
Dmitry Shmidt15907092014-03-25 10:42:57 -0700185void hs20_put_anqp_req(u32 stypes, const u8 *payload, size_t payload_len,
186 struct wpabuf *buf)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700187{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700188 u8 *len_pos;
189
Dmitry Shmidt04949592012-07-19 12:16:46 -0700190 if (buf == NULL)
Dmitry Shmidt15907092014-03-25 10:42:57 -0700191 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700192
193 len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
194 wpabuf_put_be24(buf, OUI_WFA);
195 wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
196 if (stypes == BIT(HS20_STYPE_NAI_HOME_REALM_QUERY)) {
197 wpabuf_put_u8(buf, HS20_STYPE_NAI_HOME_REALM_QUERY);
198 wpabuf_put_u8(buf, 0); /* Reserved */
199 if (payload)
200 wpabuf_put_data(buf, payload, payload_len);
201 } else {
202 u8 i;
203 wpabuf_put_u8(buf, HS20_STYPE_QUERY_LIST);
204 wpabuf_put_u8(buf, 0); /* Reserved */
205 for (i = 0; i < 32; i++) {
206 if (stypes & BIT(i))
207 wpabuf_put_u8(buf, i);
208 }
209 }
210 gas_anqp_set_element_len(buf, len_pos);
211
212 gas_anqp_set_len(buf);
Dmitry Shmidt15907092014-03-25 10:42:57 -0700213}
214
215
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700216static struct wpabuf * hs20_build_anqp_req(u32 stypes, const u8 *payload,
217 size_t payload_len)
Dmitry Shmidt15907092014-03-25 10:42:57 -0700218{
219 struct wpabuf *buf;
220
221 buf = gas_anqp_build_initial_req(0, 100 + payload_len);
222 if (buf == NULL)
223 return NULL;
224
225 hs20_put_anqp_req(stypes, payload, payload_len, buf);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700226
227 return buf;
228}
229
230
231int hs20_anqp_send_req(struct wpa_supplicant *wpa_s, const u8 *dst, u32 stypes,
Sunil Ravi876a49b2025-02-03 19:18:32 +0000232 const u8 *payload, size_t payload_len)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700233{
234 struct wpabuf *buf;
235 int ret = 0;
236 int freq;
237 struct wpa_bss *bss;
238 int res;
239
Dmitry Shmidt04949592012-07-19 12:16:46 -0700240 bss = wpa_bss_get_bssid(wpa_s, dst);
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -0700241 if (!bss) {
242 wpa_printf(MSG_WARNING,
243 "ANQP: Cannot send query to unknown BSS "
244 MACSTR, MAC2STR(dst));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700245 return -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -0700246 }
247
248 wpa_bss_anqp_unshare_alloc(bss);
249 freq = bss->freq;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700250
251 wpa_printf(MSG_DEBUG, "HS20: ANQP Query Request to " MACSTR " for "
252 "subtypes 0x%x", MAC2STR(dst), stypes);
253
254 buf = hs20_build_anqp_req(stypes, payload, payload_len);
255 if (buf == NULL)
256 return -1;
257
Hai Shalomb755a2a2020-04-23 21:49:02 -0700258 res = gas_query_req(wpa_s->gas, dst, freq, 0, 0, buf, anqp_resp_cb,
259 wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700260 if (res < 0) {
261 wpa_printf(MSG_DEBUG, "ANQP: Failed to send Query Request");
Dmitry Shmidt051af732013-10-22 13:52:46 -0700262 wpabuf_free(buf);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -0800263 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700264 } else
265 wpa_printf(MSG_DEBUG, "ANQP: Query started with dialog token "
266 "%u", res);
267
Dmitry Shmidt04949592012-07-19 12:16:46 -0700268 return ret;
269}
270
271
272void hs20_parse_rx_hs20_anqp_resp(struct wpa_supplicant *wpa_s,
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800273 struct wpa_bss *bss, const u8 *sa,
Dmitry Shmidt7d56b752015-12-22 10:59:44 -0800274 const u8 *data, size_t slen, u8 dialog_token)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700275{
276 const u8 *pos = data;
277 u8 subtype;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700278 struct wpa_bss_anqp *anqp = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700279
280 if (slen < 2)
281 return;
282
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700283 if (bss)
284 anqp = bss->anqp;
285
Dmitry Shmidt04949592012-07-19 12:16:46 -0700286 subtype = *pos++;
287 slen--;
288
289 pos++; /* Reserved */
290 slen--;
291
292 switch (subtype) {
293 case HS20_STYPE_CAPABILITY_LIST:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700294 wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
Dmitry Shmidt04949592012-07-19 12:16:46 -0700295 " HS Capability List", MAC2STR(sa));
296 wpa_hexdump_ascii(MSG_DEBUG, "HS Capability List", pos, slen);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800297 if (anqp) {
298 wpabuf_free(anqp->hs20_capability_list);
299 anqp->hs20_capability_list =
300 wpabuf_alloc_copy(pos, slen);
301 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700302 break;
303 case HS20_STYPE_OPERATOR_FRIENDLY_NAME:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700304 wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
Dmitry Shmidt04949592012-07-19 12:16:46 -0700305 " Operator Friendly Name", MAC2STR(sa));
306 wpa_hexdump_ascii(MSG_DEBUG, "oper friendly name", pos, slen);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700307 if (anqp) {
308 wpabuf_free(anqp->hs20_operator_friendly_name);
309 anqp->hs20_operator_friendly_name =
Dmitry Shmidt04949592012-07-19 12:16:46 -0700310 wpabuf_alloc_copy(pos, slen);
311 }
312 break;
313 case HS20_STYPE_WAN_METRICS:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800314 wpa_hexdump(MSG_DEBUG, "WAN Metrics", pos, slen);
315 if (slen < 13) {
316 wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short WAN "
317 "Metrics value from " MACSTR, MAC2STR(sa));
318 break;
319 }
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700320 wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800321 " WAN Metrics %02x:%u:%u:%u:%u:%u", MAC2STR(sa),
322 pos[0], WPA_GET_LE32(pos + 1), WPA_GET_LE32(pos + 5),
323 pos[9], pos[10], WPA_GET_LE16(pos + 11));
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700324 if (anqp) {
325 wpabuf_free(anqp->hs20_wan_metrics);
326 anqp->hs20_wan_metrics = wpabuf_alloc_copy(pos, slen);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700327 }
328 break;
329 case HS20_STYPE_CONNECTION_CAPABILITY:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700330 wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
Dmitry Shmidt04949592012-07-19 12:16:46 -0700331 " Connection Capability", MAC2STR(sa));
332 wpa_hexdump_ascii(MSG_DEBUG, "conn capability", pos, slen);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700333 if (anqp) {
334 wpabuf_free(anqp->hs20_connection_capability);
335 anqp->hs20_connection_capability =
Dmitry Shmidt04949592012-07-19 12:16:46 -0700336 wpabuf_alloc_copy(pos, slen);
337 }
338 break;
339 case HS20_STYPE_OPERATING_CLASS:
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -0700340 wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
Dmitry Shmidt04949592012-07-19 12:16:46 -0700341 " Operating Class", MAC2STR(sa));
342 wpa_hexdump_ascii(MSG_DEBUG, "Operating Class", pos, slen);
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -0700343 if (anqp) {
344 wpabuf_free(anqp->hs20_operating_class);
345 anqp->hs20_operating_class =
Dmitry Shmidt04949592012-07-19 12:16:46 -0700346 wpabuf_alloc_copy(pos, slen);
347 }
348 break;
349 default:
350 wpa_printf(MSG_DEBUG, "HS20: Unsupported subtype %u", subtype);
351 break;
352 }
353}
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800354
355
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800356void hs20_rx_deauth_imminent_notice(struct wpa_supplicant *wpa_s, u8 code,
357 u16 reauth_delay, const char *url)
358{
359 if (!wpa_sm_pmf_enabled(wpa_s->wpa)) {
360 wpa_printf(MSG_DEBUG, "HS 2.0: Ignore deauthentication imminent notice since PMF was not enabled");
361 return;
362 }
363
364 wpa_msg(wpa_s, MSG_INFO, HS20_DEAUTH_IMMINENT_NOTICE "%u %u %s",
365 code, reauth_delay, url);
Roshan Pius04a9d742016-12-12 12:40:46 -0800366 wpas_notify_hs20_rx_deauth_imminent_notice(wpa_s, code, reauth_delay, url);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800367
368 if (code == HS20_DEAUTH_REASON_CODE_BSS) {
Hai Shalom60840252021-02-19 19:02:11 -0800369 wpa_printf(MSG_DEBUG, "HS 2.0: Add BSS to ignore list");
370 wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800371 /* TODO: For now, disable full ESS since some drivers may not
372 * support disabling per BSS. */
373 if (wpa_s->current_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -0800374 struct os_reltime now;
375 os_get_reltime(&now);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800376 if (now.sec + reauth_delay <=
377 wpa_s->current_ssid->disabled_until.sec)
378 return;
379 wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds (BSS)",
380 reauth_delay);
381 wpa_s->current_ssid->disabled_until.sec =
382 now.sec + reauth_delay;
383 }
384 }
385
386 if (code == HS20_DEAUTH_REASON_CODE_ESS && wpa_s->current_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -0800387 struct os_reltime now;
388 os_get_reltime(&now);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800389 if (now.sec + reauth_delay <=
390 wpa_s->current_ssid->disabled_until.sec)
391 return;
392 wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds",
393 reauth_delay);
394 wpa_s->current_ssid->disabled_until.sec =
395 now.sec + reauth_delay;
396 }
397}
Dmitry Shmidt684785c2014-05-12 13:34:29 -0700398
399
Roshan Pius3a1667e2018-07-03 15:17:14 -0700400void hs20_rx_t_c_acceptance(struct wpa_supplicant *wpa_s, const char *url)
401{
402 if (!wpa_sm_pmf_enabled(wpa_s->wpa)) {
403 wpa_printf(MSG_DEBUG,
404 "HS 2.0: Ignore Terms and Conditions Acceptance since PMF was not enabled");
405 return;
406 }
407
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000408 wpas_notify_hs20_t_c_acceptance(wpa_s, url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700409}