hostapd_cli: Add command completion support
Add command completion support for hostapd_cli. Only completion for available commands and basic building blocks in preparation for per command parameter completion. Signed-off-by: Mikael Kanstrup <mikael.kanstrup@sonymobile.com>
This commit is contained in:
parent
003fe581a3
commit
1f927cd4cf
1 changed files with 145 additions and 54 deletions
|
@ -1228,70 +1228,97 @@ static int hostapd_cli_cmd_driver_flags(struct wpa_ctrl *ctrl, int argc,
|
||||||
struct hostapd_cli_cmd {
|
struct hostapd_cli_cmd {
|
||||||
const char *cmd;
|
const char *cmd;
|
||||||
int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
|
int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
|
||||||
|
char ** (*completion)(const char *str, int pos);
|
||||||
|
const char *usage;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
|
static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
|
||||||
{ "ping", hostapd_cli_cmd_ping },
|
{ "ping", hostapd_cli_cmd_ping, NULL,
|
||||||
{ "mib", hostapd_cli_cmd_mib },
|
"= pings hostapd" },
|
||||||
{ "relog", hostapd_cli_cmd_relog },
|
{ "mib", hostapd_cli_cmd_mib, NULL,
|
||||||
{ "status", hostapd_cli_cmd_status },
|
"= get MIB variables (dot1x, dot11, radius)" },
|
||||||
{ "sta", hostapd_cli_cmd_sta },
|
{ "relog", hostapd_cli_cmd_relog, NULL, NULL },
|
||||||
{ "all_sta", hostapd_cli_cmd_all_sta },
|
{ "status", hostapd_cli_cmd_status, NULL, NULL },
|
||||||
{ "new_sta", hostapd_cli_cmd_new_sta },
|
{ "sta", hostapd_cli_cmd_sta, NULL,
|
||||||
{ "deauthenticate", hostapd_cli_cmd_deauthenticate },
|
"<addr> = get MIB variables for one station" },
|
||||||
{ "disassociate", hostapd_cli_cmd_disassociate },
|
{ "all_sta", hostapd_cli_cmd_all_sta, NULL,
|
||||||
|
"= 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,
|
||||||
|
"<addr> = deauthenticate a station" },
|
||||||
|
{ "disassociate", hostapd_cli_cmd_disassociate, NULL,
|
||||||
|
"<addr> = disassociate a station" },
|
||||||
#ifdef CONFIG_IEEE80211W
|
#ifdef CONFIG_IEEE80211W
|
||||||
{ "sa_query", hostapd_cli_cmd_sa_query },
|
{ "sa_query", hostapd_cli_cmd_sa_query, NULL,
|
||||||
|
"<addr> = send SA Query to a station" },
|
||||||
#endif /* CONFIG_IEEE80211W */
|
#endif /* CONFIG_IEEE80211W */
|
||||||
#ifdef CONFIG_WPS
|
#ifdef CONFIG_WPS
|
||||||
{ "wps_pin", hostapd_cli_cmd_wps_pin },
|
{ "wps_pin", hostapd_cli_cmd_wps_pin, NULL,
|
||||||
{ "wps_check_pin", hostapd_cli_cmd_wps_check_pin },
|
"<uuid> <pin> [timeout] [addr] = add WPS Enrollee PIN" },
|
||||||
{ "wps_pbc", hostapd_cli_cmd_wps_pbc },
|
{ "wps_check_pin", hostapd_cli_cmd_wps_check_pin, NULL,
|
||||||
{ "wps_cancel", hostapd_cli_cmd_wps_cancel },
|
"<PIN> = verify PIN checksum" },
|
||||||
|
{ "wps_pbc", hostapd_cli_cmd_wps_pbc, NULL,
|
||||||
|
"= indicate button pushed to initiate PBC" },
|
||||||
|
{ "wps_cancel", hostapd_cli_cmd_wps_cancel, NULL,
|
||||||
|
"= cancel the pending WPS operation" },
|
||||||
#ifdef CONFIG_WPS_NFC
|
#ifdef CONFIG_WPS_NFC
|
||||||
{ "wps_nfc_tag_read", hostapd_cli_cmd_wps_nfc_tag_read },
|
{ "wps_nfc_tag_read", hostapd_cli_cmd_wps_nfc_tag_read, NULL,
|
||||||
{ "wps_nfc_config_token", hostapd_cli_cmd_wps_nfc_config_token },
|
"<hexdump> = report read NFC tag with WPS data" },
|
||||||
{ "wps_nfc_token", hostapd_cli_cmd_wps_nfc_token },
|
{ "wps_nfc_config_token", hostapd_cli_cmd_wps_nfc_config_token, NULL,
|
||||||
{ "nfc_get_handover_sel", hostapd_cli_cmd_nfc_get_handover_sel },
|
"<WPS/NDEF> = build NFC configuration token" },
|
||||||
|
{ "wps_nfc_token", hostapd_cli_cmd_wps_nfc_token, NULL,
|
||||||
|
"<WPS/NDEF/enable/disable> = manager NFC password token" },
|
||||||
|
{ "nfc_get_handover_sel", hostapd_cli_cmd_nfc_get_handover_sel, NULL,
|
||||||
|
NULL },
|
||||||
#endif /* CONFIG_WPS_NFC */
|
#endif /* CONFIG_WPS_NFC */
|
||||||
{ "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin },
|
{ "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin, NULL,
|
||||||
{ "wps_config", hostapd_cli_cmd_wps_config },
|
"<cmd> [params..] = enable/disable AP PIN" },
|
||||||
{ "wps_get_status", hostapd_cli_cmd_wps_get_status },
|
{ "wps_config", hostapd_cli_cmd_wps_config, NULL,
|
||||||
|
"<SSID> <auth> <encr> <key> = configure AP" },
|
||||||
|
{ "wps_get_status", hostapd_cli_cmd_wps_get_status, NULL,
|
||||||
|
"= show current WPS status" },
|
||||||
#endif /* CONFIG_WPS */
|
#endif /* CONFIG_WPS */
|
||||||
{ "disassoc_imminent", hostapd_cli_cmd_disassoc_imminent },
|
{ "disassoc_imminent", hostapd_cli_cmd_disassoc_imminent, NULL, NULL },
|
||||||
{ "ess_disassoc", hostapd_cli_cmd_ess_disassoc },
|
{ "ess_disassoc", hostapd_cli_cmd_ess_disassoc, NULL, NULL },
|
||||||
{ "bss_tm_req", hostapd_cli_cmd_bss_tm_req },
|
{ "bss_tm_req", hostapd_cli_cmd_bss_tm_req, NULL, NULL },
|
||||||
{ "get_config", hostapd_cli_cmd_get_config },
|
{ "get_config", hostapd_cli_cmd_get_config, NULL,
|
||||||
{ "help", hostapd_cli_cmd_help },
|
"= show current configuration" },
|
||||||
{ "interface", hostapd_cli_cmd_interface },
|
{ "help", hostapd_cli_cmd_help, NULL,
|
||||||
|
"= show this usage help" },
|
||||||
|
{ "interface", hostapd_cli_cmd_interface, NULL,
|
||||||
|
"[ifname] = show interfaces/select interface" },
|
||||||
#ifdef CONFIG_FST
|
#ifdef CONFIG_FST
|
||||||
{ "fst", hostapd_cli_cmd_fst },
|
{ "fst", hostapd_cli_cmd_fst, NULL, NULL },
|
||||||
#endif /* CONFIG_FST */
|
#endif /* CONFIG_FST */
|
||||||
{ "raw", hostapd_cli_cmd_raw },
|
{ "raw", hostapd_cli_cmd_raw, NULL, NULL },
|
||||||
{ "level", hostapd_cli_cmd_level },
|
{ "level", hostapd_cli_cmd_level, NULL,
|
||||||
{ "license", hostapd_cli_cmd_license },
|
"<debug level> = change debug level" },
|
||||||
{ "quit", hostapd_cli_cmd_quit },
|
{ "license", hostapd_cli_cmd_license, NULL,
|
||||||
{ "set", hostapd_cli_cmd_set },
|
"= show full hostapd_cli license" },
|
||||||
{ "get", hostapd_cli_cmd_get },
|
{ "quit", hostapd_cli_cmd_quit, NULL,
|
||||||
{ "set_qos_map_set", hostapd_cli_cmd_set_qos_map_set },
|
"= exit hostapd_cli" },
|
||||||
{ "send_qos_map_conf", hostapd_cli_cmd_send_qos_map_conf },
|
{ "set", hostapd_cli_cmd_set, NULL, NULL },
|
||||||
{ "chan_switch", hostapd_cli_cmd_chan_switch },
|
{ "get", hostapd_cli_cmd_get, NULL, NULL },
|
||||||
{ "hs20_wnm_notif", hostapd_cli_cmd_hs20_wnm_notif },
|
{ "set_qos_map_set", hostapd_cli_cmd_set_qos_map_set, NULL, NULL },
|
||||||
{ "hs20_deauth_req", hostapd_cli_cmd_hs20_deauth_req },
|
{ "send_qos_map_conf", hostapd_cli_cmd_send_qos_map_conf, NULL, NULL },
|
||||||
{ "vendor", hostapd_cli_cmd_vendor },
|
{ "chan_switch", hostapd_cli_cmd_chan_switch, NULL, NULL },
|
||||||
{ "enable", hostapd_cli_cmd_enable },
|
{ "hs20_wnm_notif", hostapd_cli_cmd_hs20_wnm_notif, NULL, NULL },
|
||||||
{ "reload", hostapd_cli_cmd_reload },
|
{ "hs20_deauth_req", hostapd_cli_cmd_hs20_deauth_req, NULL, NULL },
|
||||||
{ "disable", hostapd_cli_cmd_disable },
|
{ "vendor", hostapd_cli_cmd_vendor, NULL, NULL },
|
||||||
{ "erp_flush", hostapd_cli_cmd_erp_flush },
|
{ "enable", hostapd_cli_cmd_enable, NULL, NULL },
|
||||||
{ "log_level", hostapd_cli_cmd_log_level },
|
{ "reload", hostapd_cli_cmd_reload, NULL, NULL },
|
||||||
{ "pmksa", hostapd_cli_cmd_pmksa },
|
{ "disable", hostapd_cli_cmd_disable, NULL, NULL },
|
||||||
{ "pmksa_flush", hostapd_cli_cmd_pmksa_flush },
|
{ "erp_flush", hostapd_cli_cmd_erp_flush, NULL, NULL },
|
||||||
{ "set_neighbor", hostapd_cli_cmd_set_neighbor },
|
{ "log_level", hostapd_cli_cmd_log_level, NULL, NULL },
|
||||||
{ "remove_neighbor", hostapd_cli_cmd_remove_neighbor },
|
{ "pmksa", hostapd_cli_cmd_pmksa, NULL, NULL },
|
||||||
{ "req_lci", hostapd_cli_cmd_req_lci },
|
{ "pmksa_flush", hostapd_cli_cmd_pmksa_flush, NULL, NULL },
|
||||||
{ "req_range", hostapd_cli_cmd_req_range },
|
{ "set_neighbor", hostapd_cli_cmd_set_neighbor, NULL, NULL },
|
||||||
{ "driver_flags", hostapd_cli_cmd_driver_flags },
|
{ "remove_neighbor", hostapd_cli_cmd_remove_neighbor, NULL, NULL },
|
||||||
{ NULL, NULL }
|
{ "req_lci", hostapd_cli_cmd_req_lci, NULL, NULL },
|
||||||
|
{ "req_range", hostapd_cli_cmd_req_range, NULL, NULL },
|
||||||
|
{ "driver_flags", hostapd_cli_cmd_driver_flags, NULL, NULL },
|
||||||
|
{ NULL, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1439,13 +1466,77 @@ static void hostapd_cli_edit_eof_cb(void *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char ** list_cmd_list(void)
|
||||||
|
{
|
||||||
|
char **res;
|
||||||
|
int i, count;
|
||||||
|
|
||||||
|
count = ARRAY_SIZE(hostapd_cli_commands);
|
||||||
|
res = os_calloc(count + 1, sizeof(char *));
|
||||||
|
if (res == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; hostapd_cli_commands[i].cmd; i++) {
|
||||||
|
res[i] = os_strdup(hostapd_cli_commands[i].cmd);
|
||||||
|
if (res[i] == NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char ** hostapd_cli_cmd_completion(const char *cmd, const char *str,
|
||||||
|
int pos)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; hostapd_cli_commands[i].cmd; i++) {
|
||||||
|
if (os_strcasecmp(hostapd_cli_commands[i].cmd, cmd) != 0)
|
||||||
|
continue;
|
||||||
|
if (hostapd_cli_commands[i].completion)
|
||||||
|
return hostapd_cli_commands[i].completion(str, pos);
|
||||||
|
if (!hostapd_cli_commands[i].usage)
|
||||||
|
return NULL;
|
||||||
|
edit_clear_line();
|
||||||
|
printf("\r%s\n", hostapd_cli_commands[i].usage);
|
||||||
|
edit_redraw();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char ** hostapd_cli_edit_completion_cb(void *ctx, const char *str,
|
||||||
|
int pos)
|
||||||
|
{
|
||||||
|
char **res;
|
||||||
|
const char *end;
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
end = os_strchr(str, ' ');
|
||||||
|
if (end == NULL || str + pos < end)
|
||||||
|
return list_cmd_list();
|
||||||
|
|
||||||
|
cmd = os_malloc(pos + 1);
|
||||||
|
if (cmd == NULL)
|
||||||
|
return NULL;
|
||||||
|
os_memcpy(cmd, str, pos);
|
||||||
|
cmd[end - str] = '\0';
|
||||||
|
res = hostapd_cli_cmd_completion(cmd, str, pos);
|
||||||
|
os_free(cmd);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void hostapd_cli_interactive(void)
|
static void hostapd_cli_interactive(void)
|
||||||
{
|
{
|
||||||
printf("\nInteractive mode\n\n");
|
printf("\nInteractive mode\n\n");
|
||||||
|
|
||||||
eloop_register_signal_terminate(hostapd_cli_eloop_terminate, NULL);
|
eloop_register_signal_terminate(hostapd_cli_eloop_terminate, NULL);
|
||||||
edit_init(hostapd_cli_edit_cmd_cb, hostapd_cli_edit_eof_cb,
|
edit_init(hostapd_cli_edit_cmd_cb, hostapd_cli_edit_eof_cb,
|
||||||
NULL, NULL, NULL, NULL);
|
hostapd_cli_edit_completion_cb, NULL, NULL, NULL);
|
||||||
eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
|
eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
|
||||||
|
|
||||||
eloop_run();
|
eloop_run();
|
||||||
|
|
Loading…
Reference in a new issue