Home | History | Annotate | Line # | Download | only in wpa_supplicant
wpas_glue.c revision 1.1.1.2.12.1
      1           1.1  christos /*
      2           1.1  christos  * WPA Supplicant - Glue code to setup EAPOL and RSN modules
      3  1.1.1.2.12.1       snj  * Copyright (c) 2003-2015, Jouni Malinen <j (at) w1.fi>
      4           1.1  christos  *
      5  1.1.1.2.12.1       snj  * This software may be distributed under the terms of the BSD license.
      6  1.1.1.2.12.1       snj  * See README for more details.
      7           1.1  christos  */
      8           1.1  christos 
      9           1.1  christos #include "includes.h"
     10           1.1  christos 
     11           1.1  christos #include "common.h"
     12           1.1  christos #include "eapol_supp/eapol_supp_sm.h"
     13           1.1  christos #include "rsn_supp/wpa.h"
     14           1.1  christos #include "eloop.h"
     15           1.1  christos #include "config.h"
     16           1.1  christos #include "l2_packet/l2_packet.h"
     17           1.1  christos #include "common/wpa_common.h"
     18           1.1  christos #include "wpa_supplicant_i.h"
     19           1.1  christos #include "driver_i.h"
     20           1.1  christos #include "rsn_supp/pmksa_cache.h"
     21           1.1  christos #include "sme.h"
     22           1.1  christos #include "common/ieee802_11_defs.h"
     23           1.1  christos #include "common/wpa_ctrl.h"
     24           1.1  christos #include "wpas_glue.h"
     25           1.1  christos #include "wps_supplicant.h"
     26           1.1  christos #include "bss.h"
     27           1.1  christos #include "scan.h"
     28  1.1.1.2.12.1       snj #include "notify.h"
     29  1.1.1.2.12.1       snj #include "wpas_kay.h"
     30           1.1  christos 
     31           1.1  christos 
     32           1.1  christos #ifndef CONFIG_NO_CONFIG_BLOBS
     33           1.1  christos #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
     34           1.1  christos static void wpa_supplicant_set_config_blob(void *ctx,
     35           1.1  christos 					   struct wpa_config_blob *blob)
     36           1.1  christos {
     37           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
     38           1.1  christos 	wpa_config_set_blob(wpa_s->conf, blob);
     39           1.1  christos 	if (wpa_s->conf->update_config) {
     40           1.1  christos 		int ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
     41           1.1  christos 		if (ret) {
     42           1.1  christos 			wpa_printf(MSG_DEBUG, "Failed to update config after "
     43           1.1  christos 				   "blob set");
     44           1.1  christos 		}
     45           1.1  christos 	}
     46           1.1  christos }
     47           1.1  christos 
     48           1.1  christos 
     49           1.1  christos static const struct wpa_config_blob *
     50           1.1  christos wpa_supplicant_get_config_blob(void *ctx, const char *name)
     51           1.1  christos {
     52           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
     53           1.1  christos 	return wpa_config_get_blob(wpa_s->conf, name);
     54           1.1  christos }
     55           1.1  christos #endif /* defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) */
     56           1.1  christos #endif /* CONFIG_NO_CONFIG_BLOBS */
     57           1.1  christos 
     58           1.1  christos 
     59           1.1  christos #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
     60           1.1  christos static u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, u8 type,
     61           1.1  christos 			    const void *data, u16 data_len,
     62           1.1  christos 			    size_t *msg_len, void **data_pos)
     63           1.1  christos {
     64           1.1  christos 	struct ieee802_1x_hdr *hdr;
     65           1.1  christos 
     66           1.1  christos 	*msg_len = sizeof(*hdr) + data_len;
     67           1.1  christos 	hdr = os_malloc(*msg_len);
     68           1.1  christos 	if (hdr == NULL)
     69           1.1  christos 		return NULL;
     70           1.1  christos 
     71           1.1  christos 	hdr->version = wpa_s->conf->eapol_version;
     72           1.1  christos 	hdr->type = type;
     73           1.1  christos 	hdr->length = host_to_be16(data_len);
     74           1.1  christos 
     75           1.1  christos 	if (data)
     76           1.1  christos 		os_memcpy(hdr + 1, data, data_len);
     77           1.1  christos 	else
     78           1.1  christos 		os_memset(hdr + 1, 0, data_len);
     79           1.1  christos 
     80           1.1  christos 	if (data_pos)
     81           1.1  christos 		*data_pos = hdr + 1;
     82           1.1  christos 
     83           1.1  christos 	return (u8 *) hdr;
     84           1.1  christos }
     85           1.1  christos 
     86           1.1  christos 
     87           1.1  christos /**
     88           1.1  christos  * wpa_ether_send - Send Ethernet frame
     89           1.1  christos  * @wpa_s: Pointer to wpa_supplicant data
     90           1.1  christos  * @dest: Destination MAC address
     91           1.1  christos  * @proto: Ethertype in host byte order
     92           1.1  christos  * @buf: Frame payload starting from IEEE 802.1X header
     93           1.1  christos  * @len: Frame payload length
     94           1.1  christos  * Returns: >=0 on success, <0 on failure
     95           1.1  christos  */
     96           1.1  christos static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
     97           1.1  christos 			  u16 proto, const u8 *buf, size_t len)
     98           1.1  christos {
     99  1.1.1.2.12.1       snj #ifdef CONFIG_TESTING_OPTIONS
    100  1.1.1.2.12.1       snj 	if (wpa_s->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
    101  1.1.1.2.12.1       snj 		size_t hex_len = 2 * len + 1;
    102  1.1.1.2.12.1       snj 		char *hex = os_malloc(hex_len);
    103  1.1.1.2.12.1       snj 
    104  1.1.1.2.12.1       snj 		if (hex == NULL)
    105  1.1.1.2.12.1       snj 			return -1;
    106  1.1.1.2.12.1       snj 		wpa_snprintf_hex(hex, hex_len, buf, len);
    107  1.1.1.2.12.1       snj 		wpa_msg(wpa_s, MSG_INFO, "EAPOL-TX " MACSTR " %s",
    108  1.1.1.2.12.1       snj 			MAC2STR(dest), hex);
    109  1.1.1.2.12.1       snj 		os_free(hex);
    110  1.1.1.2.12.1       snj 		return 0;
    111  1.1.1.2.12.1       snj 	}
    112  1.1.1.2.12.1       snj #endif /* CONFIG_TESTING_OPTIONS */
    113  1.1.1.2.12.1       snj 
    114           1.1  christos 	if (wpa_s->l2) {
    115           1.1  christos 		return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
    116           1.1  christos 	}
    117           1.1  christos 
    118  1.1.1.2.12.1       snj 	return -1;
    119           1.1  christos }
    120           1.1  christos #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */
    121           1.1  christos 
    122           1.1  christos 
    123           1.1  christos #ifdef IEEE8021X_EAPOL
    124           1.1  christos 
    125           1.1  christos /**
    126           1.1  christos  * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator
    127           1.1  christos  * @ctx: Pointer to wpa_supplicant data (wpa_s)
    128           1.1  christos  * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*)
    129           1.1  christos  * @buf: EAPOL payload (after IEEE 802.1X header)
    130           1.1  christos  * @len: EAPOL payload length
    131           1.1  christos  * Returns: >=0 on success, <0 on failure
    132           1.1  christos  *
    133           1.1  christos  * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
    134           1.1  christos  * to the current Authenticator.
    135           1.1  christos  */
    136           1.1  christos static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf,
    137           1.1  christos 				     size_t len)
    138           1.1  christos {
    139           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    140           1.1  christos 	u8 *msg, *dst, bssid[ETH_ALEN];
    141           1.1  christos 	size_t msglen;
    142           1.1  christos 	int res;
    143           1.1  christos 
    144           1.1  christos 	/* TODO: could add l2_packet_sendmsg that allows fragments to avoid
    145           1.1  christos 	 * extra copy here */
    146           1.1  christos 
    147           1.1  christos 	if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
    148           1.1  christos 	    wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
    149           1.1  christos 		/* Current SSID is not using IEEE 802.1X/EAP, so drop possible
    150           1.1  christos 		 * EAPOL frames (mainly, EAPOL-Start) from EAPOL state
    151           1.1  christos 		 * machines. */
    152           1.1  christos 		wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X "
    153           1.1  christos 			   "mode (type=%d len=%lu)", type,
    154           1.1  christos 			   (unsigned long) len);
    155           1.1  christos 		return -1;
    156           1.1  christos 	}
    157           1.1  christos 
    158           1.1  christos 	if (pmksa_cache_get_current(wpa_s->wpa) &&
    159           1.1  christos 	    type == IEEE802_1X_TYPE_EAPOL_START) {
    160  1.1.1.2.12.1       snj 		/*
    161  1.1.1.2.12.1       snj 		 * We were trying to use PMKSA caching and sending EAPOL-Start
    162  1.1.1.2.12.1       snj 		 * would abort that and trigger full EAPOL authentication.
    163  1.1.1.2.12.1       snj 		 * However, we've already waited for the AP/Authenticator to
    164  1.1.1.2.12.1       snj 		 * start 4-way handshake or EAP authentication, and apparently
    165  1.1.1.2.12.1       snj 		 * it has not done so since the startWhen timer has reached zero
    166  1.1.1.2.12.1       snj 		 * to get the state machine sending EAPOL-Start. This is not
    167  1.1.1.2.12.1       snj 		 * really supposed to happen, but an interoperability issue with
    168  1.1.1.2.12.1       snj 		 * a deployed AP has been identified where the connection fails
    169  1.1.1.2.12.1       snj 		 * due to that AP failing to operate correctly if PMKID is
    170  1.1.1.2.12.1       snj 		 * included in the Association Request frame. To work around
    171  1.1.1.2.12.1       snj 		 * this, assume PMKSA caching failed and try to initiate full
    172  1.1.1.2.12.1       snj 		 * EAP authentication.
    173  1.1.1.2.12.1       snj 		 */
    174  1.1.1.2.12.1       snj 		if (!wpa_s->current_ssid ||
    175  1.1.1.2.12.1       snj 		    wpa_s->current_ssid->eap_workaround) {
    176  1.1.1.2.12.1       snj 			wpa_printf(MSG_DEBUG,
    177  1.1.1.2.12.1       snj 				   "RSN: Timeout on waiting for the AP to initiate 4-way handshake for PMKSA caching or EAP authentication - try to force it to start EAP authentication");
    178  1.1.1.2.12.1       snj 		} else {
    179  1.1.1.2.12.1       snj 			wpa_printf(MSG_DEBUG,
    180  1.1.1.2.12.1       snj 				   "RSN: PMKSA caching - do not send EAPOL-Start");
    181  1.1.1.2.12.1       snj 			return -1;
    182  1.1.1.2.12.1       snj 		}
    183           1.1  christos 	}
    184           1.1  christos 
    185           1.1  christos 	if (is_zero_ether_addr(wpa_s->bssid)) {
    186           1.1  christos 		wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
    187           1.1  christos 			   "EAPOL frame");
    188           1.1  christos 		if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
    189           1.1  christos 		    !is_zero_ether_addr(bssid)) {
    190           1.1  christos 			dst = bssid;
    191           1.1  christos 			wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
    192           1.1  christos 				   " from the driver as the EAPOL destination",
    193           1.1  christos 				   MAC2STR(dst));
    194           1.1  christos 		} else {
    195           1.1  christos 			dst = wpa_s->last_eapol_src;
    196           1.1  christos 			wpa_printf(MSG_DEBUG, "Using the source address of the"
    197           1.1  christos 				   " last received EAPOL frame " MACSTR " as "
    198           1.1  christos 				   "the EAPOL destination",
    199           1.1  christos 				   MAC2STR(dst));
    200           1.1  christos 		}
    201           1.1  christos 	} else {
    202           1.1  christos 		/* BSSID was already set (from (Re)Assoc event, so use it as
    203           1.1  christos 		 * the EAPOL destination. */
    204           1.1  christos 		dst = wpa_s->bssid;
    205           1.1  christos 	}
    206           1.1  christos 
    207           1.1  christos 	msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL);
    208           1.1  christos 	if (msg == NULL)
    209           1.1  christos 		return -1;
    210           1.1  christos 
    211           1.1  christos 	wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst));
    212           1.1  christos 	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
    213           1.1  christos 	res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen);
    214           1.1  christos 	os_free(msg);
    215           1.1  christos 	return res;
    216           1.1  christos }
    217           1.1  christos 
    218           1.1  christos 
    219           1.1  christos /**
    220           1.1  christos  * wpa_eapol_set_wep_key - set WEP key for the driver
    221           1.1  christos  * @ctx: Pointer to wpa_supplicant data (wpa_s)
    222           1.1  christos  * @unicast: 1 = individual unicast key, 0 = broadcast key
    223           1.1  christos  * @keyidx: WEP key index (0..3)
    224           1.1  christos  * @key: Pointer to key data
    225           1.1  christos  * @keylen: Key length in bytes
    226           1.1  christos  * Returns: 0 on success or < 0 on error.
    227           1.1  christos  */
    228           1.1  christos static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx,
    229           1.1  christos 				 const u8 *key, size_t keylen)
    230           1.1  christos {
    231           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    232           1.1  christos 	if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
    233           1.1  christos 		int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 :
    234           1.1  christos 			WPA_CIPHER_WEP104;
    235           1.1  christos 		if (unicast)
    236           1.1  christos 			wpa_s->pairwise_cipher = cipher;
    237           1.1  christos 		else
    238           1.1  christos 			wpa_s->group_cipher = cipher;
    239           1.1  christos 	}
    240           1.1  christos 	return wpa_drv_set_key(wpa_s, WPA_ALG_WEP,
    241  1.1.1.2.12.1       snj 			       unicast ? wpa_s->bssid : NULL,
    242  1.1.1.2.12.1       snj 			       keyidx, unicast, NULL, 0, key, keylen);
    243           1.1  christos }
    244           1.1  christos 
    245           1.1  christos 
    246           1.1  christos static void wpa_supplicant_aborted_cached(void *ctx)
    247           1.1  christos {
    248           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    249           1.1  christos 	wpa_sm_aborted_cached(wpa_s->wpa);
    250           1.1  christos }
    251           1.1  christos 
    252           1.1  christos 
    253  1.1.1.2.12.1       snj static const char * result_str(enum eapol_supp_result result)
    254  1.1.1.2.12.1       snj {
    255  1.1.1.2.12.1       snj 	switch (result) {
    256  1.1.1.2.12.1       snj 	case EAPOL_SUPP_RESULT_FAILURE:
    257  1.1.1.2.12.1       snj 		return "FAILURE";
    258  1.1.1.2.12.1       snj 	case EAPOL_SUPP_RESULT_SUCCESS:
    259  1.1.1.2.12.1       snj 		return "SUCCESS";
    260  1.1.1.2.12.1       snj 	case EAPOL_SUPP_RESULT_EXPECTED_FAILURE:
    261  1.1.1.2.12.1       snj 		return "EXPECTED_FAILURE";
    262  1.1.1.2.12.1       snj 	}
    263  1.1.1.2.12.1       snj 	return "?";
    264  1.1.1.2.12.1       snj }
    265  1.1.1.2.12.1       snj 
    266  1.1.1.2.12.1       snj 
    267  1.1.1.2.12.1       snj static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol,
    268  1.1.1.2.12.1       snj 				    enum eapol_supp_result result,
    269           1.1  christos 				    void *ctx)
    270           1.1  christos {
    271           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    272           1.1  christos 	int res, pmk_len;
    273           1.1  christos 	u8 pmk[PMK_LEN];
    274           1.1  christos 
    275  1.1.1.2.12.1       snj 	wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s",
    276  1.1.1.2.12.1       snj 		   result_str(result));
    277           1.1  christos 
    278           1.1  christos 	if (wpas_wps_eapol_cb(wpa_s) > 0)
    279           1.1  christos 		return;
    280           1.1  christos 
    281  1.1.1.2.12.1       snj 	wpa_s->eap_expected_failure = result ==
    282  1.1.1.2.12.1       snj 		EAPOL_SUPP_RESULT_EXPECTED_FAILURE;
    283  1.1.1.2.12.1       snj 
    284  1.1.1.2.12.1       snj 	if (result != EAPOL_SUPP_RESULT_SUCCESS) {
    285           1.1  christos 		/*
    286           1.1  christos 		 * Make sure we do not get stuck here waiting for long EAPOL
    287           1.1  christos 		 * timeout if the AP does not disconnect in case of
    288           1.1  christos 		 * authentication failure.
    289           1.1  christos 		 */
    290           1.1  christos 		wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
    291  1.1.1.2.12.1       snj 	} else {
    292  1.1.1.2.12.1       snj 		ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src);
    293           1.1  christos 	}
    294           1.1  christos 
    295  1.1.1.2.12.1       snj 	if (result != EAPOL_SUPP_RESULT_SUCCESS ||
    296  1.1.1.2.12.1       snj 	    !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
    297           1.1  christos 		return;
    298           1.1  christos 
    299           1.1  christos 	if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
    300           1.1  christos 		return;
    301           1.1  christos 
    302           1.1  christos 	wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
    303           1.1  christos 		   "handshake");
    304           1.1  christos 
    305           1.1  christos 	pmk_len = PMK_LEN;
    306  1.1.1.2.12.1       snj 	if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
    307  1.1.1.2.12.1       snj #ifdef CONFIG_IEEE80211R
    308  1.1.1.2.12.1       snj 		u8 buf[2 * PMK_LEN];
    309  1.1.1.2.12.1       snj 		wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for "
    310  1.1.1.2.12.1       snj 			   "driver-based 4-way hs and FT");
    311  1.1.1.2.12.1       snj 		res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN);
    312  1.1.1.2.12.1       snj 		if (res == 0) {
    313  1.1.1.2.12.1       snj 			os_memcpy(pmk, buf + PMK_LEN, PMK_LEN);
    314  1.1.1.2.12.1       snj 			os_memset(buf, 0, sizeof(buf));
    315  1.1.1.2.12.1       snj 		}
    316  1.1.1.2.12.1       snj #else /* CONFIG_IEEE80211R */
    317  1.1.1.2.12.1       snj 		res = -1;
    318  1.1.1.2.12.1       snj #endif /* CONFIG_IEEE80211R */
    319  1.1.1.2.12.1       snj 	} else {
    320  1.1.1.2.12.1       snj 		res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
    321  1.1.1.2.12.1       snj 		if (res) {
    322  1.1.1.2.12.1       snj 			/*
    323  1.1.1.2.12.1       snj 			 * EAP-LEAP is an exception from other EAP methods: it
    324  1.1.1.2.12.1       snj 			 * uses only 16-byte PMK.
    325  1.1.1.2.12.1       snj 			 */
    326  1.1.1.2.12.1       snj 			res = eapol_sm_get_key(eapol, pmk, 16);
    327  1.1.1.2.12.1       snj 			pmk_len = 16;
    328  1.1.1.2.12.1       snj 		}
    329           1.1  christos 	}
    330           1.1  christos 
    331           1.1  christos 	if (res) {
    332           1.1  christos 		wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
    333           1.1  christos 			   "machines");
    334           1.1  christos 		return;
    335           1.1  christos 	}
    336           1.1  christos 
    337  1.1.1.2.12.1       snj 	wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way "
    338  1.1.1.2.12.1       snj 			"handshake", pmk, pmk_len);
    339  1.1.1.2.12.1       snj 
    340           1.1  christos 	if (wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, NULL, 0, pmk,
    341           1.1  christos 			    pmk_len)) {
    342           1.1  christos 		wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
    343           1.1  christos 	}
    344           1.1  christos 
    345           1.1  christos 	wpa_supplicant_cancel_scan(wpa_s);
    346           1.1  christos 	wpa_supplicant_cancel_auth_timeout(wpa_s);
    347           1.1  christos 	wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    348           1.1  christos 
    349           1.1  christos }
    350           1.1  christos 
    351           1.1  christos 
    352           1.1  christos static void wpa_supplicant_notify_eapol_done(void *ctx)
    353           1.1  christos {
    354           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    355           1.1  christos 	wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
    356           1.1  christos 	if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
    357           1.1  christos 		wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
    358           1.1  christos 	} else {
    359           1.1  christos 		wpa_supplicant_cancel_auth_timeout(wpa_s);
    360           1.1  christos 		wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    361           1.1  christos 	}
    362           1.1  christos }
    363           1.1  christos 
    364           1.1  christos #endif /* IEEE8021X_EAPOL */
    365           1.1  christos 
    366           1.1  christos 
    367           1.1  christos #ifndef CONFIG_NO_WPA
    368           1.1  christos 
    369           1.1  christos static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
    370           1.1  christos {
    371           1.1  christos 	int ret = 0;
    372           1.1  christos 	struct wpa_bss *curr = NULL, *bss;
    373           1.1  christos 	struct wpa_ssid *ssid = wpa_s->current_ssid;
    374           1.1  christos 	const u8 *ie;
    375           1.1  christos 
    376           1.1  christos 	dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
    377           1.1  christos 		if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
    378           1.1  christos 			continue;
    379           1.1  christos 		if (ssid == NULL ||
    380           1.1  christos 		    ((bss->ssid_len == ssid->ssid_len &&
    381           1.1  christos 		      os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
    382           1.1  christos 		     ssid->ssid_len == 0)) {
    383           1.1  christos 			curr = bss;
    384           1.1  christos 			break;
    385           1.1  christos 		}
    386           1.1  christos 	}
    387           1.1  christos 
    388           1.1  christos 	if (curr) {
    389           1.1  christos 		ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
    390           1.1  christos 		if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
    391           1.1  christos 			ret = -1;
    392           1.1  christos 
    393           1.1  christos 		ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
    394           1.1  christos 		if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
    395           1.1  christos 			ret = -1;
    396           1.1  christos 	} else {
    397           1.1  christos 		ret = -1;
    398           1.1  christos 	}
    399           1.1  christos 
    400           1.1  christos 	return ret;
    401           1.1  christos }
    402           1.1  christos 
    403           1.1  christos 
    404           1.1  christos static int wpa_supplicant_get_beacon_ie(void *ctx)
    405           1.1  christos {
    406           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    407           1.1  christos 	if (wpa_get_beacon_ie(wpa_s) == 0) {
    408           1.1  christos 		return 0;
    409           1.1  christos 	}
    410           1.1  christos 
    411           1.1  christos 	/* No WPA/RSN IE found in the cached scan results. Try to get updated
    412           1.1  christos 	 * scan results from the driver. */
    413           1.1  christos 	if (wpa_supplicant_update_scan_results(wpa_s) < 0)
    414           1.1  christos 		return -1;
    415           1.1  christos 
    416           1.1  christos 	return wpa_get_beacon_ie(wpa_s);
    417           1.1  christos }
    418           1.1  christos 
    419           1.1  christos 
    420           1.1  christos static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
    421           1.1  christos 			     const void *data, u16 data_len,
    422           1.1  christos 			     size_t *msg_len, void **data_pos)
    423           1.1  christos {
    424           1.1  christos 	return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
    425           1.1  christos }
    426           1.1  christos 
    427           1.1  christos 
    428           1.1  christos static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
    429           1.1  christos 			   const u8 *buf, size_t len)
    430           1.1  christos {
    431           1.1  christos 	return wpa_ether_send(wpa_s, dest, proto, buf, len);
    432           1.1  christos }
    433           1.1  christos 
    434           1.1  christos 
    435           1.1  christos static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
    436           1.1  christos {
    437           1.1  christos 	wpa_supplicant_cancel_auth_timeout(wpa_s);
    438           1.1  christos }
    439           1.1  christos 
    440           1.1  christos 
    441           1.1  christos static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
    442           1.1  christos {
    443           1.1  christos 	wpa_supplicant_set_state(wpa_s, state);
    444           1.1  christos }
    445           1.1  christos 
    446           1.1  christos 
    447           1.1  christos /**
    448           1.1  christos  * wpa_supplicant_get_state - Get the connection state
    449           1.1  christos  * @wpa_s: Pointer to wpa_supplicant data
    450           1.1  christos  * Returns: The current connection state (WPA_*)
    451           1.1  christos  */
    452           1.1  christos static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
    453           1.1  christos {
    454           1.1  christos 	return wpa_s->wpa_state;
    455           1.1  christos }
    456           1.1  christos 
    457           1.1  christos 
    458           1.1  christos static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
    459           1.1  christos {
    460           1.1  christos 	return wpa_supplicant_get_state(wpa_s);
    461           1.1  christos }
    462           1.1  christos 
    463           1.1  christos 
    464           1.1  christos static void _wpa_supplicant_deauthenticate(void *wpa_s, int reason_code)
    465           1.1  christos {
    466           1.1  christos 	wpa_supplicant_deauthenticate(wpa_s, reason_code);
    467           1.1  christos 	/* Schedule a scan to make sure we continue looking for networks */
    468           1.1  christos 	wpa_supplicant_req_scan(wpa_s, 5, 0);
    469           1.1  christos }
    470           1.1  christos 
    471           1.1  christos 
    472           1.1  christos static void * wpa_supplicant_get_network_ctx(void *wpa_s)
    473           1.1  christos {
    474           1.1  christos 	return wpa_supplicant_get_ssid(wpa_s);
    475           1.1  christos }
    476           1.1  christos 
    477           1.1  christos 
    478           1.1  christos static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
    479           1.1  christos {
    480           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    481           1.1  christos 	return wpa_drv_get_bssid(wpa_s, bssid);
    482           1.1  christos }
    483           1.1  christos 
    484           1.1  christos 
    485           1.1  christos static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
    486           1.1  christos 				  const u8 *addr, int key_idx, int set_tx,
    487           1.1  christos 				  const u8 *seq, size_t seq_len,
    488           1.1  christos 				  const u8 *key, size_t key_len)
    489           1.1  christos {
    490           1.1  christos 	struct wpa_supplicant *wpa_s = _wpa_s;
    491           1.1  christos 	if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
    492           1.1  christos 		/* Clear the MIC error counter when setting a new PTK. */
    493           1.1  christos 		wpa_s->mic_errors_seen = 0;
    494           1.1  christos 	}
    495  1.1.1.2.12.1       snj #ifdef CONFIG_TESTING_GET_GTK
    496  1.1.1.2.12.1       snj 	if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
    497  1.1.1.2.12.1       snj 	    alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
    498  1.1.1.2.12.1       snj 		os_memcpy(wpa_s->last_gtk, key, key_len);
    499  1.1.1.2.12.1       snj 		wpa_s->last_gtk_len = key_len;
    500  1.1.1.2.12.1       snj 	}
    501  1.1.1.2.12.1       snj #endif /* CONFIG_TESTING_GET_GTK */
    502           1.1  christos 	return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
    503           1.1  christos 			       key, key_len);
    504           1.1  christos }
    505           1.1  christos 
    506           1.1  christos 
    507           1.1  christos static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
    508           1.1  christos 					     int protection_type,
    509           1.1  christos 					     int key_type)
    510           1.1  christos {
    511           1.1  christos 	return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
    512           1.1  christos 					  key_type);
    513           1.1  christos }
    514           1.1  christos 
    515           1.1  christos 
    516           1.1  christos static int wpa_supplicant_add_pmkid(void *wpa_s,
    517           1.1  christos 				    const u8 *bssid, const u8 *pmkid)
    518           1.1  christos {
    519           1.1  christos 	return wpa_drv_add_pmkid(wpa_s, bssid, pmkid);
    520           1.1  christos }
    521           1.1  christos 
    522           1.1  christos 
    523           1.1  christos static int wpa_supplicant_remove_pmkid(void *wpa_s,
    524           1.1  christos 				       const u8 *bssid, const u8 *pmkid)
    525           1.1  christos {
    526           1.1  christos 	return wpa_drv_remove_pmkid(wpa_s, bssid, pmkid);
    527           1.1  christos }
    528           1.1  christos 
    529           1.1  christos 
    530           1.1  christos #ifdef CONFIG_IEEE80211R
    531           1.1  christos static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
    532           1.1  christos 					const u8 *ies, size_t ies_len)
    533           1.1  christos {
    534           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    535           1.1  christos 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
    536           1.1  christos 		return sme_update_ft_ies(wpa_s, md, ies, ies_len);
    537           1.1  christos 	return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
    538           1.1  christos }
    539           1.1  christos 
    540           1.1  christos 
    541           1.1  christos static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
    542           1.1  christos 					 const u8 *target_ap,
    543           1.1  christos 					 const u8 *ies, size_t ies_len)
    544           1.1  christos {
    545           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    546  1.1.1.2.12.1       snj 	int ret;
    547  1.1.1.2.12.1       snj 	u8 *data, *pos;
    548  1.1.1.2.12.1       snj 	size_t data_len;
    549  1.1.1.2.12.1       snj 
    550  1.1.1.2.12.1       snj 	if (action != 1) {
    551  1.1.1.2.12.1       snj 		wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
    552  1.1.1.2.12.1       snj 			   action);
    553  1.1.1.2.12.1       snj 		return -1;
    554  1.1.1.2.12.1       snj 	}
    555  1.1.1.2.12.1       snj 
    556  1.1.1.2.12.1       snj 	/*
    557  1.1.1.2.12.1       snj 	 * Action frame payload:
    558  1.1.1.2.12.1       snj 	 * Category[1] = 6 (Fast BSS Transition)
    559  1.1.1.2.12.1       snj 	 * Action[1] = 1 (Fast BSS Transition Request)
    560  1.1.1.2.12.1       snj 	 * STA Address
    561  1.1.1.2.12.1       snj 	 * Target AP Address
    562  1.1.1.2.12.1       snj 	 * FT IEs
    563  1.1.1.2.12.1       snj 	 */
    564  1.1.1.2.12.1       snj 
    565  1.1.1.2.12.1       snj 	data_len = 2 + 2 * ETH_ALEN + ies_len;
    566  1.1.1.2.12.1       snj 	data = os_malloc(data_len);
    567  1.1.1.2.12.1       snj 	if (data == NULL)
    568  1.1.1.2.12.1       snj 		return -1;
    569  1.1.1.2.12.1       snj 	pos = data;
    570  1.1.1.2.12.1       snj 	*pos++ = 0x06; /* FT Action category */
    571  1.1.1.2.12.1       snj 	*pos++ = action;
    572  1.1.1.2.12.1       snj 	os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
    573  1.1.1.2.12.1       snj 	pos += ETH_ALEN;
    574  1.1.1.2.12.1       snj 	os_memcpy(pos, target_ap, ETH_ALEN);
    575  1.1.1.2.12.1       snj 	pos += ETH_ALEN;
    576  1.1.1.2.12.1       snj 	os_memcpy(pos, ies, ies_len);
    577  1.1.1.2.12.1       snj 
    578  1.1.1.2.12.1       snj 	ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
    579  1.1.1.2.12.1       snj 				  wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
    580  1.1.1.2.12.1       snj 				  data, data_len, 0);
    581  1.1.1.2.12.1       snj 	os_free(data);
    582  1.1.1.2.12.1       snj 
    583  1.1.1.2.12.1       snj 	return ret;
    584           1.1  christos }
    585           1.1  christos 
    586           1.1  christos 
    587           1.1  christos static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
    588           1.1  christos {
    589           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    590           1.1  christos 	struct wpa_driver_auth_params params;
    591           1.1  christos 	struct wpa_bss *bss;
    592           1.1  christos 
    593           1.1  christos 	bss = wpa_bss_get_bssid(wpa_s, target_ap);
    594           1.1  christos 	if (bss == NULL)
    595           1.1  christos 		return -1;
    596           1.1  christos 
    597           1.1  christos 	os_memset(&params, 0, sizeof(params));
    598           1.1  christos 	params.bssid = target_ap;
    599           1.1  christos 	params.freq = bss->freq;
    600           1.1  christos 	params.ssid = bss->ssid;
    601           1.1  christos 	params.ssid_len = bss->ssid_len;
    602           1.1  christos 	params.auth_alg = WPA_AUTH_ALG_FT;
    603           1.1  christos 	params.local_state_change = 1;
    604           1.1  christos 	return wpa_drv_authenticate(wpa_s, &params);
    605           1.1  christos }
    606           1.1  christos #endif /* CONFIG_IEEE80211R */
    607           1.1  christos 
    608           1.1  christos 
    609  1.1.1.2.12.1       snj #ifdef CONFIG_TDLS
    610           1.1  christos 
    611  1.1.1.2.12.1       snj static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
    612  1.1.1.2.12.1       snj 					int *tdls_ext_setup,
    613  1.1.1.2.12.1       snj 					int *tdls_chan_switch)
    614           1.1  christos {
    615           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    616  1.1.1.2.12.1       snj 
    617  1.1.1.2.12.1       snj 	*tdls_supported = 0;
    618  1.1.1.2.12.1       snj 	*tdls_ext_setup = 0;
    619  1.1.1.2.12.1       snj 	*tdls_chan_switch = 0;
    620  1.1.1.2.12.1       snj 
    621  1.1.1.2.12.1       snj 	if (!wpa_s->drv_capa_known)
    622  1.1.1.2.12.1       snj 		return -1;
    623  1.1.1.2.12.1       snj 
    624  1.1.1.2.12.1       snj 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
    625  1.1.1.2.12.1       snj 		*tdls_supported = 1;
    626  1.1.1.2.12.1       snj 
    627  1.1.1.2.12.1       snj 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
    628  1.1.1.2.12.1       snj 		*tdls_ext_setup = 1;
    629  1.1.1.2.12.1       snj 
    630  1.1.1.2.12.1       snj 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
    631  1.1.1.2.12.1       snj 		*tdls_chan_switch = 1;
    632  1.1.1.2.12.1       snj 
    633  1.1.1.2.12.1       snj 	return 0;
    634  1.1.1.2.12.1       snj }
    635  1.1.1.2.12.1       snj 
    636  1.1.1.2.12.1       snj 
    637  1.1.1.2.12.1       snj static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
    638  1.1.1.2.12.1       snj 					 u8 action_code, u8 dialog_token,
    639  1.1.1.2.12.1       snj 					 u16 status_code, u32 peer_capab,
    640  1.1.1.2.12.1       snj 					 int initiator, const u8 *buf,
    641  1.1.1.2.12.1       snj 					 size_t len)
    642  1.1.1.2.12.1       snj {
    643  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    644  1.1.1.2.12.1       snj 	return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
    645  1.1.1.2.12.1       snj 				      status_code, peer_capab, initiator, buf,
    646  1.1.1.2.12.1       snj 				      len);
    647  1.1.1.2.12.1       snj }
    648  1.1.1.2.12.1       snj 
    649  1.1.1.2.12.1       snj 
    650  1.1.1.2.12.1       snj static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
    651  1.1.1.2.12.1       snj {
    652  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    653  1.1.1.2.12.1       snj 	return wpa_drv_tdls_oper(wpa_s, oper, peer);
    654  1.1.1.2.12.1       snj }
    655  1.1.1.2.12.1       snj 
    656  1.1.1.2.12.1       snj 
    657  1.1.1.2.12.1       snj static int wpa_supplicant_tdls_peer_addset(
    658  1.1.1.2.12.1       snj 	void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
    659  1.1.1.2.12.1       snj 	const u8 *supp_rates, size_t supp_rates_len,
    660  1.1.1.2.12.1       snj 	const struct ieee80211_ht_capabilities *ht_capab,
    661  1.1.1.2.12.1       snj 	const struct ieee80211_vht_capabilities *vht_capab,
    662  1.1.1.2.12.1       snj 	u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
    663  1.1.1.2.12.1       snj 	const u8 *supp_channels, size_t supp_channels_len,
    664  1.1.1.2.12.1       snj 	const u8 *supp_oper_classes, size_t supp_oper_classes_len)
    665  1.1.1.2.12.1       snj {
    666  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    667  1.1.1.2.12.1       snj 	struct hostapd_sta_add_params params;
    668  1.1.1.2.12.1       snj 
    669  1.1.1.2.12.1       snj 	os_memset(&params, 0, sizeof(params));
    670  1.1.1.2.12.1       snj 
    671  1.1.1.2.12.1       snj 	params.addr = peer;
    672  1.1.1.2.12.1       snj 	params.aid = aid;
    673  1.1.1.2.12.1       snj 	params.capability = capability;
    674  1.1.1.2.12.1       snj 	params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
    675  1.1.1.2.12.1       snj 
    676  1.1.1.2.12.1       snj 	/*
    677  1.1.1.2.12.1       snj 	 * Don't rely only on qosinfo for WMM capability. It may be 0 even when
    678  1.1.1.2.12.1       snj 	 * present. Allow the WMM IE to also indicate QoS support.
    679  1.1.1.2.12.1       snj 	 */
    680  1.1.1.2.12.1       snj 	if (wmm || qosinfo)
    681  1.1.1.2.12.1       snj 		params.flags |= WPA_STA_WMM;
    682  1.1.1.2.12.1       snj 
    683  1.1.1.2.12.1       snj 	params.ht_capabilities = ht_capab;
    684  1.1.1.2.12.1       snj 	params.vht_capabilities = vht_capab;
    685  1.1.1.2.12.1       snj 	params.qosinfo = qosinfo;
    686  1.1.1.2.12.1       snj 	params.listen_interval = 0;
    687  1.1.1.2.12.1       snj 	params.supp_rates = supp_rates;
    688  1.1.1.2.12.1       snj 	params.supp_rates_len = supp_rates_len;
    689  1.1.1.2.12.1       snj 	params.set = !add;
    690  1.1.1.2.12.1       snj 	params.ext_capab = ext_capab;
    691  1.1.1.2.12.1       snj 	params.ext_capab_len = ext_capab_len;
    692  1.1.1.2.12.1       snj 	params.supp_channels = supp_channels;
    693  1.1.1.2.12.1       snj 	params.supp_channels_len = supp_channels_len;
    694  1.1.1.2.12.1       snj 	params.supp_oper_classes = supp_oper_classes;
    695  1.1.1.2.12.1       snj 	params.supp_oper_classes_len = supp_oper_classes_len;
    696  1.1.1.2.12.1       snj 
    697  1.1.1.2.12.1       snj 	return wpa_drv_sta_add(wpa_s, &params);
    698  1.1.1.2.12.1       snj }
    699  1.1.1.2.12.1       snj 
    700  1.1.1.2.12.1       snj 
    701  1.1.1.2.12.1       snj static int wpa_supplicant_tdls_enable_channel_switch(
    702  1.1.1.2.12.1       snj 	void *ctx, const u8 *addr, u8 oper_class,
    703  1.1.1.2.12.1       snj 	const struct hostapd_freq_params *params)
    704  1.1.1.2.12.1       snj {
    705  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    706  1.1.1.2.12.1       snj 
    707  1.1.1.2.12.1       snj 	return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
    708  1.1.1.2.12.1       snj 						  params);
    709  1.1.1.2.12.1       snj }
    710  1.1.1.2.12.1       snj 
    711  1.1.1.2.12.1       snj 
    712  1.1.1.2.12.1       snj static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
    713  1.1.1.2.12.1       snj {
    714  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    715  1.1.1.2.12.1       snj 
    716  1.1.1.2.12.1       snj 	return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
    717  1.1.1.2.12.1       snj }
    718  1.1.1.2.12.1       snj 
    719  1.1.1.2.12.1       snj #endif /* CONFIG_TDLS */
    720  1.1.1.2.12.1       snj 
    721  1.1.1.2.12.1       snj #endif /* CONFIG_NO_WPA */
    722  1.1.1.2.12.1       snj 
    723  1.1.1.2.12.1       snj 
    724  1.1.1.2.12.1       snj enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
    725  1.1.1.2.12.1       snj {
    726  1.1.1.2.12.1       snj 	if (os_strcmp(field, "IDENTITY") == 0)
    727  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_EAP_IDENTITY;
    728  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "PASSWORD") == 0)
    729  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_EAP_PASSWORD;
    730  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "NEW_PASSWORD") == 0)
    731  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
    732  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "PIN") == 0)
    733  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_EAP_PIN;
    734  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "OTP") == 0)
    735  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_EAP_OTP;
    736  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "PASSPHRASE") == 0)
    737  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_EAP_PASSPHRASE;
    738  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "SIM") == 0)
    739  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_SIM;
    740  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
    741  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_PSK_PASSPHRASE;
    742  1.1.1.2.12.1       snj 	else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
    743  1.1.1.2.12.1       snj 		return WPA_CTRL_REQ_EXT_CERT_CHECK;
    744  1.1.1.2.12.1       snj 	return WPA_CTRL_REQ_UNKNOWN;
    745  1.1.1.2.12.1       snj }
    746  1.1.1.2.12.1       snj 
    747  1.1.1.2.12.1       snj 
    748  1.1.1.2.12.1       snj const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
    749  1.1.1.2.12.1       snj 					       const char *default_txt,
    750  1.1.1.2.12.1       snj 					       const char **txt)
    751  1.1.1.2.12.1       snj {
    752  1.1.1.2.12.1       snj 	const char *ret = NULL;
    753  1.1.1.2.12.1       snj 
    754  1.1.1.2.12.1       snj 	*txt = default_txt;
    755  1.1.1.2.12.1       snj 
    756  1.1.1.2.12.1       snj 	switch (field) {
    757  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_EAP_IDENTITY:
    758  1.1.1.2.12.1       snj 		*txt = "Identity";
    759  1.1.1.2.12.1       snj 		ret = "IDENTITY";
    760  1.1.1.2.12.1       snj 		break;
    761  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_EAP_PASSWORD:
    762  1.1.1.2.12.1       snj 		*txt = "Password";
    763  1.1.1.2.12.1       snj 		ret = "PASSWORD";
    764  1.1.1.2.12.1       snj 		break;
    765  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
    766  1.1.1.2.12.1       snj 		*txt = "New Password";
    767  1.1.1.2.12.1       snj 		ret = "NEW_PASSWORD";
    768  1.1.1.2.12.1       snj 		break;
    769  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_EAP_PIN:
    770  1.1.1.2.12.1       snj 		*txt = "PIN";
    771  1.1.1.2.12.1       snj 		ret = "PIN";
    772  1.1.1.2.12.1       snj 		break;
    773  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_EAP_OTP:
    774  1.1.1.2.12.1       snj 		ret = "OTP";
    775  1.1.1.2.12.1       snj 		break;
    776  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_EAP_PASSPHRASE:
    777  1.1.1.2.12.1       snj 		*txt = "Private key passphrase";
    778  1.1.1.2.12.1       snj 		ret = "PASSPHRASE";
    779  1.1.1.2.12.1       snj 		break;
    780  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_SIM:
    781  1.1.1.2.12.1       snj 		ret = "SIM";
    782  1.1.1.2.12.1       snj 		break;
    783  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_PSK_PASSPHRASE:
    784  1.1.1.2.12.1       snj 		*txt = "PSK or passphrase";
    785  1.1.1.2.12.1       snj 		ret = "PSK_PASSPHRASE";
    786  1.1.1.2.12.1       snj 		break;
    787  1.1.1.2.12.1       snj 	case WPA_CTRL_REQ_EXT_CERT_CHECK:
    788  1.1.1.2.12.1       snj 		*txt = "External server certificate validation";
    789  1.1.1.2.12.1       snj 		ret = "EXT_CERT_CHECK";
    790  1.1.1.2.12.1       snj 		break;
    791  1.1.1.2.12.1       snj 	default:
    792  1.1.1.2.12.1       snj 		break;
    793  1.1.1.2.12.1       snj 	}
    794  1.1.1.2.12.1       snj 
    795  1.1.1.2.12.1       snj 	/* txt needs to be something */
    796  1.1.1.2.12.1       snj 	if (*txt == NULL) {
    797  1.1.1.2.12.1       snj 		wpa_printf(MSG_WARNING, "No message for request %d", field);
    798  1.1.1.2.12.1       snj 		ret = NULL;
    799  1.1.1.2.12.1       snj 	}
    800  1.1.1.2.12.1       snj 
    801  1.1.1.2.12.1       snj 	return ret;
    802  1.1.1.2.12.1       snj }
    803  1.1.1.2.12.1       snj 
    804  1.1.1.2.12.1       snj 
    805  1.1.1.2.12.1       snj void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
    806  1.1.1.2.12.1       snj 			const char *field_name, const char *txt)
    807  1.1.1.2.12.1       snj {
    808           1.1  christos 	char *buf;
    809           1.1  christos 	size_t buflen;
    810           1.1  christos 	int len;
    811           1.1  christos 
    812           1.1  christos 	buflen = 100 + os_strlen(txt) + ssid->ssid_len;
    813           1.1  christos 	buf = os_malloc(buflen);
    814           1.1  christos 	if (buf == NULL)
    815           1.1  christos 		return;
    816  1.1.1.2.12.1       snj 	len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
    817  1.1.1.2.12.1       snj 			  field_name, ssid->id, txt);
    818  1.1.1.2.12.1       snj 	if (os_snprintf_error(buflen, len)) {
    819           1.1  christos 		os_free(buf);
    820           1.1  christos 		return;
    821           1.1  christos 	}
    822           1.1  christos 	if (ssid->ssid && buflen > len + ssid->ssid_len) {
    823           1.1  christos 		os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
    824           1.1  christos 		len += ssid->ssid_len;
    825           1.1  christos 		buf[len] = '\0';
    826           1.1  christos 	}
    827           1.1  christos 	buf[buflen - 1] = '\0';
    828  1.1.1.2.12.1       snj 	wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
    829           1.1  christos 	os_free(buf);
    830           1.1  christos }
    831  1.1.1.2.12.1       snj 
    832  1.1.1.2.12.1       snj 
    833  1.1.1.2.12.1       snj #ifdef IEEE8021X_EAPOL
    834  1.1.1.2.12.1       snj #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
    835  1.1.1.2.12.1       snj static void wpa_supplicant_eap_param_needed(void *ctx,
    836  1.1.1.2.12.1       snj 					    enum wpa_ctrl_req_type field,
    837  1.1.1.2.12.1       snj 					    const char *default_txt)
    838  1.1.1.2.12.1       snj {
    839  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    840  1.1.1.2.12.1       snj 	struct wpa_ssid *ssid = wpa_s->current_ssid;
    841  1.1.1.2.12.1       snj 	const char *field_name, *txt = NULL;
    842  1.1.1.2.12.1       snj 
    843  1.1.1.2.12.1       snj 	if (ssid == NULL)
    844  1.1.1.2.12.1       snj 		return;
    845  1.1.1.2.12.1       snj 
    846  1.1.1.2.12.1       snj 	if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
    847  1.1.1.2.12.1       snj 		ssid->eap.pending_ext_cert_check = PENDING_CHECK;
    848  1.1.1.2.12.1       snj 	wpas_notify_network_request(wpa_s, ssid, field, default_txt);
    849  1.1.1.2.12.1       snj 
    850  1.1.1.2.12.1       snj 	field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
    851  1.1.1.2.12.1       snj 						       &txt);
    852  1.1.1.2.12.1       snj 	if (field_name == NULL) {
    853  1.1.1.2.12.1       snj 		wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
    854  1.1.1.2.12.1       snj 			   field);
    855  1.1.1.2.12.1       snj 		return;
    856  1.1.1.2.12.1       snj 	}
    857  1.1.1.2.12.1       snj 
    858  1.1.1.2.12.1       snj 	wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
    859  1.1.1.2.12.1       snj 
    860  1.1.1.2.12.1       snj 	wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
    861  1.1.1.2.12.1       snj }
    862           1.1  christos #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
    863           1.1  christos #define wpa_supplicant_eap_param_needed NULL
    864           1.1  christos #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
    865           1.1  christos 
    866           1.1  christos 
    867  1.1.1.2.12.1       snj #ifdef CONFIG_EAP_PROXY
    868  1.1.1.2.12.1       snj static void wpa_supplicant_eap_proxy_cb(void *ctx)
    869  1.1.1.2.12.1       snj {
    870  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    871  1.1.1.2.12.1       snj 	size_t len;
    872  1.1.1.2.12.1       snj 
    873  1.1.1.2.12.1       snj 	wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol,
    874  1.1.1.2.12.1       snj 						     wpa_s->imsi, &len);
    875  1.1.1.2.12.1       snj 	if (wpa_s->mnc_len > 0) {
    876  1.1.1.2.12.1       snj 		wpa_s->imsi[len] = '\0';
    877  1.1.1.2.12.1       snj 		wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
    878  1.1.1.2.12.1       snj 			   wpa_s->imsi, wpa_s->mnc_len);
    879  1.1.1.2.12.1       snj 	} else {
    880  1.1.1.2.12.1       snj 		wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
    881  1.1.1.2.12.1       snj 	}
    882  1.1.1.2.12.1       snj }
    883  1.1.1.2.12.1       snj #endif /* CONFIG_EAP_PROXY */
    884  1.1.1.2.12.1       snj 
    885  1.1.1.2.12.1       snj 
    886           1.1  christos static void wpa_supplicant_port_cb(void *ctx, int authorized)
    887           1.1  christos {
    888           1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    889       1.1.1.2  christos #ifdef CONFIG_AP
    890       1.1.1.2  christos 	if (wpa_s->ap_iface) {
    891       1.1.1.2  christos 		wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
    892       1.1.1.2  christos 			   "port status: %s",
    893       1.1.1.2  christos 			   authorized ? "Authorized" : "Unauthorized");
    894       1.1.1.2  christos 		return;
    895       1.1.1.2  christos 	}
    896       1.1.1.2  christos #endif /* CONFIG_AP */
    897           1.1  christos 	wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
    898           1.1  christos 		   authorized ? "Authorized" : "Unauthorized");
    899           1.1  christos 	wpa_drv_set_supp_port(wpa_s, authorized);
    900           1.1  christos }
    901  1.1.1.2.12.1       snj 
    902  1.1.1.2.12.1       snj 
    903  1.1.1.2.12.1       snj static void wpa_supplicant_cert_cb(void *ctx, int depth, const char *subject,
    904  1.1.1.2.12.1       snj 				   const char *altsubject[], int num_altsubject,
    905  1.1.1.2.12.1       snj 				   const char *cert_hash,
    906  1.1.1.2.12.1       snj 				   const struct wpabuf *cert)
    907  1.1.1.2.12.1       snj {
    908  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    909  1.1.1.2.12.1       snj 
    910  1.1.1.2.12.1       snj 	wpas_notify_certification(wpa_s, depth, subject, altsubject,
    911  1.1.1.2.12.1       snj 				  num_altsubject, cert_hash, cert);
    912  1.1.1.2.12.1       snj }
    913  1.1.1.2.12.1       snj 
    914  1.1.1.2.12.1       snj 
    915  1.1.1.2.12.1       snj static void wpa_supplicant_status_cb(void *ctx, const char *status,
    916  1.1.1.2.12.1       snj 				     const char *parameter)
    917  1.1.1.2.12.1       snj {
    918  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    919  1.1.1.2.12.1       snj 
    920  1.1.1.2.12.1       snj 	wpas_notify_eap_status(wpa_s, status, parameter);
    921  1.1.1.2.12.1       snj }
    922  1.1.1.2.12.1       snj 
    923  1.1.1.2.12.1       snj 
    924  1.1.1.2.12.1       snj static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
    925  1.1.1.2.12.1       snj {
    926  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
    927  1.1.1.2.12.1       snj 	char *str;
    928  1.1.1.2.12.1       snj 	int res;
    929  1.1.1.2.12.1       snj 
    930  1.1.1.2.12.1       snj 	wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
    931  1.1.1.2.12.1       snj 			  id, len);
    932  1.1.1.2.12.1       snj 
    933  1.1.1.2.12.1       snj 	if (wpa_s->current_ssid == NULL)
    934  1.1.1.2.12.1       snj 		return;
    935  1.1.1.2.12.1       snj 
    936  1.1.1.2.12.1       snj 	if (id == NULL) {
    937  1.1.1.2.12.1       snj 		if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
    938  1.1.1.2.12.1       snj 				   "NULL", 0) < 0)
    939  1.1.1.2.12.1       snj 			return;
    940  1.1.1.2.12.1       snj 	} else {
    941  1.1.1.2.12.1       snj 		str = os_malloc(len * 2 + 1);
    942  1.1.1.2.12.1       snj 		if (str == NULL)
    943  1.1.1.2.12.1       snj 			return;
    944  1.1.1.2.12.1       snj 		wpa_snprintf_hex(str, len * 2 + 1, id, len);
    945  1.1.1.2.12.1       snj 		res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
    946  1.1.1.2.12.1       snj 				     str, 0);
    947  1.1.1.2.12.1       snj 		os_free(str);
    948  1.1.1.2.12.1       snj 		if (res < 0)
    949  1.1.1.2.12.1       snj 			return;
    950  1.1.1.2.12.1       snj 	}
    951  1.1.1.2.12.1       snj 
    952  1.1.1.2.12.1       snj 	if (wpa_s->conf->update_config) {
    953  1.1.1.2.12.1       snj 		res = wpa_config_write(wpa_s->confname, wpa_s->conf);
    954  1.1.1.2.12.1       snj 		if (res) {
    955  1.1.1.2.12.1       snj 			wpa_printf(MSG_DEBUG, "Failed to update config after "
    956  1.1.1.2.12.1       snj 				   "anonymous_id update");
    957  1.1.1.2.12.1       snj 		}
    958  1.1.1.2.12.1       snj 	}
    959  1.1.1.2.12.1       snj }
    960           1.1  christos #endif /* IEEE8021X_EAPOL */
    961           1.1  christos 
    962           1.1  christos 
    963           1.1  christos int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
    964           1.1  christos {
    965           1.1  christos #ifdef IEEE8021X_EAPOL
    966           1.1  christos 	struct eapol_ctx *ctx;
    967           1.1  christos 	ctx = os_zalloc(sizeof(*ctx));
    968           1.1  christos 	if (ctx == NULL) {
    969           1.1  christos 		wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
    970           1.1  christos 		return -1;
    971           1.1  christos 	}
    972           1.1  christos 
    973           1.1  christos 	ctx->ctx = wpa_s;
    974           1.1  christos 	ctx->msg_ctx = wpa_s;
    975           1.1  christos 	ctx->eapol_send_ctx = wpa_s;
    976           1.1  christos 	ctx->preauth = 0;
    977           1.1  christos 	ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
    978           1.1  christos 	ctx->eapol_send = wpa_supplicant_eapol_send;
    979           1.1  christos 	ctx->set_wep_key = wpa_eapol_set_wep_key;
    980  1.1.1.2.12.1       snj #ifndef CONFIG_NO_CONFIG_BLOBS
    981           1.1  christos 	ctx->set_config_blob = wpa_supplicant_set_config_blob;
    982           1.1  christos 	ctx->get_config_blob = wpa_supplicant_get_config_blob;
    983  1.1.1.2.12.1       snj #endif /* CONFIG_NO_CONFIG_BLOBS */
    984           1.1  christos 	ctx->aborted_cached = wpa_supplicant_aborted_cached;
    985           1.1  christos 	ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
    986           1.1  christos 	ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
    987           1.1  christos 	ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
    988  1.1.1.2.12.1       snj 	ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
    989           1.1  christos 	ctx->wps = wpa_s->wps;
    990           1.1  christos 	ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
    991  1.1.1.2.12.1       snj #ifdef CONFIG_EAP_PROXY
    992  1.1.1.2.12.1       snj 	ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
    993  1.1.1.2.12.1       snj #endif /* CONFIG_EAP_PROXY */
    994           1.1  christos 	ctx->port_cb = wpa_supplicant_port_cb;
    995           1.1  christos 	ctx->cb = wpa_supplicant_eapol_cb;
    996  1.1.1.2.12.1       snj 	ctx->cert_cb = wpa_supplicant_cert_cb;
    997  1.1.1.2.12.1       snj 	ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
    998  1.1.1.2.12.1       snj 	ctx->status_cb = wpa_supplicant_status_cb;
    999  1.1.1.2.12.1       snj 	ctx->set_anon_id = wpa_supplicant_set_anon_id;
   1000           1.1  christos 	ctx->cb_ctx = wpa_s;
   1001           1.1  christos 	wpa_s->eapol = eapol_sm_init(ctx);
   1002           1.1  christos 	if (wpa_s->eapol == NULL) {
   1003           1.1  christos 		os_free(ctx);
   1004           1.1  christos 		wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
   1005           1.1  christos 			   "machines.");
   1006           1.1  christos 		return -1;
   1007           1.1  christos 	}
   1008           1.1  christos #endif /* IEEE8021X_EAPOL */
   1009           1.1  christos 
   1010           1.1  christos 	return 0;
   1011           1.1  christos }
   1012           1.1  christos 
   1013           1.1  christos 
   1014  1.1.1.2.12.1       snj #ifndef CONFIG_NO_WPA
   1015  1.1.1.2.12.1       snj static void wpa_supplicant_set_rekey_offload(void *ctx,
   1016  1.1.1.2.12.1       snj 					     const u8 *kek, size_t kek_len,
   1017  1.1.1.2.12.1       snj 					     const u8 *kck, size_t kck_len,
   1018  1.1.1.2.12.1       snj 					     const u8 *replay_ctr)
   1019  1.1.1.2.12.1       snj {
   1020  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
   1021  1.1.1.2.12.1       snj 
   1022  1.1.1.2.12.1       snj 	wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
   1023  1.1.1.2.12.1       snj }
   1024  1.1.1.2.12.1       snj 
   1025  1.1.1.2.12.1       snj 
   1026  1.1.1.2.12.1       snj static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
   1027  1.1.1.2.12.1       snj 					   size_t pmk_len)
   1028  1.1.1.2.12.1       snj {
   1029  1.1.1.2.12.1       snj 	struct wpa_supplicant *wpa_s = ctx;
   1030  1.1.1.2.12.1       snj 
   1031  1.1.1.2.12.1       snj 	if (wpa_s->conf->key_mgmt_offload &&
   1032  1.1.1.2.12.1       snj 	    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
   1033  1.1.1.2.12.1       snj 		return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0,
   1034  1.1.1.2.12.1       snj 				       NULL, 0, pmk, pmk_len);
   1035  1.1.1.2.12.1       snj 	else
   1036  1.1.1.2.12.1       snj 		return 0;
   1037  1.1.1.2.12.1       snj }
   1038  1.1.1.2.12.1       snj #endif /* CONFIG_NO_WPA */
   1039  1.1.1.2.12.1       snj 
   1040  1.1.1.2.12.1       snj 
   1041           1.1  christos int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
   1042           1.1  christos {
   1043           1.1  christos #ifndef CONFIG_NO_WPA
   1044           1.1  christos 	struct wpa_sm_ctx *ctx;
   1045           1.1  christos 	ctx = os_zalloc(sizeof(*ctx));
   1046           1.1  christos 	if (ctx == NULL) {
   1047           1.1  christos 		wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
   1048           1.1  christos 		return -1;
   1049           1.1  christos 	}
   1050           1.1  christos 
   1051           1.1  christos 	ctx->ctx = wpa_s;
   1052           1.1  christos 	ctx->msg_ctx = wpa_s;
   1053           1.1  christos 	ctx->set_state = _wpa_supplicant_set_state;
   1054           1.1  christos 	ctx->get_state = _wpa_supplicant_get_state;
   1055           1.1  christos 	ctx->deauthenticate = _wpa_supplicant_deauthenticate;
   1056           1.1  christos 	ctx->set_key = wpa_supplicant_set_key;
   1057           1.1  christos 	ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
   1058           1.1  christos 	ctx->get_bssid = wpa_supplicant_get_bssid;
   1059           1.1  christos 	ctx->ether_send = _wpa_ether_send;
   1060           1.1  christos 	ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
   1061           1.1  christos 	ctx->alloc_eapol = _wpa_alloc_eapol;
   1062           1.1  christos 	ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
   1063           1.1  christos 	ctx->add_pmkid = wpa_supplicant_add_pmkid;
   1064           1.1  christos 	ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
   1065           1.1  christos #ifndef CONFIG_NO_CONFIG_BLOBS
   1066           1.1  christos 	ctx->set_config_blob = wpa_supplicant_set_config_blob;
   1067           1.1  christos 	ctx->get_config_blob = wpa_supplicant_get_config_blob;
   1068           1.1  christos #endif /* CONFIG_NO_CONFIG_BLOBS */
   1069           1.1  christos 	ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
   1070           1.1  christos #ifdef CONFIG_IEEE80211R
   1071           1.1  christos 	ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
   1072           1.1  christos 	ctx->send_ft_action = wpa_supplicant_send_ft_action;
   1073           1.1  christos 	ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
   1074           1.1  christos #endif /* CONFIG_IEEE80211R */
   1075  1.1.1.2.12.1       snj #ifdef CONFIG_TDLS
   1076  1.1.1.2.12.1       snj 	ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
   1077  1.1.1.2.12.1       snj 	ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
   1078  1.1.1.2.12.1       snj 	ctx->tdls_oper = wpa_supplicant_tdls_oper;
   1079  1.1.1.2.12.1       snj 	ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
   1080  1.1.1.2.12.1       snj 	ctx->tdls_enable_channel_switch =
   1081  1.1.1.2.12.1       snj 		wpa_supplicant_tdls_enable_channel_switch;
   1082  1.1.1.2.12.1       snj 	ctx->tdls_disable_channel_switch =
   1083  1.1.1.2.12.1       snj 		wpa_supplicant_tdls_disable_channel_switch;
   1084  1.1.1.2.12.1       snj #endif /* CONFIG_TDLS */
   1085  1.1.1.2.12.1       snj 	ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
   1086  1.1.1.2.12.1       snj 	ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
   1087           1.1  christos 
   1088           1.1  christos 	wpa_s->wpa = wpa_sm_init(ctx);
   1089           1.1  christos 	if (wpa_s->wpa == NULL) {
   1090           1.1  christos 		wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
   1091           1.1  christos 			   "machine");
   1092  1.1.1.2.12.1       snj 		os_free(ctx);
   1093           1.1  christos 		return -1;
   1094           1.1  christos 	}
   1095           1.1  christos #endif /* CONFIG_NO_WPA */
   1096           1.1  christos 
   1097           1.1  christos 	return 0;
   1098           1.1  christos }
   1099           1.1  christos 
   1100           1.1  christos 
   1101           1.1  christos void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
   1102           1.1  christos 					struct wpa_ssid *ssid)
   1103           1.1  christos {
   1104           1.1  christos 	struct rsn_supp_config conf;
   1105           1.1  christos 	if (ssid) {
   1106           1.1  christos 		os_memset(&conf, 0, sizeof(conf));
   1107           1.1  christos 		conf.network_ctx = ssid;
   1108           1.1  christos 		conf.peerkey_enabled = ssid->peerkey;
   1109           1.1  christos 		conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
   1110           1.1  christos #ifdef IEEE8021X_EAPOL
   1111  1.1.1.2.12.1       snj 		conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
   1112  1.1.1.2.12.1       snj 			wpa_s->conf->okc : ssid->proactive_key_caching;
   1113           1.1  christos 		conf.eap_workaround = ssid->eap_workaround;
   1114           1.1  christos 		conf.eap_conf_ctx = &ssid->eap;
   1115           1.1  christos #endif /* IEEE8021X_EAPOL */
   1116           1.1  christos 		conf.ssid = ssid->ssid;
   1117           1.1  christos 		conf.ssid_len = ssid->ssid_len;
   1118           1.1  christos 		conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
   1119  1.1.1.2.12.1       snj #ifdef CONFIG_P2P
   1120  1.1.1.2.12.1       snj 		if (ssid->p2p_group && wpa_s->current_bss &&
   1121  1.1.1.2.12.1       snj 		    !wpa_s->p2p_disable_ip_addr_req) {
   1122  1.1.1.2.12.1       snj 			struct wpabuf *p2p;
   1123  1.1.1.2.12.1       snj 			p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
   1124  1.1.1.2.12.1       snj 							  P2P_IE_VENDOR_TYPE);
   1125  1.1.1.2.12.1       snj 			if (p2p) {
   1126  1.1.1.2.12.1       snj 				u8 group_capab;
   1127  1.1.1.2.12.1       snj 				group_capab = p2p_get_group_capab(p2p);
   1128  1.1.1.2.12.1       snj 				if (group_capab &
   1129  1.1.1.2.12.1       snj 				    P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
   1130  1.1.1.2.12.1       snj 					conf.p2p = 1;
   1131  1.1.1.2.12.1       snj 				wpabuf_free(p2p);
   1132  1.1.1.2.12.1       snj 			}
   1133  1.1.1.2.12.1       snj 		}
   1134  1.1.1.2.12.1       snj #endif /* CONFIG_P2P */
   1135  1.1.1.2.12.1       snj 		conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
   1136           1.1  christos 	}
   1137           1.1  christos 	wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
   1138           1.1  christos }
   1139