Add Suite B AKMs to key_mgmt capability list
[mech_eap.git] / wpa_supplicant / ctrl_iface.c
index c663512..caa480c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * WPA Supplicant / Control interface (shared code for all backends)
- * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -19,6 +19,7 @@
 #include "common/ieee802_11_defs.h"
 #include "common/ieee802_11_common.h"
 #include "common/wpa_ctrl.h"
+#include "crypto/tls.h"
 #include "ap/hostapd.h"
 #include "eap_peer/eap.h"
 #include "eapol_supp/eapol_supp_sm.h"
@@ -436,11 +437,22 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_AP */
        } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
                wpa_s->extra_roc_dur = atoi(value);
+       } else if (os_strcasecmp(cmd, "test_failure") == 0) {
+               wpa_s->test_failure = atoi(value);
 #endif /* CONFIG_TESTING_OPTIONS */
 #ifndef CONFIG_NO_CONFIG_BLOBS
        } else if (os_strcmp(cmd, "blob") == 0) {
                ret = wpas_ctrl_set_blob(wpa_s, value);
 #endif /* CONFIG_NO_CONFIG_BLOBS */
+       } else if (os_strcasecmp(cmd, "setband") == 0) {
+               if (os_strcmp(value, "AUTO") == 0)
+                       wpa_s->setband = WPA_SETBAND_AUTO;
+               else if (os_strcmp(value, "5G") == 0)
+                       wpa_s->setband = WPA_SETBAND_5G;
+               else if (os_strcmp(value, "2G") == 0)
+                       wpa_s->setband = WPA_SETBAND_2G;
+               else
+                       ret = -1;
        } else {
                value[-1] = '=';
                ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
@@ -484,6 +496,8 @@ static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
                                       wpa_s->last_gtk_len);
                return res;
 #endif /* CONFIG_TESTING_GET_GTK */
+       } else if (os_strcmp(cmd, "tls_library") == 0) {
+               res = tls_get_library_version(buf, buflen);
        }
 
        if (os_snprintf_error(buflen, res))
@@ -644,6 +658,104 @@ static int ctrl_iface_get_capability_tdls(
        return ret;
 }
 
+
+static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
+       struct wpa_supplicant *wpa_s, char *cmd)
+{
+       u8 peer[ETH_ALEN];
+       struct hostapd_freq_params freq_params;
+       u8 oper_class;
+       char *pos, *end;
+
+       if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
+               wpa_printf(MSG_INFO,
+                          "tdls_chanswitch: Only supported with external setup");
+               return -1;
+       }
+
+       os_memset(&freq_params, 0, sizeof(freq_params));
+
+       pos = os_strchr(cmd, ' ');
+       if (pos == NULL)
+               return -1;
+       *pos++ = '\0';
+
+       oper_class = strtol(pos, &end, 10);
+       if (pos == end) {
+               wpa_printf(MSG_INFO,
+                          "tdls_chanswitch: Invalid op class provided");
+               return -1;
+       }
+
+       pos = end;
+       freq_params.freq = atoi(pos);
+       if (freq_params.freq == 0) {
+               wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
+               return -1;
+       }
+
+#define SET_FREQ_SETTING(str) \
+       do { \
+               const char *pos2 = os_strstr(pos, " " #str "="); \
+               if (pos2) { \
+                       pos2 += sizeof(" " #str "=") - 1; \
+                       freq_params.str = atoi(pos2); \
+               } \
+       } while (0)
+
+       SET_FREQ_SETTING(center_freq1);
+       SET_FREQ_SETTING(center_freq2);
+       SET_FREQ_SETTING(bandwidth);
+       SET_FREQ_SETTING(sec_channel_offset);
+#undef SET_FREQ_SETTING
+
+       freq_params.ht_enabled = !!os_strstr(pos, " ht");
+       freq_params.vht_enabled = !!os_strstr(pos, " vht");
+
+       if (hwaddr_aton(cmd, peer)) {
+               wpa_printf(MSG_DEBUG,
+                          "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
+                          cmd);
+               return -1;
+       }
+
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
+                  " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
+                  MAC2STR(peer), oper_class, freq_params.freq,
+                  freq_params.center_freq1, freq_params.center_freq2,
+                  freq_params.bandwidth, freq_params.sec_channel_offset,
+                  freq_params.ht_enabled ? " HT" : "",
+                  freq_params.vht_enabled ? " VHT" : "");
+
+       return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
+                                          &freq_params);
+}
+
+
+static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
+       struct wpa_supplicant *wpa_s, char *cmd)
+{
+       u8 peer[ETH_ALEN];
+
+       if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
+               wpa_printf(MSG_INFO,
+                          "tdls_chanswitch: Only supported with external setup");
+               return -1;
+       }
+
+       if (hwaddr_aton(cmd, peer)) {
+               wpa_printf(MSG_DEBUG,
+                          "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
+                          cmd);
+               return -1;
+       }
+
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
+                  MAC2STR(peer));
+
+       return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
+}
+
 #endif /* CONFIG_TDLS */
 
 
