2 * Interworking (IEEE 802.11u)
3 * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
4 * Copyright (c) 2011-2014, Jouni Malinen <j@w1.fi>
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
13 #include "common/ieee802_11_defs.h"
14 #include "common/gas.h"
15 #include "common/wpa_ctrl.h"
16 #include "utils/pcsc_funcs.h"
17 #include "utils/eloop.h"
18 #include "drivers/driver.h"
19 #include "eap_common/eap_defs.h"
20 #include "eap_peer/eap.h"
21 #include "eap_peer/eap_methods.h"
22 #include "eapol_supp/eapol_supp_sm.h"
23 #include "rsn_supp/wpa.h"
24 #include "wpa_supplicant_i.h"
26 #include "config_ssid.h"
31 #include "gas_query.h"
32 #include "hs20_supplicant.h"
33 #include "interworking.h"
36 #if defined(EAP_SIM) | defined(EAP_SIM_DYNAMIC)
37 #define INTERWORKING_3GPP
39 #if defined(EAP_AKA) | defined(EAP_AKA_DYNAMIC)
40 #define INTERWORKING_3GPP
42 #if defined(EAP_AKA_PRIME) | defined(EAP_AKA_PRIME_DYNAMIC)
43 #define INTERWORKING_3GPP
48 static void interworking_next_anqp_fetch(struct wpa_supplicant
*wpa_s
);
49 static struct wpa_cred
* interworking_credentials_available_realm(
50 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
52 static struct wpa_cred
* interworking_credentials_available_3gpp(
53 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
57 static int cred_prio_cmp(const struct wpa_cred
*a
, const struct wpa_cred
*b
)
59 if (a
->priority
> b
->priority
)
61 if (a
->priority
< b
->priority
)
63 if (a
->provisioning_sp
== NULL
|| b
->provisioning_sp
== NULL
||
64 os_strcmp(a
->provisioning_sp
, b
->provisioning_sp
) != 0)
66 if (a
->sp_priority
< b
->sp_priority
)
68 if (a
->sp_priority
> b
->sp_priority
)
74 static void interworking_reconnect(struct wpa_supplicant
*wpa_s
)
78 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
79 wpa_supplicant_cancel_sched_scan(wpa_s
);
80 wpa_s
->own_disconnect_req
= 1;
81 wpa_supplicant_deauthenticate(wpa_s
,
82 WLAN_REASON_DEAUTH_LEAVING
);
84 wpa_s
->disconnected
= 0;
85 wpa_s
->reassociate
= 1;
86 tried
= wpa_s
->interworking_fast_assoc_tried
;
87 wpa_s
->interworking_fast_assoc_tried
= 1;
89 if (!tried
&& wpa_supplicant_fast_associate(wpa_s
) >= 0)
92 wpa_s
->interworking_fast_assoc_tried
= 0;
93 wpa_supplicant_req_scan(wpa_s
, 0, 0);
97 static struct wpabuf
* anqp_build_req(u16 info_ids
[], size_t num_ids
,
104 buf
= gas_anqp_build_initial_req(0, 4 + num_ids
* 2 +
105 (extra
? wpabuf_len(extra
) : 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
);
116 wpabuf_put_buf(buf
, extra
);
118 gas_anqp_set_len(buf
);
124 static void interworking_anqp_resp_cb(void *ctx
, const u8
*dst
,
126 enum gas_query_result result
,
127 const struct wpabuf
*adv_proto
,
128 const struct wpabuf
*resp
,
131 struct wpa_supplicant
*wpa_s
= ctx
;
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
);
136 anqp_resp_cb(wpa_s
, dst
, dialog_token
, result
, adv_proto
, resp
,
138 interworking_next_anqp_fetch(wpa_s
);
142 static int cred_with_roaming_consortium(struct wpa_supplicant
*wpa_s
)
144 struct wpa_cred
*cred
;
146 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
147 if (cred
->roaming_consortium_len
)
149 if (cred
->required_roaming_consortium_len
)
151 if (cred
->num_roaming_consortiums
)
158 static int cred_with_3gpp(struct wpa_supplicant
*wpa_s
)
160 struct wpa_cred
*cred
;
162 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
163 if (cred
->pcsc
|| cred
->imsi
)
170 static int cred_with_nai_realm(struct wpa_supplicant
*wpa_s
)
172 struct wpa_cred
*cred
;
174 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
175 if (cred
->pcsc
|| cred
->imsi
)
177 if (!cred
->eap_method
)
186 static int cred_with_domain(struct wpa_supplicant
*wpa_s
)
188 struct wpa_cred
*cred
;
190 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
191 if (cred
->domain
|| cred
->pcsc
|| cred
->imsi
||
192 cred
->roaming_partner
)
201 static int cred_with_min_backhaul(struct wpa_supplicant
*wpa_s
)
203 struct wpa_cred
*cred
;
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
)
216 static int cred_with_conn_capab(struct wpa_supplicant
*wpa_s
)
218 struct wpa_cred
*cred
;
220 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
221 if (cred
->num_req_conn_capab
)
227 #endif /* CONFIG_HS20 */
230 static int additional_roaming_consortiums(struct wpa_bss
*bss
)
233 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
234 if (ie
== NULL
|| ie
[1] == 0)
236 return ie
[2]; /* Number of ANQP OIs */
240 static void interworking_continue_anqp(void *eloop_ctx
, void *sock_ctx
)
242 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
243 interworking_next_anqp_fetch(wpa_s
);
247 static int interworking_anqp_send_req(struct wpa_supplicant
*wpa_s
,
254 size_t num_info_ids
= 0;
255 struct wpabuf
*extra
= NULL
;
256 int all
= wpa_s
->fetch_all_anqp
;
258 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: ANQP Query Request to " MACSTR
,
259 MAC2STR(bss
->bssid
));
260 wpa_s
->interworking_gas_bss
= bss
;
262 info_ids
[num_info_ids
++] = ANQP_CAPABILITY_LIST
;
264 info_ids
[num_info_ids
++] = ANQP_VENUE_NAME
;
265 info_ids
[num_info_ids
++] = ANQP_NETWORK_AUTH_TYPE
;
267 if (all
|| (cred_with_roaming_consortium(wpa_s
) &&
268 additional_roaming_consortiums(bss
)))
269 info_ids
[num_info_ids
++] = ANQP_ROAMING_CONSORTIUM
;
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
;
274 if (all
|| cred_with_3gpp(wpa_s
)) {
275 info_ids
[num_info_ids
++] = ANQP_3GPP_CELLULAR_NETWORK
;
276 wpa_supplicant_scard_init(wpa_s
, NULL
);
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);
284 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
287 extra
= wpabuf_alloc(100);
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
);
299 HS20_STYPE_OPERATOR_FRIENDLY_NAME
);
300 if (all
|| cred_with_min_backhaul(wpa_s
))
301 wpabuf_put_u8(extra
, HS20_STYPE_WAN_METRICS
);
302 if (all
|| cred_with_conn_capab(wpa_s
))
303 wpabuf_put_u8(extra
, HS20_STYPE_CONNECTION_CAPABILITY
);
305 wpabuf_put_u8(extra
, HS20_STYPE_OPERATING_CLASS
);
307 wpabuf_put_u8(extra
, HS20_STYPE_OSU_PROVIDERS_LIST
);
308 wpabuf_put_u8(extra
, HS20_STYPE_OSU_PROVIDERS_NAI_LIST
);
310 gas_anqp_set_element_len(extra
, len_pos
);
312 #endif /* CONFIG_HS20 */
314 buf
= anqp_build_req(info_ids
, num_info_ids
, extra
);
319 res
= gas_query_req(wpa_s
->gas
, bss
->bssid
, bss
->freq
, 0, buf
,
320 interworking_anqp_resp_cb
, wpa_s
);
322 wpa_msg(wpa_s
, MSG_DEBUG
, "ANQP: Failed to send Query Request");
325 eloop_register_timeout(0, 0, interworking_continue_anqp
, wpa_s
,
328 wpa_msg(wpa_s
, MSG_DEBUG
,
329 "ANQP: Query started with dialog token %u", res
);
335 struct nai_realm_eap
{
338 enum nai_realm_eap_auth_inner_non_eap inner_non_eap
;
340 u8 tunneled_cred_type
;
347 struct nai_realm_eap
*eap
;
351 static void nai_realm_free(struct nai_realm
*realms
, u16 count
)
357 for (i
= 0; i
< count
; i
++) {
358 os_free(realms
[i
].eap
);
359 os_free(realms
[i
].realm
);
365 static const u8
* nai_realm_parse_eap(struct nai_realm_eap
*e
, const u8
*pos
,
368 u8 elen
, auth_count
, a
;
372 wpa_printf(MSG_DEBUG
, "No room for EAP Method fixed fields");
377 if (elen
> end
- pos
|| elen
< 2) {
378 wpa_printf(MSG_DEBUG
, "No room for EAP Method subfield");
384 wpa_printf(MSG_DEBUG
, "EAP Method: len=%u method=%u auth_count=%u",
385 elen
, e
->method
, auth_count
);
387 for (a
= 0; a
< auth_count
; a
++) {
391 wpa_printf(MSG_DEBUG
,
392 "No room for Authentication Parameter subfield header");
398 if (len
> end
- pos
) {
399 wpa_printf(MSG_DEBUG
,
400 "No room for Authentication Parameter subfield");
405 case NAI_REALM_EAP_AUTH_NON_EAP_INNER_AUTH
:
408 e
->inner_non_eap
= *pos
;
409 if (e
->method
!= EAP_TYPE_TTLS
)
412 case NAI_REALM_INNER_NON_EAP_PAP
:
413 wpa_printf(MSG_DEBUG
, "EAP-TTLS/PAP");
415 case NAI_REALM_INNER_NON_EAP_CHAP
:
416 wpa_printf(MSG_DEBUG
, "EAP-TTLS/CHAP");
418 case NAI_REALM_INNER_NON_EAP_MSCHAP
:
419 wpa_printf(MSG_DEBUG
, "EAP-TTLS/MSCHAP");
421 case NAI_REALM_INNER_NON_EAP_MSCHAPV2
:
422 wpa_printf(MSG_DEBUG
, "EAP-TTLS/MSCHAPV2");
426 case NAI_REALM_EAP_AUTH_INNER_AUTH_EAP_METHOD
:
429 e
->inner_method
= *pos
;
430 wpa_printf(MSG_DEBUG
, "Inner EAP method: %u",
433 case NAI_REALM_EAP_AUTH_CRED_TYPE
:
437 wpa_printf(MSG_DEBUG
, "Credential Type: %u",
440 case NAI_REALM_EAP_AUTH_TUNNELED_CRED_TYPE
:
443 e
->tunneled_cred_type
= *pos
;
444 wpa_printf(MSG_DEBUG
, "Tunneled EAP Method Credential "
445 "Type: %u", e
->tunneled_cred_type
);
448 wpa_printf(MSG_DEBUG
, "Unsupported Authentication "
449 "Parameter: id=%u len=%u", id
, len
);
450 wpa_hexdump(MSG_DEBUG
, "Authentication Parameter "
462 static const u8
* nai_realm_parse_realm(struct nai_realm
*r
, const u8
*pos
,
470 wpa_printf(MSG_DEBUG
, "No room for NAI Realm Data "
475 len
= WPA_GET_LE16(pos
); /* NAI Realm Data field Length */
477 if (len
> end
- pos
|| len
< 3) {
478 wpa_printf(MSG_DEBUG
, "No room for NAI Realm Data "
480 len
, (unsigned int) (end
- pos
));
485 r
->encoding
= *pos
++;
487 if (realm_len
> f_end
- pos
) {
488 wpa_printf(MSG_DEBUG
, "No room for NAI Realm "
490 realm_len
, (unsigned int) (f_end
- pos
));
493 wpa_hexdump_ascii(MSG_DEBUG
, "NAI Realm", pos
, realm_len
);
494 r
->realm
= dup_binstr(pos
, realm_len
);
495 if (r
->realm
== NULL
)
499 if (f_end
- pos
< 1) {
500 wpa_printf(MSG_DEBUG
, "No room for EAP Method Count");
503 r
->eap_count
= *pos
++;
504 wpa_printf(MSG_DEBUG
, "EAP Count: %u", r
->eap_count
);
505 if (r
->eap_count
* 3 > f_end
- pos
) {
506 wpa_printf(MSG_DEBUG
, "No room for EAP Methods");
509 r
->eap
= os_calloc(r
->eap_count
, sizeof(struct nai_realm_eap
));
513 for (e
= 0; e
< r
->eap_count
; e
++) {
514 pos
= nai_realm_parse_eap(&r
->eap
[e
], pos
, f_end
);
523 static struct nai_realm
* nai_realm_parse(struct wpabuf
*anqp
, u16
*count
)
525 struct nai_realm
*realm
;
532 left
= wpabuf_len(anqp
);
536 pos
= wpabuf_head_u8(anqp
);
538 num
= WPA_GET_LE16(pos
);
539 wpa_printf(MSG_DEBUG
, "NAI Realm Count: %u", num
);
543 if (num
> left
/ 5) {
544 wpa_printf(MSG_DEBUG
, "Invalid NAI Realm Count %u - not "
545 "enough data (%u octets) for that many realms",
546 num
, (unsigned int) left
);
550 realm
= os_calloc(num
, sizeof(struct nai_realm
));
554 for (i
= 0; i
< num
; i
++) {
555 pos
= nai_realm_parse_realm(&realm
[i
], pos
, end
);
557 nai_realm_free(realm
, num
);
567 static int nai_realm_match(struct nai_realm
*realm
, const char *home_realm
)
569 char *tmp
, *pos
, *end
;
572 if (realm
->realm
== NULL
|| home_realm
== NULL
)
575 if (os_strchr(realm
->realm
, ';') == NULL
)
576 return os_strcasecmp(realm
->realm
, home_realm
) == 0;
578 tmp
= os_strdup(realm
->realm
);
584 end
= os_strchr(pos
, ';');
587 if (os_strcasecmp(pos
, home_realm
) == 0) {
602 static int nai_realm_cred_username(struct wpa_supplicant
*wpa_s
,
603 struct nai_realm_eap
*eap
)
605 if (eap_get_name(EAP_VENDOR_IETF
, eap
->method
) == NULL
) {
606 wpa_msg(wpa_s
, MSG_DEBUG
,
607 "nai-realm-cred-username: EAP method not supported: %d",
609 return 0; /* method not supported */
612 if (eap
->method
!= EAP_TYPE_TTLS
&& eap
->method
!= EAP_TYPE_PEAP
&&
613 eap
->method
!= EAP_TYPE_FAST
) {
614 /* Only tunneled methods with username/password supported */
615 wpa_msg(wpa_s
, MSG_DEBUG
,
616 "nai-realm-cred-username: Method: %d is not TTLS, PEAP, or FAST",
621 if (eap
->method
== EAP_TYPE_PEAP
|| eap
->method
== EAP_TYPE_FAST
) {
622 if (eap
->inner_method
&&
623 eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
) == NULL
) {
624 wpa_msg(wpa_s
, MSG_DEBUG
,
625 "nai-realm-cred-username: PEAP/FAST: Inner method not supported: %d",
629 if (!eap
->inner_method
&&
630 eap_get_name(EAP_VENDOR_IETF
, EAP_TYPE_MSCHAPV2
) == NULL
) {
631 wpa_msg(wpa_s
, MSG_DEBUG
,
632 "nai-realm-cred-username: MSCHAPv2 not supported");
637 if (eap
->method
== EAP_TYPE_TTLS
) {
638 if (eap
->inner_method
== 0 && eap
->inner_non_eap
== 0)
639 return 1; /* Assume TTLS/MSCHAPv2 is used */
640 if (eap
->inner_method
&&
641 eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
) == NULL
) {
642 wpa_msg(wpa_s
, MSG_DEBUG
,
643 "nai-realm-cred-username: TTLS, but inner not supported: %d",
647 if (eap
->inner_non_eap
&&
648 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_PAP
&&
649 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_CHAP
&&
650 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_MSCHAP
&&
651 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_MSCHAPV2
) {
652 wpa_msg(wpa_s
, MSG_DEBUG
,
653 "nai-realm-cred-username: TTLS, inner-non-eap not supported: %d",
659 if (eap
->inner_method
&&
660 eap
->inner_method
!= EAP_TYPE_GTC
&&
661 eap
->inner_method
!= EAP_TYPE_MSCHAPV2
) {
662 wpa_msg(wpa_s
, MSG_DEBUG
,
663 "nai-realm-cred-username: inner-method not GTC or MSCHAPv2: %d",
672 static int nai_realm_cred_cert(struct wpa_supplicant
*wpa_s
,
673 struct nai_realm_eap
*eap
)
675 if (eap_get_name(EAP_VENDOR_IETF
, eap
->method
) == NULL
) {
676 wpa_msg(wpa_s
, MSG_DEBUG
,
677 "nai-realm-cred-cert: Method not supported: %d",
679 return 0; /* method not supported */
682 if (eap
->method
!= EAP_TYPE_TLS
) {
683 /* Only EAP-TLS supported for credential authentication */
684 wpa_msg(wpa_s
, MSG_DEBUG
,
685 "nai-realm-cred-cert: Method not TLS: %d",
694 static struct nai_realm_eap
* nai_realm_find_eap(struct wpa_supplicant
*wpa_s
,
695 struct wpa_cred
*cred
,
696 struct nai_realm
*realm
)
700 if (cred
->username
== NULL
||
701 cred
->username
[0] == '\0' ||
702 ((cred
->password
== NULL
||
703 cred
->password
[0] == '\0') &&
704 (cred
->private_key
== NULL
||
705 cred
->private_key
[0] == '\0'))) {
706 wpa_msg(wpa_s
, MSG_DEBUG
,
707 "nai-realm-find-eap: incomplete cred info: username: %s password: %s private_key: %s",
708 cred
->username
? cred
->username
: "NULL",
709 cred
->password
? cred
->password
: "NULL",
710 cred
->private_key
? cred
->private_key
: "NULL");
714 for (e
= 0; e
< realm
->eap_count
; e
++) {
715 struct nai_realm_eap
*eap
= &realm
->eap
[e
];
716 if (cred
->password
&& cred
->password
[0] &&
717 nai_realm_cred_username(wpa_s
, eap
))
719 if (cred
->private_key
&& cred
->private_key
[0] &&
720 nai_realm_cred_cert(wpa_s
, eap
))
728 #ifdef INTERWORKING_3GPP
730 static int plmn_id_match(struct wpabuf
*anqp
, const char *imsi
, int mnc_len
)
732 u8 plmn
[3], plmn2
[3];
737 * See Annex A of 3GPP TS 24.234 v8.1.0 for description. The network
738 * operator is allowed to include only two digits of the MNC, so allow
739 * matches based on both two and three digit MNC assumptions. Since some
740 * SIM/USIM cards may not expose MNC length conveniently, we may be
741 * provided the default MNC length 3 here and as such, checking with MNC
742 * length 2 is justifiable even though 3GPP TS 24.234 does not mention
743 * that case. Anyway, MCC/MNC pair where both 2 and 3 digit MNC is used
744 * with otherwise matching values would not be good idea in general, so
745 * this should not result in selecting incorrect networks.
747 /* Match with 3 digit MNC */
748 plmn
[0] = (imsi
[0] - '0') | ((imsi
[1] - '0') << 4);
749 plmn
[1] = (imsi
[2] - '0') | ((imsi
[5] - '0') << 4);
750 plmn
[2] = (imsi
[3] - '0') | ((imsi
[4] - '0') << 4);
751 /* Match with 2 digit MNC */
752 plmn2
[0] = (imsi
[0] - '0') | ((imsi
[1] - '0') << 4);
753 plmn2
[1] = (imsi
[2] - '0') | 0xf0;
754 plmn2
[2] = (imsi
[3] - '0') | ((imsi
[4] - '0') << 4);
758 pos
= wpabuf_head_u8(anqp
);
759 end
= pos
+ wpabuf_len(anqp
);
763 wpa_printf(MSG_DEBUG
, "Unsupported GUD version 0x%x", *pos
);
768 if (udhl
> end
- pos
) {
769 wpa_printf(MSG_DEBUG
, "Invalid UDHL");
774 wpa_printf(MSG_DEBUG
, "Interworking: Matching against MCC/MNC alternatives: %02x:%02x:%02x or %02x:%02x:%02x (IMSI %s, MNC length %d)",
775 plmn
[0], plmn
[1], plmn
[2], plmn2
[0], plmn2
[1], plmn2
[2],
778 while (end
- pos
>= 2) {
787 if (iei
== 0 && len
> 0) {
790 wpa_hexdump(MSG_DEBUG
, "Interworking: PLMN List information element",
793 for (i
= 0; i
< num
; i
++) {
796 if (os_memcmp(pos
, plmn
, 3) == 0 ||
797 os_memcmp(pos
, plmn2
, 3) == 0)
798 return 1; /* Found matching PLMN */
802 wpa_hexdump(MSG_DEBUG
, "Interworking: Unrecognized 3GPP information element",
813 static int build_root_nai(char *nai
, size_t nai_len
, const char *imsi
,
814 size_t mnc_len
, char prefix
)
816 const char *sep
, *msin
;
818 size_t msin_len
, plmn_len
;
821 * TS 23.003, Clause 14 (3GPP to WLAN Interworking)
823 * <aka:0|sim:1><IMSI>@wlan.mnc<MNC>.mcc<MCC>.3gppnetwork.org
824 * <MNC> is zero-padded to three digits in case two-digit MNC is used
827 if (imsi
== NULL
|| os_strlen(imsi
) > 16) {
828 wpa_printf(MSG_DEBUG
, "No valid IMSI available");
831 sep
= os_strchr(imsi
, '-');
833 plmn_len
= sep
- imsi
;
835 } else if (mnc_len
&& os_strlen(imsi
) >= 3 + mnc_len
) {
836 plmn_len
= 3 + mnc_len
;
837 msin
= imsi
+ plmn_len
;
840 if (plmn_len
!= 5 && plmn_len
!= 6)
842 msin_len
= os_strlen(msin
);
848 os_memcpy(pos
, imsi
, plmn_len
);
850 os_memcpy(pos
, msin
, msin_len
);
852 pos
+= os_snprintf(pos
, end
- pos
, "@wlan.mnc");
862 os_snprintf(pos
, end
- pos
, ".mcc%c%c%c.3gppnetwork.org",
863 imsi
[0], imsi
[1], imsi
[2]);
869 static int set_root_nai(struct wpa_ssid
*ssid
, const char *imsi
, char prefix
)
872 if (build_root_nai(nai
, sizeof(nai
), imsi
, 0, prefix
) < 0)
874 return wpa_config_set_quoted(ssid
, "identity", nai
);
877 #endif /* INTERWORKING_3GPP */
880 static int already_connected(struct wpa_supplicant
*wpa_s
,
881 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
883 struct wpa_ssid
*ssid
, *sel_ssid
;
884 struct wpa_bss
*selected
;
886 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
|| wpa_s
->current_ssid
== NULL
)
889 ssid
= wpa_s
->current_ssid
;
890 if (ssid
->parent_cred
!= cred
)
893 if (ssid
->ssid_len
!= bss
->ssid_len
||
894 os_memcmp(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0)
898 selected
= wpa_supplicant_pick_network(wpa_s
, &sel_ssid
);
899 if (selected
&& sel_ssid
&& sel_ssid
->priority
> ssid
->priority
)
900 return 0; /* higher priority network in scan results */
906 static void remove_duplicate_network(struct wpa_supplicant
*wpa_s
,
907 struct wpa_cred
*cred
,
910 struct wpa_ssid
*ssid
;
912 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
913 if (ssid
->parent_cred
!= cred
)
915 if (ssid
->ssid_len
!= bss
->ssid_len
||
916 os_memcmp(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0)
925 wpa_printf(MSG_DEBUG
, "Interworking: Remove duplicate network entry for the same credential");
927 if (ssid
== wpa_s
->current_ssid
) {
928 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
929 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
930 wpa_s
->own_disconnect_req
= 1;
931 wpa_supplicant_deauthenticate(wpa_s
,
932 WLAN_REASON_DEAUTH_LEAVING
);
935 wpas_notify_network_removed(wpa_s
, ssid
);
936 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
940 static int interworking_set_hs20_params(struct wpa_supplicant
*wpa_s
,
941 struct wpa_ssid
*ssid
)
943 const char *key_mgmt
= NULL
;
944 #ifdef CONFIG_IEEE80211R
946 struct wpa_driver_capa capa
;
948 res
= wpa_drv_get_capa(wpa_s
, &capa
);
949 if (res
== 0 && capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT
) {
950 key_mgmt
= wpa_s
->conf
->pmf
!= NO_MGMT_FRAME_PROTECTION
?
951 "WPA-EAP WPA-EAP-SHA256 FT-EAP" :
954 #endif /* CONFIG_IEEE80211R */
957 key_mgmt
= wpa_s
->conf
->pmf
!= NO_MGMT_FRAME_PROTECTION
?
958 "WPA-EAP WPA-EAP-SHA256" : "WPA-EAP";
959 if (wpa_config_set(ssid
, "key_mgmt", key_mgmt
, 0) < 0 ||
960 wpa_config_set(ssid
, "proto", "RSN", 0) < 0 ||
961 wpa_config_set(ssid
, "ieee80211w", "1", 0) < 0 ||
962 wpa_config_set(ssid
, "pairwise", "CCMP", 0) < 0)
968 static int interworking_connect_3gpp(struct wpa_supplicant
*wpa_s
,
969 struct wpa_cred
*cred
,
970 struct wpa_bss
*bss
, int only_add
)
972 #ifdef INTERWORKING_3GPP
973 struct wpa_ssid
*ssid
;
978 if (bss
->anqp
== NULL
|| bss
->anqp
->anqp_3gpp
== NULL
)
981 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Connect with " MACSTR
982 " (3GPP)", MAC2STR(bss
->bssid
));
984 if (already_connected(wpa_s
, cred
, bss
)) {
985 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_ALREADY_CONNECTED MACSTR
,
986 MAC2STR(bss
->bssid
));
987 return wpa_s
->current_ssid
->id
;
990 remove_duplicate_network(wpa_s
, cred
, bss
);
992 ssid
= wpa_config_add_network(wpa_s
->conf
);
995 ssid
->parent_cred
= cred
;
997 wpas_notify_network_added(wpa_s
, ssid
);
998 wpa_config_set_network_defaults(ssid
);
999 ssid
->priority
= cred
->priority
;
1000 ssid
->temporary
= 1;
1001 ssid
->ssid
= os_zalloc(bss
->ssid_len
+ 1);
1002 if (ssid
->ssid
== NULL
)
1004 os_memcpy(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
);
1005 ssid
->ssid_len
= bss
->ssid_len
;
1006 ssid
->eap
.sim_num
= cred
->sim_num
;
1008 if (interworking_set_hs20_params(wpa_s
, ssid
) < 0)
1011 eap_type
= EAP_TYPE_SIM
;
1012 if (cred
->pcsc
&& wpa_s
->scard
&& scard_supports_umts(wpa_s
->scard
))
1013 eap_type
= EAP_TYPE_AKA
;
1014 if (cred
->eap_method
&& cred
->eap_method
[0].vendor
== EAP_VENDOR_IETF
) {
1015 if (cred
->eap_method
[0].method
== EAP_TYPE_SIM
||
1016 cred
->eap_method
[0].method
== EAP_TYPE_AKA
||
1017 cred
->eap_method
[0].method
== EAP_TYPE_AKA_PRIME
)
1018 eap_type
= cred
->eap_method
[0].method
;
1024 res
= wpa_config_set(ssid
, "eap", "SIM", 0);
1028 res
= wpa_config_set(ssid
, "eap", "AKA", 0);
1030 case EAP_TYPE_AKA_PRIME
:
1032 res
= wpa_config_set(ssid
, "eap", "AKA'", 0);
1039 wpa_msg(wpa_s
, MSG_DEBUG
,
1040 "Selected EAP method (%d) not supported", eap_type
);
1044 if (!cred
->pcsc
&& set_root_nai(ssid
, cred
->imsi
, prefix
) < 0) {
1045 wpa_msg(wpa_s
, MSG_DEBUG
, "Failed to set Root NAI");
1049 if (cred
->milenage
&& cred
->milenage
[0]) {
1050 if (wpa_config_set_quoted(ssid
, "password",
1051 cred
->milenage
) < 0)
1053 } else if (cred
->pcsc
) {
1054 if (wpa_config_set_quoted(ssid
, "pcsc", "") < 0)
1056 if (wpa_s
->conf
->pcsc_pin
&&
1057 wpa_config_set_quoted(ssid
, "pin", wpa_s
->conf
->pcsc_pin
)
1062 wpa_s
->next_ssid
= ssid
;
1063 wpa_config_update_prio_list(wpa_s
->conf
);
1065 interworking_reconnect(wpa_s
);
1070 wpas_notify_network_removed(wpa_s
, ssid
);
1071 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1072 #endif /* INTERWORKING_3GPP */
1077 static int roaming_consortium_element_match(const u8
*ie
, const u8
*rc_id
,
1080 const u8
*pos
, *end
;
1087 end
= ie
+ 2 + ie
[1];
1089 /* Roaming Consortium element:
1090 * Number of ANQP OIs
1091 * OI #1 and #2 lengths
1092 * OI #1, [OI #2], [OI #3]
1098 pos
++; /* skip Number of ANQP OIs */
1100 if ((lens
& 0x0f) + (lens
>> 4) > end
- pos
)
1103 if ((lens
& 0x0f) == rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
1107 if ((lens
>> 4) == rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
1111 if (pos
< end
&& (size_t) (end
- pos
) == rc_len
&&
1112 os_memcmp(pos
, rc_id
, rc_len
) == 0)
1119 static int roaming_consortium_anqp_match(const struct wpabuf
*anqp
,
1120 const u8
*rc_id
, size_t rc_len
)
1122 const u8
*pos
, *end
;
1128 pos
= wpabuf_head(anqp
);
1129 end
= pos
+ wpabuf_len(anqp
);
1131 /* Set of <OI Length, OI> duples */
1134 if (len
> end
- pos
)
1136 if (len
== rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
1145 static int roaming_consortium_match(const u8
*ie
, const struct wpabuf
*anqp
,
1146 const u8
*rc_id
, size_t rc_len
)
1148 return roaming_consortium_element_match(ie
, rc_id
, rc_len
) ||
1149 roaming_consortium_anqp_match(anqp
, rc_id
, rc_len
);
1153 static int cred_roaming_consortiums_match(const u8
*ie
,
1154 const struct wpabuf
*anqp
,
1155 const struct wpa_cred
*cred
)
1159 for (i
= 0; i
< cred
->num_roaming_consortiums
; i
++) {
1160 if (roaming_consortium_match(ie
, anqp
,
1161 cred
->roaming_consortiums
[i
],
1162 cred
->roaming_consortiums_len
[i
]))
1170 static int cred_no_required_oi_match(struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1174 if (cred
->required_roaming_consortium_len
== 0)
1177 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
1180 (bss
->anqp
== NULL
|| bss
->anqp
->roaming_consortium
== NULL
))
1183 return !roaming_consortium_match(ie
,
1185 bss
->anqp
->roaming_consortium
: NULL
,
1186 cred
->required_roaming_consortium
,
1187 cred
->required_roaming_consortium_len
);
1191 static int cred_excluded_ssid(struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1195 if (!cred
->excluded_ssid
)
1198 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
1199 struct excluded_ssid
*e
= &cred
->excluded_ssid
[i
];
1200 if (bss
->ssid_len
== e
->ssid_len
&&
1201 os_memcmp(bss
->ssid
, e
->ssid
, e
->ssid_len
) == 0)
1209 static int cred_below_min_backhaul(struct wpa_supplicant
*wpa_s
,
1210 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1214 unsigned int dl_bandwidth
, ul_bandwidth
;
1216 u8 wan_info
, dl_load
, ul_load
;
1218 u32 ul_speed
, dl_speed
;
1220 if (!cred
->min_dl_bandwidth_home
&&
1221 !cred
->min_ul_bandwidth_home
&&
1222 !cred
->min_dl_bandwidth_roaming
&&
1223 !cred
->min_ul_bandwidth_roaming
)
1224 return 0; /* No bandwidth constraint specified */
1226 if (bss
->anqp
== NULL
|| bss
->anqp
->hs20_wan_metrics
== NULL
)
1227 return 0; /* No WAN Metrics known - ignore constraint */
1229 wan
= wpabuf_head(bss
->anqp
->hs20_wan_metrics
);
1231 if (wan_info
& BIT(3))
1232 return 1; /* WAN link at capacity */
1233 lmd
= WPA_GET_LE16(wan
+ 11);
1235 return 0; /* Downlink/Uplink Load was not measured */
1236 dl_speed
= WPA_GET_LE32(wan
+ 1);
1237 ul_speed
= WPA_GET_LE32(wan
+ 5);
1241 if (dl_speed
>= 0xffffff)
1242 dl_bandwidth
= dl_speed
/ 255 * (255 - dl_load
);
1244 dl_bandwidth
= dl_speed
* (255 - dl_load
) / 255;
1246 if (ul_speed
>= 0xffffff)
1247 ul_bandwidth
= ul_speed
/ 255 * (255 - ul_load
);
1249 ul_bandwidth
= ul_speed
* (255 - ul_load
) / 255;
1251 res
= interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
?
1252 bss
->anqp
->domain_name
: NULL
);
1254 if (cred
->min_dl_bandwidth_home
> dl_bandwidth
)
1256 if (cred
->min_ul_bandwidth_home
> ul_bandwidth
)
1259 if (cred
->min_dl_bandwidth_roaming
> dl_bandwidth
)
1261 if (cred
->min_ul_bandwidth_roaming
> ul_bandwidth
)
1264 #endif /* CONFIG_HS20 */
1270 static int cred_over_max_bss_load(struct wpa_supplicant
*wpa_s
,
1271 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1276 if (!cred
->max_bss_load
)
1277 return 0; /* No BSS Load constraint specified */
1279 ie
= wpa_bss_get_ie(bss
, WLAN_EID_BSS_LOAD
);
1280 if (ie
== NULL
|| ie
[1] < 3)
1281 return 0; /* No BSS Load advertised */
1283 res
= interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
?
1284 bss
->anqp
->domain_name
: NULL
);
1286 return 0; /* Not a home network */
1288 return ie
[4] > cred
->max_bss_load
;
1294 static int has_proto_match(const u8
*pos
, const u8
*end
, u8 proto
)
1296 while (end
- pos
>= 4) {
1297 if (pos
[0] == proto
&& pos
[3] == 1 /* Open */)
1306 static int has_proto_port_match(const u8
*pos
, const u8
*end
, u8 proto
,
1309 while (end
- pos
>= 4) {
1310 if (pos
[0] == proto
&& WPA_GET_LE16(&pos
[1]) == port
&&
1311 pos
[3] == 1 /* Open */)
1319 #endif /* CONFIG_HS20 */
1322 static int cred_conn_capab_missing(struct wpa_supplicant
*wpa_s
,
1323 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1327 const u8
*capab
, *end
;
1331 if (!cred
->num_req_conn_capab
)
1332 return 0; /* No connection capability constraint specified */
1334 if (bss
->anqp
== NULL
|| bss
->anqp
->hs20_connection_capability
== NULL
)
1335 return 0; /* No Connection Capability known - ignore constraint
1338 res
= interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
?
1339 bss
->anqp
->domain_name
: NULL
);
1341 return 0; /* No constraint in home network */
1343 capab
= wpabuf_head(bss
->anqp
->hs20_connection_capability
);
1344 end
= capab
+ wpabuf_len(bss
->anqp
->hs20_connection_capability
);
1346 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
1347 ports
= cred
->req_conn_capab_port
[i
];
1349 if (!has_proto_match(capab
, end
,
1350 cred
->req_conn_capab_proto
[i
]))
1353 for (j
= 0; ports
[j
] > -1; j
++) {
1354 if (!has_proto_port_match(
1356 cred
->req_conn_capab_proto
[i
],
1362 #endif /* CONFIG_HS20 */
1368 static struct wpa_cred
* interworking_credentials_available_roaming_consortium(
1369 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
1372 struct wpa_cred
*cred
, *selected
= NULL
;
1374 const struct wpabuf
*anqp
;
1375 int is_excluded
= 0;
1377 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
1378 anqp
= bss
->anqp
? bss
->anqp
->roaming_consortium
: NULL
;
1383 if (wpa_s
->conf
->cred
== NULL
)
1386 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1387 if (cred
->roaming_consortium_len
== 0 &&
1388 cred
->num_roaming_consortiums
== 0)
1391 if (!cred
->eap_method
)
1394 if ((cred
->roaming_consortium_len
== 0 ||
1395 !roaming_consortium_match(ie
, anqp
,
1396 cred
->roaming_consortium
,
1397 cred
->roaming_consortium_len
)) &&
1398 !cred_roaming_consortiums_match(ie
, anqp
, cred
) &&
1399 (cred
->required_roaming_consortium_len
== 0 ||
1400 !roaming_consortium_match(
1401 ie
, anqp
, cred
->required_roaming_consortium
,
1402 cred
->required_roaming_consortium_len
)))
1405 if (cred_no_required_oi_match(cred
, bss
))
1407 if (!ignore_bw
&& cred_below_min_backhaul(wpa_s
, cred
, bss
))
1409 if (!ignore_bw
&& cred_over_max_bss_load(wpa_s
, cred
, bss
))
1411 if (!ignore_bw
&& cred_conn_capab_missing(wpa_s
, cred
, bss
))
1413 if (cred_excluded_ssid(cred
, bss
)) {
1414 if (excluded
== NULL
)
1416 if (selected
== NULL
) {
1421 if (selected
== NULL
|| is_excluded
||
1422 cred_prio_cmp(selected
, cred
) < 0) {
1430 *excluded
= is_excluded
;
1436 static int interworking_set_eap_params(struct wpa_ssid
*ssid
,
1437 struct wpa_cred
*cred
, int ttls
)
1439 if (cred
->eap_method
) {
1440 ttls
= cred
->eap_method
->vendor
== EAP_VENDOR_IETF
&&
1441 cred
->eap_method
->method
== EAP_TYPE_TTLS
;
1443 os_free(ssid
->eap
.eap_methods
);
1444 ssid
->eap
.eap_methods
=
1445 os_malloc(sizeof(struct eap_method_type
) * 2);
1446 if (ssid
->eap
.eap_methods
== NULL
)
1448 os_memcpy(ssid
->eap
.eap_methods
, cred
->eap_method
,
1449 sizeof(*cred
->eap_method
));
1450 ssid
->eap
.eap_methods
[1].vendor
= EAP_VENDOR_IETF
;
1451 ssid
->eap
.eap_methods
[1].method
= EAP_TYPE_NONE
;
1454 if (ttls
&& cred
->username
&& cred
->username
[0]) {
1457 /* Use anonymous NAI in Phase 1 */
1458 pos
= os_strchr(cred
->username
, '@');
1460 size_t buflen
= 9 + os_strlen(pos
) + 1;
1461 anon
= os_malloc(buflen
);
1464 os_snprintf(anon
, buflen
, "anonymous%s", pos
);
1465 } else if (cred
->realm
) {
1466 size_t buflen
= 10 + os_strlen(cred
->realm
) + 1;
1467 anon
= os_malloc(buflen
);
1470 os_snprintf(anon
, buflen
, "anonymous@%s", cred
->realm
);
1472 anon
= os_strdup("anonymous");
1476 if (wpa_config_set_quoted(ssid
, "anonymous_identity", anon
) <
1484 if (!ttls
&& cred
->username
&& cred
->username
[0] && cred
->realm
&&
1485 !os_strchr(cred
->username
, '@')) {
1490 buflen
= os_strlen(cred
->username
) + 1 +
1491 os_strlen(cred
->realm
) + 1;
1493 id
= os_malloc(buflen
);
1496 os_snprintf(id
, buflen
, "%s@%s", cred
->username
, cred
->realm
);
1497 res
= wpa_config_set_quoted(ssid
, "identity", id
);
1501 } else if (cred
->username
&& cred
->username
[0] &&
1502 wpa_config_set_quoted(ssid
, "identity", cred
->username
) < 0)
1505 if (cred
->password
&& cred
->password
[0]) {
1506 if (cred
->ext_password
&&
1507 wpa_config_set(ssid
, "password", cred
->password
, 0) < 0)
1509 if (!cred
->ext_password
&&
1510 wpa_config_set_quoted(ssid
, "password", cred
->password
) <
1515 if (cred
->client_cert
&& cred
->client_cert
[0] &&
1516 wpa_config_set_quoted(ssid
, "client_cert", cred
->client_cert
) < 0)
1520 if (cred
->private_key
&&
1521 os_strncmp(cred
->private_key
, "keystore://", 11) == 0) {
1522 /* Use OpenSSL engine configuration for Android keystore */
1523 if (wpa_config_set_quoted(ssid
, "engine_id", "keystore") < 0 ||
1524 wpa_config_set_quoted(ssid
, "key_id",
1525 cred
->private_key
+ 11) < 0 ||
1526 wpa_config_set(ssid
, "engine", "1", 0) < 0)
1529 #endif /* ANDROID */
1530 if (cred
->private_key
&& cred
->private_key
[0] &&
1531 wpa_config_set_quoted(ssid
, "private_key", cred
->private_key
) < 0)
1534 if (cred
->private_key_passwd
&& cred
->private_key_passwd
[0] &&
1535 wpa_config_set_quoted(ssid
, "private_key_passwd",
1536 cred
->private_key_passwd
) < 0)
1540 os_free(ssid
->eap
.phase1
);
1541 ssid
->eap
.phase1
= os_strdup(cred
->phase1
);
1544 os_free(ssid
->eap
.phase2
);
1545 ssid
->eap
.phase2
= os_strdup(cred
->phase2
);
1548 if (cred
->ca_cert
&& cred
->ca_cert
[0] &&
1549 wpa_config_set_quoted(ssid
, "ca_cert", cred
->ca_cert
) < 0)
1552 if (cred
->domain_suffix_match
&& cred
->domain_suffix_match
[0] &&
1553 wpa_config_set_quoted(ssid
, "domain_suffix_match",
1554 cred
->domain_suffix_match
) < 0)
1557 ssid
->eap
.cert
.ocsp
= cred
->ocsp
;
1563 static int interworking_connect_roaming_consortium(
1564 struct wpa_supplicant
*wpa_s
, struct wpa_cred
*cred
,
1565 struct wpa_bss
*bss
, int only_add
)
1567 struct wpa_ssid
*ssid
;
1569 const struct wpabuf
*anqp
;
1572 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Connect with " MACSTR
1573 " based on roaming consortium match", MAC2STR(bss
->bssid
));
1575 if (already_connected(wpa_s
, cred
, bss
)) {
1576 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_ALREADY_CONNECTED MACSTR
,
1577 MAC2STR(bss
->bssid
));
1578 return wpa_s
->current_ssid
->id
;
1581 remove_duplicate_network(wpa_s
, cred
, bss
);
1583 ssid
= wpa_config_add_network(wpa_s
->conf
);
1586 ssid
->parent_cred
= cred
;
1587 wpas_notify_network_added(wpa_s
, ssid
);
1588 wpa_config_set_network_defaults(ssid
);
1589 ssid
->priority
= cred
->priority
;
1590 ssid
->temporary
= 1;
1591 ssid
->ssid
= os_zalloc(bss
->ssid_len
+ 1);
1592 if (ssid
->ssid
== NULL
)
1594 os_memcpy(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
);
1595 ssid
->ssid_len
= bss
->ssid_len
;
1597 if (interworking_set_hs20_params(wpa_s
, ssid
) < 0)
1600 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
1601 anqp
= bss
->anqp
? bss
->anqp
->roaming_consortium
: NULL
;
1602 for (i
= 0; (ie
|| anqp
) && i
< cred
->num_roaming_consortiums
; i
++) {
1603 if (!roaming_consortium_match(
1604 ie
, anqp
, cred
->roaming_consortiums
[i
],
1605 cred
->roaming_consortiums_len
[i
]))
1608 ssid
->roaming_consortium_selection
=
1609 os_malloc(cred
->roaming_consortiums_len
[i
]);
1610 if (!ssid
->roaming_consortium_selection
)
1612 os_memcpy(ssid
->roaming_consortium_selection
,
1613 cred
->roaming_consortiums
[i
],
1614 cred
->roaming_consortiums_len
[i
]);
1615 ssid
->roaming_consortium_selection_len
=
1616 cred
->roaming_consortiums_len
[i
];
1620 if (cred
->eap_method
== NULL
) {
1621 wpa_msg(wpa_s
, MSG_DEBUG
,
1622 "Interworking: No EAP method set for credential using roaming consortium");
1626 if (interworking_set_eap_params(
1628 cred
->eap_method
->vendor
== EAP_VENDOR_IETF
&&
1629 cred
->eap_method
->method
== EAP_TYPE_TTLS
) < 0)
1632 wpa_s
->next_ssid
= ssid
;
1633 wpa_config_update_prio_list(wpa_s
->conf
);
1635 interworking_reconnect(wpa_s
);
1640 wpas_notify_network_removed(wpa_s
, ssid
);
1641 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1646 int interworking_connect(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
1649 struct wpa_cred
*cred
, *cred_rc
, *cred_3gpp
;
1650 struct wpa_ssid
*ssid
;
1651 struct nai_realm
*realm
;
1652 struct nai_realm_eap
*eap
= NULL
;
1655 int excluded
= 0, *excl
= &excluded
;
1658 if (wpa_s
->conf
->cred
== NULL
|| bss
== NULL
)
1660 if (disallowed_bssid(wpa_s
, bss
->bssid
) ||
1661 disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
1662 wpa_msg(wpa_s
, MSG_DEBUG
,
1663 "Interworking: Reject connection to disallowed BSS "
1664 MACSTR
, MAC2STR(bss
->bssid
));
1668 wpa_printf(MSG_DEBUG
, "Interworking: Considering BSS " MACSTR
1670 MAC2STR(bss
->bssid
));
1672 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) {
1674 * We currently support only HS 2.0 networks and those are
1675 * required to use WPA2-Enterprise.
1677 wpa_msg(wpa_s
, MSG_DEBUG
,
1678 "Interworking: Network does not use RSN");
1682 cred_rc
= interworking_credentials_available_roaming_consortium(
1683 wpa_s
, bss
, 0, excl
);
1685 wpa_msg(wpa_s
, MSG_DEBUG
,
1686 "Interworking: Highest roaming consortium matching credential priority %d sp_priority %d",
1687 cred_rc
->priority
, cred_rc
->sp_priority
);
1688 if (excl
&& !(*excl
))
1692 cred
= interworking_credentials_available_realm(wpa_s
, bss
, 0, excl
);
1694 wpa_msg(wpa_s
, MSG_DEBUG
,
1695 "Interworking: Highest NAI Realm list matching credential priority %d sp_priority %d",
1696 cred
->priority
, cred
->sp_priority
);
1697 if (excl
&& !(*excl
))
1701 cred_3gpp
= interworking_credentials_available_3gpp(wpa_s
, bss
, 0,
1704 wpa_msg(wpa_s
, MSG_DEBUG
,
1705 "Interworking: Highest 3GPP matching credential priority %d sp_priority %d",
1706 cred_3gpp
->priority
, cred_3gpp
->sp_priority
);
1707 if (excl
&& !(*excl
))
1711 if (!cred_rc
&& !cred
&& !cred_3gpp
) {
1712 wpa_msg(wpa_s
, MSG_DEBUG
,
1713 "Interworking: No full credential matches - consider options without BW(etc.) limits");
1714 cred_rc
= interworking_credentials_available_roaming_consortium(
1715 wpa_s
, bss
, 1, excl
);
1717 wpa_msg(wpa_s
, MSG_DEBUG
,
1718 "Interworking: Highest roaming consortium matching credential priority %d sp_priority %d (ignore BW)",
1719 cred_rc
->priority
, cred_rc
->sp_priority
);
1720 if (excl
&& !(*excl
))
1724 cred
= interworking_credentials_available_realm(wpa_s
, bss
, 1,
1727 wpa_msg(wpa_s
, MSG_DEBUG
,
1728 "Interworking: Highest NAI Realm list matching credential priority %d sp_priority %d (ignore BW)",
1729 cred
->priority
, cred
->sp_priority
);
1730 if (excl
&& !(*excl
))
1734 cred_3gpp
= interworking_credentials_available_3gpp(wpa_s
, bss
,
1737 wpa_msg(wpa_s
, MSG_DEBUG
,
1738 "Interworking: Highest 3GPP matching credential priority %d sp_priority %d (ignore BW)",
1739 cred_3gpp
->priority
, cred_3gpp
->sp_priority
);
1740 if (excl
&& !(*excl
))
1746 (cred
== NULL
|| cred_prio_cmp(cred_rc
, cred
) >= 0) &&
1747 (cred_3gpp
== NULL
|| cred_prio_cmp(cred_rc
, cred_3gpp
) >= 0))
1748 return interworking_connect_roaming_consortium(wpa_s
, cred_rc
,
1752 (cred
== NULL
|| cred_prio_cmp(cred_3gpp
, cred
) >= 0)) {
1753 return interworking_connect_3gpp(wpa_s
, cred_3gpp
, bss
,
1758 wpa_msg(wpa_s
, MSG_DEBUG
,
1759 "Interworking: No matching credentials found for "
1760 MACSTR
, MAC2STR(bss
->bssid
));
1764 realm
= nai_realm_parse(bss
->anqp
? bss
->anqp
->nai_realm
: NULL
,
1766 if (realm
== NULL
) {
1767 wpa_msg(wpa_s
, MSG_DEBUG
,
1768 "Interworking: Could not parse NAI Realm list from "
1769 MACSTR
, MAC2STR(bss
->bssid
));
1773 for (i
= 0; i
< count
; i
++) {
1774 if (!nai_realm_match(&realm
[i
], cred
->realm
))
1776 eap
= nai_realm_find_eap(wpa_s
, cred
, &realm
[i
]);
1782 wpa_msg(wpa_s
, MSG_DEBUG
,
1783 "Interworking: No matching credentials and EAP method found for "
1784 MACSTR
, MAC2STR(bss
->bssid
));
1785 nai_realm_free(realm
, count
);
1789 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Connect with " MACSTR
,
1790 MAC2STR(bss
->bssid
));
1792 if (already_connected(wpa_s
, cred
, bss
)) {
1793 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_ALREADY_CONNECTED MACSTR
,
1794 MAC2STR(bss
->bssid
));
1795 nai_realm_free(realm
, count
);
1799 remove_duplicate_network(wpa_s
, cred
, bss
);
1801 ssid
= wpa_config_add_network(wpa_s
->conf
);
1803 nai_realm_free(realm
, count
);
1806 ssid
->parent_cred
= cred
;
1807 wpas_notify_network_added(wpa_s
, ssid
);
1808 wpa_config_set_network_defaults(ssid
);
1809 ssid
->priority
= cred
->priority
;
1810 ssid
->temporary
= 1;
1811 ssid
->ssid
= os_zalloc(bss
->ssid_len
+ 1);
1812 if (ssid
->ssid
== NULL
)
1814 os_memcpy(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
);
1815 ssid
->ssid_len
= bss
->ssid_len
;
1817 if (interworking_set_hs20_params(wpa_s
, ssid
) < 0)
1820 if (wpa_config_set(ssid
, "eap", eap_get_name(EAP_VENDOR_IETF
,
1821 eap
->method
), 0) < 0)
1824 switch (eap
->method
) {
1826 if (eap
->inner_method
) {
1827 name
= eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
);
1830 os_snprintf(buf
, sizeof(buf
), "\"autheap=%s\"", name
);
1831 if (wpa_config_set(ssid
, "phase2", buf
, 0) < 0)
1835 switch (eap
->inner_non_eap
) {
1836 case NAI_REALM_INNER_NON_EAP_PAP
:
1837 if (wpa_config_set(ssid
, "phase2", "\"auth=PAP\"", 0) <
1841 case NAI_REALM_INNER_NON_EAP_CHAP
:
1842 if (wpa_config_set(ssid
, "phase2", "\"auth=CHAP\"", 0)
1846 case NAI_REALM_INNER_NON_EAP_MSCHAP
:
1847 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAP\"",
1851 case NAI_REALM_INNER_NON_EAP_MSCHAPV2
:
1852 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAPV2\"",
1857 /* EAP params were not set - assume TTLS/MSCHAPv2 */
1858 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAPV2\"",
1866 if (wpa_config_set(ssid
, "phase1", "\"fast_provisioning=2\"",
1869 if (wpa_config_set(ssid
, "pac_file",
1870 "\"blob://pac_interworking\"", 0) < 0)
1872 name
= eap_get_name(EAP_VENDOR_IETF
,
1873 eap
->inner_method
? eap
->inner_method
:
1877 os_snprintf(buf
, sizeof(buf
), "\"auth=%s\"", name
);
1878 if (wpa_config_set(ssid
, "phase2", buf
, 0) < 0)
1885 if (interworking_set_eap_params(ssid
, cred
,
1886 eap
->method
== EAP_TYPE_TTLS
) < 0)
1889 nai_realm_free(realm
, count
);
1891 wpa_s
->next_ssid
= ssid
;
1892 wpa_config_update_prio_list(wpa_s
->conf
);
1894 interworking_reconnect(wpa_s
);
1899 wpas_notify_network_removed(wpa_s
, ssid
);
1900 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1901 nai_realm_free(realm
, count
);
1907 static int interworking_pcsc_read_imsi(struct wpa_supplicant
*wpa_s
)
1911 if (wpa_s
->imsi
[0] && wpa_s
->mnc_len
)
1914 len
= sizeof(wpa_s
->imsi
) - 1;
1915 if (scard_get_imsi(wpa_s
->scard
, wpa_s
->imsi
, &len
)) {
1916 scard_deinit(wpa_s
->scard
);
1917 wpa_s
->scard
= NULL
;
1918 wpa_msg(wpa_s
, MSG_ERROR
, "Could not read IMSI");
1921 wpa_s
->imsi
[len
] = '\0';
1922 wpa_s
->mnc_len
= scard_get_mnc_len(wpa_s
->scard
);
1923 wpa_printf(MSG_DEBUG
, "SCARD: IMSI %s (MNC length %d)",
1924 wpa_s
->imsi
, wpa_s
->mnc_len
);
1928 #endif /* PCSC_FUNCS */
1931 static struct wpa_cred
* interworking_credentials_available_3gpp(
1932 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
1935 struct wpa_cred
*selected
= NULL
;
1936 #ifdef INTERWORKING_3GPP
1937 struct wpa_cred
*cred
;
1939 int is_excluded
= 0;
1941 if (bss
->anqp
== NULL
|| bss
->anqp
->anqp_3gpp
== NULL
) {
1942 wpa_msg(wpa_s
, MSG_DEBUG
,
1943 "interworking-avail-3gpp: not avail, anqp: %p anqp_3gpp: %p",
1944 bss
->anqp
, bss
->anqp
? bss
->anqp
->anqp_3gpp
: NULL
);
1948 #ifdef CONFIG_EAP_PROXY
1949 if (!wpa_s
->imsi
[0]) {
1951 wpa_msg(wpa_s
, MSG_DEBUG
,
1952 "Interworking: IMSI not available - try to read again through eap_proxy");
1953 wpa_s
->mnc_len
= eapol_sm_get_eap_proxy_imsi(wpa_s
->eapol
, -1,
1956 if (wpa_s
->mnc_len
> 0) {
1957 wpa_s
->imsi
[len
] = '\0';
1958 wpa_msg(wpa_s
, MSG_DEBUG
,
1959 "eap_proxy: IMSI %s (MNC length %d)",
1960 wpa_s
->imsi
, wpa_s
->mnc_len
);
1962 wpa_msg(wpa_s
, MSG_DEBUG
,
1963 "eap_proxy: IMSI not available");
1966 #endif /* CONFIG_EAP_PROXY */
1968 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1976 if (cred
->pcsc
&& wpa_s
->scard
) {
1977 if (interworking_pcsc_read_imsi(wpa_s
) < 0)
1980 mnc_len
= wpa_s
->mnc_len
;
1983 #endif /* PCSC_FUNCS */
1984 #ifdef CONFIG_EAP_PROXY
1985 if (cred
->pcsc
&& wpa_s
->mnc_len
> 0 && wpa_s
->imsi
[0]) {
1987 mnc_len
= wpa_s
->mnc_len
;
1990 #endif /* CONFIG_EAP_PROXY */
1992 if (cred
->imsi
== NULL
|| !cred
->imsi
[0] ||
1993 (!wpa_s
->conf
->external_sim
&&
1994 (cred
->milenage
== NULL
|| !cred
->milenage
[0])))
1997 sep
= os_strchr(cred
->imsi
, '-');
1999 (sep
- cred
->imsi
!= 5 && sep
- cred
->imsi
!= 6))
2001 mnc_len
= sep
- cred
->imsi
- 3;
2002 os_memcpy(imsi_buf
, cred
->imsi
, 3 + mnc_len
);
2004 msin_len
= os_strlen(cred
->imsi
);
2005 if (3 + mnc_len
+ msin_len
>= sizeof(imsi_buf
) - 1)
2006 msin_len
= sizeof(imsi_buf
) - 3 - mnc_len
- 1;
2007 os_memcpy(&imsi_buf
[3 + mnc_len
], sep
, msin_len
);
2008 imsi_buf
[3 + mnc_len
+ msin_len
] = '\0';
2011 #if defined(PCSC_FUNCS) || defined(CONFIG_EAP_PROXY)
2013 #endif /* PCSC_FUNCS || CONFIG_EAP_PROXY */
2014 wpa_msg(wpa_s
, MSG_DEBUG
,
2015 "Interworking: Parsing 3GPP info from " MACSTR
,
2016 MAC2STR(bss
->bssid
));
2017 ret
= plmn_id_match(bss
->anqp
->anqp_3gpp
, imsi
, mnc_len
);
2018 wpa_msg(wpa_s
, MSG_DEBUG
, "PLMN match %sfound",
2021 if (cred_no_required_oi_match(cred
, bss
))
2024 cred_below_min_backhaul(wpa_s
, cred
, bss
))
2027 cred_over_max_bss_load(wpa_s
, cred
, bss
))
2030 cred_conn_capab_missing(wpa_s
, cred
, bss
))
2032 if (cred_excluded_ssid(cred
, bss
)) {
2033 if (excluded
== NULL
)
2035 if (selected
== NULL
) {
2040 if (selected
== NULL
|| is_excluded
||
2041 cred_prio_cmp(selected
, cred
) < 0) {
2050 *excluded
= is_excluded
;
2051 #endif /* INTERWORKING_3GPP */
2056 static struct wpa_cred
* interworking_credentials_available_realm(
2057 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
2060 struct wpa_cred
*cred
, *selected
= NULL
;
2061 struct nai_realm
*realm
;
2063 int is_excluded
= 0;
2065 if (bss
->anqp
== NULL
|| bss
->anqp
->nai_realm
== NULL
)
2068 if (wpa_s
->conf
->cred
== NULL
)
2071 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Parsing NAI Realm list from "
2072 MACSTR
, MAC2STR(bss
->bssid
));
2073 realm
= nai_realm_parse(bss
->anqp
->nai_realm
, &count
);
2074 if (realm
== NULL
) {
2075 wpa_msg(wpa_s
, MSG_DEBUG
,
2076 "Interworking: Could not parse NAI Realm list from "
2077 MACSTR
, MAC2STR(bss
->bssid
));
2081 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2082 if (cred
->realm
== NULL
)
2085 for (i
= 0; i
< count
; i
++) {
2086 if (!nai_realm_match(&realm
[i
], cred
->realm
))
2088 if (nai_realm_find_eap(wpa_s
, cred
, &realm
[i
])) {
2089 if (cred_no_required_oi_match(cred
, bss
))
2092 cred_below_min_backhaul(wpa_s
, cred
, bss
))
2095 cred_over_max_bss_load(wpa_s
, cred
, bss
))
2098 cred_conn_capab_missing(wpa_s
, cred
, bss
))
2100 if (cred_excluded_ssid(cred
, bss
)) {
2101 if (excluded
== NULL
)
2103 if (selected
== NULL
) {
2108 if (selected
== NULL
|| is_excluded
||
2109 cred_prio_cmp(selected
, cred
) < 0)
2117 wpa_msg(wpa_s
, MSG_DEBUG
,
2118 "Interworking: realm-find-eap returned false");
2123 nai_realm_free(realm
, count
);
2126 *excluded
= is_excluded
;
2132 static struct wpa_cred
* interworking_credentials_available_helper(
2133 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
2136 struct wpa_cred
*cred
, *cred2
;
2137 int excluded1
, excluded2
= 0;
2139 if (disallowed_bssid(wpa_s
, bss
->bssid
) ||
2140 disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
2141 wpa_printf(MSG_DEBUG
, "Interworking: Ignore disallowed BSS "
2142 MACSTR
, MAC2STR(bss
->bssid
));
2146 cred
= interworking_credentials_available_realm(wpa_s
, bss
, ignore_bw
,
2148 cred2
= interworking_credentials_available_3gpp(wpa_s
, bss
, ignore_bw
,
2150 if (cred
&& cred2
&&
2151 (cred_prio_cmp(cred2
, cred
) >= 0 || (!excluded2
&& excluded1
))) {
2153 excluded1
= excluded2
;
2157 excluded1
= excluded2
;
2160 cred2
= interworking_credentials_available_roaming_consortium(
2161 wpa_s
, bss
, ignore_bw
, &excluded2
);
2162 if (cred
&& cred2
&&
2163 (cred_prio_cmp(cred2
, cred
) >= 0 || (!excluded2
&& excluded1
))) {
2165 excluded1
= excluded2
;
2169 excluded1
= excluded2
;
2173 *excluded
= excluded1
;
2178 static struct wpa_cred
* interworking_credentials_available(
2179 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int *excluded
)
2181 struct wpa_cred
*cred
;
2185 cred
= interworking_credentials_available_helper(wpa_s
, bss
, 0,
2189 return interworking_credentials_available_helper(wpa_s
, bss
, 1,
2194 int domain_name_list_contains(struct wpabuf
*domain_names
,
2195 const char *domain
, int exact_match
)
2197 const u8
*pos
, *end
;
2200 len
= os_strlen(domain
);
2201 pos
= wpabuf_head(domain_names
);
2202 end
= pos
+ wpabuf_len(domain_names
);
2204 while (end
- pos
> 1) {
2208 if (elen
> end
- pos
)
2211 wpa_hexdump_ascii(MSG_DEBUG
, "Interworking: AP domain name",
2214 os_strncasecmp(domain
, (const char *) pos
, len
) == 0)
2216 if (!exact_match
&& elen
> len
&& pos
[elen
- len
- 1] == '.') {
2217 const char *ap
= (const char *) pos
;
2218 int offset
= elen
- len
;
2220 if (os_strncasecmp(domain
, ap
+ offset
, len
) == 0)
2231 int interworking_home_sp_cred(struct wpa_supplicant
*wpa_s
,
2232 struct wpa_cred
*cred
,
2233 struct wpabuf
*domain_names
)
2237 #ifdef INTERWORKING_3GPP
2238 char nai
[100], *realm
;
2245 else if (cred
->pcsc
&& wpa_s
->scard
) {
2246 if (interworking_pcsc_read_imsi(wpa_s
) < 0)
2249 mnc_len
= wpa_s
->mnc_len
;
2251 #endif /* PCSC_FUNCS */
2252 #ifdef CONFIG_EAP_PROXY
2253 else if (cred
->pcsc
&& wpa_s
->mnc_len
> 0 && wpa_s
->imsi
[0]) {
2255 mnc_len
= wpa_s
->mnc_len
;
2257 #endif /* CONFIG_EAP_PROXY */
2259 imsi
&& build_root_nai(nai
, sizeof(nai
), imsi
, mnc_len
, 0) == 0) {
2260 realm
= os_strchr(nai
, '@');
2263 wpa_msg(wpa_s
, MSG_DEBUG
,
2264 "Interworking: Search for match with SIM/USIM domain %s",
2265 realm
? realm
: "[NULL]");
2267 domain_name_list_contains(domain_names
, realm
, 1))
2272 #endif /* INTERWORKING_3GPP */
2274 if (domain_names
== NULL
|| cred
->domain
== NULL
)
2277 for (i
= 0; i
< cred
->num_domain
; i
++) {
2278 wpa_msg(wpa_s
, MSG_DEBUG
,
2279 "Interworking: Search for match with home SP FQDN %s",
2281 if (domain_name_list_contains(domain_names
, cred
->domain
[i
], 1))
2289 static int interworking_home_sp(struct wpa_supplicant
*wpa_s
,
2290 struct wpabuf
*domain_names
)
2292 struct wpa_cred
*cred
;
2294 if (domain_names
== NULL
|| wpa_s
->conf
->cred
== NULL
)
2297 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2298 int res
= interworking_home_sp_cred(wpa_s
, cred
, domain_names
);
2307 static int interworking_find_network_match(struct wpa_supplicant
*wpa_s
)
2309 struct wpa_bss
*bss
;
2310 struct wpa_ssid
*ssid
;
2312 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2313 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
2314 if (wpas_network_disabled(wpa_s
, ssid
) ||
2315 ssid
->mode
!= WPAS_MODE_INFRA
)
2317 if (ssid
->ssid_len
!= bss
->ssid_len
||
2318 os_memcmp(ssid
->ssid
, bss
->ssid
, ssid
->ssid_len
) !=
2322 * TODO: Consider more accurate matching of security
2323 * configuration similarly to what is done in events.c
2333 static int roaming_partner_match(struct wpa_supplicant
*wpa_s
,
2334 struct roaming_partner
*partner
,
2335 struct wpabuf
*domain_names
)
2337 wpa_printf(MSG_DEBUG
, "Interworking: Comparing roaming_partner info fqdn='%s' exact_match=%d priority=%u country='%s'",
2338 partner
->fqdn
, partner
->exact_match
, partner
->priority
,
2340 wpa_hexdump_ascii(MSG_DEBUG
, "Interworking: Domain names",
2341 wpabuf_head(domain_names
),
2342 wpabuf_len(domain_names
));
2343 if (!domain_name_list_contains(domain_names
, partner
->fqdn
,
2344 partner
->exact_match
))
2346 /* TODO: match Country */
2351 static u8
roaming_prio(struct wpa_supplicant
*wpa_s
, struct wpa_cred
*cred
,
2352 struct wpa_bss
*bss
)
2356 if (bss
->anqp
== NULL
|| bss
->anqp
->domain_name
== NULL
) {
2357 wpa_printf(MSG_DEBUG
, "Interworking: No ANQP domain name info -> use default roaming partner priority 128");
2358 return 128; /* cannot check preference with domain name */
2361 if (interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
->domain_name
) > 0)
2363 wpa_printf(MSG_DEBUG
, "Interworking: Determined to be home SP -> use maximum preference 0 as roaming partner priority");
2364 return 0; /* max preference for home SP network */
2367 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
2368 if (roaming_partner_match(wpa_s
, &cred
->roaming_partner
[i
],
2369 bss
->anqp
->domain_name
)) {
2370 wpa_printf(MSG_DEBUG
, "Interworking: Roaming partner preference match - priority %u",
2371 cred
->roaming_partner
[i
].priority
);
2372 return cred
->roaming_partner
[i
].priority
;
2376 wpa_printf(MSG_DEBUG
, "Interworking: No roaming partner preference match - use default roaming partner priority 128");
2381 static struct wpa_bss
* pick_best_roaming_partner(struct wpa_supplicant
*wpa_s
,
2382 struct wpa_bss
*selected
,
2383 struct wpa_cred
*cred
)
2385 struct wpa_bss
*bss
;
2387 struct wpa_cred
*cred2
;
2390 * Check if any other BSS is operated by a more preferred roaming
2394 best_prio
= roaming_prio(wpa_s
, cred
, selected
);
2395 wpa_printf(MSG_DEBUG
, "Interworking: roaming_prio=%u for selected BSS "
2396 MACSTR
" (cred=%d)", best_prio
, MAC2STR(selected
->bssid
),
2399 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2400 if (bss
== selected
)
2402 cred2
= interworking_credentials_available(wpa_s
, bss
, NULL
);
2405 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
2407 prio
= roaming_prio(wpa_s
, cred2
, bss
);
2408 wpa_printf(MSG_DEBUG
, "Interworking: roaming_prio=%u for BSS "
2409 MACSTR
" (cred=%d)", prio
, MAC2STR(bss
->bssid
),
2411 if (prio
< best_prio
) {
2412 int bh1
, bh2
, load1
, load2
, conn1
, conn2
;
2413 bh1
= cred_below_min_backhaul(wpa_s
, cred
, selected
);
2414 load1
= cred_over_max_bss_load(wpa_s
, cred
, selected
);
2415 conn1
= cred_conn_capab_missing(wpa_s
, cred
, selected
);
2416 bh2
= cred_below_min_backhaul(wpa_s
, cred2
, bss
);
2417 load2
= cred_over_max_bss_load(wpa_s
, cred2
, bss
);
2418 conn2
= cred_conn_capab_missing(wpa_s
, cred2
, bss
);
2419 wpa_printf(MSG_DEBUG
, "Interworking: old: %d %d %d new: %d %d %d",
2420 bh1
, load1
, conn1
, bh2
, load2
, conn2
);
2421 if (bh1
|| load1
|| conn1
|| !(bh2
|| load2
|| conn2
)) {
2422 wpa_printf(MSG_DEBUG
, "Interworking: Better roaming partner " MACSTR
" selected", MAC2STR(bss
->bssid
));
2433 static void interworking_select_network(struct wpa_supplicant
*wpa_s
)
2435 struct wpa_bss
*bss
, *selected
= NULL
, *selected_home
= NULL
;
2436 struct wpa_bss
*selected2
= NULL
, *selected2_home
= NULL
;
2437 unsigned int count
= 0;
2440 struct wpa_cred
*cred
, *selected_cred
= NULL
;
2441 struct wpa_cred
*selected_home_cred
= NULL
;
2442 struct wpa_cred
*selected2_cred
= NULL
;
2443 struct wpa_cred
*selected2_home_cred
= NULL
;
2445 wpa_s
->network_select
= 0;
2447 wpa_printf(MSG_DEBUG
, "Interworking: Select network (auto_select=%d)",
2448 wpa_s
->auto_select
);
2449 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2451 int bh
, bss_load
, conn_capab
;
2452 cred
= interworking_credentials_available(wpa_s
, bss
,
2457 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) {
2459 * We currently support only HS 2.0 networks and those
2460 * are required to use WPA2-Enterprise.
2462 wpa_msg(wpa_s
, MSG_DEBUG
,
2463 "Interworking: Credential match with " MACSTR
2464 " but network does not use RSN",
2465 MAC2STR(bss
->bssid
));
2470 res
= interworking_home_sp(wpa_s
, bss
->anqp
?
2471 bss
->anqp
->domain_name
: NULL
);
2478 bh
= cred_below_min_backhaul(wpa_s
, cred
, bss
);
2479 bss_load
= cred_over_max_bss_load(wpa_s
, cred
, bss
);
2480 conn_capab
= cred_conn_capab_missing(wpa_s
, cred
, bss
);
2481 wpa_msg(wpa_s
, MSG_INFO
, "%s" MACSTR
" type=%s%s%s%s id=%d priority=%d sp_priority=%d",
2482 excluded
? INTERWORKING_BLACKLISTED
: INTERWORKING_AP
,
2483 MAC2STR(bss
->bssid
), type
,
2484 bh
? " below_min_backhaul=1" : "",
2485 bss_load
? " over_max_bss_load=1" : "",
2486 conn_capab
? " conn_capab_missing=1" : "",
2487 cred
->id
, cred
->priority
, cred
->sp_priority
);
2490 if (wpa_s
->auto_select
||
2491 (wpa_s
->conf
->auto_interworking
&&
2492 wpa_s
->auto_network_select
)) {
2493 if (bh
|| bss_load
|| conn_capab
) {
2494 if (selected2_cred
== NULL
||
2495 cred_prio_cmp(cred
, selected2_cred
) > 0) {
2496 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected2");
2498 selected2_cred
= cred
;
2501 (selected2_home_cred
== NULL
||
2502 cred_prio_cmp(cred
, selected2_home_cred
) >
2504 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected2_home");
2505 selected2_home
= bss
;
2506 selected2_home_cred
= cred
;
2509 if (selected_cred
== NULL
||
2510 cred_prio_cmp(cred
, selected_cred
) > 0) {
2511 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected");
2513 selected_cred
= cred
;
2516 (selected_home_cred
== NULL
||
2517 cred_prio_cmp(cred
, selected_home_cred
) >
2519 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected_home");
2520 selected_home
= bss
;
2521 selected_home_cred
= cred
;
2527 if (selected_home
&& selected_home
!= selected
&&
2528 selected_home_cred
&&
2529 (selected_cred
== NULL
||
2530 cred_prio_cmp(selected_home_cred
, selected_cred
) >= 0)) {
2531 /* Prefer network operated by the Home SP */
2532 wpa_printf(MSG_DEBUG
, "Interworking: Overrided selected with selected_home");
2533 selected
= selected_home
;
2534 selected_cred
= selected_home_cred
;
2538 if (selected2_home
) {
2539 wpa_printf(MSG_DEBUG
, "Interworking: Use home BSS with BW limit mismatch since no other network could be selected");
2540 selected
= selected2_home
;
2541 selected_cred
= selected2_home_cred
;
2542 } else if (selected2
) {
2543 wpa_printf(MSG_DEBUG
, "Interworking: Use visited BSS with BW limit mismatch since no other network could be selected");
2544 selected
= selected2
;
2545 selected_cred
= selected2_cred
;
2551 * No matching network was found based on configured
2552 * credentials. Check whether any of the enabled network blocks
2553 * have matching APs.
2555 if (interworking_find_network_match(wpa_s
)) {
2556 wpa_msg(wpa_s
, MSG_DEBUG
,
2557 "Interworking: Possible BSS match for enabled network configurations");
2558 if (wpa_s
->auto_select
) {
2559 interworking_reconnect(wpa_s
);
2564 if (wpa_s
->auto_network_select
) {
2565 wpa_msg(wpa_s
, MSG_DEBUG
,
2566 "Interworking: Continue scanning after ANQP fetch");
2567 wpa_supplicant_req_scan(wpa_s
, wpa_s
->scan_interval
,
2572 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_NO_MATCH
"No network "
2573 "with matching credentials found");
2574 if (wpa_s
->wpa_state
== WPA_SCANNING
)
2575 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2579 wpa_printf(MSG_DEBUG
, "Interworking: Selected " MACSTR
,
2580 MAC2STR(selected
->bssid
));
2581 selected
= pick_best_roaming_partner(wpa_s
, selected
,
2583 wpa_printf(MSG_DEBUG
, "Interworking: Selected " MACSTR
2584 " (after best roaming partner selection)",
2585 MAC2STR(selected
->bssid
));
2586 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_SELECTED MACSTR
,
2587 MAC2STR(selected
->bssid
));
2588 interworking_connect(wpa_s
, selected
, 0);
2589 } else if (wpa_s
->wpa_state
== WPA_SCANNING
)
2590 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2594 static struct wpa_bss_anqp
*
2595 interworking_match_anqp_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
2597 struct wpa_bss
*other
;
2599 if (is_zero_ether_addr(bss
->hessid
))
2600 return NULL
; /* Cannot be in the same homegenous ESS */
2602 dl_list_for_each(other
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2605 if (other
->anqp
== NULL
)
2607 if (other
->anqp
->roaming_consortium
== NULL
&&
2608 other
->anqp
->nai_realm
== NULL
&&
2609 other
->anqp
->anqp_3gpp
== NULL
&&
2610 other
->anqp
->domain_name
== NULL
)
2612 if (!(other
->flags
& WPA_BSS_ANQP_FETCH_TRIED
))
2614 if (os_memcmp(bss
->hessid
, other
->hessid
, ETH_ALEN
) != 0)
2616 if (bss
->ssid_len
!= other
->ssid_len
||
2617 os_memcmp(bss
->ssid
, other
->ssid
, bss
->ssid_len
) != 0)
2620 wpa_msg(wpa_s
, MSG_DEBUG
,
2621 "Interworking: Share ANQP data with already fetched BSSID "
2622 MACSTR
" and " MACSTR
,
2623 MAC2STR(other
->bssid
), MAC2STR(bss
->bssid
));
2624 other
->anqp
->users
++;
2632 static void interworking_next_anqp_fetch(struct wpa_supplicant
*wpa_s
)
2634 struct wpa_bss
*bss
;
2637 wpa_printf(MSG_DEBUG
, "Interworking: next_anqp_fetch - "
2638 "fetch_anqp_in_progress=%d fetch_osu_icon_in_progress=%d",
2639 wpa_s
->fetch_anqp_in_progress
,
2640 wpa_s
->fetch_osu_icon_in_progress
);
2642 if (eloop_terminated() || !wpa_s
->fetch_anqp_in_progress
) {
2643 wpa_printf(MSG_DEBUG
, "Interworking: Stop next-ANQP-fetch");
2648 if (wpa_s
->fetch_osu_icon_in_progress
) {
2649 wpa_printf(MSG_DEBUG
, "Interworking: Next icon (in progress)");
2650 hs20_next_osu_icon(wpa_s
);
2653 #endif /* CONFIG_HS20 */
2655 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2656 if (!(bss
->caps
& IEEE80211_CAP_ESS
))
2658 if (!wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_INTERWORKING
))
2659 continue; /* AP does not support Interworking */
2660 if (disallowed_bssid(wpa_s
, bss
->bssid
) ||
2661 disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
))
2662 continue; /* Disallowed BSS */
2664 if (!(bss
->flags
& WPA_BSS_ANQP_FETCH_TRIED
)) {
2665 if (bss
->anqp
== NULL
) {
2666 bss
->anqp
= interworking_match_anqp_info(wpa_s
,
2669 /* Shared data already fetched */
2672 bss
->anqp
= wpa_bss_anqp_alloc();
2673 if (bss
->anqp
== NULL
)
2677 bss
->flags
|= WPA_BSS_ANQP_FETCH_TRIED
;
2678 wpa_msg(wpa_s
, MSG_INFO
, "Starting ANQP fetch for "
2679 MACSTR
" (HESSID " MACSTR
")",
2680 MAC2STR(bss
->bssid
), MAC2STR(bss
->hessid
));
2681 interworking_anqp_send_req(wpa_s
, bss
);
2688 if (wpa_s
->fetch_osu_info
) {
2689 if (wpa_s
->num_prov_found
== 0 &&
2690 wpa_s
->fetch_osu_waiting_scan
&&
2691 wpa_s
->num_osu_scans
< 3) {
2692 wpa_printf(MSG_DEBUG
, "HS 2.0: No OSU providers seen - try to scan again");
2693 hs20_start_osu_scan(wpa_s
);
2696 wpa_printf(MSG_DEBUG
, "Interworking: Next icon");
2697 hs20_osu_icon_fetch(wpa_s
);
2700 #endif /* CONFIG_HS20 */
2701 wpa_msg(wpa_s
, MSG_INFO
, "ANQP fetch completed");
2702 wpa_s
->fetch_anqp_in_progress
= 0;
2703 if (wpa_s
->network_select
)
2704 interworking_select_network(wpa_s
);
2709 void interworking_start_fetch_anqp(struct wpa_supplicant
*wpa_s
)
2711 struct wpa_bss
*bss
;
2713 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
)
2714 bss
->flags
&= ~WPA_BSS_ANQP_FETCH_TRIED
;
2716 wpa_s
->fetch_anqp_in_progress
= 1;
2719 * Start actual ANQP operation from eloop call to make sure the loop
2720 * does not end up using excessive recursion.
2722 eloop_register_timeout(0, 0, interworking_continue_anqp
, wpa_s
, NULL
);
2726 int interworking_fetch_anqp(struct wpa_supplicant
*wpa_s
)
2728 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
)
2731 wpa_s
->network_select
= 0;
2732 wpa_s
->fetch_all_anqp
= 1;
2733 wpa_s
->fetch_osu_info
= 0;
2735 interworking_start_fetch_anqp(wpa_s
);
2741 void interworking_stop_fetch_anqp(struct wpa_supplicant
*wpa_s
)
2743 if (!wpa_s
->fetch_anqp_in_progress
)
2746 wpa_s
->fetch_anqp_in_progress
= 0;
2750 int anqp_send_req(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
2751 u16 info_ids
[], size_t num_ids
, u32 subtypes
,
2755 struct wpabuf
*extra_buf
= NULL
;
2758 struct wpa_bss
*bss
;
2761 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
2763 wpa_printf(MSG_WARNING
,
2764 "ANQP: Cannot send query to unknown BSS "
2765 MACSTR
, MAC2STR(dst
));
2769 wpa_bss_anqp_unshare_alloc(bss
);
2772 wpa_msg(wpa_s
, MSG_DEBUG
,
2773 "ANQP: Query Request to " MACSTR
" for %u id(s)",
2774 MAC2STR(dst
), (unsigned int) num_ids
);
2777 if (subtypes
!= 0) {
2778 extra_buf
= wpabuf_alloc(100);
2779 if (extra_buf
== NULL
)
2781 hs20_put_anqp_req(subtypes
, NULL
, 0, extra_buf
);
2783 #endif /* CONFIG_HS20 */
2789 mbo
= mbo_build_anqp_buf(wpa_s
, bss
, mbo_subtypes
);
2791 if (wpabuf_resize(&extra_buf
, wpabuf_len(mbo
))) {
2792 wpabuf_free(extra_buf
);
2796 wpabuf_put_buf(extra_buf
, mbo
);
2800 #endif /* CONFIG_MBO */
2802 buf
= anqp_build_req(info_ids
, num_ids
, extra_buf
);
2803 wpabuf_free(extra_buf
);
2807 res
= gas_query_req(wpa_s
->gas
, dst
, freq
, 0, buf
, anqp_resp_cb
, wpa_s
);
2809 wpa_msg(wpa_s
, MSG_DEBUG
, "ANQP: Failed to send Query Request");
2813 wpa_msg(wpa_s
, MSG_DEBUG
,
2814 "ANQP: Query started with dialog token %u", res
);
2821 static void anqp_add_extra(struct wpa_supplicant
*wpa_s
,
2822 struct wpa_bss_anqp
*anqp
, u16 info_id
,
2823 const u8
*data
, size_t slen
)
2825 struct wpa_bss_anqp_elem
*tmp
, *elem
= NULL
;
2830 dl_list_for_each(tmp
, &anqp
->anqp_elems
, struct wpa_bss_anqp_elem
,
2832 if (tmp
->infoid
== info_id
) {
2839 elem
= os_zalloc(sizeof(*elem
));
2842 elem
->infoid
= info_id
;
2843 dl_list_add(&anqp
->anqp_elems
, &elem
->list
);
2845 wpabuf_free(elem
->payload
);
2848 elem
->payload
= wpabuf_alloc_copy(data
, slen
);
2849 if (!elem
->payload
) {
2850 dl_list_del(&elem
->list
);
2856 static void interworking_parse_venue_url(struct wpa_supplicant
*wpa_s
,
2857 const u8
*data
, size_t len
)
2859 const u8
*pos
= data
, *end
= data
+ len
;
2862 while (end
- pos
>= 2) {
2866 if (slen
< 1 || slen
> end
- pos
) {
2867 wpa_printf(MSG_DEBUG
,
2868 "ANQP: Truncated Venue URL Duple field");
2873 os_memcpy(url
, pos
, slen
- 1);
2874 url
[slen
- 1] = '\0';
2875 wpa_msg(wpa_s
, MSG_INFO
, RX_VENUE_URL
"%u %s", num
, url
);
2881 static void interworking_parse_rx_anqp_resp(struct wpa_supplicant
*wpa_s
,
2882 struct wpa_bss
*bss
, const u8
*sa
,
2884 const u8
*data
, size_t slen
,
2887 const u8
*pos
= data
;
2888 struct wpa_bss_anqp
*anqp
= NULL
;
2895 case ANQP_CAPABILITY_LIST
:
2896 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2897 " ANQP Capability list", MAC2STR(sa
));
2898 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Capability list",
2901 wpabuf_free(anqp
->capability_list
);
2902 anqp
->capability_list
= wpabuf_alloc_copy(pos
, slen
);
2905 case ANQP_VENUE_NAME
:
2906 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2907 " Venue Name", MAC2STR(sa
));
2908 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Venue Name", pos
, slen
);
2910 wpabuf_free(anqp
->venue_name
);
2911 anqp
->venue_name
= wpabuf_alloc_copy(pos
, slen
);
2914 case ANQP_NETWORK_AUTH_TYPE
:
2915 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2916 " Network Authentication Type information",
2918 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Network Authentication "
2921 wpabuf_free(anqp
->network_auth_type
);
2922 anqp
->network_auth_type
= wpabuf_alloc_copy(pos
, slen
);
2925 case ANQP_ROAMING_CONSORTIUM
:
2926 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2927 " Roaming Consortium list", MAC2STR(sa
));
2928 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Roaming Consortium",
2931 wpabuf_free(anqp
->roaming_consortium
);
2932 anqp
->roaming_consortium
= wpabuf_alloc_copy(pos
, slen
);
2935 case ANQP_IP_ADDR_TYPE_AVAILABILITY
:
2936 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2937 " IP Address Type Availability information",
2939 wpa_hexdump(MSG_MSGDUMP
, "ANQP: IP Address Availability",
2942 wpabuf_free(anqp
->ip_addr_type_availability
);
2943 anqp
->ip_addr_type_availability
=
2944 wpabuf_alloc_copy(pos
, slen
);
2947 case ANQP_NAI_REALM
:
2948 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2949 " NAI Realm list", MAC2STR(sa
));
2950 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: NAI Realm", pos
, slen
);
2952 wpabuf_free(anqp
->nai_realm
);
2953 anqp
->nai_realm
= wpabuf_alloc_copy(pos
, slen
);
2956 case ANQP_3GPP_CELLULAR_NETWORK
:
2957 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2958 " 3GPP Cellular Network information", MAC2STR(sa
));
2959 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: 3GPP Cellular Network",
2962 wpabuf_free(anqp
->anqp_3gpp
);
2963 anqp
->anqp_3gpp
= wpabuf_alloc_copy(pos
, slen
);
2966 case ANQP_DOMAIN_NAME
:
2967 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2968 " Domain Name list", MAC2STR(sa
));
2969 wpa_hexdump_ascii(MSG_MSGDUMP
, "ANQP: Domain Name", pos
, slen
);
2971 wpabuf_free(anqp
->domain_name
);
2972 anqp
->domain_name
= wpabuf_alloc_copy(pos
, slen
);
2976 case ANQP_FILS_REALM_INFO
:
2977 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
2978 " FILS Realm Information", MAC2STR(sa
));
2979 wpa_hexdump_ascii(MSG_MSGDUMP
, "ANQP: FILS Realm Information",
2982 wpabuf_free(anqp
->fils_realm_info
);
2983 anqp
->fils_realm_info
= wpabuf_alloc_copy(pos
, slen
);
2986 #endif /* CONFIG_FILS */
2987 case ANQP_VENUE_URL
:
2988 wpa_msg(wpa_s
, MSG_INFO
, RX_ANQP MACSTR
" Venue URL",
2990 anqp_add_extra(wpa_s
, anqp
, info_id
, pos
, slen
);
2992 if (!pmf_in_use(wpa_s
, sa
)) {
2993 wpa_printf(MSG_DEBUG
,
2994 "ANQP: Ignore Venue URL since PMF was not enabled");
2997 interworking_parse_venue_url(wpa_s
, pos
, slen
);
2999 case ANQP_VENDOR_SPECIFIC
:
3003 switch (WPA_GET_BE24(pos
)) {
3015 case HS20_ANQP_OUI_TYPE
:
3016 hs20_parse_rx_hs20_anqp_resp(wpa_s
, bss
, sa
,
3020 #endif /* CONFIG_HS20 */
3022 case MBO_ANQP_OUI_TYPE
:
3023 mbo_parse_rx_anqp_resp(wpa_s
, bss
, sa
,
3026 #endif /* CONFIG_MBO */
3028 wpa_msg(wpa_s
, MSG_DEBUG
,
3029 "ANQP: Unsupported ANQP vendor type %u",
3035 wpa_msg(wpa_s
, MSG_DEBUG
,
3036 "Interworking: Unsupported vendor-specific ANQP OUI %06x",
3042 wpa_msg(wpa_s
, MSG_DEBUG
,
3043 "Interworking: Unsupported ANQP Info ID %u", info_id
);
3044 anqp_add_extra(wpa_s
, anqp
, info_id
, data
, slen
);
3050 void anqp_resp_cb(void *ctx
, const u8
*dst
, u8 dialog_token
,
3051 enum gas_query_result result
,
3052 const struct wpabuf
*adv_proto
,
3053 const struct wpabuf
*resp
, u16 status_code
)
3055 struct wpa_supplicant
*wpa_s
= ctx
;
3060 struct wpa_bss
*bss
= NULL
, *tmp
;
3061 const char *anqp_result
= "SUCCESS";
3063 wpa_printf(MSG_DEBUG
, "Interworking: anqp_resp_cb dst=" MACSTR
3064 " dialog_token=%u result=%d status_code=%u",
3065 MAC2STR(dst
), dialog_token
, result
, status_code
);
3066 if (result
!= GAS_QUERY_SUCCESS
) {
3068 if (wpa_s
->fetch_osu_icon_in_progress
)
3069 hs20_icon_fetch_failed(wpa_s
);
3070 #endif /* CONFIG_HS20 */
3071 anqp_result
= "FAILURE";
3075 pos
= wpabuf_head(adv_proto
);
3076 if (wpabuf_len(adv_proto
) < 4 || pos
[0] != WLAN_EID_ADV_PROTO
||
3077 pos
[1] < 2 || pos
[3] != ACCESS_NETWORK_QUERY_PROTOCOL
) {
3078 wpa_msg(wpa_s
, MSG_DEBUG
,
3079 "ANQP: Unexpected Advertisement Protocol in response");
3081 if (wpa_s
->fetch_osu_icon_in_progress
)
3082 hs20_icon_fetch_failed(wpa_s
);
3083 #endif /* CONFIG_HS20 */
3084 anqp_result
= "INVALID_FRAME";
3089 * If possible, select the BSS entry based on which BSS entry was used
3090 * for the request. This can help in cases where multiple BSS entries
3091 * may exist for the same AP.
3093 dl_list_for_each_reverse(tmp
, &wpa_s
->bss
, struct wpa_bss
, list
) {
3094 if (tmp
== wpa_s
->interworking_gas_bss
&&
3095 os_memcmp(tmp
->bssid
, dst
, ETH_ALEN
) == 0) {
3101 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
3103 pos
= wpabuf_head(resp
);
3104 end
= pos
+ wpabuf_len(resp
);
3107 unsigned int left
= end
- pos
;
3110 wpa_msg(wpa_s
, MSG_DEBUG
, "ANQP: Invalid element");
3111 anqp_result
= "INVALID_FRAME";
3112 goto out_parse_done
;
3114 info_id
= WPA_GET_LE16(pos
);
3116 slen
= WPA_GET_LE16(pos
);
3120 wpa_msg(wpa_s
, MSG_DEBUG
,
3121 "ANQP: Invalid element length for Info ID %u",
3123 anqp_result
= "INVALID_FRAME";
3124 goto out_parse_done
;
3126 interworking_parse_rx_anqp_resp(wpa_s
, bss
, dst
, info_id
, pos
,
3127 slen
, dialog_token
);
3133 hs20_notify_parse_done(wpa_s
);
3134 #endif /* CONFIG_HS20 */
3136 wpa_msg(wpa_s
, MSG_INFO
, ANQP_QUERY_DONE
"addr=" MACSTR
" result=%s",
3137 MAC2STR(dst
), anqp_result
);
3141 static void interworking_scan_res_handler(struct wpa_supplicant
*wpa_s
,
3142 struct wpa_scan_results
*scan_res
)
3144 wpa_msg(wpa_s
, MSG_DEBUG
,
3145 "Interworking: Scan results available - start ANQP fetch");
3146 interworking_start_fetch_anqp(wpa_s
);
3150 int interworking_select(struct wpa_supplicant
*wpa_s
, int auto_select
,
3153 interworking_stop_fetch_anqp(wpa_s
);
3154 wpa_s
->network_select
= 1;
3155 wpa_s
->auto_network_select
= 0;
3156 wpa_s
->auto_select
= !!auto_select
;
3157 wpa_s
->fetch_all_anqp
= 0;
3158 wpa_s
->fetch_osu_info
= 0;
3159 wpa_msg(wpa_s
, MSG_DEBUG
,
3160 "Interworking: Start scan for network selection");
3161 wpa_s
->scan_res_handler
= interworking_scan_res_handler
;
3162 wpa_s
->normal_scans
= 0;
3163 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
3164 os_free(wpa_s
->manual_scan_freqs
);
3165 wpa_s
->manual_scan_freqs
= freqs
;
3166 wpa_s
->after_wps
= 0;
3167 wpa_s
->known_wps_freq
= 0;
3168 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3174 static void gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
3175 enum gas_query_result result
,
3176 const struct wpabuf
*adv_proto
,
3177 const struct wpabuf
*resp
, u16 status_code
)
3179 struct wpa_supplicant
*wpa_s
= ctx
;
3182 wpa_msg(wpa_s
, MSG_INFO
, GAS_RESPONSE_INFO
"addr=" MACSTR
3183 " dialog_token=%d status_code=%d resp_len=%d",
3184 MAC2STR(addr
), dialog_token
, status_code
,
3185 resp
? (int) wpabuf_len(resp
) : -1);
3189 n
= wpabuf_dup(resp
);
3192 wpabuf_free(wpa_s
->prev_gas_resp
);
3193 wpa_s
->prev_gas_resp
= wpa_s
->last_gas_resp
;
3194 os_memcpy(wpa_s
->prev_gas_addr
, wpa_s
->last_gas_addr
, ETH_ALEN
);
3195 wpa_s
->prev_gas_dialog_token
= wpa_s
->last_gas_dialog_token
;
3196 wpa_s
->last_gas_resp
= n
;
3197 os_memcpy(wpa_s
->last_gas_addr
, addr
, ETH_ALEN
);
3198 wpa_s
->last_gas_dialog_token
= dialog_token
;
3202 int gas_send_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
3203 const struct wpabuf
*adv_proto
,
3204 const struct wpabuf
*query
)
3209 struct wpa_bss
*bss
;
3212 u8 query_resp_len_limit
= 0;
3214 freq
= wpa_s
->assoc_freq
;
3215 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
3221 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS request to " MACSTR
" (freq %d MHz)",
3222 MAC2STR(dst
), freq
);
3223 wpa_hexdump_buf(MSG_DEBUG
, "Advertisement Protocol ID", adv_proto
);
3224 wpa_hexdump_buf(MSG_DEBUG
, "GAS Query", query
);
3226 len
= 3 + wpabuf_len(adv_proto
) + 2;
3228 len
+= wpabuf_len(query
);
3229 buf
= gas_build_initial_req(0, len
);
3233 /* Advertisement Protocol IE */
3234 wpabuf_put_u8(buf
, WLAN_EID_ADV_PROTO
);
3235 wpabuf_put_u8(buf
, 1 + wpabuf_len(adv_proto
)); /* Length */
3236 wpabuf_put_u8(buf
, query_resp_len_limit
& 0x7f);
3237 wpabuf_put_buf(buf
, adv_proto
);
3241 wpabuf_put_le16(buf
, wpabuf_len(query
));
3242 wpabuf_put_buf(buf
, query
);
3244 wpabuf_put_le16(buf
, 0);
3246 res
= gas_query_req(wpa_s
->gas
, dst
, freq
, 0, buf
, gas_resp_cb
, wpa_s
);
3248 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS: Failed to send Query Request");
3252 wpa_msg(wpa_s
, MSG_DEBUG
,
3253 "GAS: Query started with dialog token %u", res
);