]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - wpa_supplicant/ctrl_iface.c
Add a reattach command for fast reassociate-back-to-same-BSS
[thirdparty/hostap.git] / wpa_supplicant / ctrl_iface.c
index 663f4097405135a96b6356aa2ce1550d47472ed9..98c4b65541100ecafc882ebad2efd8354315e9d1 100644 (file)
 #include "blacklist.h"
 #include "autoscan.h"
 #include "wnm_sta.h"
+#include "offchannel.h"
 
 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
                                            char *buf, int len);
 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
                                                  char *buf, int len);
 
-
-static int pno_start(struct wpa_supplicant *wpa_s)
-{
-       int ret, interval;
-       size_t i, num_ssid;
-       struct wpa_ssid *ssid;
-       struct wpa_driver_scan_params params;
-
-       if (wpa_s->pno || wpa_s->pno_sched_pending)
-               return 0;
-
-       if ((wpa_s->wpa_state > WPA_SCANNING) &&
-           (wpa_s->wpa_state <= WPA_COMPLETED)) {
-               wpa_printf(MSG_ERROR, "PNO: In assoc process");
-               return -EAGAIN;
-       }
-
-       if (wpa_s->wpa_state == WPA_SCANNING) {
-               wpa_supplicant_cancel_scan(wpa_s);
-               if (wpa_s->sched_scanning) {
-                       wpa_printf(MSG_DEBUG, "Schedule PNO on completion of "
-                                  "ongoing sched scan");
-                       wpa_supplicant_cancel_sched_scan(wpa_s);
-                       wpa_s->pno_sched_pending = 1;
-                       return 0;
-               }
-       }
-
-       os_memset(&params, 0, sizeof(params));
-
-       num_ssid = 0;
-       ssid = wpa_s->conf->ssid;
-       while (ssid) {
-               if (!wpas_network_disabled(wpa_s, ssid))
-                       num_ssid++;
-               ssid = ssid->next;
-       }
-       if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
-               wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
-                          "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
-               num_ssid = WPAS_MAX_SCAN_SSIDS;
-       }
-
-       if (num_ssid == 0) {
-               wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
-               return -1;
-       }
-
-       params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
-                                       num_ssid);
-       if (params.filter_ssids == NULL)
-               return -1;
-       i = 0;
-       ssid = wpa_s->conf->ssid;
-       while (ssid) {
-               if (!wpas_network_disabled(wpa_s, ssid)) {
-                       params.ssids[i].ssid = ssid->ssid;
-                       params.ssids[i].ssid_len = ssid->ssid_len;
-                       params.num_ssids++;
-                       os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
-                                 ssid->ssid_len);
-                       params.filter_ssids[i].ssid_len = ssid->ssid_len;
-                       params.num_filter_ssids++;
-                       i++;
-                       if (i == num_ssid)
-                               break;
-               }
-               ssid = ssid->next;
-       }
-
-       if (wpa_s->conf->filter_rssi)
-               params.filter_rssi = wpa_s->conf->filter_rssi;
-
-       interval = wpa_s->conf->sched_scan_interval ?
-               wpa_s->conf->sched_scan_interval : 10;
-
-       ret = wpa_supplicant_start_sched_scan(wpa_s, &params, interval);
-       os_free(params.filter_ssids);
-       if (ret == 0)
-               wpa_s->pno = 1;
-       return ret;
-}
-
-
-static int pno_stop(struct wpa_supplicant *wpa_s)
-{
-       int ret = 0;
-
-       if (wpa_s->pno || wpa_s->sched_scanning) {
-               wpa_s->pno = 0;
-               ret = wpa_supplicant_stop_sched_scan(wpa_s);
-       }
-
-       wpa_s->pno_sched_pending = 0;
-
-       if (wpa_s->wpa_state == WPA_SCANNING)
-               wpa_supplicant_req_scan(wpa_s, 0, 0);
-
-       return ret;
-}
-
-
 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
 {
        char *pos;
@@ -391,9 +290,9 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_TDLS */
        } else if (os_strcasecmp(cmd, "pno") == 0) {
                if (atoi(value))
-                       ret = pno_start(wpa_s);
+                       ret = wpas_start_pno(wpa_s);
                else
-                       ret = pno_stop(wpa_s);
+                       ret = wpas_stop_pno(wpa_s);
        } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
                int disabled = atoi(value);
                if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
