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));
109 len_pos
= gas_anqp_add_element(buf
, ANQP_QUERY_LIST
);
110 for (i
= 0; i
< num_ids
; i
++)
111 wpabuf_put_le16(buf
, info_ids
[i
]);
112 gas_anqp_set_element_len(buf
, len_pos
);
114 wpabuf_put_buf(buf
, extra
);
116 gas_anqp_set_len(buf
);
122 static void interworking_anqp_resp_cb(void *ctx
, const u8
*dst
,
124 enum gas_query_result result
,
125 const struct wpabuf
*adv_proto
,
126 const struct wpabuf
*resp
,
129 struct wpa_supplicant
*wpa_s
= ctx
;
131 wpa_printf(MSG_DEBUG
, "ANQP: Response callback dst=" MACSTR
132 " dialog_token=%u result=%d status_code=%u",
133 MAC2STR(dst
), dialog_token
, result
, status_code
);
134 anqp_resp_cb(wpa_s
, dst
, dialog_token
, result
, adv_proto
, resp
,
136 interworking_next_anqp_fetch(wpa_s
);
140 static int cred_with_roaming_consortium(struct wpa_supplicant
*wpa_s
)
142 struct wpa_cred
*cred
;
144 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
145 if (cred
->roaming_consortium_len
)
147 if (cred
->required_roaming_consortium_len
)
154 static int cred_with_3gpp(struct wpa_supplicant
*wpa_s
)
156 struct wpa_cred
*cred
;
158 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
159 if (cred
->pcsc
|| cred
->imsi
)
166 static int cred_with_nai_realm(struct wpa_supplicant
*wpa_s
)
168 struct wpa_cred
*cred
;
170 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
171 if (cred
->pcsc
|| cred
->imsi
)
173 if (!cred
->eap_method
)
175 if (cred
->realm
&& cred
->roaming_consortium_len
== 0)
182 static int cred_with_domain(struct wpa_supplicant
*wpa_s
)
184 struct wpa_cred
*cred
;
186 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
187 if (cred
->domain
|| cred
->pcsc
|| cred
->imsi
||
188 cred
->roaming_partner
)
197 static int cred_with_min_backhaul(struct wpa_supplicant
*wpa_s
)
199 struct wpa_cred
*cred
;
201 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
202 if (cred
->min_dl_bandwidth_home
||
203 cred
->min_ul_bandwidth_home
||
204 cred
->min_dl_bandwidth_roaming
||
205 cred
->min_ul_bandwidth_roaming
)
212 static int cred_with_conn_capab(struct wpa_supplicant
*wpa_s
)
214 struct wpa_cred
*cred
;
216 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
217 if (cred
->num_req_conn_capab
)
223 #endif /* CONFIG_HS20 */
226 static int additional_roaming_consortiums(struct wpa_bss
*bss
)
229 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
230 if (ie
== NULL
|| ie
[1] == 0)
232 return ie
[2]; /* Number of ANQP OIs */
236 static void interworking_continue_anqp(void *eloop_ctx
, void *sock_ctx
)
238 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
239 interworking_next_anqp_fetch(wpa_s
);
243 static int interworking_anqp_send_req(struct wpa_supplicant
*wpa_s
,
250 size_t num_info_ids
= 0;
251 struct wpabuf
*extra
= NULL
;
252 int all
= wpa_s
->fetch_all_anqp
;
254 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: ANQP Query Request to " MACSTR
,
255 MAC2STR(bss
->bssid
));
256 wpa_s
->interworking_gas_bss
= bss
;
258 info_ids
[num_info_ids
++] = ANQP_CAPABILITY_LIST
;
260 info_ids
[num_info_ids
++] = ANQP_VENUE_NAME
;
261 info_ids
[num_info_ids
++] = ANQP_NETWORK_AUTH_TYPE
;
263 if (all
|| (cred_with_roaming_consortium(wpa_s
) &&
264 additional_roaming_consortiums(bss
)))
265 info_ids
[num_info_ids
++] = ANQP_ROAMING_CONSORTIUM
;
267 info_ids
[num_info_ids
++] = ANQP_IP_ADDR_TYPE_AVAILABILITY
;
268 if (all
|| cred_with_nai_realm(wpa_s
))
269 info_ids
[num_info_ids
++] = ANQP_NAI_REALM
;
270 if (all
|| cred_with_3gpp(wpa_s
)) {
271 info_ids
[num_info_ids
++] = ANQP_3GPP_CELLULAR_NETWORK
;
272 wpa_supplicant_scard_init(wpa_s
, NULL
);
274 if (all
|| cred_with_domain(wpa_s
))
275 info_ids
[num_info_ids
++] = ANQP_DOMAIN_NAME
;
276 wpa_hexdump(MSG_DEBUG
, "Interworking: ANQP Query info",
277 (u8
*) info_ids
, num_info_ids
* 2);
280 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
283 extra
= wpabuf_alloc(100);
287 len_pos
= gas_anqp_add_element(extra
, ANQP_VENDOR_SPECIFIC
);
288 wpabuf_put_be24(extra
, OUI_WFA
);
289 wpabuf_put_u8(extra
, HS20_ANQP_OUI_TYPE
);
290 wpabuf_put_u8(extra
, HS20_STYPE_QUERY_LIST
);
291 wpabuf_put_u8(extra
, 0); /* Reserved */
292 wpabuf_put_u8(extra
, HS20_STYPE_CAPABILITY_LIST
);
295 HS20_STYPE_OPERATOR_FRIENDLY_NAME
);
296 if (all
|| cred_with_min_backhaul(wpa_s
))
297 wpabuf_put_u8(extra
, HS20_STYPE_WAN_METRICS
);
298 if (all
|| cred_with_conn_capab(wpa_s
))
299 wpabuf_put_u8(extra
, HS20_STYPE_CONNECTION_CAPABILITY
);
301 wpabuf_put_u8(extra
, HS20_STYPE_OPERATING_CLASS
);
303 wpabuf_put_u8(extra
, HS20_STYPE_OSU_PROVIDERS_LIST
);
304 gas_anqp_set_element_len(extra
, len_pos
);
306 #endif /* CONFIG_HS20 */
308 buf
= anqp_build_req(info_ids
, num_info_ids
, extra
);
313 res
= gas_query_req(wpa_s
->gas
, bss
->bssid
, bss
->freq
, buf
,
314 interworking_anqp_resp_cb
, wpa_s
);
316 wpa_msg(wpa_s
, MSG_DEBUG
, "ANQP: Failed to send Query Request");
319 eloop_register_timeout(0, 0, interworking_continue_anqp
, wpa_s
,
322 wpa_msg(wpa_s
, MSG_DEBUG
,
323 "ANQP: Query started with dialog token %u", res
);
329 struct nai_realm_eap
{
332 enum nai_realm_eap_auth_inner_non_eap inner_non_eap
;
334 u8 tunneled_cred_type
;
341 struct nai_realm_eap
*eap
;
345 static void nai_realm_free(struct nai_realm
*realms
, u16 count
)
351 for (i
= 0; i
< count
; i
++) {
352 os_free(realms
[i
].eap
);
353 os_free(realms
[i
].realm
);
359 static const u8
* nai_realm_parse_eap(struct nai_realm_eap
*e
, const u8
*pos
,
362 u8 elen
, auth_count
, a
;
366 wpa_printf(MSG_DEBUG
, "No room for EAP Method fixed fields");
371 if (elen
> end
- pos
|| elen
< 2) {
372 wpa_printf(MSG_DEBUG
, "No room for EAP Method subfield");
378 wpa_printf(MSG_DEBUG
, "EAP Method: len=%u method=%u auth_count=%u",
379 elen
, e
->method
, auth_count
);
381 for (a
= 0; a
< auth_count
; a
++) {
385 wpa_printf(MSG_DEBUG
,
386 "No room for Authentication Parameter subfield header");
392 if (len
> end
- pos
) {
393 wpa_printf(MSG_DEBUG
,
394 "No room for Authentication Parameter subfield");
399 case NAI_REALM_EAP_AUTH_NON_EAP_INNER_AUTH
:
402 e
->inner_non_eap
= *pos
;
403 if (e
->method
!= EAP_TYPE_TTLS
)
406 case NAI_REALM_INNER_NON_EAP_PAP
:
407 wpa_printf(MSG_DEBUG
, "EAP-TTLS/PAP");
409 case NAI_REALM_INNER_NON_EAP_CHAP
:
410 wpa_printf(MSG_DEBUG
, "EAP-TTLS/CHAP");
412 case NAI_REALM_INNER_NON_EAP_MSCHAP
:
413 wpa_printf(MSG_DEBUG
, "EAP-TTLS/MSCHAP");
415 case NAI_REALM_INNER_NON_EAP_MSCHAPV2
:
416 wpa_printf(MSG_DEBUG
, "EAP-TTLS/MSCHAPV2");
420 case NAI_REALM_EAP_AUTH_INNER_AUTH_EAP_METHOD
:
423 e
->inner_method
= *pos
;
424 wpa_printf(MSG_DEBUG
, "Inner EAP method: %u",
427 case NAI_REALM_EAP_AUTH_CRED_TYPE
:
431 wpa_printf(MSG_DEBUG
, "Credential Type: %u",
434 case NAI_REALM_EAP_AUTH_TUNNELED_CRED_TYPE
:
437 e
->tunneled_cred_type
= *pos
;
438 wpa_printf(MSG_DEBUG
, "Tunneled EAP Method Credential "
439 "Type: %u", e
->tunneled_cred_type
);
442 wpa_printf(MSG_DEBUG
, "Unsupported Authentication "
443 "Parameter: id=%u len=%u", id
, len
);
444 wpa_hexdump(MSG_DEBUG
, "Authentication Parameter "
456 static const u8
* nai_realm_parse_realm(struct nai_realm
*r
, const u8
*pos
,
464 wpa_printf(MSG_DEBUG
, "No room for NAI Realm Data "
469 len
= WPA_GET_LE16(pos
); /* NAI Realm Data field Length */
471 if (len
> end
- pos
|| len
< 3) {
472 wpa_printf(MSG_DEBUG
, "No room for NAI Realm Data "
474 len
, (unsigned int) (end
- pos
));
479 r
->encoding
= *pos
++;
481 if (realm_len
> f_end
- pos
) {
482 wpa_printf(MSG_DEBUG
, "No room for NAI Realm "
484 realm_len
, (unsigned int) (f_end
- pos
));
487 wpa_hexdump_ascii(MSG_DEBUG
, "NAI Realm", pos
, realm_len
);
488 r
->realm
= dup_binstr(pos
, realm_len
);
489 if (r
->realm
== NULL
)
493 if (f_end
- pos
< 1) {
494 wpa_printf(MSG_DEBUG
, "No room for EAP Method Count");
497 r
->eap_count
= *pos
++;
498 wpa_printf(MSG_DEBUG
, "EAP Count: %u", r
->eap_count
);
499 if (r
->eap_count
* 3 > f_end
- pos
) {
500 wpa_printf(MSG_DEBUG
, "No room for EAP Methods");
503 r
->eap
= os_calloc(r
->eap_count
, sizeof(struct nai_realm_eap
));
507 for (e
= 0; e
< r
->eap_count
; e
++) {
508 pos
= nai_realm_parse_eap(&r
->eap
[e
], pos
, f_end
);
517 static struct nai_realm
* nai_realm_parse(struct wpabuf
*anqp
, u16
*count
)
519 struct nai_realm
*realm
;
526 left
= wpabuf_len(anqp
);
530 pos
= wpabuf_head_u8(anqp
);
532 num
= WPA_GET_LE16(pos
);
533 wpa_printf(MSG_DEBUG
, "NAI Realm Count: %u", num
);
537 if (num
> left
/ 5) {
538 wpa_printf(MSG_DEBUG
, "Invalid NAI Realm Count %u - not "
539 "enough data (%u octets) for that many realms",
540 num
, (unsigned int) left
);
544 realm
= os_calloc(num
, sizeof(struct nai_realm
));
548 for (i
= 0; i
< num
; i
++) {
549 pos
= nai_realm_parse_realm(&realm
[i
], pos
, end
);
551 nai_realm_free(realm
, num
);
561 static int nai_realm_match(struct nai_realm
*realm
, const char *home_realm
)
563 char *tmp
, *pos
, *end
;
566 if (realm
->realm
== NULL
|| home_realm
== NULL
)
569 if (os_strchr(realm
->realm
, ';') == NULL
)
570 return os_strcasecmp(realm
->realm
, home_realm
) == 0;
572 tmp
= os_strdup(realm
->realm
);
578 end
= os_strchr(pos
, ';');
581 if (os_strcasecmp(pos
, home_realm
) == 0) {
596 static int nai_realm_cred_username(struct wpa_supplicant
*wpa_s
,
597 struct nai_realm_eap
*eap
)
599 if (eap_get_name(EAP_VENDOR_IETF
, eap
->method
) == NULL
) {
600 wpa_msg(wpa_s
, MSG_DEBUG
,
601 "nai-realm-cred-username: EAP method not supported: %d",
603 return 0; /* method not supported */
606 if (eap
->method
!= EAP_TYPE_TTLS
&& eap
->method
!= EAP_TYPE_PEAP
&&
607 eap
->method
!= EAP_TYPE_FAST
) {
608 /* Only tunneled methods with username/password supported */
609 wpa_msg(wpa_s
, MSG_DEBUG
,
610 "nai-realm-cred-username: Method: %d is not TTLS, PEAP, or FAST",
615 if (eap
->method
== EAP_TYPE_PEAP
|| eap
->method
== EAP_TYPE_FAST
) {
616 if (eap
->inner_method
&&
617 eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
) == NULL
) {
618 wpa_msg(wpa_s
, MSG_DEBUG
,
619 "nai-realm-cred-username: PEAP/FAST: Inner method not supported: %d",
623 if (!eap
->inner_method
&&
624 eap_get_name(EAP_VENDOR_IETF
, EAP_TYPE_MSCHAPV2
) == NULL
) {
625 wpa_msg(wpa_s
, MSG_DEBUG
,
626 "nai-realm-cred-username: MSCHAPv2 not supported");
631 if (eap
->method
== EAP_TYPE_TTLS
) {
632 if (eap
->inner_method
== 0 && eap
->inner_non_eap
== 0)
633 return 1; /* Assume TTLS/MSCHAPv2 is used */
634 if (eap
->inner_method
&&
635 eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
) == NULL
) {
636 wpa_msg(wpa_s
, MSG_DEBUG
,
637 "nai-realm-cred-username: TTLS, but inner not supported: %d",
641 if (eap
->inner_non_eap
&&
642 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_PAP
&&
643 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_CHAP
&&
644 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_MSCHAP
&&
645 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_MSCHAPV2
) {
646 wpa_msg(wpa_s
, MSG_DEBUG
,
647 "nai-realm-cred-username: TTLS, inner-non-eap not supported: %d",
653 if (eap
->inner_method
&&
654 eap
->inner_method
!= EAP_TYPE_GTC
&&
655 eap
->inner_method
!= EAP_TYPE_MSCHAPV2
) {
656 wpa_msg(wpa_s
, MSG_DEBUG
,
657 "nai-realm-cred-username: inner-method not GTC or MSCHAPv2: %d",
666 static int nai_realm_cred_cert(struct wpa_supplicant
*wpa_s
,
667 struct nai_realm_eap
*eap
)
669 if (eap_get_name(EAP_VENDOR_IETF
, eap
->method
) == NULL
) {
670 wpa_msg(wpa_s
, MSG_DEBUG
,
671 "nai-realm-cred-cert: Method not supported: %d",
673 return 0; /* method not supported */
676 if (eap
->method
!= EAP_TYPE_TLS
) {
677 /* Only EAP-TLS supported for credential authentication */
678 wpa_msg(wpa_s
, MSG_DEBUG
,
679 "nai-realm-cred-cert: Method not TLS: %d",
688 static struct nai_realm_eap
* nai_realm_find_eap(struct wpa_supplicant
*wpa_s
,
689 struct wpa_cred
*cred
,
690 struct nai_realm
*realm
)
694 if (cred
->username
== NULL
||
695 cred
->username
[0] == '\0' ||
696 ((cred
->password
== NULL
||
697 cred
->password
[0] == '\0') &&
698 (cred
->private_key
== NULL
||
699 cred
->private_key
[0] == '\0'))) {
700 wpa_msg(wpa_s
, MSG_DEBUG
,
701 "nai-realm-find-eap: incomplete cred info: username: %s password: %s private_key: %s",
702 cred
->username
? cred
->username
: "NULL",
703 cred
->password
? cred
->password
: "NULL",
704 cred
->private_key
? cred
->private_key
: "NULL");
708 for (e
= 0; e
< realm
->eap_count
; e
++) {
709 struct nai_realm_eap
*eap
= &realm
->eap
[e
];
710 if (cred
->password
&& cred
->password
[0] &&
711 nai_realm_cred_username(wpa_s
, eap
))
713 if (cred
->private_key
&& cred
->private_key
[0] &&
714 nai_realm_cred_cert(wpa_s
, eap
))
722 #ifdef INTERWORKING_3GPP
724 static int plmn_id_match(struct wpabuf
*anqp
, const char *imsi
, int mnc_len
)
726 u8 plmn
[3], plmn2
[3];
731 * See Annex A of 3GPP TS 24.234 v8.1.0 for description. The network
732 * operator is allowed to include only two digits of the MNC, so allow
733 * matches based on both two and three digit MNC assumptions. Since some
734 * SIM/USIM cards may not expose MNC length conveniently, we may be
735 * provided the default MNC length 3 here and as such, checking with MNC
736 * length 2 is justifiable even though 3GPP TS 24.234 does not mention
737 * that case. Anyway, MCC/MNC pair where both 2 and 3 digit MNC is used
738 * with otherwise matching values would not be good idea in general, so
739 * this should not result in selecting incorrect networks.
741 /* Match with 3 digit MNC */
742 plmn
[0] = (imsi
[0] - '0') | ((imsi
[1] - '0') << 4);
743 plmn
[1] = (imsi
[2] - '0') | ((imsi
[5] - '0') << 4);
744 plmn
[2] = (imsi
[3] - '0') | ((imsi
[4] - '0') << 4);
745 /* Match with 2 digit MNC */
746 plmn2
[0] = (imsi
[0] - '0') | ((imsi
[1] - '0') << 4);
747 plmn2
[1] = (imsi
[2] - '0') | 0xf0;
748 plmn2
[2] = (imsi
[3] - '0') | ((imsi
[4] - '0') << 4);
752 pos
= wpabuf_head_u8(anqp
);
753 end
= pos
+ wpabuf_len(anqp
);
757 wpa_printf(MSG_DEBUG
, "Unsupported GUD version 0x%x", *pos
);
762 if (udhl
> end
- pos
) {
763 wpa_printf(MSG_DEBUG
, "Invalid UDHL");
768 wpa_printf(MSG_DEBUG
, "Interworking: Matching against MCC/MNC alternatives: %02x:%02x:%02x or %02x:%02x:%02x (IMSI %s, MNC length %d)",
769 plmn
[0], plmn
[1], plmn
[2], plmn2
[0], plmn2
[1], plmn2
[2],
772 while (end
- pos
>= 2) {
781 if (iei
== 0 && len
> 0) {
784 wpa_hexdump(MSG_DEBUG
, "Interworking: PLMN List information element",
787 for (i
= 0; i
< num
; i
++) {
790 if (os_memcmp(pos
, plmn
, 3) == 0 ||
791 os_memcmp(pos
, plmn2
, 3) == 0)
792 return 1; /* Found matching PLMN */
796 wpa_hexdump(MSG_DEBUG
, "Interworking: Unrecognized 3GPP information element",
807 static int build_root_nai(char *nai
, size_t nai_len
, const char *imsi
,
808 size_t mnc_len
, char prefix
)
810 const char *sep
, *msin
;
812 size_t msin_len
, plmn_len
;
815 * TS 23.003, Clause 14 (3GPP to WLAN Interworking)
817 * <aka:0|sim:1><IMSI>@wlan.mnc<MNC>.mcc<MCC>.3gppnetwork.org
818 * <MNC> is zero-padded to three digits in case two-digit MNC is used
821 if (imsi
== NULL
|| os_strlen(imsi
) > 16) {
822 wpa_printf(MSG_DEBUG
, "No valid IMSI available");
825 sep
= os_strchr(imsi
, '-');
827 plmn_len
= sep
- imsi
;
829 } else if (mnc_len
&& os_strlen(imsi
) >= 3 + mnc_len
) {
830 plmn_len
= 3 + mnc_len
;
831 msin
= imsi
+ plmn_len
;
834 if (plmn_len
!= 5 && plmn_len
!= 6)
836 msin_len
= os_strlen(msin
);
842 os_memcpy(pos
, imsi
, plmn_len
);
844 os_memcpy(pos
, msin
, msin_len
);
846 pos
+= os_snprintf(pos
, end
- pos
, "@wlan.mnc");
856 os_snprintf(pos
, end
- pos
, ".mcc%c%c%c.3gppnetwork.org",
857 imsi
[0], imsi
[1], imsi
[2]);
863 static int set_root_nai(struct wpa_ssid
*ssid
, const char *imsi
, char prefix
)
866 if (build_root_nai(nai
, sizeof(nai
), imsi
, 0, prefix
) < 0)
868 return wpa_config_set_quoted(ssid
, "identity", nai
);
871 #endif /* INTERWORKING_3GPP */
874 static int already_connected(struct wpa_supplicant
*wpa_s
,
875 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
877 struct wpa_ssid
*ssid
, *sel_ssid
;
878 struct wpa_bss
*selected
;
880 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
|| wpa_s
->current_ssid
== NULL
)
883 ssid
= wpa_s
->current_ssid
;
884 if (ssid
->parent_cred
!= cred
)
887 if (ssid
->ssid_len
!= bss
->ssid_len
||
888 os_memcmp(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0)
892 selected
= wpa_supplicant_pick_network(wpa_s
, &sel_ssid
);
893 if (selected
&& sel_ssid
&& sel_ssid
->priority
> ssid
->priority
)
894 return 0; /* higher priority network in scan results */
900 static void remove_duplicate_network(struct wpa_supplicant
*wpa_s
,
901 struct wpa_cred
*cred
,
904 struct wpa_ssid
*ssid
;
906 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
907 if (ssid
->parent_cred
!= cred
)
909 if (ssid
->ssid_len
!= bss
->ssid_len
||
910 os_memcmp(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0)
919 wpa_printf(MSG_DEBUG
, "Interworking: Remove duplicate network entry for the same credential");
921 if (ssid
== wpa_s
->current_ssid
) {
922 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
923 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
924 wpa_s
->own_disconnect_req
= 1;
925 wpa_supplicant_deauthenticate(wpa_s
,
926 WLAN_REASON_DEAUTH_LEAVING
);
929 wpas_notify_network_removed(wpa_s
, ssid
);
930 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
934 static int interworking_set_hs20_params(struct wpa_supplicant
*wpa_s
,
935 struct wpa_ssid
*ssid
)
937 const char *key_mgmt
= NULL
;
938 #ifdef CONFIG_IEEE80211R
940 struct wpa_driver_capa capa
;
942 res
= wpa_drv_get_capa(wpa_s
, &capa
);
943 if (res
== 0 && capa
.key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT
) {
944 key_mgmt
= wpa_s
->conf
->pmf
!= NO_MGMT_FRAME_PROTECTION
?
945 "WPA-EAP WPA-EAP-SHA256 FT-EAP" :
948 #endif /* CONFIG_IEEE80211R */
951 key_mgmt
= wpa_s
->conf
->pmf
!= NO_MGMT_FRAME_PROTECTION
?
952 "WPA-EAP WPA-EAP-SHA256" : "WPA-EAP";
953 if (wpa_config_set(ssid
, "key_mgmt", key_mgmt
, 0) < 0 ||
954 wpa_config_set(ssid
, "proto", "RSN", 0) < 0 ||
955 wpa_config_set(ssid
, "pairwise", "CCMP", 0) < 0)
961 static int interworking_connect_3gpp(struct wpa_supplicant
*wpa_s
,
962 struct wpa_cred
*cred
,
963 struct wpa_bss
*bss
, int only_add
)
965 #ifdef INTERWORKING_3GPP
966 struct wpa_ssid
*ssid
;
971 if (bss
->anqp
== NULL
|| bss
->anqp
->anqp_3gpp
== NULL
)
974 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Connect with " MACSTR
975 " (3GPP)", MAC2STR(bss
->bssid
));
977 if (already_connected(wpa_s
, cred
, bss
)) {
978 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_ALREADY_CONNECTED MACSTR
,
979 MAC2STR(bss
->bssid
));
980 return wpa_s
->current_ssid
->id
;
983 remove_duplicate_network(wpa_s
, cred
, bss
);
985 ssid
= wpa_config_add_network(wpa_s
->conf
);
988 ssid
->parent_cred
= cred
;
990 wpas_notify_network_added(wpa_s
, ssid
);
991 wpa_config_set_network_defaults(ssid
);
992 ssid
->priority
= cred
->priority
;
994 ssid
->ssid
= os_zalloc(bss
->ssid_len
+ 1);
995 if (ssid
->ssid
== NULL
)
997 os_memcpy(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
);
998 ssid
->ssid_len
= bss
->ssid_len
;
999 ssid
->eap
.sim_num
= cred
->sim_num
;
1001 if (interworking_set_hs20_params(wpa_s
, ssid
) < 0)
1004 eap_type
= EAP_TYPE_SIM
;
1005 if (cred
->pcsc
&& wpa_s
->scard
&& scard_supports_umts(wpa_s
->scard
))
1006 eap_type
= EAP_TYPE_AKA
;
1007 if (cred
->eap_method
&& cred
->eap_method
[0].vendor
== EAP_VENDOR_IETF
) {
1008 if (cred
->eap_method
[0].method
== EAP_TYPE_SIM
||
1009 cred
->eap_method
[0].method
== EAP_TYPE_AKA
||
1010 cred
->eap_method
[0].method
== EAP_TYPE_AKA_PRIME
)
1011 eap_type
= cred
->eap_method
[0].method
;
1017 res
= wpa_config_set(ssid
, "eap", "SIM", 0);
1021 res
= wpa_config_set(ssid
, "eap", "AKA", 0);
1023 case EAP_TYPE_AKA_PRIME
:
1025 res
= wpa_config_set(ssid
, "eap", "AKA'", 0);
1032 wpa_msg(wpa_s
, MSG_DEBUG
,
1033 "Selected EAP method (%d) not supported", eap_type
);
1037 if (!cred
->pcsc
&& set_root_nai(ssid
, cred
->imsi
, prefix
) < 0) {
1038 wpa_msg(wpa_s
, MSG_DEBUG
, "Failed to set Root NAI");
1042 if (cred
->milenage
&& cred
->milenage
[0]) {
1043 if (wpa_config_set_quoted(ssid
, "password",
1044 cred
->milenage
) < 0)
1046 } else if (cred
->pcsc
) {
1047 if (wpa_config_set_quoted(ssid
, "pcsc", "") < 0)
1049 if (wpa_s
->conf
->pcsc_pin
&&
1050 wpa_config_set_quoted(ssid
, "pin", wpa_s
->conf
->pcsc_pin
)
1055 wpa_s
->next_ssid
= ssid
;
1056 wpa_config_update_prio_list(wpa_s
->conf
);
1058 interworking_reconnect(wpa_s
);
1063 wpas_notify_network_removed(wpa_s
, ssid
);
1064 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1065 #endif /* INTERWORKING_3GPP */
1070 static int roaming_consortium_element_match(const u8
*ie
, const u8
*rc_id
,
1073 const u8
*pos
, *end
;
1080 end
= ie
+ 2 + ie
[1];
1082 /* Roaming Consortium element:
1083 * Number of ANQP OIs
1084 * OI #1 and #2 lengths
1085 * OI #1, [OI #2], [OI #3]
1091 pos
++; /* skip Number of ANQP OIs */
1093 if ((lens
& 0x0f) + (lens
>> 4) > end
- pos
)
1096 if ((lens
& 0x0f) == rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
1100 if ((lens
>> 4) == rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
1104 if (pos
< end
&& (size_t) (end
- pos
) == rc_len
&&
1105 os_memcmp(pos
, rc_id
, rc_len
) == 0)
1112 static int roaming_consortium_anqp_match(const struct wpabuf
*anqp
,
1113 const u8
*rc_id
, size_t rc_len
)
1115 const u8
*pos
, *end
;
1121 pos
= wpabuf_head(anqp
);
1122 end
= pos
+ wpabuf_len(anqp
);
1124 /* Set of <OI Length, OI> duples */
1127 if (len
> end
- pos
)
1129 if (len
== rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
1138 static int roaming_consortium_match(const u8
*ie
, const struct wpabuf
*anqp
,
1139 const u8
*rc_id
, size_t rc_len
)
1141 return roaming_consortium_element_match(ie
, rc_id
, rc_len
) ||
1142 roaming_consortium_anqp_match(anqp
, rc_id
, rc_len
);
1146 static int cred_no_required_oi_match(struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1150 if (cred
->required_roaming_consortium_len
== 0)
1153 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
1156 (bss
->anqp
== NULL
|| bss
->anqp
->roaming_consortium
== NULL
))
1159 return !roaming_consortium_match(ie
,
1161 bss
->anqp
->roaming_consortium
: NULL
,
1162 cred
->required_roaming_consortium
,
1163 cred
->required_roaming_consortium_len
);
1167 static int cred_excluded_ssid(struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1171 if (!cred
->excluded_ssid
)
1174 for (i
= 0; i
< cred
->num_excluded_ssid
; i
++) {
1175 struct excluded_ssid
*e
= &cred
->excluded_ssid
[i
];
1176 if (bss
->ssid_len
== e
->ssid_len
&&
1177 os_memcmp(bss
->ssid
, e
->ssid
, e
->ssid_len
) == 0)
1185 static int cred_below_min_backhaul(struct wpa_supplicant
*wpa_s
,
1186 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1190 unsigned int dl_bandwidth
, ul_bandwidth
;
1192 u8 wan_info
, dl_load
, ul_load
;
1194 u32 ul_speed
, dl_speed
;
1196 if (!cred
->min_dl_bandwidth_home
&&
1197 !cred
->min_ul_bandwidth_home
&&
1198 !cred
->min_dl_bandwidth_roaming
&&
1199 !cred
->min_ul_bandwidth_roaming
)
1200 return 0; /* No bandwidth constraint specified */
1202 if (bss
->anqp
== NULL
|| bss
->anqp
->hs20_wan_metrics
== NULL
)
1203 return 0; /* No WAN Metrics known - ignore constraint */
1205 wan
= wpabuf_head(bss
->anqp
->hs20_wan_metrics
);
1207 if (wan_info
& BIT(3))
1208 return 1; /* WAN link at capacity */
1209 lmd
= WPA_GET_LE16(wan
+ 11);
1211 return 0; /* Downlink/Uplink Load was not measured */
1212 dl_speed
= WPA_GET_LE32(wan
+ 1);
1213 ul_speed
= WPA_GET_LE32(wan
+ 5);
1217 if (dl_speed
>= 0xffffff)
1218 dl_bandwidth
= dl_speed
/ 255 * (255 - dl_load
);
1220 dl_bandwidth
= dl_speed
* (255 - dl_load
) / 255;
1222 if (ul_speed
>= 0xffffff)
1223 ul_bandwidth
= ul_speed
/ 255 * (255 - ul_load
);
1225 ul_bandwidth
= ul_speed
* (255 - ul_load
) / 255;
1227 res
= interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
?
1228 bss
->anqp
->domain_name
: NULL
);
1230 if (cred
->min_dl_bandwidth_home
> dl_bandwidth
)
1232 if (cred
->min_ul_bandwidth_home
> ul_bandwidth
)
1235 if (cred
->min_dl_bandwidth_roaming
> dl_bandwidth
)
1237 if (cred
->min_ul_bandwidth_roaming
> ul_bandwidth
)
1240 #endif /* CONFIG_HS20 */
1246 static int cred_over_max_bss_load(struct wpa_supplicant
*wpa_s
,
1247 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1252 if (!cred
->max_bss_load
)
1253 return 0; /* No BSS Load constraint specified */
1255 ie
= wpa_bss_get_ie(bss
, WLAN_EID_BSS_LOAD
);
1256 if (ie
== NULL
|| ie
[1] < 3)
1257 return 0; /* No BSS Load advertised */
1259 res
= interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
?
1260 bss
->anqp
->domain_name
: NULL
);
1262 return 0; /* Not a home network */
1264 return ie
[4] > cred
->max_bss_load
;
1270 static int has_proto_match(const u8
*pos
, const u8
*end
, u8 proto
)
1272 while (end
- pos
>= 4) {
1273 if (pos
[0] == proto
&& pos
[3] == 1 /* Open */)
1282 static int has_proto_port_match(const u8
*pos
, const u8
*end
, u8 proto
,
1285 while (end
- pos
>= 4) {
1286 if (pos
[0] == proto
&& WPA_GET_LE16(&pos
[1]) == port
&&
1287 pos
[3] == 1 /* Open */)
1295 #endif /* CONFIG_HS20 */
1298 static int cred_conn_capab_missing(struct wpa_supplicant
*wpa_s
,
1299 struct wpa_cred
*cred
, struct wpa_bss
*bss
)
1303 const u8
*capab
, *end
;
1307 if (!cred
->num_req_conn_capab
)
1308 return 0; /* No connection capability constraint specified */
1310 if (bss
->anqp
== NULL
|| bss
->anqp
->hs20_connection_capability
== NULL
)
1311 return 0; /* No Connection Capability known - ignore constraint
1314 res
= interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
?
1315 bss
->anqp
->domain_name
: NULL
);
1317 return 0; /* No constraint in home network */
1319 capab
= wpabuf_head(bss
->anqp
->hs20_connection_capability
);
1320 end
= capab
+ wpabuf_len(bss
->anqp
->hs20_connection_capability
);
1322 for (i
= 0; i
< cred
->num_req_conn_capab
; i
++) {
1323 ports
= cred
->req_conn_capab_port
[i
];
1325 if (!has_proto_match(capab
, end
,
1326 cred
->req_conn_capab_proto
[i
]))
1329 for (j
= 0; ports
[j
] > -1; j
++) {
1330 if (!has_proto_port_match(
1332 cred
->req_conn_capab_proto
[i
],
1338 #endif /* CONFIG_HS20 */
1344 static struct wpa_cred
* interworking_credentials_available_roaming_consortium(
1345 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
1348 struct wpa_cred
*cred
, *selected
= NULL
;
1350 int is_excluded
= 0;
1352 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
1355 (bss
->anqp
== NULL
|| bss
->anqp
->roaming_consortium
== NULL
))
1358 if (wpa_s
->conf
->cred
== NULL
)
1361 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1362 if (cred
->roaming_consortium_len
== 0)
1365 if (!roaming_consortium_match(ie
,
1367 bss
->anqp
->roaming_consortium
:
1369 cred
->roaming_consortium
,
1370 cred
->roaming_consortium_len
))
1373 if (cred_no_required_oi_match(cred
, bss
))
1375 if (!ignore_bw
&& cred_below_min_backhaul(wpa_s
, cred
, bss
))
1377 if (!ignore_bw
&& cred_over_max_bss_load(wpa_s
, cred
, bss
))
1379 if (!ignore_bw
&& cred_conn_capab_missing(wpa_s
, cred
, bss
))
1381 if (cred_excluded_ssid(cred
, bss
)) {
1382 if (excluded
== NULL
)
1384 if (selected
== NULL
) {
1389 if (selected
== NULL
|| is_excluded
||
1390 cred_prio_cmp(selected
, cred
) < 0) {
1398 *excluded
= is_excluded
;
1404 static int interworking_set_eap_params(struct wpa_ssid
*ssid
,
1405 struct wpa_cred
*cred
, int ttls
)
1407 if (cred
->eap_method
) {
1408 ttls
= cred
->eap_method
->vendor
== EAP_VENDOR_IETF
&&
1409 cred
->eap_method
->method
== EAP_TYPE_TTLS
;
1411 os_free(ssid
->eap
.eap_methods
);
1412 ssid
->eap
.eap_methods
=
1413 os_malloc(sizeof(struct eap_method_type
) * 2);
1414 if (ssid
->eap
.eap_methods
== NULL
)
1416 os_memcpy(ssid
->eap
.eap_methods
, cred
->eap_method
,
1417 sizeof(*cred
->eap_method
));
1418 ssid
->eap
.eap_methods
[1].vendor
= EAP_VENDOR_IETF
;
1419 ssid
->eap
.eap_methods
[1].method
= EAP_TYPE_NONE
;
1422 if (ttls
&& cred
->username
&& cred
->username
[0]) {
1425 /* Use anonymous NAI in Phase 1 */
1426 pos
= os_strchr(cred
->username
, '@');
1428 size_t buflen
= 9 + os_strlen(pos
) + 1;
1429 anon
= os_malloc(buflen
);
1432 os_snprintf(anon
, buflen
, "anonymous%s", pos
);
1433 } else if (cred
->realm
) {
1434 size_t buflen
= 10 + os_strlen(cred
->realm
) + 1;
1435 anon
= os_malloc(buflen
);
1438 os_snprintf(anon
, buflen
, "anonymous@%s", cred
->realm
);
1440 anon
= os_strdup("anonymous");
1444 if (wpa_config_set_quoted(ssid
, "anonymous_identity", anon
) <
1452 if (!ttls
&& cred
->username
&& cred
->username
[0] && cred
->realm
&&
1453 !os_strchr(cred
->username
, '@')) {
1458 buflen
= os_strlen(cred
->username
) + 1 +
1459 os_strlen(cred
->realm
) + 1;
1461 id
= os_malloc(buflen
);
1464 os_snprintf(id
, buflen
, "%s@%s", cred
->username
, cred
->realm
);
1465 res
= wpa_config_set_quoted(ssid
, "identity", id
);
1469 } else if (cred
->username
&& cred
->username
[0] &&
1470 wpa_config_set_quoted(ssid
, "identity", cred
->username
) < 0)
1473 if (cred
->password
&& cred
->password
[0]) {
1474 if (cred
->ext_password
&&
1475 wpa_config_set(ssid
, "password", cred
->password
, 0) < 0)
1477 if (!cred
->ext_password
&&
1478 wpa_config_set_quoted(ssid
, "password", cred
->password
) <
1483 if (cred
->client_cert
&& cred
->client_cert
[0] &&
1484 wpa_config_set_quoted(ssid
, "client_cert", cred
->client_cert
) < 0)
1488 if (cred
->private_key
&&
1489 os_strncmp(cred
->private_key
, "keystore://", 11) == 0) {
1490 /* Use OpenSSL engine configuration for Android keystore */
1491 if (wpa_config_set_quoted(ssid
, "engine_id", "keystore") < 0 ||
1492 wpa_config_set_quoted(ssid
, "key_id",
1493 cred
->private_key
+ 11) < 0 ||
1494 wpa_config_set(ssid
, "engine", "1", 0) < 0)
1497 #endif /* ANDROID */
1498 if (cred
->private_key
&& cred
->private_key
[0] &&
1499 wpa_config_set_quoted(ssid
, "private_key", cred
->private_key
) < 0)
1502 if (cred
->private_key_passwd
&& cred
->private_key_passwd
[0] &&
1503 wpa_config_set_quoted(ssid
, "private_key_passwd",
1504 cred
->private_key_passwd
) < 0)
1508 os_free(ssid
->eap
.phase1
);
1509 ssid
->eap
.phase1
= os_strdup(cred
->phase1
);
1512 os_free(ssid
->eap
.phase2
);
1513 ssid
->eap
.phase2
= os_strdup(cred
->phase2
);
1516 if (cred
->ca_cert
&& cred
->ca_cert
[0] &&
1517 wpa_config_set_quoted(ssid
, "ca_cert", cred
->ca_cert
) < 0)
1520 if (cred
->domain_suffix_match
&& cred
->domain_suffix_match
[0] &&
1521 wpa_config_set_quoted(ssid
, "domain_suffix_match",
1522 cred
->domain_suffix_match
) < 0)
1525 ssid
->eap
.ocsp
= cred
->ocsp
;
1531 static int interworking_connect_roaming_consortium(
1532 struct wpa_supplicant
*wpa_s
, struct wpa_cred
*cred
,
1533 struct wpa_bss
*bss
, int only_add
)
1535 struct wpa_ssid
*ssid
;
1537 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Connect with " MACSTR
1538 " based on roaming consortium match", MAC2STR(bss
->bssid
));
1540 if (already_connected(wpa_s
, cred
, bss
)) {
1541 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_ALREADY_CONNECTED MACSTR
,
1542 MAC2STR(bss
->bssid
));
1543 return wpa_s
->current_ssid
->id
;
1546 remove_duplicate_network(wpa_s
, cred
, bss
);
1548 ssid
= wpa_config_add_network(wpa_s
->conf
);
1551 ssid
->parent_cred
= cred
;
1552 wpas_notify_network_added(wpa_s
, ssid
);
1553 wpa_config_set_network_defaults(ssid
);
1554 ssid
->priority
= cred
->priority
;
1555 ssid
->temporary
= 1;
1556 ssid
->ssid
= os_zalloc(bss
->ssid_len
+ 1);
1557 if (ssid
->ssid
== NULL
)
1559 os_memcpy(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
);
1560 ssid
->ssid_len
= bss
->ssid_len
;
1562 if (interworking_set_hs20_params(wpa_s
, ssid
) < 0)
1565 if (cred
->eap_method
== NULL
) {
1566 wpa_msg(wpa_s
, MSG_DEBUG
,
1567 "Interworking: No EAP method set for credential using roaming consortium");
1571 if (interworking_set_eap_params(
1573 cred
->eap_method
->vendor
== EAP_VENDOR_IETF
&&
1574 cred
->eap_method
->method
== EAP_TYPE_TTLS
) < 0)
1577 wpa_s
->next_ssid
= ssid
;
1578 wpa_config_update_prio_list(wpa_s
->conf
);
1580 interworking_reconnect(wpa_s
);
1585 wpas_notify_network_removed(wpa_s
, ssid
);
1586 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1591 static int interworking_connect_helper(struct wpa_supplicant
*wpa_s
,
1592 struct wpa_bss
*bss
, int allow_excluded
,
1595 struct wpa_cred
*cred
, *cred_rc
, *cred_3gpp
;
1596 struct wpa_ssid
*ssid
;
1597 struct nai_realm
*realm
;
1598 struct nai_realm_eap
*eap
= NULL
;
1601 int excluded
= 0, *excl
= allow_excluded
? &excluded
: NULL
;
1604 if (wpa_s
->conf
->cred
== NULL
|| bss
== NULL
)
1606 if (disallowed_bssid(wpa_s
, bss
->bssid
) ||
1607 disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
1608 wpa_msg(wpa_s
, MSG_DEBUG
,
1609 "Interworking: Reject connection to disallowed BSS "
1610 MACSTR
, MAC2STR(bss
->bssid
));
1614 wpa_printf(MSG_DEBUG
, "Interworking: Considering BSS " MACSTR
1615 " for connection (allow_excluded=%d)",
1616 MAC2STR(bss
->bssid
), allow_excluded
);
1618 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) {
1620 * We currently support only HS 2.0 networks and those are
1621 * required to use WPA2-Enterprise.
1623 wpa_msg(wpa_s
, MSG_DEBUG
,
1624 "Interworking: Network does not use RSN");
1628 cred_rc
= interworking_credentials_available_roaming_consortium(
1629 wpa_s
, bss
, 0, excl
);
1631 wpa_msg(wpa_s
, MSG_DEBUG
,
1632 "Interworking: Highest roaming consortium matching credential priority %d sp_priority %d",
1633 cred_rc
->priority
, cred_rc
->sp_priority
);
1634 if (allow_excluded
&& excl
&& !(*excl
))
1638 cred
= interworking_credentials_available_realm(wpa_s
, bss
, 0, excl
);
1640 wpa_msg(wpa_s
, MSG_DEBUG
,
1641 "Interworking: Highest NAI Realm list matching credential priority %d sp_priority %d",
1642 cred
->priority
, cred
->sp_priority
);
1643 if (allow_excluded
&& excl
&& !(*excl
))
1647 cred_3gpp
= interworking_credentials_available_3gpp(wpa_s
, bss
, 0,
1650 wpa_msg(wpa_s
, MSG_DEBUG
,
1651 "Interworking: Highest 3GPP matching credential priority %d sp_priority %d",
1652 cred_3gpp
->priority
, cred_3gpp
->sp_priority
);
1653 if (allow_excluded
&& excl
&& !(*excl
))
1657 if (!cred_rc
&& !cred
&& !cred_3gpp
) {
1658 wpa_msg(wpa_s
, MSG_DEBUG
,
1659 "Interworking: No full credential matches - consider options without BW(etc.) limits");
1660 cred_rc
= interworking_credentials_available_roaming_consortium(
1661 wpa_s
, bss
, 1, excl
);
1663 wpa_msg(wpa_s
, MSG_DEBUG
,
1664 "Interworking: Highest roaming consortium matching credential priority %d sp_priority %d (ignore BW)",
1665 cred_rc
->priority
, cred_rc
->sp_priority
);
1666 if (allow_excluded
&& excl
&& !(*excl
))
1670 cred
= interworking_credentials_available_realm(wpa_s
, bss
, 1,
1673 wpa_msg(wpa_s
, MSG_DEBUG
,
1674 "Interworking: Highest NAI Realm list matching credential priority %d sp_priority %d (ignore BW)",
1675 cred
->priority
, cred
->sp_priority
);
1676 if (allow_excluded
&& excl
&& !(*excl
))
1680 cred_3gpp
= interworking_credentials_available_3gpp(wpa_s
, bss
,
1683 wpa_msg(wpa_s
, MSG_DEBUG
,
1684 "Interworking: Highest 3GPP matching credential priority %d sp_priority %d (ignore BW)",
1685 cred_3gpp
->priority
, cred_3gpp
->sp_priority
);
1686 if (allow_excluded
&& excl
&& !(*excl
))
1692 (cred
== NULL
|| cred_prio_cmp(cred_rc
, cred
) >= 0) &&
1693 (cred_3gpp
== NULL
|| cred_prio_cmp(cred_rc
, cred_3gpp
) >= 0))
1694 return interworking_connect_roaming_consortium(wpa_s
, cred_rc
,
1698 (cred
== NULL
|| cred_prio_cmp(cred_3gpp
, cred
) >= 0)) {
1699 return interworking_connect_3gpp(wpa_s
, cred_3gpp
, bss
,
1704 wpa_msg(wpa_s
, MSG_DEBUG
,
1705 "Interworking: No matching credentials found for "
1706 MACSTR
, MAC2STR(bss
->bssid
));
1710 realm
= nai_realm_parse(bss
->anqp
? bss
->anqp
->nai_realm
: NULL
,
1712 if (realm
== NULL
) {
1713 wpa_msg(wpa_s
, MSG_DEBUG
,
1714 "Interworking: Could not parse NAI Realm list from "
1715 MACSTR
, MAC2STR(bss
->bssid
));
1719 for (i
= 0; i
< count
; i
++) {
1720 if (!nai_realm_match(&realm
[i
], cred
->realm
))
1722 eap
= nai_realm_find_eap(wpa_s
, cred
, &realm
[i
]);
1728 wpa_msg(wpa_s
, MSG_DEBUG
,
1729 "Interworking: No matching credentials and EAP method found for "
1730 MACSTR
, MAC2STR(bss
->bssid
));
1731 nai_realm_free(realm
, count
);
1735 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Connect with " MACSTR
,
1736 MAC2STR(bss
->bssid
));
1738 if (already_connected(wpa_s
, cred
, bss
)) {
1739 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_ALREADY_CONNECTED MACSTR
,
1740 MAC2STR(bss
->bssid
));
1741 nai_realm_free(realm
, count
);
1745 remove_duplicate_network(wpa_s
, cred
, bss
);
1747 ssid
= wpa_config_add_network(wpa_s
->conf
);
1749 nai_realm_free(realm
, count
);
1752 ssid
->parent_cred
= cred
;
1753 wpas_notify_network_added(wpa_s
, ssid
);
1754 wpa_config_set_network_defaults(ssid
);
1755 ssid
->priority
= cred
->priority
;
1756 ssid
->temporary
= 1;
1757 ssid
->ssid
= os_zalloc(bss
->ssid_len
+ 1);
1758 if (ssid
->ssid
== NULL
)
1760 os_memcpy(ssid
->ssid
, bss
->ssid
, bss
->ssid_len
);
1761 ssid
->ssid_len
= bss
->ssid_len
;
1763 if (interworking_set_hs20_params(wpa_s
, ssid
) < 0)
1766 if (wpa_config_set(ssid
, "eap", eap_get_name(EAP_VENDOR_IETF
,
1767 eap
->method
), 0) < 0)
1770 switch (eap
->method
) {
1772 if (eap
->inner_method
) {
1773 os_snprintf(buf
, sizeof(buf
), "\"autheap=%s\"",
1774 eap_get_name(EAP_VENDOR_IETF
,
1775 eap
->inner_method
));
1776 if (wpa_config_set(ssid
, "phase2", buf
, 0) < 0)
1780 switch (eap
->inner_non_eap
) {
1781 case NAI_REALM_INNER_NON_EAP_PAP
:
1782 if (wpa_config_set(ssid
, "phase2", "\"auth=PAP\"", 0) <
1786 case NAI_REALM_INNER_NON_EAP_CHAP
:
1787 if (wpa_config_set(ssid
, "phase2", "\"auth=CHAP\"", 0)
1791 case NAI_REALM_INNER_NON_EAP_MSCHAP
:
1792 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAP\"",
1796 case NAI_REALM_INNER_NON_EAP_MSCHAPV2
:
1797 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAPV2\"",
1802 /* EAP params were not set - assume TTLS/MSCHAPv2 */
1803 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAPV2\"",
1811 if (wpa_config_set(ssid
, "phase1", "\"fast_provisioning=2\"",
1814 if (wpa_config_set(ssid
, "pac_file",
1815 "\"blob://pac_interworking\"", 0) < 0)
1817 name
= eap_get_name(EAP_VENDOR_IETF
,
1818 eap
->inner_method
? eap
->inner_method
:
1822 os_snprintf(buf
, sizeof(buf
), "\"auth=%s\"", name
);
1823 if (wpa_config_set(ssid
, "phase2", buf
, 0) < 0)
1830 if (interworking_set_eap_params(ssid
, cred
,
1831 eap
->method
== EAP_TYPE_TTLS
) < 0)
1834 nai_realm_free(realm
, count
);
1836 wpa_s
->next_ssid
= ssid
;
1837 wpa_config_update_prio_list(wpa_s
->conf
);
1839 interworking_reconnect(wpa_s
);
1844 wpas_notify_network_removed(wpa_s
, ssid
);
1845 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1846 nai_realm_free(realm
, count
);
1851 int interworking_connect(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
1854 return interworking_connect_helper(wpa_s
, bss
, 1, only_add
);
1859 static int interworking_pcsc_read_imsi(struct wpa_supplicant
*wpa_s
)
1863 if (wpa_s
->imsi
[0] && wpa_s
->mnc_len
)
1866 len
= sizeof(wpa_s
->imsi
) - 1;
1867 if (scard_get_imsi(wpa_s
->scard
, wpa_s
->imsi
, &len
)) {
1868 scard_deinit(wpa_s
->scard
);
1869 wpa_s
->scard
= NULL
;
1870 wpa_msg(wpa_s
, MSG_ERROR
, "Could not read IMSI");
1873 wpa_s
->imsi
[len
] = '\0';
1874 wpa_s
->mnc_len
= scard_get_mnc_len(wpa_s
->scard
);
1875 wpa_printf(MSG_DEBUG
, "SCARD: IMSI %s (MNC length %d)",
1876 wpa_s
->imsi
, wpa_s
->mnc_len
);
1880 #endif /* PCSC_FUNCS */
1883 static struct wpa_cred
* interworking_credentials_available_3gpp(
1884 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
1887 struct wpa_cred
*selected
= NULL
;
1888 #ifdef INTERWORKING_3GPP
1889 struct wpa_cred
*cred
;
1891 int is_excluded
= 0;
1893 if (bss
->anqp
== NULL
|| bss
->anqp
->anqp_3gpp
== NULL
) {
1894 wpa_msg(wpa_s
, MSG_DEBUG
,
1895 "interworking-avail-3gpp: not avail, anqp: %p anqp_3gpp: %p",
1896 bss
->anqp
, bss
->anqp
? bss
->anqp
->anqp_3gpp
: NULL
);
1900 #ifdef CONFIG_EAP_PROXY
1901 if (!wpa_s
->imsi
[0]) {
1903 wpa_msg(wpa_s
, MSG_DEBUG
,
1904 "Interworking: IMSI not available - try to read again through eap_proxy");
1905 wpa_s
->mnc_len
= eapol_sm_get_eap_proxy_imsi(wpa_s
->eapol
,
1908 if (wpa_s
->mnc_len
> 0) {
1909 wpa_s
->imsi
[len
] = '\0';
1910 wpa_msg(wpa_s
, MSG_DEBUG
,
1911 "eap_proxy: IMSI %s (MNC length %d)",
1912 wpa_s
->imsi
, wpa_s
->mnc_len
);
1914 wpa_msg(wpa_s
, MSG_DEBUG
,
1915 "eap_proxy: IMSI not available");
1918 #endif /* CONFIG_EAP_PROXY */
1920 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1928 if (cred
->pcsc
&& wpa_s
->scard
) {
1929 if (interworking_pcsc_read_imsi(wpa_s
) < 0)
1932 mnc_len
= wpa_s
->mnc_len
;
1935 #endif /* PCSC_FUNCS */
1936 #ifdef CONFIG_EAP_PROXY
1937 if (cred
->pcsc
&& wpa_s
->mnc_len
> 0 && wpa_s
->imsi
[0]) {
1939 mnc_len
= wpa_s
->mnc_len
;
1942 #endif /* CONFIG_EAP_PROXY */
1944 if (cred
->imsi
== NULL
|| !cred
->imsi
[0] ||
1945 (!wpa_s
->conf
->external_sim
&&
1946 (cred
->milenage
== NULL
|| !cred
->milenage
[0])))
1949 sep
= os_strchr(cred
->imsi
, '-');
1951 (sep
- cred
->imsi
!= 5 && sep
- cred
->imsi
!= 6))
1953 mnc_len
= sep
- cred
->imsi
- 3;
1954 os_memcpy(imsi_buf
, cred
->imsi
, 3 + mnc_len
);
1956 msin_len
= os_strlen(cred
->imsi
);
1957 if (3 + mnc_len
+ msin_len
>= sizeof(imsi_buf
) - 1)
1958 msin_len
= sizeof(imsi_buf
) - 3 - mnc_len
- 1;
1959 os_memcpy(&imsi_buf
[3 + mnc_len
], sep
, msin_len
);
1960 imsi_buf
[3 + mnc_len
+ msin_len
] = '\0';
1963 #if defined(PCSC_FUNCS) || defined(CONFIG_EAP_PROXY)
1965 #endif /* PCSC_FUNCS || CONFIG_EAP_PROXY */
1966 wpa_msg(wpa_s
, MSG_DEBUG
,
1967 "Interworking: Parsing 3GPP info from " MACSTR
,
1968 MAC2STR(bss
->bssid
));
1969 ret
= plmn_id_match(bss
->anqp
->anqp_3gpp
, imsi
, mnc_len
);
1970 wpa_msg(wpa_s
, MSG_DEBUG
, "PLMN match %sfound",
1973 if (cred_no_required_oi_match(cred
, bss
))
1976 cred_below_min_backhaul(wpa_s
, cred
, bss
))
1979 cred_over_max_bss_load(wpa_s
, cred
, bss
))
1982 cred_conn_capab_missing(wpa_s
, cred
, bss
))
1984 if (cred_excluded_ssid(cred
, bss
)) {
1985 if (excluded
== NULL
)
1987 if (selected
== NULL
) {
1992 if (selected
== NULL
|| is_excluded
||
1993 cred_prio_cmp(selected
, cred
) < 0) {
2002 *excluded
= is_excluded
;
2003 #endif /* INTERWORKING_3GPP */
2008 static struct wpa_cred
* interworking_credentials_available_realm(
2009 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
2012 struct wpa_cred
*cred
, *selected
= NULL
;
2013 struct nai_realm
*realm
;
2015 int is_excluded
= 0;
2017 if (bss
->anqp
== NULL
|| bss
->anqp
->nai_realm
== NULL
)
2020 if (wpa_s
->conf
->cred
== NULL
)
2023 wpa_msg(wpa_s
, MSG_DEBUG
, "Interworking: Parsing NAI Realm list from "
2024 MACSTR
, MAC2STR(bss
->bssid
));
2025 realm
= nai_realm_parse(bss
->anqp
->nai_realm
, &count
);
2026 if (realm
== NULL
) {
2027 wpa_msg(wpa_s
, MSG_DEBUG
,
2028 "Interworking: Could not parse NAI Realm list from "
2029 MACSTR
, MAC2STR(bss
->bssid
));
2033 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2034 if (cred
->realm
== NULL
)
2037 for (i
= 0; i
< count
; i
++) {
2038 if (!nai_realm_match(&realm
[i
], cred
->realm
))
2040 if (nai_realm_find_eap(wpa_s
, cred
, &realm
[i
])) {
2041 if (cred_no_required_oi_match(cred
, bss
))
2044 cred_below_min_backhaul(wpa_s
, cred
, bss
))
2047 cred_over_max_bss_load(wpa_s
, cred
, bss
))
2050 cred_conn_capab_missing(wpa_s
, cred
, bss
))
2052 if (cred_excluded_ssid(cred
, bss
)) {
2053 if (excluded
== NULL
)
2055 if (selected
== NULL
) {
2060 if (selected
== NULL
|| is_excluded
||
2061 cred_prio_cmp(selected
, cred
) < 0)
2069 wpa_msg(wpa_s
, MSG_DEBUG
,
2070 "Interworking: realm-find-eap returned false");
2075 nai_realm_free(realm
, count
);
2078 *excluded
= is_excluded
;
2084 static struct wpa_cred
* interworking_credentials_available_helper(
2085 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int ignore_bw
,
2088 struct wpa_cred
*cred
, *cred2
;
2089 int excluded1
, excluded2
= 0;
2091 if (disallowed_bssid(wpa_s
, bss
->bssid
) ||
2092 disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
)) {
2093 wpa_printf(MSG_DEBUG
, "Interworking: Ignore disallowed BSS "
2094 MACSTR
, MAC2STR(bss
->bssid
));
2098 cred
= interworking_credentials_available_realm(wpa_s
, bss
, ignore_bw
,
2100 cred2
= interworking_credentials_available_3gpp(wpa_s
, bss
, ignore_bw
,
2102 if (cred
&& cred2
&&
2103 (cred_prio_cmp(cred2
, cred
) >= 0 || (!excluded2
&& excluded1
))) {
2105 excluded1
= excluded2
;
2109 excluded1
= excluded2
;
2112 cred2
= interworking_credentials_available_roaming_consortium(
2113 wpa_s
, bss
, ignore_bw
, &excluded2
);
2114 if (cred
&& cred2
&&
2115 (cred_prio_cmp(cred2
, cred
) >= 0 || (!excluded2
&& excluded1
))) {
2117 excluded1
= excluded2
;
2121 excluded1
= excluded2
;
2125 *excluded
= excluded1
;
2130 static struct wpa_cred
* interworking_credentials_available(
2131 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
, int *excluded
)
2133 struct wpa_cred
*cred
;
2137 cred
= interworking_credentials_available_helper(wpa_s
, bss
, 0,
2141 return interworking_credentials_available_helper(wpa_s
, bss
, 1,
2146 int domain_name_list_contains(struct wpabuf
*domain_names
,
2147 const char *domain
, int exact_match
)
2149 const u8
*pos
, *end
;
2152 len
= os_strlen(domain
);
2153 pos
= wpabuf_head(domain_names
);
2154 end
= pos
+ wpabuf_len(domain_names
);
2156 while (end
- pos
> 1) {
2160 if (elen
> end
- pos
)
2163 wpa_hexdump_ascii(MSG_DEBUG
, "Interworking: AP domain name",
2166 os_strncasecmp(domain
, (const char *) pos
, len
) == 0)
2168 if (!exact_match
&& elen
> len
&& pos
[elen
- len
- 1] == '.') {
2169 const char *ap
= (const char *) pos
;
2170 int offset
= elen
- len
;
2172 if (os_strncasecmp(domain
, ap
+ offset
, len
) == 0)
2183 int interworking_home_sp_cred(struct wpa_supplicant
*wpa_s
,
2184 struct wpa_cred
*cred
,
2185 struct wpabuf
*domain_names
)
2189 #ifdef INTERWORKING_3GPP
2190 char nai
[100], *realm
;
2197 else if (cred
->pcsc
&& wpa_s
->scard
) {
2198 if (interworking_pcsc_read_imsi(wpa_s
) < 0)
2201 mnc_len
= wpa_s
->mnc_len
;
2203 #endif /* PCSC_FUNCS */
2204 #ifdef CONFIG_EAP_PROXY
2205 else if (cred
->pcsc
&& wpa_s
->mnc_len
> 0 && wpa_s
->imsi
[0]) {
2207 mnc_len
= wpa_s
->mnc_len
;
2209 #endif /* CONFIG_EAP_PROXY */
2211 imsi
&& build_root_nai(nai
, sizeof(nai
), imsi
, mnc_len
, 0) == 0) {
2212 realm
= os_strchr(nai
, '@');
2215 wpa_msg(wpa_s
, MSG_DEBUG
,
2216 "Interworking: Search for match with SIM/USIM domain %s",
2219 domain_name_list_contains(domain_names
, realm
, 1))
2224 #endif /* INTERWORKING_3GPP */
2226 if (domain_names
== NULL
|| cred
->domain
== NULL
)
2229 for (i
= 0; i
< cred
->num_domain
; i
++) {
2230 wpa_msg(wpa_s
, MSG_DEBUG
,
2231 "Interworking: Search for match with home SP FQDN %s",
2233 if (domain_name_list_contains(domain_names
, cred
->domain
[i
], 1))
2241 static int interworking_home_sp(struct wpa_supplicant
*wpa_s
,
2242 struct wpabuf
*domain_names
)
2244 struct wpa_cred
*cred
;
2246 if (domain_names
== NULL
|| wpa_s
->conf
->cred
== NULL
)
2249 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2250 int res
= interworking_home_sp_cred(wpa_s
, cred
, domain_names
);
2259 static int interworking_find_network_match(struct wpa_supplicant
*wpa_s
)
2261 struct wpa_bss
*bss
;
2262 struct wpa_ssid
*ssid
;
2264 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2265 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
2266 if (wpas_network_disabled(wpa_s
, ssid
) ||
2267 ssid
->mode
!= WPAS_MODE_INFRA
)
2269 if (ssid
->ssid_len
!= bss
->ssid_len
||
2270 os_memcmp(ssid
->ssid
, bss
->ssid
, ssid
->ssid_len
) !=
2274 * TODO: Consider more accurate matching of security
2275 * configuration similarly to what is done in events.c
2285 static int roaming_partner_match(struct wpa_supplicant
*wpa_s
,
2286 struct roaming_partner
*partner
,
2287 struct wpabuf
*domain_names
)
2289 wpa_printf(MSG_DEBUG
, "Interworking: Comparing roaming_partner info fqdn='%s' exact_match=%d priority=%u country='%s'",
2290 partner
->fqdn
, partner
->exact_match
, partner
->priority
,
2292 wpa_hexdump_ascii(MSG_DEBUG
, "Interworking: Domain names",
2293 wpabuf_head(domain_names
),
2294 wpabuf_len(domain_names
));
2295 if (!domain_name_list_contains(domain_names
, partner
->fqdn
,
2296 partner
->exact_match
))
2298 /* TODO: match Country */
2303 static u8
roaming_prio(struct wpa_supplicant
*wpa_s
, struct wpa_cred
*cred
,
2304 struct wpa_bss
*bss
)
2308 if (bss
->anqp
== NULL
|| bss
->anqp
->domain_name
== NULL
) {
2309 wpa_printf(MSG_DEBUG
, "Interworking: No ANQP domain name info -> use default roaming partner priority 128");
2310 return 128; /* cannot check preference with domain name */
2313 if (interworking_home_sp_cred(wpa_s
, cred
, bss
->anqp
->domain_name
) > 0)
2315 wpa_printf(MSG_DEBUG
, "Interworking: Determined to be home SP -> use maximum preference 0 as roaming partner priority");
2316 return 0; /* max preference for home SP network */
2319 for (i
= 0; i
< cred
->num_roaming_partner
; i
++) {
2320 if (roaming_partner_match(wpa_s
, &cred
->roaming_partner
[i
],
2321 bss
->anqp
->domain_name
)) {
2322 wpa_printf(MSG_DEBUG
, "Interworking: Roaming partner preference match - priority %u",
2323 cred
->roaming_partner
[i
].priority
);
2324 return cred
->roaming_partner
[i
].priority
;
2328 wpa_printf(MSG_DEBUG
, "Interworking: No roaming partner preference match - use default roaming partner priority 128");
2333 static struct wpa_bss
* pick_best_roaming_partner(struct wpa_supplicant
*wpa_s
,
2334 struct wpa_bss
*selected
,
2335 struct wpa_cred
*cred
)
2337 struct wpa_bss
*bss
;
2339 struct wpa_cred
*cred2
;
2342 * Check if any other BSS is operated by a more preferred roaming
2346 best_prio
= roaming_prio(wpa_s
, cred
, selected
);
2347 wpa_printf(MSG_DEBUG
, "Interworking: roaming_prio=%u for selected BSS "
2348 MACSTR
" (cred=%d)", best_prio
, MAC2STR(selected
->bssid
),
2351 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2352 if (bss
== selected
)
2354 cred2
= interworking_credentials_available(wpa_s
, bss
, NULL
);
2357 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
))
2359 prio
= roaming_prio(wpa_s
, cred2
, bss
);
2360 wpa_printf(MSG_DEBUG
, "Interworking: roaming_prio=%u for BSS "
2361 MACSTR
" (cred=%d)", prio
, MAC2STR(bss
->bssid
),
2363 if (prio
< best_prio
) {
2364 int bh1
, bh2
, load1
, load2
, conn1
, conn2
;
2365 bh1
= cred_below_min_backhaul(wpa_s
, cred
, selected
);
2366 load1
= cred_over_max_bss_load(wpa_s
, cred
, selected
);
2367 conn1
= cred_conn_capab_missing(wpa_s
, cred
, selected
);
2368 bh2
= cred_below_min_backhaul(wpa_s
, cred2
, bss
);
2369 load2
= cred_over_max_bss_load(wpa_s
, cred2
, bss
);
2370 conn2
= cred_conn_capab_missing(wpa_s
, cred2
, bss
);
2371 wpa_printf(MSG_DEBUG
, "Interworking: old: %d %d %d new: %d %d %d",
2372 bh1
, load1
, conn1
, bh2
, load2
, conn2
);
2373 if (bh1
|| load1
|| conn1
|| !(bh2
|| load2
|| conn2
)) {
2374 wpa_printf(MSG_DEBUG
, "Interworking: Better roaming partner " MACSTR
" selected", MAC2STR(bss
->bssid
));
2385 static void interworking_select_network(struct wpa_supplicant
*wpa_s
)
2387 struct wpa_bss
*bss
, *selected
= NULL
, *selected_home
= NULL
;
2388 struct wpa_bss
*selected2
= NULL
, *selected2_home
= NULL
;
2389 unsigned int count
= 0;
2392 struct wpa_cred
*cred
, *selected_cred
= NULL
;
2393 struct wpa_cred
*selected_home_cred
= NULL
;
2394 struct wpa_cred
*selected2_cred
= NULL
;
2395 struct wpa_cred
*selected2_home_cred
= NULL
;
2397 wpa_s
->network_select
= 0;
2399 wpa_printf(MSG_DEBUG
, "Interworking: Select network (auto_select=%d)",
2400 wpa_s
->auto_select
);
2401 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2403 int bh
, bss_load
, conn_capab
;
2404 cred
= interworking_credentials_available(wpa_s
, bss
,
2409 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) {
2411 * We currently support only HS 2.0 networks and those
2412 * are required to use WPA2-Enterprise.
2414 wpa_msg(wpa_s
, MSG_DEBUG
,
2415 "Interworking: Credential match with " MACSTR
2416 " but network does not use RSN",
2417 MAC2STR(bss
->bssid
));
2422 res
= interworking_home_sp(wpa_s
, bss
->anqp
?
2423 bss
->anqp
->domain_name
: NULL
);
2430 bh
= cred_below_min_backhaul(wpa_s
, cred
, bss
);
2431 bss_load
= cred_over_max_bss_load(wpa_s
, cred
, bss
);
2432 conn_capab
= cred_conn_capab_missing(wpa_s
, cred
, bss
);
2433 wpa_msg(wpa_s
, MSG_INFO
, "%s" MACSTR
" type=%s%s%s%s id=%d priority=%d sp_priority=%d",
2434 excluded
? INTERWORKING_BLACKLISTED
: INTERWORKING_AP
,
2435 MAC2STR(bss
->bssid
), type
,
2436 bh
? " below_min_backhaul=1" : "",
2437 bss_load
? " over_max_bss_load=1" : "",
2438 conn_capab
? " conn_capab_missing=1" : "",
2439 cred
->id
, cred
->priority
, cred
->sp_priority
);
2442 if (wpa_s
->auto_select
||
2443 (wpa_s
->conf
->auto_interworking
&&
2444 wpa_s
->auto_network_select
)) {
2445 if (bh
|| bss_load
|| conn_capab
) {
2446 if (selected2_cred
== NULL
||
2447 cred_prio_cmp(cred
, selected2_cred
) > 0) {
2448 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected2");
2450 selected2_cred
= cred
;
2453 (selected2_home_cred
== NULL
||
2454 cred_prio_cmp(cred
, selected2_home_cred
) >
2456 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected2_home");
2457 selected2_home
= bss
;
2458 selected2_home_cred
= cred
;
2461 if (selected_cred
== NULL
||
2462 cred_prio_cmp(cred
, selected_cred
) > 0) {
2463 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected");
2465 selected_cred
= cred
;
2468 (selected_home_cred
== NULL
||
2469 cred_prio_cmp(cred
, selected_home_cred
) >
2471 wpa_printf(MSG_DEBUG
, "Interworking: Mark as selected_home");
2472 selected_home
= bss
;
2473 selected_home_cred
= cred
;
2479 if (selected_home
&& selected_home
!= selected
&&
2480 selected_home_cred
&&
2481 (selected_cred
== NULL
||
2482 cred_prio_cmp(selected_home_cred
, selected_cred
) >= 0)) {
2483 /* Prefer network operated by the Home SP */
2484 wpa_printf(MSG_DEBUG
, "Interworking: Overrided selected with selected_home");
2485 selected
= selected_home
;
2486 selected_cred
= selected_home_cred
;
2490 if (selected2_home
) {
2491 wpa_printf(MSG_DEBUG
, "Interworking: Use home BSS with BW limit mismatch since no other network could be selected");
2492 selected
= selected2_home
;
2493 selected_cred
= selected2_home_cred
;
2494 } else if (selected2
) {
2495 wpa_printf(MSG_DEBUG
, "Interworking: Use visited BSS with BW limit mismatch since no other network could be selected");
2496 selected
= selected2
;
2497 selected_cred
= selected2_cred
;
2503 * No matching network was found based on configured
2504 * credentials. Check whether any of the enabled network blocks
2505 * have matching APs.
2507 if (interworking_find_network_match(wpa_s
)) {
2508 wpa_msg(wpa_s
, MSG_DEBUG
,
2509 "Interworking: Possible BSS match for enabled network configurations");
2510 if (wpa_s
->auto_select
) {
2511 interworking_reconnect(wpa_s
);
2516 if (wpa_s
->auto_network_select
) {
2517 wpa_msg(wpa_s
, MSG_DEBUG
,
2518 "Interworking: Continue scanning after ANQP fetch");
2519 wpa_supplicant_req_scan(wpa_s
, wpa_s
->scan_interval
,
2524 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_NO_MATCH
"No network "
2525 "with matching credentials found");
2526 if (wpa_s
->wpa_state
== WPA_SCANNING
)
2527 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2531 wpa_printf(MSG_DEBUG
, "Interworking: Selected " MACSTR
,
2532 MAC2STR(selected
->bssid
));
2533 selected
= pick_best_roaming_partner(wpa_s
, selected
,
2535 wpa_printf(MSG_DEBUG
, "Interworking: Selected " MACSTR
2536 " (after best roaming partner selection)",
2537 MAC2STR(selected
->bssid
));
2538 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_SELECTED MACSTR
,
2539 MAC2STR(selected
->bssid
));
2540 interworking_connect(wpa_s
, selected
, 0);
2545 static struct wpa_bss_anqp
*
2546 interworking_match_anqp_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
2548 struct wpa_bss
*other
;
2550 if (is_zero_ether_addr(bss
->hessid
))
2551 return NULL
; /* Cannot be in the same homegenous ESS */
2553 dl_list_for_each(other
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2556 if (other
->anqp
== NULL
)
2558 if (other
->anqp
->roaming_consortium
== NULL
&&
2559 other
->anqp
->nai_realm
== NULL
&&
2560 other
->anqp
->anqp_3gpp
== NULL
&&
2561 other
->anqp
->domain_name
== NULL
)
2563 if (!(other
->flags
& WPA_BSS_ANQP_FETCH_TRIED
))
2565 if (os_memcmp(bss
->hessid
, other
->hessid
, ETH_ALEN
) != 0)
2567 if (bss
->ssid_len
!= other
->ssid_len
||
2568 os_memcmp(bss
->ssid
, other
->ssid
, bss
->ssid_len
) != 0)
2571 wpa_msg(wpa_s
, MSG_DEBUG
,
2572 "Interworking: Share ANQP data with already fetched BSSID "
2573 MACSTR
" and " MACSTR
,
2574 MAC2STR(other
->bssid
), MAC2STR(bss
->bssid
));
2575 other
->anqp
->users
++;
2583 static void interworking_next_anqp_fetch(struct wpa_supplicant
*wpa_s
)
2585 struct wpa_bss
*bss
;
2589 wpa_printf(MSG_DEBUG
, "Interworking: next_anqp_fetch - "
2590 "fetch_anqp_in_progress=%d fetch_osu_icon_in_progress=%d",
2591 wpa_s
->fetch_anqp_in_progress
,
2592 wpa_s
->fetch_osu_icon_in_progress
);
2594 if (eloop_terminated() || !wpa_s
->fetch_anqp_in_progress
) {
2595 wpa_printf(MSG_DEBUG
, "Interworking: Stop next-ANQP-fetch");
2600 if (wpa_s
->fetch_osu_icon_in_progress
) {
2601 wpa_printf(MSG_DEBUG
, "Interworking: Next icon (in progress)");
2602 hs20_next_osu_icon(wpa_s
);
2605 #endif /* CONFIG_HS20 */
2607 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2608 if (!(bss
->caps
& IEEE80211_CAP_ESS
))
2610 ie
= wpa_bss_get_ie(bss
, WLAN_EID_EXT_CAPAB
);
2611 if (ie
== NULL
|| ie
[1] < 4 || !(ie
[5] & 0x80))
2612 continue; /* AP does not support Interworking */
2613 if (disallowed_bssid(wpa_s
, bss
->bssid
) ||
2614 disallowed_ssid(wpa_s
, bss
->ssid
, bss
->ssid_len
))
2615 continue; /* Disallowed BSS */
2617 if (!(bss
->flags
& WPA_BSS_ANQP_FETCH_TRIED
)) {
2618 if (bss
->anqp
== NULL
) {
2619 bss
->anqp
= interworking_match_anqp_info(wpa_s
,
2622 /* Shared data already fetched */
2625 bss
->anqp
= wpa_bss_anqp_alloc();
2626 if (bss
->anqp
== NULL
)
2630 bss
->flags
|= WPA_BSS_ANQP_FETCH_TRIED
;
2631 wpa_msg(wpa_s
, MSG_INFO
, "Starting ANQP fetch for "
2632 MACSTR
, MAC2STR(bss
->bssid
));
2633 interworking_anqp_send_req(wpa_s
, bss
);
2640 if (wpa_s
->fetch_osu_info
) {
2641 if (wpa_s
->num_prov_found
== 0 &&
2642 wpa_s
->fetch_osu_waiting_scan
&&
2643 wpa_s
->num_osu_scans
< 3) {
2644 wpa_printf(MSG_DEBUG
, "HS 2.0: No OSU providers seen - try to scan again");
2645 hs20_start_osu_scan(wpa_s
);
2648 wpa_printf(MSG_DEBUG
, "Interworking: Next icon");
2649 hs20_osu_icon_fetch(wpa_s
);
2652 #endif /* CONFIG_HS20 */
2653 wpa_msg(wpa_s
, MSG_INFO
, "ANQP fetch completed");
2654 wpa_s
->fetch_anqp_in_progress
= 0;
2655 if (wpa_s
->network_select
)
2656 interworking_select_network(wpa_s
);
2661 void interworking_start_fetch_anqp(struct wpa_supplicant
*wpa_s
)
2663 struct wpa_bss
*bss
;
2665 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
)
2666 bss
->flags
&= ~WPA_BSS_ANQP_FETCH_TRIED
;
2668 wpa_s
->fetch_anqp_in_progress
= 1;
2671 * Start actual ANQP operation from eloop call to make sure the loop
2672 * does not end up using excessive recursion.
2674 eloop_register_timeout(0, 0, interworking_continue_anqp
, wpa_s
, NULL
);
2678 int interworking_fetch_anqp(struct wpa_supplicant
*wpa_s
)
2680 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
)
2683 wpa_s
->network_select
= 0;
2684 wpa_s
->fetch_all_anqp
= 1;
2685 wpa_s
->fetch_osu_info
= 0;
2687 interworking_start_fetch_anqp(wpa_s
);
2693 void interworking_stop_fetch_anqp(struct wpa_supplicant
*wpa_s
)
2695 if (!wpa_s
->fetch_anqp_in_progress
)
2698 wpa_s
->fetch_anqp_in_progress
= 0;
2702 int anqp_send_req(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
2703 u16 info_ids
[], size_t num_ids
, u32 subtypes
)
2706 struct wpabuf
*hs20_buf
= NULL
;
2709 struct wpa_bss
*bss
;
2712 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
2714 wpa_printf(MSG_WARNING
,
2715 "ANQP: Cannot send query to unknown BSS "
2716 MACSTR
, MAC2STR(dst
));
2720 wpa_bss_anqp_unshare_alloc(bss
);
2723 wpa_msg(wpa_s
, MSG_DEBUG
,
2724 "ANQP: Query Request to " MACSTR
" for %u id(s)",
2725 MAC2STR(dst
), (unsigned int) num_ids
);
2728 if (subtypes
!= 0) {
2729 hs20_buf
= wpabuf_alloc(100);
2730 if (hs20_buf
== NULL
)
2732 hs20_put_anqp_req(subtypes
, NULL
, 0, hs20_buf
);
2734 #endif /* CONFIG_HS20 */
2736 buf
= anqp_build_req(info_ids
, num_ids
, hs20_buf
);
2737 wpabuf_free(hs20_buf
);
2741 res
= gas_query_req(wpa_s
->gas
, dst
, freq
, buf
, anqp_resp_cb
, wpa_s
);
2743 wpa_msg(wpa_s
, MSG_DEBUG
, "ANQP: Failed to send Query Request");
2747 wpa_msg(wpa_s
, MSG_DEBUG
,
2748 "ANQP: Query started with dialog token %u", res
);
2755 static void anqp_add_extra(struct wpa_supplicant
*wpa_s
,
2756 struct wpa_bss_anqp
*anqp
, u16 info_id
,
2757 const u8
*data
, size_t slen
)
2759 struct wpa_bss_anqp_elem
*tmp
, *elem
= NULL
;
2764 dl_list_for_each(tmp
, &anqp
->anqp_elems
, struct wpa_bss_anqp_elem
,
2766 if (tmp
->infoid
== info_id
) {
2773 elem
= os_zalloc(sizeof(*elem
));
2776 elem
->infoid
= info_id
;
2777 dl_list_add(&anqp
->anqp_elems
, &elem
->list
);
2779 wpabuf_free(elem
->payload
);
2782 elem
->payload
= wpabuf_alloc_copy(data
, slen
);
2783 if (!elem
->payload
) {
2784 dl_list_del(&elem
->list
);
2790 static void interworking_parse_rx_anqp_resp(struct wpa_supplicant
*wpa_s
,
2791 struct wpa_bss
*bss
, const u8
*sa
,
2793 const u8
*data
, size_t slen
,
2796 const u8
*pos
= data
;
2797 struct wpa_bss_anqp
*anqp
= NULL
;
2800 #endif /* CONFIG_HS20 */
2806 case ANQP_CAPABILITY_LIST
:
2807 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2808 " ANQP Capability list", MAC2STR(sa
));
2809 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Capability list",
2812 wpabuf_free(anqp
->capability_list
);
2813 anqp
->capability_list
= wpabuf_alloc_copy(pos
, slen
);
2816 case ANQP_VENUE_NAME
:
2817 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2818 " Venue Name", MAC2STR(sa
));
2819 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Venue Name", pos
, slen
);
2821 wpabuf_free(anqp
->venue_name
);
2822 anqp
->venue_name
= wpabuf_alloc_copy(pos
, slen
);
2825 case ANQP_NETWORK_AUTH_TYPE
:
2826 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2827 " Network Authentication Type information",
2829 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Network Authentication "
2832 wpabuf_free(anqp
->network_auth_type
);
2833 anqp
->network_auth_type
= wpabuf_alloc_copy(pos
, slen
);
2836 case ANQP_ROAMING_CONSORTIUM
:
2837 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2838 " Roaming Consortium list", MAC2STR(sa
));
2839 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Roaming Consortium",
2842 wpabuf_free(anqp
->roaming_consortium
);
2843 anqp
->roaming_consortium
= wpabuf_alloc_copy(pos
, slen
);
2846 case ANQP_IP_ADDR_TYPE_AVAILABILITY
:
2847 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2848 " IP Address Type Availability information",
2850 wpa_hexdump(MSG_MSGDUMP
, "ANQP: IP Address Availability",
2853 wpabuf_free(anqp
->ip_addr_type_availability
);
2854 anqp
->ip_addr_type_availability
=
2855 wpabuf_alloc_copy(pos
, slen
);
2858 case ANQP_NAI_REALM
:
2859 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2860 " NAI Realm list", MAC2STR(sa
));
2861 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: NAI Realm", pos
, slen
);
2863 wpabuf_free(anqp
->nai_realm
);
2864 anqp
->nai_realm
= wpabuf_alloc_copy(pos
, slen
);
2867 case ANQP_3GPP_CELLULAR_NETWORK
:
2868 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2869 " 3GPP Cellular Network information", MAC2STR(sa
));
2870 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: 3GPP Cellular Network",
2873 wpabuf_free(anqp
->anqp_3gpp
);
2874 anqp
->anqp_3gpp
= wpabuf_alloc_copy(pos
, slen
);
2877 case ANQP_DOMAIN_NAME
:
2878 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
2879 " Domain Name list", MAC2STR(sa
));
2880 wpa_hexdump_ascii(MSG_MSGDUMP
, "ANQP: Domain Name", pos
, slen
);
2882 wpabuf_free(anqp
->domain_name
);
2883 anqp
->domain_name
= wpabuf_alloc_copy(pos
, slen
);
2886 case ANQP_VENDOR_SPECIFIC
:
2890 switch (WPA_GET_BE24(pos
)) {
2902 case HS20_ANQP_OUI_TYPE
:
2903 hs20_parse_rx_hs20_anqp_resp(wpa_s
, bss
, sa
,
2908 wpa_msg(wpa_s
, MSG_DEBUG
,
2909 "HS20: Unsupported ANQP vendor type %u",
2914 #endif /* CONFIG_HS20 */
2916 wpa_msg(wpa_s
, MSG_DEBUG
,
2917 "Interworking: Unsupported vendor-specific ANQP OUI %06x",
2923 wpa_msg(wpa_s
, MSG_DEBUG
,
2924 "Interworking: Unsupported ANQP Info ID %u", info_id
);
2925 anqp_add_extra(wpa_s
, anqp
, info_id
, data
, slen
);
2931 void anqp_resp_cb(void *ctx
, const u8
*dst
, u8 dialog_token
,
2932 enum gas_query_result result
,
2933 const struct wpabuf
*adv_proto
,
2934 const struct wpabuf
*resp
, u16 status_code
)
2936 struct wpa_supplicant
*wpa_s
= ctx
;
2941 struct wpa_bss
*bss
= NULL
, *tmp
;
2942 const char *anqp_result
= "SUCCESS";
2944 wpa_printf(MSG_DEBUG
, "Interworking: anqp_resp_cb dst=" MACSTR
2945 " dialog_token=%u result=%d status_code=%u",
2946 MAC2STR(dst
), dialog_token
, result
, status_code
);
2947 if (result
!= GAS_QUERY_SUCCESS
) {
2949 if (wpa_s
->fetch_osu_icon_in_progress
)
2950 hs20_icon_fetch_failed(wpa_s
);
2951 #endif /* CONFIG_HS20 */
2952 anqp_result
= "FAILURE";
2956 pos
= wpabuf_head(adv_proto
);
2957 if (wpabuf_len(adv_proto
) < 4 || pos
[0] != WLAN_EID_ADV_PROTO
||
2958 pos
[1] < 2 || pos
[3] != ACCESS_NETWORK_QUERY_PROTOCOL
) {
2959 wpa_msg(wpa_s
, MSG_DEBUG
,
2960 "ANQP: Unexpected Advertisement Protocol in response");
2962 if (wpa_s
->fetch_osu_icon_in_progress
)
2963 hs20_icon_fetch_failed(wpa_s
);
2964 #endif /* CONFIG_HS20 */
2965 anqp_result
= "INVALID_FRAME";
2970 * If possible, select the BSS entry based on which BSS entry was used
2971 * for the request. This can help in cases where multiple BSS entries
2972 * may exist for the same AP.
2974 dl_list_for_each_reverse(tmp
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2975 if (tmp
== wpa_s
->interworking_gas_bss
&&
2976 os_memcmp(tmp
->bssid
, dst
, ETH_ALEN
) == 0) {
2982 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
2984 pos
= wpabuf_head(resp
);
2985 end
= pos
+ wpabuf_len(resp
);
2988 unsigned int left
= end
- pos
;
2991 wpa_msg(wpa_s
, MSG_DEBUG
, "ANQP: Invalid element");
2992 anqp_result
= "INVALID_FRAME";
2993 goto out_parse_done
;
2995 info_id
= WPA_GET_LE16(pos
);
2997 slen
= WPA_GET_LE16(pos
);
3001 wpa_msg(wpa_s
, MSG_DEBUG
,
3002 "ANQP: Invalid element length for Info ID %u",
3004 anqp_result
= "INVALID_FRAME";
3005 goto out_parse_done
;
3007 interworking_parse_rx_anqp_resp(wpa_s
, bss
, dst
, info_id
, pos
,
3008 slen
, dialog_token
);
3014 hs20_notify_parse_done(wpa_s
);
3015 #endif /* CONFIG_HS20 */
3017 wpa_msg(wpa_s
, MSG_INFO
, ANQP_QUERY_DONE
"addr=" MACSTR
" result=%s",
3018 MAC2STR(dst
), anqp_result
);
3022 static void interworking_scan_res_handler(struct wpa_supplicant
*wpa_s
,
3023 struct wpa_scan_results
*scan_res
)
3025 wpa_msg(wpa_s
, MSG_DEBUG
,
3026 "Interworking: Scan results available - start ANQP fetch");
3027 interworking_start_fetch_anqp(wpa_s
);
3031 int interworking_select(struct wpa_supplicant
*wpa_s
, int auto_select
,
3034 interworking_stop_fetch_anqp(wpa_s
);
3035 wpa_s
->network_select
= 1;
3036 wpa_s
->auto_network_select
= 0;
3037 wpa_s
->auto_select
= !!auto_select
;
3038 wpa_s
->fetch_all_anqp
= 0;
3039 wpa_s
->fetch_osu_info
= 0;
3040 wpa_msg(wpa_s
, MSG_DEBUG
,
3041 "Interworking: Start scan for network selection");
3042 wpa_s
->scan_res_handler
= interworking_scan_res_handler
;
3043 wpa_s
->normal_scans
= 0;
3044 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
3045 os_free(wpa_s
->manual_scan_freqs
);
3046 wpa_s
->manual_scan_freqs
= freqs
;
3047 wpa_s
->after_wps
= 0;
3048 wpa_s
->known_wps_freq
= 0;
3049 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3055 static void gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
3056 enum gas_query_result result
,
3057 const struct wpabuf
*adv_proto
,
3058 const struct wpabuf
*resp
, u16 status_code
)
3060 struct wpa_supplicant
*wpa_s
= ctx
;
3063 wpa_msg(wpa_s
, MSG_INFO
, GAS_RESPONSE_INFO
"addr=" MACSTR
3064 " dialog_token=%d status_code=%d resp_len=%d",
3065 MAC2STR(addr
), dialog_token
, status_code
,
3066 resp
? (int) wpabuf_len(resp
) : -1);
3070 n
= wpabuf_dup(resp
);
3073 wpabuf_free(wpa_s
->prev_gas_resp
);
3074 wpa_s
->prev_gas_resp
= wpa_s
->last_gas_resp
;
3075 os_memcpy(wpa_s
->prev_gas_addr
, wpa_s
->last_gas_addr
, ETH_ALEN
);
3076 wpa_s
->prev_gas_dialog_token
= wpa_s
->last_gas_dialog_token
;
3077 wpa_s
->last_gas_resp
= n
;
3078 os_memcpy(wpa_s
->last_gas_addr
, addr
, ETH_ALEN
);
3079 wpa_s
->last_gas_dialog_token
= dialog_token
;
3083 int gas_send_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
3084 const struct wpabuf
*adv_proto
,
3085 const struct wpabuf
*query
)
3090 struct wpa_bss
*bss
;
3093 u8 query_resp_len_limit
= 0;
3095 freq
= wpa_s
->assoc_freq
;
3096 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
3102 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS request to " MACSTR
" (freq %d MHz)",
3103 MAC2STR(dst
), freq
);
3104 wpa_hexdump_buf(MSG_DEBUG
, "Advertisement Protocol ID", adv_proto
);
3105 wpa_hexdump_buf(MSG_DEBUG
, "GAS Query", query
);
3107 len
= 3 + wpabuf_len(adv_proto
) + 2;
3109 len
+= wpabuf_len(query
);
3110 buf
= gas_build_initial_req(0, len
);
3114 /* Advertisement Protocol IE */
3115 wpabuf_put_u8(buf
, WLAN_EID_ADV_PROTO
);
3116 wpabuf_put_u8(buf
, 1 + wpabuf_len(adv_proto
)); /* Length */
3117 wpabuf_put_u8(buf
, query_resp_len_limit
& 0x7f);
3118 wpabuf_put_buf(buf
, adv_proto
);
3122 wpabuf_put_le16(buf
, wpabuf_len(query
));
3123 wpabuf_put_buf(buf
, query
);
3125 wpabuf_put_le16(buf
, 0);
3127 res
= gas_query_req(wpa_s
->gas
, dst
, freq
, buf
, gas_resp_cb
, wpa_s
);
3129 wpa_msg(wpa_s
, MSG_DEBUG
, "GAS: Failed to send Query Request");
3133 wpa_msg(wpa_s
, MSG_DEBUG
,
3134 "GAS: Query started with dialog token %u", res
);