Changeset View
Changeset View
Standalone View
Standalone View
contrib/wpa/hostapd/hostapd_cli.c
Context not available. | |||||
fprintf(stderr, "%s\n", hostapd_cli_version); | fprintf(stderr, "%s\n", hostapd_cli_version); | ||||
fprintf(stderr, | fprintf(stderr, | ||||
"\n" | "\n" | ||||
"usage: hostapd_cli [-p<path>] [-i<ifname>] [-hvB] " | "usage: hostapd_cli [-p<path>] [-i<ifname>] [-hvBr] " | ||||
"[-a<path>] \\\n" | "[-a<path>] \\\n" | ||||
" [-P<pid file>] [-G<ping interval>] [command..]\n" | " [-P<pid file>] [-G<ping interval>] [command..]\n" | ||||
"\n" | "\n" | ||||
Context not available. | |||||
" -a<file> run in daemon mode executing the action file " | " -a<file> run in daemon mode executing the action file " | ||||
"based on events\n" | "based on events\n" | ||||
" from hostapd\n" | " from hostapd\n" | ||||
" -r try to reconnect when client socket is " | |||||
"disconnected.\n" | |||||
" This is useful only when used with -a.\n" | |||||
" -B run a daemon in the background\n" | " -B run a daemon in the background\n" | ||||
" -i<ifname> Interface to listen on (default: first " | " -i<ifname> Interface to listen on (default: first " | ||||
"interface found in the\n" | "interface found in the\n" | ||||
Context not available. | |||||
#endif /* CONFIG_TAXONOMY */ | #endif /* CONFIG_TAXONOMY */ | ||||
#ifdef CONFIG_IEEE80211W | |||||
static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc, | static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc, | ||||
char *argv[]) | char *argv[]) | ||||
{ | { | ||||
Context not available. | |||||
snprintf(buf, sizeof(buf), "SA_QUERY %s", argv[0]); | snprintf(buf, sizeof(buf), "SA_QUERY %s", argv[0]); | ||||
return wpa_ctrl_command(ctrl, buf); | return wpa_ctrl_command(ctrl, buf); | ||||
} | } | ||||
#endif /* CONFIG_IEEE80211W */ | |||||
#ifdef CONFIG_WPS | #ifdef CONFIG_WPS | ||||
Context not available. | |||||
dir = opendir(ctrl_iface_dir); | dir = opendir(ctrl_iface_dir); | ||||
if (dir == NULL) { | if (dir == NULL) { | ||||
printf("Control interface directory '%s' could not be " | printf("Control interface directory '%s' could not be " | ||||
"openned.\n", ctrl_iface_dir); | "opened.\n", ctrl_iface_dir); | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
char cmd[256]; | char cmd[256]; | ||||
int res; | int res; | ||||
if (argc < 2 || argc > 3) { | if (argc < 2 || argc > 4) { | ||||
printf("Invalid vendor command\n" | printf("Invalid vendor command\n" | ||||
"usage: <vendor id> <command id> [<hex formatted command argument>]\n"); | "usage: <vendor id> <command id> [<hex formatted command argument>] [nested=<0|1>]\n"); | ||||
return -1; | return -1; | ||||
} | } | ||||
res = os_snprintf(cmd, sizeof(cmd), "VENDOR %s %s %s", argv[0], argv[1], | res = os_snprintf(cmd, sizeof(cmd), "VENDOR %s %s %s%s%s", argv[0], | ||||
argc == 3 ? argv[2] : ""); | argv[1], argc >= 3 ? argv[2] : "", | ||||
argc == 4 ? " " : "", argc == 4 ? argv[3] : ""); | |||||
if (os_snprintf_error(sizeof(cmd), res)) { | if (os_snprintf_error(sizeof(cmd), res)) { | ||||
printf("Too long VENDOR command.\n"); | printf("Too long VENDOR command.\n"); | ||||
return -1; | return -1; | ||||
Context not available. | |||||
} | } | ||||
static int hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl *ctrl, int argc, | static int hostapd_cli_cmd_show_neighbor(struct wpa_ctrl *ctrl, int argc, | ||||
char *argv[]) | char *argv[]) | ||||
{ | { | ||||
char cmd[400]; | return wpa_ctrl_command(ctrl, "SHOW_NEIGHBOR"); | ||||
int res; | } | ||||
if (argc != 2) { | |||||
printf("Invalid remove_neighbor command: needs 2 arguments\n"); | |||||
return -1; | |||||
} | |||||
res = os_snprintf(cmd, sizeof(cmd), "REMOVE_NEIGHBOR %s %s", | static int hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl *ctrl, int argc, | ||||
argv[0], argv[1]); | char *argv[]) | ||||
if (os_snprintf_error(sizeof(cmd), res)) { | { | ||||
printf("Too long REMOVE_NEIGHBOR command.\n"); | return hostapd_cli_cmd(ctrl, "REMOVE_NEIGHBOR", 1, argc, argv); | ||||
return -1; | |||||
} | |||||
return wpa_ctrl_command(ctrl, cmd); | |||||
} | } | ||||
Context not available. | |||||
} | } | ||||
static int hostapd_cli_cmd_dpp_bootstrap_set(struct wpa_ctrl *ctrl, int argc, | |||||
char *argv[]) | |||||
{ | |||||
return hostapd_cli_cmd(ctrl, "DPP_BOOTSTRAP_SET", 1, argc, argv); | |||||
} | |||||
static int hostapd_cli_cmd_dpp_auth_init(struct wpa_ctrl *ctrl, int argc, | static int hostapd_cli_cmd_dpp_auth_init(struct wpa_ctrl *ctrl, int argc, | ||||
char *argv[]) | char *argv[]) | ||||
{ | { | ||||
Context not available. | |||||
return hostapd_cli_cmd(ctrl, "DPP_PKEX_REMOVE", 1, argc, argv); | return hostapd_cli_cmd(ctrl, "DPP_PKEX_REMOVE", 1, argc, argv); | ||||
} | } | ||||
#ifdef CONFIG_DPP2 | |||||
static int hostapd_cli_cmd_dpp_controller_start(struct wpa_ctrl *ctrl, int argc, | |||||
char *argv[]) | |||||
{ | |||||
return hostapd_cli_cmd(ctrl, "DPP_CONTROLLER_START", 1, argc, argv); | |||||
} | |||||
static int hostapd_cli_cmd_dpp_controller_stop(struct wpa_ctrl *ctrl, int argc, | |||||
char *argv[]) | |||||
{ | |||||
return wpa_ctrl_command(ctrl, "DPP_CONTROLLER_STOP"); | |||||
} | |||||
static int hostapd_cli_cmd_dpp_chirp(struct wpa_ctrl *ctrl, int argc, | |||||
char *argv[]) | |||||
{ | |||||
return hostapd_cli_cmd(ctrl, "DPP_CHIRP", 1, argc, argv); | |||||
} | |||||
static int hostapd_cli_cmd_dpp_stop_chirp(struct wpa_ctrl *ctrl, int argc, | |||||
char *argv[]) | |||||
{ | |||||
return wpa_ctrl_command(ctrl, "DPP_STOP_CHIRP"); | |||||
} | |||||
#endif /* CONFIG_DPP2 */ | |||||
#endif /* CONFIG_DPP */ | #endif /* CONFIG_DPP */ | ||||
Context not available. | |||||
} | } | ||||
#ifdef ANDROID | |||||
static int hostapd_cli_cmd_driver(struct wpa_ctrl *ctrl, int argc, char *argv[]) | |||||
{ | |||||
return hostapd_cli_cmd(ctrl, "DRIVER", 1, argc, argv); | |||||
} | |||||
#endif /* ANDROID */ | |||||
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[]); | ||||
Context not available. | |||||
{ "signature", hostapd_cli_cmd_signature, hostapd_complete_stations, | { "signature", hostapd_cli_cmd_signature, hostapd_complete_stations, | ||||
"<addr> = get taxonomy signature for a station" }, | "<addr> = get taxonomy signature for a station" }, | ||||
#endif /* CONFIG_TAXONOMY */ | #endif /* CONFIG_TAXONOMY */ | ||||
#ifdef CONFIG_IEEE80211W | |||||
{ "sa_query", hostapd_cli_cmd_sa_query, hostapd_complete_stations, | { "sa_query", hostapd_cli_cmd_sa_query, hostapd_complete_stations, | ||||
"<addr> = send SA Query to a station" }, | "<addr> = send SA Query to a station" }, | ||||
#endif /* CONFIG_IEEE80211W */ | |||||
#ifdef CONFIG_WPS | #ifdef CONFIG_WPS | ||||
{ "wps_pin", hostapd_cli_cmd_wps_pin, NULL, | { "wps_pin", hostapd_cli_cmd_wps_pin, NULL, | ||||
"<uuid> <pin> [timeout] [addr] = add WPS Enrollee PIN" }, | "<uuid> <pin> [timeout] [addr] = add WPS Enrollee PIN" }, | ||||
Context not available. | |||||
{ "set_neighbor", hostapd_cli_cmd_set_neighbor, NULL, | { "set_neighbor", hostapd_cli_cmd_set_neighbor, NULL, | ||||
"<addr> <ssid=> <nr=> [lci=] [civic=] [stat]\n" | "<addr> <ssid=> <nr=> [lci=] [civic=] [stat]\n" | ||||
" = add AP to neighbor database" }, | " = add AP to neighbor database" }, | ||||
{ "show_neighbor", hostapd_cli_cmd_show_neighbor, NULL, | |||||
" = show neighbor database entries" }, | |||||
{ "remove_neighbor", hostapd_cli_cmd_remove_neighbor, NULL, | { "remove_neighbor", hostapd_cli_cmd_remove_neighbor, NULL, | ||||
"<addr> <ssid=> = remove AP from neighbor database" }, | "<addr> [ssid=<hex>] = remove AP from neighbor database" }, | ||||
{ "req_lci", hostapd_cli_cmd_req_lci, hostapd_complete_stations, | { "req_lci", hostapd_cli_cmd_req_lci, hostapd_complete_stations, | ||||
"<addr> = send LCI request to a station"}, | "<addr> = send LCI request to a station"}, | ||||
{ "req_range", hostapd_cli_cmd_req_range, NULL, | { "req_range", hostapd_cli_cmd_req_range, NULL, | ||||
Context not available. | |||||
"<id> = get DPP bootstrap URI" }, | "<id> = get DPP bootstrap URI" }, | ||||
{ "dpp_bootstrap_info", hostapd_cli_cmd_dpp_bootstrap_info, NULL, | { "dpp_bootstrap_info", hostapd_cli_cmd_dpp_bootstrap_info, NULL, | ||||
"<id> = show DPP bootstrap information" }, | "<id> = show DPP bootstrap information" }, | ||||
{ "dpp_bootstrap_set", hostapd_cli_cmd_dpp_bootstrap_set, NULL, | |||||
"<id> [conf=..] [ssid=<SSID>] [ssid_charset=#] [psk=<PSK>] [pass=<passphrase>] [configurator=<id>] [conn_status=#] [akm_use_selector=<0|1>] [group_id=..] [expiry=#] [csrattrs=..] = set DPP configurator parameters" }, | |||||
{ "dpp_auth_init", hostapd_cli_cmd_dpp_auth_init, NULL, | { "dpp_auth_init", hostapd_cli_cmd_dpp_auth_init, NULL, | ||||
"peer=<id> [own=<id>] = initiate DPP bootstrapping" }, | "peer=<id> [own=<id>] = initiate DPP bootstrapping" }, | ||||
{ "dpp_listen", hostapd_cli_cmd_dpp_listen, NULL, | { "dpp_listen", hostapd_cli_cmd_dpp_listen, NULL, | ||||
Context not available. | |||||
"add PKEX code" }, | "add PKEX code" }, | ||||
{ "dpp_pkex_remove", hostapd_cli_cmd_dpp_pkex_remove, NULL, | { "dpp_pkex_remove", hostapd_cli_cmd_dpp_pkex_remove, NULL, | ||||
"*|<id> = remove DPP pkex information" }, | "*|<id> = remove DPP pkex information" }, | ||||
#ifdef CONFIG_DPP2 | |||||
{ "dpp_controller_start", hostapd_cli_cmd_dpp_controller_start, NULL, | |||||
"[tcp_port=<port>] [role=..] = start DPP controller" }, | |||||
{ "dpp_controller_stop", hostapd_cli_cmd_dpp_controller_stop, NULL, | |||||
"= stop DPP controller" }, | |||||
{ "dpp_chirp", hostapd_cli_cmd_dpp_chirp, NULL, | |||||
"own=<BI ID> iter=<count> = start DPP chirp" }, | |||||
{ "dpp_stop_chirp", hostapd_cli_cmd_dpp_stop_chirp, NULL, | |||||
"= stop DPP chirp" }, | |||||
#endif /* CONFIG_DPP2 */ | |||||
#endif /* CONFIG_DPP */ | #endif /* CONFIG_DPP */ | ||||
{ "accept_acl", hostapd_cli_cmd_accept_macacl, NULL, | { "accept_acl", hostapd_cli_cmd_accept_macacl, NULL, | ||||
"=Add/Delete/Show/Clear accept MAC ACL" }, | "=Add/Delete/Show/Clear accept MAC ACL" }, | ||||
Context not available. | |||||
"<addr> [req_mode=] <measurement request hexdump> = send a Beacon report request to a station" }, | "<addr> [req_mode=] <measurement request hexdump> = send a Beacon report request to a station" }, | ||||
{ "reload_wpa_psk", hostapd_cli_cmd_reload_wpa_psk, NULL, | { "reload_wpa_psk", hostapd_cli_cmd_reload_wpa_psk, NULL, | ||||
"= reload wpa_psk_file only" }, | "= reload wpa_psk_file only" }, | ||||
#ifdef ANDROID | |||||
{ "driver", hostapd_cli_cmd_driver, NULL, | |||||
"<driver sub command> [<hex formatted data>] = send driver command data" }, | |||||
#endif /* ANDROID */ | |||||
{ NULL, NULL, NULL, NULL } | { NULL, NULL, NULL, NULL } | ||||
}; | }; | ||||
Context not available. | |||||
int warning_displayed = 0; | int warning_displayed = 0; | ||||
int c; | int c; | ||||
int daemonize = 0; | int daemonize = 0; | ||||
int reconnect = 0; | |||||
if (os_program_init()) | if (os_program_init()) | ||||
return -1; | return -1; | ||||
for (;;) { | for (;;) { | ||||
c = getopt(argc, argv, "a:BhG:i:p:P:s:v"); | c = getopt(argc, argv, "a:BhG:i:p:P:rs:v"); | ||||
if (c < 0) | if (c < 0) | ||||
break; | break; | ||||
switch (c) { | switch (c) { | ||||
Context not available. | |||||
case 'P': | case 'P': | ||||
pid_file = optarg; | pid_file = optarg; | ||||
break; | break; | ||||
case 'r': | |||||
reconnect = 1; | |||||
break; | |||||
case 's': | case 's': | ||||
client_socket_dir = optarg; | client_socket_dir = optarg; | ||||
break; | break; | ||||
Context not available. | |||||
printf("Connection established.\n"); | printf("Connection established.\n"); | ||||
break; | break; | ||||
} | } | ||||
if (!interactive && !reconnect) { | |||||
if (!interactive) { | |||||
perror("Failed to connect to hostapd - " | perror("Failed to connect to hostapd - " | ||||
"wpa_ctrl_open"); | "wpa_ctrl_open"); | ||||
return -1; | return -1; | ||||
Context not available. | |||||
return -1; | return -1; | ||||
if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue()) | if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue()) | ||||
return -1; | return -1; | ||||
if (reconnect && action_file && ctrl_ifname) { | |||||
if (interactive) | while (!hostapd_cli_quit) { | ||||
if (ctrl_conn) | |||||
hostapd_cli_action(ctrl_conn); | |||||
os_sleep(1, 0); | |||||
hostapd_cli_reconnect(ctrl_ifname); | |||||
} | |||||
} else if (interactive) | |||||
hostapd_cli_interactive(); | hostapd_cli_interactive(); | ||||
else if (action_file) | else if (action_file) | ||||
hostapd_cli_action(ctrl_conn); | hostapd_cli_action(ctrl_conn); | ||||
Context not available. |