@@ -452,6 +351,10 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
                ret = set_disallow_aps(wpa_s, value);
        } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
                wpa_s->no_keep_alive = !!atoi(value);
+#ifdef CONFIG_TESTING_OPTIONS
+       } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
+               wpa_s->ext_mgmt_frame_handling = !!atoi(value);
+#endif /* CONFIG_TESTING_OPTIONS */
        } else {
                value[-1] = '=';
                ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
@@ -1106,34 +1009,6 @@ static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
 }
 
 
-static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s,
-                                        char *cmd, char *reply,
-                                        size_t max_len)
-{
-       size_t len;
-       struct wpabuf *buf;
-       int ret;
-
-       len = os_strlen(cmd);
-       if (len & 0x01)
-               return -1;
-       len /= 2;
-
-       buf = wpabuf_alloc(len);
-       if (buf == NULL)
-               return -1;
-       if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
-               wpabuf_free(buf);
-               return -1;
-       }
-
-       ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf);
-       wpabuf_free(buf);
-
-       return ret;
-}
-
-
 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
                                         char *cmd)
 {
@@ -1582,6 +1457,9 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
 {
        char *pos, *end, tmp[30];
        int res, verbose, wps, ret;
+#ifdef CONFIG_HS20
+       const u8 *hs20;
+#endif /* CONFIG_HS20 */
 
        if (os_strcmp(params, "-DRIVER") == 0)
                return wpa_drv_status(wpa_s, buf, buflen);
@@ -1720,10 +1598,16 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
 
 #ifdef CONFIG_HS20
        if (wpa_s->current_bss &&
-           wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
+           (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
+                                         HS20_IE_VENDOR_TYPE)) &&
            wpa_s->wpa_proto == WPA_PROTO_RSN &&
            wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
-               ret = os_snprintf(pos, end - pos, "hs20=1\n");
+               int release = 1;
+               if (hs20[1] >= 5) {
+                       u8 rel_num = (hs20[6] & 0xf0) >> 4;
+                       release = rel_num + 1;
+               }
+               ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
@@ -1739,15 +1623,38 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
                        if (wpa_s->current_ssid->parent_cred != cred)
                                continue;
 
-                       for (i = 0; cred->domain && i < cred->num_domain; i++) {
+                       if (cred->provisioning_sp) {
                                ret = os_snprintf(pos, end - pos,
-                                                 "home_sp=%s\n",
-                                                 cred->domain[i]);
+                                                 "provisioning_sp=%s\n",
+                                                 cred->provisioning_sp);
                                if (ret < 0 || ret >= end - pos)
                                        return pos - buf;
                                pos += ret;
                        }
 
+                       if (!cred->domain)
+                               goto no_domain;
+
+                       i = 0;
+                       if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
+                               struct wpabuf *names =
+                                       wpa_s->current_bss->anqp->domain_name;
+                               for (i = 0; names && i < cred->num_domain; i++)
+                               {
+                                       if (domain_name_list_contains(
+                                                   names, cred->domain[i], 1))
+                                               break;
+                               }
+                               if (i == cred->num_domain)
+                                       i = 0; /* show first entry by default */
+                       }
+                       ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
+                                         cred->domain[i]);
+                       if (ret < 0 || ret >= end - pos)
+                               return pos - buf;
+                       pos += ret;
+
+               no_domain:
                        if (wpa_s->current_bss == NULL ||
                            wpa_s->current_bss->anqp == NULL)
                                res = -1;
