2 * Interworking (IEEE 802.11u)
3 * Copyright (c) 2011-2012, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "common/ieee802_11_defs.h"
13 #include "common/gas.h"
14 #include "common/wpa_ctrl.h"
15 #include "utils/pcsc_funcs.h"
16 #include "drivers/driver.h"
17 #include "eap_common/eap_defs.h"
18 #include "eap_peer/eap.h"
19 #include "eap_peer/eap_methods.h"
20 #include "wpa_supplicant_i.h"
22 #include "config_ssid.h"
26 #include "gas_query.h"
27 #include "hs20_supplicant.h"
28 #include "interworking.h"
31 #if defined(EAP_SIM) | defined(EAP_SIM_DYNAMIC)
32 #define INTERWORKING_3GPP
34 #if defined(EAP_AKA) | defined(EAP_AKA_DYNAMIC)
35 #define INTERWORKING_3GPP
37 #if defined(EAP_AKA_PRIME) | defined(EAP_AKA_PRIME_DYNAMIC)
38 #define INTERWORKING_3GPP
43 static void interworking_next_anqp_fetch(struct wpa_supplicant
*wpa_s
);
46 static void interworking_reconnect(struct wpa_supplicant
*wpa_s
)
48 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
49 wpa_supplicant_cancel_sched_scan(wpa_s
);
50 wpa_supplicant_deauthenticate(wpa_s
,
51 WLAN_REASON_DEAUTH_LEAVING
);
53 wpa_s
->disconnected
= 0;
54 wpa_s
->reassociate
= 1;
56 if (wpa_s
->last_scan_res_used
> 0) {
59 if (now
.sec
- wpa_s
->last_scan
.sec
<= 5) {
60 wpa_printf(MSG_DEBUG
, "Interworking: Old scan results "
61 "are fresh - connect without new scan");
62 if (wpas_select_network_from_last_scan(wpa_s
) == 0)
67 wpa_supplicant_req_scan(wpa_s
, 0, 0);
71 static struct wpabuf
* anqp_build_req(u16 info_ids
[], size_t num_ids
,
78 buf
= gas_anqp_build_initial_req(0, 4 + num_ids
* 2 +
79 (extra
? wpabuf_len(extra
) : 0));
83 len_pos
= gas_anqp_add_element(buf
, ANQP_QUERY_LIST
);
84 for (i
= 0; i
< num_ids
; i
++)
85 wpabuf_put_le16(buf
, info_ids
[i
]);
86 gas_anqp_set_element_len(buf
, len_pos
);
88 wpabuf_put_buf(buf
, extra
);
90 gas_anqp_set_len(buf
);
96 static void interworking_anqp_resp_cb(void *ctx
, const u8
*dst
,
98 enum gas_query_result result
,
99 const struct wpabuf
*adv_proto
,
100 const struct wpabuf
*resp
,
103 struct wpa_supplicant
*wpa_s
= ctx
;
105 anqp_resp_cb(wpa_s
, dst
, dialog_token
, result
, adv_proto
, resp
,
107 interworking_next_anqp_fetch(wpa_s
);
111 static int interworking_anqp_send_req(struct wpa_supplicant
*wpa_s
,
118 ANQP_CAPABILITY_LIST
,
120 ANQP_NETWORK_AUTH_TYPE
,
121 ANQP_ROAMING_CONSORTIUM
,
122 ANQP_IP_ADDR_TYPE_AVAILABILITY
,
124 ANQP_3GPP_CELLULAR_NETWORK
,
127 struct wpabuf
*extra
= NULL
;
129 wpa_printf(MSG_DEBUG
, "Interworking: ANQP Query Request to " MACSTR
,
130 MAC2STR(bss
->bssid
));
133 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
136 extra
= wpabuf_alloc(100);
140 len_pos
= gas_anqp_add_element(extra
, ANQP_VENDOR_SPECIFIC
);
141 wpabuf_put_be24(extra
, OUI_WFA
);
142 wpabuf_put_u8(extra
, HS20_ANQP_OUI_TYPE
);
143 wpabuf_put_u8(extra
, HS20_STYPE_QUERY_LIST
);
144 wpabuf_put_u8(extra
, 0); /* Reserved */
145 wpabuf_put_u8(extra
, HS20_STYPE_CAPABILITY_LIST
);
146 wpabuf_put_u8(extra
, HS20_STYPE_OPERATOR_FRIENDLY_NAME
);
147 wpabuf_put_u8(extra
, HS20_STYPE_WAN_METRICS
);
148 wpabuf_put_u8(extra
, HS20_STYPE_CONNECTION_CAPABILITY
);
149 wpabuf_put_u8(extra
, HS20_STYPE_OPERATING_CLASS
);
150 gas_anqp_set_element_len(extra
, len_pos
);
152 #endif /* CONFIG_HS20 */
154 buf
= anqp_build_req(info_ids
, sizeof(info_ids
) / sizeof(info_ids
[0]),
160 res
= gas_query_req(wpa_s
->gas
, bss
->bssid
, bss
->freq
, buf
,
161 interworking_anqp_resp_cb
, wpa_s
);
163 wpa_printf(MSG_DEBUG
, "ANQP: Failed to send Query Request");
166 wpa_printf(MSG_DEBUG
, "ANQP: Query started with dialog token "
174 struct nai_realm_eap
{
177 enum nai_realm_eap_auth_inner_non_eap inner_non_eap
;
179 u8 tunneled_cred_type
;
186 struct nai_realm_eap
*eap
;
190 static void nai_realm_free(struct nai_realm
*realms
, u16 count
)
196 for (i
= 0; i
< count
; i
++) {
197 os_free(realms
[i
].eap
);
198 os_free(realms
[i
].realm
);
204 static const u8
* nai_realm_parse_eap(struct nai_realm_eap
*e
, const u8
*pos
,
207 u8 elen
, auth_count
, a
;
211 wpa_printf(MSG_DEBUG
, "No room for EAP Method fixed fields");
216 if (pos
+ elen
> end
|| elen
< 2) {
217 wpa_printf(MSG_DEBUG
, "No room for EAP Method subfield");
223 wpa_printf(MSG_DEBUG
, "EAP Method: len=%u method=%u auth_count=%u",
224 elen
, e
->method
, auth_count
);
226 for (a
= 0; a
< auth_count
; a
++) {
229 if (pos
+ 2 > end
|| pos
+ 2 + pos
[1] > end
) {
230 wpa_printf(MSG_DEBUG
, "No room for Authentication "
231 "Parameter subfield");
239 case NAI_REALM_EAP_AUTH_NON_EAP_INNER_AUTH
:
242 e
->inner_non_eap
= *pos
;
243 if (e
->method
!= EAP_TYPE_TTLS
)
246 case NAI_REALM_INNER_NON_EAP_PAP
:
247 wpa_printf(MSG_DEBUG
, "EAP-TTLS/PAP");
249 case NAI_REALM_INNER_NON_EAP_CHAP
:
250 wpa_printf(MSG_DEBUG
, "EAP-TTLS/CHAP");
252 case NAI_REALM_INNER_NON_EAP_MSCHAP
:
253 wpa_printf(MSG_DEBUG
, "EAP-TTLS/MSCHAP");
255 case NAI_REALM_INNER_NON_EAP_MSCHAPV2
:
256 wpa_printf(MSG_DEBUG
, "EAP-TTLS/MSCHAPV2");
260 case NAI_REALM_EAP_AUTH_INNER_AUTH_EAP_METHOD
:
263 e
->inner_method
= *pos
;
264 wpa_printf(MSG_DEBUG
, "Inner EAP method: %u",
267 case NAI_REALM_EAP_AUTH_CRED_TYPE
:
271 wpa_printf(MSG_DEBUG
, "Credential Type: %u",
274 case NAI_REALM_EAP_AUTH_TUNNELED_CRED_TYPE
:
277 e
->tunneled_cred_type
= *pos
;
278 wpa_printf(MSG_DEBUG
, "Tunneled EAP Method Credential "
279 "Type: %u", e
->tunneled_cred_type
);
282 wpa_printf(MSG_DEBUG
, "Unsupported Authentication "
283 "Parameter: id=%u len=%u", id
, len
);
284 wpa_hexdump(MSG_DEBUG
, "Authentication Parameter "
296 static const u8
* nai_realm_parse_realm(struct nai_realm
*r
, const u8
*pos
,
304 wpa_printf(MSG_DEBUG
, "No room for NAI Realm Data "
309 len
= WPA_GET_LE16(pos
); /* NAI Realm Data field Length */
311 if (pos
+ len
> end
|| len
< 3) {
312 wpa_printf(MSG_DEBUG
, "No room for NAI Realm Data "
314 len
, (unsigned int) (end
- pos
));
319 r
->encoding
= *pos
++;
321 if (pos
+ realm_len
> f_end
) {
322 wpa_printf(MSG_DEBUG
, "No room for NAI Realm "
324 realm_len
, (unsigned int) (f_end
- pos
));
327 wpa_hexdump_ascii(MSG_DEBUG
, "NAI Realm", pos
, realm_len
);
328 r
->realm
= os_malloc(realm_len
+ 1);
329 if (r
->realm
== NULL
)
331 os_memcpy(r
->realm
, pos
, realm_len
);
332 r
->realm
[realm_len
] = '\0';
335 if (pos
+ 1 > f_end
) {
336 wpa_printf(MSG_DEBUG
, "No room for EAP Method Count");
339 r
->eap_count
= *pos
++;
340 wpa_printf(MSG_DEBUG
, "EAP Count: %u", r
->eap_count
);
341 if (pos
+ r
->eap_count
* 3 > f_end
) {
342 wpa_printf(MSG_DEBUG
, "No room for EAP Methods");
345 r
->eap
= os_calloc(r
->eap_count
, sizeof(struct nai_realm_eap
));
349 for (e
= 0; e
< r
->eap_count
; e
++) {
350 pos
= nai_realm_parse_eap(&r
->eap
[e
], pos
, f_end
);
359 static struct nai_realm
* nai_realm_parse(struct wpabuf
*anqp
, u16
*count
)
361 struct nai_realm
*realm
;
365 if (anqp
== NULL
|| wpabuf_len(anqp
) < 2)
368 pos
= wpabuf_head_u8(anqp
);
369 end
= pos
+ wpabuf_len(anqp
);
370 num
= WPA_GET_LE16(pos
);
371 wpa_printf(MSG_DEBUG
, "NAI Realm Count: %u", num
);
374 if (num
* 5 > end
- pos
) {
375 wpa_printf(MSG_DEBUG
, "Invalid NAI Realm Count %u - not "
376 "enough data (%u octets) for that many realms",
377 num
, (unsigned int) (end
- pos
));
381 realm
= os_calloc(num
, sizeof(struct nai_realm
));
385 for (i
= 0; i
< num
; i
++) {
386 pos
= nai_realm_parse_realm(&realm
[i
], pos
, end
);
388 nai_realm_free(realm
, num
);
398 static int nai_realm_match(struct nai_realm
*realm
, const char *home_realm
)
400 char *tmp
, *pos
, *end
;
403 if (realm
->realm
== NULL
|| home_realm
== NULL
)
406 if (os_strchr(realm
->realm
, ';') == NULL
)
407 return os_strcasecmp(realm
->realm
, home_realm
) == 0;
409 tmp
= os_strdup(realm
->realm
);
415 end
= os_strchr(pos
, ';');
418 if (os_strcasecmp(pos
, home_realm
) == 0) {
433 static int nai_realm_cred_username(struct nai_realm_eap
*eap
)
435 if (eap_get_name(EAP_VENDOR_IETF
, eap
->method
) == NULL
)
436 return 0; /* method not supported */
438 if (eap
->method
!= EAP_TYPE_TTLS
&& eap
->method
!= EAP_TYPE_PEAP
) {
439 /* Only tunneled methods with username/password supported */
443 if (eap
->method
== EAP_TYPE_PEAP
&&
444 eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
) == NULL
)
447 if (eap
->method
== EAP_TYPE_TTLS
) {
448 if (eap
->inner_method
== 0 && eap
->inner_non_eap
== 0)
450 if (eap
->inner_method
&&
451 eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
) == NULL
)
453 if (eap
->inner_non_eap
&&
454 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_PAP
&&
455 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_CHAP
&&
456 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_MSCHAP
&&
457 eap
->inner_non_eap
!= NAI_REALM_INNER_NON_EAP_MSCHAPV2
)
461 if (eap
->inner_method
&&
462 eap
->inner_method
!= EAP_TYPE_GTC
&&
463 eap
->inner_method
!= EAP_TYPE_MSCHAPV2
)
470 static int nai_realm_cred_cert(struct nai_realm_eap
*eap
)
472 if (eap_get_name(EAP_VENDOR_IETF
, eap
->method
) == NULL
)
473 return 0; /* method not supported */
475 if (eap
->method
!= EAP_TYPE_TLS
) {
476 /* Only EAP-TLS supported for credential authentication */
484 static struct nai_realm_eap
* nai_realm_find_eap(struct wpa_cred
*cred
,
485 struct nai_realm
*realm
)
490 cred
->username
== NULL
||
491 cred
->username
[0] == '\0' ||
492 ((cred
->password
== NULL
||
493 cred
->password
[0] == '\0') &&
494 (cred
->private_key
== NULL
||
495 cred
->private_key
[0] == '\0')))
498 for (e
= 0; e
< realm
->eap_count
; e
++) {
499 struct nai_realm_eap
*eap
= &realm
->eap
[e
];
500 if (cred
->password
&& cred
->password
[0] &&
501 nai_realm_cred_username(eap
))
503 if (cred
->private_key
&& cred
->private_key
[0] &&
504 nai_realm_cred_cert(eap
))
512 #ifdef INTERWORKING_3GPP
514 static int plmn_id_match(struct wpabuf
*anqp
, const char *imsi
, int mnc_len
)
520 /* See Annex A of 3GPP TS 24.234 v8.1.0 for description */
521 plmn
[0] = (imsi
[0] - '0') | ((imsi
[1] - '0') << 4);
522 plmn
[1] = imsi
[2] - '0';
523 /* default to MNC length 3 if unknown */
525 plmn
[1] |= (imsi
[5] - '0') << 4;
528 plmn
[2] = (imsi
[3] - '0') | ((imsi
[4] - '0') << 4);
532 pos
= wpabuf_head_u8(anqp
);
533 end
= pos
+ wpabuf_len(anqp
);
537 wpa_printf(MSG_DEBUG
, "Unsupported GUD version 0x%x", *pos
);
542 if (pos
+ udhl
> end
) {
543 wpa_printf(MSG_DEBUG
, "Invalid UDHL");
548 while (pos
+ 2 <= end
) {
557 if (iei
== 0 && len
> 0) {
561 for (i
= 0; i
< num
; i
++) {
564 if (os_memcmp(pos
, plmn
, 3) == 0)
565 return 1; /* Found matching PLMN */
577 static int build_root_nai(char *nai
, size_t nai_len
, const char *imsi
,
578 size_t mnc_len
, char prefix
)
580 const char *sep
, *msin
;
582 size_t msin_len
, plmn_len
;
585 * TS 23.003, Clause 14 (3GPP to WLAN Interworking)
587 * <aka:0|sim:1><IMSI>@wlan.mnc<MNC>.mcc<MCC>.3gppnetwork.org
588 * <MNC> is zero-padded to three digits in case two-digit MNC is used
591 if (imsi
== NULL
|| os_strlen(imsi
) > 16) {
592 wpa_printf(MSG_DEBUG
, "No valid IMSI available");
595 sep
= os_strchr(imsi
, '-');
597 plmn_len
= sep
- imsi
;
599 } else if (mnc_len
&& os_strlen(imsi
) >= 3 + mnc_len
) {
600 plmn_len
= 3 + mnc_len
;
601 msin
= imsi
+ plmn_len
;
604 if (plmn_len
!= 5 && plmn_len
!= 6)
606 msin_len
= os_strlen(msin
);
612 os_memcpy(pos
, imsi
, plmn_len
);
614 os_memcpy(pos
, msin
, msin_len
);
616 pos
+= os_snprintf(pos
, end
- pos
, "@wlan.mnc");
626 pos
+= os_snprintf(pos
, end
- pos
, ".mcc%c%c%c.3gppnetwork.org",
627 imsi
[0], imsi
[1], imsi
[2]);
633 static int set_root_nai(struct wpa_ssid
*ssid
, const char *imsi
, char prefix
)
636 if (build_root_nai(nai
, sizeof(nai
), imsi
, 0, prefix
) < 0)
638 return wpa_config_set_quoted(ssid
, "identity", nai
);
641 #endif /* INTERWORKING_3GPP */
644 static int interworking_set_hs20_params(struct wpa_ssid
*ssid
)
646 if (wpa_config_set(ssid
, "key_mgmt", "WPA-EAP", 0) < 0)
648 if (wpa_config_set(ssid
, "proto", "RSN", 0) < 0)
650 if (wpa_config_set(ssid
, "pairwise", "CCMP", 0) < 0)
656 static int interworking_connect_3gpp(struct wpa_supplicant
*wpa_s
,
659 #ifdef INTERWORKING_3GPP
660 struct wpa_cred
*cred
;
661 struct wpa_ssid
*ssid
;
664 if (bss
->anqp_3gpp
== NULL
)
667 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
673 if (cred
->pcsc
&& wpa_s
->conf
->pcsc_reader
&& wpa_s
->scard
&&
676 mnc_len
= wpa_s
->mnc_len
;
679 #endif /* PCSC_FUNCS */
681 if (cred
->imsi
== NULL
|| !cred
->imsi
[0] ||
682 cred
->milenage
== NULL
|| !cred
->milenage
[0])
685 sep
= os_strchr(cred
->imsi
, '-');
687 (sep
- cred
->imsi
!= 5 && sep
- cred
->imsi
!= 6))
689 mnc_len
= sep
- cred
->imsi
- 3;
694 #endif /* PCSC_FUNCS */
695 if (plmn_id_match(bss
->anqp_3gpp
, imsi
, mnc_len
))
701 ie
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
704 wpa_printf(MSG_DEBUG
, "Interworking: Connect with " MACSTR
" (3GPP)",
705 MAC2STR(bss
->bssid
));
707 ssid
= wpa_config_add_network(wpa_s
->conf
);
711 wpas_notify_network_added(wpa_s
, ssid
);
712 wpa_config_set_network_defaults(ssid
);
713 ssid
->priority
= cred
->priority
;
715 ssid
->ssid
= os_zalloc(ie
[1] + 1);
716 if (ssid
->ssid
== NULL
)
718 os_memcpy(ssid
->ssid
, ie
+ 2, ie
[1]);
719 ssid
->ssid_len
= ie
[1];
721 if (interworking_set_hs20_params(ssid
) < 0)
724 /* TODO: figure out whether to use EAP-SIM, EAP-AKA, or EAP-AKA' */
725 if (wpa_config_set(ssid
, "eap", "SIM", 0) < 0) {
726 wpa_printf(MSG_DEBUG
, "EAP-SIM not supported");
729 if (cred
->pcsc
&& wpa_s
->scard
&& scard_supports_umts(wpa_s
->scard
))
730 wpa_config_set(ssid
, "eap", "AKA", 0);
731 if (!cred
->pcsc
&& set_root_nai(ssid
, cred
->imsi
, '1') < 0) {
732 wpa_printf(MSG_DEBUG
, "Failed to set Root NAI");
736 if (cred
->milenage
&& cred
->milenage
[0]) {
737 if (wpa_config_set_quoted(ssid
, "password",
740 } else if (cred
->pcsc
) {
741 if (wpa_config_set_quoted(ssid
, "pcsc", "") < 0)
743 if (wpa_s
->conf
->pcsc_pin
&&
744 wpa_config_set_quoted(ssid
, "pin", wpa_s
->conf
->pcsc_pin
)
749 if (cred
->password
&& cred
->password
[0] &&
750 wpa_config_set_quoted(ssid
, "password", cred
->password
) < 0)
753 wpa_config_update_prio_list(wpa_s
->conf
);
754 interworking_reconnect(wpa_s
);
759 wpas_notify_network_removed(wpa_s
, ssid
);
760 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
761 #endif /* INTERWORKING_3GPP */
766 static int roaming_consortium_element_match(const u8
*ie
, const u8
*rc_id
,
776 end
= ie
+ 2 + ie
[1];
778 /* Roaming Consortium element:
780 * OI #1 and #2 lengths
781 * OI #1, [OI #2], [OI #3]
787 pos
++; /* skip Number of ANQP OIs */
789 if (pos
+ (lens
& 0x0f) + (lens
>> 4) > end
)
792 if ((lens
& 0x0f) == rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
796 if ((lens
>> 4) == rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
800 if (pos
< end
&& (size_t) (end
- pos
) == rc_len
&&
801 os_memcmp(pos
, rc_id
, rc_len
) == 0)
808 static int roaming_consortium_anqp_match(const struct wpabuf
*anqp
,
809 const u8
*rc_id
, size_t rc_len
)
817 pos
= wpabuf_head(anqp
);
818 end
= pos
+ wpabuf_len(anqp
);
820 /* Set of <OI Length, OI> duples */
825 if (len
== rc_len
&& os_memcmp(pos
, rc_id
, rc_len
) == 0)
834 static int roaming_consortium_match(const u8
*ie
, const struct wpabuf
*anqp
,
835 const u8
*rc_id
, size_t rc_len
)
837 return roaming_consortium_element_match(ie
, rc_id
, rc_len
) ||
838 roaming_consortium_anqp_match(anqp
, rc_id
, rc_len
);
842 static struct wpa_cred
* interworking_credentials_available_roaming_consortium(
843 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
845 struct wpa_cred
*cred
, *selected
= NULL
;
848 ie
= wpa_bss_get_ie(bss
, WLAN_EID_ROAMING_CONSORTIUM
);
850 if (ie
== NULL
&& bss
->anqp_roaming_consortium
== NULL
)
853 if (wpa_s
->conf
->cred
== NULL
)
856 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
857 if (cred
->roaming_consortium_len
== 0)
860 if (!roaming_consortium_match(ie
, bss
->anqp_roaming_consortium
,
861 cred
->roaming_consortium
,
862 cred
->roaming_consortium_len
))
865 if (selected
== NULL
||
866 selected
->priority
< cred
->priority
)
874 static int interworking_set_eap_params(struct wpa_ssid
*ssid
,
875 struct wpa_cred
*cred
, int ttls
)
877 if (cred
->eap_method
) {
878 ttls
= cred
->eap_method
->vendor
== EAP_VENDOR_IETF
&&
879 cred
->eap_method
->method
== EAP_TYPE_TTLS
;
881 os_free(ssid
->eap
.eap_methods
);
882 ssid
->eap
.eap_methods
=
883 os_malloc(sizeof(struct eap_method_type
) * 2);
884 if (ssid
->eap
.eap_methods
== NULL
)
886 os_memcpy(ssid
->eap
.eap_methods
, cred
->eap_method
,
887 sizeof(*cred
->eap_method
));
888 ssid
->eap
.eap_methods
[1].vendor
= EAP_VENDOR_IETF
;
889 ssid
->eap
.eap_methods
[1].method
= EAP_TYPE_NONE
;
892 if (ttls
&& cred
->username
&& cred
->username
[0]) {
895 /* Use anonymous NAI in Phase 1 */
896 pos
= os_strchr(cred
->username
, '@');
898 size_t buflen
= 9 + os_strlen(pos
) + 1;
899 anon
= os_malloc(buflen
);
902 os_snprintf(anon
, buflen
, "anonymous%s", pos
);
903 } else if (cred
->realm
) {
904 size_t buflen
= 10 + os_strlen(cred
->realm
) + 1;
905 anon
= os_malloc(buflen
);
908 os_snprintf(anon
, buflen
, "anonymous@%s", cred
->realm
);
910 anon
= os_strdup("anonymous");
914 if (wpa_config_set_quoted(ssid
, "anonymous_identity", anon
) <
922 if (cred
->username
&& cred
->username
[0] &&
923 wpa_config_set_quoted(ssid
, "identity", cred
->username
) < 0)
926 if (cred
->password
&& cred
->password
[0]) {
927 if (cred
->ext_password
&&
928 wpa_config_set(ssid
, "password", cred
->password
, 0) < 0)
930 if (!cred
->ext_password
&&
931 wpa_config_set_quoted(ssid
, "password", cred
->password
) <
936 if (cred
->client_cert
&& cred
->client_cert
[0] &&
937 wpa_config_set_quoted(ssid
, "client_cert", cred
->client_cert
) < 0)
940 if (cred
->private_key
&& cred
->private_key
[0] &&
941 wpa_config_set_quoted(ssid
, "private_key", cred
->private_key
) < 0)
944 if (cred
->private_key_passwd
&& cred
->private_key_passwd
[0] &&
945 wpa_config_set_quoted(ssid
, "private_key_passwd",
946 cred
->private_key_passwd
) < 0)
950 os_free(ssid
->eap
.phase1
);
951 ssid
->eap
.phase1
= os_strdup(cred
->phase1
);
954 os_free(ssid
->eap
.phase2
);
955 ssid
->eap
.phase2
= os_strdup(cred
->phase2
);
958 if (cred
->ca_cert
&& cred
->ca_cert
[0] &&
959 wpa_config_set_quoted(ssid
, "ca_cert", cred
->ca_cert
) < 0)
966 static int interworking_connect_roaming_consortium(
967 struct wpa_supplicant
*wpa_s
, struct wpa_cred
*cred
,
968 struct wpa_bss
*bss
, const u8
*ssid_ie
)
970 struct wpa_ssid
*ssid
;
972 wpa_printf(MSG_DEBUG
, "Interworking: Connect with " MACSTR
" based on "
973 "roaming consortium match", MAC2STR(bss
->bssid
));
975 ssid
= wpa_config_add_network(wpa_s
->conf
);
978 wpas_notify_network_added(wpa_s
, ssid
);
979 wpa_config_set_network_defaults(ssid
);
980 ssid
->priority
= cred
->priority
;
982 ssid
->ssid
= os_zalloc(ssid_ie
[1] + 1);
983 if (ssid
->ssid
== NULL
)
985 os_memcpy(ssid
->ssid
, ssid_ie
+ 2, ssid_ie
[1]);
986 ssid
->ssid_len
= ssid_ie
[1];
988 if (interworking_set_hs20_params(ssid
) < 0)
991 if (cred
->eap_method
== NULL
) {
992 wpa_printf(MSG_DEBUG
, "Interworking: No EAP method set for "
993 "credential using roaming consortium");
997 if (interworking_set_eap_params(
999 cred
->eap_method
->vendor
== EAP_VENDOR_IETF
&&
1000 cred
->eap_method
->method
== EAP_TYPE_TTLS
) < 0)
1003 wpa_config_update_prio_list(wpa_s
->conf
);
1004 interworking_reconnect(wpa_s
);
1009 wpas_notify_network_removed(wpa_s
, ssid
);
1010 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1015 int interworking_connect(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
1017 struct wpa_cred
*cred
;
1018 struct wpa_ssid
*ssid
;
1019 struct nai_realm
*realm
;
1020 struct nai_realm_eap
*eap
= NULL
;
1025 if (wpa_s
->conf
->cred
== NULL
|| bss
== NULL
)
1027 ie
= wpa_bss_get_ie(bss
, WLAN_EID_SSID
);
1028 if (ie
== NULL
|| ie
[1] == 0) {
1029 wpa_printf(MSG_DEBUG
, "Interworking: No SSID known for "
1030 MACSTR
, MAC2STR(bss
->bssid
));
1034 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) {
1036 * We currently support only HS 2.0 networks and those are
1037 * required to use WPA2-Enterprise.
1039 wpa_printf(MSG_DEBUG
, "Interworking: Network does not use "
1044 cred
= interworking_credentials_available_roaming_consortium(wpa_s
,
1047 return interworking_connect_roaming_consortium(wpa_s
, cred
,
1050 realm
= nai_realm_parse(bss
->anqp_nai_realm
, &count
);
1051 if (realm
== NULL
) {
1052 wpa_printf(MSG_DEBUG
, "Interworking: Could not parse NAI "
1053 "Realm list from " MACSTR
, MAC2STR(bss
->bssid
));
1057 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1058 for (i
= 0; i
< count
; i
++) {
1059 if (!nai_realm_match(&realm
[i
], cred
->realm
))
1061 eap
= nai_realm_find_eap(cred
, &realm
[i
]);
1070 if (interworking_connect_3gpp(wpa_s
, bss
) == 0) {
1072 nai_realm_free(realm
, count
);
1076 wpa_printf(MSG_DEBUG
, "Interworking: No matching credentials "
1077 "and EAP method found for " MACSTR
,
1078 MAC2STR(bss
->bssid
));
1079 nai_realm_free(realm
, count
);
1083 wpa_printf(MSG_DEBUG
, "Interworking: Connect with " MACSTR
,
1084 MAC2STR(bss
->bssid
));
1086 ssid
= wpa_config_add_network(wpa_s
->conf
);
1088 nai_realm_free(realm
, count
);
1091 wpas_notify_network_added(wpa_s
, ssid
);
1092 wpa_config_set_network_defaults(ssid
);
1093 ssid
->priority
= cred
->priority
;
1094 ssid
->temporary
= 1;
1095 ssid
->ssid
= os_zalloc(ie
[1] + 1);
1096 if (ssid
->ssid
== NULL
)
1098 os_memcpy(ssid
->ssid
, ie
+ 2, ie
[1]);
1099 ssid
->ssid_len
= ie
[1];
1101 if (interworking_set_hs20_params(ssid
) < 0)
1104 if (wpa_config_set(ssid
, "eap", eap_get_name(EAP_VENDOR_IETF
,
1105 eap
->method
), 0) < 0)
1108 switch (eap
->method
) {
1110 if (eap
->inner_method
) {
1111 os_snprintf(buf
, sizeof(buf
), "\"autheap=%s\"",
1112 eap_get_name(EAP_VENDOR_IETF
,
1113 eap
->inner_method
));
1114 if (wpa_config_set(ssid
, "phase2", buf
, 0) < 0)
1118 switch (eap
->inner_non_eap
) {
1119 case NAI_REALM_INNER_NON_EAP_PAP
:
1120 if (wpa_config_set(ssid
, "phase2", "\"auth=PAP\"", 0) <
1124 case NAI_REALM_INNER_NON_EAP_CHAP
:
1125 if (wpa_config_set(ssid
, "phase2", "\"auth=CHAP\"", 0)
1129 case NAI_REALM_INNER_NON_EAP_MSCHAP
:
1130 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAP\"",
1134 case NAI_REALM_INNER_NON_EAP_MSCHAPV2
:
1135 if (wpa_config_set(ssid
, "phase2", "\"auth=MSCHAPV2\"",
1142 os_snprintf(buf
, sizeof(buf
), "\"auth=%s\"",
1143 eap_get_name(EAP_VENDOR_IETF
, eap
->inner_method
));
1144 if (wpa_config_set(ssid
, "phase2", buf
, 0) < 0)
1151 if (interworking_set_eap_params(ssid
, cred
,
1152 eap
->method
== EAP_TYPE_TTLS
) < 0)
1155 nai_realm_free(realm
, count
);
1157 wpa_config_update_prio_list(wpa_s
->conf
);
1158 interworking_reconnect(wpa_s
);
1163 wpas_notify_network_removed(wpa_s
, ssid
);
1164 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1165 nai_realm_free(realm
, count
);
1170 static struct wpa_cred
* interworking_credentials_available_3gpp(
1171 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
1173 struct wpa_cred
*cred
, *selected
= NULL
;
1176 #ifdef INTERWORKING_3GPP
1177 if (bss
->anqp_3gpp
== NULL
)
1180 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1186 if (cred
->pcsc
&& wpa_s
->conf
->pcsc_reader
&& wpa_s
->scard
&&
1189 mnc_len
= wpa_s
->mnc_len
;
1192 #endif /* PCSC_FUNCS */
1194 if (cred
->imsi
== NULL
|| !cred
->imsi
[0] ||
1195 cred
->milenage
== NULL
|| !cred
->milenage
[0])
1198 sep
= os_strchr(cred
->imsi
, '-');
1200 (sep
- cred
->imsi
!= 5 && sep
- cred
->imsi
!= 6))
1202 mnc_len
= sep
- cred
->imsi
- 3;
1207 #endif /* PCSC_FUNCS */
1208 wpa_printf(MSG_DEBUG
, "Interworking: Parsing 3GPP info from "
1209 MACSTR
, MAC2STR(bss
->bssid
));
1210 ret
= plmn_id_match(bss
->anqp_3gpp
, imsi
, mnc_len
);
1211 wpa_printf(MSG_DEBUG
, "PLMN match %sfound", ret
? "" : "not ");
1213 if (selected
== NULL
||
1214 selected
->priority
< cred
->priority
)
1218 #endif /* INTERWORKING_3GPP */
1223 static struct wpa_cred
* interworking_credentials_available_realm(
1224 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
1226 struct wpa_cred
*cred
, *selected
= NULL
;
1227 struct nai_realm
*realm
;
1230 if (bss
->anqp_nai_realm
== NULL
)
1233 if (wpa_s
->conf
->cred
== NULL
)
1236 wpa_printf(MSG_DEBUG
, "Interworking: Parsing NAI Realm list from "
1237 MACSTR
, MAC2STR(bss
->bssid
));
1238 realm
= nai_realm_parse(bss
->anqp_nai_realm
, &count
);
1239 if (realm
== NULL
) {
1240 wpa_printf(MSG_DEBUG
, "Interworking: Could not parse NAI "
1241 "Realm list from " MACSTR
, MAC2STR(bss
->bssid
));
1245 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1246 if (cred
->realm
== NULL
)
1249 for (i
= 0; i
< count
; i
++) {
1250 if (!nai_realm_match(&realm
[i
], cred
->realm
))
1252 if (nai_realm_find_eap(cred
, &realm
[i
])) {
1253 if (selected
== NULL
||
1254 selected
->priority
< cred
->priority
)
1261 nai_realm_free(realm
, count
);
1267 static struct wpa_cred
* interworking_credentials_available(
1268 struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
)
1270 struct wpa_cred
*cred
, *cred2
;
1272 cred
= interworking_credentials_available_realm(wpa_s
, bss
);
1273 cred2
= interworking_credentials_available_3gpp(wpa_s
, bss
);
1274 if (cred
&& cred2
&& cred2
->priority
>= cred
->priority
)
1279 cred2
= interworking_credentials_available_roaming_consortium(wpa_s
,
1281 if (cred
&& cred2
&& cred2
->priority
>= cred
->priority
)
1290 static int domain_name_list_contains(struct wpabuf
*domain_names
,
1293 const u8
*pos
, *end
;
1296 len
= os_strlen(domain
);
1297 pos
= wpabuf_head(domain_names
);
1298 end
= pos
+ wpabuf_len(domain_names
);
1300 while (pos
+ 1 < end
) {
1301 if (pos
+ 1 + pos
[0] > end
)
1304 wpa_hexdump_ascii(MSG_DEBUG
, "Interworking: AP domain name",
1306 if (pos
[0] == len
&&
1307 os_strncasecmp(domain
, (const char *) (pos
+ 1), len
) == 0)
1317 static int interworking_home_sp(struct wpa_supplicant
*wpa_s
,
1318 struct wpabuf
*domain_names
)
1320 struct wpa_cred
*cred
;
1321 #ifdef INTERWORKING_3GPP
1322 char nai
[100], *realm
;
1323 #endif /* INTERWORKING_3GPP */
1325 if (domain_names
== NULL
|| wpa_s
->conf
->cred
== NULL
)
1328 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1329 #ifdef INTERWORKING_3GPP
1335 else if (cred
->pcsc
&& wpa_s
->conf
->pcsc_reader
&&
1336 wpa_s
->scard
&& wpa_s
->imsi
[0]) {
1338 mnc_len
= wpa_s
->mnc_len
;
1340 #endif /* CONFIG_PCSC */
1341 if (imsi
&& build_root_nai(nai
, sizeof(nai
), imsi
, mnc_len
, 0)
1343 realm
= os_strchr(nai
, '@');
1346 wpa_printf(MSG_DEBUG
, "Interworking: Search for match "
1347 "with SIM/USIM domain %s", realm
);
1349 domain_name_list_contains(domain_names
, realm
))
1352 #endif /* INTERWORKING_3GPP */
1354 if (cred
->domain
== NULL
)
1357 wpa_printf(MSG_DEBUG
, "Interworking: Search for match with "
1358 "home SP FQDN %s", cred
->domain
);
1359 if (domain_name_list_contains(domain_names
, cred
->domain
))
1367 static int interworking_find_network_match(struct wpa_supplicant
*wpa_s
)
1369 struct wpa_bss
*bss
;
1370 struct wpa_ssid
*ssid
;
1372 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1373 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1374 if (wpas_network_disabled(wpa_s
, ssid
) ||
1375 ssid
->mode
!= WPAS_MODE_INFRA
)
1377 if (ssid
->ssid_len
!= bss
->ssid_len
||
1378 os_memcmp(ssid
->ssid
, bss
->ssid
, ssid
->ssid_len
) !=
1382 * TODO: Consider more accurate matching of security
1383 * configuration similarly to what is done in events.c
1393 static void interworking_select_network(struct wpa_supplicant
*wpa_s
)
1395 struct wpa_bss
*bss
, *selected
= NULL
, *selected_home
= NULL
;
1396 int selected_prio
= -999999, selected_home_prio
= -999999;
1397 unsigned int count
= 0;
1400 struct wpa_cred
*cred
;
1402 wpa_s
->network_select
= 0;
1404 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1405 cred
= interworking_credentials_available(wpa_s
, bss
);
1408 if (!wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) {
1410 * We currently support only HS 2.0 networks and those
1411 * are required to use WPA2-Enterprise.
1413 wpa_printf(MSG_DEBUG
, "Interworking: Credential match "
1414 "with " MACSTR
" but network does not use "
1415 "RSN", MAC2STR(bss
->bssid
));
1419 res
= interworking_home_sp(wpa_s
, bss
->anqp_domain_name
);
1426 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_AP MACSTR
" type=%s",
1427 MAC2STR(bss
->bssid
), type
);
1428 if (wpa_s
->auto_select
||
1429 (wpa_s
->conf
->auto_interworking
&&
1430 wpa_s
->auto_network_select
)) {
1431 if (selected
== NULL
||
1432 cred
->priority
> selected_prio
) {
1434 selected_prio
= cred
->priority
;
1437 (selected_home
== NULL
||
1438 cred
->priority
> selected_home_prio
)) {
1439 selected_home
= bss
;
1440 selected_home_prio
= cred
->priority
;
1445 if (selected_home
&& selected_home
!= selected
&&
1446 selected_home_prio
>= selected_prio
) {
1447 /* Prefer network operated by the Home SP */
1448 selected
= selected_home
;
1453 * No matching network was found based on configured
1454 * credentials. Check whether any of the enabled network blocks
1455 * have matching APs.
1457 if (interworking_find_network_match(wpa_s
)) {
1458 wpa_printf(MSG_DEBUG
, "Interworking: Possible BSS "
1459 "match for enabled network configurations");
1460 if (wpa_s
->auto_select
)
1461 interworking_reconnect(wpa_s
);
1465 if (wpa_s
->auto_network_select
) {
1466 wpa_printf(MSG_DEBUG
, "Interworking: Continue "
1467 "scanning after ANQP fetch");
1468 wpa_supplicant_req_scan(wpa_s
, wpa_s
->scan_interval
,
1473 wpa_msg(wpa_s
, MSG_INFO
, INTERWORKING_NO_MATCH
"No network "
1474 "with matching credentials found");
1478 interworking_connect(wpa_s
, selected
);
1482 static void interworking_next_anqp_fetch(struct wpa_supplicant
*wpa_s
)
1484 struct wpa_bss
*bss
;
1488 if (!wpa_s
->fetch_anqp_in_progress
)
1491 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1492 if (!(bss
->caps
& IEEE80211_CAP_ESS
))
1494 ie
= wpa_bss_get_ie(bss
, WLAN_EID_EXT_CAPAB
);
1495 if (ie
== NULL
|| ie
[1] < 4 || !(ie
[5] & 0x80))
1496 continue; /* AP does not support Interworking */
1498 if (!(bss
->flags
& WPA_BSS_ANQP_FETCH_TRIED
)) {
1500 bss
->flags
|= WPA_BSS_ANQP_FETCH_TRIED
;
1501 wpa_msg(wpa_s
, MSG_INFO
, "Starting ANQP fetch for "
1502 MACSTR
, MAC2STR(bss
->bssid
));
1503 interworking_anqp_send_req(wpa_s
, bss
);
1509 wpa_msg(wpa_s
, MSG_INFO
, "ANQP fetch completed");
1510 wpa_s
->fetch_anqp_in_progress
= 0;
1511 if (wpa_s
->network_select
)
1512 interworking_select_network(wpa_s
);
1517 void interworking_start_fetch_anqp(struct wpa_supplicant
*wpa_s
)
1519 struct wpa_bss
*bss
;
1521 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
)
1522 bss
->flags
&= ~WPA_BSS_ANQP_FETCH_TRIED
;
1524 wpa_s
->fetch_anqp_in_progress
= 1;
1525 interworking_next_anqp_fetch(wpa_s
);
1529 int interworking_fetch_anqp(struct wpa_supplicant
*wpa_s
)
1531 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
)
1534 wpa_s
->network_select
= 0;
1536 interworking_start_fetch_anqp(wpa_s
);
1542 void interworking_stop_fetch_anqp(struct wpa_supplicant
*wpa_s
)
1544 if (!wpa_s
->fetch_anqp_in_progress
)
1547 wpa_s
->fetch_anqp_in_progress
= 0;
1551 int anqp_send_req(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1552 u16 info_ids
[], size_t num_ids
)
1557 struct wpa_bss
*bss
;
1560 freq
= wpa_s
->assoc_freq
;
1561 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
1567 wpa_printf(MSG_DEBUG
, "ANQP: Query Request to " MACSTR
" for %u id(s)",
1568 MAC2STR(dst
), (unsigned int) num_ids
);
1570 buf
= anqp_build_req(info_ids
, num_ids
, NULL
);
1574 res
= gas_query_req(wpa_s
->gas
, dst
, freq
, buf
, anqp_resp_cb
, wpa_s
);
1576 wpa_printf(MSG_DEBUG
, "ANQP: Failed to send Query Request");
1579 wpa_printf(MSG_DEBUG
, "ANQP: Query started with dialog token "
1587 static void interworking_parse_rx_anqp_resp(struct wpa_supplicant
*wpa_s
,
1588 const u8
*sa
, u16 info_id
,
1589 const u8
*data
, size_t slen
)
1591 const u8
*pos
= data
;
1592 struct wpa_bss
*bss
= wpa_bss_get_bssid(wpa_s
, sa
);
1595 #endif /* CONFIG_HS20 */
1598 case ANQP_CAPABILITY_LIST
:
1599 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1600 " ANQP Capability list", MAC2STR(sa
));
1602 case ANQP_VENUE_NAME
:
1603 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1604 " Venue Name", MAC2STR(sa
));
1605 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Venue Name", pos
, slen
);
1607 wpabuf_free(bss
->anqp_venue_name
);
1608 bss
->anqp_venue_name
= wpabuf_alloc_copy(pos
, slen
);
1611 case ANQP_NETWORK_AUTH_TYPE
:
1612 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1613 " Network Authentication Type information",
1615 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Network Authentication "
1618 wpabuf_free(bss
->anqp_network_auth_type
);
1619 bss
->anqp_network_auth_type
=
1620 wpabuf_alloc_copy(pos
, slen
);
1623 case ANQP_ROAMING_CONSORTIUM
:
1624 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1625 " Roaming Consortium list", MAC2STR(sa
));
1626 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: Roaming Consortium",
1629 wpabuf_free(bss
->anqp_roaming_consortium
);
1630 bss
->anqp_roaming_consortium
=
1631 wpabuf_alloc_copy(pos
, slen
);
1634 case ANQP_IP_ADDR_TYPE_AVAILABILITY
:
1635 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1636 " IP Address Type Availability information",
1638 wpa_hexdump(MSG_MSGDUMP
, "ANQP: IP Address Availability",
1641 wpabuf_free(bss
->anqp_ip_addr_type_availability
);
1642 bss
->anqp_ip_addr_type_availability
=
1643 wpabuf_alloc_copy(pos
, slen
);
1646 case ANQP_NAI_REALM
:
1647 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1648 " NAI Realm list", MAC2STR(sa
));
1649 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: NAI Realm", pos
, slen
);
1651 wpabuf_free(bss
->anqp_nai_realm
);
1652 bss
->anqp_nai_realm
= wpabuf_alloc_copy(pos
, slen
);
1655 case ANQP_3GPP_CELLULAR_NETWORK
:
1656 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1657 " 3GPP Cellular Network information", MAC2STR(sa
));
1658 wpa_hexdump_ascii(MSG_DEBUG
, "ANQP: 3GPP Cellular Network",
1661 wpabuf_free(bss
->anqp_3gpp
);
1662 bss
->anqp_3gpp
= wpabuf_alloc_copy(pos
, slen
);
1665 case ANQP_DOMAIN_NAME
:
1666 wpa_msg(wpa_s
, MSG_INFO
, "RX-ANQP " MACSTR
1667 " Domain Name list", MAC2STR(sa
));
1668 wpa_hexdump_ascii(MSG_MSGDUMP
, "ANQP: Domain Name", pos
, slen
);
1670 wpabuf_free(bss
->anqp_domain_name
);
1671 bss
->anqp_domain_name
= wpabuf_alloc_copy(pos
, slen
);
1674 case ANQP_VENDOR_SPECIFIC
:
1678 switch (WPA_GET_BE24(pos
)) {
1690 case HS20_ANQP_OUI_TYPE
:
1691 hs20_parse_rx_hs20_anqp_resp(wpa_s
, sa
, pos
,
1695 wpa_printf(MSG_DEBUG
, "HS20: Unsupported ANQP "
1696 "vendor type %u", type
);
1700 #endif /* CONFIG_HS20 */
1702 wpa_printf(MSG_DEBUG
, "Interworking: Unsupported "
1703 "vendor-specific ANQP OUI %06x",
1709 wpa_printf(MSG_DEBUG
, "Interworking: Unsupported ANQP Info ID "
1716 void anqp_resp_cb(void *ctx
, const u8
*dst
, u8 dialog_token
,
1717 enum gas_query_result result
,
1718 const struct wpabuf
*adv_proto
,
1719 const struct wpabuf
*resp
, u16 status_code
)
1721 struct wpa_supplicant
*wpa_s
= ctx
;
1727 if (result
!= GAS_QUERY_SUCCESS
)
1730 pos
= wpabuf_head(adv_proto
);
1731 if (wpabuf_len(adv_proto
) < 4 || pos
[0] != WLAN_EID_ADV_PROTO
||
1732 pos
[1] < 2 || pos
[3] != ACCESS_NETWORK_QUERY_PROTOCOL
) {
1733 wpa_printf(MSG_DEBUG
, "ANQP: Unexpected Advertisement "
1734 "Protocol in response");
1738 pos
= wpabuf_head(resp
);
1739 end
= pos
+ wpabuf_len(resp
);
1742 if (pos
+ 4 > end
) {
1743 wpa_printf(MSG_DEBUG
, "ANQP: Invalid element");
1746 info_id
= WPA_GET_LE16(pos
);
1748 slen
= WPA_GET_LE16(pos
);
1750 if (pos
+ slen
> end
) {
1751 wpa_printf(MSG_DEBUG
, "ANQP: Invalid element length "
1752 "for Info ID %u", info_id
);
1755 interworking_parse_rx_anqp_resp(wpa_s
, dst
, info_id
, pos
,
1762 static void interworking_scan_res_handler(struct wpa_supplicant
*wpa_s
,
1763 struct wpa_scan_results
*scan_res
)
1765 wpa_printf(MSG_DEBUG
, "Interworking: Scan results available - start "
1767 interworking_start_fetch_anqp(wpa_s
);
1771 int interworking_select(struct wpa_supplicant
*wpa_s
, int auto_select
)
1773 interworking_stop_fetch_anqp(wpa_s
);
1774 wpa_s
->network_select
= 1;
1775 wpa_s
->auto_network_select
= 0;
1776 wpa_s
->auto_select
= !!auto_select
;
1777 wpa_printf(MSG_DEBUG
, "Interworking: Start scan for network "
1779 wpa_s
->scan_res_handler
= interworking_scan_res_handler
;
1780 wpa_s
->scan_req
= 2;
1781 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1787 static void gas_resp_cb(void *ctx
, const u8
*addr
, u8 dialog_token
,
1788 enum gas_query_result result
,
1789 const struct wpabuf
*adv_proto
,
1790 const struct wpabuf
*resp
, u16 status_code
)
1792 struct wpa_supplicant
*wpa_s
= ctx
;
1794 wpa_msg(wpa_s
, MSG_INFO
, GAS_RESPONSE_INFO
"addr=" MACSTR
1795 " dialog_token=%d status_code=%d resp_len=%d",
1796 MAC2STR(addr
), dialog_token
, status_code
,
1797 resp
? (int) wpabuf_len(resp
) : -1);
1801 wpabuf_free(wpa_s
->last_gas_resp
);
1802 wpa_s
->last_gas_resp
= wpabuf_dup(resp
);
1803 if (wpa_s
->last_gas_resp
== NULL
)
1805 os_memcpy(wpa_s
->last_gas_addr
, addr
, ETH_ALEN
);
1806 wpa_s
->last_gas_dialog_token
= dialog_token
;
1810 int gas_send_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1811 const struct wpabuf
*adv_proto
,
1812 const struct wpabuf
*query
)
1817 struct wpa_bss
*bss
;
1820 u8 query_resp_len_limit
= 0, pame_bi
= 0;
1822 freq
= wpa_s
->assoc_freq
;
1823 bss
= wpa_bss_get_bssid(wpa_s
, dst
);
1829 wpa_printf(MSG_DEBUG
, "GAS request to " MACSTR
" (freq %d MHz)",
1830 MAC2STR(dst
), freq
);
1831 wpa_hexdump_buf(MSG_DEBUG
, "Advertisement Protocol ID", adv_proto
);
1832 wpa_hexdump_buf(MSG_DEBUG
, "GAS Query", query
);
1834 len
= 3 + wpabuf_len(adv_proto
) + 2;
1836 len
+= wpabuf_len(query
);
1837 buf
= gas_build_initial_req(0, len
);
1841 /* Advertisement Protocol IE */
1842 wpabuf_put_u8(buf
, WLAN_EID_ADV_PROTO
);
1843 wpabuf_put_u8(buf
, 1 + wpabuf_len(adv_proto
)); /* Length */
1844 wpabuf_put_u8(buf
, (query_resp_len_limit
& 0x7f) |
1845 (pame_bi
? 0x80 : 0));
1846 wpabuf_put_buf(buf
, adv_proto
);
1850 wpabuf_put_le16(buf
, wpabuf_len(query
));
1851 wpabuf_put_buf(buf
, query
);
1853 wpabuf_put_le16(buf
, 0);
1855 res
= gas_query_req(wpa_s
->gas
, dst
, freq
, buf
, gas_resp_cb
, wpa_s
);
1857 wpa_printf(MSG_DEBUG
, "GAS: Failed to send Query Request");
1860 wpa_printf(MSG_DEBUG
, "GAS: Query started with dialog token "