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
);
640 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
641 os_free(wpa_s
->dpp_config_obj_override
);
642 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
643 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
644 os_free(wpa_s
->dpp_discovery_override
);
645 wpa_s
->dpp_discovery_override
= os_strdup(value
);
646 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
647 os_free(wpa_s
->dpp_groups_override
);
648 wpa_s
->dpp_groups_override
= os_strdup(value
);
649 } else if (os_strcasecmp(cmd
, "dpp_devices_override") == 0) {
650 os_free(wpa_s
->dpp_devices_override
);
651 wpa_s
->dpp_devices_override
= os_strdup(value
);
652 } else if (os_strcasecmp(cmd
,
653 "dpp_ignore_netaccesskey_mismatch") == 0) {
654 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
655 #endif /* CONFIG_DPP */
656 #endif /* CONFIG_TESTING_OPTIONS */
657 #ifndef CONFIG_NO_CONFIG_BLOBS
658 } else if (os_strcmp(cmd
, "blob") == 0) {
659 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
660 #endif /* CONFIG_NO_CONFIG_BLOBS */
661 } else if (os_strcasecmp(cmd
, "setband") == 0) {
662 ret
= wpas_ctrl_set_band(wpa_s
, value
);
664 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
665 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
668 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
670 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
671 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
672 #endif /* CONFIG_MBO */
673 } else if (os_strcasecmp(cmd
, "lci") == 0) {
674 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
675 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
676 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
677 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
678 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
679 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
680 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
681 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
682 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
683 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
684 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
687 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
689 wpa_supplicant_update_config(wpa_s
);
696 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
697 char *cmd
, char *buf
, size_t buflen
)
701 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
703 if (os_strcmp(cmd
, "version") == 0) {
704 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
705 } else if (os_strcasecmp(cmd
, "country") == 0) {
706 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
707 res
= os_snprintf(buf
, buflen
, "%c%c",
708 wpa_s
->conf
->country
[0],
709 wpa_s
->conf
->country
[1]);
710 #ifdef CONFIG_WIFI_DISPLAY
711 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
713 if (wpa_s
->global
->p2p
== NULL
||
714 wpa_s
->global
->p2p_disabled
)
717 enabled
= wpa_s
->global
->wifi_display
;
718 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
719 #endif /* CONFIG_WIFI_DISPLAY */
720 #ifdef CONFIG_TESTING_GET_GTK
721 } else if (os_strcmp(cmd
, "gtk") == 0) {
722 if (wpa_s
->last_gtk_len
== 0)
724 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
725 wpa_s
->last_gtk_len
);
727 #endif /* CONFIG_TESTING_GET_GTK */
728 } else if (os_strcmp(cmd
, "tls_library") == 0) {
729 res
= tls_get_library_version(buf
, buflen
);
731 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
734 if (os_snprintf_error(buflen
, res
))
740 #ifdef IEEE8021X_EAPOL
741 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
745 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
747 if (hwaddr_aton(addr
, bssid
)) {
748 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
753 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
754 rsn_preauth_deinit(wpa_s
->wpa
);
755 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
760 #endif /* IEEE8021X_EAPOL */
763 #ifdef CONFIG_PEERKEY
764 /* MLME-STKSTART.request(peer) */
765 static int wpa_supplicant_ctrl_iface_stkstart(
766 struct wpa_supplicant
*wpa_s
, char *addr
)
770 if (hwaddr_aton(addr
, peer
)) {
771 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
772 "address '%s'", addr
);
776 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
779 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
781 #endif /* CONFIG_PEERKEY */
786 static int wpa_supplicant_ctrl_iface_tdls_discover(
787 struct wpa_supplicant
*wpa_s
, char *addr
)
792 if (hwaddr_aton(addr
, peer
)) {
793 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
794 "address '%s'", addr
);
798 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
801 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
802 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
804 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
810 static int wpa_supplicant_ctrl_iface_tdls_setup(
811 struct wpa_supplicant
*wpa_s
, char *addr
)
816 if (hwaddr_aton(addr
, peer
)) {
817 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
818 "address '%s'", addr
);
822 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
825 if ((wpa_s
->conf
->tdls_external_control
) &&
826 wpa_tdls_is_external_setup(wpa_s
->wpa
))
827 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
829 wpa_tdls_remove(wpa_s
->wpa
, peer
);
831 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
832 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
834 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
840 static int wpa_supplicant_ctrl_iface_tdls_teardown(
841 struct wpa_supplicant
*wpa_s
, char *addr
)
846 if (os_strcmp(addr
, "*") == 0) {
847 /* remove everyone */
848 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
849 wpa_tdls_teardown_peers(wpa_s
->wpa
);
853 if (hwaddr_aton(addr
, peer
)) {
854 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
855 "address '%s'", addr
);
859 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
862 if ((wpa_s
->conf
->tdls_external_control
) &&
863 wpa_tdls_is_external_setup(wpa_s
->wpa
))
864 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
866 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
867 ret
= wpa_tdls_teardown_link(
869 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
871 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
877 static int ctrl_iface_get_capability_tdls(
878 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
882 ret
= os_snprintf(buf
, buflen
, "%s\n",
883 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
885 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
886 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
887 if (os_snprintf_error(buflen
, ret
))
893 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
894 struct wpa_supplicant
*wpa_s
, char *cmd
)
897 struct hostapd_freq_params freq_params
;
901 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
903 "tdls_chanswitch: Only supported with external setup");
907 os_memset(&freq_params
, 0, sizeof(freq_params
));
909 pos
= os_strchr(cmd
, ' ');
914 oper_class
= strtol(pos
, &end
, 10);
917 "tdls_chanswitch: Invalid op class provided");
922 freq_params
.freq
= atoi(pos
);
923 if (freq_params
.freq
== 0) {
924 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
928 #define SET_FREQ_SETTING(str) \
930 const char *pos2 = os_strstr(pos, " " #str "="); \
932 pos2 += sizeof(" " #str "=") - 1; \
933 freq_params.str = atoi(pos2); \
937 SET_FREQ_SETTING(center_freq1
);
938 SET_FREQ_SETTING(center_freq2
);
939 SET_FREQ_SETTING(bandwidth
);
940 SET_FREQ_SETTING(sec_channel_offset
);
941 #undef SET_FREQ_SETTING
943 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
944 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
946 if (hwaddr_aton(cmd
, peer
)) {
947 wpa_printf(MSG_DEBUG
,
948 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
953 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
954 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
955 MAC2STR(peer
), oper_class
, freq_params
.freq
,
956 freq_params
.center_freq1
, freq_params
.center_freq2
,
957 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
958 freq_params
.ht_enabled
? " HT" : "",
959 freq_params
.vht_enabled
? " VHT" : "");
961 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
966 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
967 struct wpa_supplicant
*wpa_s
, char *cmd
)
971 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
973 "tdls_chanswitch: Only supported with external setup");
977 if (hwaddr_aton(cmd
, peer
)) {
978 wpa_printf(MSG_DEBUG
,
979 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
984 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
987 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
991 static int wpa_supplicant_ctrl_iface_tdls_link_status(
992 struct wpa_supplicant
*wpa_s
, const char *addr
,
993 char *buf
, size_t buflen
)
996 const char *tdls_status
;
999 if (hwaddr_aton(addr
, peer
)) {
1000 wpa_printf(MSG_DEBUG
,
1001 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1005 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1008 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1009 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1010 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1011 if (os_snprintf_error(buflen
, ret
))
1017 #endif /* CONFIG_TDLS */
1020 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1022 char *token
, *context
= NULL
;
1023 struct wmm_ac_ts_setup_params params
= {
1028 while ((token
= str_token(cmd
, " ", &context
))) {
1029 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1030 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1031 sscanf(token
, "nominal_msdu_size=%i",
1032 ¶ms
.nominal_msdu_size
) == 1 ||
1033 sscanf(token
, "mean_data_rate=%i",
1034 ¶ms
.mean_data_rate
) == 1 ||
1035 sscanf(token
, "min_phy_rate=%i",
1036 ¶ms
.minimum_phy_rate
) == 1 ||
1037 sscanf(token
, "sba=%i",
1038 ¶ms
.surplus_bandwidth_allowance
) == 1)
1041 if (os_strcasecmp(token
, "downlink") == 0) {
1042 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1043 } else if (os_strcasecmp(token
, "uplink") == 0) {
1044 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1045 } else if (os_strcasecmp(token
, "bidi") == 0) {
1046 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1047 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1048 params
.fixed_nominal_msdu
= 1;
1050 wpa_printf(MSG_DEBUG
,
1051 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1058 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1062 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1064 u8 tsid
= atoi(cmd
);
1066 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1070 #ifdef CONFIG_IEEE80211R
1071 static int wpa_supplicant_ctrl_iface_ft_ds(
1072 struct wpa_supplicant
*wpa_s
, char *addr
)
1074 u8 target_ap
[ETH_ALEN
];
1075 struct wpa_bss
*bss
;
1078 if (hwaddr_aton(addr
, target_ap
)) {
1079 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1080 "address '%s'", addr
);
1084 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1086 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1088 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1092 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1094 #endif /* CONFIG_IEEE80211R */
1098 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1101 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1103 u8 p2p_dev_addr
[ETH_ALEN
];
1104 #endif /* CONFIG_P2P */
1106 u8
*_p2p_dev_addr
= NULL
;
1107 #endif /* CONFIG_AP */
1109 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
1112 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1113 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1114 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1115 "P2P Device Address '%s'",
1119 _p2p_dev_addr
= p2p_dev_addr
;
1120 #endif /* CONFIG_P2P */
1121 } else if (hwaddr_aton(cmd
, bssid
)) {
1122 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1128 if (wpa_s
->ap_iface
)
1129 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1130 #endif /* CONFIG_AP */
1132 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1136 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1137 char *cmd
, char *buf
,
1140 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1144 pin
= os_strchr(cmd
, ' ');
1148 if (os_strcmp(cmd
, "any") == 0)
1150 else if (os_strcmp(cmd
, "get") == 0) {
1151 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1154 } else if (hwaddr_aton(cmd
, bssid
)) {
1155 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1161 if (wpa_s
->ap_iface
) {
1166 pos
= os_strchr(pin
, ' ');
1169 timeout
= atoi(pos
);
1173 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1174 buf
, buflen
, timeout
);
1176 #endif /* CONFIG_AP */
1179 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1183 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1184 if (os_snprintf_error(buflen
, ret
))
1189 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1194 /* Return the generated PIN */
1195 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1196 if (os_snprintf_error(buflen
, ret
))
1202 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1203 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1210 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1211 (u8
*) cmd
, os_strlen(cmd
));
1212 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1213 if (*pos
< '0' || *pos
> '9')
1217 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1221 if (len
!= 4 && len
!= 8) {
1222 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1228 unsigned int pin_val
;
1229 pin_val
= atoi(pin
);
1230 if (!wps_pin_valid(pin_val
)) {
1231 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1232 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1233 if (os_snprintf_error(buflen
, ret
))
1239 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1240 if (os_snprintf_error(buflen
, ret
))
1247 #ifdef CONFIG_WPS_NFC
1249 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1252 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1254 if (cmd
== NULL
|| cmd
[0] == '\0')
1256 else if (hwaddr_aton(cmd
, bssid
))
1259 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1264 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1265 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1272 pos
= os_strchr(cmd
, ' ');
1275 if (os_strcmp(cmd
, "WPS") == 0)
1277 else if (os_strcmp(cmd
, "NDEF") == 0)
1282 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1286 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1288 reply
[res
++] = '\n';
1297 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1298 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1304 if (os_strcmp(cmd
, "WPS") == 0)
1306 else if (os_strcmp(cmd
, "NDEF") == 0)
1311 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1315 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1317 reply
[res
++] = '\n';
1326 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1327 struct wpa_supplicant
*wpa_s
, char *pos
)
1333 int forced_freq
= 0;
1335 freq
= strstr(pos
, " freq=");
1339 forced_freq
= atoi(freq
);
1342 len
= os_strlen(pos
);
1347 buf
= wpabuf_alloc(len
);
1350 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1355 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1362 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1363 char *reply
, size_t max_len
,
1369 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1373 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1375 reply
[res
++] = '\n';
1385 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1386 char *reply
, size_t max_len
,
1392 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1394 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1398 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1400 reply
[res
++] = '\n';
1407 #endif /* CONFIG_P2P */
1410 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1411 char *cmd
, char *reply
,
1417 pos
= os_strchr(cmd
, ' ');
1422 if (os_strcmp(cmd
, "WPS") == 0)
1424 else if (os_strcmp(cmd
, "NDEF") == 0)
1429 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1432 return wpas_ctrl_nfc_get_handover_req_wps(
1433 wpa_s
, reply
, max_len
, ndef
);
1437 if (os_strcmp(pos
, "P2P-CR") == 0) {
1438 return wpas_ctrl_nfc_get_handover_req_p2p(
1439 wpa_s
, reply
, max_len
, ndef
);
1441 #endif /* CONFIG_P2P */
1447 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1448 char *reply
, size_t max_len
,
1449 int ndef
, int cr
, char *uuid
)
1454 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1458 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1460 reply
[res
++] = '\n';
1470 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1471 char *reply
, size_t max_len
,
1477 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1481 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1483 reply
[res
++] = '\n';
1490 #endif /* CONFIG_P2P */
1493 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1494 char *cmd
, char *reply
,
1500 pos
= os_strchr(cmd
, ' ');
1505 if (os_strcmp(cmd
, "WPS") == 0)
1507 else if (os_strcmp(cmd
, "NDEF") == 0)
1512 pos2
= os_strchr(pos
, ' ');
1515 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1518 return wpas_ctrl_nfc_get_handover_sel_wps(
1519 wpa_s
, reply
, max_len
, ndef
,
1520 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1524 if (os_strcmp(pos
, "P2P-CR") == 0) {
1525 return wpas_ctrl_nfc_get_handover_sel_p2p(
1526 wpa_s
, reply
, max_len
, ndef
, 0);
1529 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1530 return wpas_ctrl_nfc_get_handover_sel_p2p(
1531 wpa_s
, reply
, max_len
, ndef
, 1);
1533 #endif /* CONFIG_P2P */
1539 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1543 struct wpabuf
*req
, *sel
;
1545 char *pos
, *role
, *type
, *pos2
;
1548 int forced_freq
= 0;
1550 freq
= strstr(cmd
, " freq=");
1554 forced_freq
= atoi(freq
);
1556 #endif /* CONFIG_P2P */
1559 pos
= os_strchr(role
, ' ');
1561 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1567 pos
= os_strchr(type
, ' ');
1569 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1574 pos2
= os_strchr(pos
, ' ');
1576 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1581 len
= os_strlen(pos
);
1583 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1588 req
= wpabuf_alloc(len
);
1590 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1593 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1594 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1599 len
= os_strlen(pos2
);
1601 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1607 sel
= wpabuf_alloc(len
);
1609 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1613 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1614 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1620 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1621 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1623 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1624 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1626 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1628 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1630 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1631 #endif /* CONFIG_AP */
1633 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1635 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1636 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1638 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1640 #endif /* CONFIG_P2P */
1642 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1643 "reported: role=%s type=%s", role
, type
);
1650 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1655 #endif /* CONFIG_WPS_NFC */
1658 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1667 struct wps_new_ap_settings ap
;
1669 pin
= os_strchr(cmd
, ' ');
1674 if (hwaddr_aton(cmd
, bssid
)) {
1675 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1680 new_ssid
= os_strchr(pin
, ' ');
1681 if (new_ssid
== NULL
)
1682 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1685 new_auth
= os_strchr(new_ssid
, ' ');
1686 if (new_auth
== NULL
)
1690 new_encr
= os_strchr(new_auth
, ' ');
1691 if (new_encr
== NULL
)
1695 new_key
= os_strchr(new_encr
, ' ');
1696 if (new_key
== NULL
)
1700 os_memset(&ap
, 0, sizeof(ap
));
1701 ap
.ssid_hex
= new_ssid
;
1704 ap
.key_hex
= new_key
;
1705 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1710 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1711 char *cmd
, char *buf
,
1716 const char *pin_txt
;
1718 if (!wpa_s
->ap_iface
)
1721 pos
= os_strchr(cmd
, ' ');
1725 if (os_strcmp(cmd
, "disable") == 0) {
1726 wpas_wps_ap_pin_disable(wpa_s
);
1727 return os_snprintf(buf
, buflen
, "OK\n");
1730 if (os_strcmp(cmd
, "random") == 0) {
1732 timeout
= atoi(pos
);
1733 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1734 if (pin_txt
== NULL
)
1736 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1739 if (os_strcmp(cmd
, "get") == 0) {
1740 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1741 if (pin_txt
== NULL
)
1743 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1746 if (os_strcmp(cmd
, "set") == 0) {
1751 pos
= os_strchr(pos
, ' ');
1754 timeout
= atoi(pos
);
1756 if (os_strlen(pin
) > buflen
)
1758 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1760 return os_snprintf(buf
, buflen
, "%s", pin
);
1765 #endif /* CONFIG_AP */
1768 #ifdef CONFIG_WPS_ER
1769 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1772 char *uuid
= cmd
, *pin
, *pos
;
1773 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1774 pin
= os_strchr(uuid
, ' ');
1778 pos
= os_strchr(pin
, ' ');
1781 if (hwaddr_aton(pos
, addr_buf
) == 0)
1784 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1788 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1791 char *uuid
= cmd
, *pin
;
1792 pin
= os_strchr(uuid
, ' ');
1796 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1800 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1801 struct wpa_supplicant
*wpa_s
, char *cmd
)
1803 char *uuid
= cmd
, *id
;
1804 id
= os_strchr(uuid
, ' ');
1808 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1812 static int wpa_supplicant_ctrl_iface_wps_er_config(
1813 struct wpa_supplicant
*wpa_s
, char *cmd
)
1820 struct wps_new_ap_settings ap
;
1822 pin
= os_strchr(cmd
, ' ');
1827 new_ssid
= os_strchr(pin
, ' ');
1828 if (new_ssid
== NULL
)
1832 new_auth
= os_strchr(new_ssid
, ' ');
1833 if (new_auth
== NULL
)
1837 new_encr
= os_strchr(new_auth
, ' ');
1838 if (new_encr
== NULL
)
1842 new_key
= os_strchr(new_encr
, ' ');
1843 if (new_key
== NULL
)
1847 os_memset(&ap
, 0, sizeof(ap
));
1848 ap
.ssid_hex
= new_ssid
;
1851 ap
.key_hex
= new_key
;
1852 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1856 #ifdef CONFIG_WPS_NFC
1857 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1858 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1865 uuid
= os_strchr(cmd
, ' ');
1870 if (os_strcmp(cmd
, "WPS") == 0)
1872 else if (os_strcmp(cmd
, "NDEF") == 0)
1877 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1881 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1883 reply
[res
++] = '\n';
1890 #endif /* CONFIG_WPS_NFC */
1891 #endif /* CONFIG_WPS_ER */
1893 #endif /* CONFIG_WPS */
1896 #ifdef CONFIG_IBSS_RSN
1897 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1898 struct wpa_supplicant
*wpa_s
, char *addr
)
1902 if (hwaddr_aton(addr
, peer
)) {
1903 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1904 "address '%s'", addr
);
1908 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1911 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1913 #endif /* CONFIG_IBSS_RSN */
1916 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1919 #ifdef IEEE8021X_EAPOL
1922 struct wpa_ssid
*ssid
;
1924 pos
= os_strchr(rsp
, '-');
1929 pos
= os_strchr(pos
, ':');
1934 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1935 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1936 (u8
*) pos
, os_strlen(pos
));
1938 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1940 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1945 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1947 #else /* IEEE8021X_EAPOL */
1948 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1950 #endif /* IEEE8021X_EAPOL */
1954 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1956 char *buf
, size_t buflen
)
1958 char *pos
, *end
, tmp
[30];
1959 int res
, verbose
, wps
, ret
;
1962 #endif /* CONFIG_HS20 */
1966 if (os_strcmp(params
, "-DRIVER") == 0)
1967 return wpa_drv_status(wpa_s
, buf
, buflen
);
1968 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1969 wps
= os_strcmp(params
, "-WPS") == 0;
1972 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1973 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1974 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1975 MAC2STR(wpa_s
->bssid
));
1976 if (os_snprintf_error(end
- pos
, ret
))
1979 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1981 if (os_snprintf_error(end
- pos
, ret
))
1985 u8
*_ssid
= ssid
->ssid
;
1986 size_t ssid_len
= ssid
->ssid_len
;
1987 u8 ssid_buf
[SSID_MAX_LEN
];
1988 if (ssid_len
== 0) {
1989 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1996 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1997 wpa_ssid_txt(_ssid
, ssid_len
),
1999 if (os_snprintf_error(end
- pos
, ret
))
2003 if (wps
&& ssid
->passphrase
&&
2004 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2005 (ssid
->mode
== WPAS_MODE_AP
||
2006 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2007 ret
= os_snprintf(pos
, end
- pos
,
2010 if (os_snprintf_error(end
- pos
, ret
))
2015 ret
= os_snprintf(pos
, end
- pos
,
2018 if (os_snprintf_error(end
- pos
, ret
))
2023 switch (ssid
->mode
) {
2024 case WPAS_MODE_INFRA
:
2025 ret
= os_snprintf(pos
, end
- pos
,
2028 case WPAS_MODE_IBSS
:
2029 ret
= os_snprintf(pos
, end
- pos
,
2033 ret
= os_snprintf(pos
, end
- pos
,
2036 case WPAS_MODE_P2P_GO
:
2037 ret
= os_snprintf(pos
, end
- pos
,
2040 case WPAS_MODE_P2P_GROUP_FORMATION
:
2041 ret
= os_snprintf(pos
, end
- pos
,
2042 "mode=P2P GO - group "
2045 case WPAS_MODE_MESH
:
2046 ret
= os_snprintf(pos
, end
- pos
,
2053 if (os_snprintf_error(end
- pos
, ret
))
2059 if (wpa_s
->ap_iface
) {
2060 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2064 #endif /* CONFIG_AP */
2065 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2069 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2072 #endif /* CONFIG_AP */
2073 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2074 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2075 wpa_s
->sme
.sae
.group
);
2076 if (os_snprintf_error(end
- pos
, ret
))
2080 #endif /* CONFIG_SAE */
2081 #endif /* CONFIG_SME */
2082 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2083 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2084 if (os_snprintf_error(end
- pos
, ret
))
2089 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2090 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2091 if (os_snprintf_error(end
- pos
, ret
))
2097 if (wpa_s
->global
->p2p
) {
2098 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2099 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2100 if (os_snprintf_error(end
- pos
, ret
))
2104 #endif /* CONFIG_P2P */
2106 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2107 MAC2STR(wpa_s
->own_addr
));
2108 if (os_snprintf_error(end
- pos
, ret
))
2113 if (wpa_s
->current_bss
&&
2114 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2115 HS20_IE_VENDOR_TYPE
)) &&
2116 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2117 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2120 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2121 release
= rel_num
+ 1;
2123 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2124 if (os_snprintf_error(end
- pos
, ret
))
2129 if (wpa_s
->current_ssid
) {
2130 struct wpa_cred
*cred
;
2133 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2136 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2139 if (cred
->provisioning_sp
) {
2140 ret
= os_snprintf(pos
, end
- pos
,
2141 "provisioning_sp=%s\n",
2142 cred
->provisioning_sp
);
2143 if (os_snprintf_error(end
- pos
, ret
))
2152 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2153 struct wpabuf
*names
=
2154 wpa_s
->current_bss
->anqp
->domain_name
;
2155 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2157 if (domain_name_list_contains(
2158 names
, cred
->domain
[i
], 1))
2161 if (i
== cred
->num_domain
)
2162 i
= 0; /* show first entry by default */
2164 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2166 if (os_snprintf_error(end
- pos
, ret
))
2171 if (wpa_s
->current_bss
== NULL
||
2172 wpa_s
->current_bss
->anqp
== NULL
)
2175 res
= interworking_home_sp_cred(
2177 wpa_s
->current_bss
->anqp
->domain_name
);
2185 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2186 if (os_snprintf_error(end
- pos
, ret
))
2193 #endif /* CONFIG_HS20 */
2195 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2196 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2197 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2203 #ifdef CONFIG_MACSEC
2204 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2207 #endif /* CONFIG_MACSEC */
2209 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2213 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2214 if (os_snprintf_error(end
- pos
, ret
))
2217 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2221 ret
= os_snprintf(pos
, end
- pos
, "\n");
2222 if (os_snprintf_error(end
- pos
, ret
))
2227 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2234 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2235 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2236 if (os_snprintf_error(end
- pos
, ret
))
2240 #endif /* CONFIG_WPS */
2244 * Allow using the STATUS command with default behavior, say for debug,
2245 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2246 * events with STATUS-NO_EVENTS.
2248 if (os_strcmp(params
, "-NO_EVENTS")) {
2249 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2250 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2251 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2253 MAC2STR(wpa_s
->bssid
),
2254 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2255 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2256 wpa_s
->current_ssid
->ssid_len
) : "");
2257 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2258 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2259 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2260 "- connection to " MACSTR
2261 " completed %s [id=%d id_str=%s]",
2262 MAC2STR(wpa_s
->bssid
), "(auth)",
2263 ssid
? ssid
->id
: -1,
2264 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2267 #endif /* ANDROID */
2273 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2278 struct wpa_ssid
*ssid
;
2281 /* cmd: "<network id> <BSSID>" */
2282 pos
= os_strchr(cmd
, ' ');
2287 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2288 if (hwaddr_aton(pos
, bssid
)) {
2289 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2293 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2295 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2300 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2301 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2307 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2308 char *cmd
, char *buf
,
2312 struct wpa_blacklist
*e
;
2316 /* cmd: "BLACKLIST [<BSSID>]" */
2320 e
= wpa_s
->blacklist
;
2322 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2324 if (os_snprintf_error(end
- pos
, ret
))
2333 if (os_strncmp(cmd
, "clear", 5) == 0) {
2334 wpa_blacklist_clear(wpa_s
);
2335 os_memcpy(buf
, "OK\n", 3);
2339 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2340 if (hwaddr_aton(cmd
, bssid
)) {
2341 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2346 * Add the BSSID twice, so its count will be 2, causing it to be
2347 * skipped when processing scan results.
2349 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2352 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2355 os_memcpy(buf
, "OK\n", 3);
2360 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2361 char *cmd
, char *buf
,
2364 char *pos
, *end
, *stamp
;
2367 /* cmd: "LOG_LEVEL [<level>]" */
2371 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2373 debug_level_str(wpa_debug_level
),
2374 wpa_debug_timestamp
);
2375 if (os_snprintf_error(end
- pos
, ret
))
2384 stamp
= os_strchr(cmd
, ' ');
2387 while (*stamp
== ' ') {
2392 if (os_strlen(cmd
)) {
2393 int level
= str_to_debug_level(cmd
);
2396 wpa_debug_level
= level
;
2399 if (stamp
&& os_strlen(stamp
))
2400 wpa_debug_timestamp
= atoi(stamp
);
2402 os_memcpy(buf
, "OK\n", 3);
2407 static int wpa_supplicant_ctrl_iface_list_networks(
2408 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2410 char *pos
, *end
, *prev
;
2411 struct wpa_ssid
*ssid
;
2416 ret
= os_snprintf(pos
, end
- pos
,
2417 "network id / ssid / bssid / flags\n");
2418 if (os_snprintf_error(end
- pos
, ret
))
2422 ssid
= wpa_s
->conf
->ssid
;
2424 /* skip over ssids until we find next one */
2425 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2426 int last_id
= atoi(cmd
+ 8);
2427 if (last_id
!= -1) {
2428 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2436 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2438 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2439 if (os_snprintf_error(end
- pos
, ret
))
2442 if (ssid
->bssid_set
) {
2443 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2444 MAC2STR(ssid
->bssid
));
2446 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2448 if (os_snprintf_error(end
- pos
, ret
))
2451 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2452 ssid
== wpa_s
->current_ssid
?
2454 ssid
->disabled
? "[DISABLED]" : "",
2455 ssid
->disabled_until
.sec
?
2456 "[TEMP-DISABLED]" : "",
2457 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2459 if (os_snprintf_error(end
- pos
, ret
))
2462 ret
= os_snprintf(pos
, end
- pos
, "\n");
2463 if (os_snprintf_error(end
- pos
, ret
))
2474 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2477 ret
= os_snprintf(pos
, end
- pos
, "-");
2478 if (os_snprintf_error(end
- pos
, ret
))
2481 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2489 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2490 const u8
*ie
, size_t ie_len
)
2492 struct wpa_ie_data data
;
2496 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2497 if (os_snprintf_error(end
- pos
, ret
))
2501 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2502 ret
= os_snprintf(pos
, end
- pos
, "?]");
2503 if (os_snprintf_error(end
- pos
, ret
))
2510 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2511 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2512 pos
== start
? "" : "+");
2513 if (os_snprintf_error(end
- pos
, ret
))
2517 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2518 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2519 pos
== start
? "" : "+");
2520 if (os_snprintf_error(end
- pos
, ret
))
2524 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2525 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2526 pos
== start
? "" : "+");
2527 if (os_snprintf_error(end
- pos
, ret
))
2531 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2532 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2533 pos
== start
? "" : "+");
2534 if (os_snprintf_error(end
- pos
, ret
))
2538 #ifdef CONFIG_IEEE80211R
2539 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2540 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2541 pos
== start
? "" : "+");
2542 if (os_snprintf_error(end
- pos
, ret
))
2546 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2547 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2548 pos
== start
? "" : "+");
2549 if (os_snprintf_error(end
- pos
, ret
))
2553 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2554 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2555 pos
== start
? "" : "+");
2556 if (os_snprintf_error(end
- pos
, ret
))
2560 #endif /* CONFIG_IEEE80211R */
2561 #ifdef CONFIG_IEEE80211W
2562 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2563 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2564 pos
== start
? "" : "+");
2565 if (os_snprintf_error(end
- pos
, ret
))
2569 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2570 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2571 pos
== start
? "" : "+");
2572 if (os_snprintf_error(end
- pos
, ret
))
2576 #endif /* CONFIG_IEEE80211W */
2578 #ifdef CONFIG_SUITEB
2579 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2580 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2581 pos
== start
? "" : "+");
2582 if (os_snprintf_error(end
- pos
, ret
))
2586 #endif /* CONFIG_SUITEB */
2588 #ifdef CONFIG_SUITEB192
2589 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2590 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2591 pos
== start
? "" : "+");
2592 if (os_snprintf_error(end
- pos
, ret
))
2596 #endif /* CONFIG_SUITEB192 */
2599 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2600 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2601 pos
== start
? "" : "+");
2602 if (os_snprintf_error(end
- pos
, ret
))
2606 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2607 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2608 pos
== start
? "" : "+");
2609 if (os_snprintf_error(end
- pos
, ret
))
2613 #ifdef CONFIG_IEEE80211R
2614 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2615 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2616 pos
== start
? "" : "+");
2617 if (os_snprintf_error(end
- pos
, ret
))
2621 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2622 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2623 pos
== start
? "" : "+");
2624 if (os_snprintf_error(end
- pos
, ret
))
2628 #endif /* CONFIG_IEEE80211R */
2629 #endif /* CONFIG_FILS */
2632 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2633 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2634 pos
== start
? "" : "+");
2635 if (os_snprintf_error(end
- pos
, ret
))
2639 #endif /* CONFIG_OWE */
2642 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2643 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2644 pos
== start
? "" : "+");
2645 if (os_snprintf_error(end
- pos
, ret
))
2649 #endif /* CONFIG_DPP */
2651 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2652 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2653 pos
== start
? "" : "+");
2654 if (os_snprintf_error(end
- pos
, ret
))
2659 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2661 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2662 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2663 if (os_snprintf_error(end
- pos
, ret
))
2668 ret
= os_snprintf(pos
, end
- pos
, "]");
2669 if (os_snprintf_error(end
- pos
, ret
))
2678 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2679 char *pos
, char *end
,
2680 struct wpabuf
*wps_ie
)
2687 if (wps_is_selected_pbc_registrar(wps_ie
))
2689 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2691 else if (wps_is_selected_pin_registrar(wps_ie
))
2696 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2697 if (!os_snprintf_error(end
- pos
, ret
))
2699 wpabuf_free(wps_ie
);
2702 #endif /* CONFIG_WPS */
2705 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2706 char *pos
, char *end
,
2707 const struct wpa_bss
*bss
)
2710 struct wpabuf
*wps_ie
;
2711 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2712 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2713 #else /* CONFIG_WPS */
2715 #endif /* CONFIG_WPS */
2719 /* Format one result on one text line into a buffer. */
2720 static int wpa_supplicant_ctrl_iface_scan_result(
2721 struct wpa_supplicant
*wpa_s
,
2722 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2726 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
;
2728 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2729 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2731 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2732 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2733 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2735 return 0; /* Do not show P2P listen discovery results here */
2740 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2741 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2742 if (os_snprintf_error(end
- pos
, ret
))
2745 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2747 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2748 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2750 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2753 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2755 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2756 osen_ie
, 2 + osen_ie
[1]);
2757 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2758 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2759 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2760 if (os_snprintf_error(end
- pos
, ret
))
2765 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2766 if (os_snprintf_error(end
- pos
, ret
))
2770 if (bss_is_dmg(bss
)) {
2772 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2773 if (os_snprintf_error(end
- pos
, ret
))
2776 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2777 case IEEE80211_CAP_DMG_IBSS
:
2780 case IEEE80211_CAP_DMG_AP
:
2783 case IEEE80211_CAP_DMG_PBSS
:
2790 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2791 if (os_snprintf_error(end
- pos
, ret
))
2795 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2796 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2797 if (os_snprintf_error(end
- pos
, ret
))
2801 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2802 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2803 if (os_snprintf_error(end
- pos
, ret
))
2809 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2810 if (os_snprintf_error(end
- pos
, ret
))
2815 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2816 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2817 if (os_snprintf_error(end
- pos
, ret
))
2821 #endif /* CONFIG_HS20 */
2823 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2824 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2825 if (os_snprintf_error(end
- pos
, ret
))
2829 #endif /* CONFIG_FILS */
2831 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2832 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2833 if (os_snprintf_error(end
- pos
, ret
))
2837 #endif /* CONFIG_FST */
2839 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2840 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2841 if (os_snprintf_error(end
- pos
, ret
))
2845 ret
= os_snprintf(pos
, end
- pos
, "\n");
2846 if (os_snprintf_error(end
- pos
, ret
))
2854 static int wpa_supplicant_ctrl_iface_scan_results(
2855 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2858 struct wpa_bss
*bss
;
2863 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2865 if (os_snprintf_error(end
- pos
, ret
))
2869 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2870 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2872 if (ret
< 0 || ret
>= end
- pos
)
2883 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2884 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2886 char *pos
, ifname
[IFNAMSIZ
+ 1];
2890 pos
= os_strstr(cmd
, "ifname=");
2893 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2896 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2899 os_strlcpy(reply
, ifname
, max_len
);
2900 return os_strlen(ifname
);
2904 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2905 struct wpa_supplicant
*wpa_s
, char *cmd
)
2908 struct wpa_ssid
*ssid
;
2911 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2913 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2915 wpa_printf(MSG_DEBUG
,
2916 "CTRL_IFACE: Could not find network id=%d", id
);
2919 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2920 wpa_printf(MSG_DEBUG
,
2921 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2924 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2925 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2926 wpa_printf(MSG_ERROR
,
2927 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2932 * TODO: If necessary write our own group_add function,
2933 * for now we can reuse select_network
2935 wpa_supplicant_select_network(wpa_s
, ssid
);
2941 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2942 struct wpa_supplicant
*wpa_s
, char *cmd
)
2944 struct wpa_supplicant
*orig
;
2945 struct wpa_global
*global
;
2948 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2950 global
= wpa_s
->global
;
2953 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2954 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2960 wpa_printf(MSG_ERROR
,
2961 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2965 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2966 wpa_printf(MSG_ERROR
,
2967 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2971 wpa_s
->reassociate
= 0;
2972 wpa_s
->disconnected
= 1;
2973 wpa_supplicant_cancel_sched_scan(wpa_s
);
2974 wpa_supplicant_cancel_scan(wpa_s
);
2977 * TODO: If necessary write our own group_remove function,
2978 * for now we can reuse deauthenticate
2980 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2982 if (wpa_s
->mesh_if_created
)
2983 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
2989 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
2990 struct wpa_supplicant
*wpa_s
, char *cmd
)
2994 if (hwaddr_aton(cmd
, addr
) < 0)
2997 return wpas_mesh_peer_remove(wpa_s
, addr
);
3001 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3002 struct wpa_supplicant
*wpa_s
, char *cmd
)
3008 pos
= os_strstr(cmd
, " duration=");
3011 duration
= atoi(pos
+ 10);
3016 if (hwaddr_aton(cmd
, addr
))
3019 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3022 #endif /* CONFIG_MESH */
3025 static int wpa_supplicant_ctrl_iface_select_network(
3026 struct wpa_supplicant
*wpa_s
, char *cmd
)
3029 struct wpa_ssid
*ssid
;
3032 /* cmd: "<network id>" or "any" */
3033 if (os_strncmp(cmd
, "any", 3) == 0) {
3034 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3038 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3040 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3042 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3043 "network id=%d", id
);
3046 if (ssid
->disabled
== 2) {
3047 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3048 "SELECT_NETWORK with persistent P2P group");
3053 pos
= os_strstr(cmd
, " freq=");
3055 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3057 os_free(wpa_s
->select_network_scan_freqs
);
3058 wpa_s
->select_network_scan_freqs
= freqs
;
3062 wpa_s
->scan_min_time
.sec
= 0;
3063 wpa_s
->scan_min_time
.usec
= 0;
3064 wpa_supplicant_select_network(wpa_s
, ssid
);
3070 static int wpa_supplicant_ctrl_iface_enable_network(
3071 struct wpa_supplicant
*wpa_s
, char *cmd
)
3074 struct wpa_ssid
*ssid
;
3076 /* cmd: "<network id>" or "all" */
3077 if (os_strcmp(cmd
, "all") == 0) {
3078 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3082 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3084 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3086 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3087 "network id=%d", id
);
3090 if (ssid
->disabled
== 2) {
3091 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3092 "ENABLE_NETWORK with persistent P2P group");
3096 if (os_strstr(cmd
, " no-connect")) {
3101 wpa_s
->scan_min_time
.sec
= 0;
3102 wpa_s
->scan_min_time
.usec
= 0;
3103 wpa_supplicant_enable_network(wpa_s
, ssid
);
3109 static int wpa_supplicant_ctrl_iface_disable_network(
3110 struct wpa_supplicant
*wpa_s
, char *cmd
)
3113 struct wpa_ssid
*ssid
;
3115 /* cmd: "<network id>" or "all" */
3116 if (os_strcmp(cmd
, "all") == 0) {
3117 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3121 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3123 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3125 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3126 "network id=%d", id
);
3129 if (ssid
->disabled
== 2) {
3130 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3131 "DISABLE_NETWORK with persistent P2P "
3136 wpa_supplicant_disable_network(wpa_s
, ssid
);
3142 static int wpa_supplicant_ctrl_iface_add_network(
3143 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3145 struct wpa_ssid
*ssid
;
3148 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3150 ssid
= wpa_supplicant_add_network(wpa_s
);
3154 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3155 if (os_snprintf_error(buflen
, ret
))
3161 static int wpa_supplicant_ctrl_iface_remove_network(
3162 struct wpa_supplicant
*wpa_s
, char *cmd
)
3165 struct wpa_ssid
*ssid
;
3168 /* cmd: "<network id>" or "all" */
3169 if (os_strcmp(cmd
, "all") == 0) {
3170 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3171 if (wpa_s
->sched_scanning
)
3172 wpa_supplicant_cancel_sched_scan(wpa_s
);
3174 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3175 if (wpa_s
->current_ssid
) {
3177 wpa_s
->sme
.prev_bssid_set
= 0;
3178 #endif /* CONFIG_SME */
3179 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3180 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3181 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3182 wpa_s
->own_disconnect_req
= 1;
3183 wpa_supplicant_deauthenticate(
3184 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3186 ssid
= wpa_s
->conf
->ssid
;
3188 struct wpa_ssid
*remove_ssid
= ssid
;
3191 if (wpa_s
->last_ssid
== remove_ssid
)
3192 wpa_s
->last_ssid
= NULL
;
3193 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3194 wpa_config_remove_network(wpa_s
->conf
, id
);
3200 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3202 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3204 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3209 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3210 "network id=%d", id
);
3217 static int wpa_supplicant_ctrl_iface_update_network(
3218 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3219 char *name
, char *value
)
3223 ret
= wpa_config_set(ssid
, name
, value
, 0);
3225 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3226 "variable '%s'", name
);
3230 return 0; /* No change to the previously configured value */
3232 if (os_strcmp(name
, "bssid") != 0 &&
3233 os_strcmp(name
, "bssid_hint") != 0 &&
3234 os_strcmp(name
, "priority") != 0) {
3235 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3237 if (wpa_s
->current_ssid
== ssid
||
3238 wpa_s
->current_ssid
== NULL
) {
3240 * Invalidate the EAP session cache if anything in the
3241 * current or previously used configuration changes.
3243 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3247 if ((os_strcmp(name
, "psk") == 0 &&
3248 value
[0] == '"' && ssid
->ssid_len
) ||
3249 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3250 wpa_config_update_psk(ssid
);
3251 else if (os_strcmp(name
, "priority") == 0)
3252 wpa_config_update_prio_list(wpa_s
->conf
);
3258 static int wpa_supplicant_ctrl_iface_set_network(
3259 struct wpa_supplicant
*wpa_s
, char *cmd
)
3261 int id
, ret
, prev_bssid_set
, prev_disabled
;
3262 struct wpa_ssid
*ssid
;
3264 u8 prev_bssid
[ETH_ALEN
];
3266 /* cmd: "<network id> <variable name> <value>" */
3267 name
= os_strchr(cmd
, ' ');
3272 value
= os_strchr(name
, ' ');
3278 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3280 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3281 (u8
*) value
, os_strlen(value
));
3283 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3285 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3290 prev_bssid_set
= ssid
->bssid_set
;
3291 prev_disabled
= ssid
->disabled
;
3292 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3293 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3296 (ssid
->bssid_set
!= prev_bssid_set
||
3297 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3298 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3300 if (prev_disabled
!= ssid
->disabled
&&
3301 (prev_disabled
== 2 || ssid
->disabled
== 2))
3302 wpas_notify_network_type_changed(wpa_s
, ssid
);
3308 static int wpa_supplicant_ctrl_iface_get_network(
3309 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3313 struct wpa_ssid
*ssid
;
3316 /* cmd: "<network id> <variable name>" */
3317 name
= os_strchr(cmd
, ' ');
3318 if (name
== NULL
|| buflen
== 0)
3323 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3326 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3328 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3333 value
= wpa_config_get_no_key(ssid
, name
);
3334 if (value
== NULL
) {
3335 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3336 "variable '%s'", name
);
3340 res
= os_strlcpy(buf
, value
, buflen
);
3341 if (res
>= buflen
) {
3352 static int wpa_supplicant_ctrl_iface_dup_network(
3353 struct wpa_supplicant
*wpa_s
, char *cmd
,
3354 struct wpa_supplicant
*dst_wpa_s
)
3356 struct wpa_ssid
*ssid_s
, *ssid_d
;
3357 char *name
, *id
, *value
;
3358 int id_s
, id_d
, ret
;
3360 /* cmd: "<src network id> <dst network id> <variable name>" */
3361 id
= os_strchr(cmd
, ' ');
3366 name
= os_strchr(id
, ' ');
3374 wpa_printf(MSG_DEBUG
,
3375 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3376 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3378 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3379 if (ssid_s
== NULL
) {
3380 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3381 "network id=%d", id_s
);
3385 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3386 if (ssid_d
== NULL
) {
3387 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3388 "network id=%d", id_d
);
3392 value
= wpa_config_get(ssid_s
, name
);
3393 if (value
== NULL
) {
3394 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3395 "variable '%s'", name
);
3399 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3408 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3409 char *buf
, size_t buflen
)
3412 struct wpa_cred
*cred
;
3417 ret
= os_snprintf(pos
, end
- pos
,
3418 "cred id / realm / username / domain / imsi\n");
3419 if (os_snprintf_error(end
- pos
, ret
))
3423 cred
= wpa_s
->conf
->cred
;
3425 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3426 cred
->id
, cred
->realm
? cred
->realm
: "",
3427 cred
->username
? cred
->username
: "",
3428 cred
->domain
? cred
->domain
[0] : "",
3429 cred
->imsi
? cred
->imsi
: "");
3430 if (os_snprintf_error(end
- pos
, ret
))
3441 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3442 char *buf
, size_t buflen
)
3444 struct wpa_cred
*cred
;
3447 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3449 cred
= wpa_config_add_cred(wpa_s
->conf
);
3453 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3455 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3456 if (os_snprintf_error(buflen
, ret
))
3462 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3463 struct wpa_cred
*cred
)
3465 struct wpa_ssid
*ssid
;
3470 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3475 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3476 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3480 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3482 /* Remove any network entry created based on the removed credential */
3483 ssid
= wpa_s
->conf
->ssid
;
3485 if (ssid
->parent_cred
== cred
) {
3488 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3489 "used the removed credential", ssid
->id
);
3490 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3491 if (os_snprintf_error(sizeof(str
), res
))
3492 str
[sizeof(str
) - 1] = '\0';
3494 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3503 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3507 struct wpa_cred
*cred
, *prev
;
3509 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3510 * "provisioning_sp=<FQDN> */
3511 if (os_strcmp(cmd
, "all") == 0) {
3512 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3513 cred
= wpa_s
->conf
->cred
;
3517 wpas_ctrl_remove_cred(wpa_s
, prev
);
3522 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3523 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3525 cred
= wpa_s
->conf
->cred
;
3531 for (i
= 0; i
< prev
->num_domain
; i
++) {
3532 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3535 wpas_ctrl_remove_cred(wpa_s
, prev
);
3543 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3544 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3546 cred
= wpa_s
->conf
->cred
;
3550 if (prev
->provisioning_sp
&&
3551 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3552 wpas_ctrl_remove_cred(wpa_s
, prev
);
3558 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3560 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3561 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3565 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3569 struct wpa_cred
*cred
;
3572 /* cmd: "<cred id> <variable name> <value>" */
3573 name
= os_strchr(cmd
, ' ');
3578 value
= os_strchr(name
, ' ');
3584 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3586 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3587 (u8
*) value
, os_strlen(value
));
3589 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3591 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3596 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3597 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3598 "variable '%s'", name
);
3602 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3608 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3609 char *cmd
, char *buf
,
3614 struct wpa_cred
*cred
;
3617 /* cmd: "<cred id> <variable name>" */
3618 name
= os_strchr(cmd
, ' ');
3624 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3627 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3629 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3634 value
= wpa_config_get_cred_no_key(cred
, name
);
3635 if (value
== NULL
) {
3636 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3641 res
= os_strlcpy(buf
, value
, buflen
);
3642 if (res
>= buflen
) {
3653 #ifndef CONFIG_NO_CONFIG_WRITE
3654 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3658 if (!wpa_s
->conf
->update_config
) {
3659 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3660 "to update configuration (update_config=0)");
3664 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3666 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3667 "update configuration");
3669 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3675 #endif /* CONFIG_NO_CONFIG_WRITE */
3678 struct cipher_info
{
3684 static const struct cipher_info ciphers
[] = {
3685 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3686 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3687 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3688 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3689 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3690 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3691 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3692 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3695 static const struct cipher_info ciphers_group_mgmt
[] = {
3696 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3697 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3698 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3699 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3703 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3704 struct wpa_driver_capa
*capa
,
3705 char *buf
, size_t buflen
)
3718 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3724 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3725 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3726 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3727 pos
== buf
? "" : " ",
3729 if (os_snprintf_error(end
- pos
, ret
))
3739 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3740 struct wpa_driver_capa
*capa
,
3741 char *buf
, size_t buflen
)
3754 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3760 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3761 if (capa
->enc
& ciphers
[i
].capa
) {
3762 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3763 pos
== buf
? "" : " ",
3765 if (os_snprintf_error(end
- pos
, ret
))
3775 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3776 struct wpa_driver_capa
*capa
,
3777 char *buf
, size_t buflen
)
3789 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3790 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3791 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3792 pos
== buf
? "" : " ",
3793 ciphers_group_mgmt
[i
].name
);
3794 if (os_snprintf_error(end
- pos
, ret
))
3804 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3805 struct wpa_driver_capa
*capa
,
3806 char *buf
, size_t buflen
)
3818 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3825 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3826 if (os_snprintf_error(end
- pos
, ret
))
3830 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3831 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3832 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3833 if (os_snprintf_error(end
- pos
, ret
))
3838 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3839 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3840 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3841 if (os_snprintf_error(end
- pos
, ret
))
3846 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3847 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3848 if (os_snprintf_error(end
- pos
, ret
))
3853 #ifdef CONFIG_SUITEB
3854 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3855 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3856 if (os_snprintf_error(end
- pos
, ret
))
3860 #endif /* CONFIG_SUITEB */
3861 #ifdef CONFIG_SUITEB192
3862 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3863 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3864 if (os_snprintf_error(end
- pos
, ret
))
3868 #endif /* CONFIG_SUITEB192 */
3870 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
3871 ret
= os_snprintf(pos
, end
- pos
, " OWE");
3872 if (os_snprintf_error(end
- pos
, ret
))
3876 #endif /* CONFIG_OWE */
3878 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
3879 ret
= os_snprintf(pos
, end
- pos
, " DPP");
3880 if (os_snprintf_error(end
- pos
, ret
))
3884 #endif /* CONFIG_DPP */
3886 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
3887 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
3888 if (os_snprintf_error(end
- pos
, ret
))
3892 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
3893 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
3894 if (os_snprintf_error(end
- pos
, ret
))
3898 #ifdef CONFIG_IEEE80211R
3899 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
3900 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
3901 if (os_snprintf_error(end
- pos
, ret
))
3905 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
3906 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
3907 if (os_snprintf_error(end
- pos
, ret
))
3911 #endif /* CONFIG_IEEE80211R */
3912 #endif /* CONFIG_FILS */
3918 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3919 struct wpa_driver_capa
*capa
,
3920 char *buf
, size_t buflen
)
3932 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3938 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3939 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3940 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3941 pos
== buf
? "" : " ");
3942 if (os_snprintf_error(end
- pos
, ret
))
3947 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3948 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3949 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3950 pos
== buf
? "" : " ");
3951 if (os_snprintf_error(end
- pos
, ret
))
3960 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
3961 int res
, char *strict
,
3962 struct wpa_driver_capa
*capa
,
3963 char *buf
, size_t buflen
)
3975 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3981 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3982 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3983 pos
== buf
? "" : " ");
3984 if (os_snprintf_error(end
- pos
, ret
))
3989 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3990 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3991 pos
== buf
? "" : " ");
3992 if (os_snprintf_error(end
- pos
, ret
))
3997 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3998 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3999 pos
== buf
? "" : " ");
4000 if (os_snprintf_error(end
- pos
, ret
))
4006 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4007 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4008 pos
== buf
? "" : " ");
4009 if (os_snprintf_error(end
- pos
, ret
))
4013 #endif /* CONFIG_SAE */
4016 if (wpa_is_fils_supported(wpa_s
)) {
4017 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4018 pos
== buf
? "" : " ");
4019 if (os_snprintf_error(end
- pos
, ret
))
4024 #ifdef CONFIG_FILS_SK_PFS
4025 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4026 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4027 pos
== buf
? "" : " ");
4028 if (os_snprintf_error(end
- pos
, ret
))
4032 #endif /* CONFIG_FILS_SK_PFS */
4033 #endif /* CONFIG_FILS */
4039 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4040 struct wpa_driver_capa
*capa
,
4041 char *buf
, size_t buflen
)
4053 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4059 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4060 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4061 pos
== buf
? "" : " ");
4062 if (os_snprintf_error(end
- pos
, ret
))
4067 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4068 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4069 pos
== buf
? "" : " ");
4070 if (os_snprintf_error(end
- pos
, ret
))
4076 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4077 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4078 pos
== buf
? "" : " ");
4079 if (os_snprintf_error(end
- pos
, ret
))
4083 #endif /* CONFIG_MESH */
4089 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4090 char *buf
, size_t buflen
)
4092 struct hostapd_channel_data
*chnl
;
4094 char *pos
, *end
, *hmode
;
4099 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4100 switch (wpa_s
->hw
.modes
[j
].mode
) {
4101 case HOSTAPD_MODE_IEEE80211B
:
4104 case HOSTAPD_MODE_IEEE80211G
:
4107 case HOSTAPD_MODE_IEEE80211A
:
4110 case HOSTAPD_MODE_IEEE80211AD
:
4116 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4117 if (os_snprintf_error(end
- pos
, ret
))
4120 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4121 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4122 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4124 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4125 if (os_snprintf_error(end
- pos
, ret
))
4129 ret
= os_snprintf(pos
, end
- pos
, "\n");
4130 if (os_snprintf_error(end
- pos
, ret
))
4139 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4140 char *buf
, size_t buflen
)
4142 struct hostapd_channel_data
*chnl
;
4144 char *pos
, *end
, *hmode
;
4149 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4150 switch (wpa_s
->hw
.modes
[j
].mode
) {
4151 case HOSTAPD_MODE_IEEE80211B
:
4154 case HOSTAPD_MODE_IEEE80211G
:
4157 case HOSTAPD_MODE_IEEE80211A
:
4160 case HOSTAPD_MODE_IEEE80211AD
:
4166 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4168 if (os_snprintf_error(end
- pos
, ret
))
4171 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4172 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4173 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4175 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4176 chnl
[i
].chan
, chnl
[i
].freq
,
4177 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4179 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4182 if (os_snprintf_error(end
- pos
, ret
))
4186 ret
= os_snprintf(pos
, end
- pos
, "\n");
4187 if (os_snprintf_error(end
- pos
, ret
))
4196 static int wpa_supplicant_ctrl_iface_get_capability(
4197 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4200 struct wpa_driver_capa capa
;
4206 /* Determine whether or not strict checking was requested */
4207 len
= os_strlcpy(field
, _field
, sizeof(field
));
4208 if (len
>= sizeof(field
))
4210 strict
= os_strchr(field
, ' ');
4211 if (strict
!= NULL
) {
4213 if (os_strcmp(strict
, "strict") != 0)
4217 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4218 field
, strict
? strict
: "");
4220 if (os_strcmp(field
, "eap") == 0) {
4221 return eap_get_names(buf
, buflen
);
4224 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4226 if (os_strcmp(field
, "pairwise") == 0)
4227 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4230 if (os_strcmp(field
, "group") == 0)
4231 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4234 if (os_strcmp(field
, "group_mgmt") == 0)
4235 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4238 if (os_strcmp(field
, "key_mgmt") == 0)
4239 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4242 if (os_strcmp(field
, "proto") == 0)
4243 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4246 if (os_strcmp(field
, "auth_alg") == 0)
4247 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4248 &capa
, buf
, buflen
);
4250 if (os_strcmp(field
, "modes") == 0)
4251 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4254 if (os_strcmp(field
, "channels") == 0)
4255 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4257 if (os_strcmp(field
, "freq") == 0)
4258 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4261 if (os_strcmp(field
, "tdls") == 0)
4262 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4263 #endif /* CONFIG_TDLS */
4266 if (os_strcmp(field
, "erp") == 0) {
4267 res
= os_snprintf(buf
, buflen
, "ERP");
4268 if (os_snprintf_error(buflen
, res
))
4272 #endif /* CONFIG_EPR */
4275 if (os_strcmp(field
, "fips") == 0) {
4276 res
= os_snprintf(buf
, buflen
, "FIPS");
4277 if (os_snprintf_error(buflen
, res
))
4281 #endif /* CONFIG_FIPS */
4284 if (os_strcmp(field
, "acs") == 0) {
4285 res
= os_snprintf(buf
, buflen
, "ACS");
4286 if (os_snprintf_error(buflen
, res
))
4290 #endif /* CONFIG_ACS */
4293 if (os_strcmp(field
, "fils") == 0) {
4294 #ifdef CONFIG_FILS_SK_PFS
4295 if (wpa_is_fils_supported(wpa_s
) &&
4296 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4297 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4298 if (os_snprintf_error(buflen
, res
))
4302 #endif /* CONFIG_FILS_SK_PFS */
4304 if (wpa_is_fils_supported(wpa_s
)) {
4305 res
= os_snprintf(buf
, buflen
, "FILS");
4306 if (os_snprintf_error(buflen
, res
))
4311 #endif /* CONFIG_FILS */
4313 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4320 #ifdef CONFIG_INTERWORKING
4321 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4322 struct wpabuf
*data
)
4332 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4333 if (os_snprintf_error(end
- pos
, ret
))
4337 d
= wpabuf_head_u8(data
);
4338 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4339 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4340 if (os_snprintf_error(end
- pos
, ret
))
4345 ret
= os_snprintf(pos
, end
- pos
, "\n");
4346 if (os_snprintf_error(end
- pos
, ret
))
4352 #endif /* CONFIG_INTERWORKING */
4356 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4359 const u8
*ie
, *ie_end
;
4363 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4366 ie_end
= ie
+ 2 + ie
[1];
4368 if (ie_end
- ie
< 2)
4371 info
= WPA_GET_LE16(ie
);
4373 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4374 if (os_snprintf_error(end
- pos
, ret
))
4378 if (info
& BIT(7)) {
4379 /* Cache Identifier Included */
4380 if (ie_end
- ie
< 2)
4382 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4384 if (os_snprintf_error(end
- pos
, ret
))
4390 if (info
& BIT(8)) {
4391 /* HESSID Included */
4392 if (ie_end
- ie
< ETH_ALEN
)
4394 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4396 if (os_snprintf_error(end
- pos
, ret
))
4402 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4404 if (ie_end
- ie
< realms
* 2)
4406 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4407 if (os_snprintf_error(end
- pos
, ret
))
4411 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4416 ret
= os_snprintf(pos
, end
- pos
, "\n");
4417 if (os_snprintf_error(end
- pos
, ret
))
4424 #endif /* CONFIG_FILS */
4427 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4428 unsigned long mask
, char *buf
, size_t buflen
)
4433 const u8
*ie
, *ie2
, *osen_ie
, *mesh
;
4438 if (mask
& WPA_BSS_MASK_ID
) {
4439 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4440 if (os_snprintf_error(end
- pos
, ret
))
4445 if (mask
& WPA_BSS_MASK_BSSID
) {
4446 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4447 MAC2STR(bss
->bssid
));
4448 if (os_snprintf_error(end
- pos
, ret
))
4453 if (mask
& WPA_BSS_MASK_FREQ
) {
4454 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4455 if (os_snprintf_error(end
- pos
, ret
))
4460 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4461 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4463 if (os_snprintf_error(end
- pos
, ret
))
4468 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4469 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4471 if (os_snprintf_error(end
- pos
, ret
))
4476 if (mask
& WPA_BSS_MASK_QUAL
) {
4477 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4478 if (os_snprintf_error(end
- pos
, ret
))
4483 if (mask
& WPA_BSS_MASK_NOISE
) {
4484 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4485 if (os_snprintf_error(end
- pos
, ret
))
4490 if (mask
& WPA_BSS_MASK_LEVEL
) {
4491 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4492 if (os_snprintf_error(end
- pos
, ret
))
4497 if (mask
& WPA_BSS_MASK_TSF
) {
4498 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4499 (unsigned long long) bss
->tsf
);
4500 if (os_snprintf_error(end
- pos
, ret
))
4505 if (mask
& WPA_BSS_MASK_AGE
) {
4506 struct os_reltime now
;
4508 os_get_reltime(&now
);
4509 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4510 (int) (now
.sec
- bss
->last_update
.sec
));
4511 if (os_snprintf_error(end
- pos
, ret
))
4516 if (mask
& WPA_BSS_MASK_IE
) {
4517 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4518 if (os_snprintf_error(end
- pos
, ret
))
4522 ie
= (const u8
*) (bss
+ 1);
4523 for (i
= 0; i
< bss
->ie_len
; i
++) {
4524 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4525 if (os_snprintf_error(end
- pos
, ret
))
4530 ret
= os_snprintf(pos
, end
- pos
, "\n");
4531 if (os_snprintf_error(end
- pos
, ret
))
4536 if (mask
& WPA_BSS_MASK_FLAGS
) {
4537 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4538 if (os_snprintf_error(end
- pos
, ret
))
4542 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4544 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4546 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4548 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4550 pos
= wpa_supplicant_ie_txt(pos
, end
,
4551 mesh
? "RSN" : "WPA2", ie2
,
4553 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4555 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4556 osen_ie
, 2 + osen_ie
[1]);
4557 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4558 if (!ie
&& !ie2
&& !osen_ie
&&
4559 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4560 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4561 if (os_snprintf_error(end
- pos
, ret
))
4567 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4568 if (os_snprintf_error(end
- pos
, ret
))
4573 if (bss_is_dmg(bss
)) {
4575 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4576 if (os_snprintf_error(end
- pos
, ret
))
4579 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4580 case IEEE80211_CAP_DMG_IBSS
:
4583 case IEEE80211_CAP_DMG_AP
:
4586 case IEEE80211_CAP_DMG_PBSS
:
4593 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4594 if (os_snprintf_error(end
- pos
, ret
))
4598 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4599 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4600 if (os_snprintf_error(end
- pos
, ret
))
4604 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4605 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4606 if (os_snprintf_error(end
- pos
, ret
))
4611 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4612 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4613 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4614 if (os_snprintf_error(end
- pos
, ret
))
4619 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4620 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4621 if (os_snprintf_error(end
- pos
, ret
))
4625 #endif /* CONFIG_HS20 */
4627 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4628 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4629 if (os_snprintf_error(end
- pos
, ret
))
4633 #endif /* CONFIG_FILS */
4635 ret
= os_snprintf(pos
, end
- pos
, "\n");
4636 if (os_snprintf_error(end
- pos
, ret
))
4641 if (mask
& WPA_BSS_MASK_SSID
) {
4642 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4643 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4644 if (os_snprintf_error(end
- pos
, ret
))
4650 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4651 ie
= (const u8
*) (bss
+ 1);
4652 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4653 if (ret
>= end
- pos
)
4658 #endif /* CONFIG_WPS */
4661 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4662 ie
= (const u8
*) (bss
+ 1);
4663 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4664 if (ret
>= end
- pos
)
4669 #endif /* CONFIG_P2P */
4671 #ifdef CONFIG_WIFI_DISPLAY
4672 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4674 ie
= (const u8
*) (bss
+ 1);
4675 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4676 WFD_IE_VENDOR_TYPE
);
4678 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4679 if (os_snprintf_error(end
- pos
, ret
)) {
4685 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4690 ret
= os_snprintf(pos
, end
- pos
, "\n");
4691 if (os_snprintf_error(end
- pos
, ret
))
4696 #endif /* CONFIG_WIFI_DISPLAY */
4698 #ifdef CONFIG_INTERWORKING
4699 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4700 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4701 struct wpa_bss_anqp_elem
*elem
;
4703 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4704 anqp
->capability_list
);
4705 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4707 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4708 anqp
->network_auth_type
);
4709 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4710 anqp
->roaming_consortium
);
4711 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4712 anqp
->ip_addr_type_availability
);
4713 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4715 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4716 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4718 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4719 anqp
->fils_realm_info
);
4721 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4722 anqp
->hs20_capability_list
);
4723 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4724 anqp
->hs20_operator_friendly_name
);
4725 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4726 anqp
->hs20_wan_metrics
);
4727 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4728 anqp
->hs20_connection_capability
);
4729 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4730 anqp
->hs20_operating_class
);
4731 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4732 anqp
->hs20_osu_providers_list
);
4733 #endif /* CONFIG_HS20 */
4735 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4736 struct wpa_bss_anqp_elem
, list
) {
4739 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4741 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4744 #endif /* CONFIG_INTERWORKING */
4747 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4748 ie
= (const u8
*) (bss
+ 1);
4749 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4750 if (ret
>= end
- pos
)
4755 #endif /* CONFIG_MESH */
4757 if (mask
& WPA_BSS_MASK_SNR
) {
4758 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4759 if (os_snprintf_error(end
- pos
, ret
))
4764 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4765 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4766 bss
->est_throughput
);
4767 if (os_snprintf_error(end
- pos
, ret
))
4773 if (mask
& WPA_BSS_MASK_FST
) {
4774 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4775 if (ret
< 0 || ret
>= end
- pos
)
4779 #endif /* CONFIG_FST */
4781 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4782 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4783 bss
->last_update_idx
);
4784 if (os_snprintf_error(end
- pos
, ret
))
4789 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4790 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4791 if (os_snprintf_error(end
- pos
, ret
))
4795 ie
= (const u8
*) (bss
+ 1);
4797 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4798 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4799 if (os_snprintf_error(end
- pos
, ret
))
4804 ret
= os_snprintf(pos
, end
- pos
, "\n");
4805 if (os_snprintf_error(end
- pos
, ret
))
4811 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4812 ret
= print_fils_indication(bss
, pos
, end
);
4817 #endif /* CONFIG_FILS */
4819 if (mask
& WPA_BSS_MASK_DELIM
) {
4820 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4821 if (os_snprintf_error(end
- pos
, ret
))
4830 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4831 const char *cmd
, char *buf
,
4836 struct wpa_bss
*bss
;
4837 struct wpa_bss
*bsslast
= NULL
;
4838 struct dl_list
*next
;
4841 char *ctmp
, *end
= buf
+ buflen
;
4842 unsigned long mask
= WPA_BSS_MASK_ALL
;
4844 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4845 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4846 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4848 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4850 } else { /* N1-N2 */
4851 unsigned int id1
, id2
;
4853 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4854 wpa_printf(MSG_INFO
, "Wrong BSS range "
4859 if (*(cmd
+ 6) == '-')
4862 id1
= atoi(cmd
+ 6);
4864 if (*ctmp
>= '0' && *ctmp
<= '9')
4867 id2
= (unsigned int) -1;
4868 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4869 if (id2
== (unsigned int) -1)
4870 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4874 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4875 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4876 struct wpa_bss
*tmp
= bss
;
4878 next
= tmp
->list_id
.next
;
4879 if (next
== &wpa_s
->bss_id
)
4881 tmp
= dl_list_entry(
4882 next
, struct wpa_bss
,
4891 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4892 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4893 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4894 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4895 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4897 bss
= wpa_bss_get_id(wpa_s
, i
);
4898 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4900 bss
= wpa_bss_get_id(wpa_s
, i
);
4902 next
= bss
->list_id
.next
;
4903 if (next
== &wpa_s
->bss_id
)
4906 bss
= dl_list_entry(next
, struct wpa_bss
,
4909 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
4910 bss
= wpa_s
->current_bss
;
4912 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4913 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4914 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4917 #endif /* CONFIG_P2P */
4918 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4919 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4921 struct wpa_bss
*tmp
;
4924 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4933 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4934 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4936 mask
= WPA_BSS_MASK_ALL
;
4942 if (bsslast
== NULL
)
4945 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4949 if (bss
== bsslast
) {
4950 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4951 (bss
== dl_list_last(&wpa_s
->bss_id
,
4952 struct wpa_bss
, list_id
))) {
4955 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4957 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4958 wpa_printf(MSG_DEBUG
,
4959 "Could not add end delim");
4964 next
= bss
->list_id
.next
;
4965 if (next
== &wpa_s
->bss_id
)
4967 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4968 } while (bss
&& len
);
4974 static int wpa_supplicant_ctrl_iface_ap_scan(
4975 struct wpa_supplicant
*wpa_s
, char *cmd
)
4977 int ap_scan
= atoi(cmd
);
4978 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4982 static int wpa_supplicant_ctrl_iface_scan_interval(
4983 struct wpa_supplicant
*wpa_s
, char *cmd
)
4985 int scan_int
= atoi(cmd
);
4986 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4990 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4991 struct wpa_supplicant
*wpa_s
, char *cmd
)
4993 int expire_age
= atoi(cmd
);
4994 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4998 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4999 struct wpa_supplicant
*wpa_s
, char *cmd
)
5001 int expire_count
= atoi(cmd
);
5002 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5006 static void wpa_supplicant_ctrl_iface_bss_flush(
5007 struct wpa_supplicant
*wpa_s
, char *cmd
)
5009 int flush_age
= atoi(cmd
);
5012 wpa_bss_flush(wpa_s
);
5014 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5018 #ifdef CONFIG_TESTING_OPTIONS
5019 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5021 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5022 /* MLME-DELETEKEYS.request */
5023 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
5024 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
5025 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
5026 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
5027 #ifdef CONFIG_IEEE80211W
5028 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
5029 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
5030 #endif /* CONFIG_IEEE80211W */
5032 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5034 /* MLME-SETPROTECTION.request(None) */
5035 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5036 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5037 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5038 wpa_sm_drop_sa(wpa_s
->wpa
);
5040 #endif /* CONFIG_TESTING_OPTIONS */
5043 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5046 #ifdef CONFIG_NO_SCAN_PROCESSING
5048 #else /* CONFIG_NO_SCAN_PROCESSING */
5050 struct wpa_bss
*bss
;
5051 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5053 if (hwaddr_aton(addr
, bssid
)) {
5054 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5055 "address '%s'", addr
);
5059 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5062 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5063 "configuration known for the target AP");
5067 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5069 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5075 * TODO: Find best network configuration block from configuration to
5076 * allow roaming to other networks
5079 wpa_s
->reassociate
= 1;
5080 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5083 #endif /* CONFIG_NO_SCAN_PROCESSING */
5088 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5090 unsigned int timeout
= atoi(cmd
);
5091 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5092 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5093 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5095 unsigned int search_delay
;
5096 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5100 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5101 wpa_dbg(wpa_s
, MSG_INFO
,
5102 "Reject P2P_FIND since interface is disabled");
5105 if (os_strstr(cmd
, "type=social"))
5106 type
= P2P_FIND_ONLY_SOCIAL
;
5107 else if (os_strstr(cmd
, "type=progressive"))
5108 type
= P2P_FIND_PROGRESSIVE
;
5110 pos
= os_strstr(cmd
, "dev_id=");
5113 if (hwaddr_aton(pos
, dev_id
))
5118 pos
= os_strstr(cmd
, "dev_type=");
5121 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5123 _dev_type
= dev_type
;
5126 pos
= os_strstr(cmd
, "delay=");
5129 search_delay
= atoi(pos
);
5131 search_delay
= wpas_p2p_search_delay(wpa_s
);
5133 pos
= os_strstr(cmd
, "freq=");
5141 /* Must be searched for last, because it adds nul termination */
5142 pos
= os_strstr(cmd
, " seek=");
5145 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5148 _seek
[seek_count
++] = pos
;
5150 term
= os_strchr(pos
, ' ');
5154 pos
= os_strstr(term
+ 1, "seek=");
5158 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5163 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5164 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5168 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5170 const char *last
= NULL
;
5175 /* Expected predefined CPT names delimited by ':' */
5176 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5177 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5178 wpa_printf(MSG_ERROR
,
5179 "P2PS: CPT name list is too long, expected up to %d names",
5180 P2PS_FEATURE_CAPAB_CPT_MAX
);
5185 token_len
= last
- token
;
5187 if (token_len
== 3 &&
5188 os_memcmp(token
, "UDP", token_len
) == 0) {
5189 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5190 } else if (token_len
== 3 &&
5191 os_memcmp(token
, "MAC", token_len
) == 0) {
5192 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5194 wpa_printf(MSG_ERROR
,
5195 "P2PS: Unsupported CPT name '%s'", token
);
5200 if (isblank((unsigned char) *last
)) {
5210 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5212 struct p2ps_provision
*p2ps_prov
;
5214 size_t info_len
= 0;
5216 u8 role
= P2PS_SETUP_NONE
;
5217 long long unsigned val
;
5220 pos
= os_strstr(cmd
, "info=");
5223 info_len
= os_strlen(pos
);
5226 info
= os_malloc(info_len
+ 1);
5228 info_len
= utf8_unescape(pos
, info_len
,
5229 info
, info_len
+ 1);
5235 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5236 if (p2ps_prov
== NULL
) {
5242 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5243 p2ps_prov
->info
[info_len
] = '\0';
5247 pos
= os_strstr(cmd
, "status=");
5249 p2ps_prov
->status
= atoi(pos
+ 7);
5251 p2ps_prov
->status
= -1;
5253 pos
= os_strstr(cmd
, "adv_id=");
5254 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5256 p2ps_prov
->adv_id
= val
;
5258 pos
= os_strstr(cmd
, "method=");
5260 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5262 p2ps_prov
->method
= 0;
5264 pos
= os_strstr(cmd
, "session=");
5265 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5267 p2ps_prov
->session_id
= val
;
5269 pos
= os_strstr(cmd
, "adv_mac=");
5270 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5273 pos
= os_strstr(cmd
, "session_mac=");
5274 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5277 pos
= os_strstr(cmd
, "cpt=");
5279 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5280 p2ps_prov
->cpt_priority
))
5283 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5286 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5287 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5289 /* force conncap with tstCap (no sanity checks) */
5290 pos
= os_strstr(cmd
, "tstCap=");
5292 role
= strtol(pos
+ 7, NULL
, 16);
5294 pos
= os_strstr(cmd
, "role=");
5296 role
= strtol(pos
+ 5, NULL
, 16);
5297 if (role
!= P2PS_SETUP_CLIENT
&&
5298 role
!= P2PS_SETUP_GROUP_OWNER
)
5299 role
= P2PS_SETUP_NONE
;
5302 p2ps_prov
->role
= role
;
5312 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5315 struct p2ps_provision
*p2ps_prov
;
5318 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5320 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5322 if (hwaddr_aton(cmd
, addr
))
5329 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5333 if (p2ps_prov
->status
< 0) {
5338 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5343 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5346 struct p2ps_provision
*p2ps_prov
;
5349 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5350 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5353 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5354 if (hwaddr_aton(cmd
, addr
))
5361 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5365 p2ps_prov
->pd_seeker
= 1;
5367 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5372 static int parse_freq(int chwidth
, int freq2
)
5377 return VHT_CHANWIDTH_80P80MHZ
;
5383 return VHT_CHANWIDTH_USE_HT
;
5385 return VHT_CHANWIDTH_80MHZ
;
5387 return VHT_CHANWIDTH_160MHZ
;
5389 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5396 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5397 char *buf
, size_t buflen
)
5402 enum p2p_wps_method wps_method
;
5405 int persistent_group
, persistent_id
= -1;
5412 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5413 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5414 size_t group_ssid_len
= 0;
5416 if (!wpa_s
->global
->p2p_init_wpa_s
)
5418 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5419 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5420 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5421 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5424 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5425 * [persistent|persistent=<network id>]
5426 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5427 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5429 if (hwaddr_aton(cmd
, addr
))
5437 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5438 pos2
= os_strstr(pos
, " persistent=");
5440 struct wpa_ssid
*ssid
;
5441 persistent_id
= atoi(pos2
+ 12);
5442 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5443 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5444 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5445 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5446 "SSID id=%d for persistent P2P group (GO)",
5451 join
= os_strstr(pos
, " join") != NULL
;
5452 auth
= os_strstr(pos
, " auth") != NULL
;
5453 automatic
= os_strstr(pos
, " auto") != NULL
;
5454 pd
= os_strstr(pos
, " provdisc") != NULL
;
5455 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5456 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5459 pos2
= os_strstr(pos
, " go_intent=");
5462 go_intent
= atoi(pos2
);
5463 if (go_intent
< 0 || go_intent
> 15)
5467 pos2
= os_strstr(pos
, " freq=");
5475 pos2
= os_strstr(pos
, " freq2=");
5477 freq2
= atoi(pos2
+ 7);
5479 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5481 chwidth
= atoi(pos2
+ 18);
5483 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5484 if (max_oper_chwidth
< 0)
5487 pos2
= os_strstr(pos
, " ssid=");
5492 end
= os_strchr(pos2
, ' ');
5494 group_ssid_len
= os_strlen(pos2
) / 2;
5496 group_ssid_len
= (end
- pos2
) / 2;
5497 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5498 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5500 group_ssid
= _group_ssid
;
5503 if (os_strncmp(pos
, "pin", 3) == 0) {
5504 /* Request random PIN (to be displayed) and enable the PIN */
5505 wps_method
= WPS_PIN_DISPLAY
;
5506 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5507 wps_method
= WPS_PBC
;
5508 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5509 wps_method
= WPS_P2PS
;
5512 pos
= os_strchr(pin
, ' ');
5513 wps_method
= WPS_PIN_KEYPAD
;
5516 if (os_strncmp(pos
, "display", 7) == 0)
5517 wps_method
= WPS_PIN_DISPLAY
;
5519 if (!wps_pin_str_valid(pin
)) {
5520 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5525 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5526 persistent_group
, automatic
, join
,
5527 auth
, go_intent
, freq
, freq2
, persistent_id
,
5528 pd
, ht40
, vht
, max_oper_chwidth
,
5529 group_ssid
, group_ssid_len
);
5530 if (new_pin
== -2) {
5531 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5534 if (new_pin
== -3) {
5535 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5540 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5541 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5542 if (os_snprintf_error(buflen
, ret
))
5547 os_memcpy(buf
, "OK\n", 3);
5552 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5554 unsigned int timeout
= atoi(cmd
);
5555 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5556 wpa_dbg(wpa_s
, MSG_INFO
,
5557 "Reject P2P_LISTEN since interface is disabled");
5560 return wpas_p2p_listen(wpa_s
, timeout
);
5564 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5568 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5570 /* <addr> <config method> [join|auto] */
5572 if (hwaddr_aton(cmd
, addr
))
5580 if (os_strstr(pos
, " join") != NULL
)
5581 use
= WPAS_P2P_PD_FOR_JOIN
;
5582 else if (os_strstr(pos
, " auto") != NULL
)
5583 use
= WPAS_P2P_PD_AUTO
;
5585 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5589 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5592 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5594 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5595 ssid
->passphrase
== NULL
)
5598 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5599 return os_strlen(buf
);
5603 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5604 char *buf
, size_t buflen
)
5608 u8 dst_buf
[ETH_ALEN
], *dst
;
5609 struct wpabuf
*tlvs
;
5613 if (hwaddr_aton(cmd
, dst_buf
))
5616 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5617 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5624 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5627 if (hexstr2bin(pos
, &version
, 1) < 0)
5633 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5634 #ifdef CONFIG_WIFI_DISPLAY
5635 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5636 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5637 #endif /* CONFIG_WIFI_DISPLAY */
5638 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5640 char *svc_info
= NULL
;
5644 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5647 pos
= os_strchr(pos
, ' ');
5648 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5653 pos
= os_strchr(svc_str
, ' ');
5658 /* All remaining data is the svc_info string */
5659 if (pos
&& pos
[0] && pos
[0] != ' ') {
5660 len
= os_strlen(pos
);
5662 /* Unescape in place */
5663 len
= utf8_unescape(pos
, len
, pos
, len
);
5670 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5673 len
= os_strlen(pos
);
5677 tlvs
= wpabuf_alloc(len
);
5680 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5685 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5690 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5691 if (os_snprintf_error(buflen
, res
))
5697 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5700 long long unsigned val
;
5702 if (sscanf(cmd
, "%llx", &val
) != 1)
5705 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5709 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5714 struct wpabuf
*resp_tlvs
;
5718 pos
= os_strchr(cmd
, ' ');
5726 if (hwaddr_aton(pos
, dst
))
5733 pos2
= os_strchr(pos
, ' ');
5737 dialog_token
= atoi(pos
);
5739 len
= os_strlen(pos2
);
5743 resp_tlvs
= wpabuf_alloc(len
);
5744 if (resp_tlvs
== NULL
)
5746 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5747 wpabuf_free(resp_tlvs
);
5751 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5752 wpabuf_free(resp_tlvs
);
5757 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5760 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5762 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5767 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5772 struct wpabuf
*query
, *resp
;
5774 pos
= os_strchr(cmd
, ' ');
5779 len
= os_strlen(cmd
);
5783 query
= wpabuf_alloc(len
);
5786 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5791 len
= os_strlen(pos
);
5797 resp
= wpabuf_alloc(len
);
5802 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5808 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5817 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5822 pos
= os_strchr(cmd
, ' ');
5827 if (hexstr2bin(cmd
, &version
, 1) < 0)
5830 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5834 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5835 u8 replace
, char *cmd
)
5839 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5840 char *svc_info
= NULL
;
5842 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5844 pos
= os_strchr(cmd
, ' ');
5849 /* Auto-Accept value is mandatory, and must be one of the
5850 * single values (0, 1, 2, 4) */
5851 auto_accept
= atoi(cmd
);
5852 switch (auto_accept
) {
5853 case P2PS_SETUP_NONE
: /* No auto-accept */
5854 case P2PS_SETUP_NEW
:
5855 case P2PS_SETUP_CLIENT
:
5856 case P2PS_SETUP_GROUP_OWNER
:
5862 /* Advertisement ID is mandatory */
5864 pos
= os_strchr(cmd
, ' ');
5869 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5870 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5873 /* Only allow replacements if exist, and adds if not */
5874 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5882 /* svc_state between 0 - 0xff is mandatory */
5883 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5886 pos
= os_strchr(pos
, ' ');
5890 /* config_methods is mandatory */
5892 if (sscanf(pos
, "%x", &config_methods
) != 1)
5895 if (!(config_methods
&
5896 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5899 pos
= os_strchr(pos
, ' ');
5906 /* Advertisement string is mandatory */
5907 if (!pos
[0] || pos
[0] == ' ')
5910 /* Terminate svc string */
5911 pos
= os_strchr(pos
, ' ');
5915 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5917 pos
= os_strchr(pos
, ' ');
5921 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5924 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5928 /* Service and Response Information are optional */
5929 if (pos
&& pos
[0]) {
5932 /* Note the bare ' included, which cannot exist legally
5933 * in unescaped string. */
5934 svc_info
= os_strstr(pos
, "svc_info='");
5938 len
= os_strlen(svc_info
);
5939 utf8_unescape(svc_info
, len
, svc_info
, len
);
5943 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
5944 (u8
) svc_state
, (u16
) config_methods
,
5945 svc_info
, cpt_prio
);
5949 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5953 pos
= os_strchr(cmd
, ' ');
5958 if (os_strcmp(cmd
, "bonjour") == 0)
5959 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
5960 if (os_strcmp(cmd
, "upnp") == 0)
5961 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
5962 if (os_strcmp(cmd
, "asp") == 0)
5963 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
5964 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5969 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
5973 struct wpabuf
*query
;
5976 len
= os_strlen(cmd
);
5980 query
= wpabuf_alloc(len
);
5983 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5988 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
5994 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5999 pos
= os_strchr(cmd
, ' ');
6004 if (hexstr2bin(cmd
, &version
, 1) < 0)
6007 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6011 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6015 if (os_strcmp(cmd
, "all") == 0) {
6016 wpas_p2p_service_flush_asp(wpa_s
);
6020 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6023 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6027 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6031 pos
= os_strchr(cmd
, ' ');
6036 if (os_strcmp(cmd
, "bonjour") == 0)
6037 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6038 if (os_strcmp(cmd
, "upnp") == 0)
6039 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6040 if (os_strcmp(cmd
, "asp") == 0)
6041 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6042 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6047 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6051 pos
= os_strchr(cmd
, ' ');
6056 if (os_strcmp(cmd
, "asp") == 0)
6057 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6059 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6064 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6070 if (hwaddr_aton(cmd
, addr
))
6073 return wpas_p2p_reject(wpa_s
, addr
);
6077 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6081 struct wpa_ssid
*ssid
;
6082 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6083 int freq
= 0, pref_freq
= 0;
6084 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6087 pos
= os_strstr(cmd
, " peer=");
6090 if (hwaddr_aton(pos
, peer
))
6094 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6095 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6096 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6097 "for persistent P2P group",
6102 pos
= os_strstr(cmd
, " freq=");
6110 pos
= os_strstr(cmd
, " pref=");
6113 pref_freq
= atoi(pos
);
6118 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6119 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6122 pos
= os_strstr(cmd
, "freq2=");
6124 freq2
= atoi(pos
+ 6);
6126 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6128 chwidth
= atoi(pos
+ 18);
6130 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6131 if (max_oper_chwidth
< 0)
6134 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6135 max_oper_chwidth
, pref_freq
);
6139 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6142 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6144 pos
= os_strstr(cmd
, " peer=");
6150 if (hwaddr_aton(pos
, peer
)) {
6151 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6155 pos
= os_strstr(pos
, " go_dev_addr=");
6158 if (hwaddr_aton(pos
, go_dev_addr
)) {
6159 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6163 go_dev
= go_dev_addr
;
6166 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6170 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6172 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6173 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6174 if (os_strncmp(cmd
, "group=", 6) == 0)
6175 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6181 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6182 int id
, int freq
, int vht_center_freq2
,
6183 int ht40
, int vht
, int vht_chwidth
)
6185 struct wpa_ssid
*ssid
;
6187 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6188 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6189 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6190 "for persistent P2P group",
6195 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6196 vht_center_freq2
, 0, ht40
, vht
,
6197 vht_chwidth
, NULL
, 0, 0);
6201 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6203 int freq
= 0, persistent
= 0, group_id
= -1;
6204 int vht
= wpa_s
->conf
->p2p_go_vht
;
6205 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6206 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6207 char *token
, *context
= NULL
;
6209 while ((token
= str_token(cmd
, " ", &context
))) {
6210 if (sscanf(token
, "freq=%d", &freq
) == 1 ||
6211 sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6212 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6213 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6215 } else if (os_strcmp(token
, "ht40") == 0) {
6217 } else if (os_strcmp(token
, "vht") == 0) {
6220 } else if (os_strcmp(token
, "persistent") == 0) {
6223 wpa_printf(MSG_DEBUG
,
6224 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6230 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6231 if (max_oper_chwidth
< 0)
6235 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6236 freq
, freq2
, ht40
, vht
,
6239 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6244 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6245 char *buf
, size_t buflen
)
6247 u8 dev_addr
[ETH_ALEN
];
6248 struct wpa_ssid
*ssid
;
6252 ssid
= wpa_s
->current_ssid
;
6253 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6254 hwaddr_aton(cmd
, dev_addr
))
6257 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6260 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6261 if (os_snprintf_error(buflen
, res
))
6267 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6268 const u8
*p2p_dev_addr
)
6270 struct wpa_supplicant
*wpa_s
;
6272 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6273 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6281 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6282 char *buf
, size_t buflen
)
6284 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6286 const struct p2p_peer_info
*info
;
6288 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6289 struct wpa_ssid
*ssid
;
6292 if (!wpa_s
->global
->p2p
)
6295 if (os_strcmp(cmd
, "FIRST") == 0) {
6298 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6299 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6304 if (hwaddr_aton(cmd
, addr
) < 0)
6310 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6313 group_capab
= info
->group_capab
;
6316 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6317 wpa_printf(MSG_DEBUG
,
6318 "P2P: Could not find any BSS with p2p_dev_addr "
6319 MACSTR
", hence override group_capab from 0x%x to 0",
6320 MAC2STR(info
->p2p_device_addr
), group_capab
);
6327 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6333 "serial_number=%s\n"
6334 "config_methods=0x%x\n"
6336 "group_capab=0x%x\n"
6338 MAC2STR(info
->p2p_device_addr
),
6339 wps_dev_type_bin2str(info
->pri_dev_type
,
6340 devtype
, sizeof(devtype
)),
6345 info
->serial_number
,
6346 info
->config_methods
,
6350 if (os_snprintf_error(end
- pos
, res
))
6354 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6357 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6358 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6359 wps_dev_type_bin2str(t
, devtype
,
6361 if (os_snprintf_error(end
- pos
, res
))
6366 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6368 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6369 if (os_snprintf_error(end
- pos
, res
))
6374 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6379 if (info
->vendor_elems
) {
6380 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6381 if (os_snprintf_error(end
- pos
, res
))
6385 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6386 wpabuf_head(info
->vendor_elems
),
6387 wpabuf_len(info
->vendor_elems
));
6389 res
= os_snprintf(pos
, end
- pos
, "\n");
6390 if (os_snprintf_error(end
- pos
, res
))
6399 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6404 if (wpa_s
->global
->p2p
== NULL
)
6407 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6410 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6411 struct wpa_freq_range
*freq
;
6412 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6413 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6414 freq
->min
, freq
->max
);
6417 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6422 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6426 if (wpa_s
->global
->p2p
== NULL
)
6429 param
= os_strchr(cmd
, ' ');
6434 if (os_strcmp(cmd
, "discoverability") == 0) {
6435 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6440 if (os_strcmp(cmd
, "managed") == 0) {
6441 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6445 if (os_strcmp(cmd
, "listen_channel") == 0) {
6447 u8 channel
, op_class
;
6449 channel
= atoi(param
);
6450 pos
= os_strchr(param
, ' ');
6451 op_class
= pos
? atoi(pos
) : 81;
6453 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6457 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6458 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6462 if (os_strcmp(cmd
, "noa") == 0) {
6464 int count
, start
, duration
;
6465 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6466 count
= atoi(param
);
6467 pos
= os_strchr(param
, ',');
6472 pos
= os_strchr(pos
, ',');
6476 duration
= atoi(pos
);
6477 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6479 if (count
== 0 && duration
> 0)
6481 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6482 "start=%d duration=%d", count
, start
, duration
);
6483 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6486 if (os_strcmp(cmd
, "ps") == 0)
6487 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6489 if (os_strcmp(cmd
, "oppps") == 0)
6490 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6492 if (os_strcmp(cmd
, "ctwindow") == 0)
6493 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6495 if (os_strcmp(cmd
, "disabled") == 0) {
6496 wpa_s
->global
->p2p_disabled
= atoi(param
);
6497 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6498 wpa_s
->global
->p2p_disabled
?
6499 "disabled" : "enabled");
6500 if (wpa_s
->global
->p2p_disabled
) {
6501 wpas_p2p_stop_find(wpa_s
);
6502 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6503 p2p_flush(wpa_s
->global
->p2p
);
6508 if (os_strcmp(cmd
, "conc_pref") == 0) {
6509 if (os_strcmp(param
, "sta") == 0)
6510 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6511 else if (os_strcmp(param
, "p2p") == 0)
6512 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6514 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6517 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6522 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6523 wpa_s
->force_long_sd
= atoi(param
);
6527 if (os_strcmp(cmd
, "peer_filter") == 0) {
6529 if (hwaddr_aton(param
, addr
))
6531 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6535 if (os_strcmp(cmd
, "cross_connect") == 0)
6536 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6538 if (os_strcmp(cmd
, "go_apsd") == 0) {
6539 if (os_strcmp(param
, "disable") == 0)
6540 wpa_s
->set_ap_uapsd
= 0;
6542 wpa_s
->set_ap_uapsd
= 1;
6543 wpa_s
->ap_uapsd
= atoi(param
);
6548 if (os_strcmp(cmd
, "client_apsd") == 0) {
6549 if (os_strcmp(param
, "disable") == 0)
6550 wpa_s
->set_sta_uapsd
= 0;
6554 /* format: BE,BK,VI,VO;max SP Length */
6556 pos
= os_strchr(param
, ',');
6561 pos
= os_strchr(pos
, ',');
6566 pos
= os_strchr(pos
, ',');
6571 /* ignore max SP Length for now */
6573 wpa_s
->set_sta_uapsd
= 1;
6574 wpa_s
->sta_uapsd
= 0;
6576 wpa_s
->sta_uapsd
|= BIT(0);
6578 wpa_s
->sta_uapsd
|= BIT(1);
6580 wpa_s
->sta_uapsd
|= BIT(2);
6582 wpa_s
->sta_uapsd
|= BIT(3);
6587 if (os_strcmp(cmd
, "disallow_freq") == 0)
6588 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6590 if (os_strcmp(cmd
, "disc_int") == 0) {
6591 int min_disc_int
, max_disc_int
, max_disc_tu
;
6596 min_disc_int
= atoi(pos
);
6597 pos
= os_strchr(pos
, ' ');
6602 max_disc_int
= atoi(pos
);
6603 pos
= os_strchr(pos
, ' ');
6608 max_disc_tu
= atoi(pos
);
6610 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6611 max_disc_int
, max_disc_tu
);
6614 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6615 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6619 #ifdef CONFIG_WPS_NFC
6620 if (os_strcmp(cmd
, "nfc_tag") == 0)
6621 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6622 #endif /* CONFIG_WPS_NFC */
6624 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6625 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6629 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6632 op_class
= atoi(param
);
6633 param
= os_strchr(param
, ':');
6638 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6643 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6650 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6652 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6653 wpa_s
->force_long_sd
= 0;
6655 #ifdef CONFIG_TESTING_OPTIONS
6656 os_free(wpa_s
->get_pref_freq_list_override
);
6657 wpa_s
->get_pref_freq_list_override
= NULL
;
6658 #endif /* CONFIG_TESTING_OPTIONS */
6660 wpas_p2p_stop_find(wpa_s
);
6661 wpa_s
->parent
->p2ps_method_config_any
= 0;
6662 if (wpa_s
->global
->p2p
)
6663 p2p_flush(wpa_s
->global
->p2p
);
6667 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6670 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6673 pos
= os_strchr(cmd
, ' ');
6679 pos2
= os_strchr(pos
, ' ');
6687 pos
= os_strchr(pos2
, ' ');
6695 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6699 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6702 unsigned int period
= 0, interval
= 0;
6705 pos
= os_strchr(cmd
, ' ');
6710 interval
= atoi(pos
);
6713 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6717 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6724 if (os_strncmp(pos
, "iface=", 6) == 0) {
6728 if (hwaddr_aton(pos
, peer
))
6731 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6736 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6738 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6740 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6742 wpa_printf(MSG_DEBUG
,
6743 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6747 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6750 #endif /* CONFIG_P2P */
6753 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6755 struct wpa_freq_range_list ranges
;
6757 struct hostapd_hw_modes
*mode
;
6760 if (wpa_s
->hw
.modes
== NULL
)
6763 os_memset(&ranges
, 0, sizeof(ranges
));
6764 if (freq_range_list_parse(&ranges
, val
) < 0)
6767 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6770 mode
= &wpa_s
->hw
.modes
[i
];
6771 for (j
= 0; j
< mode
->num_channels
; j
++) {
6774 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6777 freq
= mode
->channels
[j
].freq
;
6778 if (!freq_range_list_includes(&ranges
, freq
))
6781 int_array_add_unique(&freqs
, freq
);
6785 os_free(ranges
.range
);
6790 #ifdef CONFIG_INTERWORKING
6792 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6800 auto_sel
= os_strstr(param
, "auto") != NULL
;
6802 pos
= os_strstr(param
, "freq=");
6804 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6811 return interworking_select(wpa_s
, auto_sel
, freqs
);
6815 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6819 struct wpa_bss
*bss
;
6821 if (hwaddr_aton(dst
, bssid
)) {
6822 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6826 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6828 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6833 if (bss
->ssid_len
== 0) {
6836 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6837 " does not have SSID information", MAC2STR(bssid
));
6839 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6841 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6842 bss
->ssid_len
> 0) {
6850 wpa_printf(MSG_DEBUG
,
6851 "Found another matching BSS entry with SSID");
6854 return interworking_connect(wpa_s
, bss
, only_add
);
6858 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6860 u8 dst_addr
[ETH_ALEN
];
6863 #define MAX_ANQP_INFO_ID 100
6864 u16 id
[MAX_ANQP_INFO_ID
];
6867 u32 mbo_subtypes
= 0;
6869 used
= hwaddr_aton2(dst
, dst_addr
);
6875 while (num_id
< MAX_ANQP_INFO_ID
) {
6876 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6878 int num
= atoi(pos
+ 5);
6879 if (num
<= 0 || num
> 31)
6881 subtypes
|= BIT(num
);
6882 #else /* CONFIG_HS20 */
6884 #endif /* CONFIG_HS20 */
6885 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6887 int num
= atoi(pos
+ 4);
6889 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
6891 mbo_subtypes
|= BIT(num
);
6892 #else /* CONFIG_MBO */
6894 #endif /* CONFIG_MBO */
6896 id
[num_id
] = atoi(pos
);
6900 pos
= os_strchr(pos
+ 1, ',');
6906 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
6909 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
6914 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
6916 u8 dst_addr
[ETH_ALEN
];
6917 struct wpabuf
*advproto
, *query
= NULL
;
6922 used
= hwaddr_aton2(cmd
, dst_addr
);
6930 /* Advertisement Protocol ID */
6931 end
= os_strchr(pos
, ' ');
6935 len
= os_strlen(pos
);
6941 advproto
= wpabuf_alloc(len
);
6942 if (advproto
== NULL
)
6944 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
6948 /* Optional Query Request */
6953 len
= os_strlen(pos
);
6960 query
= wpabuf_alloc(len
);
6963 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
6968 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
6971 wpabuf_free(advproto
);
6978 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
6985 size_t resp_len
, start
, requested_len
;
6986 struct wpabuf
*resp
;
6989 used
= hwaddr_aton2(cmd
, addr
);
6996 dialog_token
= atoi(pos
);
6998 if (wpa_s
->last_gas_resp
&&
6999 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7000 dialog_token
== wpa_s
->last_gas_dialog_token
)
7001 resp
= wpa_s
->last_gas_resp
;
7002 else if (wpa_s
->prev_gas_resp
&&
7003 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7004 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7005 resp
= wpa_s
->prev_gas_resp
;
7009 resp_len
= wpabuf_len(resp
);
7011 requested_len
= resp_len
;
7013 pos
= os_strchr(pos
, ' ');
7016 if (start
> resp_len
)
7017 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7018 pos
= os_strchr(pos
, ',');
7022 requested_len
= atoi(pos
);
7023 if (start
+ requested_len
> resp_len
)
7024 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7027 if (requested_len
* 2 + 1 > buflen
)
7028 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7030 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7033 if (start
+ requested_len
== resp_len
) {
7035 * Free memory by dropping the response after it has been
7038 if (resp
== wpa_s
->prev_gas_resp
) {
7039 wpabuf_free(wpa_s
->prev_gas_resp
);
7040 wpa_s
->prev_gas_resp
= NULL
;
7042 wpabuf_free(wpa_s
->last_gas_resp
);
7043 wpa_s
->last_gas_resp
= NULL
;
7049 #endif /* CONFIG_INTERWORKING */
7054 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7056 u8 dst_addr
[ETH_ALEN
];
7061 used
= hwaddr_aton2(dst
, dst_addr
);
7068 int num
= atoi(pos
);
7069 if (num
<= 0 || num
> 31)
7071 subtypes
|= BIT(num
);
7072 pos
= os_strchr(pos
+ 1, ',');
7081 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7085 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7086 const u8
*addr
, const char *realm
)
7092 rlen
= os_strlen(realm
);
7094 buf
= os_malloc(len
);
7097 buf
[0] = 1; /* NAI Home Realm Count */
7098 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7100 os_memcpy(buf
+ 3, realm
, rlen
);
7102 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7103 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7112 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7115 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7116 u8 dst_addr
[ETH_ALEN
];
7122 used
= hwaddr_aton2(dst
, dst_addr
);
7126 while (dst
[used
] == ' ')
7128 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7129 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7132 len
= os_strlen(dst
+ used
);
7134 if (len
== 0 && cred
&& cred
->realm
)
7135 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7140 buf
= os_malloc(len
);
7143 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7148 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7149 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7157 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7160 u8 dst_addr
[ETH_ALEN
];
7162 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7164 used
= hwaddr_aton2(cmd
, dst_addr
);
7169 icon
= str_token(cmd
, " ", &ctx
);
7170 poffset
= str_token(cmd
, " ", &ctx
);
7171 psize
= str_token(cmd
, " ", &ctx
);
7172 if (!icon
|| !poffset
|| !psize
)
7175 wpa_s
->fetch_osu_icon_in_progress
= 0;
7176 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7181 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7183 u8 dst_addr
[ETH_ALEN
];
7188 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7190 used
= hwaddr_aton2(cmd
, dst_addr
);
7194 while (cmd
[used
] == ' ')
7196 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7198 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7202 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7204 u8 dst_addr
[ETH_ALEN
];
7208 used
= hwaddr_aton2(cmd
, dst_addr
);
7212 while (cmd
[used
] == ' ')
7216 wpa_s
->fetch_osu_icon_in_progress
= 0;
7217 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7218 (u8
*) icon
, os_strlen(icon
), inmem
);
7221 #endif /* CONFIG_HS20 */
7224 #ifdef CONFIG_AUTOSCAN
7226 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7229 enum wpa_states state
= wpa_s
->wpa_state
;
7230 char *new_params
= NULL
;
7232 if (os_strlen(cmd
) > 0) {
7233 new_params
= os_strdup(cmd
);
7234 if (new_params
== NULL
)
7238 os_free(wpa_s
->conf
->autoscan
);
7239 wpa_s
->conf
->autoscan
= new_params
;
7241 if (wpa_s
->conf
->autoscan
== NULL
)
7242 autoscan_deinit(wpa_s
);
7243 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7244 autoscan_init(wpa_s
, 1);
7245 else if (state
== WPA_SCANNING
)
7246 wpa_supplicant_reinit_autoscan(wpa_s
);
7248 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7249 wpa_supplicant_state_txt(state
));
7254 #endif /* CONFIG_AUTOSCAN */
7259 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7265 struct wpabuf
*tfs_req
= NULL
;
7267 if (os_strncmp(cmd
, "enter", 5) == 0)
7269 else if (os_strncmp(cmd
, "exit", 4) == 0)
7274 pos
= os_strstr(cmd
, " interval=");
7276 intval
= atoi(pos
+ 10);
7278 pos
= os_strstr(cmd
, " tfs_req=");
7283 end
= os_strchr(pos
, ' ');
7287 len
= os_strlen(pos
);
7291 tfs_req
= wpabuf_alloc(len
);
7292 if (tfs_req
== NULL
)
7294 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7295 wpabuf_free(tfs_req
);
7300 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7301 WNM_SLEEP_MODE_EXIT
, intval
,
7303 wpabuf_free(tfs_req
);
7309 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7311 int query_reason
, list
= 0;
7312 char *btm_candidates
= NULL
;
7314 query_reason
= atoi(cmd
);
7316 cmd
= os_strchr(cmd
, ' ');
7318 if (os_strncmp(cmd
, " list", 5) == 0)
7321 btm_candidates
= cmd
;
7324 wpa_printf(MSG_DEBUG
,
7325 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7326 query_reason
, list
? " candidate list" : "");
7328 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7333 #endif /* CONFIG_WNM */
7336 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7339 struct wpa_signal_info si
;
7343 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7350 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7351 "NOISE=%d\nFREQUENCY=%u\n",
7352 si
.current_signal
, si
.current_txrate
/ 1000,
7353 si
.current_noise
, si
.frequency
);
7354 if (os_snprintf_error(end
- pos
, ret
))
7358 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7359 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7360 channel_width_to_string(si
.chanwidth
));
7361 if (os_snprintf_error(end
- pos
, ret
))
7366 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
7367 ret
= os_snprintf(pos
, end
- pos
,
7368 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7369 si
.center_frq1
, si
.center_frq2
);
7370 if (os_snprintf_error(end
- pos
, ret
))
7375 if (si
.avg_signal
) {
7376 ret
= os_snprintf(pos
, end
- pos
,
7377 "AVG_RSSI=%d\n", si
.avg_signal
);
7378 if (os_snprintf_error(end
- pos
, ret
))
7383 if (si
.avg_beacon_signal
) {
7384 ret
= os_snprintf(pos
, end
- pos
,
7385 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7386 if (os_snprintf_error(end
- pos
, ret
))
7395 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7402 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7403 wpa_printf(MSG_DEBUG
,
7404 "Reject SIGNAL_MONITOR command - bgscan is active");
7407 pos
= os_strstr(cmd
, "THRESHOLD=");
7409 threshold
= atoi(pos
+ 10);
7410 pos
= os_strstr(cmd
, "HYSTERESIS=");
7412 hysteresis
= atoi(pos
+ 11);
7413 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7417 #ifdef CONFIG_TESTING_OPTIONS
7418 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7419 enum wpa_driver_if_type if_type
,
7421 unsigned int *freq_list
)
7423 char *pos
= wpa_s
->get_pref_freq_list_override
;
7425 unsigned int count
= 0;
7427 /* Override string format:
7428 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7431 if (atoi(pos
) == (int) if_type
)
7433 pos
= os_strchr(pos
, ' ');
7439 pos
= os_strchr(pos
, ':');
7443 end
= os_strchr(pos
, ' ');
7444 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7445 freq_list
[count
++] = atoi(pos
);
7446 pos
= os_strchr(pos
, ',');
7454 #endif /* CONFIG_TESTING_OPTIONS */
7457 static int wpas_ctrl_iface_get_pref_freq_list(
7458 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7460 unsigned int freq_list
[100], num
= 100, i
;
7462 enum wpa_driver_if_type iface_type
;
7468 /* buf: "<interface_type>" */
7469 if (os_strcmp(cmd
, "STATION") == 0)
7470 iface_type
= WPA_IF_STATION
;
7471 else if (os_strcmp(cmd
, "AP") == 0)
7472 iface_type
= WPA_IF_AP_BSS
;
7473 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7474 iface_type
= WPA_IF_P2P_GO
;
7475 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7476 iface_type
= WPA_IF_P2P_CLIENT
;
7477 else if (os_strcmp(cmd
, "IBSS") == 0)
7478 iface_type
= WPA_IF_IBSS
;
7479 else if (os_strcmp(cmd
, "TDLS") == 0)
7480 iface_type
= WPA_IF_TDLS
;
7484 wpa_printf(MSG_DEBUG
,
7485 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7488 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7492 for (i
= 0; i
< num
; i
++) {
7493 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7494 i
> 0 ? "," : "", freq_list
[i
]);
7495 if (os_snprintf_error(end
- pos
, ret
))
7504 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7505 char *buf
, size_t buflen
)
7510 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7511 (long long unsigned) wpa_s
->drv_flags
);
7512 if (os_snprintf_error(buflen
, ret
))
7518 for (i
= 0; i
< 64; i
++) {
7519 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7520 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7521 driver_flag_to_string(1LLU << i
));
7522 if (os_snprintf_error(end
- pos
, ret
))
7532 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7535 struct hostap_sta_driver_data sta
;
7538 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7542 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7543 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7544 if (os_snprintf_error(buflen
, ret
))
7551 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7552 char *buf
, size_t buflen
)
7556 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7558 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7559 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7562 country
[0] = cmd
[8];
7563 country
[1] = cmd
[9];
7565 p2p_set_country(p2p
, country
);
7568 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7569 if (os_snprintf_error(buflen
, ret
))
7574 #endif /* ANDROID */
7577 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7578 char *buf
, size_t buflen
)
7583 unsigned int vendor_id
, subcmd
;
7584 struct wpabuf
*reply
;
7585 size_t data_len
= 0;
7587 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7588 vendor_id
= strtoul(cmd
, &pos
, 16);
7589 if (!isblank((unsigned char) *pos
))
7592 subcmd
= strtoul(pos
, &pos
, 10);
7595 if (!isblank((unsigned char) *pos
++))
7597 data_len
= os_strlen(pos
);
7602 data
= os_malloc(data_len
);
7606 if (hexstr2bin(pos
, data
, data_len
)) {
7607 wpa_printf(MSG_DEBUG
,
7608 "Vendor command: wrong parameter format");
7614 reply
= wpabuf_alloc((buflen
- 1) / 2);
7620 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7624 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7634 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7637 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7638 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7639 #endif /* CONFIG_P2P */
7641 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7643 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7644 wpa_s
->ignore_post_flush_scan_res
= 1;
7646 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7648 * Avoid possible auto connect re-connection on getting
7649 * disconnected due to state flush.
7651 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7655 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7656 wpas_p2p_cancel(p2p_wpa_s
);
7657 p2p_ctrl_flush(p2p_wpa_s
);
7658 wpas_p2p_service_flush(p2p_wpa_s
);
7659 p2p_wpa_s
->global
->p2p_disabled
= 0;
7660 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7661 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7662 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7663 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7664 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7665 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7666 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7667 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7668 #endif /* CONFIG_P2P */
7670 #ifdef CONFIG_WPS_TESTING
7671 wps_version_number
= 0x20;
7672 wps_testing_dummy_cred
= 0;
7673 wps_corrupt_pkhash
= 0;
7674 wps_force_auth_types_in_use
= 0;
7675 wps_force_encr_types_in_use
= 0;
7676 #endif /* CONFIG_WPS_TESTING */
7678 wpa_s
->wps_fragment_size
= 0;
7679 wpas_wps_cancel(wpa_s
);
7680 wps_registrar_flush(wpa_s
->wps
->registrar
);
7681 #endif /* CONFIG_WPS */
7682 wpa_s
->after_wps
= 0;
7683 wpa_s
->known_wps_freq
= 0;
7686 wpas_dpp_deinit(wpa_s
);
7687 #endif /* CONFIG_DPP */
7690 #ifdef CONFIG_TDLS_TESTING
7692 #endif /* CONFIG_TDLS_TESTING */
7693 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7694 wpa_tdls_enable(wpa_s
->wpa
, 1);
7695 #endif /* CONFIG_TDLS */
7697 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7698 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7700 wpa_s
->no_keep_alive
= 0;
7701 wpa_s
->own_disconnect_req
= 0;
7703 os_free(wpa_s
->disallow_aps_bssid
);
7704 wpa_s
->disallow_aps_bssid
= NULL
;
7705 wpa_s
->disallow_aps_bssid_count
= 0;
7706 os_free(wpa_s
->disallow_aps_ssid
);
7707 wpa_s
->disallow_aps_ssid
= NULL
;
7708 wpa_s
->disallow_aps_ssid_count
= 0;
7710 wpa_s
->set_sta_uapsd
= 0;
7711 wpa_s
->sta_uapsd
= 0;
7713 wpa_drv_radio_disable(wpa_s
, 0);
7714 wpa_blacklist_clear(wpa_s
);
7715 wpa_s
->extra_blacklist_count
= 0;
7716 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7717 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7718 wpa_config_flush_blobs(wpa_s
->conf
);
7719 wpa_s
->conf
->auto_interworking
= 0;
7720 wpa_s
->conf
->okc
= 0;
7722 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7723 rsn_preauth_deinit(wpa_s
->wpa
);
7725 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7726 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7727 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7728 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7730 radio_remove_works(wpa_s
, NULL
, 1);
7731 wpa_s
->ext_work_in_progress
= 0;
7733 wpa_s
->next_ssid
= NULL
;
7735 #ifdef CONFIG_INTERWORKING
7737 hs20_cancel_fetch_osu(wpa_s
);
7738 hs20_del_icon(wpa_s
, NULL
, NULL
);
7739 #endif /* CONFIG_HS20 */
7740 #endif /* CONFIG_INTERWORKING */
7742 wpa_s
->ext_mgmt_frame_handling
= 0;
7743 wpa_s
->ext_eapol_frame_io
= 0;
7744 #ifdef CONFIG_TESTING_OPTIONS
7745 wpa_s
->extra_roc_dur
= 0;
7746 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7747 wpa_s
->p2p_go_csa_on_inv
= 0;
7748 wpa_s
->ignore_auth_resp
= 0;
7749 wpa_s
->ignore_assoc_disallow
= 0;
7750 wpa_s
->reject_btm_req_reason
= 0;
7751 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7752 os_free(wpa_s
->get_pref_freq_list_override
);
7753 wpa_s
->get_pref_freq_list_override
= NULL
;
7754 #endif /* CONFIG_TESTING_OPTIONS */
7756 wpa_s
->disconnected
= 0;
7757 os_free(wpa_s
->next_scan_freqs
);
7758 wpa_s
->next_scan_freqs
= NULL
;
7759 os_free(wpa_s
->select_network_scan_freqs
);
7760 wpa_s
->select_network_scan_freqs
= NULL
;
7762 wpa_bss_flush(wpa_s
);
7763 if (!dl_list_empty(&wpa_s
->bss
)) {
7764 wpa_printf(MSG_DEBUG
,
7765 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7766 MACSTR
" pending_bssid=" MACSTR
,
7767 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7768 MAC2STR(wpa_s
->bssid
),
7769 MAC2STR(wpa_s
->pending_bssid
));
7772 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7773 wpa_s
->wnmsleep_used
= 0;
7776 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7777 #endif /* CONFIG_SME */
7779 wpabuf_free(wpa_s
->ric_ies
);
7780 wpa_s
->ric_ies
= NULL
;
7784 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7785 char *buf
, size_t buflen
)
7787 struct wpa_radio_work
*work
;
7789 struct os_reltime now
, diff
;
7794 os_get_reltime(&now
);
7796 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7800 os_reltime_sub(&now
, &work
->time
, &diff
);
7801 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7802 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7803 work
->started
, diff
.sec
, diff
.usec
);
7804 if (os_snprintf_error(end
- pos
, ret
))
7813 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7815 struct wpa_radio_work
*work
= eloop_ctx
;
7816 struct wpa_external_work
*ework
= work
->ctx
;
7818 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7819 "Timing out external radio work %u (%s)",
7820 ework
->id
, work
->type
);
7821 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7822 work
->wpa_s
->ext_work_in_progress
= 0;
7823 radio_work_done(work
);
7828 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7830 struct wpa_external_work
*ework
= work
->ctx
;
7834 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7838 * work->type points to a buffer in ework, so need to replace
7839 * that here with a fixed string to avoid use of freed memory
7842 work
->type
= "freed-ext-work";
7848 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7849 ework
->id
, ework
->type
);
7850 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7851 work
->wpa_s
->ext_work_in_progress
= 1;
7852 if (!ework
->timeout
)
7853 ework
->timeout
= 10;
7854 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7859 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7860 char *buf
, size_t buflen
)
7862 struct wpa_external_work
*ework
;
7866 unsigned int freq
= 0;
7868 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7870 ework
= os_zalloc(sizeof(*ework
));
7874 pos
= os_strchr(cmd
, ' ');
7876 type_len
= pos
- cmd
;
7879 pos2
= os_strstr(pos
, "freq=");
7881 freq
= atoi(pos2
+ 5);
7883 pos2
= os_strstr(pos
, "timeout=");
7885 ework
->timeout
= atoi(pos2
+ 8);
7887 type_len
= os_strlen(cmd
);
7889 if (4 + type_len
>= sizeof(ework
->type
))
7890 type_len
= sizeof(ework
->type
) - 4 - 1;
7891 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
7892 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
7893 ework
->type
[4 + type_len
] = '\0';
7895 wpa_s
->ext_work_id
++;
7896 if (wpa_s
->ext_work_id
== 0)
7897 wpa_s
->ext_work_id
++;
7898 ework
->id
= wpa_s
->ext_work_id
;
7900 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
7906 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
7907 if (os_snprintf_error(buflen
, ret
))
7913 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
7915 struct wpa_radio_work
*work
;
7916 unsigned int id
= atoi(cmd
);
7918 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7920 struct wpa_external_work
*ework
;
7922 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7925 if (id
&& ework
->id
!= id
)
7927 wpa_dbg(wpa_s
, MSG_DEBUG
,
7928 "Completed external radio work %u (%s)",
7929 ework
->id
, ework
->type
);
7930 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
7931 wpa_s
->ext_work_in_progress
= 0;
7932 radio_work_done(work
);
7934 return 3; /* "OK\n" */
7941 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
7942 char *buf
, size_t buflen
)
7944 if (os_strcmp(cmd
, "show") == 0)
7945 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
7946 if (os_strncmp(cmd
, "add ", 4) == 0)
7947 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
7948 if (os_strncmp(cmd
, "done ", 5) == 0)
7949 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
7954 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
7956 struct wpa_radio_work
*work
, *tmp
;
7958 if (!wpa_s
|| !wpa_s
->radio
)
7961 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
7962 struct wpa_radio_work
, list
) {
7963 struct wpa_external_work
*ework
;
7965 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7968 wpa_dbg(wpa_s
, MSG_DEBUG
,
7969 "Flushing%s external radio work %u (%s)",
7970 work
->started
? " started" : "", ework
->id
,
7973 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7975 radio_work_done(work
);
7981 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
7983 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7984 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
7988 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
7989 unsigned int *scan_id_count
, int scan_id
[])
7991 const char *pos
= value
;
7994 if (*pos
== ' ' || *pos
== '\0')
7996 if (*scan_id_count
== MAX_SCAN_ID
)
7998 scan_id
[(*scan_id_count
)++] = atoi(pos
);
7999 pos
= os_strchr(pos
, ',');
8008 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8009 char *reply
, int reply_size
, int *reply_len
)
8012 unsigned int manual_scan_passive
= 0;
8013 unsigned int manual_scan_use_id
= 0;
8014 unsigned int manual_scan_only_new
= 0;
8015 unsigned int scan_only
= 0;
8016 unsigned int scan_id_count
= 0;
8017 int scan_id
[MAX_SCAN_ID
];
8018 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8019 struct wpa_scan_results
*scan_res
);
8020 int *manual_scan_freqs
= NULL
;
8021 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8022 unsigned int ssid_count
= 0;
8024 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8029 if (radio_work_pending(wpa_s
, "scan")) {
8030 wpa_printf(MSG_DEBUG
,
8031 "Pending scan scheduled - reject new request");
8032 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8036 #ifdef CONFIG_INTERWORKING
8037 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8038 wpa_printf(MSG_DEBUG
,
8039 "Interworking select in progress - reject new scan");
8040 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8043 #endif /* CONFIG_INTERWORKING */
8046 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8049 pos
= os_strstr(params
, "freq=");
8051 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8053 if (manual_scan_freqs
== NULL
) {
8059 pos
= os_strstr(params
, "passive=");
8061 manual_scan_passive
= !!atoi(pos
+ 8);
8063 pos
= os_strstr(params
, "use_id=");
8065 manual_scan_use_id
= atoi(pos
+ 7);
8067 pos
= os_strstr(params
, "only_new=1");
8069 manual_scan_only_new
= 1;
8071 pos
= os_strstr(params
, "scan_id=");
8072 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8078 pos
= os_strstr(params
, "bssid=");
8083 if (hwaddr_aton(pos
, bssid
)) {
8084 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8088 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8092 while (pos
&& *pos
!= '\0') {
8093 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8099 if (*end
== '\0' || *end
== ' ')
8104 ns
= os_realloc_array(
8105 ssid
, ssid_count
+ 1,
8106 sizeof(struct wpa_ssid_value
));
8113 if ((end
- pos
) & 0x01 ||
8114 end
- pos
> 2 * SSID_MAX_LEN
||
8115 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8116 (end
- pos
) / 2) < 0) {
8117 wpa_printf(MSG_DEBUG
,
8118 "Invalid SSID value '%s'",
8123 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8124 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8125 ssid
[ssid_count
].ssid
,
8126 ssid
[ssid_count
].ssid_len
);
8131 pos
= os_strchr(pos
, ' ');
8137 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8138 os_free(wpa_s
->ssids_from_scan_req
);
8140 wpa_s
->ssids_from_scan_req
= ssid
;
8143 wpa_s
->ssids_from_scan_req
= NULL
;
8147 scan_res_handler
= scan_only_handler
;
8148 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8149 scan_res_handler
= NULL
;
8151 scan_res_handler
= wpa_s
->scan_res_handler
;
8153 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8154 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8155 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8156 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8157 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8158 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8159 wpa_s
->scan_id_count
= scan_id_count
;
8160 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8161 wpa_s
->scan_res_handler
= scan_res_handler
;
8162 os_free(wpa_s
->manual_scan_freqs
);
8163 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8164 manual_scan_freqs
= NULL
;
8166 wpa_s
->normal_scans
= 0;
8167 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8168 wpa_s
->after_wps
= 0;
8169 wpa_s
->known_wps_freq
= 0;
8170 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8171 if (wpa_s
->manual_scan_use_id
) {
8172 wpa_s
->manual_scan_id
++;
8173 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8174 wpa_s
->manual_scan_id
);
8175 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8176 wpa_s
->manual_scan_id
);
8178 } else if (wpa_s
->sched_scanning
) {
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_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8190 wpa_supplicant_cancel_sched_scan(wpa_s
);
8191 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8192 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8193 if (wpa_s
->manual_scan_use_id
) {
8194 wpa_s
->manual_scan_id
++;
8195 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8196 wpa_s
->manual_scan_id
);
8197 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8198 wpa_s
->manual_scan_id
);
8201 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8202 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8206 os_free(manual_scan_freqs
);
8211 #ifdef CONFIG_TESTING_OPTIONS
8213 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8214 unsigned int freq
, const u8
*dst
,
8215 const u8
*src
, const u8
*bssid
,
8216 const u8
*data
, size_t data_len
,
8217 enum offchannel_send_action_result
8220 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8221 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8222 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8223 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8224 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8225 "NO_ACK" : "FAILED"));
8229 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8233 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8235 int freq
= 0, no_cck
= 0, wait_time
= 0;
8237 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8238 * <action=Action frame payload> */
8240 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8243 used
= hwaddr_aton2(pos
, da
);
8249 used
= hwaddr_aton2(pos
, bssid
);
8254 param
= os_strstr(pos
, " freq=");
8260 param
= os_strstr(pos
, " no_cck=");
8263 no_cck
= atoi(param
);
8266 param
= os_strstr(pos
, " wait_time=");
8269 wait_time
= atoi(param
);
8272 param
= os_strstr(pos
, " action=");
8277 len
= os_strlen(param
);
8282 buf
= os_malloc(len
);
8286 if (hexstr2bin(param
, buf
, len
) < 0) {
8291 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8292 buf
, len
, wait_time
,
8293 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8299 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8301 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8302 offchannel_send_action_done(wpa_s
);
8306 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8312 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8313 union wpa_event_data event
;
8315 if (!wpa_s
->ext_mgmt_frame_handling
)
8318 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8320 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8323 param
= os_strstr(pos
, "freq=");
8329 param
= os_strstr(pos
, " datarate=");
8332 datarate
= atoi(param
);
8335 param
= os_strstr(pos
, " ssi_signal=");
8338 ssi_signal
= atoi(param
);
8341 param
= os_strstr(pos
, " frame=");
8346 len
= os_strlen(param
);
8351 buf
= os_malloc(len
);
8355 if (hexstr2bin(param
, buf
, len
) < 0) {
8360 os_memset(&event
, 0, sizeof(event
));
8361 event
.rx_mgmt
.freq
= freq
;
8362 event
.rx_mgmt
.frame
= buf
;
8363 event
.rx_mgmt
.frame_len
= len
;
8364 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8365 event
.rx_mgmt
.datarate
= datarate
;
8366 wpa_s
->ext_mgmt_frame_handling
= 0;
8367 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8368 wpa_s
->ext_mgmt_frame_handling
= 1;
8376 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8379 struct wpa_scan_res
*res
;
8380 struct os_reltime now
;
8387 if (os_strcmp(param
, "START") == 0) {
8388 wpa_bss_update_start(wpa_s
);
8392 if (os_strcmp(param
, "END") == 0) {
8393 wpa_bss_update_end(wpa_s
, NULL
, 1);
8397 if (os_strncmp(param
, "BSS ", 4) != 0)
8401 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8405 pos
= os_strstr(param
, " flags=");
8407 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8409 pos
= os_strstr(param
, " bssid=");
8410 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8413 pos
= os_strstr(param
, " freq=");
8415 res
->freq
= atoi(pos
+ 6);
8417 pos
= os_strstr(param
, " beacon_int=");
8419 res
->beacon_int
= atoi(pos
+ 12);
8421 pos
= os_strstr(param
, " caps=");
8423 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8425 pos
= os_strstr(param
, " qual=");
8427 res
->qual
= atoi(pos
+ 6);
8429 pos
= os_strstr(param
, " noise=");
8431 res
->noise
= atoi(pos
+ 7);
8433 pos
= os_strstr(param
, " level=");
8435 res
->level
= atoi(pos
+ 7);
8437 pos
= os_strstr(param
, " tsf=");
8439 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8441 pos
= os_strstr(param
, " age=");
8443 res
->age
= atoi(pos
+ 5);
8445 pos
= os_strstr(param
, " est_throughput=");
8447 res
->est_throughput
= atoi(pos
+ 16);
8449 pos
= os_strstr(param
, " snr=");
8451 res
->snr
= atoi(pos
+ 5);
8453 pos
= os_strstr(param
, " parent_tsf=");
8455 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8457 pos
= os_strstr(param
, " tsf_bssid=");
8458 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8461 pos
= os_strstr(param
, " ie=");
8464 end
= os_strchr(pos
, ' ');
8466 end
= pos
+ os_strlen(pos
);
8467 res
->ie_len
= (end
- pos
) / 2;
8468 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8472 pos
= os_strstr(param
, " beacon_ie=");
8475 end
= os_strchr(pos
, ' ');
8477 end
= pos
+ os_strlen(pos
);
8478 res
->beacon_ie_len
= (end
- pos
) / 2;
8479 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8480 res
->beacon_ie_len
))
8484 os_get_reltime(&now
);
8485 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8494 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8497 union wpa_event_data event
;
8498 enum wpa_event_type ev
;
8500 /* <event name> [parameters..] */
8502 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8505 param
= os_strchr(pos
, ' ');
8509 os_memset(&event
, 0, sizeof(event
));
8511 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8512 ev
= EVENT_INTERFACE_ENABLED
;
8513 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8514 ev
= EVENT_INTERFACE_DISABLED
;
8515 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8516 ev
= EVENT_AVOID_FREQUENCIES
;
8519 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8521 wpa_supplicant_event(wpa_s
, ev
, &event
);
8522 os_free(event
.freq_range
.range
);
8524 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8525 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8527 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8532 wpa_supplicant_event(wpa_s
, ev
, &event
);
8538 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8541 u8 src
[ETH_ALEN
], *buf
;
8545 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8548 used
= hwaddr_aton2(pos
, src
);
8555 len
= os_strlen(pos
);
8560 buf
= os_malloc(len
);
8564 if (hexstr2bin(pos
, buf
, len
) < 0) {
8569 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8576 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8580 const u16
*pos
= buf
;
8582 for (i
= 0; i
< len
/ 2; i
++)
8586 sum
= (sum
& 0xffff) + (sum
>> 16);
8588 return sum
^ 0xffff;
8592 #define HWSIM_PACKETLEN 1500
8593 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8595 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8598 struct wpa_supplicant
*wpa_s
= ctx
;
8599 const struct ether_header
*eth
;
8604 if (len
!= HWSIM_PACKETLEN
)
8607 eth
= (const struct ether_header
*) buf
;
8608 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8609 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8611 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8612 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8615 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
8621 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
8622 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
8626 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8629 int enabled
= atoi(cmd
);
8634 if (wpa_s
->l2_test
) {
8635 l2_packet_deinit(wpa_s
->l2_test
);
8636 wpa_s
->l2_test
= NULL
;
8637 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8645 pos
= os_strstr(cmd
, " ifname=");
8649 ifname
= wpa_s
->ifname
;
8651 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8652 ETHERTYPE_IP
, wpas_data_test_rx
,
8654 if (wpa_s
->l2_test
== NULL
)
8657 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8663 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8665 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8670 u8 buf
[2 + HWSIM_PACKETLEN
];
8671 struct ether_header
*eth
;
8676 if (wpa_s
->l2_test
== NULL
)
8679 /* format: <dst> <src> <tos> */
8682 used
= hwaddr_aton2(pos
, dst
);
8688 used
= hwaddr_aton2(pos
, src
);
8693 val
= strtol(pos
, NULL
, 0);
8694 if (val
< 0 || val
> 0xff)
8698 eth
= (struct ether_header
*) &buf
[2];
8699 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8700 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8701 eth
->ether_type
= htons(ETHERTYPE_IP
);
8702 ip
= (struct iphdr
*) (eth
+ 1);
8703 os_memset(ip
, 0, sizeof(*ip
));
8708 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8710 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8711 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8712 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8713 dpos
= (u8
*) (ip
+ 1);
8714 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8717 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8718 HWSIM_PACKETLEN
) < 0)
8721 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8722 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8728 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8732 struct ether_header
*eth
;
8733 struct l2_packet_data
*l2
= NULL
;
8738 len
= os_strlen(cmd
);
8739 if (len
& 1 || len
< ETH_HLEN
* 2)
8743 buf
= os_malloc(len
);
8747 if (hexstr2bin(cmd
, buf
, len
) < 0)
8750 eth
= (struct ether_header
*) buf
;
8751 ethertype
= ntohs(eth
->ether_type
);
8753 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8754 wpas_data_test_rx
, wpa_s
, 1);
8758 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8759 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8762 l2_packet_deinit(l2
);
8765 return res
< 0 ? -1 : 0;
8769 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8771 #ifdef WPA_TRACE_BFD
8774 wpa_trace_fail_after
= atoi(cmd
);
8775 pos
= os_strchr(cmd
, ':');
8778 os_strlcpy(wpa_trace_fail_func
, pos
,
8779 sizeof(wpa_trace_fail_func
));
8781 wpa_trace_fail_after
= 0;
8784 #else /* WPA_TRACE_BFD */
8786 #endif /* WPA_TRACE_BFD */
8790 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8791 char *buf
, size_t buflen
)
8793 #ifdef WPA_TRACE_BFD
8794 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8795 wpa_trace_fail_func
);
8796 #else /* WPA_TRACE_BFD */
8798 #endif /* WPA_TRACE_BFD */
8802 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8804 #ifdef WPA_TRACE_BFD
8807 wpa_trace_test_fail_after
= atoi(cmd
);
8808 pos
= os_strchr(cmd
, ':');
8811 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8812 sizeof(wpa_trace_test_fail_func
));
8814 wpa_trace_test_fail_after
= 0;
8817 #else /* WPA_TRACE_BFD */
8819 #endif /* WPA_TRACE_BFD */
8823 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8824 char *buf
, size_t buflen
)
8826 #ifdef WPA_TRACE_BFD
8827 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8828 wpa_trace_test_fail_func
);
8829 #else /* WPA_TRACE_BFD */
8831 #endif /* WPA_TRACE_BFD */
8835 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8837 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8838 int i
, count
= (intptr_t) timeout_ctx
;
8840 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8842 for (i
= 0; i
< count
; i
++) {
8843 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8849 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8857 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8858 (void *) (intptr_t) count
);
8862 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8868 len
= os_strlen(cmd
);
8876 buf
= wpabuf_alloc(len
);
8880 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
8886 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
8890 #endif /* CONFIG_TESTING_OPTIONS */
8893 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
8899 struct ieee802_11_elems elems
;
8902 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8904 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8906 pos
= os_strchr(pos
, ' ');
8911 len
= os_strlen(pos
);
8918 buf
= wpabuf_alloc(len
);
8922 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
8927 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
8933 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
8934 wpa_s
->vendor_elem
[frame
] = buf
;
8935 wpas_vendor_elem_update(wpa_s
);
8939 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
8944 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
8946 wpas_vendor_elem_update(wpa_s
);
8952 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
8953 char *buf
, size_t buflen
)
8955 int frame
= atoi(cmd
);
8957 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8959 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8961 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8964 return wpa_snprintf_hex(buf
, buflen
,
8965 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
8966 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
8970 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
8976 struct ieee802_11_elems elems
;
8980 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8982 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8984 pos
= os_strchr(pos
, ' ');
8990 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
8991 wpa_s
->vendor_elem
[frame
] = NULL
;
8992 wpas_vendor_elem_update(wpa_s
);
8996 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8999 len
= os_strlen(pos
);
9006 buf
= os_malloc(len
);
9010 if (hexstr2bin(pos
, buf
, len
) < 0) {
9015 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9020 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9026 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9028 struct wpa_supplicant
*wpa_s
= ctx
;
9033 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9035 * BSSID Information[4]
9036 * Operating Class[1]
9039 * Optional Subelements[variable]
9041 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9043 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9044 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9048 data
= wpabuf_head_u8(neighbor_rep
);
9049 len
= wpabuf_len(neighbor_rep
);
9051 while (len
>= 2 + NR_IE_MIN_LEN
) {
9053 char lci
[256 * 2 + 1];
9054 char civic
[256 * 2 + 1];
9055 u8 nr_len
= data
[1];
9056 const u8
*pos
= data
, *end
;
9058 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9059 nr_len
< NR_IE_MIN_LEN
) {
9060 wpa_printf(MSG_DEBUG
,
9061 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9066 if (2U + nr_len
> len
) {
9067 wpa_printf(MSG_DEBUG
,
9068 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9069 data
[0], len
, nr_len
);
9076 pos
+= NR_IE_MIN_LEN
;
9080 while (end
- pos
> 2) {
9085 if (s_len
> end
- pos
)
9087 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9088 /* Measurement Token[1] */
9089 /* Measurement Report Mode[1] */
9090 /* Measurement Type[1] */
9091 /* Measurement Report[variable] */
9093 case MEASURE_TYPE_LCI
:
9096 wpa_snprintf_hex(lci
, sizeof(lci
),
9099 case MEASURE_TYPE_LOCATION_CIVIC
:
9102 wpa_snprintf_hex(civic
, sizeof(civic
),
9111 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9113 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9114 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9115 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9117 lci
[0] ? " lci=" : "", lci
,
9118 civic
[0] ? " civic=" : "", civic
);
9125 wpabuf_free(neighbor_rep
);
9129 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9132 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9133 int ret
, lci
= 0, civic
= 0;
9136 ssid_s
= os_strstr(cmd
, "ssid=");
9138 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9139 wpa_printf(MSG_ERROR
,
9140 "CTRL: Send Neighbor Report: bad SSID");
9147 * Move cmd after the SSID text that may include "lci" or
9150 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9156 if (cmd
&& os_strstr(cmd
, "lci"))
9159 if (cmd
&& os_strstr(cmd
, "civic"))
9162 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9163 wpas_ctrl_neighbor_rep_cb
,
9170 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9172 eapol_sm_erp_flush(wpa_s
->eapol
);
9177 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9180 char *token
, *context
= NULL
;
9181 unsigned int enable
= ~0, type
= 0;
9182 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9183 u8
*addr
= NULL
, *mask
= NULL
;
9185 while ((token
= str_token(cmd
, " ", &context
))) {
9186 if (os_strcasecmp(token
, "scan") == 0) {
9187 type
|= MAC_ADDR_RAND_SCAN
;
9188 } else if (os_strcasecmp(token
, "sched") == 0) {
9189 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9190 } else if (os_strcasecmp(token
, "pno") == 0) {
9191 type
|= MAC_ADDR_RAND_PNO
;
9192 } else if (os_strcasecmp(token
, "all") == 0) {
9193 type
= wpa_s
->mac_addr_rand_supported
;
9194 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9195 enable
= atoi(token
+ 7);
9196 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9198 if (hwaddr_aton(token
+ 5, addr
)) {
9199 wpa_printf(MSG_INFO
,
9200 "CTRL: Invalid MAC address: %s",
9204 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9206 if (hwaddr_aton(token
+ 5, mask
)) {
9207 wpa_printf(MSG_INFO
,
9208 "CTRL: Invalid MAC address mask: %s",
9213 wpa_printf(MSG_INFO
,
9214 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9221 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9225 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
9226 wpa_printf(MSG_INFO
,
9227 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9228 type
, wpa_s
->mac_addr_rand_supported
);
9233 wpa_printf(MSG_INFO
,
9234 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9239 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
9241 if (type
& MAC_ADDR_RAND_PNO
) {
9242 wpas_stop_pno(wpa_s
);
9243 wpas_start_pno(wpa_s
);
9245 } else if (wpa_s
->sched_scanning
&&
9246 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
9247 wpas_scan_restart_sched_scan(wpa_s
);
9252 if ((addr
&& !mask
) || (!addr
&& mask
)) {
9253 wpa_printf(MSG_INFO
,
9254 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9258 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
9259 wpa_printf(MSG_INFO
,
9260 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9264 if (type
& MAC_ADDR_RAND_SCAN
) {
9265 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
9269 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
9270 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
9273 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
9274 wpas_scan_restart_sched_scan(wpa_s
);
9277 if (type
& MAC_ADDR_RAND_PNO
) {
9278 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
9281 wpas_stop_pno(wpa_s
);
9282 wpas_start_pno(wpa_s
);
9290 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9291 char *buf
, size_t buflen
)
9295 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9297 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9298 buflen
- reply_len
);
9299 #endif /* CONFIG_AP */
9304 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9306 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9308 wpas_ap_pmksa_cache_flush(wpa_s
);
9309 #endif /* CONFIG_AP */
9313 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9315 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9316 const char *cmd
, char *buf
, size_t buflen
)
9318 struct rsn_pmksa_cache_entry
*entry
;
9319 struct wpa_ssid
*ssid
;
9320 char *pos
, *pos2
, *end
;
9322 struct os_reltime now
;
9324 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9331 os_get_reltime(&now
);
9335 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9336 * <expiration in seconds> <akmp> <opportunistic>
9337 * [FILS Cache Identifier]
9340 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9341 entry
= entry
->next
) {
9342 if (entry
->network_ctx
!= ssid
)
9346 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9347 MAC2STR(entry
->aa
));
9348 if (os_snprintf_error(end
- pos2
, ret
))
9352 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9355 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9356 if (os_snprintf_error(end
- pos2
, ret
))
9360 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9363 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9364 (int) (entry
->reauth_time
- now
.sec
),
9365 (int) (entry
->expiration
- now
.sec
),
9367 entry
->opportunistic
);
9368 if (os_snprintf_error(end
- pos2
, ret
))
9372 if (entry
->fils_cache_id_set
) {
9373 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9374 entry
->fils_cache_id
[0],
9375 entry
->fils_cache_id
[1]);
9376 if (os_snprintf_error(end
- pos2
, ret
))
9381 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9382 if (os_snprintf_error(end
- pos2
, ret
))
9393 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9396 struct rsn_pmksa_cache_entry
*entry
;
9397 struct wpa_ssid
*ssid
;
9400 struct os_reltime now
;
9401 int reauth_time
= 0, expiration
= 0, i
;
9405 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9406 * <expiration in seconds> <akmp> <opportunistic>
9407 * [FILS Cache Identifier]
9410 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9414 pos
= os_strchr(cmd
, ' ');
9419 entry
= os_zalloc(sizeof(*entry
));
9423 if (hwaddr_aton(pos
, entry
->aa
))
9426 pos
= os_strchr(pos
, ' ');
9431 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9434 pos
= os_strchr(pos
, ' ');
9439 pos2
= os_strchr(pos
, ' ');
9442 entry
->pmk_len
= (pos2
- pos
) / 2;
9443 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9444 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9447 pos
= os_strchr(pos
, ' ');
9452 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9453 &entry
->akmp
, &entry
->opportunistic
) != 4)
9455 for (i
= 0; i
< 4; i
++) {
9456 pos
= os_strchr(pos
, ' ');
9465 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9466 FILS_CACHE_ID_LEN
) < 0)
9468 entry
->fils_cache_id_set
= 1;
9470 os_get_reltime(&now
);
9471 entry
->expiration
= now
.sec
+ expiration
;
9472 entry
->reauth_time
= now
.sec
+ reauth_time
;
9474 entry
->network_ctx
= ssid
;
9476 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9487 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9488 const char *cmd
, char *buf
,
9496 if (os_strcasecmp(cmd
, "any") == 0)
9497 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9499 if (hwaddr_aton(cmd
, spa
))
9502 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9506 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9510 * We do not check mesh interface existance because PMKSA should be
9511 * stored before wpa_s->ifmsh creation to suppress commit message
9514 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9517 #endif /* CONFIG_MESH */
9518 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9522 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9525 struct fils_hlp_req
*req
;
9528 /* format: <dst> <packet starting from ethertype> */
9530 req
= os_zalloc(sizeof(*req
));
9534 if (hwaddr_aton(cmd
, req
->dst
))
9537 pos
= os_strchr(cmd
, ' ');
9541 req
->pkt
= wpabuf_parse_bin(pos
);
9545 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9548 wpabuf_free(req
->pkt
);
9552 #endif /* CONFIG_FILS */
9555 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9557 if (os_strcmp(cmd
, "PING") == 0 ||
9558 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9559 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9560 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9561 os_strncmp(cmd
, "STA ", 4) == 0 ||
9562 os_strncmp(cmd
, "STA-", 4) == 0)
9563 return MSG_EXCESSIVE
;
9568 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9569 char *buf
, size_t *resp_len
)
9572 const int reply_size
= 4096;
9575 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9576 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9577 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9578 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9579 if (wpa_debug_show_keys
)
9580 wpa_dbg(wpa_s
, MSG_DEBUG
,
9581 "Control interface command '%s'", buf
);
9583 wpa_dbg(wpa_s
, MSG_DEBUG
,
9584 "Control interface command '%s [REMOVED]'",
9585 os_strncmp(buf
, WPA_CTRL_RSP
,
9586 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9588 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9589 "SET_NETWORK" : "key-add"));
9590 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9591 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9592 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9593 (const u8
*) buf
, os_strlen(buf
));
9595 int level
= wpas_ctrl_cmd_debug_level(buf
);
9596 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9599 reply
= os_malloc(reply_size
);
9600 if (reply
== NULL
) {
9605 os_memcpy(reply
, "OK\n", 3);
9608 if (os_strcmp(buf
, "PING") == 0) {
9609 os_memcpy(reply
, "PONG\n", 5);
9611 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9612 reply_len
= os_strlen(wpa_s
->ifname
);
9613 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9614 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9615 if (wpa_debug_reopen_file() < 0)
9617 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9618 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9619 } else if (os_strcmp(buf
, "MIB") == 0) {
9620 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9621 if (reply_len
>= 0) {
9622 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9624 reply_size
- reply_len
);
9626 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9627 reply_len
= wpa_supplicant_ctrl_iface_status(
9628 wpa_s
, buf
+ 6, reply
, reply_size
);
9629 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9630 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9631 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9632 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9633 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9634 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9635 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9637 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9638 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9641 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9642 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9644 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9645 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9647 #endif /* CONFIG_MESH */
9648 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9649 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9650 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9652 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9653 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9655 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9656 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9658 } else if (os_strcmp(buf
, "LOGON") == 0) {
9659 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9660 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9661 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9662 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9663 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9666 wpas_request_connection(wpa_s
);
9667 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9668 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9669 !wpa_s
->current_ssid
)
9672 wpa_s
->reattach
= 1;
9673 wpas_request_connection(wpa_s
);
9675 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9676 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9678 else if (wpa_s
->disconnected
)
9679 wpas_request_connection(wpa_s
);
9680 #ifdef IEEE8021X_EAPOL
9681 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9682 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9684 #endif /* IEEE8021X_EAPOL */
9685 #ifdef CONFIG_PEERKEY
9686 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
9687 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
9689 #endif /* CONFIG_PEERKEY */
9690 #ifdef CONFIG_IEEE80211R
9691 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9692 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9694 #endif /* CONFIG_IEEE80211R */
9696 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9697 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9699 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9703 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9704 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9706 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9710 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9711 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9714 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9715 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9716 wpa_s
, buf
+ 14, reply
, reply_size
);
9717 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9718 if (wpas_wps_cancel(wpa_s
))
9720 #ifdef CONFIG_WPS_NFC
9721 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
9722 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
9724 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
9725 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
9727 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9728 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9729 wpa_s
, buf
+ 21, reply
, reply_size
);
9730 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
9731 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
9732 wpa_s
, buf
+ 14, reply
, reply_size
);
9733 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
9734 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
9737 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9738 reply_len
= wpas_ctrl_nfc_get_handover_req(
9739 wpa_s
, buf
+ 21, reply
, reply_size
);
9740 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9741 reply_len
= wpas_ctrl_nfc_get_handover_sel(
9742 wpa_s
, buf
+ 21, reply
, reply_size
);
9743 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
9744 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
9746 #endif /* CONFIG_WPS_NFC */
9747 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
9748 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
9751 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
9752 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
9753 wpa_s
, buf
+ 11, reply
, reply_size
);
9754 #endif /* CONFIG_AP */
9755 #ifdef CONFIG_WPS_ER
9756 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
9757 if (wpas_wps_er_start(wpa_s
, NULL
))
9759 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
9760 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
9762 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
9763 wpas_wps_er_stop(wpa_s
);
9764 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
9765 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
9767 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
9768 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
9770 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9772 } else if (ret
== -3) {
9773 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
9775 } else if (ret
== -4) {
9776 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
9780 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
9781 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
9783 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
9784 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
9787 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
9788 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
9790 #ifdef CONFIG_WPS_NFC
9791 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9792 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9793 wpa_s
, buf
+ 24, reply
, reply_size
);
9794 #endif /* CONFIG_WPS_NFC */
9795 #endif /* CONFIG_WPS_ER */
9796 #endif /* CONFIG_WPS */
9797 #ifdef CONFIG_IBSS_RSN
9798 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
9799 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
9801 #endif /* CONFIG_IBSS_RSN */
9803 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
9804 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9805 wpa_s
, buf
+ 19, reply
, reply_size
);
9806 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
9807 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9808 wpa_s
, "", reply
, reply_size
);
9809 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
9810 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
9812 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
9813 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
9816 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
9817 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
9819 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
9820 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
9822 #endif /* CONFIG_MESH */
9824 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
9825 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
9827 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
9828 if (p2p_ctrl_find(wpa_s
, ""))
9830 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
9831 wpas_p2p_stop_find(wpa_s
);
9832 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
9833 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
9835 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
9836 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
9838 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
9839 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
9841 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
9842 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
9844 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
9845 if (p2p_ctrl_listen(wpa_s
, ""))
9847 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
9848 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
9850 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
9851 if (p2p_ctrl_group_add(wpa_s
, ""))
9853 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
9854 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
9856 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
9857 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
9859 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
9860 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
9862 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
9863 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
9864 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
9865 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
9867 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
9868 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
9870 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
9871 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
9873 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
9874 wpas_p2p_sd_service_update(wpa_s
);
9875 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
9876 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
9878 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
9879 wpas_p2p_service_flush(wpa_s
);
9880 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
9881 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
9883 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
9884 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
9886 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
9887 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
9889 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
9890 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
9892 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
9893 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
9895 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
9896 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
9898 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
9899 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
9901 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
9902 p2p_ctrl_flush(wpa_s
);
9903 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
9904 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
9906 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
9907 if (wpas_p2p_cancel(wpa_s
))
9909 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
9910 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
9912 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
9913 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
9915 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
9916 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
9918 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
9919 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
9921 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
9922 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
9924 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
9925 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
9927 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
9928 if (wpas_p2p_lo_stop(wpa_s
))
9930 #endif /* CONFIG_P2P */
9931 #ifdef CONFIG_WIFI_DISPLAY
9932 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
9933 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
9935 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
9936 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
9938 #endif /* CONFIG_WIFI_DISPLAY */
9939 #ifdef CONFIG_INTERWORKING
9940 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
9941 if (interworking_fetch_anqp(wpa_s
) < 0)
9943 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
9944 interworking_stop_fetch_anqp(wpa_s
);
9945 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
9946 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
9948 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
9949 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
9951 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
9952 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
9954 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9957 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
9961 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
9962 if (os_snprintf_error(reply_size
, reply_len
))
9965 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
9966 if (get_anqp(wpa_s
, buf
+ 9) < 0)
9968 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
9969 if (gas_request(wpa_s
, buf
+ 12) < 0)
9971 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
9972 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
9974 #endif /* CONFIG_INTERWORKING */
9976 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
9977 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
9979 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
9980 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
9982 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
9983 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
9985 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
9986 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
9988 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
9989 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
9990 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
9991 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
9993 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
9994 if (hs20_fetch_osu(wpa_s
, 0) < 0)
9996 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
9997 if (hs20_fetch_osu(wpa_s
, 1) < 0)
9999 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10000 hs20_cancel_fetch_osu(wpa_s
);
10001 #endif /* CONFIG_HS20 */
10002 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10004 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10005 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10009 * Notify response from timeout to allow the control
10010 * interface response to be sent first.
10012 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10015 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10016 if (wpa_supplicant_reload_configuration(wpa_s
))
10018 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10019 wpa_supplicant_terminate_proc(wpa_s
->global
);
10020 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10021 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10023 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10024 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10025 wpa_s
, buf
+ 9, reply
, reply_size
);
10026 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10027 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10028 wpa_s
, buf
+ 9, reply
, reply_size
);
10029 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10030 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10031 wpa_s
, buf
+ 14, reply
, reply_size
);
10032 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10033 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10034 wpa_s
, NULL
, reply
, reply_size
);
10035 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10036 wpas_request_disconnection(wpa_s
);
10037 } else if (os_strcmp(buf
, "SCAN") == 0) {
10038 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10039 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10040 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10041 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10042 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10043 wpa_s
, reply
, reply_size
);
10044 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10045 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10047 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10048 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10050 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10051 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10053 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10054 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10056 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10057 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10058 wpa_s
, reply
, reply_size
);
10059 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10060 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10062 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10063 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10065 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10066 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10067 wpa_s
, buf
+ 12, reply
, reply_size
);
10068 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10069 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10072 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10073 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10074 wpa_s
, reply
, reply_size
);
10075 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10076 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10077 wpa_s
, reply
, reply_size
);
10078 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10079 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10081 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10082 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10084 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10085 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10088 #ifndef CONFIG_NO_CONFIG_WRITE
10089 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10090 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10092 #endif /* CONFIG_NO_CONFIG_WRITE */
10093 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10094 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10095 wpa_s
, buf
+ 15, reply
, reply_size
);
10096 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10097 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10099 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10100 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10102 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10103 reply_len
= wpa_supplicant_global_iface_list(
10104 wpa_s
->global
, reply
, reply_size
);
10105 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10106 reply_len
= wpa_supplicant_global_iface_interfaces(
10107 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10108 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10109 reply_len
= wpa_supplicant_ctrl_iface_bss(
10110 wpa_s
, buf
+ 4, reply
, reply_size
);
10112 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10113 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10114 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10115 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10117 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10118 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10120 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10121 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10123 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10124 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10126 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10127 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10129 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10130 if (wpas_ap_stop_ap(wpa_s
))
10132 #endif /* CONFIG_AP */
10133 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10134 wpas_notify_suspend(wpa_s
->global
);
10135 } else if (os_strcmp(buf
, "RESUME") == 0) {
10136 wpas_notify_resume(wpa_s
->global
);
10137 #ifdef CONFIG_TESTING_OPTIONS
10138 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10139 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10140 #endif /* CONFIG_TESTING_OPTIONS */
10141 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10142 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10144 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10145 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10146 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10147 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10149 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10150 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10153 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10154 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10156 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10157 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10159 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10160 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10162 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10163 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10165 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10166 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10169 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10170 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10173 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10174 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10175 wpa_s
, buf
+ 17, reply
, reply_size
);
10176 #endif /* CONFIG_TDLS */
10177 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10178 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10179 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10180 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10182 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10183 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10185 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10186 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10188 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10189 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10191 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10192 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10194 #ifdef CONFIG_AUTOSCAN
10195 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10196 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10198 #endif /* CONFIG_AUTOSCAN */
10199 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10200 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10203 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10204 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10206 #endif /* ANDROID */
10207 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10208 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10210 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10211 pmksa_cache_clear_current(wpa_s
->wpa
);
10212 eapol_sm_request_reauth(wpa_s
->eapol
);
10214 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10215 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10217 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10218 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10220 #endif /* CONFIG_WNM */
10221 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10222 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10223 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10224 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10226 #ifdef CONFIG_TESTING_OPTIONS
10227 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10228 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10230 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10231 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10232 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10233 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10235 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10236 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10238 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10239 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10241 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10242 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10244 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10245 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10247 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10248 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10250 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10251 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10253 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10254 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10255 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10256 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10258 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10259 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10260 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10261 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10263 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10264 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10266 #endif /* CONFIG_TESTING_OPTIONS */
10267 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10268 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10270 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10271 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10273 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10274 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10276 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10277 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10279 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10280 wpas_ctrl_iface_erp_flush(wpa_s
);
10281 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10282 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10284 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10285 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10286 wpa_s
, buf
+ 19, reply
, reply_size
);
10288 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10289 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10291 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10292 wpas_flush_fils_hlp_req(wpa_s
);
10293 #endif /* CONFIG_FILS */
10295 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10298 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10302 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10303 if (os_snprintf_error(reply_size
, reply_len
))
10306 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10309 res
= wpas_dpp_bootstrap_gen(wpa_s
, buf
+ 18);
10313 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10314 if (os_snprintf_error(reply_size
, reply_len
))
10317 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10318 if (wpas_dpp_bootstrap_remove(wpa_s
, buf
+ 21) < 0)
10320 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10323 uri
= wpas_dpp_bootstrap_get_uri(wpa_s
, atoi(buf
+ 22));
10327 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10328 if (os_snprintf_error(reply_size
, reply_len
))
10331 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10332 reply_len
= wpas_dpp_bootstrap_info(wpa_s
, atoi(buf
+ 19),
10333 reply
, reply_size
);
10334 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10335 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10337 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10338 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10340 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10341 wpas_dpp_listen_stop(wpa_s
);
10342 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10345 res
= wpas_dpp_configurator_add(wpa_s
, buf
+ 20);
10349 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10350 if (os_snprintf_error(reply_size
, reply_len
))
10353 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10354 if (wpas_dpp_configurator_remove(wpa_s
, buf
+ 24) < 0)
10356 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10357 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 22) < 0)
10359 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10362 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10366 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10367 if (os_snprintf_error(reply_size
, reply_len
))
10370 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10371 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10373 #endif /* CONFIG_DPP */
10375 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10379 if (reply_len
< 0) {
10380 os_memcpy(reply
, "FAIL\n", 5);
10384 *resp_len
= reply_len
;
10389 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10392 struct wpa_interface iface
;
10394 struct wpa_supplicant
*wpa_s
;
10395 unsigned int create_iface
= 0;
10396 u8 mac_addr
[ETH_ALEN
];
10397 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10400 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10401 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10403 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10405 os_memset(&iface
, 0, sizeof(iface
));
10408 iface
.ifname
= pos
= cmd
;
10409 pos
= os_strchr(pos
, '\t');
10412 if (iface
.ifname
[0] == '\0')
10417 iface
.confname
= pos
;
10418 pos
= os_strchr(pos
, '\t');
10421 if (iface
.confname
[0] == '\0')
10422 iface
.confname
= NULL
;
10426 iface
.driver
= pos
;
10427 pos
= os_strchr(pos
, '\t');
10430 if (iface
.driver
[0] == '\0')
10431 iface
.driver
= NULL
;
10435 iface
.ctrl_interface
= pos
;
10436 pos
= os_strchr(pos
, '\t');
10439 if (iface
.ctrl_interface
[0] == '\0')
10440 iface
.ctrl_interface
= NULL
;
10444 iface
.driver_param
= pos
;
10445 pos
= os_strchr(pos
, '\t');
10448 if (iface
.driver_param
[0] == '\0')
10449 iface
.driver_param
= NULL
;
10453 iface
.bridge_ifname
= pos
;
10454 pos
= os_strchr(pos
, '\t');
10457 if (iface
.bridge_ifname
[0] == '\0')
10458 iface
.bridge_ifname
= NULL
;
10463 pos
= os_strchr(pos
, '\t');
10469 if (os_strcmp(extra
, "create") == 0) {
10474 if (os_strcmp(pos
, "sta") == 0) {
10475 type
= WPA_IF_STATION
;
10476 } else if (os_strcmp(pos
, "ap") == 0) {
10477 type
= WPA_IF_AP_BSS
;
10479 wpa_printf(MSG_DEBUG
,
10480 "INTERFACE_ADD unsupported interface type: '%s'",
10485 wpa_printf(MSG_DEBUG
,
10486 "INTERFACE_ADD unsupported extra parameter: '%s'",
10492 if (create_iface
) {
10493 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10495 if (!global
->ifaces
)
10497 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10498 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10499 wpa_printf(MSG_ERROR
,
10500 "CTRL_IFACE interface creation failed");
10504 wpa_printf(MSG_DEBUG
,
10505 "CTRL_IFACE interface '%s' created with MAC addr: "
10506 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10509 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10512 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10515 wpa_s
->added_vif
= create_iface
;
10520 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10525 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10528 struct wpa_supplicant
*wpa_s
;
10530 unsigned int delete_iface
;
10532 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10534 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10537 delete_iface
= wpa_s
->added_vif
;
10538 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10539 if (!ret
&& delete_iface
) {
10540 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10542 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10548 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10550 struct wpa_interface_info
*prev
;
10554 iface
= iface
->next
;
10556 os_free(prev
->ifname
);
10557 os_free(prev
->desc
);
10563 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10564 char *buf
, int len
)
10567 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10570 for (i
= 0; wpa_drivers
[i
]; i
++) {
10571 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10572 if (drv
->get_interfaces
== NULL
)
10574 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10579 iface
= last
= tmp
;
10588 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10589 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10590 tmp
->drv_name
, tmp
->ifname
,
10591 tmp
->desc
? tmp
->desc
: "");
10592 if (os_snprintf_error(end
- pos
, res
)) {
10599 wpa_free_iface_info(iface
);
10605 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10607 char *buf
, int len
)
10611 struct wpa_supplicant
*wpa_s
;
10615 show_ctrl
= !!os_strstr(input
, "ctrl");
10617 wpa_s
= global
->ifaces
;
10623 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10625 wpa_s
->conf
->ctrl_interface
?
10626 wpa_s
->conf
->ctrl_interface
: "N/A");
10628 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10631 if (os_snprintf_error(end
- pos
, res
)) {
10636 wpa_s
= wpa_s
->next
;
10642 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10643 const char *ifname
,
10644 char *cmd
, size_t *resp_len
)
10646 struct wpa_supplicant
*wpa_s
;
10648 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10649 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10653 if (wpa_s
== NULL
) {
10654 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10656 *resp_len
= os_strlen(resp
);
10662 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10666 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10667 char *buf
, size_t *resp_len
)
10670 static const char * cmd
[] = {
10676 "P2P_GET_PASSPHRASE",
10677 "P2P_SERVICE_UPDATE",
10678 "P2P_SERVICE_FLUSH",
10681 "P2P_PRESENCE_REQ",
10685 #endif /* CONFIG_AP */
10688 static const char * prefix
[] = {
10691 #endif /* ANDROID */
10698 "P2P_GROUP_REMOVE ",
10700 "P2P_GROUP_MEMBER ",
10702 "P2P_SERV_DISC_REQ ",
10703 "P2P_SERV_DISC_CANCEL_REQ ",
10704 "P2P_SERV_DISC_RESP ",
10705 "P2P_SERV_DISC_EXTERNAL ",
10706 "P2P_SERVICE_ADD ",
10707 "P2P_SERVICE_DEL ",
10708 "P2P_SERVICE_REP ",
10713 "P2P_UNAUTHORIZE ",
10714 "P2P_PRESENCE_REQ ",
10716 "P2P_REMOVE_CLIENT ",
10718 "WPS_NFC_TAG_READ ",
10719 "NFC_GET_HANDOVER_SEL ",
10720 "NFC_GET_HANDOVER_REQ ",
10721 "NFC_REPORT_HANDOVER ",
10722 "P2P_ASP_PROVISION ",
10723 "P2P_ASP_PROVISION_RESP ",
10727 #endif /* CONFIG_AP */
10733 if (global
->p2p_init_wpa_s
== NULL
)
10736 for (i
= 0; !found
&& cmd
[i
]; i
++) {
10737 if (os_strcmp(buf
, cmd
[i
]) == 0)
10741 for (i
= 0; !found
&& prefix
[i
]; i
++) {
10742 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
10747 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10749 #endif /* CONFIG_P2P */
10754 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
10755 char *buf
, size_t *resp_len
)
10757 #ifdef CONFIG_WIFI_DISPLAY
10758 if (global
->p2p_init_wpa_s
== NULL
)
10760 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
10761 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
10762 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10764 #endif /* CONFIG_WIFI_DISPLAY */
10769 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
10770 char *buf
, size_t *resp_len
)
10774 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
10778 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
10786 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
10790 value
= os_strchr(cmd
, ' ');
10795 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
10797 #ifdef CONFIG_WIFI_DISPLAY
10798 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
10799 wifi_display_enable(global
, !!atoi(value
));
10802 #endif /* CONFIG_WIFI_DISPLAY */
10804 /* Restore cmd to its original value to allow redirection */
10811 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
10814 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
10818 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
10819 * <variable name> */
10821 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
10822 p
= os_strchr(cmd
, ' ');
10827 wpa_s
[i
] = global
->ifaces
;
10828 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
10829 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
10834 wpa_printf(MSG_DEBUG
,
10835 "CTRL_IFACE: Could not find iface=%s", cmd
);
10842 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
10846 #ifndef CONFIG_NO_CONFIG_WRITE
10847 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
10849 int ret
= 0, saved
= 0;
10850 struct wpa_supplicant
*wpa_s
;
10852 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10853 if (!wpa_s
->conf
->update_config
) {
10854 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
10858 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
10859 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
10862 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
10867 if (!saved
&& !ret
) {
10868 wpa_dbg(wpa_s
, MSG_DEBUG
,
10869 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
10875 #endif /* CONFIG_NO_CONFIG_WRITE */
10878 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
10879 char *buf
, size_t buflen
)
10883 struct wpa_supplicant
*wpa_s
;
10886 end
= buf
+ buflen
;
10889 if (global
->p2p
&& !global
->p2p_disabled
) {
10890 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
10893 MAC2STR(global
->p2p_dev_addr
),
10894 p2p_get_state_txt(global
->p2p
));
10895 if (os_snprintf_error(end
- pos
, ret
))
10898 } else if (global
->p2p
) {
10899 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
10900 if (os_snprintf_error(end
- pos
, ret
))
10904 #endif /* CONFIG_P2P */
10906 #ifdef CONFIG_WIFI_DISPLAY
10907 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
10908 !!global
->wifi_display
);
10909 if (os_snprintf_error(end
- pos
, ret
))
10912 #endif /* CONFIG_WIFI_DISPLAY */
10914 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10915 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
10916 "address=" MACSTR
"\n",
10917 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
10918 if (os_snprintf_error(end
- pos
, ret
))
10929 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
10930 char *cmd
, char *buf
,
10933 char ifname
[IFNAMSIZ
+ 1];
10934 struct fst_iface_cfg cfg
;
10935 struct wpa_supplicant
*wpa_s
;
10936 struct fst_wpa_obj iface_obj
;
10938 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
10939 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10942 wpa_printf(MSG_INFO
, "FST: Already attached");
10945 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
10946 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
10949 return os_snprintf(buf
, reply_size
, "OK\n");
10957 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
10958 char *cmd
, char *buf
,
10961 char ifname
[IFNAMSIZ
+ 1];
10962 struct wpa_supplicant
*wpa_s
;
10964 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
10965 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10967 if (!fst_iface_detach(ifname
)) {
10969 return os_snprintf(buf
, reply_size
, "OK\n");
10977 #endif /* CONFIG_FST */
10980 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
10981 char *buf
, size_t *resp_len
)
10984 const int reply_size
= 2048;
10986 int level
= MSG_DEBUG
;
10988 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
10989 char *pos
= os_strchr(buf
+ 7, ' ');
10992 return wpas_global_ctrl_iface_ifname(global
,
10998 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11002 if (os_strcmp(buf
, "PING") == 0)
11003 level
= MSG_EXCESSIVE
;
11004 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11005 (const u8
*) buf
, os_strlen(buf
));
11007 reply
= os_malloc(reply_size
);
11008 if (reply
== NULL
) {
11013 os_memcpy(reply
, "OK\n", 3);
11016 if (os_strcmp(buf
, "PING") == 0) {
11017 os_memcpy(reply
, "PONG\n", 5);
11019 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11020 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11022 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11023 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11025 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11026 reply_len
= wpa_supplicant_global_iface_list(
11027 global
, reply
, reply_size
);
11028 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11029 reply_len
= wpa_supplicant_global_iface_interfaces(
11030 global
, buf
+ 10, reply
, reply_size
);
11032 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11033 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11036 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11037 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11040 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11041 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11042 #endif /* CONFIG_FST */
11043 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11044 wpa_supplicant_terminate_proc(global
);
11045 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11046 wpas_notify_suspend(global
);
11047 } else if (os_strcmp(buf
, "RESUME") == 0) {
11048 wpas_notify_resume(global
);
11049 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11050 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11052 if (global
->p2p_init_wpa_s
) {
11054 /* Check if P2P redirection would work for this
11056 return wpa_supplicant_ctrl_iface_process(
11057 global
->p2p_init_wpa_s
,
11060 #endif /* CONFIG_P2P */
11063 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11064 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11066 #ifndef CONFIG_NO_CONFIG_WRITE
11067 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11068 if (wpas_global_ctrl_iface_save_config(global
))
11070 #endif /* CONFIG_NO_CONFIG_WRITE */
11071 } else if (os_strcmp(buf
, "STATUS") == 0) {
11072 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11074 #ifdef CONFIG_MODULE_TESTS
11075 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11076 if (wpas_module_tests() < 0)
11078 #endif /* CONFIG_MODULE_TESTS */
11079 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11080 if (wpa_debug_reopen_file() < 0)
11083 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11087 if (reply_len
< 0) {
11088 os_memcpy(reply
, "FAIL\n", 5);
11092 *resp_len
= reply_len
;