Merge branch 'moonshot' of ssh://moonshot.suchdamage.org:822/srv/git/libeap into...
[libeap.git] / wpa_supplicant / ctrl_iface.c
index 97f8e28..6c7b561 100644 (file)
@@ -84,6 +84,29 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
                        ret = -1;
        } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
                wpa_s->wps_fragment_size = atoi(value);
+#ifdef CONFIG_WPS_TESTING
+       } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
+               long int val;
+               val = strtol(value, NULL, 0);
+               if (val < 0 || val > 0xff) {
+                       ret = -1;
+                       wpa_printf(MSG_DEBUG, "WPS: Invalid "
+                                  "wps_version_number %ld", val);
+               } else {
+                       wps_version_number = val;
+                       wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
+                                  "version %u.%u",
+                                  (wps_version_number & 0xf0) >> 4,
+                                  wps_version_number & 0x0f);
+               }
+       } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
+               wps_testing_dummy_cred = atoi(value);
+               wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
+                          wps_testing_dummy_cred);
+#endif /* CONFIG_WPS_TESTING */
+       } else if (os_strcasecmp(cmd, "ampdu") == 0) {
+               if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
+                       ret = -1;
        } else {
                value[-1] = '=';
                ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
@@ -216,7 +239,8 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
 #endif /* CONFIG_AP */
 
        if (pin) {
-               ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0);
+               ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
+                                        DEV_PW_DEFAULT);
                if (ret < 0)
                        return -1;
                ret = os_snprintf(buf, buflen, "%s", pin);
@@ -225,7 +249,7 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
                return ret;
        }
 
-       ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0);
+       ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
        if (ret < 0)
                return -1;
 
@@ -237,6 +261,51 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
 }
 
 
+static int wpa_supplicant_ctrl_iface_wps_check_pin(
+       struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
+{
+       char pin[9];
+       size_t len;
+       char *pos;
+       int ret;
+
+       wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
+                             (u8 *) cmd, os_strlen(cmd));
+       for (pos = cmd, len = 0; *pos != '\0'; pos++) {
+               if (*pos < '0' || *pos > '9')
+                       continue;
+               pin[len++] = *pos;
+               if (len == 9) {
+                       wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
+                       return -1;
+               }
+       }
+       if (len != 4 && len != 8) {
+               wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
+               return -1;
+       }
+       pin[len] = '\0';
+
+       if (len == 8) {
+               unsigned int pin_val;
+               pin_val = atoi(pin);
+               if (!wps_pin_valid(pin_val)) {
+                       wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
+                       ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
+                       if (ret < 0 || (size_t) ret >= buflen)
+                               return -1;
+                       return ret;
+               }
+       }
+
+       ret = os_snprintf(buf, buflen, "%s", pin);
+       if (ret < 0 || (size_t) ret >= buflen)
+               return -1;
+
+       return ret;
+}
+
+
 #ifdef CONFIG_WPS_OOB
 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
                                             char *cmd)
@@ -597,6 +666,22 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
                pos += ret;
        }
 
+#ifdef CONFIG_P2P
+       if (wpa_s->global->p2p) {
+               ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
+                                 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
+                         MAC2STR(wpa_s->own_addr));
+       if (ret < 0 || ret >= end - pos)
+               return pos - buf;
+       pos += ret;
+#endif /* CONFIG_P2P */
+
        if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
            wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
                res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
@@ -894,7 +979,13 @@ static int wpa_supplicant_ctrl_iface_scan_result(
 {
        char *pos, *end;
        int ret;
-       const u8 *ie, *ie2;
+       const u8 *ie, *ie2, *p2p;
+
+       p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
+       if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
+           os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
+           0)
+               return 0; /* Do not show P2P listen discovery results here */
 
        pos = buf;
        end = buf + buflen;
@@ -929,6 +1020,12 @@ static int wpa_supplicant_ctrl_iface_scan_result(
                        return pos - buf;
                pos += ret;
        }
+       if (p2p) {
+               ret = os_snprintf(pos, end - pos, "[P2P]");
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
 
        ret = os_snprintf(pos, end - pos, "\t%s",
                          wpa_ssid_txt(bss->ssid, bss->ssid_len));
@@ -1648,6 +1745,12 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
                        return pos - buf;
                pos += ret;
        }
+       if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
+               ret = os_snprintf(pos, end - pos, "[P2P]");
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
 
        ret = os_snprintf(pos, end - pos, "\n");
        if (ret < 0 || ret >= end - pos)
@@ -1704,6 +1807,14 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
        pos += ret;
 #endif /* CONFIG_WPS */
 
+#ifdef CONFIG_P2P
+       ie = (const u8 *) (bss + 1);
+       ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
+       if (ret < 0 || ret >= end - pos)
+               return pos - buf;
+       pos += ret;
+#endif /* CONFIG_P2P */
+
        return pos - buf;
 }
 
@@ -1813,7 +1924,7 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
        int freq = 0;
 
        /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] [persistent]
