TDLS: Declare tdls_testing as extern in a header file
[mech_eap.git] / wpa_supplicant / wpas_glue.c
index fcfa9fb..f84c8b9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * WPA Supplicant - Glue code to setup EAPOL and RSN modules
- * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -115,7 +115,7 @@ static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
                return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
        }
 
-       return wpa_drv_send_eapol(wpa_s, dest, proto, buf, len);
+       return -1;
 }
 #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */
 
@@ -543,7 +543,44 @@ static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
                                         const u8 *ies, size_t ies_len)
 {
        struct wpa_supplicant *wpa_s = ctx;
-       return wpa_drv_send_ft_action(wpa_s, action, target_ap, ies, ies_len);
+       int ret;
+       u8 *data, *pos;
+       size_t data_len;
+
+       if (action != 1) {
+               wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
+                          action);
+               return -1;
+       }
+
+       /*
+        * Action frame payload:
+        * Category[1] = 6 (Fast BSS Transition)
+        * Action[1] = 1 (Fast BSS Transition Request)
+        * STA Address
+        * Target AP Address
+        * FT IEs
+        */
+
+       data_len = 2 + 2 * ETH_ALEN + ies_len;
+       data = os_malloc(data_len);
+       if (data == NULL)
+               return -1;
+       pos = data;
+       *pos++ = 0x06; /* FT Action category */
+       *pos++ = action;
+       os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
+       pos += ETH_ALEN;
+       os_memcpy(pos, target_ap, ETH_ALEN);
+       pos += ETH_ALEN;
+       os_memcpy(pos, ies, ies_len);
+
+       ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
+                                 wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
+                                 data, data_len, 0);
+       os_free(data);
+
+       return ret;
 }
 
 
@@ -572,12 +609,14 @@ static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
 #ifdef CONFIG_TDLS
 
 static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
-                                       int *tdls_ext_setup)
+                                       int *tdls_ext_setup,
+                                       int *tdls_chan_switch)
 {
        struct wpa_supplicant *wpa_s = ctx;
 
        *tdls_supported = 0;
        *tdls_ext_setup = 0;
+       *tdls_chan_switch = 0;
 
        if (!wpa_s->drv_capa_known)
                return -1;
@@ -588,6 +627,9 @@ static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
        if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
                *tdls_ext_setup = 1;
 
+       if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
+               *tdls_chan_switch = 1;
+
        return 0;
 }
 
@@ -655,6 +697,25 @@ static int wpa_supplicant_tdls_peer_addset(
        return wpa_drv_sta_add(wpa_s, &params);
 }
 
+
+static int wpa_supplicant_tdls_enable_channel_switch(
+       void *ctx, const u8 *addr, u8 oper_class,
+       const struct hostapd_freq_params *params)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+
+       return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
+                                                 params);
+}
+
+
+static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+
+       return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
+}
+
 #endif /* CONFIG_TDLS */
 
 #endif /* CONFIG_NO_WPA */
@@ -676,6 +737,10 @@ enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
                return WPA_CTRL_REQ_EAP_PASSPHRASE;
        else if (os_strcmp(field, "SIM") == 0)
                return WPA_CTRL_REQ_SIM;
+       else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
+               return WPA_CTRL_REQ_PSK_PASSPHRASE;
+       else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
+               return WPA_CTRL_REQ_EXT_CERT_CHECK;
        return WPA_CTRL_REQ_UNKNOWN;
 }
 
@@ -715,6 +780,14 @@ const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
        case WPA_CTRL_REQ_SIM:
                ret = "SIM";
                break;
+       case WPA_CTRL_REQ_PSK_PASSPHRASE:
+               *txt = "PSK or passphrase";
+               ret = "PSK_PASSPHRASE";
+               break;
+       case WPA_CTRL_REQ_EXT_CERT_CHECK:
+               *txt = "External server certificate validation";
+               ret = "EXT_CERT_CHECK";
+               break;
        default:
                break;
        }
@@ -728,6 +801,35 @@ const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
        return ret;
 }
 
