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