@@ -2070,7 +1977,8 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
                                    const u8 *ie, size_t ie_len)
 {
        struct wpa_ie_data data;
-       int first, ret;
+       char *start;
+       int ret;
 
        ret = os_snprintf(pos, end - pos, "[%s-", proto);
        if (ret < 0 || ret >= end - pos)
@@ -2085,62 +1993,58 @@ static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
                return pos;
        }
 
-       first = 1;
+       start = pos;
        if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
-               ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
+               ret = os_snprintf(pos, end - pos, "%sEAP",
+                                 pos == start ? "" : "+");
                if (ret < 0 || ret >= end - pos)
                        return pos;
                pos += ret;
-               first = 0;
        }
        if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
-               ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
+               ret = os_snprintf(pos, end - pos, "%sPSK",
+                                 pos == start ? "" : "+");
                if (ret < 0 || ret >= end - pos)
                        return pos;
                pos += ret;
-               first = 0;
        }
        if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
-               ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
+               ret = os_snprintf(pos, end - pos, "%sNone",
+                                 pos == start ? "" : "+");
                if (ret < 0 || ret >= end - pos)
                        return pos;
                pos += ret;
-               first = 0;
        }
 #ifdef CONFIG_IEEE80211R
        if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
                ret = os_snprintf(pos, end - pos, "%sFT/EAP",
-                                 first ? "" : "+");
+                                 pos == start ? "" : "+");
                if (ret < 0 || ret >= end - pos)
                        return pos;
                pos += ret;
-               first = 0;
        }
        if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
                ret = os_snprintf(pos, end - pos, "%sFT/PSK",
-                                 first ? "" : "+");
+                                 pos == start ? "" : "+");
                if (ret < 0 || ret >= end - pos)
                        return pos;
                pos += ret;
-               first = 0;
        }
 #endif /* CONFIG_IEEE80211R */
 #ifdef CONFIG_IEEE80211W
        if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
                ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
-                                 first ? "" : "+");
+                                 pos == start ? "" : "+");
                if (ret < 0 || ret >= end - pos)
                        return pos;
                pos += ret;
-               first = 0;
        }
        if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
                ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
-                                 first ? "" : "+");
+                                 pos == start ? "" : "+");
                if (ret < 0 || ret >= end - pos)
                        return pos;
                pos += ret;
-               first = 0;
        }
 #endif /* CONFIG_IEEE80211W */
 
@@ -2714,7 +2618,8 @@ static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
        int id;
        struct wpa_cred *cred, *prev;
 
-       /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
+       /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
+        * "provisioning_sp=<FQDN> */
        if (os_strcmp(cmd, "all") == 0) {
                wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
                cred = wpa_s->conf->cred;
@@ -2747,6 +2652,20 @@ static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
                return 0;
        }
 
+       if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
+               wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
+                          cmd + 16);
+               cred = wpa_s->conf->cred;
+               while (cred) {
+                       prev = cred;
+                       cred = cred->next;
+                       if (prev->provisioning_sp &&
+                           os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
+                               wpas_ctrl_remove_cred(wpa_s, prev);
+               }
+               return 0;
+       }
+
        id = atoi(cmd);
        wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
 
@@ -2843,7 +2762,7 @@ static int ctrl_iface_get_capability_pairwise(int res, char *strict,
                                              struct wpa_driver_capa *capa,
                                              char *buf, size_t buflen)
 {
-       int ret, first = 1;
+       int ret;
        char *pos, *end;
        size_t len;
        unsigned int i;
@@ -2863,11 +2782,11 @@ static int ctrl_iface_get_capability_pairwise(int res, char *strict,
        for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
                if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
                        ret = os_snprintf(pos, end - pos, "%s%s",
-                                         first ? "" : " ", ciphers[i].name);
+                                         pos == buf ? "" : " ",
+                                         ciphers[i].name);
                        if (ret < 0 || ret >= end - pos)
                                return pos - buf;
                        pos += ret;
-                       first = 0;
                }
        }
 
