1 /*
2 * WPA Supplicant - command line interface for wpa_supplicant daemon
3 * Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "includes.h"
10
11 #ifdef CONFIG_CTRL_IFACE
12
13 #ifdef CONFIG_CTRL_IFACE_UNIX
14 #include <dirent.h>
15 #endif /* CONFIG_CTRL_IFACE_UNIX */
16
17 #include "common/cli.h"
18 #include "common/wpa_ctrl.h"
19 #include "utils/common.h"
20 #include "utils/eloop.h"
21 #include "utils/edit.h"
22 #include "utils/list.h"
23 #include "common/version.h"
24 #include "common/ieee802_11_defs.h"
25 #ifdef ANDROID
26 #include <cutils/properties.h>
27 #endif /* ANDROID */
28
29
30 static const char *const wpa_cli_version =
31 "wpa_cli v" VERSION_STR "\n"
32 "Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributors";
33
34 #define VENDOR_ELEM_FRAME_ID \
35 " 0: Probe Req (P2P), 1: Probe Resp (P2P) , 2: Probe Resp (GO), " \
36 "3: Beacon (GO), 4: PD Req, 5: PD Resp, 6: GO Neg Req, " \
37 "7: GO Neg Resp, 8: GO Neg Conf, 9: Inv Req, 10: Inv Resp, " \
38 "11: Assoc Req (P2P), 12: Assoc Resp (P2P)"
39
40 static struct wpa_ctrl *ctrl_conn;
41 static struct wpa_ctrl *mon_conn;
42 static int wpa_cli_quit = 0;
43 static int wpa_cli_attached = 0;
44 static int wpa_cli_connected = -1;
45 static int wpa_cli_last_id = 0;
46 #ifndef CONFIG_CTRL_IFACE_DIR
47 #define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
48 #endif /* CONFIG_CTRL_IFACE_DIR */
49 static const char *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR;
50 static const char *client_socket_dir = NULL;
51 static char *ctrl_ifname = NULL;
52 static const char *global = NULL;
53 static const char *pid_file = NULL;
54 static const char *action_file = NULL;
55 static int reconnect = 0;
56 static int ping_interval = 5;
57 static int interactive = 0;
58 static char *ifname_prefix = NULL;
59
60 static DEFINE_DL_LIST(bsses); /* struct cli_txt_entry */
61 static DEFINE_DL_LIST(p2p_peers); /* struct cli_txt_entry */
62 static DEFINE_DL_LIST(p2p_groups); /* struct cli_txt_entry */
63 static DEFINE_DL_LIST(ifnames); /* struct cli_txt_entry */
64 static DEFINE_DL_LIST(networks); /* struct cli_txt_entry */
65 static DEFINE_DL_LIST(creds); /* struct cli_txt_entry */
66 #ifdef CONFIG_AP
67 static DEFINE_DL_LIST(stations); /* struct cli_txt_entry */
68 #endif /* CONFIG_AP */
69
70
71 static void print_help(const char *cmd);
72 static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx);
73 static void wpa_cli_close_connection(void);
74 static char * wpa_cli_get_default_ifname(void);
75 static char ** wpa_list_cmd_list(void);
76 static void update_creds(struct wpa_ctrl *ctrl);
77 static void update_networks(struct wpa_ctrl *ctrl);
78 static void update_stations(struct wpa_ctrl *ctrl);
79 static void update_ifnames(struct wpa_ctrl *ctrl);
80
81
usage(void)82 static void usage(void)
83 {
84 printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvBr] "
85 "[-a<action file>] \\\n"
86 " [-P<pid file>] [-g<global ctrl>] [-G<ping interval>] "
87 "\\\n"
88 " [-s<wpa_client_socket_file_path>] "
89 "[command..]\n"
90 " -h = help (show this usage text)\n"
91 " -v = shown version information\n"
92 " -a = run in daemon mode executing the action file based on "
93 "events from\n"
94 " wpa_supplicant\n"
95 " -r = try to reconnect when client socket is disconnected.\n"
96 " This is useful only when used with -a.\n"
97 " -B = run a daemon in the background\n"
98 " default path: " CONFIG_CTRL_IFACE_DIR "\n"
99 " default interface: first interface found in socket path\n");
100 print_help(NULL);
101 }
102
103
wpa_cli_show_event(const char * event)104 static int wpa_cli_show_event(const char *event)
105 {
106 const char *start;
107
108 start = os_strchr(event, '>');
109 if (start == NULL)
110 return 1;
111
112 start++;
113 /*
114 * Skip BSS added/removed events since they can be relatively frequent
115 * and are likely of not much use for an interactive user.
116 */
117 if (str_starts(start, WPA_EVENT_BSS_ADDED) ||
118 str_starts(start, WPA_EVENT_BSS_REMOVED))
119 return 0;
120
121 return 1;
122 }
123
124
wpa_cli_open_connection(const char * ifname,int attach)125 static int wpa_cli_open_connection(const char *ifname, int attach)
126 {
127 #if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
128 ctrl_conn = wpa_ctrl_open(ifname);
129 if (ctrl_conn == NULL)
130 return -1;
131
132 if (attach && interactive)
133 mon_conn = wpa_ctrl_open(ifname);
134 else
135 mon_conn = NULL;
136 #else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
137 char *cfile = NULL;
138 int flen, res;
139
140 if (ifname == NULL)
141 return -1;
142
143 #ifdef ANDROID
144 if (access(ctrl_iface_dir, F_OK) < 0) {
145 cfile = os_strdup(ifname);
146 if (cfile == NULL)
147 return -1;
148 }
149 #endif /* ANDROID */
150
151 if (client_socket_dir && client_socket_dir[0] &&
152 access(client_socket_dir, F_OK) < 0) {
153 perror(client_socket_dir);
154 os_free(cfile);
155 return -1;
156 }
157
158 if (cfile == NULL) {
159 flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
160 cfile = os_malloc(flen);
161 if (cfile == NULL)
162 return -1;
163 res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir,
164 ifname);
165 if (os_snprintf_error(flen, res)) {
166 os_free(cfile);
167 return -1;
168 }
169 }
170
171 ctrl_conn = wpa_ctrl_open2(cfile, client_socket_dir);
172 if (ctrl_conn == NULL) {
173 os_free(cfile);
174 return -1;
175 }
176
177 if (attach && interactive)
178 mon_conn = wpa_ctrl_open2(cfile, client_socket_dir);
179 else
180 mon_conn = NULL;
181 os_free(cfile);
182 #endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
183
184 if (mon_conn) {
185 if (wpa_ctrl_attach(mon_conn) == 0) {
186 wpa_cli_attached = 1;
187 if (interactive)
188 eloop_register_read_sock(
189 wpa_ctrl_get_fd(mon_conn),
190 wpa_cli_mon_receive, NULL, NULL);
191 } else {
192 printf("Warning: Failed to attach to "
193 "wpa_supplicant.\n");
194 wpa_cli_close_connection();
195 return -1;
196 }
197 }
198
199 return 0;
200 }
201
202
wpa_cli_close_connection(void)203 static void wpa_cli_close_connection(void)
204 {
205 if (ctrl_conn == NULL)
206 return;
207
208 if (wpa_cli_attached) {
209 wpa_ctrl_detach(interactive ? mon_conn : ctrl_conn);
210 wpa_cli_attached = 0;
211 }
212 wpa_ctrl_close(ctrl_conn);
213 ctrl_conn = NULL;
214 if (mon_conn) {
215 eloop_unregister_read_sock(wpa_ctrl_get_fd(mon_conn));
216 wpa_ctrl_close(mon_conn);
217 mon_conn = NULL;
218 }
219 }
220
221
wpa_cli_msg_cb(char * msg,size_t len)222 static void wpa_cli_msg_cb(char *msg, size_t len)
223 {
224 printf("%s\n", msg);
225 }
226
227
_wpa_ctrl_command(struct wpa_ctrl * ctrl,const char * cmd,int print)228 static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd, int print)
229 {
230 char buf[4096];
231 size_t len;
232 int ret;
233
234 if (ctrl_conn == NULL) {
235 printf("Not connected to wpa_supplicant - command dropped.\n");
236 return -1;
237 }
238 if (ifname_prefix) {
239 os_snprintf(buf, sizeof(buf), "IFNAME=%s %s",
240 ifname_prefix, cmd);
241 buf[sizeof(buf) - 1] = '\0';
242 cmd = buf;
243 }
244 len = sizeof(buf) - 1;
245 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
246 wpa_cli_msg_cb);
247 if (ret == -2) {
248 printf("'%s' command timed out.\n", cmd);
249 return -2;
250 } else if (ret < 0) {
251 printf("'%s' command failed.\n", cmd);
252 return -1;
253 }
254 if (print) {
255 buf[len] = '\0';
256 printf("%s", buf);
257 if (interactive && len > 0 && buf[len - 1] != '\n')
258 printf("\n");
259 }
260 return 0;
261 }
262
263
wpa_ctrl_command(struct wpa_ctrl * ctrl,const char * cmd)264 static int wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd)
265 {
266 return _wpa_ctrl_command(ctrl, cmd, 1);
267 }
268
269
wpa_cli_cmd(struct wpa_ctrl * ctrl,const char * cmd,int min_args,int argc,char * argv[])270 static int wpa_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd, int min_args,
271 int argc, char *argv[])
272 {
273 char buf[4096];
274 if (argc < min_args) {
275 printf("Invalid %s command - at least %d argument%s "
276 "required.\n", cmd, min_args,
277 min_args > 1 ? "s are" : " is");
278 return -1;
279 }
280 if (write_cmd(buf, sizeof(buf), cmd, argc, argv) < 0)
281 return -1;
282 return wpa_ctrl_command(ctrl, buf);
283 }
284
285
wpa_cli_cmd_ifname(struct wpa_ctrl * ctrl,int argc,char * argv[])286 static int wpa_cli_cmd_ifname(struct wpa_ctrl *ctrl, int argc, char *argv[])
287 {
288 return wpa_ctrl_command(ctrl, "IFNAME");
289 }
290
291
wpa_cli_cmd_status(struct wpa_ctrl * ctrl,int argc,char * argv[])292 static int wpa_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
293 {
294 if (argc > 0 && os_strcmp(argv[0], "verbose") == 0)
295 return wpa_ctrl_command(ctrl, "STATUS-VERBOSE");
296 if (argc > 0 && os_strcmp(argv[0], "wps") == 0)
297 return wpa_ctrl_command(ctrl, "STATUS-WPS");
298 if (argc > 0 && os_strcmp(argv[0], "driver") == 0)
299 return wpa_ctrl_command(ctrl, "STATUS-DRIVER");
300 #ifdef ANDROID
301 if (argc > 0 && os_strcmp(argv[0], "no_events") == 0)
302 return wpa_ctrl_command(ctrl, "STATUS-NO_EVENTS");
303 #endif /* ANDROID */
304 return wpa_ctrl_command(ctrl, "STATUS");
305 }
306
307
wpa_cli_cmd_ping(struct wpa_ctrl * ctrl,int argc,char * argv[])308 static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
309 {
310 return wpa_ctrl_command(ctrl, "PING");
311 }
312
313
wpa_cli_cmd_relog(struct wpa_ctrl * ctrl,int argc,char * argv[])314 static int wpa_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
315 {
316 return wpa_ctrl_command(ctrl, "RELOG");
317 }
318
319
wpa_cli_cmd_note(struct wpa_ctrl * ctrl,int argc,char * argv[])320 static int wpa_cli_cmd_note(struct wpa_ctrl *ctrl, int argc, char *argv[])
321 {
322 return wpa_cli_cmd(ctrl, "NOTE", 1, argc, argv);
323 }
324
325
wpa_cli_cmd_mib(struct wpa_ctrl * ctrl,int argc,char * argv[])326 static int wpa_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
327 {
328 return wpa_ctrl_command(ctrl, "MIB");
329 }
330
331
wpa_cli_cmd_pmksa(struct wpa_ctrl * ctrl,int argc,char * argv[])332 static int wpa_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int argc, char *argv[])
333 {
334 return wpa_ctrl_command(ctrl, "PMKSA");
335 }
336
337
wpa_cli_cmd_pmksa_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])338 static int wpa_cli_cmd_pmksa_flush(struct wpa_ctrl *ctrl, int argc,
339 char *argv[])
340 {
341 return wpa_ctrl_command(ctrl, "PMKSA_FLUSH");
342 }
343
344
345 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
346
wpa_cli_cmd_pmksa_get(struct wpa_ctrl * ctrl,int argc,char * argv[])347 static int wpa_cli_cmd_pmksa_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
348 {
349 return wpa_cli_cmd(ctrl, "PMKSA_GET", 1, argc, argv);
350 }
351
352
wpa_cli_cmd_pmksa_add(struct wpa_ctrl * ctrl,int argc,char * argv[])353 static int wpa_cli_cmd_pmksa_add(struct wpa_ctrl *ctrl, int argc, char *argv[])
354 {
355 return wpa_cli_cmd(ctrl, "PMKSA_ADD", 8, argc, argv);
356 }
357
358
359 #ifdef CONFIG_MESH
360
wpa_cli_mesh_cmd_pmksa_get(struct wpa_ctrl * ctrl,int argc,char * argv[])361 static int wpa_cli_mesh_cmd_pmksa_get(struct wpa_ctrl *ctrl, int argc,
362 char *argv[])
363 {
364 return wpa_cli_cmd(ctrl, "MESH_PMKSA_GET", 1, argc, argv);
365 }
366
367
wpa_cli_mesh_cmd_pmksa_add(struct wpa_ctrl * ctrl,int argc,char * argv[])368 static int wpa_cli_mesh_cmd_pmksa_add(struct wpa_ctrl *ctrl, int argc,
369 char *argv[])
370 {
371 return wpa_cli_cmd(ctrl, "MESH_PMKSA_ADD", 4, argc, argv);
372 }
373
374 #endif /* CONFIG_MESH */
375 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
376
377
wpa_cli_cmd_help(struct wpa_ctrl * ctrl,int argc,char * argv[])378 static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
379 {
380 print_help(argc > 0 ? argv[0] : NULL);
381 return 0;
382 }
383
384
wpa_cli_complete_help(const char * str,int pos)385 static char ** wpa_cli_complete_help(const char *str, int pos)
386 {
387 int arg = get_cmd_arg_num(str, pos);
388 char **res = NULL;
389
390 switch (arg) {
391 case 1:
392 res = wpa_list_cmd_list();
393 break;
394 }
395
396 return res;
397 }
398
399
wpa_cli_cmd_license(struct wpa_ctrl * ctrl,int argc,char * argv[])400 static int wpa_cli_cmd_license(struct wpa_ctrl *ctrl, int argc, char *argv[])
401 {
402 printf("%s\n\n%s\n", wpa_cli_version, cli_full_license);
403 return 0;
404 }
405
406
wpa_cli_cmd_quit(struct wpa_ctrl * ctrl,int argc,char * argv[])407 static int wpa_cli_cmd_quit(struct wpa_ctrl *ctrl, int argc, char *argv[])
408 {
409 wpa_cli_quit = 1;
410 if (interactive)
411 eloop_terminate();
412 return 0;
413 }
414
415
wpa_cli_cmd_set(struct wpa_ctrl * ctrl,int argc,char * argv[])416 static int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
417 {
418 char cmd[256];
419 int res;
420
421 if (argc == 1) {
422 res = os_snprintf(cmd, sizeof(cmd), "SET %s ", argv[0]);
423 if (os_snprintf_error(sizeof(cmd), res)) {
424 printf("Too long SET command.\n");
425 return -1;
426 }
427 return wpa_ctrl_command(ctrl, cmd);
428 }
429
430 return wpa_cli_cmd(ctrl, "SET", 2, argc, argv);
431 }
432
433
wpa_cli_complete_set(const char * str,int pos)434 static char ** wpa_cli_complete_set(const char *str, int pos)
435 {
436 int arg = get_cmd_arg_num(str, pos);
437 const char *fields[] = {
438 /* runtime values */
439 "EAPOL::heldPeriod", "EAPOL::authPeriod", "EAPOL::startPeriod",
440 "EAPOL::maxStart", "dot11RSNAConfigPMKLifetime",
441 "dot11RSNAConfigPMKReauthThreshold", "dot11RSNAConfigSATimeout",
442 "wps_fragment_size", "wps_version_number", "ampdu",
443 "tdls_testing", "tdls_disabled", "pno", "radio_disabled",
444 "uapsd", "ps", "wifi_display", "bssid_filter", "disallow_aps",
445 "no_keep_alive",
446 /* global configuration parameters */
447 #ifdef CONFIG_CTRL_IFACE
448 "ctrl_interface", "no_ctrl_interface", "ctrl_interface_group",
449 #endif /* CONFIG_CTRL_IFACE */
450 "eapol_version", "ap_scan", "bgscan",
451 #ifdef CONFIG_MESH
452 "user_mpm", "max_peer_links", "mesh_max_inactivity",
453 "dot11RSNASAERetransPeriod",
454 #endif /* CONFIG_MESH */
455 "disable_scan_offload", "fast_reauth", "opensc_engine_path",
456 "pkcs11_engine_path", "pkcs11_module_path", "openssl_ciphers",
457 "pcsc_reader", "pcsc_pin", "external_sim", "driver_param",
458 "dot11RSNAConfigPMKLifetime",
459 "dot11RSNAConfigPMKReauthThreshold",
460 "dot11RSNAConfigSATimeout",
461 #ifndef CONFIG_NO_CONFIG_WRITE
462 "update_config",
463 #endif /* CONFIG_NO_CONFIG_WRITE */
464 "load_dynamic_eap",
465 #ifdef CONFIG_WPS
466 "uuid", "device_name", "manufacturer", "model_name",
467 "model_number", "serial_number", "device_type", "os_version",
468 "config_methods", "wps_cred_processing", "wps_vendor_ext_m1",
469 #endif /* CONFIG_WPS */
470 #ifdef CONFIG_P2P
471 "sec_device_type",
472 "p2p_listen_reg_class", "p2p_listen_channel",
473 "p2p_oper_reg_class", "p2p_oper_channel", "p2p_go_intent",
474 "p2p_ssid_postfix", "persistent_reconnect", "p2p_intra_bss",
475 "p2p_group_idle", "p2p_passphrase_len", "p2p_pref_chan",
476 "p2p_no_go_freq", "p2p_add_cli_chan",
477 "p2p_optimize_listen_chan", "p2p_go_ht40", "p2p_go_vht",
478 "p2p_disabled", "p2p_go_ctwindow", "p2p_no_group_iface",
479 "p2p_ignore_shared_freq", "ip_addr_go", "ip_addr_mask",
480 "ip_addr_start", "ip_addr_end", "p2p_go_edmg",
481 #endif /* CONFIG_P2P */
482 "country", "bss_max_count", "bss_expiration_age",
483 "bss_expiration_scan_count", "filter_ssids", "filter_rssi",
484 "max_num_sta", "disassoc_low_ack", "ap_isolate",
485 #ifdef CONFIG_HS20
486 "hs20",
487 #endif /* CONFIG_HS20 */
488 "interworking", "hessid", "access_network_type", "pbc_in_m1",
489 "go_interworking", "go_access_network_type", "go_internet",
490 "go_venue_group", "go_venue_type",
491 "autoscan", "wps_nfc_dev_pw_id", "wps_nfc_dh_pubkey",
492 "wps_nfc_dh_privkey", "wps_nfc_dev_pw", "ext_password_backend",
493 "p2p_go_max_inactivity", "auto_interworking", "okc", "pmf",
494 "sae_groups", "dtim_period", "beacon_int",
495 "ap_vendor_elements", "ignore_old_scan_res", "freq_list",
496 "scan_cur_freq", "scan_res_valid_for_connect",
497 "sched_scan_interval",
498 "tdls_external_control", "osu_dir", "wowlan_triggers",
499 "p2p_search_delay", "mac_addr", "rand_addr_lifetime",
500 "preassoc_mac_addr", "key_mgmt_offload", "passive_scan",
501 "reassoc_same_bss_optim", "wps_priority",
502 #ifdef CONFIG_TESTING_OPTIONS
503 "ignore_auth_resp",
504 #endif /* CONFIG_TESTING_OPTIONS */
505 "relative_rssi", "relative_band_adjust",
506 "extended_key_id",
507 };
508 int i, num_fields = ARRAY_SIZE(fields);
509
510 if (arg == 1) {
511 char **res = os_calloc(num_fields + 1, sizeof(char *));
512 if (res == NULL)
513 return NULL;
514 for (i = 0; i < num_fields; i++) {
515 res[i] = os_strdup(fields[i]);
516 if (res[i] == NULL)
517 return res;
518 }
519 return res;
520 }
521
522 if (arg > 1 && os_strncasecmp(str, "set bssid_filter ", 17) == 0)
523 return cli_txt_list_array(&bsses);
524
525 return NULL;
526 }
527
wpa_cli_cmd_dump(struct wpa_ctrl * ctrl,int argc,char * argv[])528 static int wpa_cli_cmd_dump(struct wpa_ctrl *ctrl, int argc, char *argv[])
529 {
530 return wpa_ctrl_command(ctrl, "DUMP");
531 }
532
533
wpa_cli_cmd_driver_flags(struct wpa_ctrl * ctrl,int argc,char * argv[])534 static int wpa_cli_cmd_driver_flags(struct wpa_ctrl *ctrl, int argc,
535 char *argv[])
536 {
537 return wpa_ctrl_command(ctrl, "DRIVER_FLAGS");
538 }
539
540
wpa_cli_cmd_get(struct wpa_ctrl * ctrl,int argc,char * argv[])541 static int wpa_cli_cmd_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
542 {
543 return wpa_cli_cmd(ctrl, "GET", 1, argc, argv);
544 }
545
546
wpa_cli_complete_get(const char * str,int pos)547 static char ** wpa_cli_complete_get(const char *str, int pos)
548 {
549 int arg = get_cmd_arg_num(str, pos);
550 const char *fields[] = {
551 #ifdef CONFIG_CTRL_IFACE
552 "ctrl_interface", "ctrl_interface_group",
553 #endif /* CONFIG_CTRL_IFACE */
554 "eapol_version", "ap_scan",
555 #ifdef CONFIG_MESH
556 "user_mpm", "max_peer_links", "mesh_max_inactivity",
557 #endif /* CONFIG_MESH */
558 "disable_scan_offload", "fast_reauth", "opensc_engine_path",
559 "pkcs11_engine_path", "pkcs11_module_path", "openssl_ciphers",
560 "pcsc_reader", "pcsc_pin", "external_sim", "driver_param",
561 "dot11RSNAConfigPMKLifetime",
562 "dot11RSNAConfigPMKReauthThreshold",
563 "dot11RSNAConfigSATimeout",
564 #ifndef CONFIG_NO_CONFIG_WRITE
565 "update_config",
566 #endif /* CONFIG_NO_CONFIG_WRITE */
567 #ifdef CONFIG_WPS
568 "device_name", "manufacturer", "model_name", "model_number",
569 "serial_number", "config_methods", "wps_cred_processing",
570 #endif /* CONFIG_WPS */
571 #ifdef CONFIG_P2P
572 "p2p_listen_reg_class", "p2p_listen_channel",
573 "p2p_oper_reg_class", "p2p_oper_channel", "p2p_go_intent",
574 "p2p_ssid_postfix", "persistent_reconnect", "p2p_intra_bss",
575 "p2p_group_idle", "p2p_passphrase_len", "p2p_add_cli_chan",
576 "p2p_optimize_listen_chan", "p2p_go_ht40", "p2p_go_vht",
577 "p2p_disabled", "p2p_go_ctwindow", "p2p_no_group_iface",
578 "p2p_ignore_shared_freq", "ip_addr_go", "ip_addr_mask",
579 "ip_addr_start", "ip_addr_end",
580 #endif /* CONFIG_P2P */
581 "bss_max_count", "bss_expiration_age",
582 "bss_expiration_scan_count", "filter_ssids", "filter_rssi",
583 "max_num_sta", "disassoc_low_ack", "ap_isolate",
584 #ifdef CONFIG_HS20
585 "hs20",
586 #endif /* CONFIG_HS20 */
587 "interworking", "access_network_type", "pbc_in_m1", "autoscan",
588 "go_interworking", "go_access_network_type", "go_internet",
589 "go_venue_group", "go_venue_type",
590 "wps_nfc_dev_pw_id", "ext_password_backend",
591 "p2p_go_max_inactivity", "auto_interworking", "okc", "pmf",
592 "dtim_period", "beacon_int", "ignore_old_scan_res",
593 "scan_cur_freq", "scan_res_valid_for_connect",
594 "sched_scan_interval",
595 "sched_scan_start_delay",
596 "tdls_external_control", "osu_dir", "wowlan_triggers",
597 "p2p_search_delay", "mac_addr", "rand_addr_lifetime",
598 "preassoc_mac_addr", "key_mgmt_offload", "passive_scan",
599 "reassoc_same_bss_optim", "extended_key_id"
600 };
601 int i, num_fields = ARRAY_SIZE(fields);
602
603 if (arg == 1) {
604 char **res = os_calloc(num_fields + 1, sizeof(char *));
605 if (res == NULL)
606 return NULL;
607 for (i = 0; i < num_fields; i++) {
608 res[i] = os_strdup(fields[i]);
609 if (res[i] == NULL)
610 return res;
611 }
612 return res;
613 }
614
615 return NULL;
616 }
617
618
wpa_cli_cmd_logoff(struct wpa_ctrl * ctrl,int argc,char * argv[])619 static int wpa_cli_cmd_logoff(struct wpa_ctrl *ctrl, int argc, char *argv[])
620 {
621 return wpa_ctrl_command(ctrl, "LOGOFF");
622 }
623
624
wpa_cli_cmd_logon(struct wpa_ctrl * ctrl,int argc,char * argv[])625 static int wpa_cli_cmd_logon(struct wpa_ctrl *ctrl, int argc, char *argv[])
626 {
627 return wpa_ctrl_command(ctrl, "LOGON");
628 }
629
630
wpa_cli_cmd_reassociate(struct wpa_ctrl * ctrl,int argc,char * argv[])631 static int wpa_cli_cmd_reassociate(struct wpa_ctrl *ctrl, int argc,
632 char *argv[])
633 {
634 return wpa_ctrl_command(ctrl, "REASSOCIATE");
635 }
636
637
wpa_cli_cmd_reattach(struct wpa_ctrl * ctrl,int argc,char * argv[])638 static int wpa_cli_cmd_reattach(struct wpa_ctrl *ctrl, int argc, char *argv[])
639 {
640 return wpa_ctrl_command(ctrl, "REATTACH");
641 }
642
643
wpa_cli_cmd_preauthenticate(struct wpa_ctrl * ctrl,int argc,char * argv[])644 static int wpa_cli_cmd_preauthenticate(struct wpa_ctrl *ctrl, int argc,
645 char *argv[])
646 {
647 return wpa_cli_cmd(ctrl, "PREAUTH", 1, argc, argv);
648 }
649
650
wpa_cli_cmd_ap_scan(struct wpa_ctrl * ctrl,int argc,char * argv[])651 static int wpa_cli_cmd_ap_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
652 {
653 return wpa_cli_cmd(ctrl, "AP_SCAN", 1, argc, argv);
654 }
655
656
wpa_cli_cmd_scan_interval(struct wpa_ctrl * ctrl,int argc,char * argv[])657 static int wpa_cli_cmd_scan_interval(struct wpa_ctrl *ctrl, int argc,
658 char *argv[])
659 {
660 return wpa_cli_cmd(ctrl, "SCAN_INTERVAL", 1, argc, argv);
661 }
662
663
wpa_cli_cmd_bss_expire_age(struct wpa_ctrl * ctrl,int argc,char * argv[])664 static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
665 char *argv[])
666 {
667 return wpa_cli_cmd(ctrl, "BSS_EXPIRE_AGE", 1, argc, argv);
668 }
669
670
wpa_cli_cmd_bss_expire_count(struct wpa_ctrl * ctrl,int argc,char * argv[])671 static int wpa_cli_cmd_bss_expire_count(struct wpa_ctrl *ctrl, int argc,
672 char *argv[])
673 {
674 return wpa_cli_cmd(ctrl, "BSS_EXPIRE_COUNT", 1, argc, argv);
675 }
676
677
wpa_cli_cmd_bss_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])678 static int wpa_cli_cmd_bss_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
679 {
680 char cmd[256];
681 int res;
682
683 if (argc < 1)
684 res = os_snprintf(cmd, sizeof(cmd), "BSS_FLUSH 0");
685 else
686 res = os_snprintf(cmd, sizeof(cmd), "BSS_FLUSH %s", argv[0]);
687 if (os_snprintf_error(sizeof(cmd), res)) {
688 printf("Too long BSS_FLUSH command.\n");
689 return -1;
690 }
691 return wpa_ctrl_command(ctrl, cmd);
692 }
693
694
wpa_cli_cmd_ft_ds(struct wpa_ctrl * ctrl,int argc,char * argv[])695 static int wpa_cli_cmd_ft_ds(struct wpa_ctrl *ctrl, int argc, char *argv[])
696 {
697 return wpa_cli_cmd(ctrl, "FT_DS", 1, argc, argv);
698 }
699
700
wpa_cli_cmd_wps_pbc(struct wpa_ctrl * ctrl,int argc,char * argv[])701 static int wpa_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc, char *argv[])
702 {
703 return wpa_cli_cmd(ctrl, "WPS_PBC", 0, argc, argv);
704 }
705
706
wpa_cli_cmd_wps_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])707 static int wpa_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
708 {
709 if (argc == 0) {
710 printf("Invalid WPS_PIN command: need one or two arguments:\n"
711 "- BSSID: use 'any' to select any\n"
712 "- PIN: optional, used only with devices that have no "
713 "display\n");
714 return -1;
715 }
716
717 return wpa_cli_cmd(ctrl, "WPS_PIN", 1, argc, argv);
718 }
719
720
wpa_cli_cmd_wps_check_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])721 static int wpa_cli_cmd_wps_check_pin(struct wpa_ctrl *ctrl, int argc,
722 char *argv[])
723 {
724 return wpa_cli_cmd(ctrl, "WPS_CHECK_PIN", 1, argc, argv);
725 }
726
727
wpa_cli_cmd_wps_cancel(struct wpa_ctrl * ctrl,int argc,char * argv[])728 static int wpa_cli_cmd_wps_cancel(struct wpa_ctrl *ctrl, int argc,
729 char *argv[])
730 {
731 return wpa_ctrl_command(ctrl, "WPS_CANCEL");
732 }
733
734
735 #ifdef CONFIG_WPS_NFC
736
wpa_cli_cmd_wps_nfc(struct wpa_ctrl * ctrl,int argc,char * argv[])737 static int wpa_cli_cmd_wps_nfc(struct wpa_ctrl *ctrl, int argc, char *argv[])
738 {
739 return wpa_cli_cmd(ctrl, "WPS_NFC", 0, argc, argv);
740 }
741
742
wpa_cli_cmd_wps_nfc_config_token(struct wpa_ctrl * ctrl,int argc,char * argv[])743 static int wpa_cli_cmd_wps_nfc_config_token(struct wpa_ctrl *ctrl, int argc,
744 char *argv[])
745 {
746 return wpa_cli_cmd(ctrl, "WPS_NFC_CONFIG_TOKEN", 1, argc, argv);
747 }
748
749
wpa_cli_cmd_wps_nfc_token(struct wpa_ctrl * ctrl,int argc,char * argv[])750 static int wpa_cli_cmd_wps_nfc_token(struct wpa_ctrl *ctrl, int argc,
751 char *argv[])
752 {
753 return wpa_cli_cmd(ctrl, "WPS_NFC_TOKEN", 1, argc, argv);
754 }
755
756
wpa_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl * ctrl,int argc,char * argv[])757 static int wpa_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl *ctrl, int argc,
758 char *argv[])
759 {
760 int ret;
761 char *buf;
762 size_t buflen;
763
764 if (argc != 1) {
765 printf("Invalid 'wps_nfc_tag_read' command - one argument "
766 "is required.\n");
767 return -1;
768 }
769
770 buflen = 18 + os_strlen(argv[0]);
771 buf = os_malloc(buflen);
772 if (buf == NULL)
773 return -1;
774 os_snprintf(buf, buflen, "WPS_NFC_TAG_READ %s", argv[0]);
775
776 ret = wpa_ctrl_command(ctrl, buf);
777 os_free(buf);
778
779 return ret;
780 }
781
782
wpa_cli_cmd_nfc_get_handover_req(struct wpa_ctrl * ctrl,int argc,char * argv[])783 static int wpa_cli_cmd_nfc_get_handover_req(struct wpa_ctrl *ctrl, int argc,
784 char *argv[])
785 {
786 return wpa_cli_cmd(ctrl, "NFC_GET_HANDOVER_REQ", 2, argc, argv);
787 }
788
789
wpa_cli_cmd_nfc_get_handover_sel(struct wpa_ctrl * ctrl,int argc,char * argv[])790 static int wpa_cli_cmd_nfc_get_handover_sel(struct wpa_ctrl *ctrl, int argc,
791 char *argv[])
792 {
793 return wpa_cli_cmd(ctrl, "NFC_GET_HANDOVER_SEL", 2, argc, argv);
794 }
795
796
wpa_cli_cmd_nfc_report_handover(struct wpa_ctrl * ctrl,int argc,char * argv[])797 static int wpa_cli_cmd_nfc_report_handover(struct wpa_ctrl *ctrl, int argc,
798 char *argv[])
799 {
800 return wpa_cli_cmd(ctrl, "NFC_REPORT_HANDOVER", 4, argc, argv);
801 }
802
803 #endif /* CONFIG_WPS_NFC */
804
805
wpa_cli_cmd_wps_reg(struct wpa_ctrl * ctrl,int argc,char * argv[])806 static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
807 {
808 char cmd[256];
809 int res;
810
811 if (argc == 2)
812 res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s",
813 argv[0], argv[1]);
814 else if (argc == 5 || argc == 6) {
815 char ssid_hex[2 * SSID_MAX_LEN + 1];
816 char key_hex[2 * 64 + 1];
817 int i;
818
819 ssid_hex[0] = '\0';
820 for (i = 0; i < SSID_MAX_LEN; i++) {
821 if (argv[2][i] == '\0')
822 break;
823 os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
824 }
825
826 key_hex[0] = '\0';
827 if (argc == 6) {
828 for (i = 0; i < 64; i++) {
829 if (argv[5][i] == '\0')
830 break;
831 os_snprintf(&key_hex[i * 2], 3, "%02x",
832 argv[5][i]);
833 }
834 }
835
836 res = os_snprintf(cmd, sizeof(cmd),
837 "WPS_REG %s %s %s %s %s %s",
838 argv[0], argv[1], ssid_hex, argv[3], argv[4],
839 key_hex);
840 } else {
841 printf("Invalid WPS_REG command: need two arguments:\n"
842 "- BSSID of the target AP\n"
843 "- AP PIN\n");
844 printf("Alternatively, six arguments can be used to "
845 "reconfigure the AP:\n"
846 "- BSSID of the target AP\n"
847 "- AP PIN\n"
848 "- new SSID\n"
849 "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
850 "- new encr (NONE, WEP, TKIP, CCMP)\n"
851 "- new key\n");
852 return -1;
853 }
854
855 if (os_snprintf_error(sizeof(cmd), res)) {
856 printf("Too long WPS_REG command.\n");
857 return -1;
858 }
859 return wpa_ctrl_command(ctrl, cmd);
860 }
861
862
wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])863 static int wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
864 char *argv[])
865 {
866 return wpa_cli_cmd(ctrl, "WPS_AP_PIN", 1, argc, argv);
867 }
868
869
wpa_cli_cmd_wps_er_start(struct wpa_ctrl * ctrl,int argc,char * argv[])870 static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl *ctrl, int argc,
871 char *argv[])
872 {
873 return wpa_cli_cmd(ctrl, "WPS_ER_START", 0, argc, argv);
874 }
875
876
wpa_cli_cmd_wps_er_stop(struct wpa_ctrl * ctrl,int argc,char * argv[])877 static int wpa_cli_cmd_wps_er_stop(struct wpa_ctrl *ctrl, int argc,
878 char *argv[])
879 {
880 return wpa_ctrl_command(ctrl, "WPS_ER_STOP");
881
882 }
883
884
wpa_cli_cmd_wps_er_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])885 static int wpa_cli_cmd_wps_er_pin(struct wpa_ctrl *ctrl, int argc,
886 char *argv[])
887 {
888 if (argc < 2) {
889 printf("Invalid WPS_ER_PIN command: need at least two "
890 "arguments:\n"
891 "- UUID: use 'any' to select any\n"
892 "- PIN: Enrollee PIN\n"
893 "optional: - Enrollee MAC address\n");
894 return -1;
895 }
896
897 return wpa_cli_cmd(ctrl, "WPS_ER_PIN", 2, argc, argv);
898 }
899
900
wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl * ctrl,int argc,char * argv[])901 static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl *ctrl, int argc,
902 char *argv[])
903 {
904 return wpa_cli_cmd(ctrl, "WPS_ER_PBC", 1, argc, argv);
905 }
906
907
wpa_cli_cmd_wps_er_learn(struct wpa_ctrl * ctrl,int argc,char * argv[])908 static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl *ctrl, int argc,
909 char *argv[])
910 {
911 if (argc != 2) {
912 printf("Invalid WPS_ER_LEARN command: need two arguments:\n"
913 "- UUID: specify which AP to use\n"
914 "- PIN: AP PIN\n");
915 return -1;
916 }
917
918 return wpa_cli_cmd(ctrl, "WPS_ER_LEARN", 2, argc, argv);
919 }
920
921
wpa_cli_cmd_wps_er_set_config(struct wpa_ctrl * ctrl,int argc,char * argv[])922 static int wpa_cli_cmd_wps_er_set_config(struct wpa_ctrl *ctrl, int argc,
923 char *argv[])
924 {
925 if (argc != 2) {
926 printf("Invalid WPS_ER_SET_CONFIG command: need two "
927 "arguments:\n"
928 "- UUID: specify which AP to use\n"
929 "- Network configuration id\n");
930 return -1;
931 }
932
933 return wpa_cli_cmd(ctrl, "WPS_ER_SET_CONFIG", 2, argc, argv);
934 }
935
936
wpa_cli_cmd_wps_er_config(struct wpa_ctrl * ctrl,int argc,char * argv[])937 static int wpa_cli_cmd_wps_er_config(struct wpa_ctrl *ctrl, int argc,
938 char *argv[])
939 {
940 char cmd[256];
941 int res;
942
943 if (argc == 5 || argc == 6) {
944 char ssid_hex[2 * SSID_MAX_LEN + 1];
945 char key_hex[2 * 64 + 1];
946 int i;
947
948 ssid_hex[0] = '\0';
949 for (i = 0; i < SSID_MAX_LEN; i++) {
950 if (argv[2][i] == '\0')
951 break;
952 os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
953 }
954
955 key_hex[0] = '\0';
956 if (argc == 6) {
957 for (i = 0; i < 64; i++) {
958 if (argv[5][i] == '\0')
959 break;
960 os_snprintf(&key_hex[i * 2], 3, "%02x",
961 argv[5][i]);
962 }
963 }
964
965 res = os_snprintf(cmd, sizeof(cmd),
966 "WPS_ER_CONFIG %s %s %s %s %s %s",
967 argv[0], argv[1], ssid_hex, argv[3], argv[4],
968 key_hex);
969 } else {
970 printf("Invalid WPS_ER_CONFIG command: need six arguments:\n"
971 "- AP UUID\n"
972 "- AP PIN\n"
973 "- new SSID\n"
974 "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
975 "- new encr (NONE, WEP, TKIP, CCMP)\n"
976 "- new key\n");
977 return -1;
978 }
979
980 if (os_snprintf_error(sizeof(cmd), res)) {
981 printf("Too long WPS_ER_CONFIG command.\n");
982 return -1;
983 }
984 return wpa_ctrl_command(ctrl, cmd);
985 }
986
987
988 #ifdef CONFIG_WPS_NFC
wpa_cli_cmd_wps_er_nfc_config_token(struct wpa_ctrl * ctrl,int argc,char * argv[])989 static int wpa_cli_cmd_wps_er_nfc_config_token(struct wpa_ctrl *ctrl, int argc,
990 char *argv[])
991 {
992 if (argc != 2) {
993 printf("Invalid WPS_ER_NFC_CONFIG_TOKEN command: need two "
994 "arguments:\n"
995 "- WPS/NDEF: token format\n"
996 "- UUID: specify which AP to use\n");
997 return -1;
998 }
999
1000 return wpa_cli_cmd(ctrl, "WPS_ER_NFC_CONFIG_TOKEN", 2, argc, argv);
1001 }
1002 #endif /* CONFIG_WPS_NFC */
1003
1004
wpa_cli_cmd_ibss_rsn(struct wpa_ctrl * ctrl,int argc,char * argv[])1005 static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
1006 {
1007 return wpa_cli_cmd(ctrl, "IBSS_RSN", 1, argc, argv);
1008 }
1009
1010
wpa_cli_cmd_level(struct wpa_ctrl * ctrl,int argc,char * argv[])1011 static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
1012 {
1013 return wpa_cli_cmd(ctrl, "LEVEL", 1, argc, argv);
1014 }
1015
1016
wpa_cli_cmd_identity(struct wpa_ctrl * ctrl,int argc,char * argv[])1017 static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
1018 {
1019 char cmd[256], *pos, *end;
1020 int i, ret;
1021
1022 if (argc < 2) {
1023 printf("Invalid IDENTITY command: needs two arguments "
1024 "(network id and identity)\n");
1025 return -1;
1026 }
1027
1028 end = cmd + sizeof(cmd);
1029 pos = cmd;
1030 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
1031 argv[0], argv[1]);
1032 if (os_snprintf_error(end - pos, ret)) {
1033 printf("Too long IDENTITY command.\n");
1034 return -1;
1035 }
1036 pos += ret;
1037 for (i = 2; i < argc; i++) {
1038 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1039 if (os_snprintf_error(end - pos, ret)) {
1040 printf("Too long IDENTITY command.\n");
1041 return -1;
1042 }
1043 pos += ret;
1044 }
1045
1046 return wpa_ctrl_command(ctrl, cmd);
1047 }
1048
1049
wpa_cli_cmd_password(struct wpa_ctrl * ctrl,int argc,char * argv[])1050 static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
1051 {
1052 char cmd[256], *pos, *end;
1053 int i, ret;
1054
1055 if (argc < 2) {
1056 printf("Invalid PASSWORD command: needs two arguments "
1057 "(network id and password)\n");
1058 return -1;
1059 }
1060
1061 end = cmd + sizeof(cmd);
1062 pos = cmd;
1063 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
1064 argv[0], argv[1]);
1065 if (os_snprintf_error(end - pos, ret)) {
1066 printf("Too long PASSWORD command.\n");
1067 return -1;
1068 }
1069 pos += ret;
1070 for (i = 2; i < argc; i++) {
1071 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1072 if (os_snprintf_error(end - pos, ret)) {
1073 printf("Too long PASSWORD command.\n");
1074 return -1;
1075 }
1076 pos += ret;
1077 }
1078
1079 return wpa_ctrl_command(ctrl, cmd);
1080 }
1081
1082
wpa_cli_cmd_new_password(struct wpa_ctrl * ctrl,int argc,char * argv[])1083 static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
1084 char *argv[])
1085 {
1086 char cmd[256], *pos, *end;
1087 int i, ret;
1088
1089 if (argc < 2) {
1090 printf("Invalid NEW_PASSWORD command: needs two arguments "
1091 "(network id and password)\n");
1092 return -1;
1093 }
1094
1095 end = cmd + sizeof(cmd);
1096 pos = cmd;
1097 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
1098 argv[0], argv[1]);
1099 if (os_snprintf_error(end - pos, ret)) {
1100 printf("Too long NEW_PASSWORD command.\n");
1101 return -1;
1102 }
1103 pos += ret;
1104 for (i = 2; i < argc; i++) {
1105 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1106 if (os_snprintf_error(end - pos, ret)) {
1107 printf("Too long NEW_PASSWORD command.\n");
1108 return -1;
1109 }
1110 pos += ret;
1111 }
1112
1113 return wpa_ctrl_command(ctrl, cmd);
1114 }
1115
1116
wpa_cli_cmd_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])1117 static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
1118 {
1119 char cmd[256], *pos, *end;
1120 int i, ret;
1121
1122 if (argc < 2) {
1123 printf("Invalid PIN command: needs two arguments "
1124 "(network id and pin)\n");
1125 return -1;
1126 }
1127
1128 end = cmd + sizeof(cmd);
1129 pos = cmd;
1130 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
1131 argv[0], argv[1]);
1132 if (os_snprintf_error(end - pos, ret)) {
1133 printf("Too long PIN command.\n");
1134 return -1;
1135 }
1136 pos += ret;
1137 for (i = 2; i < argc; i++) {
1138 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1139 if (os_snprintf_error(end - pos, ret)) {
1140 printf("Too long PIN command.\n");
1141 return -1;
1142 }
1143 pos += ret;
1144 }
1145 return wpa_ctrl_command(ctrl, cmd);
1146 }
1147
1148
wpa_cli_cmd_otp(struct wpa_ctrl * ctrl,int argc,char * argv[])1149 static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
1150 {
1151 char cmd[256], *pos, *end;
1152 int i, ret;
1153
1154 if (argc < 2) {
1155 printf("Invalid OTP command: needs two arguments (network "
1156 "id and password)\n");
1157 return -1;
1158 }
1159
1160 end = cmd + sizeof(cmd);
1161 pos = cmd;
1162 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
1163 argv[0], argv[1]);
1164 if (os_snprintf_error(end - pos, ret)) {
1165 printf("Too long OTP command.\n");
1166 return -1;
1167 }
1168 pos += ret;
1169 for (i = 2; i < argc; i++) {
1170 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1171 if (os_snprintf_error(end - pos, ret)) {
1172 printf("Too long OTP command.\n");
1173 return -1;
1174 }
1175 pos += ret;
1176 }
1177
1178 return wpa_ctrl_command(ctrl, cmd);
1179 }
1180
1181
wpa_cli_cmd_sim(struct wpa_ctrl * ctrl,int argc,char * argv[])1182 static int wpa_cli_cmd_sim(struct wpa_ctrl *ctrl, int argc, char *argv[])
1183 {
1184 char cmd[256], *pos, *end;
1185 int i, ret;
1186
1187 if (argc < 2) {
1188 printf("Invalid SIM command: needs two arguments "
1189 "(network id and SIM operation response)\n");
1190 return -1;
1191 }
1192
1193 end = cmd + sizeof(cmd);
1194 pos = cmd;
1195 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "SIM-%s:%s",
1196 argv[0], argv[1]);
1197 if (os_snprintf_error(end - pos, ret)) {
1198 printf("Too long SIM command.\n");
1199 return -1;
1200 }
1201 pos += ret;
1202 for (i = 2; i < argc; i++) {
1203 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1204 if (os_snprintf_error(end - pos, ret)) {
1205 printf("Too long SIM command.\n");
1206 return -1;
1207 }
1208 pos += ret;
1209 }
1210 return wpa_ctrl_command(ctrl, cmd);
1211 }
1212
1213
wpa_cli_cmd_psk_passphrase(struct wpa_ctrl * ctrl,int argc,char * argv[])1214 static int wpa_cli_cmd_psk_passphrase(struct wpa_ctrl *ctrl, int argc,
1215 char *argv[])
1216 {
1217 char cmd[256], *pos, *end;
1218 int i, ret;
1219
1220 if (argc < 2) {
1221 printf("Invalid PSK_PASSPHRASE command: needs two arguments (network id and PSK/passphrase)\n");
1222 return -1;
1223 }
1224
1225 end = cmd + sizeof(cmd);
1226 pos = cmd;
1227 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PSK_PASSPHRASE-%s:%s",
1228 argv[0], argv[1]);
1229 if (os_snprintf_error(end - pos, ret)) {
1230 printf("Too long PSK_PASSPHRASE command.\n");
1231 return -1;
1232 }
1233 pos += ret;
1234 for (i = 2; i < argc; i++) {
1235 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1236 if (os_snprintf_error(end - pos, ret)) {
1237 printf("Too long PSK_PASSPHRASE command.\n");
1238 return -1;
1239 }
1240 pos += ret;
1241 }
1242
1243 return wpa_ctrl_command(ctrl, cmd);
1244 }
1245
1246
wpa_cli_cmd_passphrase(struct wpa_ctrl * ctrl,int argc,char * argv[])1247 static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
1248 char *argv[])
1249 {
1250 char cmd[256], *pos, *end;
1251 int i, ret;
1252
1253 if (argc < 2) {
1254 printf("Invalid PASSPHRASE command: needs two arguments "
1255 "(network id and passphrase)\n");
1256 return -1;
1257 }
1258
1259 end = cmd + sizeof(cmd);
1260 pos = cmd;
1261 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
1262 argv[0], argv[1]);
1263 if (os_snprintf_error(end - pos, ret)) {
1264 printf("Too long PASSPHRASE command.\n");
1265 return -1;
1266 }
1267 pos += ret;
1268 for (i = 2; i < argc; i++) {
1269 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
1270 if (os_snprintf_error(end - pos, ret)) {
1271 printf("Too long PASSPHRASE command.\n");
1272 return -1;
1273 }
1274 pos += ret;
1275 }
1276
1277 return wpa_ctrl_command(ctrl, cmd);
1278 }
1279
1280
wpa_cli_cmd_bssid(struct wpa_ctrl * ctrl,int argc,char * argv[])1281 static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
1282 {
1283 if (argc < 2) {
1284 printf("Invalid BSSID command: needs two arguments (network "
1285 "id and BSSID)\n");
1286 return -1;
1287 }
1288
1289 return wpa_cli_cmd(ctrl, "BSSID", 2, argc, argv);
1290 }
1291
1292
wpa_cli_cmd_bssid_ignore(struct wpa_ctrl * ctrl,int argc,char * argv[])1293 static int wpa_cli_cmd_bssid_ignore(struct wpa_ctrl *ctrl, int argc,
1294 char *argv[])
1295 {
1296 return wpa_cli_cmd(ctrl, "BSSID_IGNORE", 0, argc, argv);
1297 }
1298
1299
wpa_cli_cmd_log_level(struct wpa_ctrl * ctrl,int argc,char * argv[])1300 static int wpa_cli_cmd_log_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
1301 {
1302 return wpa_cli_cmd(ctrl, "LOG_LEVEL", 0, argc, argv);
1303 }
1304
1305
wpa_cli_cmd_list_networks(struct wpa_ctrl * ctrl,int argc,char * argv[])1306 static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
1307 char *argv[])
1308 {
1309 return wpa_cli_cmd(ctrl, "LIST_NETWORKS", 0, argc, argv);
1310 }
1311
1312
wpa_cli_cmd_select_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1313 static int wpa_cli_cmd_select_network(struct wpa_ctrl *ctrl, int argc,
1314 char *argv[])
1315 {
1316 return wpa_cli_cmd(ctrl, "SELECT_NETWORK", 1, argc, argv);
1317 }
1318
1319
wpa_cli_cmd_enable_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1320 static int wpa_cli_cmd_enable_network(struct wpa_ctrl *ctrl, int argc,
1321 char *argv[])
1322 {
1323 return wpa_cli_cmd(ctrl, "ENABLE_NETWORK", 1, argc, argv);
1324 }
1325
1326
wpa_cli_cmd_disable_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1327 static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc,
1328 char *argv[])
1329 {
1330 return wpa_cli_cmd(ctrl, "DISABLE_NETWORK", 1, argc, argv);
1331 }
1332
1333
wpa_cli_cmd_add_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1334 static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc,
1335 char *argv[])
1336 {
1337 int res = wpa_ctrl_command(ctrl, "ADD_NETWORK");
1338 if (interactive)
1339 update_networks(ctrl);
1340 return res;
1341 }
1342
1343
wpa_cli_cmd_remove_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1344 static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc,
1345 char *argv[])
1346 {
1347 int res = wpa_cli_cmd(ctrl, "REMOVE_NETWORK", 1, argc, argv);
1348 if (interactive)
1349 update_networks(ctrl);
1350 return res;
1351 }
1352
1353
wpa_cli_show_network_variables(void)1354 static void wpa_cli_show_network_variables(void)
1355 {
1356 printf("set_network variables:\n"
1357 " ssid (network name, SSID)\n"
1358 " psk (WPA passphrase or pre-shared key)\n"
1359 " key_mgmt (key management protocol)\n"
1360 " identity (EAP identity)\n"
1361 " password (EAP password)\n"
1362 " ...\n"
1363 "\n"
1364 "Note: Values are entered in the same format as the "
1365 "configuration file is using,\n"
1366 "i.e., strings values need to be inside double quotation "
1367 "marks.\n"
1368 "For example: set_network 1 ssid \"network name\"\n"
1369 "\n"
1370 "Please see wpa_supplicant.conf documentation for full list "
1371 "of\navailable variables.\n");
1372 }
1373
1374
wpa_cli_cmd_set_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1375 static int wpa_cli_cmd_set_network(struct wpa_ctrl *ctrl, int argc,
1376 char *argv[])
1377 {
1378 if (argc == 0) {
1379 wpa_cli_show_network_variables();
1380 return 0;
1381 }
1382
1383 if (argc < 3) {
1384 printf("Invalid SET_NETWORK command: needs three arguments\n"
1385 "(network id, variable name, and value)\n");
1386 return -1;
1387 }
1388
1389 return wpa_cli_cmd(ctrl, "SET_NETWORK", 3, argc, argv);
1390 }
1391
1392
wpa_cli_cmd_get_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1393 static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
1394 char *argv[])
1395 {
1396 if (argc == 0) {
1397 wpa_cli_show_network_variables();
1398 return 0;
1399 }
1400
1401 if (argc != 2) {
1402 printf("Invalid GET_NETWORK command: needs two arguments\n"
1403 "(network id and variable name)\n");
1404 return -1;
1405 }
1406
1407 return wpa_cli_cmd(ctrl, "GET_NETWORK", 2, argc, argv);
1408 }
1409
1410
1411 static const char *network_fields[] = {
1412 "ssid", "scan_ssid", "bssid", "bssid_ignore",
1413 "bssid_accept", "psk", "proto", "key_mgmt",
1414 "bg_scan_period", "pairwise", "group", "auth_alg", "scan_freq",
1415 "freq_list", "max_oper_chwidth", "ht40", "vht", "vht_center_freq1",
1416 "vht_center_freq2", "ht", "edmg",
1417 #ifdef IEEE8021X_EAPOL
1418 "eap", "identity", "anonymous_identity", "password", "ca_cert",
1419 "ca_path", "client_cert", "private_key", "private_key_passwd",
1420 "dh_file", "subject_match", "altsubject_match",
1421 "check_cert_subject",
1422 "domain_suffix_match", "domain_match", "ca_cert2", "ca_path2",
1423 "client_cert2", "private_key2", "private_key2_passwd",
1424 "dh_file2", "subject_match2", "altsubject_match2",
1425 "check_cert_subject2",
1426 "domain_suffix_match2", "domain_match2", "phase1", "phase2",
1427 "pcsc", "pin", "engine_id", "key_id", "cert_id", "ca_cert_id",
1428 "pin2", "engine2_id", "key2_id", "cert2_id", "ca_cert2_id",
1429 "engine", "engine2", "eapol_flags", "sim_num",
1430 "openssl_ciphers", "erp",
1431 #endif /* IEEE8021X_EAPOL */
1432 "wep_key0", "wep_key1", "wep_key2", "wep_key3",
1433 "wep_tx_keyidx", "priority",
1434 #ifdef IEEE8021X_EAPOL
1435 "eap_workaround", "pac_file", "fragment_size", "ocsp",
1436 #endif /* IEEE8021X_EAPOL */
1437 "mode",
1438 "proactive_key_caching", "disabled", "id_str",
1439 "ieee80211w",
1440 "mixed_cell", "frequency", "fixed_freq",
1441 #ifdef CONFIG_MESH
1442 "no_auto_peer", "mesh_rssi_threshold",
1443 "mesh_basic_rates", "dot11MeshMaxRetries",
1444 "dot11MeshRetryTimeout", "dot11MeshConfirmTimeout",
1445 "dot11MeshHoldingTimeout",
1446 #endif /* CONFIG_MESH */
1447 "wpa_ptk_rekey", "bgscan", "ignore_broadcast_ssid",
1448 "wpa_deny_ptk0_rekey",
1449 "enable_edmg", "edmg_channel",
1450 #ifdef CONFIG_P2P
1451 "go_p2p_dev_addr", "p2p_client_list", "psk_list",
1452 #endif /* CONFIG_P2P */
1453 #ifdef CONFIG_HT_OVERRIDES
1454 "disable_ht", "disable_ht40", "disable_sgi", "disable_ldpc",
1455 "ht40_intolerant", "disable_max_amsdu", "ampdu_factor",
1456 "ampdu_density", "ht_mcs", "rx_stbc", "tx_stbc",
1457 #endif /* CONFIG_HT_OVERRIDES */
1458 #ifdef CONFIG_VHT_OVERRIDES
1459 "disable_vht", "vht_capa", "vht_capa_mask", "vht_rx_mcs_nss_1",
1460 "vht_rx_mcs_nss_2", "vht_rx_mcs_nss_3", "vht_rx_mcs_nss_4",
1461 "vht_rx_mcs_nss_5", "vht_rx_mcs_nss_6", "vht_rx_mcs_nss_7",
1462 "vht_rx_mcs_nss_8", "vht_tx_mcs_nss_1", "vht_tx_mcs_nss_2",
1463 "vht_tx_mcs_nss_3", "vht_tx_mcs_nss_4", "vht_tx_mcs_nss_5",
1464 "vht_tx_mcs_nss_6", "vht_tx_mcs_nss_7", "vht_tx_mcs_nss_8",
1465 #endif /* CONFIG_VHT_OVERRIDES */
1466 #ifdef CONFIG_HE_OVERRIDES
1467 "disable_he",
1468 #endif /* CONFIG_HE_OVERRIDES */
1469 "ap_max_inactivity", "dtim_period", "beacon_int",
1470 #ifdef CONFIG_MACSEC
1471 "macsec_policy",
1472 "macsec_integ_only",
1473 "macsec_replay_protect",
1474 "macsec_replay_window",
1475 "macsec_port",
1476 "mka_priority",
1477 #endif /* CONFIG_MACSEC */
1478 #ifdef CONFIG_HS20
1479 "update_identifier",
1480 #endif /* CONFIG_HS20 */
1481 "mac_addr", "pbss", "wps_disabled"
1482 };
1483
1484
wpa_cli_complete_network(const char * str,int pos)1485 static char ** wpa_cli_complete_network(const char *str, int pos)
1486 {
1487 int arg = get_cmd_arg_num(str, pos);
1488 int i, num_fields = ARRAY_SIZE(network_fields);
1489 char **res = NULL;
1490
1491 switch (arg) {
1492 case 1:
1493 res = cli_txt_list_array(&networks);
1494 break;
1495 case 2:
1496 res = os_calloc(num_fields + 1, sizeof(char *));
1497 if (res == NULL)
1498 return NULL;
1499 for (i = 0; i < num_fields; i++) {
1500 res[i] = os_strdup(network_fields[i]);
1501 if (res[i] == NULL)
1502 break;
1503 }
1504 }
1505 return res;
1506 }
1507
1508
wpa_cli_complete_network_id(const char * str,int pos)1509 static char ** wpa_cli_complete_network_id(const char *str, int pos)
1510 {
1511 int arg = get_cmd_arg_num(str, pos);
1512 if (arg == 1)
1513 return cli_txt_list_array(&networks);
1514 return NULL;
1515 }
1516
1517
wpa_cli_cmd_dup_network(struct wpa_ctrl * ctrl,int argc,char * argv[])1518 static int wpa_cli_cmd_dup_network(struct wpa_ctrl *ctrl, int argc,
1519 char *argv[])
1520 {
1521 if (argc == 0) {
1522 wpa_cli_show_network_variables();
1523 return 0;
1524 }
1525
1526 if (argc < 3) {
1527 printf("Invalid DUP_NETWORK command: needs three arguments\n"
1528 "(src netid, dest netid, and variable name)\n");
1529 return -1;
1530 }
1531
1532 return wpa_cli_cmd(ctrl, "DUP_NETWORK", 3, argc, argv);
1533 }
1534
1535
wpa_cli_complete_dup_network(const char * str,int pos)1536 static char ** wpa_cli_complete_dup_network(const char *str, int pos)
1537 {
1538 int arg = get_cmd_arg_num(str, pos);
1539 int i, num_fields = ARRAY_SIZE(network_fields);
1540 char **res = NULL;
1541
1542 switch (arg) {
1543 case 1:
1544 case 2:
1545 res = cli_txt_list_array(&networks);
1546 break;
1547 case 3:
1548 res = os_calloc(num_fields + 1, sizeof(char *));
1549 if (res == NULL)
1550 return NULL;
1551 for (i = 0; i < num_fields; i++) {
1552 res[i] = os_strdup(network_fields[i]);
1553 if (res[i] == NULL)
1554 break;
1555 }
1556 }
1557 return res;
1558 }
1559
1560
wpa_cli_cmd_list_creds(struct wpa_ctrl * ctrl,int argc,char * argv[])1561 static int wpa_cli_cmd_list_creds(struct wpa_ctrl *ctrl, int argc,
1562 char *argv[])
1563 {
1564 return wpa_ctrl_command(ctrl, "LIST_CREDS");
1565 }
1566
1567
wpa_cli_cmd_add_cred(struct wpa_ctrl * ctrl,int argc,char * argv[])1568 static int wpa_cli_cmd_add_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
1569 {
1570 int res = wpa_ctrl_command(ctrl, "ADD_CRED");
1571 if (interactive)
1572 update_creds(ctrl);
1573 return res;
1574 }
1575
1576
wpa_cli_cmd_remove_cred(struct wpa_ctrl * ctrl,int argc,char * argv[])1577 static int wpa_cli_cmd_remove_cred(struct wpa_ctrl *ctrl, int argc,
1578 char *argv[])
1579 {
1580 int res = wpa_cli_cmd(ctrl, "REMOVE_CRED", 1, argc, argv);
1581 if (interactive)
1582 update_creds(ctrl);
1583 return res;
1584 }
1585
1586
1587 static const char * const cred_fields[] = {
1588 "temporary", "priority", "sp_priority", "pcsc", "eap",
1589 "update_identifier", "min_dl_bandwidth_home", "min_ul_bandwidth_home",
1590 "min_dl_bandwidth_roaming", "min_ul_bandwidth_roaming", "max_bss_load",
1591 "req_conn_capab", "ocsp", "sim_num", "realm", "username", "password",
1592 "ca_cert", "client_cert", "private_key", "private_key_passwd", "imsi",
1593 "milenage", "domain_suffix_match", "domain", "phase1", "phase2",
1594 "roaming_consortium", "required_roaming_consortium", "excluded_ssid",
1595 "roaming_partner", "provisioning_sp"
1596 };
1597
1598
wpa_cli_complete_cred(const char * str,int pos)1599 static char ** wpa_cli_complete_cred(const char *str, int pos)
1600 {
1601 int arg = get_cmd_arg_num(str, pos);
1602 int i, num_fields = ARRAY_SIZE(cred_fields);
1603 char **res = NULL;
1604
1605 switch (arg) {
1606 case 1:
1607 res = cli_txt_list_array(&creds);
1608 break;
1609 case 2:
1610 res = os_calloc(num_fields + 1, sizeof(char *));
1611 if (res == NULL)
1612 return NULL;
1613 for (i = 0; i < num_fields; i++) {
1614 res[i] = os_strdup(cred_fields[i]);
1615 if (res[i] == NULL)
1616 break;
1617 }
1618 }
1619 return res;
1620 }
1621
1622
wpa_cli_cmd_set_cred(struct wpa_ctrl * ctrl,int argc,char * argv[])1623 static int wpa_cli_cmd_set_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
1624 {
1625 if (argc != 3) {
1626 printf("Invalid SET_CRED command: needs three arguments\n"
1627 "(cred id, variable name, and value)\n");
1628 return -1;
1629 }
1630
1631 return wpa_cli_cmd(ctrl, "SET_CRED", 3, argc, argv);
1632 }
1633
1634
wpa_cli_cmd_get_cred(struct wpa_ctrl * ctrl,int argc,char * argv[])1635 static int wpa_cli_cmd_get_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
1636 {
1637 if (argc != 2) {
1638 printf("Invalid GET_CRED command: needs two arguments\n"
1639 "(cred id, variable name)\n");
1640 return -1;
1641 }
1642
1643 return wpa_cli_cmd(ctrl, "GET_CRED", 2, argc, argv);
1644 }
1645
1646
wpa_cli_cmd_disconnect(struct wpa_ctrl * ctrl,int argc,char * argv[])1647 static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
1648 char *argv[])
1649 {
1650 return wpa_ctrl_command(ctrl, "DISCONNECT");
1651 }
1652
1653
wpa_cli_cmd_reconnect(struct wpa_ctrl * ctrl,int argc,char * argv[])1654 static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
1655 char *argv[])
1656 {
1657 return wpa_ctrl_command(ctrl, "RECONNECT");
1658 }
1659
1660
wpa_cli_cmd_save_config(struct wpa_ctrl * ctrl,int argc,char * argv[])1661 static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
1662 char *argv[])
1663 {
1664 return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
1665 }
1666
1667
wpa_cli_cmd_scan(struct wpa_ctrl * ctrl,int argc,char * argv[])1668 static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
1669 {
1670 return wpa_cli_cmd(ctrl, "SCAN", 0, argc, argv);
1671 }
1672
1673
wpa_cli_cmd_scan_results(struct wpa_ctrl * ctrl,int argc,char * argv[])1674 static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
1675 char *argv[])
1676 {
1677 return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
1678 }
1679
1680
wpa_cli_cmd_abort_scan(struct wpa_ctrl * ctrl,int argc,char * argv[])1681 static int wpa_cli_cmd_abort_scan(struct wpa_ctrl *ctrl, int argc,
1682 char *argv[])
1683 {
1684 return wpa_ctrl_command(ctrl, "ABORT_SCAN");
1685 }
1686
1687
wpa_cli_cmd_bss(struct wpa_ctrl * ctrl,int argc,char * argv[])1688 static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
1689 {
1690 return wpa_cli_cmd(ctrl, "BSS", 1, argc, argv);
1691 }
1692
1693
wpa_cli_complete_bss(const char * str,int pos)1694 static char ** wpa_cli_complete_bss(const char *str, int pos)
1695 {
1696 int arg = get_cmd_arg_num(str, pos);
1697 char **res = NULL;
1698
1699 switch (arg) {
1700 case 1:
1701 res = cli_txt_list_array(&bsses);
1702 break;
1703 }
1704
1705 return res;
1706 }
1707
1708
wpa_cli_cmd_get_capability(struct wpa_ctrl * ctrl,int argc,char * argv[])1709 static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
1710 char *argv[])
1711 {
1712 if (argc < 1 || argc > 3) {
1713 printf("Invalid GET_CAPABILITY command: need at least one argument and max three arguments\n");
1714 return -1;
1715 }
1716
1717 if (argc > 1 && os_strcmp(argv[0], "key_mgmt") != 0 &&
1718 os_strncmp(argv[1], "iftype=", 7) == 0) {
1719 printf("Invalid GET_CAPABILITY command: 'iftype=' param is allowed only for 'key_mgmt'\n");
1720 return -1;
1721 }
1722
1723 if (argc == 2 && os_strcmp(argv[1], "strict") != 0 &&
1724 os_strncmp(argv[1], "iftype=", 7) != 0) {
1725 printf("Invalid GET_CAPABILITY command: the second argument, if any, must be 'strict' OR 'iftype=<iftype_name>'\n");
1726 return -1;
1727 }
1728
1729 if (argc == 3 && os_strcmp(argv[2], "strict") != 0) {
1730 printf("Invalid GET_CAPABILITY command: the third argument, if any, must be 'strict'\n");
1731 return -1;
1732 }
1733
1734 return wpa_cli_cmd(ctrl, "GET_CAPABILITY", 1, argc, argv);
1735 }
1736
1737
wpa_cli_complete_get_capability(const char * str,int pos)1738 static char ** wpa_cli_complete_get_capability(const char *str, int pos)
1739 {
1740 int arg = get_cmd_arg_num(str, pos);
1741 const char *fields[] = {
1742 "eap", "pairwise", "group", "group_mgmt", "key_mgmt",
1743 "proto", "auth_alg", "modes", "channels", "freq",
1744 #ifdef CONFIG_TDLS
1745 "tdls",
1746 #endif /* CONFIG_TDLS */
1747 #ifdef CONFIG_ERP
1748 "erp",
1749 #endif /* CONFIG_ERP */
1750 #ifdef CONFIG_FIPS
1751 "fips",
1752 #endif /* CONFIG_FIPS */
1753 #ifdef CONFIG_ACS
1754 "acs",
1755 #endif /* CONFIG_ACS */
1756 };
1757 const char *iftypes[] = {
1758 "iftype=STATION", "iftype=AP", "iftype=P2P_CLIENT",
1759 "iftype=P2P_GO", "iftype=AP_VLAN", "iftype=IBSS", "iftype=NAN",
1760 "iftype=P2P_DEVICE", "iftype=MESH",
1761 };
1762 int i, num_fields = ARRAY_SIZE(fields);
1763 int num_iftypes = ARRAY_SIZE(iftypes);
1764 char **res = NULL;
1765
1766 if (arg == 1) {
1767 res = os_calloc(num_fields + 1, sizeof(char *));
1768 if (res == NULL)
1769 return NULL;
1770 for (i = 0; i < num_fields; i++) {
1771 res[i] = os_strdup(fields[i]);
1772 if (res[i] == NULL)
1773 return res;
1774 }
1775 }
1776 if (arg == 2) {
1777 /* the second argument can be "iftype=<iftype_name>" OR
1778 * "strict" */
1779 res = os_calloc(num_iftypes + 2, sizeof(char *));
1780 if (!res)
1781 return NULL;
1782 res[0] = os_strdup("strict");
1783 if (!res[0])
1784 return res;
1785 for (i = 0; i < num_iftypes; i++) {
1786 res[i + 1] = os_strdup(iftypes[i]);
1787 if (!res[i + 1])
1788 return res;
1789 }
1790 }
1791 if (arg == 3) {
1792 res = os_calloc(1 + 1, sizeof(char *));
1793 if (res == NULL)
1794 return NULL;
1795 res[0] = os_strdup("strict");
1796 }
1797 return res;
1798 }
1799
1800
wpa_cli_list_interfaces(struct wpa_ctrl * ctrl)1801 static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
1802 {
1803 printf("Available interfaces:\n");
1804 return wpa_ctrl_command(ctrl, "INTERFACES");
1805 }
1806
1807
wpa_cli_cmd_interface(struct wpa_ctrl * ctrl,int argc,char * argv[])1808 static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
1809 {
1810 if (argc < 1) {
1811 wpa_cli_list_interfaces(ctrl);
1812 return 0;
1813 }
1814
1815 wpa_cli_close_connection();
1816 os_free(ctrl_ifname);
1817 ctrl_ifname = os_strdup(argv[0]);
1818 if (!ctrl_ifname) {
1819 printf("Failed to allocate memory\n");
1820 return 0;
1821 }
1822
1823 if (wpa_cli_open_connection(ctrl_ifname, 1) == 0) {
1824 printf("Connected to interface '%s'.\n", ctrl_ifname);
1825 } else {
1826 printf("Could not connect to interface '%s' - re-trying\n",
1827 ctrl_ifname);
1828 }
1829 return 0;
1830 }
1831
1832
wpa_cli_cmd_reconfigure(struct wpa_ctrl * ctrl,int argc,char * argv[])1833 static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
1834 char *argv[])
1835 {
1836 return wpa_ctrl_command(ctrl, "RECONFIGURE");
1837 }
1838
1839
wpa_cli_cmd_terminate(struct wpa_ctrl * ctrl,int argc,char * argv[])1840 static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
1841 char *argv[])
1842 {
1843 return wpa_ctrl_command(ctrl, "TERMINATE");
1844 }
1845
1846
wpa_cli_cmd_interface_add(struct wpa_ctrl * ctrl,int argc,char * argv[])1847 static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
1848 char *argv[])
1849 {
1850 char cmd[256];
1851 int res;
1852
1853 if (argc < 1) {
1854 printf("Invalid INTERFACE_ADD command: needs at least one "
1855 "argument (interface name)\n"
1856 "All arguments: ifname confname driver ctrl_interface "
1857 "driver_param bridge_name [create]\n");
1858 return -1;
1859 }
1860
1861 /*
1862 * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
1863 * <driver_param>TAB<bridge_name>[TAB<create>[TAB<type>]]
1864 */
1865 res = os_snprintf(cmd, sizeof(cmd),
1866 "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
1867 argv[0],
1868 argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
1869 argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
1870 argc > 5 ? argv[5] : "", argc > 6 ? argv[6] : "",
1871 argc > 7 ? argv[7] : "");
1872 if (os_snprintf_error(sizeof(cmd), res))
1873 return -1;
1874 cmd[sizeof(cmd) - 1] = '\0';
1875 return wpa_ctrl_command(ctrl, cmd);
1876 }
1877
1878
wpa_cli_cmd_interface_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])1879 static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
1880 char *argv[])
1881 {
1882 return wpa_cli_cmd(ctrl, "INTERFACE_REMOVE", 1, argc, argv);
1883 }
1884
1885
wpa_cli_cmd_interface_list(struct wpa_ctrl * ctrl,int argc,char * argv[])1886 static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
1887 char *argv[])
1888 {
1889 return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
1890 }
1891
1892
1893 #ifdef CONFIG_AP
wpa_cli_cmd_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])1894 static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
1895 {
1896 return wpa_cli_cmd(ctrl, "STA", 1, argc, argv);
1897 }
1898
1899
wpa_cli_complete_sta(const char * str,int pos)1900 static char ** wpa_cli_complete_sta(const char *str, int pos)
1901 {
1902 int arg = get_cmd_arg_num(str, pos);
1903 char **res = NULL;
1904
1905 switch (arg) {
1906 case 1:
1907 res = cli_txt_list_array(&stations);
1908 break;
1909 }
1910
1911 return res;
1912 }
1913
1914
wpa_ctrl_command_sta(struct wpa_ctrl * ctrl,const char * cmd,char * addr,size_t addr_len,int print)1915 static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, const char *cmd,
1916 char *addr, size_t addr_len, int print)
1917 {
1918 char buf[4096], *pos;
1919 size_t len;
1920 int ret;
1921
1922 if (ctrl_conn == NULL) {
1923 printf("Not connected to hostapd - command dropped.\n");
1924 return -1;
1925 }
1926 if (ifname_prefix) {
1927 os_snprintf(buf, sizeof(buf), "IFNAME=%s %s",
1928 ifname_prefix, cmd);
1929 buf[sizeof(buf) - 1] = '\0';
1930 cmd = buf;
1931 }
1932 len = sizeof(buf) - 1;
1933 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
1934 wpa_cli_msg_cb);
1935 if (ret == -2) {
1936 printf("'%s' command timed out.\n", cmd);
1937 return -2;
1938 } else if (ret < 0) {
1939 printf("'%s' command failed.\n", cmd);
1940 return -1;
1941 }
1942
1943 buf[len] = '\0';
1944 if (os_memcmp(buf, "FAIL", 4) == 0 ||
1945 os_memcmp(buf, "UNKNOWN COMMAND", 15) == 0)
1946 return -1;
1947 if (print)
1948 printf("%s", buf);
1949
1950 pos = buf;
1951 while (*pos != '\0' && *pos != '\n')
1952 pos++;
1953 *pos = '\0';
1954 os_strlcpy(addr, buf, addr_len);
1955 return 0;
1956 }
1957
1958
wpa_cli_cmd_all_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])1959 static int wpa_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
1960 {
1961 char addr[32], cmd[64];
1962
1963 if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 1))
1964 return 0;
1965 do {
1966 os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
1967 } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 1) == 0);
1968
1969 return -1;
1970 }
1971
1972
wpa_cli_cmd_list_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])1973 static int wpa_cli_cmd_list_sta(struct wpa_ctrl *ctrl, int argc,
1974 char *argv[])
1975 {
1976 char addr[32], cmd[64];
1977
1978 if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
1979 return 0;
1980 do {
1981 if (os_strcmp(addr, "") != 0)
1982 printf("%s\n", addr);
1983 os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
1984 } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
1985
1986 return 0;
1987 }
1988
1989
wpa_cli_cmd_deauthenticate(struct wpa_ctrl * ctrl,int argc,char * argv[])1990 static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
1991 char *argv[])
1992 {
1993 return wpa_cli_cmd(ctrl, "DEAUTHENTICATE", 1, argc, argv);
1994 }
1995
1996
wpa_cli_complete_deauthenticate(const char * str,int pos)1997 static char ** wpa_cli_complete_deauthenticate(const char *str, int pos)
1998 {
1999 int arg = get_cmd_arg_num(str, pos);
2000 char **res = NULL;
2001
2002 switch (arg) {
2003 case 1:
2004 res = cli_txt_list_array(&stations);
2005 break;
2006 }
2007
2008 return res;
2009 }
2010
2011
wpa_cli_cmd_disassociate(struct wpa_ctrl * ctrl,int argc,char * argv[])2012 static int wpa_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
2013 char *argv[])
2014 {
2015 return wpa_cli_cmd(ctrl, "DISASSOCIATE", 1, argc, argv);
2016 }
2017
2018
wpa_cli_complete_disassociate(const char * str,int pos)2019 static char ** wpa_cli_complete_disassociate(const char *str, int pos)
2020 {
2021 int arg = get_cmd_arg_num(str, pos);
2022 char **res = NULL;
2023
2024 switch (arg) {
2025 case 1:
2026 res = cli_txt_list_array(&stations);
2027 break;
2028 }
2029
2030 return res;
2031 }
2032
2033
wpa_cli_cmd_chanswitch(struct wpa_ctrl * ctrl,int argc,char * argv[])2034 static int wpa_cli_cmd_chanswitch(struct wpa_ctrl *ctrl, int argc,
2035 char *argv[])
2036 {
2037 return wpa_cli_cmd(ctrl, "CHAN_SWITCH", 2, argc, argv);
2038 }
2039
2040 #endif /* CONFIG_AP */
2041
2042
wpa_cli_cmd_suspend(struct wpa_ctrl * ctrl,int argc,char * argv[])2043 static int wpa_cli_cmd_suspend(struct wpa_ctrl *ctrl, int argc, char *argv[])
2044 {
2045 return wpa_ctrl_command(ctrl, "SUSPEND");
2046 }
2047
2048
wpa_cli_cmd_resume(struct wpa_ctrl * ctrl,int argc,char * argv[])2049 static int wpa_cli_cmd_resume(struct wpa_ctrl *ctrl, int argc, char *argv[])
2050 {
2051 return wpa_ctrl_command(ctrl, "RESUME");
2052 }
2053
2054
2055 #ifdef CONFIG_TESTING_OPTIONS
wpa_cli_cmd_drop_sa(struct wpa_ctrl * ctrl,int argc,char * argv[])2056 static int wpa_cli_cmd_drop_sa(struct wpa_ctrl *ctrl, int argc, char *argv[])
2057 {
2058 return wpa_ctrl_command(ctrl, "DROP_SA");
2059 }
2060 #endif /* CONFIG_TESTING_OPTIONS */
2061
2062
wpa_cli_cmd_roam(struct wpa_ctrl * ctrl,int argc,char * argv[])2063 static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[])
2064 {
2065 return wpa_cli_cmd(ctrl, "ROAM", 1, argc, argv);
2066 }
2067
2068
2069 #ifdef CONFIG_MESH
2070
wpa_cli_cmd_mesh_interface_add(struct wpa_ctrl * ctrl,int argc,char * argv[])2071 static int wpa_cli_cmd_mesh_interface_add(struct wpa_ctrl *ctrl, int argc,
2072 char *argv[])
2073 {
2074 return wpa_cli_cmd(ctrl, "MESH_INTERFACE_ADD", 0, argc, argv);
2075 }
2076
2077
wpa_cli_cmd_mesh_group_add(struct wpa_ctrl * ctrl,int argc,char * argv[])2078 static int wpa_cli_cmd_mesh_group_add(struct wpa_ctrl *ctrl, int argc,
2079 char *argv[])
2080 {
2081 return wpa_cli_cmd(ctrl, "MESH_GROUP_ADD", 1, argc, argv);
2082 }
2083
2084
wpa_cli_cmd_mesh_group_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])2085 static int wpa_cli_cmd_mesh_group_remove(struct wpa_ctrl *ctrl, int argc,
2086 char *argv[])
2087 {
2088 return wpa_cli_cmd(ctrl, "MESH_GROUP_REMOVE", 1, argc, argv);
2089 }
2090
2091
wpa_cli_cmd_mesh_peer_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])2092 static int wpa_cli_cmd_mesh_peer_remove(struct wpa_ctrl *ctrl, int argc,
2093 char *argv[])
2094 {
2095 return wpa_cli_cmd(ctrl, "MESH_PEER_REMOVE", 1, argc, argv);
2096 }
2097
2098
wpa_cli_cmd_mesh_peer_add(struct wpa_ctrl * ctrl,int argc,char * argv[])2099 static int wpa_cli_cmd_mesh_peer_add(struct wpa_ctrl *ctrl, int argc,
2100 char *argv[])
2101 {
2102 return wpa_cli_cmd(ctrl, "MESH_PEER_ADD", 1, argc, argv);
2103 }
2104
2105
wpa_cli_cmd_mesh_link_probe(struct wpa_ctrl * ctrl,int argc,char * argv[])2106 static int wpa_cli_cmd_mesh_link_probe(struct wpa_ctrl *ctrl, int argc,
2107 char *argv[])
2108 {
2109 return wpa_cli_cmd(ctrl, "MESH_LINK_PROBE", 1, argc, argv);
2110 }
2111
2112 #endif /* CONFIG_MESH */
2113
2114
2115 #ifdef CONFIG_P2P
2116
wpa_cli_cmd_p2p_find(struct wpa_ctrl * ctrl,int argc,char * argv[])2117 static int wpa_cli_cmd_p2p_find(struct wpa_ctrl *ctrl, int argc, char *argv[])
2118 {
2119 return wpa_cli_cmd(ctrl, "P2P_FIND", 0, argc, argv);
2120 }
2121
2122
wpa_cli_complete_p2p_find(const char * str,int pos)2123 static char ** wpa_cli_complete_p2p_find(const char *str, int pos)
2124 {
2125 char **res = NULL;
2126 int arg = get_cmd_arg_num(str, pos);
2127
2128 res = os_calloc(6, sizeof(char *));
2129 if (res == NULL)
2130 return NULL;
2131 res[0] = os_strdup("type=social");
2132 if (res[0] == NULL) {
2133 os_free(res);
2134 return NULL;
2135 }
2136 res[1] = os_strdup("type=progressive");
2137 if (res[1] == NULL)
2138 return res;
2139 res[2] = os_strdup("delay=");
2140 if (res[2] == NULL)
2141 return res;
2142 res[3] = os_strdup("dev_id=");
2143 if (res[3] == NULL)
2144 return res;
2145 if (arg == 1)
2146 res[4] = os_strdup("[timeout]");
2147
2148 return res;
2149 }
2150
2151
wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl * ctrl,int argc,char * argv[])2152 static int wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl *ctrl, int argc,
2153 char *argv[])
2154 {
2155 return wpa_ctrl_command(ctrl, "P2P_STOP_FIND");
2156 }
2157
2158
wpa_cli_cmd_p2p_asp_provision(struct wpa_ctrl * ctrl,int argc,char * argv[])2159 static int wpa_cli_cmd_p2p_asp_provision(struct wpa_ctrl *ctrl, int argc,
2160 char *argv[])
2161 {
2162 return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION", 3, argc, argv);
2163 }
2164
2165
wpa_cli_cmd_p2p_asp_provision_resp(struct wpa_ctrl * ctrl,int argc,char * argv[])2166 static int wpa_cli_cmd_p2p_asp_provision_resp(struct wpa_ctrl *ctrl, int argc,
2167 char *argv[])
2168 {
2169 return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION_RESP", 2, argc, argv);
2170 }
2171
2172
wpa_cli_cmd_p2p_connect(struct wpa_ctrl * ctrl,int argc,char * argv[])2173 static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl *ctrl, int argc,
2174 char *argv[])
2175 {
2176 return wpa_cli_cmd(ctrl, "P2P_CONNECT", 2, argc, argv);
2177 }
2178
2179
wpa_cli_complete_p2p_connect(const char * str,int pos)2180 static char ** wpa_cli_complete_p2p_connect(const char *str, int pos)
2181 {
2182 int arg = get_cmd_arg_num(str, pos);
2183 char **res = NULL;
2184
2185 switch (arg) {
2186 case 1:
2187 res = cli_txt_list_array(&p2p_peers);
2188 break;
2189 }
2190
2191 return res;
2192 }
2193
2194
wpa_cli_cmd_p2p_listen(struct wpa_ctrl * ctrl,int argc,char * argv[])2195 static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl *ctrl, int argc,
2196 char *argv[])
2197 {
2198 return wpa_cli_cmd(ctrl, "P2P_LISTEN", 0, argc, argv);
2199 }
2200
2201
wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])2202 static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl *ctrl, int argc,
2203 char *argv[])
2204 {
2205 return wpa_cli_cmd(ctrl, "P2P_GROUP_REMOVE", 1, argc, argv);
2206 }
2207
2208
wpa_cli_complete_p2p_group_remove(const char * str,int pos)2209 static char ** wpa_cli_complete_p2p_group_remove(const char *str, int pos)
2210 {
2211 int arg = get_cmd_arg_num(str, pos);
2212 char **res = NULL;
2213
2214 switch (arg) {
2215 case 1:
2216 res = cli_txt_list_array(&p2p_groups);
2217 break;
2218 }
2219
2220 return res;
2221 }
2222
2223
wpa_cli_cmd_p2p_group_add(struct wpa_ctrl * ctrl,int argc,char * argv[])2224 static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl *ctrl, int argc,
2225 char *argv[])
2226 {
2227 return wpa_cli_cmd(ctrl, "P2P_GROUP_ADD", 0, argc, argv);
2228 }
2229
2230
wpa_cli_cmd_p2p_group_member(struct wpa_ctrl * ctrl,int argc,char * argv[])2231 static int wpa_cli_cmd_p2p_group_member(struct wpa_ctrl *ctrl, int argc,
2232 char *argv[])
2233 {
2234 return wpa_cli_cmd(ctrl, "P2P_GROUP_MEMBER", 1, argc, argv);
2235 }
2236
2237
wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl * ctrl,int argc,char * argv[])2238 static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl *ctrl, int argc,
2239 char *argv[])
2240 {
2241 if (argc != 2 && argc != 3) {
2242 printf("Invalid P2P_PROV_DISC command: needs at least "
2243 "two arguments, address and config method\n"
2244 "(display, keypad, or pbc) and an optional join\n");
2245 return -1;
2246 }
2247
2248 return wpa_cli_cmd(ctrl, "P2P_PROV_DISC", 2, argc, argv);
2249 }
2250
2251
wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl * ctrl,int argc,char * argv[])2252 static int wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl *ctrl, int argc,
2253 char *argv[])
2254 {
2255 return wpa_ctrl_command(ctrl, "P2P_GET_PASSPHRASE");
2256 }
2257
2258
wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl * ctrl,int argc,char * argv[])2259 static int wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl *ctrl, int argc,
2260 char *argv[])
2261 {
2262 char cmd[4096];
2263
2264 if (argc < 2) {
2265 printf("Invalid P2P_SERV_DISC_REQ command: needs two "
2266 "or more arguments (address and TLVs)\n");
2267 return -1;
2268 }
2269
2270 if (write_cmd(cmd, sizeof(cmd), "P2P_SERV_DISC_REQ", argc, argv) < 0)
2271 return -1;
2272 return wpa_ctrl_command(ctrl, cmd);
2273 }
2274
2275
wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl * ctrl,int argc,char * argv[])2276 static int wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl *ctrl,
2277 int argc, char *argv[])
2278 {
2279 return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_CANCEL_REQ", 1, argc, argv);
2280 }
2281
2282
wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl * ctrl,int argc,char * argv[])2283 static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl *ctrl, int argc,
2284 char *argv[])
2285 {
2286 char cmd[4096];
2287 int res;
2288
2289 if (argc != 4) {
2290 printf("Invalid P2P_SERV_DISC_RESP command: needs four "
2291 "arguments (freq, address, dialog token, and TLVs)\n");
2292 return -1;
2293 }
2294
2295 res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_RESP %s %s %s %s",
2296 argv[0], argv[1], argv[2], argv[3]);
2297 if (os_snprintf_error(sizeof(cmd), res))
2298 return -1;
2299 cmd[sizeof(cmd) - 1] = '\0';
2300 return wpa_ctrl_command(ctrl, cmd);
2301 }
2302
2303
wpa_cli_cmd_p2p_service_update(struct wpa_ctrl * ctrl,int argc,char * argv[])2304 static int wpa_cli_cmd_p2p_service_update(struct wpa_ctrl *ctrl, int argc,
2305 char *argv[])
2306 {
2307 return wpa_ctrl_command(ctrl, "P2P_SERVICE_UPDATE");
2308 }
2309
2310
wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl * ctrl,int argc,char * argv[])2311 static int wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl *ctrl,
2312 int argc, char *argv[])
2313 {
2314 return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_EXTERNAL", 1, argc, argv);
2315 }
2316
2317
wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])2318 static int wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl *ctrl, int argc,
2319 char *argv[])
2320 {
2321 return wpa_ctrl_command(ctrl, "P2P_SERVICE_FLUSH");
2322 }
2323
2324
wpa_cli_cmd_p2p_service_add(struct wpa_ctrl * ctrl,int argc,char * argv[])2325 static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl *ctrl, int argc,
2326 char *argv[])
2327 {
2328 if (argc < 3) {
2329 printf("Invalid P2P_SERVICE_ADD command: needs 3-6 arguments\n");
2330 return -1;
2331 }
2332
2333 return wpa_cli_cmd(ctrl, "P2P_SERVICE_ADD", 3, argc, argv);
2334 }
2335
2336
wpa_cli_cmd_p2p_service_rep(struct wpa_ctrl * ctrl,int argc,char * argv[])2337 static int wpa_cli_cmd_p2p_service_rep(struct wpa_ctrl *ctrl, int argc,
2338 char *argv[])
2339 {
2340 if (argc < 5 || argc > 6) {
2341 printf("Invalid P2P_SERVICE_REP command: needs 5-6 "
2342 "arguments\n");
2343 return -1;
2344 }
2345
2346 return wpa_cli_cmd(ctrl, "P2P_SERVICE_REP", 5, argc, argv);
2347 }
2348
2349
wpa_cli_cmd_p2p_service_del(struct wpa_ctrl * ctrl,int argc,char * argv[])2350 static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl *ctrl, int argc,
2351 char *argv[])
2352 {
2353 char cmd[4096];
2354 int res;
2355
2356 if (argc != 2 && argc != 3) {
2357 printf("Invalid P2P_SERVICE_DEL command: needs two or three "
2358 "arguments\n");
2359 return -1;
2360 }
2361
2362 if (argc == 3)
2363 res = os_snprintf(cmd, sizeof(cmd),
2364 "P2P_SERVICE_DEL %s %s %s",
2365 argv[0], argv[1], argv[2]);
2366 else
2367 res = os_snprintf(cmd, sizeof(cmd),
2368 "P2P_SERVICE_DEL %s %s",
2369 argv[0], argv[1]);
2370 if (os_snprintf_error(sizeof(cmd), res))
2371 return -1;
2372 cmd[sizeof(cmd) - 1] = '\0';
2373 return wpa_ctrl_command(ctrl, cmd);
2374 }
2375
2376
wpa_cli_cmd_p2p_reject(struct wpa_ctrl * ctrl,int argc,char * argv[])2377 static int wpa_cli_cmd_p2p_reject(struct wpa_ctrl *ctrl,
2378 int argc, char *argv[])
2379 {
2380 return wpa_cli_cmd(ctrl, "P2P_REJECT", 1, argc, argv);
2381 }
2382
2383
wpa_cli_cmd_p2p_invite(struct wpa_ctrl * ctrl,int argc,char * argv[])2384 static int wpa_cli_cmd_p2p_invite(struct wpa_ctrl *ctrl,
2385 int argc, char *argv[])
2386 {
2387 return wpa_cli_cmd(ctrl, "P2P_INVITE", 1, argc, argv);
2388 }
2389
2390
wpa_cli_cmd_p2p_peer(struct wpa_ctrl * ctrl,int argc,char * argv[])2391 static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl *ctrl, int argc, char *argv[])
2392 {
2393 return wpa_cli_cmd(ctrl, "P2P_PEER", 1, argc, argv);
2394 }
2395
2396
wpa_cli_complete_p2p_peer(const char * str,int pos)2397 static char ** wpa_cli_complete_p2p_peer(const char *str, int pos)
2398 {
2399 int arg = get_cmd_arg_num(str, pos);
2400 char **res = NULL;
2401
2402 switch (arg) {
2403 case 1:
2404 res = cli_txt_list_array(&p2p_peers);
2405 break;
2406 }
2407
2408 return res;
2409 }
2410
2411
wpa_ctrl_command_p2p_peer(struct wpa_ctrl * ctrl,const char * cmd,char * addr,size_t addr_len,int discovered)2412 static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl *ctrl, const char *cmd,
2413 char *addr, size_t addr_len,
2414 int discovered)
2415 {
2416 char buf[4096], *pos;
2417 size_t len;
2418 int ret;
2419
2420 if (ctrl_conn == NULL)
2421 return -1;
2422 len = sizeof(buf) - 1;
2423 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
2424 wpa_cli_msg_cb);
2425 if (ret == -2) {
2426 printf("'%s' command timed out.\n", cmd);
2427 return -2;
2428 } else if (ret < 0) {
2429 printf("'%s' command failed.\n", cmd);
2430 return -1;
2431 }
2432
2433 buf[len] = '\0';
2434 if (os_memcmp(buf, "FAIL", 4) == 0)
2435 return -1;
2436
2437 pos = buf;
2438 while (*pos != '\0' && *pos != '\n')
2439 pos++;
2440 *pos++ = '\0';
2441 os_strlcpy(addr, buf, addr_len);
2442 if (!discovered || os_strstr(pos, "[PROBE_REQ_ONLY]") == NULL)
2443 printf("%s\n", addr);
2444 return 0;
2445 }
2446
2447
wpa_cli_cmd_p2p_peers(struct wpa_ctrl * ctrl,int argc,char * argv[])2448 static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl *ctrl, int argc, char *argv[])
2449 {
2450 char addr[32], cmd[64];
2451 int discovered;
2452
2453 discovered = argc > 0 && os_strcmp(argv[0], "discovered") == 0;
2454
2455 if (wpa_ctrl_command_p2p_peer(ctrl, "P2P_PEER FIRST",
2456 addr, sizeof(addr), discovered))
2457 return -1;
2458 do {
2459 os_snprintf(cmd, sizeof(cmd), "P2P_PEER NEXT-%s", addr);
2460 } while (wpa_ctrl_command_p2p_peer(ctrl, cmd, addr, sizeof(addr),
2461 discovered) == 0);
2462
2463 return 0;
2464 }
2465
2466
wpa_cli_cmd_p2p_set(struct wpa_ctrl * ctrl,int argc,char * argv[])2467 static int wpa_cli_cmd_p2p_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
2468 {
2469 return wpa_cli_cmd(ctrl, "P2P_SET", 2, argc, argv);
2470 }
2471
2472
wpa_cli_complete_p2p_set(const char * str,int pos)2473 static char ** wpa_cli_complete_p2p_set(const char *str, int pos)
2474 {
2475 int arg = get_cmd_arg_num(str, pos);
2476 const char *fields[] = {
2477 "discoverability",
2478 "managed",
2479 "listen_channel",
2480 "ssid_postfix",
2481 "noa",
2482 "ps",
2483 "oppps",
2484 "ctwindow",
2485 "disabled",
2486 "conc_pref",
2487 "force_long_sd",
2488 "peer_filter",
2489 "cross_connect",
2490 "go_apsd",
2491 "client_apsd",
2492 "disallow_freq",
2493 "disc_int",
2494 "per_sta_psk",
2495 };
2496 int i, num_fields = ARRAY_SIZE(fields);
2497
2498 if (arg == 1) {
2499 char **res = os_calloc(num_fields + 1, sizeof(char *));
2500 if (res == NULL)
2501 return NULL;
2502 for (i = 0; i < num_fields; i++) {
2503 res[i] = os_strdup(fields[i]);
2504 if (res[i] == NULL)
2505 return res;
2506 }
2507 return res;
2508 }
2509
2510 if (arg == 2 && os_strncasecmp(str, "p2p_set peer_filter ", 20) == 0)
2511 return cli_txt_list_array(&p2p_peers);
2512
2513 return NULL;
2514 }
2515
2516
wpa_cli_cmd_p2p_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])2517 static int wpa_cli_cmd_p2p_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
2518 {
2519 return wpa_ctrl_command(ctrl, "P2P_FLUSH");
2520 }
2521
2522
wpa_cli_cmd_p2p_cancel(struct wpa_ctrl * ctrl,int argc,char * argv[])2523 static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl *ctrl, int argc,
2524 char *argv[])
2525 {
2526 return wpa_ctrl_command(ctrl, "P2P_CANCEL");
2527 }
2528
2529
wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl * ctrl,int argc,char * argv[])2530 static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl *ctrl, int argc,
2531 char *argv[])
2532 {
2533 return wpa_cli_cmd(ctrl, "P2P_UNAUTHORIZE", 1, argc, argv);
2534 }
2535
2536
wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl * ctrl,int argc,char * argv[])2537 static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl *ctrl, int argc,
2538 char *argv[])
2539 {
2540 if (argc != 0 && argc != 2 && argc != 4) {
2541 printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
2542 "(preferred duration, interval; in microsecods).\n"
2543 "Optional second pair can be used to provide "
2544 "acceptable values.\n");
2545 return -1;
2546 }
2547
2548 return wpa_cli_cmd(ctrl, "P2P_PRESENCE_REQ", 0, argc, argv);
2549 }
2550
2551
wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl * ctrl,int argc,char * argv[])2552 static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl *ctrl, int argc,
2553 char *argv[])
2554 {
2555 if (argc != 0 && argc != 2) {
2556 printf("Invalid P2P_EXT_LISTEN command: needs two arguments "
2557 "(availability period, availability interval; in "
2558 "millisecods).\n"
2559 "Extended Listen Timing can be cancelled with this "
2560 "command when used without parameters.\n");
2561 return -1;
2562 }
2563
2564 return wpa_cli_cmd(ctrl, "P2P_EXT_LISTEN", 0, argc, argv);
2565 }
2566
2567
wpa_cli_cmd_p2p_remove_client(struct wpa_ctrl * ctrl,int argc,char * argv[])2568 static int wpa_cli_cmd_p2p_remove_client(struct wpa_ctrl *ctrl, int argc,
2569 char *argv[])
2570 {
2571 return wpa_cli_cmd(ctrl, "P2P_REMOVE_CLIENT", 1, argc, argv);
2572 }
2573
2574 #endif /* CONFIG_P2P */
2575
2576
wpa_cli_cmd_vendor_elem_add(struct wpa_ctrl * ctrl,int argc,char * argv[])2577 static int wpa_cli_cmd_vendor_elem_add(struct wpa_ctrl *ctrl, int argc,
2578 char *argv[])
2579 {
2580 return wpa_cli_cmd(ctrl, "VENDOR_ELEM_ADD", 2, argc, argv);
2581 }
2582
2583
wpa_cli_cmd_vendor_elem_get(struct wpa_ctrl * ctrl,int argc,char * argv[])2584 static int wpa_cli_cmd_vendor_elem_get(struct wpa_ctrl *ctrl, int argc,
2585 char *argv[])
2586 {
2587 return wpa_cli_cmd(ctrl, "VENDOR_ELEM_GET", 1, argc, argv);
2588 }
2589
2590
wpa_cli_cmd_vendor_elem_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])2591 static int wpa_cli_cmd_vendor_elem_remove(struct wpa_ctrl *ctrl, int argc,
2592 char *argv[])
2593 {
2594 return wpa_cli_cmd(ctrl, "VENDOR_ELEM_REMOVE", 2, argc, argv);
2595 }
2596
2597
2598 #ifdef CONFIG_WIFI_DISPLAY
2599
wpa_cli_cmd_wfd_subelem_set(struct wpa_ctrl * ctrl,int argc,char * argv[])2600 static int wpa_cli_cmd_wfd_subelem_set(struct wpa_ctrl *ctrl, int argc,
2601 char *argv[])
2602 {
2603 char cmd[100];
2604 int res;
2605
2606 if (argc != 1 && argc != 2) {
2607 printf("Invalid WFD_SUBELEM_SET command: needs one or two "
2608 "arguments (subelem, hexdump)\n");
2609 return -1;
2610 }
2611
2612 res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_SET %s %s",
2613 argv[0], argc > 1 ? argv[1] : "");
2614 if (os_snprintf_error(sizeof(cmd), res))
2615 return -1;
2616 cmd[sizeof(cmd) - 1] = '\0';
2617 return wpa_ctrl_command(ctrl, cmd);
2618 }
2619
2620
wpa_cli_cmd_wfd_subelem_get(struct wpa_ctrl * ctrl,int argc,char * argv[])2621 static int wpa_cli_cmd_wfd_subelem_get(struct wpa_ctrl *ctrl, int argc,
2622 char *argv[])
2623 {
2624 char cmd[100];
2625 int res;
2626
2627 if (argc != 1) {
2628 printf("Invalid WFD_SUBELEM_GET command: needs one "
2629 "argument (subelem)\n");
2630 return -1;
2631 }
2632
2633 res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_GET %s",
2634 argv[0]);
2635 if (os_snprintf_error(sizeof(cmd), res))
2636 return -1;
2637 cmd[sizeof(cmd) - 1] = '\0';
2638 return wpa_ctrl_command(ctrl, cmd);
2639 }
2640 #endif /* CONFIG_WIFI_DISPLAY */
2641
2642
2643 #ifdef CONFIG_INTERWORKING
wpa_cli_cmd_fetch_anqp(struct wpa_ctrl * ctrl,int argc,char * argv[])2644 static int wpa_cli_cmd_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
2645 char *argv[])
2646 {
2647 return wpa_ctrl_command(ctrl, "FETCH_ANQP");
2648 }
2649
2650
wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl * ctrl,int argc,char * argv[])2651 static int wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
2652 char *argv[])
2653 {
2654 return wpa_ctrl_command(ctrl, "STOP_FETCH_ANQP");
2655 }
2656
2657
wpa_cli_cmd_interworking_select(struct wpa_ctrl * ctrl,int argc,char * argv[])2658 static int wpa_cli_cmd_interworking_select(struct wpa_ctrl *ctrl, int argc,
2659 char *argv[])
2660 {
2661 return wpa_cli_cmd(ctrl, "INTERWORKING_SELECT", 0, argc, argv);
2662 }
2663
2664
wpa_cli_cmd_interworking_connect(struct wpa_ctrl * ctrl,int argc,char * argv[])2665 static int wpa_cli_cmd_interworking_connect(struct wpa_ctrl *ctrl, int argc,
2666 char *argv[])
2667 {
2668 return wpa_cli_cmd(ctrl, "INTERWORKING_CONNECT", 1, argc, argv);
2669 }
2670
2671
wpa_cli_cmd_interworking_add_network(struct wpa_ctrl * ctrl,int argc,char * argv[])2672 static int wpa_cli_cmd_interworking_add_network(struct wpa_ctrl *ctrl, int argc,
2673 char *argv[])
2674 {
2675 return wpa_cli_cmd(ctrl, "INTERWORKING_ADD_NETWORK", 1, argc, argv);
2676 }
2677
2678
wpa_cli_cmd_anqp_get(struct wpa_ctrl * ctrl,int argc,char * argv[])2679 static int wpa_cli_cmd_anqp_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
2680 {
2681 return wpa_cli_cmd(ctrl, "ANQP_GET", 2, argc, argv);
2682 }
2683
2684
wpa_cli_cmd_gas_request(struct wpa_ctrl * ctrl,int argc,char * argv[])2685 static int wpa_cli_cmd_gas_request(struct wpa_ctrl *ctrl, int argc,
2686 char *argv[])
2687 {
2688 return wpa_cli_cmd(ctrl, "GAS_REQUEST", 2, argc, argv);
2689 }
2690
2691
wpa_cli_cmd_gas_response_get(struct wpa_ctrl * ctrl,int argc,char * argv[])2692 static int wpa_cli_cmd_gas_response_get(struct wpa_ctrl *ctrl, int argc,
2693 char *argv[])
2694 {
2695 return wpa_cli_cmd(ctrl, "GAS_RESPONSE_GET", 2, argc, argv);
2696 }
2697 #endif /* CONFIG_INTERWORKING */
2698
2699
2700 #ifdef CONFIG_HS20
2701
wpa_cli_cmd_hs20_anqp_get(struct wpa_ctrl * ctrl,int argc,char * argv[])2702 static int wpa_cli_cmd_hs20_anqp_get(struct wpa_ctrl *ctrl, int argc,
2703 char *argv[])
2704 {
2705 return wpa_cli_cmd(ctrl, "HS20_ANQP_GET", 2, argc, argv);
2706 }
2707
2708
wpa_cli_cmd_get_nai_home_realm_list(struct wpa_ctrl * ctrl,int argc,char * argv[])2709 static int wpa_cli_cmd_get_nai_home_realm_list(struct wpa_ctrl *ctrl, int argc,
2710 char *argv[])
2711 {
2712 char cmd[512];
2713
2714 if (argc == 0) {
2715 printf("Command needs one or two arguments (dst mac addr and "
2716 "optional home realm)\n");
2717 return -1;
2718 }
2719
2720 if (write_cmd(cmd, sizeof(cmd), "HS20_GET_NAI_HOME_REALM_LIST",
2721 argc, argv) < 0)
2722 return -1;
2723
2724 return wpa_ctrl_command(ctrl, cmd);
2725 }
2726
2727
wpa_cli_cmd_hs20_icon_request(struct wpa_ctrl * ctrl,int argc,char * argv[])2728 static int wpa_cli_cmd_hs20_icon_request(struct wpa_ctrl *ctrl, int argc,
2729 char *argv[])
2730 {
2731 char cmd[512];
2732
2733 if (argc < 2) {
2734 printf("Command needs two arguments (dst mac addr and "
2735 "icon name)\n");
2736 return -1;
2737 }
2738
2739 if (write_cmd(cmd, sizeof(cmd), "HS20_ICON_REQUEST", argc, argv) < 0)
2740 return -1;
2741
2742 return wpa_ctrl_command(ctrl, cmd);
2743 }
2744
2745
wpa_cli_cmd_fetch_osu(struct wpa_ctrl * ctrl,int argc,char * argv[])2746 static int wpa_cli_cmd_fetch_osu(struct wpa_ctrl *ctrl, int argc, char *argv[])
2747 {
2748 return wpa_ctrl_command(ctrl, "FETCH_OSU");
2749 }
2750
2751
wpa_cli_cmd_cancel_fetch_osu(struct wpa_ctrl * ctrl,int argc,char * argv[])2752 static int wpa_cli_cmd_cancel_fetch_osu(struct wpa_ctrl *ctrl, int argc,
2753 char *argv[])
2754 {
2755 return wpa_ctrl_command(ctrl, "CANCEL_FETCH_OSU");
2756 }
2757
2758 #endif /* CONFIG_HS20 */
2759
2760
wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl * ctrl,int argc,char * argv[])2761 static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl *ctrl, int argc,
2762 char *argv[])
2763 {
2764 return wpa_cli_cmd(ctrl, "STA_AUTOCONNECT", 1, argc, argv);
2765 }
2766
2767
wpa_cli_cmd_tdls_discover(struct wpa_ctrl * ctrl,int argc,char * argv[])2768 static int wpa_cli_cmd_tdls_discover(struct wpa_ctrl *ctrl, int argc,
2769 char *argv[])
2770 {
2771 return wpa_cli_cmd(ctrl, "TDLS_DISCOVER", 1, argc, argv);
2772 }
2773
2774
wpa_cli_cmd_tdls_setup(struct wpa_ctrl * ctrl,int argc,char * argv[])2775 static int wpa_cli_cmd_tdls_setup(struct wpa_ctrl *ctrl, int argc,
2776 char *argv[])
2777 {
2778 return wpa_cli_cmd(ctrl, "TDLS_SETUP", 1, argc, argv);
2779 }
2780
2781
wpa_cli_cmd_tdls_teardown(struct wpa_ctrl * ctrl,int argc,char * argv[])2782 static int wpa_cli_cmd_tdls_teardown(struct wpa_ctrl *ctrl, int argc,
2783 char *argv[])
2784 {
2785 return wpa_cli_cmd(ctrl, "TDLS_TEARDOWN", 1, argc, argv);
2786 }
2787
2788
wpa_cli_cmd_tdls_link_status(struct wpa_ctrl * ctrl,int argc,char * argv[])2789 static int wpa_cli_cmd_tdls_link_status(struct wpa_ctrl *ctrl, int argc,
2790 char *argv[])
2791 {
2792 return wpa_cli_cmd(ctrl, "TDLS_LINK_STATUS", 1, argc, argv);
2793 }
2794
2795
wpa_cli_cmd_wmm_ac_addts(struct wpa_ctrl * ctrl,int argc,char * argv[])2796 static int wpa_cli_cmd_wmm_ac_addts(struct wpa_ctrl *ctrl, int argc,
2797 char *argv[])
2798 {
2799 return wpa_cli_cmd(ctrl, "WMM_AC_ADDTS", 3, argc, argv);
2800 }
2801
2802
wpa_cli_cmd_wmm_ac_delts(struct wpa_ctrl * ctrl,int argc,char * argv[])2803 static int wpa_cli_cmd_wmm_ac_delts(struct wpa_ctrl *ctrl, int argc,
2804 char *argv[])
2805 {
2806 return wpa_cli_cmd(ctrl, "WMM_AC_DELTS", 1, argc, argv);
2807 }
2808
2809
wpa_cli_cmd_wmm_ac_status(struct wpa_ctrl * ctrl,int argc,char * argv[])2810 static int wpa_cli_cmd_wmm_ac_status(struct wpa_ctrl *ctrl, int argc,
2811 char *argv[])
2812 {
2813 return wpa_ctrl_command(ctrl, "WMM_AC_STATUS");
2814 }
2815
2816
wpa_cli_cmd_tdls_chan_switch(struct wpa_ctrl * ctrl,int argc,char * argv[])2817 static int wpa_cli_cmd_tdls_chan_switch(struct wpa_ctrl *ctrl, int argc,
2818 char *argv[])
2819 {
2820 return wpa_cli_cmd(ctrl, "TDLS_CHAN_SWITCH", 2, argc, argv);
2821 }
2822
2823
wpa_cli_cmd_tdls_cancel_chan_switch(struct wpa_ctrl * ctrl,int argc,char * argv[])2824 static int wpa_cli_cmd_tdls_cancel_chan_switch(struct wpa_ctrl *ctrl, int argc,
2825 char *argv[])
2826 {
2827 return wpa_cli_cmd(ctrl, "TDLS_CANCEL_CHAN_SWITCH", 1, argc, argv);
2828 }
2829
2830
wpa_cli_cmd_signal_poll(struct wpa_ctrl * ctrl,int argc,char * argv[])2831 static int wpa_cli_cmd_signal_poll(struct wpa_ctrl *ctrl, int argc,
2832 char *argv[])
2833 {
2834 return wpa_ctrl_command(ctrl, "SIGNAL_POLL");
2835 }
2836
2837
wpa_cli_cmd_signal_monitor(struct wpa_ctrl * ctrl,int argc,char * argv[])2838 static int wpa_cli_cmd_signal_monitor(struct wpa_ctrl *ctrl, int argc,
2839 char *argv[])
2840 {
2841 return wpa_cli_cmd(ctrl, "SIGNAL_MONITOR", 0, argc, argv);
2842 }
2843
2844
wpa_cli_cmd_pktcnt_poll(struct wpa_ctrl * ctrl,int argc,char * argv[])2845 static int wpa_cli_cmd_pktcnt_poll(struct wpa_ctrl *ctrl, int argc,
2846 char *argv[])
2847 {
2848 return wpa_ctrl_command(ctrl, "PKTCNT_POLL");
2849 }
2850
2851
wpa_cli_cmd_reauthenticate(struct wpa_ctrl * ctrl,int argc,char * argv[])2852 static int wpa_cli_cmd_reauthenticate(struct wpa_ctrl *ctrl, int argc,
2853 char *argv[])
2854 {
2855 return wpa_ctrl_command(ctrl, "REAUTHENTICATE");
2856 }
2857
2858
2859 #ifdef CONFIG_AUTOSCAN
2860
wpa_cli_cmd_autoscan(struct wpa_ctrl * ctrl,int argc,char * argv[])2861 static int wpa_cli_cmd_autoscan(struct wpa_ctrl *ctrl, int argc, char *argv[])
2862 {
2863 if (argc == 0)
2864 return wpa_ctrl_command(ctrl, "AUTOSCAN ");
2865
2866 return wpa_cli_cmd(ctrl, "AUTOSCAN", 0, argc, argv);
2867 }
2868
2869 #endif /* CONFIG_AUTOSCAN */
2870
2871
2872 #ifdef CONFIG_WNM
2873
wpa_cli_cmd_wnm_sleep(struct wpa_ctrl * ctrl,int argc,char * argv[])2874 static int wpa_cli_cmd_wnm_sleep(struct wpa_ctrl *ctrl, int argc, char *argv[])
2875 {
2876 return wpa_cli_cmd(ctrl, "WNM_SLEEP", 0, argc, argv);
2877 }
2878
2879
wpa_cli_cmd_wnm_bss_query(struct wpa_ctrl * ctrl,int argc,char * argv[])2880 static int wpa_cli_cmd_wnm_bss_query(struct wpa_ctrl *ctrl, int argc, char *argv[])
2881 {
2882 return wpa_cli_cmd(ctrl, "WNM_BSS_QUERY", 1, argc, argv);
2883 }
2884
2885 #endif /* CONFIG_WNM */
2886
2887
wpa_cli_cmd_raw(struct wpa_ctrl * ctrl,int argc,char * argv[])2888 static int wpa_cli_cmd_raw(struct wpa_ctrl *ctrl, int argc, char *argv[])
2889 {
2890 if (argc == 0)
2891 return -1;
2892 return wpa_cli_cmd(ctrl, argv[0], 0, argc - 1, &argv[1]);
2893 }
2894
2895
2896 #ifdef ANDROID
wpa_cli_cmd_driver(struct wpa_ctrl * ctrl,int argc,char * argv[])2897 static int wpa_cli_cmd_driver(struct wpa_ctrl *ctrl, int argc, char *argv[])
2898 {
2899 return wpa_cli_cmd(ctrl, "DRIVER", 1, argc, argv);
2900 }
2901 #endif /* ANDROID */
2902
2903
wpa_cli_cmd_vendor(struct wpa_ctrl * ctrl,int argc,char * argv[])2904 static int wpa_cli_cmd_vendor(struct wpa_ctrl *ctrl, int argc, char *argv[])
2905 {
2906 return wpa_cli_cmd(ctrl, "VENDOR", 1, argc, argv);
2907 }
2908
2909
wpa_cli_cmd_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])2910 static int wpa_cli_cmd_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
2911 {
2912 return wpa_ctrl_command(ctrl, "FLUSH");
2913 }
2914
2915
wpa_cli_cmd_radio_work(struct wpa_ctrl * ctrl,int argc,char * argv[])2916 static int wpa_cli_cmd_radio_work(struct wpa_ctrl *ctrl, int argc, char *argv[])
2917 {
2918 return wpa_cli_cmd(ctrl, "RADIO_WORK", 1, argc, argv);
2919 }
2920
2921
wpa_cli_cmd_neighbor_rep_request(struct wpa_ctrl * ctrl,int argc,char * argv[])2922 static int wpa_cli_cmd_neighbor_rep_request(struct wpa_ctrl *ctrl, int argc,
2923 char *argv[])
2924 {
2925 return wpa_cli_cmd(ctrl, "NEIGHBOR_REP_REQUEST", 0, argc, argv);
2926 }
2927
2928
wpa_cli_cmd_erp_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])2929 static int wpa_cli_cmd_erp_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
2930 {
2931 return wpa_ctrl_command(ctrl, "ERP_FLUSH");
2932 }
2933
2934
wpa_cli_cmd_mac_rand_scan(struct wpa_ctrl * ctrl,int argc,char * argv[])2935 static int wpa_cli_cmd_mac_rand_scan(struct wpa_ctrl *ctrl, int argc,
2936 char *argv[])
2937 {
2938 return wpa_cli_cmd(ctrl, "MAC_RAND_SCAN", 1, argc, argv);
2939 }
2940
2941
wpa_cli_cmd_get_pref_freq_list(struct wpa_ctrl * ctrl,int argc,char * argv[])2942 static int wpa_cli_cmd_get_pref_freq_list(struct wpa_ctrl *ctrl, int argc,
2943 char *argv[])
2944 {
2945 return wpa_cli_cmd(ctrl, "GET_PREF_FREQ_LIST", 1, argc, argv);
2946 }
2947
2948
wpa_cli_cmd_p2p_lo_start(struct wpa_ctrl * ctrl,int argc,char * argv[])2949 static int wpa_cli_cmd_p2p_lo_start(struct wpa_ctrl *ctrl, int argc,
2950 char *argv[])
2951 {
2952 return wpa_cli_cmd(ctrl, "P2P_LO_START", 4, argc, argv);
2953 }
2954
2955
wpa_cli_cmd_p2p_lo_stop(struct wpa_ctrl * ctrl,int argc,char * argv[])2956 static int wpa_cli_cmd_p2p_lo_stop(struct wpa_ctrl *ctrl, int argc,
2957 char *argv[])
2958 {
2959 return wpa_cli_cmd(ctrl, "P2P_LO_STOP", 0, argc, argv);
2960 }
2961
2962
2963 #ifdef CONFIG_DPP
2964
wpa_cli_cmd_dpp_qr_code(struct wpa_ctrl * ctrl,int argc,char * argv[])2965 static int wpa_cli_cmd_dpp_qr_code(struct wpa_ctrl *ctrl, int argc,
2966 char *argv[])
2967 {
2968 return wpa_cli_cmd(ctrl, "DPP_QR_CODE", 1, argc, argv);
2969 }
2970
2971
wpa_cli_cmd_dpp_bootstrap_gen(struct wpa_ctrl * ctrl,int argc,char * argv[])2972 static int wpa_cli_cmd_dpp_bootstrap_gen(struct wpa_ctrl *ctrl, int argc,
2973 char *argv[])
2974 {
2975 return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_GEN", 1, argc, argv);
2976 }
2977
2978
wpa_cli_cmd_dpp_bootstrap_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])2979 static int wpa_cli_cmd_dpp_bootstrap_remove(struct wpa_ctrl *ctrl, int argc,
2980 char *argv[])
2981 {
2982 return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_REMOVE", 1, argc, argv);
2983 }
2984
2985
wpa_cli_cmd_dpp_bootstrap_get_uri(struct wpa_ctrl * ctrl,int argc,char * argv[])2986 static int wpa_cli_cmd_dpp_bootstrap_get_uri(struct wpa_ctrl *ctrl, int argc,
2987 char *argv[])
2988 {
2989 return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_GET_URI", 1, argc, argv);
2990 }
2991
2992
wpa_cli_cmd_dpp_bootstrap_info(struct wpa_ctrl * ctrl,int argc,char * argv[])2993 static int wpa_cli_cmd_dpp_bootstrap_info(struct wpa_ctrl *ctrl, int argc,
2994 char *argv[])
2995 {
2996 return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_INFO", 1, argc, argv);
2997 }
2998
2999
wpa_cli_cmd_dpp_bootstrap_set(struct wpa_ctrl * ctrl,int argc,char * argv[])3000 static int wpa_cli_cmd_dpp_bootstrap_set(struct wpa_ctrl *ctrl, int argc,
3001 char *argv[])
3002 {
3003 return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_SET", 1, argc, argv);
3004 }
3005
3006
wpa_cli_cmd_dpp_auth_init(struct wpa_ctrl * ctrl,int argc,char * argv[])3007 static int wpa_cli_cmd_dpp_auth_init(struct wpa_ctrl *ctrl, int argc,
3008 char *argv[])
3009 {
3010 return wpa_cli_cmd(ctrl, "DPP_AUTH_INIT", 1, argc, argv);
3011 }
3012
3013
wpa_cli_cmd_dpp_listen(struct wpa_ctrl * ctrl,int argc,char * argv[])3014 static int wpa_cli_cmd_dpp_listen(struct wpa_ctrl *ctrl, int argc,
3015 char *argv[])
3016 {
3017 return wpa_cli_cmd(ctrl, "DPP_LISTEN", 1, argc, argv);
3018 }
3019
3020
wpa_cli_cmd_dpp_stop_listen(struct wpa_ctrl * ctrl,int argc,char * argv[])3021 static int wpa_cli_cmd_dpp_stop_listen(struct wpa_ctrl *ctrl, int argc,
3022 char *argv[])
3023 {
3024 return wpa_ctrl_command(ctrl, "DPP_STOP_LISTEN");
3025 }
3026
3027
wpa_cli_cmd_dpp_configurator_add(struct wpa_ctrl * ctrl,int argc,char * argv[])3028 static int wpa_cli_cmd_dpp_configurator_add(struct wpa_ctrl *ctrl, int argc,
3029 char *argv[])
3030 {
3031 return wpa_cli_cmd(ctrl, "DPP_CONFIGURATOR_ADD", 0, argc, argv);
3032 }
3033
3034
wpa_cli_cmd_dpp_configurator_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])3035 static int wpa_cli_cmd_dpp_configurator_remove(struct wpa_ctrl *ctrl, int argc,
3036 char *argv[])
3037 {
3038 return wpa_cli_cmd(ctrl, "DPP_CONFIGURATOR_REMOVE", 1, argc, argv);
3039 }
3040
3041
wpa_cli_cmd_dpp_configurator_get_key(struct wpa_ctrl * ctrl,int argc,char * argv[])3042 static int wpa_cli_cmd_dpp_configurator_get_key(struct wpa_ctrl *ctrl, int argc,
3043 char *argv[])
3044 {
3045 return wpa_cli_cmd(ctrl, "DPP_CONFIGURATOR_GET_KEY", 1, argc, argv);
3046 }
3047
3048
wpa_cli_cmd_dpp_configurator_sign(struct wpa_ctrl * ctrl,int argc,char * argv[])3049 static int wpa_cli_cmd_dpp_configurator_sign(struct wpa_ctrl *ctrl, int argc,
3050 char *argv[])
3051 {
3052 return wpa_cli_cmd(ctrl, "DPP_CONFIGURATOR_SIGN", 1, argc, argv);
3053 }
3054
3055
wpa_cli_cmd_dpp_pkex_add(struct wpa_ctrl * ctrl,int argc,char * argv[])3056 static int wpa_cli_cmd_dpp_pkex_add(struct wpa_ctrl *ctrl, int argc,
3057 char *argv[])
3058 {
3059 return wpa_cli_cmd(ctrl, "DPP_PKEX_ADD", 1, argc, argv);
3060 }
3061
3062
wpa_cli_cmd_dpp_pkex_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])3063 static int wpa_cli_cmd_dpp_pkex_remove(struct wpa_ctrl *ctrl, int argc,
3064 char *argv[])
3065 {
3066 return wpa_cli_cmd(ctrl, "DPP_PKEX_REMOVE", 1, argc, argv);
3067 }
3068
3069
3070 #ifdef CONFIG_DPP2
3071
wpa_cli_cmd_dpp_controller_start(struct wpa_ctrl * ctrl,int argc,char * argv[])3072 static int wpa_cli_cmd_dpp_controller_start(struct wpa_ctrl *ctrl, int argc,
3073 char *argv[])
3074 {
3075 return wpa_cli_cmd(ctrl, "DPP_CONTROLLER_START", 1, argc, argv);
3076 }
3077
3078
wpa_cli_cmd_dpp_controller_stop(struct wpa_ctrl * ctrl,int argc,char * argv[])3079 static int wpa_cli_cmd_dpp_controller_stop(struct wpa_ctrl *ctrl, int argc,
3080 char *argv[])
3081 {
3082 return wpa_ctrl_command(ctrl, "DPP_CONTROLLER_STOP");
3083 }
3084
3085
wpa_cli_cmd_dpp_chirp(struct wpa_ctrl * ctrl,int argc,char * argv[])3086 static int wpa_cli_cmd_dpp_chirp(struct wpa_ctrl *ctrl, int argc,
3087 char *argv[])
3088 {
3089 return wpa_cli_cmd(ctrl, "DPP_CHIRP", 1, argc, argv);
3090 }
3091
3092
wpa_cli_cmd_dpp_stop_chirp(struct wpa_ctrl * ctrl,int argc,char * argv[])3093 static int wpa_cli_cmd_dpp_stop_chirp(struct wpa_ctrl *ctrl, int argc,
3094 char *argv[])
3095 {
3096 return wpa_ctrl_command(ctrl, "DPP_STOP_CHIRP");
3097 }
3098
3099 #endif /* CONFIG_DPP2 */
3100 #endif /* CONFIG_DPP */
3101
3102
wpa_ctrl_command_bss(struct wpa_ctrl * ctrl,const char * cmd)3103 static int wpa_ctrl_command_bss(struct wpa_ctrl *ctrl, const char *cmd)
3104 {
3105 char buf[512], *pos, *bssid = NULL, *freq = NULL, *level = NULL,
3106 *flags = NULL, *ssid = NULL;
3107 size_t len;
3108 int ret, id = -1;
3109
3110 if (!ctrl_conn)
3111 return -1;
3112 len = sizeof(buf) - 1;
3113 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
3114 wpa_cli_msg_cb);
3115 if (ret == -2) {
3116 printf("'%s' command timed out.\n", cmd);
3117 return -2;
3118 } else if (ret < 0) {
3119 printf("'%s' command failed.\n", cmd);
3120 return -1;
3121 }
3122
3123 buf[len] = '\0';
3124 if (os_memcmp(buf, "FAIL", 4) == 0)
3125 return -1;
3126
3127 pos = buf;
3128 while (*pos != '\0') {
3129 if (str_starts(pos, "id="))
3130 id = atoi(pos + 3);
3131 if (str_starts(pos, "bssid="))
3132 bssid = pos + 6;
3133 if (str_starts(pos, "freq="))
3134 freq = pos + 5;
3135 if (str_starts(pos, "level="))
3136 level = pos + 6;
3137 if (str_starts(pos, "flags="))
3138 flags = pos + 6;
3139 if (str_starts(pos, "ssid="))
3140 ssid = pos + 5;
3141
3142 while (*pos != '\0' && *pos != '\n')
3143 pos++;
3144 *pos++ = '\0';
3145 }
3146 if (id != -1)
3147 printf("%s\t%s\t%s\t%s\t%s\n", bssid ? bssid : "N/A",
3148 freq ? freq : "N/A", level ? level : "N/A",
3149 flags ? flags : "N/A", ssid ? ssid : "N/A");
3150 return id;
3151 }
3152
3153
wpa_cli_cmd_all_bss(struct wpa_ctrl * ctrl,int argc,char * argv[])3154 static int wpa_cli_cmd_all_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
3155 {
3156 char cmd[64];
3157 int id = -1;
3158 unsigned int mask;
3159
3160 printf("bssid / frequency / signal level / flags / ssid\n");
3161
3162 mask = WPA_BSS_MASK_ID | WPA_BSS_MASK_BSSID | WPA_BSS_MASK_FREQ |
3163 WPA_BSS_MASK_LEVEL | WPA_BSS_MASK_FLAGS | WPA_BSS_MASK_SSID;
3164 do {
3165 if (id < 0)
3166 os_snprintf(cmd, sizeof(cmd), "BSS FIRST MASK=0x%x",
3167 mask);
3168 else
3169 os_snprintf(cmd, sizeof(cmd), "BSS NEXT-%d MASK=0x%x",
3170 id, mask);
3171 id = wpa_ctrl_command_bss(ctrl, cmd);
3172 } while (id >= 0);
3173
3174 return 0;
3175 }
3176
3177
3178 #ifdef CONFIG_PASN
3179
wpa_cli_cmd_pasn_auth_start(struct wpa_ctrl * ctrl,int argc,char * argv[])3180 static int wpa_cli_cmd_pasn_auth_start(struct wpa_ctrl *ctrl, int argc,
3181 char *argv[])
3182 {
3183 return wpa_cli_cmd(ctrl, "PASN_AUTH_START", 4, argc, argv);
3184 }
3185
3186
wpa_cli_cmd_pasn_auth_stop(struct wpa_ctrl * ctrl,int argc,char * argv[])3187 static int wpa_cli_cmd_pasn_auth_stop(struct wpa_ctrl *ctrl, int argc,
3188 char *argv[])
3189 {
3190 return wpa_cli_cmd(ctrl, "PASN_AUTH_STOP", 0, argc, argv);
3191 }
3192
wpa_cli_cmd_ptksa_cache_list(struct wpa_ctrl * ctrl,int argc,char * argv[])3193 static int wpa_cli_cmd_ptksa_cache_list(struct wpa_ctrl *ctrl, int argc,
3194 char *argv[])
3195 {
3196 return wpa_cli_cmd(ctrl, "PTKSA_CACHE_LIST", 0, argc, argv);
3197 }
3198
3199 #endif /* CONFIG_PASN */
3200
3201
3202 enum wpa_cli_cmd_flags {
3203 cli_cmd_flag_none = 0x00,
3204 cli_cmd_flag_sensitive = 0x01
3205 };
3206
3207 struct wpa_cli_cmd {
3208 const char *cmd;
3209 int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
3210 char ** (*completion)(const char *str, int pos);
3211 enum wpa_cli_cmd_flags flags;
3212 const char *usage;
3213 };
3214
3215 static const struct wpa_cli_cmd wpa_cli_commands[] = {
3216 { "status", wpa_cli_cmd_status, NULL,
3217 cli_cmd_flag_none,
3218 "[verbose] = get current WPA/EAPOL/EAP status" },
3219 { "ifname", wpa_cli_cmd_ifname, NULL,
3220 cli_cmd_flag_none,
3221 "= get current interface name" },
3222 { "ping", wpa_cli_cmd_ping, NULL,
3223 cli_cmd_flag_none,
3224 "= pings wpa_supplicant" },
3225 { "relog", wpa_cli_cmd_relog, NULL,
3226 cli_cmd_flag_none,
3227 "= re-open log-file (allow rolling logs)" },
3228 { "note", wpa_cli_cmd_note, NULL,
3229 cli_cmd_flag_none,
3230 "<text> = add a note to wpa_supplicant debug log" },
3231 { "mib", wpa_cli_cmd_mib, NULL,
3232 cli_cmd_flag_none,
3233 "= get MIB variables (dot1x, dot11)" },
3234 { "help", wpa_cli_cmd_help, wpa_cli_complete_help,
3235 cli_cmd_flag_none,
3236 "[command] = show usage help" },
3237 { "interface", wpa_cli_cmd_interface, NULL,
3238 cli_cmd_flag_none,
3239 "[ifname] = show interfaces/select interface" },
3240 { "level", wpa_cli_cmd_level, NULL,
3241 cli_cmd_flag_none,
3242 "<debug level> = change debug level" },
3243 { "license", wpa_cli_cmd_license, NULL,
3244 cli_cmd_flag_none,
3245 "= show full wpa_cli license" },
3246 { "quit", wpa_cli_cmd_quit, NULL,
3247 cli_cmd_flag_none,
3248 "= exit wpa_cli" },
3249 { "set", wpa_cli_cmd_set, wpa_cli_complete_set,
3250 cli_cmd_flag_none,
3251 "= set variables (shows list of variables when run without "
3252 "arguments)" },
3253 { "dump", wpa_cli_cmd_dump, NULL,
3254 cli_cmd_flag_none,
3255 "= dump config variables" },
3256 { "get", wpa_cli_cmd_get, wpa_cli_complete_get,
3257 cli_cmd_flag_none,
3258 "<name> = get information" },
3259 { "driver_flags", wpa_cli_cmd_driver_flags, NULL,
3260 cli_cmd_flag_none,
3261 "= list driver flags" },
3262 { "logon", wpa_cli_cmd_logon, NULL,
3263 cli_cmd_flag_none,
3264 "= IEEE 802.1X EAPOL state machine logon" },
3265 { "logoff", wpa_cli_cmd_logoff, NULL,
3266 cli_cmd_flag_none,
3267 "= IEEE 802.1X EAPOL state machine logoff" },
3268 { "pmksa", wpa_cli_cmd_pmksa, NULL,
3269 cli_cmd_flag_none,
3270 "= show PMKSA cache" },
3271 { "pmksa_flush", wpa_cli_cmd_pmksa_flush, NULL,
3272 cli_cmd_flag_none,
3273 "= flush PMKSA cache entries" },
3274 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
3275 { "pmksa_get", wpa_cli_cmd_pmksa_get, NULL,
3276 cli_cmd_flag_none,
3277 "<network_id> = fetch all stored PMKSA cache entries" },
3278 { "pmksa_add", wpa_cli_cmd_pmksa_add, NULL,
3279 cli_cmd_flag_sensitive,
3280 "<network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> <expiration in seconds> <akmp> <opportunistic> = store PMKSA cache entry from external storage" },
3281 #ifdef CONFIG_MESH
3282 { "mesh_pmksa_get", wpa_cli_mesh_cmd_pmksa_get, NULL,
3283 cli_cmd_flag_none,
3284 "<peer MAC address | any> = fetch all stored mesh PMKSA cache entries" },
3285 { "mesh_pmksa_add", wpa_cli_mesh_cmd_pmksa_add, NULL,
3286 cli_cmd_flag_sensitive,
3287 "<BSSID> <PMKID> <PMK> <expiration in seconds> = store mesh PMKSA cache entry from external storage" },
3288 #endif /* CONFIG_MESH */
3289 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
3290 { "reassociate", wpa_cli_cmd_reassociate, NULL,
3291 cli_cmd_flag_none,
3292 "= force reassociation" },
3293 { "reattach", wpa_cli_cmd_reattach, NULL,
3294 cli_cmd_flag_none,
3295 "= force reassociation back to the same BSS" },
3296 { "preauthenticate", wpa_cli_cmd_preauthenticate, wpa_cli_complete_bss,
3297 cli_cmd_flag_none,
3298 "<BSSID> = force preauthentication" },
3299 { "identity", wpa_cli_cmd_identity, wpa_cli_complete_network_id,
3300 cli_cmd_flag_none,
3301 "<network id> <identity> = configure identity for an SSID" },
3302 { "password", wpa_cli_cmd_password, wpa_cli_complete_network_id,
3303 cli_cmd_flag_sensitive,
3304 "<network id> <password> = configure password for an SSID" },
3305 { "new_password", wpa_cli_cmd_new_password,
3306 wpa_cli_complete_network_id, cli_cmd_flag_sensitive,
3307 "<network id> <password> = change password for an SSID" },
3308 { "pin", wpa_cli_cmd_pin, wpa_cli_complete_network_id,
3309 cli_cmd_flag_sensitive,
3310 "<network id> <pin> = configure pin for an SSID" },
3311 { "otp", wpa_cli_cmd_otp, wpa_cli_complete_network_id,
3312 cli_cmd_flag_sensitive,
3313 "<network id> <password> = configure one-time-password for an SSID"
3314 },
3315 { "psk_passphrase", wpa_cli_cmd_psk_passphrase,
3316 wpa_cli_complete_network_id, cli_cmd_flag_sensitive,
3317 "<network id> <PSK/passphrase> = configure PSK/passphrase for an SSID" },
3318 { "passphrase", wpa_cli_cmd_passphrase, wpa_cli_complete_network_id,
3319 cli_cmd_flag_sensitive,
3320 "<network id> <passphrase> = configure private key passphrase\n"
3321 " for an SSID" },
3322 { "sim", wpa_cli_cmd_sim, wpa_cli_complete_network_id,
3323 cli_cmd_flag_sensitive,
3324 "<network id> <pin> = report SIM operation result" },
3325 { "bssid", wpa_cli_cmd_bssid, wpa_cli_complete_network_id,
3326 cli_cmd_flag_none,
3327 "<network id> <BSSID> = set preferred BSSID for an SSID" },
3328 { "bssid_ignore", wpa_cli_cmd_bssid_ignore, wpa_cli_complete_bss,
3329 cli_cmd_flag_none,
3330 "<BSSID> = add a BSSID to the list of temporarily ignored BSSs\n"
3331 "bssid_ignore clear = clear the list of temporarily ignored BSSIDs\n"
3332 "bssid_ignore = display the list of temporarily ignored BSSIDs" },
3333 { "blacklist", /* deprecated alias for bssid_ignore */
3334 wpa_cli_cmd_bssid_ignore, wpa_cli_complete_bss,
3335 cli_cmd_flag_none,
3336 "= deprecated alias for bssid_ignore" },
3337 { "log_level", wpa_cli_cmd_log_level, NULL,
3338 cli_cmd_flag_none,
3339 "<level> [<timestamp>] = update the log level/timestamp\n"
3340 "log_level = display the current log level and log options" },
3341 { "list_networks", wpa_cli_cmd_list_networks, NULL,
3342 cli_cmd_flag_none,
3343 "= list configured networks" },
3344 { "select_network", wpa_cli_cmd_select_network,
3345 wpa_cli_complete_network_id,
3346 cli_cmd_flag_none,
3347 "<network id> = select a network (disable others)" },
3348 { "enable_network", wpa_cli_cmd_enable_network,
3349 wpa_cli_complete_network_id,
3350 cli_cmd_flag_none,
3351 "<network id> = enable a network" },
3352 { "disable_network", wpa_cli_cmd_disable_network,
3353 wpa_cli_complete_network_id,
3354 cli_cmd_flag_none,
3355 "<network id> = disable a network" },
3356 { "add_network", wpa_cli_cmd_add_network, NULL,
3357 cli_cmd_flag_none,
3358 "= add a network" },
3359 { "remove_network", wpa_cli_cmd_remove_network,
3360 wpa_cli_complete_network_id,
3361 cli_cmd_flag_none,
3362 "<network id> = remove a network" },
3363 { "set_network", wpa_cli_cmd_set_network, wpa_cli_complete_network,
3364 cli_cmd_flag_sensitive,
3365 "<network id> <variable> <value> = set network variables (shows\n"
3366 " list of variables when run without arguments)" },
3367 { "get_network", wpa_cli_cmd_get_network, wpa_cli_complete_network,
3368 cli_cmd_flag_none,
3369 "<network id> <variable> = get network variables" },
3370 { "dup_network", wpa_cli_cmd_dup_network, wpa_cli_complete_dup_network,
3371 cli_cmd_flag_none,
3372 "<src network id> <dst network id> <variable> = duplicate network variables"
3373 },
3374 { "list_creds", wpa_cli_cmd_list_creds, NULL,
3375 cli_cmd_flag_none,
3376 "= list configured credentials" },
3377 { "add_cred", wpa_cli_cmd_add_cred, NULL,
3378 cli_cmd_flag_none,
3379 "= add a credential" },
3380 { "remove_cred", wpa_cli_cmd_remove_cred, NULL,
3381 cli_cmd_flag_none,
3382 "<cred id> = remove a credential" },
3383 { "set_cred", wpa_cli_cmd_set_cred, wpa_cli_complete_cred,
3384 cli_cmd_flag_sensitive,
3385 "<cred id> <variable> <value> = set credential variables" },
3386 { "get_cred", wpa_cli_cmd_get_cred, wpa_cli_complete_cred,
3387 cli_cmd_flag_none,
3388 "<cred id> <variable> = get credential variables" },
3389 { "save_config", wpa_cli_cmd_save_config, NULL,
3390 cli_cmd_flag_none,
3391 "= save the current configuration" },
3392 { "disconnect", wpa_cli_cmd_disconnect, NULL,
3393 cli_cmd_flag_none,
3394 "= disconnect and wait for reassociate/reconnect command before\n"
3395 " connecting" },
3396 { "reconnect", wpa_cli_cmd_reconnect, NULL,
3397 cli_cmd_flag_none,
3398 "= like reassociate, but only takes effect if already disconnected"
3399 },
3400 { "scan", wpa_cli_cmd_scan, NULL,
3401 cli_cmd_flag_none,
3402 "= request new BSS scan" },
3403 { "scan_results", wpa_cli_cmd_scan_results, NULL,
3404 cli_cmd_flag_none,
3405 "= get latest scan results" },
3406 { "abort_scan", wpa_cli_cmd_abort_scan, NULL,
3407 cli_cmd_flag_none,
3408 "= request ongoing scan to be aborted" },
3409 { "bss", wpa_cli_cmd_bss, wpa_cli_complete_bss,
3410 cli_cmd_flag_none,
3411 "<<idx> | <bssid>> = get detailed scan result info" },
3412 { "get_capability", wpa_cli_cmd_get_capability,
3413 wpa_cli_complete_get_capability, cli_cmd_flag_none,
3414 "<eap/pairwise/group/key_mgmt/proto/auth_alg/channels/freq/modes> "
3415 "= get capabilities" },
3416 { "reconfigure", wpa_cli_cmd_reconfigure, NULL,
3417 cli_cmd_flag_none,
3418 "= force wpa_supplicant to re-read its configuration file" },
3419 { "terminate", wpa_cli_cmd_terminate, NULL,
3420 cli_cmd_flag_none,
3421 "= terminate wpa_supplicant" },
3422 { "interface_add", wpa_cli_cmd_interface_add, NULL,
3423 cli_cmd_flag_none,
3424 "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
3425 " <bridge_name> <create> <type> = adds new interface, all "
3426 "parameters but\n"
3427 " <ifname> are optional. Supported types are station ('sta') and "
3428 "AP ('ap')" },
3429 { "interface_remove", wpa_cli_cmd_interface_remove, NULL,
3430 cli_cmd_flag_none,
3431 "<ifname> = removes the interface" },
3432 { "interface_list", wpa_cli_cmd_interface_list, NULL,
3433 cli_cmd_flag_none,
3434 "= list available interfaces" },
3435 { "ap_scan", wpa_cli_cmd_ap_scan, NULL,
3436 cli_cmd_flag_none,
3437 "<value> = set ap_scan parameter" },
3438 { "scan_interval", wpa_cli_cmd_scan_interval, NULL,
3439 cli_cmd_flag_none,
3440 "<value> = set scan_interval parameter (in seconds)" },
3441 { "bss_expire_age", wpa_cli_cmd_bss_expire_age, NULL,
3442 cli_cmd_flag_none,
3443 "<value> = set BSS expiration age parameter" },
3444 { "bss_expire_count", wpa_cli_cmd_bss_expire_count, NULL,
3445 cli_cmd_flag_none,
3446 "<value> = set BSS expiration scan count parameter" },
3447 { "bss_flush", wpa_cli_cmd_bss_flush, NULL,
3448 cli_cmd_flag_none,
3449 "<value> = set BSS flush age (0 by default)" },
3450 { "ft_ds", wpa_cli_cmd_ft_ds, wpa_cli_complete_bss,
3451 cli_cmd_flag_none,
3452 "<addr> = request over-the-DS FT with <addr>" },
3453 { "wps_pbc", wpa_cli_cmd_wps_pbc, wpa_cli_complete_bss,
3454 cli_cmd_flag_none,
3455 "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
3456 { "wps_pin", wpa_cli_cmd_wps_pin, wpa_cli_complete_bss,
3457 cli_cmd_flag_sensitive,
3458 "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
3459 "hardcoded)" },
3460 { "wps_check_pin", wpa_cli_cmd_wps_check_pin, NULL,
3461 cli_cmd_flag_sensitive,
3462 "<PIN> = verify PIN checksum" },
3463 { "wps_cancel", wpa_cli_cmd_wps_cancel, NULL, cli_cmd_flag_none,
3464 "Cancels the pending WPS operation" },
3465 #ifdef CONFIG_WPS_NFC
3466 { "wps_nfc", wpa_cli_cmd_wps_nfc, wpa_cli_complete_bss,
3467 cli_cmd_flag_none,
3468 "[BSSID] = start Wi-Fi Protected Setup: NFC" },
3469 { "wps_nfc_config_token", wpa_cli_cmd_wps_nfc_config_token, NULL,
3470 cli_cmd_flag_none,
3471 "<WPS|NDEF> = build configuration token" },
3472 { "wps_nfc_token", wpa_cli_cmd_wps_nfc_token, NULL,
3473 cli_cmd_flag_none,
3474 "<WPS|NDEF> = create password token" },
3475 { "wps_nfc_tag_read", wpa_cli_cmd_wps_nfc_tag_read, NULL,
3476 cli_cmd_flag_sensitive,
3477 "<hexdump of payload> = report read NFC tag with WPS data" },
3478 { "nfc_get_handover_req", wpa_cli_cmd_nfc_get_handover_req, NULL,
3479 cli_cmd_flag_none,
3480 "<NDEF> <WPS> = create NFC handover request" },
3481 { "nfc_get_handover_sel", wpa_cli_cmd_nfc_get_handover_sel, NULL,
3482 cli_cmd_flag_none,
3483 "<NDEF> <WPS> = create NFC handover select" },
3484 { "nfc_report_handover", wpa_cli_cmd_nfc_report_handover, NULL,
3485 cli_cmd_flag_none,
3486 "<role> <type> <hexdump of req> <hexdump of sel> = report completed "
3487 "NFC handover" },
3488 #endif /* CONFIG_WPS_NFC */
3489 { "wps_reg", wpa_cli_cmd_wps_reg, wpa_cli_complete_bss,
3490 cli_cmd_flag_sensitive,
3491 "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
3492 { "wps_ap_pin", wpa_cli_cmd_wps_ap_pin, NULL,
3493 cli_cmd_flag_sensitive,
3494 "[params..] = enable/disable AP PIN" },
3495 { "wps_er_start", wpa_cli_cmd_wps_er_start, NULL,
3496 cli_cmd_flag_none,
3497 "[IP address] = start Wi-Fi Protected Setup External Registrar" },
3498 { "wps_er_stop", wpa_cli_cmd_wps_er_stop, NULL,
3499 cli_cmd_flag_none,
3500 "= stop Wi-Fi Protected Setup External Registrar" },
3501 { "wps_er_pin", wpa_cli_cmd_wps_er_pin, NULL,
3502 cli_cmd_flag_sensitive,
3503 "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
3504 { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc, NULL,
3505 cli_cmd_flag_none,
3506 "<UUID> = accept an Enrollee PBC using External Registrar" },
3507 { "wps_er_learn", wpa_cli_cmd_wps_er_learn, NULL,
3508 cli_cmd_flag_sensitive,
3509 "<UUID> <PIN> = learn AP configuration" },
3510 { "wps_er_set_config", wpa_cli_cmd_wps_er_set_config, NULL,
3511 cli_cmd_flag_none,
3512 "<UUID> <network id> = set AP configuration for enrolling" },
3513 { "wps_er_config", wpa_cli_cmd_wps_er_config, NULL,
3514 cli_cmd_flag_sensitive,
3515 "<UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP" },
3516 #ifdef CONFIG_WPS_NFC
3517 { "wps_er_nfc_config_token", wpa_cli_cmd_wps_er_nfc_config_token, NULL,
3518 cli_cmd_flag_none,
3519 "<WPS/NDEF> <UUID> = build NFC configuration token" },
3520 #endif /* CONFIG_WPS_NFC */
3521 { "ibss_rsn", wpa_cli_cmd_ibss_rsn, NULL,
3522 cli_cmd_flag_none,
3523 "<addr> = request RSN authentication with <addr> in IBSS" },
3524 #ifdef CONFIG_AP
3525 { "sta", wpa_cli_cmd_sta, wpa_cli_complete_sta,
3526 cli_cmd_flag_none,
3527 "<addr> = get information about an associated station (AP)" },
3528 { "all_sta", wpa_cli_cmd_all_sta, NULL,
3529 cli_cmd_flag_none,
3530 "= get information about all associated stations (AP)" },
3531 { "list_sta", wpa_cli_cmd_list_sta, NULL,
3532 cli_cmd_flag_none,
3533 "= list all stations (AP)" },
3534 { "deauthenticate", wpa_cli_cmd_deauthenticate,
3535 wpa_cli_complete_deauthenticate, cli_cmd_flag_none,
3536 "<addr> = deauthenticate a station" },
3537 { "disassociate", wpa_cli_cmd_disassociate,
3538 wpa_cli_complete_disassociate, cli_cmd_flag_none,
3539 "<addr> = disassociate a station" },
3540 { "chan_switch", wpa_cli_cmd_chanswitch, NULL,
3541 cli_cmd_flag_none,
3542 "<cs_count> <freq> [sec_channel_offset=] [center_freq1=]"
3543 " [center_freq2=] [bandwidth=] [blocktx] [ht|vht]"
3544 " = CSA parameters" },
3545 #endif /* CONFIG_AP */
3546 { "suspend", wpa_cli_cmd_suspend, NULL, cli_cmd_flag_none,
3547 "= notification of suspend/hibernate" },
3548 { "resume", wpa_cli_cmd_resume, NULL, cli_cmd_flag_none,
3549 "= notification of resume/thaw" },
3550 #ifdef CONFIG_TESTING_OPTIONS
3551 { "drop_sa", wpa_cli_cmd_drop_sa, NULL, cli_cmd_flag_none,
3552 "= drop SA without deauth/disassoc (test command)" },
3553 #endif /* CONFIG_TESTING_OPTIONS */
3554 { "roam", wpa_cli_cmd_roam, wpa_cli_complete_bss,
3555 cli_cmd_flag_none,
3556 "<addr> = roam to the specified BSS" },
3557 #ifdef CONFIG_MESH
3558 { "mesh_interface_add", wpa_cli_cmd_mesh_interface_add, NULL,
3559 cli_cmd_flag_none,
3560 "[ifname] = Create a new mesh interface" },
3561 { "mesh_group_add", wpa_cli_cmd_mesh_group_add, NULL,
3562 cli_cmd_flag_none,
3563 "<network id> = join a mesh network (disable others)" },
3564 { "mesh_group_remove", wpa_cli_cmd_mesh_group_remove, NULL,
3565 cli_cmd_flag_none,
3566 "<ifname> = Remove mesh group interface" },
3567 { "mesh_peer_remove", wpa_cli_cmd_mesh_peer_remove, NULL,
3568 cli_cmd_flag_none,
3569 "<addr> = Remove a mesh peer" },
3570 { "mesh_peer_add", wpa_cli_cmd_mesh_peer_add, NULL,
3571 cli_cmd_flag_none,
3572 "<addr> [duration=<seconds>] = Add a mesh peer" },
3573 { "mesh_link_probe", wpa_cli_cmd_mesh_link_probe, NULL,
3574 cli_cmd_flag_none,
3575 "<addr> [payload=<hex dump of payload>] = Probe a mesh link for a given peer by injecting a frame." },
3576 #endif /* CONFIG_MESH */
3577 #ifdef CONFIG_P2P
3578 { "p2p_find", wpa_cli_cmd_p2p_find, wpa_cli_complete_p2p_find,
3579 cli_cmd_flag_none,
3580 "[timeout] [type=*] = find P2P Devices for up-to timeout seconds" },
3581 { "p2p_stop_find", wpa_cli_cmd_p2p_stop_find, NULL, cli_cmd_flag_none,
3582 "= stop P2P Devices search" },
3583 { "p2p_asp_provision", wpa_cli_cmd_p2p_asp_provision, NULL,
3584 cli_cmd_flag_none,
3585 "<addr> adv_id=<adv_id> conncap=<conncap> [info=<infodata>] = provision with a P2P ASP Device" },
3586 { "p2p_asp_provision_resp", wpa_cli_cmd_p2p_asp_provision_resp, NULL,
3587 cli_cmd_flag_none,
3588 "<addr> adv_id=<adv_id> [role<conncap>] [info=<infodata>] = provision with a P2P ASP Device" },
3589 { "p2p_connect", wpa_cli_cmd_p2p_connect, wpa_cli_complete_p2p_connect,
3590 cli_cmd_flag_none,
3591 "<addr> <\"pbc\"|PIN> [ht40] = connect to a P2P Device" },
3592 { "p2p_listen", wpa_cli_cmd_p2p_listen, NULL, cli_cmd_flag_none,
3593 "[timeout] = listen for P2P Devices for up-to timeout seconds" },
3594 { "p2p_group_remove", wpa_cli_cmd_p2p_group_remove,
3595 wpa_cli_complete_p2p_group_remove, cli_cmd_flag_none,
3596 "<ifname> = remove P2P group interface (terminate group if GO)" },
3597 { "p2p_group_add", wpa_cli_cmd_p2p_group_add, NULL, cli_cmd_flag_none,
3598 "[ht40] = add a new P2P group (local end as GO)" },
3599 { "p2p_group_member", wpa_cli_cmd_p2p_group_member, NULL,
3600 cli_cmd_flag_none,
3601 "<dev_addr> = Get peer interface address on local GO using peer Device Address" },
3602 { "p2p_prov_disc", wpa_cli_cmd_p2p_prov_disc,
3603 wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
3604 "<addr> <method> = request provisioning discovery" },
3605 { "p2p_get_passphrase", wpa_cli_cmd_p2p_get_passphrase, NULL,
3606 cli_cmd_flag_none,
3607 "= get the passphrase for a group (GO only)" },
3608 { "p2p_serv_disc_req", wpa_cli_cmd_p2p_serv_disc_req,
3609 wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
3610 "<addr> <TLVs> = schedule service discovery request" },
3611 { "p2p_serv_disc_cancel_req", wpa_cli_cmd_p2p_serv_disc_cancel_req,
3612 NULL, cli_cmd_flag_none,
3613 "<id> = cancel pending service discovery request" },
3614 { "p2p_serv_disc_resp", wpa_cli_cmd_p2p_serv_disc_resp, NULL,
3615 cli_cmd_flag_none,
3616 "<freq> <addr> <dialog token> <TLVs> = service discovery response" },
3617 { "p2p_service_update", wpa_cli_cmd_p2p_service_update, NULL,
3618 cli_cmd_flag_none,
3619 "= indicate change in local services" },
3620 { "p2p_serv_disc_external", wpa_cli_cmd_p2p_serv_disc_external, NULL,
3621 cli_cmd_flag_none,
3622 "<external> = set external processing of service discovery" },
3623 { "p2p_service_flush", wpa_cli_cmd_p2p_service_flush, NULL,
3624 cli_cmd_flag_none,
3625 "= remove all stored service entries" },
3626 { "p2p_service_add", wpa_cli_cmd_p2p_service_add, NULL,
3627 cli_cmd_flag_none,
3628 "<bonjour|upnp|asp> <query|version> <response|service> = add a local "
3629 "service" },
3630 { "p2p_service_rep", wpa_cli_cmd_p2p_service_rep, NULL,
3631 cli_cmd_flag_none,
3632 "asp <auto> <adv_id> <svc_state> <svc_string> [<svc_info>] = replace "
3633 "local ASP service" },
3634 { "p2p_service_del", wpa_cli_cmd_p2p_service_del, NULL,
3635 cli_cmd_flag_none,
3636 "<bonjour|upnp> <query|version> [|service] = remove a local "
3637 "service" },
3638 { "p2p_reject", wpa_cli_cmd_p2p_reject, wpa_cli_complete_p2p_peer,
3639 cli_cmd_flag_none,
3640 "<addr> = reject connection attempts from a specific peer" },
3641 { "p2p_invite", wpa_cli_cmd_p2p_invite, NULL,
3642 cli_cmd_flag_none,
3643 "<cmd> [peer=addr] = invite peer" },
3644 { "p2p_peers", wpa_cli_cmd_p2p_peers, NULL, cli_cmd_flag_none,
3645 "[discovered] = list known (optionally, only fully discovered) P2P "
3646 "peers" },
3647 { "p2p_peer", wpa_cli_cmd_p2p_peer, wpa_cli_complete_p2p_peer,
3648 cli_cmd_flag_none,
3649 "<address> = show information about known P2P peer" },
3650 { "p2p_set", wpa_cli_cmd_p2p_set, wpa_cli_complete_p2p_set,
3651 cli_cmd_flag_none,
3652 "<field> <value> = set a P2P parameter" },
3653 { "p2p_flush", wpa_cli_cmd_p2p_flush, NULL, cli_cmd_flag_none,
3654 "= flush P2P state" },
3655 { "p2p_cancel", wpa_cli_cmd_p2p_cancel, NULL, cli_cmd_flag_none,
3656 "= cancel P2P group formation" },
3657 { "p2p_unauthorize", wpa_cli_cmd_p2p_unauthorize,
3658 wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
3659 "<address> = unauthorize a peer" },
3660 { "p2p_presence_req", wpa_cli_cmd_p2p_presence_req, NULL,
3661 cli_cmd_flag_none,
3662 "[<duration> <interval>] [<duration> <interval>] = request GO "
3663 "presence" },
3664 { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen, NULL,
3665 cli_cmd_flag_none,
3666 "[<period> <interval>] = set extended listen timing" },
3667 { "p2p_remove_client", wpa_cli_cmd_p2p_remove_client,
3668 wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
3669 "<address|iface=address> = remove a peer from all groups" },
3670 #endif /* CONFIG_P2P */
3671 { "vendor_elem_add", wpa_cli_cmd_vendor_elem_add, NULL,
3672 cli_cmd_flag_none,
3673 "<frame id> <hexdump of elem(s)> = add vendor specific IEs to frame(s)\n"
3674 VENDOR_ELEM_FRAME_ID },
3675 { "vendor_elem_get", wpa_cli_cmd_vendor_elem_get, NULL,
3676 cli_cmd_flag_none,
3677 "<frame id> = get vendor specific IE(s) to frame(s)\n"
3678 VENDOR_ELEM_FRAME_ID },
3679 { "vendor_elem_remove", wpa_cli_cmd_vendor_elem_remove, NULL,
3680 cli_cmd_flag_none,
3681 "<frame id> <hexdump of elem(s)> = remove vendor specific IE(s) in frame(s)\n"
3682 VENDOR_ELEM_FRAME_ID },
3683 #ifdef CONFIG_WIFI_DISPLAY
3684 { "wfd_subelem_set", wpa_cli_cmd_wfd_subelem_set, NULL,
3685 cli_cmd_flag_none,
3686 "<subelem> [contents] = set Wi-Fi Display subelement" },
3687 { "wfd_subelem_get", wpa_cli_cmd_wfd_subelem_get, NULL,
3688 cli_cmd_flag_none,
3689 "<subelem> = get Wi-Fi Display subelement" },
3690 #endif /* CONFIG_WIFI_DISPLAY */
3691 #ifdef CONFIG_INTERWORKING
3692 { "fetch_anqp", wpa_cli_cmd_fetch_anqp, NULL, cli_cmd_flag_none,
3693 "= fetch ANQP information for all APs" },
3694 { "stop_fetch_anqp", wpa_cli_cmd_stop_fetch_anqp, NULL,
3695 cli_cmd_flag_none,
3696 "= stop fetch_anqp operation" },
3697 { "interworking_select", wpa_cli_cmd_interworking_select, NULL,
3698 cli_cmd_flag_none,
3699 "[auto] = perform Interworking network selection" },
3700 { "interworking_connect", wpa_cli_cmd_interworking_connect,
3701 wpa_cli_complete_bss, cli_cmd_flag_none,
3702 "<BSSID> = connect using Interworking credentials" },
3703 { "interworking_add_network", wpa_cli_cmd_interworking_add_network,
3704 wpa_cli_complete_bss, cli_cmd_flag_none,
3705 "<BSSID> = connect using Interworking credentials" },
3706 { "anqp_get", wpa_cli_cmd_anqp_get, wpa_cli_complete_bss,
3707 cli_cmd_flag_none,
3708 "<addr> <info id>[,<info id>]... = request ANQP information" },
3709 { "gas_request", wpa_cli_cmd_gas_request, wpa_cli_complete_bss,
3710 cli_cmd_flag_none,
3711 "<addr> <AdvProtoID> [QueryReq] = GAS request" },
3712 { "gas_response_get", wpa_cli_cmd_gas_response_get,
3713 wpa_cli_complete_bss, cli_cmd_flag_none,
3714 "<addr> <dialog token> [start,len] = Fetch last GAS response" },
3715 #endif /* CONFIG_INTERWORKING */
3716 #ifdef CONFIG_HS20
3717 { "hs20_anqp_get", wpa_cli_cmd_hs20_anqp_get, wpa_cli_complete_bss,
3718 cli_cmd_flag_none,
3719 "<addr> <subtype>[,<subtype>]... = request HS 2.0 ANQP information"
3720 },
3721 { "nai_home_realm_list", wpa_cli_cmd_get_nai_home_realm_list,
3722 wpa_cli_complete_bss, cli_cmd_flag_none,
3723 "<addr> <home realm> = get HS20 nai home realm list" },
3724 { "hs20_icon_request", wpa_cli_cmd_hs20_icon_request,
3725 wpa_cli_complete_bss, cli_cmd_flag_none,
3726 "<addr> <icon name> = get Hotspot 2.0 OSU icon" },
3727 { "fetch_osu", wpa_cli_cmd_fetch_osu, NULL, cli_cmd_flag_none,
3728 "= fetch OSU provider information from all APs" },
3729 { "cancel_fetch_osu", wpa_cli_cmd_cancel_fetch_osu, NULL,
3730 cli_cmd_flag_none,
3731 "= cancel fetch_osu command" },
3732 #endif /* CONFIG_HS20 */
3733 { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect, NULL,
3734 cli_cmd_flag_none,
3735 "<0/1> = disable/enable automatic reconnection" },
3736 { "tdls_discover", wpa_cli_cmd_tdls_discover, NULL,
3737 cli_cmd_flag_none,
3738 "<addr> = request TDLS discovery with <addr>" },
3739 { "tdls_setup", wpa_cli_cmd_tdls_setup, NULL,
3740 cli_cmd_flag_none,
3741 "<addr> = request TDLS setup with <addr>" },
3742 { "tdls_teardown", wpa_cli_cmd_tdls_teardown, NULL,
3743 cli_cmd_flag_none,
3744 "<addr> = tear down TDLS with <addr>" },
3745 { "tdls_link_status", wpa_cli_cmd_tdls_link_status, NULL,
3746 cli_cmd_flag_none,
3747 "<addr> = TDLS link status with <addr>" },
3748 { "wmm_ac_addts", wpa_cli_cmd_wmm_ac_addts, NULL,
3749 cli_cmd_flag_none,
3750 "<uplink/downlink/bidi> <tsid=0..7> <up=0..7> [nominal_msdu_size=#] "
3751 "[mean_data_rate=#] [min_phy_rate=#] [sba=#] [fixed_nominal_msdu] "
3752 "= add WMM-AC traffic stream" },
3753 { "wmm_ac_delts", wpa_cli_cmd_wmm_ac_delts, NULL,
3754 cli_cmd_flag_none,
3755 "<tsid> = delete WMM-AC traffic stream" },
3756 { "wmm_ac_status", wpa_cli_cmd_wmm_ac_status, NULL,
3757 cli_cmd_flag_none,
3758 "= show status for Wireless Multi-Media Admission-Control" },
3759 { "tdls_chan_switch", wpa_cli_cmd_tdls_chan_switch, NULL,
3760 cli_cmd_flag_none,
3761 "<addr> <oper class> <freq> [sec_channel_offset=] [center_freq1=] "
3762 "[center_freq2=] [bandwidth=] [ht|vht] = enable channel switching "
3763 "with TDLS peer" },
3764 { "tdls_cancel_chan_switch", wpa_cli_cmd_tdls_cancel_chan_switch, NULL,
3765 cli_cmd_flag_none,
3766 "<addr> = disable channel switching with TDLS peer <addr>" },
3767 { "signal_poll", wpa_cli_cmd_signal_poll, NULL,
3768 cli_cmd_flag_none,
3769 "= get signal parameters" },
3770 { "signal_monitor", wpa_cli_cmd_signal_monitor, NULL,
3771 cli_cmd_flag_none,
3772 "= set signal monitor parameters" },
3773 { "pktcnt_poll", wpa_cli_cmd_pktcnt_poll, NULL,
3774 cli_cmd_flag_none,
3775 "= get TX/RX packet counters" },
3776 { "reauthenticate", wpa_cli_cmd_reauthenticate, NULL,
3777 cli_cmd_flag_none,
3778 "= trigger IEEE 802.1X/EAPOL reauthentication" },
3779 #ifdef CONFIG_AUTOSCAN
3780 { "autoscan", wpa_cli_cmd_autoscan, NULL, cli_cmd_flag_none,
3781 "[params] = Set or unset (if none) autoscan parameters" },
3782 #endif /* CONFIG_AUTOSCAN */
3783 #ifdef CONFIG_WNM
3784 { "wnm_sleep", wpa_cli_cmd_wnm_sleep, NULL, cli_cmd_flag_none,
3785 "<enter/exit> [interval=#] = enter/exit WNM-Sleep mode" },
3786 { "wnm_bss_query", wpa_cli_cmd_wnm_bss_query, NULL, cli_cmd_flag_none,
3787 "<query reason> [list]"
3788 " [neighbor=<BSSID>,<BSSID information>,<operating class>,<channel number>,<PHY type>[,<hexdump of optional subelements>]"
3789 " = Send BSS Transition Management Query" },
3790 #endif /* CONFIG_WNM */
3791 { "raw", wpa_cli_cmd_raw, NULL, cli_cmd_flag_sensitive,
3792 "<params..> = Sent unprocessed command" },
3793 { "flush", wpa_cli_cmd_flush, NULL, cli_cmd_flag_none,
3794 "= flush wpa_supplicant state" },
3795 #ifdef ANDROID
3796 { "driver", wpa_cli_cmd_driver, NULL, cli_cmd_flag_none,
3797 "<command> = driver private commands" },
3798 #endif /* ANDROID */
3799 { "radio_work", wpa_cli_cmd_radio_work, NULL, cli_cmd_flag_none,
3800 "= radio_work <show/add/done>" },
3801 { "vendor", wpa_cli_cmd_vendor, NULL, cli_cmd_flag_none,
3802 "<vendor id> <command id> [<hex formatted command argument>] = Send vendor command"
3803 },
3804 { "neighbor_rep_request",
3805 wpa_cli_cmd_neighbor_rep_request, NULL, cli_cmd_flag_none,
3806 "[ssid=<SSID>] [lci] [civic] = Trigger request to AP for neighboring AP report (with optional given SSID in hex or enclosed in double quotes, default: current SSID; with optional LCI and location civic request)"
3807 },
3808 { "erp_flush", wpa_cli_cmd_erp_flush, NULL, cli_cmd_flag_none,
3809 "= flush ERP keys" },
3810 { "mac_rand_scan",
3811 wpa_cli_cmd_mac_rand_scan, NULL, cli_cmd_flag_none,
3812 "<scan|sched|pno|all> enable=<0/1> [addr=mac-address "
3813 "mask=mac-address-mask] = scan MAC randomization"
3814 },
3815 { "get_pref_freq_list", wpa_cli_cmd_get_pref_freq_list, NULL,
3816 cli_cmd_flag_none,
3817 "<interface type> = retrieve preferred freq list for the specified interface type" },
3818 { "p2p_lo_start", wpa_cli_cmd_p2p_lo_start, NULL,
3819 cli_cmd_flag_none,
3820 "<freq> <period> <interval> <count> = start P2P listen offload" },
3821 { "p2p_lo_stop", wpa_cli_cmd_p2p_lo_stop, NULL,
3822 cli_cmd_flag_none,
3823 "= stop P2P listen offload" },
3824 #ifdef CONFIG_DPP
3825 { "dpp_qr_code", wpa_cli_cmd_dpp_qr_code, NULL, cli_cmd_flag_none,
3826 "report a scanned DPP URI from a QR Code" },
3827 { "dpp_bootstrap_gen", wpa_cli_cmd_dpp_bootstrap_gen, NULL,
3828 cli_cmd_flag_sensitive,
3829 "type=<qrcode> [chan=..] [mac=..] [info=..] [curve=..] [key=..] = generate DPP bootstrap information" },
3830 { "dpp_bootstrap_remove", wpa_cli_cmd_dpp_bootstrap_remove, NULL,
3831 cli_cmd_flag_none,
3832 "*|<id> = remove DPP bootstrap information" },
3833 { "dpp_bootstrap_get_uri", wpa_cli_cmd_dpp_bootstrap_get_uri, NULL,
3834 cli_cmd_flag_none,
3835 "<id> = get DPP bootstrap URI" },
3836 { "dpp_bootstrap_info", wpa_cli_cmd_dpp_bootstrap_info, NULL,
3837 cli_cmd_flag_none,
3838 "<id> = show DPP bootstrap information" },
3839 { "dpp_bootstrap_set", wpa_cli_cmd_dpp_bootstrap_set, NULL,
3840 cli_cmd_flag_none,
3841 "<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" },
3842 { "dpp_auth_init", wpa_cli_cmd_dpp_auth_init, NULL, cli_cmd_flag_none,
3843 "peer=<id> [own=<id>] = initiate DPP bootstrapping" },
3844 { "dpp_listen", wpa_cli_cmd_dpp_listen, NULL, cli_cmd_flag_none,
3845 "<freq in MHz> = start DPP listen" },
3846 { "dpp_stop_listen", wpa_cli_cmd_dpp_stop_listen, NULL,
3847 cli_cmd_flag_none,
3848 "= stop DPP listen" },
3849 { "dpp_configurator_add", wpa_cli_cmd_dpp_configurator_add, NULL,
3850 cli_cmd_flag_sensitive,
3851 "[curve=..] [key=..] = add DPP configurator" },
3852 { "dpp_configurator_remove", wpa_cli_cmd_dpp_configurator_remove, NULL,
3853 cli_cmd_flag_none,
3854 "*|<id> = remove DPP configurator" },
3855 { "dpp_configurator_get_key", wpa_cli_cmd_dpp_configurator_get_key,
3856 NULL, cli_cmd_flag_none,
3857 "<id> = Get DPP configurator's private key" },
3858 { "dpp_configurator_sign", wpa_cli_cmd_dpp_configurator_sign, NULL,
3859 cli_cmd_flag_none,
3860 "conf=<role> configurator=<id> = generate self DPP configuration" },
3861 { "dpp_pkex_add", wpa_cli_cmd_dpp_pkex_add, NULL,
3862 cli_cmd_flag_sensitive,
3863 "add PKEX code" },
3864 { "dpp_pkex_remove", wpa_cli_cmd_dpp_pkex_remove, NULL,
3865 cli_cmd_flag_none,
3866 "*|<id> = remove DPP pkex information" },
3867 #ifdef CONFIG_DPP2
3868 { "dpp_controller_start", wpa_cli_cmd_dpp_controller_start, NULL,
3869 cli_cmd_flag_none,
3870 "[tcp_port=<port>] [role=..] = start DPP controller" },
3871 { "dpp_controller_stop", wpa_cli_cmd_dpp_controller_stop, NULL,
3872 cli_cmd_flag_none,
3873 "= stop DPP controller" },
3874 { "dpp_chirp", wpa_cli_cmd_dpp_chirp, NULL,
3875 cli_cmd_flag_none,
3876 "own=<BI ID> iter=<count> = start DPP chirp" },
3877 { "dpp_stop_chirp", wpa_cli_cmd_dpp_stop_chirp, NULL,
3878 cli_cmd_flag_none,
3879 "= stop DPP chirp" },
3880 #endif /* CONFIG_DPP2 */
3881 #endif /* CONFIG_DPP */
3882 { "all_bss", wpa_cli_cmd_all_bss, NULL, cli_cmd_flag_none,
3883 "= list all BSS entries (scan results)" },
3884 #ifdef CONFIG_PASN
3885 { "pasn_auth_start", wpa_cli_cmd_pasn_auth_start, NULL,
3886 cli_cmd_flag_none,
3887 "bssid=<BSSID> akmp=<WPA key mgmt> cipher=<WPA cipher> group=<group> nid=<network id> = Start PASN authentication" },
3888 { "pasn_auth_stop", wpa_cli_cmd_pasn_auth_stop, NULL,
3889 cli_cmd_flag_none,
3890 "= Stop PASN authentication" },
3891 { "ptksa_cache_list", wpa_cli_cmd_ptksa_cache_list, NULL,
3892 cli_cmd_flag_none,
3893 "= Get the PTKSA Cache" },
3894 #endif /* CONFIG_PASN */
3895 { NULL, NULL, NULL, cli_cmd_flag_none, NULL }
3896 };
3897
3898
3899 /*
3900 * Prints command usage, lines are padded with the specified string.
3901 */
print_cmd_help(const struct wpa_cli_cmd * cmd,const char * pad)3902 static void print_cmd_help(const struct wpa_cli_cmd *cmd, const char *pad)
3903 {
3904 char c;
3905 size_t n;
3906
3907 printf("%s%s ", pad, cmd->cmd);
3908 for (n = 0; (c = cmd->usage[n]); n++) {
3909 printf("%c", c);
3910 if (c == '\n')
3911 printf("%s", pad);
3912 }
3913 printf("\n");
3914 }
3915
3916
print_help(const char * cmd)3917 static void print_help(const char *cmd)
3918 {
3919 int n;
3920 printf("commands:\n");
3921 for (n = 0; wpa_cli_commands[n].cmd; n++) {
3922 if (cmd == NULL || str_starts(wpa_cli_commands[n].cmd, cmd))
3923 print_cmd_help(&wpa_cli_commands[n], " ");
3924 }
3925 }
3926
3927
wpa_cli_edit_filter_history_cb(void * ctx,const char * cmd)3928 static int wpa_cli_edit_filter_history_cb(void *ctx, const char *cmd)
3929 {
3930 const char *c, *delim;
3931 int n;
3932 size_t len;
3933
3934 delim = os_strchr(cmd, ' ');
3935 if (delim)
3936 len = delim - cmd;
3937 else
3938 len = os_strlen(cmd);
3939
3940 for (n = 0; (c = wpa_cli_commands[n].cmd); n++) {
3941 if (os_strncasecmp(cmd, c, len) == 0 && len == os_strlen(c))
3942 return (wpa_cli_commands[n].flags &
3943 cli_cmd_flag_sensitive);
3944 }
3945 return 0;
3946 }
3947
3948
wpa_list_cmd_list(void)3949 static char ** wpa_list_cmd_list(void)
3950 {
3951 char **res;
3952 int i, count;
3953 struct cli_txt_entry *e;
3954
3955 count = ARRAY_SIZE(wpa_cli_commands);
3956 count += dl_list_len(&p2p_groups);
3957 count += dl_list_len(&ifnames);
3958 res = os_calloc(count + 1, sizeof(char *));
3959 if (res == NULL)
3960 return NULL;
3961
3962 for (i = 0; wpa_cli_commands[i].cmd; i++) {
3963 res[i] = os_strdup(wpa_cli_commands[i].cmd);
3964 if (res[i] == NULL)
3965 break;
3966 }
3967
3968 dl_list_for_each(e, &p2p_groups, struct cli_txt_entry, list) {
3969 size_t len = 8 + os_strlen(e->txt);
3970 res[i] = os_malloc(len);
3971 if (res[i] == NULL)
3972 break;
3973 os_snprintf(res[i], len, "ifname=%s", e->txt);
3974 i++;
3975 }
3976
3977 dl_list_for_each(e, &ifnames, struct cli_txt_entry, list) {
3978 res[i] = os_strdup(e->txt);
3979 if (res[i] == NULL)
3980 break;
3981 i++;
3982 }
3983
3984 return res;
3985 }
3986
3987
wpa_cli_cmd_completion(const char * cmd,const char * str,int pos)3988 static char ** wpa_cli_cmd_completion(const char *cmd, const char *str,
3989 int pos)
3990 {
3991 int i;
3992
3993 for (i = 0; wpa_cli_commands[i].cmd; i++) {
3994 if (os_strcasecmp(wpa_cli_commands[i].cmd, cmd) == 0) {
3995 if (wpa_cli_commands[i].completion)
3996 return wpa_cli_commands[i].completion(str,
3997 pos);
3998 edit_clear_line();
3999 printf("\r%s\n", wpa_cli_commands[i].usage);
4000 edit_redraw();
4001 break;
4002 }
4003 }
4004
4005 return NULL;
4006 }
4007
4008
wpa_cli_edit_completion_cb(void * ctx,const char * str,int pos)4009 static char ** wpa_cli_edit_completion_cb(void *ctx, const char *str, int pos)
4010 {
4011 char **res;
4012 const char *end;
4013 char *cmd;
4014
4015 if (pos > 7 && os_strncasecmp(str, "IFNAME=", 7) == 0) {
4016 end = os_strchr(str, ' ');
4017 if (end && pos > end - str) {
4018 pos -= end - str + 1;
4019 str = end + 1;
4020 }
4021 }
4022
4023 end = os_strchr(str, ' ');
4024 if (end == NULL || str + pos < end)
4025 return wpa_list_cmd_list();
4026
4027 cmd = os_malloc(pos + 1);
4028 if (cmd == NULL)
4029 return NULL;
4030 os_memcpy(cmd, str, pos);
4031 cmd[end - str] = '\0';
4032 res = wpa_cli_cmd_completion(cmd, str, pos);
4033 os_free(cmd);
4034 return res;
4035 }
4036
4037
wpa_request(struct wpa_ctrl * ctrl,int argc,char * argv[])4038 static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
4039 {
4040 const struct wpa_cli_cmd *cmd, *match = NULL;
4041 int count;
4042 int ret = 0;
4043
4044 if (argc > 1 && os_strncasecmp(argv[0], "IFNAME=", 7) == 0) {
4045 ifname_prefix = argv[0] + 7;
4046 argv = &argv[1];
4047 argc--;
4048 } else
4049 ifname_prefix = NULL;
4050
4051 if (argc == 0)
4052 return -1;
4053
4054 count = 0;
4055 cmd = wpa_cli_commands;
4056 while (cmd->cmd) {
4057 if (os_strncasecmp(cmd->cmd, argv[0], os_strlen(argv[0])) == 0)
4058 {
4059 match = cmd;
4060 if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
4061 /* we have an exact match */
4062 count = 1;
4063 break;
4064 }
4065 count++;
4066 }
4067 cmd++;
4068 }
4069
4070 if (count > 1) {
4071 printf("Ambiguous command '%s'; possible commands:", argv[0]);
4072 cmd = wpa_cli_commands;
4073 while (cmd->cmd) {
4074 if (os_strncasecmp(cmd->cmd, argv[0],
4075 os_strlen(argv[0])) == 0) {
4076 printf(" %s", cmd->cmd);
4077 }
4078 cmd++;
4079 }
4080 printf("\n");
4081 ret = 1;
4082 } else if (count == 0) {
4083 printf("Unknown command '%s'\n", argv[0]);
4084 ret = 1;
4085 } else {
4086 ret = match->handler(ctrl, argc - 1, &argv[1]);
4087 }
4088
4089 return ret;
4090 }
4091
4092
wpa_cli_exec(const char * program,const char * arg1,const char * arg2)4093 static int wpa_cli_exec(const char *program, const char *arg1,
4094 const char *arg2)
4095 {
4096 char *arg;
4097 size_t len;
4098 int res;
4099
4100 /* If no interface is specified, set the global */
4101 if (!arg1)
4102 arg1 = "global";
4103
4104 len = os_strlen(arg1) + os_strlen(arg2) + 2;
4105 arg = os_malloc(len);
4106 if (arg == NULL)
4107 return -1;
4108 os_snprintf(arg, len, "%s %s", arg1, arg2);
4109 res = os_exec(program, arg, 1);
4110 os_free(arg);
4111
4112 return res;
4113 }
4114
4115
wpa_cli_action_process(const char * msg)4116 static void wpa_cli_action_process(const char *msg)
4117 {
4118 const char *pos;
4119 char *copy = NULL, *id, *pos2;
4120 const char *ifname = ctrl_ifname;
4121 char ifname_buf[100];
4122
4123 if (eloop_terminated())
4124 return;
4125
4126 pos = msg;
4127 if (os_strncmp(pos, "IFNAME=", 7) == 0) {
4128 const char *end;
4129 end = os_strchr(pos + 7, ' ');
4130 if (end && (unsigned int) (end - pos) < sizeof(ifname_buf)) {
4131 pos += 7;
4132 os_memcpy(ifname_buf, pos, end - pos);
4133 ifname_buf[end - pos] = '\0';
4134 ifname = ifname_buf;
4135 pos = end + 1;
4136 }
4137 }
4138 if (*pos == '<') {
4139 const char *prev = pos;
4140 /* skip priority */
4141 pos = os_strchr(pos, '>');
4142 if (pos)
4143 pos++;
4144 else
4145 pos = prev;
4146 }
4147
4148 if (str_starts(pos, WPA_EVENT_CONNECTED)) {
4149 int new_id = -1;
4150 os_unsetenv("WPA_ID");
4151 os_unsetenv("WPA_ID_STR");
4152 os_unsetenv("WPA_CTRL_DIR");
4153
4154 pos = os_strstr(pos, "[id=");
4155 if (pos)
4156 copy = os_strdup(pos + 4);
4157
4158 if (copy) {
4159 pos2 = id = copy;
4160 while (*pos2 && *pos2 != ' ')
4161 pos2++;
4162 *pos2++ = '\0';
4163 new_id = atoi(id);
4164 os_setenv("WPA_ID", id, 1);
4165 while (*pos2 && *pos2 != '=')
4166 pos2++;
4167 if (*pos2 == '=')
4168 pos2++;
4169 id = pos2;
4170 while (*pos2 && *pos2 != ']')
4171 pos2++;
4172 *pos2 = '\0';
4173 os_setenv("WPA_ID_STR", id, 1);
4174 os_free(copy);
4175 }
4176
4177 os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1);
4178
4179 if (wpa_cli_connected <= 0 || new_id != wpa_cli_last_id) {
4180 wpa_cli_connected = 1;
4181 wpa_cli_last_id = new_id;
4182 wpa_cli_exec(action_file, ifname, "CONNECTED");
4183 }
4184 } else if (str_starts(pos, WPA_EVENT_DISCONNECTED)) {
4185 if (wpa_cli_connected) {
4186 wpa_cli_connected = 0;
4187 wpa_cli_exec(action_file, ifname, "DISCONNECTED");
4188 }
4189 } else if (str_starts(pos, WPA_EVENT_CHANNEL_SWITCH_STARTED)) {
4190 wpa_cli_exec(action_file, ctrl_ifname, pos);
4191 } else if (str_starts(pos, AP_EVENT_ENABLED)) {
4192 wpa_cli_exec(action_file, ctrl_ifname, pos);
4193 } else if (str_starts(pos, AP_EVENT_DISABLED)) {
4194 wpa_cli_exec(action_file, ctrl_ifname, pos);
4195 } else if (str_starts(pos, MESH_GROUP_STARTED)) {
4196 wpa_cli_exec(action_file, ctrl_ifname, pos);
4197 } else if (str_starts(pos, MESH_GROUP_REMOVED)) {
4198 wpa_cli_exec(action_file, ctrl_ifname, pos);
4199 } else if (str_starts(pos, MESH_PEER_CONNECTED)) {
4200 wpa_cli_exec(action_file, ctrl_ifname, pos);
4201 } else if (str_starts(pos, MESH_PEER_DISCONNECTED)) {
4202 wpa_cli_exec(action_file, ctrl_ifname, pos);
4203 } else if (str_starts(pos, P2P_EVENT_GROUP_STARTED)) {
4204 wpa_cli_exec(action_file, ifname, pos);
4205 } else if (str_starts(pos, P2P_EVENT_GROUP_REMOVED)) {
4206 wpa_cli_exec(action_file, ifname, pos);
4207 } else if (str_starts(pos, P2P_EVENT_CROSS_CONNECT_ENABLE)) {
4208 wpa_cli_exec(action_file, ifname, pos);
4209 } else if (str_starts(pos, P2P_EVENT_CROSS_CONNECT_DISABLE)) {
4210 wpa_cli_exec(action_file, ifname, pos);
4211 } else if (str_starts(pos, P2P_EVENT_GO_NEG_FAILURE)) {
4212 wpa_cli_exec(action_file, ifname, pos);
4213 } else if (str_starts(pos, WPS_EVENT_SUCCESS)) {
4214 wpa_cli_exec(action_file, ifname, pos);
4215 } else if (str_starts(pos, WPS_EVENT_ACTIVE)) {
4216 wpa_cli_exec(action_file, ifname, pos);
4217 } else if (str_starts(pos, WPS_EVENT_OVERLAP)) {
4218 wpa_cli_exec(action_file, ifname, pos);
4219 } else if (str_starts(pos, WPS_EVENT_PIN_ACTIVE)) {
4220 wpa_cli_exec(action_file, ifname, pos);
4221 } else if (str_starts(pos, WPS_EVENT_CANCEL)) {
4222 wpa_cli_exec(action_file, ifname, pos);
4223 } else if (str_starts(pos, WPS_EVENT_TIMEOUT)) {
4224 wpa_cli_exec(action_file, ifname, pos);
4225 } else if (str_starts(pos, WPS_EVENT_FAIL)) {
4226 wpa_cli_exec(action_file, ifname, pos);
4227 } else if (str_starts(pos, AP_STA_CONNECTED)) {
4228 wpa_cli_exec(action_file, ifname, pos);
4229 } else if (str_starts(pos, AP_STA_DISCONNECTED)) {
4230 wpa_cli_exec(action_file, ifname, pos);
4231 } else if (str_starts(pos, ESS_DISASSOC_IMMINENT)) {
4232 wpa_cli_exec(action_file, ifname, pos);
4233 } else if (str_starts(pos, HS20_SUBSCRIPTION_REMEDIATION)) {
4234 wpa_cli_exec(action_file, ifname, pos);
4235 } else if (str_starts(pos, HS20_DEAUTH_IMMINENT_NOTICE)) {
4236 wpa_cli_exec(action_file, ifname, pos);
4237 } else if (str_starts(pos, HS20_T_C_ACCEPTANCE)) {
4238 wpa_cli_exec(action_file, ifname, pos);
4239 } else if (str_starts(pos, DPP_EVENT_CONF_RECEIVED)) {
4240 wpa_cli_exec(action_file, ifname, pos);
4241 } else if (str_starts(pos, DPP_EVENT_CONFOBJ_AKM)) {
4242 wpa_cli_exec(action_file, ifname, pos);
4243 } else if (str_starts(pos, DPP_EVENT_CONFOBJ_SSID)) {
4244 wpa_cli_exec(action_file, ifname, pos);
4245 } else if (str_starts(pos, DPP_EVENT_CONNECTOR)) {
4246 wpa_cli_exec(action_file, ifname, pos);
4247 } else if (str_starts(pos, DPP_EVENT_CONFOBJ_PASS)) {
4248 wpa_cli_exec(action_file, ifname, pos);
4249 } else if (str_starts(pos, DPP_EVENT_CONFOBJ_PSK)) {
4250 wpa_cli_exec(action_file, ifname, pos);
4251 } else if (str_starts(pos, DPP_EVENT_C_SIGN_KEY)) {
4252 wpa_cli_exec(action_file, ifname, pos);
4253 } else if (str_starts(pos, DPP_EVENT_NET_ACCESS_KEY)) {
4254 wpa_cli_exec(action_file, ifname, pos);
4255 } else if (str_starts(pos, WPA_EVENT_TERMINATING)) {
4256 printf("wpa_supplicant is terminating - stop monitoring\n");
4257 if (!reconnect)
4258 wpa_cli_quit = 1;
4259 }
4260 }
4261
4262
4263 #ifndef CONFIG_ANSI_C_EXTRA
wpa_cli_action_cb(char * msg,size_t len)4264 static void wpa_cli_action_cb(char *msg, size_t len)
4265 {
4266 wpa_cli_action_process(msg);
4267 }
4268 #endif /* CONFIG_ANSI_C_EXTRA */
4269
4270
wpa_cli_open_global_ctrl(void)4271 static int wpa_cli_open_global_ctrl(void)
4272 {
4273 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
4274 ctrl_conn = wpa_ctrl_open(NULL);
4275 #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4276 ctrl_conn = wpa_ctrl_open(global);
4277 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4278 if (!ctrl_conn) {
4279 fprintf(stderr,
4280 "Failed to connect to wpa_supplicant global interface: %s error: %s\n",
4281 global, strerror(errno));
4282 return -1;
4283 }
4284
4285 if (interactive) {
4286 update_ifnames(ctrl_conn);
4287 mon_conn = wpa_ctrl_open(global);
4288 if (mon_conn) {
4289 if (wpa_ctrl_attach(mon_conn) == 0) {
4290 wpa_cli_attached = 1;
4291 eloop_register_read_sock(
4292 wpa_ctrl_get_fd(mon_conn),
4293 wpa_cli_mon_receive,
4294 NULL, NULL);
4295 } else {
4296 printf("Failed to open monitor connection through global control interface\n");
4297 }
4298 }
4299 update_stations(ctrl_conn);
4300 }
4301
4302 return 0;
4303 }
4304
4305
wpa_cli_reconnect(void)4306 static void wpa_cli_reconnect(void)
4307 {
4308 wpa_cli_close_connection();
4309 if ((global && wpa_cli_open_global_ctrl() < 0) ||
4310 (!global && wpa_cli_open_connection(ctrl_ifname, 1) < 0))
4311 return;
4312
4313 if (interactive) {
4314 edit_clear_line();
4315 printf("\rConnection to wpa_supplicant re-established\n");
4316 edit_redraw();
4317 update_stations(ctrl_conn);
4318 }
4319 }
4320
4321
cli_event(const char * str)4322 static void cli_event(const char *str)
4323 {
4324 const char *start, *s;
4325
4326 start = os_strchr(str, '>');
4327 if (start == NULL)
4328 return;
4329
4330 start++;
4331
4332 if (str_starts(start, WPA_EVENT_BSS_ADDED)) {
4333 s = os_strchr(start, ' ');
4334 if (s == NULL)
4335 return;
4336 s = os_strchr(s + 1, ' ');
4337 if (s == NULL)
4338 return;
4339 cli_txt_list_add(&bsses, s + 1);
4340 return;
4341 }
4342
4343 if (str_starts(start, WPA_EVENT_BSS_REMOVED)) {
4344 s = os_strchr(start, ' ');
4345 if (s == NULL)
4346 return;
4347 s = os_strchr(s + 1, ' ');
4348 if (s == NULL)
4349 return;
4350 cli_txt_list_del_addr(&bsses, s + 1);
4351 return;
4352 }
4353
4354 #ifdef CONFIG_P2P
4355 if (str_starts(start, P2P_EVENT_DEVICE_FOUND)) {
4356 s = os_strstr(start, " p2p_dev_addr=");
4357 if (s == NULL)
4358 return;
4359 cli_txt_list_add_addr(&p2p_peers, s + 14);
4360 return;
4361 }
4362
4363 if (str_starts(start, P2P_EVENT_DEVICE_LOST)) {
4364 s = os_strstr(start, " p2p_dev_addr=");
4365 if (s == NULL)
4366 return;
4367 cli_txt_list_del_addr(&p2p_peers, s + 14);
4368 return;
4369 }
4370
4371 if (str_starts(start, P2P_EVENT_GROUP_STARTED)) {
4372 s = os_strchr(start, ' ');
4373 if (s == NULL)
4374 return;
4375 cli_txt_list_add_word(&p2p_groups, s + 1, ' ');
4376 return;
4377 }
4378
4379 if (str_starts(start, P2P_EVENT_GROUP_REMOVED)) {
4380 s = os_strchr(start, ' ');
4381 if (s == NULL)
4382 return;
4383 cli_txt_list_del_word(&p2p_groups, s + 1, ' ');
4384 return;
4385 }
4386 #endif /* CONFIG_P2P */
4387 }
4388
4389
check_terminating(const char * msg)4390 static int check_terminating(const char *msg)
4391 {
4392 const char *pos = msg;
4393
4394 if (*pos == '<') {
4395 /* skip priority */
4396 pos = os_strchr(pos, '>');
4397 if (pos)
4398 pos++;
4399 else
4400 pos = msg;
4401 }
4402
4403 if (str_starts(pos, WPA_EVENT_TERMINATING) && ctrl_conn) {
4404 edit_clear_line();
4405 printf("\rConnection to wpa_supplicant lost - trying to "
4406 "reconnect\n");
4407 edit_redraw();
4408 wpa_cli_attached = 0;
4409 wpa_cli_close_connection();
4410 return 1;
4411 }
4412
4413 return 0;
4414 }
4415
4416
wpa_cli_recv_pending(struct wpa_ctrl * ctrl,int action_monitor)4417 static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor)
4418 {
4419 if (ctrl_conn == NULL) {
4420 wpa_cli_reconnect();
4421 return;
4422 }
4423 while (wpa_ctrl_pending(ctrl) > 0) {
4424 char buf[4096];
4425 size_t len = sizeof(buf) - 1;
4426 if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
4427 buf[len] = '\0';
4428 if (action_monitor)
4429 wpa_cli_action_process(buf);
4430 else {
4431 cli_event(buf);
4432 if (wpa_cli_show_event(buf)) {
4433 edit_clear_line();
4434 printf("\r%s\n", buf);
4435 edit_redraw();
4436 }
4437
4438 if (interactive && check_terminating(buf) > 0)
4439 return;
4440 }
4441 } else {
4442 printf("Could not read pending message.\n");
4443 break;
4444 }
4445 }
4446
4447 if (wpa_ctrl_pending(ctrl) < 0) {
4448 printf("Connection to wpa_supplicant lost - trying to "
4449 "reconnect\n");
4450 if (reconnect) {
4451 eloop_terminate();
4452 return;
4453 }
4454 wpa_cli_reconnect();
4455 }
4456 }
4457
4458
wpa_cli_ping(void * eloop_ctx,void * timeout_ctx)4459 static void wpa_cli_ping(void *eloop_ctx, void *timeout_ctx)
4460 {
4461 if (ctrl_conn) {
4462 int res;
4463 char *prefix = ifname_prefix;
4464
4465 ifname_prefix = NULL;
4466 res = _wpa_ctrl_command(ctrl_conn, "PING", 0);
4467 ifname_prefix = prefix;
4468 if (res) {
4469 printf("Connection to wpa_supplicant lost - trying to "
4470 "reconnect\n");
4471 wpa_cli_close_connection();
4472 }
4473 }
4474 if (!ctrl_conn)
4475 wpa_cli_reconnect();
4476 eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
4477 }
4478
4479
wpa_cli_mon_receive(int sock,void * eloop_ctx,void * sock_ctx)4480 static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx)
4481 {
4482 wpa_cli_recv_pending(mon_conn, 0);
4483 }
4484
4485
wpa_cli_edit_cmd_cb(void * ctx,char * cmd)4486 static void wpa_cli_edit_cmd_cb(void *ctx, char *cmd)
4487 {
4488 char *argv[max_args];
4489 int argc;
4490 argc = tokenize_cmd(cmd, argv);
4491 if (argc)
4492 wpa_request(ctrl_conn, argc, argv);
4493 }
4494
4495
wpa_cli_edit_eof_cb(void * ctx)4496 static void wpa_cli_edit_eof_cb(void *ctx)
4497 {
4498 eloop_terminate();
4499 }
4500
4501
4502 static int warning_displayed = 0;
4503 static char *hfile = NULL;
4504 static int edit_started = 0;
4505
start_edit(void)4506 static void start_edit(void)
4507 {
4508 char *home;
4509 char *ps = NULL;
4510
4511 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4512 ps = wpa_ctrl_get_remote_ifname(ctrl_conn);
4513 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4514
4515 #ifdef CONFIG_WPA_CLI_HISTORY_DIR
4516 home = CONFIG_WPA_CLI_HISTORY_DIR;
4517 #else /* CONFIG_WPA_CLI_HISTORY_DIR */
4518 home = getenv("HOME");
4519 #endif /* CONFIG_WPA_CLI_HISTORY_DIR */
4520 if (home) {
4521 const char *fname = ".wpa_cli_history";
4522 int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
4523 hfile = os_malloc(hfile_len);
4524 if (hfile)
4525 os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
4526 }
4527
4528 if (edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
4529 wpa_cli_edit_completion_cb, NULL, hfile, ps) < 0) {
4530 eloop_terminate();
4531 return;
4532 }
4533
4534 edit_started = 1;
4535 eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
4536 }
4537
4538
update_bssid_list(struct wpa_ctrl * ctrl)4539 static void update_bssid_list(struct wpa_ctrl *ctrl)
4540 {
4541 char buf[4096];
4542 size_t len = sizeof(buf);
4543 int ret;
4544 const char *cmd = "BSS RANGE=ALL MASK=0x2";
4545 char *pos, *end;
4546
4547 if (ctrl == NULL)
4548 return;
4549 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
4550 if (ret < 0)
4551 return;
4552 buf[len] = '\0';
4553
4554 pos = buf;
4555 while (pos) {
4556 pos = os_strstr(pos, "bssid=");
4557 if (pos == NULL)
4558 break;
4559 pos += 6;
4560 end = os_strchr(pos, '\n');
4561 if (end == NULL)
4562 break;
4563 *end = '\0';
4564 cli_txt_list_add(&bsses, pos);
4565 pos = end + 1;
4566 }
4567 }
4568
4569
update_ifnames(struct wpa_ctrl * ctrl)4570 static void update_ifnames(struct wpa_ctrl *ctrl)
4571 {
4572 char buf[4096];
4573 size_t len = sizeof(buf);
4574 int ret;
4575 const char *cmd = "INTERFACES";
4576 char *pos, *end;
4577 char txt[200];
4578
4579 cli_txt_list_flush(&ifnames);
4580
4581 if (ctrl == NULL)
4582 return;
4583 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
4584 if (ret < 0)
4585 return;
4586 buf[len] = '\0';
4587
4588 pos = buf;
4589 while (pos) {
4590 end = os_strchr(pos, '\n');
4591 if (end == NULL)
4592 break;
4593 *end = '\0';
4594 ret = os_snprintf(txt, sizeof(txt), "ifname=%s", pos);
4595 if (!os_snprintf_error(sizeof(txt), ret))
4596 cli_txt_list_add(&ifnames, txt);
4597 pos = end + 1;
4598 }
4599 }
4600
4601
update_creds(struct wpa_ctrl * ctrl)4602 static void update_creds(struct wpa_ctrl *ctrl)
4603 {
4604 char buf[4096];
4605 size_t len = sizeof(buf);
4606 int ret;
4607 const char *cmd = "LIST_CREDS";
4608 char *pos, *end;
4609 int header = 1;
4610
4611 cli_txt_list_flush(&creds);
4612
4613 if (ctrl == NULL)
4614 return;
4615 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
4616 if (ret < 0)
4617 return;
4618 buf[len] = '\0';
4619
4620 pos = buf;
4621 while (pos) {
4622 end = os_strchr(pos, '\n');
4623 if (end == NULL)
4624 break;
4625 *end = '\0';
4626 if (!header)
4627 cli_txt_list_add_word(&creds, pos, '\t');
4628 header = 0;
4629 pos = end + 1;
4630 }
4631 }
4632
4633
update_networks(struct wpa_ctrl * ctrl)4634 static void update_networks(struct wpa_ctrl *ctrl)
4635 {
4636 char buf[4096];
4637 size_t len = sizeof(buf);
4638 int ret;
4639 const char *cmd = "LIST_NETWORKS";
4640 char *pos, *end;
4641 int header = 1;
4642
4643 cli_txt_list_flush(&networks);
4644
4645 if (ctrl == NULL)
4646 return;
4647 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
4648 if (ret < 0)
4649 return;
4650 buf[len] = '\0';
4651
4652 pos = buf;
4653 while (pos) {
4654 end = os_strchr(pos, '\n');
4655 if (end == NULL)
4656 break;
4657 *end = '\0';
4658 if (!header)
4659 cli_txt_list_add_word(&networks, pos, '\t');
4660 header = 0;
4661 pos = end + 1;
4662 }
4663 }
4664
4665
update_stations(struct wpa_ctrl * ctrl)4666 static void update_stations(struct wpa_ctrl *ctrl)
4667 {
4668 #ifdef CONFIG_AP
4669 char addr[32], cmd[64];
4670
4671 if (!ctrl || !interactive)
4672 return;
4673
4674 cli_txt_list_flush(&stations);
4675
4676 if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
4677 return;
4678 do {
4679 if (os_strcmp(addr, "") != 0)
4680 cli_txt_list_add(&stations, addr);
4681 os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
4682 } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
4683 #endif /* CONFIG_AP */
4684 }
4685
4686
try_connection(void * eloop_ctx,void * timeout_ctx)4687 static void try_connection(void *eloop_ctx, void *timeout_ctx)
4688 {
4689 if (ctrl_conn)
4690 goto done;
4691
4692 if (ctrl_ifname == NULL)
4693 ctrl_ifname = wpa_cli_get_default_ifname();
4694
4695 if (wpa_cli_open_connection(ctrl_ifname, 1)) {
4696 if (!warning_displayed) {
4697 printf("Could not connect to wpa_supplicant: "
4698 "%s - re-trying\n",
4699 ctrl_ifname ? ctrl_ifname : "(nil)");
4700 warning_displayed = 1;
4701 }
4702 eloop_register_timeout(1, 0, try_connection, NULL, NULL);
4703 return;
4704 }
4705
4706 update_bssid_list(ctrl_conn);
4707 update_creds(ctrl_conn);
4708 update_networks(ctrl_conn);
4709 update_stations(ctrl_conn);
4710
4711 if (warning_displayed)
4712 printf("Connection established.\n");
4713
4714 done:
4715 start_edit();
4716 }
4717
4718
wpa_cli_interactive(void)4719 static void wpa_cli_interactive(void)
4720 {
4721 printf("\nInteractive mode\n\n");
4722
4723 eloop_register_timeout(0, 0, try_connection, NULL, NULL);
4724 eloop_run();
4725 eloop_cancel_timeout(try_connection, NULL, NULL);
4726
4727 cli_txt_list_flush(&p2p_peers);
4728 cli_txt_list_flush(&p2p_groups);
4729 cli_txt_list_flush(&bsses);
4730 cli_txt_list_flush(&ifnames);
4731 cli_txt_list_flush(&creds);
4732 cli_txt_list_flush(&networks);
4733 if (edit_started)
4734 edit_deinit(hfile, wpa_cli_edit_filter_history_cb);
4735 os_free(hfile);
4736 eloop_cancel_timeout(wpa_cli_ping, NULL, NULL);
4737 wpa_cli_close_connection();
4738 }
4739
4740
wpa_cli_action_ping(void * eloop_ctx,void * timeout_ctx)4741 static void wpa_cli_action_ping(void *eloop_ctx, void *timeout_ctx)
4742 {
4743 struct wpa_ctrl *ctrl = eloop_ctx;
4744 char buf[256];
4745 size_t len;
4746
4747 /* verify that connection is still working */
4748 len = sizeof(buf) - 1;
4749 if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
4750 wpa_cli_action_cb) < 0 ||
4751 len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
4752 printf("wpa_supplicant did not reply to PING command - exiting\n");
4753 eloop_terminate();
4754 return;
4755 }
4756 eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
4757 ctrl, NULL);
4758 }
4759
4760
wpa_cli_action_receive(int sock,void * eloop_ctx,void * sock_ctx)4761 static void wpa_cli_action_receive(int sock, void *eloop_ctx, void *sock_ctx)
4762 {
4763 struct wpa_ctrl *ctrl = eloop_ctx;
4764
4765 wpa_cli_recv_pending(ctrl, 1);
4766 }
4767
4768
wpa_cli_action(struct wpa_ctrl * ctrl)4769 static void wpa_cli_action(struct wpa_ctrl *ctrl)
4770 {
4771 #ifdef CONFIG_ANSI_C_EXTRA
4772 /* TODO: ANSI C version(?) */
4773 printf("Action processing not supported in ANSI C build.\n");
4774 #else /* CONFIG_ANSI_C_EXTRA */
4775 int fd;
4776
4777 fd = wpa_ctrl_get_fd(ctrl);
4778 eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
4779 ctrl, NULL);
4780 eloop_register_read_sock(fd, wpa_cli_action_receive, ctrl, NULL);
4781 eloop_run();
4782 eloop_cancel_timeout(wpa_cli_action_ping, ctrl, NULL);
4783 eloop_unregister_read_sock(fd);
4784 #endif /* CONFIG_ANSI_C_EXTRA */
4785 }
4786
4787
wpa_cli_cleanup(void)4788 static void wpa_cli_cleanup(void)
4789 {
4790 wpa_cli_close_connection();
4791 if (pid_file)
4792 os_daemonize_terminate(pid_file);
4793
4794 os_program_deinit();
4795 }
4796
4797
wpa_cli_terminate(int sig,void * ctx)4798 static void wpa_cli_terminate(int sig, void *ctx)
4799 {
4800 eloop_terminate();
4801 if (reconnect)
4802 wpa_cli_quit = 1;
4803 }
4804
4805
wpa_cli_get_default_ifname(void)4806 static char * wpa_cli_get_default_ifname(void)
4807 {
4808 char *ifname = NULL;
4809
4810 #ifdef ANDROID
4811 char ifprop[PROPERTY_VALUE_MAX];
4812 if (property_get("wifi.interface", ifprop, NULL) != 0) {
4813 ifname = os_strdup(ifprop);
4814 printf("Using interface '%s'\n", ifname ? ifname : "N/A");
4815 }
4816 #else /* ANDROID */
4817 #ifdef CONFIG_CTRL_IFACE_UNIX
4818 struct dirent *dent;
4819 DIR *dir = opendir(ctrl_iface_dir);
4820 if (!dir) {
4821 return NULL;
4822 }
4823 while ((dent = readdir(dir))) {
4824 #ifdef _DIRENT_HAVE_D_TYPE
4825 /*
4826 * Skip the file if it is not a socket. Also accept
4827 * DT_UNKNOWN (0) in case the C library or underlying
4828 * file system does not support d_type.
4829 */
4830 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
4831 continue;
4832 #endif /* _DIRENT_HAVE_D_TYPE */
4833 /* Skip current/previous directory and special P2P Device
4834 * interfaces. */
4835 if (os_strcmp(dent->d_name, ".") == 0 ||
4836 os_strcmp(dent->d_name, "..") == 0 ||
4837 os_strncmp(dent->d_name, "p2p-dev-", 8) == 0)
4838 continue;
4839 printf("Selected interface '%s'\n", dent->d_name);
4840 ifname = os_strdup(dent->d_name);
4841 break;
4842 }
4843 closedir(dir);
4844 #endif /* CONFIG_CTRL_IFACE_UNIX */
4845
4846 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
4847 char buf[4096], *pos;
4848 size_t len;
4849 struct wpa_ctrl *ctrl;
4850 int ret;
4851
4852 ctrl = wpa_ctrl_open(NULL);
4853 if (ctrl == NULL)
4854 return NULL;
4855
4856 len = sizeof(buf) - 1;
4857 ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf, &len, NULL);
4858 if (ret >= 0) {
4859 buf[len] = '\0';
4860 pos = os_strchr(buf, '\n');
4861 if (pos)
4862 *pos = '\0';
4863 ifname = os_strdup(buf);
4864 }
4865 wpa_ctrl_close(ctrl);
4866 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4867 #endif /* ANDROID */
4868
4869 return ifname;
4870 }
4871
4872
main(int argc,char * argv[])4873 int main(int argc, char *argv[])
4874 {
4875 int c;
4876 int daemonize = 0;
4877 int ret = 0;
4878
4879 if (os_program_init())
4880 return -1;
4881
4882 for (;;) {
4883 c = getopt(argc, argv, "a:Bg:G:hi:p:P:rs:v");
4884 if (c < 0)
4885 break;
4886 switch (c) {
4887 case 'a':
4888 action_file = optarg;
4889 break;
4890 case 'B':
4891 daemonize = 1;
4892 break;
4893 case 'g':
4894 global = optarg;
4895 break;
4896 case 'G':
4897 ping_interval = atoi(optarg);
4898 break;
4899 case 'h':
4900 usage();
4901 return 0;
4902 case 'v':
4903 printf("%s\n", wpa_cli_version);
4904 return 0;
4905 case 'i':
4906 os_free(ctrl_ifname);
4907 ctrl_ifname = os_strdup(optarg);
4908 break;
4909 case 'p':
4910 ctrl_iface_dir = optarg;
4911 break;
4912 case 'P':
4913 pid_file = optarg;
4914 break;
4915 case 'r':
4916 reconnect = 1;
4917 break;
4918 case 's':
4919 client_socket_dir = optarg;
4920 break;
4921 default:
4922 usage();
4923 return -1;
4924 }
4925 }
4926
4927 interactive = (argc == optind) && (action_file == NULL);
4928
4929 if (interactive)
4930 printf("%s\n\n%s\n\n", wpa_cli_version, cli_license);
4931
4932 if (eloop_init())
4933 return -1;
4934
4935 if (global && wpa_cli_open_global_ctrl() < 0)
4936 return -1;
4937
4938 eloop_register_signal_terminate(wpa_cli_terminate, NULL);
4939
4940 if (ctrl_ifname == NULL)
4941 ctrl_ifname = wpa_cli_get_default_ifname();
4942
4943 if (reconnect && action_file && ctrl_ifname) {
4944 while (!wpa_cli_quit) {
4945 if (ctrl_conn)
4946 wpa_cli_action(ctrl_conn);
4947 else
4948 os_sleep(1, 0);
4949 wpa_cli_close_connection();
4950 wpa_cli_open_connection(ctrl_ifname, 0);
4951 if (ctrl_conn) {
4952 if (wpa_ctrl_attach(ctrl_conn) != 0)
4953 wpa_cli_close_connection();
4954 else
4955 wpa_cli_attached = 1;
4956 }
4957 }
4958 } else if (interactive) {
4959 wpa_cli_interactive();
4960 } else {
4961 if (!global &&
4962 wpa_cli_open_connection(ctrl_ifname, 0) < 0) {
4963 fprintf(stderr, "Failed to connect to non-global "
4964 "ctrl_ifname: %s error: %s\n",
4965 ctrl_ifname ? ctrl_ifname : "(nil)",
4966 strerror(errno));
4967 return -1;
4968 }
4969
4970 if (action_file) {
4971 if (wpa_ctrl_attach(ctrl_conn) == 0) {
4972 wpa_cli_attached = 1;
4973 } else {
4974 printf("Warning: Failed to attach to "
4975 "wpa_supplicant.\n");
4976 return -1;
4977 }
4978 }
4979
4980 if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
4981 return -1;
4982
4983 if (action_file)
4984 wpa_cli_action(ctrl_conn);
4985 else
4986 ret = wpa_request(ctrl_conn, argc - optind,
4987 &argv[optind]);
4988 }
4989
4990 os_free(ctrl_ifname);
4991 eloop_destroy();
4992 wpa_cli_cleanup();
4993
4994 return ret;
4995 }
4996
4997 #else /* CONFIG_CTRL_IFACE */
main(int argc,char * argv[])4998 int main(int argc, char *argv[])
4999 {
5000 printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
5001 return -1;
5002 }
5003 #endif /* CONFIG_CTRL_IFACE */
5004