@@ -2211,6 +2323,7 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
        }
 #endif /* CONFIG_IEEE80211W */
 
+#ifdef CONFIG_SUITEB
        if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
                ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
                                  pos == start ? "" : "+");
@@ -2218,6 +2331,17 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
                        return pos;
                pos += ret;
        }
+#endif /* CONFIG_SUITEB */
+
+#ifdef CONFIG_SUITEB192
+       if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
+               ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
+                                 pos == start ? "" : "+");
+               if (os_snprintf_error(end - pos, ret))
+                       return pos;
+               pos += ret;
+       }
+#endif /* CONFIG_SUITEB192 */
 
        pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
 
@@ -2423,6 +2547,27 @@ static int wpa_supplicant_ctrl_iface_scan_results(
 
 #ifdef CONFIG_MESH
 
+static int wpa_supplicant_ctrl_iface_mesh_interface_add(
+       struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
+{
+       char *pos, ifname[IFNAMSIZ + 1];
+
+       ifname[0] = '\0';
+
+       pos = os_strstr(cmd, "ifname=");
+       if (pos) {
+               pos += 7;
+               os_strlcpy(ifname, pos, sizeof(ifname));
+       }
+
+       if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
+               return -1;
+
+       os_strlcpy(reply, ifname, max_len);
+       return os_strlen(ifname);
+}
+
+
 static int wpa_supplicant_ctrl_iface_mesh_group_add(
        struct wpa_supplicant *wpa_s, char *cmd)
 {
@@ -2463,17 +2608,32 @@ static int wpa_supplicant_ctrl_iface_mesh_group_add(
 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
        struct wpa_supplicant *wpa_s, char *cmd)
 {
-       /*
-        * TODO: Support a multiple mesh and other iface type combinations
-        */
-       if (os_strcmp(cmd, wpa_s->ifname) != 0) {
-               wpa_printf(MSG_DEBUG,
-                          "CTRL_IFACE: MESH_GROUP_REMOVE unknown interface name: %s",
+       struct wpa_supplicant *orig;
+       struct wpa_global *global;
+       int found = 0;
+
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
+
+       global = wpa_s->global;
+       orig = wpa_s;
+
+       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               if (os_strcmp(wpa_s->ifname, cmd) == 0) {
+                       found = 1;
+                       break;
+               }
+       }
+       if (!found) {
+               wpa_printf(MSG_ERROR,
+                          "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
                           cmd);
                return -1;
        }
-
-       wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
+       if (wpa_s->mesh_if_created && wpa_s == orig) {
+               wpa_printf(MSG_ERROR,
+                          "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
+               return -1;
+       }
 
        wpa_s->reassociate = 0;
        wpa_s->disconnected = 1;
@@ -2486,6 +2646,9 @@ static int wpa_supplicant_ctrl_iface_mesh_group_remove(
         */
        wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
 
+       if (wpa_s->mesh_if_created)
+               wpa_supplicant_remove_iface(global, wpa_s, 0);
+
        return 0;
 }
 
@@ -3182,6 +3345,13 @@ static const struct cipher_info ciphers[] = {
        { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
 };
 
+static const struct cipher_info ciphers_group_mgmt[] = {
+       { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
+       { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
+       { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
+       { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
+};
+
 
 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
                                              struct wpa_driver_capa *capa,
@@ -3255,6 +3425,35 @@ static int ctrl_iface_get_capability_group(int res, char *strict,
 }
 
 
+static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
+                                               struct wpa_driver_capa *capa,
+                                               char *buf, size_t buflen)
+{
+       int ret;
+       char *pos, *end;
+       unsigned int i;
+
+       pos = buf;
+       end = pos + buflen;
+
+       if (res < 0)
+               return 0;
+
+       for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
+               if (capa->enc & ciphers_group_mgmt[i].capa) {
+                       ret = os_snprintf(pos, end - pos, "%s%s",
+                                         pos == buf ? "" : " ",
+                                         ciphers_group_mgmt[i].name);
+                       if (os_snprintf_error(end - pos, ret))
+                               return pos - buf;
+                       pos += ret;
+               }
+       }
+
+       return pos - buf;
+}
+
+
 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
                                              struct wpa_driver_capa *capa,
                                              char *buf, size_t buflen)
@@ -3304,6 +3503,23 @@ static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
                pos += ret;
        }
 
+#ifdef CONFIG_SUITEB
+       if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
+               ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
+               if (os_snprintf_error(end - pos, ret))
+                       return pos - buf;
+               pos += ret;
+       }
+#endif /* CONFIG_SUITEB */
+#ifdef CONFIG_SUITEB192
+       if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
+               ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
+               if (os_snprintf_error(end - pos, ret))
+                       return pos - buf;
+               pos += ret;
+       }
+#endif /* CONFIG_SUITEB192 */
+
        return pos - buf;
 }
 
@@ -3350,7 +3566,8 @@ static int ctrl_iface_get_capability_proto(int res, char *strict,
 }
 
 
-static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
+static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
+                                             int res, char *strict,
                                              struct wpa_driver_capa *capa,
                                              char *buf, size_t buflen)
 {
@@ -3394,6 +3611,16 @@ static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
                pos += ret;
        }
 
+#ifdef CONFIG_SAE
+       if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
+               ret = os_snprintf(pos, end - pos, "%sSAE",
+                                 pos == buf ? "" : " ");
+               if (os_snprintf_error(end - pos, ret))
+                       return pos - buf;
+               pos += ret;
+       }
+#endif /* CONFIG_SAE */
+
        return pos - buf;
 }
 
@@ -3434,6 +3661,16 @@ static int ctrl_iface_get_capability_modes(int res, char *strict,
                pos += ret;
        }
 
+#ifdef CONFIG_MESH
+       if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
+               ret = os_snprintf(pos, end - pos, "%sMESH",
+                                 pos == buf ? "" : " ");
+               if (os_snprintf_error(end - pos, ret))
+                       return pos - buf;
+               pos += ret;
+       }
+#endif /* CONFIG_MESH */
+
        return pos - buf;
 }
 
