[PATCH 5/5] wpa_cli: Completion routine for dup_network command
Mikael Kanstrup
mikael.kanstrup
Tue Mar 24 09:10:40 PDT 2015
Add command completion routine for dup_network command
Signed-off-by: Mikael Kanstrup <mikael.kanstrup at sonymobile.com>
---
wpa_supplicant/wpa_cli.c | 39 ++++++++++++++++++++++++++++++++-------
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index fe29b77..eed95a0 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -1528,10 +1528,7 @@ static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
return wpa_cli_cmd(ctrl, "GET_NETWORK", 2, argc, argv);
}
-static char ** wpa_cli_complete_network(const char *str, int pos)
-{
- int arg = get_cmd_arg_num(str, pos);
- const char *fields[] = {
+static const char *network_fields[] = {
"ssid", "scan_ssid", "bssid", "bssid_blacklist",
"bssid_whitelist", "psk", "proto", "key_mgmt",
"bg_scan_period", "pairwise", "group", "auth_alg", "scan_freq",
@@ -1595,7 +1592,11 @@ static char ** wpa_cli_complete_network(const char *str, int pos)
#endif /* CONFIG_HS20 */
"mac_addr"
};
- int i, num_fields = ARRAY_SIZE(fields);
+
+static char ** wpa_cli_complete_network(const char *str, int pos)
+{
+ int arg = get_cmd_arg_num(str, pos);
+ int i, num_fields = ARRAY_SIZE(network_fields);
char** res = NULL;
switch (arg) {
@@ -1607,7 +1608,7 @@ static char ** wpa_cli_complete_network(const char *str, int pos)
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
- res[i] = os_strdup(fields[i]);
+ res[i] = os_strdup(network_fields[i]);
if (res[i] == NULL)
break;
}
@@ -1637,9 +1638,33 @@ static int wpa_cli_cmd_dup_network(struct wpa_ctrl *ctrl, int argc,
return -1;
}
+
return wpa_cli_cmd(ctrl, "DUP_NETWORK", 3, argc, argv);
}
+static char ** wpa_cli_complete_dup_network(const char *str, int pos)
+{
+ int arg = get_cmd_arg_num(str, pos);
+ int i, num_fields = ARRAY_SIZE(network_fields);
+ char** res = NULL;
+
+ switch (arg) {
+ case 1:
+ case 2:
+ res = cli_txt_list_array(&networks);
+ break;
+ case 3:
+ res = os_calloc(num_fields + 1, sizeof(char *));
+ if (res == NULL)
+ return NULL;
+ for (i = 0; i < num_fields; i++) {
+ res[i] = os_strdup(network_fields[i]);
+ if (res[i] == NULL)
+ break;
+ }
+ }
+ return res;
+}
static int wpa_cli_cmd_list_creds(struct wpa_ctrl *ctrl, int argc,
char *argv[])
@@ -2902,7 +2927,7 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
{ "get_network", wpa_cli_cmd_get_network, wpa_cli_complete_network,
cli_cmd_flag_none,
"<network id> <variable> = get network variables" },
- { "dup_network", wpa_cli_cmd_dup_network, NULL,
+ { "dup_network", wpa_cli_cmd_dup_network, wpa_cli_complete_dup_network,
cli_cmd_flag_none,
"<src network id> <dst network id> <variable> = duplicate network variables"
},
--
1.8.2.2
More information about the Hostap
mailing list