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"
23 #include "crypto/tls.h"
24 #include "ap/hostapd.h"
25 #include "eap_peer/eap.h"
26 #include "eapol_supp/eapol_supp_sm.h"
27 #include "rsn_supp/wpa.h"
28 #include "rsn_supp/preauth.h"
29 #include "rsn_supp/pmksa_cache.h"
30 #include "l2_packet/l2_packet.h"
33 #include "fst/fst_ctrl_iface.h"
35 #include "wpa_supplicant_i.h"
37 #include "wps_supplicant.h"
40 #include "p2p_supplicant.h"
42 #include "hs20_supplicant.h"
43 #include "wifi_display.h"
47 #include "ctrl_iface.h"
48 #include "interworking.h"
49 #include "blacklist.h"
52 #include "offchannel.h"
53 #include "drivers/driver.h"
55 #include "dpp_supplicant.h"
57 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
59 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
62 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
68 static int wpa_is_fils_supported(struct wpa_supplicant
*wpa_s
)
70 return (((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
71 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
)) ||
72 (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
73 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD
)));
77 #ifdef CONFIG_FILS_SK_PFS
78 static int wpa_is_fils_sk_pfs_supported(struct wpa_supplicant
*wpa_s
)
80 return (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) &&
81 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
);
83 #endif /* CONFIG_FILS_SK_PFS */
85 #endif /* CONFIG_FILS */
88 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
91 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
98 if (hwaddr_aton(pos
, addr
)) {
102 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
108 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
111 pos
= os_strchr(pos
, ' ');
116 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
117 os_free(wpa_s
->bssid_filter
);
118 wpa_s
->bssid_filter
= filter
;
119 wpa_s
->bssid_filter_count
= count
;
125 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
128 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
129 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
130 size_t count
= 0, ssid_count
= 0;
134 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
135 * SSID_SPEC ::= ssid <SSID_HEX>
136 * BSSID_SPEC ::= bssid <BSSID_HEX>
143 if (os_strncmp(pos
, "bssid ", 6) == 0) {
146 res
= hwaddr_aton2(pos
, addr
);
150 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
151 "BSSID value '%s'", pos
);
155 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
162 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
164 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
170 if (*end
== '\0' || *end
== ' ')
175 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
176 sizeof(struct wpa_ssid_value
));
184 if ((end
- pos
) & 0x01 ||
185 end
- pos
> 2 * SSID_MAX_LEN
||
186 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
187 (end
- pos
) / 2) < 0) {
190 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
191 "SSID value '%s'", pos
);
194 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
195 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
196 ssid
[ssid_count
].ssid
,
197 ssid
[ssid_count
].ssid_len
);
201 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
208 pos
= os_strchr(pos
, ' ');
213 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
214 os_free(wpa_s
->disallow_aps_bssid
);
215 wpa_s
->disallow_aps_bssid
= bssid
;
216 wpa_s
->disallow_aps_bssid_count
= count
;
218 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
219 os_free(wpa_s
->disallow_aps_ssid
);
220 wpa_s
->disallow_aps_ssid
= ssid
;
221 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
223 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
226 c
= wpa_s
->current_ssid
;
227 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
230 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
231 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
234 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
235 "because current AP was marked disallowed");
238 wpa_s
->sme
.prev_bssid_set
= 0;
239 #endif /* CONFIG_SME */
240 wpa_s
->reassociate
= 1;
241 wpa_s
->own_disconnect_req
= 1;
242 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
243 wpa_supplicant_req_scan(wpa_s
, 0, 0);
249 #ifndef CONFIG_NO_CONFIG_BLOBS
250 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
253 struct wpa_config_blob
*blob
;
256 pos
= os_strchr(pos
, ' ');
260 len
= os_strlen(pos
);
264 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
265 blob
= os_zalloc(sizeof(*blob
));
268 blob
->name
= os_strdup(name
);
269 blob
->data
= os_malloc(len
/ 2);
270 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
271 wpa_config_free_blob(blob
);
275 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
276 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
277 wpa_config_free_blob(blob
);
282 wpa_config_set_blob(wpa_s
->conf
, blob
);
286 #endif /* CONFIG_NO_CONFIG_BLOBS */
289 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
297 params
= os_strchr(cmd
, ' ');
298 os_free(wpa_s
->manual_sched_scan_freqs
);
301 pos
= os_strstr(params
, "freq=");
303 freqs
= freq_range_to_channel_list(wpa_s
,
306 wpa_s
->manual_sched_scan_freqs
= freqs
;
307 ret
= wpas_start_pno(wpa_s
);
309 ret
= wpas_stop_pno(wpa_s
);
315 static int wpas_ctrl_set_band(struct wpa_supplicant
*wpa_s
, char *band
)
317 union wpa_event_data event
;
319 if (os_strcmp(band
, "AUTO") == 0)
320 wpa_s
->setband
= WPA_SETBAND_AUTO
;
321 else if (os_strcmp(band
, "5G") == 0)
322 wpa_s
->setband
= WPA_SETBAND_5G
;
323 else if (os_strcmp(band
, "2G") == 0)
324 wpa_s
->setband
= WPA_SETBAND_2G
;
328 if (wpa_drv_setband(wpa_s
, wpa_s
->setband
) == 0) {
329 os_memset(&event
, 0, sizeof(event
));
330 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
331 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
332 wpa_supplicant_event(wpa_s
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
339 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant
*wpa_s
,
344 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
345 wpabuf_free(wpa_s
->lci
);
350 lci
= wpabuf_parse_bin(cmd
);
354 if (os_get_reltime(&wpa_s
->lci_time
)) {
359 wpabuf_free(wpa_s
->lci
);
367 wpas_ctrl_set_relative_rssi(struct wpa_supplicant
*wpa_s
, const char *cmd
)
371 if (os_strcmp(cmd
, "disable") == 0) {
372 wpa_s
->srp
.relative_rssi_set
= 0;
376 relative_rssi
= atoi(cmd
);
377 if (relative_rssi
< 0 || relative_rssi
> 100)
379 wpa_s
->srp
.relative_rssi
= relative_rssi
;
380 wpa_s
->srp
.relative_rssi_set
= 1;
385 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant
*wpa_s
,
391 /* <band>:adjust_value */
392 pos
= os_strchr(cmd
, ':');
396 adjust_rssi
= atoi(pos
);
397 if (adjust_rssi
< -100 || adjust_rssi
> 100)
400 if (os_strncmp(cmd
, "2G", 2) == 0)
401 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_2G
;
402 else if (os_strncmp(cmd
, "5G", 2) == 0)
403 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_5G
;
407 wpa_s
->srp
.relative_adjust_rssi
= adjust_rssi
;
413 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant
*wpa_s
,
416 struct wpabuf
*ric_ies
;
418 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
419 wpabuf_free(wpa_s
->ric_ies
);
420 wpa_s
->ric_ies
= NULL
;
424 ric_ies
= wpabuf_parse_bin(cmd
);
428 wpabuf_free(wpa_s
->ric_ies
);
429 wpa_s
->ric_ies
= ric_ies
;
435 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
441 value
= os_strchr(cmd
, ' ');
446 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
447 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
448 eapol_sm_configure(wpa_s
->eapol
,
449 atoi(value
), -1, -1, -1);
450 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
451 eapol_sm_configure(wpa_s
->eapol
,
452 -1, atoi(value
), -1, -1);
453 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
454 eapol_sm_configure(wpa_s
->eapol
,
455 -1, -1, atoi(value
), -1);
456 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
457 eapol_sm_configure(wpa_s
->eapol
,
458 -1, -1, -1, atoi(value
));
459 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
460 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
465 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
467 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
469 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
474 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
476 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
477 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
482 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
484 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
485 wpa_s
->wps_fragment_size
= atoi(value
);
486 #ifdef CONFIG_WPS_TESTING
487 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
489 val
= strtol(value
, NULL
, 0);
490 if (val
< 0 || val
> 0xff) {
492 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
493 "wps_version_number %ld", val
);
495 wps_version_number
= val
;
496 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
498 (wps_version_number
& 0xf0) >> 4,
499 wps_version_number
& 0x0f);
501 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
502 wps_testing_dummy_cred
= atoi(value
);
503 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
504 wps_testing_dummy_cred
);
505 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
506 wps_corrupt_pkhash
= atoi(value
);
507 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
509 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
510 if (value
[0] == '\0') {
511 wps_force_auth_types_in_use
= 0;
513 wps_force_auth_types
= strtol(value
, NULL
, 0);
514 wps_force_auth_types_in_use
= 1;
516 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
517 if (value
[0] == '\0') {
518 wps_force_encr_types_in_use
= 0;
520 wps_force_encr_types
= strtol(value
, NULL
, 0);
521 wps_force_encr_types_in_use
= 1;
523 #endif /* CONFIG_WPS_TESTING */
524 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
525 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
528 #ifdef CONFIG_TDLS_TESTING
529 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
530 tdls_testing
= strtol(value
, NULL
, 0);
531 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
532 #endif /* CONFIG_TDLS_TESTING */
533 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
534 int disabled
= atoi(value
);
535 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
537 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
539 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
541 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
542 #endif /* CONFIG_TDLS */
543 } else if (os_strcasecmp(cmd
, "pno") == 0) {
544 ret
= wpas_ctrl_pno(wpa_s
, value
);
545 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
546 int disabled
= atoi(value
);
547 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
550 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
551 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
552 if (os_strcmp(value
, "disable") == 0)
553 wpa_s
->set_sta_uapsd
= 0;
557 /* format: BE,BK,VI,VO;max SP Length */
559 pos
= os_strchr(value
, ',');
564 pos
= os_strchr(pos
, ',');
569 pos
= os_strchr(pos
, ',');
574 /* ignore max SP Length for now */
576 wpa_s
->set_sta_uapsd
= 1;
577 wpa_s
->sta_uapsd
= 0;
579 wpa_s
->sta_uapsd
|= BIT(0);
581 wpa_s
->sta_uapsd
|= BIT(1);
583 wpa_s
->sta_uapsd
|= BIT(2);
585 wpa_s
->sta_uapsd
|= BIT(3);
587 } else if (os_strcasecmp(cmd
, "ps") == 0) {
588 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
589 #ifdef CONFIG_WIFI_DISPLAY
590 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
591 int enabled
= !!atoi(value
);
592 if (enabled
&& !wpa_s
->global
->p2p
)
595 wifi_display_enable(wpa_s
->global
, enabled
);
596 #endif /* CONFIG_WIFI_DISPLAY */
597 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
598 ret
= set_bssid_filter(wpa_s
, value
);
599 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
600 ret
= set_disallow_aps(wpa_s
, value
);
601 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
602 wpa_s
->no_keep_alive
= !!atoi(value
);
604 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
605 os_free(wpa_s
->dpp_configurator_params
);
606 wpa_s
->dpp_configurator_params
= os_strdup(value
);
607 #endif /* CONFIG_DPP */
608 #ifdef CONFIG_TESTING_OPTIONS
609 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
610 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
611 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
612 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
614 if (wpa_s
->ap_iface
) {
615 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
616 wpa_s
->ext_eapol_frame_io
;
618 #endif /* CONFIG_AP */
619 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
620 wpa_s
->extra_roc_dur
= atoi(value
);
621 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
622 wpa_s
->test_failure
= atoi(value
);
623 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
624 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
625 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
626 wpa_s
->ignore_auth_resp
= !!atoi(value
);
627 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
628 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
629 wpa_drv_ignore_assoc_disallow(wpa_s
,
630 wpa_s
->ignore_assoc_disallow
);
631 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
632 wpa_s
->reject_btm_req_reason
= atoi(value
);
633 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
634 os_free(wpa_s
->get_pref_freq_list_override
);
636 wpa_s
->get_pref_freq_list_override
= NULL
;
638 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
639 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
640 wpabuf_free(wpa_s
->sae_commit_override
);
641 if (value
[0] == '\0')
642 wpa_s
->sae_commit_override
= NULL
;
644 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
646 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
647 os_free(wpa_s
->dpp_config_obj_override
);
648 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
649 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
650 os_free(wpa_s
->dpp_discovery_override
);
651 wpa_s
->dpp_discovery_override
= os_strdup(value
);
652 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
653 os_free(wpa_s
->dpp_groups_override
);
654 wpa_s
->dpp_groups_override
= os_strdup(value
);
655 } else if (os_strcasecmp(cmd
,
656 "dpp_ignore_netaccesskey_mismatch") == 0) {
657 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
658 #endif /* CONFIG_DPP */
659 #endif /* CONFIG_TESTING_OPTIONS */
660 #ifndef CONFIG_NO_CONFIG_BLOBS
661 } else if (os_strcmp(cmd
, "blob") == 0) {
662 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
663 #endif /* CONFIG_NO_CONFIG_BLOBS */
664 } else if (os_strcasecmp(cmd
, "setband") == 0) {
665 ret
= wpas_ctrl_set_band(wpa_s
, value
);
667 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
668 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
671 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
673 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
674 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
675 } else if (os_strcasecmp(cmd
, "oce") == 0) {
676 wpa_s
->conf
->oce
= atoi(value
);
677 if (wpa_s
->conf
->oce
) {
678 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
679 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
680 wpa_s
->enable_oce
= OCE_STA
;
682 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
684 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
685 /* TODO: Need to add STA-CFON support */
686 wpa_printf(MSG_ERROR
,
687 "OCE STA-CFON feature is not yet supported");
691 wpa_s
->enable_oce
= 0;
693 #endif /* CONFIG_MBO */
694 } else if (os_strcasecmp(cmd
, "lci") == 0) {
695 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
696 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
697 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
698 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
699 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
700 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
701 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
702 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
703 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
704 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
705 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
708 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
710 wpa_supplicant_update_config(wpa_s
);
717 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
718 char *cmd
, char *buf
, size_t buflen
)
722 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
724 if (os_strcmp(cmd
, "version") == 0) {
725 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
726 } else if (os_strcasecmp(cmd
, "country") == 0) {
727 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
728 res
= os_snprintf(buf
, buflen
, "%c%c",
729 wpa_s
->conf
->country
[0],
730 wpa_s
->conf
->country
[1]);
731 #ifdef CONFIG_WIFI_DISPLAY
732 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
734 if (wpa_s
->global
->p2p
== NULL
||
735 wpa_s
->global
->p2p_disabled
)
738 enabled
= wpa_s
->global
->wifi_display
;
739 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
740 #endif /* CONFIG_WIFI_DISPLAY */
741 #ifdef CONFIG_TESTING_GET_GTK
742 } else if (os_strcmp(cmd
, "gtk") == 0) {
743 if (wpa_s
->last_gtk_len
== 0)
745 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
746 wpa_s
->last_gtk_len
);
748 #endif /* CONFIG_TESTING_GET_GTK */
749 } else if (os_strcmp(cmd
, "tls_library") == 0) {
750 res
= tls_get_library_version(buf
, buflen
);
752 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
755 if (os_snprintf_error(buflen
, res
))
761 #ifdef IEEE8021X_EAPOL
762 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
766 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
768 if (hwaddr_aton(addr
, bssid
)) {
769 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
774 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
775 rsn_preauth_deinit(wpa_s
->wpa
);
776 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
781 #endif /* IEEE8021X_EAPOL */
784 #ifdef CONFIG_PEERKEY
785 /* MLME-STKSTART.request(peer) */
786 static int wpa_supplicant_ctrl_iface_stkstart(
787 struct wpa_supplicant
*wpa_s
, char *addr
)
791 if (hwaddr_aton(addr
, peer
)) {
792 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
793 "address '%s'", addr
);
797 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
800 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
802 #endif /* CONFIG_PEERKEY */
807 static int wpa_supplicant_ctrl_iface_tdls_discover(
808 struct wpa_supplicant
*wpa_s
, char *addr
)
813 if (hwaddr_aton(addr
, peer
)) {
814 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
815 "address '%s'", addr
);
819 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
822 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
823 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
825 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
831 static int wpa_supplicant_ctrl_iface_tdls_setup(
832 struct wpa_supplicant
*wpa_s
, char *addr
)
837 if (hwaddr_aton(addr
, peer
)) {
838 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
839 "address '%s'", addr
);
843 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
846 if ((wpa_s
->conf
->tdls_external_control
) &&
847 wpa_tdls_is_external_setup(wpa_s
->wpa
))
848 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
850 wpa_tdls_remove(wpa_s
->wpa
, peer
);
852 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
853 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
855 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
861 static int wpa_supplicant_ctrl_iface_tdls_teardown(
862 struct wpa_supplicant
*wpa_s
, char *addr
)
867 if (os_strcmp(addr
, "*") == 0) {
868 /* remove everyone */
869 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
870 wpa_tdls_teardown_peers(wpa_s
->wpa
);
874 if (hwaddr_aton(addr
, peer
)) {
875 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
876 "address '%s'", addr
);
880 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
883 if ((wpa_s
->conf
->tdls_external_control
) &&
884 wpa_tdls_is_external_setup(wpa_s
->wpa
))
885 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
887 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
888 ret
= wpa_tdls_teardown_link(
890 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
892 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
898 static int ctrl_iface_get_capability_tdls(
899 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
903 ret
= os_snprintf(buf
, buflen
, "%s\n",
904 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
906 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
907 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
908 if (os_snprintf_error(buflen
, ret
))
914 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
915 struct wpa_supplicant
*wpa_s
, char *cmd
)
918 struct hostapd_freq_params freq_params
;
922 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
924 "tdls_chanswitch: Only supported with external setup");
928 os_memset(&freq_params
, 0, sizeof(freq_params
));
930 pos
= os_strchr(cmd
, ' ');
935 oper_class
= strtol(pos
, &end
, 10);
938 "tdls_chanswitch: Invalid op class provided");
943 freq_params
.freq
= atoi(pos
);
944 if (freq_params
.freq
== 0) {
945 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
949 #define SET_FREQ_SETTING(str) \
951 const char *pos2 = os_strstr(pos, " " #str "="); \
953 pos2 += sizeof(" " #str "=") - 1; \
954 freq_params.str = atoi(pos2); \
958 SET_FREQ_SETTING(center_freq1
);
959 SET_FREQ_SETTING(center_freq2
);
960 SET_FREQ_SETTING(bandwidth
);
961 SET_FREQ_SETTING(sec_channel_offset
);
962 #undef SET_FREQ_SETTING
964 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
965 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
967 if (hwaddr_aton(cmd
, peer
)) {
968 wpa_printf(MSG_DEBUG
,
969 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
974 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
975 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
976 MAC2STR(peer
), oper_class
, freq_params
.freq
,
977 freq_params
.center_freq1
, freq_params
.center_freq2
,
978 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
979 freq_params
.ht_enabled
? " HT" : "",
980 freq_params
.vht_enabled
? " VHT" : "");
982 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
987 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
988 struct wpa_supplicant
*wpa_s
, char *cmd
)
992 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
994 "tdls_chanswitch: Only supported with external setup");
998 if (hwaddr_aton(cmd
, peer
)) {
999 wpa_printf(MSG_DEBUG
,
1000 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1005 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1008 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1012 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1013 struct wpa_supplicant
*wpa_s
, const char *addr
,
1014 char *buf
, size_t buflen
)
1017 const char *tdls_status
;
1020 if (hwaddr_aton(addr
, peer
)) {
1021 wpa_printf(MSG_DEBUG
,
1022 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1026 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1029 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1030 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1031 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1032 if (os_snprintf_error(buflen
, ret
))
1038 #endif /* CONFIG_TDLS */
1041 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1043 char *token
, *context
= NULL
;
1044 struct wmm_ac_ts_setup_params params
= {
1049 while ((token
= str_token(cmd
, " ", &context
))) {
1050 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1051 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1052 sscanf(token
, "nominal_msdu_size=%i",
1053 ¶ms
.nominal_msdu_size
) == 1 ||
1054 sscanf(token
, "mean_data_rate=%i",
1055 ¶ms
.mean_data_rate
) == 1 ||
1056 sscanf(token
, "min_phy_rate=%i",
1057 ¶ms
.minimum_phy_rate
) == 1 ||
1058 sscanf(token
, "sba=%i",
1059 ¶ms
.surplus_bandwidth_allowance
) == 1)
1062 if (os_strcasecmp(token
, "downlink") == 0) {
1063 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1064 } else if (os_strcasecmp(token
, "uplink") == 0) {
1065 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1066 } else if (os_strcasecmp(token
, "bidi") == 0) {
1067 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1068 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1069 params
.fixed_nominal_msdu
= 1;
1071 wpa_printf(MSG_DEBUG
,
1072 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1079 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1083 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1085 u8 tsid
= atoi(cmd
);
1087 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1091 #ifdef CONFIG_IEEE80211R
1092 static int wpa_supplicant_ctrl_iface_ft_ds(
1093 struct wpa_supplicant
*wpa_s
, char *addr
)
1095 u8 target_ap
[ETH_ALEN
];
1096 struct wpa_bss
*bss
;
1099 if (hwaddr_aton(addr
, target_ap
)) {
1100 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1101 "address '%s'", addr
);
1105 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1107 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1109 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1113 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1115 #endif /* CONFIG_IEEE80211R */
1119 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1122 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1124 u8 p2p_dev_addr
[ETH_ALEN
];
1125 #endif /* CONFIG_P2P */
1127 u8
*_p2p_dev_addr
= NULL
;
1128 #endif /* CONFIG_AP */
1130 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
1133 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1134 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1135 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1136 "P2P Device Address '%s'",
1140 _p2p_dev_addr
= p2p_dev_addr
;
1141 #endif /* CONFIG_P2P */
1142 } else if (hwaddr_aton(cmd
, bssid
)) {
1143 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1149 if (wpa_s
->ap_iface
)
1150 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1151 #endif /* CONFIG_AP */
1153 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1157 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1158 char *cmd
, char *buf
,
1161 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1165 pin
= os_strchr(cmd
, ' ');
1169 if (os_strcmp(cmd
, "any") == 0)
1171 else if (os_strcmp(cmd
, "get") == 0) {
1172 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1175 } else if (hwaddr_aton(cmd
, bssid
)) {
1176 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1182 if (wpa_s
->ap_iface
) {
1187 pos
= os_strchr(pin
, ' ');
1190 timeout
= atoi(pos
);
1194 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1195 buf
, buflen
, timeout
);
1197 #endif /* CONFIG_AP */
1200 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1204 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1205 if (os_snprintf_error(buflen
, ret
))
1210 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1215 /* Return the generated PIN */
1216 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1217 if (os_snprintf_error(buflen
, ret
))
1223 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1224 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1231 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1232 (u8
*) cmd
, os_strlen(cmd
));
1233 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1234 if (*pos
< '0' || *pos
> '9')
1238 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1242 if (len
!= 4 && len
!= 8) {
1243 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1249 unsigned int pin_val
;
1250 pin_val
= atoi(pin
);
1251 if (!wps_pin_valid(pin_val
)) {
1252 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1253 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1254 if (os_snprintf_error(buflen
, ret
))
1260 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1261 if (os_snprintf_error(buflen
, ret
))
1268 #ifdef CONFIG_WPS_NFC
1270 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1273 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1275 if (cmd
== NULL
|| cmd
[0] == '\0')
1277 else if (hwaddr_aton(cmd
, bssid
))
1280 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1285 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1286 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1293 pos
= os_strchr(cmd
, ' ');
1296 if (os_strcmp(cmd
, "WPS") == 0)
1298 else if (os_strcmp(cmd
, "NDEF") == 0)
1303 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1307 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1309 reply
[res
++] = '\n';
1318 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1319 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1325 if (os_strcmp(cmd
, "WPS") == 0)
1327 else if (os_strcmp(cmd
, "NDEF") == 0)
1332 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1336 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1338 reply
[res
++] = '\n';
1347 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1348 struct wpa_supplicant
*wpa_s
, char *pos
)
1354 int forced_freq
= 0;
1356 freq
= strstr(pos
, " freq=");
1360 forced_freq
= atoi(freq
);
1363 len
= os_strlen(pos
);
1368 buf
= wpabuf_alloc(len
);
1371 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1376 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1383 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1384 char *reply
, size_t max_len
,
1390 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1394 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1396 reply
[res
++] = '\n';
1406 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1407 char *reply
, size_t max_len
,
1413 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1415 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1419 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1421 reply
[res
++] = '\n';
1428 #endif /* CONFIG_P2P */
1431 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1432 char *cmd
, char *reply
,
1438 pos
= os_strchr(cmd
, ' ');
1443 if (os_strcmp(cmd
, "WPS") == 0)
1445 else if (os_strcmp(cmd
, "NDEF") == 0)
1450 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1453 return wpas_ctrl_nfc_get_handover_req_wps(
1454 wpa_s
, reply
, max_len
, ndef
);
1458 if (os_strcmp(pos
, "P2P-CR") == 0) {
1459 return wpas_ctrl_nfc_get_handover_req_p2p(
1460 wpa_s
, reply
, max_len
, ndef
);
1462 #endif /* CONFIG_P2P */
1468 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1469 char *reply
, size_t max_len
,
1470 int ndef
, int cr
, char *uuid
)
1475 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1479 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1481 reply
[res
++] = '\n';
1491 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1492 char *reply
, size_t max_len
,
1498 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1502 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1504 reply
[res
++] = '\n';
1511 #endif /* CONFIG_P2P */
1514 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1515 char *cmd
, char *reply
,
1521 pos
= os_strchr(cmd
, ' ');
1526 if (os_strcmp(cmd
, "WPS") == 0)
1528 else if (os_strcmp(cmd
, "NDEF") == 0)
1533 pos2
= os_strchr(pos
, ' ');
1536 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1539 return wpas_ctrl_nfc_get_handover_sel_wps(
1540 wpa_s
, reply
, max_len
, ndef
,
1541 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1545 if (os_strcmp(pos
, "P2P-CR") == 0) {
1546 return wpas_ctrl_nfc_get_handover_sel_p2p(
1547 wpa_s
, reply
, max_len
, ndef
, 0);
1550 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1551 return wpas_ctrl_nfc_get_handover_sel_p2p(
1552 wpa_s
, reply
, max_len
, ndef
, 1);
1554 #endif /* CONFIG_P2P */
1560 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1564 struct wpabuf
*req
, *sel
;
1566 char *pos
, *role
, *type
, *pos2
;
1569 int forced_freq
= 0;
1571 freq
= strstr(cmd
, " freq=");
1575 forced_freq
= atoi(freq
);
1577 #endif /* CONFIG_P2P */
1580 pos
= os_strchr(role
, ' ');
1582 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1588 pos
= os_strchr(type
, ' ');
1590 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1595 pos2
= os_strchr(pos
, ' ');
1597 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1602 len
= os_strlen(pos
);
1604 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1609 req
= wpabuf_alloc(len
);
1611 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1614 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1615 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1620 len
= os_strlen(pos2
);
1622 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1628 sel
= wpabuf_alloc(len
);
1630 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1634 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1635 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1641 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1642 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1644 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1645 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1647 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1649 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1651 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1652 #endif /* CONFIG_AP */
1654 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1656 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1657 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1659 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1661 #endif /* CONFIG_P2P */
1663 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1664 "reported: role=%s type=%s", role
, type
);
1671 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1676 #endif /* CONFIG_WPS_NFC */
1679 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1688 struct wps_new_ap_settings ap
;
1690 pin
= os_strchr(cmd
, ' ');
1695 if (hwaddr_aton(cmd
, bssid
)) {
1696 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1701 new_ssid
= os_strchr(pin
, ' ');
1702 if (new_ssid
== NULL
)
1703 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1706 new_auth
= os_strchr(new_ssid
, ' ');
1707 if (new_auth
== NULL
)
1711 new_encr
= os_strchr(new_auth
, ' ');
1712 if (new_encr
== NULL
)
1716 new_key
= os_strchr(new_encr
, ' ');
1717 if (new_key
== NULL
)
1721 os_memset(&ap
, 0, sizeof(ap
));
1722 ap
.ssid_hex
= new_ssid
;
1725 ap
.key_hex
= new_key
;
1726 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1731 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1732 char *cmd
, char *buf
,
1737 const char *pin_txt
;
1739 if (!wpa_s
->ap_iface
)
1742 pos
= os_strchr(cmd
, ' ');
1746 if (os_strcmp(cmd
, "disable") == 0) {
1747 wpas_wps_ap_pin_disable(wpa_s
);
1748 return os_snprintf(buf
, buflen
, "OK\n");
1751 if (os_strcmp(cmd
, "random") == 0) {
1753 timeout
= atoi(pos
);
1754 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1755 if (pin_txt
== NULL
)
1757 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1760 if (os_strcmp(cmd
, "get") == 0) {
1761 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1762 if (pin_txt
== NULL
)
1764 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1767 if (os_strcmp(cmd
, "set") == 0) {
1772 pos
= os_strchr(pos
, ' ');
1775 timeout
= atoi(pos
);
1777 if (os_strlen(pin
) > buflen
)
1779 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1781 return os_snprintf(buf
, buflen
, "%s", pin
);
1786 #endif /* CONFIG_AP */
1789 #ifdef CONFIG_WPS_ER
1790 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1793 char *uuid
= cmd
, *pin
, *pos
;
1794 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1795 pin
= os_strchr(uuid
, ' ');
1799 pos
= os_strchr(pin
, ' ');
1802 if (hwaddr_aton(pos
, addr_buf
) == 0)
1805 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1809 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1812 char *uuid
= cmd
, *pin
;
1813 pin
= os_strchr(uuid
, ' ');
1817 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1821 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1822 struct wpa_supplicant
*wpa_s
, char *cmd
)
1824 char *uuid
= cmd
, *id
;
1825 id
= os_strchr(uuid
, ' ');
1829 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1833 static int wpa_supplicant_ctrl_iface_wps_er_config(
1834 struct wpa_supplicant
*wpa_s
, char *cmd
)
1841 struct wps_new_ap_settings ap
;
1843 pin
= os_strchr(cmd
, ' ');
1848 new_ssid
= os_strchr(pin
, ' ');
1849 if (new_ssid
== NULL
)
1853 new_auth
= os_strchr(new_ssid
, ' ');
1854 if (new_auth
== NULL
)
1858 new_encr
= os_strchr(new_auth
, ' ');
1859 if (new_encr
== NULL
)
1863 new_key
= os_strchr(new_encr
, ' ');
1864 if (new_key
== NULL
)
1868 os_memset(&ap
, 0, sizeof(ap
));
1869 ap
.ssid_hex
= new_ssid
;
1872 ap
.key_hex
= new_key
;
1873 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1877 #ifdef CONFIG_WPS_NFC
1878 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1879 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1886 uuid
= os_strchr(cmd
, ' ');
1891 if (os_strcmp(cmd
, "WPS") == 0)
1893 else if (os_strcmp(cmd
, "NDEF") == 0)
1898 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1902 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1904 reply
[res
++] = '\n';
1911 #endif /* CONFIG_WPS_NFC */
1912 #endif /* CONFIG_WPS_ER */
1914 #endif /* CONFIG_WPS */
1917 #ifdef CONFIG_IBSS_RSN
1918 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1919 struct wpa_supplicant
*wpa_s
, char *addr
)
1923 if (hwaddr_aton(addr
, peer
)) {
1924 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1925 "address '%s'", addr
);
1929 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1932 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1934 #endif /* CONFIG_IBSS_RSN */
1937 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1940 #ifdef IEEE8021X_EAPOL
1943 struct wpa_ssid
*ssid
;
1945 pos
= os_strchr(rsp
, '-');
1950 pos
= os_strchr(pos
, ':');
1955 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1956 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1957 (u8
*) pos
, os_strlen(pos
));
1959 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1961 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1966 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1968 #else /* IEEE8021X_EAPOL */
1969 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1971 #endif /* IEEE8021X_EAPOL */
1975 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1977 char *buf
, size_t buflen
)
1979 char *pos
, *end
, tmp
[30];
1980 int res
, verbose
, wps
, ret
;
1983 #endif /* CONFIG_HS20 */
1987 if (os_strcmp(params
, "-DRIVER") == 0)
1988 return wpa_drv_status(wpa_s
, buf
, buflen
);
1989 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1990 wps
= os_strcmp(params
, "-WPS") == 0;
1993 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1994 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1995 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1996 MAC2STR(wpa_s
->bssid
));
1997 if (os_snprintf_error(end
- pos
, ret
))
2000 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2002 if (os_snprintf_error(end
- pos
, ret
))
2006 u8
*_ssid
= ssid
->ssid
;
2007 size_t ssid_len
= ssid
->ssid_len
;
2008 u8 ssid_buf
[SSID_MAX_LEN
];
2009 if (ssid_len
== 0) {
2010 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2017 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2018 wpa_ssid_txt(_ssid
, ssid_len
),
2020 if (os_snprintf_error(end
- pos
, ret
))
2024 if (wps
&& ssid
->passphrase
&&
2025 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2026 (ssid
->mode
== WPAS_MODE_AP
||
2027 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2028 ret
= os_snprintf(pos
, end
- pos
,
2031 if (os_snprintf_error(end
- pos
, ret
))
2036 ret
= os_snprintf(pos
, end
- pos
,
2039 if (os_snprintf_error(end
- pos
, ret
))
2044 switch (ssid
->mode
) {
2045 case WPAS_MODE_INFRA
:
2046 ret
= os_snprintf(pos
, end
- pos
,
2049 case WPAS_MODE_IBSS
:
2050 ret
= os_snprintf(pos
, end
- pos
,
2054 ret
= os_snprintf(pos
, end
- pos
,
2057 case WPAS_MODE_P2P_GO
:
2058 ret
= os_snprintf(pos
, end
- pos
,
2061 case WPAS_MODE_P2P_GROUP_FORMATION
:
2062 ret
= os_snprintf(pos
, end
- pos
,
2063 "mode=P2P GO - group "
2066 case WPAS_MODE_MESH
:
2067 ret
= os_snprintf(pos
, end
- pos
,
2074 if (os_snprintf_error(end
- pos
, ret
))
2080 if (wpa_s
->ap_iface
) {
2081 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2085 #endif /* CONFIG_AP */
2086 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2090 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2093 #endif /* CONFIG_AP */
2094 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2095 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2096 wpa_s
->sme
.sae
.group
);
2097 if (os_snprintf_error(end
- pos
, ret
))
2101 #endif /* CONFIG_SAE */
2102 #endif /* CONFIG_SME */
2103 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2104 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2105 if (os_snprintf_error(end
- pos
, ret
))
2110 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2111 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2112 if (os_snprintf_error(end
- pos
, ret
))
2118 if (wpa_s
->global
->p2p
) {
2119 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2120 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2121 if (os_snprintf_error(end
- pos
, ret
))
2125 #endif /* CONFIG_P2P */
2127 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2128 MAC2STR(wpa_s
->own_addr
));
2129 if (os_snprintf_error(end
- pos
, ret
))
2134 if (wpa_s
->current_bss
&&
2135 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2136 HS20_IE_VENDOR_TYPE
)) &&
2137 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2138 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2141 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2142 release
= rel_num
+ 1;
2144 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2145 if (os_snprintf_error(end
- pos
, ret
))
2150 if (wpa_s
->current_ssid
) {
2151 struct wpa_cred
*cred
;
2154 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2157 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2160 if (cred
->provisioning_sp
) {
2161 ret
= os_snprintf(pos
, end
- pos
,
2162 "provisioning_sp=%s\n",
2163 cred
->provisioning_sp
);
2164 if (os_snprintf_error(end
- pos
, ret
))
2173 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2174 struct wpabuf
*names
=
2175 wpa_s
->current_bss
->anqp
->domain_name
;
2176 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2178 if (domain_name_list_contains(
2179 names
, cred
->domain
[i
], 1))
2182 if (i
== cred
->num_domain
)
2183 i
= 0; /* show first entry by default */
2185 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2187 if (os_snprintf_error(end
- pos
, ret
))
2192 if (wpa_s
->current_bss
== NULL
||
2193 wpa_s
->current_bss
->anqp
== NULL
)
2196 res
= interworking_home_sp_cred(
2198 wpa_s
->current_bss
->anqp
->domain_name
);
2206 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2207 if (os_snprintf_error(end
- pos
, ret
))
2214 #endif /* CONFIG_HS20 */
2216 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2217 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2218 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2224 #ifdef CONFIG_MACSEC
2225 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2228 #endif /* CONFIG_MACSEC */
2230 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2234 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2235 if (os_snprintf_error(end
- pos
, ret
))
2238 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2242 ret
= os_snprintf(pos
, end
- pos
, "\n");
2243 if (os_snprintf_error(end
- pos
, ret
))
2248 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2255 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2256 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2257 if (os_snprintf_error(end
- pos
, ret
))
2261 #endif /* CONFIG_WPS */
2265 * Allow using the STATUS command with default behavior, say for debug,
2266 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2267 * events with STATUS-NO_EVENTS.
2269 if (os_strcmp(params
, "-NO_EVENTS")) {
2270 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2271 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2272 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2274 MAC2STR(wpa_s
->bssid
),
2275 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2276 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2277 wpa_s
->current_ssid
->ssid_len
) : "");
2278 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2279 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2280 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2281 "- connection to " MACSTR
2282 " completed %s [id=%d id_str=%s]",
2283 MAC2STR(wpa_s
->bssid
), "(auth)",
2284 ssid
? ssid
->id
: -1,
2285 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2288 #endif /* ANDROID */
2294 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2299 struct wpa_ssid
*ssid
;
2302 /* cmd: "<network id> <BSSID>" */
2303 pos
= os_strchr(cmd
, ' ');
2308 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2309 if (hwaddr_aton(pos
, bssid
)) {
2310 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2314 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2316 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2321 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2322 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2328 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2329 char *cmd
, char *buf
,
2333 struct wpa_blacklist
*e
;
2337 /* cmd: "BLACKLIST [<BSSID>]" */
2341 e
= wpa_s
->blacklist
;
2343 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2345 if (os_snprintf_error(end
- pos
, ret
))
2354 if (os_strncmp(cmd
, "clear", 5) == 0) {
2355 wpa_blacklist_clear(wpa_s
);
2356 os_memcpy(buf
, "OK\n", 3);
2360 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2361 if (hwaddr_aton(cmd
, bssid
)) {
2362 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2367 * Add the BSSID twice, so its count will be 2, causing it to be
2368 * skipped when processing scan results.
2370 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2373 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2376 os_memcpy(buf
, "OK\n", 3);
2381 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2382 char *cmd
, char *buf
,
2385 char *pos
, *end
, *stamp
;
2388 /* cmd: "LOG_LEVEL [<level>]" */
2392 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2394 debug_level_str(wpa_debug_level
),
2395 wpa_debug_timestamp
);
2396 if (os_snprintf_error(end
- pos
, ret
))
2405 stamp
= os_strchr(cmd
, ' ');
2408 while (*stamp
== ' ') {
2413 if (os_strlen(cmd
)) {
2414 int level
= str_to_debug_level(cmd
);
2417 wpa_debug_level
= level
;
2420 if (stamp
&& os_strlen(stamp
))
2421 wpa_debug_timestamp
= atoi(stamp
);
2423 os_memcpy(buf
, "OK\n", 3);
2428 static int wpa_supplicant_ctrl_iface_list_networks(
2429 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2431 char *pos
, *end
, *prev
;
2432 struct wpa_ssid
*ssid
;
2437 ret
= os_snprintf(pos
, end
- pos
,
2438 "network id / ssid / bssid / flags\n");
2439 if (os_snprintf_error(end
- pos
, ret
))
2443 ssid
= wpa_s
->conf
->ssid
;
2445 /* skip over ssids until we find next one */
2446 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2447 int last_id
= atoi(cmd
+ 8);
2448 if (last_id
!= -1) {
2449 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2457 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2459 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2460 if (os_snprintf_error(end
- pos
, ret
))
2463 if (ssid
->bssid_set
) {
2464 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2465 MAC2STR(ssid
->bssid
));
2467 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2469 if (os_snprintf_error(end
- pos
, ret
))
2472 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2473 ssid
== wpa_s
->current_ssid
?
2475 ssid
->disabled
? "[DISABLED]" : "",
2476 ssid
->disabled_until
.sec
?
2477 "[TEMP-DISABLED]" : "",
2478 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2480 if (os_snprintf_error(end
- pos
, ret
))
2483 ret
= os_snprintf(pos
, end
- pos
, "\n");
2484 if (os_snprintf_error(end
- pos
, ret
))
2495 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2498 ret
= os_snprintf(pos
, end
- pos
, "-");
2499 if (os_snprintf_error(end
- pos
, ret
))
2502 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2510 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2511 const u8
*ie
, size_t ie_len
)
2513 struct wpa_ie_data data
;
2517 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2518 if (os_snprintf_error(end
- pos
, ret
))
2522 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2523 ret
= os_snprintf(pos
, end
- pos
, "?]");
2524 if (os_snprintf_error(end
- pos
, ret
))
2531 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2532 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2533 pos
== start
? "" : "+");
2534 if (os_snprintf_error(end
- pos
, ret
))
2538 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2539 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2540 pos
== start
? "" : "+");
2541 if (os_snprintf_error(end
- pos
, ret
))
2545 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2546 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2547 pos
== start
? "" : "+");
2548 if (os_snprintf_error(end
- pos
, ret
))
2552 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2553 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2554 pos
== start
? "" : "+");
2555 if (os_snprintf_error(end
- pos
, ret
))
2559 #ifdef CONFIG_IEEE80211R
2560 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2561 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2562 pos
== start
? "" : "+");
2563 if (os_snprintf_error(end
- pos
, ret
))
2567 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2568 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2569 pos
== start
? "" : "+");
2570 if (os_snprintf_error(end
- pos
, ret
))
2574 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2575 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2576 pos
== start
? "" : "+");
2577 if (os_snprintf_error(end
- pos
, ret
))
2581 #endif /* CONFIG_IEEE80211R */
2582 #ifdef CONFIG_IEEE80211W
2583 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2584 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2585 pos
== start
? "" : "+");
2586 if (os_snprintf_error(end
- pos
, ret
))
2590 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2591 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2592 pos
== start
? "" : "+");
2593 if (os_snprintf_error(end
- pos
, ret
))
2597 #endif /* CONFIG_IEEE80211W */
2599 #ifdef CONFIG_SUITEB
2600 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2601 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2602 pos
== start
? "" : "+");
2603 if (os_snprintf_error(end
- pos
, ret
))
2607 #endif /* CONFIG_SUITEB */
2609 #ifdef CONFIG_SUITEB192
2610 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2611 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2612 pos
== start
? "" : "+");
2613 if (os_snprintf_error(end
- pos
, ret
))
2617 #endif /* CONFIG_SUITEB192 */
2620 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2621 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2622 pos
== start
? "" : "+");
2623 if (os_snprintf_error(end
- pos
, ret
))
2627 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2628 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2629 pos
== start
? "" : "+");
2630 if (os_snprintf_error(end
- pos
, ret
))
2634 #ifdef CONFIG_IEEE80211R
2635 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2636 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2637 pos
== start
? "" : "+");
2638 if (os_snprintf_error(end
- pos
, ret
))
2642 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2643 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2644 pos
== start
? "" : "+");
2645 if (os_snprintf_error(end
- pos
, ret
))
2649 #endif /* CONFIG_IEEE80211R */
2650 #endif /* CONFIG_FILS */
2653 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2654 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2655 pos
== start
? "" : "+");
2656 if (os_snprintf_error(end
- pos
, ret
))
2660 #endif /* CONFIG_OWE */
2663 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2664 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2665 pos
== start
? "" : "+");
2666 if (os_snprintf_error(end
- pos
, ret
))
2670 #endif /* CONFIG_DPP */
2672 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2673 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2674 pos
== start
? "" : "+");
2675 if (os_snprintf_error(end
- pos
, ret
))
2680 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2682 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2683 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2684 if (os_snprintf_error(end
- pos
, ret
))
2689 ret
= os_snprintf(pos
, end
- pos
, "]");
2690 if (os_snprintf_error(end
- pos
, ret
))
2699 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2700 char *pos
, char *end
,
2701 struct wpabuf
*wps_ie
)
2708 if (wps_is_selected_pbc_registrar(wps_ie
))
2710 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2712 else if (wps_is_selected_pin_registrar(wps_ie
))
2717 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2718 if (!os_snprintf_error(end
- pos
, ret
))
2720 wpabuf_free(wps_ie
);
2723 #endif /* CONFIG_WPS */
2726 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2727 char *pos
, char *end
,
2728 const struct wpa_bss
*bss
)
2731 struct wpabuf
*wps_ie
;
2732 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2733 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2734 #else /* CONFIG_WPS */
2736 #endif /* CONFIG_WPS */
2740 /* Format one result on one text line into a buffer. */
2741 static int wpa_supplicant_ctrl_iface_scan_result(
2742 struct wpa_supplicant
*wpa_s
,
2743 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2747 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
;
2749 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2750 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2752 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2753 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2754 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2756 return 0; /* Do not show P2P listen discovery results here */
2761 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2762 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2763 if (os_snprintf_error(end
- pos
, ret
))
2766 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2768 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2769 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2771 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2774 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2776 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2777 osen_ie
, 2 + osen_ie
[1]);
2778 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2779 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2780 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2781 if (os_snprintf_error(end
- pos
, ret
))
2786 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2787 if (os_snprintf_error(end
- pos
, ret
))
2791 if (bss_is_dmg(bss
)) {
2793 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2794 if (os_snprintf_error(end
- pos
, ret
))
2797 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2798 case IEEE80211_CAP_DMG_IBSS
:
2801 case IEEE80211_CAP_DMG_AP
:
2804 case IEEE80211_CAP_DMG_PBSS
:
2811 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2812 if (os_snprintf_error(end
- pos
, ret
))
2816 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2817 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2818 if (os_snprintf_error(end
- pos
, ret
))
2822 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2823 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2824 if (os_snprintf_error(end
- pos
, ret
))
2830 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2831 if (os_snprintf_error(end
- pos
, ret
))
2836 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2837 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2838 if (os_snprintf_error(end
- pos
, ret
))
2842 #endif /* CONFIG_HS20 */
2844 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2845 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2846 if (os_snprintf_error(end
- pos
, ret
))
2850 #endif /* CONFIG_FILS */
2852 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2853 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2854 if (os_snprintf_error(end
- pos
, ret
))
2858 #endif /* CONFIG_FST */
2860 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2861 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2862 if (os_snprintf_error(end
- pos
, ret
))
2866 ret
= os_snprintf(pos
, end
- pos
, "\n");
2867 if (os_snprintf_error(end
- pos
, ret
))
2875 static int wpa_supplicant_ctrl_iface_scan_results(
2876 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2879 struct wpa_bss
*bss
;
2884 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2886 if (os_snprintf_error(end
- pos
, ret
))
2890 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2891 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2893 if (ret
< 0 || ret
>= end
- pos
)
2904 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2905 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2907 char *pos
, ifname
[IFNAMSIZ
+ 1];
2911 pos
= os_strstr(cmd
, "ifname=");
2914 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2917 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2920 os_strlcpy(reply
, ifname
, max_len
);
2921 return os_strlen(ifname
);
2925 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2926 struct wpa_supplicant
*wpa_s
, char *cmd
)
2929 struct wpa_ssid
*ssid
;
2932 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2934 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2936 wpa_printf(MSG_DEBUG
,
2937 "CTRL_IFACE: Could not find network id=%d", id
);
2940 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2941 wpa_printf(MSG_DEBUG
,
2942 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2945 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2946 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2947 wpa_printf(MSG_ERROR
,
2948 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2953 * TODO: If necessary write our own group_add function,
2954 * for now we can reuse select_network
2956 wpa_supplicant_select_network(wpa_s
, ssid
);
2962 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2963 struct wpa_supplicant
*wpa_s
, char *cmd
)
2965 struct wpa_supplicant
*orig
;
2966 struct wpa_global
*global
;
2969 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2971 global
= wpa_s
->global
;
2974 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2975 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2981 wpa_printf(MSG_ERROR
,
2982 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2986 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2987 wpa_printf(MSG_ERROR
,
2988 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2992 wpa_s
->reassociate
= 0;
2993 wpa_s
->disconnected
= 1;
2994 wpa_supplicant_cancel_sched_scan(wpa_s
);
2995 wpa_supplicant_cancel_scan(wpa_s
);
2998 * TODO: If necessary write our own group_remove function,
2999 * for now we can reuse deauthenticate
3001 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3003 if (wpa_s
->mesh_if_created
)
3004 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3010 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3011 struct wpa_supplicant
*wpa_s
, char *cmd
)
3015 if (hwaddr_aton(cmd
, addr
) < 0)
3018 return wpas_mesh_peer_remove(wpa_s
, addr
);
3022 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3023 struct wpa_supplicant
*wpa_s
, char *cmd
)
3029 pos
= os_strstr(cmd
, " duration=");
3032 duration
= atoi(pos
+ 10);
3037 if (hwaddr_aton(cmd
, addr
))
3040 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3043 #endif /* CONFIG_MESH */
3046 static int wpa_supplicant_ctrl_iface_select_network(
3047 struct wpa_supplicant
*wpa_s
, char *cmd
)
3050 struct wpa_ssid
*ssid
;
3053 /* cmd: "<network id>" or "any" */
3054 if (os_strncmp(cmd
, "any", 3) == 0) {
3055 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3059 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3061 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3063 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3064 "network id=%d", id
);
3067 if (ssid
->disabled
== 2) {
3068 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3069 "SELECT_NETWORK with persistent P2P group");
3074 pos
= os_strstr(cmd
, " freq=");
3076 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3078 os_free(wpa_s
->select_network_scan_freqs
);
3079 wpa_s
->select_network_scan_freqs
= freqs
;
3083 wpa_s
->scan_min_time
.sec
= 0;
3084 wpa_s
->scan_min_time
.usec
= 0;
3085 wpa_supplicant_select_network(wpa_s
, ssid
);
3091 static int wpa_supplicant_ctrl_iface_enable_network(
3092 struct wpa_supplicant
*wpa_s
, char *cmd
)
3095 struct wpa_ssid
*ssid
;
3097 /* cmd: "<network id>" or "all" */
3098 if (os_strcmp(cmd
, "all") == 0) {
3099 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3103 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3105 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3107 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3108 "network id=%d", id
);
3111 if (ssid
->disabled
== 2) {
3112 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3113 "ENABLE_NETWORK with persistent P2P group");
3117 if (os_strstr(cmd
, " no-connect")) {
3122 wpa_s
->scan_min_time
.sec
= 0;
3123 wpa_s
->scan_min_time
.usec
= 0;
3124 wpa_supplicant_enable_network(wpa_s
, ssid
);
3130 static int wpa_supplicant_ctrl_iface_disable_network(
3131 struct wpa_supplicant
*wpa_s
, char *cmd
)
3134 struct wpa_ssid
*ssid
;
3136 /* cmd: "<network id>" or "all" */
3137 if (os_strcmp(cmd
, "all") == 0) {
3138 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3142 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3144 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3146 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3147 "network id=%d", id
);
3150 if (ssid
->disabled
== 2) {
3151 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3152 "DISABLE_NETWORK with persistent P2P "
3157 wpa_supplicant_disable_network(wpa_s
, ssid
);
3163 static int wpa_supplicant_ctrl_iface_add_network(
3164 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3166 struct wpa_ssid
*ssid
;
3169 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3171 ssid
= wpa_supplicant_add_network(wpa_s
);
3175 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3176 if (os_snprintf_error(buflen
, ret
))
3182 static int wpa_supplicant_ctrl_iface_remove_network(
3183 struct wpa_supplicant
*wpa_s
, char *cmd
)
3186 struct wpa_ssid
*ssid
;
3189 /* cmd: "<network id>" or "all" */
3190 if (os_strcmp(cmd
, "all") == 0) {
3191 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3192 if (wpa_s
->sched_scanning
)
3193 wpa_supplicant_cancel_sched_scan(wpa_s
);
3195 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3196 if (wpa_s
->current_ssid
) {
3198 wpa_s
->sme
.prev_bssid_set
= 0;
3199 #endif /* CONFIG_SME */
3200 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3201 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3202 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3203 wpa_s
->own_disconnect_req
= 1;
3204 wpa_supplicant_deauthenticate(
3205 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3207 ssid
= wpa_s
->conf
->ssid
;
3209 struct wpa_ssid
*remove_ssid
= ssid
;
3212 if (wpa_s
->last_ssid
== remove_ssid
)
3213 wpa_s
->last_ssid
= NULL
;
3214 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3215 wpa_config_remove_network(wpa_s
->conf
, id
);
3221 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3223 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3225 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3230 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3231 "network id=%d", id
);
3238 static int wpa_supplicant_ctrl_iface_update_network(
3239 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3240 char *name
, char *value
)
3244 ret
= wpa_config_set(ssid
, name
, value
, 0);
3246 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3247 "variable '%s'", name
);
3251 return 0; /* No change to the previously configured value */
3253 if (os_strcmp(name
, "bssid") != 0 &&
3254 os_strcmp(name
, "bssid_hint") != 0 &&
3255 os_strcmp(name
, "priority") != 0) {
3256 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3258 if (wpa_s
->current_ssid
== ssid
||
3259 wpa_s
->current_ssid
== NULL
) {
3261 * Invalidate the EAP session cache if anything in the
3262 * current or previously used configuration changes.
3264 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3268 if ((os_strcmp(name
, "psk") == 0 &&
3269 value
[0] == '"' && ssid
->ssid_len
) ||
3270 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3271 wpa_config_update_psk(ssid
);
3272 else if (os_strcmp(name
, "priority") == 0)
3273 wpa_config_update_prio_list(wpa_s
->conf
);
3279 static int wpa_supplicant_ctrl_iface_set_network(
3280 struct wpa_supplicant
*wpa_s
, char *cmd
)
3282 int id
, ret
, prev_bssid_set
, prev_disabled
;
3283 struct wpa_ssid
*ssid
;
3285 u8 prev_bssid
[ETH_ALEN
];
3287 /* cmd: "<network id> <variable name> <value>" */
3288 name
= os_strchr(cmd
, ' ');
3293 value
= os_strchr(name
, ' ');
3299 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3301 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3302 (u8
*) value
, os_strlen(value
));
3304 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3306 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3311 prev_bssid_set
= ssid
->bssid_set
;
3312 prev_disabled
= ssid
->disabled
;
3313 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3314 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3317 (ssid
->bssid_set
!= prev_bssid_set
||
3318 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3319 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3321 if (prev_disabled
!= ssid
->disabled
&&
3322 (prev_disabled
== 2 || ssid
->disabled
== 2))
3323 wpas_notify_network_type_changed(wpa_s
, ssid
);
3329 static int wpa_supplicant_ctrl_iface_get_network(
3330 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3334 struct wpa_ssid
*ssid
;
3337 /* cmd: "<network id> <variable name>" */
3338 name
= os_strchr(cmd
, ' ');
3339 if (name
== NULL
|| buflen
== 0)
3344 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3347 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3349 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3354 value
= wpa_config_get_no_key(ssid
, name
);
3355 if (value
== NULL
) {
3356 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3357 "variable '%s'", name
);
3361 res
= os_strlcpy(buf
, value
, buflen
);
3362 if (res
>= buflen
) {
3373 static int wpa_supplicant_ctrl_iface_dup_network(
3374 struct wpa_supplicant
*wpa_s
, char *cmd
,
3375 struct wpa_supplicant
*dst_wpa_s
)
3377 struct wpa_ssid
*ssid_s
, *ssid_d
;
3378 char *name
, *id
, *value
;
3379 int id_s
, id_d
, ret
;
3381 /* cmd: "<src network id> <dst network id> <variable name>" */
3382 id
= os_strchr(cmd
, ' ');
3387 name
= os_strchr(id
, ' ');
3395 wpa_printf(MSG_DEBUG
,
3396 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3397 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3399 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3400 if (ssid_s
== NULL
) {
3401 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3402 "network id=%d", id_s
);
3406 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3407 if (ssid_d
== NULL
) {
3408 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3409 "network id=%d", id_d
);
3413 value
= wpa_config_get(ssid_s
, name
);
3414 if (value
== NULL
) {
3415 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3416 "variable '%s'", name
);
3420 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3429 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3430 char *buf
, size_t buflen
)
3433 struct wpa_cred
*cred
;
3438 ret
= os_snprintf(pos
, end
- pos
,
3439 "cred id / realm / username / domain / imsi\n");
3440 if (os_snprintf_error(end
- pos
, ret
))
3444 cred
= wpa_s
->conf
->cred
;
3446 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3447 cred
->id
, cred
->realm
? cred
->realm
: "",
3448 cred
->username
? cred
->username
: "",
3449 cred
->domain
? cred
->domain
[0] : "",
3450 cred
->imsi
? cred
->imsi
: "");
3451 if (os_snprintf_error(end
- pos
, ret
))
3462 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3463 char *buf
, size_t buflen
)
3465 struct wpa_cred
*cred
;
3468 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3470 cred
= wpa_config_add_cred(wpa_s
->conf
);
3474 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3476 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3477 if (os_snprintf_error(buflen
, ret
))
3483 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3484 struct wpa_cred
*cred
)
3486 struct wpa_ssid
*ssid
;
3491 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3496 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3497 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3501 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3503 /* Remove any network entry created based on the removed credential */
3504 ssid
= wpa_s
->conf
->ssid
;
3506 if (ssid
->parent_cred
== cred
) {
3509 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3510 "used the removed credential", ssid
->id
);
3511 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3512 if (os_snprintf_error(sizeof(str
), res
))
3513 str
[sizeof(str
) - 1] = '\0';
3515 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3524 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3528 struct wpa_cred
*cred
, *prev
;
3530 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3531 * "provisioning_sp=<FQDN> */
3532 if (os_strcmp(cmd
, "all") == 0) {
3533 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3534 cred
= wpa_s
->conf
->cred
;
3538 wpas_ctrl_remove_cred(wpa_s
, prev
);
3543 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3544 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3546 cred
= wpa_s
->conf
->cred
;
3552 for (i
= 0; i
< prev
->num_domain
; i
++) {
3553 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3556 wpas_ctrl_remove_cred(wpa_s
, prev
);
3564 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3565 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3567 cred
= wpa_s
->conf
->cred
;
3571 if (prev
->provisioning_sp
&&
3572 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3573 wpas_ctrl_remove_cred(wpa_s
, prev
);
3579 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3581 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3582 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3586 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3590 struct wpa_cred
*cred
;
3593 /* cmd: "<cred id> <variable name> <value>" */
3594 name
= os_strchr(cmd
, ' ');
3599 value
= os_strchr(name
, ' ');
3605 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3607 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3608 (u8
*) value
, os_strlen(value
));
3610 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3612 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3617 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3618 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3619 "variable '%s'", name
);
3623 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3629 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3630 char *cmd
, char *buf
,
3635 struct wpa_cred
*cred
;
3638 /* cmd: "<cred id> <variable name>" */
3639 name
= os_strchr(cmd
, ' ');
3645 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3648 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3650 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3655 value
= wpa_config_get_cred_no_key(cred
, name
);
3656 if (value
== NULL
) {
3657 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3662 res
= os_strlcpy(buf
, value
, buflen
);
3663 if (res
>= buflen
) {
3674 #ifndef CONFIG_NO_CONFIG_WRITE
3675 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3679 if (!wpa_s
->conf
->update_config
) {
3680 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3681 "to update configuration (update_config=0)");
3685 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3687 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3688 "update configuration");
3690 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3696 #endif /* CONFIG_NO_CONFIG_WRITE */
3699 struct cipher_info
{
3705 static const struct cipher_info ciphers
[] = {
3706 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3707 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3708 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3709 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3710 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3711 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3712 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3713 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3716 static const struct cipher_info ciphers_group_mgmt
[] = {
3717 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3718 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3719 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3720 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3724 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3725 struct wpa_driver_capa
*capa
,
3726 char *buf
, size_t buflen
)
3739 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3745 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3746 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3747 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3748 pos
== buf
? "" : " ",
3750 if (os_snprintf_error(end
- pos
, ret
))
3760 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3761 struct wpa_driver_capa
*capa
,
3762 char *buf
, size_t buflen
)
3775 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3781 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3782 if (capa
->enc
& ciphers
[i
].capa
) {
3783 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3784 pos
== buf
? "" : " ",
3786 if (os_snprintf_error(end
- pos
, ret
))
3796 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3797 struct wpa_driver_capa
*capa
,
3798 char *buf
, size_t buflen
)
3810 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3811 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3812 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3813 pos
== buf
? "" : " ",
3814 ciphers_group_mgmt
[i
].name
);
3815 if (os_snprintf_error(end
- pos
, ret
))
3825 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3826 struct wpa_driver_capa
*capa
,
3827 char *buf
, size_t buflen
)
3839 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3846 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3847 if (os_snprintf_error(end
- pos
, ret
))
3851 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3852 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3853 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3854 if (os_snprintf_error(end
- pos
, ret
))
3859 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3860 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3861 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3862 if (os_snprintf_error(end
- pos
, ret
))
3867 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3868 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3869 if (os_snprintf_error(end
- pos
, ret
))
3874 #ifdef CONFIG_SUITEB
3875 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3876 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3877 if (os_snprintf_error(end
- pos
, ret
))
3881 #endif /* CONFIG_SUITEB */
3882 #ifdef CONFIG_SUITEB192
3883 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3884 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3885 if (os_snprintf_error(end
- pos
, ret
))
3889 #endif /* CONFIG_SUITEB192 */
3891 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
3892 ret
= os_snprintf(pos
, end
- pos
, " OWE");
3893 if (os_snprintf_error(end
- pos
, ret
))
3897 #endif /* CONFIG_OWE */
3899 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
3900 ret
= os_snprintf(pos
, end
- pos
, " DPP");
3901 if (os_snprintf_error(end
- pos
, ret
))
3905 #endif /* CONFIG_DPP */
3907 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
3908 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
3909 if (os_snprintf_error(end
- pos
, ret
))
3913 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
3914 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
3915 if (os_snprintf_error(end
- pos
, ret
))
3919 #ifdef CONFIG_IEEE80211R
3920 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
3921 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
3922 if (os_snprintf_error(end
- pos
, ret
))
3926 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
3927 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
3928 if (os_snprintf_error(end
- pos
, ret
))
3932 #endif /* CONFIG_IEEE80211R */
3933 #endif /* CONFIG_FILS */
3939 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3940 struct wpa_driver_capa
*capa
,
3941 char *buf
, size_t buflen
)
3953 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3959 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3960 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3961 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3962 pos
== buf
? "" : " ");
3963 if (os_snprintf_error(end
- pos
, ret
))
3968 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3969 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3970 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3971 pos
== buf
? "" : " ");
3972 if (os_snprintf_error(end
- pos
, ret
))
3981 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
3982 int res
, char *strict
,
3983 struct wpa_driver_capa
*capa
,
3984 char *buf
, size_t buflen
)
3996 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4002 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4003 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4004 pos
== buf
? "" : " ");
4005 if (os_snprintf_error(end
- pos
, ret
))
4010 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4011 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4012 pos
== buf
? "" : " ");
4013 if (os_snprintf_error(end
- pos
, ret
))
4018 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4019 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4020 pos
== buf
? "" : " ");
4021 if (os_snprintf_error(end
- pos
, ret
))
4027 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4028 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4029 pos
== buf
? "" : " ");
4030 if (os_snprintf_error(end
- pos
, ret
))
4034 #endif /* CONFIG_SAE */
4037 if (wpa_is_fils_supported(wpa_s
)) {
4038 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4039 pos
== buf
? "" : " ");
4040 if (os_snprintf_error(end
- pos
, ret
))
4045 #ifdef CONFIG_FILS_SK_PFS
4046 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4047 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4048 pos
== buf
? "" : " ");
4049 if (os_snprintf_error(end
- pos
, ret
))
4053 #endif /* CONFIG_FILS_SK_PFS */
4054 #endif /* CONFIG_FILS */
4060 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4061 struct wpa_driver_capa
*capa
,
4062 char *buf
, size_t buflen
)
4074 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4080 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4081 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4082 pos
== buf
? "" : " ");
4083 if (os_snprintf_error(end
- pos
, ret
))
4088 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4089 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4090 pos
== buf
? "" : " ");
4091 if (os_snprintf_error(end
- pos
, ret
))
4097 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4098 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4099 pos
== buf
? "" : " ");
4100 if (os_snprintf_error(end
- pos
, ret
))
4104 #endif /* CONFIG_MESH */
4110 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4111 char *buf
, size_t buflen
)
4113 struct hostapd_channel_data
*chnl
;
4115 char *pos
, *end
, *hmode
;
4120 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4121 switch (wpa_s
->hw
.modes
[j
].mode
) {
4122 case HOSTAPD_MODE_IEEE80211B
:
4125 case HOSTAPD_MODE_IEEE80211G
:
4128 case HOSTAPD_MODE_IEEE80211A
:
4131 case HOSTAPD_MODE_IEEE80211AD
:
4137 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4138 if (os_snprintf_error(end
- pos
, ret
))
4141 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4142 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4143 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4145 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4146 if (os_snprintf_error(end
- pos
, ret
))
4150 ret
= os_snprintf(pos
, end
- pos
, "\n");
4151 if (os_snprintf_error(end
- pos
, ret
))
4160 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4161 char *buf
, size_t buflen
)
4163 struct hostapd_channel_data
*chnl
;
4165 char *pos
, *end
, *hmode
;
4170 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4171 switch (wpa_s
->hw
.modes
[j
].mode
) {
4172 case HOSTAPD_MODE_IEEE80211B
:
4175 case HOSTAPD_MODE_IEEE80211G
:
4178 case HOSTAPD_MODE_IEEE80211A
:
4181 case HOSTAPD_MODE_IEEE80211AD
:
4187 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4189 if (os_snprintf_error(end
- pos
, ret
))
4192 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4193 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4194 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4196 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4197 chnl
[i
].chan
, chnl
[i
].freq
,
4198 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4200 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4203 if (os_snprintf_error(end
- pos
, ret
))
4207 ret
= os_snprintf(pos
, end
- pos
, "\n");
4208 if (os_snprintf_error(end
- pos
, ret
))
4217 static int wpa_supplicant_ctrl_iface_get_capability(
4218 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4221 struct wpa_driver_capa capa
;
4227 /* Determine whether or not strict checking was requested */
4228 len
= os_strlcpy(field
, _field
, sizeof(field
));
4229 if (len
>= sizeof(field
))
4231 strict
= os_strchr(field
, ' ');
4232 if (strict
!= NULL
) {
4234 if (os_strcmp(strict
, "strict") != 0)
4238 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4239 field
, strict
? strict
: "");
4241 if (os_strcmp(field
, "eap") == 0) {
4242 return eap_get_names(buf
, buflen
);
4245 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4247 if (os_strcmp(field
, "pairwise") == 0)
4248 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4251 if (os_strcmp(field
, "group") == 0)
4252 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4255 if (os_strcmp(field
, "group_mgmt") == 0)
4256 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4259 if (os_strcmp(field
, "key_mgmt") == 0)
4260 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4263 if (os_strcmp(field
, "proto") == 0)
4264 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4267 if (os_strcmp(field
, "auth_alg") == 0)
4268 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4269 &capa
, buf
, buflen
);
4271 if (os_strcmp(field
, "modes") == 0)
4272 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4275 if (os_strcmp(field
, "channels") == 0)
4276 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4278 if (os_strcmp(field
, "freq") == 0)
4279 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4282 if (os_strcmp(field
, "tdls") == 0)
4283 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4284 #endif /* CONFIG_TDLS */
4287 if (os_strcmp(field
, "erp") == 0) {
4288 res
= os_snprintf(buf
, buflen
, "ERP");
4289 if (os_snprintf_error(buflen
, res
))
4293 #endif /* CONFIG_EPR */
4296 if (os_strcmp(field
, "fips") == 0) {
4297 res
= os_snprintf(buf
, buflen
, "FIPS");
4298 if (os_snprintf_error(buflen
, res
))
4302 #endif /* CONFIG_FIPS */
4305 if (os_strcmp(field
, "acs") == 0) {
4306 res
= os_snprintf(buf
, buflen
, "ACS");
4307 if (os_snprintf_error(buflen
, res
))
4311 #endif /* CONFIG_ACS */
4314 if (os_strcmp(field
, "fils") == 0) {
4315 #ifdef CONFIG_FILS_SK_PFS
4316 if (wpa_is_fils_supported(wpa_s
) &&
4317 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4318 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4319 if (os_snprintf_error(buflen
, res
))
4323 #endif /* CONFIG_FILS_SK_PFS */
4325 if (wpa_is_fils_supported(wpa_s
)) {
4326 res
= os_snprintf(buf
, buflen
, "FILS");
4327 if (os_snprintf_error(buflen
, res
))
4332 #endif /* CONFIG_FILS */
4334 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4341 #ifdef CONFIG_INTERWORKING
4342 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4343 struct wpabuf
*data
)
4353 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4354 if (os_snprintf_error(end
- pos
, ret
))
4358 d
= wpabuf_head_u8(data
);
4359 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4360 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4361 if (os_snprintf_error(end
- pos
, ret
))
4366 ret
= os_snprintf(pos
, end
- pos
, "\n");
4367 if (os_snprintf_error(end
- pos
, ret
))
4373 #endif /* CONFIG_INTERWORKING */
4377 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4380 const u8
*ie
, *ie_end
;
4384 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4387 ie_end
= ie
+ 2 + ie
[1];
4389 if (ie_end
- ie
< 2)
4392 info
= WPA_GET_LE16(ie
);
4394 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4395 if (os_snprintf_error(end
- pos
, ret
))
4399 if (info
& BIT(7)) {
4400 /* Cache Identifier Included */
4401 if (ie_end
- ie
< 2)
4403 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4405 if (os_snprintf_error(end
- pos
, ret
))
4411 if (info
& BIT(8)) {
4412 /* HESSID Included */
4413 if (ie_end
- ie
< ETH_ALEN
)
4415 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4417 if (os_snprintf_error(end
- pos
, ret
))
4423 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4425 if (ie_end
- ie
< realms
* 2)
4427 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4428 if (os_snprintf_error(end
- pos
, ret
))
4432 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4437 ret
= os_snprintf(pos
, end
- pos
, "\n");
4438 if (os_snprintf_error(end
- pos
, ret
))
4445 #endif /* CONFIG_FILS */
4448 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4449 unsigned long mask
, char *buf
, size_t buflen
)
4454 const u8
*ie
, *ie2
, *osen_ie
, *mesh
;
4459 if (mask
& WPA_BSS_MASK_ID
) {
4460 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4461 if (os_snprintf_error(end
- pos
, ret
))
4466 if (mask
& WPA_BSS_MASK_BSSID
) {
4467 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4468 MAC2STR(bss
->bssid
));
4469 if (os_snprintf_error(end
- pos
, ret
))
4474 if (mask
& WPA_BSS_MASK_FREQ
) {
4475 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4476 if (os_snprintf_error(end
- pos
, ret
))
4481 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4482 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4484 if (os_snprintf_error(end
- pos
, ret
))
4489 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4490 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4492 if (os_snprintf_error(end
- pos
, ret
))
4497 if (mask
& WPA_BSS_MASK_QUAL
) {
4498 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4499 if (os_snprintf_error(end
- pos
, ret
))
4504 if (mask
& WPA_BSS_MASK_NOISE
) {
4505 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4506 if (os_snprintf_error(end
- pos
, ret
))
4511 if (mask
& WPA_BSS_MASK_LEVEL
) {
4512 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4513 if (os_snprintf_error(end
- pos
, ret
))
4518 if (mask
& WPA_BSS_MASK_TSF
) {
4519 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4520 (unsigned long long) bss
->tsf
);
4521 if (os_snprintf_error(end
- pos
, ret
))
4526 if (mask
& WPA_BSS_MASK_AGE
) {
4527 struct os_reltime now
;
4529 os_get_reltime(&now
);
4530 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4531 (int) (now
.sec
- bss
->last_update
.sec
));
4532 if (os_snprintf_error(end
- pos
, ret
))
4537 if (mask
& WPA_BSS_MASK_IE
) {
4538 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4539 if (os_snprintf_error(end
- pos
, ret
))
4543 ie
= (const u8
*) (bss
+ 1);
4544 for (i
= 0; i
< bss
->ie_len
; i
++) {
4545 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4546 if (os_snprintf_error(end
- pos
, ret
))
4551 ret
= os_snprintf(pos
, end
- pos
, "\n");
4552 if (os_snprintf_error(end
- pos
, ret
))
4557 if (mask
& WPA_BSS_MASK_FLAGS
) {
4558 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4559 if (os_snprintf_error(end
- pos
, ret
))
4563 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4565 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4567 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4569 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4571 pos
= wpa_supplicant_ie_txt(pos
, end
,
4572 mesh
? "RSN" : "WPA2", ie2
,
4574 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4576 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4577 osen_ie
, 2 + osen_ie
[1]);
4578 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4579 if (!ie
&& !ie2
&& !osen_ie
&&
4580 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4581 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4582 if (os_snprintf_error(end
- pos
, ret
))
4588 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4589 if (os_snprintf_error(end
- pos
, ret
))
4594 if (bss_is_dmg(bss
)) {
4596 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4597 if (os_snprintf_error(end
- pos
, ret
))
4600 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4601 case IEEE80211_CAP_DMG_IBSS
:
4604 case IEEE80211_CAP_DMG_AP
:
4607 case IEEE80211_CAP_DMG_PBSS
:
4614 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4615 if (os_snprintf_error(end
- pos
, ret
))
4619 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4620 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4621 if (os_snprintf_error(end
- pos
, ret
))
4625 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4626 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4627 if (os_snprintf_error(end
- pos
, ret
))
4632 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4633 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4634 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4635 if (os_snprintf_error(end
- pos
, ret
))
4640 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4641 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4642 if (os_snprintf_error(end
- pos
, ret
))
4646 #endif /* CONFIG_HS20 */
4648 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4649 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4650 if (os_snprintf_error(end
- pos
, ret
))
4654 #endif /* CONFIG_FILS */
4656 ret
= os_snprintf(pos
, end
- pos
, "\n");
4657 if (os_snprintf_error(end
- pos
, ret
))
4662 if (mask
& WPA_BSS_MASK_SSID
) {
4663 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4664 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4665 if (os_snprintf_error(end
- pos
, ret
))
4671 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4672 ie
= (const u8
*) (bss
+ 1);
4673 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4674 if (ret
>= end
- pos
)
4679 #endif /* CONFIG_WPS */
4682 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4683 ie
= (const u8
*) (bss
+ 1);
4684 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4685 if (ret
>= end
- pos
)
4690 #endif /* CONFIG_P2P */
4692 #ifdef CONFIG_WIFI_DISPLAY
4693 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4695 ie
= (const u8
*) (bss
+ 1);
4696 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4697 WFD_IE_VENDOR_TYPE
);
4699 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4700 if (os_snprintf_error(end
- pos
, ret
)) {
4706 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4711 ret
= os_snprintf(pos
, end
- pos
, "\n");
4712 if (os_snprintf_error(end
- pos
, ret
))
4717 #endif /* CONFIG_WIFI_DISPLAY */
4719 #ifdef CONFIG_INTERWORKING
4720 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4721 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4722 struct wpa_bss_anqp_elem
*elem
;
4724 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4725 anqp
->capability_list
);
4726 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4728 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4729 anqp
->network_auth_type
);
4730 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4731 anqp
->roaming_consortium
);
4732 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4733 anqp
->ip_addr_type_availability
);
4734 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4736 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4737 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4739 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4740 anqp
->fils_realm_info
);
4742 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4743 anqp
->hs20_capability_list
);
4744 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4745 anqp
->hs20_operator_friendly_name
);
4746 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4747 anqp
->hs20_wan_metrics
);
4748 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4749 anqp
->hs20_connection_capability
);
4750 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4751 anqp
->hs20_operating_class
);
4752 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4753 anqp
->hs20_osu_providers_list
);
4754 #endif /* CONFIG_HS20 */
4756 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4757 struct wpa_bss_anqp_elem
, list
) {
4760 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4762 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4765 #endif /* CONFIG_INTERWORKING */
4768 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4769 ie
= (const u8
*) (bss
+ 1);
4770 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4771 if (ret
>= end
- pos
)
4776 #endif /* CONFIG_MESH */
4778 if (mask
& WPA_BSS_MASK_SNR
) {
4779 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4780 if (os_snprintf_error(end
- pos
, ret
))
4785 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4786 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4787 bss
->est_throughput
);
4788 if (os_snprintf_error(end
- pos
, ret
))
4794 if (mask
& WPA_BSS_MASK_FST
) {
4795 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4796 if (ret
< 0 || ret
>= end
- pos
)
4800 #endif /* CONFIG_FST */
4802 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4803 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4804 bss
->last_update_idx
);
4805 if (os_snprintf_error(end
- pos
, ret
))
4810 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4811 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4812 if (os_snprintf_error(end
- pos
, ret
))
4816 ie
= (const u8
*) (bss
+ 1);
4818 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4819 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4820 if (os_snprintf_error(end
- pos
, ret
))
4825 ret
= os_snprintf(pos
, end
- pos
, "\n");
4826 if (os_snprintf_error(end
- pos
, ret
))
4832 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4833 ret
= print_fils_indication(bss
, pos
, end
);
4838 #endif /* CONFIG_FILS */
4840 if (mask
& WPA_BSS_MASK_DELIM
) {
4841 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4842 if (os_snprintf_error(end
- pos
, ret
))
4851 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4852 const char *cmd
, char *buf
,
4857 struct wpa_bss
*bss
;
4858 struct wpa_bss
*bsslast
= NULL
;
4859 struct dl_list
*next
;
4862 char *ctmp
, *end
= buf
+ buflen
;
4863 unsigned long mask
= WPA_BSS_MASK_ALL
;
4865 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4866 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4867 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4869 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4871 } else { /* N1-N2 */
4872 unsigned int id1
, id2
;
4874 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4875 wpa_printf(MSG_INFO
, "Wrong BSS range "
4880 if (*(cmd
+ 6) == '-')
4883 id1
= atoi(cmd
+ 6);
4885 if (*ctmp
>= '0' && *ctmp
<= '9')
4888 id2
= (unsigned int) -1;
4889 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4890 if (id2
== (unsigned int) -1)
4891 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4895 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4896 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4897 struct wpa_bss
*tmp
= bss
;
4899 next
= tmp
->list_id
.next
;
4900 if (next
== &wpa_s
->bss_id
)
4902 tmp
= dl_list_entry(
4903 next
, struct wpa_bss
,
4912 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4913 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4914 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4915 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4916 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4918 bss
= wpa_bss_get_id(wpa_s
, i
);
4919 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4921 bss
= wpa_bss_get_id(wpa_s
, i
);
4923 next
= bss
->list_id
.next
;
4924 if (next
== &wpa_s
->bss_id
)
4927 bss
= dl_list_entry(next
, struct wpa_bss
,
4930 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
4931 bss
= wpa_s
->current_bss
;
4933 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4934 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4935 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4938 #endif /* CONFIG_P2P */
4939 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4940 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4942 struct wpa_bss
*tmp
;
4945 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4954 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4955 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4957 mask
= WPA_BSS_MASK_ALL
;
4963 if (bsslast
== NULL
)
4966 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4970 if (bss
== bsslast
) {
4971 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4972 (bss
== dl_list_last(&wpa_s
->bss_id
,
4973 struct wpa_bss
, list_id
))) {
4976 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4978 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4979 wpa_printf(MSG_DEBUG
,
4980 "Could not add end delim");
4985 next
= bss
->list_id
.next
;
4986 if (next
== &wpa_s
->bss_id
)
4988 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4989 } while (bss
&& len
);
4995 static int wpa_supplicant_ctrl_iface_ap_scan(
4996 struct wpa_supplicant
*wpa_s
, char *cmd
)
4998 int ap_scan
= atoi(cmd
);
4999 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5003 static int wpa_supplicant_ctrl_iface_scan_interval(
5004 struct wpa_supplicant
*wpa_s
, char *cmd
)
5006 int scan_int
= atoi(cmd
);
5007 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5011 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5012 struct wpa_supplicant
*wpa_s
, char *cmd
)
5014 int expire_age
= atoi(cmd
);
5015 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5019 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5020 struct wpa_supplicant
*wpa_s
, char *cmd
)
5022 int expire_count
= atoi(cmd
);
5023 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5027 static void wpa_supplicant_ctrl_iface_bss_flush(
5028 struct wpa_supplicant
*wpa_s
, char *cmd
)
5030 int flush_age
= atoi(cmd
);
5033 wpa_bss_flush(wpa_s
);
5035 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5039 #ifdef CONFIG_TESTING_OPTIONS
5040 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5042 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5043 /* MLME-DELETEKEYS.request */
5044 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
5045 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
5046 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
5047 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
5048 #ifdef CONFIG_IEEE80211W
5049 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
5050 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
5051 #endif /* CONFIG_IEEE80211W */
5053 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5055 /* MLME-SETPROTECTION.request(None) */
5056 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5057 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5058 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5059 wpa_sm_drop_sa(wpa_s
->wpa
);
5061 #endif /* CONFIG_TESTING_OPTIONS */
5064 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5067 #ifdef CONFIG_NO_SCAN_PROCESSING
5069 #else /* CONFIG_NO_SCAN_PROCESSING */
5071 struct wpa_bss
*bss
;
5072 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5074 if (hwaddr_aton(addr
, bssid
)) {
5075 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5076 "address '%s'", addr
);
5080 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5083 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5084 "configuration known for the target AP");
5088 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5090 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5096 * TODO: Find best network configuration block from configuration to
5097 * allow roaming to other networks
5100 wpa_s
->reassociate
= 1;
5101 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5104 #endif /* CONFIG_NO_SCAN_PROCESSING */
5109 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5111 unsigned int timeout
= atoi(cmd
);
5112 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5113 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5114 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5116 unsigned int search_delay
;
5117 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5121 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5122 wpa_dbg(wpa_s
, MSG_INFO
,
5123 "Reject P2P_FIND since interface is disabled");
5126 if (os_strstr(cmd
, "type=social"))
5127 type
= P2P_FIND_ONLY_SOCIAL
;
5128 else if (os_strstr(cmd
, "type=progressive"))
5129 type
= P2P_FIND_PROGRESSIVE
;
5131 pos
= os_strstr(cmd
, "dev_id=");
5134 if (hwaddr_aton(pos
, dev_id
))
5139 pos
= os_strstr(cmd
, "dev_type=");
5142 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5144 _dev_type
= dev_type
;
5147 pos
= os_strstr(cmd
, "delay=");
5150 search_delay
= atoi(pos
);
5152 search_delay
= wpas_p2p_search_delay(wpa_s
);
5154 pos
= os_strstr(cmd
, "freq=");
5162 /* Must be searched for last, because it adds nul termination */
5163 pos
= os_strstr(cmd
, " seek=");
5166 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5169 _seek
[seek_count
++] = pos
;
5171 term
= os_strchr(pos
, ' ');
5175 pos
= os_strstr(term
+ 1, "seek=");
5179 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5184 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5185 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5189 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5191 const char *last
= NULL
;
5196 /* Expected predefined CPT names delimited by ':' */
5197 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5198 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5199 wpa_printf(MSG_ERROR
,
5200 "P2PS: CPT name list is too long, expected up to %d names",
5201 P2PS_FEATURE_CAPAB_CPT_MAX
);
5206 token_len
= last
- token
;
5208 if (token_len
== 3 &&
5209 os_memcmp(token
, "UDP", token_len
) == 0) {
5210 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5211 } else if (token_len
== 3 &&
5212 os_memcmp(token
, "MAC", token_len
) == 0) {
5213 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5215 wpa_printf(MSG_ERROR
,
5216 "P2PS: Unsupported CPT name '%s'", token
);
5221 if (isblank((unsigned char) *last
)) {
5231 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5233 struct p2ps_provision
*p2ps_prov
;
5235 size_t info_len
= 0;
5237 u8 role
= P2PS_SETUP_NONE
;
5238 long long unsigned val
;
5241 pos
= os_strstr(cmd
, "info=");
5244 info_len
= os_strlen(pos
);
5247 info
= os_malloc(info_len
+ 1);
5249 info_len
= utf8_unescape(pos
, info_len
,
5250 info
, info_len
+ 1);
5256 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5257 if (p2ps_prov
== NULL
) {
5263 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5264 p2ps_prov
->info
[info_len
] = '\0';
5268 pos
= os_strstr(cmd
, "status=");
5270 p2ps_prov
->status
= atoi(pos
+ 7);
5272 p2ps_prov
->status
= -1;
5274 pos
= os_strstr(cmd
, "adv_id=");
5275 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5277 p2ps_prov
->adv_id
= val
;
5279 pos
= os_strstr(cmd
, "method=");
5281 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5283 p2ps_prov
->method
= 0;
5285 pos
= os_strstr(cmd
, "session=");
5286 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5288 p2ps_prov
->session_id
= val
;
5290 pos
= os_strstr(cmd
, "adv_mac=");
5291 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5294 pos
= os_strstr(cmd
, "session_mac=");
5295 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5298 pos
= os_strstr(cmd
, "cpt=");
5300 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5301 p2ps_prov
->cpt_priority
))
5304 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5307 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5308 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5310 /* force conncap with tstCap (no sanity checks) */
5311 pos
= os_strstr(cmd
, "tstCap=");
5313 role
= strtol(pos
+ 7, NULL
, 16);
5315 pos
= os_strstr(cmd
, "role=");
5317 role
= strtol(pos
+ 5, NULL
, 16);
5318 if (role
!= P2PS_SETUP_CLIENT
&&
5319 role
!= P2PS_SETUP_GROUP_OWNER
)
5320 role
= P2PS_SETUP_NONE
;
5323 p2ps_prov
->role
= role
;
5333 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5336 struct p2ps_provision
*p2ps_prov
;
5339 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5341 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5343 if (hwaddr_aton(cmd
, addr
))
5350 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5354 if (p2ps_prov
->status
< 0) {
5359 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5364 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5367 struct p2ps_provision
*p2ps_prov
;
5370 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5371 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5374 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5375 if (hwaddr_aton(cmd
, addr
))
5382 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5386 p2ps_prov
->pd_seeker
= 1;
5388 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5393 static int parse_freq(int chwidth
, int freq2
)
5398 return VHT_CHANWIDTH_80P80MHZ
;
5404 return VHT_CHANWIDTH_USE_HT
;
5406 return VHT_CHANWIDTH_80MHZ
;
5408 return VHT_CHANWIDTH_160MHZ
;
5410 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5417 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5418 char *buf
, size_t buflen
)
5423 enum p2p_wps_method wps_method
;
5426 int persistent_group
, persistent_id
= -1;
5433 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5434 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5435 size_t group_ssid_len
= 0;
5437 if (!wpa_s
->global
->p2p_init_wpa_s
)
5439 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5440 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5441 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5442 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5445 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5446 * [persistent|persistent=<network id>]
5447 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5448 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5450 if (hwaddr_aton(cmd
, addr
))
5458 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5459 pos2
= os_strstr(pos
, " persistent=");
5461 struct wpa_ssid
*ssid
;
5462 persistent_id
= atoi(pos2
+ 12);
5463 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5464 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5465 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5466 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5467 "SSID id=%d for persistent P2P group (GO)",
5472 join
= os_strstr(pos
, " join") != NULL
;
5473 auth
= os_strstr(pos
, " auth") != NULL
;
5474 automatic
= os_strstr(pos
, " auto") != NULL
;
5475 pd
= os_strstr(pos
, " provdisc") != NULL
;
5476 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5477 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5480 pos2
= os_strstr(pos
, " go_intent=");
5483 go_intent
= atoi(pos2
);
5484 if (go_intent
< 0 || go_intent
> 15)
5488 pos2
= os_strstr(pos
, " freq=");
5496 pos2
= os_strstr(pos
, " freq2=");
5498 freq2
= atoi(pos2
+ 7);
5500 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5502 chwidth
= atoi(pos2
+ 18);
5504 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5505 if (max_oper_chwidth
< 0)
5508 pos2
= os_strstr(pos
, " ssid=");
5513 end
= os_strchr(pos2
, ' ');
5515 group_ssid_len
= os_strlen(pos2
) / 2;
5517 group_ssid_len
= (end
- pos2
) / 2;
5518 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5519 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5521 group_ssid
= _group_ssid
;
5524 if (os_strncmp(pos
, "pin", 3) == 0) {
5525 /* Request random PIN (to be displayed) and enable the PIN */
5526 wps_method
= WPS_PIN_DISPLAY
;
5527 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5528 wps_method
= WPS_PBC
;
5529 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5530 wps_method
= WPS_P2PS
;
5533 pos
= os_strchr(pin
, ' ');
5534 wps_method
= WPS_PIN_KEYPAD
;
5537 if (os_strncmp(pos
, "display", 7) == 0)
5538 wps_method
= WPS_PIN_DISPLAY
;
5540 if (!wps_pin_str_valid(pin
)) {
5541 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5546 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5547 persistent_group
, automatic
, join
,
5548 auth
, go_intent
, freq
, freq2
, persistent_id
,
5549 pd
, ht40
, vht
, max_oper_chwidth
,
5550 group_ssid
, group_ssid_len
);
5551 if (new_pin
== -2) {
5552 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5555 if (new_pin
== -3) {
5556 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5561 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5562 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5563 if (os_snprintf_error(buflen
, ret
))
5568 os_memcpy(buf
, "OK\n", 3);
5573 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5575 unsigned int timeout
= atoi(cmd
);
5576 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5577 wpa_dbg(wpa_s
, MSG_INFO
,
5578 "Reject P2P_LISTEN since interface is disabled");
5581 return wpas_p2p_listen(wpa_s
, timeout
);
5585 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5589 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5591 /* <addr> <config method> [join|auto] */
5593 if (hwaddr_aton(cmd
, addr
))
5601 if (os_strstr(pos
, " join") != NULL
)
5602 use
= WPAS_P2P_PD_FOR_JOIN
;
5603 else if (os_strstr(pos
, " auto") != NULL
)
5604 use
= WPAS_P2P_PD_AUTO
;
5606 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5610 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5613 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5615 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5616 ssid
->passphrase
== NULL
)
5619 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5620 return os_strlen(buf
);
5624 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5625 char *buf
, size_t buflen
)
5629 u8 dst_buf
[ETH_ALEN
], *dst
;
5630 struct wpabuf
*tlvs
;
5634 if (hwaddr_aton(cmd
, dst_buf
))
5637 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5638 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5645 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5648 if (hexstr2bin(pos
, &version
, 1) < 0)
5654 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5655 #ifdef CONFIG_WIFI_DISPLAY
5656 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5657 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5658 #endif /* CONFIG_WIFI_DISPLAY */
5659 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5661 char *svc_info
= NULL
;
5665 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5668 pos
= os_strchr(pos
, ' ');
5669 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5674 pos
= os_strchr(svc_str
, ' ');
5679 /* All remaining data is the svc_info string */
5680 if (pos
&& pos
[0] && pos
[0] != ' ') {
5681 len
= os_strlen(pos
);
5683 /* Unescape in place */
5684 len
= utf8_unescape(pos
, len
, pos
, len
);
5691 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5694 len
= os_strlen(pos
);
5698 tlvs
= wpabuf_alloc(len
);
5701 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5706 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5711 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5712 if (os_snprintf_error(buflen
, res
))
5718 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5721 long long unsigned val
;
5723 if (sscanf(cmd
, "%llx", &val
) != 1)
5726 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5730 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5735 struct wpabuf
*resp_tlvs
;
5739 pos
= os_strchr(cmd
, ' ');
5747 if (hwaddr_aton(pos
, dst
))
5754 pos2
= os_strchr(pos
, ' ');
5758 dialog_token
= atoi(pos
);
5760 len
= os_strlen(pos2
);
5764 resp_tlvs
= wpabuf_alloc(len
);
5765 if (resp_tlvs
== NULL
)
5767 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5768 wpabuf_free(resp_tlvs
);
5772 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5773 wpabuf_free(resp_tlvs
);
5778 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5781 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5783 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5788 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5793 struct wpabuf
*query
, *resp
;
5795 pos
= os_strchr(cmd
, ' ');
5800 len
= os_strlen(cmd
);
5804 query
= wpabuf_alloc(len
);
5807 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5812 len
= os_strlen(pos
);
5818 resp
= wpabuf_alloc(len
);
5823 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5829 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5838 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5843 pos
= os_strchr(cmd
, ' ');
5848 if (hexstr2bin(cmd
, &version
, 1) < 0)
5851 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5855 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5856 u8 replace
, char *cmd
)
5860 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5861 char *svc_info
= NULL
;
5863 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5865 pos
= os_strchr(cmd
, ' ');
5870 /* Auto-Accept value is mandatory, and must be one of the
5871 * single values (0, 1, 2, 4) */
5872 auto_accept
= atoi(cmd
);
5873 switch (auto_accept
) {
5874 case P2PS_SETUP_NONE
: /* No auto-accept */
5875 case P2PS_SETUP_NEW
:
5876 case P2PS_SETUP_CLIENT
:
5877 case P2PS_SETUP_GROUP_OWNER
:
5883 /* Advertisement ID is mandatory */
5885 pos
= os_strchr(cmd
, ' ');
5890 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5891 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5894 /* Only allow replacements if exist, and adds if not */
5895 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5903 /* svc_state between 0 - 0xff is mandatory */
5904 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5907 pos
= os_strchr(pos
, ' ');
5911 /* config_methods is mandatory */
5913 if (sscanf(pos
, "%x", &config_methods
) != 1)
5916 if (!(config_methods
&
5917 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5920 pos
= os_strchr(pos
, ' ');
5927 /* Advertisement string is mandatory */
5928 if (!pos
[0] || pos
[0] == ' ')
5931 /* Terminate svc string */
5932 pos
= os_strchr(pos
, ' ');
5936 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5938 pos
= os_strchr(pos
, ' ');
5942 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5945 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5949 /* Service and Response Information are optional */
5950 if (pos
&& pos
[0]) {
5953 /* Note the bare ' included, which cannot exist legally
5954 * in unescaped string. */
5955 svc_info
= os_strstr(pos
, "svc_info='");
5959 len
= os_strlen(svc_info
);
5960 utf8_unescape(svc_info
, len
, svc_info
, len
);
5964 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
5965 (u8
) svc_state
, (u16
) config_methods
,
5966 svc_info
, cpt_prio
);
5970 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5974 pos
= os_strchr(cmd
, ' ');
5979 if (os_strcmp(cmd
, "bonjour") == 0)
5980 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
5981 if (os_strcmp(cmd
, "upnp") == 0)
5982 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
5983 if (os_strcmp(cmd
, "asp") == 0)
5984 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
5985 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5990 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
5994 struct wpabuf
*query
;
5997 len
= os_strlen(cmd
);
6001 query
= wpabuf_alloc(len
);
6004 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6009 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6015 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6020 pos
= os_strchr(cmd
, ' ');
6025 if (hexstr2bin(cmd
, &version
, 1) < 0)
6028 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6032 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6036 if (os_strcmp(cmd
, "all") == 0) {
6037 wpas_p2p_service_flush_asp(wpa_s
);
6041 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6044 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6048 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6052 pos
= os_strchr(cmd
, ' ');
6057 if (os_strcmp(cmd
, "bonjour") == 0)
6058 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6059 if (os_strcmp(cmd
, "upnp") == 0)
6060 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6061 if (os_strcmp(cmd
, "asp") == 0)
6062 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6063 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6068 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6072 pos
= os_strchr(cmd
, ' ');
6077 if (os_strcmp(cmd
, "asp") == 0)
6078 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6080 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6085 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6091 if (hwaddr_aton(cmd
, addr
))
6094 return wpas_p2p_reject(wpa_s
, addr
);
6098 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6102 struct wpa_ssid
*ssid
;
6103 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6104 int freq
= 0, pref_freq
= 0;
6105 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6108 pos
= os_strstr(cmd
, " peer=");
6111 if (hwaddr_aton(pos
, peer
))
6115 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6116 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6117 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6118 "for persistent P2P group",
6123 pos
= os_strstr(cmd
, " freq=");
6131 pos
= os_strstr(cmd
, " pref=");
6134 pref_freq
= atoi(pos
);
6139 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6140 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6143 pos
= os_strstr(cmd
, "freq2=");
6145 freq2
= atoi(pos
+ 6);
6147 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6149 chwidth
= atoi(pos
+ 18);
6151 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6152 if (max_oper_chwidth
< 0)
6155 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6156 max_oper_chwidth
, pref_freq
);
6160 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6163 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6165 pos
= os_strstr(cmd
, " peer=");
6171 if (hwaddr_aton(pos
, peer
)) {
6172 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6176 pos
= os_strstr(pos
, " go_dev_addr=");
6179 if (hwaddr_aton(pos
, go_dev_addr
)) {
6180 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6184 go_dev
= go_dev_addr
;
6187 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6191 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6193 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6194 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6195 if (os_strncmp(cmd
, "group=", 6) == 0)
6196 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6202 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6203 int id
, int freq
, int vht_center_freq2
,
6204 int ht40
, int vht
, int vht_chwidth
)
6206 struct wpa_ssid
*ssid
;
6208 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6209 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6210 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6211 "for persistent P2P group",
6216 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6217 vht_center_freq2
, 0, ht40
, vht
,
6218 vht_chwidth
, NULL
, 0, 0);
6222 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6224 int freq
= 0, persistent
= 0, group_id
= -1;
6225 int vht
= wpa_s
->conf
->p2p_go_vht
;
6226 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6227 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6228 char *token
, *context
= NULL
;
6230 while ((token
= str_token(cmd
, " ", &context
))) {
6231 if (sscanf(token
, "freq=%d", &freq
) == 1 ||
6232 sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6233 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6234 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6236 } else if (os_strcmp(token
, "ht40") == 0) {
6238 } else if (os_strcmp(token
, "vht") == 0) {
6241 } else if (os_strcmp(token
, "persistent") == 0) {
6244 wpa_printf(MSG_DEBUG
,
6245 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6251 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6252 if (max_oper_chwidth
< 0)
6256 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6257 freq
, freq2
, ht40
, vht
,
6260 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6265 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6266 char *buf
, size_t buflen
)
6268 u8 dev_addr
[ETH_ALEN
];
6269 struct wpa_ssid
*ssid
;
6273 ssid
= wpa_s
->current_ssid
;
6274 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6275 hwaddr_aton(cmd
, dev_addr
))
6278 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6281 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6282 if (os_snprintf_error(buflen
, res
))
6288 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6289 const u8
*p2p_dev_addr
)
6291 struct wpa_supplicant
*wpa_s
;
6293 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6294 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6302 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6303 char *buf
, size_t buflen
)
6305 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6307 const struct p2p_peer_info
*info
;
6309 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6310 struct wpa_ssid
*ssid
;
6313 if (!wpa_s
->global
->p2p
)
6316 if (os_strcmp(cmd
, "FIRST") == 0) {
6319 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6320 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6325 if (hwaddr_aton(cmd
, addr
) < 0)
6331 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6334 group_capab
= info
->group_capab
;
6337 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6338 wpa_printf(MSG_DEBUG
,
6339 "P2P: Could not find any BSS with p2p_dev_addr "
6340 MACSTR
", hence override group_capab from 0x%x to 0",
6341 MAC2STR(info
->p2p_device_addr
), group_capab
);
6348 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6354 "serial_number=%s\n"
6355 "config_methods=0x%x\n"
6357 "group_capab=0x%x\n"
6359 MAC2STR(info
->p2p_device_addr
),
6360 wps_dev_type_bin2str(info
->pri_dev_type
,
6361 devtype
, sizeof(devtype
)),
6366 info
->serial_number
,
6367 info
->config_methods
,
6371 if (os_snprintf_error(end
- pos
, res
))
6375 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6378 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6379 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6380 wps_dev_type_bin2str(t
, devtype
,
6382 if (os_snprintf_error(end
- pos
, res
))
6387 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6389 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6390 if (os_snprintf_error(end
- pos
, res
))
6395 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6400 if (info
->vendor_elems
) {
6401 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6402 if (os_snprintf_error(end
- pos
, res
))
6406 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6407 wpabuf_head(info
->vendor_elems
),
6408 wpabuf_len(info
->vendor_elems
));
6410 res
= os_snprintf(pos
, end
- pos
, "\n");
6411 if (os_snprintf_error(end
- pos
, res
))
6420 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6425 if (wpa_s
->global
->p2p
== NULL
)
6428 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6431 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6432 struct wpa_freq_range
*freq
;
6433 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6434 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6435 freq
->min
, freq
->max
);
6438 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6443 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6447 if (wpa_s
->global
->p2p
== NULL
)
6450 param
= os_strchr(cmd
, ' ');
6455 if (os_strcmp(cmd
, "discoverability") == 0) {
6456 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6461 if (os_strcmp(cmd
, "managed") == 0) {
6462 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6466 if (os_strcmp(cmd
, "listen_channel") == 0) {
6468 u8 channel
, op_class
;
6470 channel
= atoi(param
);
6471 pos
= os_strchr(param
, ' ');
6472 op_class
= pos
? atoi(pos
) : 81;
6474 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6478 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6479 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6483 if (os_strcmp(cmd
, "noa") == 0) {
6485 int count
, start
, duration
;
6486 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6487 count
= atoi(param
);
6488 pos
= os_strchr(param
, ',');
6493 pos
= os_strchr(pos
, ',');
6497 duration
= atoi(pos
);
6498 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6500 if (count
== 0 && duration
> 0)
6502 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6503 "start=%d duration=%d", count
, start
, duration
);
6504 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6507 if (os_strcmp(cmd
, "ps") == 0)
6508 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6510 if (os_strcmp(cmd
, "oppps") == 0)
6511 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6513 if (os_strcmp(cmd
, "ctwindow") == 0)
6514 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6516 if (os_strcmp(cmd
, "disabled") == 0) {
6517 wpa_s
->global
->p2p_disabled
= atoi(param
);
6518 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6519 wpa_s
->global
->p2p_disabled
?
6520 "disabled" : "enabled");
6521 if (wpa_s
->global
->p2p_disabled
) {
6522 wpas_p2p_stop_find(wpa_s
);
6523 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6524 p2p_flush(wpa_s
->global
->p2p
);
6529 if (os_strcmp(cmd
, "conc_pref") == 0) {
6530 if (os_strcmp(param
, "sta") == 0)
6531 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6532 else if (os_strcmp(param
, "p2p") == 0)
6533 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6535 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6538 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6543 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6544 wpa_s
->force_long_sd
= atoi(param
);
6548 if (os_strcmp(cmd
, "peer_filter") == 0) {
6550 if (hwaddr_aton(param
, addr
))
6552 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6556 if (os_strcmp(cmd
, "cross_connect") == 0)
6557 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6559 if (os_strcmp(cmd
, "go_apsd") == 0) {
6560 if (os_strcmp(param
, "disable") == 0)
6561 wpa_s
->set_ap_uapsd
= 0;
6563 wpa_s
->set_ap_uapsd
= 1;
6564 wpa_s
->ap_uapsd
= atoi(param
);
6569 if (os_strcmp(cmd
, "client_apsd") == 0) {
6570 if (os_strcmp(param
, "disable") == 0)
6571 wpa_s
->set_sta_uapsd
= 0;
6575 /* format: BE,BK,VI,VO;max SP Length */
6577 pos
= os_strchr(param
, ',');
6582 pos
= os_strchr(pos
, ',');
6587 pos
= os_strchr(pos
, ',');
6592 /* ignore max SP Length for now */
6594 wpa_s
->set_sta_uapsd
= 1;
6595 wpa_s
->sta_uapsd
= 0;
6597 wpa_s
->sta_uapsd
|= BIT(0);
6599 wpa_s
->sta_uapsd
|= BIT(1);
6601 wpa_s
->sta_uapsd
|= BIT(2);
6603 wpa_s
->sta_uapsd
|= BIT(3);
6608 if (os_strcmp(cmd
, "disallow_freq") == 0)
6609 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6611 if (os_strcmp(cmd
, "disc_int") == 0) {
6612 int min_disc_int
, max_disc_int
, max_disc_tu
;
6617 min_disc_int
= atoi(pos
);
6618 pos
= os_strchr(pos
, ' ');
6623 max_disc_int
= atoi(pos
);
6624 pos
= os_strchr(pos
, ' ');
6629 max_disc_tu
= atoi(pos
);
6631 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6632 max_disc_int
, max_disc_tu
);
6635 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6636 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6640 #ifdef CONFIG_WPS_NFC
6641 if (os_strcmp(cmd
, "nfc_tag") == 0)
6642 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6643 #endif /* CONFIG_WPS_NFC */
6645 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6646 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6650 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6653 op_class
= atoi(param
);
6654 param
= os_strchr(param
, ':');
6659 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6664 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6671 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6673 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6674 wpa_s
->force_long_sd
= 0;
6676 #ifdef CONFIG_TESTING_OPTIONS
6677 os_free(wpa_s
->get_pref_freq_list_override
);
6678 wpa_s
->get_pref_freq_list_override
= NULL
;
6679 #endif /* CONFIG_TESTING_OPTIONS */
6681 wpas_p2p_stop_find(wpa_s
);
6682 wpa_s
->parent
->p2ps_method_config_any
= 0;
6683 if (wpa_s
->global
->p2p
)
6684 p2p_flush(wpa_s
->global
->p2p
);
6688 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6691 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6694 pos
= os_strchr(cmd
, ' ');
6700 pos2
= os_strchr(pos
, ' ');
6708 pos
= os_strchr(pos2
, ' ');
6716 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6720 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6723 unsigned int period
= 0, interval
= 0;
6726 pos
= os_strchr(cmd
, ' ');
6731 interval
= atoi(pos
);
6734 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6738 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6745 if (os_strncmp(pos
, "iface=", 6) == 0) {
6749 if (hwaddr_aton(pos
, peer
))
6752 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6757 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6759 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6761 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6763 wpa_printf(MSG_DEBUG
,
6764 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6768 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6771 #endif /* CONFIG_P2P */
6774 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6776 struct wpa_freq_range_list ranges
;
6778 struct hostapd_hw_modes
*mode
;
6781 if (wpa_s
->hw
.modes
== NULL
)
6784 os_memset(&ranges
, 0, sizeof(ranges
));
6785 if (freq_range_list_parse(&ranges
, val
) < 0)
6788 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6791 mode
= &wpa_s
->hw
.modes
[i
];
6792 for (j
= 0; j
< mode
->num_channels
; j
++) {
6795 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6798 freq
= mode
->channels
[j
].freq
;
6799 if (!freq_range_list_includes(&ranges
, freq
))
6802 int_array_add_unique(&freqs
, freq
);
6806 os_free(ranges
.range
);
6811 #ifdef CONFIG_INTERWORKING
6813 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6821 auto_sel
= os_strstr(param
, "auto") != NULL
;
6823 pos
= os_strstr(param
, "freq=");
6825 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6832 return interworking_select(wpa_s
, auto_sel
, freqs
);
6836 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6840 struct wpa_bss
*bss
;
6842 if (hwaddr_aton(dst
, bssid
)) {
6843 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6847 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6849 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6854 if (bss
->ssid_len
== 0) {
6857 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6858 " does not have SSID information", MAC2STR(bssid
));
6860 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6862 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6863 bss
->ssid_len
> 0) {
6871 wpa_printf(MSG_DEBUG
,
6872 "Found another matching BSS entry with SSID");
6875 return interworking_connect(wpa_s
, bss
, only_add
);
6879 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6881 u8 dst_addr
[ETH_ALEN
];
6884 #define MAX_ANQP_INFO_ID 100
6885 u16 id
[MAX_ANQP_INFO_ID
];
6888 u32 mbo_subtypes
= 0;
6890 used
= hwaddr_aton2(dst
, dst_addr
);
6896 while (num_id
< MAX_ANQP_INFO_ID
) {
6897 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6899 int num
= atoi(pos
+ 5);
6900 if (num
<= 0 || num
> 31)
6902 subtypes
|= BIT(num
);
6903 #else /* CONFIG_HS20 */
6905 #endif /* CONFIG_HS20 */
6906 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6908 int num
= atoi(pos
+ 4);
6910 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
6912 mbo_subtypes
|= BIT(num
);
6913 #else /* CONFIG_MBO */
6915 #endif /* CONFIG_MBO */
6917 id
[num_id
] = atoi(pos
);
6921 pos
= os_strchr(pos
+ 1, ',');
6927 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
6930 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
6935 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
6937 u8 dst_addr
[ETH_ALEN
];
6938 struct wpabuf
*advproto
, *query
= NULL
;
6943 used
= hwaddr_aton2(cmd
, dst_addr
);
6951 /* Advertisement Protocol ID */
6952 end
= os_strchr(pos
, ' ');
6956 len
= os_strlen(pos
);
6962 advproto
= wpabuf_alloc(len
);
6963 if (advproto
== NULL
)
6965 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
6969 /* Optional Query Request */
6974 len
= os_strlen(pos
);
6981 query
= wpabuf_alloc(len
);
6984 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
6989 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
6992 wpabuf_free(advproto
);
6999 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7006 size_t resp_len
, start
, requested_len
;
7007 struct wpabuf
*resp
;
7010 used
= hwaddr_aton2(cmd
, addr
);
7017 dialog_token
= atoi(pos
);
7019 if (wpa_s
->last_gas_resp
&&
7020 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7021 dialog_token
== wpa_s
->last_gas_dialog_token
)
7022 resp
= wpa_s
->last_gas_resp
;
7023 else if (wpa_s
->prev_gas_resp
&&
7024 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7025 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7026 resp
= wpa_s
->prev_gas_resp
;
7030 resp_len
= wpabuf_len(resp
);
7032 requested_len
= resp_len
;
7034 pos
= os_strchr(pos
, ' ');
7037 if (start
> resp_len
)
7038 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7039 pos
= os_strchr(pos
, ',');
7043 requested_len
= atoi(pos
);
7044 if (start
+ requested_len
> resp_len
)
7045 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7048 if (requested_len
* 2 + 1 > buflen
)
7049 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7051 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7054 if (start
+ requested_len
== resp_len
) {
7056 * Free memory by dropping the response after it has been
7059 if (resp
== wpa_s
->prev_gas_resp
) {
7060 wpabuf_free(wpa_s
->prev_gas_resp
);
7061 wpa_s
->prev_gas_resp
= NULL
;
7063 wpabuf_free(wpa_s
->last_gas_resp
);
7064 wpa_s
->last_gas_resp
= NULL
;
7070 #endif /* CONFIG_INTERWORKING */
7075 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7077 u8 dst_addr
[ETH_ALEN
];
7082 used
= hwaddr_aton2(dst
, dst_addr
);
7089 int num
= atoi(pos
);
7090 if (num
<= 0 || num
> 31)
7092 subtypes
|= BIT(num
);
7093 pos
= os_strchr(pos
+ 1, ',');
7102 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7106 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7107 const u8
*addr
, const char *realm
)
7113 rlen
= os_strlen(realm
);
7115 buf
= os_malloc(len
);
7118 buf
[0] = 1; /* NAI Home Realm Count */
7119 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7121 os_memcpy(buf
+ 3, realm
, rlen
);
7123 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7124 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7133 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7136 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7137 u8 dst_addr
[ETH_ALEN
];
7143 used
= hwaddr_aton2(dst
, dst_addr
);
7147 while (dst
[used
] == ' ')
7149 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7150 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7153 len
= os_strlen(dst
+ used
);
7155 if (len
== 0 && cred
&& cred
->realm
)
7156 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7161 buf
= os_malloc(len
);
7164 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7169 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7170 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7178 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7181 u8 dst_addr
[ETH_ALEN
];
7183 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7185 used
= hwaddr_aton2(cmd
, dst_addr
);
7190 icon
= str_token(cmd
, " ", &ctx
);
7191 poffset
= str_token(cmd
, " ", &ctx
);
7192 psize
= str_token(cmd
, " ", &ctx
);
7193 if (!icon
|| !poffset
|| !psize
)
7196 wpa_s
->fetch_osu_icon_in_progress
= 0;
7197 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7202 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7204 u8 dst_addr
[ETH_ALEN
];
7209 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7211 used
= hwaddr_aton2(cmd
, dst_addr
);
7215 while (cmd
[used
] == ' ')
7217 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7219 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7223 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7225 u8 dst_addr
[ETH_ALEN
];
7229 used
= hwaddr_aton2(cmd
, dst_addr
);
7233 while (cmd
[used
] == ' ')
7237 wpa_s
->fetch_osu_icon_in_progress
= 0;
7238 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7239 (u8
*) icon
, os_strlen(icon
), inmem
);
7242 #endif /* CONFIG_HS20 */
7245 #ifdef CONFIG_AUTOSCAN
7247 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7250 enum wpa_states state
= wpa_s
->wpa_state
;
7251 char *new_params
= NULL
;
7253 if (os_strlen(cmd
) > 0) {
7254 new_params
= os_strdup(cmd
);
7255 if (new_params
== NULL
)
7259 os_free(wpa_s
->conf
->autoscan
);
7260 wpa_s
->conf
->autoscan
= new_params
;
7262 if (wpa_s
->conf
->autoscan
== NULL
)
7263 autoscan_deinit(wpa_s
);
7264 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7265 autoscan_init(wpa_s
, 1);
7266 else if (state
== WPA_SCANNING
)
7267 wpa_supplicant_reinit_autoscan(wpa_s
);
7269 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7270 wpa_supplicant_state_txt(state
));
7275 #endif /* CONFIG_AUTOSCAN */
7280 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7286 struct wpabuf
*tfs_req
= NULL
;
7288 if (os_strncmp(cmd
, "enter", 5) == 0)
7290 else if (os_strncmp(cmd
, "exit", 4) == 0)
7295 pos
= os_strstr(cmd
, " interval=");
7297 intval
= atoi(pos
+ 10);
7299 pos
= os_strstr(cmd
, " tfs_req=");
7304 end
= os_strchr(pos
, ' ');
7308 len
= os_strlen(pos
);
7312 tfs_req
= wpabuf_alloc(len
);
7313 if (tfs_req
== NULL
)
7315 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7316 wpabuf_free(tfs_req
);
7321 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7322 WNM_SLEEP_MODE_EXIT
, intval
,
7324 wpabuf_free(tfs_req
);
7330 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7332 int query_reason
, list
= 0;
7333 char *btm_candidates
= NULL
;
7335 query_reason
= atoi(cmd
);
7337 cmd
= os_strchr(cmd
, ' ');
7339 if (os_strncmp(cmd
, " list", 5) == 0)
7342 btm_candidates
= cmd
;
7345 wpa_printf(MSG_DEBUG
,
7346 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7347 query_reason
, list
? " candidate list" : "");
7349 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7354 #endif /* CONFIG_WNM */
7357 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7360 struct wpa_signal_info si
;
7364 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7371 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7372 "NOISE=%d\nFREQUENCY=%u\n",
7373 si
.current_signal
, si
.current_txrate
/ 1000,
7374 si
.current_noise
, si
.frequency
);
7375 if (os_snprintf_error(end
- pos
, ret
))
7379 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7380 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7381 channel_width_to_string(si
.chanwidth
));
7382 if (os_snprintf_error(end
- pos
, ret
))
7387 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
7388 ret
= os_snprintf(pos
, end
- pos
,
7389 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7390 si
.center_frq1
, si
.center_frq2
);
7391 if (os_snprintf_error(end
- pos
, ret
))
7396 if (si
.avg_signal
) {
7397 ret
= os_snprintf(pos
, end
- pos
,
7398 "AVG_RSSI=%d\n", si
.avg_signal
);
7399 if (os_snprintf_error(end
- pos
, ret
))
7404 if (si
.avg_beacon_signal
) {
7405 ret
= os_snprintf(pos
, end
- pos
,
7406 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7407 if (os_snprintf_error(end
- pos
, ret
))
7416 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7423 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7424 wpa_printf(MSG_DEBUG
,
7425 "Reject SIGNAL_MONITOR command - bgscan is active");
7428 pos
= os_strstr(cmd
, "THRESHOLD=");
7430 threshold
= atoi(pos
+ 10);
7431 pos
= os_strstr(cmd
, "HYSTERESIS=");
7433 hysteresis
= atoi(pos
+ 11);
7434 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7438 #ifdef CONFIG_TESTING_OPTIONS
7439 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7440 enum wpa_driver_if_type if_type
,
7442 unsigned int *freq_list
)
7444 char *pos
= wpa_s
->get_pref_freq_list_override
;
7446 unsigned int count
= 0;
7448 /* Override string format:
7449 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7452 if (atoi(pos
) == (int) if_type
)
7454 pos
= os_strchr(pos
, ' ');
7460 pos
= os_strchr(pos
, ':');
7464 end
= os_strchr(pos
, ' ');
7465 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7466 freq_list
[count
++] = atoi(pos
);
7467 pos
= os_strchr(pos
, ',');
7475 #endif /* CONFIG_TESTING_OPTIONS */
7478 static int wpas_ctrl_iface_get_pref_freq_list(
7479 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7481 unsigned int freq_list
[100], num
= 100, i
;
7483 enum wpa_driver_if_type iface_type
;
7489 /* buf: "<interface_type>" */
7490 if (os_strcmp(cmd
, "STATION") == 0)
7491 iface_type
= WPA_IF_STATION
;
7492 else if (os_strcmp(cmd
, "AP") == 0)
7493 iface_type
= WPA_IF_AP_BSS
;
7494 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7495 iface_type
= WPA_IF_P2P_GO
;
7496 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7497 iface_type
= WPA_IF_P2P_CLIENT
;
7498 else if (os_strcmp(cmd
, "IBSS") == 0)
7499 iface_type
= WPA_IF_IBSS
;
7500 else if (os_strcmp(cmd
, "TDLS") == 0)
7501 iface_type
= WPA_IF_TDLS
;
7505 wpa_printf(MSG_DEBUG
,
7506 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7509 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7513 for (i
= 0; i
< num
; i
++) {
7514 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7515 i
> 0 ? "," : "", freq_list
[i
]);
7516 if (os_snprintf_error(end
- pos
, ret
))
7525 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7526 char *buf
, size_t buflen
)
7531 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7532 (long long unsigned) wpa_s
->drv_flags
);
7533 if (os_snprintf_error(buflen
, ret
))
7539 for (i
= 0; i
< 64; i
++) {
7540 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7541 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7542 driver_flag_to_string(1LLU << i
));
7543 if (os_snprintf_error(end
- pos
, ret
))
7553 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7556 struct hostap_sta_driver_data sta
;
7559 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7563 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7564 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7565 if (os_snprintf_error(buflen
, ret
))
7572 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7573 char *buf
, size_t buflen
)
7577 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7579 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7580 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7583 country
[0] = cmd
[8];
7584 country
[1] = cmd
[9];
7586 p2p_set_country(p2p
, country
);
7589 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7590 if (os_snprintf_error(buflen
, ret
))
7595 #endif /* ANDROID */
7598 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7599 char *buf
, size_t buflen
)
7604 unsigned int vendor_id
, subcmd
;
7605 struct wpabuf
*reply
;
7606 size_t data_len
= 0;
7608 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7609 vendor_id
= strtoul(cmd
, &pos
, 16);
7610 if (!isblank((unsigned char) *pos
))
7613 subcmd
= strtoul(pos
, &pos
, 10);
7616 if (!isblank((unsigned char) *pos
++))
7618 data_len
= os_strlen(pos
);
7623 data
= os_malloc(data_len
);
7627 if (hexstr2bin(pos
, data
, data_len
)) {
7628 wpa_printf(MSG_DEBUG
,
7629 "Vendor command: wrong parameter format");
7635 reply
= wpabuf_alloc((buflen
- 1) / 2);
7641 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7645 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7655 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7658 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7659 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7660 #endif /* CONFIG_P2P */
7662 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7664 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7665 wpa_s
->ignore_post_flush_scan_res
= 1;
7667 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7669 * Avoid possible auto connect re-connection on getting
7670 * disconnected due to state flush.
7672 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7676 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7677 wpas_p2p_cancel(p2p_wpa_s
);
7678 p2p_ctrl_flush(p2p_wpa_s
);
7679 wpas_p2p_service_flush(p2p_wpa_s
);
7680 p2p_wpa_s
->global
->p2p_disabled
= 0;
7681 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7682 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7683 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7684 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7685 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7686 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7687 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7688 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7689 #endif /* CONFIG_P2P */
7691 #ifdef CONFIG_WPS_TESTING
7692 wps_version_number
= 0x20;
7693 wps_testing_dummy_cred
= 0;
7694 wps_corrupt_pkhash
= 0;
7695 wps_force_auth_types_in_use
= 0;
7696 wps_force_encr_types_in_use
= 0;
7697 #endif /* CONFIG_WPS_TESTING */
7699 wpa_s
->wps_fragment_size
= 0;
7700 wpas_wps_cancel(wpa_s
);
7701 wps_registrar_flush(wpa_s
->wps
->registrar
);
7702 #endif /* CONFIG_WPS */
7703 wpa_s
->after_wps
= 0;
7704 wpa_s
->known_wps_freq
= 0;
7707 wpas_dpp_deinit(wpa_s
);
7708 #endif /* CONFIG_DPP */
7711 #ifdef CONFIG_TDLS_TESTING
7713 #endif /* CONFIG_TDLS_TESTING */
7714 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7715 wpa_tdls_enable(wpa_s
->wpa
, 1);
7716 #endif /* CONFIG_TDLS */
7718 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7719 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7721 wpa_s
->no_keep_alive
= 0;
7722 wpa_s
->own_disconnect_req
= 0;
7724 os_free(wpa_s
->disallow_aps_bssid
);
7725 wpa_s
->disallow_aps_bssid
= NULL
;
7726 wpa_s
->disallow_aps_bssid_count
= 0;
7727 os_free(wpa_s
->disallow_aps_ssid
);
7728 wpa_s
->disallow_aps_ssid
= NULL
;
7729 wpa_s
->disallow_aps_ssid_count
= 0;
7731 wpa_s
->set_sta_uapsd
= 0;
7732 wpa_s
->sta_uapsd
= 0;
7734 wpa_drv_radio_disable(wpa_s
, 0);
7735 wpa_blacklist_clear(wpa_s
);
7736 wpa_s
->extra_blacklist_count
= 0;
7737 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7738 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7739 wpa_config_flush_blobs(wpa_s
->conf
);
7740 wpa_s
->conf
->auto_interworking
= 0;
7741 wpa_s
->conf
->okc
= 0;
7743 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7744 rsn_preauth_deinit(wpa_s
->wpa
);
7746 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7747 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7748 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7749 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7751 radio_remove_works(wpa_s
, NULL
, 1);
7752 wpa_s
->ext_work_in_progress
= 0;
7754 wpa_s
->next_ssid
= NULL
;
7756 #ifdef CONFIG_INTERWORKING
7758 hs20_cancel_fetch_osu(wpa_s
);
7759 hs20_del_icon(wpa_s
, NULL
, NULL
);
7760 #endif /* CONFIG_HS20 */
7761 #endif /* CONFIG_INTERWORKING */
7763 wpa_s
->ext_mgmt_frame_handling
= 0;
7764 wpa_s
->ext_eapol_frame_io
= 0;
7765 #ifdef CONFIG_TESTING_OPTIONS
7766 wpa_s
->extra_roc_dur
= 0;
7767 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7768 wpa_s
->p2p_go_csa_on_inv
= 0;
7769 wpa_s
->ignore_auth_resp
= 0;
7770 wpa_s
->ignore_assoc_disallow
= 0;
7771 wpa_s
->reject_btm_req_reason
= 0;
7772 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7773 os_free(wpa_s
->get_pref_freq_list_override
);
7774 wpa_s
->get_pref_freq_list_override
= NULL
;
7775 wpabuf_free(wpa_s
->sae_commit_override
);
7776 wpa_s
->sae_commit_override
= NULL
;
7777 #endif /* CONFIG_TESTING_OPTIONS */
7779 wpa_s
->disconnected
= 0;
7780 os_free(wpa_s
->next_scan_freqs
);
7781 wpa_s
->next_scan_freqs
= NULL
;
7782 os_free(wpa_s
->select_network_scan_freqs
);
7783 wpa_s
->select_network_scan_freqs
= NULL
;
7785 wpa_bss_flush(wpa_s
);
7786 if (!dl_list_empty(&wpa_s
->bss
)) {
7787 wpa_printf(MSG_DEBUG
,
7788 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7789 MACSTR
" pending_bssid=" MACSTR
,
7790 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7791 MAC2STR(wpa_s
->bssid
),
7792 MAC2STR(wpa_s
->pending_bssid
));
7795 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7796 wpa_s
->wnmsleep_used
= 0;
7799 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7800 #endif /* CONFIG_SME */
7802 wpabuf_free(wpa_s
->ric_ies
);
7803 wpa_s
->ric_ies
= NULL
;
7807 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7808 char *buf
, size_t buflen
)
7810 struct wpa_radio_work
*work
;
7812 struct os_reltime now
, diff
;
7817 os_get_reltime(&now
);
7819 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7823 os_reltime_sub(&now
, &work
->time
, &diff
);
7824 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7825 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7826 work
->started
, diff
.sec
, diff
.usec
);
7827 if (os_snprintf_error(end
- pos
, ret
))
7836 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7838 struct wpa_radio_work
*work
= eloop_ctx
;
7839 struct wpa_external_work
*ework
= work
->ctx
;
7841 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7842 "Timing out external radio work %u (%s)",
7843 ework
->id
, work
->type
);
7844 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7845 work
->wpa_s
->ext_work_in_progress
= 0;
7846 radio_work_done(work
);
7851 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7853 struct wpa_external_work
*ework
= work
->ctx
;
7857 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7861 * work->type points to a buffer in ework, so need to replace
7862 * that here with a fixed string to avoid use of freed memory
7865 work
->type
= "freed-ext-work";
7871 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7872 ework
->id
, ework
->type
);
7873 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7874 work
->wpa_s
->ext_work_in_progress
= 1;
7875 if (!ework
->timeout
)
7876 ework
->timeout
= 10;
7877 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7882 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7883 char *buf
, size_t buflen
)
7885 struct wpa_external_work
*ework
;
7889 unsigned int freq
= 0;
7891 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7893 ework
= os_zalloc(sizeof(*ework
));
7897 pos
= os_strchr(cmd
, ' ');
7899 type_len
= pos
- cmd
;
7902 pos2
= os_strstr(pos
, "freq=");
7904 freq
= atoi(pos2
+ 5);
7906 pos2
= os_strstr(pos
, "timeout=");
7908 ework
->timeout
= atoi(pos2
+ 8);
7910 type_len
= os_strlen(cmd
);
7912 if (4 + type_len
>= sizeof(ework
->type
))
7913 type_len
= sizeof(ework
->type
) - 4 - 1;
7914 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
7915 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
7916 ework
->type
[4 + type_len
] = '\0';
7918 wpa_s
->ext_work_id
++;
7919 if (wpa_s
->ext_work_id
== 0)
7920 wpa_s
->ext_work_id
++;
7921 ework
->id
= wpa_s
->ext_work_id
;
7923 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
7929 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
7930 if (os_snprintf_error(buflen
, ret
))
7936 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
7938 struct wpa_radio_work
*work
;
7939 unsigned int id
= atoi(cmd
);
7941 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7943 struct wpa_external_work
*ework
;
7945 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7948 if (id
&& ework
->id
!= id
)
7950 wpa_dbg(wpa_s
, MSG_DEBUG
,
7951 "Completed external radio work %u (%s)",
7952 ework
->id
, ework
->type
);
7953 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
7954 wpa_s
->ext_work_in_progress
= 0;
7955 radio_work_done(work
);
7957 return 3; /* "OK\n" */
7964 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
7965 char *buf
, size_t buflen
)
7967 if (os_strcmp(cmd
, "show") == 0)
7968 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
7969 if (os_strncmp(cmd
, "add ", 4) == 0)
7970 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
7971 if (os_strncmp(cmd
, "done ", 5) == 0)
7972 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
7977 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
7979 struct wpa_radio_work
*work
, *tmp
;
7981 if (!wpa_s
|| !wpa_s
->radio
)
7984 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
7985 struct wpa_radio_work
, list
) {
7986 struct wpa_external_work
*ework
;
7988 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7991 wpa_dbg(wpa_s
, MSG_DEBUG
,
7992 "Flushing%s external radio work %u (%s)",
7993 work
->started
? " started" : "", ework
->id
,
7996 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7998 radio_work_done(work
);
8004 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8006 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8007 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8011 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8012 unsigned int *scan_id_count
, int scan_id
[])
8014 const char *pos
= value
;
8017 if (*pos
== ' ' || *pos
== '\0')
8019 if (*scan_id_count
== MAX_SCAN_ID
)
8021 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8022 pos
= os_strchr(pos
, ',');
8031 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8032 char *reply
, int reply_size
, int *reply_len
)
8035 unsigned int manual_scan_passive
= 0;
8036 unsigned int manual_scan_use_id
= 0;
8037 unsigned int manual_scan_only_new
= 0;
8038 unsigned int scan_only
= 0;
8039 unsigned int scan_id_count
= 0;
8040 int scan_id
[MAX_SCAN_ID
];
8041 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8042 struct wpa_scan_results
*scan_res
);
8043 int *manual_scan_freqs
= NULL
;
8044 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8045 unsigned int ssid_count
= 0;
8047 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8052 if (radio_work_pending(wpa_s
, "scan")) {
8053 wpa_printf(MSG_DEBUG
,
8054 "Pending scan scheduled - reject new request");
8055 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8059 #ifdef CONFIG_INTERWORKING
8060 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8061 wpa_printf(MSG_DEBUG
,
8062 "Interworking select in progress - reject new scan");
8063 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8066 #endif /* CONFIG_INTERWORKING */
8069 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8072 pos
= os_strstr(params
, "freq=");
8074 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8076 if (manual_scan_freqs
== NULL
) {
8082 pos
= os_strstr(params
, "passive=");
8084 manual_scan_passive
= !!atoi(pos
+ 8);
8086 pos
= os_strstr(params
, "use_id=");
8088 manual_scan_use_id
= atoi(pos
+ 7);
8090 pos
= os_strstr(params
, "only_new=1");
8092 manual_scan_only_new
= 1;
8094 pos
= os_strstr(params
, "scan_id=");
8095 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8101 pos
= os_strstr(params
, "bssid=");
8106 if (hwaddr_aton(pos
, bssid
)) {
8107 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8111 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8115 while (pos
&& *pos
!= '\0') {
8116 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8122 if (*end
== '\0' || *end
== ' ')
8127 ns
= os_realloc_array(
8128 ssid
, ssid_count
+ 1,
8129 sizeof(struct wpa_ssid_value
));
8136 if ((end
- pos
) & 0x01 ||
8137 end
- pos
> 2 * SSID_MAX_LEN
||
8138 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8139 (end
- pos
) / 2) < 0) {
8140 wpa_printf(MSG_DEBUG
,
8141 "Invalid SSID value '%s'",
8146 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8147 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8148 ssid
[ssid_count
].ssid
,
8149 ssid
[ssid_count
].ssid_len
);
8154 pos
= os_strchr(pos
, ' ');
8160 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8161 os_free(wpa_s
->ssids_from_scan_req
);
8163 wpa_s
->ssids_from_scan_req
= ssid
;
8166 wpa_s
->ssids_from_scan_req
= NULL
;
8170 scan_res_handler
= scan_only_handler
;
8171 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8172 scan_res_handler
= NULL
;
8174 scan_res_handler
= wpa_s
->scan_res_handler
;
8176 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8177 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8178 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8179 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8180 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8181 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8182 wpa_s
->scan_id_count
= scan_id_count
;
8183 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8184 wpa_s
->scan_res_handler
= scan_res_handler
;
8185 os_free(wpa_s
->manual_scan_freqs
);
8186 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8187 manual_scan_freqs
= NULL
;
8189 wpa_s
->normal_scans
= 0;
8190 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8191 wpa_s
->after_wps
= 0;
8192 wpa_s
->known_wps_freq
= 0;
8193 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8194 if (wpa_s
->manual_scan_use_id
) {
8195 wpa_s
->manual_scan_id
++;
8196 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8197 wpa_s
->manual_scan_id
);
8198 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8199 wpa_s
->manual_scan_id
);
8201 } else if (wpa_s
->sched_scanning
) {
8202 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8203 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8204 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8205 wpa_s
->scan_id_count
= scan_id_count
;
8206 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8207 wpa_s
->scan_res_handler
= scan_res_handler
;
8208 os_free(wpa_s
->manual_scan_freqs
);
8209 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8210 manual_scan_freqs
= NULL
;
8212 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8213 wpa_supplicant_cancel_sched_scan(wpa_s
);
8214 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8215 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8216 if (wpa_s
->manual_scan_use_id
) {
8217 wpa_s
->manual_scan_id
++;
8218 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8219 wpa_s
->manual_scan_id
);
8220 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8221 wpa_s
->manual_scan_id
);
8224 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8225 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8229 os_free(manual_scan_freqs
);
8234 #ifdef CONFIG_TESTING_OPTIONS
8236 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8237 unsigned int freq
, const u8
*dst
,
8238 const u8
*src
, const u8
*bssid
,
8239 const u8
*data
, size_t data_len
,
8240 enum offchannel_send_action_result
8243 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8244 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8245 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8246 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8247 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8248 "NO_ACK" : "FAILED"));
8252 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8256 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8258 int freq
= 0, no_cck
= 0, wait_time
= 0;
8260 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8261 * <action=Action frame payload> */
8263 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8266 used
= hwaddr_aton2(pos
, da
);
8272 used
= hwaddr_aton2(pos
, bssid
);
8277 param
= os_strstr(pos
, " freq=");
8283 param
= os_strstr(pos
, " no_cck=");
8286 no_cck
= atoi(param
);
8289 param
= os_strstr(pos
, " wait_time=");
8292 wait_time
= atoi(param
);
8295 param
= os_strstr(pos
, " action=");
8300 len
= os_strlen(param
);
8305 buf
= os_malloc(len
);
8309 if (hexstr2bin(param
, buf
, len
) < 0) {
8314 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8315 buf
, len
, wait_time
,
8316 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8322 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8324 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8325 offchannel_send_action_done(wpa_s
);
8329 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8335 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8336 union wpa_event_data event
;
8338 if (!wpa_s
->ext_mgmt_frame_handling
)
8341 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8343 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8346 param
= os_strstr(pos
, "freq=");
8352 param
= os_strstr(pos
, " datarate=");
8355 datarate
= atoi(param
);
8358 param
= os_strstr(pos
, " ssi_signal=");
8361 ssi_signal
= atoi(param
);
8364 param
= os_strstr(pos
, " frame=");
8369 len
= os_strlen(param
);
8374 buf
= os_malloc(len
);
8378 if (hexstr2bin(param
, buf
, len
) < 0) {
8383 os_memset(&event
, 0, sizeof(event
));
8384 event
.rx_mgmt
.freq
= freq
;
8385 event
.rx_mgmt
.frame
= buf
;
8386 event
.rx_mgmt
.frame_len
= len
;
8387 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8388 event
.rx_mgmt
.datarate
= datarate
;
8389 wpa_s
->ext_mgmt_frame_handling
= 0;
8390 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8391 wpa_s
->ext_mgmt_frame_handling
= 1;
8399 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8402 struct wpa_scan_res
*res
;
8403 struct os_reltime now
;
8410 if (os_strcmp(param
, "START") == 0) {
8411 wpa_bss_update_start(wpa_s
);
8415 if (os_strcmp(param
, "END") == 0) {
8416 wpa_bss_update_end(wpa_s
, NULL
, 1);
8420 if (os_strncmp(param
, "BSS ", 4) != 0)
8424 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8428 pos
= os_strstr(param
, " flags=");
8430 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8432 pos
= os_strstr(param
, " bssid=");
8433 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8436 pos
= os_strstr(param
, " freq=");
8438 res
->freq
= atoi(pos
+ 6);
8440 pos
= os_strstr(param
, " beacon_int=");
8442 res
->beacon_int
= atoi(pos
+ 12);
8444 pos
= os_strstr(param
, " caps=");
8446 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8448 pos
= os_strstr(param
, " qual=");
8450 res
->qual
= atoi(pos
+ 6);
8452 pos
= os_strstr(param
, " noise=");
8454 res
->noise
= atoi(pos
+ 7);
8456 pos
= os_strstr(param
, " level=");
8458 res
->level
= atoi(pos
+ 7);
8460 pos
= os_strstr(param
, " tsf=");
8462 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8464 pos
= os_strstr(param
, " age=");
8466 res
->age
= atoi(pos
+ 5);
8468 pos
= os_strstr(param
, " est_throughput=");
8470 res
->est_throughput
= atoi(pos
+ 16);
8472 pos
= os_strstr(param
, " snr=");
8474 res
->snr
= atoi(pos
+ 5);
8476 pos
= os_strstr(param
, " parent_tsf=");
8478 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8480 pos
= os_strstr(param
, " tsf_bssid=");
8481 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8484 pos
= os_strstr(param
, " ie=");
8487 end
= os_strchr(pos
, ' ');
8489 end
= pos
+ os_strlen(pos
);
8490 res
->ie_len
= (end
- pos
) / 2;
8491 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8495 pos
= os_strstr(param
, " beacon_ie=");
8498 end
= os_strchr(pos
, ' ');
8500 end
= pos
+ os_strlen(pos
);
8501 res
->beacon_ie_len
= (end
- pos
) / 2;
8502 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8503 res
->beacon_ie_len
))
8507 os_get_reltime(&now
);
8508 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8517 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8520 union wpa_event_data event
;
8521 enum wpa_event_type ev
;
8523 /* <event name> [parameters..] */
8525 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8528 param
= os_strchr(pos
, ' ');
8532 os_memset(&event
, 0, sizeof(event
));
8534 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8535 ev
= EVENT_INTERFACE_ENABLED
;
8536 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8537 ev
= EVENT_INTERFACE_DISABLED
;
8538 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8539 ev
= EVENT_AVOID_FREQUENCIES
;
8542 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8544 wpa_supplicant_event(wpa_s
, ev
, &event
);
8545 os_free(event
.freq_range
.range
);
8547 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8548 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8550 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8555 wpa_supplicant_event(wpa_s
, ev
, &event
);
8561 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8564 u8 src
[ETH_ALEN
], *buf
;
8568 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8571 used
= hwaddr_aton2(pos
, src
);
8578 len
= os_strlen(pos
);
8583 buf
= os_malloc(len
);
8587 if (hexstr2bin(pos
, buf
, len
) < 0) {
8592 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8599 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8603 const u16
*pos
= buf
;
8605 for (i
= 0; i
< len
/ 2; i
++)
8609 sum
= (sum
& 0xffff) + (sum
>> 16);
8611 return sum
^ 0xffff;
8615 #define HWSIM_PACKETLEN 1500
8616 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8618 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8621 struct wpa_supplicant
*wpa_s
= ctx
;
8622 const struct ether_header
*eth
;
8627 if (len
!= HWSIM_PACKETLEN
)
8630 eth
= (const struct ether_header
*) buf
;
8631 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8632 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8634 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8635 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8638 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
8644 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
8645 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
8649 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8652 int enabled
= atoi(cmd
);
8657 if (wpa_s
->l2_test
) {
8658 l2_packet_deinit(wpa_s
->l2_test
);
8659 wpa_s
->l2_test
= NULL
;
8660 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8668 pos
= os_strstr(cmd
, " ifname=");
8672 ifname
= wpa_s
->ifname
;
8674 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8675 ETHERTYPE_IP
, wpas_data_test_rx
,
8677 if (wpa_s
->l2_test
== NULL
)
8680 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8686 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8688 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8693 u8 buf
[2 + HWSIM_PACKETLEN
];
8694 struct ether_header
*eth
;
8699 if (wpa_s
->l2_test
== NULL
)
8702 /* format: <dst> <src> <tos> */
8705 used
= hwaddr_aton2(pos
, dst
);
8711 used
= hwaddr_aton2(pos
, src
);
8716 val
= strtol(pos
, NULL
, 0);
8717 if (val
< 0 || val
> 0xff)
8721 eth
= (struct ether_header
*) &buf
[2];
8722 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8723 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8724 eth
->ether_type
= htons(ETHERTYPE_IP
);
8725 ip
= (struct iphdr
*) (eth
+ 1);
8726 os_memset(ip
, 0, sizeof(*ip
));
8731 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8733 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8734 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8735 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8736 dpos
= (u8
*) (ip
+ 1);
8737 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8740 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8741 HWSIM_PACKETLEN
) < 0)
8744 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8745 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8751 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8755 struct ether_header
*eth
;
8756 struct l2_packet_data
*l2
= NULL
;
8761 len
= os_strlen(cmd
);
8762 if (len
& 1 || len
< ETH_HLEN
* 2)
8766 buf
= os_malloc(len
);
8770 if (hexstr2bin(cmd
, buf
, len
) < 0)
8773 eth
= (struct ether_header
*) buf
;
8774 ethertype
= ntohs(eth
->ether_type
);
8776 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8777 wpas_data_test_rx
, wpa_s
, 1);
8781 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8782 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8785 l2_packet_deinit(l2
);
8788 return res
< 0 ? -1 : 0;
8792 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8794 #ifdef WPA_TRACE_BFD
8797 wpa_trace_fail_after
= atoi(cmd
);
8798 pos
= os_strchr(cmd
, ':');
8801 os_strlcpy(wpa_trace_fail_func
, pos
,
8802 sizeof(wpa_trace_fail_func
));
8804 wpa_trace_fail_after
= 0;
8807 #else /* WPA_TRACE_BFD */
8809 #endif /* WPA_TRACE_BFD */
8813 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8814 char *buf
, size_t buflen
)
8816 #ifdef WPA_TRACE_BFD
8817 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8818 wpa_trace_fail_func
);
8819 #else /* WPA_TRACE_BFD */
8821 #endif /* WPA_TRACE_BFD */
8825 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8827 #ifdef WPA_TRACE_BFD
8830 wpa_trace_test_fail_after
= atoi(cmd
);
8831 pos
= os_strchr(cmd
, ':');
8834 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8835 sizeof(wpa_trace_test_fail_func
));
8837 wpa_trace_test_fail_after
= 0;
8840 #else /* WPA_TRACE_BFD */
8842 #endif /* WPA_TRACE_BFD */
8846 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8847 char *buf
, size_t buflen
)
8849 #ifdef WPA_TRACE_BFD
8850 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8851 wpa_trace_test_fail_func
);
8852 #else /* WPA_TRACE_BFD */
8854 #endif /* WPA_TRACE_BFD */
8858 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8860 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8861 int i
, count
= (intptr_t) timeout_ctx
;
8863 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8865 for (i
= 0; i
< count
; i
++) {
8866 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8872 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8880 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8881 (void *) (intptr_t) count
);
8885 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8891 len
= os_strlen(cmd
);
8899 buf
= wpabuf_alloc(len
);
8903 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
8909 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
8913 #endif /* CONFIG_TESTING_OPTIONS */
8916 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
8922 struct ieee802_11_elems elems
;
8925 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8927 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8929 pos
= os_strchr(pos
, ' ');
8934 len
= os_strlen(pos
);
8941 buf
= wpabuf_alloc(len
);
8945 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
8950 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
8956 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
8957 wpa_s
->vendor_elem
[frame
] = buf
;
8958 wpas_vendor_elem_update(wpa_s
);
8962 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
8967 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
8969 wpas_vendor_elem_update(wpa_s
);
8975 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
8976 char *buf
, size_t buflen
)
8978 int frame
= atoi(cmd
);
8980 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8982 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8984 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8987 return wpa_snprintf_hex(buf
, buflen
,
8988 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
8989 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
8993 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
8999 struct ieee802_11_elems elems
;
9003 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9005 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9007 pos
= os_strchr(pos
, ' ');
9013 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9014 wpa_s
->vendor_elem
[frame
] = NULL
;
9015 wpas_vendor_elem_update(wpa_s
);
9019 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9022 len
= os_strlen(pos
);
9029 buf
= os_malloc(len
);
9033 if (hexstr2bin(pos
, buf
, len
) < 0) {
9038 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9043 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9049 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9051 struct wpa_supplicant
*wpa_s
= ctx
;
9056 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9058 * BSSID Information[4]
9059 * Operating Class[1]
9062 * Optional Subelements[variable]
9064 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9066 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9067 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9071 data
= wpabuf_head_u8(neighbor_rep
);
9072 len
= wpabuf_len(neighbor_rep
);
9074 while (len
>= 2 + NR_IE_MIN_LEN
) {
9076 char lci
[256 * 2 + 1];
9077 char civic
[256 * 2 + 1];
9078 u8 nr_len
= data
[1];
9079 const u8
*pos
= data
, *end
;
9081 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9082 nr_len
< NR_IE_MIN_LEN
) {
9083 wpa_printf(MSG_DEBUG
,
9084 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9089 if (2U + nr_len
> len
) {
9090 wpa_printf(MSG_DEBUG
,
9091 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9092 data
[0], len
, nr_len
);
9099 pos
+= NR_IE_MIN_LEN
;
9103 while (end
- pos
> 2) {
9108 if (s_len
> end
- pos
)
9110 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9111 /* Measurement Token[1] */
9112 /* Measurement Report Mode[1] */
9113 /* Measurement Type[1] */
9114 /* Measurement Report[variable] */
9116 case MEASURE_TYPE_LCI
:
9119 wpa_snprintf_hex(lci
, sizeof(lci
),
9122 case MEASURE_TYPE_LOCATION_CIVIC
:
9125 wpa_snprintf_hex(civic
, sizeof(civic
),
9134 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9136 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9137 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9138 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9140 lci
[0] ? " lci=" : "", lci
,
9141 civic
[0] ? " civic=" : "", civic
);
9148 wpabuf_free(neighbor_rep
);
9152 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9155 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9156 int ret
, lci
= 0, civic
= 0;
9159 ssid_s
= os_strstr(cmd
, "ssid=");
9161 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9162 wpa_printf(MSG_ERROR
,
9163 "CTRL: Send Neighbor Report: bad SSID");
9170 * Move cmd after the SSID text that may include "lci" or
9173 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9179 if (cmd
&& os_strstr(cmd
, "lci"))
9182 if (cmd
&& os_strstr(cmd
, "civic"))
9185 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9186 wpas_ctrl_neighbor_rep_cb
,
9193 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9195 eapol_sm_erp_flush(wpa_s
->eapol
);
9200 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9203 char *token
, *context
= NULL
;
9204 unsigned int enable
= ~0, type
= 0;
9205 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9206 u8
*addr
= NULL
, *mask
= NULL
;
9208 while ((token
= str_token(cmd
, " ", &context
))) {
9209 if (os_strcasecmp(token
, "scan") == 0) {
9210 type
|= MAC_ADDR_RAND_SCAN
;
9211 } else if (os_strcasecmp(token
, "sched") == 0) {
9212 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9213 } else if (os_strcasecmp(token
, "pno") == 0) {
9214 type
|= MAC_ADDR_RAND_PNO
;
9215 } else if (os_strcasecmp(token
, "all") == 0) {
9216 type
= wpa_s
->mac_addr_rand_supported
;
9217 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9218 enable
= atoi(token
+ 7);
9219 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9221 if (hwaddr_aton(token
+ 5, addr
)) {
9222 wpa_printf(MSG_INFO
,
9223 "CTRL: Invalid MAC address: %s",
9227 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9229 if (hwaddr_aton(token
+ 5, mask
)) {
9230 wpa_printf(MSG_INFO
,
9231 "CTRL: Invalid MAC address mask: %s",
9236 wpa_printf(MSG_INFO
,
9237 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9244 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9248 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
9249 wpa_printf(MSG_INFO
,
9250 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9251 type
, wpa_s
->mac_addr_rand_supported
);
9256 wpa_printf(MSG_INFO
,
9257 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9262 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
9264 if (type
& MAC_ADDR_RAND_PNO
) {
9265 wpas_stop_pno(wpa_s
);
9266 wpas_start_pno(wpa_s
);
9268 } else if (wpa_s
->sched_scanning
&&
9269 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
9270 wpas_scan_restart_sched_scan(wpa_s
);
9275 if ((addr
&& !mask
) || (!addr
&& mask
)) {
9276 wpa_printf(MSG_INFO
,
9277 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9281 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
9282 wpa_printf(MSG_INFO
,
9283 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9287 if (type
& MAC_ADDR_RAND_SCAN
) {
9288 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
9292 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
9293 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
9296 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
9297 wpas_scan_restart_sched_scan(wpa_s
);
9300 if (type
& MAC_ADDR_RAND_PNO
) {
9301 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
9304 wpas_stop_pno(wpa_s
);
9305 wpas_start_pno(wpa_s
);
9313 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9314 char *buf
, size_t buflen
)
9318 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9320 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9321 buflen
- reply_len
);
9322 #endif /* CONFIG_AP */
9327 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9329 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9331 wpas_ap_pmksa_cache_flush(wpa_s
);
9332 #endif /* CONFIG_AP */
9336 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9338 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9339 const char *cmd
, char *buf
, size_t buflen
)
9341 struct rsn_pmksa_cache_entry
*entry
;
9342 struct wpa_ssid
*ssid
;
9343 char *pos
, *pos2
, *end
;
9345 struct os_reltime now
;
9347 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9354 os_get_reltime(&now
);
9358 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9359 * <expiration in seconds> <akmp> <opportunistic>
9360 * [FILS Cache Identifier]
9363 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9364 entry
= entry
->next
) {
9365 if (entry
->network_ctx
!= ssid
)
9369 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9370 MAC2STR(entry
->aa
));
9371 if (os_snprintf_error(end
- pos2
, ret
))
9375 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9378 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9379 if (os_snprintf_error(end
- pos2
, ret
))
9383 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9386 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9387 (int) (entry
->reauth_time
- now
.sec
),
9388 (int) (entry
->expiration
- now
.sec
),
9390 entry
->opportunistic
);
9391 if (os_snprintf_error(end
- pos2
, ret
))
9395 if (entry
->fils_cache_id_set
) {
9396 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9397 entry
->fils_cache_id
[0],
9398 entry
->fils_cache_id
[1]);
9399 if (os_snprintf_error(end
- pos2
, ret
))
9404 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9405 if (os_snprintf_error(end
- pos2
, ret
))
9416 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9419 struct rsn_pmksa_cache_entry
*entry
;
9420 struct wpa_ssid
*ssid
;
9423 struct os_reltime now
;
9424 int reauth_time
= 0, expiration
= 0, i
;
9428 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9429 * <expiration in seconds> <akmp> <opportunistic>
9430 * [FILS Cache Identifier]
9433 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9437 pos
= os_strchr(cmd
, ' ');
9442 entry
= os_zalloc(sizeof(*entry
));
9446 if (hwaddr_aton(pos
, entry
->aa
))
9449 pos
= os_strchr(pos
, ' ');
9454 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9457 pos
= os_strchr(pos
, ' ');
9462 pos2
= os_strchr(pos
, ' ');
9465 entry
->pmk_len
= (pos2
- pos
) / 2;
9466 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9467 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9470 pos
= os_strchr(pos
, ' ');
9475 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9476 &entry
->akmp
, &entry
->opportunistic
) != 4)
9478 for (i
= 0; i
< 4; i
++) {
9479 pos
= os_strchr(pos
, ' ');
9488 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9489 FILS_CACHE_ID_LEN
) < 0)
9491 entry
->fils_cache_id_set
= 1;
9493 os_get_reltime(&now
);
9494 entry
->expiration
= now
.sec
+ expiration
;
9495 entry
->reauth_time
= now
.sec
+ reauth_time
;
9497 entry
->network_ctx
= ssid
;
9499 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9510 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9511 const char *cmd
, char *buf
,
9519 if (os_strcasecmp(cmd
, "any") == 0)
9520 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9522 if (hwaddr_aton(cmd
, spa
))
9525 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9529 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9533 * We do not check mesh interface existance because PMKSA should be
9534 * stored before wpa_s->ifmsh creation to suppress commit message
9537 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9540 #endif /* CONFIG_MESH */
9541 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9545 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9548 struct fils_hlp_req
*req
;
9551 /* format: <dst> <packet starting from ethertype> */
9553 req
= os_zalloc(sizeof(*req
));
9557 if (hwaddr_aton(cmd
, req
->dst
))
9560 pos
= os_strchr(cmd
, ' ');
9564 req
->pkt
= wpabuf_parse_bin(pos
);
9568 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9571 wpabuf_free(req
->pkt
);
9575 #endif /* CONFIG_FILS */
9578 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9580 if (os_strcmp(cmd
, "PING") == 0 ||
9581 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9582 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9583 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9584 os_strncmp(cmd
, "STA ", 4) == 0 ||
9585 os_strncmp(cmd
, "STA-", 4) == 0)
9586 return MSG_EXCESSIVE
;
9591 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9592 char *buf
, size_t *resp_len
)
9595 const int reply_size
= 4096;
9598 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9599 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9600 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9601 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9602 if (wpa_debug_show_keys
)
9603 wpa_dbg(wpa_s
, MSG_DEBUG
,
9604 "Control interface command '%s'", buf
);
9606 wpa_dbg(wpa_s
, MSG_DEBUG
,
9607 "Control interface command '%s [REMOVED]'",
9608 os_strncmp(buf
, WPA_CTRL_RSP
,
9609 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9611 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9612 "SET_NETWORK" : "key-add"));
9613 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9614 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9615 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9616 (const u8
*) buf
, os_strlen(buf
));
9618 int level
= wpas_ctrl_cmd_debug_level(buf
);
9619 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9622 reply
= os_malloc(reply_size
);
9623 if (reply
== NULL
) {
9628 os_memcpy(reply
, "OK\n", 3);
9631 if (os_strcmp(buf
, "PING") == 0) {
9632 os_memcpy(reply
, "PONG\n", 5);
9634 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9635 reply_len
= os_strlen(wpa_s
->ifname
);
9636 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9637 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9638 if (wpa_debug_reopen_file() < 0)
9640 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9641 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9642 } else if (os_strcmp(buf
, "MIB") == 0) {
9643 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9644 if (reply_len
>= 0) {
9645 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9647 reply_size
- reply_len
);
9649 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9650 reply_len
= wpa_supplicant_ctrl_iface_status(
9651 wpa_s
, buf
+ 6, reply
, reply_size
);
9652 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9653 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9654 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9655 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9656 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9657 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9658 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9660 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9661 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9664 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9665 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9667 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9668 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9670 #endif /* CONFIG_MESH */
9671 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9672 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9673 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9675 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9676 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9678 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9679 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9681 } else if (os_strcmp(buf
, "LOGON") == 0) {
9682 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9683 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9684 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9685 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9686 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9689 wpas_request_connection(wpa_s
);
9690 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9691 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9692 !wpa_s
->current_ssid
)
9695 wpa_s
->reattach
= 1;
9696 wpas_request_connection(wpa_s
);
9698 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9699 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9701 else if (wpa_s
->disconnected
)
9702 wpas_request_connection(wpa_s
);
9703 #ifdef IEEE8021X_EAPOL
9704 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9705 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9707 #endif /* IEEE8021X_EAPOL */
9708 #ifdef CONFIG_PEERKEY
9709 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
9710 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
9712 #endif /* CONFIG_PEERKEY */
9713 #ifdef CONFIG_IEEE80211R
9714 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9715 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9717 #endif /* CONFIG_IEEE80211R */
9719 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9720 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9722 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9726 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9727 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9729 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9733 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9734 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9737 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9738 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9739 wpa_s
, buf
+ 14, reply
, reply_size
);
9740 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9741 if (wpas_wps_cancel(wpa_s
))
9743 #ifdef CONFIG_WPS_NFC
9744 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
9745 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
9747 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
9748 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
9750 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9751 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9752 wpa_s
, buf
+ 21, reply
, reply_size
);
9753 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
9754 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
9755 wpa_s
, buf
+ 14, reply
, reply_size
);
9756 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
9757 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
9760 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9761 reply_len
= wpas_ctrl_nfc_get_handover_req(
9762 wpa_s
, buf
+ 21, reply
, reply_size
);
9763 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9764 reply_len
= wpas_ctrl_nfc_get_handover_sel(
9765 wpa_s
, buf
+ 21, reply
, reply_size
);
9766 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
9767 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
9769 #endif /* CONFIG_WPS_NFC */
9770 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
9771 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
9774 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
9775 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
9776 wpa_s
, buf
+ 11, reply
, reply_size
);
9777 #endif /* CONFIG_AP */
9778 #ifdef CONFIG_WPS_ER
9779 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
9780 if (wpas_wps_er_start(wpa_s
, NULL
))
9782 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
9783 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
9785 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
9786 wpas_wps_er_stop(wpa_s
);
9787 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
9788 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
9790 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
9791 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
9793 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9795 } else if (ret
== -3) {
9796 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
9798 } else if (ret
== -4) {
9799 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
9803 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
9804 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
9806 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
9807 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
9810 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
9811 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
9813 #ifdef CONFIG_WPS_NFC
9814 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9815 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9816 wpa_s
, buf
+ 24, reply
, reply_size
);
9817 #endif /* CONFIG_WPS_NFC */
9818 #endif /* CONFIG_WPS_ER */
9819 #endif /* CONFIG_WPS */
9820 #ifdef CONFIG_IBSS_RSN
9821 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
9822 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
9824 #endif /* CONFIG_IBSS_RSN */
9826 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
9827 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9828 wpa_s
, buf
+ 19, reply
, reply_size
);
9829 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
9830 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9831 wpa_s
, "", reply
, reply_size
);
9832 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
9833 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
9835 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
9836 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
9839 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
9840 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
9842 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
9843 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
9845 #endif /* CONFIG_MESH */
9847 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
9848 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
9850 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
9851 if (p2p_ctrl_find(wpa_s
, ""))
9853 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
9854 wpas_p2p_stop_find(wpa_s
);
9855 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
9856 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
9858 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
9859 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
9861 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
9862 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
9864 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
9865 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
9867 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
9868 if (p2p_ctrl_listen(wpa_s
, ""))
9870 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
9871 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
9873 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
9874 if (p2p_ctrl_group_add(wpa_s
, ""))
9876 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
9877 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
9879 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
9880 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
9882 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
9883 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
9885 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
9886 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
9887 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
9888 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
9890 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
9891 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
9893 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
9894 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
9896 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
9897 wpas_p2p_sd_service_update(wpa_s
);
9898 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
9899 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
9901 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
9902 wpas_p2p_service_flush(wpa_s
);
9903 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
9904 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
9906 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
9907 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
9909 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
9910 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
9912 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
9913 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
9915 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
9916 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
9918 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
9919 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
9921 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
9922 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
9924 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
9925 p2p_ctrl_flush(wpa_s
);
9926 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
9927 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
9929 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
9930 if (wpas_p2p_cancel(wpa_s
))
9932 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
9933 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
9935 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
9936 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
9938 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
9939 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
9941 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
9942 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
9944 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
9945 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
9947 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
9948 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
9950 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
9951 if (wpas_p2p_lo_stop(wpa_s
))
9953 #endif /* CONFIG_P2P */
9954 #ifdef CONFIG_WIFI_DISPLAY
9955 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
9956 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
9958 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
9959 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
9961 #endif /* CONFIG_WIFI_DISPLAY */
9962 #ifdef CONFIG_INTERWORKING
9963 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
9964 if (interworking_fetch_anqp(wpa_s
) < 0)
9966 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
9967 interworking_stop_fetch_anqp(wpa_s
);
9968 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
9969 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
9971 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
9972 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
9974 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
9975 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
9977 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9980 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
9984 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
9985 if (os_snprintf_error(reply_size
, reply_len
))
9988 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
9989 if (get_anqp(wpa_s
, buf
+ 9) < 0)
9991 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
9992 if (gas_request(wpa_s
, buf
+ 12) < 0)
9994 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
9995 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
9997 #endif /* CONFIG_INTERWORKING */
9999 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10000 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10002 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10003 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10005 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10006 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10008 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10009 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10011 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10012 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10013 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10014 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10016 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10017 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10019 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10020 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10022 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10023 hs20_cancel_fetch_osu(wpa_s
);
10024 #endif /* CONFIG_HS20 */
10025 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10027 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10028 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10032 * Notify response from timeout to allow the control
10033 * interface response to be sent first.
10035 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10038 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10039 if (wpa_supplicant_reload_configuration(wpa_s
))
10041 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10042 wpa_supplicant_terminate_proc(wpa_s
->global
);
10043 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10044 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10046 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10047 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10048 wpa_s
, buf
+ 9, reply
, reply_size
);
10049 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10050 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10051 wpa_s
, buf
+ 9, reply
, reply_size
);
10052 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10053 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10054 wpa_s
, buf
+ 14, reply
, reply_size
);
10055 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10056 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10057 wpa_s
, NULL
, reply
, reply_size
);
10058 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10059 wpas_request_disconnection(wpa_s
);
10060 } else if (os_strcmp(buf
, "SCAN") == 0) {
10061 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10062 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10063 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10064 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10065 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10066 wpa_s
, reply
, reply_size
);
10067 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10068 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10070 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10071 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10073 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10074 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10076 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10077 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10079 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10080 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10081 wpa_s
, reply
, reply_size
);
10082 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10083 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10085 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10086 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10088 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10089 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10090 wpa_s
, buf
+ 12, reply
, reply_size
);
10091 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10092 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10095 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10096 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10097 wpa_s
, reply
, reply_size
);
10098 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10099 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10100 wpa_s
, reply
, reply_size
);
10101 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10102 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10104 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10105 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10107 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10108 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10111 #ifndef CONFIG_NO_CONFIG_WRITE
10112 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10113 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10115 #endif /* CONFIG_NO_CONFIG_WRITE */
10116 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10117 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10118 wpa_s
, buf
+ 15, reply
, reply_size
);
10119 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10120 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10122 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10123 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10125 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10126 reply_len
= wpa_supplicant_global_iface_list(
10127 wpa_s
->global
, reply
, reply_size
);
10128 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10129 reply_len
= wpa_supplicant_global_iface_interfaces(
10130 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10131 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10132 reply_len
= wpa_supplicant_ctrl_iface_bss(
10133 wpa_s
, buf
+ 4, reply
, reply_size
);
10135 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10136 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10137 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10138 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10140 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10141 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10143 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10144 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10146 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10147 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10149 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10150 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10152 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10153 if (wpas_ap_stop_ap(wpa_s
))
10155 #endif /* CONFIG_AP */
10156 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10157 wpas_notify_suspend(wpa_s
->global
);
10158 } else if (os_strcmp(buf
, "RESUME") == 0) {
10159 wpas_notify_resume(wpa_s
->global
);
10160 #ifdef CONFIG_TESTING_OPTIONS
10161 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10162 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10163 #endif /* CONFIG_TESTING_OPTIONS */
10164 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10165 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10167 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10168 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10169 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10170 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10172 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10173 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10176 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10177 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10179 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10180 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10182 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10183 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10185 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10186 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10188 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10189 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10192 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10193 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10196 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10197 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10198 wpa_s
, buf
+ 17, reply
, reply_size
);
10199 #endif /* CONFIG_TDLS */
10200 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10201 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10202 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10203 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10205 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10206 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10208 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10209 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10211 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10212 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10214 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10215 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10217 #ifdef CONFIG_AUTOSCAN
10218 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10219 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10221 #endif /* CONFIG_AUTOSCAN */
10222 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10223 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10226 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10227 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10229 #endif /* ANDROID */
10230 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10231 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10233 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10234 pmksa_cache_clear_current(wpa_s
->wpa
);
10235 eapol_sm_request_reauth(wpa_s
->eapol
);
10237 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10238 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10240 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10241 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10243 #endif /* CONFIG_WNM */
10244 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10245 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10246 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10247 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10249 #ifdef CONFIG_TESTING_OPTIONS
10250 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10251 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10253 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10254 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10255 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10256 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10258 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10259 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10261 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10262 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10264 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10265 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10267 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10268 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10270 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10271 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10273 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10274 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10276 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10277 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10278 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10279 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10281 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10282 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10283 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10284 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10286 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10287 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10289 #endif /* CONFIG_TESTING_OPTIONS */
10290 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10291 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10293 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10294 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10296 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10297 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10299 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10300 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10302 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10303 wpas_ctrl_iface_erp_flush(wpa_s
);
10304 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10305 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10307 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10308 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10309 wpa_s
, buf
+ 19, reply
, reply_size
);
10311 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10312 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10314 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10315 wpas_flush_fils_hlp_req(wpa_s
);
10316 #endif /* CONFIG_FILS */
10318 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10321 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10325 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10326 if (os_snprintf_error(reply_size
, reply_len
))
10329 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10332 res
= wpas_dpp_bootstrap_gen(wpa_s
, buf
+ 18);
10336 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10337 if (os_snprintf_error(reply_size
, reply_len
))
10340 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10341 if (wpas_dpp_bootstrap_remove(wpa_s
, buf
+ 21) < 0)
10343 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10346 uri
= wpas_dpp_bootstrap_get_uri(wpa_s
, atoi(buf
+ 22));
10350 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10351 if (os_snprintf_error(reply_size
, reply_len
))
10354 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10355 reply_len
= wpas_dpp_bootstrap_info(wpa_s
, atoi(buf
+ 19),
10356 reply
, reply_size
);
10357 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10358 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10360 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10361 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10363 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10364 wpas_dpp_listen_stop(wpa_s
);
10365 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10368 res
= wpas_dpp_configurator_add(wpa_s
, buf
+ 20);
10372 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10373 if (os_snprintf_error(reply_size
, reply_len
))
10376 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10377 if (wpas_dpp_configurator_remove(wpa_s
, buf
+ 24) < 0)
10379 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10380 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 22) < 0)
10382 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10385 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10389 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10390 if (os_snprintf_error(reply_size
, reply_len
))
10393 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10394 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10396 #endif /* CONFIG_DPP */
10398 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10402 if (reply_len
< 0) {
10403 os_memcpy(reply
, "FAIL\n", 5);
10407 *resp_len
= reply_len
;
10412 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10415 struct wpa_interface iface
;
10417 struct wpa_supplicant
*wpa_s
;
10418 unsigned int create_iface
= 0;
10419 u8 mac_addr
[ETH_ALEN
];
10420 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10423 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10424 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10426 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10428 os_memset(&iface
, 0, sizeof(iface
));
10431 iface
.ifname
= pos
= cmd
;
10432 pos
= os_strchr(pos
, '\t');
10435 if (iface
.ifname
[0] == '\0')
10440 iface
.confname
= pos
;
10441 pos
= os_strchr(pos
, '\t');
10444 if (iface
.confname
[0] == '\0')
10445 iface
.confname
= NULL
;
10449 iface
.driver
= pos
;
10450 pos
= os_strchr(pos
, '\t');
10453 if (iface
.driver
[0] == '\0')
10454 iface
.driver
= NULL
;
10458 iface
.ctrl_interface
= pos
;
10459 pos
= os_strchr(pos
, '\t');
10462 if (iface
.ctrl_interface
[0] == '\0')
10463 iface
.ctrl_interface
= NULL
;
10467 iface
.driver_param
= pos
;
10468 pos
= os_strchr(pos
, '\t');
10471 if (iface
.driver_param
[0] == '\0')
10472 iface
.driver_param
= NULL
;
10476 iface
.bridge_ifname
= pos
;
10477 pos
= os_strchr(pos
, '\t');
10480 if (iface
.bridge_ifname
[0] == '\0')
10481 iface
.bridge_ifname
= NULL
;
10486 pos
= os_strchr(pos
, '\t');
10492 if (os_strcmp(extra
, "create") == 0) {
10497 if (os_strcmp(pos
, "sta") == 0) {
10498 type
= WPA_IF_STATION
;
10499 } else if (os_strcmp(pos
, "ap") == 0) {
10500 type
= WPA_IF_AP_BSS
;
10502 wpa_printf(MSG_DEBUG
,
10503 "INTERFACE_ADD unsupported interface type: '%s'",
10508 wpa_printf(MSG_DEBUG
,
10509 "INTERFACE_ADD unsupported extra parameter: '%s'",
10515 if (create_iface
) {
10516 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10518 if (!global
->ifaces
)
10520 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10521 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10522 wpa_printf(MSG_ERROR
,
10523 "CTRL_IFACE interface creation failed");
10527 wpa_printf(MSG_DEBUG
,
10528 "CTRL_IFACE interface '%s' created with MAC addr: "
10529 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10532 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10535 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10538 wpa_s
->added_vif
= create_iface
;
10543 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10548 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10551 struct wpa_supplicant
*wpa_s
;
10553 unsigned int delete_iface
;
10555 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10557 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10560 delete_iface
= wpa_s
->added_vif
;
10561 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10562 if (!ret
&& delete_iface
) {
10563 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10565 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10571 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10573 struct wpa_interface_info
*prev
;
10577 iface
= iface
->next
;
10579 os_free(prev
->ifname
);
10580 os_free(prev
->desc
);
10586 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10587 char *buf
, int len
)
10590 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10593 for (i
= 0; wpa_drivers
[i
]; i
++) {
10594 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10595 if (drv
->get_interfaces
== NULL
)
10597 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10602 iface
= last
= tmp
;
10611 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10612 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10613 tmp
->drv_name
, tmp
->ifname
,
10614 tmp
->desc
? tmp
->desc
: "");
10615 if (os_snprintf_error(end
- pos
, res
)) {
10622 wpa_free_iface_info(iface
);
10628 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10630 char *buf
, int len
)
10634 struct wpa_supplicant
*wpa_s
;
10638 show_ctrl
= !!os_strstr(input
, "ctrl");
10640 wpa_s
= global
->ifaces
;
10646 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10648 wpa_s
->conf
->ctrl_interface
?
10649 wpa_s
->conf
->ctrl_interface
: "N/A");
10651 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10654 if (os_snprintf_error(end
- pos
, res
)) {
10659 wpa_s
= wpa_s
->next
;
10665 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10666 const char *ifname
,
10667 char *cmd
, size_t *resp_len
)
10669 struct wpa_supplicant
*wpa_s
;
10671 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10672 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10676 if (wpa_s
== NULL
) {
10677 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10679 *resp_len
= os_strlen(resp
);
10685 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10689 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10690 char *buf
, size_t *resp_len
)
10693 static const char * cmd
[] = {
10699 "P2P_GET_PASSPHRASE",
10700 "P2P_SERVICE_UPDATE",
10701 "P2P_SERVICE_FLUSH",
10704 "P2P_PRESENCE_REQ",
10708 #endif /* CONFIG_AP */
10711 static const char * prefix
[] = {
10714 #endif /* ANDROID */
10721 "P2P_GROUP_REMOVE ",
10723 "P2P_GROUP_MEMBER ",
10725 "P2P_SERV_DISC_REQ ",
10726 "P2P_SERV_DISC_CANCEL_REQ ",
10727 "P2P_SERV_DISC_RESP ",
10728 "P2P_SERV_DISC_EXTERNAL ",
10729 "P2P_SERVICE_ADD ",
10730 "P2P_SERVICE_DEL ",
10731 "P2P_SERVICE_REP ",
10736 "P2P_UNAUTHORIZE ",
10737 "P2P_PRESENCE_REQ ",
10739 "P2P_REMOVE_CLIENT ",
10741 "WPS_NFC_TAG_READ ",
10742 "NFC_GET_HANDOVER_SEL ",
10743 "NFC_GET_HANDOVER_REQ ",
10744 "NFC_REPORT_HANDOVER ",
10745 "P2P_ASP_PROVISION ",
10746 "P2P_ASP_PROVISION_RESP ",
10750 #endif /* CONFIG_AP */
10756 if (global
->p2p_init_wpa_s
== NULL
)
10759 for (i
= 0; !found
&& cmd
[i
]; i
++) {
10760 if (os_strcmp(buf
, cmd
[i
]) == 0)
10764 for (i
= 0; !found
&& prefix
[i
]; i
++) {
10765 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
10770 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10772 #endif /* CONFIG_P2P */
10777 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
10778 char *buf
, size_t *resp_len
)
10780 #ifdef CONFIG_WIFI_DISPLAY
10781 if (global
->p2p_init_wpa_s
== NULL
)
10783 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
10784 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
10785 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10787 #endif /* CONFIG_WIFI_DISPLAY */
10792 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
10793 char *buf
, size_t *resp_len
)
10797 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
10801 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
10809 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
10813 value
= os_strchr(cmd
, ' ');
10818 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
10820 #ifdef CONFIG_WIFI_DISPLAY
10821 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
10822 wifi_display_enable(global
, !!atoi(value
));
10825 #endif /* CONFIG_WIFI_DISPLAY */
10827 /* Restore cmd to its original value to allow redirection */
10834 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
10837 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
10841 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
10842 * <variable name> */
10844 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
10845 p
= os_strchr(cmd
, ' ');
10850 wpa_s
[i
] = global
->ifaces
;
10851 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
10852 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
10857 wpa_printf(MSG_DEBUG
,
10858 "CTRL_IFACE: Could not find iface=%s", cmd
);
10865 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
10869 #ifndef CONFIG_NO_CONFIG_WRITE
10870 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
10872 int ret
= 0, saved
= 0;
10873 struct wpa_supplicant
*wpa_s
;
10875 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10876 if (!wpa_s
->conf
->update_config
) {
10877 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
10881 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
10882 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
10885 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
10890 if (!saved
&& !ret
) {
10891 wpa_dbg(wpa_s
, MSG_DEBUG
,
10892 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
10898 #endif /* CONFIG_NO_CONFIG_WRITE */
10901 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
10902 char *buf
, size_t buflen
)
10906 struct wpa_supplicant
*wpa_s
;
10909 end
= buf
+ buflen
;
10912 if (global
->p2p
&& !global
->p2p_disabled
) {
10913 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
10916 MAC2STR(global
->p2p_dev_addr
),
10917 p2p_get_state_txt(global
->p2p
));
10918 if (os_snprintf_error(end
- pos
, ret
))
10921 } else if (global
->p2p
) {
10922 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
10923 if (os_snprintf_error(end
- pos
, ret
))
10927 #endif /* CONFIG_P2P */
10929 #ifdef CONFIG_WIFI_DISPLAY
10930 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
10931 !!global
->wifi_display
);
10932 if (os_snprintf_error(end
- pos
, ret
))
10935 #endif /* CONFIG_WIFI_DISPLAY */
10937 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10938 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
10939 "address=" MACSTR
"\n",
10940 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
10941 if (os_snprintf_error(end
- pos
, ret
))
10952 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
10953 char *cmd
, char *buf
,
10956 char ifname
[IFNAMSIZ
+ 1];
10957 struct fst_iface_cfg cfg
;
10958 struct wpa_supplicant
*wpa_s
;
10959 struct fst_wpa_obj iface_obj
;
10961 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
10962 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10965 wpa_printf(MSG_INFO
, "FST: Already attached");
10968 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
10969 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
10972 return os_snprintf(buf
, reply_size
, "OK\n");
10980 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
10981 char *cmd
, char *buf
,
10984 char ifname
[IFNAMSIZ
+ 1];
10985 struct wpa_supplicant
*wpa_s
;
10987 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
10988 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10990 if (!fst_iface_detach(ifname
)) {
10992 return os_snprintf(buf
, reply_size
, "OK\n");
11000 #endif /* CONFIG_FST */
11003 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11004 char *buf
, size_t *resp_len
)
11007 const int reply_size
= 2048;
11009 int level
= MSG_DEBUG
;
11011 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11012 char *pos
= os_strchr(buf
+ 7, ' ');
11015 return wpas_global_ctrl_iface_ifname(global
,
11021 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11025 if (os_strcmp(buf
, "PING") == 0)
11026 level
= MSG_EXCESSIVE
;
11027 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11028 (const u8
*) buf
, os_strlen(buf
));
11030 reply
= os_malloc(reply_size
);
11031 if (reply
== NULL
) {
11036 os_memcpy(reply
, "OK\n", 3);
11039 if (os_strcmp(buf
, "PING") == 0) {
11040 os_memcpy(reply
, "PONG\n", 5);
11042 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11043 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11045 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11046 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11048 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11049 reply_len
= wpa_supplicant_global_iface_list(
11050 global
, reply
, reply_size
);
11051 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11052 reply_len
= wpa_supplicant_global_iface_interfaces(
11053 global
, buf
+ 10, reply
, reply_size
);
11055 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11056 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11059 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11060 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11063 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11064 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11065 #endif /* CONFIG_FST */
11066 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11067 wpa_supplicant_terminate_proc(global
);
11068 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11069 wpas_notify_suspend(global
);
11070 } else if (os_strcmp(buf
, "RESUME") == 0) {
11071 wpas_notify_resume(global
);
11072 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11073 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11075 if (global
->p2p_init_wpa_s
) {
11077 /* Check if P2P redirection would work for this
11079 return wpa_supplicant_ctrl_iface_process(
11080 global
->p2p_init_wpa_s
,
11083 #endif /* CONFIG_P2P */
11086 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11087 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11089 #ifndef CONFIG_NO_CONFIG_WRITE
11090 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11091 if (wpas_global_ctrl_iface_save_config(global
))
11093 #endif /* CONFIG_NO_CONFIG_WRITE */
11094 } else if (os_strcmp(buf
, "STATUS") == 0) {
11095 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11097 #ifdef CONFIG_MODULE_TESTS
11098 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11099 if (wpas_module_tests() < 0)
11101 #endif /* CONFIG_MODULE_TESTS */
11102 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11103 if (wpa_debug_reopen_file() < 0)
11106 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11110 if (reply_len
< 0) {
11111 os_memcpy(reply
, "FAIL\n", 5);
11115 *resp_len
= reply_len
;