Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Interworking (IEEE 802.11u) |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2013, Qualcomm Atheros, Inc. |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4 | * Copyright (c) 2011-2014, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include "includes.h" |
| 11 | |
| 12 | #include "common.h" |
| 13 | #include "common/ieee802_11_defs.h" |
| 14 | #include "common/gas.h" |
| 15 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 16 | #include "utils/pcsc_funcs.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 17 | #include "utils/eloop.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 18 | #include "drivers/driver.h" |
| 19 | #include "eap_common/eap_defs.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 20 | #include "eap_peer/eap.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 21 | #include "eap_peer/eap_methods.h" |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 22 | #include "eapol_supp/eapol_supp_sm.h" |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 23 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 24 | #include "wpa_supplicant_i.h" |
| 25 | #include "config.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 26 | #include "config_ssid.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 27 | #include "bss.h" |
| 28 | #include "scan.h" |
| 29 | #include "notify.h" |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 30 | #include "driver_i.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 31 | #include "gas_query.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 32 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 33 | #include "interworking.h" |
| 34 | |
| 35 | |
| 36 | #if defined(EAP_SIM) | defined(EAP_SIM_DYNAMIC) |
| 37 | #define INTERWORKING_3GPP |
| 38 | #else |
| 39 | #if defined(EAP_AKA) | defined(EAP_AKA_DYNAMIC) |
| 40 | #define INTERWORKING_3GPP |
| 41 | #else |
| 42 | #if defined(EAP_AKA_PRIME) | defined(EAP_AKA_PRIME_DYNAMIC) |
| 43 | #define INTERWORKING_3GPP |
| 44 | #endif |
| 45 | #endif |
| 46 | #endif |
| 47 | |
| 48 | static void interworking_next_anqp_fetch(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 49 | static struct wpa_cred * interworking_credentials_available_realm( |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 50 | struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int ignore_bw, |
| 51 | int *excluded); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 52 | static struct wpa_cred * interworking_credentials_available_3gpp( |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 53 | struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int ignore_bw, |
| 54 | int *excluded); |
| 55 | |
| 56 | |
| 57 | static int cred_prio_cmp(const struct wpa_cred *a, const struct wpa_cred *b) |
| 58 | { |
| 59 | if (a->priority > b->priority) |
| 60 | return 1; |
| 61 | if (a->priority < b->priority) |
| 62 | return -1; |
| 63 | if (a->provisioning_sp == NULL || b->provisioning_sp == NULL || |
| 64 | os_strcmp(a->provisioning_sp, b->provisioning_sp) != 0) |
| 65 | return 0; |
| 66 | if (a->sp_priority < b->sp_priority) |
| 67 | return 1; |
| 68 | if (a->sp_priority > b->sp_priority) |
| 69 | return -1; |
| 70 | return 0; |
| 71 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 72 | |
| 73 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 74 | static void interworking_reconnect(struct wpa_supplicant *wpa_s) |
| 75 | { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 76 | unsigned int tried; |
| 77 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 78 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 79 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 80 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 81 | wpa_supplicant_deauthenticate(wpa_s, |
| 82 | WLAN_REASON_DEAUTH_LEAVING); |
| 83 | } |
| 84 | wpa_s->disconnected = 0; |
| 85 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 86 | tried = wpa_s->interworking_fast_assoc_tried; |
| 87 | wpa_s->interworking_fast_assoc_tried = 1; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 88 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 89 | if (!tried && wpa_supplicant_fast_associate(wpa_s) >= 0) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 90 | return; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 91 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 92 | wpa_s->interworking_fast_assoc_tried = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 93 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 94 | } |
| 95 | |
| 96 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 97 | static struct wpabuf * anqp_build_req(u16 info_ids[], size_t num_ids, |
| 98 | struct wpabuf *extra) |
| 99 | { |
| 100 | struct wpabuf *buf; |
| 101 | size_t i; |
| 102 | u8 *len_pos; |
| 103 | |
| 104 | buf = gas_anqp_build_initial_req(0, 4 + num_ids * 2 + |
| 105 | (extra ? wpabuf_len(extra) : 0)); |
| 106 | if (buf == NULL) |
| 107 | return NULL; |
| 108 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 109 | if (num_ids > 0) { |
| 110 | len_pos = gas_anqp_add_element(buf, ANQP_QUERY_LIST); |
| 111 | for (i = 0; i < num_ids; i++) |
| 112 | wpabuf_put_le16(buf, info_ids[i]); |
| 113 | gas_anqp_set_element_len(buf, len_pos); |
| 114 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 115 | if (extra) |
| 116 | wpabuf_put_buf(buf, extra); |
| 117 | |
| 118 | gas_anqp_set_len(buf); |
| 119 | |
| 120 | return buf; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | static void interworking_anqp_resp_cb(void *ctx, const u8 *dst, |
| 125 | u8 dialog_token, |
| 126 | enum gas_query_result result, |
| 127 | const struct wpabuf *adv_proto, |
| 128 | const struct wpabuf *resp, |
| 129 | u16 status_code) |
| 130 | { |
| 131 | struct wpa_supplicant *wpa_s = ctx; |
| 132 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 133 | wpa_printf(MSG_DEBUG, "ANQP: Response callback dst=" MACSTR |
| 134 | " dialog_token=%u result=%d status_code=%u", |
| 135 | MAC2STR(dst), dialog_token, result, status_code); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 136 | anqp_resp_cb(wpa_s, dst, dialog_token, result, adv_proto, resp, |
| 137 | status_code); |
| 138 | interworking_next_anqp_fetch(wpa_s); |
| 139 | } |
| 140 | |
| 141 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 142 | static int cred_with_roaming_consortium(struct wpa_supplicant *wpa_s) |
| 143 | { |
| 144 | struct wpa_cred *cred; |
| 145 | |
| 146 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 147 | if (cred->num_home_ois) |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 148 | return 1; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 149 | if (cred->num_required_home_ois) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 150 | return 1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 151 | if (cred->num_roaming_consortiums) |
| 152 | return 1; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 153 | } |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | static int cred_with_3gpp(struct wpa_supplicant *wpa_s) |
| 159 | { |
| 160 | struct wpa_cred *cred; |
| 161 | |
| 162 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| 163 | if (cred->pcsc || cred->imsi) |
| 164 | return 1; |
| 165 | } |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | static int cred_with_nai_realm(struct wpa_supplicant *wpa_s) |
| 171 | { |
| 172 | struct wpa_cred *cred; |
| 173 | |
| 174 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| 175 | if (cred->pcsc || cred->imsi) |
| 176 | continue; |
| 177 | if (!cred->eap_method) |
| 178 | return 1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 179 | if (cred->realm) |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 180 | return 1; |
| 181 | } |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | |
| 186 | static int cred_with_domain(struct wpa_supplicant *wpa_s) |
| 187 | { |
| 188 | struct wpa_cred *cred; |
| 189 | |
| 190 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 191 | if (cred->domain || cred->pcsc || cred->imsi || |
| 192 | cred->roaming_partner) |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 193 | return 1; |
| 194 | } |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 199 | #ifdef CONFIG_HS20 |
| 200 | |
| 201 | static int cred_with_min_backhaul(struct wpa_supplicant *wpa_s) |
| 202 | { |
| 203 | struct wpa_cred *cred; |
| 204 | |
| 205 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| 206 | if (cred->min_dl_bandwidth_home || |
| 207 | cred->min_ul_bandwidth_home || |
| 208 | cred->min_dl_bandwidth_roaming || |
| 209 | cred->min_ul_bandwidth_roaming) |
| 210 | return 1; |
| 211 | } |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | |
| 216 | static int cred_with_conn_capab(struct wpa_supplicant *wpa_s) |
| 217 | { |
| 218 | struct wpa_cred *cred; |
| 219 | |
| 220 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| 221 | if (cred->num_req_conn_capab) |
| 222 | return 1; |
| 223 | } |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | #endif /* CONFIG_HS20 */ |
| 228 | |
| 229 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 230 | static int additional_roaming_consortiums(struct wpa_bss *bss) |
| 231 | { |
| 232 | const u8 *ie; |
| 233 | ie = wpa_bss_get_ie(bss, WLAN_EID_ROAMING_CONSORTIUM); |
| 234 | if (ie == NULL || ie[1] == 0) |
| 235 | return 0; |
| 236 | return ie[2]; /* Number of ANQP OIs */ |
| 237 | } |
| 238 | |
| 239 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 240 | static void interworking_continue_anqp(void *eloop_ctx, void *sock_ctx) |
| 241 | { |
| 242 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 243 | interworking_next_anqp_fetch(wpa_s); |
| 244 | } |
| 245 | |
| 246 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 247 | static int interworking_anqp_send_req(struct wpa_supplicant *wpa_s, |
| 248 | struct wpa_bss *bss) |
| 249 | { |
| 250 | struct wpabuf *buf; |
| 251 | int ret = 0; |
| 252 | int res; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 253 | u16 info_ids[8]; |
| 254 | size_t num_info_ids = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 255 | struct wpabuf *extra = NULL; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 256 | int all = wpa_s->fetch_all_anqp; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 257 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 258 | wpa_msg(wpa_s, MSG_DEBUG, "Interworking: ANQP Query Request to " MACSTR, |
| 259 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 260 | wpa_s->interworking_gas_bss = bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 261 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 262 | info_ids[num_info_ids++] = ANQP_CAPABILITY_LIST; |
| 263 | if (all) { |
| 264 | info_ids[num_info_ids++] = ANQP_VENUE_NAME; |
| 265 | info_ids[num_info_ids++] = ANQP_NETWORK_AUTH_TYPE; |
| 266 | } |
| 267 | if (all || (cred_with_roaming_consortium(wpa_s) && |
| 268 | additional_roaming_consortiums(bss))) |
| 269 | info_ids[num_info_ids++] = ANQP_ROAMING_CONSORTIUM; |
| 270 | if (all) |
| 271 | info_ids[num_info_ids++] = ANQP_IP_ADDR_TYPE_AVAILABILITY; |
| 272 | if (all || cred_with_nai_realm(wpa_s)) |
| 273 | info_ids[num_info_ids++] = ANQP_NAI_REALM; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 274 | if (all || cred_with_3gpp(wpa_s)) { |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 275 | info_ids[num_info_ids++] = ANQP_3GPP_CELLULAR_NETWORK; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 276 | wpa_supplicant_scard_init(wpa_s, NULL); |
| 277 | } |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 278 | if (all || cred_with_domain(wpa_s)) |
| 279 | info_ids[num_info_ids++] = ANQP_DOMAIN_NAME; |
| 280 | wpa_hexdump(MSG_DEBUG, "Interworking: ANQP Query info", |
| 281 | (u8 *) info_ids, num_info_ids * 2); |
| 282 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 283 | #ifdef CONFIG_HS20 |
| 284 | if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) { |
| 285 | u8 *len_pos; |
| 286 | |
| 287 | extra = wpabuf_alloc(100); |
| 288 | if (!extra) |
| 289 | return -1; |
| 290 | |
| 291 | len_pos = gas_anqp_add_element(extra, ANQP_VENDOR_SPECIFIC); |
| 292 | wpabuf_put_be24(extra, OUI_WFA); |
| 293 | wpabuf_put_u8(extra, HS20_ANQP_OUI_TYPE); |
| 294 | wpabuf_put_u8(extra, HS20_STYPE_QUERY_LIST); |
| 295 | wpabuf_put_u8(extra, 0); /* Reserved */ |
| 296 | wpabuf_put_u8(extra, HS20_STYPE_CAPABILITY_LIST); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 297 | if (all) |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 298 | wpabuf_put_u8(extra, |
| 299 | HS20_STYPE_OPERATOR_FRIENDLY_NAME); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 300 | if (all || cred_with_min_backhaul(wpa_s)) |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 301 | wpabuf_put_u8(extra, HS20_STYPE_WAN_METRICS); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 302 | if (all || cred_with_conn_capab(wpa_s)) |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 303 | wpabuf_put_u8(extra, HS20_STYPE_CONNECTION_CAPABILITY); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 304 | if (all) |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 305 | wpabuf_put_u8(extra, HS20_STYPE_OPERATING_CLASS); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 306 | if (all) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 307 | wpabuf_put_u8(extra, HS20_STYPE_OSU_PROVIDERS_LIST); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 308 | wpabuf_put_u8(extra, HS20_STYPE_OSU_PROVIDERS_NAI_LIST); |
| 309 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 310 | gas_anqp_set_element_len(extra, len_pos); |
| 311 | } |
| 312 | #endif /* CONFIG_HS20 */ |
| 313 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 314 | buf = anqp_build_req(info_ids, num_info_ids, extra); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 315 | wpabuf_free(extra); |
| 316 | if (buf == NULL) |
| 317 | return -1; |
| 318 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 319 | res = gas_query_req(wpa_s->gas, bss->bssid, bss->freq, 0, 0, buf, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 320 | interworking_anqp_resp_cb, wpa_s); |
| 321 | if (res < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 322 | wpa_msg(wpa_s, MSG_DEBUG, "ANQP: Failed to send Query Request"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 323 | wpabuf_free(buf); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 324 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 325 | eloop_register_timeout(0, 0, interworking_continue_anqp, wpa_s, |
| 326 | NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 327 | } else |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 328 | wpa_msg(wpa_s, MSG_DEBUG, |
| 329 | "ANQP: Query started with dialog token %u", res); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 330 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | |
| 335 | struct nai_realm_eap { |
| 336 | u8 method; |
| 337 | u8 inner_method; |
| 338 | enum nai_realm_eap_auth_inner_non_eap inner_non_eap; |
| 339 | u8 cred_type; |
| 340 | u8 tunneled_cred_type; |
| 341 | }; |
| 342 | |
| 343 | struct nai_realm { |
| 344 | u8 encoding; |
| 345 | char *realm; |
| 346 | u8 eap_count; |
| 347 | struct nai_realm_eap *eap; |
| 348 | }; |
| 349 | |
| 350 | |
| 351 | static void nai_realm_free(struct nai_realm *realms, u16 count) |
| 352 | { |
| 353 | u16 i; |
| 354 | |
| 355 | if (realms == NULL) |
| 356 | return; |
| 357 | for (i = 0; i < count; i++) { |
| 358 | os_free(realms[i].eap); |
| 359 | os_free(realms[i].realm); |
| 360 | } |
| 361 | os_free(realms); |
| 362 | } |
| 363 | |
| 364 | |
| 365 | static const u8 * nai_realm_parse_eap(struct nai_realm_eap *e, const u8 *pos, |
| 366 | const u8 *end) |
| 367 | { |
| 368 | u8 elen, auth_count, a; |
| 369 | const u8 *e_end; |
| 370 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 371 | if (end - pos < 3) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 372 | wpa_printf(MSG_DEBUG, "No room for EAP Method fixed fields"); |
| 373 | return NULL; |
| 374 | } |
| 375 | |
| 376 | elen = *pos++; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 377 | if (elen > end - pos || elen < 2) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 378 | wpa_printf(MSG_DEBUG, "No room for EAP Method subfield"); |
| 379 | return NULL; |
| 380 | } |
| 381 | e_end = pos + elen; |
| 382 | e->method = *pos++; |
| 383 | auth_count = *pos++; |
| 384 | wpa_printf(MSG_DEBUG, "EAP Method: len=%u method=%u auth_count=%u", |
| 385 | elen, e->method, auth_count); |
| 386 | |
| 387 | for (a = 0; a < auth_count; a++) { |
| 388 | u8 id, len; |
| 389 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 390 | if (end - pos < 2) { |
| 391 | wpa_printf(MSG_DEBUG, |
| 392 | "No room for Authentication Parameter subfield header"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 393 | return NULL; |
| 394 | } |
| 395 | |
| 396 | id = *pos++; |
| 397 | len = *pos++; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 398 | if (len > end - pos) { |
| 399 | wpa_printf(MSG_DEBUG, |
| 400 | "No room for Authentication Parameter subfield"); |
| 401 | return NULL; |
| 402 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 403 | |
| 404 | switch (id) { |
| 405 | case NAI_REALM_EAP_AUTH_NON_EAP_INNER_AUTH: |
| 406 | if (len < 1) |
| 407 | break; |
| 408 | e->inner_non_eap = *pos; |
| 409 | if (e->method != EAP_TYPE_TTLS) |
| 410 | break; |
| 411 | switch (*pos) { |
| 412 | case NAI_REALM_INNER_NON_EAP_PAP: |
| 413 | wpa_printf(MSG_DEBUG, "EAP-TTLS/PAP"); |
| 414 | break; |
| 415 | case NAI_REALM_INNER_NON_EAP_CHAP: |
| 416 | wpa_printf(MSG_DEBUG, "EAP-TTLS/CHAP"); |
| 417 | break; |
| 418 | case NAI_REALM_INNER_NON_EAP_MSCHAP: |
| 419 | wpa_printf(MSG_DEBUG, "EAP-TTLS/MSCHAP"); |
| 420 | break; |
| 421 | case NAI_REALM_INNER_NON_EAP_MSCHAPV2: |
| 422 | wpa_printf(MSG_DEBUG, "EAP-TTLS/MSCHAPV2"); |
| 423 | break; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 424 | default: |
| 425 | wpa_printf(MSG_DEBUG, |
| 426 | "Unsupported EAP-TTLS inner method %u", |
| 427 | *pos); |
| 428 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 429 | } |
| 430 | break; |
| 431 | case NAI_REALM_EAP_AUTH_INNER_AUTH_EAP_METHOD: |
| 432 | if (len < 1) |
| 433 | break; |
| 434 | e->inner_method = *pos; |
| 435 | wpa_printf(MSG_DEBUG, "Inner EAP method: %u", |
| 436 | e->inner_method); |
| 437 | break; |
| 438 | case NAI_REALM_EAP_AUTH_CRED_TYPE: |
| 439 | if (len < 1) |
| 440 | break; |
| 441 | e->cred_type = *pos; |
| 442 | wpa_printf(MSG_DEBUG, "Credential Type: %u", |
| 443 | e->cred_type); |
| 444 | break; |
| 445 | case NAI_REALM_EAP_AUTH_TUNNELED_CRED_TYPE: |
| 446 | if (len < 1) |
| 447 | break; |
| 448 | e->tunneled_cred_type = *pos; |
| 449 | wpa_printf(MSG_DEBUG, "Tunneled EAP Method Credential " |
| 450 | "Type: %u", e->tunneled_cred_type); |
| 451 | break; |
| 452 | default: |
| 453 | wpa_printf(MSG_DEBUG, "Unsupported Authentication " |
| 454 | "Parameter: id=%u len=%u", id, len); |
| 455 | wpa_hexdump(MSG_DEBUG, "Authentication Parameter " |
| 456 | "Value", pos, len); |
| 457 | break; |
| 458 | } |
| 459 | |
| 460 | pos += len; |
| 461 | } |
| 462 | |
| 463 | return e_end; |
| 464 | } |
| 465 | |
| 466 | |
| 467 | static const u8 * nai_realm_parse_realm(struct nai_realm *r, const u8 *pos, |
| 468 | const u8 *end) |
| 469 | { |
| 470 | u16 len; |
| 471 | const u8 *f_end; |
| 472 | u8 realm_len, e; |
| 473 | |
| 474 | if (end - pos < 4) { |
| 475 | wpa_printf(MSG_DEBUG, "No room for NAI Realm Data " |
| 476 | "fixed fields"); |
| 477 | return NULL; |
| 478 | } |
| 479 | |
| 480 | len = WPA_GET_LE16(pos); /* NAI Realm Data field Length */ |
| 481 | pos += 2; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 482 | if (len > end - pos || len < 3) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 483 | wpa_printf(MSG_DEBUG, "No room for NAI Realm Data " |
| 484 | "(len=%u; left=%u)", |
| 485 | len, (unsigned int) (end - pos)); |
| 486 | return NULL; |
| 487 | } |
| 488 | f_end = pos + len; |
| 489 | |
| 490 | r->encoding = *pos++; |
| 491 | realm_len = *pos++; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 492 | if (realm_len > f_end - pos) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 493 | wpa_printf(MSG_DEBUG, "No room for NAI Realm " |
| 494 | "(len=%u; left=%u)", |
| 495 | realm_len, (unsigned int) (f_end - pos)); |
| 496 | return NULL; |
| 497 | } |
| 498 | wpa_hexdump_ascii(MSG_DEBUG, "NAI Realm", pos, realm_len); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 499 | r->realm = dup_binstr(pos, realm_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 500 | if (r->realm == NULL) |
| 501 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 502 | pos += realm_len; |
| 503 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 504 | if (f_end - pos < 1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 505 | wpa_printf(MSG_DEBUG, "No room for EAP Method Count"); |
| 506 | return NULL; |
| 507 | } |
| 508 | r->eap_count = *pos++; |
| 509 | wpa_printf(MSG_DEBUG, "EAP Count: %u", r->eap_count); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 510 | if (r->eap_count * 3 > f_end - pos) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 511 | wpa_printf(MSG_DEBUG, "No room for EAP Methods"); |
| 512 | return NULL; |
| 513 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 514 | r->eap = os_calloc(r->eap_count, sizeof(struct nai_realm_eap)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 515 | if (r->eap == NULL) |
| 516 | return NULL; |
| 517 | |
| 518 | for (e = 0; e < r->eap_count; e++) { |
| 519 | pos = nai_realm_parse_eap(&r->eap[e], pos, f_end); |
| 520 | if (pos == NULL) |
| 521 | return NULL; |
| 522 | } |
| 523 | |
| 524 | return f_end; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | static struct nai_realm * nai_realm_parse(struct wpabuf *anqp, u16 *count) |
| 529 | { |
| 530 | struct nai_realm *realm; |
| 531 | const u8 *pos, *end; |
| 532 | u16 i, num; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 533 | size_t left; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 534 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 535 | if (anqp == NULL) |
| 536 | return NULL; |
| 537 | left = wpabuf_len(anqp); |
| 538 | if (left < 2) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 539 | return NULL; |
| 540 | |
| 541 | pos = wpabuf_head_u8(anqp); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 542 | end = pos + left; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 543 | num = WPA_GET_LE16(pos); |
| 544 | wpa_printf(MSG_DEBUG, "NAI Realm Count: %u", num); |
| 545 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 546 | left -= 2; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 547 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 548 | if (num > left / 5) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 549 | wpa_printf(MSG_DEBUG, "Invalid NAI Realm Count %u - not " |
| 550 | "enough data (%u octets) for that many realms", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 551 | num, (unsigned int) left); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 552 | return NULL; |
| 553 | } |
| 554 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 555 | realm = os_calloc(num, sizeof(struct nai_realm)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 556 | if (realm == NULL) |
| 557 | return NULL; |
| 558 | |
| 559 | for (i = 0; i < num; i++) { |
| 560 | pos = nai_realm_parse_realm(&realm[i], pos, end); |
| 561 | if (pos == NULL) { |
| 562 | nai_realm_free(realm, num); |
| 563 | return NULL; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | *count = num; |
| 568 | return realm; |
| 569 | } |
| 570 | |
| 571 | |
| 572 | static int nai_realm_match(struct nai_realm *realm, const char *home_realm) |
| 573 | { |
| 574 | char *tmp, *pos, *end; |
| 575 | int match = 0; |
| 576 | |
| 577 | if (realm->realm == NULL || home_realm == NULL) |
| 578 | return 0; |
| 579 | |
| 580 | if (os_strchr(realm->realm, ';') == NULL) |
| 581 | return os_strcasecmp(realm->realm, home_realm) == 0; |
| 582 | |
| 583 | tmp = os_strdup(realm->realm); |
| 584 | if (tmp == NULL) |
| 585 | return 0; |
| 586 | |
| 587 | pos = tmp; |
| 588 | while (*pos) { |
| 589 | end = os_strchr(pos, ';'); |
| 590 | if (end) |
| 591 | *end = '\0'; |
| 592 | if (os_strcasecmp(pos, home_realm) == 0) { |
| 593 | match = 1; |
| 594 | break; |
| 595 | } |
| 596 | if (end == NULL) |
| 597 | break; |
| 598 | pos = end + 1; |
| 599 | } |
| 600 | |
| 601 | os_free(tmp); |
| 602 | |
| 603 | return match; |
| 604 | } |
| 605 | |
| 606 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 607 | static int nai_realm_cred_username(struct wpa_supplicant *wpa_s, |
| 608 | struct nai_realm_eap *eap) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 609 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 610 | if (eap_get_name(EAP_VENDOR_IETF, eap->method) == NULL) { |
| 611 | wpa_msg(wpa_s, MSG_DEBUG, |
| 612 | "nai-realm-cred-username: EAP method not supported: %d", |
| 613 | eap->method); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 614 | return 0; /* method not supported */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 615 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 616 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 617 | if (eap->method != EAP_TYPE_TTLS && eap->method != EAP_TYPE_PEAP && |
| 618 | eap->method != EAP_TYPE_FAST) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 619 | /* Only tunneled methods with username/password supported */ |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 620 | wpa_msg(wpa_s, MSG_DEBUG, |
| 621 | "nai-realm-cred-username: Method: %d is not TTLS, PEAP, or FAST", |
| 622 | eap->method); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 623 | return 0; |
| 624 | } |
| 625 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 626 | if (eap->method == EAP_TYPE_PEAP || eap->method == EAP_TYPE_FAST) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 627 | if (eap->inner_method && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 628 | eap_get_name(EAP_VENDOR_IETF, eap->inner_method) == NULL) { |
| 629 | wpa_msg(wpa_s, MSG_DEBUG, |
| 630 | "nai-realm-cred-username: PEAP/FAST: Inner method not supported: %d", |
| 631 | eap->inner_method); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 632 | return 0; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 633 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 634 | if (!eap->inner_method && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 635 | eap_get_name(EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2) == NULL) { |
| 636 | wpa_msg(wpa_s, MSG_DEBUG, |
| 637 | "nai-realm-cred-username: MSCHAPv2 not supported"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 638 | return 0; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 639 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 640 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 641 | |
| 642 | if (eap->method == EAP_TYPE_TTLS) { |
| 643 | if (eap->inner_method == 0 && eap->inner_non_eap == 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 644 | return 1; /* Assume TTLS/MSCHAPv2 is used */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 645 | if (eap->inner_method && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 646 | eap_get_name(EAP_VENDOR_IETF, eap->inner_method) == NULL) { |
| 647 | wpa_msg(wpa_s, MSG_DEBUG, |
| 648 | "nai-realm-cred-username: TTLS, but inner not supported: %d", |
| 649 | eap->inner_method); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 650 | return 0; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 651 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 652 | if (eap->inner_non_eap && |
| 653 | eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_PAP && |
| 654 | eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_CHAP && |
| 655 | eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_MSCHAP && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 656 | eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_MSCHAPV2) { |
| 657 | wpa_msg(wpa_s, MSG_DEBUG, |
| 658 | "nai-realm-cred-username: TTLS, inner-non-eap not supported: %d", |
| 659 | eap->inner_non_eap); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 660 | return 0; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 661 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | if (eap->inner_method && |
| 665 | eap->inner_method != EAP_TYPE_GTC && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 666 | eap->inner_method != EAP_TYPE_MSCHAPV2) { |
| 667 | wpa_msg(wpa_s, MSG_DEBUG, |
| 668 | "nai-realm-cred-username: inner-method not GTC or MSCHAPv2: %d", |
| 669 | eap->inner_method); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | return 1; |
| 674 | } |
| 675 | |
| 676 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 677 | static int nai_realm_cred_cert(struct wpa_supplicant *wpa_s, |
| 678 | struct nai_realm_eap *eap) |
| 679 | { |
| 680 | if (eap_get_name(EAP_VENDOR_IETF, eap->method) == NULL) { |
| 681 | wpa_msg(wpa_s, MSG_DEBUG, |
| 682 | "nai-realm-cred-cert: Method not supported: %d", |
| 683 | eap->method); |
| 684 | return 0; /* method not supported */ |
| 685 | } |
| 686 | |
| 687 | if (eap->method != EAP_TYPE_TLS) { |
| 688 | /* Only EAP-TLS supported for credential authentication */ |
| 689 | wpa_msg(wpa_s, MSG_DEBUG, |
| 690 | "nai-realm-cred-cert: Method not TLS: %d", |
| 691 | eap->method); |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | return 1; |
| 696 | } |
| 697 | |
| 698 | |
| 699 | static struct nai_realm_eap * nai_realm_find_eap(struct wpa_supplicant *wpa_s, |
| 700 | struct wpa_cred *cred, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 701 | struct nai_realm *realm) |
| 702 | { |
| 703 | u8 e; |
| 704 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 705 | if (cred->username == NULL || |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 706 | cred->username[0] == '\0' || |
| 707 | ((cred->password == NULL || |
| 708 | cred->password[0] == '\0') && |
| 709 | (cred->private_key == NULL || |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 710 | cred->private_key[0] == '\0') && |
| 711 | (!cred->key_id || cred->key_id[0] == '\0'))) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 712 | wpa_msg(wpa_s, MSG_DEBUG, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 713 | "nai-realm-find-eap: incomplete cred info: username: %s password: %s private_key: %s key_id: %s", |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 714 | cred->username ? cred->username : "NULL", |
| 715 | cred->password ? cred->password : "NULL", |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 716 | cred->private_key ? cred->private_key : "NULL", |
| 717 | cred->key_id ? cred->key_id : "NULL"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 718 | return NULL; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 719 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 720 | |
| 721 | for (e = 0; e < realm->eap_count; e++) { |
| 722 | struct nai_realm_eap *eap = &realm->eap[e]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 723 | if (cred->password && cred->password[0] && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 724 | nai_realm_cred_username(wpa_s, eap)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 725 | return eap; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 726 | if (((cred->private_key && cred->private_key[0]) || |
| 727 | (cred->key_id && cred->key_id[0])) && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 728 | nai_realm_cred_cert(wpa_s, eap)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 729 | return eap; |
| 730 | } |
| 731 | |
| 732 | return NULL; |
| 733 | } |
| 734 | |
| 735 | |
| 736 | #ifdef INTERWORKING_3GPP |
| 737 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 738 | static int plmn_id_match(struct wpabuf *anqp, const char *imsi, int mnc_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 739 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 740 | u8 plmn[3], plmn2[3]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 741 | const u8 *pos, *end; |
| 742 | u8 udhl; |
| 743 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 744 | /* |
| 745 | * See Annex A of 3GPP TS 24.234 v8.1.0 for description. The network |
| 746 | * operator is allowed to include only two digits of the MNC, so allow |
| 747 | * matches based on both two and three digit MNC assumptions. Since some |
| 748 | * SIM/USIM cards may not expose MNC length conveniently, we may be |
| 749 | * provided the default MNC length 3 here and as such, checking with MNC |
| 750 | * length 2 is justifiable even though 3GPP TS 24.234 does not mention |
| 751 | * that case. Anyway, MCC/MNC pair where both 2 and 3 digit MNC is used |
| 752 | * with otherwise matching values would not be good idea in general, so |
| 753 | * this should not result in selecting incorrect networks. |
| 754 | */ |
| 755 | /* Match with 3 digit MNC */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 756 | plmn[0] = (imsi[0] - '0') | ((imsi[1] - '0') << 4); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 757 | plmn[1] = (imsi[2] - '0') | ((imsi[5] - '0') << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 758 | plmn[2] = (imsi[3] - '0') | ((imsi[4] - '0') << 4); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 759 | /* Match with 2 digit MNC */ |
| 760 | plmn2[0] = (imsi[0] - '0') | ((imsi[1] - '0') << 4); |
| 761 | plmn2[1] = (imsi[2] - '0') | 0xf0; |
| 762 | plmn2[2] = (imsi[3] - '0') | ((imsi[4] - '0') << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 763 | |
| 764 | if (anqp == NULL) |
| 765 | return 0; |
| 766 | pos = wpabuf_head_u8(anqp); |
| 767 | end = pos + wpabuf_len(anqp); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 768 | if (end - pos < 2) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 769 | return 0; |
| 770 | if (*pos != 0) { |
| 771 | wpa_printf(MSG_DEBUG, "Unsupported GUD version 0x%x", *pos); |
| 772 | return 0; |
| 773 | } |
| 774 | pos++; |
| 775 | udhl = *pos++; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 776 | if (udhl > end - pos) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 777 | wpa_printf(MSG_DEBUG, "Invalid UDHL"); |
| 778 | return 0; |
| 779 | } |
| 780 | end = pos + udhl; |
| 781 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 782 | wpa_printf(MSG_DEBUG, "Interworking: Matching against MCC/MNC alternatives: %02x:%02x:%02x or %02x:%02x:%02x (IMSI %s, MNC length %d)", |
| 783 | plmn[0], plmn[1], plmn[2], plmn2[0], plmn2[1], plmn2[2], |
| 784 | imsi, mnc_len); |
| 785 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 786 | while (end - pos >= 2) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 787 | u8 iei, len; |
| 788 | const u8 *l_end; |
| 789 | iei = *pos++; |
| 790 | len = *pos++ & 0x7f; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 791 | if (len > end - pos) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 792 | break; |
| 793 | l_end = pos + len; |
| 794 | |
| 795 | if (iei == 0 && len > 0) { |
| 796 | /* PLMN List */ |
| 797 | u8 num, i; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 798 | wpa_hexdump(MSG_DEBUG, "Interworking: PLMN List information element", |
| 799 | pos, len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 800 | num = *pos++; |
| 801 | for (i = 0; i < num; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 802 | if (l_end - pos < 3) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 803 | break; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 804 | if (os_memcmp(pos, plmn, 3) == 0 || |
| 805 | os_memcmp(pos, plmn2, 3) == 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 806 | return 1; /* Found matching PLMN */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 807 | pos += 3; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 808 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 809 | } else { |
| 810 | wpa_hexdump(MSG_DEBUG, "Interworking: Unrecognized 3GPP information element", |
| 811 | pos, len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | pos = l_end; |
| 815 | } |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 821 | static int build_root_nai(char *nai, size_t nai_len, const char *imsi, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 822 | size_t mnc_len, char prefix) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 823 | { |
| 824 | const char *sep, *msin; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 825 | char *end, *pos; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 826 | size_t msin_len, plmn_len; |
| 827 | |
| 828 | /* |
| 829 | * TS 23.003, Clause 14 (3GPP to WLAN Interworking) |
| 830 | * Root NAI: |
| 831 | * <aka:0|sim:1><IMSI>@wlan.mnc<MNC>.mcc<MCC>.3gppnetwork.org |
| 832 | * <MNC> is zero-padded to three digits in case two-digit MNC is used |
| 833 | */ |
| 834 | |
| 835 | if (imsi == NULL || os_strlen(imsi) > 16) { |
| 836 | wpa_printf(MSG_DEBUG, "No valid IMSI available"); |
| 837 | return -1; |
| 838 | } |
| 839 | sep = os_strchr(imsi, '-'); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 840 | if (sep) { |
| 841 | plmn_len = sep - imsi; |
| 842 | msin = sep + 1; |
| 843 | } else if (mnc_len && os_strlen(imsi) >= 3 + mnc_len) { |
| 844 | plmn_len = 3 + mnc_len; |
| 845 | msin = imsi + plmn_len; |
| 846 | } else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 847 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 848 | if (plmn_len != 5 && plmn_len != 6) |
| 849 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 850 | msin_len = os_strlen(msin); |
| 851 | |
| 852 | pos = nai; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 853 | end = nai + nai_len; |
| 854 | if (prefix) |
| 855 | *pos++ = prefix; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 856 | os_memcpy(pos, imsi, plmn_len); |
| 857 | pos += plmn_len; |
| 858 | os_memcpy(pos, msin, msin_len); |
| 859 | pos += msin_len; |
| 860 | pos += os_snprintf(pos, end - pos, "@wlan.mnc"); |
| 861 | if (plmn_len == 5) { |
| 862 | *pos++ = '0'; |
| 863 | *pos++ = imsi[3]; |
| 864 | *pos++ = imsi[4]; |
| 865 | } else { |
| 866 | *pos++ = imsi[3]; |
| 867 | *pos++ = imsi[4]; |
| 868 | *pos++ = imsi[5]; |
| 869 | } |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 870 | os_snprintf(pos, end - pos, ".mcc%c%c%c.3gppnetwork.org", |
| 871 | imsi[0], imsi[1], imsi[2]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 872 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | |
| 877 | static int set_root_nai(struct wpa_ssid *ssid, const char *imsi, char prefix) |
| 878 | { |
| 879 | char nai[100]; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 880 | if (build_root_nai(nai, sizeof(nai), imsi, 0, prefix) < 0) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 881 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 882 | return wpa_config_set_quoted(ssid, "identity", nai); |
| 883 | } |
| 884 | |
| 885 | #endif /* INTERWORKING_3GPP */ |
| 886 | |
| 887 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 888 | static int already_connected(struct wpa_supplicant *wpa_s, |
| 889 | struct wpa_cred *cred, struct wpa_bss *bss) |
| 890 | { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 891 | struct wpa_ssid *ssid, *sel_ssid; |
| 892 | struct wpa_bss *selected; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 893 | |
| 894 | if (wpa_s->wpa_state < WPA_ASSOCIATED || wpa_s->current_ssid == NULL) |
| 895 | return 0; |
| 896 | |
| 897 | ssid = wpa_s->current_ssid; |
| 898 | if (ssid->parent_cred != cred) |
| 899 | return 0; |
| 900 | |
| 901 | if (ssid->ssid_len != bss->ssid_len || |
| 902 | os_memcmp(ssid->ssid, bss->ssid, bss->ssid_len) != 0) |
| 903 | return 0; |
| 904 | |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 905 | sel_ssid = NULL; |
| 906 | selected = wpa_supplicant_pick_network(wpa_s, &sel_ssid); |
| 907 | if (selected && sel_ssid && sel_ssid->priority > ssid->priority) |
| 908 | return 0; /* higher priority network in scan results */ |
| 909 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 910 | return 1; |
| 911 | } |
| 912 | |
| 913 | |
| 914 | static void remove_duplicate_network(struct wpa_supplicant *wpa_s, |
| 915 | struct wpa_cred *cred, |
| 916 | struct wpa_bss *bss) |
| 917 | { |
| 918 | struct wpa_ssid *ssid; |
| 919 | |
| 920 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 921 | if (ssid->parent_cred != cred) |
| 922 | continue; |
| 923 | if (ssid->ssid_len != bss->ssid_len || |
| 924 | os_memcmp(ssid->ssid, bss->ssid, bss->ssid_len) != 0) |
| 925 | continue; |
| 926 | |
| 927 | break; |
| 928 | } |
| 929 | |
| 930 | if (ssid == NULL) |
| 931 | return; |
| 932 | |
| 933 | wpa_printf(MSG_DEBUG, "Interworking: Remove duplicate network entry for the same credential"); |
| 934 | |
| 935 | if (ssid == wpa_s->current_ssid) { |
| 936 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 937 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 938 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 939 | wpa_supplicant_deauthenticate(wpa_s, |
| 940 | WLAN_REASON_DEAUTH_LEAVING); |
| 941 | } |
| 942 | |
| 943 | wpas_notify_network_removed(wpa_s, ssid); |
| 944 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 945 | } |
| 946 | |
| 947 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 948 | static int interworking_set_hs20_params(struct wpa_supplicant *wpa_s, |
| 949 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 950 | { |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 951 | const char *key_mgmt = NULL; |
| 952 | #ifdef CONFIG_IEEE80211R |
| 953 | int res; |
| 954 | struct wpa_driver_capa capa; |
| 955 | |
| 956 | res = wpa_drv_get_capa(wpa_s, &capa); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 957 | if (res == 0 && capa.key_mgmt_iftype[WPA_IF_STATION] & |
| 958 | WPA_DRIVER_CAPA_KEY_MGMT_FT) { |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 959 | key_mgmt = wpa_s->conf->pmf != NO_MGMT_FRAME_PROTECTION ? |
| 960 | "WPA-EAP WPA-EAP-SHA256 FT-EAP" : |
| 961 | "WPA-EAP FT-EAP"; |
| 962 | } |
| 963 | #endif /* CONFIG_IEEE80211R */ |
| 964 | |
| 965 | if (!key_mgmt) |
| 966 | key_mgmt = wpa_s->conf->pmf != NO_MGMT_FRAME_PROTECTION ? |
| 967 | "WPA-EAP WPA-EAP-SHA256" : "WPA-EAP"; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 968 | if (wpa_config_set(ssid, "key_mgmt", key_mgmt, 0) < 0 || |
| 969 | wpa_config_set(ssid, "proto", "RSN", 0) < 0 || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 970 | wpa_config_set(ssid, "ieee80211w", |
| 971 | wpa_s->conf->pmf == MGMT_FRAME_PROTECTION_REQUIRED ? |
| 972 | "2" : "1", 0) < 0 || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 973 | wpa_config_set(ssid, "pairwise", "CCMP", 0) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 974 | return -1; |
| 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 979 | static int interworking_connect_3gpp(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 980 | struct wpa_cred *cred, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 981 | struct wpa_bss *bss, int only_add) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 982 | { |
| 983 | #ifdef INTERWORKING_3GPP |
| 984 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 985 | int eap_type; |
| 986 | int res; |
| 987 | char prefix; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 988 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 989 | if (bss->anqp == NULL || bss->anqp->anqp_3gpp == NULL) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 990 | return -1; |
| 991 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 992 | wpa_msg(wpa_s, MSG_DEBUG, "Interworking: Connect with " MACSTR |
| 993 | " (3GPP)", MAC2STR(bss->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 994 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 995 | if (already_connected(wpa_s, cred, bss)) { |
| 996 | wpa_msg(wpa_s, MSG_INFO, INTERWORKING_ALREADY_CONNECTED MACSTR, |
| 997 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 998 | return wpa_s->current_ssid->id; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | remove_duplicate_network(wpa_s, cred, bss); |
| 1002 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1003 | ssid = wpa_config_add_network(wpa_s->conf); |
| 1004 | if (ssid == NULL) |
| 1005 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1006 | ssid->parent_cred = cred; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1007 | |
| 1008 | wpas_notify_network_added(wpa_s, ssid); |
| 1009 | wpa_config_set_network_defaults(ssid); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1010 | ssid->priority = cred->priority; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1011 | ssid->temporary = 1; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1012 | ssid->ssid = os_zalloc(bss->ssid_len + 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1013 | if (ssid->ssid == NULL) |
| 1014 | goto fail; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1015 | os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len); |
| 1016 | ssid->ssid_len = bss->ssid_len; |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 1017 | ssid->eap.sim_num = cred->sim_num; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1018 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1019 | if (interworking_set_hs20_params(wpa_s, ssid) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1020 | goto fail; |
| 1021 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1022 | eap_type = EAP_TYPE_SIM; |
| 1023 | if (cred->pcsc && wpa_s->scard && scard_supports_umts(wpa_s->scard)) |
| 1024 | eap_type = EAP_TYPE_AKA; |
| 1025 | if (cred->eap_method && cred->eap_method[0].vendor == EAP_VENDOR_IETF) { |
| 1026 | if (cred->eap_method[0].method == EAP_TYPE_SIM || |
| 1027 | cred->eap_method[0].method == EAP_TYPE_AKA || |
| 1028 | cred->eap_method[0].method == EAP_TYPE_AKA_PRIME) |
| 1029 | eap_type = cred->eap_method[0].method; |
| 1030 | } |
| 1031 | |
| 1032 | switch (eap_type) { |
| 1033 | case EAP_TYPE_SIM: |
| 1034 | prefix = '1'; |
| 1035 | res = wpa_config_set(ssid, "eap", "SIM", 0); |
| 1036 | break; |
| 1037 | case EAP_TYPE_AKA: |
| 1038 | prefix = '0'; |
| 1039 | res = wpa_config_set(ssid, "eap", "AKA", 0); |
| 1040 | break; |
| 1041 | case EAP_TYPE_AKA_PRIME: |
| 1042 | prefix = '6'; |
| 1043 | res = wpa_config_set(ssid, "eap", "AKA'", 0); |
| 1044 | break; |
| 1045 | default: |
| 1046 | res = -1; |
| 1047 | break; |
| 1048 | } |
| 1049 | if (res < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1050 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1051 | "Selected EAP method (%d) not supported", eap_type); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1052 | goto fail; |
| 1053 | } |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1054 | |
| 1055 | if (!cred->pcsc && set_root_nai(ssid, cred->imsi, prefix) < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1056 | wpa_msg(wpa_s, MSG_DEBUG, "Failed to set Root NAI"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1057 | goto fail; |
| 1058 | } |
| 1059 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1060 | if (cred->milenage && cred->milenage[0]) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1061 | if (wpa_config_set_quoted(ssid, "password", |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1062 | cred->milenage) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1063 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1064 | } else if (cred->pcsc) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1065 | if (wpa_config_set_quoted(ssid, "pcsc", "") < 0) |
| 1066 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1067 | if (wpa_s->conf->pcsc_pin && |
| 1068 | wpa_config_set_quoted(ssid, "pin", wpa_s->conf->pcsc_pin) |
| 1069 | < 0) |
| 1070 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1073 | if (cred->imsi_privacy_cert && cred->imsi_privacy_cert[0]) { |
| 1074 | if (wpa_config_set_quoted(ssid, "imsi_privacy_cert", |
| 1075 | cred->imsi_privacy_cert) < 0) |
| 1076 | goto fail; |
| 1077 | } |
| 1078 | |
| 1079 | if (cred->imsi_privacy_attr && cred->imsi_privacy_attr[0]) { |
| 1080 | if (wpa_config_set_quoted(ssid, "imsi_privacy_attr", |
| 1081 | cred->imsi_privacy_attr) < 0) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1082 | goto fail; |
| 1083 | } |
| 1084 | |
Steven Liu | 9138d43 | 2022-11-23 22:29:05 +0000 | [diff] [blame] | 1085 | if (cred->strict_conservative_peer_mode) { |
| 1086 | if (wpa_config_set_quoted(ssid, "strict_conservative_peer_mode", |
| 1087 | "1") < 0) |
| 1088 | goto fail; |
| 1089 | } |
| 1090 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1091 | wpa_s->next_ssid = ssid; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1092 | wpa_config_update_prio_list(wpa_s->conf); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1093 | if (!only_add) |
| 1094 | interworking_reconnect(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1095 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1096 | return ssid->id; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1097 | |
| 1098 | fail: |
| 1099 | wpas_notify_network_removed(wpa_s, ssid); |
| 1100 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 1101 | #endif /* INTERWORKING_3GPP */ |
| 1102 | return -1; |
| 1103 | } |
| 1104 | |
| 1105 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1106 | static int oi_element_match(const u8 *ie, const u8 *oi, size_t oi_len) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1107 | { |
| 1108 | const u8 *pos, *end; |
| 1109 | u8 lens; |
| 1110 | |
| 1111 | if (ie == NULL) |
| 1112 | return 0; |
| 1113 | |
| 1114 | pos = ie + 2; |
| 1115 | end = ie + 2 + ie[1]; |
| 1116 | |
| 1117 | /* Roaming Consortium element: |
| 1118 | * Number of ANQP OIs |
| 1119 | * OI #1 and #2 lengths |
| 1120 | * OI #1, [OI #2], [OI #3] |
| 1121 | */ |
| 1122 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1123 | if (end - pos < 2) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1124 | return 0; |
| 1125 | |
| 1126 | pos++; /* skip Number of ANQP OIs */ |
| 1127 | lens = *pos++; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1128 | if ((lens & 0x0f) + (lens >> 4) > end - pos) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1129 | return 0; |
| 1130 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1131 | if ((lens & 0x0f) == oi_len && os_memcmp(pos, oi, oi_len) == 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1132 | return 1; |
| 1133 | pos += lens & 0x0f; |
| 1134 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1135 | if ((lens >> 4) == oi_len && os_memcmp(pos, oi, oi_len) == 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1136 | return 1; |
| 1137 | pos += lens >> 4; |
| 1138 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1139 | if (pos < end && (size_t) (end - pos) == oi_len && |
| 1140 | os_memcmp(pos, oi, oi_len) == 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1141 | return 1; |
| 1142 | |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
| 1146 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1147 | static int oi_anqp_match(const struct wpabuf *anqp, const u8 *oi, |
| 1148 | size_t oi_len) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1149 | { |
| 1150 | const u8 *pos, *end; |
| 1151 | u8 len; |
| 1152 | |
| 1153 | if (anqp == NULL) |
| 1154 | return 0; |
| 1155 | |
| 1156 | pos = wpabuf_head(anqp); |
| 1157 | end = pos + wpabuf_len(anqp); |
| 1158 | |
| 1159 | /* Set of <OI Length, OI> duples */ |
| 1160 | while (pos < end) { |
| 1161 | len = *pos++; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1162 | if (len > end - pos) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1163 | break; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1164 | if (len == oi_len && os_memcmp(pos, oi, oi_len) == 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1165 | return 1; |
| 1166 | pos += len; |
| 1167 | } |
| 1168 | |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1173 | static int oi_match(const u8 *ie, const struct wpabuf *anqp, |
| 1174 | const u8 *oi, size_t oi_len) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1175 | { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1176 | return oi_element_match(ie, oi, oi_len) || |
| 1177 | oi_anqp_match(anqp, oi, oi_len); |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | static int cred_home_ois_match(const u8 *ie, const struct wpabuf *anqp, |
| 1182 | const struct wpa_cred *cred) { |
| 1183 | unsigned int i; |
| 1184 | |
| 1185 | /* There's a match if at least one of the home OI matches. */ |
| 1186 | for (i = 0; i < cred->num_home_ois; i++) { |
| 1187 | if (oi_match(ie, anqp, cred->home_ois[i], |
| 1188 | cred->home_ois_len[i])) |
| 1189 | return 1; |
| 1190 | } |
| 1191 | |
| 1192 | return 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1196 | static int cred_roaming_consortiums_match(const u8 *ie, |
| 1197 | const struct wpabuf *anqp, |
| 1198 | const struct wpa_cred *cred) |
| 1199 | { |
| 1200 | unsigned int i; |
| 1201 | |
| 1202 | for (i = 0; i < cred->num_roaming_consortiums; i++) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1203 | if (oi_match(ie, anqp, cred->roaming_consortiums[i], |
| 1204 | cred->roaming_consortiums_len[i])) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1205 | return 1; |
| 1206 | } |
| 1207 | |
| 1208 | return 0; |
| 1209 | } |
| 1210 | |
| 1211 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1212 | static int cred_no_required_oi_match(struct wpa_cred *cred, struct wpa_bss *bss) |
| 1213 | { |
| 1214 | const u8 *ie; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1215 | unsigned int i; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1216 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1217 | if (cred->num_required_home_ois == 0) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1218 | return 0; |
| 1219 | |
| 1220 | ie = wpa_bss_get_ie(bss, WLAN_EID_ROAMING_CONSORTIUM); |
| 1221 | |
| 1222 | if (ie == NULL && |
| 1223 | (bss->anqp == NULL || bss->anqp->roaming_consortium == NULL)) |
| 1224 | return 1; |
| 1225 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1226 | /* According to Passpoint specification, there must be a match for |
| 1227 | * each required home OI provided. */ |
| 1228 | for (i = 0; i < cred->num_required_home_ois; i++) { |
| 1229 | if (!oi_match(ie, bss->anqp ? |
| 1230 | bss->anqp->roaming_consortium : NULL, |
| 1231 | cred->required_home_ois[i], |
| 1232 | cred->required_home_ois_len[i])) |
| 1233 | return 1; |
| 1234 | } |
| 1235 | return 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1239 | static int cred_excluded_ssid(struct wpa_cred *cred, struct wpa_bss *bss) |
| 1240 | { |
| 1241 | size_t i; |
| 1242 | |
| 1243 | if (!cred->excluded_ssid) |
| 1244 | return 0; |
| 1245 | |
| 1246 | for (i = 0; i < cred->num_excluded_ssid; i++) { |
| 1247 | struct excluded_ssid *e = &cred->excluded_ssid[i]; |
| 1248 | if (bss->ssid_len == e->ssid_len && |
| 1249 | os_memcmp(bss->ssid, e->ssid, e->ssid_len) == 0) |
| 1250 | return 1; |
| 1251 | } |
| 1252 | |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
| 1256 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1257 | static int cred_below_min_backhaul(struct wpa_supplicant *wpa_s, |
| 1258 | struct wpa_cred *cred, struct wpa_bss *bss) |
| 1259 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1260 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1261 | int res; |
| 1262 | unsigned int dl_bandwidth, ul_bandwidth; |
| 1263 | const u8 *wan; |
| 1264 | u8 wan_info, dl_load, ul_load; |
| 1265 | u16 lmd; |
| 1266 | u32 ul_speed, dl_speed; |
| 1267 | |
| 1268 | if (!cred->min_dl_bandwidth_home && |
| 1269 | !cred->min_ul_bandwidth_home && |
| 1270 | !cred->min_dl_bandwidth_roaming && |
| 1271 | !cred->min_ul_bandwidth_roaming) |
| 1272 | return 0; /* No bandwidth constraint specified */ |
| 1273 | |
| 1274 | if (bss->anqp == NULL || bss->anqp->hs20_wan_metrics == NULL) |
| 1275 | return 0; /* No WAN Metrics known - ignore constraint */ |
| 1276 | |
| 1277 | wan = wpabuf_head(bss->anqp->hs20_wan_metrics); |
| 1278 | wan_info = wan[0]; |
| 1279 | if (wan_info & BIT(3)) |
| 1280 | return 1; /* WAN link at capacity */ |
| 1281 | lmd = WPA_GET_LE16(wan + 11); |
| 1282 | if (lmd == 0) |
| 1283 | return 0; /* Downlink/Uplink Load was not measured */ |
| 1284 | dl_speed = WPA_GET_LE32(wan + 1); |
| 1285 | ul_speed = WPA_GET_LE32(wan + 5); |
| 1286 | dl_load = wan[9]; |
| 1287 | ul_load = wan[10]; |
| 1288 | |
| 1289 | if (dl_speed >= 0xffffff) |
| 1290 | dl_bandwidth = dl_speed / 255 * (255 - dl_load); |
| 1291 | else |
| 1292 | dl_bandwidth = dl_speed * (255 - dl_load) / 255; |
| 1293 | |
| 1294 | if (ul_speed >= 0xffffff) |
| 1295 | ul_bandwidth = ul_speed / 255 * (255 - ul_load); |
| 1296 | else |
| 1297 | ul_bandwidth = ul_speed * (255 - ul_load) / 255; |
| 1298 | |
| 1299 | res = interworking_home_sp_cred(wpa_s, cred, bss->anqp ? |
| 1300 | bss->anqp->domain_name : NULL); |
| 1301 | if (res > 0) { |
| 1302 | if (cred->min_dl_bandwidth_home > dl_bandwidth) |
| 1303 | return 1; |
| 1304 | if (cred->min_ul_bandwidth_home > ul_bandwidth) |
| 1305 | return 1; |
| 1306 | } else { |
| 1307 | if (cred->min_dl_bandwidth_roaming > dl_bandwidth) |
| 1308 | return 1; |
| 1309 | if (cred->min_ul_bandwidth_roaming > ul_bandwidth) |
| 1310 | return 1; |
| 1311 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1312 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1313 | |
| 1314 | return 0; |
| 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | static int cred_over_max_bss_load(struct wpa_supplicant *wpa_s, |
| 1319 | struct wpa_cred *cred, struct wpa_bss *bss) |
| 1320 | { |
| 1321 | const u8 *ie; |
| 1322 | int res; |
| 1323 | |
| 1324 | if (!cred->max_bss_load) |
| 1325 | return 0; /* No BSS Load constraint specified */ |
| 1326 | |
| 1327 | ie = wpa_bss_get_ie(bss, WLAN_EID_BSS_LOAD); |
| 1328 | if (ie == NULL || ie[1] < 3) |
| 1329 | return 0; /* No BSS Load advertised */ |
| 1330 | |
| 1331 | res = interworking_home_sp_cred(wpa_s, cred, bss->anqp ? |
| 1332 | bss->anqp->domain_name : NULL); |
| 1333 | if (res <= 0) |
| 1334 | return 0; /* Not a home network */ |
| 1335 | |
| 1336 | return ie[4] > cred->max_bss_load; |
| 1337 | } |
| 1338 | |
| 1339 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1340 | #ifdef CONFIG_HS20 |
| 1341 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1342 | static int has_proto_match(const u8 *pos, const u8 *end, u8 proto) |
| 1343 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1344 | while (end - pos >= 4) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1345 | if (pos[0] == proto && pos[3] == 1 /* Open */) |
| 1346 | return 1; |
| 1347 | pos += 4; |
| 1348 | } |
| 1349 | |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | static int has_proto_port_match(const u8 *pos, const u8 *end, u8 proto, |
| 1355 | u16 port) |
| 1356 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1357 | while (end - pos >= 4) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1358 | if (pos[0] == proto && WPA_GET_LE16(&pos[1]) == port && |
| 1359 | pos[3] == 1 /* Open */) |
| 1360 | return 1; |
| 1361 | pos += 4; |
| 1362 | } |
| 1363 | |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1367 | #endif /* CONFIG_HS20 */ |
| 1368 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1369 | |
| 1370 | static int cred_conn_capab_missing(struct wpa_supplicant *wpa_s, |
| 1371 | struct wpa_cred *cred, struct wpa_bss *bss) |
| 1372 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1373 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1374 | int res; |
| 1375 | const u8 *capab, *end; |
| 1376 | unsigned int i, j; |
| 1377 | int *ports; |
| 1378 | |
| 1379 | if (!cred->num_req_conn_capab) |
| 1380 | return 0; /* No connection capability constraint specified */ |
| 1381 | |
| 1382 | if (bss->anqp == NULL || bss->anqp->hs20_connection_capability == NULL) |
| 1383 | return 0; /* No Connection Capability known - ignore constraint |
| 1384 | */ |
| 1385 | |
| 1386 | res = interworking_home_sp_cred(wpa_s, cred, bss->anqp ? |
| 1387 | bss->anqp->domain_name : NULL); |
| 1388 | if (res > 0) |
| 1389 | return 0; /* No constraint in home network */ |
| 1390 | |
| 1391 | capab = wpabuf_head(bss->anqp->hs20_connection_capability); |
| 1392 | end = capab + wpabuf_len(bss->anqp->hs20_connection_capability); |
| 1393 | |
| 1394 | for (i = 0; i < cred->num_req_conn_capab; i++) { |
| 1395 | ports = cred->req_conn_capab_port[i]; |
| 1396 | if (!ports) { |
| 1397 | if (!has_proto_match(capab, end, |
| 1398 | cred->req_conn_capab_proto[i])) |
| 1399 | return 1; |
| 1400 | } else { |
| 1401 | for (j = 0; ports[j] > -1; j++) { |
| 1402 | if (!has_proto_port_match( |
| 1403 | capab, end, |
| 1404 | cred->req_conn_capab_proto[i], |
| 1405 | ports[j])) |
| 1406 | return 1; |
| 1407 | } |
| 1408 | } |
| 1409 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1410 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1411 | |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1416 | static struct wpa_cred * interworking_credentials_available_roaming_consortium( |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1417 | struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int ignore_bw, |
| 1418 | int *excluded) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1419 | { |
| 1420 | struct wpa_cred *cred, *selected = NULL; |
| 1421 | const u8 *ie; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1422 | const struct wpabuf *anqp; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1423 | int is_excluded = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1424 | |
| 1425 | ie = wpa_bss_get_ie(bss, WLAN_EID_ROAMING_CONSORTIUM); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1426 | anqp = bss->anqp ? bss->anqp->roaming_consortium : NULL; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1427 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1428 | if (!ie && !anqp) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1429 | return NULL; |
| 1430 | |
| 1431 | if (wpa_s->conf->cred == NULL) |
| 1432 | return NULL; |
| 1433 | |
| 1434 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1435 | if (cred->num_home_ois == 0 && |
| 1436 | cred->num_required_home_ois == 0 && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1437 | cred->num_roaming_consortiums == 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1438 | continue; |
| 1439 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1440 | if (!cred->eap_method) |
| 1441 | continue; |
| 1442 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1443 | /* If there's required home OIs, there must be a match for each |
| 1444 | * required OI (see Passpoint v3.2 - 9.1.2 - RequiredHomeOI). */ |
| 1445 | if (cred->num_required_home_ois > 0 && |
| 1446 | cred_no_required_oi_match(cred, bss)) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1447 | continue; |
| 1448 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1449 | if (!cred_home_ois_match(ie, anqp, cred) && |
| 1450 | !cred_roaming_consortiums_match(ie, anqp, cred)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1451 | continue; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1452 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1453 | if (!ignore_bw && cred_below_min_backhaul(wpa_s, cred, bss)) |
| 1454 | continue; |
| 1455 | if (!ignore_bw && cred_over_max_bss_load(wpa_s, cred, bss)) |
| 1456 | continue; |
| 1457 | if (!ignore_bw && cred_conn_capab_missing(wpa_s, cred, bss)) |
| 1458 | continue; |
| 1459 | if (cred_excluded_ssid(cred, bss)) { |
| 1460 | if (excluded == NULL) |
| 1461 | continue; |
| 1462 | if (selected == NULL) { |
| 1463 | selected = cred; |
| 1464 | is_excluded = 1; |
| 1465 | } |
| 1466 | } else { |
| 1467 | if (selected == NULL || is_excluded || |
| 1468 | cred_prio_cmp(selected, cred) < 0) { |
| 1469 | selected = cred; |
| 1470 | is_excluded = 0; |
| 1471 | } |
| 1472 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1475 | if (excluded) |
| 1476 | *excluded = is_excluded; |
| 1477 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1478 | return selected; |
| 1479 | } |
| 1480 | |
| 1481 | |
| 1482 | static int interworking_set_eap_params(struct wpa_ssid *ssid, |
| 1483 | struct wpa_cred *cred, int ttls) |
| 1484 | { |
| 1485 | if (cred->eap_method) { |
| 1486 | ttls = cred->eap_method->vendor == EAP_VENDOR_IETF && |
| 1487 | cred->eap_method->method == EAP_TYPE_TTLS; |
| 1488 | |
| 1489 | os_free(ssid->eap.eap_methods); |
| 1490 | ssid->eap.eap_methods = |
| 1491 | os_malloc(sizeof(struct eap_method_type) * 2); |
| 1492 | if (ssid->eap.eap_methods == NULL) |
| 1493 | return -1; |
| 1494 | os_memcpy(ssid->eap.eap_methods, cred->eap_method, |
| 1495 | sizeof(*cred->eap_method)); |
| 1496 | ssid->eap.eap_methods[1].vendor = EAP_VENDOR_IETF; |
| 1497 | ssid->eap.eap_methods[1].method = EAP_TYPE_NONE; |
| 1498 | } |
| 1499 | |
| 1500 | if (ttls && cred->username && cred->username[0]) { |
| 1501 | const char *pos; |
| 1502 | char *anon; |
| 1503 | /* Use anonymous NAI in Phase 1 */ |
| 1504 | pos = os_strchr(cred->username, '@'); |
| 1505 | if (pos) { |
| 1506 | size_t buflen = 9 + os_strlen(pos) + 1; |
| 1507 | anon = os_malloc(buflen); |
| 1508 | if (anon == NULL) |
| 1509 | return -1; |
| 1510 | os_snprintf(anon, buflen, "anonymous%s", pos); |
| 1511 | } else if (cred->realm) { |
| 1512 | size_t buflen = 10 + os_strlen(cred->realm) + 1; |
| 1513 | anon = os_malloc(buflen); |
| 1514 | if (anon == NULL) |
| 1515 | return -1; |
| 1516 | os_snprintf(anon, buflen, "anonymous@%s", cred->realm); |
| 1517 | } else { |
| 1518 | anon = os_strdup("anonymous"); |
| 1519 | if (anon == NULL) |
| 1520 | return -1; |
| 1521 | } |
| 1522 | if (wpa_config_set_quoted(ssid, "anonymous_identity", anon) < |
| 1523 | 0) { |
| 1524 | os_free(anon); |
| 1525 | return -1; |
| 1526 | } |
| 1527 | os_free(anon); |
| 1528 | } |
| 1529 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1530 | if (!ttls && cred->username && cred->username[0] && cred->realm && |
| 1531 | !os_strchr(cred->username, '@')) { |
| 1532 | char *id; |
| 1533 | size_t buflen; |
| 1534 | int res; |
| 1535 | |
| 1536 | buflen = os_strlen(cred->username) + 1 + |
| 1537 | os_strlen(cred->realm) + 1; |
| 1538 | |
| 1539 | id = os_malloc(buflen); |
| 1540 | if (!id) |
| 1541 | return -1; |
| 1542 | os_snprintf(id, buflen, "%s@%s", cred->username, cred->realm); |
| 1543 | res = wpa_config_set_quoted(ssid, "identity", id); |
| 1544 | os_free(id); |
| 1545 | if (res < 0) |
| 1546 | return -1; |
| 1547 | } else if (cred->username && cred->username[0] && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1548 | wpa_config_set_quoted(ssid, "identity", cred->username) < 0) |
| 1549 | return -1; |
| 1550 | |
| 1551 | if (cred->password && cred->password[0]) { |
| 1552 | if (cred->ext_password && |
| 1553 | wpa_config_set(ssid, "password", cred->password, 0) < 0) |
| 1554 | return -1; |
| 1555 | if (!cred->ext_password && |
| 1556 | wpa_config_set_quoted(ssid, "password", cred->password) < |
| 1557 | 0) |
| 1558 | return -1; |
| 1559 | } |
| 1560 | |
| 1561 | if (cred->client_cert && cred->client_cert[0] && |
| 1562 | wpa_config_set_quoted(ssid, "client_cert", cred->client_cert) < 0) |
| 1563 | return -1; |
| 1564 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1565 | #ifdef ANDROID |
| 1566 | if (cred->private_key && |
| 1567 | os_strncmp(cred->private_key, "keystore://", 11) == 0) { |
| 1568 | /* Use OpenSSL engine configuration for Android keystore */ |
| 1569 | if (wpa_config_set_quoted(ssid, "engine_id", "keystore") < 0 || |
| 1570 | wpa_config_set_quoted(ssid, "key_id", |
| 1571 | cred->private_key + 11) < 0 || |
| 1572 | wpa_config_set(ssid, "engine", "1", 0) < 0) |
| 1573 | return -1; |
| 1574 | } else |
| 1575 | #endif /* ANDROID */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1576 | if (cred->private_key && cred->private_key[0] && |
| 1577 | wpa_config_set_quoted(ssid, "private_key", cred->private_key) < 0) |
| 1578 | return -1; |
| 1579 | |
| 1580 | if (cred->private_key_passwd && cred->private_key_passwd[0] && |
| 1581 | wpa_config_set_quoted(ssid, "private_key_passwd", |
| 1582 | cred->private_key_passwd) < 0) |
| 1583 | return -1; |
| 1584 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1585 | if (cred->ca_cert_id && cred->ca_cert_id[0] && |
| 1586 | wpa_config_set_quoted(ssid, "ca_cert_id", cred->ca_cert_id) < 0) |
| 1587 | return -1; |
| 1588 | |
| 1589 | if (cred->cert_id && cred->cert_id[0] && |
| 1590 | wpa_config_set_quoted(ssid, "cert_id", cred->cert_id) < 0) |
| 1591 | return -1; |
| 1592 | |
| 1593 | if (cred->key_id && cred->key_id[0] && |
| 1594 | wpa_config_set_quoted(ssid, "key_id", cred->key_id) < 0) |
| 1595 | return -1; |
| 1596 | |
| 1597 | if (cred->engine_id && cred->engine_id[0] && |
| 1598 | wpa_config_set_quoted(ssid, "engine_id", cred->engine_id) < 0) |
| 1599 | return -1; |
| 1600 | |
| 1601 | ssid->eap.cert.engine = cred->engine; |
| 1602 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1603 | if (cred->phase1) { |
| 1604 | os_free(ssid->eap.phase1); |
| 1605 | ssid->eap.phase1 = os_strdup(cred->phase1); |
| 1606 | } |
| 1607 | if (cred->phase2) { |
| 1608 | os_free(ssid->eap.phase2); |
| 1609 | ssid->eap.phase2 = os_strdup(cred->phase2); |
| 1610 | } |
| 1611 | |
| 1612 | if (cred->ca_cert && cred->ca_cert[0] && |
| 1613 | wpa_config_set_quoted(ssid, "ca_cert", cred->ca_cert) < 0) |
| 1614 | return -1; |
| 1615 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1616 | if (cred->domain_suffix_match && cred->domain_suffix_match[0] && |
| 1617 | wpa_config_set_quoted(ssid, "domain_suffix_match", |
| 1618 | cred->domain_suffix_match) < 0) |
| 1619 | return -1; |
| 1620 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1621 | ssid->eap.cert.ocsp = cred->ocsp; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1622 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1623 | return 0; |
| 1624 | } |
| 1625 | |
| 1626 | |
| 1627 | static int interworking_connect_roaming_consortium( |
| 1628 | struct wpa_supplicant *wpa_s, struct wpa_cred *cred, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1629 | struct wpa_bss *bss, int only_add) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1630 | { |
| 1631 | struct wpa_ssid *ssid; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1632 | const u8 *ie; |
| 1633 | const struct wpabuf *anqp; |
| 1634 | unsigned int i; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1635 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1636 | wpa_msg(wpa_s, MSG_DEBUG, "Interworking: Connect with " MACSTR |
| 1637 | " based on roaming consortium match", MAC2STR(bss->bssid)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1638 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1639 | if (already_connected(wpa_s, cred, bss)) { |
| 1640 | wpa_msg(wpa_s, MSG_INFO, INTERWORKING_ALREADY_CONNECTED MACSTR, |
| 1641 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1642 | return wpa_s->current_ssid->id; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | remove_duplicate_network(wpa_s, cred, bss); |
| 1646 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1647 | ssid = wpa_config_add_network(wpa_s->conf); |
| 1648 | if (ssid == NULL) |
| 1649 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1650 | ssid->parent_cred = cred; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1651 | wpas_notify_network_added(wpa_s, ssid); |
| 1652 | wpa_config_set_network_defaults(ssid); |
| 1653 | ssid->priority = cred->priority; |
| 1654 | ssid->temporary = 1; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1655 | ssid->ssid = os_zalloc(bss->ssid_len + 1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1656 | if (ssid->ssid == NULL) |
| 1657 | goto fail; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1658 | os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len); |
| 1659 | ssid->ssid_len = bss->ssid_len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1660 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1661 | if (interworking_set_hs20_params(wpa_s, ssid) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1662 | goto fail; |
| 1663 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1664 | ie = wpa_bss_get_ie(bss, WLAN_EID_ROAMING_CONSORTIUM); |
| 1665 | anqp = bss->anqp ? bss->anqp->roaming_consortium : NULL; |
| 1666 | for (i = 0; (ie || anqp) && i < cred->num_roaming_consortiums; i++) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame^] | 1667 | if (!oi_match(ie, anqp, cred->roaming_consortiums[i], |
| 1668 | cred->roaming_consortiums_len[i])) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1669 | continue; |
| 1670 | |
| 1671 | ssid->roaming_consortium_selection = |
| 1672 | os_malloc(cred->roaming_consortiums_len[i]); |
| 1673 | if (!ssid->roaming_consortium_selection) |
| 1674 | goto fail; |
| 1675 | os_memcpy(ssid->roaming_consortium_selection, |
| 1676 | cred->roaming_consortiums[i], |
| 1677 | cred->roaming_consortiums_len[i]); |
| 1678 | ssid->roaming_consortium_selection_len = |
| 1679 | cred->roaming_consortiums_len[i]; |
| 1680 | break; |
| 1681 | } |
| 1682 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1683 | if (cred->eap_method == NULL) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1684 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1685 | "Interworking: No EAP method set for credential using roaming consortium"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1686 | goto fail; |
| 1687 | } |
| 1688 | |
| 1689 | if (interworking_set_eap_params( |
| 1690 | ssid, cred, |
| 1691 | cred->eap_method->vendor == EAP_VENDOR_IETF && |
| 1692 | cred->eap_method->method == EAP_TYPE_TTLS) < 0) |
| 1693 | goto fail; |
| 1694 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1695 | wpa_s->next_ssid = ssid; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1696 | wpa_config_update_prio_list(wpa_s->conf); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1697 | if (!only_add) |
| 1698 | interworking_reconnect(wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1699 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1700 | return ssid->id; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1701 | |
| 1702 | fail: |
| 1703 | wpas_notify_network_removed(wpa_s, ssid); |
| 1704 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 1705 | return -1; |
| 1706 | } |
| 1707 | |
| 1708 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1709 | int interworking_connect(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 1710 | int only_add) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1711 | { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1712 | struct wpa_cred *cred, *cred_rc, *cred_3gpp; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1713 | struct wpa_ssid *ssid; |
| 1714 | struct nai_realm *realm; |
| 1715 | struct nai_realm_eap *eap = NULL; |
| 1716 | u16 count, i; |
| 1717 | char buf[100]; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1718 | int excluded = 0, *excl = &excluded; |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 1719 | const char *name; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1720 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1721 | if (wpa_s->conf->cred == NULL || bss == NULL) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1722 | return -1; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1723 | if (disallowed_bssid(wpa_s, bss->bssid) || |
| 1724 | disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1725 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1726 | "Interworking: Reject connection to disallowed BSS " |
| 1727 | MACSTR, MAC2STR(bss->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1728 | return -1; |
| 1729 | } |
| 1730 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1731 | wpa_printf(MSG_DEBUG, "Interworking: Considering BSS " MACSTR |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1732 | " for connection", |
| 1733 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1734 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1735 | if (!wpa_bss_get_ie(bss, WLAN_EID_RSN)) { |
| 1736 | /* |
| 1737 | * We currently support only HS 2.0 networks and those are |
| 1738 | * required to use WPA2-Enterprise. |
| 1739 | */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1740 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1741 | "Interworking: Network does not use RSN"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1742 | return -1; |
| 1743 | } |
| 1744 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1745 | cred_rc = interworking_credentials_available_roaming_consortium( |
| 1746 | wpa_s, bss, 0, excl); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1747 | if (cred_rc) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1748 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1749 | "Interworking: Highest roaming consortium matching credential priority %d sp_priority %d", |
| 1750 | cred_rc->priority, cred_rc->sp_priority); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1751 | if (excl && !(*excl)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1752 | excl = NULL; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1753 | } |
| 1754 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1755 | cred = interworking_credentials_available_realm(wpa_s, bss, 0, excl); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1756 | if (cred) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1757 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1758 | "Interworking: Highest NAI Realm list matching credential priority %d sp_priority %d", |
| 1759 | cred->priority, cred->sp_priority); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1760 | if (excl && !(*excl)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1761 | excl = NULL; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1762 | } |
| 1763 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1764 | cred_3gpp = interworking_credentials_available_3gpp(wpa_s, bss, 0, |
| 1765 | excl); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1766 | if (cred_3gpp) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1767 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1768 | "Interworking: Highest 3GPP matching credential priority %d sp_priority %d", |
| 1769 | cred_3gpp->priority, cred_3gpp->sp_priority); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1770 | if (excl && !(*excl)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1771 | excl = NULL; |
| 1772 | } |
| 1773 | |
| 1774 | if (!cred_rc && !cred && !cred_3gpp) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1775 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1776 | "Interworking: No full credential matches - consider options without BW(etc.) limits"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1777 | cred_rc = interworking_credentials_available_roaming_consortium( |
| 1778 | wpa_s, bss, 1, excl); |
| 1779 | if (cred_rc) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1780 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1781 | "Interworking: Highest roaming consortium matching credential priority %d sp_priority %d (ignore BW)", |
| 1782 | cred_rc->priority, cred_rc->sp_priority); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1783 | if (excl && !(*excl)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1784 | excl = NULL; |
| 1785 | } |
| 1786 | |
| 1787 | cred = interworking_credentials_available_realm(wpa_s, bss, 1, |
| 1788 | excl); |
| 1789 | if (cred) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1790 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1791 | "Interworking: Highest NAI Realm list matching credential priority %d sp_priority %d (ignore BW)", |
| 1792 | cred->priority, cred->sp_priority); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1793 | if (excl && !(*excl)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1794 | excl = NULL; |
| 1795 | } |
| 1796 | |
| 1797 | cred_3gpp = interworking_credentials_available_3gpp(wpa_s, bss, |
| 1798 | 1, excl); |
| 1799 | if (cred_3gpp) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1800 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1801 | "Interworking: Highest 3GPP matching credential priority %d sp_priority %d (ignore BW)", |
| 1802 | cred_3gpp->priority, cred_3gpp->sp_priority); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 1803 | if (excl && !(*excl)) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1804 | excl = NULL; |
| 1805 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | if (cred_rc && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1809 | (cred == NULL || cred_prio_cmp(cred_rc, cred) >= 0) && |
| 1810 | (cred_3gpp == NULL || cred_prio_cmp(cred_rc, cred_3gpp) >= 0)) |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1811 | return interworking_connect_roaming_consortium(wpa_s, cred_rc, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1812 | bss, only_add); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1813 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1814 | if (cred_3gpp && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1815 | (cred == NULL || cred_prio_cmp(cred_3gpp, cred) >= 0)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1816 | return interworking_connect_3gpp(wpa_s, cred_3gpp, bss, |
| 1817 | only_add); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | if (cred == NULL) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1821 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1822 | "Interworking: No matching credentials found for " |
| 1823 | MACSTR, MAC2STR(bss->bssid)); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1824 | return -1; |
| 1825 | } |
| 1826 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1827 | realm = nai_realm_parse(bss->anqp ? bss->anqp->nai_realm : NULL, |
| 1828 | &count); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1829 | if (realm == NULL) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1830 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1831 | "Interworking: Could not parse NAI Realm list from " |
| 1832 | MACSTR, MAC2STR(bss->bssid)); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1833 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1834 | } |
| 1835 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1836 | for (i = 0; i < count; i++) { |
| 1837 | if (!nai_realm_match(&realm[i], cred->realm)) |
| 1838 | continue; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1839 | eap = nai_realm_find_eap(wpa_s, cred, &realm[i]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1840 | if (eap) |
| 1841 | break; |
| 1842 | } |
| 1843 | |
| 1844 | if (!eap) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1845 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1846 | "Interworking: No matching credentials and EAP method found for " |
| 1847 | MACSTR, MAC2STR(bss->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1848 | nai_realm_free(realm, count); |
| 1849 | return -1; |
| 1850 | } |
| 1851 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1852 | wpa_msg(wpa_s, MSG_DEBUG, "Interworking: Connect with " MACSTR, |
| 1853 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1854 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1855 | if (already_connected(wpa_s, cred, bss)) { |
| 1856 | wpa_msg(wpa_s, MSG_INFO, INTERWORKING_ALREADY_CONNECTED MACSTR, |
| 1857 | MAC2STR(bss->bssid)); |
| 1858 | nai_realm_free(realm, count); |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | remove_duplicate_network(wpa_s, cred, bss); |
| 1863 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1864 | ssid = wpa_config_add_network(wpa_s->conf); |
| 1865 | if (ssid == NULL) { |
| 1866 | nai_realm_free(realm, count); |
| 1867 | return -1; |
| 1868 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1869 | ssid->parent_cred = cred; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1870 | wpas_notify_network_added(wpa_s, ssid); |
| 1871 | wpa_config_set_network_defaults(ssid); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1872 | ssid->priority = cred->priority; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1873 | ssid->temporary = 1; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1874 | ssid->ssid = os_zalloc(bss->ssid_len + 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1875 | if (ssid->ssid == NULL) |
| 1876 | goto fail; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1877 | os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len); |
| 1878 | ssid->ssid_len = bss->ssid_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1879 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1880 | if (interworking_set_hs20_params(wpa_s, ssid) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1881 | goto fail; |
| 1882 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1883 | if (wpa_config_set(ssid, "eap", eap_get_name(EAP_VENDOR_IETF, |
| 1884 | eap->method), 0) < 0) |
| 1885 | goto fail; |
| 1886 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1887 | switch (eap->method) { |
| 1888 | case EAP_TYPE_TTLS: |
| 1889 | if (eap->inner_method) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1890 | name = eap_get_name(EAP_VENDOR_IETF, eap->inner_method); |
| 1891 | if (!name) |
| 1892 | goto fail; |
| 1893 | os_snprintf(buf, sizeof(buf), "\"autheap=%s\"", name); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1894 | if (wpa_config_set(ssid, "phase2", buf, 0) < 0) |
| 1895 | goto fail; |
| 1896 | break; |
| 1897 | } |
| 1898 | switch (eap->inner_non_eap) { |
| 1899 | case NAI_REALM_INNER_NON_EAP_PAP: |
| 1900 | if (wpa_config_set(ssid, "phase2", "\"auth=PAP\"", 0) < |
| 1901 | 0) |
| 1902 | goto fail; |
| 1903 | break; |
| 1904 | case NAI_REALM_INNER_NON_EAP_CHAP: |
| 1905 | if (wpa_config_set(ssid, "phase2", "\"auth=CHAP\"", 0) |
| 1906 | < 0) |
| 1907 | goto fail; |
| 1908 | break; |
| 1909 | case NAI_REALM_INNER_NON_EAP_MSCHAP: |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1910 | if (wpa_config_set(ssid, "phase2", "\"auth=MSCHAP\"", |
| 1911 | 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1912 | goto fail; |
| 1913 | break; |
| 1914 | case NAI_REALM_INNER_NON_EAP_MSCHAPV2: |
| 1915 | if (wpa_config_set(ssid, "phase2", "\"auth=MSCHAPV2\"", |
| 1916 | 0) < 0) |
| 1917 | goto fail; |
| 1918 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1919 | default: |
| 1920 | /* EAP params were not set - assume TTLS/MSCHAPv2 */ |
| 1921 | if (wpa_config_set(ssid, "phase2", "\"auth=MSCHAPV2\"", |
| 1922 | 0) < 0) |
| 1923 | goto fail; |
| 1924 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1925 | } |
| 1926 | break; |
| 1927 | case EAP_TYPE_PEAP: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1928 | case EAP_TYPE_FAST: |
| 1929 | if (wpa_config_set(ssid, "phase1", "\"fast_provisioning=2\"", |
| 1930 | 0) < 0) |
| 1931 | goto fail; |
| 1932 | if (wpa_config_set(ssid, "pac_file", |
| 1933 | "\"blob://pac_interworking\"", 0) < 0) |
| 1934 | goto fail; |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 1935 | name = eap_get_name(EAP_VENDOR_IETF, |
| 1936 | eap->inner_method ? eap->inner_method : |
| 1937 | EAP_TYPE_MSCHAPV2); |
| 1938 | if (name == NULL) |
| 1939 | goto fail; |
| 1940 | os_snprintf(buf, sizeof(buf), "\"auth=%s\"", name); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1941 | if (wpa_config_set(ssid, "phase2", buf, 0) < 0) |
| 1942 | goto fail; |
| 1943 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1944 | case EAP_TYPE_TLS: |
| 1945 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1946 | } |
| 1947 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1948 | if (interworking_set_eap_params(ssid, cred, |
| 1949 | eap->method == EAP_TYPE_TTLS) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1950 | goto fail; |
| 1951 | |
| 1952 | nai_realm_free(realm, count); |
| 1953 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1954 | wpa_s->next_ssid = ssid; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1955 | wpa_config_update_prio_list(wpa_s->conf); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1956 | if (!only_add) |
| 1957 | interworking_reconnect(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1958 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1959 | return ssid->id; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1960 | |
| 1961 | fail: |
| 1962 | wpas_notify_network_removed(wpa_s, ssid); |
| 1963 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 1964 | nai_realm_free(realm, count); |
| 1965 | return -1; |
| 1966 | } |
| 1967 | |
| 1968 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 1969 | #ifdef PCSC_FUNCS |
| 1970 | static int interworking_pcsc_read_imsi(struct wpa_supplicant *wpa_s) |
| 1971 | { |
| 1972 | size_t len; |
| 1973 | |
| 1974 | if (wpa_s->imsi[0] && wpa_s->mnc_len) |
| 1975 | return 0; |
| 1976 | |
| 1977 | len = sizeof(wpa_s->imsi) - 1; |
| 1978 | if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) { |
| 1979 | scard_deinit(wpa_s->scard); |
| 1980 | wpa_s->scard = NULL; |
| 1981 | wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI"); |
| 1982 | return -1; |
| 1983 | } |
| 1984 | wpa_s->imsi[len] = '\0'; |
| 1985 | wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard); |
| 1986 | wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)", |
| 1987 | wpa_s->imsi, wpa_s->mnc_len); |
| 1988 | |
| 1989 | return 0; |
| 1990 | } |
| 1991 | #endif /* PCSC_FUNCS */ |
| 1992 | |
| 1993 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1994 | static struct wpa_cred * interworking_credentials_available_3gpp( |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1995 | struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int ignore_bw, |
| 1996 | int *excluded) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1997 | { |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 1998 | struct wpa_cred *selected = NULL; |
| 1999 | #ifdef INTERWORKING_3GPP |
| 2000 | struct wpa_cred *cred; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2001 | int ret; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2002 | int is_excluded = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2003 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2004 | if (bss->anqp == NULL || bss->anqp->anqp_3gpp == NULL) { |
| 2005 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2006 | "interworking-avail-3gpp: not avail, anqp: %p anqp_3gpp: %p", |
| 2007 | bss->anqp, bss->anqp ? bss->anqp->anqp_3gpp : NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2008 | return NULL; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2009 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2010 | |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 2011 | #ifdef CONFIG_EAP_PROXY |
| 2012 | if (!wpa_s->imsi[0]) { |
| 2013 | size_t len; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2014 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2015 | "Interworking: IMSI not available - try to read again through eap_proxy"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2016 | wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1, |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 2017 | wpa_s->imsi, |
| 2018 | &len); |
| 2019 | if (wpa_s->mnc_len > 0) { |
| 2020 | wpa_s->imsi[len] = '\0'; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2021 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2022 | "eap_proxy: IMSI %s (MNC length %d)", |
| 2023 | wpa_s->imsi, wpa_s->mnc_len); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 2024 | } else { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2025 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2026 | "eap_proxy: IMSI not available"); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | #endif /* CONFIG_EAP_PROXY */ |
| 2030 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2031 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| 2032 | char *sep; |
| 2033 | const char *imsi; |
| 2034 | int mnc_len; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2035 | char imsi_buf[16]; |
| 2036 | size_t msin_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2037 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2038 | #ifdef PCSC_FUNCS |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 2039 | if (cred->pcsc && wpa_s->scard) { |
| 2040 | if (interworking_pcsc_read_imsi(wpa_s) < 0) |
| 2041 | continue; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2042 | imsi = wpa_s->imsi; |
| 2043 | mnc_len = wpa_s->mnc_len; |
| 2044 | goto compare; |
| 2045 | } |
| 2046 | #endif /* PCSC_FUNCS */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2047 | #ifdef CONFIG_EAP_PROXY |
| 2048 | if (cred->pcsc && wpa_s->mnc_len > 0 && wpa_s->imsi[0]) { |
| 2049 | imsi = wpa_s->imsi; |
| 2050 | mnc_len = wpa_s->mnc_len; |
| 2051 | goto compare; |
| 2052 | } |
| 2053 | #endif /* CONFIG_EAP_PROXY */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2054 | |
| 2055 | if (cred->imsi == NULL || !cred->imsi[0] || |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2056 | (!wpa_s->conf->external_sim && |
| 2057 | (cred->milenage == NULL || !cred->milenage[0]))) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2058 | continue; |
| 2059 | |
| 2060 | sep = os_strchr(cred->imsi, '-'); |
| 2061 | if (sep == NULL || |
| 2062 | (sep - cred->imsi != 5 && sep - cred->imsi != 6)) |
| 2063 | continue; |
| 2064 | mnc_len = sep - cred->imsi - 3; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2065 | os_memcpy(imsi_buf, cred->imsi, 3 + mnc_len); |
| 2066 | sep++; |
| 2067 | msin_len = os_strlen(cred->imsi); |
| 2068 | if (3 + mnc_len + msin_len >= sizeof(imsi_buf) - 1) |
| 2069 | msin_len = sizeof(imsi_buf) - 3 - mnc_len - 1; |
| 2070 | os_memcpy(&imsi_buf[3 + mnc_len], sep, msin_len); |
| 2071 | imsi_buf[3 + mnc_len + msin_len] = '\0'; |
| 2072 | imsi = imsi_buf; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2073 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2074 | #if defined(PCSC_FUNCS) || defined(CONFIG_EAP_PROXY) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2075 | compare: |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2076 | #endif /* PCSC_FUNCS || CONFIG_EAP_PROXY */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2077 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2078 | "Interworking: Parsing 3GPP info from " MACSTR, |
| 2079 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2080 | ret = plmn_id_match(bss->anqp->anqp_3gpp, imsi, mnc_len); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2081 | wpa_msg(wpa_s, MSG_DEBUG, "PLMN match %sfound", |
| 2082 | ret ? "" : "not "); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2083 | if (ret) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2084 | if (cred_no_required_oi_match(cred, bss)) |
| 2085 | continue; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2086 | if (!ignore_bw && |
| 2087 | cred_below_min_backhaul(wpa_s, cred, bss)) |
| 2088 | continue; |
| 2089 | if (!ignore_bw && |
| 2090 | cred_over_max_bss_load(wpa_s, cred, bss)) |
| 2091 | continue; |
| 2092 | if (!ignore_bw && |
| 2093 | cred_conn_capab_missing(wpa_s, cred, bss)) |
| 2094 | continue; |
| 2095 | if (cred_excluded_ssid(cred, bss)) { |
| 2096 | if (excluded == NULL) |
| 2097 | continue; |
| 2098 | if (selected == NULL) { |
| 2099 | selected = cred; |
| 2100 | is_excluded = 1; |
| 2101 | } |
| 2102 | } else { |
| 2103 | if (selected == NULL || is_excluded || |
| 2104 | cred_prio_cmp(selected, cred) < 0) { |
| 2105 | selected = cred; |
| 2106 | is_excluded = 0; |
| 2107 | } |
| 2108 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2109 | } |
| 2110 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2111 | |
| 2112 | if (excluded) |
| 2113 | *excluded = is_excluded; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2114 | #endif /* INTERWORKING_3GPP */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2115 | return selected; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2119 | static struct wpa_cred * interworking_credentials_available_realm( |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2120 | struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int ignore_bw, |
| 2121 | int *excluded) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2122 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2123 | struct wpa_cred *cred, *selected = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2124 | struct nai_realm *realm; |
| 2125 | u16 count, i; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2126 | int is_excluded = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2127 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2128 | if (bss->anqp == NULL || bss->anqp->nai_realm == NULL) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2129 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2130 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2131 | if (wpa_s->conf->cred == NULL) |
| 2132 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2133 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2134 | wpa_msg(wpa_s, MSG_DEBUG, "Interworking: Parsing NAI Realm list from " |
| 2135 | MACSTR, MAC2STR(bss->bssid)); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2136 | realm = nai_realm_parse(bss->anqp->nai_realm, &count); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2137 | if (realm == NULL) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2138 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2139 | "Interworking: Could not parse NAI Realm list from " |
| 2140 | MACSTR, MAC2STR(bss->bssid)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2141 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2142 | } |
| 2143 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2144 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
| 2145 | if (cred->realm == NULL) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2146 | continue; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2147 | |
| 2148 | for (i = 0; i < count; i++) { |
| 2149 | if (!nai_realm_match(&realm[i], cred->realm)) |
| 2150 | continue; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2151 | if (nai_realm_find_eap(wpa_s, cred, &realm[i])) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2152 | if (cred_no_required_oi_match(cred, bss)) |
| 2153 | continue; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2154 | if (!ignore_bw && |
| 2155 | cred_below_min_backhaul(wpa_s, cred, bss)) |
| 2156 | continue; |
| 2157 | if (!ignore_bw && |
| 2158 | cred_over_max_bss_load(wpa_s, cred, bss)) |
| 2159 | continue; |
| 2160 | if (!ignore_bw && |
| 2161 | cred_conn_capab_missing(wpa_s, cred, bss)) |
| 2162 | continue; |
| 2163 | if (cred_excluded_ssid(cred, bss)) { |
| 2164 | if (excluded == NULL) |
| 2165 | continue; |
| 2166 | if (selected == NULL) { |
| 2167 | selected = cred; |
| 2168 | is_excluded = 1; |
| 2169 | } |
| 2170 | } else { |
| 2171 | if (selected == NULL || is_excluded || |
| 2172 | cred_prio_cmp(selected, cred) < 0) |
| 2173 | { |
| 2174 | selected = cred; |
| 2175 | is_excluded = 0; |
| 2176 | } |
| 2177 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2178 | break; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2179 | } else { |
| 2180 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2181 | "Interworking: realm-find-eap returned false"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2182 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | nai_realm_free(realm, count); |
| 2187 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2188 | if (excluded) |
| 2189 | *excluded = is_excluded; |
| 2190 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2191 | return selected; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2195 | static struct wpa_cred * interworking_credentials_available_helper( |
| 2196 | struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int ignore_bw, |
| 2197 | int *excluded) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2198 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2199 | struct wpa_cred *cred, *cred2; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2200 | int excluded1, excluded2 = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2201 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2202 | if (disallowed_bssid(wpa_s, bss->bssid) || |
| 2203 | disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) { |
| 2204 | wpa_printf(MSG_DEBUG, "Interworking: Ignore disallowed BSS " |
| 2205 | MACSTR, MAC2STR(bss->bssid)); |
| 2206 | return NULL; |
| 2207 | } |
| 2208 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2209 | cred = interworking_credentials_available_realm(wpa_s, bss, ignore_bw, |
| 2210 | &excluded1); |
| 2211 | cred2 = interworking_credentials_available_3gpp(wpa_s, bss, ignore_bw, |
| 2212 | &excluded2); |
| 2213 | if (cred && cred2 && |
| 2214 | (cred_prio_cmp(cred2, cred) >= 0 || (!excluded2 && excluded1))) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2215 | cred = cred2; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2216 | excluded1 = excluded2; |
| 2217 | } |
| 2218 | if (!cred) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2219 | cred = cred2; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2220 | excluded1 = excluded2; |
| 2221 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2222 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2223 | cred2 = interworking_credentials_available_roaming_consortium( |
| 2224 | wpa_s, bss, ignore_bw, &excluded2); |
| 2225 | if (cred && cred2 && |
| 2226 | (cred_prio_cmp(cred2, cred) >= 0 || (!excluded2 && excluded1))) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2227 | cred = cred2; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2228 | excluded1 = excluded2; |
| 2229 | } |
| 2230 | if (!cred) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2231 | cred = cred2; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2232 | excluded1 = excluded2; |
| 2233 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2234 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2235 | if (excluded) |
| 2236 | *excluded = excluded1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2237 | return cred; |
| 2238 | } |
| 2239 | |
| 2240 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2241 | static struct wpa_cred * interworking_credentials_available( |
| 2242 | struct wpa_supplicant *wpa_s, struct wpa_bss *bss, int *excluded) |
| 2243 | { |
| 2244 | struct wpa_cred *cred; |
| 2245 | |
| 2246 | if (excluded) |
| 2247 | *excluded = 0; |
| 2248 | cred = interworking_credentials_available_helper(wpa_s, bss, 0, |
| 2249 | excluded); |
| 2250 | if (cred) |
| 2251 | return cred; |
| 2252 | return interworking_credentials_available_helper(wpa_s, bss, 1, |
| 2253 | excluded); |
| 2254 | } |
| 2255 | |
| 2256 | |
| 2257 | int domain_name_list_contains(struct wpabuf *domain_names, |
| 2258 | const char *domain, int exact_match) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2259 | { |
| 2260 | const u8 *pos, *end; |
| 2261 | size_t len; |
| 2262 | |
| 2263 | len = os_strlen(domain); |
| 2264 | pos = wpabuf_head(domain_names); |
| 2265 | end = pos + wpabuf_len(domain_names); |
| 2266 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2267 | while (end - pos > 1) { |
| 2268 | u8 elen; |
| 2269 | |
| 2270 | elen = *pos++; |
| 2271 | if (elen > end - pos) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2272 | break; |
| 2273 | |
| 2274 | wpa_hexdump_ascii(MSG_DEBUG, "Interworking: AP domain name", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2275 | pos, elen); |
| 2276 | if (elen == len && |
| 2277 | os_strncasecmp(domain, (const char *) pos, len) == 0) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2278 | return 1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2279 | if (!exact_match && elen > len && pos[elen - len - 1] == '.') { |
| 2280 | const char *ap = (const char *) pos; |
| 2281 | int offset = elen - len; |
| 2282 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2283 | if (os_strncasecmp(domain, ap + offset, len) == 0) |
| 2284 | return 1; |
| 2285 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2286 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2287 | pos += elen; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | return 0; |
| 2291 | } |
| 2292 | |
| 2293 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2294 | int interworking_home_sp_cred(struct wpa_supplicant *wpa_s, |
| 2295 | struct wpa_cred *cred, |
| 2296 | struct wpabuf *domain_names) |
| 2297 | { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2298 | size_t i; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2299 | int ret = -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2300 | #ifdef INTERWORKING_3GPP |
| 2301 | char nai[100], *realm; |
| 2302 | |
| 2303 | char *imsi = NULL; |
| 2304 | int mnc_len = 0; |
| 2305 | if (cred->imsi) |
| 2306 | imsi = cred->imsi; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 2307 | #ifdef PCSC_FUNCS |
| 2308 | else if (cred->pcsc && wpa_s->scard) { |
| 2309 | if (interworking_pcsc_read_imsi(wpa_s) < 0) |
| 2310 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2311 | imsi = wpa_s->imsi; |
| 2312 | mnc_len = wpa_s->mnc_len; |
| 2313 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 2314 | #endif /* PCSC_FUNCS */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2315 | #ifdef CONFIG_EAP_PROXY |
| 2316 | else if (cred->pcsc && wpa_s->mnc_len > 0 && wpa_s->imsi[0]) { |
| 2317 | imsi = wpa_s->imsi; |
| 2318 | mnc_len = wpa_s->mnc_len; |
| 2319 | } |
| 2320 | #endif /* CONFIG_EAP_PROXY */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2321 | if (domain_names && |
| 2322 | imsi && build_root_nai(nai, sizeof(nai), imsi, mnc_len, 0) == 0) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2323 | realm = os_strchr(nai, '@'); |
| 2324 | if (realm) |
| 2325 | realm++; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2326 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2327 | "Interworking: Search for match with SIM/USIM domain %s", |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2328 | realm ? realm : "[NULL]"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2329 | if (realm && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2330 | domain_name_list_contains(domain_names, realm, 1)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2331 | return 1; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2332 | if (realm) |
| 2333 | ret = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2334 | } |
| 2335 | #endif /* INTERWORKING_3GPP */ |
| 2336 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2337 | if (domain_names == NULL || cred->domain == NULL) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2338 | return ret; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2339 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2340 | for (i = 0; i < cred->num_domain; i++) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2341 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2342 | "Interworking: Search for match with home SP FQDN %s", |
| 2343 | cred->domain[i]); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2344 | if (domain_name_list_contains(domain_names, cred->domain[i], 1)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2345 | return 1; |
| 2346 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2347 | |
| 2348 | return 0; |
| 2349 | } |
| 2350 | |
| 2351 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2352 | static int interworking_home_sp(struct wpa_supplicant *wpa_s, |
| 2353 | struct wpabuf *domain_names) |
| 2354 | { |
| 2355 | struct wpa_cred *cred; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2356 | |
| 2357 | if (domain_names == NULL || wpa_s->conf->cred == NULL) |
| 2358 | return -1; |
| 2359 | |
| 2360 | for (cred = wpa_s->conf->cred; cred; cred = cred->next) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2361 | int res = interworking_home_sp_cred(wpa_s, cred, domain_names); |
| 2362 | if (res) |
| 2363 | return res; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | return 0; |
| 2367 | } |
| 2368 | |
| 2369 | |
| 2370 | static int interworking_find_network_match(struct wpa_supplicant *wpa_s) |
| 2371 | { |
| 2372 | struct wpa_bss *bss; |
| 2373 | struct wpa_ssid *ssid; |
| 2374 | |
| 2375 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 2376 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 2377 | if (wpas_network_disabled(wpa_s, ssid) || |
| 2378 | ssid->mode != WPAS_MODE_INFRA) |
| 2379 | continue; |
| 2380 | if (ssid->ssid_len != bss->ssid_len || |
| 2381 | os_memcmp(ssid->ssid, bss->ssid, ssid->ssid_len) != |
| 2382 | 0) |
| 2383 | continue; |
| 2384 | /* |
| 2385 | * TODO: Consider more accurate matching of security |
| 2386 | * configuration similarly to what is done in events.c |
| 2387 | */ |
| 2388 | return 1; |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2396 | static int roaming_partner_match(struct wpa_supplicant *wpa_s, |
| 2397 | struct roaming_partner *partner, |
| 2398 | struct wpabuf *domain_names) |
| 2399 | { |
| 2400 | wpa_printf(MSG_DEBUG, "Interworking: Comparing roaming_partner info fqdn='%s' exact_match=%d priority=%u country='%s'", |
| 2401 | partner->fqdn, partner->exact_match, partner->priority, |
| 2402 | partner->country); |
| 2403 | wpa_hexdump_ascii(MSG_DEBUG, "Interworking: Domain names", |
| 2404 | wpabuf_head(domain_names), |
| 2405 | wpabuf_len(domain_names)); |
| 2406 | if (!domain_name_list_contains(domain_names, partner->fqdn, |
| 2407 | partner->exact_match)) |
| 2408 | return 0; |
| 2409 | /* TODO: match Country */ |
| 2410 | return 1; |
| 2411 | } |
| 2412 | |
| 2413 | |
| 2414 | static u8 roaming_prio(struct wpa_supplicant *wpa_s, struct wpa_cred *cred, |
| 2415 | struct wpa_bss *bss) |
| 2416 | { |
| 2417 | size_t i; |
| 2418 | |
| 2419 | if (bss->anqp == NULL || bss->anqp->domain_name == NULL) { |
| 2420 | wpa_printf(MSG_DEBUG, "Interworking: No ANQP domain name info -> use default roaming partner priority 128"); |
| 2421 | return 128; /* cannot check preference with domain name */ |
| 2422 | } |
| 2423 | |
| 2424 | if (interworking_home_sp_cred(wpa_s, cred, bss->anqp->domain_name) > 0) |
| 2425 | { |
| 2426 | wpa_printf(MSG_DEBUG, "Interworking: Determined to be home SP -> use maximum preference 0 as roaming partner priority"); |
| 2427 | return 0; /* max preference for home SP network */ |
| 2428 | } |
| 2429 | |
| 2430 | for (i = 0; i < cred->num_roaming_partner; i++) { |
| 2431 | if (roaming_partner_match(wpa_s, &cred->roaming_partner[i], |
| 2432 | bss->anqp->domain_name)) { |
| 2433 | wpa_printf(MSG_DEBUG, "Interworking: Roaming partner preference match - priority %u", |
| 2434 | cred->roaming_partner[i].priority); |
| 2435 | return cred->roaming_partner[i].priority; |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | wpa_printf(MSG_DEBUG, "Interworking: No roaming partner preference match - use default roaming partner priority 128"); |
| 2440 | return 128; |
| 2441 | } |
| 2442 | |
| 2443 | |
| 2444 | static struct wpa_bss * pick_best_roaming_partner(struct wpa_supplicant *wpa_s, |
| 2445 | struct wpa_bss *selected, |
| 2446 | struct wpa_cred *cred) |
| 2447 | { |
| 2448 | struct wpa_bss *bss; |
| 2449 | u8 best_prio, prio; |
| 2450 | struct wpa_cred *cred2; |
| 2451 | |
| 2452 | /* |
| 2453 | * Check if any other BSS is operated by a more preferred roaming |
| 2454 | * partner. |
| 2455 | */ |
| 2456 | |
| 2457 | best_prio = roaming_prio(wpa_s, cred, selected); |
| 2458 | wpa_printf(MSG_DEBUG, "Interworking: roaming_prio=%u for selected BSS " |
| 2459 | MACSTR " (cred=%d)", best_prio, MAC2STR(selected->bssid), |
| 2460 | cred->id); |
| 2461 | |
| 2462 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 2463 | if (bss == selected) |
| 2464 | continue; |
| 2465 | cred2 = interworking_credentials_available(wpa_s, bss, NULL); |
| 2466 | if (!cred2) |
| 2467 | continue; |
| 2468 | if (!wpa_bss_get_ie(bss, WLAN_EID_RSN)) |
| 2469 | continue; |
| 2470 | prio = roaming_prio(wpa_s, cred2, bss); |
| 2471 | wpa_printf(MSG_DEBUG, "Interworking: roaming_prio=%u for BSS " |
| 2472 | MACSTR " (cred=%d)", prio, MAC2STR(bss->bssid), |
| 2473 | cred2->id); |
| 2474 | if (prio < best_prio) { |
| 2475 | int bh1, bh2, load1, load2, conn1, conn2; |
| 2476 | bh1 = cred_below_min_backhaul(wpa_s, cred, selected); |
| 2477 | load1 = cred_over_max_bss_load(wpa_s, cred, selected); |
| 2478 | conn1 = cred_conn_capab_missing(wpa_s, cred, selected); |
| 2479 | bh2 = cred_below_min_backhaul(wpa_s, cred2, bss); |
| 2480 | load2 = cred_over_max_bss_load(wpa_s, cred2, bss); |
| 2481 | conn2 = cred_conn_capab_missing(wpa_s, cred2, bss); |
| 2482 | wpa_printf(MSG_DEBUG, "Interworking: old: %d %d %d new: %d %d %d", |
| 2483 | bh1, load1, conn1, bh2, load2, conn2); |
| 2484 | if (bh1 || load1 || conn1 || !(bh2 || load2 || conn2)) { |
| 2485 | wpa_printf(MSG_DEBUG, "Interworking: Better roaming partner " MACSTR " selected", MAC2STR(bss->bssid)); |
| 2486 | best_prio = prio; |
| 2487 | selected = bss; |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | return selected; |
| 2493 | } |
| 2494 | |
| 2495 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2496 | static void interworking_select_network(struct wpa_supplicant *wpa_s) |
| 2497 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2498 | struct wpa_bss *bss, *selected = NULL, *selected_home = NULL; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2499 | struct wpa_bss *selected2 = NULL, *selected2_home = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2500 | unsigned int count = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2501 | const char *type; |
| 2502 | int res; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2503 | struct wpa_cred *cred, *selected_cred = NULL; |
| 2504 | struct wpa_cred *selected_home_cred = NULL; |
| 2505 | struct wpa_cred *selected2_cred = NULL; |
| 2506 | struct wpa_cred *selected2_home_cred = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2507 | |
| 2508 | wpa_s->network_select = 0; |
| 2509 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2510 | wpa_printf(MSG_DEBUG, "Interworking: Select network (auto_select=%d)", |
| 2511 | wpa_s->auto_select); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2512 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2513 | int excluded = 0; |
| 2514 | int bh, bss_load, conn_capab; |
| 2515 | cred = interworking_credentials_available(wpa_s, bss, |
| 2516 | &excluded); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2517 | if (!cred) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2518 | continue; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2519 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2520 | if (!wpa_bss_get_ie(bss, WLAN_EID_RSN)) { |
| 2521 | /* |
| 2522 | * We currently support only HS 2.0 networks and those |
| 2523 | * are required to use WPA2-Enterprise. |
| 2524 | */ |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2525 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2526 | "Interworking: Credential match with " MACSTR |
| 2527 | " but network does not use RSN", |
| 2528 | MAC2STR(bss->bssid)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2529 | continue; |
| 2530 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2531 | if (!excluded) |
| 2532 | count++; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2533 | res = interworking_home_sp(wpa_s, bss->anqp ? |
| 2534 | bss->anqp->domain_name : NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2535 | if (res > 0) |
| 2536 | type = "home"; |
| 2537 | else if (res == 0) |
| 2538 | type = "roaming"; |
| 2539 | else |
| 2540 | type = "unknown"; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2541 | bh = cred_below_min_backhaul(wpa_s, cred, bss); |
| 2542 | bss_load = cred_over_max_bss_load(wpa_s, cred, bss); |
| 2543 | conn_capab = cred_conn_capab_missing(wpa_s, cred, bss); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2544 | wpas_notify_interworking_ap_added(wpa_s, bss, cred, excluded, |
| 2545 | type, bh, bss_load, |
| 2546 | conn_capab); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2547 | if (excluded) |
| 2548 | continue; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2549 | if (wpa_s->auto_select || |
| 2550 | (wpa_s->conf->auto_interworking && |
| 2551 | wpa_s->auto_network_select)) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2552 | if (bh || bss_load || conn_capab) { |
| 2553 | if (selected2_cred == NULL || |
| 2554 | cred_prio_cmp(cred, selected2_cred) > 0) { |
| 2555 | wpa_printf(MSG_DEBUG, "Interworking: Mark as selected2"); |
| 2556 | selected2 = bss; |
| 2557 | selected2_cred = cred; |
| 2558 | } |
| 2559 | if (res > 0 && |
| 2560 | (selected2_home_cred == NULL || |
| 2561 | cred_prio_cmp(cred, selected2_home_cred) > |
| 2562 | 0)) { |
| 2563 | wpa_printf(MSG_DEBUG, "Interworking: Mark as selected2_home"); |
| 2564 | selected2_home = bss; |
| 2565 | selected2_home_cred = cred; |
| 2566 | } |
| 2567 | } else { |
| 2568 | if (selected_cred == NULL || |
| 2569 | cred_prio_cmp(cred, selected_cred) > 0) { |
| 2570 | wpa_printf(MSG_DEBUG, "Interworking: Mark as selected"); |
| 2571 | selected = bss; |
| 2572 | selected_cred = cred; |
| 2573 | } |
| 2574 | if (res > 0 && |
| 2575 | (selected_home_cred == NULL || |
| 2576 | cred_prio_cmp(cred, selected_home_cred) > |
| 2577 | 0)) { |
| 2578 | wpa_printf(MSG_DEBUG, "Interworking: Mark as selected_home"); |
| 2579 | selected_home = bss; |
| 2580 | selected_home_cred = cred; |
| 2581 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | if (selected_home && selected_home != selected && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2587 | selected_home_cred && |
| 2588 | (selected_cred == NULL || |
| 2589 | cred_prio_cmp(selected_home_cred, selected_cred) >= 0)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2590 | /* Prefer network operated by the Home SP */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2591 | wpa_printf(MSG_DEBUG, "Interworking: Overrode selected with selected_home"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2592 | selected = selected_home; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2593 | selected_cred = selected_home_cred; |
| 2594 | } |
| 2595 | |
| 2596 | if (!selected) { |
| 2597 | if (selected2_home) { |
| 2598 | wpa_printf(MSG_DEBUG, "Interworking: Use home BSS with BW limit mismatch since no other network could be selected"); |
| 2599 | selected = selected2_home; |
| 2600 | selected_cred = selected2_home_cred; |
| 2601 | } else if (selected2) { |
| 2602 | wpa_printf(MSG_DEBUG, "Interworking: Use visited BSS with BW limit mismatch since no other network could be selected"); |
| 2603 | selected = selected2; |
| 2604 | selected_cred = selected2_cred; |
| 2605 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | if (count == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2609 | /* |
| 2610 | * No matching network was found based on configured |
| 2611 | * credentials. Check whether any of the enabled network blocks |
| 2612 | * have matching APs. |
| 2613 | */ |
| 2614 | if (interworking_find_network_match(wpa_s)) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2615 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2616 | "Interworking: Possible BSS match for enabled network configurations"); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 2617 | if (wpa_s->auto_select) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2618 | interworking_reconnect(wpa_s); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 2619 | return; |
| 2620 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | if (wpa_s->auto_network_select) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2624 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2625 | "Interworking: Continue scanning after ANQP fetch"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2626 | wpa_supplicant_req_scan(wpa_s, wpa_s->scan_interval, |
| 2627 | 0); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2628 | return; |
| 2629 | } |
| 2630 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2631 | wpa_msg(wpa_s, MSG_INFO, INTERWORKING_NO_MATCH "No network " |
| 2632 | "with matching credentials found"); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2633 | if (wpa_s->wpa_state == WPA_SCANNING) |
| 2634 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2635 | } |
| 2636 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2637 | wpas_notify_interworking_select_done(wpa_s); |
| 2638 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2639 | if (selected) { |
| 2640 | wpa_printf(MSG_DEBUG, "Interworking: Selected " MACSTR, |
| 2641 | MAC2STR(selected->bssid)); |
| 2642 | selected = pick_best_roaming_partner(wpa_s, selected, |
| 2643 | selected_cred); |
| 2644 | wpa_printf(MSG_DEBUG, "Interworking: Selected " MACSTR |
| 2645 | " (after best roaming partner selection)", |
| 2646 | MAC2STR(selected->bssid)); |
| 2647 | wpa_msg(wpa_s, MSG_INFO, INTERWORKING_SELECTED MACSTR, |
| 2648 | MAC2STR(selected->bssid)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2649 | interworking_connect(wpa_s, selected, 0); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2650 | } else if (wpa_s->wpa_state == WPA_SCANNING) |
| 2651 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2655 | static struct wpa_bss_anqp * |
| 2656 | interworking_match_anqp_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
| 2657 | { |
| 2658 | struct wpa_bss *other; |
| 2659 | |
| 2660 | if (is_zero_ether_addr(bss->hessid)) |
| 2661 | return NULL; /* Cannot be in the same homegenous ESS */ |
| 2662 | |
| 2663 | dl_list_for_each(other, &wpa_s->bss, struct wpa_bss, list) { |
| 2664 | if (other == bss) |
| 2665 | continue; |
| 2666 | if (other->anqp == NULL) |
| 2667 | continue; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2668 | if (other->anqp->roaming_consortium == NULL && |
| 2669 | other->anqp->nai_realm == NULL && |
| 2670 | other->anqp->anqp_3gpp == NULL && |
| 2671 | other->anqp->domain_name == NULL) |
| 2672 | continue; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2673 | if (!(other->flags & WPA_BSS_ANQP_FETCH_TRIED)) |
| 2674 | continue; |
| 2675 | if (os_memcmp(bss->hessid, other->hessid, ETH_ALEN) != 0) |
| 2676 | continue; |
| 2677 | if (bss->ssid_len != other->ssid_len || |
| 2678 | os_memcmp(bss->ssid, other->ssid, bss->ssid_len) != 0) |
| 2679 | continue; |
| 2680 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2681 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2682 | "Interworking: Share ANQP data with already fetched BSSID " |
| 2683 | MACSTR " and " MACSTR, |
| 2684 | MAC2STR(other->bssid), MAC2STR(bss->bssid)); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2685 | other->anqp->users++; |
| 2686 | return other->anqp; |
| 2687 | } |
| 2688 | |
| 2689 | return NULL; |
| 2690 | } |
| 2691 | |
| 2692 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2693 | static void interworking_next_anqp_fetch(struct wpa_supplicant *wpa_s) |
| 2694 | { |
| 2695 | struct wpa_bss *bss; |
| 2696 | int found = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2697 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2698 | wpa_printf(MSG_DEBUG, "Interworking: next_anqp_fetch - " |
| 2699 | "fetch_anqp_in_progress=%d fetch_osu_icon_in_progress=%d", |
| 2700 | wpa_s->fetch_anqp_in_progress, |
| 2701 | wpa_s->fetch_osu_icon_in_progress); |
| 2702 | |
| 2703 | if (eloop_terminated() || !wpa_s->fetch_anqp_in_progress) { |
| 2704 | wpa_printf(MSG_DEBUG, "Interworking: Stop next-ANQP-fetch"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2705 | return; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2706 | } |
| 2707 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2708 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2709 | if (wpa_s->fetch_osu_icon_in_progress) { |
| 2710 | wpa_printf(MSG_DEBUG, "Interworking: Next icon (in progress)"); |
| 2711 | hs20_next_osu_icon(wpa_s); |
| 2712 | return; |
| 2713 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2714 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2715 | |
| 2716 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 2717 | if (!(bss->caps & IEEE80211_CAP_ESS)) |
| 2718 | continue; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2719 | if (!wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_INTERWORKING)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2720 | continue; /* AP does not support Interworking */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2721 | if (disallowed_bssid(wpa_s, bss->bssid) || |
| 2722 | disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) |
| 2723 | continue; /* Disallowed BSS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2724 | |
| 2725 | if (!(bss->flags & WPA_BSS_ANQP_FETCH_TRIED)) { |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2726 | if (bss->anqp == NULL) { |
| 2727 | bss->anqp = interworking_match_anqp_info(wpa_s, |
| 2728 | bss); |
| 2729 | if (bss->anqp) { |
| 2730 | /* Shared data already fetched */ |
| 2731 | continue; |
| 2732 | } |
| 2733 | bss->anqp = wpa_bss_anqp_alloc(); |
| 2734 | if (bss->anqp == NULL) |
| 2735 | break; |
| 2736 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2737 | found++; |
| 2738 | bss->flags |= WPA_BSS_ANQP_FETCH_TRIED; |
| 2739 | wpa_msg(wpa_s, MSG_INFO, "Starting ANQP fetch for " |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2740 | MACSTR " (HESSID " MACSTR ")", |
| 2741 | MAC2STR(bss->bssid), MAC2STR(bss->hessid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2742 | interworking_anqp_send_req(wpa_s, bss); |
| 2743 | break; |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | if (found == 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2748 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2749 | if (wpa_s->fetch_osu_info) { |
| 2750 | if (wpa_s->num_prov_found == 0 && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2751 | wpa_s->fetch_osu_waiting_scan && |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2752 | wpa_s->num_osu_scans < 3) { |
| 2753 | wpa_printf(MSG_DEBUG, "HS 2.0: No OSU providers seen - try to scan again"); |
| 2754 | hs20_start_osu_scan(wpa_s); |
| 2755 | return; |
| 2756 | } |
| 2757 | wpa_printf(MSG_DEBUG, "Interworking: Next icon"); |
| 2758 | hs20_osu_icon_fetch(wpa_s); |
| 2759 | return; |
| 2760 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2761 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2762 | wpa_msg(wpa_s, MSG_INFO, "ANQP fetch completed"); |
| 2763 | wpa_s->fetch_anqp_in_progress = 0; |
| 2764 | if (wpa_s->network_select) |
| 2765 | interworking_select_network(wpa_s); |
| 2766 | } |
| 2767 | } |
| 2768 | |
| 2769 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2770 | void interworking_start_fetch_anqp(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2771 | { |
| 2772 | struct wpa_bss *bss; |
| 2773 | |
| 2774 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) |
| 2775 | bss->flags &= ~WPA_BSS_ANQP_FETCH_TRIED; |
| 2776 | |
| 2777 | wpa_s->fetch_anqp_in_progress = 1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2778 | |
| 2779 | /* |
| 2780 | * Start actual ANQP operation from eloop call to make sure the loop |
| 2781 | * does not end up using excessive recursion. |
| 2782 | */ |
| 2783 | eloop_register_timeout(0, 0, interworking_continue_anqp, wpa_s, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | |
| 2787 | int interworking_fetch_anqp(struct wpa_supplicant *wpa_s) |
| 2788 | { |
| 2789 | if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) |
| 2790 | return 0; |
| 2791 | |
| 2792 | wpa_s->network_select = 0; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2793 | wpa_s->fetch_all_anqp = 1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2794 | wpa_s->fetch_osu_info = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2795 | |
| 2796 | interworking_start_fetch_anqp(wpa_s); |
| 2797 | |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
| 2801 | |
| 2802 | void interworking_stop_fetch_anqp(struct wpa_supplicant *wpa_s) |
| 2803 | { |
| 2804 | if (!wpa_s->fetch_anqp_in_progress) |
| 2805 | return; |
| 2806 | |
| 2807 | wpa_s->fetch_anqp_in_progress = 0; |
| 2808 | } |
| 2809 | |
| 2810 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2811 | int anqp_send_req(struct wpa_supplicant *wpa_s, const u8 *dst, int freq, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2812 | u16 info_ids[], size_t num_ids, u32 subtypes, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2813 | u32 mbo_subtypes) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2814 | { |
| 2815 | struct wpabuf *buf; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2816 | struct wpabuf *extra_buf = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2817 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2818 | struct wpa_bss *bss; |
| 2819 | int res; |
| 2820 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2821 | bss = wpa_bss_get_bssid(wpa_s, dst); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2822 | if (!bss && !freq) { |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 2823 | wpa_printf(MSG_WARNING, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2824 | "ANQP: Cannot send query without BSS freq info"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2825 | return -1; |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2828 | if (bss) |
| 2829 | wpa_bss_anqp_unshare_alloc(bss); |
| 2830 | if (bss && !freq) |
| 2831 | freq = bss->freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2832 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2833 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2834 | "ANQP: Query Request to " MACSTR " for %u id(s)", |
| 2835 | MAC2STR(dst), (unsigned int) num_ids); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2836 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 2837 | #ifdef CONFIG_HS20 |
| 2838 | if (subtypes != 0) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2839 | extra_buf = wpabuf_alloc(100); |
| 2840 | if (extra_buf == NULL) |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 2841 | return -1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2842 | hs20_put_anqp_req(subtypes, NULL, 0, extra_buf); |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 2843 | } |
| 2844 | #endif /* CONFIG_HS20 */ |
| 2845 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2846 | #ifdef CONFIG_MBO |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2847 | if (mbo_subtypes) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2848 | struct wpabuf *mbo; |
| 2849 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2850 | if (!bss) { |
| 2851 | wpa_printf(MSG_WARNING, |
| 2852 | "ANQP: Cannot send MBO query to unknown BSS " |
| 2853 | MACSTR, MAC2STR(dst)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2854 | wpabuf_free(extra_buf); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2855 | return -1; |
| 2856 | } |
| 2857 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2858 | mbo = mbo_build_anqp_buf(wpa_s, bss, mbo_subtypes); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2859 | if (mbo) { |
| 2860 | if (wpabuf_resize(&extra_buf, wpabuf_len(mbo))) { |
| 2861 | wpabuf_free(extra_buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2862 | wpabuf_free(mbo); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2863 | return -1; |
| 2864 | } |
| 2865 | wpabuf_put_buf(extra_buf, mbo); |
| 2866 | wpabuf_free(mbo); |
| 2867 | } |
| 2868 | } |
| 2869 | #endif /* CONFIG_MBO */ |
| 2870 | |
| 2871 | buf = anqp_build_req(info_ids, num_ids, extra_buf); |
| 2872 | wpabuf_free(extra_buf); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2873 | if (buf == NULL) |
| 2874 | return -1; |
| 2875 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2876 | res = gas_query_req(wpa_s->gas, dst, freq, 0, 0, buf, anqp_resp_cb, |
| 2877 | wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2878 | if (res < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2879 | wpa_msg(wpa_s, MSG_DEBUG, "ANQP: Failed to send Query Request"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2880 | wpabuf_free(buf); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2881 | ret = -1; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2882 | } else { |
| 2883 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2884 | "ANQP: Query started with dialog token %u", res); |
| 2885 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2886 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2887 | return ret; |
| 2888 | } |
| 2889 | |
| 2890 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2891 | static void anqp_add_extra(struct wpa_supplicant *wpa_s, |
| 2892 | struct wpa_bss_anqp *anqp, u16 info_id, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2893 | const u8 *data, size_t slen, bool protected_response) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2894 | { |
| 2895 | struct wpa_bss_anqp_elem *tmp, *elem = NULL; |
| 2896 | |
| 2897 | if (!anqp) |
| 2898 | return; |
| 2899 | |
| 2900 | dl_list_for_each(tmp, &anqp->anqp_elems, struct wpa_bss_anqp_elem, |
| 2901 | list) { |
| 2902 | if (tmp->infoid == info_id) { |
| 2903 | elem = tmp; |
| 2904 | break; |
| 2905 | } |
| 2906 | } |
| 2907 | |
| 2908 | if (!elem) { |
| 2909 | elem = os_zalloc(sizeof(*elem)); |
| 2910 | if (!elem) |
| 2911 | return; |
| 2912 | elem->infoid = info_id; |
| 2913 | dl_list_add(&anqp->anqp_elems, &elem->list); |
| 2914 | } else { |
| 2915 | wpabuf_free(elem->payload); |
| 2916 | } |
| 2917 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2918 | elem->protected_response = protected_response; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2919 | elem->payload = wpabuf_alloc_copy(data, slen); |
| 2920 | if (!elem->payload) { |
| 2921 | dl_list_del(&elem->list); |
| 2922 | os_free(elem); |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2927 | static void interworking_parse_venue_url(struct wpa_supplicant *wpa_s, |
| 2928 | const u8 *data, size_t len) |
| 2929 | { |
| 2930 | const u8 *pos = data, *end = data + len; |
| 2931 | char url[255]; |
| 2932 | |
| 2933 | while (end - pos >= 2) { |
| 2934 | u8 slen, num; |
| 2935 | |
| 2936 | slen = *pos++; |
| 2937 | if (slen < 1 || slen > end - pos) { |
| 2938 | wpa_printf(MSG_DEBUG, |
| 2939 | "ANQP: Truncated Venue URL Duple field"); |
| 2940 | return; |
| 2941 | } |
| 2942 | |
| 2943 | num = *pos++; |
| 2944 | os_memcpy(url, pos, slen - 1); |
| 2945 | url[slen - 1] = '\0'; |
| 2946 | wpa_msg(wpa_s, MSG_INFO, RX_VENUE_URL "%u %s", num, url); |
| 2947 | pos += slen - 1; |
| 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2952 | static void interworking_parse_rx_anqp_resp(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2953 | struct wpa_bss *bss, const u8 *sa, |
| 2954 | u16 info_id, |
Dmitry Shmidt | 0e58d9b | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2955 | const u8 *data, size_t slen, |
| 2956 | u8 dialog_token) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2957 | { |
| 2958 | const u8 *pos = data; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2959 | struct wpa_bss_anqp *anqp = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2960 | u8 type; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2961 | bool protected_response; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2962 | |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2963 | if (bss) |
| 2964 | anqp = bss->anqp; |
| 2965 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2966 | switch (info_id) { |
| 2967 | case ANQP_CAPABILITY_LIST: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2968 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2969 | " ANQP Capability list", MAC2STR(sa)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2970 | wpa_hexdump_ascii(MSG_DEBUG, "ANQP: Capability list", |
| 2971 | pos, slen); |
| 2972 | if (anqp) { |
| 2973 | wpabuf_free(anqp->capability_list); |
| 2974 | anqp->capability_list = wpabuf_alloc_copy(pos, slen); |
| 2975 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2976 | break; |
| 2977 | case ANQP_VENUE_NAME: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2978 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2979 | " Venue Name", MAC2STR(sa)); |
| 2980 | wpa_hexdump_ascii(MSG_DEBUG, "ANQP: Venue Name", pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2981 | if (anqp) { |
| 2982 | wpabuf_free(anqp->venue_name); |
| 2983 | anqp->venue_name = wpabuf_alloc_copy(pos, slen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2984 | } |
| 2985 | break; |
| 2986 | case ANQP_NETWORK_AUTH_TYPE: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2987 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2988 | " Network Authentication Type information", |
| 2989 | MAC2STR(sa)); |
| 2990 | wpa_hexdump_ascii(MSG_DEBUG, "ANQP: Network Authentication " |
| 2991 | "Type", pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2992 | if (anqp) { |
| 2993 | wpabuf_free(anqp->network_auth_type); |
| 2994 | anqp->network_auth_type = wpabuf_alloc_copy(pos, slen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2995 | } |
| 2996 | break; |
| 2997 | case ANQP_ROAMING_CONSORTIUM: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2998 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2999 | " Roaming Consortium list", MAC2STR(sa)); |
| 3000 | wpa_hexdump_ascii(MSG_DEBUG, "ANQP: Roaming Consortium", |
| 3001 | pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3002 | if (anqp) { |
| 3003 | wpabuf_free(anqp->roaming_consortium); |
| 3004 | anqp->roaming_consortium = wpabuf_alloc_copy(pos, slen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3005 | } |
| 3006 | break; |
| 3007 | case ANQP_IP_ADDR_TYPE_AVAILABILITY: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3008 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3009 | " IP Address Type Availability information", |
| 3010 | MAC2STR(sa)); |
| 3011 | wpa_hexdump(MSG_MSGDUMP, "ANQP: IP Address Availability", |
| 3012 | pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3013 | if (anqp) { |
| 3014 | wpabuf_free(anqp->ip_addr_type_availability); |
| 3015 | anqp->ip_addr_type_availability = |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3016 | wpabuf_alloc_copy(pos, slen); |
| 3017 | } |
| 3018 | break; |
| 3019 | case ANQP_NAI_REALM: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3020 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3021 | " NAI Realm list", MAC2STR(sa)); |
| 3022 | wpa_hexdump_ascii(MSG_DEBUG, "ANQP: NAI Realm", pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3023 | if (anqp) { |
| 3024 | wpabuf_free(anqp->nai_realm); |
| 3025 | anqp->nai_realm = wpabuf_alloc_copy(pos, slen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3026 | } |
| 3027 | break; |
| 3028 | case ANQP_3GPP_CELLULAR_NETWORK: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3029 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3030 | " 3GPP Cellular Network information", MAC2STR(sa)); |
| 3031 | wpa_hexdump_ascii(MSG_DEBUG, "ANQP: 3GPP Cellular Network", |
| 3032 | pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3033 | if (anqp) { |
| 3034 | wpabuf_free(anqp->anqp_3gpp); |
| 3035 | anqp->anqp_3gpp = wpabuf_alloc_copy(pos, slen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3036 | } |
| 3037 | break; |
| 3038 | case ANQP_DOMAIN_NAME: |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3039 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3040 | " Domain Name list", MAC2STR(sa)); |
| 3041 | wpa_hexdump_ascii(MSG_MSGDUMP, "ANQP: Domain Name", pos, slen); |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3042 | if (anqp) { |
| 3043 | wpabuf_free(anqp->domain_name); |
| 3044 | anqp->domain_name = wpabuf_alloc_copy(pos, slen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3045 | } |
| 3046 | break; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3047 | #ifdef CONFIG_FILS |
| 3048 | case ANQP_FILS_REALM_INFO: |
| 3049 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR |
| 3050 | " FILS Realm Information", MAC2STR(sa)); |
| 3051 | wpa_hexdump_ascii(MSG_MSGDUMP, "ANQP: FILS Realm Information", |
| 3052 | pos, slen); |
| 3053 | if (anqp) { |
| 3054 | wpabuf_free(anqp->fils_realm_info); |
| 3055 | anqp->fils_realm_info = wpabuf_alloc_copy(pos, slen); |
| 3056 | } |
| 3057 | break; |
| 3058 | #endif /* CONFIG_FILS */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 3059 | case ANQP_VENUE_URL: |
| 3060 | wpa_msg(wpa_s, MSG_INFO, RX_ANQP MACSTR " Venue URL", |
| 3061 | MAC2STR(sa)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3062 | protected_response = pmf_in_use(wpa_s, sa); |
| 3063 | anqp_add_extra(wpa_s, anqp, info_id, pos, slen, |
| 3064 | protected_response); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 3065 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3066 | if (!protected_response) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 3067 | wpa_printf(MSG_DEBUG, |
| 3068 | "ANQP: Ignore Venue URL since PMF was not enabled"); |
| 3069 | break; |
| 3070 | } |
| 3071 | interworking_parse_venue_url(wpa_s, pos, slen); |
| 3072 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3073 | case ANQP_VENDOR_SPECIFIC: |
| 3074 | if (slen < 3) |
| 3075 | return; |
| 3076 | |
| 3077 | switch (WPA_GET_BE24(pos)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3078 | case OUI_WFA: |
| 3079 | pos += 3; |
| 3080 | slen -= 3; |
| 3081 | |
| 3082 | if (slen < 1) |
| 3083 | return; |
| 3084 | type = *pos++; |
| 3085 | slen--; |
| 3086 | |
| 3087 | switch (type) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3088 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3089 | case HS20_ANQP_OUI_TYPE: |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3090 | hs20_parse_rx_hs20_anqp_resp(wpa_s, bss, sa, |
Dmitry Shmidt | 0e58d9b | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 3091 | pos, slen, |
| 3092 | dialog_token); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3093 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3094 | #endif /* CONFIG_HS20 */ |
| 3095 | #ifdef CONFIG_MBO |
| 3096 | case MBO_ANQP_OUI_TYPE: |
| 3097 | mbo_parse_rx_anqp_resp(wpa_s, bss, sa, |
| 3098 | pos, slen); |
| 3099 | break; |
| 3100 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3101 | default: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3102 | wpa_msg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3103 | "ANQP: Unsupported ANQP vendor type %u", |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3104 | type); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3105 | break; |
| 3106 | } |
| 3107 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3108 | default: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3109 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3110 | "Interworking: Unsupported vendor-specific ANQP OUI %06x", |
| 3111 | WPA_GET_BE24(pos)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3112 | return; |
| 3113 | } |
| 3114 | break; |
| 3115 | default: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3116 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3117 | "Interworking: Unsupported ANQP Info ID %u", info_id); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3118 | anqp_add_extra(wpa_s, anqp, info_id, data, slen, |
| 3119 | pmf_in_use(wpa_s, sa)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3120 | break; |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | |
| 3125 | void anqp_resp_cb(void *ctx, const u8 *dst, u8 dialog_token, |
| 3126 | enum gas_query_result result, |
| 3127 | const struct wpabuf *adv_proto, |
| 3128 | const struct wpabuf *resp, u16 status_code) |
| 3129 | { |
| 3130 | struct wpa_supplicant *wpa_s = ctx; |
| 3131 | const u8 *pos; |
| 3132 | const u8 *end; |
| 3133 | u16 info_id; |
| 3134 | u16 slen; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3135 | struct wpa_bss *bss = NULL, *tmp; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3136 | const char *anqp_result = "SUCCESS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3137 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3138 | wpa_printf(MSG_DEBUG, "Interworking: anqp_resp_cb dst=" MACSTR |
| 3139 | " dialog_token=%u result=%d status_code=%u", |
| 3140 | MAC2STR(dst), dialog_token, result, status_code); |
| 3141 | if (result != GAS_QUERY_SUCCESS) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3142 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3143 | if (wpa_s->fetch_osu_icon_in_progress) |
| 3144 | hs20_icon_fetch_failed(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3145 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3146 | anqp_result = "FAILURE"; |
| 3147 | goto out; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3148 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3149 | |
| 3150 | pos = wpabuf_head(adv_proto); |
| 3151 | if (wpabuf_len(adv_proto) < 4 || pos[0] != WLAN_EID_ADV_PROTO || |
| 3152 | pos[1] < 2 || pos[3] != ACCESS_NETWORK_QUERY_PROTOCOL) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3153 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3154 | "ANQP: Unexpected Advertisement Protocol in response"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3155 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3156 | if (wpa_s->fetch_osu_icon_in_progress) |
| 3157 | hs20_icon_fetch_failed(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3158 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3159 | anqp_result = "INVALID_FRAME"; |
| 3160 | goto out; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3161 | } |
| 3162 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3163 | /* |
| 3164 | * If possible, select the BSS entry based on which BSS entry was used |
| 3165 | * for the request. This can help in cases where multiple BSS entries |
| 3166 | * may exist for the same AP. |
| 3167 | */ |
| 3168 | dl_list_for_each_reverse(tmp, &wpa_s->bss, struct wpa_bss, list) { |
| 3169 | if (tmp == wpa_s->interworking_gas_bss && |
| 3170 | os_memcmp(tmp->bssid, dst, ETH_ALEN) == 0) { |
| 3171 | bss = tmp; |
| 3172 | break; |
| 3173 | } |
| 3174 | } |
| 3175 | if (bss == NULL) |
| 3176 | bss = wpa_bss_get_bssid(wpa_s, dst); |
| 3177 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3178 | pos = wpabuf_head(resp); |
| 3179 | end = pos + wpabuf_len(resp); |
| 3180 | |
| 3181 | while (pos < end) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3182 | unsigned int left = end - pos; |
| 3183 | |
| 3184 | if (left < 4) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3185 | wpa_msg(wpa_s, MSG_DEBUG, "ANQP: Invalid element"); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3186 | anqp_result = "INVALID_FRAME"; |
| 3187 | goto out_parse_done; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3188 | } |
| 3189 | info_id = WPA_GET_LE16(pos); |
| 3190 | pos += 2; |
| 3191 | slen = WPA_GET_LE16(pos); |
| 3192 | pos += 2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3193 | left -= 4; |
| 3194 | if (left < slen) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3195 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3196 | "ANQP: Invalid element length for Info ID %u", |
| 3197 | info_id); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3198 | anqp_result = "INVALID_FRAME"; |
| 3199 | goto out_parse_done; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3200 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3201 | interworking_parse_rx_anqp_resp(wpa_s, bss, dst, info_id, pos, |
Dmitry Shmidt | 0e58d9b | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 3202 | slen, dialog_token); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3203 | pos += slen; |
| 3204 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3205 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3206 | out_parse_done: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3207 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3208 | hs20_notify_parse_done(wpa_s); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3209 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3210 | out: |
| 3211 | wpa_msg(wpa_s, MSG_INFO, ANQP_QUERY_DONE "addr=" MACSTR " result=%s", |
| 3212 | MAC2STR(dst), anqp_result); |
Roshan Pius | 04a9d74 | 2016-12-12 12:40:46 -0800 | [diff] [blame] | 3213 | wpas_notify_anqp_query_done(wpa_s, dst, anqp_result, bss ? bss->anqp : NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | |
| 3217 | static void interworking_scan_res_handler(struct wpa_supplicant *wpa_s, |
| 3218 | struct wpa_scan_results *scan_res) |
| 3219 | { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3220 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3221 | "Interworking: Scan results available - start ANQP fetch"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3222 | interworking_start_fetch_anqp(wpa_s); |
| 3223 | } |
| 3224 | |
| 3225 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3226 | int interworking_select(struct wpa_supplicant *wpa_s, int auto_select, |
| 3227 | int *freqs) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3228 | { |
| 3229 | interworking_stop_fetch_anqp(wpa_s); |
| 3230 | wpa_s->network_select = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3231 | wpa_s->auto_network_select = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3232 | wpa_s->auto_select = !!auto_select; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 3233 | wpa_s->fetch_all_anqp = 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3234 | wpa_s->fetch_osu_info = 0; |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3235 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3236 | "Interworking: Start scan for network selection"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3237 | wpa_s->scan_res_handler = interworking_scan_res_handler; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3238 | wpa_s->normal_scans = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3239 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3240 | os_free(wpa_s->manual_scan_freqs); |
| 3241 | wpa_s->manual_scan_freqs = freqs; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 3242 | wpa_s->after_wps = 0; |
| 3243 | wpa_s->known_wps_freq = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3244 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 3245 | |
| 3246 | return 0; |
| 3247 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3248 | |
| 3249 | |
| 3250 | static void gas_resp_cb(void *ctx, const u8 *addr, u8 dialog_token, |
| 3251 | enum gas_query_result result, |
| 3252 | const struct wpabuf *adv_proto, |
| 3253 | const struct wpabuf *resp, u16 status_code) |
| 3254 | { |
| 3255 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3256 | struct wpabuf *n; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3257 | |
| 3258 | wpa_msg(wpa_s, MSG_INFO, GAS_RESPONSE_INFO "addr=" MACSTR |
| 3259 | " dialog_token=%d status_code=%d resp_len=%d", |
| 3260 | MAC2STR(addr), dialog_token, status_code, |
| 3261 | resp ? (int) wpabuf_len(resp) : -1); |
| 3262 | if (!resp) |
| 3263 | return; |
| 3264 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3265 | n = wpabuf_dup(resp); |
| 3266 | if (n == NULL) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3267 | return; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3268 | wpabuf_free(wpa_s->prev_gas_resp); |
| 3269 | wpa_s->prev_gas_resp = wpa_s->last_gas_resp; |
| 3270 | os_memcpy(wpa_s->prev_gas_addr, wpa_s->last_gas_addr, ETH_ALEN); |
| 3271 | wpa_s->prev_gas_dialog_token = wpa_s->last_gas_dialog_token; |
| 3272 | wpa_s->last_gas_resp = n; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3273 | os_memcpy(wpa_s->last_gas_addr, addr, ETH_ALEN); |
| 3274 | wpa_s->last_gas_dialog_token = dialog_token; |
| 3275 | } |
| 3276 | |
| 3277 | |
| 3278 | int gas_send_request(struct wpa_supplicant *wpa_s, const u8 *dst, |
| 3279 | const struct wpabuf *adv_proto, |
| 3280 | const struct wpabuf *query) |
| 3281 | { |
| 3282 | struct wpabuf *buf; |
| 3283 | int ret = 0; |
| 3284 | int freq; |
| 3285 | struct wpa_bss *bss; |
| 3286 | int res; |
| 3287 | size_t len; |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 3288 | u8 query_resp_len_limit = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3289 | |
| 3290 | freq = wpa_s->assoc_freq; |
| 3291 | bss = wpa_bss_get_bssid(wpa_s, dst); |
| 3292 | if (bss) |
| 3293 | freq = bss->freq; |
| 3294 | if (freq <= 0) |
| 3295 | return -1; |
| 3296 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3297 | wpa_msg(wpa_s, MSG_DEBUG, "GAS request to " MACSTR " (freq %d MHz)", |
| 3298 | MAC2STR(dst), freq); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3299 | wpa_hexdump_buf(MSG_DEBUG, "Advertisement Protocol ID", adv_proto); |
| 3300 | wpa_hexdump_buf(MSG_DEBUG, "GAS Query", query); |
| 3301 | |
| 3302 | len = 3 + wpabuf_len(adv_proto) + 2; |
| 3303 | if (query) |
| 3304 | len += wpabuf_len(query); |
| 3305 | buf = gas_build_initial_req(0, len); |
| 3306 | if (buf == NULL) |
| 3307 | return -1; |
| 3308 | |
| 3309 | /* Advertisement Protocol IE */ |
| 3310 | wpabuf_put_u8(buf, WLAN_EID_ADV_PROTO); |
| 3311 | wpabuf_put_u8(buf, 1 + wpabuf_len(adv_proto)); /* Length */ |
Dmitry Shmidt | 7f0b69e | 2014-07-28 10:35:20 -0700 | [diff] [blame] | 3312 | wpabuf_put_u8(buf, query_resp_len_limit & 0x7f); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3313 | wpabuf_put_buf(buf, adv_proto); |
| 3314 | |
| 3315 | /* GAS Query */ |
| 3316 | if (query) { |
| 3317 | wpabuf_put_le16(buf, wpabuf_len(query)); |
| 3318 | wpabuf_put_buf(buf, query); |
| 3319 | } else |
| 3320 | wpabuf_put_le16(buf, 0); |
| 3321 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3322 | res = gas_query_req(wpa_s->gas, dst, freq, 0, 0, buf, gas_resp_cb, |
| 3323 | wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3324 | if (res < 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3325 | wpa_msg(wpa_s, MSG_DEBUG, "GAS: Failed to send Query Request"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3326 | wpabuf_free(buf); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3327 | ret = -1; |
| 3328 | } else |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3329 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3330 | "GAS: Query started with dialog token %u", res); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3331 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3332 | return ret; |
| 3333 | } |