MBO: Send WNM-Notification when cellular capabilities change
[mech_eap.git] / wpa_supplicant / ctrl_iface.c
index 1f4630f..f585b92 100644 (file)
@@ -371,6 +371,20 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
                wps_corrupt_pkhash = atoi(value);
                wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
                           wps_corrupt_pkhash);
+       } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
+               if (value[0] == '\0') {
+                       wps_force_auth_types_in_use = 0;
+               } else {
+                       wps_force_auth_types = strtol(value, NULL, 0);
+                       wps_force_auth_types_in_use = 1;
+               }
+       } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
+               if (value[0] == '\0') {
+                       wps_force_encr_types_in_use = 0;
+               } else {
+                       wps_force_encr_types = strtol(value, NULL, 0);
+                       wps_force_encr_types_in_use = 1;
+               }
 #endif /* CONFIG_WPS_TESTING */
        } else if (os_strcasecmp(cmd, "ampdu") == 0) {
                if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
@@ -476,6 +490,12 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_NO_CONFIG_BLOBS */
        } else if (os_strcasecmp(cmd, "setband") == 0) {
                ret = wpas_ctrl_set_band(wpa_s, value);
+#ifdef CONFIG_MBO
+       } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
+               ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
+       } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
+               wpas_mbo_update_cell_capa(wpa_s, atoi(value));
+#endif /* CONFIG_MBO */
        } else {
                value[-1] = '=';
                ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
@@ -942,7 +962,8 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
        if (os_strcmp(cmd, "any") == 0)
                _bssid = NULL;
        else if (os_strcmp(cmd, "get") == 0) {
-               ret = wps_generate_pin();
+               if (wps_generate_pin((unsigned int *) &ret) < 0)
+                       return -1;
                goto done;
        } else if (hwaddr_aton(cmd, bssid)) {
                wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
@@ -3937,6 +3958,15 @@ static int wpa_supplicant_ctrl_iface_get_capability(
        }
 #endif /* CONFIG_FIPS */
 
+#ifdef CONFIG_ACS
+       if (os_strcmp(field, "acs") == 0) {
+               res = os_snprintf(buf, buflen, "ACS");
+               if (os_snprintf_error(buflen, res))
+                       return -1;
+               return res;
+       }
+#endif /* CONFIG_ACS */
+
        wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
                   field);
 
@@ -4689,7 +4719,7 @@ static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
                        return -1;
                }
 
-               if (isblank(*last)) {
+               if (isblank((unsigned char) *last)) {
                        i++;
                        break;
                }
@@ -4902,6 +4932,8 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
        int freq = 0;
        int pd;
        int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
+       u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
+       size_t group_ssid_len = 0;
 
        if (!wpa_s->global->p2p_init_wpa_s)
                return -1;
@@ -4914,7 +4946,7 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
        /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
         * [persistent|persistent=<network id>]
         * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
-        * [ht40] [vht] [auto] */
+        * [ht40] [vht] [auto] [ssid=<hexdump>] */
 
        if (hwaddr_aton(cmd, addr))
                return -1;
@@ -4974,6 +5006,22 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
        if (max_oper_chwidth < 0)
                return -1;
 
+       pos2 = os_strstr(pos, " ssid=");
+       if (pos2) {
+               char *end;
+
+               pos2 += 6;
+               end = os_strchr(pos2, ' ');
+               if (!end)
+                       group_ssid_len = os_strlen(pos2) / 2;
+               else
+                       group_ssid_len = (end - pos2) / 2;
+               if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
+                   hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
+                       return -1;
+               group_ssid = _group_ssid;
+       }
+
        if (os_strncmp(pos, "pin", 3) == 0) {
                /* Request random PIN (to be displayed) and enable the PIN */
                wps_method = WPS_PIN_DISPLAY;
@@ -4999,7 +5047,8 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
        new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
                                   persistent_group, automatic, join,
                                   auth, go_intent, freq, freq2, persistent_id,
-                                  pd, ht40, vht, max_oper_chwidth);
+                                  pd, ht40, vht, max_oper_chwidth,
+                                  group_ssid, group_ssid_len);
        if (new_pin == -2) {
                os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
                return 25;
@@ -6450,7 +6499,7 @@ static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
        if (subtypes == 0)
                return -1;
 
-       return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
+       return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
 }
 
 