+
+void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
+                       const char *field_name, const char *txt)
+{
+       char *buf;
+       size_t buflen;
+       int len;
+
+       buflen = 100 + os_strlen(txt) + ssid->ssid_len;
+       buf = os_malloc(buflen);
+       if (buf == NULL)
+               return;
+       len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
+                         field_name, ssid->id, txt);
+       if (os_snprintf_error(buflen, len)) {
+               os_free(buf);
+               return;
+       }
+       if (ssid->ssid && buflen > len + ssid->ssid_len) {
+               os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
+               len += ssid->ssid_len;
+               buf[len] = '\0';
+       }
+       buf[buflen - 1] = '\0';
+       wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
+       os_free(buf);
+}
+
+
 #ifdef IEEE8021X_EAPOL
 #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
 static void wpa_supplicant_eap_param_needed(void *ctx,
@@ -737,13 +839,12 @@ static void wpa_supplicant_eap_param_needed(void *ctx,
        struct wpa_supplicant *wpa_s = ctx;
        struct wpa_ssid *ssid = wpa_s->current_ssid;
        const char *field_name, *txt = NULL;
-       char *buf;
-       size_t buflen;
-       int len;
 
        if (ssid == NULL)
                return;
 
+       if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
+               ssid->eap.pending_ext_cert_check = PENDING_CHECK;
        wpas_notify_network_request(wpa_s, ssid, field, default_txt);
 
        field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
@@ -756,31 +857,32 @@ static void wpa_supplicant_eap_param_needed(void *ctx,
 
        wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
 
-       buflen = 100 + os_strlen(txt) + ssid->ssid_len;
-       buf = os_malloc(buflen);
-       if (buf == NULL)
-               return;
-       len = os_snprintf(buf, buflen,
-                         WPA_CTRL_REQ "%s-%d:%s needed for SSID ",
-                         field_name, ssid->id, txt);
-       if (len < 0 || (size_t) len >= buflen) {
-               os_free(buf);
-               return;
-       }
-       if (ssid->ssid && buflen > len + ssid->ssid_len) {
-               os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
-               len += ssid->ssid_len;
-               buf[len] = '\0';
-       }
-       buf[buflen - 1] = '\0';
-       wpa_msg(wpa_s, MSG_INFO, "%s", buf);
-       os_free(buf);
+       wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
 }
 #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
 #define wpa_supplicant_eap_param_needed NULL
 #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
 
 
+#ifdef CONFIG_EAP_PROXY
+static void wpa_supplicant_eap_proxy_cb(void *ctx)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+       size_t len;
+
+       wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol,
+                                                    wpa_s->imsi, &len);
+       if (wpa_s->mnc_len > 0) {
+               wpa_s->imsi[len] = '\0';
+               wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
+                          wpa_s->imsi, wpa_s->mnc_len);
+       } else {
+               wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
+       }
+}
+#endif /* CONFIG_EAP_PROXY */
+
+
 static void wpa_supplicant_port_cb(void *ctx, int authorized)
 {
        struct wpa_supplicant *wpa_s = ctx;
@@ -799,12 +901,14 @@ static void wpa_supplicant_port_cb(void *ctx, int authorized)
 
 
 static void wpa_supplicant_cert_cb(void *ctx, int depth, const char *subject,
+                                  const char *altsubject[], int num_altsubject,
                                   const char *cert_hash,
                                   const struct wpabuf *cert)
 {
        struct wpa_supplicant *wpa_s = ctx;
 
-       wpas_notify_certification(wpa_s, depth, subject, cert_hash, cert);
+       wpas_notify_certification(wpa_s, depth, subject, altsubject,
+                                 num_altsubject, cert_hash, cert);
 }
 
 
@@ -881,11 +985,16 @@ int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
        ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
        ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
        ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
+       ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
        ctx->wps = wpa_s->wps;
        ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
+#ifdef CONFIG_EAP_PROXY
+       ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
+#endif /* CONFIG_EAP_PROXY */
        ctx->port_cb = wpa_supplicant_port_cb;
        ctx->cb = wpa_supplicant_eapol_cb;
        ctx->cert_cb = wpa_supplicant_cert_cb;
+       ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
        ctx->status_cb = wpa_supplicant_status_cb;
        ctx->set_anon_id = wpa_supplicant_set_anon_id;
        ctx->cb_ctx = wpa_s;
@@ -903,13 +1012,28 @@ int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
 
 
 #ifndef CONFIG_NO_WPA
-static void wpa_supplicant_set_rekey_offload(void *ctx, const u8 *kek,
-                                            const u8 *kck,
+static void wpa_supplicant_set_rekey_offload(void *ctx,
+                                            const u8 *kek, size_t kek_len,
+                                            const u8 *kck, size_t kck_len,
                                             const u8 *replay_ctr)
 {
        struct wpa_supplicant *wpa_s = ctx;
 
-       wpa_drv_set_rekey_info(wpa_s, kek, kck, replay_ctr);
+       wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
+}
+
+
+static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
+                                          size_t pmk_len)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+
+       if (wpa_s->conf->key_mgmt_offload &&
+           (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
+               return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0,
+                                      NULL, 0, pmk, pmk_len);
+       else
+               return 0;
 }
 #endif /* CONFIG_NO_WPA */
 
@@ -953,13 +1077,19 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
        ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
        ctx->tdls_oper = wpa_supplicant_tdls_oper;
        ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
+       ctx->tdls_enable_channel_switch =
+               wpa_supplicant_tdls_enable_channel_switch;
+       ctx->tdls_disable_channel_switch =
+               wpa_supplicant_tdls_disable_channel_switch;
 #endif /* CONFIG_TDLS */
        ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
+       ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
 
        wpa_s->wpa = wpa_sm_init(ctx);
        if (wpa_s->wpa == NULL) {
                wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
                           "machine");
+               os_free(ctx);
                return -1;
        }
 #endif /* CONFIG_NO_WPA */
@@ -1002,6 +1132,7 @@ void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
                        }
                }
 #endif /* CONFIG_P2P */
+               conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
        }
        wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
 }