2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
10 #ifdef CONFIG_TESTING_OPTIONS
11 #include <netinet/ip.h>
12 #endif /* CONFIG_TESTING_OPTIONS */
14 #include "utils/common.h"
15 #include "utils/eloop.h"
16 #include "utils/uuid.h"
17 #include "utils/module_tests.h"
18 #include "common/version.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
21 #include "common/wpa_ctrl.h"
23 #include "common/dpp.h"
24 #endif /* CONFIG_DPP */
25 #include "crypto/tls.h"
26 #include "ap/hostapd.h"
27 #include "eap_peer/eap.h"
28 #include "eapol_supp/eapol_supp_sm.h"
29 #include "rsn_supp/wpa.h"
30 #include "rsn_supp/preauth.h"
31 #include "rsn_supp/pmksa_cache.h"
32 #include "l2_packet/l2_packet.h"
35 #include "fst/fst_ctrl_iface.h"
37 #include "wpa_supplicant_i.h"
39 #include "wps_supplicant.h"
42 #include "p2p_supplicant.h"
44 #include "hs20_supplicant.h"
45 #include "wifi_display.h"
49 #include "ctrl_iface.h"
50 #include "interworking.h"
51 #include "blacklist.h"
54 #include "offchannel.h"
55 #include "drivers/driver.h"
57 #include "dpp_supplicant.h"
61 #include <net/if_ether.h>
62 #elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS)
63 #include <net/ethernet.h>
66 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
68 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
71 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
75 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
78 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
85 if (hwaddr_aton(pos
, addr
)) {
89 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
95 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
98 pos
= os_strchr(pos
, ' ');
103 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
104 os_free(wpa_s
->bssid_filter
);
105 wpa_s
->bssid_filter
= filter
;
106 wpa_s
->bssid_filter_count
= count
;
112 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
115 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
116 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
117 size_t count
= 0, ssid_count
= 0;
121 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
122 * SSID_SPEC ::= ssid <SSID_HEX>
123 * BSSID_SPEC ::= bssid <BSSID_HEX>
130 if (os_strncmp(pos
, "bssid ", 6) == 0) {
133 res
= hwaddr_aton2(pos
, addr
);
137 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
138 "BSSID value '%s'", pos
);
142 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
149 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
151 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
157 if (*end
== '\0' || *end
== ' ')
162 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
163 sizeof(struct wpa_ssid_value
));
171 if ((end
- pos
) & 0x01 ||
172 end
- pos
> 2 * SSID_MAX_LEN
||
173 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
174 (end
- pos
) / 2) < 0) {
177 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
178 "SSID value '%s'", pos
);
181 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
182 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
183 ssid
[ssid_count
].ssid
,
184 ssid
[ssid_count
].ssid_len
);
188 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
195 pos
= os_strchr(pos
, ' ');
200 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
201 os_free(wpa_s
->disallow_aps_bssid
);
202 wpa_s
->disallow_aps_bssid
= bssid
;
203 wpa_s
->disallow_aps_bssid_count
= count
;
205 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
206 os_free(wpa_s
->disallow_aps_ssid
);
207 wpa_s
->disallow_aps_ssid
= ssid
;
208 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
210 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
213 c
= wpa_s
->current_ssid
;
214 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
217 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
218 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
221 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
222 "because current AP was marked disallowed");
225 wpa_s
->sme
.prev_bssid_set
= 0;
226 #endif /* CONFIG_SME */
227 wpa_s
->reassociate
= 1;
228 wpa_s
->own_disconnect_req
= 1;
229 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
230 wpa_supplicant_req_scan(wpa_s
, 0, 0);
236 #ifndef CONFIG_NO_CONFIG_BLOBS
237 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
240 struct wpa_config_blob
*blob
;
243 pos
= os_strchr(pos
, ' ');
247 len
= os_strlen(pos
);
251 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
252 blob
= os_zalloc(sizeof(*blob
));
255 blob
->name
= os_strdup(name
);
256 blob
->data
= os_malloc(len
/ 2);
257 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
258 wpa_config_free_blob(blob
);
262 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
263 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
264 wpa_config_free_blob(blob
);
269 wpa_config_set_blob(wpa_s
->conf
, blob
);
273 #endif /* CONFIG_NO_CONFIG_BLOBS */
276 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
284 params
= os_strchr(cmd
, ' ');
285 os_free(wpa_s
->manual_sched_scan_freqs
);
288 pos
= os_strstr(params
, "freq=");
290 freqs
= freq_range_to_channel_list(wpa_s
,
293 wpa_s
->manual_sched_scan_freqs
= freqs
;
294 ret
= wpas_start_pno(wpa_s
);
296 ret
= wpas_stop_pno(wpa_s
);
302 static int wpas_ctrl_set_band(struct wpa_supplicant
*wpa_s
, char *band
)
304 union wpa_event_data event
;
306 if (os_strcmp(band
, "AUTO") == 0)
307 wpa_s
->setband
= WPA_SETBAND_AUTO
;
308 else if (os_strcmp(band
, "5G") == 0)
309 wpa_s
->setband
= WPA_SETBAND_5G
;
310 else if (os_strcmp(band
, "2G") == 0)
311 wpa_s
->setband
= WPA_SETBAND_2G
;
315 if (wpa_drv_setband(wpa_s
, wpa_s
->setband
) == 0) {
316 os_memset(&event
, 0, sizeof(event
));
317 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
318 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
319 wpa_supplicant_event(wpa_s
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
326 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant
*wpa_s
,
331 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
332 wpabuf_free(wpa_s
->lci
);
337 lci
= wpabuf_parse_bin(cmd
);
341 if (os_get_reltime(&wpa_s
->lci_time
)) {
346 wpabuf_free(wpa_s
->lci
);
354 wpas_ctrl_set_relative_rssi(struct wpa_supplicant
*wpa_s
, const char *cmd
)
358 if (os_strcmp(cmd
, "disable") == 0) {
359 wpa_s
->srp
.relative_rssi_set
= 0;
363 relative_rssi
= atoi(cmd
);
364 if (relative_rssi
< 0 || relative_rssi
> 100)
366 wpa_s
->srp
.relative_rssi
= relative_rssi
;
367 wpa_s
->srp
.relative_rssi_set
= 1;
372 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant
*wpa_s
,
378 /* <band>:adjust_value */
379 pos
= os_strchr(cmd
, ':');
383 adjust_rssi
= atoi(pos
);
384 if (adjust_rssi
< -100 || adjust_rssi
> 100)
387 if (os_strncmp(cmd
, "2G", 2) == 0)
388 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_2G
;
389 else if (os_strncmp(cmd
, "5G", 2) == 0)
390 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_5G
;
394 wpa_s
->srp
.relative_adjust_rssi
= adjust_rssi
;
400 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant
*wpa_s
,
403 struct wpabuf
*ric_ies
;
405 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
406 wpabuf_free(wpa_s
->ric_ies
);
407 wpa_s
->ric_ies
= NULL
;
411 ric_ies
= wpabuf_parse_bin(cmd
);
415 wpabuf_free(wpa_s
->ric_ies
);
416 wpa_s
->ric_ies
= ric_ies
;
422 #ifdef CONFIG_TESTING_OPTIONS
423 static int wpas_ctrl_iface_set_dso(struct wpa_supplicant
*wpa_s
,
427 const char *pos
= val
;
428 struct driver_signal_override
*dso
= NULL
, *tmp
, parsed
;
430 if (hwaddr_aton(pos
, bssid
))
432 pos
= os_strchr(pos
, ' ');
434 dl_list_for_each(tmp
, &wpa_s
->drv_signal_override
,
435 struct driver_signal_override
, list
) {
436 if (os_memcmp(bssid
, tmp
->bssid
, ETH_ALEN
) == 0) {
443 /* Remove existing entry */
445 dl_list_del(&dso
->list
);
452 /* Update an existing entry or add a new one */
453 os_memset(&parsed
, 0, sizeof(parsed
));
454 if (sscanf(pos
, "%d %d %d %d %d",
455 &parsed
.si_current_signal
,
456 &parsed
.si_avg_signal
,
457 &parsed
.si_avg_beacon_signal
,
458 &parsed
.si_current_noise
,
459 &parsed
.scan_level
) != 5)
463 dso
= os_zalloc(sizeof(*dso
));
466 os_memcpy(dso
->bssid
, bssid
, ETH_ALEN
);
467 dl_list_add(&wpa_s
->drv_signal_override
, &dso
->list
);
469 dso
->si_current_signal
= parsed
.si_current_signal
;
470 dso
->si_avg_signal
= parsed
.si_avg_signal
;
471 dso
->si_avg_beacon_signal
= parsed
.si_avg_beacon_signal
;
472 dso
->si_current_noise
= parsed
.si_current_noise
;
473 dso
->scan_level
= parsed
.scan_level
;
477 #endif /* CONFIG_TESTING_OPTIONS */
480 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
486 value
= os_strchr(cmd
, ' ');
491 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
492 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
493 eapol_sm_configure(wpa_s
->eapol
,
494 atoi(value
), -1, -1, -1);
495 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
496 eapol_sm_configure(wpa_s
->eapol
,
497 -1, atoi(value
), -1, -1);
498 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
499 eapol_sm_configure(wpa_s
->eapol
,
500 -1, -1, atoi(value
), -1);
501 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
502 eapol_sm_configure(wpa_s
->eapol
,
503 -1, -1, -1, atoi(value
));
504 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
505 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
510 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
512 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
514 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
519 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
521 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
522 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
527 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
529 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
530 wpa_s
->wps_fragment_size
= atoi(value
);
531 #ifdef CONFIG_WPS_TESTING
532 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
534 val
= strtol(value
, NULL
, 0);
535 if (val
< 0 || val
> 0xff) {
537 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
538 "wps_version_number %ld", val
);
540 wps_version_number
= val
;
541 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
543 (wps_version_number
& 0xf0) >> 4,
544 wps_version_number
& 0x0f);
546 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
547 wps_testing_dummy_cred
= atoi(value
);
548 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
549 wps_testing_dummy_cred
);
550 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
551 wps_corrupt_pkhash
= atoi(value
);
552 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
554 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
555 if (value
[0] == '\0') {
556 wps_force_auth_types_in_use
= 0;
558 wps_force_auth_types
= strtol(value
, NULL
, 0);
559 wps_force_auth_types_in_use
= 1;
561 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
562 if (value
[0] == '\0') {
563 wps_force_encr_types_in_use
= 0;
565 wps_force_encr_types
= strtol(value
, NULL
, 0);
566 wps_force_encr_types_in_use
= 1;
568 #endif /* CONFIG_WPS_TESTING */
569 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
570 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
573 #ifdef CONFIG_TDLS_TESTING
574 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
575 tdls_testing
= strtol(value
, NULL
, 0);
576 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
577 #endif /* CONFIG_TDLS_TESTING */
578 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
579 int disabled
= atoi(value
);
580 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
582 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
584 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
586 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
587 #endif /* CONFIG_TDLS */
588 } else if (os_strcasecmp(cmd
, "pno") == 0) {
589 ret
= wpas_ctrl_pno(wpa_s
, value
);
590 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
591 int disabled
= atoi(value
);
592 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
595 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
596 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
597 if (os_strcmp(value
, "disable") == 0)
598 wpa_s
->set_sta_uapsd
= 0;
602 /* format: BE,BK,VI,VO;max SP Length */
604 pos
= os_strchr(value
, ',');
609 pos
= os_strchr(pos
, ',');
614 pos
= os_strchr(pos
, ',');
619 /* ignore max SP Length for now */
621 wpa_s
->set_sta_uapsd
= 1;
622 wpa_s
->sta_uapsd
= 0;
624 wpa_s
->sta_uapsd
|= BIT(0);
626 wpa_s
->sta_uapsd
|= BIT(1);
628 wpa_s
->sta_uapsd
|= BIT(2);
630 wpa_s
->sta_uapsd
|= BIT(3);
632 } else if (os_strcasecmp(cmd
, "ps") == 0) {
633 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
634 #ifdef CONFIG_WIFI_DISPLAY
635 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
636 int enabled
= !!atoi(value
);
637 if (enabled
&& !wpa_s
->global
->p2p
)
640 wifi_display_enable(wpa_s
->global
, enabled
);
641 #endif /* CONFIG_WIFI_DISPLAY */
642 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
643 ret
= set_bssid_filter(wpa_s
, value
);
644 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
645 ret
= set_disallow_aps(wpa_s
, value
);
646 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
647 wpa_s
->no_keep_alive
= !!atoi(value
);
649 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
650 os_free(wpa_s
->dpp_configurator_params
);
651 wpa_s
->dpp_configurator_params
= os_strdup(value
);
652 } else if (os_strcasecmp(cmd
, "dpp_init_max_tries") == 0) {
653 wpa_s
->dpp_init_max_tries
= atoi(value
);
654 } else if (os_strcasecmp(cmd
, "dpp_init_retry_time") == 0) {
655 wpa_s
->dpp_init_retry_time
= atoi(value
);
656 } else if (os_strcasecmp(cmd
, "dpp_resp_wait_time") == 0) {
657 wpa_s
->dpp_resp_wait_time
= atoi(value
);
658 } else if (os_strcasecmp(cmd
, "dpp_resp_max_tries") == 0) {
659 wpa_s
->dpp_resp_max_tries
= atoi(value
);
660 } else if (os_strcasecmp(cmd
, "dpp_resp_retry_time") == 0) {
661 wpa_s
->dpp_resp_retry_time
= atoi(value
);
662 #ifdef CONFIG_TESTING_OPTIONS
663 } else if (os_strcasecmp(cmd
, "dpp_pkex_own_mac_override") == 0) {
664 if (hwaddr_aton(value
, dpp_pkex_own_mac_override
))
666 } else if (os_strcasecmp(cmd
, "dpp_pkex_peer_mac_override") == 0) {
667 if (hwaddr_aton(value
, dpp_pkex_peer_mac_override
))
669 } else if (os_strcasecmp(cmd
, "dpp_pkex_ephemeral_key_override") == 0) {
670 size_t hex_len
= os_strlen(value
);
673 2 * sizeof(dpp_pkex_ephemeral_key_override
))
675 else if (hexstr2bin(value
, dpp_pkex_ephemeral_key_override
,
679 dpp_pkex_ephemeral_key_override_len
= hex_len
/ 2;
680 } else if (os_strcasecmp(cmd
, "dpp_protocol_key_override") == 0) {
681 size_t hex_len
= os_strlen(value
);
683 if (hex_len
> 2 * sizeof(dpp_protocol_key_override
))
685 else if (hexstr2bin(value
, dpp_protocol_key_override
,
689 dpp_protocol_key_override_len
= hex_len
/ 2;
690 } else if (os_strcasecmp(cmd
, "dpp_nonce_override") == 0) {
691 size_t hex_len
= os_strlen(value
);
693 if (hex_len
> 2 * sizeof(dpp_nonce_override
))
695 else if (hexstr2bin(value
, dpp_nonce_override
, hex_len
/ 2))
698 dpp_nonce_override_len
= hex_len
/ 2;
699 #endif /* CONFIG_TESTING_OPTIONS */
700 #endif /* CONFIG_DPP */
701 #ifdef CONFIG_TESTING_OPTIONS
702 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
703 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
704 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
705 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
707 if (wpa_s
->ap_iface
) {
708 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
709 wpa_s
->ext_eapol_frame_io
;
711 #endif /* CONFIG_AP */
712 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
713 wpa_s
->extra_roc_dur
= atoi(value
);
714 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
715 wpa_s
->test_failure
= atoi(value
);
716 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
717 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
718 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
719 wpa_s
->ignore_auth_resp
= !!atoi(value
);
720 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
721 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
722 wpa_drv_ignore_assoc_disallow(wpa_s
,
723 wpa_s
->ignore_assoc_disallow
);
724 } else if (os_strcasecmp(cmd
, "disable_sa_query") == 0) {
725 wpa_s
->disable_sa_query
= !!atoi(value
);
726 } else if (os_strcasecmp(cmd
, "ignore_sae_h2e_only") == 0) {
727 wpa_s
->ignore_sae_h2e_only
= !!atoi(value
);
728 } else if (os_strcasecmp(cmd
, "extra_sae_rejected_groups") == 0) {
731 os_free(wpa_s
->extra_sae_rejected_groups
);
732 wpa_s
->extra_sae_rejected_groups
= NULL
;
734 while (pos
&& pos
[0]) {
738 wpa_printf(MSG_DEBUG
,
739 "TESTING: Extra rejection of SAE group %d",
742 int_array_add_unique(
743 &wpa_s
->extra_sae_rejected_groups
,
745 pos
= os_strchr(pos
, ' ');
750 } else if (os_strcasecmp(cmd
, "rsne_override_eapol") == 0) {
751 wpabuf_free(wpa_s
->rsne_override_eapol
);
752 if (os_strcmp(value
, "NULL") == 0)
753 wpa_s
->rsne_override_eapol
= NULL
;
755 wpa_s
->rsne_override_eapol
= wpabuf_parse_bin(value
);
756 } else if (os_strcasecmp(cmd
, "rsnxe_override_assoc") == 0) {
757 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
758 if (os_strcmp(value
, "NULL") == 0)
759 wpa_s
->rsnxe_override_assoc
= NULL
;
761 wpa_s
->rsnxe_override_assoc
= wpabuf_parse_bin(value
);
762 } else if (os_strcasecmp(cmd
, "rsnxe_override_eapol") == 0) {
763 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
764 if (os_strcmp(value
, "NULL") == 0)
765 wpa_s
->rsnxe_override_eapol
= NULL
;
767 wpa_s
->rsnxe_override_eapol
= wpabuf_parse_bin(value
);
768 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
769 wpa_s
->reject_btm_req_reason
= atoi(value
);
770 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
771 os_free(wpa_s
->get_pref_freq_list_override
);
773 wpa_s
->get_pref_freq_list_override
= NULL
;
775 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
776 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
777 wpabuf_free(wpa_s
->sae_commit_override
);
778 if (value
[0] == '\0')
779 wpa_s
->sae_commit_override
= NULL
;
781 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
782 } else if (os_strcasecmp(cmd
, "driver_signal_override") == 0) {
783 ret
= wpas_ctrl_iface_set_dso(wpa_s
, value
);
785 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
786 os_free(wpa_s
->dpp_config_obj_override
);
787 if (value
[0] == '\0')
788 wpa_s
->dpp_config_obj_override
= NULL
;
790 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
791 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
792 os_free(wpa_s
->dpp_discovery_override
);
793 if (value
[0] == '\0')
794 wpa_s
->dpp_discovery_override
= NULL
;
796 wpa_s
->dpp_discovery_override
= os_strdup(value
);
797 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
798 os_free(wpa_s
->dpp_groups_override
);
799 if (value
[0] == '\0')
800 wpa_s
->dpp_groups_override
= NULL
;
802 wpa_s
->dpp_groups_override
= os_strdup(value
);
803 } else if (os_strcasecmp(cmd
,
804 "dpp_ignore_netaccesskey_mismatch") == 0) {
805 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
806 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
807 dpp_test
= atoi(value
);
808 #endif /* CONFIG_DPP */
809 #endif /* CONFIG_TESTING_OPTIONS */
811 } else if (os_strcasecmp(cmd
, "disable_fils") == 0) {
812 wpa_s
->disable_fils
= !!atoi(value
);
813 wpa_drv_disable_fils(wpa_s
, wpa_s
->disable_fils
);
814 wpa_supplicant_set_default_scan_ies(wpa_s
);
815 #endif /* CONFIG_FILS */
816 #ifndef CONFIG_NO_CONFIG_BLOBS
817 } else if (os_strcmp(cmd
, "blob") == 0) {
818 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
819 #endif /* CONFIG_NO_CONFIG_BLOBS */
820 } else if (os_strcasecmp(cmd
, "setband") == 0) {
821 ret
= wpas_ctrl_set_band(wpa_s
, value
);
823 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
824 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
827 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
829 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
830 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
831 } else if (os_strcasecmp(cmd
, "oce") == 0) {
832 wpa_s
->conf
->oce
= atoi(value
);
833 if (wpa_s
->conf
->oce
) {
834 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
835 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
836 wpa_s
->enable_oce
= OCE_STA
;
838 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
840 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
841 /* TODO: Need to add STA-CFON support */
842 wpa_printf(MSG_ERROR
,
843 "OCE STA-CFON feature is not yet supported");
847 wpa_s
->enable_oce
= 0;
849 wpa_supplicant_set_default_scan_ies(wpa_s
);
850 #endif /* CONFIG_MBO */
851 } else if (os_strcasecmp(cmd
, "lci") == 0) {
852 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
853 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
854 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
855 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
856 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
857 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
858 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
859 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
860 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
861 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
862 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
864 } else if (os_strcasecmp(cmd
, "coloc_intf_elems") == 0) {
865 struct wpabuf
*elems
;
867 elems
= wpabuf_parse_bin(value
);
870 wnm_set_coloc_intf_elems(wpa_s
, elems
);
871 #endif /* CONFIG_WNM */
874 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
876 wpa_supplicant_update_config(wpa_s
);
883 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
884 char *cmd
, char *buf
, size_t buflen
)
888 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
890 if (os_strcmp(cmd
, "version") == 0) {
891 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
892 } else if (os_strcasecmp(cmd
, "country") == 0) {
893 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
894 res
= os_snprintf(buf
, buflen
, "%c%c",
895 wpa_s
->conf
->country
[0],
896 wpa_s
->conf
->country
[1]);
897 #ifdef CONFIG_WIFI_DISPLAY
898 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
900 if (wpa_s
->global
->p2p
== NULL
||
901 wpa_s
->global
->p2p_disabled
)
904 enabled
= wpa_s
->global
->wifi_display
;
905 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
906 #endif /* CONFIG_WIFI_DISPLAY */
907 #ifdef CONFIG_TESTING_GET_GTK
908 } else if (os_strcmp(cmd
, "gtk") == 0) {
909 if (wpa_s
->last_gtk_len
== 0)
911 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
912 wpa_s
->last_gtk_len
);
914 #endif /* CONFIG_TESTING_GET_GTK */
915 } else if (os_strcmp(cmd
, "tls_library") == 0) {
916 res
= tls_get_library_version(buf
, buflen
);
917 #ifdef CONFIG_TESTING_OPTIONS
918 } else if (os_strcmp(cmd
, "anonce") == 0) {
919 return wpa_snprintf_hex(buf
, buflen
,
920 wpa_sm_get_anonce(wpa_s
->wpa
),
922 } else if (os_strcasecmp(cmd
, "last_tk_key_idx") == 0) {
923 res
= os_snprintf(buf
, buflen
, "%d", wpa_s
->last_tk_key_idx
);
924 #endif /* CONFIG_TESTING_OPTIONS */
926 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
929 if (os_snprintf_error(buflen
, res
))
935 #ifdef IEEE8021X_EAPOL
936 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
940 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
942 if (hwaddr_aton(addr
, bssid
)) {
943 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
948 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
949 rsn_preauth_deinit(wpa_s
->wpa
);
950 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
955 #endif /* IEEE8021X_EAPOL */
960 static int wpa_supplicant_ctrl_iface_tdls_discover(
961 struct wpa_supplicant
*wpa_s
, char *addr
)
966 if (hwaddr_aton(addr
, peer
)) {
967 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
968 "address '%s'", addr
);
972 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
975 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
976 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
978 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
984 static int wpa_supplicant_ctrl_iface_tdls_setup(
985 struct wpa_supplicant
*wpa_s
, char *addr
)
990 if (hwaddr_aton(addr
, peer
)) {
991 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
992 "address '%s'", addr
);
996 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
999 if ((wpa_s
->conf
->tdls_external_control
) &&
1000 wpa_tdls_is_external_setup(wpa_s
->wpa
))
1001 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
1003 wpa_tdls_remove(wpa_s
->wpa
, peer
);
1005 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
1006 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
1008 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
1014 static int wpa_supplicant_ctrl_iface_tdls_teardown(
1015 struct wpa_supplicant
*wpa_s
, char *addr
)
1020 if (os_strcmp(addr
, "*") == 0) {
1021 /* remove everyone */
1022 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
1023 wpa_tdls_teardown_peers(wpa_s
->wpa
);
1027 if (hwaddr_aton(addr
, peer
)) {
1028 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1029 "address '%s'", addr
);
1033 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
1036 if ((wpa_s
->conf
->tdls_external_control
) &&
1037 wpa_tdls_is_external_setup(wpa_s
->wpa
))
1038 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
1040 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
1041 ret
= wpa_tdls_teardown_link(
1043 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
1045 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
1051 static int ctrl_iface_get_capability_tdls(
1052 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1056 ret
= os_snprintf(buf
, buflen
, "%s\n",
1057 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
1059 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
1060 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
1061 if (os_snprintf_error(buflen
, ret
))
1067 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1068 struct wpa_supplicant
*wpa_s
, char *cmd
)
1071 struct hostapd_freq_params freq_params
;
1075 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1076 wpa_printf(MSG_INFO
,
1077 "tdls_chanswitch: Only supported with external setup");
1081 os_memset(&freq_params
, 0, sizeof(freq_params
));
1083 pos
= os_strchr(cmd
, ' ');
1088 oper_class
= strtol(pos
, &end
, 10);
1090 wpa_printf(MSG_INFO
,
1091 "tdls_chanswitch: Invalid op class provided");
1096 freq_params
.freq
= atoi(pos
);
1097 if (freq_params
.freq
== 0) {
1098 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
1102 #define SET_FREQ_SETTING(str) \
1104 const char *pos2 = os_strstr(pos, " " #str "="); \
1106 pos2 += sizeof(" " #str "=") - 1; \
1107 freq_params.str = atoi(pos2); \
1111 SET_FREQ_SETTING(center_freq1
);
1112 SET_FREQ_SETTING(center_freq2
);
1113 SET_FREQ_SETTING(bandwidth
);
1114 SET_FREQ_SETTING(sec_channel_offset
);
1115 #undef SET_FREQ_SETTING
1117 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
1118 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
1120 if (hwaddr_aton(cmd
, peer
)) {
1121 wpa_printf(MSG_DEBUG
,
1122 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1127 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1128 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1129 MAC2STR(peer
), oper_class
, freq_params
.freq
,
1130 freq_params
.center_freq1
, freq_params
.center_freq2
,
1131 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
1132 freq_params
.ht_enabled
? " HT" : "",
1133 freq_params
.vht_enabled
? " VHT" : "");
1135 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
1140 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1141 struct wpa_supplicant
*wpa_s
, char *cmd
)
1145 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1146 wpa_printf(MSG_INFO
,
1147 "tdls_chanswitch: Only supported with external setup");
1151 if (hwaddr_aton(cmd
, peer
)) {
1152 wpa_printf(MSG_DEBUG
,
1153 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1158 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1161 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1165 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1166 struct wpa_supplicant
*wpa_s
, const char *addr
,
1167 char *buf
, size_t buflen
)
1170 const char *tdls_status
;
1173 if (hwaddr_aton(addr
, peer
)) {
1174 wpa_printf(MSG_DEBUG
,
1175 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1179 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1182 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1183 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1184 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1185 if (os_snprintf_error(buflen
, ret
))
1191 #endif /* CONFIG_TDLS */
1194 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1196 char *token
, *context
= NULL
;
1197 struct wmm_ac_ts_setup_params params
= {
1202 while ((token
= str_token(cmd
, " ", &context
))) {
1203 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1204 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1205 sscanf(token
, "nominal_msdu_size=%i",
1206 ¶ms
.nominal_msdu_size
) == 1 ||
1207 sscanf(token
, "mean_data_rate=%i",
1208 ¶ms
.mean_data_rate
) == 1 ||
1209 sscanf(token
, "min_phy_rate=%i",
1210 ¶ms
.minimum_phy_rate
) == 1 ||
1211 sscanf(token
, "sba=%i",
1212 ¶ms
.surplus_bandwidth_allowance
) == 1)
1215 if (os_strcasecmp(token
, "downlink") == 0) {
1216 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1217 } else if (os_strcasecmp(token
, "uplink") == 0) {
1218 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1219 } else if (os_strcasecmp(token
, "bidi") == 0) {
1220 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1221 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1222 params
.fixed_nominal_msdu
= 1;
1224 wpa_printf(MSG_DEBUG
,
1225 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1232 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1236 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1238 u8 tsid
= atoi(cmd
);
1240 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1244 #ifdef CONFIG_IEEE80211R
1245 static int wpa_supplicant_ctrl_iface_ft_ds(
1246 struct wpa_supplicant
*wpa_s
, char *addr
)
1248 u8 target_ap
[ETH_ALEN
];
1249 struct wpa_bss
*bss
;
1252 if (hwaddr_aton(addr
, target_ap
)) {
1253 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1254 "address '%s'", addr
);
1258 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1260 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1262 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1266 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1268 #endif /* CONFIG_IEEE80211R */
1272 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1275 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1277 u8 p2p_dev_addr
[ETH_ALEN
];
1278 #endif /* CONFIG_P2P */
1280 u8
*_p2p_dev_addr
= NULL
;
1281 #endif /* CONFIG_AP */
1285 if (!cmd
|| os_strcmp(cmd
, "any") == 0 ||
1286 os_strncmp(cmd
, "any ", 4) == 0) {
1289 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1290 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1291 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1292 "P2P Device Address '%s'",
1296 _p2p_dev_addr
= p2p_dev_addr
;
1297 #endif /* CONFIG_P2P */
1298 } else if (os_strncmp(cmd
, "multi_ap=", 9) == 0) {
1300 multi_ap
= atoi(cmd
+ 9);
1301 } else if (hwaddr_aton(cmd
, bssid
)) {
1302 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1308 pos
= os_strstr(cmd
, " multi_ap=");
1311 multi_ap
= atoi(pos
);
1316 if (wpa_s
->ap_iface
)
1317 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1318 #endif /* CONFIG_AP */
1320 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0, multi_ap
);
1324 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1325 char *cmd
, char *buf
,
1328 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1332 pin
= os_strchr(cmd
, ' ');
1336 if (os_strcmp(cmd
, "any") == 0)
1338 else if (os_strcmp(cmd
, "get") == 0) {
1339 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1342 } else if (hwaddr_aton(cmd
, bssid
)) {
1343 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1349 if (wpa_s
->ap_iface
) {
1354 pos
= os_strchr(pin
, ' ');
1357 timeout
= atoi(pos
);
1361 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1362 buf
, buflen
, timeout
);
1364 #endif /* CONFIG_AP */
1367 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1371 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1372 if (os_snprintf_error(buflen
, ret
))
1377 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1382 /* Return the generated PIN */
1383 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1384 if (os_snprintf_error(buflen
, ret
))
1390 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1391 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1398 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1399 (u8
*) cmd
, os_strlen(cmd
));
1400 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1401 if (*pos
< '0' || *pos
> '9')
1405 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1409 if (len
!= 4 && len
!= 8) {
1410 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1416 unsigned int pin_val
;
1417 pin_val
= atoi(pin
);
1418 if (!wps_pin_valid(pin_val
)) {
1419 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1420 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1421 if (os_snprintf_error(buflen
, ret
))
1427 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1428 if (os_snprintf_error(buflen
, ret
))
1435 #ifdef CONFIG_WPS_NFC
1437 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1440 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1442 if (cmd
== NULL
|| cmd
[0] == '\0')
1444 else if (hwaddr_aton(cmd
, bssid
))
1447 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1452 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1453 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1460 pos
= os_strchr(cmd
, ' ');
1463 if (os_strcmp(cmd
, "WPS") == 0)
1465 else if (os_strcmp(cmd
, "NDEF") == 0)
1470 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1474 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1476 reply
[res
++] = '\n';
1485 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1486 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1492 if (os_strcmp(cmd
, "WPS") == 0)
1494 else if (os_strcmp(cmd
, "NDEF") == 0)
1499 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1503 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1505 reply
[res
++] = '\n';
1514 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1515 struct wpa_supplicant
*wpa_s
, char *pos
)
1521 int forced_freq
= 0;
1523 freq
= strstr(pos
, " freq=");
1527 forced_freq
= atoi(freq
);
1530 len
= os_strlen(pos
);
1535 buf
= wpabuf_alloc(len
);
1538 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1543 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1550 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1551 char *reply
, size_t max_len
,
1557 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1561 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1563 reply
[res
++] = '\n';
1573 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1574 char *reply
, size_t max_len
,
1580 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1582 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1586 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1588 reply
[res
++] = '\n';
1595 #endif /* CONFIG_P2P */
1598 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1599 char *cmd
, char *reply
,
1605 pos
= os_strchr(cmd
, ' ');
1610 if (os_strcmp(cmd
, "WPS") == 0)
1612 else if (os_strcmp(cmd
, "NDEF") == 0)
1617 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1620 return wpas_ctrl_nfc_get_handover_req_wps(
1621 wpa_s
, reply
, max_len
, ndef
);
1625 if (os_strcmp(pos
, "P2P-CR") == 0) {
1626 return wpas_ctrl_nfc_get_handover_req_p2p(
1627 wpa_s
, reply
, max_len
, ndef
);
1629 #endif /* CONFIG_P2P */
1635 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1636 char *reply
, size_t max_len
,
1637 int ndef
, int cr
, char *uuid
)
1642 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1646 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1648 reply
[res
++] = '\n';
1658 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1659 char *reply
, size_t max_len
,
1665 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1669 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1671 reply
[res
++] = '\n';
1678 #endif /* CONFIG_P2P */
1681 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1682 char *cmd
, char *reply
,
1688 pos
= os_strchr(cmd
, ' ');
1693 if (os_strcmp(cmd
, "WPS") == 0)
1695 else if (os_strcmp(cmd
, "NDEF") == 0)
1700 pos2
= os_strchr(pos
, ' ');
1703 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1706 return wpas_ctrl_nfc_get_handover_sel_wps(
1707 wpa_s
, reply
, max_len
, ndef
,
1708 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1712 if (os_strcmp(pos
, "P2P-CR") == 0) {
1713 return wpas_ctrl_nfc_get_handover_sel_p2p(
1714 wpa_s
, reply
, max_len
, ndef
, 0);
1717 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1718 return wpas_ctrl_nfc_get_handover_sel_p2p(
1719 wpa_s
, reply
, max_len
, ndef
, 1);
1721 #endif /* CONFIG_P2P */
1727 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1731 struct wpabuf
*req
, *sel
;
1733 char *pos
, *role
, *type
, *pos2
;
1736 int forced_freq
= 0;
1738 freq
= strstr(cmd
, " freq=");
1742 forced_freq
= atoi(freq
);
1744 #endif /* CONFIG_P2P */
1747 pos
= os_strchr(role
, ' ');
1749 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1755 pos
= os_strchr(type
, ' ');
1757 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1762 pos2
= os_strchr(pos
, ' ');
1764 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1769 len
= os_strlen(pos
);
1771 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1776 req
= wpabuf_alloc(len
);
1778 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1781 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1782 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1787 len
= os_strlen(pos2
);
1789 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1795 sel
= wpabuf_alloc(len
);
1797 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1801 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1802 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1808 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1809 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1811 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1812 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1814 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1816 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1818 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1819 #endif /* CONFIG_AP */
1821 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1823 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1824 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1826 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1828 #endif /* CONFIG_P2P */
1830 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1831 "reported: role=%s type=%s", role
, type
);
1838 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1843 #endif /* CONFIG_WPS_NFC */
1846 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1855 struct wps_new_ap_settings ap
;
1857 pin
= os_strchr(cmd
, ' ');
1862 if (hwaddr_aton(cmd
, bssid
)) {
1863 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1868 new_ssid
= os_strchr(pin
, ' ');
1869 if (new_ssid
== NULL
)
1870 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1873 new_auth
= os_strchr(new_ssid
, ' ');
1874 if (new_auth
== NULL
)
1878 new_encr
= os_strchr(new_auth
, ' ');
1879 if (new_encr
== NULL
)
1883 new_key
= os_strchr(new_encr
, ' ');
1884 if (new_key
== NULL
)
1888 os_memset(&ap
, 0, sizeof(ap
));
1889 ap
.ssid_hex
= new_ssid
;
1892 ap
.key_hex
= new_key
;
1893 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1898 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1899 char *cmd
, char *buf
,
1904 const char *pin_txt
;
1906 if (!wpa_s
->ap_iface
)
1909 pos
= os_strchr(cmd
, ' ');
1913 if (os_strcmp(cmd
, "disable") == 0) {
1914 wpas_wps_ap_pin_disable(wpa_s
);
1915 return os_snprintf(buf
, buflen
, "OK\n");
1918 if (os_strcmp(cmd
, "random") == 0) {
1920 timeout
= atoi(pos
);
1921 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1922 if (pin_txt
== NULL
)
1924 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1927 if (os_strcmp(cmd
, "get") == 0) {
1928 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1929 if (pin_txt
== NULL
)
1931 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1934 if (os_strcmp(cmd
, "set") == 0) {
1939 pos
= os_strchr(pos
, ' ');
1942 timeout
= atoi(pos
);
1944 if (os_strlen(pin
) > buflen
)
1946 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1948 return os_snprintf(buf
, buflen
, "%s", pin
);
1953 #endif /* CONFIG_AP */
1956 #ifdef CONFIG_WPS_ER
1957 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1960 char *uuid
= cmd
, *pin
, *pos
;
1961 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1962 pin
= os_strchr(uuid
, ' ');
1966 pos
= os_strchr(pin
, ' ');
1969 if (hwaddr_aton(pos
, addr_buf
) == 0)
1972 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1976 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1979 char *uuid
= cmd
, *pin
;
1980 pin
= os_strchr(uuid
, ' ');
1984 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1988 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1989 struct wpa_supplicant
*wpa_s
, char *cmd
)
1991 char *uuid
= cmd
, *id
;
1992 id
= os_strchr(uuid
, ' ');
1996 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
2000 static int wpa_supplicant_ctrl_iface_wps_er_config(
2001 struct wpa_supplicant
*wpa_s
, char *cmd
)
2008 struct wps_new_ap_settings ap
;
2010 pin
= os_strchr(cmd
, ' ');
2015 new_ssid
= os_strchr(pin
, ' ');
2016 if (new_ssid
== NULL
)
2020 new_auth
= os_strchr(new_ssid
, ' ');
2021 if (new_auth
== NULL
)
2025 new_encr
= os_strchr(new_auth
, ' ');
2026 if (new_encr
== NULL
)
2030 new_key
= os_strchr(new_encr
, ' ');
2031 if (new_key
== NULL
)
2035 os_memset(&ap
, 0, sizeof(ap
));
2036 ap
.ssid_hex
= new_ssid
;
2039 ap
.key_hex
= new_key
;
2040 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
2044 #ifdef CONFIG_WPS_NFC
2045 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2046 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2053 uuid
= os_strchr(cmd
, ' ');
2058 if (os_strcmp(cmd
, "WPS") == 0)
2060 else if (os_strcmp(cmd
, "NDEF") == 0)
2065 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
2069 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
2071 reply
[res
++] = '\n';
2078 #endif /* CONFIG_WPS_NFC */
2079 #endif /* CONFIG_WPS_ER */
2081 #endif /* CONFIG_WPS */
2084 #ifdef CONFIG_IBSS_RSN
2085 static int wpa_supplicant_ctrl_iface_ibss_rsn(
2086 struct wpa_supplicant
*wpa_s
, char *addr
)
2090 if (hwaddr_aton(addr
, peer
)) {
2091 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
2092 "address '%s'", addr
);
2096 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
2099 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
2101 #endif /* CONFIG_IBSS_RSN */
2104 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
2107 #ifdef IEEE8021X_EAPOL
2110 struct wpa_ssid
*ssid
;
2112 pos
= os_strchr(rsp
, '-');
2117 pos
= os_strchr(pos
, ':');
2122 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
2123 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2124 (u8
*) pos
, os_strlen(pos
));
2126 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2128 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2133 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
2135 #else /* IEEE8021X_EAPOL */
2136 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
2138 #endif /* IEEE8021X_EAPOL */
2142 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
2144 char *buf
, size_t buflen
)
2146 char *pos
, *end
, tmp
[30];
2147 int res
, verbose
, wps
, ret
;
2150 #endif /* CONFIG_HS20 */
2154 if (os_strcmp(params
, "-DRIVER") == 0)
2155 return wpa_drv_status(wpa_s
, buf
, buflen
);
2156 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
2157 wps
= os_strcmp(params
, "-WPS") == 0;
2160 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
2161 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2162 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2163 MAC2STR(wpa_s
->bssid
));
2164 if (os_snprintf_error(end
- pos
, ret
))
2167 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2169 if (os_snprintf_error(end
- pos
, ret
))
2173 u8
*_ssid
= ssid
->ssid
;
2174 size_t ssid_len
= ssid
->ssid_len
;
2175 u8 ssid_buf
[SSID_MAX_LEN
];
2176 if (ssid_len
== 0) {
2177 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2184 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2185 wpa_ssid_txt(_ssid
, ssid_len
),
2187 if (os_snprintf_error(end
- pos
, ret
))
2191 if (wps
&& ssid
->passphrase
&&
2192 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2193 (ssid
->mode
== WPAS_MODE_AP
||
2194 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2195 ret
= os_snprintf(pos
, end
- pos
,
2198 if (os_snprintf_error(end
- pos
, ret
))
2203 ret
= os_snprintf(pos
, end
- pos
,
2206 if (os_snprintf_error(end
- pos
, ret
))
2211 switch (ssid
->mode
) {
2212 case WPAS_MODE_INFRA
:
2213 ret
= os_snprintf(pos
, end
- pos
,
2216 case WPAS_MODE_IBSS
:
2217 ret
= os_snprintf(pos
, end
- pos
,
2221 ret
= os_snprintf(pos
, end
- pos
,
2224 case WPAS_MODE_P2P_GO
:
2225 ret
= os_snprintf(pos
, end
- pos
,
2228 case WPAS_MODE_P2P_GROUP_FORMATION
:
2229 ret
= os_snprintf(pos
, end
- pos
,
2230 "mode=P2P GO - group "
2233 case WPAS_MODE_MESH
:
2234 ret
= os_snprintf(pos
, end
- pos
,
2241 if (os_snprintf_error(end
- pos
, ret
))
2246 if (wpa_s
->connection_set
&&
2247 (wpa_s
->connection_ht
|| wpa_s
->connection_vht
||
2248 wpa_s
->connection_he
)) {
2249 ret
= os_snprintf(pos
, end
- pos
,
2250 "wifi_generation=%u\n",
2251 wpa_s
->connection_he
? 6 :
2252 (wpa_s
->connection_vht
? 5 : 4));
2253 if (os_snprintf_error(end
- pos
, ret
))
2259 if (wpa_s
->ap_iface
) {
2260 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2264 #endif /* CONFIG_AP */
2265 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2269 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2272 #endif /* CONFIG_AP */
2273 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2274 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2275 wpa_s
->sme
.sae
.group
);
2276 if (os_snprintf_error(end
- pos
, ret
))
2280 #endif /* CONFIG_SAE */
2281 #endif /* CONFIG_SME */
2282 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2283 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2284 if (os_snprintf_error(end
- pos
, ret
))
2289 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2290 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2291 if (os_snprintf_error(end
- pos
, ret
))
2297 if (wpa_s
->global
->p2p
) {
2298 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2299 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2300 if (os_snprintf_error(end
- pos
, ret
))
2304 #endif /* CONFIG_P2P */
2306 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2307 MAC2STR(wpa_s
->own_addr
));
2308 if (os_snprintf_error(end
- pos
, ret
))
2313 if (wpa_s
->current_bss
&&
2314 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2315 HS20_IE_VENDOR_TYPE
)) &&
2316 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2317 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2320 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2321 release
= rel_num
+ 1;
2323 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2324 if (os_snprintf_error(end
- pos
, ret
))
2329 if (wpa_s
->current_ssid
) {
2330 struct wpa_cred
*cred
;
2333 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2336 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2339 if (cred
->provisioning_sp
) {
2340 ret
= os_snprintf(pos
, end
- pos
,
2341 "provisioning_sp=%s\n",
2342 cred
->provisioning_sp
);
2343 if (os_snprintf_error(end
- pos
, ret
))
2352 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2353 struct wpabuf
*names
=
2354 wpa_s
->current_bss
->anqp
->domain_name
;
2355 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2357 if (domain_name_list_contains(
2358 names
, cred
->domain
[i
], 1))
2361 if (i
== cred
->num_domain
)
2362 i
= 0; /* show first entry by default */
2364 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2366 if (os_snprintf_error(end
- pos
, ret
))
2371 if (wpa_s
->current_bss
== NULL
||
2372 wpa_s
->current_bss
->anqp
== NULL
)
2375 res
= interworking_home_sp_cred(
2377 wpa_s
->current_bss
->anqp
->domain_name
);
2385 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2386 if (os_snprintf_error(end
- pos
, ret
))
2393 #endif /* CONFIG_HS20 */
2395 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2396 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2397 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2403 #ifdef CONFIG_MACSEC
2404 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2407 #endif /* CONFIG_MACSEC */
2409 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2413 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2414 if (os_snprintf_error(end
- pos
, ret
))
2417 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2421 ret
= os_snprintf(pos
, end
- pos
, "\n");
2422 if (os_snprintf_error(end
- pos
, ret
))
2427 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2434 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2435 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2436 if (os_snprintf_error(end
- pos
, ret
))
2440 #endif /* CONFIG_WPS */
2442 if (wpa_s
->ieee80211ac
) {
2443 ret
= os_snprintf(pos
, end
- pos
, "ieee80211ac=1\n");
2444 if (os_snprintf_error(end
- pos
, ret
))
2451 * Allow using the STATUS command with default behavior, say for debug,
2452 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2453 * events with STATUS-NO_EVENTS.
2455 if (os_strcmp(params
, "-NO_EVENTS")) {
2456 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2457 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2458 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2460 MAC2STR(wpa_s
->bssid
),
2461 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2462 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2463 wpa_s
->current_ssid
->ssid_len
) : "");
2464 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2465 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2466 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2467 "- connection to " MACSTR
2468 " completed %s [id=%d id_str=%s]",
2469 MAC2STR(wpa_s
->bssid
), "(auth)",
2470 ssid
? ssid
->id
: -1,
2471 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2474 #endif /* ANDROID */
2480 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2485 struct wpa_ssid
*ssid
;
2488 /* cmd: "<network id> <BSSID>" */
2489 pos
= os_strchr(cmd
, ' ');
2494 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2495 if (hwaddr_aton(pos
, bssid
)) {
2496 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2500 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2502 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2507 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2508 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2514 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2515 char *cmd
, char *buf
,
2519 struct wpa_blacklist
*e
;
2523 /* cmd: "BLACKLIST [<BSSID>]" */
2527 e
= wpa_s
->blacklist
;
2529 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2531 if (os_snprintf_error(end
- pos
, ret
))
2540 if (os_strncmp(cmd
, "clear", 5) == 0) {
2541 wpa_blacklist_clear(wpa_s
);
2542 os_memcpy(buf
, "OK\n", 3);
2546 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2547 if (hwaddr_aton(cmd
, bssid
)) {
2548 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2553 * Add the BSSID twice, so its count will be 2, causing it to be
2554 * skipped when processing scan results.
2556 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2559 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2562 os_memcpy(buf
, "OK\n", 3);
2567 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2568 char *cmd
, char *buf
,
2571 char *pos
, *end
, *stamp
;
2574 /* cmd: "LOG_LEVEL [<level>]" */
2578 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2580 debug_level_str(wpa_debug_level
),
2581 wpa_debug_timestamp
);
2582 if (os_snprintf_error(end
- pos
, ret
))
2591 stamp
= os_strchr(cmd
, ' ');
2594 while (*stamp
== ' ') {
2599 if (os_strlen(cmd
)) {
2600 int level
= str_to_debug_level(cmd
);
2603 wpa_debug_level
= level
;
2606 if (stamp
&& os_strlen(stamp
))
2607 wpa_debug_timestamp
= atoi(stamp
);
2609 os_memcpy(buf
, "OK\n", 3);
2614 static int wpa_supplicant_ctrl_iface_list_networks(
2615 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2617 char *pos
, *end
, *prev
;
2618 struct wpa_ssid
*ssid
;
2623 ret
= os_snprintf(pos
, end
- pos
,
2624 "network id / ssid / bssid / flags\n");
2625 if (os_snprintf_error(end
- pos
, ret
))
2629 ssid
= wpa_s
->conf
->ssid
;
2631 /* skip over ssids until we find next one */
2632 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2633 int last_id
= atoi(cmd
+ 8);
2634 if (last_id
!= -1) {
2635 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2643 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2645 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2646 if (os_snprintf_error(end
- pos
, ret
))
2649 if (ssid
->bssid_set
) {
2650 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2651 MAC2STR(ssid
->bssid
));
2653 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2655 if (os_snprintf_error(end
- pos
, ret
))
2658 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2659 ssid
== wpa_s
->current_ssid
?
2661 ssid
->disabled
? "[DISABLED]" : "",
2662 ssid
->disabled_until
.sec
?
2663 "[TEMP-DISABLED]" : "",
2664 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2666 if (os_snprintf_error(end
- pos
, ret
))
2669 ret
= os_snprintf(pos
, end
- pos
, "\n");
2670 if (os_snprintf_error(end
- pos
, ret
))
2681 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2684 ret
= os_snprintf(pos
, end
- pos
, "-");
2685 if (os_snprintf_error(end
- pos
, ret
))
2688 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2696 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2697 const u8
*ie
, size_t ie_len
)
2699 struct wpa_ie_data data
;
2703 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2704 if (os_snprintf_error(end
- pos
, ret
))
2708 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2709 ret
= os_snprintf(pos
, end
- pos
, "?]");
2710 if (os_snprintf_error(end
- pos
, ret
))
2717 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2718 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2719 pos
== start
? "" : "+");
2720 if (os_snprintf_error(end
- pos
, ret
))
2724 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2725 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2726 pos
== start
? "" : "+");
2727 if (os_snprintf_error(end
- pos
, ret
))
2731 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2732 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2733 pos
== start
? "" : "+");
2734 if (os_snprintf_error(end
- pos
, ret
))
2738 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2739 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2740 pos
== start
? "" : "+");
2741 if (os_snprintf_error(end
- pos
, ret
))
2745 #ifdef CONFIG_IEEE80211R
2746 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2747 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2748 pos
== start
? "" : "+");
2749 if (os_snprintf_error(end
- pos
, ret
))
2753 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2754 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2755 pos
== start
? "" : "+");
2756 if (os_snprintf_error(end
- pos
, ret
))
2760 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2761 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2762 pos
== start
? "" : "+");
2763 if (os_snprintf_error(end
- pos
, ret
))
2767 #endif /* CONFIG_IEEE80211R */
2768 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2769 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2770 pos
== start
? "" : "+");
2771 if (os_snprintf_error(end
- pos
, ret
))
2775 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2776 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2777 pos
== start
? "" : "+");
2778 if (os_snprintf_error(end
- pos
, ret
))
2783 #ifdef CONFIG_SUITEB
2784 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2785 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2786 pos
== start
? "" : "+");
2787 if (os_snprintf_error(end
- pos
, ret
))
2791 #endif /* CONFIG_SUITEB */
2793 #ifdef CONFIG_SUITEB192
2794 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2795 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2796 pos
== start
? "" : "+");
2797 if (os_snprintf_error(end
- pos
, ret
))
2801 #endif /* CONFIG_SUITEB192 */
2804 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2805 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2806 pos
== start
? "" : "+");
2807 if (os_snprintf_error(end
- pos
, ret
))
2811 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2812 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2813 pos
== start
? "" : "+");
2814 if (os_snprintf_error(end
- pos
, ret
))
2818 #ifdef CONFIG_IEEE80211R
2819 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2820 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2821 pos
== start
? "" : "+");
2822 if (os_snprintf_error(end
- pos
, ret
))
2826 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2827 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2828 pos
== start
? "" : "+");
2829 if (os_snprintf_error(end
- pos
, ret
))
2833 #endif /* CONFIG_IEEE80211R */
2834 #endif /* CONFIG_FILS */
2837 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2838 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2839 pos
== start
? "" : "+");
2840 if (os_snprintf_error(end
- pos
, ret
))
2844 #endif /* CONFIG_OWE */
2847 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2848 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2849 pos
== start
? "" : "+");
2850 if (os_snprintf_error(end
- pos
, ret
))
2854 #endif /* CONFIG_DPP */
2856 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2857 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2858 pos
== start
? "" : "+");
2859 if (os_snprintf_error(end
- pos
, ret
))
2864 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2866 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2867 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2868 if (os_snprintf_error(end
- pos
, ret
))
2873 ret
= os_snprintf(pos
, end
- pos
, "]");
2874 if (os_snprintf_error(end
- pos
, ret
))
2883 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2884 char *pos
, char *end
,
2885 struct wpabuf
*wps_ie
)
2892 if (wps_is_selected_pbc_registrar(wps_ie
))
2894 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2896 else if (wps_is_selected_pin_registrar(wps_ie
))
2901 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2902 if (!os_snprintf_error(end
- pos
, ret
))
2904 wpabuf_free(wps_ie
);
2907 #endif /* CONFIG_WPS */
2910 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2911 char *pos
, char *end
,
2912 const struct wpa_bss
*bss
)
2915 struct wpabuf
*wps_ie
;
2916 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2917 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2918 #else /* CONFIG_WPS */
2920 #endif /* CONFIG_WPS */
2924 /* Format one result on one text line into a buffer. */
2925 static int wpa_supplicant_ctrl_iface_scan_result(
2926 struct wpa_supplicant
*wpa_s
,
2927 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2931 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
, *owe
;
2933 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2934 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2936 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2937 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2938 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2940 return 0; /* Do not show P2P listen discovery results here */
2945 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2946 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2947 if (os_snprintf_error(end
- pos
, ret
))
2950 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2952 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2953 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2955 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2958 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2960 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2961 osen_ie
, 2 + osen_ie
[1]);
2962 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
2964 ret
= os_snprintf(pos
, end
- pos
,
2965 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2966 if (os_snprintf_error(end
- pos
, ret
))
2970 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2971 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2972 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2973 if (os_snprintf_error(end
- pos
, ret
))
2978 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2979 if (os_snprintf_error(end
- pos
, ret
))
2983 if (bss_is_dmg(bss
)) {
2986 if (get_ie_ext((const u8
*) (bss
+ 1), bss
->ie_len
,
2987 WLAN_EID_EXT_EDMG_OPERATION
)) {
2988 ret
= os_snprintf(pos
, end
- pos
, "[EDMG]");
2989 if (os_snprintf_error(end
- pos
, ret
))
2994 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2995 if (os_snprintf_error(end
- pos
, ret
))
2998 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2999 case IEEE80211_CAP_DMG_IBSS
:
3002 case IEEE80211_CAP_DMG_AP
:
3005 case IEEE80211_CAP_DMG_PBSS
:
3012 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
3013 if (os_snprintf_error(end
- pos
, ret
))
3017 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3018 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3019 if (os_snprintf_error(end
- pos
, ret
))
3023 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3024 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3025 if (os_snprintf_error(end
- pos
, ret
))
3031 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3032 if (os_snprintf_error(end
- pos
, ret
))
3037 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
3038 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3039 if (os_snprintf_error(end
- pos
, ret
))
3043 #endif /* CONFIG_HS20 */
3045 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
3046 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
3047 if (os_snprintf_error(end
- pos
, ret
))
3051 #endif /* CONFIG_FILS */
3053 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
3054 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
3055 if (os_snprintf_error(end
- pos
, ret
))
3059 #endif /* CONFIG_FST */
3060 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
3061 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
3062 if (os_snprintf_error(end
- pos
, ret
))
3067 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
3068 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3069 if (os_snprintf_error(end
- pos
, ret
))
3073 ret
= os_snprintf(pos
, end
- pos
, "\n");
3074 if (os_snprintf_error(end
- pos
, ret
))
3082 static int wpa_supplicant_ctrl_iface_scan_results(
3083 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3086 struct wpa_bss
*bss
;
3091 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
3093 if (os_snprintf_error(end
- pos
, ret
))
3097 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
3098 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
3100 if (ret
< 0 || ret
>= end
- pos
)
3111 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3112 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
3114 char *pos
, ifname
[IFNAMSIZ
+ 1];
3118 pos
= os_strstr(cmd
, "ifname=");
3121 os_strlcpy(ifname
, pos
, sizeof(ifname
));
3124 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
3127 os_strlcpy(reply
, ifname
, max_len
);
3128 return os_strlen(ifname
);
3132 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3133 struct wpa_supplicant
*wpa_s
, char *cmd
)
3136 struct wpa_ssid
*ssid
;
3139 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
3141 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3143 wpa_printf(MSG_DEBUG
,
3144 "CTRL_IFACE: Could not find network id=%d", id
);
3147 if (ssid
->mode
!= WPAS_MODE_MESH
) {
3148 wpa_printf(MSG_DEBUG
,
3149 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3152 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3153 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
3154 wpa_printf(MSG_ERROR
,
3155 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3160 * TODO: If necessary write our own group_add function,
3161 * for now we can reuse select_network
3163 wpa_supplicant_select_network(wpa_s
, ssid
);
3169 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3170 struct wpa_supplicant
*wpa_s
, char *cmd
)
3172 struct wpa_supplicant
*orig
;
3173 struct wpa_global
*global
;
3176 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
3178 global
= wpa_s
->global
;
3181 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3182 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
3188 wpa_printf(MSG_ERROR
,
3189 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3193 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
3194 wpa_printf(MSG_ERROR
,
3195 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3199 wpa_s
->reassociate
= 0;
3200 wpa_s
->disconnected
= 1;
3201 wpa_supplicant_cancel_sched_scan(wpa_s
);
3202 wpa_supplicant_cancel_scan(wpa_s
);
3205 * TODO: If necessary write our own group_remove function,
3206 * for now we can reuse deauthenticate
3208 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3210 if (wpa_s
->mesh_if_created
)
3211 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3217 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3218 struct wpa_supplicant
*wpa_s
, char *cmd
)
3222 if (hwaddr_aton(cmd
, addr
) < 0)
3225 return wpas_mesh_peer_remove(wpa_s
, addr
);
3229 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3230 struct wpa_supplicant
*wpa_s
, char *cmd
)
3236 pos
= os_strstr(cmd
, " duration=");
3239 duration
= atoi(pos
+ 10);
3244 if (hwaddr_aton(cmd
, addr
))
3247 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3251 static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3252 struct wpa_supplicant
*wpa_s
, char *cmd
)
3254 struct ether_header
*eth
;
3258 size_t payload_len
= 0, len
;
3261 if (hwaddr_aton(cmd
, addr
))
3264 pos
= os_strstr(cmd
, " payload=");
3267 payload_len
= os_strlen(pos
);
3268 if (payload_len
& 1)
3274 len
= ETH_HLEN
+ payload_len
;
3275 buf
= os_malloc(len
);
3279 eth
= (struct ether_header
*) buf
;
3280 os_memcpy(eth
->ether_dhost
, addr
, ETH_ALEN
);
3281 os_memcpy(eth
->ether_shost
, wpa_s
->own_addr
, ETH_ALEN
);
3282 eth
->ether_type
= htons(ETH_P_802_3
);
3284 if (payload_len
&& hexstr2bin(pos
, buf
+ ETH_HLEN
, payload_len
) < 0)
3287 ret
= wpa_drv_mesh_link_probe(wpa_s
, addr
, buf
, len
);
3293 #endif /* CONFIG_MESH */
3296 static int wpa_supplicant_ctrl_iface_select_network(
3297 struct wpa_supplicant
*wpa_s
, char *cmd
)
3300 struct wpa_ssid
*ssid
;
3303 /* cmd: "<network id>" or "any" */
3304 if (os_strncmp(cmd
, "any", 3) == 0) {
3305 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3309 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3311 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3313 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3314 "network id=%d", id
);
3317 if (ssid
->disabled
== 2) {
3318 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3319 "SELECT_NETWORK with persistent P2P group");
3324 pos
= os_strstr(cmd
, " freq=");
3326 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3328 os_free(wpa_s
->select_network_scan_freqs
);
3329 wpa_s
->select_network_scan_freqs
= freqs
;
3333 wpa_s
->scan_min_time
.sec
= 0;
3334 wpa_s
->scan_min_time
.usec
= 0;
3335 wpa_supplicant_select_network(wpa_s
, ssid
);
3341 static int wpa_supplicant_ctrl_iface_enable_network(
3342 struct wpa_supplicant
*wpa_s
, char *cmd
)
3345 struct wpa_ssid
*ssid
;
3347 /* cmd: "<network id>" or "all" */
3348 if (os_strcmp(cmd
, "all") == 0) {
3349 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3353 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3355 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3357 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3358 "network id=%d", id
);
3361 if (ssid
->disabled
== 2) {
3362 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3363 "ENABLE_NETWORK with persistent P2P group");
3367 if (os_strstr(cmd
, " no-connect")) {
3372 wpa_s
->scan_min_time
.sec
= 0;
3373 wpa_s
->scan_min_time
.usec
= 0;
3374 wpa_supplicant_enable_network(wpa_s
, ssid
);
3380 static int wpa_supplicant_ctrl_iface_disable_network(
3381 struct wpa_supplicant
*wpa_s
, char *cmd
)
3384 struct wpa_ssid
*ssid
;
3386 /* cmd: "<network id>" or "all" */
3387 if (os_strcmp(cmd
, "all") == 0) {
3388 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3392 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3394 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3396 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3397 "network id=%d", id
);
3400 if (ssid
->disabled
== 2) {
3401 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3402 "DISABLE_NETWORK with persistent P2P "
3407 wpa_supplicant_disable_network(wpa_s
, ssid
);
3413 static int wpa_supplicant_ctrl_iface_add_network(
3414 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3416 struct wpa_ssid
*ssid
;
3419 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3421 ssid
= wpa_supplicant_add_network(wpa_s
);
3425 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3426 if (os_snprintf_error(buflen
, ret
))
3432 static int wpa_supplicant_ctrl_iface_remove_network(
3433 struct wpa_supplicant
*wpa_s
, char *cmd
)
3436 struct wpa_ssid
*ssid
;
3439 /* cmd: "<network id>" or "all" */
3440 if (os_strcmp(cmd
, "all") == 0) {
3441 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3442 if (wpa_s
->sched_scanning
)
3443 wpa_supplicant_cancel_sched_scan(wpa_s
);
3445 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3446 if (wpa_s
->current_ssid
) {
3448 wpa_s
->sme
.prev_bssid_set
= 0;
3449 #endif /* CONFIG_SME */
3450 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3451 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3452 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3453 wpa_s
->own_disconnect_req
= 1;
3454 wpa_supplicant_deauthenticate(
3455 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3457 ssid
= wpa_s
->conf
->ssid
;
3459 struct wpa_ssid
*remove_ssid
= ssid
;
3462 if (wpa_s
->last_ssid
== remove_ssid
)
3463 wpa_s
->last_ssid
= NULL
;
3464 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3465 wpa_config_remove_network(wpa_s
->conf
, id
);
3471 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3473 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3475 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3480 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3481 "network id=%d", id
);
3488 static int wpa_supplicant_ctrl_iface_update_network(
3489 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3490 char *name
, char *value
)
3494 ret
= wpa_config_set(ssid
, name
, value
, 0);
3496 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3497 "variable '%s'", name
);
3501 return 0; /* No change to the previously configured value */
3503 if (os_strcmp(name
, "bssid") != 0 &&
3504 os_strcmp(name
, "bssid_hint") != 0 &&
3505 os_strcmp(name
, "priority") != 0) {
3506 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3508 if (wpa_s
->current_ssid
== ssid
||
3509 wpa_s
->current_ssid
== NULL
) {
3511 * Invalidate the EAP session cache if anything in the
3512 * current or previously used configuration changes.
3514 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3518 if ((os_strcmp(name
, "psk") == 0 &&
3519 value
[0] == '"' && ssid
->ssid_len
) ||
3520 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3521 wpa_config_update_psk(ssid
);
3522 else if (os_strcmp(name
, "priority") == 0)
3523 wpa_config_update_prio_list(wpa_s
->conf
);
3529 static int wpa_supplicant_ctrl_iface_set_network(
3530 struct wpa_supplicant
*wpa_s
, char *cmd
)
3532 int id
, ret
, prev_bssid_set
, prev_disabled
;
3533 struct wpa_ssid
*ssid
;
3535 u8 prev_bssid
[ETH_ALEN
];
3537 /* cmd: "<network id> <variable name> <value>" */
3538 name
= os_strchr(cmd
, ' ');
3543 value
= os_strchr(name
, ' ');
3549 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3551 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3552 (u8
*) value
, os_strlen(value
));
3554 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3556 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3561 prev_bssid_set
= ssid
->bssid_set
;
3562 prev_disabled
= ssid
->disabled
;
3563 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3564 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3567 (ssid
->bssid_set
!= prev_bssid_set
||
3568 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3569 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3571 if (prev_disabled
!= ssid
->disabled
&&
3572 (prev_disabled
== 2 || ssid
->disabled
== 2))
3573 wpas_notify_network_type_changed(wpa_s
, ssid
);
3579 static int wpa_supplicant_ctrl_iface_get_network(
3580 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3584 struct wpa_ssid
*ssid
;
3587 /* cmd: "<network id> <variable name>" */
3588 name
= os_strchr(cmd
, ' ');
3589 if (name
== NULL
|| buflen
== 0)
3594 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3597 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3599 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3604 value
= wpa_config_get_no_key(ssid
, name
);
3605 if (value
== NULL
) {
3606 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3607 "variable '%s'", name
);
3611 res
= os_strlcpy(buf
, value
, buflen
);
3612 if (res
>= buflen
) {
3623 static int wpa_supplicant_ctrl_iface_dup_network(
3624 struct wpa_supplicant
*wpa_s
, char *cmd
,
3625 struct wpa_supplicant
*dst_wpa_s
)
3627 struct wpa_ssid
*ssid_s
, *ssid_d
;
3628 char *name
, *id
, *value
;
3629 int id_s
, id_d
, ret
;
3631 /* cmd: "<src network id> <dst network id> <variable name>" */
3632 id
= os_strchr(cmd
, ' ');
3637 name
= os_strchr(id
, ' ');
3645 wpa_printf(MSG_DEBUG
,
3646 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3647 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3649 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3650 if (ssid_s
== NULL
) {
3651 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3652 "network id=%d", id_s
);
3656 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3657 if (ssid_d
== NULL
) {
3658 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3659 "network id=%d", id_d
);
3663 value
= wpa_config_get(ssid_s
, name
);
3664 if (value
== NULL
) {
3665 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3666 "variable '%s'", name
);
3670 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3679 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3680 char *buf
, size_t buflen
)
3683 struct wpa_cred
*cred
;
3688 ret
= os_snprintf(pos
, end
- pos
,
3689 "cred id / realm / username / domain / imsi\n");
3690 if (os_snprintf_error(end
- pos
, ret
))
3694 cred
= wpa_s
->conf
->cred
;
3696 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3697 cred
->id
, cred
->realm
? cred
->realm
: "",
3698 cred
->username
? cred
->username
: "",
3699 cred
->domain
? cred
->domain
[0] : "",
3700 cred
->imsi
? cred
->imsi
: "");
3701 if (os_snprintf_error(end
- pos
, ret
))
3712 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3713 char *buf
, size_t buflen
)
3715 struct wpa_cred
*cred
;
3718 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3720 cred
= wpa_config_add_cred(wpa_s
->conf
);
3724 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3726 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3727 if (os_snprintf_error(buflen
, ret
))
3733 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3734 struct wpa_cred
*cred
)
3736 struct wpa_ssid
*ssid
;
3741 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3746 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3747 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3751 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3753 /* Remove any network entry created based on the removed credential */
3754 ssid
= wpa_s
->conf
->ssid
;
3756 if (ssid
->parent_cred
== cred
) {
3759 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3760 "used the removed credential", ssid
->id
);
3761 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3762 if (os_snprintf_error(sizeof(str
), res
))
3763 str
[sizeof(str
) - 1] = '\0';
3765 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3774 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3778 struct wpa_cred
*cred
, *prev
;
3780 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3781 * "provisioning_sp=<FQDN> */
3782 if (os_strcmp(cmd
, "all") == 0) {
3783 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3784 cred
= wpa_s
->conf
->cred
;
3788 wpas_ctrl_remove_cred(wpa_s
, prev
);
3793 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3794 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3796 cred
= wpa_s
->conf
->cred
;
3802 for (i
= 0; i
< prev
->num_domain
; i
++) {
3803 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3806 wpas_ctrl_remove_cred(wpa_s
, prev
);
3814 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3815 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3817 cred
= wpa_s
->conf
->cred
;
3821 if (prev
->provisioning_sp
&&
3822 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3823 wpas_ctrl_remove_cred(wpa_s
, prev
);
3829 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3831 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3832 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3836 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3840 struct wpa_cred
*cred
;
3843 /* cmd: "<cred id> <variable name> <value>" */
3844 name
= os_strchr(cmd
, ' ');
3849 value
= os_strchr(name
, ' ');
3855 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3857 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3858 (u8
*) value
, os_strlen(value
));
3860 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3862 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3867 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3868 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3869 "variable '%s'", name
);
3873 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3879 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3880 char *cmd
, char *buf
,
3885 struct wpa_cred
*cred
;
3888 /* cmd: "<cred id> <variable name>" */
3889 name
= os_strchr(cmd
, ' ');
3895 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3898 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3900 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3905 value
= wpa_config_get_cred_no_key(cred
, name
);
3906 if (value
== NULL
) {
3907 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3912 res
= os_strlcpy(buf
, value
, buflen
);
3913 if (res
>= buflen
) {
3924 #ifndef CONFIG_NO_CONFIG_WRITE
3925 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3929 if (!wpa_s
->conf
->update_config
) {
3930 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3931 "to update configuration (update_config=0)");
3935 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3937 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3938 "update configuration");
3940 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3946 #endif /* CONFIG_NO_CONFIG_WRITE */
3949 struct cipher_info
{
3955 static const struct cipher_info ciphers
[] = {
3956 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3957 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3958 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3959 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3960 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3961 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3963 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3964 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3965 #endif /* CONFIG_WEP */
3968 static const struct cipher_info ciphers_group_mgmt
[] = {
3969 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3970 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3971 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3972 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3976 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3977 struct wpa_driver_capa
*capa
,
3978 char *buf
, size_t buflen
)
3991 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3997 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3998 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3999 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4000 pos
== buf
? "" : " ",
4002 if (os_snprintf_error(end
- pos
, ret
))
4012 static int ctrl_iface_get_capability_group(int res
, char *strict
,
4013 struct wpa_driver_capa
*capa
,
4014 char *buf
, size_t buflen
)
4028 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
4029 #else /* CONFIG_WEP */
4030 len
= os_strlcpy(buf
, "CCMP TKIP", buflen
);
4031 #endif /* CONFIG_WEP */
4037 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
4038 if (capa
->enc
& ciphers
[i
].capa
) {
4039 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4040 pos
== buf
? "" : " ",
4042 if (os_snprintf_error(end
- pos
, ret
))
4052 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
4053 struct wpa_driver_capa
*capa
,
4054 char *buf
, size_t buflen
)
4066 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
4067 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
4068 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4069 pos
== buf
? "" : " ",
4070 ciphers_group_mgmt
[i
].name
);
4071 if (os_snprintf_error(end
- pos
, ret
))
4081 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
4082 struct wpa_driver_capa
*capa
,
4083 char *buf
, size_t buflen
)
4095 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4102 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
4103 if (os_snprintf_error(end
- pos
, ret
))
4107 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4108 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
4109 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
4110 if (os_snprintf_error(end
- pos
, ret
))
4115 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
4116 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4117 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
4118 if (os_snprintf_error(end
- pos
, ret
))
4123 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
4124 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
4125 if (os_snprintf_error(end
- pos
, ret
))
4130 #ifdef CONFIG_SUITEB
4131 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
4132 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
4133 if (os_snprintf_error(end
- pos
, ret
))
4137 #endif /* CONFIG_SUITEB */
4138 #ifdef CONFIG_SUITEB192
4139 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
4140 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
4141 if (os_snprintf_error(end
- pos
, ret
))
4145 #endif /* CONFIG_SUITEB192 */
4147 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
4148 ret
= os_snprintf(pos
, end
- pos
, " OWE");
4149 if (os_snprintf_error(end
- pos
, ret
))
4153 #endif /* CONFIG_OWE */
4155 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
4156 ret
= os_snprintf(pos
, end
- pos
, " DPP");
4157 if (os_snprintf_error(end
- pos
, ret
))
4161 #endif /* CONFIG_DPP */
4163 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
4164 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
4165 if (os_snprintf_error(end
- pos
, ret
))
4169 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
4170 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
4171 if (os_snprintf_error(end
- pos
, ret
))
4175 #ifdef CONFIG_IEEE80211R
4176 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
4177 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
4178 if (os_snprintf_error(end
- pos
, ret
))
4182 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
4183 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
4184 if (os_snprintf_error(end
- pos
, ret
))
4188 #endif /* CONFIG_IEEE80211R */
4189 #endif /* CONFIG_FILS */
4190 #ifdef CONFIG_IEEE80211R
4191 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
) {
4192 ret
= os_snprintf(pos
, end
- pos
, " FT-PSK");
4193 if (os_snprintf_error(end
- pos
, ret
))
4197 #endif /* CONFIG_IEEE80211R */
4199 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SAE
) {
4200 ret
= os_snprintf(pos
, end
- pos
, " SAE");
4201 if (os_snprintf_error(end
- pos
, ret
))
4205 #endif /* CONFIG_SAE */
4211 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
4212 struct wpa_driver_capa
*capa
,
4213 char *buf
, size_t buflen
)
4225 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
4231 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
4232 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4233 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
4234 pos
== buf
? "" : " ");
4235 if (os_snprintf_error(end
- pos
, ret
))
4240 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4241 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
4242 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
4243 pos
== buf
? "" : " ");
4244 if (os_snprintf_error(end
- pos
, ret
))
4253 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
4254 int res
, char *strict
,
4255 struct wpa_driver_capa
*capa
,
4256 char *buf
, size_t buflen
)
4268 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4274 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4275 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4276 pos
== buf
? "" : " ");
4277 if (os_snprintf_error(end
- pos
, ret
))
4282 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4283 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4284 pos
== buf
? "" : " ");
4285 if (os_snprintf_error(end
- pos
, ret
))
4290 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4291 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4292 pos
== buf
? "" : " ");
4293 if (os_snprintf_error(end
- pos
, ret
))
4299 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4300 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4301 pos
== buf
? "" : " ");
4302 if (os_snprintf_error(end
- pos
, ret
))
4306 #endif /* CONFIG_SAE */
4309 if (wpa_is_fils_supported(wpa_s
)) {
4310 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4311 pos
== buf
? "" : " ");
4312 if (os_snprintf_error(end
- pos
, ret
))
4317 #ifdef CONFIG_FILS_SK_PFS
4318 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4319 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4320 pos
== buf
? "" : " ");
4321 if (os_snprintf_error(end
- pos
, ret
))
4325 #endif /* CONFIG_FILS_SK_PFS */
4326 #endif /* CONFIG_FILS */
4332 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4333 struct wpa_driver_capa
*capa
,
4334 char *buf
, size_t buflen
)
4346 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4352 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4353 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4354 pos
== buf
? "" : " ");
4355 if (os_snprintf_error(end
- pos
, ret
))
4360 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4361 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4362 pos
== buf
? "" : " ");
4363 if (os_snprintf_error(end
- pos
, ret
))
4369 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4370 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4371 pos
== buf
? "" : " ");
4372 if (os_snprintf_error(end
- pos
, ret
))
4376 #endif /* CONFIG_MESH */
4382 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4383 char *buf
, size_t buflen
)
4385 struct hostapd_channel_data
*chnl
;
4387 char *pos
, *end
, *hmode
;
4392 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4393 switch (wpa_s
->hw
.modes
[j
].mode
) {
4394 case HOSTAPD_MODE_IEEE80211B
:
4397 case HOSTAPD_MODE_IEEE80211G
:
4400 case HOSTAPD_MODE_IEEE80211A
:
4403 case HOSTAPD_MODE_IEEE80211AD
:
4409 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4410 if (os_snprintf_error(end
- pos
, ret
))
4413 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4414 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4415 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4417 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4418 if (os_snprintf_error(end
- pos
, ret
))
4422 ret
= os_snprintf(pos
, end
- pos
, "\n");
4423 if (os_snprintf_error(end
- pos
, ret
))
4432 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4433 char *buf
, size_t buflen
)
4435 struct hostapd_channel_data
*chnl
;
4437 char *pos
, *end
, *hmode
;
4442 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4443 switch (wpa_s
->hw
.modes
[j
].mode
) {
4444 case HOSTAPD_MODE_IEEE80211B
:
4447 case HOSTAPD_MODE_IEEE80211G
:
4450 case HOSTAPD_MODE_IEEE80211A
:
4453 case HOSTAPD_MODE_IEEE80211AD
:
4459 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4461 if (os_snprintf_error(end
- pos
, ret
))
4464 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4465 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4466 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4468 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4469 chnl
[i
].chan
, chnl
[i
].freq
,
4470 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4472 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4475 if (os_snprintf_error(end
- pos
, ret
))
4479 ret
= os_snprintf(pos
, end
- pos
, "\n");
4480 if (os_snprintf_error(end
- pos
, ret
))
4489 static int wpa_supplicant_ctrl_iface_get_capability(
4490 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4493 struct wpa_driver_capa capa
;
4499 /* Determine whether or not strict checking was requested */
4500 len
= os_strlcpy(field
, _field
, sizeof(field
));
4501 if (len
>= sizeof(field
))
4503 strict
= os_strchr(field
, ' ');
4504 if (strict
!= NULL
) {
4506 if (os_strcmp(strict
, "strict") != 0)
4510 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4511 field
, strict
? strict
: "");
4513 if (os_strcmp(field
, "eap") == 0) {
4514 return eap_get_names(buf
, buflen
);
4517 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4519 if (os_strcmp(field
, "pairwise") == 0)
4520 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4523 if (os_strcmp(field
, "group") == 0)
4524 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4527 if (os_strcmp(field
, "group_mgmt") == 0)
4528 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4531 if (os_strcmp(field
, "key_mgmt") == 0)
4532 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4535 if (os_strcmp(field
, "proto") == 0)
4536 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4539 if (os_strcmp(field
, "auth_alg") == 0)
4540 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4541 &capa
, buf
, buflen
);
4543 if (os_strcmp(field
, "modes") == 0)
4544 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4547 if (os_strcmp(field
, "channels") == 0)
4548 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4550 if (os_strcmp(field
, "freq") == 0)
4551 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4554 if (os_strcmp(field
, "tdls") == 0)
4555 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4556 #endif /* CONFIG_TDLS */
4559 if (os_strcmp(field
, "erp") == 0) {
4560 res
= os_snprintf(buf
, buflen
, "ERP");
4561 if (os_snprintf_error(buflen
, res
))
4565 #endif /* CONFIG_EPR */
4568 if (os_strcmp(field
, "fips") == 0) {
4569 res
= os_snprintf(buf
, buflen
, "FIPS");
4570 if (os_snprintf_error(buflen
, res
))
4574 #endif /* CONFIG_FIPS */
4577 if (os_strcmp(field
, "acs") == 0) {
4578 res
= os_snprintf(buf
, buflen
, "ACS");
4579 if (os_snprintf_error(buflen
, res
))
4583 #endif /* CONFIG_ACS */
4586 if (os_strcmp(field
, "fils") == 0) {
4587 #ifdef CONFIG_FILS_SK_PFS
4588 if (wpa_is_fils_supported(wpa_s
) &&
4589 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4590 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4591 if (os_snprintf_error(buflen
, res
))
4595 #endif /* CONFIG_FILS_SK_PFS */
4597 if (wpa_is_fils_supported(wpa_s
)) {
4598 res
= os_snprintf(buf
, buflen
, "FILS");
4599 if (os_snprintf_error(buflen
, res
))
4604 #endif /* CONFIG_FILS */
4606 if (os_strcmp(field
, "multibss") == 0 && wpa_s
->multi_bss_support
) {
4607 res
= os_snprintf(buf
, buflen
, "MULTIBSS-STA");
4608 if (os_snprintf_error(buflen
, res
))
4614 if (os_strcmp(field
, "dpp") == 0) {
4616 res
= os_snprintf(buf
, buflen
, "DPP=2");
4617 #else /* CONFIG_DPP2 */
4618 res
= os_snprintf(buf
, buflen
, "DPP=1");
4619 #endif /* CONFIG_DPP2 */
4620 if (os_snprintf_error(buflen
, res
))
4624 #endif /* CONFIG_DPP */
4626 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4633 #ifdef CONFIG_INTERWORKING
4634 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4635 struct wpabuf
*data
)
4645 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4646 if (os_snprintf_error(end
- pos
, ret
))
4650 d
= wpabuf_head_u8(data
);
4651 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4652 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4653 if (os_snprintf_error(end
- pos
, ret
))
4658 ret
= os_snprintf(pos
, end
- pos
, "\n");
4659 if (os_snprintf_error(end
- pos
, ret
))
4665 #endif /* CONFIG_INTERWORKING */
4669 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4672 const u8
*ie
, *ie_end
;
4676 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4679 ie_end
= ie
+ 2 + ie
[1];
4681 if (ie_end
- ie
< 2)
4684 info
= WPA_GET_LE16(ie
);
4686 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4687 if (os_snprintf_error(end
- pos
, ret
))
4691 if (info
& BIT(7)) {
4692 /* Cache Identifier Included */
4693 if (ie_end
- ie
< 2)
4695 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4697 if (os_snprintf_error(end
- pos
, ret
))
4703 if (info
& BIT(8)) {
4704 /* HESSID Included */
4705 if (ie_end
- ie
< ETH_ALEN
)
4707 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4709 if (os_snprintf_error(end
- pos
, ret
))
4715 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4717 if (ie_end
- ie
< realms
* 2)
4719 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4720 if (os_snprintf_error(end
- pos
, ret
))
4724 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4729 ret
= os_snprintf(pos
, end
- pos
, "\n");
4730 if (os_snprintf_error(end
- pos
, ret
))
4737 #endif /* CONFIG_FILS */
4740 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4741 unsigned long mask
, char *buf
, size_t buflen
)
4746 const u8
*ie
, *ie2
, *osen_ie
, *mesh
, *owe
;
4751 if (mask
& WPA_BSS_MASK_ID
) {
4752 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4753 if (os_snprintf_error(end
- pos
, ret
))
4758 if (mask
& WPA_BSS_MASK_BSSID
) {
4759 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4760 MAC2STR(bss
->bssid
));
4761 if (os_snprintf_error(end
- pos
, ret
))
4766 if (mask
& WPA_BSS_MASK_FREQ
) {
4767 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4768 if (os_snprintf_error(end
- pos
, ret
))
4773 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4774 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4776 if (os_snprintf_error(end
- pos
, ret
))
4781 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4782 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4784 if (os_snprintf_error(end
- pos
, ret
))
4789 if (mask
& WPA_BSS_MASK_QUAL
) {
4790 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4791 if (os_snprintf_error(end
- pos
, ret
))
4796 if (mask
& WPA_BSS_MASK_NOISE
) {
4797 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4798 if (os_snprintf_error(end
- pos
, ret
))
4803 if (mask
& WPA_BSS_MASK_LEVEL
) {
4804 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4805 if (os_snprintf_error(end
- pos
, ret
))
4810 if (mask
& WPA_BSS_MASK_TSF
) {
4811 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4812 (unsigned long long) bss
->tsf
);
4813 if (os_snprintf_error(end
- pos
, ret
))
4818 if (mask
& WPA_BSS_MASK_AGE
) {
4819 struct os_reltime now
;
4821 os_get_reltime(&now
);
4822 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4823 (int) (now
.sec
- bss
->last_update
.sec
));
4824 if (os_snprintf_error(end
- pos
, ret
))
4829 if (mask
& WPA_BSS_MASK_IE
) {
4830 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4831 if (os_snprintf_error(end
- pos
, ret
))
4835 ie
= (const u8
*) (bss
+ 1);
4836 for (i
= 0; i
< bss
->ie_len
; i
++) {
4837 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4838 if (os_snprintf_error(end
- pos
, ret
))
4843 ret
= os_snprintf(pos
, end
- pos
, "\n");
4844 if (os_snprintf_error(end
- pos
, ret
))
4849 if (mask
& WPA_BSS_MASK_FLAGS
) {
4850 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4851 if (os_snprintf_error(end
- pos
, ret
))
4855 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4857 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4859 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4861 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4863 pos
= wpa_supplicant_ie_txt(pos
, end
,
4864 mesh
? "RSN" : "WPA2", ie2
,
4866 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4868 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4869 osen_ie
, 2 + osen_ie
[1]);
4870 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
4874 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4875 if (os_snprintf_error(end
- pos
, ret
))
4879 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4880 if (!ie
&& !ie2
&& !osen_ie
&&
4881 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4882 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4883 if (os_snprintf_error(end
- pos
, ret
))
4889 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4890 if (os_snprintf_error(end
- pos
, ret
))
4895 if (bss_is_dmg(bss
)) {
4897 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4898 if (os_snprintf_error(end
- pos
, ret
))
4901 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4902 case IEEE80211_CAP_DMG_IBSS
:
4905 case IEEE80211_CAP_DMG_AP
:
4908 case IEEE80211_CAP_DMG_PBSS
:
4915 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4916 if (os_snprintf_error(end
- pos
, ret
))
4920 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4921 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4922 if (os_snprintf_error(end
- pos
, ret
))
4926 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4927 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4928 if (os_snprintf_error(end
- pos
, ret
))
4933 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4934 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4935 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4936 if (os_snprintf_error(end
- pos
, ret
))
4941 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4942 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4943 if (os_snprintf_error(end
- pos
, ret
))
4947 #endif /* CONFIG_HS20 */
4949 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4950 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4951 if (os_snprintf_error(end
- pos
, ret
))
4955 #endif /* CONFIG_FILS */
4957 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
4958 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
4959 if (os_snprintf_error(end
- pos
, ret
))
4963 #endif /* CONFIG_FST */
4964 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
4965 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
4966 if (os_snprintf_error(end
- pos
, ret
))
4971 ret
= os_snprintf(pos
, end
- pos
, "\n");
4972 if (os_snprintf_error(end
- pos
, ret
))
4977 if (mask
& WPA_BSS_MASK_SSID
) {
4978 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4979 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4980 if (os_snprintf_error(end
- pos
, ret
))
4986 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4987 ie
= (const u8
*) (bss
+ 1);
4988 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4989 if (ret
>= end
- pos
)
4994 #endif /* CONFIG_WPS */
4997 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4998 ie
= (const u8
*) (bss
+ 1);
4999 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
5000 if (ret
>= end
- pos
)
5005 #endif /* CONFIG_P2P */
5007 #ifdef CONFIG_WIFI_DISPLAY
5008 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
5010 ie
= (const u8
*) (bss
+ 1);
5011 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
5012 WFD_IE_VENDOR_TYPE
);
5014 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
5015 if (os_snprintf_error(end
- pos
, ret
)) {
5021 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
5026 ret
= os_snprintf(pos
, end
- pos
, "\n");
5027 if (os_snprintf_error(end
- pos
, ret
))
5032 #endif /* CONFIG_WIFI_DISPLAY */
5034 #ifdef CONFIG_INTERWORKING
5035 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
5036 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
5037 struct wpa_bss_anqp_elem
*elem
;
5039 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
5040 anqp
->capability_list
);
5041 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
5043 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
5044 anqp
->network_auth_type
);
5045 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
5046 anqp
->roaming_consortium
);
5047 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
5048 anqp
->ip_addr_type_availability
);
5049 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
5051 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
5052 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
5054 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
5055 anqp
->fils_realm_info
);
5057 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
5058 anqp
->hs20_capability_list
);
5059 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
5060 anqp
->hs20_operator_friendly_name
);
5061 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
5062 anqp
->hs20_wan_metrics
);
5063 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
5064 anqp
->hs20_connection_capability
);
5065 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
5066 anqp
->hs20_operating_class
);
5067 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
5068 anqp
->hs20_osu_providers_list
);
5069 pos
= anqp_add_hex(pos
, end
, "hs20_operator_icon_metadata",
5070 anqp
->hs20_operator_icon_metadata
);
5071 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_nai_list",
5072 anqp
->hs20_osu_providers_nai_list
);
5073 #endif /* CONFIG_HS20 */
5075 dl_list_for_each(elem
, &anqp
->anqp_elems
,
5076 struct wpa_bss_anqp_elem
, list
) {
5079 os_snprintf(title
, sizeof(title
), "anqp[%u]",
5081 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
5084 #endif /* CONFIG_INTERWORKING */
5087 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
5088 ie
= (const u8
*) (bss
+ 1);
5089 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
5090 if (ret
>= end
- pos
)
5095 #endif /* CONFIG_MESH */
5097 if (mask
& WPA_BSS_MASK_SNR
) {
5098 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
5099 if (os_snprintf_error(end
- pos
, ret
))
5104 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
5105 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
5106 bss
->est_throughput
);
5107 if (os_snprintf_error(end
- pos
, ret
))
5113 if (mask
& WPA_BSS_MASK_FST
) {
5114 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
5115 if (ret
< 0 || ret
>= end
- pos
)
5119 #endif /* CONFIG_FST */
5121 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
5122 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
5123 bss
->last_update_idx
);
5124 if (os_snprintf_error(end
- pos
, ret
))
5129 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
5130 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
5131 if (os_snprintf_error(end
- pos
, ret
))
5135 ie
= (const u8
*) (bss
+ 1);
5137 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
5138 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
5139 if (os_snprintf_error(end
- pos
, ret
))
5144 ret
= os_snprintf(pos
, end
- pos
, "\n");
5145 if (os_snprintf_error(end
- pos
, ret
))
5151 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
5152 ret
= print_fils_indication(bss
, pos
, end
);
5157 #endif /* CONFIG_FILS */
5159 if (mask
& WPA_BSS_MASK_DELIM
) {
5160 ret
= os_snprintf(pos
, end
- pos
, "====\n");
5161 if (os_snprintf_error(end
- pos
, ret
))
5170 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
5171 const char *cmd
, char *buf
,
5176 struct wpa_bss
*bss
;
5177 struct wpa_bss
*bsslast
= NULL
;
5178 struct dl_list
*next
;
5181 char *ctmp
, *end
= buf
+ buflen
;
5182 unsigned long mask
= WPA_BSS_MASK_ALL
;
5184 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
5185 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
5186 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
5188 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
5190 } else { /* N1-N2 */
5191 unsigned int id1
, id2
;
5193 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
5194 wpa_printf(MSG_INFO
, "Wrong BSS range "
5199 if (*(cmd
+ 6) == '-')
5202 id1
= atoi(cmd
+ 6);
5204 if (*ctmp
>= '0' && *ctmp
<= '9')
5207 id2
= (unsigned int) -1;
5208 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
5209 if (id2
== (unsigned int) -1)
5210 bsslast
= dl_list_last(&wpa_s
->bss_id
,
5214 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
5215 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
5216 struct wpa_bss
*tmp
= bss
;
5218 next
= tmp
->list_id
.next
;
5219 if (next
== &wpa_s
->bss_id
)
5221 tmp
= dl_list_entry(
5222 next
, struct wpa_bss
,
5231 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
5232 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5233 else if (os_strncmp(cmd
, "LAST", 4) == 0)
5234 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5235 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
5237 bss
= wpa_bss_get_id(wpa_s
, i
);
5238 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
5240 bss
= wpa_bss_get_id(wpa_s
, i
);
5242 next
= bss
->list_id
.next
;
5243 if (next
== &wpa_s
->bss_id
)
5246 bss
= dl_list_entry(next
, struct wpa_bss
,
5249 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
5250 bss
= wpa_s
->current_bss
;
5252 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
5253 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
5254 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
5257 #endif /* CONFIG_P2P */
5258 } else if (hwaddr_aton(cmd
, bssid
) == 0)
5259 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5261 struct wpa_bss
*tmp
;
5264 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
5274 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
5275 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
5277 mask
= WPA_BSS_MASK_ALL
;
5283 if (bsslast
== NULL
)
5286 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
5290 if (bss
== bsslast
) {
5291 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
5292 (bss
== dl_list_last(&wpa_s
->bss_id
,
5293 struct wpa_bss
, list_id
))) {
5296 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
5298 if (os_snprintf_error(end
- buf
+ 5, res
)) {
5299 wpa_printf(MSG_DEBUG
,
5300 "Could not add end delim");
5305 next
= bss
->list_id
.next
;
5306 if (next
== &wpa_s
->bss_id
)
5308 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
5309 } while (bss
&& len
);
5315 static int wpa_supplicant_ctrl_iface_ap_scan(
5316 struct wpa_supplicant
*wpa_s
, char *cmd
)
5318 int ap_scan
= atoi(cmd
);
5319 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5323 static int wpa_supplicant_ctrl_iface_scan_interval(
5324 struct wpa_supplicant
*wpa_s
, char *cmd
)
5326 int scan_int
= atoi(cmd
);
5327 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5331 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5332 struct wpa_supplicant
*wpa_s
, char *cmd
)
5334 int expire_age
= atoi(cmd
);
5335 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5339 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5340 struct wpa_supplicant
*wpa_s
, char *cmd
)
5342 int expire_count
= atoi(cmd
);
5343 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5347 static void wpa_supplicant_ctrl_iface_bss_flush(
5348 struct wpa_supplicant
*wpa_s
, char *cmd
)
5350 int flush_age
= atoi(cmd
);
5353 wpa_bss_flush(wpa_s
);
5355 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5359 #ifdef CONFIG_TESTING_OPTIONS
5360 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5362 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5363 /* MLME-DELETEKEYS.request */
5364 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
,
5366 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
,
5368 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
,
5370 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
,
5372 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
,
5374 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
,
5377 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5378 0, KEY_FLAG_PAIRWISE
);
5379 if (wpa_sm_ext_key_id(wpa_s
->wpa
))
5380 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 1, 0,
5381 NULL
, 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
5382 /* MLME-SETPROTECTION.request(None) */
5383 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5384 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5385 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5386 wpa_sm_drop_sa(wpa_s
->wpa
);
5388 #endif /* CONFIG_TESTING_OPTIONS */
5391 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5394 #ifdef CONFIG_NO_SCAN_PROCESSING
5396 #else /* CONFIG_NO_SCAN_PROCESSING */
5398 struct wpa_bss
*bss
;
5399 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5401 if (hwaddr_aton(addr
, bssid
)) {
5402 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5403 "address '%s'", addr
);
5407 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5410 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5411 "configuration known for the target AP");
5415 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5417 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5423 * TODO: Find best network configuration block from configuration to
5424 * allow roaming to other networks
5427 wpa_s
->reassociate
= 1;
5428 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5431 #endif /* CONFIG_NO_SCAN_PROCESSING */
5436 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5438 unsigned int timeout
= atoi(cmd
);
5439 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5440 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5441 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5443 unsigned int search_delay
;
5444 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5448 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5449 wpa_dbg(wpa_s
, MSG_INFO
,
5450 "Reject P2P_FIND since interface is disabled");
5453 if (os_strstr(cmd
, "type=social"))
5454 type
= P2P_FIND_ONLY_SOCIAL
;
5455 else if (os_strstr(cmd
, "type=progressive"))
5456 type
= P2P_FIND_PROGRESSIVE
;
5458 pos
= os_strstr(cmd
, "dev_id=");
5461 if (hwaddr_aton(pos
, dev_id
))
5466 pos
= os_strstr(cmd
, "dev_type=");
5469 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5471 _dev_type
= dev_type
;
5474 pos
= os_strstr(cmd
, "delay=");
5477 search_delay
= atoi(pos
);
5479 search_delay
= wpas_p2p_search_delay(wpa_s
);
5481 pos
= os_strstr(cmd
, "freq=");
5489 /* Must be searched for last, because it adds nul termination */
5490 pos
= os_strstr(cmd
, " seek=");
5493 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5496 _seek
[seek_count
++] = pos
;
5498 term
= os_strchr(pos
, ' ');
5502 pos
= os_strstr(term
+ 1, "seek=");
5506 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5511 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5512 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5516 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5518 const char *last
= NULL
;
5523 /* Expected predefined CPT names delimited by ':' */
5524 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5525 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5526 wpa_printf(MSG_ERROR
,
5527 "P2PS: CPT name list is too long, expected up to %d names",
5528 P2PS_FEATURE_CAPAB_CPT_MAX
);
5533 token_len
= last
- token
;
5535 if (token_len
== 3 &&
5536 os_memcmp(token
, "UDP", token_len
) == 0) {
5537 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5538 } else if (token_len
== 3 &&
5539 os_memcmp(token
, "MAC", token_len
) == 0) {
5540 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5542 wpa_printf(MSG_ERROR
,
5543 "P2PS: Unsupported CPT name '%s'", token
);
5548 if (isblank((unsigned char) *last
)) {
5558 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5560 struct p2ps_provision
*p2ps_prov
;
5562 size_t info_len
= 0;
5564 u8 role
= P2PS_SETUP_NONE
;
5565 long long unsigned val
;
5568 pos
= os_strstr(cmd
, "info=");
5571 info_len
= os_strlen(pos
);
5574 info
= os_malloc(info_len
+ 1);
5576 info_len
= utf8_unescape(pos
, info_len
,
5577 info
, info_len
+ 1);
5583 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5584 if (p2ps_prov
== NULL
) {
5590 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5591 p2ps_prov
->info
[info_len
] = '\0';
5595 pos
= os_strstr(cmd
, "status=");
5597 p2ps_prov
->status
= atoi(pos
+ 7);
5599 p2ps_prov
->status
= -1;
5601 pos
= os_strstr(cmd
, "adv_id=");
5602 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5604 p2ps_prov
->adv_id
= val
;
5606 pos
= os_strstr(cmd
, "method=");
5608 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5610 p2ps_prov
->method
= 0;
5612 pos
= os_strstr(cmd
, "session=");
5613 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5615 p2ps_prov
->session_id
= val
;
5617 pos
= os_strstr(cmd
, "adv_mac=");
5618 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5621 pos
= os_strstr(cmd
, "session_mac=");
5622 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5625 pos
= os_strstr(cmd
, "cpt=");
5627 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5628 p2ps_prov
->cpt_priority
))
5631 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5634 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5635 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5637 /* force conncap with tstCap (no sanity checks) */
5638 pos
= os_strstr(cmd
, "tstCap=");
5640 role
= strtol(pos
+ 7, NULL
, 16);
5642 pos
= os_strstr(cmd
, "role=");
5644 role
= strtol(pos
+ 5, NULL
, 16);
5645 if (role
!= P2PS_SETUP_CLIENT
&&
5646 role
!= P2PS_SETUP_GROUP_OWNER
)
5647 role
= P2PS_SETUP_NONE
;
5650 p2ps_prov
->role
= role
;
5660 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5663 struct p2ps_provision
*p2ps_prov
;
5666 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5668 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5670 if (hwaddr_aton(cmd
, addr
))
5677 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5681 if (p2ps_prov
->status
< 0) {
5686 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5691 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5694 struct p2ps_provision
*p2ps_prov
;
5697 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5698 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5701 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5702 if (hwaddr_aton(cmd
, addr
))
5709 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5713 p2ps_prov
->pd_seeker
= 1;
5715 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5720 static int parse_freq(int chwidth
, int freq2
)
5725 return CHANWIDTH_80P80MHZ
;
5731 return CHANWIDTH_USE_HT
;
5733 return CHANWIDTH_80MHZ
;
5735 return CHANWIDTH_160MHZ
;
5737 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5744 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5745 char *buf
, size_t buflen
)
5750 enum p2p_wps_method wps_method
;
5753 int persistent_group
, persistent_id
= -1;
5760 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5762 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5763 size_t group_ssid_len
= 0;
5766 if (!wpa_s
->global
->p2p_init_wpa_s
)
5768 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5769 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5770 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5771 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5774 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5775 * [persistent|persistent=<network id>]
5776 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5777 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
5779 if (hwaddr_aton(cmd
, addr
))
5787 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5788 pos2
= os_strstr(pos
, " persistent=");
5790 struct wpa_ssid
*ssid
;
5791 persistent_id
= atoi(pos2
+ 12);
5792 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5793 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5794 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5795 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5796 "SSID id=%d for persistent P2P group (GO)",
5801 join
= os_strstr(pos
, " join") != NULL
;
5802 auth
= os_strstr(pos
, " auth") != NULL
;
5803 automatic
= os_strstr(pos
, " auto") != NULL
;
5804 pd
= os_strstr(pos
, " provdisc") != NULL
;
5805 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5806 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5808 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
5809 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
5811 pos2
= os_strstr(pos
, " go_intent=");
5814 go_intent
= atoi(pos2
);
5815 if (go_intent
< 0 || go_intent
> 15)
5819 pos2
= os_strstr(pos
, " freq=");
5827 pos2
= os_strstr(pos
, " freq2=");
5829 freq2
= atoi(pos2
+ 7);
5831 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5833 chwidth
= atoi(pos2
+ 18);
5835 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5836 if (max_oper_chwidth
< 0)
5839 pos2
= os_strstr(pos
, " ssid=");
5844 end
= os_strchr(pos2
, ' ');
5846 group_ssid_len
= os_strlen(pos2
) / 2;
5848 group_ssid_len
= (end
- pos2
) / 2;
5849 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5850 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5852 group_ssid
= _group_ssid
;
5855 if (os_strncmp(pos
, "pin", 3) == 0) {
5856 /* Request random PIN (to be displayed) and enable the PIN */
5857 wps_method
= WPS_PIN_DISPLAY
;
5858 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5859 wps_method
= WPS_PBC
;
5860 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5861 wps_method
= WPS_P2PS
;
5864 pos
= os_strchr(pin
, ' ');
5865 wps_method
= WPS_PIN_KEYPAD
;
5868 if (os_strncmp(pos
, "display", 7) == 0)
5869 wps_method
= WPS_PIN_DISPLAY
;
5871 if (!wps_pin_str_valid(pin
)) {
5872 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5877 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5878 persistent_group
, automatic
, join
,
5879 auth
, go_intent
, freq
, freq2
, persistent_id
,
5880 pd
, ht40
, vht
, max_oper_chwidth
, he
, edmg
,
5881 group_ssid
, group_ssid_len
);
5882 if (new_pin
== -2) {
5883 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5886 if (new_pin
== -3) {
5887 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5892 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5893 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5894 if (os_snprintf_error(buflen
, ret
))
5899 os_memcpy(buf
, "OK\n", 3);
5904 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5906 unsigned int timeout
= atoi(cmd
);
5907 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5908 wpa_dbg(wpa_s
, MSG_INFO
,
5909 "Reject P2P_LISTEN since interface is disabled");
5912 return wpas_p2p_listen(wpa_s
, timeout
);
5916 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5920 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5922 /* <addr> <config method> [join|auto] */
5924 if (hwaddr_aton(cmd
, addr
))
5932 if (os_strstr(pos
, " join") != NULL
)
5933 use
= WPAS_P2P_PD_FOR_JOIN
;
5934 else if (os_strstr(pos
, " auto") != NULL
)
5935 use
= WPAS_P2P_PD_AUTO
;
5937 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5941 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5944 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5946 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5947 ssid
->passphrase
== NULL
)
5950 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5951 return os_strlen(buf
);
5955 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5956 char *buf
, size_t buflen
)
5960 u8 dst_buf
[ETH_ALEN
], *dst
;
5961 struct wpabuf
*tlvs
;
5965 if (hwaddr_aton(cmd
, dst_buf
))
5968 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5969 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5976 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5979 if (hexstr2bin(pos
, &version
, 1) < 0)
5985 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5986 #ifdef CONFIG_WIFI_DISPLAY
5987 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5988 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5989 #endif /* CONFIG_WIFI_DISPLAY */
5990 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5992 char *svc_info
= NULL
;
5996 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5999 pos
= os_strchr(pos
, ' ');
6000 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
6005 pos
= os_strchr(svc_str
, ' ');
6010 /* All remaining data is the svc_info string */
6011 if (pos
&& pos
[0] && pos
[0] != ' ') {
6012 len
= os_strlen(pos
);
6014 /* Unescape in place */
6015 len
= utf8_unescape(pos
, len
, pos
, len
);
6022 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
6025 len
= os_strlen(pos
);
6029 tlvs
= wpabuf_alloc(len
);
6032 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
6037 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
6042 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
6043 if (os_snprintf_error(buflen
, res
))
6049 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
6052 long long unsigned val
;
6054 if (sscanf(cmd
, "%llx", &val
) != 1)
6057 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
6061 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6066 struct wpabuf
*resp_tlvs
;
6070 pos
= os_strchr(cmd
, ' ');
6078 if (hwaddr_aton(pos
, dst
))
6085 pos2
= os_strchr(pos
, ' ');
6089 dialog_token
= atoi(pos
);
6091 len
= os_strlen(pos2
);
6095 resp_tlvs
= wpabuf_alloc(len
);
6096 if (resp_tlvs
== NULL
)
6098 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
6099 wpabuf_free(resp_tlvs
);
6103 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
6104 wpabuf_free(resp_tlvs
);
6109 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
6112 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
6114 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
6119 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
6124 struct wpabuf
*query
, *resp
;
6126 pos
= os_strchr(cmd
, ' ');
6131 len
= os_strlen(cmd
);
6135 query
= wpabuf_alloc(len
);
6138 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6143 len
= os_strlen(pos
);
6149 resp
= wpabuf_alloc(len
);
6154 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
6160 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
6169 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6174 pos
= os_strchr(cmd
, ' ');
6179 if (hexstr2bin(cmd
, &version
, 1) < 0)
6182 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
6186 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
6187 u8 replace
, char *cmd
)
6191 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
6192 char *svc_info
= NULL
;
6194 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
6196 pos
= os_strchr(cmd
, ' ');
6201 /* Auto-Accept value is mandatory, and must be one of the
6202 * single values (0, 1, 2, 4) */
6203 auto_accept
= atoi(cmd
);
6204 switch (auto_accept
) {
6205 case P2PS_SETUP_NONE
: /* No auto-accept */
6206 case P2PS_SETUP_NEW
:
6207 case P2PS_SETUP_CLIENT
:
6208 case P2PS_SETUP_GROUP_OWNER
:
6214 /* Advertisement ID is mandatory */
6216 pos
= os_strchr(cmd
, ' ');
6221 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6222 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
6225 /* Only allow replacements if exist, and adds if not */
6226 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
6234 /* svc_state between 0 - 0xff is mandatory */
6235 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
6238 pos
= os_strchr(pos
, ' ');
6242 /* config_methods is mandatory */
6244 if (sscanf(pos
, "%x", &config_methods
) != 1)
6247 if (!(config_methods
&
6248 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
6251 pos
= os_strchr(pos
, ' ');
6258 /* Advertisement string is mandatory */
6259 if (!pos
[0] || pos
[0] == ' ')
6262 /* Terminate svc string */
6263 pos
= os_strchr(pos
, ' ');
6267 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
6269 pos
= os_strchr(pos
, ' ');
6273 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
6276 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
6280 /* Service and Response Information are optional */
6281 if (pos
&& pos
[0]) {
6284 /* Note the bare ' included, which cannot exist legally
6285 * in unescaped string. */
6286 svc_info
= os_strstr(pos
, "svc_info='");
6290 len
= os_strlen(svc_info
);
6291 utf8_unescape(svc_info
, len
, svc_info
, len
);
6295 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
6296 (u8
) svc_state
, (u16
) config_methods
,
6297 svc_info
, cpt_prio
);
6301 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6305 pos
= os_strchr(cmd
, ' ');
6310 if (os_strcmp(cmd
, "bonjour") == 0)
6311 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
6312 if (os_strcmp(cmd
, "upnp") == 0)
6313 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
6314 if (os_strcmp(cmd
, "asp") == 0)
6315 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
6316 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6321 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
6325 struct wpabuf
*query
;
6328 len
= os_strlen(cmd
);
6332 query
= wpabuf_alloc(len
);
6335 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6340 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6346 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6351 pos
= os_strchr(cmd
, ' ');
6356 if (hexstr2bin(cmd
, &version
, 1) < 0)
6359 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6363 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6367 if (os_strcmp(cmd
, "all") == 0) {
6368 wpas_p2p_service_flush_asp(wpa_s
);
6372 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6375 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6379 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6383 pos
= os_strchr(cmd
, ' ');
6388 if (os_strcmp(cmd
, "bonjour") == 0)
6389 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6390 if (os_strcmp(cmd
, "upnp") == 0)
6391 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6392 if (os_strcmp(cmd
, "asp") == 0)
6393 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6394 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6399 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6403 pos
= os_strchr(cmd
, ' ');
6408 if (os_strcmp(cmd
, "asp") == 0)
6409 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6411 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6416 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6422 if (hwaddr_aton(cmd
, addr
))
6425 return wpas_p2p_reject(wpa_s
, addr
);
6429 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6433 struct wpa_ssid
*ssid
;
6434 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6435 int freq
= 0, pref_freq
= 0;
6436 int ht40
, vht
, he
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6440 pos
= os_strstr(cmd
, " peer=");
6443 if (hwaddr_aton(pos
, peer
))
6447 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6448 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6449 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6450 "for persistent P2P group",
6455 pos
= os_strstr(cmd
, " freq=");
6463 pos
= os_strstr(cmd
, " pref=");
6466 pref_freq
= atoi(pos
);
6471 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6472 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6474 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
6475 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
6477 pos
= os_strstr(cmd
, "freq2=");
6479 freq2
= atoi(pos
+ 6);
6481 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6483 chwidth
= atoi(pos
+ 18);
6485 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6486 if (max_oper_chwidth
< 0)
6489 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6490 max_oper_chwidth
, pref_freq
, he
, edmg
);
6494 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6497 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6499 pos
= os_strstr(cmd
, " peer=");
6505 if (hwaddr_aton(pos
, peer
)) {
6506 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6510 pos
= os_strstr(pos
, " go_dev_addr=");
6513 if (hwaddr_aton(pos
, go_dev_addr
)) {
6514 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6518 go_dev
= go_dev_addr
;
6521 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6525 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6527 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6528 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6529 if (os_strncmp(cmd
, "group=", 6) == 0)
6530 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6536 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6537 int id
, int freq
, int vht_center_freq2
,
6538 int ht40
, int vht
, int vht_chwidth
,
6541 struct wpa_ssid
*ssid
;
6543 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6544 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6545 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6546 "for persistent P2P group",
6551 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6552 vht_center_freq2
, 0, ht40
, vht
,
6553 vht_chwidth
, he
, edmg
,
6558 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6560 int freq
= 0, persistent
= 0, group_id
= -1;
6561 int vht
= wpa_s
->conf
->p2p_go_vht
;
6562 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6563 int he
= wpa_s
->conf
->p2p_go_he
;
6564 int edmg
= wpa_s
->conf
->p2p_go_edmg
;
6565 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6566 char *token
, *context
= NULL
;
6569 #endif /* CONFIG_ACS */
6571 while ((token
= str_token(cmd
, " ", &context
))) {
6572 if (sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6573 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6574 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6577 } else if (os_strcmp(token
, "freq=acs") == 0) {
6579 #endif /* CONFIG_ACS */
6580 } else if (sscanf(token
, "freq=%d", &freq
) == 1) {
6582 } else if (os_strcmp(token
, "ht40") == 0) {
6584 } else if (os_strcmp(token
, "vht") == 0) {
6587 } else if (os_strcmp(token
, "he") == 0) {
6589 } else if (os_strcmp(token
, "edmg") == 0) {
6591 } else if (os_strcmp(token
, "persistent") == 0) {
6594 wpa_printf(MSG_DEBUG
,
6595 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6602 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_ACS_OFFLOAD
) &&
6603 (acs
|| freq
== 2 || freq
== 5)) {
6604 if (freq
== 2 && wpa_s
->best_24_freq
<= 0) {
6605 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211G
;
6606 wpa_s
->p2p_go_do_acs
= 1;
6608 } else if (freq
== 5 && wpa_s
->best_5_freq
<= 0) {
6609 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211A
;
6610 wpa_s
->p2p_go_do_acs
= 1;
6613 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211ANY
;
6614 wpa_s
->p2p_go_do_acs
= 1;
6617 wpa_s
->p2p_go_do_acs
= 0;
6619 #endif /* CONFIG_ACS */
6621 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6622 if (max_oper_chwidth
< 0)
6626 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6627 freq
, freq2
, ht40
, vht
,
6628 max_oper_chwidth
, he
,
6631 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6632 max_oper_chwidth
, he
, edmg
);
6636 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6637 char *buf
, size_t buflen
)
6639 u8 dev_addr
[ETH_ALEN
];
6640 struct wpa_ssid
*ssid
;
6644 ssid
= wpa_s
->current_ssid
;
6645 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6646 hwaddr_aton(cmd
, dev_addr
))
6649 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6652 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6653 if (os_snprintf_error(buflen
, res
))
6659 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6660 const u8
*p2p_dev_addr
)
6662 struct wpa_supplicant
*wpa_s
;
6664 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6665 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6673 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6674 char *buf
, size_t buflen
)
6676 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6678 const struct p2p_peer_info
*info
;
6680 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6681 struct wpa_ssid
*ssid
;
6684 if (!wpa_s
->global
->p2p
)
6687 if (os_strcmp(cmd
, "FIRST") == 0) {
6690 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6691 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6696 if (hwaddr_aton(cmd
, addr
) < 0)
6702 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6705 group_capab
= info
->group_capab
;
6708 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6709 wpa_printf(MSG_DEBUG
,
6710 "P2P: Could not find any BSS with p2p_dev_addr "
6711 MACSTR
", hence override group_capab from 0x%x to 0",
6712 MAC2STR(info
->p2p_device_addr
), group_capab
);
6719 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6725 "serial_number=%s\n"
6726 "config_methods=0x%x\n"
6728 "group_capab=0x%x\n"
6730 MAC2STR(info
->p2p_device_addr
),
6731 wps_dev_type_bin2str(info
->pri_dev_type
,
6732 devtype
, sizeof(devtype
)),
6737 info
->serial_number
,
6738 info
->config_methods
,
6742 if (os_snprintf_error(end
- pos
, res
))
6746 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6749 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6750 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6751 wps_dev_type_bin2str(t
, devtype
,
6753 if (os_snprintf_error(end
- pos
, res
))
6758 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6760 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6761 if (os_snprintf_error(end
- pos
, res
))
6766 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6771 if (info
->vendor_elems
) {
6772 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6773 if (os_snprintf_error(end
- pos
, res
))
6777 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6778 wpabuf_head(info
->vendor_elems
),
6779 wpabuf_len(info
->vendor_elems
));
6781 res
= os_snprintf(pos
, end
- pos
, "\n");
6782 if (os_snprintf_error(end
- pos
, res
))
6791 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6796 if (wpa_s
->global
->p2p
== NULL
)
6799 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6802 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6803 struct wpa_freq_range
*freq
;
6804 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6805 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6806 freq
->min
, freq
->max
);
6809 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6814 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6818 if (wpa_s
->global
->p2p
== NULL
)
6821 param
= os_strchr(cmd
, ' ');
6826 if (os_strcmp(cmd
, "discoverability") == 0) {
6827 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6832 if (os_strcmp(cmd
, "managed") == 0) {
6833 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6837 if (os_strcmp(cmd
, "listen_channel") == 0) {
6839 u8 channel
, op_class
;
6841 channel
= atoi(param
);
6842 pos
= os_strchr(param
, ' ');
6843 op_class
= pos
? atoi(pos
) : 81;
6845 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6849 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6850 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6854 if (os_strcmp(cmd
, "noa") == 0) {
6856 int count
, start
, duration
;
6857 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6858 count
= atoi(param
);
6859 pos
= os_strchr(param
, ',');
6864 pos
= os_strchr(pos
, ',');
6868 duration
= atoi(pos
);
6869 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6871 if (count
== 0 && duration
> 0)
6873 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6874 "start=%d duration=%d", count
, start
, duration
);
6875 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6878 if (os_strcmp(cmd
, "ps") == 0)
6879 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6881 if (os_strcmp(cmd
, "oppps") == 0)
6882 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6884 if (os_strcmp(cmd
, "ctwindow") == 0)
6885 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6887 if (os_strcmp(cmd
, "disabled") == 0) {
6888 wpa_s
->global
->p2p_disabled
= atoi(param
);
6889 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6890 wpa_s
->global
->p2p_disabled
?
6891 "disabled" : "enabled");
6892 if (wpa_s
->global
->p2p_disabled
) {
6893 wpas_p2p_stop_find(wpa_s
);
6894 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6895 p2p_flush(wpa_s
->global
->p2p
);
6900 if (os_strcmp(cmd
, "conc_pref") == 0) {
6901 if (os_strcmp(param
, "sta") == 0)
6902 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6903 else if (os_strcmp(param
, "p2p") == 0)
6904 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6906 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6909 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6914 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6915 wpa_s
->force_long_sd
= atoi(param
);
6919 if (os_strcmp(cmd
, "peer_filter") == 0) {
6921 if (hwaddr_aton(param
, addr
))
6923 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6927 if (os_strcmp(cmd
, "cross_connect") == 0)
6928 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6930 if (os_strcmp(cmd
, "go_apsd") == 0) {
6931 if (os_strcmp(param
, "disable") == 0)
6932 wpa_s
->set_ap_uapsd
= 0;
6934 wpa_s
->set_ap_uapsd
= 1;
6935 wpa_s
->ap_uapsd
= atoi(param
);
6940 if (os_strcmp(cmd
, "client_apsd") == 0) {
6941 if (os_strcmp(param
, "disable") == 0)
6942 wpa_s
->set_sta_uapsd
= 0;
6946 /* format: BE,BK,VI,VO;max SP Length */
6948 pos
= os_strchr(param
, ',');
6953 pos
= os_strchr(pos
, ',');
6958 pos
= os_strchr(pos
, ',');
6963 /* ignore max SP Length for now */
6965 wpa_s
->set_sta_uapsd
= 1;
6966 wpa_s
->sta_uapsd
= 0;
6968 wpa_s
->sta_uapsd
|= BIT(0);
6970 wpa_s
->sta_uapsd
|= BIT(1);
6972 wpa_s
->sta_uapsd
|= BIT(2);
6974 wpa_s
->sta_uapsd
|= BIT(3);
6979 if (os_strcmp(cmd
, "disallow_freq") == 0)
6980 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6982 if (os_strcmp(cmd
, "disc_int") == 0) {
6983 int min_disc_int
, max_disc_int
, max_disc_tu
;
6988 min_disc_int
= atoi(pos
);
6989 pos
= os_strchr(pos
, ' ');
6994 max_disc_int
= atoi(pos
);
6995 pos
= os_strchr(pos
, ' ');
7000 max_disc_tu
= atoi(pos
);
7002 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
7003 max_disc_int
, max_disc_tu
);
7006 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
7007 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
7011 #ifdef CONFIG_WPS_NFC
7012 if (os_strcmp(cmd
, "nfc_tag") == 0)
7013 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
7014 #endif /* CONFIG_WPS_NFC */
7016 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
7017 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
7021 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
7024 op_class
= atoi(param
);
7025 param
= os_strchr(param
, ':');
7030 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
7035 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7042 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
7044 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
7045 wpa_s
->force_long_sd
= 0;
7047 #ifdef CONFIG_TESTING_OPTIONS
7048 os_free(wpa_s
->get_pref_freq_list_override
);
7049 wpa_s
->get_pref_freq_list_override
= NULL
;
7050 #endif /* CONFIG_TESTING_OPTIONS */
7052 wpas_p2p_stop_find(wpa_s
);
7053 wpa_s
->parent
->p2ps_method_config_any
= 0;
7054 if (wpa_s
->global
->p2p
)
7055 p2p_flush(wpa_s
->global
->p2p
);
7059 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
7062 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
7065 pos
= os_strchr(cmd
, ' ');
7071 pos2
= os_strchr(pos
, ' ');
7079 pos
= os_strchr(pos2
, ' ');
7087 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
7091 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
7094 unsigned int period
= 0, interval
= 0;
7097 pos
= os_strchr(cmd
, ' ');
7102 interval
= atoi(pos
);
7105 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
7109 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
7116 if (os_strncmp(pos
, "iface=", 6) == 0) {
7120 if (hwaddr_aton(pos
, peer
))
7123 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
7128 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
7130 int freq
= 0, period
= 0, interval
= 0, count
= 0;
7132 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
7134 wpa_printf(MSG_DEBUG
,
7135 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
7139 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
7142 #endif /* CONFIG_P2P */
7145 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
7147 struct wpa_freq_range_list ranges
;
7149 struct hostapd_hw_modes
*mode
;
7152 if (wpa_s
->hw
.modes
== NULL
)
7155 os_memset(&ranges
, 0, sizeof(ranges
));
7156 if (freq_range_list_parse(&ranges
, val
) < 0)
7159 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
7162 mode
= &wpa_s
->hw
.modes
[i
];
7163 for (j
= 0; j
< mode
->num_channels
; j
++) {
7166 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
7169 freq
= mode
->channels
[j
].freq
;
7170 if (!freq_range_list_includes(&ranges
, freq
))
7173 int_array_add_unique(&freqs
, freq
);
7177 os_free(ranges
.range
);
7182 #ifdef CONFIG_INTERWORKING
7184 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
7192 auto_sel
= os_strstr(param
, "auto") != NULL
;
7194 pos
= os_strstr(param
, "freq=");
7196 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
7203 return interworking_select(wpa_s
, auto_sel
, freqs
);
7207 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
7211 struct wpa_bss
*bss
;
7213 if (hwaddr_aton(dst
, bssid
)) {
7214 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
7218 bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
7220 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
7225 if (bss
->ssid_len
== 0) {
7228 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
7229 " does not have SSID information", MAC2STR(bssid
));
7231 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
7233 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
7234 bss
->ssid_len
> 0) {
7242 wpa_printf(MSG_DEBUG
,
7243 "Found another matching BSS entry with SSID");
7246 return interworking_connect(wpa_s
, bss
, only_add
);
7250 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7252 u8 dst_addr
[ETH_ALEN
];
7255 #define MAX_ANQP_INFO_ID 100
7256 u16 id
[MAX_ANQP_INFO_ID
];
7259 u32 mbo_subtypes
= 0;
7261 used
= hwaddr_aton2(dst
, dst_addr
);
7267 while (num_id
< MAX_ANQP_INFO_ID
) {
7268 if (os_strncmp(pos
, "hs20:", 5) == 0) {
7270 int num
= atoi(pos
+ 5);
7271 if (num
<= 0 || num
> 31)
7273 subtypes
|= BIT(num
);
7274 #else /* CONFIG_HS20 */
7276 #endif /* CONFIG_HS20 */
7277 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
7279 int num
= atoi(pos
+ 4);
7281 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
7283 mbo_subtypes
|= BIT(num
);
7284 #else /* CONFIG_MBO */
7286 #endif /* CONFIG_MBO */
7288 id
[num_id
] = atoi(pos
);
7292 pos
= os_strchr(pos
+ 1, ',');
7298 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
7301 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
7306 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
7308 u8 dst_addr
[ETH_ALEN
];
7309 struct wpabuf
*advproto
, *query
= NULL
;
7314 used
= hwaddr_aton2(cmd
, dst_addr
);
7322 /* Advertisement Protocol ID */
7323 end
= os_strchr(pos
, ' ');
7327 len
= os_strlen(pos
);
7333 advproto
= wpabuf_alloc(len
);
7334 if (advproto
== NULL
)
7336 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
7340 /* Optional Query Request */
7345 len
= os_strlen(pos
);
7352 query
= wpabuf_alloc(len
);
7355 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
7360 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
7363 wpabuf_free(advproto
);
7370 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7377 size_t resp_len
, start
, requested_len
;
7378 struct wpabuf
*resp
;
7381 used
= hwaddr_aton2(cmd
, addr
);
7388 dialog_token
= atoi(pos
);
7390 if (wpa_s
->last_gas_resp
&&
7391 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7392 dialog_token
== wpa_s
->last_gas_dialog_token
)
7393 resp
= wpa_s
->last_gas_resp
;
7394 else if (wpa_s
->prev_gas_resp
&&
7395 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7396 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7397 resp
= wpa_s
->prev_gas_resp
;
7401 resp_len
= wpabuf_len(resp
);
7403 requested_len
= resp_len
;
7405 pos
= os_strchr(pos
, ' ');
7408 if (start
> resp_len
)
7409 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7410 pos
= os_strchr(pos
, ',');
7414 requested_len
= atoi(pos
);
7415 if (start
+ requested_len
> resp_len
)
7416 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7419 if (requested_len
* 2 + 1 > buflen
)
7420 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7422 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7425 if (start
+ requested_len
== resp_len
) {
7427 * Free memory by dropping the response after it has been
7430 if (resp
== wpa_s
->prev_gas_resp
) {
7431 wpabuf_free(wpa_s
->prev_gas_resp
);
7432 wpa_s
->prev_gas_resp
= NULL
;
7434 wpabuf_free(wpa_s
->last_gas_resp
);
7435 wpa_s
->last_gas_resp
= NULL
;
7441 #endif /* CONFIG_INTERWORKING */
7446 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7448 u8 dst_addr
[ETH_ALEN
];
7453 used
= hwaddr_aton2(dst
, dst_addr
);
7460 int num
= atoi(pos
);
7461 if (num
<= 0 || num
> 31)
7463 subtypes
|= BIT(num
);
7464 pos
= os_strchr(pos
+ 1, ',');
7473 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7477 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7478 const u8
*addr
, const char *realm
)
7484 rlen
= os_strlen(realm
);
7486 buf
= os_malloc(len
);
7489 buf
[0] = 1; /* NAI Home Realm Count */
7490 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7492 os_memcpy(buf
+ 3, realm
, rlen
);
7494 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7495 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7504 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7507 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7508 u8 dst_addr
[ETH_ALEN
];
7514 used
= hwaddr_aton2(dst
, dst_addr
);
7518 while (dst
[used
] == ' ')
7520 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7521 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7524 len
= os_strlen(dst
+ used
);
7526 if (len
== 0 && cred
&& cred
->realm
)
7527 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7532 buf
= os_malloc(len
);
7535 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7540 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7541 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7549 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7552 u8 dst_addr
[ETH_ALEN
];
7554 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7556 used
= hwaddr_aton2(cmd
, dst_addr
);
7561 icon
= str_token(cmd
, " ", &ctx
);
7562 poffset
= str_token(cmd
, " ", &ctx
);
7563 psize
= str_token(cmd
, " ", &ctx
);
7564 if (!icon
|| !poffset
|| !psize
)
7567 wpa_s
->fetch_osu_icon_in_progress
= 0;
7568 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7573 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7575 u8 dst_addr
[ETH_ALEN
];
7580 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7582 used
= hwaddr_aton2(cmd
, dst_addr
);
7586 while (cmd
[used
] == ' ')
7588 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7590 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7594 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7596 u8 dst_addr
[ETH_ALEN
];
7600 used
= hwaddr_aton2(cmd
, dst_addr
);
7604 while (cmd
[used
] == ' ')
7608 wpa_s
->fetch_osu_icon_in_progress
= 0;
7609 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7610 (u8
*) icon
, os_strlen(icon
), inmem
);
7613 #endif /* CONFIG_HS20 */
7616 #ifdef CONFIG_AUTOSCAN
7618 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7621 enum wpa_states state
= wpa_s
->wpa_state
;
7622 char *new_params
= NULL
;
7624 if (os_strlen(cmd
) > 0) {
7625 new_params
= os_strdup(cmd
);
7626 if (new_params
== NULL
)
7630 os_free(wpa_s
->conf
->autoscan
);
7631 wpa_s
->conf
->autoscan
= new_params
;
7633 if (wpa_s
->conf
->autoscan
== NULL
)
7634 autoscan_deinit(wpa_s
);
7635 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7636 autoscan_init(wpa_s
, 1);
7637 else if (state
== WPA_SCANNING
)
7638 wpa_supplicant_reinit_autoscan(wpa_s
);
7640 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7641 wpa_supplicant_state_txt(state
));
7646 #endif /* CONFIG_AUTOSCAN */
7651 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7657 struct wpabuf
*tfs_req
= NULL
;
7659 if (os_strncmp(cmd
, "enter", 5) == 0)
7661 else if (os_strncmp(cmd
, "exit", 4) == 0)
7666 pos
= os_strstr(cmd
, " interval=");
7668 intval
= atoi(pos
+ 10);
7670 pos
= os_strstr(cmd
, " tfs_req=");
7675 end
= os_strchr(pos
, ' ');
7679 len
= os_strlen(pos
);
7683 tfs_req
= wpabuf_alloc(len
);
7684 if (tfs_req
== NULL
)
7686 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7687 wpabuf_free(tfs_req
);
7692 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7693 WNM_SLEEP_MODE_EXIT
, intval
,
7695 wpabuf_free(tfs_req
);
7701 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7703 int query_reason
, list
= 0;
7704 char *btm_candidates
= NULL
;
7706 query_reason
= atoi(cmd
);
7708 cmd
= os_strchr(cmd
, ' ');
7710 if (os_strncmp(cmd
, " list", 5) == 0)
7713 btm_candidates
= cmd
;
7716 wpa_printf(MSG_DEBUG
,
7717 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7718 query_reason
, list
? " candidate list" : "");
7720 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7726 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant
*wpa_s
,
7729 struct wpabuf
*elems
;
7732 elems
= wpabuf_parse_bin(cmd
);
7736 ret
= wnm_send_coloc_intf_report(wpa_s
, 0, elems
);
7741 #endif /* CONFIG_WNM */
7744 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7747 struct wpa_signal_info si
;
7751 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7758 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7759 "NOISE=%d\nFREQUENCY=%u\n",
7760 si
.current_signal
, si
.current_txrate
/ 1000,
7761 si
.current_noise
, si
.frequency
);
7762 if (os_snprintf_error(end
- pos
, ret
))
7766 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7767 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7768 channel_width_to_string(si
.chanwidth
));
7769 if (os_snprintf_error(end
- pos
, ret
))
7774 if (si
.center_frq1
> 0) {
7775 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ1=%d\n",
7777 if (os_snprintf_error(end
- pos
, ret
))
7782 if (si
.center_frq2
> 0) {
7783 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ2=%d\n",
7785 if (os_snprintf_error(end
- pos
, ret
))
7790 if (si
.avg_signal
) {
7791 ret
= os_snprintf(pos
, end
- pos
,
7792 "AVG_RSSI=%d\n", si
.avg_signal
);
7793 if (os_snprintf_error(end
- pos
, ret
))
7798 if (si
.avg_beacon_signal
) {
7799 ret
= os_snprintf(pos
, end
- pos
,
7800 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7801 if (os_snprintf_error(end
- pos
, ret
))
7810 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7817 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7818 wpa_printf(MSG_DEBUG
,
7819 "Reject SIGNAL_MONITOR command - bgscan is active");
7822 pos
= os_strstr(cmd
, "THRESHOLD=");
7824 threshold
= atoi(pos
+ 10);
7825 pos
= os_strstr(cmd
, "HYSTERESIS=");
7827 hysteresis
= atoi(pos
+ 11);
7828 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7832 #ifdef CONFIG_TESTING_OPTIONS
7833 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7834 enum wpa_driver_if_type if_type
,
7836 unsigned int *freq_list
)
7838 char *pos
= wpa_s
->get_pref_freq_list_override
;
7840 unsigned int count
= 0;
7842 /* Override string format:
7843 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7846 if (atoi(pos
) == (int) if_type
)
7848 pos
= os_strchr(pos
, ' ');
7854 pos
= os_strchr(pos
, ':');
7858 end
= os_strchr(pos
, ' ');
7859 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7860 freq_list
[count
++] = atoi(pos
);
7861 pos
= os_strchr(pos
, ',');
7869 #endif /* CONFIG_TESTING_OPTIONS */
7872 static int wpas_ctrl_iface_get_pref_freq_list(
7873 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7875 unsigned int freq_list
[100], num
= 100, i
;
7877 enum wpa_driver_if_type iface_type
;
7883 /* buf: "<interface_type>" */
7884 if (os_strcmp(cmd
, "STATION") == 0)
7885 iface_type
= WPA_IF_STATION
;
7886 else if (os_strcmp(cmd
, "AP") == 0)
7887 iface_type
= WPA_IF_AP_BSS
;
7888 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7889 iface_type
= WPA_IF_P2P_GO
;
7890 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7891 iface_type
= WPA_IF_P2P_CLIENT
;
7892 else if (os_strcmp(cmd
, "IBSS") == 0)
7893 iface_type
= WPA_IF_IBSS
;
7894 else if (os_strcmp(cmd
, "TDLS") == 0)
7895 iface_type
= WPA_IF_TDLS
;
7899 wpa_printf(MSG_DEBUG
,
7900 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7903 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7907 for (i
= 0; i
< num
; i
++) {
7908 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7909 i
> 0 ? "," : "", freq_list
[i
]);
7910 if (os_snprintf_error(end
- pos
, ret
))
7919 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7920 char *buf
, size_t buflen
)
7925 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7926 (long long unsigned) wpa_s
->drv_flags
);
7927 if (os_snprintf_error(buflen
, ret
))
7933 for (i
= 0; i
< 64; i
++) {
7934 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7935 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7936 driver_flag_to_string(1LLU << i
));
7937 if (os_snprintf_error(end
- pos
, ret
))
7947 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7950 struct hostap_sta_driver_data sta
;
7953 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7957 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7958 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7959 if (os_snprintf_error(buflen
, ret
))
7966 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7967 char *buf
, size_t buflen
)
7971 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7973 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7974 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7977 country
[0] = cmd
[8];
7978 country
[1] = cmd
[9];
7980 p2p_set_country(p2p
, country
);
7983 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7984 if (os_snprintf_error(buflen
, ret
))
7989 #endif /* ANDROID */
7992 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7993 char *buf
, size_t buflen
)
7998 unsigned int vendor_id
, subcmd
;
7999 struct wpabuf
*reply
;
8000 size_t data_len
= 0;
8002 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
8003 vendor_id
= strtoul(cmd
, &pos
, 16);
8004 if (!isblank((unsigned char) *pos
))
8007 subcmd
= strtoul(pos
, &pos
, 10);
8010 if (!isblank((unsigned char) *pos
++))
8012 data_len
= os_strlen(pos
);
8017 data
= os_malloc(data_len
);
8021 if (hexstr2bin(pos
, data
, data_len
)) {
8022 wpa_printf(MSG_DEBUG
,
8023 "Vendor command: wrong parameter format");
8029 reply
= wpabuf_alloc((buflen
- 1) / 2);
8035 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
8039 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
8049 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
8052 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
8053 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
8054 #endif /* CONFIG_P2P */
8056 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
8058 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
8059 wpa_s
->ignore_post_flush_scan_res
= 1;
8061 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
8063 * Avoid possible auto connect re-connection on getting
8064 * disconnected due to state flush.
8066 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
8070 wpas_p2p_group_remove(p2p_wpa_s
, "*");
8071 wpas_p2p_cancel(p2p_wpa_s
);
8072 p2p_ctrl_flush(p2p_wpa_s
);
8073 wpas_p2p_service_flush(p2p_wpa_s
);
8074 p2p_wpa_s
->global
->p2p_disabled
= 0;
8075 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
8076 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
8077 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
8078 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
8079 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
8080 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
8081 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
8082 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
8083 #endif /* CONFIG_P2P */
8085 #ifdef CONFIG_WPS_TESTING
8086 wps_version_number
= 0x20;
8087 wps_testing_dummy_cred
= 0;
8088 wps_corrupt_pkhash
= 0;
8089 wps_force_auth_types_in_use
= 0;
8090 wps_force_encr_types_in_use
= 0;
8091 #endif /* CONFIG_WPS_TESTING */
8093 wpa_s
->wps_fragment_size
= 0;
8094 wpas_wps_cancel(wpa_s
);
8095 wps_registrar_flush(wpa_s
->wps
->registrar
);
8096 #endif /* CONFIG_WPS */
8097 wpa_s
->after_wps
= 0;
8098 wpa_s
->known_wps_freq
= 0;
8101 wpas_dpp_deinit(wpa_s
);
8102 wpa_s
->dpp_init_max_tries
= 0;
8103 wpa_s
->dpp_init_retry_time
= 0;
8104 wpa_s
->dpp_resp_wait_time
= 0;
8105 wpa_s
->dpp_resp_max_tries
= 0;
8106 wpa_s
->dpp_resp_retry_time
= 0;
8108 wpas_dpp_chirp_stop(wpa_s
);
8109 wpa_s
->dpp_pfs_fallback
= 0;
8110 #endif /* CONFIG_DPP2 */
8111 #ifdef CONFIG_TESTING_OPTIONS
8112 os_memset(dpp_pkex_own_mac_override
, 0, ETH_ALEN
);
8113 os_memset(dpp_pkex_peer_mac_override
, 0, ETH_ALEN
);
8114 dpp_pkex_ephemeral_key_override_len
= 0;
8115 dpp_protocol_key_override_len
= 0;
8116 dpp_nonce_override_len
= 0;
8117 #endif /* CONFIG_TESTING_OPTIONS */
8118 #endif /* CONFIG_DPP */
8121 #ifdef CONFIG_TDLS_TESTING
8123 #endif /* CONFIG_TDLS_TESTING */
8124 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
8125 wpa_tdls_enable(wpa_s
->wpa
, 1);
8126 #endif /* CONFIG_TDLS */
8128 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
8129 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
8130 wpa_s
->last_michael_mic_error
.sec
= 0;
8132 wpa_s
->no_keep_alive
= 0;
8133 wpa_s
->own_disconnect_req
= 0;
8134 wpa_s
->own_reconnect_req
= 0;
8135 wpa_s
->deny_ptk0_rekey
= 0;
8137 os_free(wpa_s
->disallow_aps_bssid
);
8138 wpa_s
->disallow_aps_bssid
= NULL
;
8139 wpa_s
->disallow_aps_bssid_count
= 0;
8140 os_free(wpa_s
->disallow_aps_ssid
);
8141 wpa_s
->disallow_aps_ssid
= NULL
;
8142 wpa_s
->disallow_aps_ssid_count
= 0;
8144 wpa_s
->set_sta_uapsd
= 0;
8145 wpa_s
->sta_uapsd
= 0;
8147 wpa_drv_radio_disable(wpa_s
, 0);
8148 wpa_blacklist_clear(wpa_s
);
8149 wpa_s
->extra_blacklist_count
= 0;
8150 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
8151 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
8152 wpa_config_flush_blobs(wpa_s
->conf
);
8153 wpa_s
->conf
->auto_interworking
= 0;
8154 wpa_s
->conf
->okc
= 0;
8156 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
8157 rsn_preauth_deinit(wpa_s
->wpa
);
8159 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
8160 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
8161 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
8162 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
8164 radio_remove_works(wpa_s
, NULL
, 1);
8165 wpa_s
->ext_work_in_progress
= 0;
8167 wpa_s
->next_ssid
= NULL
;
8169 #ifdef CONFIG_INTERWORKING
8171 hs20_cancel_fetch_osu(wpa_s
);
8172 hs20_del_icon(wpa_s
, NULL
, NULL
);
8173 #endif /* CONFIG_HS20 */
8174 #endif /* CONFIG_INTERWORKING */
8176 wpa_s
->ext_mgmt_frame_handling
= 0;
8177 wpa_s
->ext_eapol_frame_io
= 0;
8178 #ifdef CONFIG_TESTING_OPTIONS
8179 wpa_s
->extra_roc_dur
= 0;
8180 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
8181 wpa_s
->p2p_go_csa_on_inv
= 0;
8182 wpa_s
->ignore_auth_resp
= 0;
8183 wpa_s
->ignore_assoc_disallow
= 0;
8184 wpa_s
->disable_sa_query
= 0;
8185 wpa_s
->testing_resend_assoc
= 0;
8186 wpa_s
->ignore_sae_h2e_only
= 0;
8187 wpa_s
->reject_btm_req_reason
= 0;
8188 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
8189 os_free(wpa_s
->get_pref_freq_list_override
);
8190 wpa_s
->get_pref_freq_list_override
= NULL
;
8191 wpabuf_free(wpa_s
->sae_commit_override
);
8192 wpa_s
->sae_commit_override
= NULL
;
8193 os_free(wpa_s
->extra_sae_rejected_groups
);
8194 wpa_s
->extra_sae_rejected_groups
= NULL
;
8195 wpabuf_free(wpa_s
->rsne_override_eapol
);
8196 wpa_s
->rsne_override_eapol
= NULL
;
8197 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
8198 wpa_s
->rsnxe_override_assoc
= NULL
;
8199 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
8200 wpa_s
->rsnxe_override_eapol
= NULL
;
8201 wpas_clear_driver_signal_override(wpa_s
);
8203 os_free(wpa_s
->dpp_config_obj_override
);
8204 wpa_s
->dpp_config_obj_override
= NULL
;
8205 os_free(wpa_s
->dpp_discovery_override
);
8206 wpa_s
->dpp_discovery_override
= NULL
;
8207 os_free(wpa_s
->dpp_groups_override
);
8208 wpa_s
->dpp_groups_override
= NULL
;
8209 dpp_test
= DPP_TEST_DISABLED
;
8210 #endif /* CONFIG_DPP */
8211 #endif /* CONFIG_TESTING_OPTIONS */
8213 wpa_s
->disconnected
= 0;
8214 os_free(wpa_s
->next_scan_freqs
);
8215 wpa_s
->next_scan_freqs
= NULL
;
8216 os_memset(wpa_s
->next_scan_bssid
, 0, ETH_ALEN
);
8217 wpa_s
->next_scan_bssid_wildcard_ssid
= 0;
8218 os_free(wpa_s
->select_network_scan_freqs
);
8219 wpa_s
->select_network_scan_freqs
= NULL
;
8221 wpa_bss_flush(wpa_s
);
8222 if (!dl_list_empty(&wpa_s
->bss
)) {
8223 wpa_printf(MSG_DEBUG
,
8224 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8225 MACSTR
" pending_bssid=" MACSTR
,
8226 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
8227 MAC2STR(wpa_s
->bssid
),
8228 MAC2STR(wpa_s
->pending_bssid
));
8231 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
8232 wpa_s
->wnmsleep_used
= 0;
8235 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
8236 wpa_s
->sme
.auth_alg
= 0;
8237 #endif /* CONFIG_SME */
8239 wpabuf_free(wpa_s
->ric_ies
);
8240 wpa_s
->ric_ies
= NULL
;
8242 wpa_supplicant_update_channel_list(wpa_s
, NULL
);
8244 free_bss_tmp_disallowed(wpa_s
);
8248 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
8249 char *buf
, size_t buflen
)
8251 struct wpa_radio_work
*work
;
8253 struct os_reltime now
, diff
;
8258 os_get_reltime(&now
);
8260 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8264 os_reltime_sub(&now
, &work
->time
, &diff
);
8265 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
8266 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
8267 work
->started
, diff
.sec
, diff
.usec
);
8268 if (os_snprintf_error(end
- pos
, ret
))
8277 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
8279 struct wpa_radio_work
*work
= eloop_ctx
;
8280 struct wpa_external_work
*ework
= work
->ctx
;
8282 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
8283 "Timing out external radio work %u (%s)",
8284 ework
->id
, work
->type
);
8285 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
8286 work
->wpa_s
->ext_work_in_progress
= 0;
8287 radio_work_done(work
);
8292 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
8294 struct wpa_external_work
*ework
= work
->ctx
;
8298 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8302 * work->type points to a buffer in ework, so need to replace
8303 * that here with a fixed string to avoid use of freed memory
8306 work
->type
= "freed-ext-work";
8312 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
8313 ework
->id
, ework
->type
);
8314 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
8315 work
->wpa_s
->ext_work_in_progress
= 1;
8316 if (!ework
->timeout
)
8317 ework
->timeout
= 10;
8318 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
8323 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
8324 char *buf
, size_t buflen
)
8326 struct wpa_external_work
*ework
;
8330 unsigned int freq
= 0;
8332 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8334 ework
= os_zalloc(sizeof(*ework
));
8338 pos
= os_strchr(cmd
, ' ');
8340 type_len
= pos
- cmd
;
8343 pos2
= os_strstr(pos
, "freq=");
8345 freq
= atoi(pos2
+ 5);
8347 pos2
= os_strstr(pos
, "timeout=");
8349 ework
->timeout
= atoi(pos2
+ 8);
8351 type_len
= os_strlen(cmd
);
8353 if (4 + type_len
>= sizeof(ework
->type
))
8354 type_len
= sizeof(ework
->type
) - 4 - 1;
8355 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
8356 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
8357 ework
->type
[4 + type_len
] = '\0';
8359 wpa_s
->ext_work_id
++;
8360 if (wpa_s
->ext_work_id
== 0)
8361 wpa_s
->ext_work_id
++;
8362 ework
->id
= wpa_s
->ext_work_id
;
8364 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
8370 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
8371 if (os_snprintf_error(buflen
, ret
))
8377 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
8379 struct wpa_radio_work
*work
;
8380 unsigned int id
= atoi(cmd
);
8382 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8384 struct wpa_external_work
*ework
;
8386 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8389 if (id
&& ework
->id
!= id
)
8391 wpa_dbg(wpa_s
, MSG_DEBUG
,
8392 "Completed external radio work %u (%s)",
8393 ework
->id
, ework
->type
);
8394 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
8395 wpa_s
->ext_work_in_progress
= 0;
8396 radio_work_done(work
);
8398 return 3; /* "OK\n" */
8405 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
8406 char *buf
, size_t buflen
)
8408 if (os_strcmp(cmd
, "show") == 0)
8409 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
8410 if (os_strncmp(cmd
, "add ", 4) == 0)
8411 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
8412 if (os_strncmp(cmd
, "done ", 5) == 0)
8413 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
8418 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
8420 struct wpa_radio_work
*work
, *tmp
;
8422 if (!wpa_s
|| !wpa_s
->radio
)
8425 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
8426 struct wpa_radio_work
, list
) {
8427 struct wpa_external_work
*ework
;
8429 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8432 wpa_dbg(wpa_s
, MSG_DEBUG
,
8433 "Flushing%s external radio work %u (%s)",
8434 work
->started
? " started" : "", ework
->id
,
8437 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8439 radio_work_done(work
);
8445 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8447 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8448 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8452 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8453 unsigned int *scan_id_count
, int scan_id
[])
8455 const char *pos
= value
;
8458 if (*pos
== ' ' || *pos
== '\0')
8460 if (*scan_id_count
== MAX_SCAN_ID
)
8462 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8463 pos
= os_strchr(pos
, ',');
8472 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8473 char *reply
, int reply_size
, int *reply_len
)
8476 unsigned int manual_scan_passive
= 0;
8477 unsigned int manual_scan_use_id
= 0;
8478 unsigned int manual_scan_only_new
= 0;
8479 unsigned int scan_only
= 0;
8480 unsigned int scan_id_count
= 0;
8481 int scan_id
[MAX_SCAN_ID
];
8482 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8483 struct wpa_scan_results
*scan_res
);
8484 int *manual_scan_freqs
= NULL
;
8485 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8486 unsigned int ssid_count
= 0;
8488 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8493 if (radio_work_pending(wpa_s
, "scan")) {
8494 wpa_printf(MSG_DEBUG
,
8495 "Pending scan scheduled - reject new request");
8496 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8500 #ifdef CONFIG_INTERWORKING
8501 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8502 wpa_printf(MSG_DEBUG
,
8503 "Interworking select in progress - reject new scan");
8504 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8507 #endif /* CONFIG_INTERWORKING */
8510 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8513 pos
= os_strstr(params
, "freq=");
8515 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8517 if (manual_scan_freqs
== NULL
) {
8523 pos
= os_strstr(params
, "passive=");
8525 manual_scan_passive
= !!atoi(pos
+ 8);
8527 pos
= os_strstr(params
, "use_id=");
8529 manual_scan_use_id
= atoi(pos
+ 7);
8531 pos
= os_strstr(params
, "only_new=1");
8533 manual_scan_only_new
= 1;
8535 pos
= os_strstr(params
, "scan_id=");
8536 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8542 pos
= os_strstr(params
, "bssid=");
8547 if (hwaddr_aton(pos
, bssid
)) {
8548 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8552 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8554 wpa_s
->next_scan_bssid_wildcard_ssid
=
8555 os_strstr(params
, "wildcard_ssid=1") != NULL
;
8559 while (pos
&& *pos
!= '\0') {
8560 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8566 if (*end
== '\0' || *end
== ' ')
8571 ns
= os_realloc_array(
8572 ssid
, ssid_count
+ 1,
8573 sizeof(struct wpa_ssid_value
));
8580 if ((end
- pos
) & 0x01 ||
8581 end
- pos
> 2 * SSID_MAX_LEN
||
8582 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8583 (end
- pos
) / 2) < 0) {
8584 wpa_printf(MSG_DEBUG
,
8585 "Invalid SSID value '%s'",
8590 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8591 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8592 ssid
[ssid_count
].ssid
,
8593 ssid
[ssid_count
].ssid_len
);
8598 pos
= os_strchr(pos
, ' ');
8604 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8605 os_free(wpa_s
->ssids_from_scan_req
);
8607 wpa_s
->ssids_from_scan_req
= ssid
;
8610 wpa_s
->ssids_from_scan_req
= NULL
;
8614 scan_res_handler
= scan_only_handler
;
8615 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8616 scan_res_handler
= NULL
;
8618 scan_res_handler
= wpa_s
->scan_res_handler
;
8620 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8621 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8622 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8623 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8624 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8625 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8626 wpa_s
->scan_id_count
= scan_id_count
;
8627 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8628 wpa_s
->scan_res_handler
= scan_res_handler
;
8629 os_free(wpa_s
->manual_scan_freqs
);
8630 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8631 manual_scan_freqs
= NULL
;
8633 wpa_s
->normal_scans
= 0;
8634 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8635 wpa_s
->after_wps
= 0;
8636 wpa_s
->known_wps_freq
= 0;
8637 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8638 if (wpa_s
->manual_scan_use_id
) {
8639 wpa_s
->manual_scan_id
++;
8640 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8641 wpa_s
->manual_scan_id
);
8642 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8643 wpa_s
->manual_scan_id
);
8645 } else if (wpa_s
->sched_scanning
) {
8646 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8647 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8648 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8649 wpa_s
->scan_id_count
= scan_id_count
;
8650 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8651 wpa_s
->scan_res_handler
= scan_res_handler
;
8652 os_free(wpa_s
->manual_scan_freqs
);
8653 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8654 manual_scan_freqs
= NULL
;
8656 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8657 wpa_supplicant_cancel_sched_scan(wpa_s
);
8658 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8659 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8660 if (wpa_s
->manual_scan_use_id
) {
8661 wpa_s
->manual_scan_id
++;
8662 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8663 wpa_s
->manual_scan_id
);
8664 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8665 wpa_s
->manual_scan_id
);
8668 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8669 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8673 os_free(manual_scan_freqs
);
8678 #ifdef CONFIG_TESTING_OPTIONS
8680 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8681 unsigned int freq
, const u8
*dst
,
8682 const u8
*src
, const u8
*bssid
,
8683 const u8
*data
, size_t data_len
,
8684 enum offchannel_send_action_result
8687 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8688 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8689 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8690 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8691 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8692 "NO_ACK" : "FAILED"));
8696 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8700 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8702 int freq
= 0, no_cck
= 0, wait_time
= 0;
8704 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8705 * <action=Action frame payload> */
8707 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8710 used
= hwaddr_aton2(pos
, da
);
8716 used
= hwaddr_aton2(pos
, bssid
);
8721 param
= os_strstr(pos
, " freq=");
8727 param
= os_strstr(pos
, " no_cck=");
8730 no_cck
= atoi(param
);
8733 param
= os_strstr(pos
, " wait_time=");
8736 wait_time
= atoi(param
);
8739 param
= os_strstr(pos
, " action=");
8744 len
= os_strlen(param
);
8749 buf
= os_malloc(len
);
8753 if (hexstr2bin(param
, buf
, len
) < 0) {
8758 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8759 buf
, len
, wait_time
,
8760 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8766 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8768 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8769 offchannel_send_action_done(wpa_s
);
8773 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8779 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8780 union wpa_event_data event
;
8782 if (!wpa_s
->ext_mgmt_frame_handling
)
8785 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8787 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8790 param
= os_strstr(pos
, "freq=");
8796 param
= os_strstr(pos
, " datarate=");
8799 datarate
= atoi(param
);
8802 param
= os_strstr(pos
, " ssi_signal=");
8805 ssi_signal
= atoi(param
);
8808 param
= os_strstr(pos
, " frame=");
8813 len
= os_strlen(param
);
8818 buf
= os_malloc(len
);
8822 if (hexstr2bin(param
, buf
, len
) < 0) {
8827 os_memset(&event
, 0, sizeof(event
));
8828 event
.rx_mgmt
.freq
= freq
;
8829 event
.rx_mgmt
.frame
= buf
;
8830 event
.rx_mgmt
.frame_len
= len
;
8831 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8832 event
.rx_mgmt
.datarate
= datarate
;
8833 wpa_s
->ext_mgmt_frame_handling
= 0;
8834 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8835 wpa_s
->ext_mgmt_frame_handling
= 1;
8843 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8846 struct wpa_scan_res
*res
;
8847 struct os_reltime now
;
8854 if (os_strcmp(param
, "START") == 0) {
8855 wpa_bss_update_start(wpa_s
);
8859 if (os_strcmp(param
, "END") == 0) {
8860 wpa_bss_update_end(wpa_s
, NULL
, 1);
8864 if (os_strncmp(param
, "BSS ", 4) != 0)
8868 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8872 pos
= os_strstr(param
, " flags=");
8874 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8876 pos
= os_strstr(param
, " bssid=");
8877 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8880 pos
= os_strstr(param
, " freq=");
8882 res
->freq
= atoi(pos
+ 6);
8884 pos
= os_strstr(param
, " beacon_int=");
8886 res
->beacon_int
= atoi(pos
+ 12);
8888 pos
= os_strstr(param
, " caps=");
8890 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8892 pos
= os_strstr(param
, " qual=");
8894 res
->qual
= atoi(pos
+ 6);
8896 pos
= os_strstr(param
, " noise=");
8898 res
->noise
= atoi(pos
+ 7);
8900 pos
= os_strstr(param
, " level=");
8902 res
->level
= atoi(pos
+ 7);
8904 pos
= os_strstr(param
, " tsf=");
8906 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8908 pos
= os_strstr(param
, " age=");
8910 res
->age
= atoi(pos
+ 5);
8912 pos
= os_strstr(param
, " est_throughput=");
8914 res
->est_throughput
= atoi(pos
+ 16);
8916 pos
= os_strstr(param
, " snr=");
8918 res
->snr
= atoi(pos
+ 5);
8920 pos
= os_strstr(param
, " parent_tsf=");
8922 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8924 pos
= os_strstr(param
, " tsf_bssid=");
8925 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8928 pos
= os_strstr(param
, " ie=");
8931 end
= os_strchr(pos
, ' ');
8933 end
= pos
+ os_strlen(pos
);
8934 res
->ie_len
= (end
- pos
) / 2;
8935 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8939 pos
= os_strstr(param
, " beacon_ie=");
8942 end
= os_strchr(pos
, ' ');
8944 end
= pos
+ os_strlen(pos
);
8945 res
->beacon_ie_len
= (end
- pos
) / 2;
8946 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8947 res
->beacon_ie_len
))
8951 os_get_reltime(&now
);
8952 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8961 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8964 union wpa_event_data event
;
8965 enum wpa_event_type ev
;
8967 /* <event name> [parameters..] */
8969 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8972 param
= os_strchr(pos
, ' ');
8976 os_memset(&event
, 0, sizeof(event
));
8978 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8979 ev
= EVENT_INTERFACE_ENABLED
;
8980 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8981 ev
= EVENT_INTERFACE_DISABLED
;
8982 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8983 ev
= EVENT_AVOID_FREQUENCIES
;
8986 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8988 wpa_supplicant_event(wpa_s
, ev
, &event
);
8989 os_free(event
.freq_range
.range
);
8991 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8992 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8994 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8999 wpa_supplicant_event(wpa_s
, ev
, &event
);
9005 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
9008 u8 src
[ETH_ALEN
], *buf
;
9012 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
9015 used
= hwaddr_aton2(pos
, src
);
9022 len
= os_strlen(pos
);
9027 buf
= os_malloc(len
);
9031 if (hexstr2bin(pos
, buf
, len
) < 0) {
9036 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
9043 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
9047 const u16
*pos
= buf
;
9049 for (i
= 0; i
< len
/ 2; i
++)
9053 sum
= (sum
& 0xffff) + (sum
>> 16);
9055 return sum
^ 0xffff;
9059 #define HWSIM_PACKETLEN 1500
9060 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9062 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
9065 struct wpa_supplicant
*wpa_s
= ctx
;
9066 const struct ether_header
*eth
;
9072 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
9073 wpa_printf(MSG_DEBUG
,
9074 "test data: RX - ignore unexpected length %d",
9079 eth
= (const struct ether_header
*) buf
;
9080 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
9081 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
9083 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 || ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
9084 wpa_printf(MSG_DEBUG
,
9085 "test data: RX - ignore unexpect IP header");
9089 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
9090 if (*pos
!= (u8
) i
) {
9091 wpa_printf(MSG_DEBUG
,
9092 "test data: RX - ignore mismatching payload");
9098 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
9099 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
9100 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
9101 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
9105 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
9108 int enabled
= atoi(cmd
);
9113 if (wpa_s
->l2_test
) {
9114 l2_packet_deinit(wpa_s
->l2_test
);
9115 wpa_s
->l2_test
= NULL
;
9116 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
9124 pos
= os_strstr(cmd
, " ifname=");
9128 ifname
= wpa_s
->ifname
;
9130 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
9131 ETHERTYPE_IP
, wpas_data_test_rx
,
9133 if (wpa_s
->l2_test
== NULL
)
9136 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
9142 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
9144 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
9149 u8 buf
[2 + HWSIM_PACKETLEN
];
9150 struct ether_header
*eth
;
9154 size_t send_len
= HWSIM_IP_LEN
;
9156 if (wpa_s
->l2_test
== NULL
)
9159 /* format: <dst> <src> <tos> [len=<length>] */
9162 used
= hwaddr_aton2(pos
, dst
);
9168 used
= hwaddr_aton2(pos
, src
);
9173 val
= strtol(pos
, &pos2
, 0);
9174 if (val
< 0 || val
> 0xff)
9178 pos
= os_strstr(pos2
, " len=");
9181 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
9186 eth
= (struct ether_header
*) &buf
[2];
9187 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
9188 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
9189 eth
->ether_type
= htons(ETHERTYPE_IP
);
9190 ip
= (struct ip
*) (eth
+ 1);
9191 os_memset(ip
, 0, sizeof(*ip
));
9196 ip
->ip_len
= htons(send_len
);
9198 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9199 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9200 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
9201 dpos
= (u8
*) (ip
+ 1);
9202 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
9205 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
9206 sizeof(struct ether_header
) + send_len
) < 0)
9209 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
9210 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
9216 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
9220 struct ether_header
*eth
;
9221 struct l2_packet_data
*l2
= NULL
;
9226 len
= os_strlen(cmd
);
9227 if (len
& 1 || len
< ETH_HLEN
* 2)
9231 buf
= os_malloc(len
);
9235 if (hexstr2bin(cmd
, buf
, len
) < 0)
9238 eth
= (struct ether_header
*) buf
;
9239 ethertype
= ntohs(eth
->ether_type
);
9241 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
9242 wpas_data_test_rx
, wpa_s
, 1);
9246 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
9247 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
9250 l2_packet_deinit(l2
);
9253 return res
< 0 ? -1 : 0;
9257 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9259 #ifdef WPA_TRACE_BFD
9262 wpa_trace_fail_after
= atoi(cmd
);
9263 pos
= os_strchr(cmd
, ':');
9266 os_strlcpy(wpa_trace_fail_func
, pos
,
9267 sizeof(wpa_trace_fail_func
));
9269 wpa_trace_fail_after
= 0;
9272 #else /* WPA_TRACE_BFD */
9274 #endif /* WPA_TRACE_BFD */
9278 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
9279 char *buf
, size_t buflen
)
9281 #ifdef WPA_TRACE_BFD
9282 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
9283 wpa_trace_fail_func
);
9284 #else /* WPA_TRACE_BFD */
9286 #endif /* WPA_TRACE_BFD */
9290 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9292 #ifdef WPA_TRACE_BFD
9295 wpa_trace_test_fail_after
= atoi(cmd
);
9296 pos
= os_strchr(cmd
, ':');
9299 os_strlcpy(wpa_trace_test_fail_func
, pos
,
9300 sizeof(wpa_trace_test_fail_func
));
9302 wpa_trace_test_fail_after
= 0;
9305 #else /* WPA_TRACE_BFD */
9307 #endif /* WPA_TRACE_BFD */
9311 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
9312 char *buf
, size_t buflen
)
9314 #ifdef WPA_TRACE_BFD
9315 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
9316 wpa_trace_test_fail_func
);
9317 #else /* WPA_TRACE_BFD */
9319 #endif /* WPA_TRACE_BFD */
9323 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
9325 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9326 int i
, count
= (intptr_t) timeout_ctx
;
9328 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
9330 for (i
= 0; i
< count
; i
++) {
9331 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
9337 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9345 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
9346 (void *) (intptr_t) count
);
9350 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
9356 len
= os_strlen(cmd
);
9364 buf
= wpabuf_alloc(len
);
9368 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
9374 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
9379 static int wpas_ctrl_reset_pn(struct wpa_supplicant
*wpa_s
)
9381 u8 zero
[WPA_TK_MAX_LEN
];
9383 if (wpa_s
->last_tk_alg
== WPA_ALG_NONE
)
9386 wpa_printf(MSG_INFO
, "TESTING: Reset PN");
9387 os_memset(zero
, 0, sizeof(zero
));
9389 /* First, use a zero key to avoid any possible duplicate key avoidance
9391 if (wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9392 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9393 zero
, wpa_s
->last_tk_len
,
9394 KEY_FLAG_PAIRWISE_RX_TX
) < 0)
9397 /* Set the previously configured key to reset its TSC/RSC */
9398 return wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9399 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9400 wpa_s
->last_tk
, wpa_s
->last_tk_len
,
9401 KEY_FLAG_PAIRWISE_RX_TX
);
9405 static int wpas_ctrl_key_request(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9407 const char *pos
= cmd
;
9408 int error
, pairwise
;
9411 pos
= os_strchr(pos
, ' ');
9414 pairwise
= atoi(pos
);
9415 wpa_sm_key_request(wpa_s
->wpa
, error
, pairwise
);
9420 static int wpas_ctrl_resend_assoc(struct wpa_supplicant
*wpa_s
)
9423 struct wpa_driver_associate_params params
;
9426 os_memset(¶ms
, 0, sizeof(params
));
9427 params
.bssid
= wpa_s
->bssid
;
9428 params
.ssid
= wpa_s
->sme
.ssid
;
9429 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
9430 params
.freq
.freq
= wpa_s
->sme
.freq
;
9431 if (wpa_s
->last_assoc_req_wpa_ie
) {
9432 params
.wpa_ie
= wpabuf_head(wpa_s
->last_assoc_req_wpa_ie
);
9433 params
.wpa_ie_len
= wpabuf_len(wpa_s
->last_assoc_req_wpa_ie
);
9435 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
9436 params
.group_suite
= wpa_s
->group_cipher
;
9437 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
9438 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
9439 params
.wpa_proto
= wpa_s
->wpa_proto
;
9440 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
9441 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
9442 if (wpa_s
->sme
.prev_bssid_set
)
9443 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
9444 wpa_printf(MSG_INFO
, "TESTING: Resend association request");
9445 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
9446 wpa_s
->testing_resend_assoc
= 1;
9448 #else /* CONFIG_SME */
9450 #endif /* CONFIG_SME */
9453 #endif /* CONFIG_TESTING_OPTIONS */
9456 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
9462 struct ieee802_11_elems elems
;
9465 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9467 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9469 pos
= os_strchr(pos
, ' ');
9474 len
= os_strlen(pos
);
9481 buf
= wpabuf_alloc(len
);
9485 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
9490 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
9496 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
9497 wpa_s
->vendor_elem
[frame
] = buf
;
9498 wpas_vendor_elem_update(wpa_s
);
9502 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
9507 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
9509 wpas_vendor_elem_update(wpa_s
);
9515 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
9516 char *buf
, size_t buflen
)
9518 int frame
= atoi(cmd
);
9520 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9522 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9524 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9527 return wpa_snprintf_hex(buf
, buflen
,
9528 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
9529 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
9533 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
9539 struct ieee802_11_elems elems
;
9543 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9545 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9547 pos
= os_strchr(pos
, ' ');
9553 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9554 wpa_s
->vendor_elem
[frame
] = NULL
;
9555 wpas_vendor_elem_update(wpa_s
);
9559 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9562 len
= os_strlen(pos
);
9569 buf
= os_malloc(len
);
9573 if (hexstr2bin(pos
, buf
, len
) < 0) {
9578 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9583 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9589 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9591 struct wpa_supplicant
*wpa_s
= ctx
;
9596 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9598 * BSSID Information[4]
9599 * Operating Class[1]
9602 * Optional Subelements[variable]
9604 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9606 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9607 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9611 data
= wpabuf_head_u8(neighbor_rep
);
9612 len
= wpabuf_len(neighbor_rep
);
9614 while (len
>= 2 + NR_IE_MIN_LEN
) {
9616 char lci
[256 * 2 + 1];
9617 char civic
[256 * 2 + 1];
9618 u8 nr_len
= data
[1];
9619 const u8
*pos
= data
, *end
;
9621 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9622 nr_len
< NR_IE_MIN_LEN
) {
9623 wpa_dbg(wpa_s
, MSG_DEBUG
,
9624 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9629 if (2U + nr_len
> len
) {
9630 wpa_dbg(wpa_s
, MSG_DEBUG
,
9631 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9632 data
[0], len
, nr_len
);
9639 pos
+= NR_IE_MIN_LEN
;
9643 while (end
- pos
> 2) {
9648 if (s_len
> end
- pos
)
9650 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9651 /* Measurement Token[1] */
9652 /* Measurement Report Mode[1] */
9653 /* Measurement Type[1] */
9654 /* Measurement Report[variable] */
9656 case MEASURE_TYPE_LCI
:
9659 wpa_snprintf_hex(lci
, sizeof(lci
),
9662 case MEASURE_TYPE_LOCATION_CIVIC
:
9665 wpa_snprintf_hex(civic
, sizeof(civic
),
9674 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9676 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9677 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9678 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9680 lci
[0] ? " lci=" : "", lci
,
9681 civic
[0] ? " civic=" : "", civic
);
9688 wpabuf_free(neighbor_rep
);
9692 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9695 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9696 int ret
, lci
= 0, civic
= 0;
9699 ssid_s
= os_strstr(cmd
, "ssid=");
9701 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9702 wpa_msg(wpa_s
, MSG_INFO
,
9703 "CTRL: Send Neighbor Report: bad SSID");
9710 * Move cmd after the SSID text that may include "lci" or
9713 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9719 if (cmd
&& os_strstr(cmd
, "lci"))
9722 if (cmd
&& os_strstr(cmd
, "civic"))
9725 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9726 wpas_ctrl_neighbor_rep_cb
,
9733 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9735 eapol_sm_erp_flush(wpa_s
->eapol
);
9740 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9743 char *token
, *context
= NULL
;
9744 unsigned int enable
= ~0, type
= 0;
9745 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9746 u8
*addr
= NULL
, *mask
= NULL
;
9748 while ((token
= str_token(cmd
, " ", &context
))) {
9749 if (os_strcasecmp(token
, "scan") == 0) {
9750 type
|= MAC_ADDR_RAND_SCAN
;
9751 } else if (os_strcasecmp(token
, "sched") == 0) {
9752 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9753 } else if (os_strcasecmp(token
, "pno") == 0) {
9754 type
|= MAC_ADDR_RAND_PNO
;
9755 } else if (os_strcasecmp(token
, "all") == 0) {
9756 type
= wpa_s
->mac_addr_rand_supported
;
9757 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9758 enable
= atoi(token
+ 7);
9759 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9761 if (hwaddr_aton(token
+ 5, addr
)) {
9762 wpa_printf(MSG_INFO
,
9763 "CTRL: Invalid MAC address: %s",
9767 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9769 if (hwaddr_aton(token
+ 5, mask
)) {
9770 wpa_printf(MSG_INFO
,
9771 "CTRL: Invalid MAC address mask: %s",
9776 wpa_printf(MSG_INFO
,
9777 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9784 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9789 wpa_printf(MSG_INFO
,
9790 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9795 return wpas_disable_mac_addr_randomization(wpa_s
, type
);
9797 return wpas_enable_mac_addr_randomization(wpa_s
, type
, addr
, mask
);
9801 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9802 char *buf
, size_t buflen
)
9806 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9808 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9809 buflen
- reply_len
);
9810 #endif /* CONFIG_AP */
9815 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9817 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9819 wpas_ap_pmksa_cache_flush(wpa_s
);
9820 #endif /* CONFIG_AP */
9824 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9826 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9827 const char *cmd
, char *buf
, size_t buflen
)
9829 struct rsn_pmksa_cache_entry
*entry
;
9830 struct wpa_ssid
*ssid
;
9831 char *pos
, *pos2
, *end
;
9833 struct os_reltime now
;
9835 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9842 os_get_reltime(&now
);
9846 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9847 * <expiration in seconds> <akmp> <opportunistic>
9848 * [FILS Cache Identifier]
9851 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9852 entry
= entry
->next
) {
9853 if (entry
->network_ctx
!= ssid
)
9857 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9858 MAC2STR(entry
->aa
));
9859 if (os_snprintf_error(end
- pos2
, ret
))
9863 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9866 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9867 if (os_snprintf_error(end
- pos2
, ret
))
9871 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9874 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9875 (int) (entry
->reauth_time
- now
.sec
),
9876 (int) (entry
->expiration
- now
.sec
),
9878 entry
->opportunistic
);
9879 if (os_snprintf_error(end
- pos2
, ret
))
9883 if (entry
->fils_cache_id_set
) {
9884 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9885 entry
->fils_cache_id
[0],
9886 entry
->fils_cache_id
[1]);
9887 if (os_snprintf_error(end
- pos2
, ret
))
9892 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9893 if (os_snprintf_error(end
- pos2
, ret
))
9904 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9907 struct rsn_pmksa_cache_entry
*entry
;
9908 struct wpa_ssid
*ssid
;
9911 struct os_reltime now
;
9912 int reauth_time
= 0, expiration
= 0, i
;
9916 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9917 * <expiration in seconds> <akmp> <opportunistic>
9918 * [FILS Cache Identifier]
9921 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9925 pos
= os_strchr(cmd
, ' ');
9930 entry
= os_zalloc(sizeof(*entry
));
9934 if (hwaddr_aton(pos
, entry
->aa
))
9937 pos
= os_strchr(pos
, ' ');
9942 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9945 pos
= os_strchr(pos
, ' ');
9950 pos2
= os_strchr(pos
, ' ');
9953 entry
->pmk_len
= (pos2
- pos
) / 2;
9954 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9955 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9958 pos
= os_strchr(pos
, ' ');
9963 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9964 &entry
->akmp
, &entry
->opportunistic
) != 4)
9966 for (i
= 0; i
< 4; i
++) {
9967 pos
= os_strchr(pos
, ' ');
9976 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9977 FILS_CACHE_ID_LEN
) < 0)
9979 entry
->fils_cache_id_set
= 1;
9981 os_get_reltime(&now
);
9982 entry
->expiration
= now
.sec
+ expiration
;
9983 entry
->reauth_time
= now
.sec
+ reauth_time
;
9985 entry
->network_ctx
= ssid
;
9987 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9998 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9999 const char *cmd
, char *buf
,
10007 if (os_strcasecmp(cmd
, "any") == 0)
10008 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
10010 if (hwaddr_aton(cmd
, spa
))
10013 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
10017 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
10021 * We do not check mesh interface existance because PMKSA should be
10022 * stored before wpa_s->ifmsh creation to suppress commit message
10025 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
10028 #endif /* CONFIG_MESH */
10029 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10033 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
10036 struct fils_hlp_req
*req
;
10039 /* format: <dst> <packet starting from ethertype> */
10041 req
= os_zalloc(sizeof(*req
));
10045 if (hwaddr_aton(cmd
, req
->dst
))
10048 pos
= os_strchr(cmd
, ' ');
10052 req
->pkt
= wpabuf_parse_bin(pos
);
10056 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
10059 wpabuf_free(req
->pkt
);
10063 #endif /* CONFIG_FILS */
10066 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
10068 if (os_strcmp(cmd
, "PING") == 0 ||
10069 os_strncmp(cmd
, "BSS ", 4) == 0 ||
10070 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
10071 os_strncmp(cmd
, "STATUS", 6) == 0 ||
10072 os_strncmp(cmd
, "STA ", 4) == 0 ||
10073 os_strncmp(cmd
, "STA-", 4) == 0)
10074 return MSG_EXCESSIVE
;
10079 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
10080 char *buf
, size_t *resp_len
)
10083 const int reply_size
= 4096;
10086 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
10087 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
10088 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
10089 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10090 if (wpa_debug_show_keys
)
10091 wpa_dbg(wpa_s
, MSG_DEBUG
,
10092 "Control interface command '%s'", buf
);
10094 wpa_dbg(wpa_s
, MSG_DEBUG
,
10095 "Control interface command '%s [REMOVED]'",
10096 os_strncmp(buf
, WPA_CTRL_RSP
,
10097 os_strlen(WPA_CTRL_RSP
)) == 0 ?
10099 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
10100 "SET_NETWORK" : "key-add"));
10101 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
10102 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
10103 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
10104 (const u8
*) buf
, os_strlen(buf
));
10106 int level
= wpas_ctrl_cmd_debug_level(buf
);
10107 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
10110 reply
= os_malloc(reply_size
);
10111 if (reply
== NULL
) {
10116 os_memcpy(reply
, "OK\n", 3);
10119 if (os_strcmp(buf
, "PING") == 0) {
10120 os_memcpy(reply
, "PONG\n", 5);
10122 } else if (os_strcmp(buf
, "IFNAME") == 0) {
10123 reply_len
= os_strlen(wpa_s
->ifname
);
10124 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
10125 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10126 if (wpa_debug_reopen_file() < 0)
10128 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
10129 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
10130 } else if (os_strcmp(buf
, "MIB") == 0) {
10131 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
10132 if (reply_len
>= 0) {
10133 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
10135 reply_size
- reply_len
);
10136 #ifdef CONFIG_MACSEC
10137 reply_len
+= ieee802_1x_kay_get_mib(
10138 wpa_s
->kay
, reply
+ reply_len
,
10139 reply_size
- reply_len
);
10140 #endif /* CONFIG_MACSEC */
10142 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
10143 reply_len
= wpa_supplicant_ctrl_iface_status(
10144 wpa_s
, buf
+ 6, reply
, reply_size
);
10145 } else if (os_strcmp(buf
, "PMKSA") == 0) {
10146 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
10147 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
10148 wpas_ctrl_iface_pmksa_flush(wpa_s
);
10149 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10150 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
10151 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
10152 reply
, reply_size
);
10153 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
10154 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
10157 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
10158 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
10159 reply
, reply_size
);
10160 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10161 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
10163 #endif /* CONFIG_MESH */
10164 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10165 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10166 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
10168 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
10169 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
10170 reply
, reply_size
);
10171 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
10172 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
10173 reply
, reply_size
);
10174 } else if (os_strcmp(buf
, "LOGON") == 0) {
10175 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
10176 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
10177 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
10178 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
10179 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10182 wpas_request_connection(wpa_s
);
10183 } else if (os_strcmp(buf
, "REATTACH") == 0) {
10184 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
10185 !wpa_s
->current_ssid
)
10188 wpa_s
->reattach
= 1;
10189 wpas_request_connection(wpa_s
);
10191 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
10192 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10194 else if (wpa_s
->disconnected
)
10195 wpas_request_connection(wpa_s
);
10196 #ifdef IEEE8021X_EAPOL
10197 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
10198 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
10200 #endif /* IEEE8021X_EAPOL */
10201 #ifdef CONFIG_IEEE80211R
10202 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
10203 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
10205 #endif /* CONFIG_IEEE80211R */
10207 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
10208 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
10210 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10214 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
10215 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
10217 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10221 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
10222 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
10225 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
10226 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
10227 wpa_s
, buf
+ 14, reply
, reply_size
);
10228 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
10229 if (wpas_wps_cancel(wpa_s
))
10231 #ifdef CONFIG_WPS_NFC
10232 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
10233 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
10235 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
10236 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
10238 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10239 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10240 wpa_s
, buf
+ 21, reply
, reply_size
);
10241 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
10242 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
10243 wpa_s
, buf
+ 14, reply
, reply_size
);
10244 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
10245 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
10248 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10249 reply_len
= wpas_ctrl_nfc_get_handover_req(
10250 wpa_s
, buf
+ 21, reply
, reply_size
);
10251 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10252 reply_len
= wpas_ctrl_nfc_get_handover_sel(
10253 wpa_s
, buf
+ 21, reply
, reply_size
);
10254 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
10255 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
10257 #endif /* CONFIG_WPS_NFC */
10258 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
10259 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
10262 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
10263 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
10264 wpa_s
, buf
+ 11, reply
, reply_size
);
10265 #endif /* CONFIG_AP */
10266 #ifdef CONFIG_WPS_ER
10267 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
10268 if (wpas_wps_er_start(wpa_s
, NULL
))
10270 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
10271 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
10273 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
10274 wpas_wps_er_stop(wpa_s
);
10275 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
10276 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
10278 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
10279 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
10281 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10283 } else if (ret
== -3) {
10284 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
10286 } else if (ret
== -4) {
10287 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
10291 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
10292 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
10294 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
10295 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
10298 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
10299 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
10301 #ifdef CONFIG_WPS_NFC
10302 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10303 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10304 wpa_s
, buf
+ 24, reply
, reply_size
);
10305 #endif /* CONFIG_WPS_NFC */
10306 #endif /* CONFIG_WPS_ER */
10307 #endif /* CONFIG_WPS */
10308 #ifdef CONFIG_IBSS_RSN
10309 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
10310 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
10312 #endif /* CONFIG_IBSS_RSN */
10314 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
10315 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10316 wpa_s
, buf
+ 19, reply
, reply_size
);
10317 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
10318 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10319 wpa_s
, "", reply
, reply_size
);
10320 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
10321 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
10323 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
10324 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
10327 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
10328 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
10330 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
10331 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
10333 } else if (os_strncmp(buf
, "MESH_LINK_PROBE ", 16) == 0) {
10334 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s
, buf
+ 16))
10336 #endif /* CONFIG_MESH */
10338 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
10339 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
10341 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
10342 if (p2p_ctrl_find(wpa_s
, ""))
10344 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
10345 wpas_p2p_stop_find(wpa_s
);
10346 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
10347 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
10349 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10350 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
10352 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
10353 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
10355 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
10356 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
10358 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
10359 if (p2p_ctrl_listen(wpa_s
, ""))
10361 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
10362 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
10364 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
10365 if (p2p_ctrl_group_add(wpa_s
, ""))
10367 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
10368 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
10370 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
10371 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
10373 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
10374 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
10376 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
10377 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
10378 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
10379 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
10381 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10382 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
10384 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
10385 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
10387 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
10388 wpas_p2p_sd_service_update(wpa_s
);
10389 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10390 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
10392 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
10393 wpas_p2p_service_flush(wpa_s
);
10394 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
10395 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
10397 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
10398 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
10400 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
10401 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
10403 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
10404 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
10406 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
10407 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
10409 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
10410 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
10412 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
10413 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
10415 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
10416 p2p_ctrl_flush(wpa_s
);
10417 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
10418 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
10420 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
10421 if (wpas_p2p_cancel(wpa_s
))
10423 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
10424 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
10426 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
10427 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
10429 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
10430 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
10432 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
10433 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
10435 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
10436 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
10438 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
10439 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
10441 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
10442 if (wpas_p2p_lo_stop(wpa_s
))
10444 #endif /* CONFIG_P2P */
10445 #ifdef CONFIG_WIFI_DISPLAY
10446 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
10447 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
10449 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
10450 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
10451 reply
, reply_size
);
10452 #endif /* CONFIG_WIFI_DISPLAY */
10453 #ifdef CONFIG_INTERWORKING
10454 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
10455 if (interworking_fetch_anqp(wpa_s
) < 0)
10457 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
10458 interworking_stop_fetch_anqp(wpa_s
);
10459 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
10460 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
10462 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
10463 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
10465 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
10466 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
10468 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10471 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
10475 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
10476 if (os_snprintf_error(reply_size
, reply_len
))
10479 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
10480 if (get_anqp(wpa_s
, buf
+ 9) < 0)
10482 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
10483 if (gas_request(wpa_s
, buf
+ 12) < 0)
10485 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
10486 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
10488 #endif /* CONFIG_INTERWORKING */
10490 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10491 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10493 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10494 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10496 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10497 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10499 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10500 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10502 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10503 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10504 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10505 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10507 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10508 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10510 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10511 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10513 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10514 hs20_cancel_fetch_osu(wpa_s
);
10515 #endif /* CONFIG_HS20 */
10516 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10518 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10519 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10523 * Notify response from timeout to allow the control
10524 * interface response to be sent first.
10526 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10529 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10530 if (wpa_supplicant_reload_configuration(wpa_s
))
10532 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10533 wpa_supplicant_terminate_proc(wpa_s
->global
);
10534 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10535 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10537 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10538 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10539 wpa_s
, buf
+ 9, reply
, reply_size
);
10540 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10541 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10542 wpa_s
, buf
+ 9, reply
, reply_size
);
10543 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10544 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10545 wpa_s
, buf
+ 14, reply
, reply_size
);
10546 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10547 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10548 wpa_s
, NULL
, reply
, reply_size
);
10549 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10550 wpas_request_disconnection(wpa_s
);
10551 } else if (os_strcmp(buf
, "SCAN") == 0) {
10552 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10553 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10554 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10555 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10556 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10557 wpa_s
, reply
, reply_size
);
10558 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10559 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10561 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10562 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10564 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10565 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10567 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10568 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10570 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10571 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10572 wpa_s
, reply
, reply_size
);
10573 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10574 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10576 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10577 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10579 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10580 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10581 wpa_s
, buf
+ 12, reply
, reply_size
);
10582 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10583 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10586 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10587 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10588 wpa_s
, reply
, reply_size
);
10589 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10590 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10591 wpa_s
, reply
, reply_size
);
10592 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10593 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10595 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10596 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10598 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10599 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10602 #ifndef CONFIG_NO_CONFIG_WRITE
10603 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10604 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10606 #endif /* CONFIG_NO_CONFIG_WRITE */
10607 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10608 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10609 wpa_s
, buf
+ 15, reply
, reply_size
);
10610 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10611 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10613 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10614 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10616 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10617 reply_len
= wpa_supplicant_global_iface_list(
10618 wpa_s
->global
, reply
, reply_size
);
10619 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10620 reply_len
= wpa_supplicant_global_iface_interfaces(
10621 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10622 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10623 reply_len
= wpa_supplicant_ctrl_iface_bss(
10624 wpa_s
, buf
+ 4, reply
, reply_size
);
10626 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10627 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10628 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10629 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10631 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10632 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10634 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10635 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10637 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10638 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10640 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10641 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10643 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10644 if (wpas_ap_stop_ap(wpa_s
))
10646 #endif /* CONFIG_AP */
10647 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10648 wpas_notify_suspend(wpa_s
->global
);
10649 } else if (os_strcmp(buf
, "RESUME") == 0) {
10650 wpas_notify_resume(wpa_s
->global
);
10651 #ifdef CONFIG_TESTING_OPTIONS
10652 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10653 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10654 #endif /* CONFIG_TESTING_OPTIONS */
10655 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10656 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10658 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10659 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10660 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10661 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10663 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10664 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10667 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10668 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10670 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10671 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10673 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10674 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10676 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10677 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10679 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10680 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10683 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10684 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10687 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10688 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10689 wpa_s
, buf
+ 17, reply
, reply_size
);
10690 #endif /* CONFIG_TDLS */
10691 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10692 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10693 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10694 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10696 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10697 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10699 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10700 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10702 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10703 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10705 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10706 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10708 #ifdef CONFIG_AUTOSCAN
10709 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10710 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10712 #endif /* CONFIG_AUTOSCAN */
10713 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10714 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10717 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10718 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10720 #endif /* ANDROID */
10721 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10722 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10724 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10725 pmksa_cache_clear_current(wpa_s
->wpa
);
10726 eapol_sm_request_reauth(wpa_s
->eapol
);
10728 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10729 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10731 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10732 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10734 } else if (os_strncmp(buf
, "COLOC_INTF_REPORT ", 18) == 0) {
10735 if (wpas_ctrl_iface_coloc_intf_report(wpa_s
, buf
+ 18))
10737 #endif /* CONFIG_WNM */
10738 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10739 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10740 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10741 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10743 #ifdef CONFIG_TESTING_OPTIONS
10744 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10745 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10747 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10748 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10749 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10750 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10752 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10753 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10755 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10756 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10758 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10759 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10761 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10762 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10764 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10765 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10767 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10768 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10770 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10771 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10772 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10773 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10775 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10776 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10777 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10778 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10780 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10781 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10783 } else if (os_strcmp(buf
, "RESET_PN") == 0) {
10784 if (wpas_ctrl_reset_pn(wpa_s
) < 0)
10786 } else if (os_strncmp(buf
, "KEY_REQUEST ", 12) == 0) {
10787 if (wpas_ctrl_key_request(wpa_s
, buf
+ 12) < 0)
10789 } else if (os_strcmp(buf
, "RESEND_ASSOC") == 0) {
10790 if (wpas_ctrl_resend_assoc(wpa_s
) < 0)
10792 } else if (os_strcmp(buf
, "UNPROT_DEAUTH") == 0) {
10793 sme_event_unprot_disconnect(
10794 wpa_s
, wpa_s
->bssid
, NULL
,
10795 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
10796 #endif /* CONFIG_TESTING_OPTIONS */
10797 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10798 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10800 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10801 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10803 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10804 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10806 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10807 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10809 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10810 wpas_ctrl_iface_erp_flush(wpa_s
);
10811 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10812 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10814 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10815 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10816 wpa_s
, buf
+ 19, reply
, reply_size
);
10818 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10819 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10821 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10822 wpas_flush_fils_hlp_req(wpa_s
);
10823 #endif /* CONFIG_FILS */
10825 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10828 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10832 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10833 if (os_snprintf_error(reply_size
, reply_len
))
10836 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
10839 res
= wpas_dpp_nfc_uri(wpa_s
, buf
+ 12);
10843 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10844 if (os_snprintf_error(reply_size
, reply_len
))
10847 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
10850 res
= wpas_dpp_nfc_handover_req(wpa_s
, buf
+ 20);
10854 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10855 if (os_snprintf_error(reply_size
, reply_len
))
10858 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
10861 res
= wpas_dpp_nfc_handover_sel(wpa_s
, buf
+ 20);
10865 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10866 if (os_snprintf_error(reply_size
, reply_len
))
10869 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10872 res
= dpp_bootstrap_gen(wpa_s
->dpp
, buf
+ 18);
10876 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10877 if (os_snprintf_error(reply_size
, reply_len
))
10880 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10881 if (dpp_bootstrap_remove(wpa_s
->dpp
, buf
+ 21) < 0)
10883 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10886 uri
= dpp_bootstrap_get_uri(wpa_s
->dpp
, atoi(buf
+ 22));
10890 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10891 if (os_snprintf_error(reply_size
, reply_len
))
10894 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10895 reply_len
= dpp_bootstrap_info(wpa_s
->dpp
, atoi(buf
+ 19),
10896 reply
, reply_size
);
10897 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_SET ", 18) == 0) {
10898 if (dpp_bootstrap_set(wpa_s
->dpp
, atoi(buf
+ 18),
10899 os_strchr(buf
+ 18, ' ')) < 0)
10901 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10902 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10904 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10905 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10907 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10908 wpas_dpp_stop(wpa_s
);
10909 wpas_dpp_listen_stop(wpa_s
);
10910 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10913 res
= dpp_configurator_add(wpa_s
->dpp
, buf
+ 20);
10917 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10918 if (os_snprintf_error(reply_size
, reply_len
))
10921 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10922 if (dpp_configurator_remove(wpa_s
->dpp
, buf
+ 24) < 0)
10924 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10925 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 21) < 0)
10927 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10928 reply_len
= dpp_configurator_get_key_id(wpa_s
->dpp
,
10930 reply
, reply_size
);
10931 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10934 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10938 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10939 if (os_snprintf_error(reply_size
, reply_len
))
10942 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10943 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10946 } else if (os_strncmp(buf
, "DPP_CONTROLLER_START ", 21) == 0) {
10947 if (wpas_dpp_controller_start(wpa_s
, buf
+ 20) < 0)
10949 } else if (os_strcmp(buf
, "DPP_CONTROLLER_START") == 0) {
10950 if (wpas_dpp_controller_start(wpa_s
, NULL
) < 0)
10952 } else if (os_strcmp(buf
, "DPP_CONTROLLER_STOP") == 0) {
10953 dpp_controller_stop(wpa_s
->dpp
);
10954 } else if (os_strncmp(buf
, "DPP_CHIRP ", 10) == 0) {
10955 if (wpas_dpp_chirp(wpa_s
, buf
+ 9) < 0)
10957 } else if (os_strcmp(buf
, "DPP_STOP_CHIRP") == 0) {
10958 wpas_dpp_chirp_stop(wpa_s
);
10959 #endif /* CONFIG_DPP2 */
10960 #endif /* CONFIG_DPP */
10962 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10966 if (reply_len
< 0) {
10967 os_memcpy(reply
, "FAIL\n", 5);
10971 *resp_len
= reply_len
;
10976 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10979 struct wpa_interface iface
;
10981 struct wpa_supplicant
*wpa_s
;
10982 unsigned int create_iface
= 0;
10983 u8 mac_addr
[ETH_ALEN
];
10984 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10987 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10988 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10990 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10992 os_memset(&iface
, 0, sizeof(iface
));
10995 iface
.ifname
= pos
= cmd
;
10996 pos
= os_strchr(pos
, '\t');
10999 if (iface
.ifname
[0] == '\0')
11004 iface
.confname
= pos
;
11005 pos
= os_strchr(pos
, '\t');
11008 if (iface
.confname
[0] == '\0')
11009 iface
.confname
= NULL
;
11013 iface
.driver
= pos
;
11014 pos
= os_strchr(pos
, '\t');
11017 if (iface
.driver
[0] == '\0')
11018 iface
.driver
= NULL
;
11022 iface
.ctrl_interface
= pos
;
11023 pos
= os_strchr(pos
, '\t');
11026 if (iface
.ctrl_interface
[0] == '\0')
11027 iface
.ctrl_interface
= NULL
;
11031 iface
.driver_param
= pos
;
11032 pos
= os_strchr(pos
, '\t');
11035 if (iface
.driver_param
[0] == '\0')
11036 iface
.driver_param
= NULL
;
11040 iface
.bridge_ifname
= pos
;
11041 pos
= os_strchr(pos
, '\t');
11044 if (iface
.bridge_ifname
[0] == '\0')
11045 iface
.bridge_ifname
= NULL
;
11050 pos
= os_strchr(pos
, '\t');
11056 if (os_strcmp(extra
, "create") == 0) {
11061 if (os_strcmp(pos
, "sta") == 0) {
11062 type
= WPA_IF_STATION
;
11063 } else if (os_strcmp(pos
, "ap") == 0) {
11064 type
= WPA_IF_AP_BSS
;
11066 wpa_printf(MSG_DEBUG
,
11067 "INTERFACE_ADD unsupported interface type: '%s'",
11072 wpa_printf(MSG_DEBUG
,
11073 "INTERFACE_ADD unsupported extra parameter: '%s'",
11079 if (create_iface
) {
11080 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
11082 if (!global
->ifaces
)
11084 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
11085 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
11086 wpa_printf(MSG_ERROR
,
11087 "CTRL_IFACE interface creation failed");
11091 wpa_printf(MSG_DEBUG
,
11092 "CTRL_IFACE interface '%s' created with MAC addr: "
11093 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
11096 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
11099 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
11102 wpa_s
->added_vif
= create_iface
;
11107 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
11112 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
11115 struct wpa_supplicant
*wpa_s
;
11117 unsigned int delete_iface
;
11119 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
11121 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
11124 delete_iface
= wpa_s
->added_vif
;
11125 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
11126 if (!ret
&& delete_iface
) {
11127 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
11129 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
11135 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
11137 struct wpa_interface_info
*prev
;
11141 iface
= iface
->next
;
11143 os_free(prev
->ifname
);
11144 os_free(prev
->desc
);
11150 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
11151 char *buf
, int len
)
11154 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
11157 for (i
= 0; wpa_drivers
[i
]; i
++) {
11158 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
11159 if (drv
->get_interfaces
== NULL
)
11161 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
11166 iface
= last
= tmp
;
11175 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
11176 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
11177 tmp
->drv_name
, tmp
->ifname
,
11178 tmp
->desc
? tmp
->desc
: "");
11179 if (os_snprintf_error(end
- pos
, res
)) {
11186 wpa_free_iface_info(iface
);
11192 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
11194 char *buf
, int len
)
11198 struct wpa_supplicant
*wpa_s
;
11202 show_ctrl
= !!os_strstr(input
, "ctrl");
11204 wpa_s
= global
->ifaces
;
11210 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
11212 wpa_s
->conf
->ctrl_interface
?
11213 wpa_s
->conf
->ctrl_interface
: "N/A");
11215 res
= os_snprintf(pos
, end
- pos
, "%s\n",
11218 if (os_snprintf_error(end
- pos
, res
)) {
11223 wpa_s
= wpa_s
->next
;
11229 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
11230 const char *ifname
,
11231 char *cmd
, size_t *resp_len
)
11233 struct wpa_supplicant
*wpa_s
;
11235 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11236 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
11240 if (wpa_s
== NULL
) {
11241 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
11243 *resp_len
= os_strlen(resp
);
11249 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
11253 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
11254 char *buf
, size_t *resp_len
)
11257 static const char * cmd
[] = {
11263 "P2P_GET_PASSPHRASE",
11264 "P2P_SERVICE_UPDATE",
11265 "P2P_SERVICE_FLUSH",
11268 "P2P_PRESENCE_REQ",
11272 #endif /* CONFIG_AP */
11275 static const char * prefix
[] = {
11278 #endif /* ANDROID */
11285 "P2P_GROUP_REMOVE ",
11287 "P2P_GROUP_MEMBER ",
11289 "P2P_SERV_DISC_REQ ",
11290 "P2P_SERV_DISC_CANCEL_REQ ",
11291 "P2P_SERV_DISC_RESP ",
11292 "P2P_SERV_DISC_EXTERNAL ",
11293 "P2P_SERVICE_ADD ",
11294 "P2P_SERVICE_DEL ",
11295 "P2P_SERVICE_REP ",
11300 "P2P_UNAUTHORIZE ",
11301 "P2P_PRESENCE_REQ ",
11303 "P2P_REMOVE_CLIENT ",
11305 "WPS_NFC_TAG_READ ",
11306 "NFC_GET_HANDOVER_SEL ",
11307 "NFC_GET_HANDOVER_REQ ",
11308 "NFC_REPORT_HANDOVER ",
11309 "P2P_ASP_PROVISION ",
11310 "P2P_ASP_PROVISION_RESP ",
11314 #endif /* CONFIG_AP */
11320 if (global
->p2p_init_wpa_s
== NULL
)
11323 for (i
= 0; !found
&& cmd
[i
]; i
++) {
11324 if (os_strcmp(buf
, cmd
[i
]) == 0)
11328 for (i
= 0; !found
&& prefix
[i
]; i
++) {
11329 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
11334 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11336 #endif /* CONFIG_P2P */
11341 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
11342 char *buf
, size_t *resp_len
)
11344 #ifdef CONFIG_WIFI_DISPLAY
11345 if (global
->p2p_init_wpa_s
== NULL
)
11347 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
11348 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
11349 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11351 #endif /* CONFIG_WIFI_DISPLAY */
11356 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
11357 char *buf
, size_t *resp_len
)
11361 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
11365 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
11373 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
11377 value
= os_strchr(cmd
, ' ');
11382 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
11384 #ifdef CONFIG_WIFI_DISPLAY
11385 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
11386 wifi_display_enable(global
, !!atoi(value
));
11389 #endif /* CONFIG_WIFI_DISPLAY */
11391 /* Restore cmd to its original value to allow redirection */
11398 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
11401 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
11405 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11406 * <variable name> */
11408 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
11409 p
= os_strchr(cmd
, ' ');
11414 wpa_s
[i
] = global
->ifaces
;
11415 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
11416 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
11421 wpa_printf(MSG_DEBUG
,
11422 "CTRL_IFACE: Could not find iface=%s", cmd
);
11429 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
11433 #ifndef CONFIG_NO_CONFIG_WRITE
11434 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
11436 int ret
= 0, saved
= 0;
11437 struct wpa_supplicant
*wpa_s
;
11439 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11440 if (!wpa_s
->conf
->update_config
) {
11441 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11445 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
11446 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11449 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11454 if (!saved
&& !ret
) {
11455 wpa_dbg(wpa_s
, MSG_DEBUG
,
11456 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11462 #endif /* CONFIG_NO_CONFIG_WRITE */
11465 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
11466 char *buf
, size_t buflen
)
11470 struct wpa_supplicant
*wpa_s
;
11473 end
= buf
+ buflen
;
11476 if (global
->p2p
&& !global
->p2p_disabled
) {
11477 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
11480 MAC2STR(global
->p2p_dev_addr
),
11481 p2p_get_state_txt(global
->p2p
));
11482 if (os_snprintf_error(end
- pos
, ret
))
11485 } else if (global
->p2p
) {
11486 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
11487 if (os_snprintf_error(end
- pos
, ret
))
11491 #endif /* CONFIG_P2P */
11493 #ifdef CONFIG_WIFI_DISPLAY
11494 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
11495 !!global
->wifi_display
);
11496 if (os_snprintf_error(end
- pos
, ret
))
11499 #endif /* CONFIG_WIFI_DISPLAY */
11501 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11502 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
11503 "address=" MACSTR
"\n",
11504 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
11505 if (os_snprintf_error(end
- pos
, ret
))
11516 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
11517 char *cmd
, char *buf
,
11520 char ifname
[IFNAMSIZ
+ 1];
11521 struct fst_iface_cfg cfg
;
11522 struct wpa_supplicant
*wpa_s
;
11523 struct fst_wpa_obj iface_obj
;
11525 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
11526 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11529 wpa_printf(MSG_INFO
, "FST: Already attached");
11532 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
11533 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
11536 return os_snprintf(buf
, reply_size
, "OK\n");
11544 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
11545 char *cmd
, char *buf
,
11548 char ifname
[IFNAMSIZ
+ 1];
11549 struct wpa_supplicant
*wpa_s
;
11551 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
11552 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11554 if (!fst_iface_detach(ifname
)) {
11556 return os_snprintf(buf
, reply_size
, "OK\n");
11564 #endif /* CONFIG_FST */
11567 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11568 char *buf
, size_t *resp_len
)
11571 const int reply_size
= 2048;
11573 int level
= MSG_DEBUG
;
11575 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11576 char *pos
= os_strchr(buf
+ 7, ' ');
11579 return wpas_global_ctrl_iface_ifname(global
,
11585 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11589 if (os_strcmp(buf
, "PING") == 0)
11590 level
= MSG_EXCESSIVE
;
11591 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11592 (const u8
*) buf
, os_strlen(buf
));
11594 reply
= os_malloc(reply_size
);
11595 if (reply
== NULL
) {
11600 os_memcpy(reply
, "OK\n", 3);
11603 if (os_strcmp(buf
, "PING") == 0) {
11604 os_memcpy(reply
, "PONG\n", 5);
11606 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11607 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11609 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11610 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11612 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11613 reply_len
= wpa_supplicant_global_iface_list(
11614 global
, reply
, reply_size
);
11615 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11616 reply_len
= wpa_supplicant_global_iface_interfaces(
11617 global
, buf
+ 10, reply
, reply_size
);
11619 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11620 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11623 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11624 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11627 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11628 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11629 #endif /* CONFIG_FST */
11630 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11631 wpa_supplicant_terminate_proc(global
);
11632 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11633 wpas_notify_suspend(global
);
11634 } else if (os_strcmp(buf
, "RESUME") == 0) {
11635 wpas_notify_resume(global
);
11636 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11637 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11639 if (global
->p2p_init_wpa_s
) {
11641 /* Check if P2P redirection would work for this
11643 return wpa_supplicant_ctrl_iface_process(
11644 global
->p2p_init_wpa_s
,
11647 #endif /* CONFIG_P2P */
11650 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11651 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11653 #ifndef CONFIG_NO_CONFIG_WRITE
11654 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11655 if (wpas_global_ctrl_iface_save_config(global
))
11657 #endif /* CONFIG_NO_CONFIG_WRITE */
11658 } else if (os_strcmp(buf
, "STATUS") == 0) {
11659 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11661 #ifdef CONFIG_MODULE_TESTS
11662 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11663 if (wpas_module_tests() < 0)
11665 #endif /* CONFIG_MODULE_TESTS */
11666 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11667 if (wpa_debug_reopen_file() < 0)
11670 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11674 if (reply_len
< 0) {
11675 os_memcpy(reply
, "FAIL\n", 5);
11679 *resp_len
= reply_len
;