@@ -3583,6 +3820,10 @@ static int wpa_supplicant_ctrl_iface_get_capability(
                return ctrl_iface_get_capability_group(res, strict, &capa,
                                                       buf, buflen);
 
+       if (os_strcmp(field, "group_mgmt") == 0)
+               return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
+                                                           buf, buflen);
+
        if (os_strcmp(field, "key_mgmt") == 0)
                return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
                                                          buf, buflen);
@@ -3592,8 +3833,8 @@ static int wpa_supplicant_ctrl_iface_get_capability(
                                                       buf, buflen);
 
        if (os_strcmp(field, "auth_alg") == 0)
-               return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
-                                                         buf, buflen);
+               return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
+                                                         &capa, buf, buflen);
 
        if (os_strcmp(field, "modes") == 0)
                return ctrl_iface_get_capability_modes(res, strict, &capa,
@@ -4132,7 +4373,7 @@ static int wpa_supplicant_ctrl_iface_bss_expire_count(
 }
 
 
-static int wpa_supplicant_ctrl_iface_bss_flush(
+static void wpa_supplicant_ctrl_iface_bss_flush(
        struct wpa_supplicant *wpa_s, char *cmd)
 {
        int flush_age = atoi(cmd);
@@ -4141,7 +4382,6 @@ static int wpa_supplicant_ctrl_iface_bss_flush(
                wpa_bss_flush(wpa_s);
        else
                wpa_bss_flush_by_age(wpa_s, flush_age);
-       return 0;
 }
 
 
@@ -5357,6 +5597,27 @@ static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
                return -1;
        }
 
+       if (bss->ssid_len == 0) {
+               int found = 0;
+
+               wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
+                          " does not have SSID information", MAC2STR(bssid));
+
+               dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
+                                        list) {
+                       if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
+                           bss->ssid_len > 0) {
+                               found = 1;
+                               break;
+                       }
+               }
+
+               if (!found)
+                       return -1;
+               wpa_printf(MSG_DEBUG,
+                          "Found another matching BSS entry with SSID");
+       }
+
        return interworking_connect(wpa_s, bss);
 }
 
