contrib/wpa_supplicant/wpa_supplicant/events.c
int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
			      struct wpa_ssid *ssid)
{
#ifdef IEEE8021X_EAPOL
	int aka = 0, sim = 0, type;

	if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
		return 0;

	if (ssid->eap.eap_methods == NULL) {
		sim = 1;
		aka = 1;
	} else {
		struct eap_method_type *eap = ssid->eap.eap_methods;
		while (eap->vendor != EAP_VENDOR_IETF ||
		       eap->method != EAP_TYPE_NONE) {
			if (eap->vendor == EAP_VENDOR_IETF) {
				if (eap->method == EAP_TYPE_SIM)
					sim = 1;
				else if (eap->method == EAP_TYPE_AKA)
					aka = 1;
			}
			eap++;
		}
	}

	if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
		sim = 0;
	if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
		aka = 0;

	if (!sim && !aka) {
		wpa_printf(MSG_DEBUG, "Selected network is configured to use "
			   "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
		return 0;
	}

	wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
		   "(sim=%d aka=%d) - initialize PCSC", sim, aka);
	if (sim && aka)
		type = SCARD_TRY_BOTH;
	else if (aka)
		type = SCARD_USIM_ONLY;
	else
		type = SCARD_GSM_SIM_ONLY;

	wpa_s->scard = scard_init(type);
	if (wpa_s->scard == NULL) {
		wpa_printf(MSG_WARNING, "Failed to initialize SIM "
			   "(pcsc-lite)");
		return -1;
	}
	wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
	eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
#endif /* IEEE8021X_EAPOL */

	return 0;
}
/**
 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
 * @wpa_s: pointer to wpa_supplicant data
 * @ssid: Configuration data for the network
 * Returns: 0 on success, -1 on failure
 *
 * This function is called when starting authentication with a network that is
 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
 */
Initialize SIM/USIM access with PC/SC
@wpa_s: pointer to wpa_supplicant data
@ssid: Configuration data for the network
Returns: 0 on success, -1 on failure

This function is called when starting authentication with a network that is
configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
Initialize SIM / USIM access with PC / SC @wpa_s : pointer to wpa_supplicant data @ssid : Configuration data for the network Returns : 0 on success - 1 on failure This function is called when starting authentication with a network that is configured to use PC / SC for SIM / USIM access ( EAP - SIM or EAP - AKA ) .
int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
			      struct wpa_ssid *ssid)
{
#ifdef IEEE8021X_EAPOL
	int aka = 0, sim = 0, type;
	if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
		return 0;
	if (ssid->eap.eap_methods == NULL) {
		sim = 1;
		aka = 1;
	} else {
		struct eap_method_type *eap = ssid->eap.eap_methods;
		while (eap->vendor != EAP_VENDOR_IETF ||
		       eap->method != EAP_TYPE_NONE) {
			if (eap->vendor == EAP_VENDOR_IETF) {
				if (eap->method == EAP_TYPE_SIM)
					sim = 1;
				else if (eap->method == EAP_TYPE_AKA)
					aka = 1;
			}
			eap++;
		}
	}
	if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
		sim = 0;
	if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
		aka = 0;
	if (!sim && !aka) {
		wpa_printf(MSG_DEBUG, "Selected network is configured to use "
			   "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
		return 0;
	}
	wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
		   "(sim=%d aka=%d) - initialize PCSC", sim, aka);
	if (sim && aka)
		type = SCARD_TRY_BOTH;
	else if (aka)
		type = SCARD_USIM_ONLY;
	else
		type = SCARD_GSM_SIM_ONLY;
	wpa_s->scard = scard_init(type);
	if (wpa_s->scard == NULL) {
		wpa_printf(MSG_WARNING, "Failed to initialize SIM "
			   "(pcsc-lite)");
		return -1;
	}
	wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
	eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
#endif 
	return 0;
}
int wpa_supplicant_scard_init ( struct wpa_supplicant * wpa_s , struct wpa_ssid * ssid ) { #ifdef IEEE8021X_EAPOL int aka = 0 , sim = 0 , type ; if ( ssid -> eap . pcsc == NULL || wpa_s -> scard != NULL ) return 0 ; if ( ssid -> eap . eap_methods == NULL ) { sim = 1 ; aka = 1 ; } else { struct eap_method_type * eap = ssid -> eap . eap_methods ; while ( eap -> vendor != EAP_VENDOR_IETF || eap -> method != EAP_TYPE_NONE ) { if ( eap -> vendor == EAP_VENDOR_IETF ) { if ( eap -> method == EAP_TYPE_SIM ) sim = 1 ; else if ( eap -> method == EAP_TYPE_AKA ) aka = 1 ; } eap ++ ; } } if ( eap_peer_get_eap_method ( EAP_VENDOR_IETF , EAP_TYPE_SIM ) == NULL ) sim = 0 ; if ( eap_peer_get_eap_method ( EAP_VENDOR_IETF , EAP_TYPE_AKA ) == NULL ) aka = 0 ; if ( ! sim && ! aka ) { wpa_printf ( MSG_DEBUG , " " " " ) ; return 0 ; } wpa_printf ( MSG_DEBUG , " " " " , sim , aka ) ; if ( sim && aka ) type = SCARD_TRY_BOTH ; else if ( aka ) type = SCARD_USIM_ONLY ; else type = SCARD_GSM_SIM_ONLY ; wpa_s -> scard = scard_init ( type ) ; if ( wpa_s -> scard == NULL ) { wpa_printf ( MSG_WARNING , " " " " ) ; return -1 ; } wpa_sm_set_scard_ctx ( wpa_s -> wpa , wpa_s -> scard ) ; eapol_sm_register_scard_ctx ( wpa_s -> eapol , wpa_s -> scard ) ; #endif return 0 ; }
wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
 @wpa_s: pointer to wpa_supplicant data
 @ssid: Configuration data for the network
 Returns: 0 on success, -1 on failure
wpa_supplicant_scard_init - Initialize SIM / USIM access with PC / SC @wpa_s : pointer to wpa_supplicant data @ssid : Configuration data for the network Returns : 0 on success - 1 on failure
/* IEEE8021X_EAPOL */