@@ -2879,7 +2798,7 @@ static int ctrl_iface_get_capability_group(int res, char *strict,
                                           struct wpa_driver_capa *capa,
                                           char *buf, size_t buflen)
 {
-       int ret, first = 1;
+       int ret;
        char *pos, *end;
        size_t len;
        unsigned int i;
@@ -2899,11 +2818,11 @@ static int ctrl_iface_get_capability_group(int res, char *strict,
        for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
                if (capa->enc & ciphers[i].capa) {
                        ret = os_snprintf(pos, end - pos, "%s%s",
-                                         first ? "" : " ", ciphers[i].name);
+                                         pos == buf ? "" : " ",
+                                         ciphers[i].name);
                        if (ret < 0 || ret >= end - pos)
                                return pos - buf;
                        pos += ret;
-                       first = 0;
                }
        }
 
@@ -2968,7 +2887,7 @@ static int ctrl_iface_get_capability_proto(int res, char *strict,
                                           struct wpa_driver_capa *capa,
                                           char *buf, size_t buflen)
 {
-       int ret, first = 1;
+       int ret;
        char *pos, *end;
        size_t len;
 
@@ -2986,20 +2905,20 @@ static int ctrl_iface_get_capability_proto(int res, char *strict,
 
        if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
                              WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
-               ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
+               ret = os_snprintf(pos, end - pos, "%sRSN",
+                                 pos == buf ? "" : " ");
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
-               first = 0;
        }
 
        if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
                              WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
-               ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
+               ret = os_snprintf(pos, end - pos, "%sWPA",
+                                 pos == buf ? "" : " ");
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
-               first = 0;
        }
 
        return pos - buf;
@@ -3010,7 +2929,7 @@ static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
                                              struct wpa_driver_capa *capa,
                                              char *buf, size_t buflen)
 {
-       int ret, first = 1;
+       int ret;
        char *pos, *end;
        size_t len;
 
@@ -3027,28 +2946,27 @@ static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
        }
 
        if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
-               ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
+               ret = os_snprintf(pos, end - pos, "%sOPEN",
+                                 pos == buf ? "" : " ");
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
-               first = 0;
        }
 
        if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
                ret = os_snprintf(pos, end - pos, "%sSHARED",
-                                 first ? "" : " ");
+                                 pos == buf ? "" : " ");
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
-               first = 0;
        }
 
        if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
-               ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
+               ret = os_snprintf(pos, end - pos, "%sLEAP",
+                                 pos == buf ? "" : " ");
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
-               first = 0;
        }
 
        return pos - buf;
@@ -3059,7 +2977,7 @@ static int ctrl_iface_get_capability_modes(int res, char *strict,
                                           struct wpa_driver_capa *capa,
                                           char *buf, size_t buflen)
 {
-       int ret, first = 1;
+       int ret;
        char *pos, *end;
        size_t len;
 
@@ -3076,19 +2994,19 @@ static int ctrl_iface_get_capability_modes(int res, char *strict,
        }
 
        if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
-               ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " ");
+               ret = os_snprintf(pos, end - pos, "%sIBSS",
+                                 pos == buf ? "" : " ");
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
-               first = 0;
        }
 
        if (capa->flags & WPA_DRIVER_FLAGS_AP) {
-               ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " ");
+               ret = os_snprintf(pos, end - pos, "%sAP",
+                                 pos == buf ? "" : " ");
                if (ret < 0 || ret >= end - pos)
                        return pos - buf;
                pos += ret;
-               first = 0;
        }
 
        return pos - buf;
@@ -3546,6 +3464,10 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
                                   anqp->hs20_wan_metrics);
                pos = anqp_add_hex(pos, end, "hs20_connection_capability",
                                   anqp->hs20_connection_capability);
+               pos = anqp_add_hex(pos, end, "hs20_operating_class",
+                                  anqp->hs20_operating_class);
+               pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
+                                  anqp->hs20_osu_providers_list);
 #endif /* CONFIG_HS20 */
        }
 #endif /* CONFIG_INTERWORKING */
