]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Add control interface command for fetching latest status
authorJeffin Mammen <jmammen@qti.qualcomm.com>
Fri, 23 Aug 2013 13:03:15 +0000 (16:03 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 23 Aug 2013 14:49:01 +0000 (17:49 +0300)
The new wps_get_status command can be used to fetch the result of the
latest WPS operation and the current PBC state from hostapd.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

hostapd/ctrl_iface.c
hostapd/hostapd_cli.c

index 021cbe5790583d6b72b01e0fa6de7851ee22c5e2..26480d067ec20b81193cd6cdb6fc3eec403e94a2 100644 (file)
@@ -487,6 +487,75 @@ static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
 
        return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
 }
+
+
+static const char * pbc_status_str(enum pbc_status status)
+{
+       switch (status) {
+       case WPS_PBC_STATUS_DISABLE:
+               return "Disabled";
+       case WPS_PBC_STATUS_ACTIVE:
+               return "Active";
+       case WPS_PBC_STATUS_TIMEOUT:
+               return "Timed-out";
+       case WPS_PBC_STATUS_OVERLAP:
+               return "Overlap";
+       default:
+               return "Unknown";
+       }
+}
+
+
+static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
+                                            char *buf, size_t buflen)
+{
+       int ret;
+       char *pos, *end;
+
+       pos = buf;
+       end = buf + buflen;
+
+       ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
+                         pbc_status_str(hapd->wps_stats.pbc_status));
+
+       if (ret < 0 || ret >= end - pos)
+               return pos - buf;
+       pos += ret;
+
+       ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
+                         (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
+                          "Success":
+                          (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
+                           "Failed" : "None")));
+
+       if (ret < 0 || ret >= end - pos)
+               return pos - buf;
+       pos += ret;
+
+       /* If status == Failure - Add possible Reasons */
+       if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
+          hapd->wps_stats.failure_reason > 0) {
+               ret = os_snprintf(pos, end - pos,
+                                 "Failure Reason: %s\n",
+                                 wps_ei_str(hapd->wps_stats.failure_reason));
+
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (hapd->wps_stats.status) {
+               ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
+                                 MAC2STR(hapd->wps_stats.peer_addr));
+
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       return pos - buf;
+}
+
 #endif /* CONFIG_WPS */
 
 
@@ -1003,6 +1072,9 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
        } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
                if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
                        reply_len = -1;
+       } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
+               reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
+                                                             reply_size);
 #ifdef CONFIG_WPS_NFC
        } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
                if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
index 661f709e33e07212b5d3d6d5967ae93e49ac55f6..5f48fc89c079b20ecb0c88399c4c2ff723f16c99 100644 (file)
@@ -79,6 +79,7 @@ static const char *commands_help =
 #endif /* CONFIG_WPS_NFC */
 "   wps_ap_pin <cmd> [params..]  enable/disable AP PIN\n"
 "   wps_config <SSID> <auth> <encr> <key>  configure AP\n"
+"   wps_get_status       show current WPS status\n"
 #endif /* CONFIG_WPS */
 "   get_config           show current configuration\n"
 "   help                 show this usage help\n"
@@ -517,6 +518,13 @@ static int hostapd_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static int hostapd_cli_cmd_wps_get_status(struct wpa_ctrl *ctrl, int argc,
+                                         char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "WPS_GET_STATUS");
+}
+
+
 static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
                                      char *argv[])
 {
@@ -818,6 +826,7 @@ static struct hostapd_cli_cmd hostapd_cli_commands[] = {
 #endif /* CONFIG_WPS_NFC */
        { "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin },
        { "wps_config", hostapd_cli_cmd_wps_config },
+       { "wps_get_status", hostapd_cli_cmd_wps_get_status },
 #endif /* CONFIG_WPS */
        { "disassoc_imminent", hostapd_cli_cmd_disassoc_imminent },
        { "ess_disassoc", hostapd_cli_cmd_ess_disassoc },