P2P: Send WPS-FAIL event to parent interface, too
[libeap.git] / hostapd / hostapd_cli.c
index 994c76a..c0d647f 100644 (file)
@@ -83,16 +83,21 @@ static const char *commands_help =
 "   sta <addr>           get MIB variables for one station\n"
 "   all_sta              get MIB variables for all stations\n"
 "   new_sta <addr>       add a new station\n"
+"   deauthenticate <addr>  deauthenticate a station\n"
+"   disassociate <addr>  disassociate a station\n"
 #ifdef CONFIG_IEEE80211W
 "   sa_query <addr>      send SA Query to a station\n"
 #endif /* CONFIG_IEEE80211W */
 #ifdef CONFIG_WPS
-"   wps_pin <uuid> <pin> [timeout]  add WPS Enrollee PIN (Device Password)\n"
+"   wps_pin <uuid> <pin> [timeout] [addr]  add WPS Enrollee PIN\n"
+"   wps_check_pin <PIN>  verify PIN checksum\n"
 "   wps_pbc              indicate button pushed to initiate PBC\n"
 #ifdef CONFIG_WPS_OOB
 "   wps_oob <type> <path> <method>  use WPS with out-of-band (UFD)\n"
 #endif /* CONFIG_WPS_OOB */
+"   wps_ap_pin <cmd> [params..]  enable/disable AP PIN\n"
 #endif /* CONFIG_WPS */
+"   get_config           show current configuration\n"
 "   help                 show this usage help\n"
 "   interface [ifname]   show interfaces/select interface\n"
 "   level <debug level>  change debug level\n"
@@ -349,13 +354,16 @@ static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc,
 static int hostapd_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc,
                                   char *argv[])
 {
-       char buf[64];
+       char buf[256];
        if (argc < 2) {
                printf("Invalid 'wps_pin' command - at least two arguments, "
                       "UUID and PIN, are required.\n");
                return -1;
        }
-       if (argc > 2)
+       if (argc > 3)
+               snprintf(buf, sizeof(buf), "WPS_PIN %s %s %s %s",
+                        argv[0], argv[1], argv[2], argv[3]);
+       else if (argc > 2)
                snprintf(buf, sizeof(buf), "WPS_PIN %s %s %s",
                         argv[0], argv[1], argv[2]);
        else
@@ -364,6 +372,32 @@ static int hostapd_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static int hostapd_cli_cmd_wps_check_pin(struct wpa_ctrl *ctrl, int argc,
+                                        char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1 && argc != 2) {
+               printf("Invalid WPS_CHECK_PIN command: needs one argument:\n"
+                      "- PIN to be verified\n");
+               return -1;
+       }
+
+       if (argc == 2)
+               res = os_snprintf(cmd, sizeof(cmd), "WPS_CHECK_PIN %s %s",
+                                 argv[0], argv[1]);
+       else
+               res = os_snprintf(cmd, sizeof(cmd), "WPS_CHECK_PIN %s",
+                                 argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long WPS_CHECK_PIN command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 static int hostapd_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc,
                                   char *argv[])
 {
@@ -403,9 +437,37 @@ static int hostapd_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc,
        return wpa_ctrl_command(ctrl, cmd);
 }
 #endif /* CONFIG_WPS_OOB */
+
+
+static int hostapd_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
+                                     char *argv[])
+{
+       char buf[64];
+       if (argc < 1) {
+               printf("Invalid 'wps_ap_pin' command - at least one argument "
+                      "is required.\n");
+               return -1;
+       }
+       if (argc > 2)
+               snprintf(buf, sizeof(buf), "WPS_AP_PIN %s %s %s",
+                        argv[0], argv[1], argv[2]);
+       else if (argc > 1)
+               snprintf(buf, sizeof(buf), "WPS_AP_PIN %s %s",
+                        argv[0], argv[1]);
+       else
+               snprintf(buf, sizeof(buf), "WPS_AP_PIN %s", argv[0]);
+       return wpa_ctrl_command(ctrl, buf);
+}
 #endif /* CONFIG_WPS */
 
 
+static int hostapd_cli_cmd_get_config(struct wpa_ctrl *ctrl, int argc,
+                                     char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "GET_CONFIG");
+}
+
+
 static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd,
                                char *addr, size_t addr_len)
 {
@@ -543,6 +605,26 @@ static int hostapd_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static int hostapd_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 2) {
+               printf("Invalid SET command: needs two arguments (variable "
+                      "name and value)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "SET %s %s", argv[0], argv[1]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long SET command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 struct hostapd_cli_cmd {
        const char *cmd;
        int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
@@ -561,16 +643,20 @@ static struct hostapd_cli_cmd hostapd_cli_commands[] = {
 #endif /* CONFIG_IEEE80211W */
 #ifdef CONFIG_WPS
        { "wps_pin", hostapd_cli_cmd_wps_pin },
+       { "wps_check_pin", hostapd_cli_cmd_wps_check_pin },
        { "wps_pbc", hostapd_cli_cmd_wps_pbc },
 #ifdef CONFIG_WPS_OOB
        { "wps_oob", hostapd_cli_cmd_wps_oob },
 #endif /* CONFIG_WPS_OOB */
+       { "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin },
 #endif /* CONFIG_WPS */
+       { "get_config", hostapd_cli_cmd_get_config },
        { "help", hostapd_cli_cmd_help },
        { "interface", hostapd_cli_cmd_interface },
        { "level", hostapd_cli_cmd_level },
        { "license", hostapd_cli_cmd_license },
        { "quit", hostapd_cli_cmd_quit },
+       { "set", hostapd_cli_cmd_set },
        { NULL, NULL }
 };
 
@@ -791,8 +877,8 @@ int main(int argc, char *argv[])
                        printf("%s\n", hostapd_cli_version);
                        return 0;
                case 'i':
-                       free(ctrl_ifname);
-                       ctrl_ifname = strdup(optarg);
+                       os_free(ctrl_ifname);
+                       ctrl_ifname = os_strdup(optarg);
                        break;
                case 'p':
                        ctrl_iface_dir = optarg;
@@ -816,12 +902,13 @@ int main(int argc, char *argv[])
                        DIR *dir = opendir(ctrl_iface_dir);
                        if (dir) {
                                while ((dent = readdir(dir))) {
-                                       if (strcmp(dent->d_name, ".") == 0 ||
-                                           strcmp(dent->d_name, "..") == 0)
+                                       if (os_strcmp(dent->d_name, ".") == 0
+                                           ||
+                                           os_strcmp(dent->d_name, "..") == 0)
                                                continue;
                                        printf("Selected interface '%s'\n",
                                               dent->d_name);
-                                       ctrl_ifname = strdup(dent->d_name);
+                                       ctrl_ifname = os_strdup(dent->d_name);
                                        break;
                                }
                                closedir(dir);
@@ -844,7 +931,7 @@ int main(int argc, char *argv[])
                        printf("Could not connect to hostapd - re-trying\n");
                        warning_displayed = 1;
                }
-               sleep(1);
+               os_sleep(1, 0);
                continue;
        }