@@ -5197,6 +5119,26 @@ static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
        return ret;
 }
 
+
+static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
+{
+       u8 dst_addr[ETH_ALEN];
+       int used;
+       char *icon;
+
+       used = hwaddr_aton2(cmd, dst_addr);
+       if (used < 0)
+               return -1;
+
+       while (cmd[used] == ' ')
+               used++;
+       icon = &cmd[used];
+
+       wpa_s->fetch_osu_icon_in_progress = 0;
+       return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
+                                 (u8 *) icon, os_strlen(icon));
+}
+
 #endif /* CONFIG_HS20 */
 
 
@@ -5421,6 +5363,63 @@ static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
 #endif /* ANDROID */
 
 
+static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
+                                    char *buf, size_t buflen)
+{
+       int ret;
+       char *pos;
+       u8 *data = NULL;
+       unsigned int vendor_id, subcmd;
+       struct wpabuf *reply;
+       size_t data_len = 0;
+
+       /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
+       vendor_id = strtoul(cmd, &pos, 16);
+       if (!isblank(*pos))
+               return -EINVAL;
+
+       subcmd = strtoul(pos, &pos, 10);
+
+       if (*pos != '\0') {
+               if (!isblank(*pos++))
+                       return -EINVAL;
+               data_len = os_strlen(pos);
+       }
+
+       if (data_len) {
+               data_len /= 2;
+               data = os_malloc(data_len);
+               if (!data)
+                       return -ENOBUFS;
+
+               if (hexstr2bin(pos, data, data_len)) {
+                       wpa_printf(MSG_DEBUG,
+                                  "Vendor command: wrong parameter format");
+                       os_free(data);
+                       return -EINVAL;
+               }
+       }
+
+       reply = wpabuf_alloc((buflen - 1) / 2);
+       if (!reply) {
+               os_free(data);
+               return -ENOBUFS;
+       }
+
+       ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
+                                reply);
+
+       if (ret == 0)
+               ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
+                                      wpabuf_len(reply));
+
+       wpabuf_free(reply);
+       os_free(data);
+
+       return ret;
+}
+
+
 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
 {
        wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
@@ -5482,14 +5481,21 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
        wpa_config_flush_blobs(wpa_s->conf);
        wpa_s->conf->auto_interworking = 0;
        wpa_s->conf->okc = 0;
-       wpa_s->conf->pmf = 0;
 
        wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
        wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
        wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
        eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
 
-       radio_remove_unstarted_work(wpa_s, NULL);
+       radio_remove_works(wpa_s, NULL, 1);
+
+       wpa_s->next_ssid = NULL;
+
+#ifdef CONFIG_INTERWORKING
+       hs20_cancel_fetch_osu(wpa_s);
+#endif /* CONFIG_INTERWORKING */
+
+       wpa_s->ext_mgmt_frame_handling = 0;
 }
 
 
@@ -5541,6 +5547,10 @@ static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
        struct wpa_external_work *ework = work->ctx;
 
        if (deinit) {
+               if (work->started)
+                       eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
+                                            work, NULL);
+
                os_free(ework);
                return;
        }
@@ -5774,6 +5784,103 @@ static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
 }
 
 