@@ -6473,7 +6522,7 @@ static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
 
        ret = hs20_anqp_send_req(wpa_s, addr,
                                 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
-                                buf, len);
+                                buf, len, 0);
 
        os_free(buf);
 
@@ -6519,14 +6568,59 @@ static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
 
        ret = hs20_anqp_send_req(wpa_s, dst_addr,
                                 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
-                                buf, len);
+                                buf, len, 0);
        os_free(buf);
 
        return ret;
 }
 
 
-static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
+static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
+                        int buflen)
+{
+       u8 dst_addr[ETH_ALEN];
+       int used;
+       char *ctx = NULL, *icon, *poffset, *psize;
+
+       used = hwaddr_aton2(cmd, dst_addr);
+       if (used < 0)
+               return -1;
+       cmd += used;
+
+       icon = str_token(cmd, " ", &ctx);
+       poffset = str_token(cmd, " ", &ctx);
+       psize = str_token(cmd, " ", &ctx);
+       if (!icon || !poffset || !psize)
+               return -1;
+
+       wpa_s->fetch_osu_icon_in_progress = 0;
+       return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
+                            reply, buflen);
+}
+
+
+static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
+{
+       u8 dst_addr[ETH_ALEN];
+       int used;
+       char *icon;
+
+       if (!cmd[0])
+               return hs20_del_icon(wpa_s, NULL, NULL);
+
+       used = hwaddr_aton2(cmd, dst_addr);
+       if (used < 0)
+               return -1;
+
+       while (cmd[used] == ' ')
+               used++;
+       icon = cmd[used] ? &cmd[used] : NULL;
+
+       return hs20_del_icon(wpa_s, dst_addr, icon);
+}
+
+
+static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
 {
        u8 dst_addr[ETH_ALEN];
        int used;
@@ -6542,7 +6636,7 @@ static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
 
        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));
+                                 (u8 *) icon, os_strlen(icon), inmem);
 }
 
 #endif /* CONFIG_HS20 */
@@ -6632,14 +6726,27 @@ static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
 
 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
 {
-       int query_reason;
+       int query_reason, list = 0;
 
        query_reason = atoi(cmd);
 
-       wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
-                  query_reason);
+       cmd = os_strchr(cmd, ' ');
+       if (cmd) {
+               cmd++;
+               if (os_strncmp(cmd, "list", 4) == 0) {
+                       list = 1;
+               } else {
+                       wpa_printf(MSG_DEBUG, "WNM Query: Invalid option %s",
+                                  cmd);
+                       return -1;
+               }
+       }
+
+       wpa_printf(MSG_DEBUG,
+                  "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
+                  query_reason, list ? " candidate list" : "");
 
-       return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
+       return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, list);
 }
 
 #endif /* CONFIG_WNM */
@@ -6704,6 +6811,28 @@ static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
 }
 
 
