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