2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2015, 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"
60 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
62 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
65 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
69 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
72 u8 addr[ETH_ALEN], *filter = NULL, *n;
79 if (hwaddr_aton(pos, addr)) {
83 n = os_realloc_array(filter, count + 1, ETH_ALEN);
89 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
92 pos = os_strchr(pos, ' ');
97 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
98 os_free(wpa_s->bssid_filter);
99 wpa_s->bssid_filter = filter;
100 wpa_s->bssid_filter_count = count;
106 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
109 u8 addr[ETH_ALEN], *bssid = NULL, *n;
110 struct wpa_ssid_value *ssid = NULL, *ns;
111 size_t count = 0, ssid_count = 0;
115 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
116 * SSID_SPEC ::= ssid <SSID_HEX>
117 * BSSID_SPEC ::= bssid <BSSID_HEX>
124 if (os_strncmp(pos, "bssid ", 6) == 0) {
127 res = hwaddr_aton2(pos, addr);
131 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
132 "BSSID value '%s'", pos);
136 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
143 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
145 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
151 if (*end == '\0' || *end == ' ')
156 ns = os_realloc_array(ssid, ssid_count + 1,
157 sizeof(struct wpa_ssid_value));
165 if ((end - pos) & 0x01 ||
166 end - pos > 2 * SSID_MAX_LEN ||
167 hexstr2bin(pos, ssid[ssid_count].ssid,
168 (end - pos) / 2) < 0) {
171 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
172 "SSID value '%s'", pos);
175 ssid[ssid_count].ssid_len = (end - pos) / 2;
176 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
177 ssid[ssid_count].ssid,
178 ssid[ssid_count].ssid_len);
182 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
189 pos = os_strchr(pos, ' ');
194 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
195 os_free(wpa_s->disallow_aps_bssid);
196 wpa_s->disallow_aps_bssid = bssid;
197 wpa_s->disallow_aps_bssid_count = count;
199 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
200 os_free(wpa_s->disallow_aps_ssid);
201 wpa_s->disallow_aps_ssid = ssid;
202 wpa_s->disallow_aps_ssid_count = ssid_count;
204 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
207 c = wpa_s->current_ssid;
208 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
211 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
212 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
215 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
216 "because current AP was marked disallowed");
219 wpa_s->sme.prev_bssid_set = 0;
220 #endif /* CONFIG_SME */
221 wpa_s->reassociate = 1;
222 wpa_s->own_disconnect_req = 1;
223 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
224 wpa_supplicant_req_scan(wpa_s, 0, 0);
230 #ifndef CONFIG_NO_CONFIG_BLOBS
231 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
234 struct wpa_config_blob *blob;
237 pos = os_strchr(pos, ' ');
241 len = os_strlen(pos);
245 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
246 blob = os_zalloc(sizeof(*blob));
249 blob->name = os_strdup(name);
250 blob->data = os_malloc(len / 2);
251 if (blob->name == NULL || blob->data == NULL) {
252 wpa_config_free_blob(blob);
256 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
257 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
258 wpa_config_free_blob(blob);
263 wpa_config_set_blob(wpa_s->conf, blob);
267 #endif /* CONFIG_NO_CONFIG_BLOBS */
270 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
278 params = os_strchr(cmd, ' ');
279 os_free(wpa_s->manual_sched_scan_freqs);
282 pos = os_strstr(params, "freq=");
284 freqs = freq_range_to_channel_list(wpa_s,
287 wpa_s->manual_sched_scan_freqs = freqs;
288 ret = wpas_start_pno(wpa_s);
290 ret = wpas_stop_pno(wpa_s);
296 static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
298 union wpa_event_data event;
300 if (os_strcmp(band, "AUTO") == 0)
301 wpa_s->setband = WPA_SETBAND_AUTO;
302 else if (os_strcmp(band, "5G") == 0)
303 wpa_s->setband = WPA_SETBAND_5G;
304 else if (os_strcmp(band, "2G") == 0)
305 wpa_s->setband = WPA_SETBAND_2G;
309 if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
310 os_memset(&event, 0, sizeof(event));
311 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
312 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
313 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
320 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
325 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
326 wpabuf_free(wpa_s->lci);
331 lci = wpabuf_parse_bin(cmd);
335 if (os_get_reltime(&wpa_s->lci_time)) {
340 wpabuf_free(wpa_s->lci);
348 wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
352 if (os_strcmp(cmd, "disable") == 0) {
353 wpa_s->srp.relative_rssi_set = 0;
357 relative_rssi = atoi(cmd);
358 if (relative_rssi < 0 || relative_rssi > 100)
360 wpa_s->srp.relative_rssi = relative_rssi;
361 wpa_s->srp.relative_rssi_set = 1;
366 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
372 /* <band>:adjust_value */
373 pos = os_strchr(cmd, ':');
377 adjust_rssi = atoi(pos);
378 if (adjust_rssi < -100 || adjust_rssi > 100)
381 if (os_strncmp(cmd, "2G", 2) == 0)
382 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
383 else if (os_strncmp(cmd, "5G", 2) == 0)
384 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
388 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
394 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
397 struct wpabuf *ric_ies;
399 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
400 wpabuf_free(wpa_s->ric_ies);
401 wpa_s->ric_ies = NULL;
405 ric_ies = wpabuf_parse_bin(cmd);
409 wpabuf_free(wpa_s->ric_ies);
410 wpa_s->ric_ies = ric_ies;
416 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
422 value = os_strchr(cmd, ' ');
427 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
428 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
429 eapol_sm_configure(wpa_s->eapol,
430 atoi(value), -1, -1, -1);
431 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
432 eapol_sm_configure(wpa_s->eapol,
433 -1, atoi(value), -1, -1);
434 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
435 eapol_sm_configure(wpa_s->eapol,
436 -1, -1, atoi(value), -1);
437 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
438 eapol_sm_configure(wpa_s->eapol,
439 -1, -1, -1, atoi(value));
440 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
441 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
446 wpa_config_process_global(wpa_s->conf, cmd, -1);
448 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
450 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
455 wpa_config_process_global(wpa_s->conf, cmd, -1);
457 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
458 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
463 wpa_config_process_global(wpa_s->conf, cmd, -1);
465 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
466 wpa_s->wps_fragment_size = atoi(value);
467 #ifdef CONFIG_WPS_TESTING
468 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
470 val = strtol(value, NULL, 0);
471 if (val < 0 || val > 0xff) {
473 wpa_printf(MSG_DEBUG, "WPS: Invalid "
474 "wps_version_number %ld", val);
476 wps_version_number = val;
477 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
479 (wps_version_number & 0xf0) >> 4,
480 wps_version_number & 0x0f);
482 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
483 wps_testing_dummy_cred = atoi(value);
484 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
485 wps_testing_dummy_cred);
486 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
487 wps_corrupt_pkhash = atoi(value);
488 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
490 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
491 if (value[0] == '\0') {
492 wps_force_auth_types_in_use = 0;
494 wps_force_auth_types = strtol(value, NULL, 0);
495 wps_force_auth_types_in_use = 1;
497 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
498 if (value[0] == '\0') {
499 wps_force_encr_types_in_use = 0;
501 wps_force_encr_types = strtol(value, NULL, 0);
502 wps_force_encr_types_in_use = 1;
504 #endif /* CONFIG_WPS_TESTING */
505 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
506 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
509 #ifdef CONFIG_TDLS_TESTING
510 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
511 tdls_testing = strtol(value, NULL, 0);
512 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
513 #endif /* CONFIG_TDLS_TESTING */
514 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
515 int disabled = atoi(value);
516 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
518 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
520 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
522 wpa_tdls_enable(wpa_s->wpa, !disabled);
523 #endif /* CONFIG_TDLS */
524 } else if (os_strcasecmp(cmd, "pno") == 0) {
525 ret = wpas_ctrl_pno(wpa_s, value);
526 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
527 int disabled = atoi(value);
528 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
531 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
532 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
533 if (os_strcmp(value, "disable") == 0)
534 wpa_s->set_sta_uapsd = 0;
538 /* format: BE,BK,VI,VO;max SP Length */
540 pos = os_strchr(value, ',');
545 pos = os_strchr(pos, ',');
550 pos = os_strchr(pos, ',');
555 /* ignore max SP Length for now */
557 wpa_s->set_sta_uapsd = 1;
558 wpa_s->sta_uapsd = 0;
560 wpa_s->sta_uapsd |= BIT(0);
562 wpa_s->sta_uapsd |= BIT(1);
564 wpa_s->sta_uapsd |= BIT(2);
566 wpa_s->sta_uapsd |= BIT(3);
568 } else if (os_strcasecmp(cmd, "ps") == 0) {
569 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
570 #ifdef CONFIG_WIFI_DISPLAY
571 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
572 int enabled = !!atoi(value);
573 if (enabled && !wpa_s->global->p2p)
576 wifi_display_enable(wpa_s->global, enabled);
577 #endif /* CONFIG_WIFI_DISPLAY */
578 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
579 ret = set_bssid_filter(wpa_s, value);
580 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
581 ret = set_disallow_aps(wpa_s, value);
582 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
583 wpa_s->no_keep_alive = !!atoi(value);
585 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
586 os_free(wpa_s->dpp_configurator_params);
587 wpa_s->dpp_configurator_params = os_strdup(value);
588 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
589 wpa_s->dpp_init_max_tries = atoi(value);
590 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
591 wpa_s->dpp_init_retry_time = atoi(value);
592 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
593 wpa_s->dpp_resp_wait_time = atoi(value);
594 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
595 wpa_s->dpp_resp_max_tries = atoi(value);
596 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
597 wpa_s->dpp_resp_retry_time = atoi(value);
598 #ifdef CONFIG_TESTING_OPTIONS
599 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
600 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
602 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
603 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
605 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
606 size_t hex_len = os_strlen(value);
609 2 * sizeof(dpp_pkex_ephemeral_key_override))
611 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
615 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
616 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
617 size_t hex_len = os_strlen(value);
619 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
621 else if (hexstr2bin(value, dpp_protocol_key_override,
625 dpp_protocol_key_override_len = hex_len / 2;
626 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
627 size_t hex_len = os_strlen(value);
629 if (hex_len > 2 * sizeof(dpp_nonce_override))
631 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
634 dpp_nonce_override_len = hex_len / 2;
635 #endif /* CONFIG_TESTING_OPTIONS */
636 #endif /* CONFIG_DPP */
637 #ifdef CONFIG_TESTING_OPTIONS
638 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
639 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
640 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
641 wpa_s->ext_eapol_frame_io = !!atoi(value);
643 if (wpa_s->ap_iface) {
644 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
645 wpa_s->ext_eapol_frame_io;
647 #endif /* CONFIG_AP */
648 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
649 wpa_s->extra_roc_dur = atoi(value);
650 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
651 wpa_s->test_failure = atoi(value);
652 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
653 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
654 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
655 wpa_s->ignore_auth_resp = !!atoi(value);
656 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
657 wpa_s->ignore_assoc_disallow = !!atoi(value);
658 wpa_drv_ignore_assoc_disallow(wpa_s,
659 wpa_s->ignore_assoc_disallow);
660 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
661 wpa_s->reject_btm_req_reason = atoi(value);
662 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
663 os_free(wpa_s->get_pref_freq_list_override);
665 wpa_s->get_pref_freq_list_override = NULL;
667 wpa_s->get_pref_freq_list_override = os_strdup(value);
668 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
669 wpabuf_free(wpa_s->sae_commit_override);
670 if (value[0] == '\0')
671 wpa_s->sae_commit_override = NULL;
673 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
675 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
676 os_free(wpa_s->dpp_config_obj_override);
677 if (value[0] == '\0')
678 wpa_s->dpp_config_obj_override = NULL;
680 wpa_s->dpp_config_obj_override = os_strdup(value);
681 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
682 os_free(wpa_s->dpp_discovery_override);
683 if (value[0] == '\0')
684 wpa_s->dpp_discovery_override = NULL;
686 wpa_s->dpp_discovery_override = os_strdup(value);
687 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
688 os_free(wpa_s->dpp_groups_override);
689 if (value[0] == '\0')
690 wpa_s->dpp_groups_override = NULL;
692 wpa_s->dpp_groups_override = os_strdup(value);
693 } else if (os_strcasecmp(cmd,
694 "dpp_ignore_netaccesskey_mismatch") == 0) {
695 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
696 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
697 dpp_test = atoi(value);
698 #endif /* CONFIG_DPP */
699 #endif /* CONFIG_TESTING_OPTIONS */
701 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
702 wpa_s->disable_fils = !!atoi(value);
703 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
704 wpa_supplicant_set_default_scan_ies(wpa_s);
705 #endif /* CONFIG_FILS */
706 #ifndef CONFIG_NO_CONFIG_BLOBS
707 } else if (os_strcmp(cmd, "blob") == 0) {
708 ret = wpas_ctrl_set_blob(wpa_s, value);
709 #endif /* CONFIG_NO_CONFIG_BLOBS */
710 } else if (os_strcasecmp(cmd, "setband") == 0) {
711 ret = wpas_ctrl_set_band(wpa_s, value);
713 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
714 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
717 wpa_config_process_global(wpa_s->conf, cmd, -1);
719 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
720 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
721 } else if (os_strcasecmp(cmd, "oce") == 0) {
722 wpa_s->conf->oce = atoi(value);
723 if (wpa_s->conf->oce) {
724 if ((wpa_s->conf->oce & OCE_STA) &&
725 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
726 wpa_s->enable_oce = OCE_STA;
728 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
730 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
731 /* TODO: Need to add STA-CFON support */
732 wpa_printf(MSG_ERROR,
733 "OCE STA-CFON feature is not yet supported");
737 wpa_s->enable_oce = 0;
739 wpa_supplicant_set_default_scan_ies(wpa_s);
740 #endif /* CONFIG_MBO */
741 } else if (os_strcasecmp(cmd, "lci") == 0) {
742 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
743 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
744 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
745 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
746 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
747 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
748 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
749 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
750 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
751 } else if (os_strcasecmp(cmd, "roaming") == 0) {
752 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
754 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
755 struct wpabuf *elems;
757 elems = wpabuf_parse_bin(value);
760 wnm_set_coloc_intf_elems(wpa_s, elems);
761 #endif /* CONFIG_WNM */
764 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
766 wpa_supplicant_update_config(wpa_s);
773 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
774 char *cmd, char *buf, size_t buflen)
778 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
780 if (os_strcmp(cmd, "version") == 0) {
781 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
782 } else if (os_strcasecmp(cmd, "country") == 0) {
783 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
784 res = os_snprintf(buf, buflen, "%c%c",
785 wpa_s->conf->country[0],
786 wpa_s->conf->country[1]);
787 #ifdef CONFIG_WIFI_DISPLAY
788 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
790 if (wpa_s->global->p2p == NULL ||
791 wpa_s->global->p2p_disabled)
794 enabled = wpa_s->global->wifi_display;
795 res = os_snprintf(buf, buflen, "%d", enabled);
796 #endif /* CONFIG_WIFI_DISPLAY */
797 #ifdef CONFIG_TESTING_GET_GTK
798 } else if (os_strcmp(cmd, "gtk") == 0) {
799 if (wpa_s->last_gtk_len == 0)
801 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
802 wpa_s->last_gtk_len);
804 #endif /* CONFIG_TESTING_GET_GTK */
805 } else if (os_strcmp(cmd, "tls_library") == 0) {
806 res = tls_get_library_version(buf, buflen);
807 #ifdef CONFIG_TESTING_OPTIONS
808 } else if (os_strcmp(cmd, "anonce") == 0) {
809 return wpa_snprintf_hex(buf, buflen,
810 wpa_sm_get_anonce(wpa_s->wpa),
812 #endif /* CONFIG_TESTING_OPTIONS */
814 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
817 if (os_snprintf_error(buflen, res))
823 #ifdef IEEE8021X_EAPOL
824 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
828 struct wpa_ssid *ssid = wpa_s->current_ssid;
830 if (hwaddr_aton(addr, bssid)) {
831 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
836 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
837 rsn_preauth_deinit(wpa_s->wpa);
838 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
843 #endif /* IEEE8021X_EAPOL */
848 static int wpa_supplicant_ctrl_iface_tdls_discover(
849 struct wpa_supplicant *wpa_s, char *addr)
854 if (hwaddr_aton(addr, peer)) {
855 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
856 "address '%s'", addr);
860 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
863 if (wpa_tdls_is_external_setup(wpa_s->wpa))
864 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
866 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
872 static int wpa_supplicant_ctrl_iface_tdls_setup(
873 struct wpa_supplicant *wpa_s, char *addr)
878 if (hwaddr_aton(addr, peer)) {
879 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
880 "address '%s'", addr);
884 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
887 if ((wpa_s->conf->tdls_external_control) &&
888 wpa_tdls_is_external_setup(wpa_s->wpa))
889 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
891 wpa_tdls_remove(wpa_s->wpa, peer);
893 if (wpa_tdls_is_external_setup(wpa_s->wpa))
894 ret = wpa_tdls_start(wpa_s->wpa, peer);
896 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
902 static int wpa_supplicant_ctrl_iface_tdls_teardown(
903 struct wpa_supplicant *wpa_s, char *addr)
908 if (os_strcmp(addr, "*") == 0) {
909 /* remove everyone */
910 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
911 wpa_tdls_teardown_peers(wpa_s->wpa);
915 if (hwaddr_aton(addr, peer)) {
916 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
917 "address '%s'", addr);
921 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
924 if ((wpa_s->conf->tdls_external_control) &&
925 wpa_tdls_is_external_setup(wpa_s->wpa))
926 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
928 if (wpa_tdls_is_external_setup(wpa_s->wpa))
929 ret = wpa_tdls_teardown_link(
931 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
933 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
939 static int ctrl_iface_get_capability_tdls(
940 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
944 ret = os_snprintf(buf, buflen, "%s\n",
945 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
947 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
948 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
949 if (os_snprintf_error(buflen, ret))
955 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
956 struct wpa_supplicant *wpa_s, char *cmd)
959 struct hostapd_freq_params freq_params;
963 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
965 "tdls_chanswitch: Only supported with external setup");
969 os_memset(&freq_params, 0, sizeof(freq_params));
971 pos = os_strchr(cmd, ' ');
976 oper_class = strtol(pos, &end, 10);
979 "tdls_chanswitch: Invalid op class provided");
984 freq_params.freq = atoi(pos);
985 if (freq_params.freq == 0) {
986 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
990 #define SET_FREQ_SETTING(str) \
992 const char *pos2 = os_strstr(pos, " " #str "="); \
994 pos2 += sizeof(" " #str "=") - 1; \
995 freq_params.str = atoi(pos2); \
999 SET_FREQ_SETTING(center_freq1);
1000 SET_FREQ_SETTING(center_freq2);
1001 SET_FREQ_SETTING(bandwidth);
1002 SET_FREQ_SETTING(sec_channel_offset);
1003 #undef SET_FREQ_SETTING
1005 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1006 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1008 if (hwaddr_aton(cmd, peer)) {
1009 wpa_printf(MSG_DEBUG,
1010 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1015 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1016 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1017 MAC2STR(peer), oper_class, freq_params.freq,
1018 freq_params.center_freq1, freq_params.center_freq2,
1019 freq_params.bandwidth, freq_params.sec_channel_offset,
1020 freq_params.ht_enabled ? " HT" : "",
1021 freq_params.vht_enabled ? " VHT" : "");
1023 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1028 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1029 struct wpa_supplicant *wpa_s, char *cmd)
1033 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1034 wpa_printf(MSG_INFO,
1035 "tdls_chanswitch: Only supported with external setup");
1039 if (hwaddr_aton(cmd, peer)) {
1040 wpa_printf(MSG_DEBUG,
1041 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1046 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1049 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1053 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1054 struct wpa_supplicant *wpa_s, const char *addr,
1055 char *buf, size_t buflen)
1058 const char *tdls_status;
1061 if (hwaddr_aton(addr, peer)) {
1062 wpa_printf(MSG_DEBUG,
1063 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1067 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1070 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1071 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1072 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1073 if (os_snprintf_error(buflen, ret))
1079 #endif /* CONFIG_TDLS */
1082 static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1084 char *token, *context = NULL;
1085 struct wmm_ac_ts_setup_params params = {
1090 while ((token = str_token(cmd, " ", &context))) {
1091 if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 ||
1092 sscanf(token, "up=%i", ¶ms.user_priority) == 1 ||
1093 sscanf(token, "nominal_msdu_size=%i",
1094 ¶ms.nominal_msdu_size) == 1 ||
1095 sscanf(token, "mean_data_rate=%i",
1096 ¶ms.mean_data_rate) == 1 ||
1097 sscanf(token, "min_phy_rate=%i",
1098 ¶ms.minimum_phy_rate) == 1 ||
1099 sscanf(token, "sba=%i",
1100 ¶ms.surplus_bandwidth_allowance) == 1)
1103 if (os_strcasecmp(token, "downlink") == 0) {
1104 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1105 } else if (os_strcasecmp(token, "uplink") == 0) {
1106 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1107 } else if (os_strcasecmp(token, "bidi") == 0) {
1108 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1109 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1110 params.fixed_nominal_msdu = 1;
1112 wpa_printf(MSG_DEBUG,
1113 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1120 return wpas_wmm_ac_addts(wpa_s, ¶ms);
1124 static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1126 u8 tsid = atoi(cmd);
1128 return wpas_wmm_ac_delts(wpa_s, tsid);
1132 #ifdef CONFIG_IEEE80211R
1133 static int wpa_supplicant_ctrl_iface_ft_ds(
1134 struct wpa_supplicant *wpa_s, char *addr)
1136 u8 target_ap[ETH_ALEN];
1137 struct wpa_bss *bss;
1140 if (hwaddr_aton(addr, target_ap)) {
1141 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1142 "address '%s'", addr);
1146 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1148 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1150 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1154 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1156 #endif /* CONFIG_IEEE80211R */
1160 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1163 u8 bssid[ETH_ALEN], *_bssid = bssid;
1165 u8 p2p_dev_addr[ETH_ALEN];
1166 #endif /* CONFIG_P2P */
1168 u8 *_p2p_dev_addr = NULL;
1169 #endif /* CONFIG_AP */
1171 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
1174 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1175 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1176 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1177 "P2P Device Address '%s'",
1181 _p2p_dev_addr = p2p_dev_addr;
1182 #endif /* CONFIG_P2P */
1183 } else if (hwaddr_aton(cmd, bssid)) {
1184 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1190 if (wpa_s->ap_iface)
1191 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1192 #endif /* CONFIG_AP */
1194 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
1198 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1199 char *cmd, char *buf,
1202 u8 bssid[ETH_ALEN], *_bssid = bssid;
1206 pin = os_strchr(cmd, ' ');
1210 if (os_strcmp(cmd, "any") == 0)
1212 else if (os_strcmp(cmd, "get") == 0) {
1213 if (wps_generate_pin((unsigned int *) &ret) < 0)
1216 } else if (hwaddr_aton(cmd, bssid)) {
1217 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1223 if (wpa_s->ap_iface) {
1228 pos = os_strchr(pin, ' ');
1231 timeout = atoi(pos);
1235 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
1236 buf, buflen, timeout);
1238 #endif /* CONFIG_AP */
1241 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1245 ret = os_snprintf(buf, buflen, "%s", pin);
1246 if (os_snprintf_error(buflen, ret))
1251 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1256 /* Return the generated PIN */
1257 ret = os_snprintf(buf, buflen, "%08d", ret);
1258 if (os_snprintf_error(buflen, ret))
1264 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1265 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1272 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1273 (u8 *) cmd, os_strlen(cmd));
1274 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1275 if (*pos < '0' || *pos > '9')
1279 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1283 if (len != 4 && len != 8) {
1284 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1290 unsigned int pin_val;
1291 pin_val = atoi(pin);
1292 if (!wps_pin_valid(pin_val)) {
1293 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1294 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
1295 if (os_snprintf_error(buflen, ret))
1301 ret = os_snprintf(buf, buflen, "%s", pin);
1302 if (os_snprintf_error(buflen, ret))
1309 #ifdef CONFIG_WPS_NFC
1311 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1314 u8 bssid[ETH_ALEN], *_bssid = bssid;
1316 if (cmd == NULL || cmd[0] == '\0')
1318 else if (hwaddr_aton(cmd, bssid))
1321 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1326 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1327 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1334 pos = os_strchr(cmd, ' ');
1337 if (os_strcmp(cmd, "WPS") == 0)
1339 else if (os_strcmp(cmd, "NDEF") == 0)
1344 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
1348 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1350 reply[res++] = '\n';
1359 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1360 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1366 if (os_strcmp(cmd, "WPS") == 0)
1368 else if (os_strcmp(cmd, "NDEF") == 0)
1373 buf = wpas_wps_nfc_token(wpa_s, ndef);
1377 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1379 reply[res++] = '\n';
1388 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1389 struct wpa_supplicant *wpa_s, char *pos)
1395 int forced_freq = 0;
1397 freq = strstr(pos, " freq=");
1401 forced_freq = atoi(freq);
1404 len = os_strlen(pos);
1409 buf = wpabuf_alloc(len);
1412 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1417 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
1424 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
1425 char *reply, size_t max_len,
1431 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
1435 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1437 reply[res++] = '\n';
1447 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1448 char *reply, size_t max_len,
1454 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1456 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1460 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1462 reply[res++] = '\n';
1469 #endif /* CONFIG_P2P */
1472 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1473 char *cmd, char *reply,
1479 pos = os_strchr(cmd, ' ');
1484 if (os_strcmp(cmd, "WPS") == 0)
1486 else if (os_strcmp(cmd, "NDEF") == 0)
1491 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1494 return wpas_ctrl_nfc_get_handover_req_wps(
1495 wpa_s, reply, max_len, ndef);
1499 if (os_strcmp(pos, "P2P-CR") == 0) {
1500 return wpas_ctrl_nfc_get_handover_req_p2p(
1501 wpa_s, reply, max_len, ndef);
1503 #endif /* CONFIG_P2P */
1509 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1510 char *reply, size_t max_len,
1511 int ndef, int cr, char *uuid)
1516 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1520 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1522 reply[res++] = '\n';
1532 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1533 char *reply, size_t max_len,
1539 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1543 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1545 reply[res++] = '\n';
1552 #endif /* CONFIG_P2P */
1555 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1556 char *cmd, char *reply,
1562 pos = os_strchr(cmd, ' ');
1567 if (os_strcmp(cmd, "WPS") == 0)
1569 else if (os_strcmp(cmd, "NDEF") == 0)
1574 pos2 = os_strchr(pos, ' ');
1577 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1580 return wpas_ctrl_nfc_get_handover_sel_wps(
1581 wpa_s, reply, max_len, ndef,
1582 os_strcmp(pos, "WPS-CR") == 0, pos2);
1586 if (os_strcmp(pos, "P2P-CR") == 0) {
1587 return wpas_ctrl_nfc_get_handover_sel_p2p(
1588 wpa_s, reply, max_len, ndef, 0);
1591 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1592 return wpas_ctrl_nfc_get_handover_sel_p2p(
1593 wpa_s, reply, max_len, ndef, 1);
1595 #endif /* CONFIG_P2P */
1601 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1605 struct wpabuf *req, *sel;
1607 char *pos, *role, *type, *pos2;
1610 int forced_freq = 0;
1612 freq = strstr(cmd, " freq=");
1616 forced_freq = atoi(freq);
1618 #endif /* CONFIG_P2P */
1621 pos = os_strchr(role, ' ');
1623 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1629 pos = os_strchr(type, ' ');
1631 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1636 pos2 = os_strchr(pos, ' ');
1638 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1643 len = os_strlen(pos);
1645 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1650 req = wpabuf_alloc(len);
1652 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1655 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1656 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1661 len = os_strlen(pos2);
1663 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1669 sel = wpabuf_alloc(len);
1671 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1675 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1676 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1682 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1683 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1685 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1686 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1688 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1690 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1692 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1693 #endif /* CONFIG_AP */
1695 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1697 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1698 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1700 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1702 #endif /* CONFIG_P2P */
1704 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1705 "reported: role=%s type=%s", role, type);
1712 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1717 #endif /* CONFIG_WPS_NFC */
1720 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1729 struct wps_new_ap_settings ap;
1731 pin = os_strchr(cmd, ' ');
1736 if (hwaddr_aton(cmd, bssid)) {
1737 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1742 new_ssid = os_strchr(pin, ' ');
1743 if (new_ssid == NULL)
1744 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1747 new_auth = os_strchr(new_ssid, ' ');
1748 if (new_auth == NULL)
1752 new_encr = os_strchr(new_auth, ' ');
1753 if (new_encr == NULL)
1757 new_key = os_strchr(new_encr, ' ');
1758 if (new_key == NULL)
1762 os_memset(&ap, 0, sizeof(ap));
1763 ap.ssid_hex = new_ssid;
1766 ap.key_hex = new_key;
1767 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1772 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1773 char *cmd, char *buf,
1778 const char *pin_txt;
1780 if (!wpa_s->ap_iface)
1783 pos = os_strchr(cmd, ' ');
1787 if (os_strcmp(cmd, "disable") == 0) {
1788 wpas_wps_ap_pin_disable(wpa_s);
1789 return os_snprintf(buf, buflen, "OK\n");
1792 if (os_strcmp(cmd, "random") == 0) {
1794 timeout = atoi(pos);
1795 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1796 if (pin_txt == NULL)
1798 return os_snprintf(buf, buflen, "%s", pin_txt);
1801 if (os_strcmp(cmd, "get") == 0) {
1802 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1803 if (pin_txt == NULL)
1805 return os_snprintf(buf, buflen, "%s", pin_txt);
1808 if (os_strcmp(cmd, "set") == 0) {
1813 pos = os_strchr(pos, ' ');
1816 timeout = atoi(pos);
1818 if (os_strlen(pin) > buflen)
1820 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1822 return os_snprintf(buf, buflen, "%s", pin);
1827 #endif /* CONFIG_AP */
1830 #ifdef CONFIG_WPS_ER
1831 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1834 char *uuid = cmd, *pin, *pos;
1835 u8 addr_buf[ETH_ALEN], *addr = NULL;
1836 pin = os_strchr(uuid, ' ');
1840 pos = os_strchr(pin, ' ');
1843 if (hwaddr_aton(pos, addr_buf) == 0)
1846 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1850 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1853 char *uuid = cmd, *pin;
1854 pin = os_strchr(uuid, ' ');
1858 return wpas_wps_er_learn(wpa_s, uuid, pin);
1862 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1863 struct wpa_supplicant *wpa_s, char *cmd)
1865 char *uuid = cmd, *id;
1866 id = os_strchr(uuid, ' ');
1870 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1874 static int wpa_supplicant_ctrl_iface_wps_er_config(
1875 struct wpa_supplicant *wpa_s, char *cmd)
1882 struct wps_new_ap_settings ap;
1884 pin = os_strchr(cmd, ' ');
1889 new_ssid = os_strchr(pin, ' ');
1890 if (new_ssid == NULL)
1894 new_auth = os_strchr(new_ssid, ' ');
1895 if (new_auth == NULL)
1899 new_encr = os_strchr(new_auth, ' ');
1900 if (new_encr == NULL)
1904 new_key = os_strchr(new_encr, ' ');
1905 if (new_key == NULL)
1909 os_memset(&ap, 0, sizeof(ap));
1910 ap.ssid_hex = new_ssid;
1913 ap.key_hex = new_key;
1914 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1918 #ifdef CONFIG_WPS_NFC
1919 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1920 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1927 uuid = os_strchr(cmd, ' ');
1932 if (os_strcmp(cmd, "WPS") == 0)
1934 else if (os_strcmp(cmd, "NDEF") == 0)
1939 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1943 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1945 reply[res++] = '\n';
1952 #endif /* CONFIG_WPS_NFC */
1953 #endif /* CONFIG_WPS_ER */
1955 #endif /* CONFIG_WPS */
1958 #ifdef CONFIG_IBSS_RSN
1959 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1960 struct wpa_supplicant *wpa_s, char *addr)
1964 if (hwaddr_aton(addr, peer)) {
1965 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1966 "address '%s'", addr);
1970 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1973 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1975 #endif /* CONFIG_IBSS_RSN */
1978 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1981 #ifdef IEEE8021X_EAPOL
1984 struct wpa_ssid *ssid;
1986 pos = os_strchr(rsp, '-');
1991 pos = os_strchr(pos, ':');
1996 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1997 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1998 (u8 *) pos, os_strlen(pos));
2000 ssid = wpa_config_get_network(wpa_s->conf, id);
2002 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2007 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2009 #else /* IEEE8021X_EAPOL */
2010 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2012 #endif /* IEEE8021X_EAPOL */
2016 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2018 char *buf, size_t buflen)
2020 char *pos, *end, tmp[30];
2021 int res, verbose, wps, ret;
2024 #endif /* CONFIG_HS20 */
2028 if (os_strcmp(params, "-DRIVER") == 0)
2029 return wpa_drv_status(wpa_s, buf, buflen);
2030 verbose = os_strcmp(params, "-VERBOSE") == 0;
2031 wps = os_strcmp(params, "-WPS") == 0;
2034 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2035 struct wpa_ssid *ssid = wpa_s->current_ssid;
2036 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2037 MAC2STR(wpa_s->bssid));
2038 if (os_snprintf_error(end - pos, ret))
2041 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2043 if (os_snprintf_error(end - pos, ret))
2047 u8 *_ssid = ssid->ssid;
2048 size_t ssid_len = ssid->ssid_len;
2049 u8 ssid_buf[SSID_MAX_LEN];
2050 if (ssid_len == 0) {
2051 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2058 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2059 wpa_ssid_txt(_ssid, ssid_len),
2061 if (os_snprintf_error(end - pos, ret))
2065 if (wps && ssid->passphrase &&
2066 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2067 (ssid->mode == WPAS_MODE_AP ||
2068 ssid->mode == WPAS_MODE_P2P_GO)) {
2069 ret = os_snprintf(pos, end - pos,
2072 if (os_snprintf_error(end - pos, ret))
2077 ret = os_snprintf(pos, end - pos,
2080 if (os_snprintf_error(end - pos, ret))
2085 switch (ssid->mode) {
2086 case WPAS_MODE_INFRA:
2087 ret = os_snprintf(pos, end - pos,
2090 case WPAS_MODE_IBSS:
2091 ret = os_snprintf(pos, end - pos,
2095 ret = os_snprintf(pos, end - pos,
2098 case WPAS_MODE_P2P_GO:
2099 ret = os_snprintf(pos, end - pos,
2102 case WPAS_MODE_P2P_GROUP_FORMATION:
2103 ret = os_snprintf(pos, end - pos,
2104 "mode=P2P GO - group "
2107 case WPAS_MODE_MESH:
2108 ret = os_snprintf(pos, end - pos,
2115 if (os_snprintf_error(end - pos, ret))
2121 if (wpa_s->ap_iface) {
2122 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2126 #endif /* CONFIG_AP */
2127 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2131 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
2134 #endif /* CONFIG_AP */
2135 wpa_s->sme.sae.state == SAE_ACCEPTED) {
2136 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
2137 wpa_s->sme.sae.group);
2138 if (os_snprintf_error(end - pos, ret))
2142 #endif /* CONFIG_SAE */
2143 #endif /* CONFIG_SME */
2144 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2145 wpa_supplicant_state_txt(wpa_s->wpa_state));
2146 if (os_snprintf_error(end - pos, ret))
2151 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2152 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
2153 if (os_snprintf_error(end - pos, ret))
2159 if (wpa_s->global->p2p) {
2160 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2161 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
2162 if (os_snprintf_error(end - pos, ret))
2166 #endif /* CONFIG_P2P */
2168 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2169 MAC2STR(wpa_s->own_addr));
2170 if (os_snprintf_error(end - pos, ret))
2175 if (wpa_s->current_bss &&
2176 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2177 HS20_IE_VENDOR_TYPE)) &&
2178 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2179 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2182 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2183 release = rel_num + 1;
2185 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
2186 if (os_snprintf_error(end - pos, ret))
2191 if (wpa_s->current_ssid) {
2192 struct wpa_cred *cred;
2195 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
2198 if (wpa_s->current_ssid->parent_cred != cred)
2201 if (cred->provisioning_sp) {
2202 ret = os_snprintf(pos, end - pos,
2203 "provisioning_sp=%s\n",
2204 cred->provisioning_sp);
2205 if (os_snprintf_error(end - pos, ret))
2214 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2215 struct wpabuf *names =
2216 wpa_s->current_bss->anqp->domain_name;
2217 for (i = 0; names && i < cred->num_domain; i++)
2219 if (domain_name_list_contains(
2220 names, cred->domain[i], 1))
2223 if (i == cred->num_domain)
2224 i = 0; /* show first entry by default */
2226 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2228 if (os_snprintf_error(end - pos, ret))
2233 if (wpa_s->current_bss == NULL ||
2234 wpa_s->current_bss->anqp == NULL)
2237 res = interworking_home_sp_cred(
2239 wpa_s->current_bss->anqp->domain_name);
2247 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
2248 if (os_snprintf_error(end - pos, ret))
2255 #endif /* CONFIG_HS20 */
2257 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2258 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2259 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2265 #ifdef CONFIG_MACSEC
2266 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2269 #endif /* CONFIG_MACSEC */
2271 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2275 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2276 if (os_snprintf_error(end - pos, ret))
2279 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2283 ret = os_snprintf(pos, end - pos, "\n");
2284 if (os_snprintf_error(end - pos, ret))
2289 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2296 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2297 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
2298 if (os_snprintf_error(end - pos, ret))
2302 #endif /* CONFIG_WPS */
2304 if (wpa_s->ieee80211ac) {
2305 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2306 if (os_snprintf_error(end - pos, ret))
2313 * Allow using the STATUS command with default behavior, say for debug,
2314 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2315 * events with STATUS-NO_EVENTS.
2317 if (os_strcmp(params, "-NO_EVENTS")) {
2318 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2319 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2320 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2322 MAC2STR(wpa_s->bssid),
2323 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2324 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2325 wpa_s->current_ssid->ssid_len) : "");
2326 if (wpa_s->wpa_state == WPA_COMPLETED) {
2327 struct wpa_ssid *ssid = wpa_s->current_ssid;
2328 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2329 "- connection to " MACSTR
2330 " completed %s [id=%d id_str=%s]",
2331 MAC2STR(wpa_s->bssid), "(auth)",
2332 ssid ? ssid->id : -1,
2333 ssid && ssid->id_str ? ssid->id_str : "");
2336 #endif /* ANDROID */
2342 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2347 struct wpa_ssid *ssid;
2350 /* cmd: "<network id> <BSSID>" */
2351 pos = os_strchr(cmd, ' ');
2356 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2357 if (hwaddr_aton(pos, bssid)) {
2358 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2362 ssid = wpa_config_get_network(wpa_s->conf, id);
2364 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2369 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2370 ssid->bssid_set = !is_zero_ether_addr(bssid);
2376 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
2377 char *cmd, char *buf,
2381 struct wpa_blacklist *e;
2385 /* cmd: "BLACKLIST [<BSSID>]" */
2389 e = wpa_s->blacklist;
2391 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2393 if (os_snprintf_error(end - pos, ret))
2402 if (os_strncmp(cmd, "clear", 5) == 0) {
2403 wpa_blacklist_clear(wpa_s);
2404 os_memcpy(buf, "OK\n", 3);
2408 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2409 if (hwaddr_aton(cmd, bssid)) {
2410 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
2415 * Add the BSSID twice, so its count will be 2, causing it to be
2416 * skipped when processing scan results.
2418 ret = wpa_blacklist_add(wpa_s, bssid);
2421 ret = wpa_blacklist_add(wpa_s, bssid);
2424 os_memcpy(buf, "OK\n", 3);
2429 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2430 char *cmd, char *buf,
2433 char *pos, *end, *stamp;
2436 /* cmd: "LOG_LEVEL [<level>]" */
2440 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2442 debug_level_str(wpa_debug_level),
2443 wpa_debug_timestamp);
2444 if (os_snprintf_error(end - pos, ret))
2453 stamp = os_strchr(cmd, ' ');
2456 while (*stamp == ' ') {
2461 if (os_strlen(cmd)) {
2462 int level = str_to_debug_level(cmd);
2465 wpa_debug_level = level;
2468 if (stamp && os_strlen(stamp))
2469 wpa_debug_timestamp = atoi(stamp);
2471 os_memcpy(buf, "OK\n", 3);
2476 static int wpa_supplicant_ctrl_iface_list_networks(
2477 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2479 char *pos, *end, *prev;
2480 struct wpa_ssid *ssid;
2485 ret = os_snprintf(pos, end - pos,
2486 "network id / ssid / bssid / flags\n");
2487 if (os_snprintf_error(end - pos, ret))
2491 ssid = wpa_s->conf->ssid;
2493 /* skip over ssids until we find next one */
2494 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2495 int last_id = atoi(cmd + 8);
2496 if (last_id != -1) {
2497 while (ssid != NULL && ssid->id <= last_id) {
2505 ret = os_snprintf(pos, end - pos, "%d\t%s",
2507 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2508 if (os_snprintf_error(end - pos, ret))
2511 if (ssid->bssid_set) {
2512 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2513 MAC2STR(ssid->bssid));
2515 ret = os_snprintf(pos, end - pos, "\tany");
2517 if (os_snprintf_error(end - pos, ret))
2520 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2521 ssid == wpa_s->current_ssid ?
2523 ssid->disabled ? "[DISABLED]" : "",
2524 ssid->disabled_until.sec ?
2525 "[TEMP-DISABLED]" : "",
2526 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2528 if (os_snprintf_error(end - pos, ret))
2531 ret = os_snprintf(pos, end - pos, "\n");
2532 if (os_snprintf_error(end - pos, ret))
2543 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2546 ret = os_snprintf(pos, end - pos, "-");
2547 if (os_snprintf_error(end - pos, ret))
2550 ret = wpa_write_ciphers(pos, end, cipher, "+");
2558 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2559 const u8 *ie, size_t ie_len)
2561 struct wpa_ie_data data;
2565 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2566 if (os_snprintf_error(end - pos, ret))
2570 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2571 ret = os_snprintf(pos, end - pos, "?]");
2572 if (os_snprintf_error(end - pos, ret))
2579 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2580 ret = os_snprintf(pos, end - pos, "%sEAP",
2581 pos == start ? "" : "+");
2582 if (os_snprintf_error(end - pos, ret))
2586 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2587 ret = os_snprintf(pos, end - pos, "%sPSK",
2588 pos == start ? "" : "+");
2589 if (os_snprintf_error(end - pos, ret))
2593 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2594 ret = os_snprintf(pos, end - pos, "%sNone",
2595 pos == start ? "" : "+");
2596 if (os_snprintf_error(end - pos, ret))
2600 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2601 ret = os_snprintf(pos, end - pos, "%sSAE",
2602 pos == start ? "" : "+");
2603 if (os_snprintf_error(end - pos, ret))
2607 #ifdef CONFIG_IEEE80211R
2608 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2609 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2610 pos == start ? "" : "+");
2611 if (os_snprintf_error(end - pos, ret))
2615 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2616 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2617 pos == start ? "" : "+");
2618 if (os_snprintf_error(end - pos, ret))
2622 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2623 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2624 pos == start ? "" : "+");
2625 if (os_snprintf_error(end - pos, ret))
2629 #endif /* CONFIG_IEEE80211R */
2630 #ifdef CONFIG_IEEE80211W
2631 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2632 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2633 pos == start ? "" : "+");
2634 if (os_snprintf_error(end - pos, ret))
2638 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2639 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2640 pos == start ? "" : "+");
2641 if (os_snprintf_error(end - pos, ret))
2645 #endif /* CONFIG_IEEE80211W */
2647 #ifdef CONFIG_SUITEB
2648 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2649 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2650 pos == start ? "" : "+");
2651 if (os_snprintf_error(end - pos, ret))
2655 #endif /* CONFIG_SUITEB */
2657 #ifdef CONFIG_SUITEB192
2658 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2659 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2660 pos == start ? "" : "+");
2661 if (os_snprintf_error(end - pos, ret))
2665 #endif /* CONFIG_SUITEB192 */
2668 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2669 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2670 pos == start ? "" : "+");
2671 if (os_snprintf_error(end - pos, ret))
2675 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2676 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2677 pos == start ? "" : "+");
2678 if (os_snprintf_error(end - pos, ret))
2682 #ifdef CONFIG_IEEE80211R
2683 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2684 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2685 pos == start ? "" : "+");
2686 if (os_snprintf_error(end - pos, ret))
2690 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2691 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2692 pos == start ? "" : "+");
2693 if (os_snprintf_error(end - pos, ret))
2697 #endif /* CONFIG_IEEE80211R */
2698 #endif /* CONFIG_FILS */
2701 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2702 ret = os_snprintf(pos, end - pos, "%sOWE",
2703 pos == start ? "" : "+");
2704 if (os_snprintf_error(end - pos, ret))
2708 #endif /* CONFIG_OWE */
2711 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2712 ret = os_snprintf(pos, end - pos, "%sDPP",
2713 pos == start ? "" : "+");
2714 if (os_snprintf_error(end - pos, ret))
2718 #endif /* CONFIG_DPP */
2720 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2721 ret = os_snprintf(pos, end - pos, "%sOSEN",
2722 pos == start ? "" : "+");
2723 if (os_snprintf_error(end - pos, ret))
2728 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2730 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2731 ret = os_snprintf(pos, end - pos, "-preauth");
2732 if (os_snprintf_error(end - pos, ret))
2737 ret = os_snprintf(pos, end - pos, "]");
2738 if (os_snprintf_error(end - pos, ret))
2747 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2748 char *pos, char *end,
2749 struct wpabuf *wps_ie)
2756 if (wps_is_selected_pbc_registrar(wps_ie))
2758 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2760 else if (wps_is_selected_pin_registrar(wps_ie))
2765 ret = os_snprintf(pos, end - pos, "%s", txt);
2766 if (!os_snprintf_error(end - pos, ret))
2768 wpabuf_free(wps_ie);
2771 #endif /* CONFIG_WPS */
2774 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2775 char *pos, char *end,
2776 const struct wpa_bss *bss)
2779 struct wpabuf *wps_ie;
2780 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2781 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2782 #else /* CONFIG_WPS */
2784 #endif /* CONFIG_WPS */
2788 /* Format one result on one text line into a buffer. */
2789 static int wpa_supplicant_ctrl_iface_scan_result(
2790 struct wpa_supplicant *wpa_s,
2791 const struct wpa_bss *bss, char *buf, size_t buflen)
2795 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe;
2797 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2798 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2800 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2801 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2802 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2804 return 0; /* Do not show P2P listen discovery results here */
2809 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2810 MAC2STR(bss->bssid), bss->freq, bss->level);
2811 if (os_snprintf_error(end - pos, ret))
2814 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2816 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2817 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2819 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2822 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2824 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2825 osen_ie, 2 + osen_ie[1]);
2826 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
2828 ret = os_snprintf(pos, end - pos,
2829 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2830 if (os_snprintf_error(end - pos, ret))
2834 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2835 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
2836 ret = os_snprintf(pos, end - pos, "[WEP]");
2837 if (os_snprintf_error(end - pos, ret))
2842 ret = os_snprintf(pos, end - pos, "[MESH]");
2843 if (os_snprintf_error(end - pos, ret))
2847 if (bss_is_dmg(bss)) {
2849 ret = os_snprintf(pos, end - pos, "[DMG]");
2850 if (os_snprintf_error(end - pos, ret))
2853 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2854 case IEEE80211_CAP_DMG_IBSS:
2857 case IEEE80211_CAP_DMG_AP:
2860 case IEEE80211_CAP_DMG_PBSS:
2867 ret = os_snprintf(pos, end - pos, "%s", s);
2868 if (os_snprintf_error(end - pos, ret))
2872 if (bss->caps & IEEE80211_CAP_IBSS) {
2873 ret = os_snprintf(pos, end - pos, "[IBSS]");
2874 if (os_snprintf_error(end - pos, ret))
2878 if (bss->caps & IEEE80211_CAP_ESS) {
2879 ret = os_snprintf(pos, end - pos, "[ESS]");
2880 if (os_snprintf_error(end - pos, ret))
2886 ret = os_snprintf(pos, end - pos, "[P2P]");
2887 if (os_snprintf_error(end - pos, ret))
2892 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2893 ret = os_snprintf(pos, end - pos, "[HS20]");
2894 if (os_snprintf_error(end - pos, ret))
2898 #endif /* CONFIG_HS20 */
2900 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
2901 ret = os_snprintf(pos, end - pos, "[FILS]");
2902 if (os_snprintf_error(end - pos, ret))
2906 #endif /* CONFIG_FILS */
2908 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
2909 ret = os_snprintf(pos, end - pos, "[FST]");
2910 if (os_snprintf_error(end - pos, ret))
2914 #endif /* CONFIG_FST */
2916 ret = os_snprintf(pos, end - pos, "\t%s",
2917 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2918 if (os_snprintf_error(end - pos, ret))
2922 ret = os_snprintf(pos, end - pos, "\n");
2923 if (os_snprintf_error(end - pos, ret))
2931 static int wpa_supplicant_ctrl_iface_scan_results(
2932 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2935 struct wpa_bss *bss;
2940 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2942 if (os_snprintf_error(end - pos, ret))
2946 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2947 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2949 if (ret < 0 || ret >= end - pos)
2960 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2961 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2963 char *pos, ifname[IFNAMSIZ + 1];
2967 pos = os_strstr(cmd, "ifname=");
2970 os_strlcpy(ifname, pos, sizeof(ifname));
2973 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
2976 os_strlcpy(reply, ifname, max_len);
2977 return os_strlen(ifname);
2981 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2982 struct wpa_supplicant *wpa_s, char *cmd)
2985 struct wpa_ssid *ssid;
2988 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2990 ssid = wpa_config_get_network(wpa_s->conf, id);
2992 wpa_printf(MSG_DEBUG,
2993 "CTRL_IFACE: Could not find network id=%d", id);
2996 if (ssid->mode != WPAS_MODE_MESH) {
2997 wpa_printf(MSG_DEBUG,
2998 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3001 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3002 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3003 wpa_printf(MSG_ERROR,
3004 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3009 * TODO: If necessary write our own group_add function,
3010 * for now we can reuse select_network
3012 wpa_supplicant_select_network(wpa_s, ssid);
3018 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3019 struct wpa_supplicant *wpa_s, char *cmd)
3021 struct wpa_supplicant *orig;
3022 struct wpa_global *global;
3025 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3027 global = wpa_s->global;
3030 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3031 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3037 wpa_printf(MSG_ERROR,
3038 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3042 if (wpa_s->mesh_if_created && wpa_s == orig) {
3043 wpa_printf(MSG_ERROR,
3044 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3048 wpa_s->reassociate = 0;
3049 wpa_s->disconnected = 1;
3050 wpa_supplicant_cancel_sched_scan(wpa_s);
3051 wpa_supplicant_cancel_scan(wpa_s);
3054 * TODO: If necessary write our own group_remove function,
3055 * for now we can reuse deauthenticate
3057 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3059 if (wpa_s->mesh_if_created)
3060 wpa_supplicant_remove_iface(global, wpa_s, 0);
3066 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3067 struct wpa_supplicant *wpa_s, char *cmd)
3071 if (hwaddr_aton(cmd, addr) < 0)
3074 return wpas_mesh_peer_remove(wpa_s, addr);
3078 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3079 struct wpa_supplicant *wpa_s, char *cmd)
3085 pos = os_strstr(cmd, " duration=");
3088 duration = atoi(pos + 10);
3093 if (hwaddr_aton(cmd, addr))
3096 return wpas_mesh_peer_add(wpa_s, addr, duration);
3099 #endif /* CONFIG_MESH */
3102 static int wpa_supplicant_ctrl_iface_select_network(
3103 struct wpa_supplicant *wpa_s, char *cmd)
3106 struct wpa_ssid *ssid;
3109 /* cmd: "<network id>" or "any" */
3110 if (os_strncmp(cmd, "any", 3) == 0) {
3111 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3115 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3117 ssid = wpa_config_get_network(wpa_s->conf, id);
3119 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3120 "network id=%d", id);
3123 if (ssid->disabled == 2) {
3124 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3125 "SELECT_NETWORK with persistent P2P group");
3130 pos = os_strstr(cmd, " freq=");
3132 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3134 os_free(wpa_s->select_network_scan_freqs);
3135 wpa_s->select_network_scan_freqs = freqs;
3139 wpa_s->scan_min_time.sec = 0;
3140 wpa_s->scan_min_time.usec = 0;
3141 wpa_supplicant_select_network(wpa_s, ssid);
3147 static int wpa_supplicant_ctrl_iface_enable_network(
3148 struct wpa_supplicant *wpa_s, char *cmd)
3151 struct wpa_ssid *ssid;
3153 /* cmd: "<network id>" or "all" */
3154 if (os_strcmp(cmd, "all") == 0) {
3155 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3159 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3161 ssid = wpa_config_get_network(wpa_s->conf, id);
3163 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3164 "network id=%d", id);
3167 if (ssid->disabled == 2) {
3168 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3169 "ENABLE_NETWORK with persistent P2P group");
3173 if (os_strstr(cmd, " no-connect")) {
3178 wpa_s->scan_min_time.sec = 0;
3179 wpa_s->scan_min_time.usec = 0;
3180 wpa_supplicant_enable_network(wpa_s, ssid);
3186 static int wpa_supplicant_ctrl_iface_disable_network(
3187 struct wpa_supplicant *wpa_s, char *cmd)
3190 struct wpa_ssid *ssid;
3192 /* cmd: "<network id>" or "all" */
3193 if (os_strcmp(cmd, "all") == 0) {
3194 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3198 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3200 ssid = wpa_config_get_network(wpa_s->conf, id);
3202 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3203 "network id=%d", id);
3206 if (ssid->disabled == 2) {
3207 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3208 "DISABLE_NETWORK with persistent P2P "
3213 wpa_supplicant_disable_network(wpa_s, ssid);
3219 static int wpa_supplicant_ctrl_iface_add_network(
3220 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3222 struct wpa_ssid *ssid;
3225 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3227 ssid = wpa_supplicant_add_network(wpa_s);
3231 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
3232 if (os_snprintf_error(buflen, ret))
3238 static int wpa_supplicant_ctrl_iface_remove_network(
3239 struct wpa_supplicant *wpa_s, char *cmd)
3242 struct wpa_ssid *ssid;
3245 /* cmd: "<network id>" or "all" */
3246 if (os_strcmp(cmd, "all") == 0) {
3247 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
3248 if (wpa_s->sched_scanning)
3249 wpa_supplicant_cancel_sched_scan(wpa_s);
3251 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3252 if (wpa_s->current_ssid) {
3254 wpa_s->sme.prev_bssid_set = 0;
3255 #endif /* CONFIG_SME */
3256 wpa_sm_set_config(wpa_s->wpa, NULL);
3257 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
3258 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3259 wpa_s->own_disconnect_req = 1;
3260 wpa_supplicant_deauthenticate(
3261 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3263 ssid = wpa_s->conf->ssid;
3265 struct wpa_ssid *remove_ssid = ssid;
3268 if (wpa_s->last_ssid == remove_ssid)
3269 wpa_s->last_ssid = NULL;
3270 wpas_notify_network_removed(wpa_s, remove_ssid);
3271 wpa_config_remove_network(wpa_s->conf, id);
3277 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3279 result = wpa_supplicant_remove_network(wpa_s, id);
3281 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3286 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3287 "network id=%d", id);
3294 static int wpa_supplicant_ctrl_iface_update_network(
3295 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3296 char *name, char *value)
3300 ret = wpa_config_set(ssid, name, value, 0);
3302 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3303 "variable '%s'", name);
3307 return 0; /* No change to the previously configured value */
3309 if (os_strcmp(name, "bssid") != 0 &&
3310 os_strcmp(name, "bssid_hint") != 0 &&
3311 os_strcmp(name, "priority") != 0) {
3312 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3314 if (wpa_s->current_ssid == ssid ||
3315 wpa_s->current_ssid == NULL) {
3317 * Invalidate the EAP session cache if anything in the
3318 * current or previously used configuration changes.
3320 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3324 if ((os_strcmp(name, "psk") == 0 &&
3325 value[0] == '"' && ssid->ssid_len) ||
3326 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3327 wpa_config_update_psk(ssid);
3328 else if (os_strcmp(name, "priority") == 0)
3329 wpa_config_update_prio_list(wpa_s->conf);
3335 static int wpa_supplicant_ctrl_iface_set_network(
3336 struct wpa_supplicant *wpa_s, char *cmd)
3338 int id, ret, prev_bssid_set, prev_disabled;
3339 struct wpa_ssid *ssid;
3341 u8 prev_bssid[ETH_ALEN];
3343 /* cmd: "<network id> <variable name> <value>" */
3344 name = os_strchr(cmd, ' ');
3349 value = os_strchr(name, ' ');
3355 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3357 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3358 (u8 *) value, os_strlen(value));
3360 ssid = wpa_config_get_network(wpa_s->conf, id);
3362 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3367 prev_bssid_set = ssid->bssid_set;
3368 prev_disabled = ssid->disabled;
3369 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3370 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3373 (ssid->bssid_set != prev_bssid_set ||
3374 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3375 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
3377 if (prev_disabled != ssid->disabled &&
3378 (prev_disabled == 2 || ssid->disabled == 2))
3379 wpas_notify_network_type_changed(wpa_s, ssid);
3385 static int wpa_supplicant_ctrl_iface_get_network(
3386 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3390 struct wpa_ssid *ssid;
3393 /* cmd: "<network id> <variable name>" */
3394 name = os_strchr(cmd, ' ');
3395 if (name == NULL || buflen == 0)
3400 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3403 ssid = wpa_config_get_network(wpa_s->conf, id);
3405 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
3410 value = wpa_config_get_no_key(ssid, name);
3411 if (value == NULL) {
3412 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
3413 "variable '%s'", name);
3417 res = os_strlcpy(buf, value, buflen);
3418 if (res >= buflen) {
3429 static int wpa_supplicant_ctrl_iface_dup_network(
3430 struct wpa_supplicant *wpa_s, char *cmd,
3431 struct wpa_supplicant *dst_wpa_s)
3433 struct wpa_ssid *ssid_s, *ssid_d;
3434 char *name, *id, *value;
3435 int id_s, id_d, ret;
3437 /* cmd: "<src network id> <dst network id> <variable name>" */
3438 id = os_strchr(cmd, ' ');
3443 name = os_strchr(id, ' ');
3451 wpa_printf(MSG_DEBUG,
3452 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3453 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
3455 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3456 if (ssid_s == NULL) {
3457 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3458 "network id=%d", id_s);
3462 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
3463 if (ssid_d == NULL) {
3464 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3465 "network id=%d", id_d);
3469 value = wpa_config_get(ssid_s, name);
3470 if (value == NULL) {
3471 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3472 "variable '%s'", name);
3476 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
3485 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3486 char *buf, size_t buflen)
3489 struct wpa_cred *cred;
3494 ret = os_snprintf(pos, end - pos,
3495 "cred id / realm / username / domain / imsi\n");
3496 if (os_snprintf_error(end - pos, ret))
3500 cred = wpa_s->conf->cred;
3502 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3503 cred->id, cred->realm ? cred->realm : "",
3504 cred->username ? cred->username : "",
3505 cred->domain ? cred->domain[0] : "",
3506 cred->imsi ? cred->imsi : "");
3507 if (os_snprintf_error(end - pos, ret))
3518 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3519 char *buf, size_t buflen)
3521 struct wpa_cred *cred;
3524 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3526 cred = wpa_config_add_cred(wpa_s->conf);
3530 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3532 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
3533 if (os_snprintf_error(buflen, ret))
3539 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3540 struct wpa_cred *cred)
3542 struct wpa_ssid *ssid;
3547 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3552 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3553 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3557 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3559 /* Remove any network entry created based on the removed credential */
3560 ssid = wpa_s->conf->ssid;
3562 if (ssid->parent_cred == cred) {
3565 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3566 "used the removed credential", ssid->id);
3567 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3568 if (os_snprintf_error(sizeof(str), res))
3569 str[sizeof(str) - 1] = '\0';
3571 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3580 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3584 struct wpa_cred *cred, *prev;
3586 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3587 * "provisioning_sp=<FQDN> */
3588 if (os_strcmp(cmd, "all") == 0) {
3589 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3590 cred = wpa_s->conf->cred;
3594 wpas_ctrl_remove_cred(wpa_s, prev);
3599 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3600 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3602 cred = wpa_s->conf->cred;
3608 for (i = 0; i < prev->num_domain; i++) {
3609 if (os_strcmp(prev->domain[i], cmd + 8)
3612 wpas_ctrl_remove_cred(wpa_s, prev);
3620 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3621 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3623 cred = wpa_s->conf->cred;
3627 if (prev->provisioning_sp &&
3628 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3629 wpas_ctrl_remove_cred(wpa_s, prev);
3635 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3637 cred = wpa_config_get_cred(wpa_s->conf, id);
3638 return wpas_ctrl_remove_cred(wpa_s, cred);
3642 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3646 struct wpa_cred *cred;
3649 /* cmd: "<cred id> <variable name> <value>" */
3650 name = os_strchr(cmd, ' ');
3655 value = os_strchr(name, ' ');
3661 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3663 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3664 (u8 *) value, os_strlen(value));
3666 cred = wpa_config_get_cred(wpa_s->conf, id);
3668 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3673 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3674 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3675 "variable '%s'", name);
3679 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3685 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3686 char *cmd, char *buf,
3691 struct wpa_cred *cred;
3694 /* cmd: "<cred id> <variable name>" */
3695 name = os_strchr(cmd, ' ');
3701 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3704 cred = wpa_config_get_cred(wpa_s->conf, id);
3706 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3711 value = wpa_config_get_cred_no_key(cred, name);
3712 if (value == NULL) {
3713 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3718 res = os_strlcpy(buf, value, buflen);
3719 if (res >= buflen) {
3730 #ifndef CONFIG_NO_CONFIG_WRITE
3731 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3735 if (!wpa_s->conf->update_config) {
3736 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3737 "to update configuration (update_config=0)");
3741 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3744 "update configuration");
3746 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3752 #endif /* CONFIG_NO_CONFIG_WRITE */
3755 struct cipher_info {
3761 static const struct cipher_info ciphers[] = {
3762 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3763 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3764 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3765 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3766 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3767 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3768 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3769 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3772 static const struct cipher_info ciphers_group_mgmt[] = {
3773 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3774 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3775 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3776 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3780 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3781 struct wpa_driver_capa *capa,
3782 char *buf, size_t buflen)
3795 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3801 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3802 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3803 ret = os_snprintf(pos, end - pos, "%s%s",
3804 pos == buf ? "" : " ",
3806 if (os_snprintf_error(end - pos, ret))
3816 static int ctrl_iface_get_capability_group(int res, char *strict,
3817 struct wpa_driver_capa *capa,
3818 char *buf, size_t buflen)
3831 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3837 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3838 if (capa->enc & ciphers[i].capa) {
3839 ret = os_snprintf(pos, end - pos, "%s%s",
3840 pos == buf ? "" : " ",
3842 if (os_snprintf_error(end - pos, ret))
3852 static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3853 struct wpa_driver_capa *capa,
3854 char *buf, size_t buflen)
3866 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3867 if (capa->enc & ciphers_group_mgmt[i].capa) {
3868 ret = os_snprintf(pos, end - pos, "%s%s",
3869 pos == buf ? "" : " ",
3870 ciphers_group_mgmt[i].name);
3871 if (os_snprintf_error(end - pos, ret))
3881 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3882 struct wpa_driver_capa *capa,
3883 char *buf, size_t buflen)
3895 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3902 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3903 if (os_snprintf_error(end - pos, ret))
3907 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3908 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3909 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3910 if (os_snprintf_error(end - pos, ret))
3915 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3916 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3917 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3918 if (os_snprintf_error(end - pos, ret))
3923 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3924 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3925 if (os_snprintf_error(end - pos, ret))
3930 #ifdef CONFIG_SUITEB
3931 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
3932 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
3933 if (os_snprintf_error(end - pos, ret))
3937 #endif /* CONFIG_SUITEB */
3938 #ifdef CONFIG_SUITEB192
3939 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
3940 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
3941 if (os_snprintf_error(end - pos, ret))
3945 #endif /* CONFIG_SUITEB192 */
3947 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
3948 ret = os_snprintf(pos, end - pos, " OWE");
3949 if (os_snprintf_error(end - pos, ret))
3953 #endif /* CONFIG_OWE */
3955 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
3956 ret = os_snprintf(pos, end - pos, " DPP");
3957 if (os_snprintf_error(end - pos, ret))
3961 #endif /* CONFIG_DPP */
3963 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
3964 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
3965 if (os_snprintf_error(end - pos, ret))
3969 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
3970 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
3971 if (os_snprintf_error(end - pos, ret))
3975 #ifdef CONFIG_IEEE80211R
3976 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
3977 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
3978 if (os_snprintf_error(end - pos, ret))
3982 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
3983 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
3984 if (os_snprintf_error(end - pos, ret))
3988 #endif /* CONFIG_IEEE80211R */
3989 #endif /* CONFIG_FILS */
3995 static int ctrl_iface_get_capability_proto(int res, char *strict,
3996 struct wpa_driver_capa *capa,
3997 char *buf, size_t buflen)
4009 len = os_strlcpy(buf, "RSN WPA", buflen);
4015 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4016 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4017 ret = os_snprintf(pos, end - pos, "%sRSN",
4018 pos == buf ? "" : " ");
4019 if (os_snprintf_error(end - pos, ret))
4024 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4025 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
4026 ret = os_snprintf(pos, end - pos, "%sWPA",
4027 pos == buf ? "" : " ");
4028 if (os_snprintf_error(end - pos, ret))
4037 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4038 int res, char *strict,
4039 struct wpa_driver_capa *capa,
4040 char *buf, size_t buflen)
4052 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4058 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
4059 ret = os_snprintf(pos, end - pos, "%sOPEN",
4060 pos == buf ? "" : " ");
4061 if (os_snprintf_error(end - pos, ret))
4066 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4067 ret = os_snprintf(pos, end - pos, "%sSHARED",
4068 pos == buf ? "" : " ");
4069 if (os_snprintf_error(end - pos, ret))
4074 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
4075 ret = os_snprintf(pos, end - pos, "%sLEAP",
4076 pos == buf ? "" : " ");
4077 if (os_snprintf_error(end - pos, ret))
4083 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4084 ret = os_snprintf(pos, end - pos, "%sSAE",
4085 pos == buf ? "" : " ");
4086 if (os_snprintf_error(end - pos, ret))
4090 #endif /* CONFIG_SAE */
4093 if (wpa_is_fils_supported(wpa_s)) {
4094 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4095 pos == buf ? "" : " ");
4096 if (os_snprintf_error(end - pos, ret))
4101 #ifdef CONFIG_FILS_SK_PFS
4102 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4103 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4104 pos == buf ? "" : " ");
4105 if (os_snprintf_error(end - pos, ret))
4109 #endif /* CONFIG_FILS_SK_PFS */
4110 #endif /* CONFIG_FILS */
4116 static int ctrl_iface_get_capability_modes(int res, char *strict,
4117 struct wpa_driver_capa *capa,
4118 char *buf, size_t buflen)
4130 len = os_strlcpy(buf, "IBSS AP", buflen);
4136 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
4137 ret = os_snprintf(pos, end - pos, "%sIBSS",
4138 pos == buf ? "" : " ");
4139 if (os_snprintf_error(end - pos, ret))
4144 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
4145 ret = os_snprintf(pos, end - pos, "%sAP",
4146 pos == buf ? "" : " ");
4147 if (os_snprintf_error(end - pos, ret))
4153 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4154 ret = os_snprintf(pos, end - pos, "%sMESH",
4155 pos == buf ? "" : " ");
4156 if (os_snprintf_error(end - pos, ret))
4160 #endif /* CONFIG_MESH */
4166 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4167 char *buf, size_t buflen)
4169 struct hostapd_channel_data *chnl;
4171 char *pos, *end, *hmode;
4176 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4177 switch (wpa_s->hw.modes[j].mode) {
4178 case HOSTAPD_MODE_IEEE80211B:
4181 case HOSTAPD_MODE_IEEE80211G:
4184 case HOSTAPD_MODE_IEEE80211A:
4187 case HOSTAPD_MODE_IEEE80211AD:
4193 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
4194 if (os_snprintf_error(end - pos, ret))
4197 chnl = wpa_s->hw.modes[j].channels;
4198 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4199 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4201 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
4202 if (os_snprintf_error(end - pos, ret))
4206 ret = os_snprintf(pos, end - pos, "\n");
4207 if (os_snprintf_error(end - pos, ret))
4216 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4217 char *buf, size_t buflen)
4219 struct hostapd_channel_data *chnl;
4221 char *pos, *end, *hmode;
4226 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4227 switch (wpa_s->hw.modes[j].mode) {
4228 case HOSTAPD_MODE_IEEE80211B:
4231 case HOSTAPD_MODE_IEEE80211G:
4234 case HOSTAPD_MODE_IEEE80211A:
4237 case HOSTAPD_MODE_IEEE80211AD:
4243 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4245 if (os_snprintf_error(end - pos, ret))
4248 chnl = wpa_s->hw.modes[j].channels;
4249 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4250 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4252 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
4253 chnl[i].chan, chnl[i].freq,
4254 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4256 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4259 if (os_snprintf_error(end - pos, ret))
4263 ret = os_snprintf(pos, end - pos, "\n");
4264 if (os_snprintf_error(end - pos, ret))
4273 static int wpa_supplicant_ctrl_iface_get_capability(
4274 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4277 struct wpa_driver_capa capa;
4283 /* Determine whether or not strict checking was requested */
4284 len = os_strlcpy(field, _field, sizeof(field));
4285 if (len >= sizeof(field))
4287 strict = os_strchr(field, ' ');
4288 if (strict != NULL) {
4290 if (os_strcmp(strict, "strict") != 0)
4294 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4295 field, strict ? strict : "");
4297 if (os_strcmp(field, "eap") == 0) {
4298 return eap_get_names(buf, buflen);
4301 res = wpa_drv_get_capa(wpa_s, &capa);
4303 if (os_strcmp(field, "pairwise") == 0)
4304 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4307 if (os_strcmp(field, "group") == 0)
4308 return ctrl_iface_get_capability_group(res, strict, &capa,
4311 if (os_strcmp(field, "group_mgmt") == 0)
4312 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4315 if (os_strcmp(field, "key_mgmt") == 0)
4316 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4319 if (os_strcmp(field, "proto") == 0)
4320 return ctrl_iface_get_capability_proto(res, strict, &capa,
4323 if (os_strcmp(field, "auth_alg") == 0)
4324 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4325 &capa, buf, buflen);
4327 if (os_strcmp(field, "modes") == 0)
4328 return ctrl_iface_get_capability_modes(res, strict, &capa,
4331 if (os_strcmp(field, "channels") == 0)
4332 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4334 if (os_strcmp(field, "freq") == 0)
4335 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4338 if (os_strcmp(field, "tdls") == 0)
4339 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4340 #endif /* CONFIG_TDLS */
4343 if (os_strcmp(field, "erp") == 0) {
4344 res = os_snprintf(buf, buflen, "ERP");
4345 if (os_snprintf_error(buflen, res))
4349 #endif /* CONFIG_EPR */
4352 if (os_strcmp(field, "fips") == 0) {
4353 res = os_snprintf(buf, buflen, "FIPS");
4354 if (os_snprintf_error(buflen, res))
4358 #endif /* CONFIG_FIPS */
4361 if (os_strcmp(field, "acs") == 0) {
4362 res = os_snprintf(buf, buflen, "ACS");
4363 if (os_snprintf_error(buflen, res))
4367 #endif /* CONFIG_ACS */
4370 if (os_strcmp(field, "fils") == 0) {
4371 #ifdef CONFIG_FILS_SK_PFS
4372 if (wpa_is_fils_supported(wpa_s) &&
4373 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4374 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4375 if (os_snprintf_error(buflen, res))
4379 #endif /* CONFIG_FILS_SK_PFS */
4381 if (wpa_is_fils_supported(wpa_s)) {
4382 res = os_snprintf(buf, buflen, "FILS");
4383 if (os_snprintf_error(buflen, res))
4388 #endif /* CONFIG_FILS */
4390 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4397 #ifdef CONFIG_INTERWORKING
4398 static char * anqp_add_hex(char *pos, char *end, const char *title,
4399 struct wpabuf *data)
4409 ret = os_snprintf(pos, end - pos, "%s=", title);
4410 if (os_snprintf_error(end - pos, ret))
4414 d = wpabuf_head_u8(data);
4415 for (i = 0; i < wpabuf_len(data); i++) {
4416 ret = os_snprintf(pos, end - pos, "%02x", *d++);
4417 if (os_snprintf_error(end - pos, ret))
4422 ret = os_snprintf(pos, end - pos, "\n");
4423 if (os_snprintf_error(end - pos, ret))
4429 #endif /* CONFIG_INTERWORKING */
4433 static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4436 const u8 *ie, *ie_end;
4440 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4443 ie_end = ie + 2 + ie[1];
4445 if (ie_end - ie < 2)
4448 info = WPA_GET_LE16(ie);
4450 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4451 if (os_snprintf_error(end - pos, ret))
4455 if (info & BIT(7)) {
4456 /* Cache Identifier Included */
4457 if (ie_end - ie < 2)
4459 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4461 if (os_snprintf_error(end - pos, ret))
4467 if (info & BIT(8)) {
4468 /* HESSID Included */
4469 if (ie_end - ie < ETH_ALEN)
4471 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4473 if (os_snprintf_error(end - pos, ret))
4479 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4481 if (ie_end - ie < realms * 2)
4483 ret = os_snprintf(pos, end - pos, "fils_realms=");
4484 if (os_snprintf_error(end - pos, ret))
4488 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4493 ret = os_snprintf(pos, end - pos, "\n");
4494 if (os_snprintf_error(end - pos, ret))
4501 #endif /* CONFIG_FILS */
4504 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4505 unsigned long mask, char *buf, size_t buflen)
4510 const u8 *ie, *ie2, *osen_ie, *mesh, *owe;
4515 if (mask & WPA_BSS_MASK_ID) {
4516 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
4517 if (os_snprintf_error(end - pos, ret))
4522 if (mask & WPA_BSS_MASK_BSSID) {
4523 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4524 MAC2STR(bss->bssid));
4525 if (os_snprintf_error(end - pos, ret))
4530 if (mask & WPA_BSS_MASK_FREQ) {
4531 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
4532 if (os_snprintf_error(end - pos, ret))
4537 if (mask & WPA_BSS_MASK_BEACON_INT) {
4538 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4540 if (os_snprintf_error(end - pos, ret))
4545 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4546 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4548 if (os_snprintf_error(end - pos, ret))
4553 if (mask & WPA_BSS_MASK_QUAL) {
4554 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
4555 if (os_snprintf_error(end - pos, ret))
4560 if (mask & WPA_BSS_MASK_NOISE) {
4561 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
4562 if (os_snprintf_error(end - pos, ret))
4567 if (mask & WPA_BSS_MASK_LEVEL) {
4568 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
4569 if (os_snprintf_error(end - pos, ret))
4574 if (mask & WPA_BSS_MASK_TSF) {
4575 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4576 (unsigned long long) bss->tsf);
4577 if (os_snprintf_error(end - pos, ret))
4582 if (mask & WPA_BSS_MASK_AGE) {
4583 struct os_reltime now;
4585 os_get_reltime(&now);
4586 ret = os_snprintf(pos, end - pos, "age=%d\n",
4587 (int) (now.sec - bss->last_update.sec));
4588 if (os_snprintf_error(end - pos, ret))
4593 if (mask & WPA_BSS_MASK_IE) {
4594 ret = os_snprintf(pos, end - pos, "ie=");
4595 if (os_snprintf_error(end - pos, ret))
4599 ie = (const u8 *) (bss + 1);
4600 for (i = 0; i < bss->ie_len; i++) {
4601 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4602 if (os_snprintf_error(end - pos, ret))
4607 ret = os_snprintf(pos, end - pos, "\n");
4608 if (os_snprintf_error(end - pos, ret))
4613 if (mask & WPA_BSS_MASK_FLAGS) {
4614 ret = os_snprintf(pos, end - pos, "flags=");
4615 if (os_snprintf_error(end - pos, ret))
4619 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
4621 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4623 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4625 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4627 pos = wpa_supplicant_ie_txt(pos, end,
4628 mesh ? "RSN" : "WPA2", ie2,
4630 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4632 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4633 osen_ie, 2 + osen_ie[1]);
4634 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
4638 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4639 if (os_snprintf_error(end - pos, ret))
4643 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
4644 if (!ie && !ie2 && !osen_ie &&
4645 (bss->caps & IEEE80211_CAP_PRIVACY)) {
4646 ret = os_snprintf(pos, end - pos, "[WEP]");
4647 if (os_snprintf_error(end - pos, ret))
4653 ret = os_snprintf(pos, end - pos, "[MESH]");
4654 if (os_snprintf_error(end - pos, ret))
4659 if (bss_is_dmg(bss)) {
4661 ret = os_snprintf(pos, end - pos, "[DMG]");
4662 if (os_snprintf_error(end - pos, ret))
4665 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4666 case IEEE80211_CAP_DMG_IBSS:
4669 case IEEE80211_CAP_DMG_AP:
4672 case IEEE80211_CAP_DMG_PBSS:
4679 ret = os_snprintf(pos, end - pos, "%s", s);
4680 if (os_snprintf_error(end - pos, ret))
4684 if (bss->caps & IEEE80211_CAP_IBSS) {
4685 ret = os_snprintf(pos, end - pos, "[IBSS]");
4686 if (os_snprintf_error(end - pos, ret))
4690 if (bss->caps & IEEE80211_CAP_ESS) {
4691 ret = os_snprintf(pos, end - pos, "[ESS]");
4692 if (os_snprintf_error(end - pos, ret))
4697 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4698 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
4699 ret = os_snprintf(pos, end - pos, "[P2P]");
4700 if (os_snprintf_error(end - pos, ret))
4705 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4706 ret = os_snprintf(pos, end - pos, "[HS20]");
4707 if (os_snprintf_error(end - pos, ret))
4711 #endif /* CONFIG_HS20 */
4713 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
4714 ret = os_snprintf(pos, end - pos, "[FILS]");
4715 if (os_snprintf_error(end - pos, ret))
4719 #endif /* CONFIG_FILS */
4721 ret = os_snprintf(pos, end - pos, "\n");
4722 if (os_snprintf_error(end - pos, ret))
4727 if (mask & WPA_BSS_MASK_SSID) {
4728 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4729 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4730 if (os_snprintf_error(end - pos, ret))
4736 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4737 ie = (const u8 *) (bss + 1);
4738 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
4739 if (ret >= end - pos)
4744 #endif /* CONFIG_WPS */
4747 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4748 ie = (const u8 *) (bss + 1);
4749 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
4750 if (ret >= end - pos)
4755 #endif /* CONFIG_P2P */
4757 #ifdef CONFIG_WIFI_DISPLAY
4758 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4760 ie = (const u8 *) (bss + 1);
4761 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4762 WFD_IE_VENDOR_TYPE);
4764 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
4765 if (os_snprintf_error(end - pos, ret)) {
4771 pos += wpa_snprintf_hex(pos, end - pos,
4776 ret = os_snprintf(pos, end - pos, "\n");
4777 if (os_snprintf_error(end - pos, ret))
4782 #endif /* CONFIG_WIFI_DISPLAY */
4784 #ifdef CONFIG_INTERWORKING
4785 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4786 struct wpa_bss_anqp *anqp = bss->anqp;
4787 struct wpa_bss_anqp_elem *elem;
4789 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4790 anqp->capability_list);
4791 pos = anqp_add_hex(pos, end, "anqp_venue_name",
4793 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
4794 anqp->network_auth_type);
4795 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
4796 anqp->roaming_consortium);
4797 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
4798 anqp->ip_addr_type_availability);
4799 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
4801 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
4802 pos = anqp_add_hex(pos, end, "anqp_domain_name",
4804 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
4805 anqp->fils_realm_info);
4807 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4808 anqp->hs20_capability_list);
4809 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
4810 anqp->hs20_operator_friendly_name);
4811 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
4812 anqp->hs20_wan_metrics);
4813 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
4814 anqp->hs20_connection_capability);
4815 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4816 anqp->hs20_operating_class);
4817 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4818 anqp->hs20_osu_providers_list);
4819 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
4820 anqp->hs20_operator_icon_metadata);
4821 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
4822 anqp->hs20_osu_providers_nai_list);
4823 #endif /* CONFIG_HS20 */
4825 dl_list_for_each(elem, &anqp->anqp_elems,
4826 struct wpa_bss_anqp_elem, list) {
4829 os_snprintf(title, sizeof(title), "anqp[%u]",
4831 pos = anqp_add_hex(pos, end, title, elem->payload);
4834 #endif /* CONFIG_INTERWORKING */
4837 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4838 ie = (const u8 *) (bss + 1);
4839 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
4840 if (ret >= end - pos)
4845 #endif /* CONFIG_MESH */
4847 if (mask & WPA_BSS_MASK_SNR) {
4848 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
4849 if (os_snprintf_error(end - pos, ret))
4854 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
4855 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
4856 bss->est_throughput);
4857 if (os_snprintf_error(end - pos, ret))
4863 if (mask & WPA_BSS_MASK_FST) {
4864 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
4865 if (ret < 0 || ret >= end - pos)
4869 #endif /* CONFIG_FST */
4871 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
4872 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
4873 bss->last_update_idx);
4874 if (os_snprintf_error(end - pos, ret))
4879 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
4880 ret = os_snprintf(pos, end - pos, "beacon_ie=");
4881 if (os_snprintf_error(end - pos, ret))
4885 ie = (const u8 *) (bss + 1);
4887 for (i = 0; i < bss->beacon_ie_len; i++) {
4888 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4889 if (os_snprintf_error(end - pos, ret))
4894 ret = os_snprintf(pos, end - pos, "\n");
4895 if (os_snprintf_error(end - pos, ret))
4901 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
4902 ret = print_fils_indication(bss, pos, end);
4907 #endif /* CONFIG_FILS */
4909 if (mask & WPA_BSS_MASK_DELIM) {
4910 ret = os_snprintf(pos, end - pos, "====\n");
4911 if (os_snprintf_error(end - pos, ret))
4920 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
4921 const char *cmd, char *buf,
4926 struct wpa_bss *bss;
4927 struct wpa_bss *bsslast = NULL;
4928 struct dl_list *next;
4931 char *ctmp, *end = buf + buflen;
4932 unsigned long mask = WPA_BSS_MASK_ALL;
4934 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
4935 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
4936 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
4938 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
4940 } else { /* N1-N2 */
4941 unsigned int id1, id2;
4943 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
4944 wpa_printf(MSG_INFO, "Wrong BSS range "
4949 if (*(cmd + 6) == '-')
4952 id1 = atoi(cmd + 6);
4954 if (*ctmp >= '0' && *ctmp <= '9')
4957 id2 = (unsigned int) -1;
4958 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
4959 if (id2 == (unsigned int) -1)
4960 bsslast = dl_list_last(&wpa_s->bss_id,
4964 bsslast = wpa_bss_get_id(wpa_s, id2);
4965 if (bsslast == NULL && bss && id2 > id1) {
4966 struct wpa_bss *tmp = bss;
4968 next = tmp->list_id.next;
4969 if (next == &wpa_s->bss_id)
4971 tmp = dl_list_entry(
4972 next, struct wpa_bss,
4981 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
4982 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
4983 else if (os_strncmp(cmd, "LAST", 4) == 0)
4984 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
4985 else if (os_strncmp(cmd, "ID-", 3) == 0) {
4987 bss = wpa_bss_get_id(wpa_s, i);
4988 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4990 bss = wpa_bss_get_id(wpa_s, i);
4992 next = bss->list_id.next;
4993 if (next == &wpa_s->bss_id)
4996 bss = dl_list_entry(next, struct wpa_bss,
4999 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5000 bss = wpa_s->current_bss;
5002 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5003 if (hwaddr_aton(cmd + 13, bssid) == 0)
5004 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5007 #endif /* CONFIG_P2P */
5008 } else if (hwaddr_aton(cmd, bssid) == 0)
5009 bss = wpa_bss_get_bssid(wpa_s, bssid);
5011 struct wpa_bss *tmp;
5014 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5023 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5024 mask = strtoul(ctmp + 5, NULL, 0x10);
5026 mask = WPA_BSS_MASK_ALL;
5032 if (bsslast == NULL)
5035 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5039 if (bss == bsslast) {
5040 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5041 (bss == dl_list_last(&wpa_s->bss_id,
5042 struct wpa_bss, list_id))) {
5045 res = os_snprintf(buf - 5, end - buf + 5,
5047 if (os_snprintf_error(end - buf + 5, res)) {
5048 wpa_printf(MSG_DEBUG,
5049 "Could not add end delim");
5054 next = bss->list_id.next;
5055 if (next == &wpa_s->bss_id)
5057 bss = dl_list_entry(next, struct wpa_bss, list_id);
5058 } while (bss && len);
5064 static int wpa_supplicant_ctrl_iface_ap_scan(
5065 struct wpa_supplicant *wpa_s, char *cmd)
5067 int ap_scan = atoi(cmd);
5068 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5072 static int wpa_supplicant_ctrl_iface_scan_interval(
5073 struct wpa_supplicant *wpa_s, char *cmd)
5075 int scan_int = atoi(cmd);
5076 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
5080 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5081 struct wpa_supplicant *wpa_s, char *cmd)
5083 int expire_age = atoi(cmd);
5084 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5088 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5089 struct wpa_supplicant *wpa_s, char *cmd)
5091 int expire_count = atoi(cmd);
5092 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5096 static void wpa_supplicant_ctrl_iface_bss_flush(
5097 struct wpa_supplicant *wpa_s, char *cmd)
5099 int flush_age = atoi(cmd);
5102 wpa_bss_flush(wpa_s);
5104 wpa_bss_flush_by_age(wpa_s, flush_age);
5108 #ifdef CONFIG_TESTING_OPTIONS
5109 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5111 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5112 /* MLME-DELETEKEYS.request */
5113 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
5114 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
5115 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
5116 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
5117 #ifdef CONFIG_IEEE80211W
5118 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
5119 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
5120 #endif /* CONFIG_IEEE80211W */
5122 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
5124 /* MLME-SETPROTECTION.request(None) */
5125 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5126 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5127 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5128 wpa_sm_drop_sa(wpa_s->wpa);
5130 #endif /* CONFIG_TESTING_OPTIONS */
5133 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5136 #ifdef CONFIG_NO_SCAN_PROCESSING
5138 #else /* CONFIG_NO_SCAN_PROCESSING */
5140 struct wpa_bss *bss;
5141 struct wpa_ssid *ssid = wpa_s->current_ssid;
5143 if (hwaddr_aton(addr, bssid)) {
5144 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5145 "address '%s'", addr);
5149 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5152 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5153 "configuration known for the target AP");
5157 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
5159 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5165 * TODO: Find best network configuration block from configuration to
5166 * allow roaming to other networks
5169 wpa_s->reassociate = 1;
5170 wpa_supplicant_connect(wpa_s, bss, ssid);
5173 #endif /* CONFIG_NO_SCAN_PROCESSING */
5178 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5180 unsigned int timeout = atoi(cmd);
5181 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
5182 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
5183 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
5185 unsigned int search_delay;
5186 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
5190 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5191 wpa_dbg(wpa_s, MSG_INFO,
5192 "Reject P2P_FIND since interface is disabled");
5195 if (os_strstr(cmd, "type=social"))
5196 type = P2P_FIND_ONLY_SOCIAL;
5197 else if (os_strstr(cmd, "type=progressive"))
5198 type = P2P_FIND_PROGRESSIVE;
5200 pos = os_strstr(cmd, "dev_id=");
5203 if (hwaddr_aton(pos, dev_id))
5208 pos = os_strstr(cmd, "dev_type=");
5211 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5213 _dev_type = dev_type;
5216 pos = os_strstr(cmd, "delay=");
5219 search_delay = atoi(pos);
5221 search_delay = wpas_p2p_search_delay(wpa_s);
5223 pos = os_strstr(cmd, "freq=");
5231 /* Must be searched for last, because it adds nul termination */
5232 pos = os_strstr(cmd, " seek=");
5235 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5238 _seek[seek_count++] = pos;
5240 term = os_strchr(pos, ' ');
5244 pos = os_strstr(term + 1, "seek=");
5248 if (seek_count > P2P_MAX_QUERY_HASH) {
5253 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
5254 _dev_id, search_delay, seek_count, seek, freq);
5258 static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5260 const char *last = NULL;
5265 /* Expected predefined CPT names delimited by ':' */
5266 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5267 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5268 wpa_printf(MSG_ERROR,
5269 "P2PS: CPT name list is too long, expected up to %d names",
5270 P2PS_FEATURE_CAPAB_CPT_MAX);
5275 token_len = last - token;
5277 if (token_len == 3 &&
5278 os_memcmp(token, "UDP", token_len) == 0) {
5279 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5280 } else if (token_len == 3 &&
5281 os_memcmp(token, "MAC", token_len) == 0) {
5282 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5284 wpa_printf(MSG_ERROR,
5285 "P2PS: Unsupported CPT name '%s'", token);
5290 if (isblank((unsigned char) *last)) {
5300 static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5302 struct p2ps_provision *p2ps_prov;
5304 size_t info_len = 0;
5306 u8 role = P2PS_SETUP_NONE;
5307 long long unsigned val;
5310 pos = os_strstr(cmd, "info=");
5313 info_len = os_strlen(pos);
5316 info = os_malloc(info_len + 1);
5318 info_len = utf8_unescape(pos, info_len,
5319 info, info_len + 1);
5325 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5326 if (p2ps_prov == NULL) {
5332 os_memcpy(p2ps_prov->info, info, info_len);
5333 p2ps_prov->info[info_len] = '\0';
5337 pos = os_strstr(cmd, "status=");
5339 p2ps_prov->status = atoi(pos + 7);
5341 p2ps_prov->status = -1;
5343 pos = os_strstr(cmd, "adv_id=");
5344 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5346 p2ps_prov->adv_id = val;
5348 pos = os_strstr(cmd, "method=");
5350 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5352 p2ps_prov->method = 0;
5354 pos = os_strstr(cmd, "session=");
5355 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5357 p2ps_prov->session_id = val;
5359 pos = os_strstr(cmd, "adv_mac=");
5360 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5363 pos = os_strstr(cmd, "session_mac=");
5364 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5367 pos = os_strstr(cmd, "cpt=");
5369 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5370 p2ps_prov->cpt_priority))
5373 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5376 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5377 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5379 /* force conncap with tstCap (no sanity checks) */
5380 pos = os_strstr(cmd, "tstCap=");
5382 role = strtol(pos + 7, NULL, 16);
5384 pos = os_strstr(cmd, "role=");
5386 role = strtol(pos + 5, NULL, 16);
5387 if (role != P2PS_SETUP_CLIENT &&
5388 role != P2PS_SETUP_GROUP_OWNER)
5389 role = P2PS_SETUP_NONE;
5392 p2ps_prov->role = role;
5402 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5405 struct p2ps_provision *p2ps_prov;
5408 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5410 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5412 if (hwaddr_aton(cmd, addr))
5419 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5423 if (p2ps_prov->status < 0) {
5428 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5433 static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5436 struct p2ps_provision *p2ps_prov;
5439 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5440 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5443 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5444 if (hwaddr_aton(cmd, addr))
5451 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5455 p2ps_prov->pd_seeker = 1;
5457 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5462 static int parse_freq(int chwidth, int freq2)
5467 return VHT_CHANWIDTH_80P80MHZ;
5473 return VHT_CHANWIDTH_USE_HT;
5475 return VHT_CHANWIDTH_80MHZ;
5477 return VHT_CHANWIDTH_160MHZ;
5479 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5486 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5487 char *buf, size_t buflen)
5492 enum p2p_wps_method wps_method;
5495 int persistent_group, persistent_id = -1;
5502 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
5503 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5504 size_t group_ssid_len = 0;
5506 if (!wpa_s->global->p2p_init_wpa_s)
5508 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5509 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5510 wpa_s->global->p2p_init_wpa_s->ifname);
5511 wpa_s = wpa_s->global->p2p_init_wpa_s;
5514 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5515 * [persistent|persistent=<network id>]
5516 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5517 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5519 if (hwaddr_aton(cmd, addr))
5527 persistent_group = os_strstr(pos, " persistent") != NULL;
5528 pos2 = os_strstr(pos, " persistent=");
5530 struct wpa_ssid *ssid;
5531 persistent_id = atoi(pos2 + 12);
5532 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5533 if (ssid == NULL || ssid->disabled != 2 ||
5534 ssid->mode != WPAS_MODE_P2P_GO) {
5535 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
5536 "SSID id=%d for persistent P2P group (GO)",
5541 join = os_strstr(pos, " join") != NULL;
5542 auth = os_strstr(pos, " auth") != NULL;
5543 automatic = os_strstr(pos, " auto") != NULL;
5544 pd = os_strstr(pos, " provdisc") != NULL;
5545 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5546 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5549 pos2 = os_strstr(pos, " go_intent=");
5552 go_intent = atoi(pos2);
5553 if (go_intent < 0 || go_intent > 15)
5557 pos2 = os_strstr(pos, " freq=");
5565 pos2 = os_strstr(pos, " freq2=");
5567 freq2 = atoi(pos2 + 7);
5569 pos2 = os_strstr(pos, " max_oper_chwidth=");
5571 chwidth = atoi(pos2 + 18);
5573 max_oper_chwidth = parse_freq(chwidth, freq2);
5574 if (max_oper_chwidth < 0)
5577 pos2 = os_strstr(pos, " ssid=");
5582 end = os_strchr(pos2, ' ');
5584 group_ssid_len = os_strlen(pos2) / 2;
5586 group_ssid_len = (end - pos2) / 2;
5587 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
5588 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
5590 group_ssid = _group_ssid;
5593 if (os_strncmp(pos, "pin", 3) == 0) {
5594 /* Request random PIN (to be displayed) and enable the PIN */
5595 wps_method = WPS_PIN_DISPLAY;
5596 } else if (os_strncmp(pos, "pbc", 3) == 0) {
5597 wps_method = WPS_PBC;
5598 } else if (os_strstr(pos, "p2ps") != NULL) {
5599 wps_method = WPS_P2PS;
5602 pos = os_strchr(pin, ' ');
5603 wps_method = WPS_PIN_KEYPAD;
5606 if (os_strncmp(pos, "display", 7) == 0)
5607 wps_method = WPS_PIN_DISPLAY;
5609 if (!wps_pin_str_valid(pin)) {
5610 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
5615 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
5616 persistent_group, automatic, join,
5617 auth, go_intent, freq, freq2, persistent_id,
5618 pd, ht40, vht, max_oper_chwidth,
5619 group_ssid, group_ssid_len);
5620 if (new_pin == -2) {
5621 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5624 if (new_pin == -3) {
5625 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5630 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
5631 ret = os_snprintf(buf, buflen, "%08d", new_pin);
5632 if (os_snprintf_error(buflen, ret))
5637 os_memcpy(buf, "OK\n", 3);
5642 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
5644 unsigned int timeout = atoi(cmd);
5645 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5646 wpa_dbg(wpa_s, MSG_INFO,
5647 "Reject P2P_LISTEN since interface is disabled");
5650 return wpas_p2p_listen(wpa_s, timeout);
5654 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
5658 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
5660 /* <addr> <config method> [join|auto] */
5662 if (hwaddr_aton(cmd, addr))
5670 if (os_strstr(pos, " join") != NULL)
5671 use = WPAS_P2P_PD_FOR_JOIN;
5672 else if (os_strstr(pos, " auto") != NULL)
5673 use = WPAS_P2P_PD_AUTO;
5675 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
5679 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
5682 struct wpa_ssid *ssid = wpa_s->current_ssid;
5684 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
5685 ssid->passphrase == NULL)
5688 os_strlcpy(buf, ssid->passphrase, buflen);
5689 return os_strlen(buf);
5693 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
5694 char *buf, size_t buflen)
5698 u8 dst_buf[ETH_ALEN], *dst;
5699 struct wpabuf *tlvs;
5703 if (hwaddr_aton(cmd, dst_buf))
5706 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
5707 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
5714 if (os_strncmp(pos, "upnp ", 5) == 0) {
5717 if (hexstr2bin(pos, &version, 1) < 0)
5723 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
5724 #ifdef CONFIG_WIFI_DISPLAY
5725 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
5726 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
5727 #endif /* CONFIG_WIFI_DISPLAY */
5728 } else if (os_strncmp(pos, "asp ", 4) == 0) {
5730 char *svc_info = NULL;
5734 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
5737 pos = os_strchr(pos, ' ');
5738 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
5743 pos = os_strchr(svc_str, ' ');
5748 /* All remaining data is the svc_info string */
5749 if (pos && pos[0] && pos[0] != ' ') {
5750 len = os_strlen(pos);
5752 /* Unescape in place */
5753 len = utf8_unescape(pos, len, pos, len);
5760 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
5763 len = os_strlen(pos);
5767 tlvs = wpabuf_alloc(len);
5770 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
5775 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
5780 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
5781 if (os_snprintf_error(buflen, res))
5787 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5790 long long unsigned val;
5792 if (sscanf(cmd, "%llx", &val) != 1)
5795 return wpas_p2p_sd_cancel_request(wpa_s, req);
5799 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5804 struct wpabuf *resp_tlvs;
5808 pos = os_strchr(cmd, ' ');
5816 if (hwaddr_aton(pos, dst))
5823 pos2 = os_strchr(pos, ' ');
5827 dialog_token = atoi(pos);
5829 len = os_strlen(pos2);
5833 resp_tlvs = wpabuf_alloc(len);
5834 if (resp_tlvs == NULL)
5836 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
5837 wpabuf_free(resp_tlvs);
5841 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
5842 wpabuf_free(resp_tlvs);
5847 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
5850 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
5852 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
5857 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
5862 struct wpabuf *query, *resp;
5864 pos = os_strchr(cmd, ' ');
5869 len = os_strlen(cmd);
5873 query = wpabuf_alloc(len);
5876 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5881 len = os_strlen(pos);
5887 resp = wpabuf_alloc(len);
5892 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
5898 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
5907 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5912 pos = os_strchr(cmd, ' ');
5917 if (hexstr2bin(cmd, &version, 1) < 0)
5920 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
5924 static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
5925 u8 replace, char *cmd)
5929 u32 auto_accept, adv_id, svc_state, config_methods;
5930 char *svc_info = NULL;
5932 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
5934 pos = os_strchr(cmd, ' ');
5939 /* Auto-Accept value is mandatory, and must be one of the
5940 * single values (0, 1, 2, 4) */
5941 auto_accept = atoi(cmd);
5942 switch (auto_accept) {
5943 case P2PS_SETUP_NONE: /* No auto-accept */
5944 case P2PS_SETUP_NEW:
5945 case P2PS_SETUP_CLIENT:
5946 case P2PS_SETUP_GROUP_OWNER:
5952 /* Advertisement ID is mandatory */
5954 pos = os_strchr(cmd, ' ');
5959 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5960 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
5963 /* Only allow replacements if exist, and adds if not */
5964 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
5972 /* svc_state between 0 - 0xff is mandatory */
5973 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
5976 pos = os_strchr(pos, ' ');
5980 /* config_methods is mandatory */
5982 if (sscanf(pos, "%x", &config_methods) != 1)
5985 if (!(config_methods &
5986 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
5989 pos = os_strchr(pos, ' ');
5996 /* Advertisement string is mandatory */
5997 if (!pos[0] || pos[0] == ' ')
6000 /* Terminate svc string */
6001 pos = os_strchr(pos, ' ');
6005 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6007 pos = os_strchr(pos, ' ');
6011 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6014 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6018 /* Service and Response Information are optional */
6019 if (pos && pos[0]) {
6022 /* Note the bare ' included, which cannot exist legally
6023 * in unescaped string. */
6024 svc_info = os_strstr(pos, "svc_info='");
6028 len = os_strlen(svc_info);
6029 utf8_unescape(svc_info, len, svc_info, len);
6033 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6034 (u8) svc_state, (u16) config_methods,
6035 svc_info, cpt_prio);
6039 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6043 pos = os_strchr(cmd, ' ');
6048 if (os_strcmp(cmd, "bonjour") == 0)
6049 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6050 if (os_strcmp(cmd, "upnp") == 0)
6051 return p2p_ctrl_service_add_upnp(wpa_s, pos);
6052 if (os_strcmp(cmd, "asp") == 0)
6053 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
6054 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6059 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6063 struct wpabuf *query;
6066 len = os_strlen(cmd);
6070 query = wpabuf_alloc(len);
6073 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6078 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6084 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6089 pos = os_strchr(cmd, ' ');
6094 if (hexstr2bin(cmd, &version, 1) < 0)
6097 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6101 static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6105 if (os_strcmp(cmd, "all") == 0) {
6106 wpas_p2p_service_flush_asp(wpa_s);
6110 if (sscanf(cmd, "%x", &adv_id) != 1)
6113 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6117 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6121 pos = os_strchr(cmd, ' ');
6126 if (os_strcmp(cmd, "bonjour") == 0)
6127 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6128 if (os_strcmp(cmd, "upnp") == 0)
6129 return p2p_ctrl_service_del_upnp(wpa_s, pos);
6130 if (os_strcmp(cmd, "asp") == 0)
6131 return p2p_ctrl_service_del_asp(wpa_s, pos);
6132 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6137 static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6141 pos = os_strchr(cmd, ' ');
6146 if (os_strcmp(cmd, "asp") == 0)
6147 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6149 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6154 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6160 if (hwaddr_aton(cmd, addr))
6163 return wpas_p2p_reject(wpa_s, addr);
6167 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6171 struct wpa_ssid *ssid;
6172 u8 *_peer = NULL, peer[ETH_ALEN];
6173 int freq = 0, pref_freq = 0;
6174 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
6177 pos = os_strstr(cmd, " peer=");
6180 if (hwaddr_aton(pos, peer))
6184 ssid = wpa_config_get_network(wpa_s->conf, id);
6185 if (ssid == NULL || ssid->disabled != 2) {
6186 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6187 "for persistent P2P group",
6192 pos = os_strstr(cmd, " freq=");
6200 pos = os_strstr(cmd, " pref=");
6203 pref_freq = atoi(pos);
6208 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6209 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6212 pos = os_strstr(cmd, "freq2=");
6214 freq2 = atoi(pos + 6);
6216 pos = os_strstr(cmd, " max_oper_chwidth=");
6218 chwidth = atoi(pos + 18);
6220 max_oper_chwidth = parse_freq(chwidth, freq2);
6221 if (max_oper_chwidth < 0)
6224 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
6225 max_oper_chwidth, pref_freq);
6229 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6232 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
6234 pos = os_strstr(cmd, " peer=");
6240 if (hwaddr_aton(pos, peer)) {
6241 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6245 pos = os_strstr(pos, " go_dev_addr=");
6248 if (hwaddr_aton(pos, go_dev_addr)) {
6249 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6253 go_dev = go_dev_addr;
6256 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6260 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6262 if (os_strncmp(cmd, "persistent=", 11) == 0)
6263 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6264 if (os_strncmp(cmd, "group=", 6) == 0)
6265 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6271 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
6272 int id, int freq, int vht_center_freq2,
6273 int ht40, int vht, int vht_chwidth)
6275 struct wpa_ssid *ssid;
6277 ssid = wpa_config_get_network(wpa_s->conf, id);
6278 if (ssid == NULL || ssid->disabled != 2) {
6279 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6280 "for persistent P2P group",
6285 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6286 vht_center_freq2, 0, ht40, vht,
6287 vht_chwidth, NULL, 0, 0);
6291 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6293 int freq = 0, persistent = 0, group_id = -1;
6294 int vht = wpa_s->conf->p2p_go_vht;
6295 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
6296 int max_oper_chwidth, chwidth = 0, freq2 = 0;
6297 char *token, *context = NULL;
6300 #endif /* CONFIG_ACS */
6302 while ((token = str_token(cmd, " ", &context))) {
6303 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
6304 sscanf(token, "persistent=%d", &group_id) == 1 ||
6305 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
6308 } else if (os_strcmp(token, "freq=acs") == 0) {
6310 #endif /* CONFIG_ACS */
6311 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6313 } else if (os_strcmp(token, "ht40") == 0) {
6315 } else if (os_strcmp(token, "vht") == 0) {
6318 } else if (os_strcmp(token, "persistent") == 0) {
6321 wpa_printf(MSG_DEBUG,
6322 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6329 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6330 (acs || freq == 2 || freq == 5)) {
6331 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6332 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6333 wpa_s->p2p_go_do_acs = 1;
6335 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6336 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6337 wpa_s->p2p_go_do_acs = 1;
6340 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6341 wpa_s->p2p_go_do_acs = 1;
6344 #endif /* CONFIG_ACS */
6346 max_oper_chwidth = parse_freq(chwidth, freq2);
6347 if (max_oper_chwidth < 0)
6351 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
6352 freq, freq2, ht40, vht,
6355 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
6360 static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6361 char *buf, size_t buflen)
6363 u8 dev_addr[ETH_ALEN];
6364 struct wpa_ssid *ssid;
6368 ssid = wpa_s->current_ssid;
6369 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6370 hwaddr_aton(cmd, dev_addr))
6373 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6376 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6377 if (os_snprintf_error(buflen, res))
6383 static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6384 const u8 *p2p_dev_addr)
6386 struct wpa_supplicant *wpa_s;
6388 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6389 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6397 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6398 char *buf, size_t buflen)
6400 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
6402 const struct p2p_peer_info *info;
6404 char devtype[WPS_DEV_TYPE_BUFSIZE];
6405 struct wpa_ssid *ssid;
6408 if (!wpa_s->global->p2p)
6411 if (os_strcmp(cmd, "FIRST") == 0) {
6414 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6415 if (hwaddr_aton(cmd + 5, addr) < 0)
6420 if (hwaddr_aton(cmd, addr) < 0)
6426 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6429 group_capab = info->group_capab;
6432 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6433 wpa_printf(MSG_DEBUG,
6434 "P2P: Could not find any BSS with p2p_dev_addr "
6435 MACSTR ", hence override group_capab from 0x%x to 0",
6436 MAC2STR(info->p2p_device_addr), group_capab);
6443 res = os_snprintf(pos, end - pos, MACSTR "\n"
6449 "serial_number=%s\n"
6450 "config_methods=0x%x\n"
6452 "group_capab=0x%x\n"
6454 MAC2STR(info->p2p_device_addr),
6455 wps_dev_type_bin2str(info->pri_dev_type,
6456 devtype, sizeof(devtype)),
6461 info->serial_number,
6462 info->config_methods,
6466 if (os_snprintf_error(end - pos, res))
6470 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6473 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6474 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6475 wps_dev_type_bin2str(t, devtype,
6477 if (os_snprintf_error(end - pos, res))
6482 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
6484 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
6485 if (os_snprintf_error(end - pos, res))
6490 res = p2p_get_peer_info_txt(info, pos, end - pos);
6495 if (info->vendor_elems) {
6496 res = os_snprintf(pos, end - pos, "vendor_elems=");
6497 if (os_snprintf_error(end - pos, res))
6501 pos += wpa_snprintf_hex(pos, end - pos,
6502 wpabuf_head(info->vendor_elems),
6503 wpabuf_len(info->vendor_elems));
6505 res = os_snprintf(pos, end - pos, "\n");
6506 if (os_snprintf_error(end - pos, res))
6515 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6520 if (wpa_s->global->p2p == NULL)
6523 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
6526 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
6527 struct wpa_freq_range *freq;
6528 freq = &wpa_s->global->p2p_disallow_freq.range[i];
6529 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
6530 freq->min, freq->max);
6533 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
6538 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
6542 if (wpa_s->global->p2p == NULL)
6545 param = os_strchr(cmd, ' ');
6550 if (os_strcmp(cmd, "discoverability") == 0) {
6551 p2p_set_client_discoverability(wpa_s->global->p2p,
6556 if (os_strcmp(cmd, "managed") == 0) {
6557 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
6561 if (os_strcmp(cmd, "listen_channel") == 0) {
6563 u8 channel, op_class;
6565 channel = atoi(param);
6566 pos = os_strchr(param, ' ');
6567 op_class = pos ? atoi(pos) : 81;
6569 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
6573 if (os_strcmp(cmd, "ssid_postfix") == 0) {
6574 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
6578 if (os_strcmp(cmd, "noa") == 0) {
6580 int count, start, duration;
6581 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6582 count = atoi(param);
6583 pos = os_strchr(param, ',');
6588 pos = os_strchr(pos, ',');
6592 duration = atoi(pos);
6593 if (count < 0 || count > 255 || start < 0 || duration < 0)
6595 if (count == 0 && duration > 0)
6597 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6598 "start=%d duration=%d", count, start, duration);
6599 return wpas_p2p_set_noa(wpa_s, count, start, duration);
6602 if (os_strcmp(cmd, "ps") == 0)
6603 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
6605 if (os_strcmp(cmd, "oppps") == 0)
6606 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
6608 if (os_strcmp(cmd, "ctwindow") == 0)
6609 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
6611 if (os_strcmp(cmd, "disabled") == 0) {
6612 wpa_s->global->p2p_disabled = atoi(param);
6613 wpa_printf(MSG_DEBUG, "P2P functionality %s",
6614 wpa_s->global->p2p_disabled ?
6615 "disabled" : "enabled");
6616 if (wpa_s->global->p2p_disabled) {
6617 wpas_p2p_stop_find(wpa_s);
6618 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6619 p2p_flush(wpa_s->global->p2p);
6624 if (os_strcmp(cmd, "conc_pref") == 0) {
6625 if (os_strcmp(param, "sta") == 0)
6626 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
6627 else if (os_strcmp(param, "p2p") == 0)
6628 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
6630 wpa_printf(MSG_INFO, "Invalid conc_pref value");
6633 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
6638 if (os_strcmp(cmd, "force_long_sd") == 0) {
6639 wpa_s->force_long_sd = atoi(param);
6643 if (os_strcmp(cmd, "peer_filter") == 0) {
6645 if (hwaddr_aton(param, addr))
6647 p2p_set_peer_filter(wpa_s->global->p2p, addr);
6651 if (os_strcmp(cmd, "cross_connect") == 0)
6652 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
6654 if (os_strcmp(cmd, "go_apsd") == 0) {
6655 if (os_strcmp(param, "disable") == 0)
6656 wpa_s->set_ap_uapsd = 0;
6658 wpa_s->set_ap_uapsd = 1;
6659 wpa_s->ap_uapsd = atoi(param);
6664 if (os_strcmp(cmd, "client_apsd") == 0) {
6665 if (os_strcmp(param, "disable") == 0)
6666 wpa_s->set_sta_uapsd = 0;
6670 /* format: BE,BK,VI,VO;max SP Length */
6672 pos = os_strchr(param, ',');
6677 pos = os_strchr(pos, ',');
6682 pos = os_strchr(pos, ',');
6687 /* ignore max SP Length for now */
6689 wpa_s->set_sta_uapsd = 1;
6690 wpa_s->sta_uapsd = 0;
6692 wpa_s->sta_uapsd |= BIT(0);
6694 wpa_s->sta_uapsd |= BIT(1);
6696 wpa_s->sta_uapsd |= BIT(2);
6698 wpa_s->sta_uapsd |= BIT(3);
6703 if (os_strcmp(cmd, "disallow_freq") == 0)
6704 return p2p_ctrl_disallow_freq(wpa_s, param);
6706 if (os_strcmp(cmd, "disc_int") == 0) {
6707 int min_disc_int, max_disc_int, max_disc_tu;
6712 min_disc_int = atoi(pos);
6713 pos = os_strchr(pos, ' ');
6718 max_disc_int = atoi(pos);
6719 pos = os_strchr(pos, ' ');
6724 max_disc_tu = atoi(pos);
6726 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
6727 max_disc_int, max_disc_tu);
6730 if (os_strcmp(cmd, "per_sta_psk") == 0) {
6731 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
6735 #ifdef CONFIG_WPS_NFC
6736 if (os_strcmp(cmd, "nfc_tag") == 0)
6737 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
6738 #endif /* CONFIG_WPS_NFC */
6740 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
6741 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
6745 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
6748 op_class = atoi(param);
6749 param = os_strchr(param, ':');
6754 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
6759 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6766 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
6768 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6769 wpa_s->force_long_sd = 0;
6771 #ifdef CONFIG_TESTING_OPTIONS
6772 os_free(wpa_s->get_pref_freq_list_override);
6773 wpa_s->get_pref_freq_list_override = NULL;
6774 #endif /* CONFIG_TESTING_OPTIONS */
6776 wpas_p2p_stop_find(wpa_s);
6777 wpa_s->parent->p2ps_method_config_any = 0;
6778 if (wpa_s->global->p2p)
6779 p2p_flush(wpa_s->global->p2p);
6783 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
6786 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
6789 pos = os_strchr(cmd, ' ');
6795 pos2 = os_strchr(pos, ' ');
6803 pos = os_strchr(pos2, ' ');
6811 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
6815 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
6818 unsigned int period = 0, interval = 0;
6821 pos = os_strchr(cmd, ' ');
6826 interval = atoi(pos);
6829 return wpas_p2p_ext_listen(wpa_s, period, interval);
6833 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
6840 if (os_strncmp(pos, "iface=", 6) == 0) {
6844 if (hwaddr_aton(pos, peer))
6847 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
6852 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
6854 int freq = 0, period = 0, interval = 0, count = 0;
6856 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
6858 wpa_printf(MSG_DEBUG,
6859 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
6863 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
6866 #endif /* CONFIG_P2P */
6869 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
6871 struct wpa_freq_range_list ranges;
6873 struct hostapd_hw_modes *mode;
6876 if (wpa_s->hw.modes == NULL)
6879 os_memset(&ranges, 0, sizeof(ranges));
6880 if (freq_range_list_parse(&ranges, val) < 0)
6883 for (i = 0; i < wpa_s->hw.num_modes; i++) {
6886 mode = &wpa_s->hw.modes[i];
6887 for (j = 0; j < mode->num_channels; j++) {
6890 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
6893 freq = mode->channels[j].freq;
6894 if (!freq_range_list_includes(&ranges, freq))
6897 int_array_add_unique(&freqs, freq);
6901 os_free(ranges.range);
6906 #ifdef CONFIG_INTERWORKING
6908 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
6916 auto_sel = os_strstr(param, "auto") != NULL;
6918 pos = os_strstr(param, "freq=");
6920 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
6927 return interworking_select(wpa_s, auto_sel, freqs);
6931 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
6935 struct wpa_bss *bss;
6937 if (hwaddr_aton(dst, bssid)) {
6938 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
6942 bss = wpa_bss_get_bssid(wpa_s, bssid);
6944 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
6949 if (bss->ssid_len == 0) {
6952 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
6953 " does not have SSID information", MAC2STR(bssid));
6955 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
6957 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
6958 bss->ssid_len > 0) {
6966 wpa_printf(MSG_DEBUG,
6967 "Found another matching BSS entry with SSID");
6970 return interworking_connect(wpa_s, bss, only_add);
6974 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
6976 u8 dst_addr[ETH_ALEN];
6979 #define MAX_ANQP_INFO_ID 100
6980 u16 id[MAX_ANQP_INFO_ID];
6983 u32 mbo_subtypes = 0;
6985 used = hwaddr_aton2(dst, dst_addr);
6991 while (num_id < MAX_ANQP_INFO_ID) {
6992 if (os_strncmp(pos, "hs20:", 5) == 0) {
6994 int num = atoi(pos + 5);
6995 if (num <= 0 || num > 31)
6997 subtypes |= BIT(num);
6998 #else /* CONFIG_HS20 */
7000 #endif /* CONFIG_HS20 */
7001 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7003 int num = atoi(pos + 4);
7005 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
7007 mbo_subtypes |= BIT(num);
7008 #else /* CONFIG_MBO */
7010 #endif /* CONFIG_MBO */
7012 id[num_id] = atoi(pos);
7016 pos = os_strchr(pos + 1, ',');
7022 if (num_id == 0 && !subtypes && !mbo_subtypes)
7025 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
7030 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7032 u8 dst_addr[ETH_ALEN];
7033 struct wpabuf *advproto, *query = NULL;
7038 used = hwaddr_aton2(cmd, dst_addr);
7046 /* Advertisement Protocol ID */
7047 end = os_strchr(pos, ' ');
7051 len = os_strlen(pos);
7057 advproto = wpabuf_alloc(len);
7058 if (advproto == NULL)
7060 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7064 /* Optional Query Request */
7069 len = os_strlen(pos);
7076 query = wpabuf_alloc(len);
7079 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7084 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7087 wpabuf_free(advproto);
7094 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7101 size_t resp_len, start, requested_len;
7102 struct wpabuf *resp;
7105 used = hwaddr_aton2(cmd, addr);
7112 dialog_token = atoi(pos);
7114 if (wpa_s->last_gas_resp &&
7115 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7116 dialog_token == wpa_s->last_gas_dialog_token)
7117 resp = wpa_s->last_gas_resp;
7118 else if (wpa_s->prev_gas_resp &&
7119 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7120 dialog_token == wpa_s->prev_gas_dialog_token)
7121 resp = wpa_s->prev_gas_resp;
7125 resp_len = wpabuf_len(resp);
7127 requested_len = resp_len;
7129 pos = os_strchr(pos, ' ');
7132 if (start > resp_len)
7133 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7134 pos = os_strchr(pos, ',');
7138 requested_len = atoi(pos);
7139 if (start + requested_len > resp_len)
7140 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7143 if (requested_len * 2 + 1 > buflen)
7144 return os_snprintf(buf, buflen, "FAIL-Too long response");
7146 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7149 if (start + requested_len == resp_len) {
7151 * Free memory by dropping the response after it has been
7154 if (resp == wpa_s->prev_gas_resp) {
7155 wpabuf_free(wpa_s->prev_gas_resp);
7156 wpa_s->prev_gas_resp = NULL;
7158 wpabuf_free(wpa_s->last_gas_resp);
7159 wpa_s->last_gas_resp = NULL;
7165 #endif /* CONFIG_INTERWORKING */
7170 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7172 u8 dst_addr[ETH_ALEN];
7177 used = hwaddr_aton2(dst, dst_addr);
7184 int num = atoi(pos);
7185 if (num <= 0 || num > 31)
7187 subtypes |= BIT(num);
7188 pos = os_strchr(pos + 1, ',');
7197 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
7201 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7202 const u8 *addr, const char *realm)
7208 rlen = os_strlen(realm);
7210 buf = os_malloc(len);
7213 buf[0] = 1; /* NAI Home Realm Count */
7214 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7216 os_memcpy(buf + 3, realm, rlen);
7218 ret = hs20_anqp_send_req(wpa_s, addr,
7219 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
7228 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7231 struct wpa_cred *cred = wpa_s->conf->cred;
7232 u8 dst_addr[ETH_ALEN];
7238 used = hwaddr_aton2(dst, dst_addr);
7242 while (dst[used] == ' ')
7244 if (os_strncmp(dst + used, "realm=", 6) == 0)
7245 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7248 len = os_strlen(dst + used);
7250 if (len == 0 && cred && cred->realm)
7251 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7256 buf = os_malloc(len);
7259 if (hexstr2bin(dst + used, buf, len) < 0) {
7264 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7265 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
7273 static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7276 u8 dst_addr[ETH_ALEN];
7278 char *ctx = NULL, *icon, *poffset, *psize;
7280 used = hwaddr_aton2(cmd, dst_addr);
7285 icon = str_token(cmd, " ", &ctx);
7286 poffset = str_token(cmd, " ", &ctx);
7287 psize = str_token(cmd, " ", &ctx);
7288 if (!icon || !poffset || !psize)
7291 wpa_s->fetch_osu_icon_in_progress = 0;
7292 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7297 static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7299 u8 dst_addr[ETH_ALEN];
7304 return hs20_del_icon(wpa_s, NULL, NULL);
7306 used = hwaddr_aton2(cmd, dst_addr);
7310 while (cmd[used] == ' ')
7312 icon = cmd[used] ? &cmd[used] : NULL;
7314 return hs20_del_icon(wpa_s, dst_addr, icon);
7318 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
7320 u8 dst_addr[ETH_ALEN];
7324 used = hwaddr_aton2(cmd, dst_addr);
7328 while (cmd[used] == ' ')
7332 wpa_s->fetch_osu_icon_in_progress = 0;
7333 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
7334 (u8 *) icon, os_strlen(icon), inmem);
7337 #endif /* CONFIG_HS20 */
7340 #ifdef CONFIG_AUTOSCAN
7342 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7345 enum wpa_states state = wpa_s->wpa_state;
7346 char *new_params = NULL;
7348 if (os_strlen(cmd) > 0) {
7349 new_params = os_strdup(cmd);
7350 if (new_params == NULL)
7354 os_free(wpa_s->conf->autoscan);
7355 wpa_s->conf->autoscan = new_params;
7357 if (wpa_s->conf->autoscan == NULL)
7358 autoscan_deinit(wpa_s);
7359 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7360 autoscan_init(wpa_s, 1);
7361 else if (state == WPA_SCANNING)
7362 wpa_supplicant_reinit_autoscan(wpa_s);
7364 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7365 wpa_supplicant_state_txt(state));
7370 #endif /* CONFIG_AUTOSCAN */
7375 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7381 struct wpabuf *tfs_req = NULL;
7383 if (os_strncmp(cmd, "enter", 5) == 0)
7385 else if (os_strncmp(cmd, "exit", 4) == 0)
7390 pos = os_strstr(cmd, " interval=");
7392 intval = atoi(pos + 10);
7394 pos = os_strstr(cmd, " tfs_req=");
7399 end = os_strchr(pos, ' ');
7403 len = os_strlen(pos);
7407 tfs_req = wpabuf_alloc(len);
7408 if (tfs_req == NULL)
7410 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7411 wpabuf_free(tfs_req);
7416 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7417 WNM_SLEEP_MODE_EXIT, intval,
7419 wpabuf_free(tfs_req);
7425 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7427 int query_reason, list = 0;
7428 char *btm_candidates = NULL;
7430 query_reason = atoi(cmd);
7432 cmd = os_strchr(cmd, ' ');
7434 if (os_strncmp(cmd, " list", 5) == 0)
7437 btm_candidates = cmd;
7440 wpa_printf(MSG_DEBUG,
7441 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7442 query_reason, list ? " candidate list" : "");
7444 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7450 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
7453 struct wpabuf *elems;
7456 elems = wpabuf_parse_bin(cmd);
7460 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
7465 #endif /* CONFIG_WNM */
7468 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7471 struct wpa_signal_info si;
7475 ret = wpa_drv_signal_poll(wpa_s, &si);
7482 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
7483 "NOISE=%d\nFREQUENCY=%u\n",
7484 si.current_signal, si.current_txrate / 1000,
7485 si.current_noise, si.frequency);
7486 if (os_snprintf_error(end - pos, ret))
7490 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7491 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
7492 channel_width_to_string(si.chanwidth));
7493 if (os_snprintf_error(end - pos, ret))
7498 if (si.center_frq1 > 0) {
7499 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
7501 if (os_snprintf_error(end - pos, ret))
7506 if (si.center_frq2 > 0) {
7507 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
7509 if (os_snprintf_error(end - pos, ret))
7514 if (si.avg_signal) {
7515 ret = os_snprintf(pos, end - pos,
7516 "AVG_RSSI=%d\n", si.avg_signal);
7517 if (os_snprintf_error(end - pos, ret))
7522 if (si.avg_beacon_signal) {
7523 ret = os_snprintf(pos, end - pos,
7524 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
7525 if (os_snprintf_error(end - pos, ret))
7534 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
7541 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
7542 wpa_printf(MSG_DEBUG,
7543 "Reject SIGNAL_MONITOR command - bgscan is active");
7546 pos = os_strstr(cmd, "THRESHOLD=");
7548 threshold = atoi(pos + 10);
7549 pos = os_strstr(cmd, "HYSTERESIS=");
7551 hysteresis = atoi(pos + 11);
7552 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
7556 #ifdef CONFIG_TESTING_OPTIONS
7557 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
7558 enum wpa_driver_if_type if_type,
7560 unsigned int *freq_list)
7562 char *pos = wpa_s->get_pref_freq_list_override;
7564 unsigned int count = 0;
7566 /* Override string format:
7567 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7570 if (atoi(pos) == (int) if_type)
7572 pos = os_strchr(pos, ' ');
7578 pos = os_strchr(pos, ':');
7582 end = os_strchr(pos, ' ');
7583 while (pos && (!end || pos < end) && count < *num) {
7584 freq_list[count++] = atoi(pos);
7585 pos = os_strchr(pos, ',');
7593 #endif /* CONFIG_TESTING_OPTIONS */
7596 static int wpas_ctrl_iface_get_pref_freq_list(
7597 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
7599 unsigned int freq_list[100], num = 100, i;
7601 enum wpa_driver_if_type iface_type;
7607 /* buf: "<interface_type>" */
7608 if (os_strcmp(cmd, "STATION") == 0)
7609 iface_type = WPA_IF_STATION;
7610 else if (os_strcmp(cmd, "AP") == 0)
7611 iface_type = WPA_IF_AP_BSS;
7612 else if (os_strcmp(cmd, "P2P_GO") == 0)
7613 iface_type = WPA_IF_P2P_GO;
7614 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
7615 iface_type = WPA_IF_P2P_CLIENT;
7616 else if (os_strcmp(cmd, "IBSS") == 0)
7617 iface_type = WPA_IF_IBSS;
7618 else if (os_strcmp(cmd, "TDLS") == 0)
7619 iface_type = WPA_IF_TDLS;
7623 wpa_printf(MSG_DEBUG,
7624 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7627 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
7631 for (i = 0; i < num; i++) {
7632 ret = os_snprintf(pos, end - pos, "%s%u",
7633 i > 0 ? "," : "", freq_list[i]);
7634 if (os_snprintf_error(end - pos, ret))
7643 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
7644 char *buf, size_t buflen)
7649 ret = os_snprintf(buf, buflen, "%016llX:\n",
7650 (long long unsigned) wpa_s->drv_flags);
7651 if (os_snprintf_error(buflen, ret))
7657 for (i = 0; i < 64; i++) {
7658 if (wpa_s->drv_flags & (1LLU << i)) {
7659 ret = os_snprintf(pos, end - pos, "%s\n",
7660 driver_flag_to_string(1LLU << i));
7661 if (os_snprintf_error(end - pos, ret))
7671 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
7674 struct hostap_sta_driver_data sta;
7677 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
7681 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7682 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
7683 if (os_snprintf_error(buflen, ret))
7690 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7691 char *buf, size_t buflen)
7695 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
7697 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
7698 struct p2p_data *p2p = wpa_s->global->p2p;
7701 country[0] = cmd[8];
7702 country[1] = cmd[9];
7704 p2p_set_country(p2p, country);
7707 ret = os_snprintf(buf, buflen, "%s\n", "OK");
7708 if (os_snprintf_error(buflen, ret))
7713 #endif /* ANDROID */
7716 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7717 char *buf, size_t buflen)
7722 unsigned int vendor_id, subcmd;
7723 struct wpabuf *reply;
7724 size_t data_len = 0;
7726 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7727 vendor_id = strtoul(cmd, &pos, 16);
7728 if (!isblank((unsigned char) *pos))
7731 subcmd = strtoul(pos, &pos, 10);
7734 if (!isblank((unsigned char) *pos++))
7736 data_len = os_strlen(pos);
7741 data = os_malloc(data_len);
7745 if (hexstr2bin(pos, data, data_len)) {
7746 wpa_printf(MSG_DEBUG,
7747 "Vendor command: wrong parameter format");
7753 reply = wpabuf_alloc((buflen - 1) / 2);
7759 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
7763 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
7773 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
7776 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
7777 wpa_s->global->p2p_init_wpa_s : wpa_s;
7778 #endif /* CONFIG_P2P */
7780 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
7782 if (wpas_abort_ongoing_scan(wpa_s) == 0)
7783 wpa_s->ignore_post_flush_scan_res = 1;
7785 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
7787 * Avoid possible auto connect re-connection on getting
7788 * disconnected due to state flush.
7790 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
7794 wpas_p2p_group_remove(p2p_wpa_s, "*");
7795 wpas_p2p_cancel(p2p_wpa_s);
7796 p2p_ctrl_flush(p2p_wpa_s);
7797 wpas_p2p_service_flush(p2p_wpa_s);
7798 p2p_wpa_s->global->p2p_disabled = 0;
7799 p2p_wpa_s->global->p2p_per_sta_psk = 0;
7800 p2p_wpa_s->conf->num_sec_device_types = 0;
7801 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
7802 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
7803 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
7804 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
7805 p2p_wpa_s->global->pending_p2ps_group = 0;
7806 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
7807 #endif /* CONFIG_P2P */
7809 #ifdef CONFIG_WPS_TESTING
7810 wps_version_number = 0x20;
7811 wps_testing_dummy_cred = 0;
7812 wps_corrupt_pkhash = 0;
7813 wps_force_auth_types_in_use = 0;
7814 wps_force_encr_types_in_use = 0;
7815 #endif /* CONFIG_WPS_TESTING */
7817 wpa_s->wps_fragment_size = 0;
7818 wpas_wps_cancel(wpa_s);
7819 wps_registrar_flush(wpa_s->wps->registrar);
7820 #endif /* CONFIG_WPS */
7821 wpa_s->after_wps = 0;
7822 wpa_s->known_wps_freq = 0;
7825 wpas_dpp_deinit(wpa_s);
7826 wpa_s->dpp_init_max_tries = 0;
7827 wpa_s->dpp_init_retry_time = 0;
7828 wpa_s->dpp_resp_wait_time = 0;
7829 wpa_s->dpp_resp_max_tries = 0;
7830 wpa_s->dpp_resp_retry_time = 0;
7831 #ifdef CONFIG_TESTING_OPTIONS
7832 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
7833 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
7834 dpp_pkex_ephemeral_key_override_len = 0;
7835 dpp_protocol_key_override_len = 0;
7836 dpp_nonce_override_len = 0;
7837 #endif /* CONFIG_TESTING_OPTIONS */
7838 #endif /* CONFIG_DPP */
7841 #ifdef CONFIG_TDLS_TESTING
7843 #endif /* CONFIG_TDLS_TESTING */
7844 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
7845 wpa_tdls_enable(wpa_s->wpa, 1);
7846 #endif /* CONFIG_TDLS */
7848 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
7849 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
7851 wpa_s->no_keep_alive = 0;
7852 wpa_s->own_disconnect_req = 0;
7854 os_free(wpa_s->disallow_aps_bssid);
7855 wpa_s->disallow_aps_bssid = NULL;
7856 wpa_s->disallow_aps_bssid_count = 0;
7857 os_free(wpa_s->disallow_aps_ssid);
7858 wpa_s->disallow_aps_ssid = NULL;
7859 wpa_s->disallow_aps_ssid_count = 0;
7861 wpa_s->set_sta_uapsd = 0;
7862 wpa_s->sta_uapsd = 0;
7864 wpa_drv_radio_disable(wpa_s, 0);
7865 wpa_blacklist_clear(wpa_s);
7866 wpa_s->extra_blacklist_count = 0;
7867 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
7868 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
7869 wpa_config_flush_blobs(wpa_s->conf);
7870 wpa_s->conf->auto_interworking = 0;
7871 wpa_s->conf->okc = 0;
7873 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7874 rsn_preauth_deinit(wpa_s->wpa);
7876 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
7877 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
7878 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
7879 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7881 radio_remove_works(wpa_s, NULL, 1);
7882 wpa_s->ext_work_in_progress = 0;
7884 wpa_s->next_ssid = NULL;
7886 #ifdef CONFIG_INTERWORKING
7888 hs20_cancel_fetch_osu(wpa_s);
7889 hs20_del_icon(wpa_s, NULL, NULL);
7890 #endif /* CONFIG_HS20 */
7891 #endif /* CONFIG_INTERWORKING */
7893 wpa_s->ext_mgmt_frame_handling = 0;
7894 wpa_s->ext_eapol_frame_io = 0;
7895 #ifdef CONFIG_TESTING_OPTIONS
7896 wpa_s->extra_roc_dur = 0;
7897 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
7898 wpa_s->p2p_go_csa_on_inv = 0;
7899 wpa_s->ignore_auth_resp = 0;
7900 wpa_s->ignore_assoc_disallow = 0;
7901 wpa_s->testing_resend_assoc = 0;
7902 wpa_s->reject_btm_req_reason = 0;
7903 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
7904 os_free(wpa_s->get_pref_freq_list_override);
7905 wpa_s->get_pref_freq_list_override = NULL;
7906 wpabuf_free(wpa_s->sae_commit_override);
7907 wpa_s->sae_commit_override = NULL;
7909 os_free(wpa_s->dpp_config_obj_override);
7910 wpa_s->dpp_config_obj_override = NULL;
7911 os_free(wpa_s->dpp_discovery_override);
7912 wpa_s->dpp_discovery_override = NULL;
7913 os_free(wpa_s->dpp_groups_override);
7914 wpa_s->dpp_groups_override = NULL;
7915 dpp_test = DPP_TEST_DISABLED;
7916 #endif /* CONFIG_DPP */
7917 #endif /* CONFIG_TESTING_OPTIONS */
7919 wpa_s->disconnected = 0;
7920 os_free(wpa_s->next_scan_freqs);
7921 wpa_s->next_scan_freqs = NULL;
7922 os_free(wpa_s->select_network_scan_freqs);
7923 wpa_s->select_network_scan_freqs = NULL;
7925 wpa_bss_flush(wpa_s);
7926 if (!dl_list_empty(&wpa_s->bss)) {
7927 wpa_printf(MSG_DEBUG,
7928 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7929 MACSTR " pending_bssid=" MACSTR,
7930 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
7931 MAC2STR(wpa_s->bssid),
7932 MAC2STR(wpa_s->pending_bssid));
7935 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
7936 wpa_s->wnmsleep_used = 0;
7939 wpa_s->sme.last_unprot_disconnect.sec = 0;
7940 #endif /* CONFIG_SME */
7942 wpabuf_free(wpa_s->ric_ies);
7943 wpa_s->ric_ies = NULL;
7947 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
7948 char *buf, size_t buflen)
7950 struct wpa_radio_work *work;
7952 struct os_reltime now, diff;
7957 os_get_reltime(&now);
7959 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
7963 os_reltime_sub(&now, &work->time, &diff);
7964 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
7965 work->type, work->wpa_s->ifname, work->freq,
7966 work->started, diff.sec, diff.usec);
7967 if (os_snprintf_error(end - pos, ret))
7976 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
7978 struct wpa_radio_work *work = eloop_ctx;
7979 struct wpa_external_work *ework = work->ctx;
7981 wpa_dbg(work->wpa_s, MSG_DEBUG,
7982 "Timing out external radio work %u (%s)",
7983 ework->id, work->type);
7984 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
7985 work->wpa_s->ext_work_in_progress = 0;
7986 radio_work_done(work);
7991 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
7993 struct wpa_external_work *ework = work->ctx;
7997 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8001 * work->type points to a buffer in ework, so need to replace
8002 * that here with a fixed string to avoid use of freed memory
8005 work->type = "freed-ext-work";
8011 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8012 ework->id, ework->type);
8013 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
8014 work->wpa_s->ext_work_in_progress = 1;
8015 if (!ework->timeout)
8016 ework->timeout = 10;
8017 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8022 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8023 char *buf, size_t buflen)
8025 struct wpa_external_work *ework;
8029 unsigned int freq = 0;
8031 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8033 ework = os_zalloc(sizeof(*ework));
8037 pos = os_strchr(cmd, ' ');
8039 type_len = pos - cmd;
8042 pos2 = os_strstr(pos, "freq=");
8044 freq = atoi(pos2 + 5);
8046 pos2 = os_strstr(pos, "timeout=");
8048 ework->timeout = atoi(pos2 + 8);
8050 type_len = os_strlen(cmd);
8052 if (4 + type_len >= sizeof(ework->type))
8053 type_len = sizeof(ework->type) - 4 - 1;
8054 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8055 os_memcpy(ework->type + 4, cmd, type_len);
8056 ework->type[4 + type_len] = '\0';
8058 wpa_s->ext_work_id++;
8059 if (wpa_s->ext_work_id == 0)
8060 wpa_s->ext_work_id++;
8061 ework->id = wpa_s->ext_work_id;
8063 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8069 ret = os_snprintf(buf, buflen, "%u", ework->id);
8070 if (os_snprintf_error(buflen, ret))
8076 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8078 struct wpa_radio_work *work;
8079 unsigned int id = atoi(cmd);
8081 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8083 struct wpa_external_work *ework;
8085 if (os_strncmp(work->type, "ext:", 4) != 0)
8088 if (id && ework->id != id)
8090 wpa_dbg(wpa_s, MSG_DEBUG,
8091 "Completed external radio work %u (%s)",
8092 ework->id, ework->type);
8093 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
8094 wpa_s->ext_work_in_progress = 0;
8095 radio_work_done(work);
8097 return 3; /* "OK\n" */
8104 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8105 char *buf, size_t buflen)
8107 if (os_strcmp(cmd, "show") == 0)
8108 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8109 if (os_strncmp(cmd, "add ", 4) == 0)
8110 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8111 if (os_strncmp(cmd, "done ", 5) == 0)
8112 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8117 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8119 struct wpa_radio_work *work, *tmp;
8121 if (!wpa_s || !wpa_s->radio)
8124 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8125 struct wpa_radio_work, list) {
8126 struct wpa_external_work *ework;
8128 if (os_strncmp(work->type, "ext:", 4) != 0)
8131 wpa_dbg(wpa_s, MSG_DEBUG,
8132 "Flushing%s external radio work %u (%s)",
8133 work->started ? " started" : "", ework->id,
8136 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8138 radio_work_done(work);
8144 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8146 struct wpa_supplicant *wpa_s = eloop_ctx;
8147 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8151 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8152 unsigned int *scan_id_count, int scan_id[])
8154 const char *pos = value;
8157 if (*pos == ' ' || *pos == '\0')
8159 if (*scan_id_count == MAX_SCAN_ID)
8161 scan_id[(*scan_id_count)++] = atoi(pos);
8162 pos = os_strchr(pos, ',');
8171 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8172 char *reply, int reply_size, int *reply_len)
8175 unsigned int manual_scan_passive = 0;
8176 unsigned int manual_scan_use_id = 0;
8177 unsigned int manual_scan_only_new = 0;
8178 unsigned int scan_only = 0;
8179 unsigned int scan_id_count = 0;
8180 int scan_id[MAX_SCAN_ID];
8181 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8182 struct wpa_scan_results *scan_res);
8183 int *manual_scan_freqs = NULL;
8184 struct wpa_ssid_value *ssid = NULL, *ns;
8185 unsigned int ssid_count = 0;
8187 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8192 if (radio_work_pending(wpa_s, "scan")) {
8193 wpa_printf(MSG_DEBUG,
8194 "Pending scan scheduled - reject new request");
8195 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8199 #ifdef CONFIG_INTERWORKING
8200 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8201 wpa_printf(MSG_DEBUG,
8202 "Interworking select in progress - reject new scan");
8203 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8206 #endif /* CONFIG_INTERWORKING */
8209 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
8212 pos = os_strstr(params, "freq=");
8214 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8216 if (manual_scan_freqs == NULL) {
8222 pos = os_strstr(params, "passive=");
8224 manual_scan_passive = !!atoi(pos + 8);
8226 pos = os_strstr(params, "use_id=");
8228 manual_scan_use_id = atoi(pos + 7);
8230 pos = os_strstr(params, "only_new=1");
8232 manual_scan_only_new = 1;
8234 pos = os_strstr(params, "scan_id=");
8235 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8241 pos = os_strstr(params, "bssid=");
8246 if (hwaddr_aton(pos, bssid)) {
8247 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8251 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
8255 while (pos && *pos != '\0') {
8256 if (os_strncmp(pos, "ssid ", 5) == 0) {
8262 if (*end == '\0' || *end == ' ')
8267 ns = os_realloc_array(
8268 ssid, ssid_count + 1,
8269 sizeof(struct wpa_ssid_value));
8276 if ((end - pos) & 0x01 ||
8277 end - pos > 2 * SSID_MAX_LEN ||
8278 hexstr2bin(pos, ssid[ssid_count].ssid,
8279 (end - pos) / 2) < 0) {
8280 wpa_printf(MSG_DEBUG,
8281 "Invalid SSID value '%s'",
8286 ssid[ssid_count].ssid_len = (end - pos) / 2;
8287 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8288 ssid[ssid_count].ssid,
8289 ssid[ssid_count].ssid_len);
8294 pos = os_strchr(pos, ' ');
8300 wpa_s->num_ssids_from_scan_req = ssid_count;
8301 os_free(wpa_s->ssids_from_scan_req);
8303 wpa_s->ssids_from_scan_req = ssid;
8306 wpa_s->ssids_from_scan_req = NULL;
8310 scan_res_handler = scan_only_handler;
8311 else if (wpa_s->scan_res_handler == scan_only_handler)
8312 scan_res_handler = NULL;
8314 scan_res_handler = wpa_s->scan_res_handler;
8316 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8317 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8318 (wpa_s->wpa_state == WPA_COMPLETED))) {
8319 wpa_s->manual_scan_passive = manual_scan_passive;
8320 wpa_s->manual_scan_use_id = manual_scan_use_id;
8321 wpa_s->manual_scan_only_new = manual_scan_only_new;
8322 wpa_s->scan_id_count = scan_id_count;
8323 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8324 wpa_s->scan_res_handler = scan_res_handler;
8325 os_free(wpa_s->manual_scan_freqs);
8326 wpa_s->manual_scan_freqs = manual_scan_freqs;
8327 manual_scan_freqs = NULL;
8329 wpa_s->normal_scans = 0;
8330 wpa_s->scan_req = MANUAL_SCAN_REQ;
8331 wpa_s->after_wps = 0;
8332 wpa_s->known_wps_freq = 0;
8333 wpa_supplicant_req_scan(wpa_s, 0, 0);
8334 if (wpa_s->manual_scan_use_id) {
8335 wpa_s->manual_scan_id++;
8336 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8337 wpa_s->manual_scan_id);
8338 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8339 wpa_s->manual_scan_id);
8341 } else if (wpa_s->sched_scanning) {
8342 wpa_s->manual_scan_passive = manual_scan_passive;
8343 wpa_s->manual_scan_use_id = manual_scan_use_id;
8344 wpa_s->manual_scan_only_new = manual_scan_only_new;
8345 wpa_s->scan_id_count = scan_id_count;
8346 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8347 wpa_s->scan_res_handler = scan_res_handler;
8348 os_free(wpa_s->manual_scan_freqs);
8349 wpa_s->manual_scan_freqs = manual_scan_freqs;
8350 manual_scan_freqs = NULL;
8352 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8353 wpa_supplicant_cancel_sched_scan(wpa_s);
8354 wpa_s->scan_req = MANUAL_SCAN_REQ;
8355 wpa_supplicant_req_scan(wpa_s, 0, 0);
8356 if (wpa_s->manual_scan_use_id) {
8357 wpa_s->manual_scan_id++;
8358 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8359 wpa_s->manual_scan_id);
8360 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8361 wpa_s->manual_scan_id);
8364 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
8365 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8369 os_free(manual_scan_freqs);
8374 #ifdef CONFIG_TESTING_OPTIONS
8376 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
8377 unsigned int freq, const u8 *dst,
8378 const u8 *src, const u8 *bssid,
8379 const u8 *data, size_t data_len,
8380 enum offchannel_send_action_result
8383 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8384 " src=" MACSTR " bssid=" MACSTR " result=%s",
8385 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
8386 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
8387 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
8388 "NO_ACK" : "FAILED"));
8392 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
8396 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
8398 int freq = 0, no_cck = 0, wait_time = 0;
8400 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8401 * <action=Action frame payload> */
8403 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
8406 used = hwaddr_aton2(pos, da);
8412 used = hwaddr_aton2(pos, bssid);
8417 param = os_strstr(pos, " freq=");
8423 param = os_strstr(pos, " no_cck=");
8426 no_cck = atoi(param);
8429 param = os_strstr(pos, " wait_time=");
8432 wait_time = atoi(param);
8435 param = os_strstr(pos, " action=");
8440 len = os_strlen(param);
8445 buf = os_malloc(len);
8449 if (hexstr2bin(param, buf, len) < 0) {
8454 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
8455 buf, len, wait_time,
8456 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
8462 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
8464 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
8465 offchannel_send_action_done(wpa_s);
8469 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
8475 int freq = 0, datarate = 0, ssi_signal = 0;
8476 union wpa_event_data event;
8478 if (!wpa_s->ext_mgmt_frame_handling)
8481 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8483 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
8486 param = os_strstr(pos, "freq=");
8492 param = os_strstr(pos, " datarate=");
8495 datarate = atoi(param);
8498 param = os_strstr(pos, " ssi_signal=");
8501 ssi_signal = atoi(param);
8504 param = os_strstr(pos, " frame=");
8509 len = os_strlen(param);
8514 buf = os_malloc(len);
8518 if (hexstr2bin(param, buf, len) < 0) {
8523 os_memset(&event, 0, sizeof(event));
8524 event.rx_mgmt.freq = freq;
8525 event.rx_mgmt.frame = buf;
8526 event.rx_mgmt.frame_len = len;
8527 event.rx_mgmt.ssi_signal = ssi_signal;
8528 event.rx_mgmt.datarate = datarate;
8529 wpa_s->ext_mgmt_frame_handling = 0;
8530 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
8531 wpa_s->ext_mgmt_frame_handling = 1;
8539 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
8542 struct wpa_scan_res *res;
8543 struct os_reltime now;
8550 if (os_strcmp(param, "START") == 0) {
8551 wpa_bss_update_start(wpa_s);
8555 if (os_strcmp(param, "END") == 0) {
8556 wpa_bss_update_end(wpa_s, NULL, 1);
8560 if (os_strncmp(param, "BSS ", 4) != 0)
8564 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
8568 pos = os_strstr(param, " flags=");
8570 res->flags = strtol(pos + 7, NULL, 16);
8572 pos = os_strstr(param, " bssid=");
8573 if (pos && hwaddr_aton(pos + 7, res->bssid))
8576 pos = os_strstr(param, " freq=");
8578 res->freq = atoi(pos + 6);
8580 pos = os_strstr(param, " beacon_int=");
8582 res->beacon_int = atoi(pos + 12);
8584 pos = os_strstr(param, " caps=");
8586 res->caps = strtol(pos + 6, NULL, 16);
8588 pos = os_strstr(param, " qual=");
8590 res->qual = atoi(pos + 6);
8592 pos = os_strstr(param, " noise=");
8594 res->noise = atoi(pos + 7);
8596 pos = os_strstr(param, " level=");
8598 res->level = atoi(pos + 7);
8600 pos = os_strstr(param, " tsf=");
8602 res->tsf = strtoll(pos + 5, NULL, 16);
8604 pos = os_strstr(param, " age=");
8606 res->age = atoi(pos + 5);
8608 pos = os_strstr(param, " est_throughput=");
8610 res->est_throughput = atoi(pos + 16);
8612 pos = os_strstr(param, " snr=");
8614 res->snr = atoi(pos + 5);
8616 pos = os_strstr(param, " parent_tsf=");
8618 res->parent_tsf = strtoll(pos + 7, NULL, 16);
8620 pos = os_strstr(param, " tsf_bssid=");
8621 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
8624 pos = os_strstr(param, " ie=");
8627 end = os_strchr(pos, ' ');
8629 end = pos + os_strlen(pos);
8630 res->ie_len = (end - pos) / 2;
8631 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
8635 pos = os_strstr(param, " beacon_ie=");
8638 end = os_strchr(pos, ' ');
8640 end = pos + os_strlen(pos);
8641 res->beacon_ie_len = (end - pos) / 2;
8642 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
8643 res->beacon_ie_len))
8647 os_get_reltime(&now);
8648 wpa_bss_update_scan_res(wpa_s, res, &now);
8657 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
8660 union wpa_event_data event;
8661 enum wpa_event_type ev;
8663 /* <event name> [parameters..] */
8665 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
8668 param = os_strchr(pos, ' ');
8672 os_memset(&event, 0, sizeof(event));
8674 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
8675 ev = EVENT_INTERFACE_ENABLED;
8676 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
8677 ev = EVENT_INTERFACE_DISABLED;
8678 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
8679 ev = EVENT_AVOID_FREQUENCIES;
8682 if (freq_range_list_parse(&event.freq_range, param) < 0)
8684 wpa_supplicant_event(wpa_s, ev, &event);
8685 os_free(event.freq_range.range);
8687 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
8688 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
8690 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
8695 wpa_supplicant_event(wpa_s, ev, &event);
8701 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
8704 u8 src[ETH_ALEN], *buf;
8708 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
8711 used = hwaddr_aton2(pos, src);
8718 len = os_strlen(pos);
8723 buf = os_malloc(len);
8727 if (hexstr2bin(pos, buf, len) < 0) {
8732 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
8739 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
8743 const u16 *pos = buf;
8745 for (i = 0; i < len / 2; i++)
8749 sum = (sum & 0xffff) + (sum >> 16);
8751 return sum ^ 0xffff;
8755 #define HWSIM_PACKETLEN 1500
8756 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8758 static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
8761 struct wpa_supplicant *wpa_s = ctx;
8762 const struct ether_header *eth;
8767 if (len != HWSIM_PACKETLEN)
8770 eth = (const struct ether_header *) buf;
8771 os_memcpy(&ip, eth + 1, sizeof(ip));
8772 pos = &buf[sizeof(*eth) + sizeof(ip)];
8774 if (ip.ihl != 5 || ip.version != 4 ||
8775 ntohs(ip.tot_len) != HWSIM_IP_LEN)
8778 for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) {
8784 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
8785 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
8789 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
8792 int enabled = atoi(cmd);
8797 if (wpa_s->l2_test) {
8798 l2_packet_deinit(wpa_s->l2_test);
8799 wpa_s->l2_test = NULL;
8800 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
8808 pos = os_strstr(cmd, " ifname=");
8812 ifname = wpa_s->ifname;
8814 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
8815 ETHERTYPE_IP, wpas_data_test_rx,
8817 if (wpa_s->l2_test == NULL)
8820 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
8826 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
8828 u8 dst[ETH_ALEN], src[ETH_ALEN];
8833 u8 buf[2 + HWSIM_PACKETLEN];
8834 struct ether_header *eth;
8839 if (wpa_s->l2_test == NULL)
8842 /* format: <dst> <src> <tos> */
8845 used = hwaddr_aton2(pos, dst);
8851 used = hwaddr_aton2(pos, src);
8856 val = strtol(pos, NULL, 0);
8857 if (val < 0 || val > 0xff)
8861 eth = (struct ether_header *) &buf[2];
8862 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
8863 os_memcpy(eth->ether_shost, src, ETH_ALEN);
8864 eth->ether_type = htons(ETHERTYPE_IP);
8865 ip = (struct iphdr *) (eth + 1);
8866 os_memset(ip, 0, sizeof(*ip));
8871 ip->tot_len = htons(HWSIM_IP_LEN);
8873 ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8874 ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8875 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
8876 dpos = (u8 *) (ip + 1);
8877 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
8880 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
8881 HWSIM_PACKETLEN) < 0)
8884 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
8885 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
8891 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
8895 struct ether_header *eth;
8896 struct l2_packet_data *l2 = NULL;
8901 len = os_strlen(cmd);
8902 if (len & 1 || len < ETH_HLEN * 2)
8906 buf = os_malloc(len);
8910 if (hexstr2bin(cmd, buf, len) < 0)
8913 eth = (struct ether_header *) buf;
8914 ethertype = ntohs(eth->ether_type);
8916 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
8917 wpas_data_test_rx, wpa_s, 1);
8921 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
8922 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
8925 l2_packet_deinit(l2);
8928 return res < 0 ? -1 : 0;
8932 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
8934 #ifdef WPA_TRACE_BFD
8937 wpa_trace_fail_after = atoi(cmd);
8938 pos = os_strchr(cmd, ':');
8941 os_strlcpy(wpa_trace_fail_func, pos,
8942 sizeof(wpa_trace_fail_func));
8944 wpa_trace_fail_after = 0;
8947 #else /* WPA_TRACE_BFD */
8949 #endif /* WPA_TRACE_BFD */
8953 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
8954 char *buf, size_t buflen)
8956 #ifdef WPA_TRACE_BFD
8957 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
8958 wpa_trace_fail_func);
8959 #else /* WPA_TRACE_BFD */
8961 #endif /* WPA_TRACE_BFD */
8965 static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
8967 #ifdef WPA_TRACE_BFD
8970 wpa_trace_test_fail_after = atoi(cmd);
8971 pos = os_strchr(cmd, ':');
8974 os_strlcpy(wpa_trace_test_fail_func, pos,
8975 sizeof(wpa_trace_test_fail_func));
8977 wpa_trace_test_fail_after = 0;
8980 #else /* WPA_TRACE_BFD */
8982 #endif /* WPA_TRACE_BFD */
8986 static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
8987 char *buf, size_t buflen)
8989 #ifdef WPA_TRACE_BFD
8990 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
8991 wpa_trace_test_fail_func);
8992 #else /* WPA_TRACE_BFD */
8994 #endif /* WPA_TRACE_BFD */
8998 static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9000 struct wpa_supplicant *wpa_s = eloop_ctx;
9001 int i, count = (intptr_t) timeout_ctx;
9003 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9005 for (i = 0; i < count; i++) {
9006 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9012 static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9020 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9021 (void *) (intptr_t) count);
9025 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9031 len = os_strlen(cmd);
9039 buf = wpabuf_alloc(len);
9043 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9049 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9054 static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9056 u8 zero[WPA_TK_MAX_LEN];
9058 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9061 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9062 os_memset(zero, 0, sizeof(zero));
9064 /* First, use a zero key to avoid any possible duplicate key avoidance
9066 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9067 wpa_s->last_tk_key_idx, 1, zero, 6,
9068 zero, wpa_s->last_tk_len) < 0)
9071 /* Set the previously configured key to reset its TSC/RSC */
9072 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9073 wpa_s->last_tk_key_idx, 1, zero, 6,
9074 wpa_s->last_tk, wpa_s->last_tk_len);
9078 static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9080 const char *pos = cmd;
9081 int error, pairwise;
9084 pos = os_strchr(pos, ' ');
9087 pairwise = atoi(pos);
9088 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9093 static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9096 struct wpa_driver_associate_params params;
9099 os_memset(¶ms, 0, sizeof(params));
9100 params.bssid = wpa_s->bssid;
9101 params.ssid = wpa_s->sme.ssid;
9102 params.ssid_len = wpa_s->sme.ssid_len;
9103 params.freq.freq = wpa_s->sme.freq;
9104 if (wpa_s->last_assoc_req_wpa_ie) {
9105 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9106 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9108 params.pairwise_suite = wpa_s->pairwise_cipher;
9109 params.group_suite = wpa_s->group_cipher;
9110 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9111 params.key_mgmt_suite = wpa_s->key_mgmt;
9112 params.wpa_proto = wpa_s->wpa_proto;
9113 params.mgmt_frame_protection = wpa_s->sme.mfp;
9114 params.rrm_used = wpa_s->rrm.rrm_used;
9115 if (wpa_s->sme.prev_bssid_set)
9116 params.prev_bssid = wpa_s->sme.prev_bssid;
9117 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9118 ret = wpa_drv_associate(wpa_s, ¶ms);
9119 wpa_s->testing_resend_assoc = 1;
9121 #else /* CONFIG_SME */
9123 #endif /* CONFIG_SME */
9126 #endif /* CONFIG_TESTING_OPTIONS */
9129 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9135 struct ieee802_11_elems elems;
9138 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9140 wpa_s = wpas_vendor_elem(wpa_s, frame);
9142 pos = os_strchr(pos, ' ');
9147 len = os_strlen(pos);
9154 buf = wpabuf_alloc(len);
9158 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9163 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9169 if (wpa_s->vendor_elem[frame] == NULL) {
9170 wpa_s->vendor_elem[frame] = buf;
9171 wpas_vendor_elem_update(wpa_s);
9175 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9180 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9182 wpas_vendor_elem_update(wpa_s);
9188 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9189 char *buf, size_t buflen)
9191 int frame = atoi(cmd);
9193 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9195 wpa_s = wpas_vendor_elem(wpa_s, frame);
9197 if (wpa_s->vendor_elem[frame] == NULL)
9200 return wpa_snprintf_hex(buf, buflen,
9201 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9202 wpabuf_len(wpa_s->vendor_elem[frame]));
9206 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9212 struct ieee802_11_elems elems;
9216 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9218 wpa_s = wpas_vendor_elem(wpa_s, frame);
9220 pos = os_strchr(pos, ' ');
9226 wpabuf_free(wpa_s->vendor_elem[frame]);
9227 wpa_s->vendor_elem[frame] = NULL;
9228 wpas_vendor_elem_update(wpa_s);
9232 if (wpa_s->vendor_elem[frame] == NULL)
9235 len = os_strlen(pos);
9242 buf = os_malloc(len);
9246 if (hexstr2bin(pos, buf, len) < 0) {
9251 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9256 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
9262 static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9264 struct wpa_supplicant *wpa_s = ctx;
9269 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9271 * BSSID Information[4]
9272 * Operating Class[1]
9275 * Optional Subelements[variable]
9277 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9279 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
9280 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
9284 data = wpabuf_head_u8(neighbor_rep);
9285 len = wpabuf_len(neighbor_rep);
9287 while (len >= 2 + NR_IE_MIN_LEN) {
9289 char lci[256 * 2 + 1];
9290 char civic[256 * 2 + 1];
9291 u8 nr_len = data[1];
9292 const u8 *pos = data, *end;
9294 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9295 nr_len < NR_IE_MIN_LEN) {
9296 wpa_printf(MSG_DEBUG,
9297 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9302 if (2U + nr_len > len) {
9303 wpa_printf(MSG_DEBUG,
9304 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9305 data[0], len, nr_len);
9312 pos += NR_IE_MIN_LEN;
9316 while (end - pos > 2) {
9321 if (s_len > end - pos)
9323 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9324 /* Measurement Token[1] */
9325 /* Measurement Report Mode[1] */
9326 /* Measurement Type[1] */
9327 /* Measurement Report[variable] */
9329 case MEASURE_TYPE_LCI:
9332 wpa_snprintf_hex(lci, sizeof(lci),
9335 case MEASURE_TYPE_LOCATION_CIVIC:
9338 wpa_snprintf_hex(civic, sizeof(civic),
9347 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
9349 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9350 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
9351 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
9353 lci[0] ? " lci=" : "", lci,
9354 civic[0] ? " civic=" : "", civic);
9361 wpabuf_free(neighbor_rep);
9365 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
9368 struct wpa_ssid_value ssid, *ssid_p = NULL;
9369 int ret, lci = 0, civic = 0;
9372 ssid_s = os_strstr(cmd, "ssid=");
9374 if (ssid_parse(ssid_s + 5, &ssid)) {
9375 wpa_printf(MSG_ERROR,
9376 "CTRL: Send Neighbor Report: bad SSID");
9383 * Move cmd after the SSID text that may include "lci" or
9386 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
9392 if (cmd && os_strstr(cmd, "lci"))
9395 if (cmd && os_strstr(cmd, "civic"))
9398 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
9399 wpas_ctrl_neighbor_rep_cb,
9406 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
9408 eapol_sm_erp_flush(wpa_s->eapol);
9413 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
9416 char *token, *context = NULL;
9417 unsigned int enable = ~0, type = 0;
9418 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
9419 u8 *addr = NULL, *mask = NULL;
9421 while ((token = str_token(cmd, " ", &context))) {
9422 if (os_strcasecmp(token, "scan") == 0) {
9423 type |= MAC_ADDR_RAND_SCAN;
9424 } else if (os_strcasecmp(token, "sched") == 0) {
9425 type |= MAC_ADDR_RAND_SCHED_SCAN;
9426 } else if (os_strcasecmp(token, "pno") == 0) {
9427 type |= MAC_ADDR_RAND_PNO;
9428 } else if (os_strcasecmp(token, "all") == 0) {
9429 type = wpa_s->mac_addr_rand_supported;
9430 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
9431 enable = atoi(token + 7);
9432 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
9434 if (hwaddr_aton(token + 5, addr)) {
9435 wpa_printf(MSG_INFO,
9436 "CTRL: Invalid MAC address: %s",
9440 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
9442 if (hwaddr_aton(token + 5, mask)) {
9443 wpa_printf(MSG_INFO,
9444 "CTRL: Invalid MAC address mask: %s",
9449 wpa_printf(MSG_INFO,
9450 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9457 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
9461 if ((wpa_s->mac_addr_rand_supported & type) != type) {
9462 wpa_printf(MSG_INFO,
9463 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9464 type, wpa_s->mac_addr_rand_supported);
9469 wpa_printf(MSG_INFO,
9470 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9475 wpas_mac_addr_rand_scan_clear(wpa_s, type);
9477 if (type & MAC_ADDR_RAND_PNO) {
9478 wpas_stop_pno(wpa_s);
9479 wpas_start_pno(wpa_s);
9481 } else if (wpa_s->sched_scanning &&
9482 (type & MAC_ADDR_RAND_SCHED_SCAN)) {
9483 wpas_scan_restart_sched_scan(wpa_s);
9488 if ((addr && !mask) || (!addr && mask)) {
9489 wpa_printf(MSG_INFO,
9490 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9494 if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
9495 wpa_printf(MSG_INFO,
9496 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9500 if (type & MAC_ADDR_RAND_SCAN) {
9501 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
9505 if (type & MAC_ADDR_RAND_SCHED_SCAN) {
9506 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
9509 if (wpa_s->sched_scanning && !wpa_s->pno)
9510 wpas_scan_restart_sched_scan(wpa_s);
9513 if (type & MAC_ADDR_RAND_PNO) {
9514 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
9517 wpas_stop_pno(wpa_s);
9518 wpas_start_pno(wpa_s);
9526 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
9527 char *buf, size_t buflen)
9531 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
9533 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
9534 buflen - reply_len);
9535 #endif /* CONFIG_AP */
9540 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
9542 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
9544 wpas_ap_pmksa_cache_flush(wpa_s);
9545 #endif /* CONFIG_AP */
9549 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9551 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
9552 const char *cmd, char *buf, size_t buflen)
9554 struct rsn_pmksa_cache_entry *entry;
9555 struct wpa_ssid *ssid;
9556 char *pos, *pos2, *end;
9558 struct os_reltime now;
9560 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9567 os_get_reltime(&now);
9571 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9572 * <expiration in seconds> <akmp> <opportunistic>
9573 * [FILS Cache Identifier]
9576 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
9577 entry = entry->next) {
9578 if (entry->network_ctx != ssid)
9582 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
9583 MAC2STR(entry->aa));
9584 if (os_snprintf_error(end - pos2, ret))
9588 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
9591 ret = os_snprintf(pos2, end - pos2, " ");
9592 if (os_snprintf_error(end - pos2, ret))
9596 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
9599 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
9600 (int) (entry->reauth_time - now.sec),
9601 (int) (entry->expiration - now.sec),
9603 entry->opportunistic);
9604 if (os_snprintf_error(end - pos2, ret))
9608 if (entry->fils_cache_id_set) {
9609 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
9610 entry->fils_cache_id[0],
9611 entry->fils_cache_id[1]);
9612 if (os_snprintf_error(end - pos2, ret))
9617 ret = os_snprintf(pos2, end - pos2, "\n");
9618 if (os_snprintf_error(end - pos2, ret))
9629 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
9632 struct rsn_pmksa_cache_entry *entry;
9633 struct wpa_ssid *ssid;
9636 struct os_reltime now;
9637 int reauth_time = 0, expiration = 0, i;
9641 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9642 * <expiration in seconds> <akmp> <opportunistic>
9643 * [FILS Cache Identifier]
9646 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9650 pos = os_strchr(cmd, ' ');
9655 entry = os_zalloc(sizeof(*entry));
9659 if (hwaddr_aton(pos, entry->aa))
9662 pos = os_strchr(pos, ' ');
9667 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
9670 pos = os_strchr(pos, ' ');
9675 pos2 = os_strchr(pos, ' ');
9678 entry->pmk_len = (pos2 - pos) / 2;
9679 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
9680 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
9683 pos = os_strchr(pos, ' ');
9688 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
9689 &entry->akmp, &entry->opportunistic) != 4)
9691 for (i = 0; i < 4; i++) {
9692 pos = os_strchr(pos, ' ');
9701 if (hexstr2bin(pos, entry->fils_cache_id,
9702 FILS_CACHE_ID_LEN) < 0)
9704 entry->fils_cache_id_set = 1;
9706 os_get_reltime(&now);
9707 entry->expiration = now.sec + expiration;
9708 entry->reauth_time = now.sec + reauth_time;
9710 entry->network_ctx = ssid;
9712 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
9723 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
9724 const char *cmd, char *buf,
9732 if (os_strcasecmp(cmd, "any") == 0)
9733 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
9735 if (hwaddr_aton(cmd, spa))
9738 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
9742 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
9746 * We do not check mesh interface existance because PMKSA should be
9747 * stored before wpa_s->ifmsh creation to suppress commit message
9750 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
9753 #endif /* CONFIG_MESH */
9754 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9758 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
9761 struct fils_hlp_req *req;
9764 /* format: <dst> <packet starting from ethertype> */
9766 req = os_zalloc(sizeof(*req));
9770 if (hwaddr_aton(cmd, req->dst))
9773 pos = os_strchr(cmd, ' ');
9777 req->pkt = wpabuf_parse_bin(pos);
9781 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
9784 wpabuf_free(req->pkt);
9788 #endif /* CONFIG_FILS */
9791 static int wpas_ctrl_cmd_debug_level(const char *cmd)
9793 if (os_strcmp(cmd, "PING") == 0 ||
9794 os_strncmp(cmd, "BSS ", 4) == 0 ||
9795 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
9796 os_strncmp(cmd, "STATUS", 6) == 0 ||
9797 os_strncmp(cmd, "STA ", 4) == 0 ||
9798 os_strncmp(cmd, "STA-", 4) == 0)
9799 return MSG_EXCESSIVE;
9804 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
9805 char *buf, size_t *resp_len)
9808 const int reply_size = 4096;
9811 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
9812 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
9813 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
9814 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
9815 if (wpa_debug_show_keys)
9816 wpa_dbg(wpa_s, MSG_DEBUG,
9817 "Control interface command '%s'", buf);
9819 wpa_dbg(wpa_s, MSG_DEBUG,
9820 "Control interface command '%s [REMOVED]'",
9821 os_strncmp(buf, WPA_CTRL_RSP,
9822 os_strlen(WPA_CTRL_RSP)) == 0 ?
9824 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
9825 "SET_NETWORK" : "key-add"));
9826 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
9827 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
9828 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
9829 (const u8 *) buf, os_strlen(buf));
9831 int level = wpas_ctrl_cmd_debug_level(buf);
9832 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
9835 reply = os_malloc(reply_size);
9836 if (reply == NULL) {
9841 os_memcpy(reply, "OK\n", 3);
9844 if (os_strcmp(buf, "PING") == 0) {
9845 os_memcpy(reply, "PONG\n", 5);
9847 } else if (os_strcmp(buf, "IFNAME") == 0) {
9848 reply_len = os_strlen(wpa_s->ifname);
9849 os_memcpy(reply, wpa_s->ifname, reply_len);
9850 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
9851 if (wpa_debug_reopen_file() < 0)
9853 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
9854 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
9855 } else if (os_strcmp(buf, "MIB") == 0) {
9856 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
9857 if (reply_len >= 0) {
9858 reply_len += eapol_sm_get_mib(wpa_s->eapol,
9860 reply_size - reply_len);
9862 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
9863 reply_len = wpa_supplicant_ctrl_iface_status(
9864 wpa_s, buf + 6, reply, reply_size);
9865 } else if (os_strcmp(buf, "PMKSA") == 0) {
9866 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
9867 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
9868 wpas_ctrl_iface_pmksa_flush(wpa_s);
9869 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9870 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
9871 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
9873 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
9874 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
9877 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
9878 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
9880 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
9881 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
9883 #endif /* CONFIG_MESH */
9884 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9885 } else if (os_strncmp(buf, "SET ", 4) == 0) {
9886 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
9888 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
9889 reply_len = wpa_config_dump_values(wpa_s->conf,
9891 } else if (os_strncmp(buf, "GET ", 4) == 0) {
9892 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
9894 } else if (os_strcmp(buf, "LOGON") == 0) {
9895 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
9896 } else if (os_strcmp(buf, "LOGOFF") == 0) {
9897 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
9898 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
9899 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9902 wpas_request_connection(wpa_s);
9903 } else if (os_strcmp(buf, "REATTACH") == 0) {
9904 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
9905 !wpa_s->current_ssid)
9908 wpa_s->reattach = 1;
9909 wpas_request_connection(wpa_s);
9911 } else if (os_strcmp(buf, "RECONNECT") == 0) {
9912 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9914 else if (wpa_s->disconnected)
9915 wpas_request_connection(wpa_s);
9916 #ifdef IEEE8021X_EAPOL
9917 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
9918 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
9920 #endif /* IEEE8021X_EAPOL */
9921 #ifdef CONFIG_IEEE80211R
9922 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
9923 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
9925 #endif /* CONFIG_IEEE80211R */
9927 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
9928 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
9930 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9934 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
9935 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
9937 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
9941 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
9942 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
9945 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
9946 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
9947 wpa_s, buf + 14, reply, reply_size);
9948 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
9949 if (wpas_wps_cancel(wpa_s))
9951 #ifdef CONFIG_WPS_NFC
9952 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
9953 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
9955 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
9956 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
9958 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9959 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9960 wpa_s, buf + 21, reply, reply_size);
9961 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
9962 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
9963 wpa_s, buf + 14, reply, reply_size);
9964 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
9965 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
9968 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9969 reply_len = wpas_ctrl_nfc_get_handover_req(
9970 wpa_s, buf + 21, reply, reply_size);
9971 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9972 reply_len = wpas_ctrl_nfc_get_handover_sel(
9973 wpa_s, buf + 21, reply, reply_size);
9974 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
9975 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
9977 #endif /* CONFIG_WPS_NFC */
9978 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
9979 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
9982 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
9983 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
9984 wpa_s, buf + 11, reply, reply_size);
9985 #endif /* CONFIG_AP */
9986 #ifdef CONFIG_WPS_ER
9987 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
9988 if (wpas_wps_er_start(wpa_s, NULL))
9990 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
9991 if (wpas_wps_er_start(wpa_s, buf + 13))
9993 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
9994 wpas_wps_er_stop(wpa_s);
9995 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
9996 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
9998 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
9999 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
10001 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10003 } else if (ret == -3) {
10004 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
10006 } else if (ret == -4) {
10007 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
10011 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
10012 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
10014 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
10015 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
10018 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
10019 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
10021 #ifdef CONFIG_WPS_NFC
10022 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10023 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10024 wpa_s, buf + 24, reply, reply_size);
10025 #endif /* CONFIG_WPS_NFC */
10026 #endif /* CONFIG_WPS_ER */
10027 #endif /* CONFIG_WPS */
10028 #ifdef CONFIG_IBSS_RSN
10029 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10030 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10032 #endif /* CONFIG_IBSS_RSN */
10034 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10035 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10036 wpa_s, buf + 19, reply, reply_size);
10037 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10038 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10039 wpa_s, "", reply, reply_size);
10040 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10041 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10043 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10044 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10047 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10048 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10050 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10051 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10053 #endif /* CONFIG_MESH */
10055 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
10056 if (p2p_ctrl_find(wpa_s, buf + 8))
10058 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10059 if (p2p_ctrl_find(wpa_s, ""))
10061 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10062 wpas_p2p_stop_find(wpa_s);
10063 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10064 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10066 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10067 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10069 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10070 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10072 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10073 if (p2p_ctrl_listen(wpa_s, buf + 11))
10075 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10076 if (p2p_ctrl_listen(wpa_s, ""))
10078 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10079 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10081 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
10082 if (p2p_ctrl_group_add(wpa_s, ""))
10084 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10085 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10087 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10088 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10090 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10091 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10093 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10094 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10095 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10096 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10098 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10099 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10101 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10102 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10104 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10105 wpas_p2p_sd_service_update(wpa_s);
10106 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10107 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10109 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10110 wpas_p2p_service_flush(wpa_s);
10111 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10112 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10114 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10115 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10117 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10118 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10120 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10121 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10123 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10124 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10126 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10127 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10129 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10130 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10132 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
10133 p2p_ctrl_flush(wpa_s);
10134 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10135 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10137 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10138 if (wpas_p2p_cancel(wpa_s))
10140 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10141 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10143 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10144 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10146 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10147 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10149 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10150 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10152 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10153 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10155 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10156 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10158 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10159 if (wpas_p2p_lo_stop(wpa_s))
10161 #endif /* CONFIG_P2P */
10162 #ifdef CONFIG_WIFI_DISPLAY
10163 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10164 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10166 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10167 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10168 reply, reply_size);
10169 #endif /* CONFIG_WIFI_DISPLAY */
10170 #ifdef CONFIG_INTERWORKING
10171 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10172 if (interworking_fetch_anqp(wpa_s) < 0)
10174 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10175 interworking_stop_fetch_anqp(wpa_s);
10176 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10177 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10179 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10180 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
10182 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
10183 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
10185 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10188 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10192 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10193 if (os_snprintf_error(reply_size, reply_len))
10196 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10197 if (get_anqp(wpa_s, buf + 9) < 0)
10199 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10200 if (gas_request(wpa_s, buf + 12) < 0)
10202 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10203 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10205 #endif /* CONFIG_INTERWORKING */
10207 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10208 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10210 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10211 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10213 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
10214 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10216 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10217 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10219 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10220 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10221 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10222 if (del_hs20_icon(wpa_s, buf + 14) < 0)
10224 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
10225 if (hs20_fetch_osu(wpa_s, 0) < 0)
10227 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10228 if (hs20_fetch_osu(wpa_s, 1) < 0)
10230 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10231 hs20_cancel_fetch_osu(wpa_s);
10232 #endif /* CONFIG_HS20 */
10233 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10235 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10236 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10240 * Notify response from timeout to allow the control
10241 * interface response to be sent first.
10243 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
10246 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
10247 if (wpa_supplicant_reload_configuration(wpa_s))
10249 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10250 wpa_supplicant_terminate_proc(wpa_s->global);
10251 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
10252 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
10254 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
10255 reply_len = wpa_supplicant_ctrl_iface_blacklist(
10256 wpa_s, buf + 9, reply, reply_size);
10257 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
10258 reply_len = wpa_supplicant_ctrl_iface_log_level(
10259 wpa_s, buf + 9, reply, reply_size);
10260 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
10261 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10262 wpa_s, buf + 14, reply, reply_size);
10263 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
10264 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10265 wpa_s, NULL, reply, reply_size);
10266 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
10267 wpas_request_disconnection(wpa_s);
10268 } else if (os_strcmp(buf, "SCAN") == 0) {
10269 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
10270 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
10271 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
10272 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
10273 reply_len = wpa_supplicant_ctrl_iface_scan_results(
10274 wpa_s, reply, reply_size);
10275 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
10276 if (wpas_abort_ongoing_scan(wpa_s) < 0)
10278 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
10279 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
10281 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
10282 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
10284 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
10285 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
10287 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
10288 reply_len = wpa_supplicant_ctrl_iface_add_network(
10289 wpa_s, reply, reply_size);
10290 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
10291 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
10293 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
10294 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
10296 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
10297 reply_len = wpa_supplicant_ctrl_iface_get_network(
10298 wpa_s, buf + 12, reply, reply_size);
10299 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
10300 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
10303 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
10304 reply_len = wpa_supplicant_ctrl_iface_list_creds(
10305 wpa_s, reply, reply_size);
10306 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
10307 reply_len = wpa_supplicant_ctrl_iface_add_cred(
10308 wpa_s, reply, reply_size);
10309 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
10310 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
10312 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
10313 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
10315 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
10316 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
10319 #ifndef CONFIG_NO_CONFIG_WRITE
10320 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10321 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
10323 #endif /* CONFIG_NO_CONFIG_WRITE */
10324 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
10325 reply_len = wpa_supplicant_ctrl_iface_get_capability(
10326 wpa_s, buf + 15, reply, reply_size);
10327 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
10328 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
10330 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
10331 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
10333 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10334 reply_len = wpa_supplicant_global_iface_list(
10335 wpa_s->global, reply, reply_size);
10336 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
10337 reply_len = wpa_supplicant_global_iface_interfaces(
10338 wpa_s->global, buf + 10, reply, reply_size);
10339 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
10340 reply_len = wpa_supplicant_ctrl_iface_bss(
10341 wpa_s, buf + 4, reply, reply_size);
10343 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
10344 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
10345 } else if (os_strncmp(buf, "STA ", 4) == 0) {
10346 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
10348 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
10349 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
10351 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
10352 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
10354 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
10355 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
10357 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
10358 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
10360 } else if (os_strcmp(buf, "STOP_AP") == 0) {
10361 if (wpas_ap_stop_ap(wpa_s))
10363 #endif /* CONFIG_AP */
10364 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10365 wpas_notify_suspend(wpa_s->global);
10366 } else if (os_strcmp(buf, "RESUME") == 0) {
10367 wpas_notify_resume(wpa_s->global);
10368 #ifdef CONFIG_TESTING_OPTIONS
10369 } else if (os_strcmp(buf, "DROP_SA") == 0) {
10370 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
10371 #endif /* CONFIG_TESTING_OPTIONS */
10372 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
10373 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
10375 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
10376 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
10377 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
10378 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
10380 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
10381 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
10384 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
10385 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
10387 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
10388 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
10390 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
10391 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
10393 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
10394 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
10396 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
10397 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
10400 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10401 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
10404 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
10405 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
10406 wpa_s, buf + 17, reply, reply_size);
10407 #endif /* CONFIG_TDLS */
10408 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
10409 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
10410 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
10411 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
10413 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
10414 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
10416 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
10417 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
10419 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
10420 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
10422 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
10423 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
10425 #ifdef CONFIG_AUTOSCAN
10426 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
10427 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
10429 #endif /* CONFIG_AUTOSCAN */
10430 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
10431 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
10434 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
10435 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
10437 #endif /* ANDROID */
10438 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
10439 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
10441 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
10442 pmksa_cache_clear_current(wpa_s->wpa);
10443 eapol_sm_request_reauth(wpa_s->eapol);
10445 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
10446 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
10448 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
10449 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
10451 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
10452 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
10454 #endif /* CONFIG_WNM */
10455 } else if (os_strcmp(buf, "FLUSH") == 0) {
10456 wpa_supplicant_ctrl_iface_flush(wpa_s);
10457 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
10458 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
10460 #ifdef CONFIG_TESTING_OPTIONS
10461 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
10462 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
10464 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
10465 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
10466 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
10467 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
10469 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
10470 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
10472 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
10473 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
10475 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
10476 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
10478 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
10479 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
10481 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
10482 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
10484 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
10485 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
10487 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
10488 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
10489 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
10490 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
10492 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
10493 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
10494 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
10495 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
10497 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
10498 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
10500 } else if (os_strcmp(buf, "RESET_PN") == 0) {
10501 if (wpas_ctrl_reset_pn(wpa_s) < 0)
10503 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
10504 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
10506 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
10507 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
10509 #endif /* CONFIG_TESTING_OPTIONS */
10510 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
10511 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
10513 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
10514 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
10516 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10517 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
10519 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10520 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
10522 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
10523 wpas_ctrl_iface_erp_flush(wpa_s);
10524 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
10525 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
10527 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
10528 reply_len = wpas_ctrl_iface_get_pref_freq_list(
10529 wpa_s, buf + 19, reply, reply_size);
10531 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
10532 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
10534 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
10535 wpas_flush_fils_hlp_req(wpa_s);
10536 #endif /* CONFIG_FILS */
10538 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
10541 res = wpas_dpp_qr_code(wpa_s, buf + 12);
10545 reply_len = os_snprintf(reply, reply_size, "%d", res);
10546 if (os_snprintf_error(reply_size, reply_len))
10549 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10552 res = wpas_dpp_bootstrap_gen(wpa_s, buf + 18);
10556 reply_len = os_snprintf(reply, reply_size, "%d", res);
10557 if (os_snprintf_error(reply_size, reply_len))
10560 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10561 if (wpas_dpp_bootstrap_remove(wpa_s, buf + 21) < 0)
10563 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10566 uri = wpas_dpp_bootstrap_get_uri(wpa_s, atoi(buf + 22));
10570 reply_len = os_snprintf(reply, reply_size, "%s", uri);
10571 if (os_snprintf_error(reply_size, reply_len))
10574 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10575 reply_len = wpas_dpp_bootstrap_info(wpa_s, atoi(buf + 19),
10576 reply, reply_size);
10577 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
10578 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
10580 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
10581 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
10583 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
10584 wpas_dpp_stop(wpa_s);
10585 wpas_dpp_listen_stop(wpa_s);
10586 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10589 res = wpas_dpp_configurator_add(wpa_s, buf + 20);
10593 reply_len = os_snprintf(reply, reply_size, "%d", res);
10594 if (os_snprintf_error(reply_size, reply_len))
10597 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10598 if (wpas_dpp_configurator_remove(wpa_s, buf + 24) < 0)
10600 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10601 if (wpas_dpp_configurator_sign(wpa_s, buf + 22) < 0)
10603 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10604 reply_len = wpas_dpp_configurator_get_key(wpa_s, atoi(buf + 25),
10605 reply, reply_size);
10606 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
10609 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
10613 reply_len = os_snprintf(reply, reply_size, "%d", res);
10614 if (os_snprintf_error(reply_size, reply_len))
10617 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
10618 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
10620 #endif /* CONFIG_DPP */
10622 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
10626 if (reply_len < 0) {
10627 os_memcpy(reply, "FAIL\n", 5);
10631 *resp_len = reply_len;
10636 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
10639 struct wpa_interface iface;
10641 struct wpa_supplicant *wpa_s;
10642 unsigned int create_iface = 0;
10643 u8 mac_addr[ETH_ALEN];
10644 enum wpa_driver_if_type type = WPA_IF_STATION;
10647 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10648 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10650 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
10652 os_memset(&iface, 0, sizeof(iface));
10655 iface.ifname = pos = cmd;
10656 pos = os_strchr(pos, '\t');
10659 if (iface.ifname[0] == '\0')
10664 iface.confname = pos;
10665 pos = os_strchr(pos, '\t');
10668 if (iface.confname[0] == '\0')
10669 iface.confname = NULL;
10673 iface.driver = pos;
10674 pos = os_strchr(pos, '\t');
10677 if (iface.driver[0] == '\0')
10678 iface.driver = NULL;
10682 iface.ctrl_interface = pos;
10683 pos = os_strchr(pos, '\t');
10686 if (iface.ctrl_interface[0] == '\0')
10687 iface.ctrl_interface = NULL;
10691 iface.driver_param = pos;
10692 pos = os_strchr(pos, '\t');
10695 if (iface.driver_param[0] == '\0')
10696 iface.driver_param = NULL;
10700 iface.bridge_ifname = pos;
10701 pos = os_strchr(pos, '\t');
10704 if (iface.bridge_ifname[0] == '\0')
10705 iface.bridge_ifname = NULL;
10710 pos = os_strchr(pos, '\t');
10716 if (os_strcmp(extra, "create") == 0) {
10721 if (os_strcmp(pos, "sta") == 0) {
10722 type = WPA_IF_STATION;
10723 } else if (os_strcmp(pos, "ap") == 0) {
10724 type = WPA_IF_AP_BSS;
10726 wpa_printf(MSG_DEBUG,
10727 "INTERFACE_ADD unsupported interface type: '%s'",
10732 wpa_printf(MSG_DEBUG,
10733 "INTERFACE_ADD unsupported extra parameter: '%s'",
10739 if (create_iface) {
10740 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
10742 if (!global->ifaces)
10744 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
10745 NULL, NULL, NULL, mac_addr, NULL) < 0) {
10746 wpa_printf(MSG_ERROR,
10747 "CTRL_IFACE interface creation failed");
10751 wpa_printf(MSG_DEBUG,
10752 "CTRL_IFACE interface '%s' created with MAC addr: "
10753 MACSTR, iface.ifname, MAC2STR(mac_addr));
10756 if (wpa_supplicant_get_iface(global, iface.ifname))
10759 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
10762 wpa_s->added_vif = create_iface;
10767 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
10772 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
10775 struct wpa_supplicant *wpa_s;
10777 unsigned int delete_iface;
10779 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
10781 wpa_s = wpa_supplicant_get_iface(global, cmd);
10784 delete_iface = wpa_s->added_vif;
10785 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
10786 if (!ret && delete_iface) {
10787 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
10789 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
10795 static void wpa_free_iface_info(struct wpa_interface_info *iface)
10797 struct wpa_interface_info *prev;
10801 iface = iface->next;
10803 os_free(prev->ifname);
10804 os_free(prev->desc);
10810 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
10811 char *buf, int len)
10814 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
10817 for (i = 0; wpa_drivers[i]; i++) {
10818 const struct wpa_driver_ops *drv = wpa_drivers[i];
10819 if (drv->get_interfaces == NULL)
10821 tmp = drv->get_interfaces(global->drv_priv[i]);
10826 iface = last = tmp;
10835 for (tmp = iface; tmp; tmp = tmp->next) {
10836 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
10837 tmp->drv_name, tmp->ifname,
10838 tmp->desc ? tmp->desc : "");
10839 if (os_snprintf_error(end - pos, res)) {
10846 wpa_free_iface_info(iface);
10852 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
10854 char *buf, int len)
10858 struct wpa_supplicant *wpa_s;
10862 show_ctrl = !!os_strstr(input, "ctrl");
10864 wpa_s = global->ifaces;
10870 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
10872 wpa_s->conf->ctrl_interface ?
10873 wpa_s->conf->ctrl_interface : "N/A");
10875 res = os_snprintf(pos, end - pos, "%s\n",
10878 if (os_snprintf_error(end - pos, res)) {
10883 wpa_s = wpa_s->next;
10889 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
10890 const char *ifname,
10891 char *cmd, size_t *resp_len)
10893 struct wpa_supplicant *wpa_s;
10895 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
10896 if (os_strcmp(ifname, wpa_s->ifname) == 0)
10900 if (wpa_s == NULL) {
10901 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
10903 *resp_len = os_strlen(resp);
10909 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
10913 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
10914 char *buf, size_t *resp_len)
10917 static const char * cmd[] = {
10923 "P2P_GET_PASSPHRASE",
10924 "P2P_SERVICE_UPDATE",
10925 "P2P_SERVICE_FLUSH",
10928 "P2P_PRESENCE_REQ",
10932 #endif /* CONFIG_AP */
10935 static const char * prefix[] = {
10938 #endif /* ANDROID */
10945 "P2P_GROUP_REMOVE ",
10947 "P2P_GROUP_MEMBER ",
10949 "P2P_SERV_DISC_REQ ",
10950 "P2P_SERV_DISC_CANCEL_REQ ",
10951 "P2P_SERV_DISC_RESP ",
10952 "P2P_SERV_DISC_EXTERNAL ",
10953 "P2P_SERVICE_ADD ",
10954 "P2P_SERVICE_DEL ",
10955 "P2P_SERVICE_REP ",
10960 "P2P_UNAUTHORIZE ",
10961 "P2P_PRESENCE_REQ ",
10963 "P2P_REMOVE_CLIENT ",
10965 "WPS_NFC_TAG_READ ",
10966 "NFC_GET_HANDOVER_SEL ",
10967 "NFC_GET_HANDOVER_REQ ",
10968 "NFC_REPORT_HANDOVER ",
10969 "P2P_ASP_PROVISION ",
10970 "P2P_ASP_PROVISION_RESP ",
10974 #endif /* CONFIG_AP */
10980 if (global->p2p_init_wpa_s == NULL)
10983 for (i = 0; !found && cmd[i]; i++) {
10984 if (os_strcmp(buf, cmd[i]) == 0)
10988 for (i = 0; !found && prefix[i]; i++) {
10989 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
10994 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
10996 #endif /* CONFIG_P2P */
11001 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
11002 char *buf, size_t *resp_len)
11004 #ifdef CONFIG_WIFI_DISPLAY
11005 if (global->p2p_init_wpa_s == NULL)
11007 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
11008 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
11009 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11011 #endif /* CONFIG_WIFI_DISPLAY */
11016 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
11017 char *buf, size_t *resp_len)
11021 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
11025 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
11033 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11037 value = os_strchr(cmd, ' ');
11042 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11044 #ifdef CONFIG_WIFI_DISPLAY
11045 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11046 wifi_display_enable(global, !!atoi(value));
11049 #endif /* CONFIG_WIFI_DISPLAY */
11051 /* Restore cmd to its original value to allow redirection */
11058 static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11061 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11065 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11066 * <variable name> */
11068 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11069 p = os_strchr(cmd, ' ');
11074 wpa_s[i] = global->ifaces;
11075 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11076 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11081 wpa_printf(MSG_DEBUG,
11082 "CTRL_IFACE: Could not find iface=%s", cmd);
11089 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11093 #ifndef CONFIG_NO_CONFIG_WRITE
11094 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11096 int ret = 0, saved = 0;
11097 struct wpa_supplicant *wpa_s;
11099 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11100 if (!wpa_s->conf->update_config) {
11101 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11105 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11106 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11109 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11114 if (!saved && !ret) {
11115 wpa_dbg(wpa_s, MSG_DEBUG,
11116 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11122 #endif /* CONFIG_NO_CONFIG_WRITE */
11125 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11126 char *buf, size_t buflen)
11130 struct wpa_supplicant *wpa_s;
11133 end = buf + buflen;
11136 if (global->p2p && !global->p2p_disabled) {
11137 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11140 MAC2STR(global->p2p_dev_addr),
11141 p2p_get_state_txt(global->p2p));
11142 if (os_snprintf_error(end - pos, ret))
11145 } else if (global->p2p) {
11146 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
11147 if (os_snprintf_error(end - pos, ret))
11151 #endif /* CONFIG_P2P */
11153 #ifdef CONFIG_WIFI_DISPLAY
11154 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11155 !!global->wifi_display);
11156 if (os_snprintf_error(end - pos, ret))
11159 #endif /* CONFIG_WIFI_DISPLAY */
11161 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11162 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
11163 "address=" MACSTR "\n",
11164 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
11165 if (os_snprintf_error(end - pos, ret))
11176 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
11177 char *cmd, char *buf,
11180 char ifname[IFNAMSIZ + 1];
11181 struct fst_iface_cfg cfg;
11182 struct wpa_supplicant *wpa_s;
11183 struct fst_wpa_obj iface_obj;
11185 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
11186 wpa_s = wpa_supplicant_get_iface(global, ifname);
11189 wpa_printf(MSG_INFO, "FST: Already attached");
11192 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
11193 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
11196 return os_snprintf(buf, reply_size, "OK\n");
11204 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
11205 char *cmd, char *buf,
11208 char ifname[IFNAMSIZ + 1];
11209 struct wpa_supplicant *wpa_s;
11211 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
11212 wpa_s = wpa_supplicant_get_iface(global, ifname);
11214 if (!fst_iface_detach(ifname)) {
11216 return os_snprintf(buf, reply_size, "OK\n");
11224 #endif /* CONFIG_FST */
11227 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
11228 char *buf, size_t *resp_len)
11231 const int reply_size = 2048;
11233 int level = MSG_DEBUG;
11235 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
11236 char *pos = os_strchr(buf + 7, ' ');
11239 return wpas_global_ctrl_iface_ifname(global,
11245 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
11249 if (os_strcmp(buf, "PING") == 0)
11250 level = MSG_EXCESSIVE;
11251 wpa_hexdump_ascii(level, "RX global ctrl_iface",
11252 (const u8 *) buf, os_strlen(buf));
11254 reply = os_malloc(reply_size);
11255 if (reply == NULL) {
11260 os_memcpy(reply, "OK\n", 3);
11263 if (os_strcmp(buf, "PING") == 0) {
11264 os_memcpy(reply, "PONG\n", 5);
11266 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
11267 if (wpa_supplicant_global_iface_add(global, buf + 14))
11269 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
11270 if (wpa_supplicant_global_iface_remove(global, buf + 17))
11272 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11273 reply_len = wpa_supplicant_global_iface_list(
11274 global, reply, reply_size);
11275 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
11276 reply_len = wpa_supplicant_global_iface_interfaces(
11277 global, buf + 10, reply, reply_size);
11279 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
11280 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
11283 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
11284 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
11287 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
11288 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
11289 #endif /* CONFIG_FST */
11290 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11291 wpa_supplicant_terminate_proc(global);
11292 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11293 wpas_notify_suspend(global);
11294 } else if (os_strcmp(buf, "RESUME") == 0) {
11295 wpas_notify_resume(global);
11296 } else if (os_strncmp(buf, "SET ", 4) == 0) {
11297 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
11299 if (global->p2p_init_wpa_s) {
11301 /* Check if P2P redirection would work for this
11303 return wpa_supplicant_ctrl_iface_process(
11304 global->p2p_init_wpa_s,
11307 #endif /* CONFIG_P2P */
11310 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
11311 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
11313 #ifndef CONFIG_NO_CONFIG_WRITE
11314 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11315 if (wpas_global_ctrl_iface_save_config(global))
11317 #endif /* CONFIG_NO_CONFIG_WRITE */
11318 } else if (os_strcmp(buf, "STATUS") == 0) {
11319 reply_len = wpas_global_ctrl_iface_status(global, reply,
11321 #ifdef CONFIG_MODULE_TESTS
11322 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
11323 if (wpas_module_tests() < 0)
11325 #endif /* CONFIG_MODULE_TESTS */
11326 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11327 if (wpa_debug_reopen_file() < 0)
11330 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11334 if (reply_len < 0) {
11335 os_memcpy(reply, "FAIL\n", 5);
11339 *resp_len = reply_len;