2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
10 #ifdef CONFIG_TESTING_OPTIONS
11 #include <net/ethernet.h>
12 #include <netinet/ip.h>
13 #endif /* CONFIG_TESTING_OPTIONS */
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "utils/uuid.h"
18 #include "utils/module_tests.h"
19 #include "common/version.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/ieee802_11_common.h"
22 #include "common/wpa_ctrl.h"
24 #include "common/dpp.h"
25 #endif /* CONFIG_DPP */
26 #include "crypto/tls.h"
27 #include "ap/hostapd.h"
28 #include "eap_peer/eap.h"
29 #include "eapol_supp/eapol_supp_sm.h"
30 #include "rsn_supp/wpa.h"
31 #include "rsn_supp/preauth.h"
32 #include "rsn_supp/pmksa_cache.h"
33 #include "l2_packet/l2_packet.h"
36 #include "fst/fst_ctrl_iface.h"
38 #include "wpa_supplicant_i.h"
40 #include "wps_supplicant.h"
43 #include "p2p_supplicant.h"
45 #include "hs20_supplicant.h"
46 #include "wifi_display.h"
50 #include "ctrl_iface.h"
51 #include "interworking.h"
52 #include "blacklist.h"
55 #include "offchannel.h"
56 #include "drivers/driver.h"
58 #include "dpp_supplicant.h"
61 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
63 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
66 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
70 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
73 u8 addr[ETH_ALEN], *filter = NULL, *n;
80 if (hwaddr_aton(pos, addr)) {
84 n = os_realloc_array(filter, count + 1, ETH_ALEN);
90 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
93 pos = os_strchr(pos, ' ');
98 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
99 os_free(wpa_s->bssid_filter);
100 wpa_s->bssid_filter = filter;
101 wpa_s->bssid_filter_count = count;
107 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
110 u8 addr[ETH_ALEN], *bssid = NULL, *n;
111 struct wpa_ssid_value *ssid = NULL, *ns;
112 size_t count = 0, ssid_count = 0;
116 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
117 * SSID_SPEC ::= ssid <SSID_HEX>
118 * BSSID_SPEC ::= bssid <BSSID_HEX>
125 if (os_strncmp(pos, "bssid ", 6) == 0) {
128 res = hwaddr_aton2(pos, addr);
132 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
133 "BSSID value '%s'", pos);
137 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
144 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
146 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
152 if (*end == '\0' || *end == ' ')
157 ns = os_realloc_array(ssid, ssid_count + 1,
158 sizeof(struct wpa_ssid_value));
166 if ((end - pos) & 0x01 ||
167 end - pos > 2 * SSID_MAX_LEN ||
168 hexstr2bin(pos, ssid[ssid_count].ssid,
169 (end - pos) / 2) < 0) {
172 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
173 "SSID value '%s'", pos);
176 ssid[ssid_count].ssid_len = (end - pos) / 2;
177 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
178 ssid[ssid_count].ssid,
179 ssid[ssid_count].ssid_len);
183 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
190 pos = os_strchr(pos, ' ');
195 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
196 os_free(wpa_s->disallow_aps_bssid);
197 wpa_s->disallow_aps_bssid = bssid;
198 wpa_s->disallow_aps_bssid_count = count;
200 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
201 os_free(wpa_s->disallow_aps_ssid);
202 wpa_s->disallow_aps_ssid = ssid;
203 wpa_s->disallow_aps_ssid_count = ssid_count;
205 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
208 c = wpa_s->current_ssid;
209 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
212 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
213 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
216 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
217 "because current AP was marked disallowed");
220 wpa_s->sme.prev_bssid_set = 0;
221 #endif /* CONFIG_SME */
222 wpa_s->reassociate = 1;
223 wpa_s->own_disconnect_req = 1;
224 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
225 wpa_supplicant_req_scan(wpa_s, 0, 0);
231 #ifndef CONFIG_NO_CONFIG_BLOBS
232 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
235 struct wpa_config_blob *blob;
238 pos = os_strchr(pos, ' ');
242 len = os_strlen(pos);
246 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
247 blob = os_zalloc(sizeof(*blob));
250 blob->name = os_strdup(name);
251 blob->data = os_malloc(len / 2);
252 if (blob->name == NULL || blob->data == NULL) {
253 wpa_config_free_blob(blob);
257 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
258 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
259 wpa_config_free_blob(blob);
264 wpa_config_set_blob(wpa_s->conf, blob);
268 #endif /* CONFIG_NO_CONFIG_BLOBS */
271 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
279 params = os_strchr(cmd, ' ');
280 os_free(wpa_s->manual_sched_scan_freqs);
283 pos = os_strstr(params, "freq=");
285 freqs = freq_range_to_channel_list(wpa_s,
288 wpa_s->manual_sched_scan_freqs = freqs;
289 ret = wpas_start_pno(wpa_s);
291 ret = wpas_stop_pno(wpa_s);
297 static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
299 union wpa_event_data event;
301 if (os_strcmp(band, "AUTO") == 0)
302 wpa_s->setband = WPA_SETBAND_AUTO;
303 else if (os_strcmp(band, "5G") == 0)
304 wpa_s->setband = WPA_SETBAND_5G;
305 else if (os_strcmp(band, "2G") == 0)
306 wpa_s->setband = WPA_SETBAND_2G;
310 if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
311 os_memset(&event, 0, sizeof(event));
312 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
313 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
314 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
321 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
326 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
327 wpabuf_free(wpa_s->lci);
332 lci = wpabuf_parse_bin(cmd);
336 if (os_get_reltime(&wpa_s->lci_time)) {
341 wpabuf_free(wpa_s->lci);
349 wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
353 if (os_strcmp(cmd, "disable") == 0) {
354 wpa_s->srp.relative_rssi_set = 0;
358 relative_rssi = atoi(cmd);
359 if (relative_rssi < 0 || relative_rssi > 100)
361 wpa_s->srp.relative_rssi = relative_rssi;
362 wpa_s->srp.relative_rssi_set = 1;
367 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
373 /* <band>:adjust_value */
374 pos = os_strchr(cmd, ':');
378 adjust_rssi = atoi(pos);
379 if (adjust_rssi < -100 || adjust_rssi > 100)
382 if (os_strncmp(cmd, "2G", 2) == 0)
383 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
384 else if (os_strncmp(cmd, "5G", 2) == 0)
385 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
389 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
395 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
398 struct wpabuf *ric_ies;
400 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
401 wpabuf_free(wpa_s->ric_ies);
402 wpa_s->ric_ies = NULL;
406 ric_ies = wpabuf_parse_bin(cmd);
410 wpabuf_free(wpa_s->ric_ies);
411 wpa_s->ric_ies = ric_ies;
417 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
423 value = os_strchr(cmd, ' ');
428 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
429 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
430 eapol_sm_configure(wpa_s->eapol,
431 atoi(value), -1, -1, -1);
432 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
433 eapol_sm_configure(wpa_s->eapol,
434 -1, atoi(value), -1, -1);
435 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
436 eapol_sm_configure(wpa_s->eapol,
437 -1, -1, atoi(value), -1);
438 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
439 eapol_sm_configure(wpa_s->eapol,
440 -1, -1, -1, atoi(value));
441 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
442 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
447 wpa_config_process_global(wpa_s->conf, cmd, -1);
449 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
451 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
456 wpa_config_process_global(wpa_s->conf, cmd, -1);
458 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
459 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
464 wpa_config_process_global(wpa_s->conf, cmd, -1);
466 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
467 wpa_s->wps_fragment_size = atoi(value);
468 #ifdef CONFIG_WPS_TESTING
469 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
471 val = strtol(value, NULL, 0);
472 if (val < 0 || val > 0xff) {
474 wpa_printf(MSG_DEBUG, "WPS: Invalid "
475 "wps_version_number %ld", val);
477 wps_version_number = val;
478 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
480 (wps_version_number & 0xf0) >> 4,
481 wps_version_number & 0x0f);
483 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
484 wps_testing_dummy_cred = atoi(value);
485 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
486 wps_testing_dummy_cred);
487 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
488 wps_corrupt_pkhash = atoi(value);
489 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
491 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
492 if (value[0] == '\0') {
493 wps_force_auth_types_in_use = 0;
495 wps_force_auth_types = strtol(value, NULL, 0);
496 wps_force_auth_types_in_use = 1;
498 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
499 if (value[0] == '\0') {
500 wps_force_encr_types_in_use = 0;
502 wps_force_encr_types = strtol(value, NULL, 0);
503 wps_force_encr_types_in_use = 1;
505 #endif /* CONFIG_WPS_TESTING */
506 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
507 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
510 #ifdef CONFIG_TDLS_TESTING
511 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
512 tdls_testing = strtol(value, NULL, 0);
513 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
514 #endif /* CONFIG_TDLS_TESTING */
515 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
516 int disabled = atoi(value);
517 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
519 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
521 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
523 wpa_tdls_enable(wpa_s->wpa, !disabled);
524 #endif /* CONFIG_TDLS */
525 } else if (os_strcasecmp(cmd, "pno") == 0) {
526 ret = wpas_ctrl_pno(wpa_s, value);
527 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
528 int disabled = atoi(value);
529 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
532 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
533 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
534 if (os_strcmp(value, "disable") == 0)
535 wpa_s->set_sta_uapsd = 0;
539 /* format: BE,BK,VI,VO;max SP Length */
541 pos = os_strchr(value, ',');
546 pos = os_strchr(pos, ',');
551 pos = os_strchr(pos, ',');
556 /* ignore max SP Length for now */
558 wpa_s->set_sta_uapsd = 1;
559 wpa_s->sta_uapsd = 0;
561 wpa_s->sta_uapsd |= BIT(0);
563 wpa_s->sta_uapsd |= BIT(1);
565 wpa_s->sta_uapsd |= BIT(2);
567 wpa_s->sta_uapsd |= BIT(3);
569 } else if (os_strcasecmp(cmd, "ps") == 0) {
570 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
571 #ifdef CONFIG_WIFI_DISPLAY
572 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
573 int enabled = !!atoi(value);
574 if (enabled && !wpa_s->global->p2p)
577 wifi_display_enable(wpa_s->global, enabled);
578 #endif /* CONFIG_WIFI_DISPLAY */
579 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
580 ret = set_bssid_filter(wpa_s, value);
581 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
582 ret = set_disallow_aps(wpa_s, value);
583 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
584 wpa_s->no_keep_alive = !!atoi(value);
586 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
587 os_free(wpa_s->dpp_configurator_params);
588 wpa_s->dpp_configurator_params = os_strdup(value);
589 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
590 wpa_s->dpp_init_max_tries = atoi(value);
591 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
592 wpa_s->dpp_init_retry_time = atoi(value);
593 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
594 wpa_s->dpp_resp_wait_time = atoi(value);
595 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
596 wpa_s->dpp_resp_max_tries = atoi(value);
597 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
598 wpa_s->dpp_resp_retry_time = atoi(value);
599 #ifdef CONFIG_TESTING_OPTIONS
600 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
601 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
603 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
604 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
606 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
607 size_t hex_len = os_strlen(value);
610 2 * sizeof(dpp_pkex_ephemeral_key_override))
612 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
616 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
617 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
618 size_t hex_len = os_strlen(value);
620 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
622 else if (hexstr2bin(value, dpp_protocol_key_override,
626 dpp_protocol_key_override_len = hex_len / 2;
627 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
628 size_t hex_len = os_strlen(value);
630 if (hex_len > 2 * sizeof(dpp_nonce_override))
632 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
635 dpp_nonce_override_len = hex_len / 2;
636 #endif /* CONFIG_TESTING_OPTIONS */
637 #endif /* CONFIG_DPP */
638 #ifdef CONFIG_TESTING_OPTIONS
639 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
640 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
641 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
642 wpa_s->ext_eapol_frame_io = !!atoi(value);
644 if (wpa_s->ap_iface) {
645 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
646 wpa_s->ext_eapol_frame_io;
648 #endif /* CONFIG_AP */
649 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
650 wpa_s->extra_roc_dur = atoi(value);
651 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
652 wpa_s->test_failure = atoi(value);
653 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
654 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
655 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
656 wpa_s->ignore_auth_resp = !!atoi(value);
657 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
658 wpa_s->ignore_assoc_disallow = !!atoi(value);
659 wpa_drv_ignore_assoc_disallow(wpa_s,
660 wpa_s->ignore_assoc_disallow);
661 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
662 wpa_s->reject_btm_req_reason = atoi(value);
663 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
664 os_free(wpa_s->get_pref_freq_list_override);
666 wpa_s->get_pref_freq_list_override = NULL;
668 wpa_s->get_pref_freq_list_override = os_strdup(value);
669 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
670 wpabuf_free(wpa_s->sae_commit_override);
671 if (value[0] == '\0')
672 wpa_s->sae_commit_override = NULL;
674 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
676 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
677 os_free(wpa_s->dpp_config_obj_override);
678 if (value[0] == '\0')
679 wpa_s->dpp_config_obj_override = NULL;
681 wpa_s->dpp_config_obj_override = os_strdup(value);
682 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
683 os_free(wpa_s->dpp_discovery_override);
684 if (value[0] == '\0')
685 wpa_s->dpp_discovery_override = NULL;
687 wpa_s->dpp_discovery_override = os_strdup(value);
688 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
689 os_free(wpa_s->dpp_groups_override);
690 if (value[0] == '\0')
691 wpa_s->dpp_groups_override = NULL;
693 wpa_s->dpp_groups_override = os_strdup(value);
694 } else if (os_strcasecmp(cmd,
695 "dpp_ignore_netaccesskey_mismatch") == 0) {
696 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
697 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
698 dpp_test = atoi(value);
699 #endif /* CONFIG_DPP */
700 #endif /* CONFIG_TESTING_OPTIONS */
702 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
703 wpa_s->disable_fils = !!atoi(value);
704 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
705 wpa_supplicant_set_default_scan_ies(wpa_s);
706 #endif /* CONFIG_FILS */
707 #ifndef CONFIG_NO_CONFIG_BLOBS
708 } else if (os_strcmp(cmd, "blob") == 0) {
709 ret = wpas_ctrl_set_blob(wpa_s, value);
710 #endif /* CONFIG_NO_CONFIG_BLOBS */
711 } else if (os_strcasecmp(cmd, "setband") == 0) {
712 ret = wpas_ctrl_set_band(wpa_s, value);
714 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
715 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
718 wpa_config_process_global(wpa_s->conf, cmd, -1);
720 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
721 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
722 } else if (os_strcasecmp(cmd, "oce") == 0) {
723 wpa_s->conf->oce = atoi(value);
724 if (wpa_s->conf->oce) {
725 if ((wpa_s->conf->oce & OCE_STA) &&
726 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
727 wpa_s->enable_oce = OCE_STA;
729 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
731 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
732 /* TODO: Need to add STA-CFON support */
733 wpa_printf(MSG_ERROR,
734 "OCE STA-CFON feature is not yet supported");
738 wpa_s->enable_oce = 0;
740 wpa_supplicant_set_default_scan_ies(wpa_s);
741 #endif /* CONFIG_MBO */
742 } else if (os_strcasecmp(cmd, "lci") == 0) {
743 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
744 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
745 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
746 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
747 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
748 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
749 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
750 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
751 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
752 } else if (os_strcasecmp(cmd, "roaming") == 0) {
753 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
755 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
756 struct wpabuf *elems;
758 elems = wpabuf_parse_bin(value);
761 wnm_set_coloc_intf_elems(wpa_s, elems);
762 #endif /* CONFIG_WNM */
765 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
767 wpa_supplicant_update_config(wpa_s);
774 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
775 char *cmd, char *buf, size_t buflen)
779 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
781 if (os_strcmp(cmd, "version") == 0) {
782 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
783 } else if (os_strcasecmp(cmd, "country") == 0) {
784 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
785 res = os_snprintf(buf, buflen, "%c%c",
786 wpa_s->conf->country[0],
787 wpa_s->conf->country[1]);
788 #ifdef CONFIG_WIFI_DISPLAY
789 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
791 if (wpa_s->global->p2p == NULL ||
792 wpa_s->global->p2p_disabled)
795 enabled = wpa_s->global->wifi_display;
796 res = os_snprintf(buf, buflen, "%d", enabled);
797 #endif /* CONFIG_WIFI_DISPLAY */
798 #ifdef CONFIG_TESTING_GET_GTK
799 } else if (os_strcmp(cmd, "gtk") == 0) {
800 if (wpa_s->last_gtk_len == 0)
802 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
803 wpa_s->last_gtk_len);
805 #endif /* CONFIG_TESTING_GET_GTK */
806 } else if (os_strcmp(cmd, "tls_library") == 0) {
807 res = tls_get_library_version(buf, buflen);
808 #ifdef CONFIG_TESTING_OPTIONS
809 } else if (os_strcmp(cmd, "anonce") == 0) {
810 return wpa_snprintf_hex(buf, buflen,
811 wpa_sm_get_anonce(wpa_s->wpa),
813 #endif /* CONFIG_TESTING_OPTIONS */
815 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
818 if (os_snprintf_error(buflen, res))
824 #ifdef IEEE8021X_EAPOL
825 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
829 struct wpa_ssid *ssid = wpa_s->current_ssid;
831 if (hwaddr_aton(addr, bssid)) {
832 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
837 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
838 rsn_preauth_deinit(wpa_s->wpa);
839 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
844 #endif /* IEEE8021X_EAPOL */
849 static int wpa_supplicant_ctrl_iface_tdls_discover(
850 struct wpa_supplicant *wpa_s, char *addr)
855 if (hwaddr_aton(addr, peer)) {
856 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
857 "address '%s'", addr);
861 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
864 if (wpa_tdls_is_external_setup(wpa_s->wpa))
865 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
867 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
873 static int wpa_supplicant_ctrl_iface_tdls_setup(
874 struct wpa_supplicant *wpa_s, char *addr)
879 if (hwaddr_aton(addr, peer)) {
880 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
881 "address '%s'", addr);
885 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
888 if ((wpa_s->conf->tdls_external_control) &&
889 wpa_tdls_is_external_setup(wpa_s->wpa))
890 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
892 wpa_tdls_remove(wpa_s->wpa, peer);
894 if (wpa_tdls_is_external_setup(wpa_s->wpa))
895 ret = wpa_tdls_start(wpa_s->wpa, peer);
897 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
903 static int wpa_supplicant_ctrl_iface_tdls_teardown(
904 struct wpa_supplicant *wpa_s, char *addr)
909 if (os_strcmp(addr, "*") == 0) {
910 /* remove everyone */
911 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
912 wpa_tdls_teardown_peers(wpa_s->wpa);
916 if (hwaddr_aton(addr, peer)) {
917 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
918 "address '%s'", addr);
922 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
925 if ((wpa_s->conf->tdls_external_control) &&
926 wpa_tdls_is_external_setup(wpa_s->wpa))
927 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
929 if (wpa_tdls_is_external_setup(wpa_s->wpa))
930 ret = wpa_tdls_teardown_link(
932 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
934 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
940 static int ctrl_iface_get_capability_tdls(
941 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
945 ret = os_snprintf(buf, buflen, "%s\n",
946 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
948 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
949 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
950 if (os_snprintf_error(buflen, ret))
956 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
957 struct wpa_supplicant *wpa_s, char *cmd)
960 struct hostapd_freq_params freq_params;
964 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
966 "tdls_chanswitch: Only supported with external setup");
970 os_memset(&freq_params, 0, sizeof(freq_params));
972 pos = os_strchr(cmd, ' ');
977 oper_class = strtol(pos, &end, 10);
980 "tdls_chanswitch: Invalid op class provided");
985 freq_params.freq = atoi(pos);
986 if (freq_params.freq == 0) {
987 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
991 #define SET_FREQ_SETTING(str) \
993 const char *pos2 = os_strstr(pos, " " #str "="); \
995 pos2 += sizeof(" " #str "=") - 1; \
996 freq_params.str = atoi(pos2); \
1000 SET_FREQ_SETTING(center_freq1);
1001 SET_FREQ_SETTING(center_freq2);
1002 SET_FREQ_SETTING(bandwidth);
1003 SET_FREQ_SETTING(sec_channel_offset);
1004 #undef SET_FREQ_SETTING
1006 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1007 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1009 if (hwaddr_aton(cmd, peer)) {
1010 wpa_printf(MSG_DEBUG,
1011 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1016 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1017 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1018 MAC2STR(peer), oper_class, freq_params.freq,
1019 freq_params.center_freq1, freq_params.center_freq2,
1020 freq_params.bandwidth, freq_params.sec_channel_offset,
1021 freq_params.ht_enabled ? " HT" : "",
1022 freq_params.vht_enabled ? " VHT" : "");
1024 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1029 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1030 struct wpa_supplicant *wpa_s, char *cmd)
1034 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1035 wpa_printf(MSG_INFO,
1036 "tdls_chanswitch: Only supported with external setup");
1040 if (hwaddr_aton(cmd, peer)) {
1041 wpa_printf(MSG_DEBUG,
1042 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1047 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1050 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1054 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1055 struct wpa_supplicant *wpa_s, const char *addr,
1056 char *buf, size_t buflen)
1059 const char *tdls_status;
1062 if (hwaddr_aton(addr, peer)) {
1063 wpa_printf(MSG_DEBUG,
1064 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1068 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1071 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1072 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1073 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1074 if (os_snprintf_error(buflen, ret))
1080 #endif /* CONFIG_TDLS */
1083 static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1085 char *token, *context = NULL;
1086 struct wmm_ac_ts_setup_params params = {
1091 while ((token = str_token(cmd, " ", &context))) {
1092 if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 ||
1093 sscanf(token, "up=%i", ¶ms.user_priority) == 1 ||
1094 sscanf(token, "nominal_msdu_size=%i",
1095 ¶ms.nominal_msdu_size) == 1 ||
1096 sscanf(token, "mean_data_rate=%i",
1097 ¶ms.mean_data_rate) == 1 ||
1098 sscanf(token, "min_phy_rate=%i",
1099 ¶ms.minimum_phy_rate) == 1 ||
1100 sscanf(token, "sba=%i",
1101 ¶ms.surplus_bandwidth_allowance) == 1)
1104 if (os_strcasecmp(token, "downlink") == 0) {
1105 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1106 } else if (os_strcasecmp(token, "uplink") == 0) {
1107 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1108 } else if (os_strcasecmp(token, "bidi") == 0) {
1109 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1110 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1111 params.fixed_nominal_msdu = 1;
1113 wpa_printf(MSG_DEBUG,
1114 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1121 return wpas_wmm_ac_addts(wpa_s, ¶ms);
1125 static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1127 u8 tsid = atoi(cmd);
1129 return wpas_wmm_ac_delts(wpa_s, tsid);
1133 #ifdef CONFIG_IEEE80211R
1134 static int wpa_supplicant_ctrl_iface_ft_ds(
1135 struct wpa_supplicant *wpa_s, char *addr)
1137 u8 target_ap[ETH_ALEN];
1138 struct wpa_bss *bss;
1141 if (hwaddr_aton(addr, target_ap)) {
1142 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1143 "address '%s'", addr);
1147 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1149 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1151 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1155 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1157 #endif /* CONFIG_IEEE80211R */
1161 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1164 u8 bssid[ETH_ALEN], *_bssid = bssid;
1166 u8 p2p_dev_addr[ETH_ALEN];
1167 #endif /* CONFIG_P2P */
1169 u8 *_p2p_dev_addr = NULL;
1170 #endif /* CONFIG_AP */
1174 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1175 os_strncmp(cmd, "any ", 4) == 0) {
1178 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1179 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1180 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1181 "P2P Device Address '%s'",
1185 _p2p_dev_addr = p2p_dev_addr;
1186 #endif /* CONFIG_P2P */
1187 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1189 multi_ap = atoi(cmd + 9);
1190 } else if (hwaddr_aton(cmd, bssid)) {
1191 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1197 pos = os_strstr(cmd, " multi_ap=");
1200 multi_ap = atoi(pos);
1205 if (wpa_s->ap_iface)
1206 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1207 #endif /* CONFIG_AP */
1209 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
1213 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1214 char *cmd, char *buf,
1217 u8 bssid[ETH_ALEN], *_bssid = bssid;
1221 pin = os_strchr(cmd, ' ');
1225 if (os_strcmp(cmd, "any") == 0)
1227 else if (os_strcmp(cmd, "get") == 0) {
1228 if (wps_generate_pin((unsigned int *) &ret) < 0)
1231 } else if (hwaddr_aton(cmd, bssid)) {
1232 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1238 if (wpa_s->ap_iface) {
1243 pos = os_strchr(pin, ' ');
1246 timeout = atoi(pos);
1250 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
1251 buf, buflen, timeout);
1253 #endif /* CONFIG_AP */
1256 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1260 ret = os_snprintf(buf, buflen, "%s", pin);
1261 if (os_snprintf_error(buflen, ret))
1266 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1271 /* Return the generated PIN */
1272 ret = os_snprintf(buf, buflen, "%08d", ret);
1273 if (os_snprintf_error(buflen, ret))
1279 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1280 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1287 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1288 (u8 *) cmd, os_strlen(cmd));
1289 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1290 if (*pos < '0' || *pos > '9')
1294 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1298 if (len != 4 && len != 8) {
1299 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1305 unsigned int pin_val;
1306 pin_val = atoi(pin);
1307 if (!wps_pin_valid(pin_val)) {
1308 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1309 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
1310 if (os_snprintf_error(buflen, ret))
1316 ret = os_snprintf(buf, buflen, "%s", pin);
1317 if (os_snprintf_error(buflen, ret))
1324 #ifdef CONFIG_WPS_NFC
1326 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1329 u8 bssid[ETH_ALEN], *_bssid = bssid;
1331 if (cmd == NULL || cmd[0] == '\0')
1333 else if (hwaddr_aton(cmd, bssid))
1336 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1341 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1342 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1349 pos = os_strchr(cmd, ' ');
1352 if (os_strcmp(cmd, "WPS") == 0)
1354 else if (os_strcmp(cmd, "NDEF") == 0)
1359 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
1363 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1365 reply[res++] = '\n';
1374 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1375 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1381 if (os_strcmp(cmd, "WPS") == 0)
1383 else if (os_strcmp(cmd, "NDEF") == 0)
1388 buf = wpas_wps_nfc_token(wpa_s, ndef);
1392 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1394 reply[res++] = '\n';
1403 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1404 struct wpa_supplicant *wpa_s, char *pos)
1410 int forced_freq = 0;
1412 freq = strstr(pos, " freq=");
1416 forced_freq = atoi(freq);
1419 len = os_strlen(pos);
1424 buf = wpabuf_alloc(len);
1427 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1432 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
1439 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
1440 char *reply, size_t max_len,
1446 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
1450 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1452 reply[res++] = '\n';
1462 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1463 char *reply, size_t max_len,
1469 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1471 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1475 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1477 reply[res++] = '\n';
1484 #endif /* CONFIG_P2P */
1487 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1488 char *cmd, char *reply,
1494 pos = os_strchr(cmd, ' ');
1499 if (os_strcmp(cmd, "WPS") == 0)
1501 else if (os_strcmp(cmd, "NDEF") == 0)
1506 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1509 return wpas_ctrl_nfc_get_handover_req_wps(
1510 wpa_s, reply, max_len, ndef);
1514 if (os_strcmp(pos, "P2P-CR") == 0) {
1515 return wpas_ctrl_nfc_get_handover_req_p2p(
1516 wpa_s, reply, max_len, ndef);
1518 #endif /* CONFIG_P2P */
1524 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1525 char *reply, size_t max_len,
1526 int ndef, int cr, char *uuid)
1531 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1535 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1537 reply[res++] = '\n';
1547 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1548 char *reply, size_t max_len,
1554 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1558 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1560 reply[res++] = '\n';
1567 #endif /* CONFIG_P2P */
1570 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1571 char *cmd, char *reply,
1577 pos = os_strchr(cmd, ' ');
1582 if (os_strcmp(cmd, "WPS") == 0)
1584 else if (os_strcmp(cmd, "NDEF") == 0)
1589 pos2 = os_strchr(pos, ' ');
1592 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1595 return wpas_ctrl_nfc_get_handover_sel_wps(
1596 wpa_s, reply, max_len, ndef,
1597 os_strcmp(pos, "WPS-CR") == 0, pos2);
1601 if (os_strcmp(pos, "P2P-CR") == 0) {
1602 return wpas_ctrl_nfc_get_handover_sel_p2p(
1603 wpa_s, reply, max_len, ndef, 0);
1606 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1607 return wpas_ctrl_nfc_get_handover_sel_p2p(
1608 wpa_s, reply, max_len, ndef, 1);
1610 #endif /* CONFIG_P2P */
1616 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1620 struct wpabuf *req, *sel;
1622 char *pos, *role, *type, *pos2;
1625 int forced_freq = 0;
1627 freq = strstr(cmd, " freq=");
1631 forced_freq = atoi(freq);
1633 #endif /* CONFIG_P2P */
1636 pos = os_strchr(role, ' ');
1638 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1644 pos = os_strchr(type, ' ');
1646 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1651 pos2 = os_strchr(pos, ' ');
1653 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1658 len = os_strlen(pos);
1660 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1665 req = wpabuf_alloc(len);
1667 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1670 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1671 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1676 len = os_strlen(pos2);
1678 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1684 sel = wpabuf_alloc(len);
1686 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1690 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1691 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1697 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1698 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1700 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1701 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1703 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1705 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1707 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1708 #endif /* CONFIG_AP */
1710 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1712 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1713 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1715 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1717 #endif /* CONFIG_P2P */
1719 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1720 "reported: role=%s type=%s", role, type);
1727 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1732 #endif /* CONFIG_WPS_NFC */
1735 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1744 struct wps_new_ap_settings ap;
1746 pin = os_strchr(cmd, ' ');
1751 if (hwaddr_aton(cmd, bssid)) {
1752 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1757 new_ssid = os_strchr(pin, ' ');
1758 if (new_ssid == NULL)
1759 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1762 new_auth = os_strchr(new_ssid, ' ');
1763 if (new_auth == NULL)
1767 new_encr = os_strchr(new_auth, ' ');
1768 if (new_encr == NULL)
1772 new_key = os_strchr(new_encr, ' ');
1773 if (new_key == NULL)
1777 os_memset(&ap, 0, sizeof(ap));
1778 ap.ssid_hex = new_ssid;
1781 ap.key_hex = new_key;
1782 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1787 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1788 char *cmd, char *buf,
1793 const char *pin_txt;
1795 if (!wpa_s->ap_iface)
1798 pos = os_strchr(cmd, ' ');
1802 if (os_strcmp(cmd, "disable") == 0) {
1803 wpas_wps_ap_pin_disable(wpa_s);
1804 return os_snprintf(buf, buflen, "OK\n");
1807 if (os_strcmp(cmd, "random") == 0) {
1809 timeout = atoi(pos);
1810 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1811 if (pin_txt == NULL)
1813 return os_snprintf(buf, buflen, "%s", pin_txt);
1816 if (os_strcmp(cmd, "get") == 0) {
1817 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1818 if (pin_txt == NULL)
1820 return os_snprintf(buf, buflen, "%s", pin_txt);
1823 if (os_strcmp(cmd, "set") == 0) {
1828 pos = os_strchr(pos, ' ');
1831 timeout = atoi(pos);
1833 if (os_strlen(pin) > buflen)
1835 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1837 return os_snprintf(buf, buflen, "%s", pin);
1842 #endif /* CONFIG_AP */
1845 #ifdef CONFIG_WPS_ER
1846 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1849 char *uuid = cmd, *pin, *pos;
1850 u8 addr_buf[ETH_ALEN], *addr = NULL;
1851 pin = os_strchr(uuid, ' ');
1855 pos = os_strchr(pin, ' ');
1858 if (hwaddr_aton(pos, addr_buf) == 0)
1861 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1865 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1868 char *uuid = cmd, *pin;
1869 pin = os_strchr(uuid, ' ');
1873 return wpas_wps_er_learn(wpa_s, uuid, pin);
1877 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1878 struct wpa_supplicant *wpa_s, char *cmd)
1880 char *uuid = cmd, *id;
1881 id = os_strchr(uuid, ' ');
1885 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1889 static int wpa_supplicant_ctrl_iface_wps_er_config(
1890 struct wpa_supplicant *wpa_s, char *cmd)
1897 struct wps_new_ap_settings ap;
1899 pin = os_strchr(cmd, ' ');
1904 new_ssid = os_strchr(pin, ' ');
1905 if (new_ssid == NULL)
1909 new_auth = os_strchr(new_ssid, ' ');
1910 if (new_auth == NULL)
1914 new_encr = os_strchr(new_auth, ' ');
1915 if (new_encr == NULL)
1919 new_key = os_strchr(new_encr, ' ');
1920 if (new_key == NULL)
1924 os_memset(&ap, 0, sizeof(ap));
1925 ap.ssid_hex = new_ssid;
1928 ap.key_hex = new_key;
1929 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1933 #ifdef CONFIG_WPS_NFC
1934 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1935 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1942 uuid = os_strchr(cmd, ' ');
1947 if (os_strcmp(cmd, "WPS") == 0)
1949 else if (os_strcmp(cmd, "NDEF") == 0)
1954 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1958 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1960 reply[res++] = '\n';
1967 #endif /* CONFIG_WPS_NFC */
1968 #endif /* CONFIG_WPS_ER */
1970 #endif /* CONFIG_WPS */
1973 #ifdef CONFIG_IBSS_RSN
1974 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1975 struct wpa_supplicant *wpa_s, char *addr)
1979 if (hwaddr_aton(addr, peer)) {
1980 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1981 "address '%s'", addr);
1985 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1988 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1990 #endif /* CONFIG_IBSS_RSN */
1993 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1996 #ifdef IEEE8021X_EAPOL
1999 struct wpa_ssid *ssid;
2001 pos = os_strchr(rsp, '-');
2006 pos = os_strchr(pos, ':');
2011 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2012 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2013 (u8 *) pos, os_strlen(pos));
2015 ssid = wpa_config_get_network(wpa_s->conf, id);
2017 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2022 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2024 #else /* IEEE8021X_EAPOL */
2025 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2027 #endif /* IEEE8021X_EAPOL */
2031 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2033 char *buf, size_t buflen)
2035 char *pos, *end, tmp[30];
2036 int res, verbose, wps, ret;
2039 #endif /* CONFIG_HS20 */
2043 if (os_strcmp(params, "-DRIVER") == 0)
2044 return wpa_drv_status(wpa_s, buf, buflen);
2045 verbose = os_strcmp(params, "-VERBOSE") == 0;
2046 wps = os_strcmp(params, "-WPS") == 0;
2049 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2050 struct wpa_ssid *ssid = wpa_s->current_ssid;
2051 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2052 MAC2STR(wpa_s->bssid));
2053 if (os_snprintf_error(end - pos, ret))
2056 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2058 if (os_snprintf_error(end - pos, ret))
2062 u8 *_ssid = ssid->ssid;
2063 size_t ssid_len = ssid->ssid_len;
2064 u8 ssid_buf[SSID_MAX_LEN];
2065 if (ssid_len == 0) {
2066 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2073 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2074 wpa_ssid_txt(_ssid, ssid_len),
2076 if (os_snprintf_error(end - pos, ret))
2080 if (wps && ssid->passphrase &&
2081 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2082 (ssid->mode == WPAS_MODE_AP ||
2083 ssid->mode == WPAS_MODE_P2P_GO)) {
2084 ret = os_snprintf(pos, end - pos,
2087 if (os_snprintf_error(end - pos, ret))
2092 ret = os_snprintf(pos, end - pos,
2095 if (os_snprintf_error(end - pos, ret))
2100 switch (ssid->mode) {
2101 case WPAS_MODE_INFRA:
2102 ret = os_snprintf(pos, end - pos,
2105 case WPAS_MODE_IBSS:
2106 ret = os_snprintf(pos, end - pos,
2110 ret = os_snprintf(pos, end - pos,
2113 case WPAS_MODE_P2P_GO:
2114 ret = os_snprintf(pos, end - pos,
2117 case WPAS_MODE_P2P_GROUP_FORMATION:
2118 ret = os_snprintf(pos, end - pos,
2119 "mode=P2P GO - group "
2122 case WPAS_MODE_MESH:
2123 ret = os_snprintf(pos, end - pos,
2130 if (os_snprintf_error(end - pos, ret))
2135 if (wpa_s->connection_set &&
2136 (wpa_s->connection_ht || wpa_s->connection_vht ||
2137 wpa_s->connection_he)) {
2138 ret = os_snprintf(pos, end - pos,
2139 "wifi_generation=%u\n",
2140 wpa_s->connection_he ? 6 :
2141 (wpa_s->connection_vht ? 5 : 4));
2142 if (os_snprintf_error(end - pos, ret))
2148 if (wpa_s->ap_iface) {
2149 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2153 #endif /* CONFIG_AP */
2154 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2158 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
2161 #endif /* CONFIG_AP */
2162 wpa_s->sme.sae.state == SAE_ACCEPTED) {
2163 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
2164 wpa_s->sme.sae.group);
2165 if (os_snprintf_error(end - pos, ret))
2169 #endif /* CONFIG_SAE */
2170 #endif /* CONFIG_SME */
2171 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2172 wpa_supplicant_state_txt(wpa_s->wpa_state));
2173 if (os_snprintf_error(end - pos, ret))
2178 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2179 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
2180 if (os_snprintf_error(end - pos, ret))
2186 if (wpa_s->global->p2p) {
2187 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2188 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
2189 if (os_snprintf_error(end - pos, ret))
2193 #endif /* CONFIG_P2P */
2195 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2196 MAC2STR(wpa_s->own_addr));
2197 if (os_snprintf_error(end - pos, ret))
2202 if (wpa_s->current_bss &&
2203 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2204 HS20_IE_VENDOR_TYPE)) &&
2205 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2206 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2209 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2210 release = rel_num + 1;
2212 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
2213 if (os_snprintf_error(end - pos, ret))
2218 if (wpa_s->current_ssid) {
2219 struct wpa_cred *cred;
2222 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
2225 if (wpa_s->current_ssid->parent_cred != cred)
2228 if (cred->provisioning_sp) {
2229 ret = os_snprintf(pos, end - pos,
2230 "provisioning_sp=%s\n",
2231 cred->provisioning_sp);
2232 if (os_snprintf_error(end - pos, ret))
2241 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2242 struct wpabuf *names =
2243 wpa_s->current_bss->anqp->domain_name;
2244 for (i = 0; names && i < cred->num_domain; i++)
2246 if (domain_name_list_contains(
2247 names, cred->domain[i], 1))
2250 if (i == cred->num_domain)
2251 i = 0; /* show first entry by default */
2253 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2255 if (os_snprintf_error(end - pos, ret))
2260 if (wpa_s->current_bss == NULL ||
2261 wpa_s->current_bss->anqp == NULL)
2264 res = interworking_home_sp_cred(
2266 wpa_s->current_bss->anqp->domain_name);
2274 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
2275 if (os_snprintf_error(end - pos, ret))
2282 #endif /* CONFIG_HS20 */
2284 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2285 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2286 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2292 #ifdef CONFIG_MACSEC
2293 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2296 #endif /* CONFIG_MACSEC */
2298 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2302 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2303 if (os_snprintf_error(end - pos, ret))
2306 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2310 ret = os_snprintf(pos, end - pos, "\n");
2311 if (os_snprintf_error(end - pos, ret))
2316 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2323 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2324 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
2325 if (os_snprintf_error(end - pos, ret))
2329 #endif /* CONFIG_WPS */
2331 if (wpa_s->ieee80211ac) {
2332 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2333 if (os_snprintf_error(end - pos, ret))
2340 * Allow using the STATUS command with default behavior, say for debug,
2341 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2342 * events with STATUS-NO_EVENTS.
2344 if (os_strcmp(params, "-NO_EVENTS")) {
2345 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2346 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2347 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2349 MAC2STR(wpa_s->bssid),
2350 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2351 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2352 wpa_s->current_ssid->ssid_len) : "");
2353 if (wpa_s->wpa_state == WPA_COMPLETED) {
2354 struct wpa_ssid *ssid = wpa_s->current_ssid;
2355 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2356 "- connection to " MACSTR
2357 " completed %s [id=%d id_str=%s]",
2358 MAC2STR(wpa_s->bssid), "(auth)",
2359 ssid ? ssid->id : -1,
2360 ssid && ssid->id_str ? ssid->id_str : "");
2363 #endif /* ANDROID */
2369 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2374 struct wpa_ssid *ssid;
2377 /* cmd: "<network id> <BSSID>" */
2378 pos = os_strchr(cmd, ' ');
2383 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2384 if (hwaddr_aton(pos, bssid)) {
2385 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2389 ssid = wpa_config_get_network(wpa_s->conf, id);
2391 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2396 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2397 ssid->bssid_set = !is_zero_ether_addr(bssid);
2403 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
2404 char *cmd, char *buf,
2408 struct wpa_blacklist *e;
2412 /* cmd: "BLACKLIST [<BSSID>]" */
2416 e = wpa_s->blacklist;
2418 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2420 if (os_snprintf_error(end - pos, ret))
2429 if (os_strncmp(cmd, "clear", 5) == 0) {
2430 wpa_blacklist_clear(wpa_s);
2431 os_memcpy(buf, "OK\n", 3);
2435 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2436 if (hwaddr_aton(cmd, bssid)) {
2437 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
2442 * Add the BSSID twice, so its count will be 2, causing it to be
2443 * skipped when processing scan results.
2445 ret = wpa_blacklist_add(wpa_s, bssid);
2448 ret = wpa_blacklist_add(wpa_s, bssid);
2451 os_memcpy(buf, "OK\n", 3);
2456 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2457 char *cmd, char *buf,
2460 char *pos, *end, *stamp;
2463 /* cmd: "LOG_LEVEL [<level>]" */
2467 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2469 debug_level_str(wpa_debug_level),
2470 wpa_debug_timestamp);
2471 if (os_snprintf_error(end - pos, ret))
2480 stamp = os_strchr(cmd, ' ');
2483 while (*stamp == ' ') {
2488 if (os_strlen(cmd)) {
2489 int level = str_to_debug_level(cmd);
2492 wpa_debug_level = level;
2495 if (stamp && os_strlen(stamp))
2496 wpa_debug_timestamp = atoi(stamp);
2498 os_memcpy(buf, "OK\n", 3);
2503 static int wpa_supplicant_ctrl_iface_list_networks(
2504 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2506 char *pos, *end, *prev;
2507 struct wpa_ssid *ssid;
2512 ret = os_snprintf(pos, end - pos,
2513 "network id / ssid / bssid / flags\n");
2514 if (os_snprintf_error(end - pos, ret))
2518 ssid = wpa_s->conf->ssid;
2520 /* skip over ssids until we find next one */
2521 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2522 int last_id = atoi(cmd + 8);
2523 if (last_id != -1) {
2524 while (ssid != NULL && ssid->id <= last_id) {
2532 ret = os_snprintf(pos, end - pos, "%d\t%s",
2534 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2535 if (os_snprintf_error(end - pos, ret))
2538 if (ssid->bssid_set) {
2539 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2540 MAC2STR(ssid->bssid));
2542 ret = os_snprintf(pos, end - pos, "\tany");
2544 if (os_snprintf_error(end - pos, ret))
2547 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2548 ssid == wpa_s->current_ssid ?
2550 ssid->disabled ? "[DISABLED]" : "",
2551 ssid->disabled_until.sec ?
2552 "[TEMP-DISABLED]" : "",
2553 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2555 if (os_snprintf_error(end - pos, ret))
2558 ret = os_snprintf(pos, end - pos, "\n");
2559 if (os_snprintf_error(end - pos, ret))
2570 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2573 ret = os_snprintf(pos, end - pos, "-");
2574 if (os_snprintf_error(end - pos, ret))
2577 ret = wpa_write_ciphers(pos, end, cipher, "+");
2585 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2586 const u8 *ie, size_t ie_len)
2588 struct wpa_ie_data data;
2592 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2593 if (os_snprintf_error(end - pos, ret))
2597 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2598 ret = os_snprintf(pos, end - pos, "?]");
2599 if (os_snprintf_error(end - pos, ret))
2606 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2607 ret = os_snprintf(pos, end - pos, "%sEAP",
2608 pos == start ? "" : "+");
2609 if (os_snprintf_error(end - pos, ret))
2613 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2614 ret = os_snprintf(pos, end - pos, "%sPSK",
2615 pos == start ? "" : "+");
2616 if (os_snprintf_error(end - pos, ret))
2620 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2621 ret = os_snprintf(pos, end - pos, "%sNone",
2622 pos == start ? "" : "+");
2623 if (os_snprintf_error(end - pos, ret))
2627 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2628 ret = os_snprintf(pos, end - pos, "%sSAE",
2629 pos == start ? "" : "+");
2630 if (os_snprintf_error(end - pos, ret))
2634 #ifdef CONFIG_IEEE80211R
2635 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2636 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2637 pos == start ? "" : "+");
2638 if (os_snprintf_error(end - pos, ret))
2642 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2643 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2644 pos == start ? "" : "+");
2645 if (os_snprintf_error(end - pos, ret))
2649 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2650 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2651 pos == start ? "" : "+");
2652 if (os_snprintf_error(end - pos, ret))
2656 #endif /* CONFIG_IEEE80211R */
2657 #ifdef CONFIG_IEEE80211W
2658 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2659 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2660 pos == start ? "" : "+");
2661 if (os_snprintf_error(end - pos, ret))
2665 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2666 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2667 pos == start ? "" : "+");
2668 if (os_snprintf_error(end - pos, ret))
2672 #endif /* CONFIG_IEEE80211W */
2674 #ifdef CONFIG_SUITEB
2675 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2676 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2677 pos == start ? "" : "+");
2678 if (os_snprintf_error(end - pos, ret))
2682 #endif /* CONFIG_SUITEB */
2684 #ifdef CONFIG_SUITEB192
2685 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2686 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2687 pos == start ? "" : "+");
2688 if (os_snprintf_error(end - pos, ret))
2692 #endif /* CONFIG_SUITEB192 */
2695 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2696 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2697 pos == start ? "" : "+");
2698 if (os_snprintf_error(end - pos, ret))
2702 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2703 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2704 pos == start ? "" : "+");
2705 if (os_snprintf_error(end - pos, ret))
2709 #ifdef CONFIG_IEEE80211R
2710 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2711 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2712 pos == start ? "" : "+");
2713 if (os_snprintf_error(end - pos, ret))
2717 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2718 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2719 pos == start ? "" : "+");
2720 if (os_snprintf_error(end - pos, ret))
2724 #endif /* CONFIG_IEEE80211R */
2725 #endif /* CONFIG_FILS */
2728 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2729 ret = os_snprintf(pos, end - pos, "%sOWE",
2730 pos == start ? "" : "+");
2731 if (os_snprintf_error(end - pos, ret))
2735 #endif /* CONFIG_OWE */
2738 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2739 ret = os_snprintf(pos, end - pos, "%sDPP",
2740 pos == start ? "" : "+");
2741 if (os_snprintf_error(end - pos, ret))
2745 #endif /* CONFIG_DPP */
2747 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2748 ret = os_snprintf(pos, end - pos, "%sOSEN",
2749 pos == start ? "" : "+");
2750 if (os_snprintf_error(end - pos, ret))
2755 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2757 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2758 ret = os_snprintf(pos, end - pos, "-preauth");
2759 if (os_snprintf_error(end - pos, ret))
2764 ret = os_snprintf(pos, end - pos, "]");
2765 if (os_snprintf_error(end - pos, ret))
2774 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2775 char *pos, char *end,
2776 struct wpabuf *wps_ie)
2783 if (wps_is_selected_pbc_registrar(wps_ie))
2785 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2787 else if (wps_is_selected_pin_registrar(wps_ie))
2792 ret = os_snprintf(pos, end - pos, "%s", txt);
2793 if (!os_snprintf_error(end - pos, ret))
2795 wpabuf_free(wps_ie);
2798 #endif /* CONFIG_WPS */
2801 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2802 char *pos, char *end,
2803 const struct wpa_bss *bss)
2806 struct wpabuf *wps_ie;
2807 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2808 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2809 #else /* CONFIG_WPS */
2811 #endif /* CONFIG_WPS */
2815 /* Format one result on one text line into a buffer. */
2816 static int wpa_supplicant_ctrl_iface_scan_result(
2817 struct wpa_supplicant *wpa_s,
2818 const struct wpa_bss *bss, char *buf, size_t buflen)
2822 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe;
2824 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2825 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2827 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2828 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2829 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2831 return 0; /* Do not show P2P listen discovery results here */
2836 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2837 MAC2STR(bss->bssid), bss->freq, bss->level);
2838 if (os_snprintf_error(end - pos, ret))
2841 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2843 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2844 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2846 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2849 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2851 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2852 osen_ie, 2 + osen_ie[1]);
2853 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
2855 ret = os_snprintf(pos, end - pos,
2856 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2857 if (os_snprintf_error(end - pos, ret))
2861 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2862 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
2863 ret = os_snprintf(pos, end - pos, "[WEP]");
2864 if (os_snprintf_error(end - pos, ret))
2869 ret = os_snprintf(pos, end - pos, "[MESH]");
2870 if (os_snprintf_error(end - pos, ret))
2874 if (bss_is_dmg(bss)) {
2876 ret = os_snprintf(pos, end - pos, "[DMG]");
2877 if (os_snprintf_error(end - pos, ret))
2880 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2881 case IEEE80211_CAP_DMG_IBSS:
2884 case IEEE80211_CAP_DMG_AP:
2887 case IEEE80211_CAP_DMG_PBSS:
2894 ret = os_snprintf(pos, end - pos, "%s", s);
2895 if (os_snprintf_error(end - pos, ret))
2899 if (bss->caps & IEEE80211_CAP_IBSS) {
2900 ret = os_snprintf(pos, end - pos, "[IBSS]");
2901 if (os_snprintf_error(end - pos, ret))
2905 if (bss->caps & IEEE80211_CAP_ESS) {
2906 ret = os_snprintf(pos, end - pos, "[ESS]");
2907 if (os_snprintf_error(end - pos, ret))
2913 ret = os_snprintf(pos, end - pos, "[P2P]");
2914 if (os_snprintf_error(end - pos, ret))
2919 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2920 ret = os_snprintf(pos, end - pos, "[HS20]");
2921 if (os_snprintf_error(end - pos, ret))
2925 #endif /* CONFIG_HS20 */
2927 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
2928 ret = os_snprintf(pos, end - pos, "[FILS]");
2929 if (os_snprintf_error(end - pos, ret))
2933 #endif /* CONFIG_FILS */
2935 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
2936 ret = os_snprintf(pos, end - pos, "[FST]");
2937 if (os_snprintf_error(end - pos, ret))
2941 #endif /* CONFIG_FST */
2942 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
2943 ret = os_snprintf(pos, end - pos, "[UTF-8]");
2944 if (os_snprintf_error(end - pos, ret))
2949 ret = os_snprintf(pos, end - pos, "\t%s",
2950 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2951 if (os_snprintf_error(end - pos, ret))
2955 ret = os_snprintf(pos, end - pos, "\n");
2956 if (os_snprintf_error(end - pos, ret))
2964 static int wpa_supplicant_ctrl_iface_scan_results(
2965 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2968 struct wpa_bss *bss;
2973 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2975 if (os_snprintf_error(end - pos, ret))
2979 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2980 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2982 if (ret < 0 || ret >= end - pos)
2993 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2994 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2996 char *pos, ifname[IFNAMSIZ + 1];
3000 pos = os_strstr(cmd, "ifname=");
3003 os_strlcpy(ifname, pos, sizeof(ifname));
3006 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3009 os_strlcpy(reply, ifname, max_len);
3010 return os_strlen(ifname);
3014 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3015 struct wpa_supplicant *wpa_s, char *cmd)
3018 struct wpa_ssid *ssid;
3021 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3023 ssid = wpa_config_get_network(wpa_s->conf, id);
3025 wpa_printf(MSG_DEBUG,
3026 "CTRL_IFACE: Could not find network id=%d", id);
3029 if (ssid->mode != WPAS_MODE_MESH) {
3030 wpa_printf(MSG_DEBUG,
3031 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3034 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3035 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3036 wpa_printf(MSG_ERROR,
3037 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3042 * TODO: If necessary write our own group_add function,
3043 * for now we can reuse select_network
3045 wpa_supplicant_select_network(wpa_s, ssid);
3051 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3052 struct wpa_supplicant *wpa_s, char *cmd)
3054 struct wpa_supplicant *orig;
3055 struct wpa_global *global;
3058 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3060 global = wpa_s->global;
3063 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3064 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3070 wpa_printf(MSG_ERROR,
3071 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3075 if (wpa_s->mesh_if_created && wpa_s == orig) {
3076 wpa_printf(MSG_ERROR,
3077 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3081 wpa_s->reassociate = 0;
3082 wpa_s->disconnected = 1;
3083 wpa_supplicant_cancel_sched_scan(wpa_s);
3084 wpa_supplicant_cancel_scan(wpa_s);
3087 * TODO: If necessary write our own group_remove function,
3088 * for now we can reuse deauthenticate
3090 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3092 if (wpa_s->mesh_if_created)
3093 wpa_supplicant_remove_iface(global, wpa_s, 0);
3099 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3100 struct wpa_supplicant *wpa_s, char *cmd)
3104 if (hwaddr_aton(cmd, addr) < 0)
3107 return wpas_mesh_peer_remove(wpa_s, addr);
3111 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3112 struct wpa_supplicant *wpa_s, char *cmd)
3118 pos = os_strstr(cmd, " duration=");
3121 duration = atoi(pos + 10);
3126 if (hwaddr_aton(cmd, addr))
3129 return wpas_mesh_peer_add(wpa_s, addr, duration);
3132 #endif /* CONFIG_MESH */
3135 static int wpa_supplicant_ctrl_iface_select_network(
3136 struct wpa_supplicant *wpa_s, char *cmd)
3139 struct wpa_ssid *ssid;
3142 /* cmd: "<network id>" or "any" */
3143 if (os_strncmp(cmd, "any", 3) == 0) {
3144 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3148 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3150 ssid = wpa_config_get_network(wpa_s->conf, id);
3152 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3153 "network id=%d", id);
3156 if (ssid->disabled == 2) {
3157 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3158 "SELECT_NETWORK with persistent P2P group");
3163 pos = os_strstr(cmd, " freq=");
3165 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3167 os_free(wpa_s->select_network_scan_freqs);
3168 wpa_s->select_network_scan_freqs = freqs;
3172 wpa_s->scan_min_time.sec = 0;
3173 wpa_s->scan_min_time.usec = 0;
3174 wpa_supplicant_select_network(wpa_s, ssid);
3180 static int wpa_supplicant_ctrl_iface_enable_network(
3181 struct wpa_supplicant *wpa_s, char *cmd)
3184 struct wpa_ssid *ssid;
3186 /* cmd: "<network id>" or "all" */
3187 if (os_strcmp(cmd, "all") == 0) {
3188 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3192 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3194 ssid = wpa_config_get_network(wpa_s->conf, id);
3196 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3197 "network id=%d", id);
3200 if (ssid->disabled == 2) {
3201 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3202 "ENABLE_NETWORK with persistent P2P group");
3206 if (os_strstr(cmd, " no-connect")) {
3211 wpa_s->scan_min_time.sec = 0;
3212 wpa_s->scan_min_time.usec = 0;
3213 wpa_supplicant_enable_network(wpa_s, ssid);
3219 static int wpa_supplicant_ctrl_iface_disable_network(
3220 struct wpa_supplicant *wpa_s, char *cmd)
3223 struct wpa_ssid *ssid;
3225 /* cmd: "<network id>" or "all" */
3226 if (os_strcmp(cmd, "all") == 0) {
3227 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3231 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3233 ssid = wpa_config_get_network(wpa_s->conf, id);
3235 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3236 "network id=%d", id);
3239 if (ssid->disabled == 2) {
3240 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3241 "DISABLE_NETWORK with persistent P2P "
3246 wpa_supplicant_disable_network(wpa_s, ssid);
3252 static int wpa_supplicant_ctrl_iface_add_network(
3253 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3255 struct wpa_ssid *ssid;
3258 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3260 ssid = wpa_supplicant_add_network(wpa_s);
3264 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
3265 if (os_snprintf_error(buflen, ret))
3271 static int wpa_supplicant_ctrl_iface_remove_network(
3272 struct wpa_supplicant *wpa_s, char *cmd)
3275 struct wpa_ssid *ssid;
3278 /* cmd: "<network id>" or "all" */
3279 if (os_strcmp(cmd, "all") == 0) {
3280 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
3281 if (wpa_s->sched_scanning)
3282 wpa_supplicant_cancel_sched_scan(wpa_s);
3284 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3285 if (wpa_s->current_ssid) {
3287 wpa_s->sme.prev_bssid_set = 0;
3288 #endif /* CONFIG_SME */
3289 wpa_sm_set_config(wpa_s->wpa, NULL);
3290 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
3291 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3292 wpa_s->own_disconnect_req = 1;
3293 wpa_supplicant_deauthenticate(
3294 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3296 ssid = wpa_s->conf->ssid;
3298 struct wpa_ssid *remove_ssid = ssid;
3301 if (wpa_s->last_ssid == remove_ssid)
3302 wpa_s->last_ssid = NULL;
3303 wpas_notify_network_removed(wpa_s, remove_ssid);
3304 wpa_config_remove_network(wpa_s->conf, id);
3310 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3312 result = wpa_supplicant_remove_network(wpa_s, id);
3314 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3319 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3320 "network id=%d", id);
3327 static int wpa_supplicant_ctrl_iface_update_network(
3328 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3329 char *name, char *value)
3333 ret = wpa_config_set(ssid, name, value, 0);
3335 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3336 "variable '%s'", name);
3340 return 0; /* No change to the previously configured value */
3342 if (os_strcmp(name, "bssid") != 0 &&
3343 os_strcmp(name, "bssid_hint") != 0 &&
3344 os_strcmp(name, "priority") != 0) {
3345 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3347 if (wpa_s->current_ssid == ssid ||
3348 wpa_s->current_ssid == NULL) {
3350 * Invalidate the EAP session cache if anything in the
3351 * current or previously used configuration changes.
3353 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3357 if ((os_strcmp(name, "psk") == 0 &&
3358 value[0] == '"' && ssid->ssid_len) ||
3359 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3360 wpa_config_update_psk(ssid);
3361 else if (os_strcmp(name, "priority") == 0)
3362 wpa_config_update_prio_list(wpa_s->conf);
3368 static int wpa_supplicant_ctrl_iface_set_network(
3369 struct wpa_supplicant *wpa_s, char *cmd)
3371 int id, ret, prev_bssid_set, prev_disabled;
3372 struct wpa_ssid *ssid;
3374 u8 prev_bssid[ETH_ALEN];
3376 /* cmd: "<network id> <variable name> <value>" */
3377 name = os_strchr(cmd, ' ');
3382 value = os_strchr(name, ' ');
3388 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3390 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3391 (u8 *) value, os_strlen(value));
3393 ssid = wpa_config_get_network(wpa_s->conf, id);
3395 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3400 prev_bssid_set = ssid->bssid_set;
3401 prev_disabled = ssid->disabled;
3402 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3403 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3406 (ssid->bssid_set != prev_bssid_set ||
3407 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3408 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
3410 if (prev_disabled != ssid->disabled &&
3411 (prev_disabled == 2 || ssid->disabled == 2))
3412 wpas_notify_network_type_changed(wpa_s, ssid);
3418 static int wpa_supplicant_ctrl_iface_get_network(
3419 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3423 struct wpa_ssid *ssid;
3426 /* cmd: "<network id> <variable name>" */
3427 name = os_strchr(cmd, ' ');
3428 if (name == NULL || buflen == 0)
3433 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3436 ssid = wpa_config_get_network(wpa_s->conf, id);
3438 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
3443 value = wpa_config_get_no_key(ssid, name);
3444 if (value == NULL) {
3445 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
3446 "variable '%s'", name);
3450 res = os_strlcpy(buf, value, buflen);
3451 if (res >= buflen) {
3462 static int wpa_supplicant_ctrl_iface_dup_network(
3463 struct wpa_supplicant *wpa_s, char *cmd,
3464 struct wpa_supplicant *dst_wpa_s)
3466 struct wpa_ssid *ssid_s, *ssid_d;
3467 char *name, *id, *value;
3468 int id_s, id_d, ret;
3470 /* cmd: "<src network id> <dst network id> <variable name>" */
3471 id = os_strchr(cmd, ' ');
3476 name = os_strchr(id, ' ');
3484 wpa_printf(MSG_DEBUG,
3485 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3486 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
3488 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3489 if (ssid_s == NULL) {
3490 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3491 "network id=%d", id_s);
3495 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
3496 if (ssid_d == NULL) {
3497 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3498 "network id=%d", id_d);
3502 value = wpa_config_get(ssid_s, name);
3503 if (value == NULL) {
3504 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3505 "variable '%s'", name);
3509 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
3518 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3519 char *buf, size_t buflen)
3522 struct wpa_cred *cred;
3527 ret = os_snprintf(pos, end - pos,
3528 "cred id / realm / username / domain / imsi\n");
3529 if (os_snprintf_error(end - pos, ret))
3533 cred = wpa_s->conf->cred;
3535 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3536 cred->id, cred->realm ? cred->realm : "",
3537 cred->username ? cred->username : "",
3538 cred->domain ? cred->domain[0] : "",
3539 cred->imsi ? cred->imsi : "");
3540 if (os_snprintf_error(end - pos, ret))
3551 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3552 char *buf, size_t buflen)
3554 struct wpa_cred *cred;
3557 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3559 cred = wpa_config_add_cred(wpa_s->conf);
3563 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3565 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
3566 if (os_snprintf_error(buflen, ret))
3572 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3573 struct wpa_cred *cred)
3575 struct wpa_ssid *ssid;
3580 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3585 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3586 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3590 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3592 /* Remove any network entry created based on the removed credential */
3593 ssid = wpa_s->conf->ssid;
3595 if (ssid->parent_cred == cred) {
3598 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3599 "used the removed credential", ssid->id);
3600 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3601 if (os_snprintf_error(sizeof(str), res))
3602 str[sizeof(str) - 1] = '\0';
3604 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3613 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3617 struct wpa_cred *cred, *prev;
3619 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3620 * "provisioning_sp=<FQDN> */
3621 if (os_strcmp(cmd, "all") == 0) {
3622 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3623 cred = wpa_s->conf->cred;
3627 wpas_ctrl_remove_cred(wpa_s, prev);
3632 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3633 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3635 cred = wpa_s->conf->cred;
3641 for (i = 0; i < prev->num_domain; i++) {
3642 if (os_strcmp(prev->domain[i], cmd + 8)
3645 wpas_ctrl_remove_cred(wpa_s, prev);
3653 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3654 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3656 cred = wpa_s->conf->cred;
3660 if (prev->provisioning_sp &&
3661 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3662 wpas_ctrl_remove_cred(wpa_s, prev);
3668 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3670 cred = wpa_config_get_cred(wpa_s->conf, id);
3671 return wpas_ctrl_remove_cred(wpa_s, cred);
3675 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3679 struct wpa_cred *cred;
3682 /* cmd: "<cred id> <variable name> <value>" */
3683 name = os_strchr(cmd, ' ');
3688 value = os_strchr(name, ' ');
3694 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3696 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3697 (u8 *) value, os_strlen(value));
3699 cred = wpa_config_get_cred(wpa_s->conf, id);
3701 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3706 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3707 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3708 "variable '%s'", name);
3712 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3718 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3719 char *cmd, char *buf,
3724 struct wpa_cred *cred;
3727 /* cmd: "<cred id> <variable name>" */
3728 name = os_strchr(cmd, ' ');
3734 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3737 cred = wpa_config_get_cred(wpa_s->conf, id);
3739 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3744 value = wpa_config_get_cred_no_key(cred, name);
3745 if (value == NULL) {
3746 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3751 res = os_strlcpy(buf, value, buflen);
3752 if (res >= buflen) {
3763 #ifndef CONFIG_NO_CONFIG_WRITE
3764 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3768 if (!wpa_s->conf->update_config) {
3769 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3770 "to update configuration (update_config=0)");
3774 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3776 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3777 "update configuration");
3779 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3785 #endif /* CONFIG_NO_CONFIG_WRITE */
3788 struct cipher_info {
3794 static const struct cipher_info ciphers[] = {
3795 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3796 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3797 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3798 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3799 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3800 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3801 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3802 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3805 static const struct cipher_info ciphers_group_mgmt[] = {
3806 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3807 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3808 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3809 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3813 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3814 struct wpa_driver_capa *capa,
3815 char *buf, size_t buflen)
3828 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3834 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3835 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3836 ret = os_snprintf(pos, end - pos, "%s%s",
3837 pos == buf ? "" : " ",
3839 if (os_snprintf_error(end - pos, ret))
3849 static int ctrl_iface_get_capability_group(int res, char *strict,
3850 struct wpa_driver_capa *capa,
3851 char *buf, size_t buflen)
3864 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3870 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3871 if (capa->enc & ciphers[i].capa) {
3872 ret = os_snprintf(pos, end - pos, "%s%s",
3873 pos == buf ? "" : " ",
3875 if (os_snprintf_error(end - pos, ret))
3885 static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3886 struct wpa_driver_capa *capa,
3887 char *buf, size_t buflen)
3899 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3900 if (capa->enc & ciphers_group_mgmt[i].capa) {
3901 ret = os_snprintf(pos, end - pos, "%s%s",
3902 pos == buf ? "" : " ",
3903 ciphers_group_mgmt[i].name);
3904 if (os_snprintf_error(end - pos, ret))
3914 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3915 struct wpa_driver_capa *capa,
3916 char *buf, size_t buflen)
3928 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3935 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3936 if (os_snprintf_error(end - pos, ret))
3940 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3941 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3942 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3943 if (os_snprintf_error(end - pos, ret))
3948 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3949 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3950 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3951 if (os_snprintf_error(end - pos, ret))
3956 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3957 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3958 if (os_snprintf_error(end - pos, ret))
3963 #ifdef CONFIG_SUITEB
3964 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
3965 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
3966 if (os_snprintf_error(end - pos, ret))
3970 #endif /* CONFIG_SUITEB */
3971 #ifdef CONFIG_SUITEB192
3972 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
3973 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
3974 if (os_snprintf_error(end - pos, ret))
3978 #endif /* CONFIG_SUITEB192 */
3980 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
3981 ret = os_snprintf(pos, end - pos, " OWE");
3982 if (os_snprintf_error(end - pos, ret))
3986 #endif /* CONFIG_OWE */
3988 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
3989 ret = os_snprintf(pos, end - pos, " DPP");
3990 if (os_snprintf_error(end - pos, ret))
3994 #endif /* CONFIG_DPP */
3996 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
3997 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
3998 if (os_snprintf_error(end - pos, ret))
4002 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
4003 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4004 if (os_snprintf_error(end - pos, ret))
4008 #ifdef CONFIG_IEEE80211R
4009 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
4010 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4011 if (os_snprintf_error(end - pos, ret))
4015 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
4016 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4017 if (os_snprintf_error(end - pos, ret))
4021 #endif /* CONFIG_IEEE80211R */
4022 #endif /* CONFIG_FILS */
4023 #ifdef CONFIG_IEEE80211R
4024 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
4025 ret = os_snprintf(pos, end - pos, " FT-PSK");
4026 if (os_snprintf_error(end - pos, ret))
4030 #endif /* CONFIG_IEEE80211R */
4032 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
4033 ret = os_snprintf(pos, end - pos, " SAE");
4034 if (os_snprintf_error(end - pos, ret))
4038 #endif /* CONFIG_SAE */
4044 static int ctrl_iface_get_capability_proto(int res, char *strict,
4045 struct wpa_driver_capa *capa,
4046 char *buf, size_t buflen)
4058 len = os_strlcpy(buf, "RSN WPA", buflen);
4064 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4065 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4066 ret = os_snprintf(pos, end - pos, "%sRSN",
4067 pos == buf ? "" : " ");
4068 if (os_snprintf_error(end - pos, ret))
4073 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4074 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
4075 ret = os_snprintf(pos, end - pos, "%sWPA",
4076 pos == buf ? "" : " ");
4077 if (os_snprintf_error(end - pos, ret))
4086 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4087 int res, char *strict,
4088 struct wpa_driver_capa *capa,
4089 char *buf, size_t buflen)
4101 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4107 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
4108 ret = os_snprintf(pos, end - pos, "%sOPEN",
4109 pos == buf ? "" : " ");
4110 if (os_snprintf_error(end - pos, ret))
4115 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4116 ret = os_snprintf(pos, end - pos, "%sSHARED",
4117 pos == buf ? "" : " ");
4118 if (os_snprintf_error(end - pos, ret))
4123 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
4124 ret = os_snprintf(pos, end - pos, "%sLEAP",
4125 pos == buf ? "" : " ");
4126 if (os_snprintf_error(end - pos, ret))
4132 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4133 ret = os_snprintf(pos, end - pos, "%sSAE",
4134 pos == buf ? "" : " ");
4135 if (os_snprintf_error(end - pos, ret))
4139 #endif /* CONFIG_SAE */
4142 if (wpa_is_fils_supported(wpa_s)) {
4143 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4144 pos == buf ? "" : " ");
4145 if (os_snprintf_error(end - pos, ret))
4150 #ifdef CONFIG_FILS_SK_PFS
4151 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4152 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4153 pos == buf ? "" : " ");
4154 if (os_snprintf_error(end - pos, ret))
4158 #endif /* CONFIG_FILS_SK_PFS */
4159 #endif /* CONFIG_FILS */
4165 static int ctrl_iface_get_capability_modes(int res, char *strict,
4166 struct wpa_driver_capa *capa,
4167 char *buf, size_t buflen)
4179 len = os_strlcpy(buf, "IBSS AP", buflen);
4185 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
4186 ret = os_snprintf(pos, end - pos, "%sIBSS",
4187 pos == buf ? "" : " ");
4188 if (os_snprintf_error(end - pos, ret))
4193 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
4194 ret = os_snprintf(pos, end - pos, "%sAP",
4195 pos == buf ? "" : " ");
4196 if (os_snprintf_error(end - pos, ret))
4202 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4203 ret = os_snprintf(pos, end - pos, "%sMESH",
4204 pos == buf ? "" : " ");
4205 if (os_snprintf_error(end - pos, ret))
4209 #endif /* CONFIG_MESH */
4215 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4216 char *buf, size_t buflen)
4218 struct hostapd_channel_data *chnl;
4220 char *pos, *end, *hmode;
4225 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4226 switch (wpa_s->hw.modes[j].mode) {
4227 case HOSTAPD_MODE_IEEE80211B:
4230 case HOSTAPD_MODE_IEEE80211G:
4233 case HOSTAPD_MODE_IEEE80211A:
4236 case HOSTAPD_MODE_IEEE80211AD:
4242 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
4243 if (os_snprintf_error(end - pos, ret))
4246 chnl = wpa_s->hw.modes[j].channels;
4247 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4248 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4250 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
4251 if (os_snprintf_error(end - pos, ret))
4255 ret = os_snprintf(pos, end - pos, "\n");
4256 if (os_snprintf_error(end - pos, ret))
4265 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4266 char *buf, size_t buflen)
4268 struct hostapd_channel_data *chnl;
4270 char *pos, *end, *hmode;
4275 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4276 switch (wpa_s->hw.modes[j].mode) {
4277 case HOSTAPD_MODE_IEEE80211B:
4280 case HOSTAPD_MODE_IEEE80211G:
4283 case HOSTAPD_MODE_IEEE80211A:
4286 case HOSTAPD_MODE_IEEE80211AD:
4292 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4294 if (os_snprintf_error(end - pos, ret))
4297 chnl = wpa_s->hw.modes[j].channels;
4298 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4299 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4301 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
4302 chnl[i].chan, chnl[i].freq,
4303 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4305 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4308 if (os_snprintf_error(end - pos, ret))
4312 ret = os_snprintf(pos, end - pos, "\n");
4313 if (os_snprintf_error(end - pos, ret))
4322 static int wpa_supplicant_ctrl_iface_get_capability(
4323 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4326 struct wpa_driver_capa capa;
4332 /* Determine whether or not strict checking was requested */
4333 len = os_strlcpy(field, _field, sizeof(field));
4334 if (len >= sizeof(field))
4336 strict = os_strchr(field, ' ');
4337 if (strict != NULL) {
4339 if (os_strcmp(strict, "strict") != 0)
4343 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4344 field, strict ? strict : "");
4346 if (os_strcmp(field, "eap") == 0) {
4347 return eap_get_names(buf, buflen);
4350 res = wpa_drv_get_capa(wpa_s, &capa);
4352 if (os_strcmp(field, "pairwise") == 0)
4353 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4356 if (os_strcmp(field, "group") == 0)
4357 return ctrl_iface_get_capability_group(res, strict, &capa,
4360 if (os_strcmp(field, "group_mgmt") == 0)
4361 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4364 if (os_strcmp(field, "key_mgmt") == 0)
4365 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4368 if (os_strcmp(field, "proto") == 0)
4369 return ctrl_iface_get_capability_proto(res, strict, &capa,
4372 if (os_strcmp(field, "auth_alg") == 0)
4373 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4374 &capa, buf, buflen);
4376 if (os_strcmp(field, "modes") == 0)
4377 return ctrl_iface_get_capability_modes(res, strict, &capa,
4380 if (os_strcmp(field, "channels") == 0)
4381 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4383 if (os_strcmp(field, "freq") == 0)
4384 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4387 if (os_strcmp(field, "tdls") == 0)
4388 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4389 #endif /* CONFIG_TDLS */
4392 if (os_strcmp(field, "erp") == 0) {
4393 res = os_snprintf(buf, buflen, "ERP");
4394 if (os_snprintf_error(buflen, res))
4398 #endif /* CONFIG_EPR */
4401 if (os_strcmp(field, "fips") == 0) {
4402 res = os_snprintf(buf, buflen, "FIPS");
4403 if (os_snprintf_error(buflen, res))
4407 #endif /* CONFIG_FIPS */
4410 if (os_strcmp(field, "acs") == 0) {
4411 res = os_snprintf(buf, buflen, "ACS");
4412 if (os_snprintf_error(buflen, res))
4416 #endif /* CONFIG_ACS */
4419 if (os_strcmp(field, "fils") == 0) {
4420 #ifdef CONFIG_FILS_SK_PFS
4421 if (wpa_is_fils_supported(wpa_s) &&
4422 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4423 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4424 if (os_snprintf_error(buflen, res))
4428 #endif /* CONFIG_FILS_SK_PFS */
4430 if (wpa_is_fils_supported(wpa_s)) {
4431 res = os_snprintf(buf, buflen, "FILS");
4432 if (os_snprintf_error(buflen, res))
4437 #endif /* CONFIG_FILS */
4439 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4440 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4441 if (os_snprintf_error(buflen, res))
4447 if (os_strcmp(field, "dpp") == 0) {
4449 res = os_snprintf(buf, buflen, "DPP=2");
4450 #else /* CONFIG_DPP2 */
4451 res = os_snprintf(buf, buflen, "DPP=1");
4452 #endif /* CONFIG_DPP2 */
4453 if (os_snprintf_error(buflen, res))
4457 #endif /* CONFIG_DPP */
4459 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4466 #ifdef CONFIG_INTERWORKING
4467 static char * anqp_add_hex(char *pos, char *end, const char *title,
4468 struct wpabuf *data)
4478 ret = os_snprintf(pos, end - pos, "%s=", title);
4479 if (os_snprintf_error(end - pos, ret))
4483 d = wpabuf_head_u8(data);
4484 for (i = 0; i < wpabuf_len(data); i++) {
4485 ret = os_snprintf(pos, end - pos, "%02x", *d++);
4486 if (os_snprintf_error(end - pos, ret))
4491 ret = os_snprintf(pos, end - pos, "\n");
4492 if (os_snprintf_error(end - pos, ret))
4498 #endif /* CONFIG_INTERWORKING */
4502 static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4505 const u8 *ie, *ie_end;
4509 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4512 ie_end = ie + 2 + ie[1];
4514 if (ie_end - ie < 2)
4517 info = WPA_GET_LE16(ie);
4519 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4520 if (os_snprintf_error(end - pos, ret))
4524 if (info & BIT(7)) {
4525 /* Cache Identifier Included */
4526 if (ie_end - ie < 2)
4528 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4530 if (os_snprintf_error(end - pos, ret))
4536 if (info & BIT(8)) {
4537 /* HESSID Included */
4538 if (ie_end - ie < ETH_ALEN)
4540 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4542 if (os_snprintf_error(end - pos, ret))
4548 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4550 if (ie_end - ie < realms * 2)
4552 ret = os_snprintf(pos, end - pos, "fils_realms=");
4553 if (os_snprintf_error(end - pos, ret))
4557 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4562 ret = os_snprintf(pos, end - pos, "\n");
4563 if (os_snprintf_error(end - pos, ret))
4570 #endif /* CONFIG_FILS */
4573 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4574 unsigned long mask, char *buf, size_t buflen)
4579 const u8 *ie, *ie2, *osen_ie, *mesh, *owe;
4584 if (mask & WPA_BSS_MASK_ID) {
4585 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
4586 if (os_snprintf_error(end - pos, ret))
4591 if (mask & WPA_BSS_MASK_BSSID) {
4592 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4593 MAC2STR(bss->bssid));
4594 if (os_snprintf_error(end - pos, ret))
4599 if (mask & WPA_BSS_MASK_FREQ) {
4600 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
4601 if (os_snprintf_error(end - pos, ret))
4606 if (mask & WPA_BSS_MASK_BEACON_INT) {
4607 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4609 if (os_snprintf_error(end - pos, ret))
4614 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4615 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4617 if (os_snprintf_error(end - pos, ret))
4622 if (mask & WPA_BSS_MASK_QUAL) {
4623 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
4624 if (os_snprintf_error(end - pos, ret))
4629 if (mask & WPA_BSS_MASK_NOISE) {
4630 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
4631 if (os_snprintf_error(end - pos, ret))
4636 if (mask & WPA_BSS_MASK_LEVEL) {
4637 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
4638 if (os_snprintf_error(end - pos, ret))
4643 if (mask & WPA_BSS_MASK_TSF) {
4644 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4645 (unsigned long long) bss->tsf);
4646 if (os_snprintf_error(end - pos, ret))
4651 if (mask & WPA_BSS_MASK_AGE) {
4652 struct os_reltime now;
4654 os_get_reltime(&now);
4655 ret = os_snprintf(pos, end - pos, "age=%d\n",
4656 (int) (now.sec - bss->last_update.sec));
4657 if (os_snprintf_error(end - pos, ret))
4662 if (mask & WPA_BSS_MASK_IE) {
4663 ret = os_snprintf(pos, end - pos, "ie=");
4664 if (os_snprintf_error(end - pos, ret))
4668 ie = (const u8 *) (bss + 1);
4669 for (i = 0; i < bss->ie_len; i++) {
4670 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4671 if (os_snprintf_error(end - pos, ret))
4676 ret = os_snprintf(pos, end - pos, "\n");
4677 if (os_snprintf_error(end - pos, ret))
4682 if (mask & WPA_BSS_MASK_FLAGS) {
4683 ret = os_snprintf(pos, end - pos, "flags=");
4684 if (os_snprintf_error(end - pos, ret))
4688 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
4690 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4692 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4694 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4696 pos = wpa_supplicant_ie_txt(pos, end,
4697 mesh ? "RSN" : "WPA2", ie2,
4699 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4701 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4702 osen_ie, 2 + osen_ie[1]);
4703 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
4707 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4708 if (os_snprintf_error(end - pos, ret))
4712 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
4713 if (!ie && !ie2 && !osen_ie &&
4714 (bss->caps & IEEE80211_CAP_PRIVACY)) {
4715 ret = os_snprintf(pos, end - pos, "[WEP]");
4716 if (os_snprintf_error(end - pos, ret))
4722 ret = os_snprintf(pos, end - pos, "[MESH]");
4723 if (os_snprintf_error(end - pos, ret))
4728 if (bss_is_dmg(bss)) {
4730 ret = os_snprintf(pos, end - pos, "[DMG]");
4731 if (os_snprintf_error(end - pos, ret))
4734 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4735 case IEEE80211_CAP_DMG_IBSS:
4738 case IEEE80211_CAP_DMG_AP:
4741 case IEEE80211_CAP_DMG_PBSS:
4748 ret = os_snprintf(pos, end - pos, "%s", s);
4749 if (os_snprintf_error(end - pos, ret))
4753 if (bss->caps & IEEE80211_CAP_IBSS) {
4754 ret = os_snprintf(pos, end - pos, "[IBSS]");
4755 if (os_snprintf_error(end - pos, ret))
4759 if (bss->caps & IEEE80211_CAP_ESS) {
4760 ret = os_snprintf(pos, end - pos, "[ESS]");
4761 if (os_snprintf_error(end - pos, ret))
4766 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4767 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
4768 ret = os_snprintf(pos, end - pos, "[P2P]");
4769 if (os_snprintf_error(end - pos, ret))
4774 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4775 ret = os_snprintf(pos, end - pos, "[HS20]");
4776 if (os_snprintf_error(end - pos, ret))
4780 #endif /* CONFIG_HS20 */
4782 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
4783 ret = os_snprintf(pos, end - pos, "[FILS]");
4784 if (os_snprintf_error(end - pos, ret))
4788 #endif /* CONFIG_FILS */
4790 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
4791 ret = os_snprintf(pos, end - pos, "[FST]");
4792 if (os_snprintf_error(end - pos, ret))
4796 #endif /* CONFIG_FST */
4797 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
4798 ret = os_snprintf(pos, end - pos, "[UTF-8]");
4799 if (os_snprintf_error(end - pos, ret))
4804 ret = os_snprintf(pos, end - pos, "\n");
4805 if (os_snprintf_error(end - pos, ret))
4810 if (mask & WPA_BSS_MASK_SSID) {
4811 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4812 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4813 if (os_snprintf_error(end - pos, ret))
4819 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4820 ie = (const u8 *) (bss + 1);
4821 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
4822 if (ret >= end - pos)
4827 #endif /* CONFIG_WPS */
4830 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4831 ie = (const u8 *) (bss + 1);
4832 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
4833 if (ret >= end - pos)
4838 #endif /* CONFIG_P2P */
4840 #ifdef CONFIG_WIFI_DISPLAY
4841 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4843 ie = (const u8 *) (bss + 1);
4844 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4845 WFD_IE_VENDOR_TYPE);
4847 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
4848 if (os_snprintf_error(end - pos, ret)) {
4854 pos += wpa_snprintf_hex(pos, end - pos,
4859 ret = os_snprintf(pos, end - pos, "\n");
4860 if (os_snprintf_error(end - pos, ret))
4865 #endif /* CONFIG_WIFI_DISPLAY */
4867 #ifdef CONFIG_INTERWORKING
4868 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4869 struct wpa_bss_anqp *anqp = bss->anqp;
4870 struct wpa_bss_anqp_elem *elem;
4872 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4873 anqp->capability_list);
4874 pos = anqp_add_hex(pos, end, "anqp_venue_name",
4876 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
4877 anqp->network_auth_type);
4878 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
4879 anqp->roaming_consortium);
4880 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
4881 anqp->ip_addr_type_availability);
4882 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
4884 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
4885 pos = anqp_add_hex(pos, end, "anqp_domain_name",
4887 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
4888 anqp->fils_realm_info);
4890 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4891 anqp->hs20_capability_list);
4892 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
4893 anqp->hs20_operator_friendly_name);
4894 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
4895 anqp->hs20_wan_metrics);
4896 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
4897 anqp->hs20_connection_capability);
4898 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4899 anqp->hs20_operating_class);
4900 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4901 anqp->hs20_osu_providers_list);
4902 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
4903 anqp->hs20_operator_icon_metadata);
4904 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
4905 anqp->hs20_osu_providers_nai_list);
4906 #endif /* CONFIG_HS20 */
4908 dl_list_for_each(elem, &anqp->anqp_elems,
4909 struct wpa_bss_anqp_elem, list) {
4912 os_snprintf(title, sizeof(title), "anqp[%u]",
4914 pos = anqp_add_hex(pos, end, title, elem->payload);
4917 #endif /* CONFIG_INTERWORKING */
4920 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4921 ie = (const u8 *) (bss + 1);
4922 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
4923 if (ret >= end - pos)
4928 #endif /* CONFIG_MESH */
4930 if (mask & WPA_BSS_MASK_SNR) {
4931 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
4932 if (os_snprintf_error(end - pos, ret))
4937 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
4938 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
4939 bss->est_throughput);
4940 if (os_snprintf_error(end - pos, ret))
4946 if (mask & WPA_BSS_MASK_FST) {
4947 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
4948 if (ret < 0 || ret >= end - pos)
4952 #endif /* CONFIG_FST */
4954 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
4955 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
4956 bss->last_update_idx);
4957 if (os_snprintf_error(end - pos, ret))
4962 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
4963 ret = os_snprintf(pos, end - pos, "beacon_ie=");
4964 if (os_snprintf_error(end - pos, ret))
4968 ie = (const u8 *) (bss + 1);
4970 for (i = 0; i < bss->beacon_ie_len; i++) {
4971 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4972 if (os_snprintf_error(end - pos, ret))
4977 ret = os_snprintf(pos, end - pos, "\n");
4978 if (os_snprintf_error(end - pos, ret))
4984 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
4985 ret = print_fils_indication(bss, pos, end);
4990 #endif /* CONFIG_FILS */
4992 if (mask & WPA_BSS_MASK_DELIM) {
4993 ret = os_snprintf(pos, end - pos, "====\n");
4994 if (os_snprintf_error(end - pos, ret))
5003 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5004 const char *cmd, char *buf,
5009 struct wpa_bss *bss;
5010 struct wpa_bss *bsslast = NULL;
5011 struct dl_list *next;
5014 char *ctmp, *end = buf + buflen;
5015 unsigned long mask = WPA_BSS_MASK_ALL;
5017 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5018 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5019 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
5021 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5023 } else { /* N1-N2 */
5024 unsigned int id1, id2;
5026 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5027 wpa_printf(MSG_INFO, "Wrong BSS range "
5032 if (*(cmd + 6) == '-')
5035 id1 = atoi(cmd + 6);
5037 if (*ctmp >= '0' && *ctmp <= '9')
5040 id2 = (unsigned int) -1;
5041 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5042 if (id2 == (unsigned int) -1)
5043 bsslast = dl_list_last(&wpa_s->bss_id,
5047 bsslast = wpa_bss_get_id(wpa_s, id2);
5048 if (bsslast == NULL && bss && id2 > id1) {
5049 struct wpa_bss *tmp = bss;
5051 next = tmp->list_id.next;
5052 if (next == &wpa_s->bss_id)
5054 tmp = dl_list_entry(
5055 next, struct wpa_bss,
5064 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
5065 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
5066 else if (os_strncmp(cmd, "LAST", 4) == 0)
5067 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
5068 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5070 bss = wpa_bss_get_id(wpa_s, i);
5071 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5073 bss = wpa_bss_get_id(wpa_s, i);
5075 next = bss->list_id.next;
5076 if (next == &wpa_s->bss_id)
5079 bss = dl_list_entry(next, struct wpa_bss,
5082 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5083 bss = wpa_s->current_bss;
5085 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5086 if (hwaddr_aton(cmd + 13, bssid) == 0)
5087 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5090 #endif /* CONFIG_P2P */
5091 } else if (hwaddr_aton(cmd, bssid) == 0)
5092 bss = wpa_bss_get_bssid(wpa_s, bssid);
5094 struct wpa_bss *tmp;
5097 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5107 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5108 mask = strtoul(ctmp + 5, NULL, 0x10);
5110 mask = WPA_BSS_MASK_ALL;
5116 if (bsslast == NULL)
5119 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5123 if (bss == bsslast) {
5124 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5125 (bss == dl_list_last(&wpa_s->bss_id,
5126 struct wpa_bss, list_id))) {
5129 res = os_snprintf(buf - 5, end - buf + 5,
5131 if (os_snprintf_error(end - buf + 5, res)) {
5132 wpa_printf(MSG_DEBUG,
5133 "Could not add end delim");
5138 next = bss->list_id.next;
5139 if (next == &wpa_s->bss_id)
5141 bss = dl_list_entry(next, struct wpa_bss, list_id);
5142 } while (bss && len);
5148 static int wpa_supplicant_ctrl_iface_ap_scan(
5149 struct wpa_supplicant *wpa_s, char *cmd)
5151 int ap_scan = atoi(cmd);
5152 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5156 static int wpa_supplicant_ctrl_iface_scan_interval(
5157 struct wpa_supplicant *wpa_s, char *cmd)
5159 int scan_int = atoi(cmd);
5160 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
5164 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5165 struct wpa_supplicant *wpa_s, char *cmd)
5167 int expire_age = atoi(cmd);
5168 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5172 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5173 struct wpa_supplicant *wpa_s, char *cmd)
5175 int expire_count = atoi(cmd);
5176 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5180 static void wpa_supplicant_ctrl_iface_bss_flush(
5181 struct wpa_supplicant *wpa_s, char *cmd)
5183 int flush_age = atoi(cmd);
5186 wpa_bss_flush(wpa_s);
5188 wpa_bss_flush_by_age(wpa_s, flush_age);
5192 #ifdef CONFIG_TESTING_OPTIONS
5193 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5195 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5196 /* MLME-DELETEKEYS.request */
5197 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
5198 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
5199 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
5200 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
5201 #ifdef CONFIG_IEEE80211W
5202 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
5203 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
5204 #endif /* CONFIG_IEEE80211W */
5206 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
5208 /* MLME-SETPROTECTION.request(None) */
5209 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5210 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5211 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5212 wpa_sm_drop_sa(wpa_s->wpa);
5214 #endif /* CONFIG_TESTING_OPTIONS */
5217 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5220 #ifdef CONFIG_NO_SCAN_PROCESSING
5222 #else /* CONFIG_NO_SCAN_PROCESSING */
5224 struct wpa_bss *bss;
5225 struct wpa_ssid *ssid = wpa_s->current_ssid;
5227 if (hwaddr_aton(addr, bssid)) {
5228 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5229 "address '%s'", addr);
5233 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5236 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5237 "configuration known for the target AP");
5241 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
5243 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5249 * TODO: Find best network configuration block from configuration to
5250 * allow roaming to other networks
5253 wpa_s->reassociate = 1;
5254 wpa_supplicant_connect(wpa_s, bss, ssid);
5257 #endif /* CONFIG_NO_SCAN_PROCESSING */
5262 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5264 unsigned int timeout = atoi(cmd);
5265 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
5266 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
5267 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
5269 unsigned int search_delay;
5270 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
5274 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5275 wpa_dbg(wpa_s, MSG_INFO,
5276 "Reject P2P_FIND since interface is disabled");
5279 if (os_strstr(cmd, "type=social"))
5280 type = P2P_FIND_ONLY_SOCIAL;
5281 else if (os_strstr(cmd, "type=progressive"))
5282 type = P2P_FIND_PROGRESSIVE;
5284 pos = os_strstr(cmd, "dev_id=");
5287 if (hwaddr_aton(pos, dev_id))
5292 pos = os_strstr(cmd, "dev_type=");
5295 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5297 _dev_type = dev_type;
5300 pos = os_strstr(cmd, "delay=");
5303 search_delay = atoi(pos);
5305 search_delay = wpas_p2p_search_delay(wpa_s);
5307 pos = os_strstr(cmd, "freq=");
5315 /* Must be searched for last, because it adds nul termination */
5316 pos = os_strstr(cmd, " seek=");
5319 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5322 _seek[seek_count++] = pos;
5324 term = os_strchr(pos, ' ');
5328 pos = os_strstr(term + 1, "seek=");
5332 if (seek_count > P2P_MAX_QUERY_HASH) {
5337 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
5338 _dev_id, search_delay, seek_count, seek, freq);
5342 static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5344 const char *last = NULL;
5349 /* Expected predefined CPT names delimited by ':' */
5350 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5351 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5352 wpa_printf(MSG_ERROR,
5353 "P2PS: CPT name list is too long, expected up to %d names",
5354 P2PS_FEATURE_CAPAB_CPT_MAX);
5359 token_len = last - token;
5361 if (token_len == 3 &&
5362 os_memcmp(token, "UDP", token_len) == 0) {
5363 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5364 } else if (token_len == 3 &&
5365 os_memcmp(token, "MAC", token_len) == 0) {
5366 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5368 wpa_printf(MSG_ERROR,
5369 "P2PS: Unsupported CPT name '%s'", token);
5374 if (isblank((unsigned char) *last)) {
5384 static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5386 struct p2ps_provision *p2ps_prov;
5388 size_t info_len = 0;
5390 u8 role = P2PS_SETUP_NONE;
5391 long long unsigned val;
5394 pos = os_strstr(cmd, "info=");
5397 info_len = os_strlen(pos);
5400 info = os_malloc(info_len + 1);
5402 info_len = utf8_unescape(pos, info_len,
5403 info, info_len + 1);
5409 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5410 if (p2ps_prov == NULL) {
5416 os_memcpy(p2ps_prov->info, info, info_len);
5417 p2ps_prov->info[info_len] = '\0';
5421 pos = os_strstr(cmd, "status=");
5423 p2ps_prov->status = atoi(pos + 7);
5425 p2ps_prov->status = -1;
5427 pos = os_strstr(cmd, "adv_id=");
5428 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5430 p2ps_prov->adv_id = val;
5432 pos = os_strstr(cmd, "method=");
5434 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5436 p2ps_prov->method = 0;
5438 pos = os_strstr(cmd, "session=");
5439 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5441 p2ps_prov->session_id = val;
5443 pos = os_strstr(cmd, "adv_mac=");
5444 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5447 pos = os_strstr(cmd, "session_mac=");
5448 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5451 pos = os_strstr(cmd, "cpt=");
5453 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5454 p2ps_prov->cpt_priority))
5457 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5460 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5461 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5463 /* force conncap with tstCap (no sanity checks) */
5464 pos = os_strstr(cmd, "tstCap=");
5466 role = strtol(pos + 7, NULL, 16);
5468 pos = os_strstr(cmd, "role=");
5470 role = strtol(pos + 5, NULL, 16);
5471 if (role != P2PS_SETUP_CLIENT &&
5472 role != P2PS_SETUP_GROUP_OWNER)
5473 role = P2PS_SETUP_NONE;
5476 p2ps_prov->role = role;
5486 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5489 struct p2ps_provision *p2ps_prov;
5492 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5494 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5496 if (hwaddr_aton(cmd, addr))
5503 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5507 if (p2ps_prov->status < 0) {
5512 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5517 static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5520 struct p2ps_provision *p2ps_prov;
5523 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5524 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5527 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5528 if (hwaddr_aton(cmd, addr))
5535 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5539 p2ps_prov->pd_seeker = 1;
5541 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5546 static int parse_freq(int chwidth, int freq2)
5551 return VHT_CHANWIDTH_80P80MHZ;
5557 return VHT_CHANWIDTH_USE_HT;
5559 return VHT_CHANWIDTH_80MHZ;
5561 return VHT_CHANWIDTH_160MHZ;
5563 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5570 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5571 char *buf, size_t buflen)
5576 enum p2p_wps_method wps_method;
5579 int persistent_group, persistent_id = -1;
5586 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
5587 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5588 size_t group_ssid_len = 0;
5591 if (!wpa_s->global->p2p_init_wpa_s)
5593 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5594 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5595 wpa_s->global->p2p_init_wpa_s->ifname);
5596 wpa_s = wpa_s->global->p2p_init_wpa_s;
5599 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5600 * [persistent|persistent=<network id>]
5601 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5602 * [ht40] [vht] [he] [auto] [ssid=<hexdump>] */
5604 if (hwaddr_aton(cmd, addr))
5612 persistent_group = os_strstr(pos, " persistent") != NULL;
5613 pos2 = os_strstr(pos, " persistent=");
5615 struct wpa_ssid *ssid;
5616 persistent_id = atoi(pos2 + 12);
5617 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5618 if (ssid == NULL || ssid->disabled != 2 ||
5619 ssid->mode != WPAS_MODE_P2P_GO) {
5620 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
5621 "SSID id=%d for persistent P2P group (GO)",
5626 join = os_strstr(pos, " join") != NULL;
5627 auth = os_strstr(pos, " auth") != NULL;
5628 automatic = os_strstr(pos, " auto") != NULL;
5629 pd = os_strstr(pos, " provdisc") != NULL;
5630 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5631 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5633 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
5635 pos2 = os_strstr(pos, " go_intent=");
5638 go_intent = atoi(pos2);
5639 if (go_intent < 0 || go_intent > 15)
5643 pos2 = os_strstr(pos, " freq=");
5651 pos2 = os_strstr(pos, " freq2=");
5653 freq2 = atoi(pos2 + 7);
5655 pos2 = os_strstr(pos, " max_oper_chwidth=");
5657 chwidth = atoi(pos2 + 18);
5659 max_oper_chwidth = parse_freq(chwidth, freq2);
5660 if (max_oper_chwidth < 0)
5663 pos2 = os_strstr(pos, " ssid=");
5668 end = os_strchr(pos2, ' ');
5670 group_ssid_len = os_strlen(pos2) / 2;
5672 group_ssid_len = (end - pos2) / 2;
5673 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
5674 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
5676 group_ssid = _group_ssid;
5679 if (os_strncmp(pos, "pin", 3) == 0) {
5680 /* Request random PIN (to be displayed) and enable the PIN */
5681 wps_method = WPS_PIN_DISPLAY;
5682 } else if (os_strncmp(pos, "pbc", 3) == 0) {
5683 wps_method = WPS_PBC;
5684 } else if (os_strstr(pos, "p2ps") != NULL) {
5685 wps_method = WPS_P2PS;
5688 pos = os_strchr(pin, ' ');
5689 wps_method = WPS_PIN_KEYPAD;
5692 if (os_strncmp(pos, "display", 7) == 0)
5693 wps_method = WPS_PIN_DISPLAY;
5695 if (!wps_pin_str_valid(pin)) {
5696 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
5701 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
5702 persistent_group, automatic, join,
5703 auth, go_intent, freq, freq2, persistent_id,
5704 pd, ht40, vht, max_oper_chwidth, he,
5705 group_ssid, group_ssid_len);
5706 if (new_pin == -2) {
5707 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5710 if (new_pin == -3) {
5711 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5716 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
5717 ret = os_snprintf(buf, buflen, "%08d", new_pin);
5718 if (os_snprintf_error(buflen, ret))
5723 os_memcpy(buf, "OK\n", 3);
5728 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
5730 unsigned int timeout = atoi(cmd);
5731 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5732 wpa_dbg(wpa_s, MSG_INFO,
5733 "Reject P2P_LISTEN since interface is disabled");
5736 return wpas_p2p_listen(wpa_s, timeout);
5740 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
5744 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
5746 /* <addr> <config method> [join|auto] */
5748 if (hwaddr_aton(cmd, addr))
5756 if (os_strstr(pos, " join") != NULL)
5757 use = WPAS_P2P_PD_FOR_JOIN;
5758 else if (os_strstr(pos, " auto") != NULL)
5759 use = WPAS_P2P_PD_AUTO;
5761 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
5765 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
5768 struct wpa_ssid *ssid = wpa_s->current_ssid;
5770 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
5771 ssid->passphrase == NULL)
5774 os_strlcpy(buf, ssid->passphrase, buflen);
5775 return os_strlen(buf);
5779 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
5780 char *buf, size_t buflen)
5784 u8 dst_buf[ETH_ALEN], *dst;
5785 struct wpabuf *tlvs;
5789 if (hwaddr_aton(cmd, dst_buf))
5792 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
5793 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
5800 if (os_strncmp(pos, "upnp ", 5) == 0) {
5803 if (hexstr2bin(pos, &version, 1) < 0)
5809 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
5810 #ifdef CONFIG_WIFI_DISPLAY
5811 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
5812 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
5813 #endif /* CONFIG_WIFI_DISPLAY */
5814 } else if (os_strncmp(pos, "asp ", 4) == 0) {
5816 char *svc_info = NULL;
5820 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
5823 pos = os_strchr(pos, ' ');
5824 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
5829 pos = os_strchr(svc_str, ' ');
5834 /* All remaining data is the svc_info string */
5835 if (pos && pos[0] && pos[0] != ' ') {
5836 len = os_strlen(pos);
5838 /* Unescape in place */
5839 len = utf8_unescape(pos, len, pos, len);
5846 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
5849 len = os_strlen(pos);
5853 tlvs = wpabuf_alloc(len);
5856 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
5861 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
5866 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
5867 if (os_snprintf_error(buflen, res))
5873 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5876 long long unsigned val;
5878 if (sscanf(cmd, "%llx", &val) != 1)
5881 return wpas_p2p_sd_cancel_request(wpa_s, req);
5885 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5890 struct wpabuf *resp_tlvs;
5894 pos = os_strchr(cmd, ' ');
5902 if (hwaddr_aton(pos, dst))
5909 pos2 = os_strchr(pos, ' ');
5913 dialog_token = atoi(pos);
5915 len = os_strlen(pos2);
5919 resp_tlvs = wpabuf_alloc(len);
5920 if (resp_tlvs == NULL)
5922 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
5923 wpabuf_free(resp_tlvs);
5927 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
5928 wpabuf_free(resp_tlvs);
5933 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
5936 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
5938 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
5943 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
5948 struct wpabuf *query, *resp;
5950 pos = os_strchr(cmd, ' ');
5955 len = os_strlen(cmd);
5959 query = wpabuf_alloc(len);
5962 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5967 len = os_strlen(pos);
5973 resp = wpabuf_alloc(len);
5978 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
5984 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
5993 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5998 pos = os_strchr(cmd, ' ');
6003 if (hexstr2bin(cmd, &version, 1) < 0)
6006 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6010 static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6011 u8 replace, char *cmd)
6015 u32 auto_accept, adv_id, svc_state, config_methods;
6016 char *svc_info = NULL;
6018 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
6020 pos = os_strchr(cmd, ' ');
6025 /* Auto-Accept value is mandatory, and must be one of the
6026 * single values (0, 1, 2, 4) */
6027 auto_accept = atoi(cmd);
6028 switch (auto_accept) {
6029 case P2PS_SETUP_NONE: /* No auto-accept */
6030 case P2PS_SETUP_NEW:
6031 case P2PS_SETUP_CLIENT:
6032 case P2PS_SETUP_GROUP_OWNER:
6038 /* Advertisement ID is mandatory */
6040 pos = os_strchr(cmd, ' ');
6045 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6046 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6049 /* Only allow replacements if exist, and adds if not */
6050 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6058 /* svc_state between 0 - 0xff is mandatory */
6059 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6062 pos = os_strchr(pos, ' ');
6066 /* config_methods is mandatory */
6068 if (sscanf(pos, "%x", &config_methods) != 1)
6071 if (!(config_methods &
6072 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6075 pos = os_strchr(pos, ' ');
6082 /* Advertisement string is mandatory */
6083 if (!pos[0] || pos[0] == ' ')
6086 /* Terminate svc string */
6087 pos = os_strchr(pos, ' ');
6091 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6093 pos = os_strchr(pos, ' ');
6097 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6100 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6104 /* Service and Response Information are optional */
6105 if (pos && pos[0]) {
6108 /* Note the bare ' included, which cannot exist legally
6109 * in unescaped string. */
6110 svc_info = os_strstr(pos, "svc_info='");
6114 len = os_strlen(svc_info);
6115 utf8_unescape(svc_info, len, svc_info, len);
6119 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6120 (u8) svc_state, (u16) config_methods,
6121 svc_info, cpt_prio);
6125 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6129 pos = os_strchr(cmd, ' ');
6134 if (os_strcmp(cmd, "bonjour") == 0)
6135 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6136 if (os_strcmp(cmd, "upnp") == 0)
6137 return p2p_ctrl_service_add_upnp(wpa_s, pos);
6138 if (os_strcmp(cmd, "asp") == 0)
6139 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
6140 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6145 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6149 struct wpabuf *query;
6152 len = os_strlen(cmd);
6156 query = wpabuf_alloc(len);
6159 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6164 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6170 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6175 pos = os_strchr(cmd, ' ');
6180 if (hexstr2bin(cmd, &version, 1) < 0)
6183 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6187 static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6191 if (os_strcmp(cmd, "all") == 0) {
6192 wpas_p2p_service_flush_asp(wpa_s);
6196 if (sscanf(cmd, "%x", &adv_id) != 1)
6199 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6203 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6207 pos = os_strchr(cmd, ' ');
6212 if (os_strcmp(cmd, "bonjour") == 0)
6213 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6214 if (os_strcmp(cmd, "upnp") == 0)
6215 return p2p_ctrl_service_del_upnp(wpa_s, pos);
6216 if (os_strcmp(cmd, "asp") == 0)
6217 return p2p_ctrl_service_del_asp(wpa_s, pos);
6218 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6223 static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6227 pos = os_strchr(cmd, ' ');
6232 if (os_strcmp(cmd, "asp") == 0)
6233 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6235 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6240 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6246 if (hwaddr_aton(cmd, addr))
6249 return wpas_p2p_reject(wpa_s, addr);
6253 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6257 struct wpa_ssid *ssid;
6258 u8 *_peer = NULL, peer[ETH_ALEN];
6259 int freq = 0, pref_freq = 0;
6260 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
6263 pos = os_strstr(cmd, " peer=");
6266 if (hwaddr_aton(pos, peer))
6270 ssid = wpa_config_get_network(wpa_s->conf, id);
6271 if (ssid == NULL || ssid->disabled != 2) {
6272 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6273 "for persistent P2P group",
6278 pos = os_strstr(cmd, " freq=");
6286 pos = os_strstr(cmd, " pref=");
6289 pref_freq = atoi(pos);
6294 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6295 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6297 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
6299 pos = os_strstr(cmd, "freq2=");
6301 freq2 = atoi(pos + 6);
6303 pos = os_strstr(cmd, " max_oper_chwidth=");
6305 chwidth = atoi(pos + 18);
6307 max_oper_chwidth = parse_freq(chwidth, freq2);
6308 if (max_oper_chwidth < 0)
6311 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
6312 max_oper_chwidth, pref_freq, he);
6316 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6319 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
6321 pos = os_strstr(cmd, " peer=");
6327 if (hwaddr_aton(pos, peer)) {
6328 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6332 pos = os_strstr(pos, " go_dev_addr=");
6335 if (hwaddr_aton(pos, go_dev_addr)) {
6336 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6340 go_dev = go_dev_addr;
6343 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6347 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6349 if (os_strncmp(cmd, "persistent=", 11) == 0)
6350 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6351 if (os_strncmp(cmd, "group=", 6) == 0)
6352 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6358 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
6359 int id, int freq, int vht_center_freq2,
6360 int ht40, int vht, int vht_chwidth,
6363 struct wpa_ssid *ssid;
6365 ssid = wpa_config_get_network(wpa_s->conf, id);
6366 if (ssid == NULL || ssid->disabled != 2) {
6367 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6368 "for persistent P2P group",
6373 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6374 vht_center_freq2, 0, ht40, vht,
6375 vht_chwidth, he, NULL, 0, 0);
6379 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6381 int freq = 0, persistent = 0, group_id = -1;
6382 int vht = wpa_s->conf->p2p_go_vht;
6383 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
6384 int he = wpa_s->conf->p2p_go_he;
6385 int max_oper_chwidth, chwidth = 0, freq2 = 0;
6386 char *token, *context = NULL;
6389 #endif /* CONFIG_ACS */
6391 while ((token = str_token(cmd, " ", &context))) {
6392 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
6393 sscanf(token, "persistent=%d", &group_id) == 1 ||
6394 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
6397 } else if (os_strcmp(token, "freq=acs") == 0) {
6399 #endif /* CONFIG_ACS */
6400 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6402 } else if (os_strcmp(token, "ht40") == 0) {
6404 } else if (os_strcmp(token, "vht") == 0) {
6407 } else if (os_strcmp(token, "he") == 0) {
6409 } else if (os_strcmp(token, "persistent") == 0) {
6412 wpa_printf(MSG_DEBUG,
6413 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6420 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6421 (acs || freq == 2 || freq == 5)) {
6422 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6423 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6424 wpa_s->p2p_go_do_acs = 1;
6426 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6427 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6428 wpa_s->p2p_go_do_acs = 1;
6431 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6432 wpa_s->p2p_go_do_acs = 1;
6435 wpa_s->p2p_go_do_acs = 0;
6437 #endif /* CONFIG_ACS */
6439 max_oper_chwidth = parse_freq(chwidth, freq2);
6440 if (max_oper_chwidth < 0)
6444 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
6445 freq, freq2, ht40, vht,
6446 max_oper_chwidth, he);
6448 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
6449 max_oper_chwidth, he);
6453 static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6454 char *buf, size_t buflen)
6456 u8 dev_addr[ETH_ALEN];
6457 struct wpa_ssid *ssid;
6461 ssid = wpa_s->current_ssid;
6462 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6463 hwaddr_aton(cmd, dev_addr))
6466 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6469 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6470 if (os_snprintf_error(buflen, res))
6476 static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6477 const u8 *p2p_dev_addr)
6479 struct wpa_supplicant *wpa_s;
6481 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6482 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6490 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6491 char *buf, size_t buflen)
6493 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
6495 const struct p2p_peer_info *info;
6497 char devtype[WPS_DEV_TYPE_BUFSIZE];
6498 struct wpa_ssid *ssid;
6501 if (!wpa_s->global->p2p)
6504 if (os_strcmp(cmd, "FIRST") == 0) {
6507 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6508 if (hwaddr_aton(cmd + 5, addr) < 0)
6513 if (hwaddr_aton(cmd, addr) < 0)
6519 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6522 group_capab = info->group_capab;
6525 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6526 wpa_printf(MSG_DEBUG,
6527 "P2P: Could not find any BSS with p2p_dev_addr "
6528 MACSTR ", hence override group_capab from 0x%x to 0",
6529 MAC2STR(info->p2p_device_addr), group_capab);
6536 res = os_snprintf(pos, end - pos, MACSTR "\n"
6542 "serial_number=%s\n"
6543 "config_methods=0x%x\n"
6545 "group_capab=0x%x\n"
6547 MAC2STR(info->p2p_device_addr),
6548 wps_dev_type_bin2str(info->pri_dev_type,
6549 devtype, sizeof(devtype)),
6554 info->serial_number,
6555 info->config_methods,
6559 if (os_snprintf_error(end - pos, res))
6563 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6566 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6567 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6568 wps_dev_type_bin2str(t, devtype,
6570 if (os_snprintf_error(end - pos, res))
6575 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
6577 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
6578 if (os_snprintf_error(end - pos, res))
6583 res = p2p_get_peer_info_txt(info, pos, end - pos);
6588 if (info->vendor_elems) {
6589 res = os_snprintf(pos, end - pos, "vendor_elems=");
6590 if (os_snprintf_error(end - pos, res))
6594 pos += wpa_snprintf_hex(pos, end - pos,
6595 wpabuf_head(info->vendor_elems),
6596 wpabuf_len(info->vendor_elems));
6598 res = os_snprintf(pos, end - pos, "\n");
6599 if (os_snprintf_error(end - pos, res))
6608 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6613 if (wpa_s->global->p2p == NULL)
6616 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
6619 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
6620 struct wpa_freq_range *freq;
6621 freq = &wpa_s->global->p2p_disallow_freq.range[i];
6622 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
6623 freq->min, freq->max);
6626 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
6631 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
6635 if (wpa_s->global->p2p == NULL)
6638 param = os_strchr(cmd, ' ');
6643 if (os_strcmp(cmd, "discoverability") == 0) {
6644 p2p_set_client_discoverability(wpa_s->global->p2p,
6649 if (os_strcmp(cmd, "managed") == 0) {
6650 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
6654 if (os_strcmp(cmd, "listen_channel") == 0) {
6656 u8 channel, op_class;
6658 channel = atoi(param);
6659 pos = os_strchr(param, ' ');
6660 op_class = pos ? atoi(pos) : 81;
6662 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
6666 if (os_strcmp(cmd, "ssid_postfix") == 0) {
6667 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
6671 if (os_strcmp(cmd, "noa") == 0) {
6673 int count, start, duration;
6674 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6675 count = atoi(param);
6676 pos = os_strchr(param, ',');
6681 pos = os_strchr(pos, ',');
6685 duration = atoi(pos);
6686 if (count < 0 || count > 255 || start < 0 || duration < 0)
6688 if (count == 0 && duration > 0)
6690 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6691 "start=%d duration=%d", count, start, duration);
6692 return wpas_p2p_set_noa(wpa_s, count, start, duration);
6695 if (os_strcmp(cmd, "ps") == 0)
6696 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
6698 if (os_strcmp(cmd, "oppps") == 0)
6699 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
6701 if (os_strcmp(cmd, "ctwindow") == 0)
6702 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
6704 if (os_strcmp(cmd, "disabled") == 0) {
6705 wpa_s->global->p2p_disabled = atoi(param);
6706 wpa_printf(MSG_DEBUG, "P2P functionality %s",
6707 wpa_s->global->p2p_disabled ?
6708 "disabled" : "enabled");
6709 if (wpa_s->global->p2p_disabled) {
6710 wpas_p2p_stop_find(wpa_s);
6711 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6712 p2p_flush(wpa_s->global->p2p);
6717 if (os_strcmp(cmd, "conc_pref") == 0) {
6718 if (os_strcmp(param, "sta") == 0)
6719 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
6720 else if (os_strcmp(param, "p2p") == 0)
6721 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
6723 wpa_printf(MSG_INFO, "Invalid conc_pref value");
6726 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
6731 if (os_strcmp(cmd, "force_long_sd") == 0) {
6732 wpa_s->force_long_sd = atoi(param);
6736 if (os_strcmp(cmd, "peer_filter") == 0) {
6738 if (hwaddr_aton(param, addr))
6740 p2p_set_peer_filter(wpa_s->global->p2p, addr);
6744 if (os_strcmp(cmd, "cross_connect") == 0)
6745 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
6747 if (os_strcmp(cmd, "go_apsd") == 0) {
6748 if (os_strcmp(param, "disable") == 0)
6749 wpa_s->set_ap_uapsd = 0;
6751 wpa_s->set_ap_uapsd = 1;
6752 wpa_s->ap_uapsd = atoi(param);
6757 if (os_strcmp(cmd, "client_apsd") == 0) {
6758 if (os_strcmp(param, "disable") == 0)
6759 wpa_s->set_sta_uapsd = 0;
6763 /* format: BE,BK,VI,VO;max SP Length */
6765 pos = os_strchr(param, ',');
6770 pos = os_strchr(pos, ',');
6775 pos = os_strchr(pos, ',');
6780 /* ignore max SP Length for now */
6782 wpa_s->set_sta_uapsd = 1;
6783 wpa_s->sta_uapsd = 0;
6785 wpa_s->sta_uapsd |= BIT(0);
6787 wpa_s->sta_uapsd |= BIT(1);
6789 wpa_s->sta_uapsd |= BIT(2);
6791 wpa_s->sta_uapsd |= BIT(3);
6796 if (os_strcmp(cmd, "disallow_freq") == 0)
6797 return p2p_ctrl_disallow_freq(wpa_s, param);
6799 if (os_strcmp(cmd, "disc_int") == 0) {
6800 int min_disc_int, max_disc_int, max_disc_tu;
6805 min_disc_int = atoi(pos);
6806 pos = os_strchr(pos, ' ');
6811 max_disc_int = atoi(pos);
6812 pos = os_strchr(pos, ' ');
6817 max_disc_tu = atoi(pos);
6819 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
6820 max_disc_int, max_disc_tu);
6823 if (os_strcmp(cmd, "per_sta_psk") == 0) {
6824 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
6828 #ifdef CONFIG_WPS_NFC
6829 if (os_strcmp(cmd, "nfc_tag") == 0)
6830 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
6831 #endif /* CONFIG_WPS_NFC */
6833 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
6834 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
6838 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
6841 op_class = atoi(param);
6842 param = os_strchr(param, ':');
6847 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
6852 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6859 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
6861 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6862 wpa_s->force_long_sd = 0;
6864 #ifdef CONFIG_TESTING_OPTIONS
6865 os_free(wpa_s->get_pref_freq_list_override);
6866 wpa_s->get_pref_freq_list_override = NULL;
6867 #endif /* CONFIG_TESTING_OPTIONS */
6869 wpas_p2p_stop_find(wpa_s);
6870 wpa_s->parent->p2ps_method_config_any = 0;
6871 if (wpa_s->global->p2p)
6872 p2p_flush(wpa_s->global->p2p);
6876 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
6879 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
6882 pos = os_strchr(cmd, ' ');
6888 pos2 = os_strchr(pos, ' ');
6896 pos = os_strchr(pos2, ' ');
6904 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
6908 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
6911 unsigned int period = 0, interval = 0;
6914 pos = os_strchr(cmd, ' ');
6919 interval = atoi(pos);
6922 return wpas_p2p_ext_listen(wpa_s, period, interval);
6926 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
6933 if (os_strncmp(pos, "iface=", 6) == 0) {
6937 if (hwaddr_aton(pos, peer))
6940 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
6945 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
6947 int freq = 0, period = 0, interval = 0, count = 0;
6949 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
6951 wpa_printf(MSG_DEBUG,
6952 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
6956 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
6959 #endif /* CONFIG_P2P */
6962 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
6964 struct wpa_freq_range_list ranges;
6966 struct hostapd_hw_modes *mode;
6969 if (wpa_s->hw.modes == NULL)
6972 os_memset(&ranges, 0, sizeof(ranges));
6973 if (freq_range_list_parse(&ranges, val) < 0)
6976 for (i = 0; i < wpa_s->hw.num_modes; i++) {
6979 mode = &wpa_s->hw.modes[i];
6980 for (j = 0; j < mode->num_channels; j++) {
6983 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
6986 freq = mode->channels[j].freq;
6987 if (!freq_range_list_includes(&ranges, freq))
6990 int_array_add_unique(&freqs, freq);
6994 os_free(ranges.range);
6999 #ifdef CONFIG_INTERWORKING
7001 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7009 auto_sel = os_strstr(param, "auto") != NULL;
7011 pos = os_strstr(param, "freq=");
7013 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7020 return interworking_select(wpa_s, auto_sel, freqs);
7024 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7028 struct wpa_bss *bss;
7030 if (hwaddr_aton(dst, bssid)) {
7031 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7035 bss = wpa_bss_get_bssid(wpa_s, bssid);
7037 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7042 if (bss->ssid_len == 0) {
7045 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7046 " does not have SSID information", MAC2STR(bssid));
7048 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7050 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7051 bss->ssid_len > 0) {
7059 wpa_printf(MSG_DEBUG,
7060 "Found another matching BSS entry with SSID");
7063 return interworking_connect(wpa_s, bss, only_add);
7067 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7069 u8 dst_addr[ETH_ALEN];
7072 #define MAX_ANQP_INFO_ID 100
7073 u16 id[MAX_ANQP_INFO_ID];
7076 u32 mbo_subtypes = 0;
7078 used = hwaddr_aton2(dst, dst_addr);
7084 while (num_id < MAX_ANQP_INFO_ID) {
7085 if (os_strncmp(pos, "hs20:", 5) == 0) {
7087 int num = atoi(pos + 5);
7088 if (num <= 0 || num > 31)
7090 subtypes |= BIT(num);
7091 #else /* CONFIG_HS20 */
7093 #endif /* CONFIG_HS20 */
7094 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7096 int num = atoi(pos + 4);
7098 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
7100 mbo_subtypes |= BIT(num);
7101 #else /* CONFIG_MBO */
7103 #endif /* CONFIG_MBO */
7105 id[num_id] = atoi(pos);
7109 pos = os_strchr(pos + 1, ',');
7115 if (num_id == 0 && !subtypes && !mbo_subtypes)
7118 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
7123 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7125 u8 dst_addr[ETH_ALEN];
7126 struct wpabuf *advproto, *query = NULL;
7131 used = hwaddr_aton2(cmd, dst_addr);
7139 /* Advertisement Protocol ID */
7140 end = os_strchr(pos, ' ');
7144 len = os_strlen(pos);
7150 advproto = wpabuf_alloc(len);
7151 if (advproto == NULL)
7153 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7157 /* Optional Query Request */
7162 len = os_strlen(pos);
7169 query = wpabuf_alloc(len);
7172 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7177 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7180 wpabuf_free(advproto);
7187 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7194 size_t resp_len, start, requested_len;
7195 struct wpabuf *resp;
7198 used = hwaddr_aton2(cmd, addr);
7205 dialog_token = atoi(pos);
7207 if (wpa_s->last_gas_resp &&
7208 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7209 dialog_token == wpa_s->last_gas_dialog_token)
7210 resp = wpa_s->last_gas_resp;
7211 else if (wpa_s->prev_gas_resp &&
7212 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7213 dialog_token == wpa_s->prev_gas_dialog_token)
7214 resp = wpa_s->prev_gas_resp;
7218 resp_len = wpabuf_len(resp);
7220 requested_len = resp_len;
7222 pos = os_strchr(pos, ' ');
7225 if (start > resp_len)
7226 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7227 pos = os_strchr(pos, ',');
7231 requested_len = atoi(pos);
7232 if (start + requested_len > resp_len)
7233 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7236 if (requested_len * 2 + 1 > buflen)
7237 return os_snprintf(buf, buflen, "FAIL-Too long response");
7239 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7242 if (start + requested_len == resp_len) {
7244 * Free memory by dropping the response after it has been
7247 if (resp == wpa_s->prev_gas_resp) {
7248 wpabuf_free(wpa_s->prev_gas_resp);
7249 wpa_s->prev_gas_resp = NULL;
7251 wpabuf_free(wpa_s->last_gas_resp);
7252 wpa_s->last_gas_resp = NULL;
7258 #endif /* CONFIG_INTERWORKING */
7263 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7265 u8 dst_addr[ETH_ALEN];
7270 used = hwaddr_aton2(dst, dst_addr);
7277 int num = atoi(pos);
7278 if (num <= 0 || num > 31)
7280 subtypes |= BIT(num);
7281 pos = os_strchr(pos + 1, ',');
7290 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
7294 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7295 const u8 *addr, const char *realm)
7301 rlen = os_strlen(realm);
7303 buf = os_malloc(len);
7306 buf[0] = 1; /* NAI Home Realm Count */
7307 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7309 os_memcpy(buf + 3, realm, rlen);
7311 ret = hs20_anqp_send_req(wpa_s, addr,
7312 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
7321 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7324 struct wpa_cred *cred = wpa_s->conf->cred;
7325 u8 dst_addr[ETH_ALEN];
7331 used = hwaddr_aton2(dst, dst_addr);
7335 while (dst[used] == ' ')
7337 if (os_strncmp(dst + used, "realm=", 6) == 0)
7338 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7341 len = os_strlen(dst + used);
7343 if (len == 0 && cred && cred->realm)
7344 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7349 buf = os_malloc(len);
7352 if (hexstr2bin(dst + used, buf, len) < 0) {
7357 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7358 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
7366 static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7369 u8 dst_addr[ETH_ALEN];
7371 char *ctx = NULL, *icon, *poffset, *psize;
7373 used = hwaddr_aton2(cmd, dst_addr);
7378 icon = str_token(cmd, " ", &ctx);
7379 poffset = str_token(cmd, " ", &ctx);
7380 psize = str_token(cmd, " ", &ctx);
7381 if (!icon || !poffset || !psize)
7384 wpa_s->fetch_osu_icon_in_progress = 0;
7385 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7390 static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7392 u8 dst_addr[ETH_ALEN];
7397 return hs20_del_icon(wpa_s, NULL, NULL);
7399 used = hwaddr_aton2(cmd, dst_addr);
7403 while (cmd[used] == ' ')
7405 icon = cmd[used] ? &cmd[used] : NULL;
7407 return hs20_del_icon(wpa_s, dst_addr, icon);
7411 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
7413 u8 dst_addr[ETH_ALEN];
7417 used = hwaddr_aton2(cmd, dst_addr);
7421 while (cmd[used] == ' ')
7425 wpa_s->fetch_osu_icon_in_progress = 0;
7426 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
7427 (u8 *) icon, os_strlen(icon), inmem);
7430 #endif /* CONFIG_HS20 */
7433 #ifdef CONFIG_AUTOSCAN
7435 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7438 enum wpa_states state = wpa_s->wpa_state;
7439 char *new_params = NULL;
7441 if (os_strlen(cmd) > 0) {
7442 new_params = os_strdup(cmd);
7443 if (new_params == NULL)
7447 os_free(wpa_s->conf->autoscan);
7448 wpa_s->conf->autoscan = new_params;
7450 if (wpa_s->conf->autoscan == NULL)
7451 autoscan_deinit(wpa_s);
7452 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7453 autoscan_init(wpa_s, 1);
7454 else if (state == WPA_SCANNING)
7455 wpa_supplicant_reinit_autoscan(wpa_s);
7457 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7458 wpa_supplicant_state_txt(state));
7463 #endif /* CONFIG_AUTOSCAN */
7468 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7474 struct wpabuf *tfs_req = NULL;
7476 if (os_strncmp(cmd, "enter", 5) == 0)
7478 else if (os_strncmp(cmd, "exit", 4) == 0)
7483 pos = os_strstr(cmd, " interval=");
7485 intval = atoi(pos + 10);
7487 pos = os_strstr(cmd, " tfs_req=");
7492 end = os_strchr(pos, ' ');
7496 len = os_strlen(pos);
7500 tfs_req = wpabuf_alloc(len);
7501 if (tfs_req == NULL)
7503 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7504 wpabuf_free(tfs_req);
7509 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7510 WNM_SLEEP_MODE_EXIT, intval,
7512 wpabuf_free(tfs_req);
7518 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7520 int query_reason, list = 0;
7521 char *btm_candidates = NULL;
7523 query_reason = atoi(cmd);
7525 cmd = os_strchr(cmd, ' ');
7527 if (os_strncmp(cmd, " list", 5) == 0)
7530 btm_candidates = cmd;
7533 wpa_printf(MSG_DEBUG,
7534 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7535 query_reason, list ? " candidate list" : "");
7537 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7543 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
7546 struct wpabuf *elems;
7549 elems = wpabuf_parse_bin(cmd);
7553 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
7558 #endif /* CONFIG_WNM */
7561 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7564 struct wpa_signal_info si;
7568 ret = wpa_drv_signal_poll(wpa_s, &si);
7575 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
7576 "NOISE=%d\nFREQUENCY=%u\n",
7577 si.current_signal, si.current_txrate / 1000,
7578 si.current_noise, si.frequency);
7579 if (os_snprintf_error(end - pos, ret))
7583 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7584 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
7585 channel_width_to_string(si.chanwidth));
7586 if (os_snprintf_error(end - pos, ret))
7591 if (si.center_frq1 > 0) {
7592 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
7594 if (os_snprintf_error(end - pos, ret))
7599 if (si.center_frq2 > 0) {
7600 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
7602 if (os_snprintf_error(end - pos, ret))
7607 if (si.avg_signal) {
7608 ret = os_snprintf(pos, end - pos,
7609 "AVG_RSSI=%d\n", si.avg_signal);
7610 if (os_snprintf_error(end - pos, ret))
7615 if (si.avg_beacon_signal) {
7616 ret = os_snprintf(pos, end - pos,
7617 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
7618 if (os_snprintf_error(end - pos, ret))
7627 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
7634 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
7635 wpa_printf(MSG_DEBUG,
7636 "Reject SIGNAL_MONITOR command - bgscan is active");
7639 pos = os_strstr(cmd, "THRESHOLD=");
7641 threshold = atoi(pos + 10);
7642 pos = os_strstr(cmd, "HYSTERESIS=");
7644 hysteresis = atoi(pos + 11);
7645 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
7649 #ifdef CONFIG_TESTING_OPTIONS
7650 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
7651 enum wpa_driver_if_type if_type,
7653 unsigned int *freq_list)
7655 char *pos = wpa_s->get_pref_freq_list_override;
7657 unsigned int count = 0;
7659 /* Override string format:
7660 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7663 if (atoi(pos) == (int) if_type)
7665 pos = os_strchr(pos, ' ');
7671 pos = os_strchr(pos, ':');
7675 end = os_strchr(pos, ' ');
7676 while (pos && (!end || pos < end) && count < *num) {
7677 freq_list[count++] = atoi(pos);
7678 pos = os_strchr(pos, ',');
7686 #endif /* CONFIG_TESTING_OPTIONS */
7689 static int wpas_ctrl_iface_get_pref_freq_list(
7690 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
7692 unsigned int freq_list[100], num = 100, i;
7694 enum wpa_driver_if_type iface_type;
7700 /* buf: "<interface_type>" */
7701 if (os_strcmp(cmd, "STATION") == 0)
7702 iface_type = WPA_IF_STATION;
7703 else if (os_strcmp(cmd, "AP") == 0)
7704 iface_type = WPA_IF_AP_BSS;
7705 else if (os_strcmp(cmd, "P2P_GO") == 0)
7706 iface_type = WPA_IF_P2P_GO;
7707 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
7708 iface_type = WPA_IF_P2P_CLIENT;
7709 else if (os_strcmp(cmd, "IBSS") == 0)
7710 iface_type = WPA_IF_IBSS;
7711 else if (os_strcmp(cmd, "TDLS") == 0)
7712 iface_type = WPA_IF_TDLS;
7716 wpa_printf(MSG_DEBUG,
7717 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7720 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
7724 for (i = 0; i < num; i++) {
7725 ret = os_snprintf(pos, end - pos, "%s%u",
7726 i > 0 ? "," : "", freq_list[i]);
7727 if (os_snprintf_error(end - pos, ret))
7736 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
7737 char *buf, size_t buflen)
7742 ret = os_snprintf(buf, buflen, "%016llX:\n",
7743 (long long unsigned) wpa_s->drv_flags);
7744 if (os_snprintf_error(buflen, ret))
7750 for (i = 0; i < 64; i++) {
7751 if (wpa_s->drv_flags & (1LLU << i)) {
7752 ret = os_snprintf(pos, end - pos, "%s\n",
7753 driver_flag_to_string(1LLU << i));
7754 if (os_snprintf_error(end - pos, ret))
7764 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
7767 struct hostap_sta_driver_data sta;
7770 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
7774 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7775 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
7776 if (os_snprintf_error(buflen, ret))
7783 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7784 char *buf, size_t buflen)
7788 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
7790 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
7791 struct p2p_data *p2p = wpa_s->global->p2p;
7794 country[0] = cmd[8];
7795 country[1] = cmd[9];
7797 p2p_set_country(p2p, country);
7800 ret = os_snprintf(buf, buflen, "%s\n", "OK");
7801 if (os_snprintf_error(buflen, ret))
7806 #endif /* ANDROID */
7809 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7810 char *buf, size_t buflen)
7815 unsigned int vendor_id, subcmd;
7816 struct wpabuf *reply;
7817 size_t data_len = 0;
7819 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7820 vendor_id = strtoul(cmd, &pos, 16);
7821 if (!isblank((unsigned char) *pos))
7824 subcmd = strtoul(pos, &pos, 10);
7827 if (!isblank((unsigned char) *pos++))
7829 data_len = os_strlen(pos);
7834 data = os_malloc(data_len);
7838 if (hexstr2bin(pos, data, data_len)) {
7839 wpa_printf(MSG_DEBUG,
7840 "Vendor command: wrong parameter format");
7846 reply = wpabuf_alloc((buflen - 1) / 2);
7852 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
7856 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
7866 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
7869 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
7870 wpa_s->global->p2p_init_wpa_s : wpa_s;
7871 #endif /* CONFIG_P2P */
7873 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
7875 if (wpas_abort_ongoing_scan(wpa_s) == 0)
7876 wpa_s->ignore_post_flush_scan_res = 1;
7878 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
7880 * Avoid possible auto connect re-connection on getting
7881 * disconnected due to state flush.
7883 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
7887 wpas_p2p_group_remove(p2p_wpa_s, "*");
7888 wpas_p2p_cancel(p2p_wpa_s);
7889 p2p_ctrl_flush(p2p_wpa_s);
7890 wpas_p2p_service_flush(p2p_wpa_s);
7891 p2p_wpa_s->global->p2p_disabled = 0;
7892 p2p_wpa_s->global->p2p_per_sta_psk = 0;
7893 p2p_wpa_s->conf->num_sec_device_types = 0;
7894 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
7895 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
7896 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
7897 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
7898 p2p_wpa_s->global->pending_p2ps_group = 0;
7899 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
7900 #endif /* CONFIG_P2P */
7902 #ifdef CONFIG_WPS_TESTING
7903 wps_version_number = 0x20;
7904 wps_testing_dummy_cred = 0;
7905 wps_corrupt_pkhash = 0;
7906 wps_force_auth_types_in_use = 0;
7907 wps_force_encr_types_in_use = 0;
7908 #endif /* CONFIG_WPS_TESTING */
7910 wpa_s->wps_fragment_size = 0;
7911 wpas_wps_cancel(wpa_s);
7912 wps_registrar_flush(wpa_s->wps->registrar);
7913 #endif /* CONFIG_WPS */
7914 wpa_s->after_wps = 0;
7915 wpa_s->known_wps_freq = 0;
7918 wpas_dpp_deinit(wpa_s);
7919 wpa_s->dpp_init_max_tries = 0;
7920 wpa_s->dpp_init_retry_time = 0;
7921 wpa_s->dpp_resp_wait_time = 0;
7922 wpa_s->dpp_resp_max_tries = 0;
7923 wpa_s->dpp_resp_retry_time = 0;
7924 #ifdef CONFIG_TESTING_OPTIONS
7925 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
7926 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
7927 dpp_pkex_ephemeral_key_override_len = 0;
7928 dpp_protocol_key_override_len = 0;
7929 dpp_nonce_override_len = 0;
7930 #endif /* CONFIG_TESTING_OPTIONS */
7931 #endif /* CONFIG_DPP */
7934 #ifdef CONFIG_TDLS_TESTING
7936 #endif /* CONFIG_TDLS_TESTING */
7937 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
7938 wpa_tdls_enable(wpa_s->wpa, 1);
7939 #endif /* CONFIG_TDLS */
7941 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
7942 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
7944 wpa_s->no_keep_alive = 0;
7945 wpa_s->own_disconnect_req = 0;
7947 os_free(wpa_s->disallow_aps_bssid);
7948 wpa_s->disallow_aps_bssid = NULL;
7949 wpa_s->disallow_aps_bssid_count = 0;
7950 os_free(wpa_s->disallow_aps_ssid);
7951 wpa_s->disallow_aps_ssid = NULL;
7952 wpa_s->disallow_aps_ssid_count = 0;
7954 wpa_s->set_sta_uapsd = 0;
7955 wpa_s->sta_uapsd = 0;
7957 wpa_drv_radio_disable(wpa_s, 0);
7958 wpa_blacklist_clear(wpa_s);
7959 wpa_s->extra_blacklist_count = 0;
7960 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
7961 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
7962 wpa_config_flush_blobs(wpa_s->conf);
7963 wpa_s->conf->auto_interworking = 0;
7964 wpa_s->conf->okc = 0;
7966 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7967 rsn_preauth_deinit(wpa_s->wpa);
7969 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
7970 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
7971 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
7972 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7974 radio_remove_works(wpa_s, NULL, 1);
7975 wpa_s->ext_work_in_progress = 0;
7977 wpa_s->next_ssid = NULL;
7979 #ifdef CONFIG_INTERWORKING
7981 hs20_cancel_fetch_osu(wpa_s);
7982 hs20_del_icon(wpa_s, NULL, NULL);
7983 #endif /* CONFIG_HS20 */
7984 #endif /* CONFIG_INTERWORKING */
7986 wpa_s->ext_mgmt_frame_handling = 0;
7987 wpa_s->ext_eapol_frame_io = 0;
7988 #ifdef CONFIG_TESTING_OPTIONS
7989 wpa_s->extra_roc_dur = 0;
7990 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
7991 wpa_s->p2p_go_csa_on_inv = 0;
7992 wpa_s->ignore_auth_resp = 0;
7993 wpa_s->ignore_assoc_disallow = 0;
7994 wpa_s->testing_resend_assoc = 0;
7995 wpa_s->reject_btm_req_reason = 0;
7996 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
7997 os_free(wpa_s->get_pref_freq_list_override);
7998 wpa_s->get_pref_freq_list_override = NULL;
7999 wpabuf_free(wpa_s->sae_commit_override);
8000 wpa_s->sae_commit_override = NULL;
8002 os_free(wpa_s->dpp_config_obj_override);
8003 wpa_s->dpp_config_obj_override = NULL;
8004 os_free(wpa_s->dpp_discovery_override);
8005 wpa_s->dpp_discovery_override = NULL;
8006 os_free(wpa_s->dpp_groups_override);
8007 wpa_s->dpp_groups_override = NULL;
8008 dpp_test = DPP_TEST_DISABLED;
8009 #endif /* CONFIG_DPP */
8010 #endif /* CONFIG_TESTING_OPTIONS */
8012 wpa_s->disconnected = 0;
8013 os_free(wpa_s->next_scan_freqs);
8014 wpa_s->next_scan_freqs = NULL;
8015 os_free(wpa_s->select_network_scan_freqs);
8016 wpa_s->select_network_scan_freqs = NULL;
8018 wpa_bss_flush(wpa_s);
8019 if (!dl_list_empty(&wpa_s->bss)) {
8020 wpa_printf(MSG_DEBUG,
8021 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8022 MACSTR " pending_bssid=" MACSTR,
8023 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8024 MAC2STR(wpa_s->bssid),
8025 MAC2STR(wpa_s->pending_bssid));
8028 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
8029 wpa_s->wnmsleep_used = 0;
8032 wpa_s->sme.last_unprot_disconnect.sec = 0;
8033 #endif /* CONFIG_SME */
8035 wpabuf_free(wpa_s->ric_ies);
8036 wpa_s->ric_ies = NULL;
8038 wpa_supplicant_update_channel_list(wpa_s, NULL);
8040 free_bss_tmp_disallowed(wpa_s);
8044 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8045 char *buf, size_t buflen)
8047 struct wpa_radio_work *work;
8049 struct os_reltime now, diff;
8054 os_get_reltime(&now);
8056 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8060 os_reltime_sub(&now, &work->time, &diff);
8061 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8062 work->type, work->wpa_s->ifname, work->freq,
8063 work->started, diff.sec, diff.usec);
8064 if (os_snprintf_error(end - pos, ret))
8073 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8075 struct wpa_radio_work *work = eloop_ctx;
8076 struct wpa_external_work *ework = work->ctx;
8078 wpa_dbg(work->wpa_s, MSG_DEBUG,
8079 "Timing out external radio work %u (%s)",
8080 ework->id, work->type);
8081 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
8082 work->wpa_s->ext_work_in_progress = 0;
8083 radio_work_done(work);
8088 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8090 struct wpa_external_work *ework = work->ctx;
8094 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8098 * work->type points to a buffer in ework, so need to replace
8099 * that here with a fixed string to avoid use of freed memory
8102 work->type = "freed-ext-work";
8108 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8109 ework->id, ework->type);
8110 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
8111 work->wpa_s->ext_work_in_progress = 1;
8112 if (!ework->timeout)
8113 ework->timeout = 10;
8114 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8119 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8120 char *buf, size_t buflen)
8122 struct wpa_external_work *ework;
8126 unsigned int freq = 0;
8128 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8130 ework = os_zalloc(sizeof(*ework));
8134 pos = os_strchr(cmd, ' ');
8136 type_len = pos - cmd;
8139 pos2 = os_strstr(pos, "freq=");
8141 freq = atoi(pos2 + 5);
8143 pos2 = os_strstr(pos, "timeout=");
8145 ework->timeout = atoi(pos2 + 8);
8147 type_len = os_strlen(cmd);
8149 if (4 + type_len >= sizeof(ework->type))
8150 type_len = sizeof(ework->type) - 4 - 1;
8151 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8152 os_memcpy(ework->type + 4, cmd, type_len);
8153 ework->type[4 + type_len] = '\0';
8155 wpa_s->ext_work_id++;
8156 if (wpa_s->ext_work_id == 0)
8157 wpa_s->ext_work_id++;
8158 ework->id = wpa_s->ext_work_id;
8160 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8166 ret = os_snprintf(buf, buflen, "%u", ework->id);
8167 if (os_snprintf_error(buflen, ret))
8173 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8175 struct wpa_radio_work *work;
8176 unsigned int id = atoi(cmd);
8178 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8180 struct wpa_external_work *ework;
8182 if (os_strncmp(work->type, "ext:", 4) != 0)
8185 if (id && ework->id != id)
8187 wpa_dbg(wpa_s, MSG_DEBUG,
8188 "Completed external radio work %u (%s)",
8189 ework->id, ework->type);
8190 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
8191 wpa_s->ext_work_in_progress = 0;
8192 radio_work_done(work);
8194 return 3; /* "OK\n" */
8201 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8202 char *buf, size_t buflen)
8204 if (os_strcmp(cmd, "show") == 0)
8205 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8206 if (os_strncmp(cmd, "add ", 4) == 0)
8207 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8208 if (os_strncmp(cmd, "done ", 5) == 0)
8209 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8214 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8216 struct wpa_radio_work *work, *tmp;
8218 if (!wpa_s || !wpa_s->radio)
8221 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8222 struct wpa_radio_work, list) {
8223 struct wpa_external_work *ework;
8225 if (os_strncmp(work->type, "ext:", 4) != 0)
8228 wpa_dbg(wpa_s, MSG_DEBUG,
8229 "Flushing%s external radio work %u (%s)",
8230 work->started ? " started" : "", ework->id,
8233 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8235 radio_work_done(work);
8241 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8243 struct wpa_supplicant *wpa_s = eloop_ctx;
8244 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8248 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8249 unsigned int *scan_id_count, int scan_id[])
8251 const char *pos = value;
8254 if (*pos == ' ' || *pos == '\0')
8256 if (*scan_id_count == MAX_SCAN_ID)
8258 scan_id[(*scan_id_count)++] = atoi(pos);
8259 pos = os_strchr(pos, ',');
8268 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8269 char *reply, int reply_size, int *reply_len)
8272 unsigned int manual_scan_passive = 0;
8273 unsigned int manual_scan_use_id = 0;
8274 unsigned int manual_scan_only_new = 0;
8275 unsigned int scan_only = 0;
8276 unsigned int scan_id_count = 0;
8277 int scan_id[MAX_SCAN_ID];
8278 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8279 struct wpa_scan_results *scan_res);
8280 int *manual_scan_freqs = NULL;
8281 struct wpa_ssid_value *ssid = NULL, *ns;
8282 unsigned int ssid_count = 0;
8284 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8289 if (radio_work_pending(wpa_s, "scan")) {
8290 wpa_printf(MSG_DEBUG,
8291 "Pending scan scheduled - reject new request");
8292 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8296 #ifdef CONFIG_INTERWORKING
8297 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8298 wpa_printf(MSG_DEBUG,
8299 "Interworking select in progress - reject new scan");
8300 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8303 #endif /* CONFIG_INTERWORKING */
8306 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
8309 pos = os_strstr(params, "freq=");
8311 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8313 if (manual_scan_freqs == NULL) {
8319 pos = os_strstr(params, "passive=");
8321 manual_scan_passive = !!atoi(pos + 8);
8323 pos = os_strstr(params, "use_id=");
8325 manual_scan_use_id = atoi(pos + 7);
8327 pos = os_strstr(params, "only_new=1");
8329 manual_scan_only_new = 1;
8331 pos = os_strstr(params, "scan_id=");
8332 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8338 pos = os_strstr(params, "bssid=");
8343 if (hwaddr_aton(pos, bssid)) {
8344 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8348 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
8352 while (pos && *pos != '\0') {
8353 if (os_strncmp(pos, "ssid ", 5) == 0) {
8359 if (*end == '\0' || *end == ' ')
8364 ns = os_realloc_array(
8365 ssid, ssid_count + 1,
8366 sizeof(struct wpa_ssid_value));
8373 if ((end - pos) & 0x01 ||
8374 end - pos > 2 * SSID_MAX_LEN ||
8375 hexstr2bin(pos, ssid[ssid_count].ssid,
8376 (end - pos) / 2) < 0) {
8377 wpa_printf(MSG_DEBUG,
8378 "Invalid SSID value '%s'",
8383 ssid[ssid_count].ssid_len = (end - pos) / 2;
8384 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8385 ssid[ssid_count].ssid,
8386 ssid[ssid_count].ssid_len);
8391 pos = os_strchr(pos, ' ');
8397 wpa_s->num_ssids_from_scan_req = ssid_count;
8398 os_free(wpa_s->ssids_from_scan_req);
8400 wpa_s->ssids_from_scan_req = ssid;
8403 wpa_s->ssids_from_scan_req = NULL;
8407 scan_res_handler = scan_only_handler;
8408 else if (wpa_s->scan_res_handler == scan_only_handler)
8409 scan_res_handler = NULL;
8411 scan_res_handler = wpa_s->scan_res_handler;
8413 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8414 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8415 (wpa_s->wpa_state == WPA_COMPLETED))) {
8416 wpa_s->manual_scan_passive = manual_scan_passive;
8417 wpa_s->manual_scan_use_id = manual_scan_use_id;
8418 wpa_s->manual_scan_only_new = manual_scan_only_new;
8419 wpa_s->scan_id_count = scan_id_count;
8420 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8421 wpa_s->scan_res_handler = scan_res_handler;
8422 os_free(wpa_s->manual_scan_freqs);
8423 wpa_s->manual_scan_freqs = manual_scan_freqs;
8424 manual_scan_freqs = NULL;
8426 wpa_s->normal_scans = 0;
8427 wpa_s->scan_req = MANUAL_SCAN_REQ;
8428 wpa_s->after_wps = 0;
8429 wpa_s->known_wps_freq = 0;
8430 wpa_supplicant_req_scan(wpa_s, 0, 0);
8431 if (wpa_s->manual_scan_use_id) {
8432 wpa_s->manual_scan_id++;
8433 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8434 wpa_s->manual_scan_id);
8435 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8436 wpa_s->manual_scan_id);
8438 } else if (wpa_s->sched_scanning) {
8439 wpa_s->manual_scan_passive = manual_scan_passive;
8440 wpa_s->manual_scan_use_id = manual_scan_use_id;
8441 wpa_s->manual_scan_only_new = manual_scan_only_new;
8442 wpa_s->scan_id_count = scan_id_count;
8443 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8444 wpa_s->scan_res_handler = scan_res_handler;
8445 os_free(wpa_s->manual_scan_freqs);
8446 wpa_s->manual_scan_freqs = manual_scan_freqs;
8447 manual_scan_freqs = NULL;
8449 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8450 wpa_supplicant_cancel_sched_scan(wpa_s);
8451 wpa_s->scan_req = MANUAL_SCAN_REQ;
8452 wpa_supplicant_req_scan(wpa_s, 0, 0);
8453 if (wpa_s->manual_scan_use_id) {
8454 wpa_s->manual_scan_id++;
8455 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8456 wpa_s->manual_scan_id);
8457 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8458 wpa_s->manual_scan_id);
8461 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
8462 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8466 os_free(manual_scan_freqs);
8471 #ifdef CONFIG_TESTING_OPTIONS
8473 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
8474 unsigned int freq, const u8 *dst,
8475 const u8 *src, const u8 *bssid,
8476 const u8 *data, size_t data_len,
8477 enum offchannel_send_action_result
8480 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8481 " src=" MACSTR " bssid=" MACSTR " result=%s",
8482 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
8483 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
8484 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
8485 "NO_ACK" : "FAILED"));
8489 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
8493 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
8495 int freq = 0, no_cck = 0, wait_time = 0;
8497 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8498 * <action=Action frame payload> */
8500 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
8503 used = hwaddr_aton2(pos, da);
8509 used = hwaddr_aton2(pos, bssid);
8514 param = os_strstr(pos, " freq=");
8520 param = os_strstr(pos, " no_cck=");
8523 no_cck = atoi(param);
8526 param = os_strstr(pos, " wait_time=");
8529 wait_time = atoi(param);
8532 param = os_strstr(pos, " action=");
8537 len = os_strlen(param);
8542 buf = os_malloc(len);
8546 if (hexstr2bin(param, buf, len) < 0) {
8551 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
8552 buf, len, wait_time,
8553 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
8559 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
8561 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
8562 offchannel_send_action_done(wpa_s);
8566 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
8572 int freq = 0, datarate = 0, ssi_signal = 0;
8573 union wpa_event_data event;
8575 if (!wpa_s->ext_mgmt_frame_handling)
8578 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8580 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
8583 param = os_strstr(pos, "freq=");
8589 param = os_strstr(pos, " datarate=");
8592 datarate = atoi(param);
8595 param = os_strstr(pos, " ssi_signal=");
8598 ssi_signal = atoi(param);
8601 param = os_strstr(pos, " frame=");
8606 len = os_strlen(param);
8611 buf = os_malloc(len);
8615 if (hexstr2bin(param, buf, len) < 0) {
8620 os_memset(&event, 0, sizeof(event));
8621 event.rx_mgmt.freq = freq;
8622 event.rx_mgmt.frame = buf;
8623 event.rx_mgmt.frame_len = len;
8624 event.rx_mgmt.ssi_signal = ssi_signal;
8625 event.rx_mgmt.datarate = datarate;
8626 wpa_s->ext_mgmt_frame_handling = 0;
8627 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
8628 wpa_s->ext_mgmt_frame_handling = 1;
8636 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
8639 struct wpa_scan_res *res;
8640 struct os_reltime now;
8647 if (os_strcmp(param, "START") == 0) {
8648 wpa_bss_update_start(wpa_s);
8652 if (os_strcmp(param, "END") == 0) {
8653 wpa_bss_update_end(wpa_s, NULL, 1);
8657 if (os_strncmp(param, "BSS ", 4) != 0)
8661 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
8665 pos = os_strstr(param, " flags=");
8667 res->flags = strtol(pos + 7, NULL, 16);
8669 pos = os_strstr(param, " bssid=");
8670 if (pos && hwaddr_aton(pos + 7, res->bssid))
8673 pos = os_strstr(param, " freq=");
8675 res->freq = atoi(pos + 6);
8677 pos = os_strstr(param, " beacon_int=");
8679 res->beacon_int = atoi(pos + 12);
8681 pos = os_strstr(param, " caps=");
8683 res->caps = strtol(pos + 6, NULL, 16);
8685 pos = os_strstr(param, " qual=");
8687 res->qual = atoi(pos + 6);
8689 pos = os_strstr(param, " noise=");
8691 res->noise = atoi(pos + 7);
8693 pos = os_strstr(param, " level=");
8695 res->level = atoi(pos + 7);
8697 pos = os_strstr(param, " tsf=");
8699 res->tsf = strtoll(pos + 5, NULL, 16);
8701 pos = os_strstr(param, " age=");
8703 res->age = atoi(pos + 5);
8705 pos = os_strstr(param, " est_throughput=");
8707 res->est_throughput = atoi(pos + 16);
8709 pos = os_strstr(param, " snr=");
8711 res->snr = atoi(pos + 5);
8713 pos = os_strstr(param, " parent_tsf=");
8715 res->parent_tsf = strtoll(pos + 7, NULL, 16);
8717 pos = os_strstr(param, " tsf_bssid=");
8718 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
8721 pos = os_strstr(param, " ie=");
8724 end = os_strchr(pos, ' ');
8726 end = pos + os_strlen(pos);
8727 res->ie_len = (end - pos) / 2;
8728 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
8732 pos = os_strstr(param, " beacon_ie=");
8735 end = os_strchr(pos, ' ');
8737 end = pos + os_strlen(pos);
8738 res->beacon_ie_len = (end - pos) / 2;
8739 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
8740 res->beacon_ie_len))
8744 os_get_reltime(&now);
8745 wpa_bss_update_scan_res(wpa_s, res, &now);
8754 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
8757 union wpa_event_data event;
8758 enum wpa_event_type ev;
8760 /* <event name> [parameters..] */
8762 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
8765 param = os_strchr(pos, ' ');
8769 os_memset(&event, 0, sizeof(event));
8771 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
8772 ev = EVENT_INTERFACE_ENABLED;
8773 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
8774 ev = EVENT_INTERFACE_DISABLED;
8775 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
8776 ev = EVENT_AVOID_FREQUENCIES;
8779 if (freq_range_list_parse(&event.freq_range, param) < 0)
8781 wpa_supplicant_event(wpa_s, ev, &event);
8782 os_free(event.freq_range.range);
8784 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
8785 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
8787 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
8792 wpa_supplicant_event(wpa_s, ev, &event);
8798 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
8801 u8 src[ETH_ALEN], *buf;
8805 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
8808 used = hwaddr_aton2(pos, src);
8815 len = os_strlen(pos);
8820 buf = os_malloc(len);
8824 if (hexstr2bin(pos, buf, len) < 0) {
8829 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
8836 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
8840 const u16 *pos = buf;
8842 for (i = 0; i < len / 2; i++)
8846 sum = (sum & 0xffff) + (sum >> 16);
8848 return sum ^ 0xffff;
8852 #define HWSIM_PACKETLEN 1500
8853 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8855 static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
8858 struct wpa_supplicant *wpa_s = ctx;
8859 const struct ether_header *eth;
8865 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
8866 wpa_printf(MSG_DEBUG,
8867 "test data: RX - ignore unexpected length %d",
8872 eth = (const struct ether_header *) buf;
8873 os_memcpy(&ip, eth + 1, sizeof(ip));
8874 pos = &buf[sizeof(*eth) + sizeof(ip)];
8876 if (ip.ihl != 5 || ip.version != 4 ||
8877 ntohs(ip.tot_len) > HWSIM_IP_LEN) {
8878 wpa_printf(MSG_DEBUG,
8879 "test data: RX - ignore unexpect IP header");
8883 for (i = 0; i < ntohs(ip.tot_len) - sizeof(ip); i++) {
8884 if (*pos != (u8) i) {
8885 wpa_printf(MSG_DEBUG,
8886 "test data: RX - ignore mismatching payload");
8892 if (ntohs(ip.tot_len) != HWSIM_IP_LEN)
8893 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.tot_len));
8894 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
8895 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
8899 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
8902 int enabled = atoi(cmd);
8907 if (wpa_s->l2_test) {
8908 l2_packet_deinit(wpa_s->l2_test);
8909 wpa_s->l2_test = NULL;
8910 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
8918 pos = os_strstr(cmd, " ifname=");
8922 ifname = wpa_s->ifname;
8924 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
8925 ETHERTYPE_IP, wpas_data_test_rx,
8927 if (wpa_s->l2_test == NULL)
8930 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
8936 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
8938 u8 dst[ETH_ALEN], src[ETH_ALEN];
8943 u8 buf[2 + HWSIM_PACKETLEN];
8944 struct ether_header *eth;
8948 size_t send_len = HWSIM_IP_LEN;
8950 if (wpa_s->l2_test == NULL)
8953 /* format: <dst> <src> <tos> [len=<length>] */
8956 used = hwaddr_aton2(pos, dst);
8962 used = hwaddr_aton2(pos, src);
8967 val = strtol(pos, &pos2, 0);
8968 if (val < 0 || val > 0xff)
8972 pos = os_strstr(pos2, " len=");
8975 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
8980 eth = (struct ether_header *) &buf[2];
8981 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
8982 os_memcpy(eth->ether_shost, src, ETH_ALEN);
8983 eth->ether_type = htons(ETHERTYPE_IP);
8984 ip = (struct iphdr *) (eth + 1);
8985 os_memset(ip, 0, sizeof(*ip));
8990 ip->tot_len = htons(send_len);
8992 ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8993 ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8994 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
8995 dpos = (u8 *) (ip + 1);
8996 for (i = 0; i < send_len - sizeof(*ip); i++)
8999 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
9000 sizeof(struct ether_header) + send_len) < 0)
9003 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
9004 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
9010 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
9014 struct ether_header *eth;
9015 struct l2_packet_data *l2 = NULL;
9020 len = os_strlen(cmd);
9021 if (len & 1 || len < ETH_HLEN * 2)
9025 buf = os_malloc(len);
9029 if (hexstr2bin(cmd, buf, len) < 0)
9032 eth = (struct ether_header *) buf;
9033 ethertype = ntohs(eth->ether_type);
9035 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
9036 wpas_data_test_rx, wpa_s, 1);
9040 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
9041 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
9044 l2_packet_deinit(l2);
9047 return res < 0 ? -1 : 0;
9051 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
9053 #ifdef WPA_TRACE_BFD
9056 wpa_trace_fail_after = atoi(cmd);
9057 pos = os_strchr(cmd, ':');
9060 os_strlcpy(wpa_trace_fail_func, pos,
9061 sizeof(wpa_trace_fail_func));
9063 wpa_trace_fail_after = 0;
9066 #else /* WPA_TRACE_BFD */
9068 #endif /* WPA_TRACE_BFD */
9072 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
9073 char *buf, size_t buflen)
9075 #ifdef WPA_TRACE_BFD
9076 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
9077 wpa_trace_fail_func);
9078 #else /* WPA_TRACE_BFD */
9080 #endif /* WPA_TRACE_BFD */
9084 static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
9086 #ifdef WPA_TRACE_BFD
9089 wpa_trace_test_fail_after = atoi(cmd);
9090 pos = os_strchr(cmd, ':');
9093 os_strlcpy(wpa_trace_test_fail_func, pos,
9094 sizeof(wpa_trace_test_fail_func));
9096 wpa_trace_test_fail_after = 0;
9099 #else /* WPA_TRACE_BFD */
9101 #endif /* WPA_TRACE_BFD */
9105 static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
9106 char *buf, size_t buflen)
9108 #ifdef WPA_TRACE_BFD
9109 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
9110 wpa_trace_test_fail_func);
9111 #else /* WPA_TRACE_BFD */
9113 #endif /* WPA_TRACE_BFD */
9117 static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9119 struct wpa_supplicant *wpa_s = eloop_ctx;
9120 int i, count = (intptr_t) timeout_ctx;
9122 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9124 for (i = 0; i < count; i++) {
9125 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9131 static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9139 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9140 (void *) (intptr_t) count);
9144 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9150 len = os_strlen(cmd);
9158 buf = wpabuf_alloc(len);
9162 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9168 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9173 static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9175 u8 zero[WPA_TK_MAX_LEN];
9177 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9180 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9181 os_memset(zero, 0, sizeof(zero));
9183 /* First, use a zero key to avoid any possible duplicate key avoidance
9185 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9186 wpa_s->last_tk_key_idx, 1, zero, 6,
9187 zero, wpa_s->last_tk_len) < 0)
9190 /* Set the previously configured key to reset its TSC/RSC */
9191 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9192 wpa_s->last_tk_key_idx, 1, zero, 6,
9193 wpa_s->last_tk, wpa_s->last_tk_len);
9197 static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9199 const char *pos = cmd;
9200 int error, pairwise;
9203 pos = os_strchr(pos, ' ');
9206 pairwise = atoi(pos);
9207 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9212 static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9215 struct wpa_driver_associate_params params;
9218 os_memset(¶ms, 0, sizeof(params));
9219 params.bssid = wpa_s->bssid;
9220 params.ssid = wpa_s->sme.ssid;
9221 params.ssid_len = wpa_s->sme.ssid_len;
9222 params.freq.freq = wpa_s->sme.freq;
9223 if (wpa_s->last_assoc_req_wpa_ie) {
9224 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9225 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9227 params.pairwise_suite = wpa_s->pairwise_cipher;
9228 params.group_suite = wpa_s->group_cipher;
9229 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9230 params.key_mgmt_suite = wpa_s->key_mgmt;
9231 params.wpa_proto = wpa_s->wpa_proto;
9232 params.mgmt_frame_protection = wpa_s->sme.mfp;
9233 params.rrm_used = wpa_s->rrm.rrm_used;
9234 if (wpa_s->sme.prev_bssid_set)
9235 params.prev_bssid = wpa_s->sme.prev_bssid;
9236 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9237 ret = wpa_drv_associate(wpa_s, ¶ms);
9238 wpa_s->testing_resend_assoc = 1;
9240 #else /* CONFIG_SME */
9242 #endif /* CONFIG_SME */
9245 #endif /* CONFIG_TESTING_OPTIONS */
9248 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9254 struct ieee802_11_elems elems;
9257 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9259 wpa_s = wpas_vendor_elem(wpa_s, frame);
9261 pos = os_strchr(pos, ' ');
9266 len = os_strlen(pos);
9273 buf = wpabuf_alloc(len);
9277 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9282 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9288 if (wpa_s->vendor_elem[frame] == NULL) {
9289 wpa_s->vendor_elem[frame] = buf;
9290 wpas_vendor_elem_update(wpa_s);
9294 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9299 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9301 wpas_vendor_elem_update(wpa_s);
9307 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9308 char *buf, size_t buflen)
9310 int frame = atoi(cmd);
9312 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9314 wpa_s = wpas_vendor_elem(wpa_s, frame);
9316 if (wpa_s->vendor_elem[frame] == NULL)
9319 return wpa_snprintf_hex(buf, buflen,
9320 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9321 wpabuf_len(wpa_s->vendor_elem[frame]));
9325 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9331 struct ieee802_11_elems elems;
9335 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9337 wpa_s = wpas_vendor_elem(wpa_s, frame);
9339 pos = os_strchr(pos, ' ');
9345 wpabuf_free(wpa_s->vendor_elem[frame]);
9346 wpa_s->vendor_elem[frame] = NULL;
9347 wpas_vendor_elem_update(wpa_s);
9351 if (wpa_s->vendor_elem[frame] == NULL)
9354 len = os_strlen(pos);
9361 buf = os_malloc(len);
9365 if (hexstr2bin(pos, buf, len) < 0) {
9370 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9375 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
9381 static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9383 struct wpa_supplicant *wpa_s = ctx;
9388 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9390 * BSSID Information[4]
9391 * Operating Class[1]
9394 * Optional Subelements[variable]
9396 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9398 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
9399 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
9403 data = wpabuf_head_u8(neighbor_rep);
9404 len = wpabuf_len(neighbor_rep);
9406 while (len >= 2 + NR_IE_MIN_LEN) {
9408 char lci[256 * 2 + 1];
9409 char civic[256 * 2 + 1];
9410 u8 nr_len = data[1];
9411 const u8 *pos = data, *end;
9413 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9414 nr_len < NR_IE_MIN_LEN) {
9415 wpa_printf(MSG_DEBUG,
9416 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9421 if (2U + nr_len > len) {
9422 wpa_printf(MSG_DEBUG,
9423 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9424 data[0], len, nr_len);
9431 pos += NR_IE_MIN_LEN;
9435 while (end - pos > 2) {
9440 if (s_len > end - pos)
9442 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9443 /* Measurement Token[1] */
9444 /* Measurement Report Mode[1] */
9445 /* Measurement Type[1] */
9446 /* Measurement Report[variable] */
9448 case MEASURE_TYPE_LCI:
9451 wpa_snprintf_hex(lci, sizeof(lci),
9454 case MEASURE_TYPE_LOCATION_CIVIC:
9457 wpa_snprintf_hex(civic, sizeof(civic),
9466 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
9468 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9469 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
9470 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
9472 lci[0] ? " lci=" : "", lci,
9473 civic[0] ? " civic=" : "", civic);
9480 wpabuf_free(neighbor_rep);
9484 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
9487 struct wpa_ssid_value ssid, *ssid_p = NULL;
9488 int ret, lci = 0, civic = 0;
9491 ssid_s = os_strstr(cmd, "ssid=");
9493 if (ssid_parse(ssid_s + 5, &ssid)) {
9494 wpa_printf(MSG_ERROR,
9495 "CTRL: Send Neighbor Report: bad SSID");
9502 * Move cmd after the SSID text that may include "lci" or
9505 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
9511 if (cmd && os_strstr(cmd, "lci"))
9514 if (cmd && os_strstr(cmd, "civic"))
9517 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
9518 wpas_ctrl_neighbor_rep_cb,
9525 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
9527 eapol_sm_erp_flush(wpa_s->eapol);
9532 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
9535 char *token, *context = NULL;
9536 unsigned int enable = ~0, type = 0;
9537 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
9538 u8 *addr = NULL, *mask = NULL;
9540 while ((token = str_token(cmd, " ", &context))) {
9541 if (os_strcasecmp(token, "scan") == 0) {
9542 type |= MAC_ADDR_RAND_SCAN;
9543 } else if (os_strcasecmp(token, "sched") == 0) {
9544 type |= MAC_ADDR_RAND_SCHED_SCAN;
9545 } else if (os_strcasecmp(token, "pno") == 0) {
9546 type |= MAC_ADDR_RAND_PNO;
9547 } else if (os_strcasecmp(token, "all") == 0) {
9548 type = wpa_s->mac_addr_rand_supported;
9549 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
9550 enable = atoi(token + 7);
9551 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
9553 if (hwaddr_aton(token + 5, addr)) {
9554 wpa_printf(MSG_INFO,
9555 "CTRL: Invalid MAC address: %s",
9559 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
9561 if (hwaddr_aton(token + 5, mask)) {
9562 wpa_printf(MSG_INFO,
9563 "CTRL: Invalid MAC address mask: %s",
9568 wpa_printf(MSG_INFO,
9569 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9576 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
9581 wpa_printf(MSG_INFO,
9582 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9587 wpas_mac_addr_rand_scan_clear(wpa_s, type);
9589 if (type & MAC_ADDR_RAND_PNO) {
9590 wpas_stop_pno(wpa_s);
9591 wpas_start_pno(wpa_s);
9593 } else if (wpa_s->sched_scanning &&
9594 (type & MAC_ADDR_RAND_SCHED_SCAN)) {
9595 wpas_scan_restart_sched_scan(wpa_s);
9600 if ((addr && !mask) || (!addr && mask)) {
9601 wpa_printf(MSG_INFO,
9602 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9606 if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
9607 wpa_printf(MSG_INFO,
9608 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9612 if (type & MAC_ADDR_RAND_SCAN) {
9613 if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
9618 if (type & MAC_ADDR_RAND_SCHED_SCAN) {
9619 if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
9623 if (wpa_s->sched_scanning && !wpa_s->pno)
9624 wpas_scan_restart_sched_scan(wpa_s);
9627 if (type & MAC_ADDR_RAND_PNO) {
9628 if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
9633 wpas_stop_pno(wpa_s);
9634 wpas_start_pno(wpa_s);
9642 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
9643 char *buf, size_t buflen)
9647 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
9649 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
9650 buflen - reply_len);
9651 #endif /* CONFIG_AP */
9656 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
9658 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
9660 wpas_ap_pmksa_cache_flush(wpa_s);
9661 #endif /* CONFIG_AP */
9665 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9667 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
9668 const char *cmd, char *buf, size_t buflen)
9670 struct rsn_pmksa_cache_entry *entry;
9671 struct wpa_ssid *ssid;
9672 char *pos, *pos2, *end;
9674 struct os_reltime now;
9676 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9683 os_get_reltime(&now);
9687 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9688 * <expiration in seconds> <akmp> <opportunistic>
9689 * [FILS Cache Identifier]
9692 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
9693 entry = entry->next) {
9694 if (entry->network_ctx != ssid)
9698 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
9699 MAC2STR(entry->aa));
9700 if (os_snprintf_error(end - pos2, ret))
9704 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
9707 ret = os_snprintf(pos2, end - pos2, " ");
9708 if (os_snprintf_error(end - pos2, ret))
9712 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
9715 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
9716 (int) (entry->reauth_time - now.sec),
9717 (int) (entry->expiration - now.sec),
9719 entry->opportunistic);
9720 if (os_snprintf_error(end - pos2, ret))
9724 if (entry->fils_cache_id_set) {
9725 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
9726 entry->fils_cache_id[0],
9727 entry->fils_cache_id[1]);
9728 if (os_snprintf_error(end - pos2, ret))
9733 ret = os_snprintf(pos2, end - pos2, "\n");
9734 if (os_snprintf_error(end - pos2, ret))
9745 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
9748 struct rsn_pmksa_cache_entry *entry;
9749 struct wpa_ssid *ssid;
9752 struct os_reltime now;
9753 int reauth_time = 0, expiration = 0, i;
9757 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9758 * <expiration in seconds> <akmp> <opportunistic>
9759 * [FILS Cache Identifier]
9762 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9766 pos = os_strchr(cmd, ' ');
9771 entry = os_zalloc(sizeof(*entry));
9775 if (hwaddr_aton(pos, entry->aa))
9778 pos = os_strchr(pos, ' ');
9783 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
9786 pos = os_strchr(pos, ' ');
9791 pos2 = os_strchr(pos, ' ');
9794 entry->pmk_len = (pos2 - pos) / 2;
9795 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
9796 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
9799 pos = os_strchr(pos, ' ');
9804 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
9805 &entry->akmp, &entry->opportunistic) != 4)
9807 for (i = 0; i < 4; i++) {
9808 pos = os_strchr(pos, ' ');
9817 if (hexstr2bin(pos, entry->fils_cache_id,
9818 FILS_CACHE_ID_LEN) < 0)
9820 entry->fils_cache_id_set = 1;
9822 os_get_reltime(&now);
9823 entry->expiration = now.sec + expiration;
9824 entry->reauth_time = now.sec + reauth_time;
9826 entry->network_ctx = ssid;
9828 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
9839 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
9840 const char *cmd, char *buf,
9848 if (os_strcasecmp(cmd, "any") == 0)
9849 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
9851 if (hwaddr_aton(cmd, spa))
9854 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
9858 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
9862 * We do not check mesh interface existance because PMKSA should be
9863 * stored before wpa_s->ifmsh creation to suppress commit message
9866 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
9869 #endif /* CONFIG_MESH */
9870 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9874 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
9877 struct fils_hlp_req *req;
9880 /* format: <dst> <packet starting from ethertype> */
9882 req = os_zalloc(sizeof(*req));
9886 if (hwaddr_aton(cmd, req->dst))
9889 pos = os_strchr(cmd, ' ');
9893 req->pkt = wpabuf_parse_bin(pos);
9897 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
9900 wpabuf_free(req->pkt);
9904 #endif /* CONFIG_FILS */
9907 static int wpas_ctrl_cmd_debug_level(const char *cmd)
9909 if (os_strcmp(cmd, "PING") == 0 ||
9910 os_strncmp(cmd, "BSS ", 4) == 0 ||
9911 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
9912 os_strncmp(cmd, "STATUS", 6) == 0 ||
9913 os_strncmp(cmd, "STA ", 4) == 0 ||
9914 os_strncmp(cmd, "STA-", 4) == 0)
9915 return MSG_EXCESSIVE;
9920 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
9921 char *buf, size_t *resp_len)
9924 const int reply_size = 4096;
9927 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
9928 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
9929 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
9930 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
9931 if (wpa_debug_show_keys)
9932 wpa_dbg(wpa_s, MSG_DEBUG,
9933 "Control interface command '%s'", buf);
9935 wpa_dbg(wpa_s, MSG_DEBUG,
9936 "Control interface command '%s [REMOVED]'",
9937 os_strncmp(buf, WPA_CTRL_RSP,
9938 os_strlen(WPA_CTRL_RSP)) == 0 ?
9940 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
9941 "SET_NETWORK" : "key-add"));
9942 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
9943 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
9944 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
9945 (const u8 *) buf, os_strlen(buf));
9947 int level = wpas_ctrl_cmd_debug_level(buf);
9948 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
9951 reply = os_malloc(reply_size);
9952 if (reply == NULL) {
9957 os_memcpy(reply, "OK\n", 3);
9960 if (os_strcmp(buf, "PING") == 0) {
9961 os_memcpy(reply, "PONG\n", 5);
9963 } else if (os_strcmp(buf, "IFNAME") == 0) {
9964 reply_len = os_strlen(wpa_s->ifname);
9965 os_memcpy(reply, wpa_s->ifname, reply_len);
9966 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
9967 if (wpa_debug_reopen_file() < 0)
9969 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
9970 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
9971 } else if (os_strcmp(buf, "MIB") == 0) {
9972 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
9973 if (reply_len >= 0) {
9974 reply_len += eapol_sm_get_mib(wpa_s->eapol,
9976 reply_size - reply_len);
9977 #ifdef CONFIG_MACSEC
9978 reply_len += ieee802_1x_kay_get_mib(
9979 wpa_s->kay, reply + reply_len,
9980 reply_size - reply_len);
9981 #endif /* CONFIG_MACSEC */
9983 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
9984 reply_len = wpa_supplicant_ctrl_iface_status(
9985 wpa_s, buf + 6, reply, reply_size);
9986 } else if (os_strcmp(buf, "PMKSA") == 0) {
9987 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
9988 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
9989 wpas_ctrl_iface_pmksa_flush(wpa_s);
9990 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9991 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
9992 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
9994 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
9995 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
9998 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
9999 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
10000 reply, reply_size);
10001 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
10002 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
10004 #endif /* CONFIG_MESH */
10005 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10006 } else if (os_strncmp(buf, "SET ", 4) == 0) {
10007 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
10009 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
10010 reply_len = wpa_config_dump_values(wpa_s->conf,
10011 reply, reply_size);
10012 } else if (os_strncmp(buf, "GET ", 4) == 0) {
10013 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
10014 reply, reply_size);
10015 } else if (os_strcmp(buf, "LOGON") == 0) {
10016 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
10017 } else if (os_strcmp(buf, "LOGOFF") == 0) {
10018 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
10019 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
10020 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10023 wpas_request_connection(wpa_s);
10024 } else if (os_strcmp(buf, "REATTACH") == 0) {
10025 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
10026 !wpa_s->current_ssid)
10029 wpa_s->reattach = 1;
10030 wpas_request_connection(wpa_s);
10032 } else if (os_strcmp(buf, "RECONNECT") == 0) {
10033 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10035 else if (wpa_s->disconnected)
10036 wpas_request_connection(wpa_s);
10037 #ifdef IEEE8021X_EAPOL
10038 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
10039 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
10041 #endif /* IEEE8021X_EAPOL */
10042 #ifdef CONFIG_IEEE80211R
10043 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
10044 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
10046 #endif /* CONFIG_IEEE80211R */
10048 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
10049 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
10051 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10055 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
10056 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
10058 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10062 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
10063 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
10066 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
10067 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
10068 wpa_s, buf + 14, reply, reply_size);
10069 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
10070 if (wpas_wps_cancel(wpa_s))
10072 #ifdef CONFIG_WPS_NFC
10073 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
10074 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
10076 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
10077 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
10079 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10080 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10081 wpa_s, buf + 21, reply, reply_size);
10082 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
10083 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
10084 wpa_s, buf + 14, reply, reply_size);
10085 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
10086 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
10089 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10090 reply_len = wpas_ctrl_nfc_get_handover_req(
10091 wpa_s, buf + 21, reply, reply_size);
10092 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10093 reply_len = wpas_ctrl_nfc_get_handover_sel(
10094 wpa_s, buf + 21, reply, reply_size);
10095 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
10096 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
10098 #endif /* CONFIG_WPS_NFC */
10099 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
10100 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
10103 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
10104 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
10105 wpa_s, buf + 11, reply, reply_size);
10106 #endif /* CONFIG_AP */
10107 #ifdef CONFIG_WPS_ER
10108 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
10109 if (wpas_wps_er_start(wpa_s, NULL))
10111 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
10112 if (wpas_wps_er_start(wpa_s, buf + 13))
10114 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
10115 wpas_wps_er_stop(wpa_s);
10116 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
10117 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
10119 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
10120 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
10122 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10124 } else if (ret == -3) {
10125 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
10127 } else if (ret == -4) {
10128 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
10132 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
10133 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
10135 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
10136 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
10139 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
10140 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
10142 #ifdef CONFIG_WPS_NFC
10143 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10144 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10145 wpa_s, buf + 24, reply, reply_size);
10146 #endif /* CONFIG_WPS_NFC */
10147 #endif /* CONFIG_WPS_ER */
10148 #endif /* CONFIG_WPS */
10149 #ifdef CONFIG_IBSS_RSN
10150 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10151 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10153 #endif /* CONFIG_IBSS_RSN */
10155 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10156 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10157 wpa_s, buf + 19, reply, reply_size);
10158 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10159 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10160 wpa_s, "", reply, reply_size);
10161 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10162 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10164 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10165 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10168 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10169 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10171 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10172 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10174 #endif /* CONFIG_MESH */
10176 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
10177 if (p2p_ctrl_find(wpa_s, buf + 8))
10179 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10180 if (p2p_ctrl_find(wpa_s, ""))
10182 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10183 wpas_p2p_stop_find(wpa_s);
10184 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10185 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10187 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10188 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10190 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10191 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10193 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10194 if (p2p_ctrl_listen(wpa_s, buf + 11))
10196 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10197 if (p2p_ctrl_listen(wpa_s, ""))
10199 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10200 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10202 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
10203 if (p2p_ctrl_group_add(wpa_s, ""))
10205 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10206 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10208 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10209 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10211 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10212 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10214 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10215 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10216 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10217 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10219 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10220 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10222 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10223 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10225 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10226 wpas_p2p_sd_service_update(wpa_s);
10227 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10228 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10230 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10231 wpas_p2p_service_flush(wpa_s);
10232 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10233 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10235 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10236 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10238 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10239 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10241 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10242 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10244 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10245 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10247 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10248 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10250 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10251 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10253 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
10254 p2p_ctrl_flush(wpa_s);
10255 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10256 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10258 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10259 if (wpas_p2p_cancel(wpa_s))
10261 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10262 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10264 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10265 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10267 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10268 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10270 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10271 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10273 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10274 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10276 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10277 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10279 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10280 if (wpas_p2p_lo_stop(wpa_s))
10282 #endif /* CONFIG_P2P */
10283 #ifdef CONFIG_WIFI_DISPLAY
10284 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10285 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10287 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10288 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10289 reply, reply_size);
10290 #endif /* CONFIG_WIFI_DISPLAY */
10291 #ifdef CONFIG_INTERWORKING
10292 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10293 if (interworking_fetch_anqp(wpa_s) < 0)
10295 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10296 interworking_stop_fetch_anqp(wpa_s);
10297 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10298 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10300 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10301 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
10303 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
10304 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
10306 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10309 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10313 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10314 if (os_snprintf_error(reply_size, reply_len))
10317 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10318 if (get_anqp(wpa_s, buf + 9) < 0)
10320 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10321 if (gas_request(wpa_s, buf + 12) < 0)
10323 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10324 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10326 #endif /* CONFIG_INTERWORKING */
10328 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10329 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10331 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10332 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10334 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
10335 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10337 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10338 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10340 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10341 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10342 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10343 if (del_hs20_icon(wpa_s, buf + 14) < 0)
10345 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
10346 if (hs20_fetch_osu(wpa_s, 0) < 0)
10348 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10349 if (hs20_fetch_osu(wpa_s, 1) < 0)
10351 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10352 hs20_cancel_fetch_osu(wpa_s);
10353 #endif /* CONFIG_HS20 */
10354 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10356 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10357 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10361 * Notify response from timeout to allow the control
10362 * interface response to be sent first.
10364 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
10367 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
10368 if (wpa_supplicant_reload_configuration(wpa_s))
10370 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10371 wpa_supplicant_terminate_proc(wpa_s->global);
10372 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
10373 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
10375 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
10376 reply_len = wpa_supplicant_ctrl_iface_blacklist(
10377 wpa_s, buf + 9, reply, reply_size);
10378 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
10379 reply_len = wpa_supplicant_ctrl_iface_log_level(
10380 wpa_s, buf + 9, reply, reply_size);
10381 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
10382 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10383 wpa_s, buf + 14, reply, reply_size);
10384 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
10385 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10386 wpa_s, NULL, reply, reply_size);
10387 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
10388 wpas_request_disconnection(wpa_s);
10389 } else if (os_strcmp(buf, "SCAN") == 0) {
10390 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
10391 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
10392 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
10393 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
10394 reply_len = wpa_supplicant_ctrl_iface_scan_results(
10395 wpa_s, reply, reply_size);
10396 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
10397 if (wpas_abort_ongoing_scan(wpa_s) < 0)
10399 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
10400 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
10402 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
10403 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
10405 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
10406 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
10408 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
10409 reply_len = wpa_supplicant_ctrl_iface_add_network(
10410 wpa_s, reply, reply_size);
10411 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
10412 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
10414 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
10415 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
10417 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
10418 reply_len = wpa_supplicant_ctrl_iface_get_network(
10419 wpa_s, buf + 12, reply, reply_size);
10420 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
10421 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
10424 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
10425 reply_len = wpa_supplicant_ctrl_iface_list_creds(
10426 wpa_s, reply, reply_size);
10427 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
10428 reply_len = wpa_supplicant_ctrl_iface_add_cred(
10429 wpa_s, reply, reply_size);
10430 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
10431 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
10433 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
10434 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
10436 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
10437 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
10440 #ifndef CONFIG_NO_CONFIG_WRITE
10441 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10442 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
10444 #endif /* CONFIG_NO_CONFIG_WRITE */
10445 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
10446 reply_len = wpa_supplicant_ctrl_iface_get_capability(
10447 wpa_s, buf + 15, reply, reply_size);
10448 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
10449 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
10451 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
10452 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
10454 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10455 reply_len = wpa_supplicant_global_iface_list(
10456 wpa_s->global, reply, reply_size);
10457 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
10458 reply_len = wpa_supplicant_global_iface_interfaces(
10459 wpa_s->global, buf + 10, reply, reply_size);
10460 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
10461 reply_len = wpa_supplicant_ctrl_iface_bss(
10462 wpa_s, buf + 4, reply, reply_size);
10464 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
10465 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
10466 } else if (os_strncmp(buf, "STA ", 4) == 0) {
10467 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
10469 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
10470 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
10472 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
10473 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
10475 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
10476 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
10478 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
10479 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
10481 } else if (os_strcmp(buf, "STOP_AP") == 0) {
10482 if (wpas_ap_stop_ap(wpa_s))
10484 #endif /* CONFIG_AP */
10485 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10486 wpas_notify_suspend(wpa_s->global);
10487 } else if (os_strcmp(buf, "RESUME") == 0) {
10488 wpas_notify_resume(wpa_s->global);
10489 #ifdef CONFIG_TESTING_OPTIONS
10490 } else if (os_strcmp(buf, "DROP_SA") == 0) {
10491 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
10492 #endif /* CONFIG_TESTING_OPTIONS */
10493 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
10494 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
10496 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
10497 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
10498 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
10499 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
10501 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
10502 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
10505 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
10506 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
10508 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
10509 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
10511 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
10512 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
10514 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
10515 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
10517 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
10518 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
10521 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10522 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
10525 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
10526 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
10527 wpa_s, buf + 17, reply, reply_size);
10528 #endif /* CONFIG_TDLS */
10529 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
10530 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
10531 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
10532 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
10534 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
10535 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
10537 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
10538 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
10540 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
10541 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
10543 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
10544 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
10546 #ifdef CONFIG_AUTOSCAN
10547 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
10548 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
10550 #endif /* CONFIG_AUTOSCAN */
10551 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
10552 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
10555 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
10556 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
10558 #endif /* ANDROID */
10559 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
10560 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
10562 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
10563 pmksa_cache_clear_current(wpa_s->wpa);
10564 eapol_sm_request_reauth(wpa_s->eapol);
10566 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
10567 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
10569 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
10570 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
10572 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
10573 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
10575 #endif /* CONFIG_WNM */
10576 } else if (os_strcmp(buf, "FLUSH") == 0) {
10577 wpa_supplicant_ctrl_iface_flush(wpa_s);
10578 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
10579 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
10581 #ifdef CONFIG_TESTING_OPTIONS
10582 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
10583 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
10585 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
10586 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
10587 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
10588 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
10590 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
10591 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
10593 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
10594 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
10596 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
10597 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
10599 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
10600 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
10602 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
10603 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
10605 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
10606 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
10608 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
10609 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
10610 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
10611 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
10613 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
10614 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
10615 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
10616 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
10618 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
10619 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
10621 } else if (os_strcmp(buf, "RESET_PN") == 0) {
10622 if (wpas_ctrl_reset_pn(wpa_s) < 0)
10624 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
10625 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
10627 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
10628 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
10630 #ifdef CONFIG_IEEE80211W
10631 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
10632 sme_event_unprot_disconnect(
10633 wpa_s, wpa_s->bssid, NULL,
10634 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
10635 #endif /* CONFIG_IEEE80211W */
10636 #endif /* CONFIG_TESTING_OPTIONS */
10637 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
10638 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
10640 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
10641 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
10643 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10644 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
10646 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10647 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
10649 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
10650 wpas_ctrl_iface_erp_flush(wpa_s);
10651 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
10652 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
10654 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
10655 reply_len = wpas_ctrl_iface_get_pref_freq_list(
10656 wpa_s, buf + 19, reply, reply_size);
10658 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
10659 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
10661 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
10662 wpas_flush_fils_hlp_req(wpa_s);
10663 #endif /* CONFIG_FILS */
10665 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
10668 res = wpas_dpp_qr_code(wpa_s, buf + 12);
10672 reply_len = os_snprintf(reply, reply_size, "%d", res);
10673 if (os_snprintf_error(reply_size, reply_len))
10676 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10679 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
10683 reply_len = os_snprintf(reply, reply_size, "%d", res);
10684 if (os_snprintf_error(reply_size, reply_len))
10687 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10688 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
10690 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10693 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
10697 reply_len = os_snprintf(reply, reply_size, "%s", uri);
10698 if (os_snprintf_error(reply_size, reply_len))
10701 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10702 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
10703 reply, reply_size);
10704 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
10705 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
10707 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
10708 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
10710 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
10711 wpas_dpp_stop(wpa_s);
10712 wpas_dpp_listen_stop(wpa_s);
10713 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10716 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
10720 reply_len = os_snprintf(reply, reply_size, "%d", res);
10721 if (os_snprintf_error(reply_size, reply_len))
10724 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10725 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
10727 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10728 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
10730 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10731 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
10733 reply, reply_size);
10734 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
10737 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
10741 reply_len = os_snprintf(reply, reply_size, "%d", res);
10742 if (os_snprintf_error(reply_size, reply_len))
10745 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
10746 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
10748 #endif /* CONFIG_DPP */
10750 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
10754 if (reply_len < 0) {
10755 os_memcpy(reply, "FAIL\n", 5);
10759 *resp_len = reply_len;
10764 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
10767 struct wpa_interface iface;
10769 struct wpa_supplicant *wpa_s;
10770 unsigned int create_iface = 0;
10771 u8 mac_addr[ETH_ALEN];
10772 enum wpa_driver_if_type type = WPA_IF_STATION;
10775 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10776 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10778 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
10780 os_memset(&iface, 0, sizeof(iface));
10783 iface.ifname = pos = cmd;
10784 pos = os_strchr(pos, '\t');
10787 if (iface.ifname[0] == '\0')
10792 iface.confname = pos;
10793 pos = os_strchr(pos, '\t');
10796 if (iface.confname[0] == '\0')
10797 iface.confname = NULL;
10801 iface.driver = pos;
10802 pos = os_strchr(pos, '\t');
10805 if (iface.driver[0] == '\0')
10806 iface.driver = NULL;
10810 iface.ctrl_interface = pos;
10811 pos = os_strchr(pos, '\t');
10814 if (iface.ctrl_interface[0] == '\0')
10815 iface.ctrl_interface = NULL;
10819 iface.driver_param = pos;
10820 pos = os_strchr(pos, '\t');
10823 if (iface.driver_param[0] == '\0')
10824 iface.driver_param = NULL;
10828 iface.bridge_ifname = pos;
10829 pos = os_strchr(pos, '\t');
10832 if (iface.bridge_ifname[0] == '\0')
10833 iface.bridge_ifname = NULL;
10838 pos = os_strchr(pos, '\t');
10844 if (os_strcmp(extra, "create") == 0) {
10849 if (os_strcmp(pos, "sta") == 0) {
10850 type = WPA_IF_STATION;
10851 } else if (os_strcmp(pos, "ap") == 0) {
10852 type = WPA_IF_AP_BSS;
10854 wpa_printf(MSG_DEBUG,
10855 "INTERFACE_ADD unsupported interface type: '%s'",
10860 wpa_printf(MSG_DEBUG,
10861 "INTERFACE_ADD unsupported extra parameter: '%s'",
10867 if (create_iface) {
10868 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
10870 if (!global->ifaces)
10872 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
10873 NULL, NULL, NULL, mac_addr, NULL) < 0) {
10874 wpa_printf(MSG_ERROR,
10875 "CTRL_IFACE interface creation failed");
10879 wpa_printf(MSG_DEBUG,
10880 "CTRL_IFACE interface '%s' created with MAC addr: "
10881 MACSTR, iface.ifname, MAC2STR(mac_addr));
10884 if (wpa_supplicant_get_iface(global, iface.ifname))
10887 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
10890 wpa_s->added_vif = create_iface;
10895 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
10900 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
10903 struct wpa_supplicant *wpa_s;
10905 unsigned int delete_iface;
10907 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
10909 wpa_s = wpa_supplicant_get_iface(global, cmd);
10912 delete_iface = wpa_s->added_vif;
10913 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
10914 if (!ret && delete_iface) {
10915 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
10917 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
10923 static void wpa_free_iface_info(struct wpa_interface_info *iface)
10925 struct wpa_interface_info *prev;
10929 iface = iface->next;
10931 os_free(prev->ifname);
10932 os_free(prev->desc);
10938 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
10939 char *buf, int len)
10942 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
10945 for (i = 0; wpa_drivers[i]; i++) {
10946 const struct wpa_driver_ops *drv = wpa_drivers[i];
10947 if (drv->get_interfaces == NULL)
10949 tmp = drv->get_interfaces(global->drv_priv[i]);
10954 iface = last = tmp;
10963 for (tmp = iface; tmp; tmp = tmp->next) {
10964 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
10965 tmp->drv_name, tmp->ifname,
10966 tmp->desc ? tmp->desc : "");
10967 if (os_snprintf_error(end - pos, res)) {
10974 wpa_free_iface_info(iface);
10980 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
10982 char *buf, int len)
10986 struct wpa_supplicant *wpa_s;
10990 show_ctrl = !!os_strstr(input, "ctrl");
10992 wpa_s = global->ifaces;
10998 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
11000 wpa_s->conf->ctrl_interface ?
11001 wpa_s->conf->ctrl_interface : "N/A");
11003 res = os_snprintf(pos, end - pos, "%s\n",
11006 if (os_snprintf_error(end - pos, res)) {
11011 wpa_s = wpa_s->next;
11017 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
11018 const char *ifname,
11019 char *cmd, size_t *resp_len)
11021 struct wpa_supplicant *wpa_s;
11023 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11024 if (os_strcmp(ifname, wpa_s->ifname) == 0)
11028 if (wpa_s == NULL) {
11029 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
11031 *resp_len = os_strlen(resp);
11037 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
11041 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
11042 char *buf, size_t *resp_len)
11045 static const char * cmd[] = {
11051 "P2P_GET_PASSPHRASE",
11052 "P2P_SERVICE_UPDATE",
11053 "P2P_SERVICE_FLUSH",
11056 "P2P_PRESENCE_REQ",
11060 #endif /* CONFIG_AP */
11063 static const char * prefix[] = {
11066 #endif /* ANDROID */
11073 "P2P_GROUP_REMOVE ",
11075 "P2P_GROUP_MEMBER ",
11077 "P2P_SERV_DISC_REQ ",
11078 "P2P_SERV_DISC_CANCEL_REQ ",
11079 "P2P_SERV_DISC_RESP ",
11080 "P2P_SERV_DISC_EXTERNAL ",
11081 "P2P_SERVICE_ADD ",
11082 "P2P_SERVICE_DEL ",
11083 "P2P_SERVICE_REP ",
11088 "P2P_UNAUTHORIZE ",
11089 "P2P_PRESENCE_REQ ",
11091 "P2P_REMOVE_CLIENT ",
11093 "WPS_NFC_TAG_READ ",
11094 "NFC_GET_HANDOVER_SEL ",
11095 "NFC_GET_HANDOVER_REQ ",
11096 "NFC_REPORT_HANDOVER ",
11097 "P2P_ASP_PROVISION ",
11098 "P2P_ASP_PROVISION_RESP ",
11102 #endif /* CONFIG_AP */
11108 if (global->p2p_init_wpa_s == NULL)
11111 for (i = 0; !found && cmd[i]; i++) {
11112 if (os_strcmp(buf, cmd[i]) == 0)
11116 for (i = 0; !found && prefix[i]; i++) {
11117 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
11122 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11124 #endif /* CONFIG_P2P */
11129 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
11130 char *buf, size_t *resp_len)
11132 #ifdef CONFIG_WIFI_DISPLAY
11133 if (global->p2p_init_wpa_s == NULL)
11135 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
11136 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
11137 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11139 #endif /* CONFIG_WIFI_DISPLAY */
11144 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
11145 char *buf, size_t *resp_len)
11149 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
11153 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
11161 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11165 value = os_strchr(cmd, ' ');
11170 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11172 #ifdef CONFIG_WIFI_DISPLAY
11173 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11174 wifi_display_enable(global, !!atoi(value));
11177 #endif /* CONFIG_WIFI_DISPLAY */
11179 /* Restore cmd to its original value to allow redirection */
11186 static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11189 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11193 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11194 * <variable name> */
11196 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11197 p = os_strchr(cmd, ' ');
11202 wpa_s[i] = global->ifaces;
11203 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11204 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11209 wpa_printf(MSG_DEBUG,
11210 "CTRL_IFACE: Could not find iface=%s", cmd);
11217 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11221 #ifndef CONFIG_NO_CONFIG_WRITE
11222 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11224 int ret = 0, saved = 0;
11225 struct wpa_supplicant *wpa_s;
11227 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11228 if (!wpa_s->conf->update_config) {
11229 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11233 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11234 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11237 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11242 if (!saved && !ret) {
11243 wpa_dbg(wpa_s, MSG_DEBUG,
11244 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11250 #endif /* CONFIG_NO_CONFIG_WRITE */
11253 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11254 char *buf, size_t buflen)
11258 struct wpa_supplicant *wpa_s;
11261 end = buf + buflen;
11264 if (global->p2p && !global->p2p_disabled) {
11265 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11268 MAC2STR(global->p2p_dev_addr),
11269 p2p_get_state_txt(global->p2p));
11270 if (os_snprintf_error(end - pos, ret))
11273 } else if (global->p2p) {
11274 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
11275 if (os_snprintf_error(end - pos, ret))
11279 #endif /* CONFIG_P2P */
11281 #ifdef CONFIG_WIFI_DISPLAY
11282 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11283 !!global->wifi_display);
11284 if (os_snprintf_error(end - pos, ret))
11287 #endif /* CONFIG_WIFI_DISPLAY */
11289 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11290 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
11291 "address=" MACSTR "\n",
11292 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
11293 if (os_snprintf_error(end - pos, ret))
11304 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
11305 char *cmd, char *buf,
11308 char ifname[IFNAMSIZ + 1];
11309 struct fst_iface_cfg cfg;
11310 struct wpa_supplicant *wpa_s;
11311 struct fst_wpa_obj iface_obj;
11313 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
11314 wpa_s = wpa_supplicant_get_iface(global, ifname);
11317 wpa_printf(MSG_INFO, "FST: Already attached");
11320 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
11321 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
11324 return os_snprintf(buf, reply_size, "OK\n");
11332 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
11333 char *cmd, char *buf,
11336 char ifname[IFNAMSIZ + 1];
11337 struct wpa_supplicant *wpa_s;
11339 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
11340 wpa_s = wpa_supplicant_get_iface(global, ifname);
11342 if (!fst_iface_detach(ifname)) {
11344 return os_snprintf(buf, reply_size, "OK\n");
11352 #endif /* CONFIG_FST */
11355 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
11356 char *buf, size_t *resp_len)
11359 const int reply_size = 2048;
11361 int level = MSG_DEBUG;
11363 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
11364 char *pos = os_strchr(buf + 7, ' ');
11367 return wpas_global_ctrl_iface_ifname(global,
11373 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
11377 if (os_strcmp(buf, "PING") == 0)
11378 level = MSG_EXCESSIVE;
11379 wpa_hexdump_ascii(level, "RX global ctrl_iface",
11380 (const u8 *) buf, os_strlen(buf));
11382 reply = os_malloc(reply_size);
11383 if (reply == NULL) {
11388 os_memcpy(reply, "OK\n", 3);
11391 if (os_strcmp(buf, "PING") == 0) {
11392 os_memcpy(reply, "PONG\n", 5);
11394 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
11395 if (wpa_supplicant_global_iface_add(global, buf + 14))
11397 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
11398 if (wpa_supplicant_global_iface_remove(global, buf + 17))
11400 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11401 reply_len = wpa_supplicant_global_iface_list(
11402 global, reply, reply_size);
11403 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
11404 reply_len = wpa_supplicant_global_iface_interfaces(
11405 global, buf + 10, reply, reply_size);
11407 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
11408 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
11411 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
11412 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
11415 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
11416 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
11417 #endif /* CONFIG_FST */
11418 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11419 wpa_supplicant_terminate_proc(global);
11420 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11421 wpas_notify_suspend(global);
11422 } else if (os_strcmp(buf, "RESUME") == 0) {
11423 wpas_notify_resume(global);
11424 } else if (os_strncmp(buf, "SET ", 4) == 0) {
11425 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
11427 if (global->p2p_init_wpa_s) {
11429 /* Check if P2P redirection would work for this
11431 return wpa_supplicant_ctrl_iface_process(
11432 global->p2p_init_wpa_s,
11435 #endif /* CONFIG_P2P */
11438 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
11439 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
11441 #ifndef CONFIG_NO_CONFIG_WRITE
11442 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11443 if (wpas_global_ctrl_iface_save_config(global))
11445 #endif /* CONFIG_NO_CONFIG_WRITE */
11446 } else if (os_strcmp(buf, "STATUS") == 0) {
11447 reply_len = wpas_global_ctrl_iface_status(global, reply,
11449 #ifdef CONFIG_MODULE_TESTS
11450 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
11451 if (wpas_module_tests() < 0)
11453 #endif /* CONFIG_MODULE_TESTS */
11454 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11455 if (wpa_debug_reopen_file() < 0)
11458 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11462 if (reply_len < 0) {
11463 os_memcpy(reply, "FAIL\n", 5);
11467 *resp_len = reply_len;