+#ifdef CONFIG_TESTING_OPTIONS
+
+static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
+                                      unsigned int freq, const u8 *dst,
+                                      const u8 *src, const u8 *bssid,
+                                      const u8 *data, size_t data_len,
+                                      enum offchannel_send_action_result
+                                      result)
+{
+       wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
+               " src=" MACSTR " bssid=" MACSTR " result=%s",
+               freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
+               result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
+               "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
+                            "NO_ACK" : "FAILED"));
+}
+
+
+static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
+{
+       char *pos, *param;
+       size_t len;
+       u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
+       int res, used;
+       int freq = 0, no_cck = 0, wait_time = 0;
+
+       /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
+        *    <action=Action frame payload> */
+
+       wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
+
+       pos = cmd;
+       used = hwaddr_aton2(pos, da);
+       if (used < 0)
+               return -1;
+       pos += used;
+       while (*pos == ' ')
+               pos++;
+       used = hwaddr_aton2(pos, bssid);
+       if (used < 0)
+               return -1;
+       pos += used;
+
+       param = os_strstr(pos, " freq=");
+       if (param) {
+               param += 6;
+               freq = atoi(param);
+       }
+
+       param = os_strstr(pos, " no_cck=");
+       if (param) {
+               param += 8;
+               no_cck = atoi(param);
+       }
+
+       param = os_strstr(pos, " wait_time=");
+       if (param) {
+               param += 11;
+               wait_time = atoi(param);
+       }
+
+       param = os_strstr(pos, " action=");
+       if (param == NULL)
+               return -1;
+       param += 8;
+
+       len = os_strlen(param);
+       if (len & 1)
+               return -1;
+       len /= 2;
+
+       buf = os_malloc(len);
+       if (buf == NULL)
+               return -1;
+
+       if (hexstr2bin(param, buf, len) < 0) {
+               os_free(buf);
+               return -1;
+       }
+
+       res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
+                                    buf, len, wait_time,
+                                    wpas_ctrl_iface_mgmt_tx_cb, no_cck);
+       os_free(buf);
+       return res;
+}
+
+
+static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
+{
+       wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
+       offchannel_send_action_done(wpa_s);
+}
+
+#endif /* CONFIG_TESTING_OPTIONS */
+
+
 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                                         char *buf, size_t *resp_len)
 {
@@ -5856,6 +5963,14 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                        reply_len = -1;
                else
                        wpas_request_connection(wpa_s);
+       } else if (os_strcmp(buf, "REATTACH") == 0) {
+               if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
+                   !wpa_s->current_ssid)
+                       reply_len = -1;
+               else {
+                       wpa_s->reattach = 1;
+                       wpas_request_connection(wpa_s);
+               }
        } else if (os_strcmp(buf, "RECONNECT") == 0) {
                if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
                        reply_len = -1;
@@ -5924,9 +6039,6 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
                reply_len = wpas_ctrl_nfc_get_handover_sel(
                        wpa_s, buf + 21, reply, reply_size);
-       } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
-               reply_len = wpas_ctrl_nfc_rx_handover_req(
-                       wpa_s, buf + 20, reply, reply_size);
        } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
                if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
                        reply_len = -1;
@@ -6120,6 +6232,14 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
                if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
                        reply_len = -1;
+       } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
+               if (hs20_icon_request(wpa_s, buf + 18) < 0)
+                       reply_len = -1;
+       } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
+               if (hs20_fetch_osu(wpa_s) < 0)
+                       reply_len = -1;
+       } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
+               hs20_cancel_fetch_osu(wpa_s);
 #endif /* CONFIG_HS20 */
        } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
        {
@@ -6292,6 +6412,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
                                                      reply_size);
 #endif /* ANDROID */
+       } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
+               reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
+                                                     reply_size);
        } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
                pmksa_cache_clear_current(wpa_s->wpa);
                eapol_sm_request_reauth(wpa_s->eapol);
@@ -6308,6 +6431,13 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
                reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
                                                 reply_size);
+#ifdef CONFIG_TESTING_OPTIONS
+       } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
+               if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
+                       reply_len = -1;
+       } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
+               wpas_ctrl_iface_mgmt_tx_done(wpa_s);
+#endif /* CONFIG_TESTING_OPTIONS */
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;
@@ -6788,6 +6918,12 @@ char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
        } else if (os_strcmp(buf, "STATUS") == 0) {
                reply_len = wpas_global_ctrl_iface_status(global, reply,
                                                          reply_size);
+#ifdef CONFIG_MODULE_TESTS
+       } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
+               int wpas_module_tests(void);
+               if (wpas_module_tests() < 0)
+                       reply_len = -1;
+#endif /* CONFIG_MODULE_TESTS */
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;