[PATCH 7/9] hostapd_cli: Completion for disassociate and deauthenticate
Mikael Kanstrup
mikael.kanstrup at sonymobile.com
Thu Jul 7 05:04:36 PDT 2016
Command completion routine for disassociate and deauthenticate
commands implemented. Tracks AP-STA-CONNECTED/AP-STA-DISCONNECTED
events for easy station bssid lookup.
Signed-off-by: Mikael Kanstrup <mikael.kanstrup at sonymobile.com>
---
hostapd/hostapd_cli.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 2 deletions(-)
diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index a13d19c..849d468 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -76,6 +76,8 @@ static int ping_interval = 5;
static int interactive = 0;
static int event_handler_registered = 0;
+static DEFINE_DL_LIST(stations); /* struct cli_txt_entry */
+
static void print_help(FILE *stream, const char *cmd);
static char ** list_cmd_list(void);
static void hostapd_cli_receive(int sock, void *eloop_ctx, void *sock_ctx);
@@ -405,6 +407,21 @@ static int hostapd_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
}
+static char ** hostapd_complete_deauthenticate(const char *str, int pos)
+{
+ int arg = get_cmd_arg_num(str, pos);
+ char **res = NULL;
+
+ switch (arg) {
+ case 1:
+ res = cli_txt_list_array(&stations);
+ break;
+ }
+
+ return res;
+}
+
+
static int hostapd_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
@@ -423,6 +440,21 @@ static int hostapd_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
}
+static char ** hostapd_complete_disassociate(const char *str, int pos)
+{
+ int arg = get_cmd_arg_num(str, pos);
+ char **res = NULL;
+
+ switch (arg) {
+ case 1:
+ res = cli_txt_list_array(&stations);
+ break;
+ }
+
+ return res;
+}
+
+
#ifdef CONFIG_IEEE80211W
static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc,
char *argv[])
@@ -1279,9 +1311,11 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
"= get MIB variables for all stations" },
{ "new_sta", hostapd_cli_cmd_new_sta, NULL,
"<addr> = add a new station" },
- { "deauthenticate", hostapd_cli_cmd_deauthenticate, NULL,
+ { "deauthenticate", hostapd_cli_cmd_deauthenticate,
+ hostapd_complete_deauthenticate,
"<addr> = deauthenticate a station" },
- { "disassociate", hostapd_cli_cmd_disassociate, NULL,
+ { "disassociate", hostapd_cli_cmd_disassociate,
+ hostapd_complete_disassociate,
"<addr> = disassociate a station" },
#ifdef CONFIG_IEEE80211W
{ "sa_query", hostapd_cli_cmd_sa_query, NULL,
@@ -1451,6 +1485,29 @@ static void wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
static void cli_event(const char *str)
{
+ const char *start, *s;
+
+ start = os_strchr(str, '>');
+ if (start == NULL)
+ return;
+
+ start++;
+
+ if (str_starts(start, AP_STA_CONNECTED)) {
+ s = os_strchr(start, ' ');
+ if (s == NULL)
+ return;
+ cli_txt_list_add(&stations, s + 1);
+ return;
+ }
+
+ if (str_starts(start, AP_STA_DISCONNECTED)) {
+ s = os_strchr(start, ' ');
+ if (s == NULL)
+ return;
+ cli_txt_list_del_addr(&stations, s + 1);
+ return;
+ }
}
@@ -1641,6 +1698,7 @@ static void hostapd_cli_interactive(void)
eloop_run();
+ cli_txt_list_flush(&stations);
edit_deinit(NULL, NULL);
eloop_cancel_timeout(hostapd_cli_ping, NULL, NULL);
}
--
2.9.0.137.gcf4c2cf
More information about the Hostap
mailing list