+static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
+                                         const char *cmd)
+{
+       const char *pos;
+       int threshold = 0;
+       int hysteresis = 0;
+
+       if (wpa_s->bgscan && wpa_s->bgscan_priv) {
+               wpa_printf(MSG_DEBUG,
+                          "Reject SIGNAL_MONITOR command - bgscan is active");
+               return -1;
+       }
+       pos = os_strstr(cmd, "THRESHOLD=");
+       if (pos)
+               threshold = atoi(pos + 10);
+       pos = os_strstr(cmd, "HYSTERESIS=");
+       if (pos)
+               hysteresis = atoi(pos + 11);
+       return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
+}
+
+
 static int wpas_ctrl_iface_get_pref_freq_list(
        struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
 {
@@ -6808,13 +6937,13 @@ static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
 
        /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
        vendor_id = strtoul(cmd, &pos, 16);
-       if (!isblank(*pos))
+       if (!isblank((unsigned char) *pos))
                return -EINVAL;
 
        subcmd = strtoul(pos, &pos, 10);
 
        if (*pos != '\0') {
-               if (!isblank(*pos++))
+               if (!isblank((unsigned char) *pos++))
                        return -EINVAL;
                data_len = os_strlen(pos);
        }
@@ -6864,10 +6993,18 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
 
        wpas_abort_ongoing_scan(wpa_s);
 
+       if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
+               /*
+                * Avoid possible auto connect re-connection on getting
+                * disconnected due to state flush.
+                */
+               wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
+       }
+
 #ifdef CONFIG_P2P
+       wpas_p2p_group_remove(p2p_wpa_s, "*");
        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;
@@ -6884,6 +7021,8 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
        wps_version_number = 0x20;
        wps_testing_dummy_cred = 0;
        wps_corrupt_pkhash = 0;
+       wps_force_auth_types_in_use = 0;
+       wps_force_encr_types_in_use = 0;
 #endif /* CONFIG_WPS_TESTING */
 #ifdef CONFIG_WPS
        wpa_s->wps_fragment_size = 0;
@@ -6943,6 +7082,7 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
 #ifdef CONFIG_INTERWORKING
 #ifdef CONFIG_HS20
        hs20_cancel_fetch_osu(wpa_s);
+       hs20_del_icon(wpa_s, NULL, NULL);
 #endif /* CONFIG_HS20 */
 #endif /* CONFIG_INTERWORKING */
 
@@ -6952,6 +7092,7 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
        wpa_s->extra_roc_dur = 0;
        wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
        wpa_s->p2p_go_csa_on_inv = 0;
+       wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
 #endif /* CONFIG_TESTING_OPTIONS */
 
        wpa_s->disconnected = 0;
@@ -7608,6 +7749,8 @@ static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
                                            char *cmd)
 {
        int enabled = atoi(cmd);
+       char *pos;
+       const char *ifname;
 
        if (!enabled) {
                if (wpa_s->l2_test) {
@@ -7621,7 +7764,13 @@ static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
        if (wpa_s->l2_test)
                return 0;
 
-       wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
+       pos = os_strstr(cmd, " ifname=");
+       if (pos)
+               ifname = pos + 8;
+       else
+               ifname = wpa_s->ifname;
+
+       wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
                                        ETHERTYPE_IP, wpas_data_test_rx,
                                        wpa_s, 1);
        if (wpa_s->l2_test == NULL)
@@ -7841,6 +7990,35 @@ static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
                                      (void *) (intptr_t) count);
 }
 
+
+static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
+                                  const char *cmd)
+{
+       struct wpabuf *buf;
+       size_t len;
+
+       len = os_strlen(cmd);
+       if (len & 1)
+               return -1;
+       len /= 2;
+
+       if (len == 0) {
+               buf = NULL;
+       } else {
+               buf = wpabuf_alloc(len);
+               if (buf == NULL)
+                       return -1;
+
+               if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
+                       wpabuf_free(buf);
+                       return -1;
+               }
+       }
+
+       wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
+       return 0;
+}
+
 #endif /* CONFIG_TESTING_OPTIONS */
 
 
@@ -8536,7 +8714,15 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                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)
+               if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
+                       reply_len = -1;
+       } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
+               if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
+                       reply_len = -1;
+       } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
+               reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
+       } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
+               if (del_hs20_icon(wpa_s, buf + 14) < 0)
                        reply_len = -1;
        } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
                if (hs20_fetch_osu(wpa_s) < 0)
@@ -8739,6 +8925,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
                reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
                                                       reply_size);
+       } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
+               if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
+                       reply_len = -1;
        } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
                reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
                                                       reply_size);
@@ -8805,6 +8994,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
                if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
                        reply_len = -1;
+       } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
+               if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
+                       reply_len = -1;
 #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)