@@ -5670,14 +5931,6 @@ static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
 #endif /* CONFIG_HS20 */
 
 
-static int wpa_supplicant_ctrl_iface_sta_autoconnect(
-       struct wpa_supplicant *wpa_s, char *cmd)
-{
-       wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
-       return 0;
-}
-
-
 #ifdef CONFIG_AUTOSCAN
 
 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
@@ -5930,20 +6183,24 @@ static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
 
 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
 {
+#ifdef CONFIG_P2P
+       struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
+               wpa_s->global->p2p_init_wpa_s : wpa_s;
+#endif /* CONFIG_P2P */
+
        wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
 
 #ifdef CONFIG_P2P
-       wpas_p2p_cancel(wpa_s);
-       wpas_p2p_stop_find(wpa_s);
-       p2p_ctrl_flush(wpa_s);
-       wpas_p2p_group_remove(wpa_s, "*");
-       wpas_p2p_service_flush(wpa_s);
-       wpa_s->global->p2p_disabled = 0;
-       wpa_s->global->p2p_per_sta_psk = 0;
-       wpa_s->conf->num_sec_device_types = 0;
-       wpa_s->p2p_disable_ip_addr_req = 0;
-       os_free(wpa_s->global->p2p_go_avoid_freq.range);
-       wpa_s->global->p2p_go_avoid_freq.range = NULL;
+       wpas_p2p_cancel(p2p_wpa_s);
+       p2p_ctrl_flush(p2p_wpa_s);
+       wpas_p2p_group_remove(p2p_wpa_s, "*");
+       wpas_p2p_service_flush(p2p_wpa_s);
+       p2p_wpa_s->global->p2p_disabled = 0;
+       p2p_wpa_s->global->p2p_per_sta_psk = 0;
+       p2p_wpa_s->conf->num_sec_device_types = 0;
+       p2p_wpa_s->p2p_disable_ip_addr_req = 0;
+       os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
+       p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
 #endif /* CONFIG_P2P */
 
 #ifdef CONFIG_WPS_TESTING
@@ -5954,6 +6211,7 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
 #ifdef CONFIG_WPS
        wpa_s->wps_fragment_size = 0;
        wpas_wps_cancel(wpa_s);
+       wps_registrar_flush(wpa_s->wps->registrar);
 #endif /* CONFIG_WPS */
        wpa_s->after_wps = 0;
        wpa_s->known_wps_freq = 0;
@@ -5983,8 +6241,6 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
        wpa_s->sta_uapsd = 0;
 
        wpa_drv_radio_disable(wpa_s, 0);
-
-       wpa_bss_flush(wpa_s);
        wpa_blacklist_clear(wpa_s);
        wpa_s->extra_blacklist_count = 0;
        wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
@@ -6014,9 +6270,22 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
        wpa_s->ext_eapol_frame_io = 0;
 #ifdef CONFIG_TESTING_OPTIONS
        wpa_s->extra_roc_dur = 0;
+       wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
 #endif /* CONFIG_TESTING_OPTIONS */
 
        wpa_s->disconnected = 0;
+       os_free(wpa_s->next_scan_freqs);
+       wpa_s->next_scan_freqs = NULL;
+
+       wpa_bss_flush(wpa_s);
+       if (!dl_list_empty(&wpa_s->bss)) {
+               wpa_printf(MSG_DEBUG,
+                          "BSS table not empty after flush: %u entries, current_bss=%p bssid="
+                          MACSTR " pending_bssid=" MACSTR,
+                          dl_list_len(&wpa_s->bss), wpa_s->current_bss,
+                          MAC2STR(wpa_s->bssid),
+                          MAC2STR(wpa_s->pending_bssid));
+       }
 }
 
 