-        * [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */
+        * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */
 
        if (hwaddr_aton(cmd, addr))
                return -1;
@@ -1864,6 +1975,14 @@ 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, join, auth, go_intent,
                                   freq);
+       if (new_pin == -2) {
+               os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
+               return 25;
+       }
+       if (new_pin == -3) {
+               os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
+               return 25;
+       }
        if (new_pin < 0)
                return -1;
        if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
@@ -2395,9 +2514,18 @@ static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
                        return -1;
                wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
                           "start=%d duration=%d", count, start, duration);
-               return wpa_drv_set_noa(wpa_s, count, start, duration);
+               return wpas_p2p_set_noa(wpa_s, count, start, duration);
        }
 
+       if (os_strcmp(cmd, "ps") == 0)
+               return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
+
+       if (os_strcmp(cmd, "oppps") == 0)
+               return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
+
+       if (os_strcmp(cmd, "ctwindow") == 0)
+               return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
+
        if (os_strcmp(cmd, "disabled") == 0) {
                wpa_s->global->p2p_disabled = atoi(param);
                wpa_printf(MSG_DEBUG, "P2P functionality %s",
@@ -2405,11 +2533,77 @@ static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
                           "disabled" : "enabled");
                if (wpa_s->global->p2p_disabled) {
                        wpas_p2p_stop_find(wpa_s);
+                       os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
                        p2p_flush(wpa_s->global->p2p);
                }
                return 0;
        }
 
+       if (os_strcmp(cmd, "force_long_sd") == 0) {
+               wpa_s->force_long_sd = atoi(param);
+               return 0;
+       }
+
+       if (os_strcmp(cmd, "peer_filter") == 0) {
+               u8 addr[ETH_ALEN];
+               if (hwaddr_aton(param, addr))
+                       return -1;
+               p2p_set_peer_filter(wpa_s->global->p2p, addr);
+               return 0;
+       }
+
+       if (os_strcmp(cmd, "cross_connect") == 0)
+               return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
+
+       if (os_strcmp(cmd, "go_apsd") == 0) {
+               if (os_strcmp(param, "disable") == 0)
+                       wpa_s->set_ap_uapsd = 0;
+               else {
+                       wpa_s->set_ap_uapsd = 1;
+                       wpa_s->ap_uapsd = atoi(param);
+               }
+               return 0;
+       }
+
+       if (os_strcmp(cmd, "client_apsd") == 0) {
+               if (os_strcmp(param, "disable") == 0)
+                       wpa_s->set_sta_uapsd = 0;
+               else {
+                       int be, bk, vi, vo;
+                       char *pos;
+                       /* format: BE,BK,VI,VO;max SP Length */
+                       be = atoi(param);
+                       pos = os_strchr(param, ',');
+                       if (pos == NULL)
+                               return -1;
+                       pos++;
+                       bk = atoi(pos);
+                       pos = os_strchr(pos, ',');
+                       if (pos == NULL)
+                               return -1;
+                       pos++;
+                       vi = atoi(pos);
+                       pos = os_strchr(pos, ',');
+                       if (pos == NULL)
+                               return -1;
+                       pos++;
+                       vo = atoi(pos);
+                       /* ignore max SP Length for now */
+
+                       wpa_s->set_sta_uapsd = 1;
+                       wpa_s->sta_uapsd = 0;
+                       if (be)
+                               wpa_s->sta_uapsd |= BIT(0);
+                       if (bk)
+                               wpa_s->sta_uapsd |= BIT(1);
+                       if (vi)
+                               wpa_s->sta_uapsd |= BIT(2);
+                       if (vo)
+                               wpa_s->sta_uapsd |= BIT(3);
+               }
+               return 0;
+       }
+
        wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
                   cmd);
 
@@ -2469,6 +2663,14 @@ static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
 #endif /* CONFIG_P2P */
 
 
+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;
+}
+
+
 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                                         char *buf, size_t *resp_len)
 {
@@ -2482,7 +2684,10 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
                                      (const u8 *) buf, os_strlen(buf));
        } else {
-               wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface",
+               int level = MSG_DEBUG;
+               if (os_strcmp(buf, "PING") == 0)
+                       level = MSG_EXCESSIVE;
+               wpa_hexdump_ascii(level, "RX ctrl_iface",
                                  (const u8 *) buf, os_strlen(buf));
        }
 
@@ -2566,6 +2771,12 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
                                                              reply,
                                                              reply_size);
+       } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
+               reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
+                       wpa_s, buf + 14, reply, reply_size);
+       } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
+               if (wpas_wps_cancel(wpa_s))
+                       reply_len = -1;
 #ifdef CONFIG_WPS_OOB
        } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
                if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
@@ -2670,6 +2881,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
                        reply_len = -1;
        } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
+               os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
+               wpa_s->force_long_sd = 0;
                p2p_flush(wpa_s->global->p2p);
        } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
                if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
@@ -2777,6 +2990,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
                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;
        } else {
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
                reply_len = 16;