wlantest: Add new cli "help" command

Having a help cli command to view all the supported commands is helpful
when running the wlantest_cli manually instead via the python test
scripts.

$ wlantest_cli help
commands:
  ping = test connection to wlantest
  terminate = terminate wlantest
  list_bss = get BSS list
  list_sta <BSSID> = get STA list
  flush = drop all collected BSS data
  clear_sta_counters <BSSID> <STA> = clear STA counters
  clear_bss_counters <BSSID> = clear BSS counters
  get_sta_counter <counter> <BSSID> <STA> = get STA counter value
  get_bss_counter <counter> <BSSID> = get BSS counter value
  inject <frame> <prot> <sender> <BSSID> <STA/ff:ff:ff:ff:ff:ff>
  send <prot> <raw frame as hex dump>
  version = get wlantest version
  add_passphrase <passphrase> = add a known passphrase
  add_wepkey <WEP key> = add a known WEP key
  info_sta <field> <BSSID> <STA> = get STA information
  info_bss <field> <BSSID> = get BSS information
  clear_tdls_counters <BSSID> <STA1> <STA2> = clear TDLS counters
  get_tdls_counter <counter> <BSSID> <STA1> <STA2> = get TDLS counter value
  get_bss_counter <counter> <BSSID> = get BSS counter value
  relog = re-open log-file (allow rolling logs)
  get_tx_tid <BSSID> <STA> <TID> = get STA TX TID counter value
  get_rx_tid <BSSID> <STA> <TID> = get STA RX TID counter value
  help = show this usage help

$ wlantest_cli help add_passphrase
commands:
  add_passphrase <passphrase> = add a known passphrase

Signed-off-by: Gokul Sivakumar <gokulkumar792@gmail.com>
This commit is contained in:
Gokul Sivakumar 2021-11-03 22:20:21 +05:30 committed by Jouni Malinen
parent 30cf0d107f
commit daea5ceada

View file

@ -14,6 +14,9 @@
#include "utils/edit.h"
#include "wlantest_ctrl.h"
static void print_help(FILE *stream, const char *cmd);
static char ** wlantest_cli_cmd_list(void);
static int get_cmd_arg_num(const char *str, int pos)
{
@ -1566,6 +1569,28 @@ static char ** complete_get_tid(int s, const char *str, int pos)
}
static int wlantest_cli_cmd_help(int s, int argc, char *argv[])
{
print_help(stdout, argc > 0 ? argv[0] : NULL);
return 0;
}
static char ** wlantest_cli_complete_help(int s, const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = wlantest_cli_cmd_list();
break;
}
return res;
}
struct wlantest_cli_cmd {
const char *cmd;
int (*handler)(int s, int argc, char *argv[]);
@ -1623,10 +1648,45 @@ static const struct wlantest_cli_cmd wlantest_cli_commands[] = {
{ "get_rx_tid", cmd_get_rx_tid,
"<BSSID> <STA> <TID> = get STA RX TID counter value",
complete_get_tid },
{ "help", wlantest_cli_cmd_help,
"= show this usage help", wlantest_cli_complete_help },
{ NULL, NULL, NULL, NULL }
};
/*
* Prints command usage, lines are padded with the specified string.
*/
static void print_cmd_help(FILE *stream, const struct wlantest_cli_cmd *cmd,
const char *pad)
{
char c;
size_t n;
if (!cmd->usage)
return;
fprintf(stream, "%s%s ", pad, cmd->cmd);
for (n = 0; (c = cmd->usage[n]); n++) {
fprintf(stream, "%c", c);
if (c == '\n')
fprintf(stream, "%s", pad);
}
fprintf(stream, "\n");
}
static void print_help(FILE *stream, const char *cmd)
{
int n;
fprintf(stream, "commands:\n");
for (n = 0; wlantest_cli_commands[n].cmd; n++) {
if (!cmd || str_starts(wlantest_cli_commands[n].cmd, cmd))
print_cmd_help(stream, &wlantest_cli_commands[n], " ");
}
}
static int ctrl_command(int s, int argc, char *argv[])
{
const struct wlantest_cli_cmd *cmd, *match = NULL;