@@ -6256,6 +6525,13 @@ static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
                return;
        }
 
+       if (radio_work_pending(wpa_s, "scan")) {
+               wpa_printf(MSG_DEBUG,
+                          "Pending scan scheduled - reject new request");
+               *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
+               return;
+       }
+
        if (params) {
                if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
                        scan_only = 1;
@@ -6712,6 +6988,44 @@ done:
        return res < 0 ? -1 : 0;
 }
 
+
+static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
+{
+#ifdef WPA_TRACE_BFD
+       extern char wpa_trace_fail_func[256];
+       extern unsigned int wpa_trace_fail_after;
+       char *pos;
+
+       wpa_trace_fail_after = atoi(cmd);
+       pos = os_strchr(cmd, ':');
+       if (pos) {
+               pos++;
+               os_strlcpy(wpa_trace_fail_func, pos,
+                          sizeof(wpa_trace_fail_func));
+       } else {
+               wpa_trace_fail_after = 0;
+       }
+       return 0;
+#else /* WPA_TRACE_BFD */
+       return -1;
+#endif /* WPA_TRACE_BFD */
+}
+
+
+static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
+                                   char *buf, size_t buflen)
+{
+#ifdef WPA_TRACE_BFD
+       extern char wpa_trace_fail_func[256];
+       extern unsigned int wpa_trace_fail_after;
+
+       return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
+                          wpa_trace_fail_func);
+#else /* WPA_TRACE_BFD */
+       return -1;
+#endif /* WPA_TRACE_BFD */
+}
+
 #endif /* CONFIG_TESTING_OPTIONS */
 
 
@@ -6969,6 +7283,126 @@ static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
 }
 
 
+static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
+                                        char *cmd)
+{
+       char *token, *context = NULL;
+       unsigned int enable = ~0, type = 0;
+       u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
+       u8 *addr = NULL, *mask = NULL;
+
+       while ((token = str_token(cmd, " ", &context))) {
+               if (os_strcasecmp(token, "scan") == 0) {
+                       type |= MAC_ADDR_RAND_SCAN;
+               } else if (os_strcasecmp(token, "sched") == 0) {
+                       type |= MAC_ADDR_RAND_SCHED_SCAN;
+               } else if (os_strcasecmp(token, "pno") == 0) {
+                       type |= MAC_ADDR_RAND_PNO;
+               } else if (os_strcasecmp(token, "all") == 0) {
+                       type = wpa_s->mac_addr_rand_supported;
+               } else if (os_strncasecmp(token, "enable=", 7) == 0) {
+                       enable = atoi(token + 7);
+               } else if (os_strncasecmp(token, "addr=", 5) == 0) {
+                       addr = _addr;
+                       if (hwaddr_aton(token + 5, addr)) {
+                               wpa_printf(MSG_INFO,
+                                          "CTRL: Invalid MAC address: %s",
+                                          token);
+                               return -1;
+                       }
+               } else if (os_strncasecmp(token, "mask=", 5) == 0) {
+                       mask = _mask;
+                       if (hwaddr_aton(token + 5, mask)) {
+                               wpa_printf(MSG_INFO,
+                                          "CTRL: Invalid MAC address mask: %s",
+                                          token);
+                               return -1;
+                       }
+               } else {
+                       wpa_printf(MSG_INFO,
+                                  "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
+                                  token);
+                       return -1;
+               }
+       }
+
+       if (!type) {
+               wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
+               return -1;
+       }
+
+       if ((wpa_s->mac_addr_rand_supported & type) != type) {
+               wpa_printf(MSG_INFO,
+                          "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
+                          type, wpa_s->mac_addr_rand_supported);
+               return -1;
+       }
+
+       if (enable > 1) {
+               wpa_printf(MSG_INFO,
+                          "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
+               return -1;
+       }
+
+       if (!enable) {
+               wpas_mac_addr_rand_scan_clear(wpa_s, type);
+               if (wpa_s->pno) {
+                       if (type & MAC_ADDR_RAND_PNO) {
+                               wpas_stop_pno(wpa_s);
+                               wpas_start_pno(wpa_s);
+                       }
+               } else if (wpa_s->sched_scanning &&
+                          (type & MAC_ADDR_RAND_SCHED_SCAN)) {
+                       /* simulate timeout to restart the sched scan */
+                       wpa_s->sched_scan_timed_out = 1;
+                       wpa_s->prev_sched_ssid = NULL;
+                       wpa_supplicant_cancel_sched_scan(wpa_s);
+               }
+               return 0;
+       }
+
+       if ((addr && !mask) || (!addr && mask)) {
+               wpa_printf(MSG_INFO,
+                          "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
+               return -1;
+       }
+
+       if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
+               wpa_printf(MSG_INFO,
+                          "CTRL: MAC_RAND_SCAN cannot allow multicast address");
+               return -1;
+       }
+
+       if (type & MAC_ADDR_RAND_SCAN) {
+               wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
+                                           addr, mask);
+       }
+
+       if (type & MAC_ADDR_RAND_SCHED_SCAN) {
+               wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
+                                           addr, mask);
+
+               if (wpa_s->sched_scanning && !wpa_s->pno) {
+                       /* simulate timeout to restart the sched scan */
+                       wpa_s->sched_scan_timed_out = 1;
+                       wpa_s->prev_sched_ssid = NULL;
+                       wpa_supplicant_cancel_sched_scan(wpa_s);
+               }
+       }
+
+       if (type & MAC_ADDR_RAND_PNO) {
+               wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
+                                           addr, mask);
+               if (wpa_s->pno) {
+                       wpas_stop_pno(wpa_s);
+                       wpas_start_pno(wpa_s);
+               }
+       }
+
+       return 0;
+}
+
+
 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                                         char *buf, size_t *resp_len)
 {
@@ -7144,8 +7578,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                if (wpas_wps_er_start(wpa_s, buf + 13))
                        reply_len = -1;
        } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
