Merge branch 'moonshot' of ssh://moonshot.suchdamage.org:822/srv/git/libeap into...
[libeap.git] / wpa_supplicant / ctrl_iface.c
index 3d604f3..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);
@@ -238,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)
@@ -606,6 +674,12 @@ static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
                        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) ||
@@ -1901,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) {
@@ -2432,7 +2514,7 @@ 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)
@@ -2457,6 +2539,71 @@ static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
                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);
 
@@ -2516,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)
 {
@@ -2529,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));
        }
 
@@ -2613,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))
@@ -2718,6 +2882,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
                        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)
@@ -2825,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;