-               if (wpas_wps_er_stop(wpa_s))
-                       reply_len = -1;
+               wpas_wps_er_stop(wpa_s);
        } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
                if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
                        reply_len = -1;
@@ -7185,6 +7618,12 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                        reply_len = -1;
 #endif /* CONFIG_IBSS_RSN */
 #ifdef CONFIG_MESH
+       } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
+               reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
+                       wpa_s, buf + 19, reply, reply_size);
+       } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
+               reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
+                       wpa_s, "", reply, reply_size);
        } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
                if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
                        reply_len = -1;
@@ -7476,8 +7915,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
                        reply_len = -1;
        } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
-               if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
-                       reply_len = -1;
+               wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
        } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
                if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
                        reply_len = -1;
@@ -7486,8 +7924,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                                                               buf + 17))
                        reply_len = -1;
        } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
-               if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
-                       reply_len = -1;
+               wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
 #ifdef CONFIG_TDLS
        } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
                if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
@@ -7498,6 +7935,14 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
                if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
                        reply_len = -1;
+       } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
+               if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
+                                                              buf + 17))
+                       reply_len = -1;
+       } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
+               if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
+                                                                     buf + 24))
+                       reply_len = -1;
 #endif /* CONFIG_TDLS */
        } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
                reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
@@ -7533,8 +7978,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
                if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
                        reply_len = -1;
-       } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
-               if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
+       } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
+               if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
                                reply_len = -1;
 #endif /* CONFIG_WNM */
        } else if (os_strcmp(buf, "FLUSH") == 0) {
@@ -7563,6 +8008,11 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
                if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
                        reply_len = -1;
+       } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
+               if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
+                       reply_len = -1;
+       } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
+               reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
 #endif /* CONFIG_TESTING_OPTIONS */
        } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
                if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
@@ -7578,6 +8028,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                        reply_len = -1;
        } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
                wpas_ctrl_iface_erp_flush(wpa_s);
+       } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
+               if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
+                       reply_len = -1;
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;
@@ -7834,6 +8287,8 @@ static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
                "P2P_PRESENCE_REQ ",
                "P2P_EXT_LISTEN ",
                "P2P_REMOVE_CLIENT ",
+               "WPS_NFC_TOKEN ",
+               "WPS_NFC_TAG_READ ",
                "NFC_GET_HANDOVER_SEL ",
                "NFC_GET_HANDOVER_REQ ",
                "NFC_REPORT_HANDOVER ",