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
, "ignore_sae_h2e_only") == 0) {
725 wpa_s
->ignore_sae_h2e_only
= !!atoi(value
);
726 } else if (os_strcasecmp(cmd
, "extra_sae_rejected_groups") == 0) {
729 os_free(wpa_s
->extra_sae_rejected_groups
);
730 wpa_s
->extra_sae_rejected_groups
= NULL
;
732 while (pos
&& pos
[0]) {
736 wpa_printf(MSG_DEBUG
,
737 "TESTING: Extra rejection of SAE group %d",
740 int_array_add_unique(
741 &wpa_s
->extra_sae_rejected_groups
,
743 pos
= os_strchr(pos
, ' ');
748 } else if (os_strcasecmp(cmd
, "rsne_override_eapol") == 0) {
749 wpabuf_free(wpa_s
->rsne_override_eapol
);
750 if (os_strcmp(value
, "NULL") == 0)
751 wpa_s
->rsne_override_eapol
= NULL
;
753 wpa_s
->rsne_override_eapol
= wpabuf_parse_bin(value
);
754 } else if (os_strcasecmp(cmd
, "rsnxe_override_assoc") == 0) {
755 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
756 if (os_strcmp(value
, "NULL") == 0)
757 wpa_s
->rsnxe_override_assoc
= NULL
;
759 wpa_s
->rsnxe_override_assoc
= wpabuf_parse_bin(value
);
760 } else if (os_strcasecmp(cmd
, "rsnxe_override_eapol") == 0) {
761 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
762 if (os_strcmp(value
, "NULL") == 0)
763 wpa_s
->rsnxe_override_eapol
= NULL
;
765 wpa_s
->rsnxe_override_eapol
= wpabuf_parse_bin(value
);
766 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
767 wpa_s
->reject_btm_req_reason
= atoi(value
);
768 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
769 os_free(wpa_s
->get_pref_freq_list_override
);
771 wpa_s
->get_pref_freq_list_override
= NULL
;
773 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
774 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
775 wpabuf_free(wpa_s
->sae_commit_override
);
776 if (value
[0] == '\0')
777 wpa_s
->sae_commit_override
= NULL
;
779 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
780 } else if (os_strcasecmp(cmd
, "driver_signal_override") == 0) {
781 ret
= wpas_ctrl_iface_set_dso(wpa_s
, value
);
783 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
784 os_free(wpa_s
->dpp_config_obj_override
);
785 if (value
[0] == '\0')
786 wpa_s
->dpp_config_obj_override
= NULL
;
788 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
789 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
790 os_free(wpa_s
->dpp_discovery_override
);
791 if (value
[0] == '\0')
792 wpa_s
->dpp_discovery_override
= NULL
;
794 wpa_s
->dpp_discovery_override
= os_strdup(value
);
795 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
796 os_free(wpa_s
->dpp_groups_override
);
797 if (value
[0] == '\0')
798 wpa_s
->dpp_groups_override
= NULL
;
800 wpa_s
->dpp_groups_override
= os_strdup(value
);
801 } else if (os_strcasecmp(cmd
,
802 "dpp_ignore_netaccesskey_mismatch") == 0) {
803 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
804 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
805 dpp_test
= atoi(value
);
806 #endif /* CONFIG_DPP */
807 #endif /* CONFIG_TESTING_OPTIONS */
809 } else if (os_strcasecmp(cmd
, "disable_fils") == 0) {
810 wpa_s
->disable_fils
= !!atoi(value
);
811 wpa_drv_disable_fils(wpa_s
, wpa_s
->disable_fils
);
812 wpa_supplicant_set_default_scan_ies(wpa_s
);
813 #endif /* CONFIG_FILS */
814 #ifndef CONFIG_NO_CONFIG_BLOBS
815 } else if (os_strcmp(cmd
, "blob") == 0) {
816 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
817 #endif /* CONFIG_NO_CONFIG_BLOBS */
818 } else if (os_strcasecmp(cmd
, "setband") == 0) {
819 ret
= wpas_ctrl_set_band(wpa_s
, value
);
821 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
822 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
825 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
827 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
828 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
829 } else if (os_strcasecmp(cmd
, "oce") == 0) {
830 wpa_s
->conf
->oce
= atoi(value
);
831 if (wpa_s
->conf
->oce
) {
832 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
833 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
834 wpa_s
->enable_oce
= OCE_STA
;
836 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
838 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
839 /* TODO: Need to add STA-CFON support */
840 wpa_printf(MSG_ERROR
,
841 "OCE STA-CFON feature is not yet supported");
845 wpa_s
->enable_oce
= 0;
847 wpa_supplicant_set_default_scan_ies(wpa_s
);
848 #endif /* CONFIG_MBO */
849 } else if (os_strcasecmp(cmd
, "lci") == 0) {
850 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
851 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
852 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
853 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
854 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
855 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
856 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
857 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
858 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
859 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
860 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
862 } else if (os_strcasecmp(cmd
, "coloc_intf_elems") == 0) {
863 struct wpabuf
*elems
;
865 elems
= wpabuf_parse_bin(value
);
868 wnm_set_coloc_intf_elems(wpa_s
, elems
);
869 #endif /* CONFIG_WNM */
872 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
874 wpa_supplicant_update_config(wpa_s
);
881 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
882 char *cmd
, char *buf
, size_t buflen
)
886 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
888 if (os_strcmp(cmd
, "version") == 0) {
889 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
890 } else if (os_strcasecmp(cmd
, "country") == 0) {
891 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
892 res
= os_snprintf(buf
, buflen
, "%c%c",
893 wpa_s
->conf
->country
[0],
894 wpa_s
->conf
->country
[1]);
895 #ifdef CONFIG_WIFI_DISPLAY
896 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
898 if (wpa_s
->global
->p2p
== NULL
||
899 wpa_s
->global
->p2p_disabled
)
902 enabled
= wpa_s
->global
->wifi_display
;
903 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
904 #endif /* CONFIG_WIFI_DISPLAY */
905 #ifdef CONFIG_TESTING_GET_GTK
906 } else if (os_strcmp(cmd
, "gtk") == 0) {
907 if (wpa_s
->last_gtk_len
== 0)
909 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
910 wpa_s
->last_gtk_len
);
912 #endif /* CONFIG_TESTING_GET_GTK */
913 } else if (os_strcmp(cmd
, "tls_library") == 0) {
914 res
= tls_get_library_version(buf
, buflen
);
915 #ifdef CONFIG_TESTING_OPTIONS
916 } else if (os_strcmp(cmd
, "anonce") == 0) {
917 return wpa_snprintf_hex(buf
, buflen
,
918 wpa_sm_get_anonce(wpa_s
->wpa
),
920 #endif /* CONFIG_TESTING_OPTIONS */
922 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
925 if (os_snprintf_error(buflen
, res
))
931 #ifdef IEEE8021X_EAPOL
932 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
936 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
938 if (hwaddr_aton(addr
, bssid
)) {
939 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
944 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
945 rsn_preauth_deinit(wpa_s
->wpa
);
946 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
951 #endif /* IEEE8021X_EAPOL */
956 static int wpa_supplicant_ctrl_iface_tdls_discover(
957 struct wpa_supplicant
*wpa_s
, char *addr
)
962 if (hwaddr_aton(addr
, peer
)) {
963 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
964 "address '%s'", addr
);
968 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
971 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
972 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
974 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
980 static int wpa_supplicant_ctrl_iface_tdls_setup(
981 struct wpa_supplicant
*wpa_s
, char *addr
)
986 if (hwaddr_aton(addr
, peer
)) {
987 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
988 "address '%s'", addr
);
992 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
995 if ((wpa_s
->conf
->tdls_external_control
) &&
996 wpa_tdls_is_external_setup(wpa_s
->wpa
))
997 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
999 wpa_tdls_remove(wpa_s
->wpa
, peer
);
1001 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
1002 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
1004 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
1010 static int wpa_supplicant_ctrl_iface_tdls_teardown(
1011 struct wpa_supplicant
*wpa_s
, char *addr
)
1016 if (os_strcmp(addr
, "*") == 0) {
1017 /* remove everyone */
1018 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
1019 wpa_tdls_teardown_peers(wpa_s
->wpa
);
1023 if (hwaddr_aton(addr
, peer
)) {
1024 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1025 "address '%s'", addr
);
1029 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
1032 if ((wpa_s
->conf
->tdls_external_control
) &&
1033 wpa_tdls_is_external_setup(wpa_s
->wpa
))
1034 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
1036 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
1037 ret
= wpa_tdls_teardown_link(
1039 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
1041 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
1047 static int ctrl_iface_get_capability_tdls(
1048 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1052 ret
= os_snprintf(buf
, buflen
, "%s\n",
1053 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
1055 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
1056 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
1057 if (os_snprintf_error(buflen
, ret
))
1063 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1064 struct wpa_supplicant
*wpa_s
, char *cmd
)
1067 struct hostapd_freq_params freq_params
;
1071 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1072 wpa_printf(MSG_INFO
,
1073 "tdls_chanswitch: Only supported with external setup");
1077 os_memset(&freq_params
, 0, sizeof(freq_params
));
1079 pos
= os_strchr(cmd
, ' ');
1084 oper_class
= strtol(pos
, &end
, 10);
1086 wpa_printf(MSG_INFO
,
1087 "tdls_chanswitch: Invalid op class provided");
1092 freq_params
.freq
= atoi(pos
);
1093 if (freq_params
.freq
== 0) {
1094 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
1098 #define SET_FREQ_SETTING(str) \
1100 const char *pos2 = os_strstr(pos, " " #str "="); \
1102 pos2 += sizeof(" " #str "=") - 1; \
1103 freq_params.str = atoi(pos2); \
1107 SET_FREQ_SETTING(center_freq1
);
1108 SET_FREQ_SETTING(center_freq2
);
1109 SET_FREQ_SETTING(bandwidth
);
1110 SET_FREQ_SETTING(sec_channel_offset
);
1111 #undef SET_FREQ_SETTING
1113 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
1114 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
1116 if (hwaddr_aton(cmd
, peer
)) {
1117 wpa_printf(MSG_DEBUG
,
1118 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1123 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1124 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1125 MAC2STR(peer
), oper_class
, freq_params
.freq
,
1126 freq_params
.center_freq1
, freq_params
.center_freq2
,
1127 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
1128 freq_params
.ht_enabled
? " HT" : "",
1129 freq_params
.vht_enabled
? " VHT" : "");
1131 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
1136 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1137 struct wpa_supplicant
*wpa_s
, char *cmd
)
1141 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1142 wpa_printf(MSG_INFO
,
1143 "tdls_chanswitch: Only supported with external setup");
1147 if (hwaddr_aton(cmd
, peer
)) {
1148 wpa_printf(MSG_DEBUG
,
1149 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1154 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1157 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1161 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1162 struct wpa_supplicant
*wpa_s
, const char *addr
,
1163 char *buf
, size_t buflen
)
1166 const char *tdls_status
;
1169 if (hwaddr_aton(addr
, peer
)) {
1170 wpa_printf(MSG_DEBUG
,
1171 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1175 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1178 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1179 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1180 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1181 if (os_snprintf_error(buflen
, ret
))
1187 #endif /* CONFIG_TDLS */
1190 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1192 char *token
, *context
= NULL
;
1193 struct wmm_ac_ts_setup_params params
= {
1198 while ((token
= str_token(cmd
, " ", &context
))) {
1199 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1200 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1201 sscanf(token
, "nominal_msdu_size=%i",
1202 ¶ms
.nominal_msdu_size
) == 1 ||
1203 sscanf(token
, "mean_data_rate=%i",
1204 ¶ms
.mean_data_rate
) == 1 ||
1205 sscanf(token
, "min_phy_rate=%i",
1206 ¶ms
.minimum_phy_rate
) == 1 ||
1207 sscanf(token
, "sba=%i",
1208 ¶ms
.surplus_bandwidth_allowance
) == 1)
1211 if (os_strcasecmp(token
, "downlink") == 0) {
1212 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1213 } else if (os_strcasecmp(token
, "uplink") == 0) {
1214 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1215 } else if (os_strcasecmp(token
, "bidi") == 0) {
1216 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1217 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1218 params
.fixed_nominal_msdu
= 1;
1220 wpa_printf(MSG_DEBUG
,
1221 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1228 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1232 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1234 u8 tsid
= atoi(cmd
);
1236 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1240 #ifdef CONFIG_IEEE80211R
1241 static int wpa_supplicant_ctrl_iface_ft_ds(
1242 struct wpa_supplicant
*wpa_s
, char *addr
)
1244 u8 target_ap
[ETH_ALEN
];
1245 struct wpa_bss
*bss
;
1248 if (hwaddr_aton(addr
, target_ap
)) {
1249 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1250 "address '%s'", addr
);
1254 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1256 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1258 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1262 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1264 #endif /* CONFIG_IEEE80211R */
1268 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1271 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1273 u8 p2p_dev_addr
[ETH_ALEN
];
1274 #endif /* CONFIG_P2P */
1276 u8
*_p2p_dev_addr
= NULL
;
1277 #endif /* CONFIG_AP */
1281 if (!cmd
|| os_strcmp(cmd
, "any") == 0 ||
1282 os_strncmp(cmd
, "any ", 4) == 0) {
1285 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1286 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1287 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1288 "P2P Device Address '%s'",
1292 _p2p_dev_addr
= p2p_dev_addr
;
1293 #endif /* CONFIG_P2P */
1294 } else if (os_strncmp(cmd
, "multi_ap=", 9) == 0) {
1296 multi_ap
= atoi(cmd
+ 9);
1297 } else if (hwaddr_aton(cmd
, bssid
)) {
1298 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1304 pos
= os_strstr(cmd
, " multi_ap=");
1307 multi_ap
= atoi(pos
);
1312 if (wpa_s
->ap_iface
)
1313 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1314 #endif /* CONFIG_AP */
1316 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0, multi_ap
);
1320 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1321 char *cmd
, char *buf
,
1324 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1328 pin
= os_strchr(cmd
, ' ');
1332 if (os_strcmp(cmd
, "any") == 0)
1334 else if (os_strcmp(cmd
, "get") == 0) {
1335 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1338 } else if (hwaddr_aton(cmd
, bssid
)) {
1339 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1345 if (wpa_s
->ap_iface
) {
1350 pos
= os_strchr(pin
, ' ');
1353 timeout
= atoi(pos
);
1357 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1358 buf
, buflen
, timeout
);
1360 #endif /* CONFIG_AP */
1363 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1367 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1368 if (os_snprintf_error(buflen
, ret
))
1373 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1378 /* Return the generated PIN */
1379 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1380 if (os_snprintf_error(buflen
, ret
))
1386 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1387 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1394 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1395 (u8
*) cmd
, os_strlen(cmd
));
1396 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1397 if (*pos
< '0' || *pos
> '9')
1401 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1405 if (len
!= 4 && len
!= 8) {
1406 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1412 unsigned int pin_val
;
1413 pin_val
= atoi(pin
);
1414 if (!wps_pin_valid(pin_val
)) {
1415 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1416 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1417 if (os_snprintf_error(buflen
, ret
))
1423 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1424 if (os_snprintf_error(buflen
, ret
))
1431 #ifdef CONFIG_WPS_NFC
1433 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1436 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1438 if (cmd
== NULL
|| cmd
[0] == '\0')
1440 else if (hwaddr_aton(cmd
, bssid
))
1443 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1448 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1449 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1456 pos
= os_strchr(cmd
, ' ');
1459 if (os_strcmp(cmd
, "WPS") == 0)
1461 else if (os_strcmp(cmd
, "NDEF") == 0)
1466 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1470 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1472 reply
[res
++] = '\n';
1481 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1482 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1488 if (os_strcmp(cmd
, "WPS") == 0)
1490 else if (os_strcmp(cmd
, "NDEF") == 0)
1495 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1499 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1501 reply
[res
++] = '\n';
1510 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1511 struct wpa_supplicant
*wpa_s
, char *pos
)
1517 int forced_freq
= 0;
1519 freq
= strstr(pos
, " freq=");
1523 forced_freq
= atoi(freq
);
1526 len
= os_strlen(pos
);
1531 buf
= wpabuf_alloc(len
);
1534 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1539 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1546 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1547 char *reply
, size_t max_len
,
1553 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1557 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1559 reply
[res
++] = '\n';
1569 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1570 char *reply
, size_t max_len
,
1576 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1578 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1582 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1584 reply
[res
++] = '\n';
1591 #endif /* CONFIG_P2P */
1594 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1595 char *cmd
, char *reply
,
1601 pos
= os_strchr(cmd
, ' ');
1606 if (os_strcmp(cmd
, "WPS") == 0)
1608 else if (os_strcmp(cmd
, "NDEF") == 0)
1613 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1616 return wpas_ctrl_nfc_get_handover_req_wps(
1617 wpa_s
, reply
, max_len
, ndef
);
1621 if (os_strcmp(pos
, "P2P-CR") == 0) {
1622 return wpas_ctrl_nfc_get_handover_req_p2p(
1623 wpa_s
, reply
, max_len
, ndef
);
1625 #endif /* CONFIG_P2P */
1631 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1632 char *reply
, size_t max_len
,
1633 int ndef
, int cr
, char *uuid
)
1638 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1642 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1644 reply
[res
++] = '\n';
1654 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1655 char *reply
, size_t max_len
,
1661 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1665 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1667 reply
[res
++] = '\n';
1674 #endif /* CONFIG_P2P */
1677 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1678 char *cmd
, char *reply
,
1684 pos
= os_strchr(cmd
, ' ');
1689 if (os_strcmp(cmd
, "WPS") == 0)
1691 else if (os_strcmp(cmd
, "NDEF") == 0)
1696 pos2
= os_strchr(pos
, ' ');
1699 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1702 return wpas_ctrl_nfc_get_handover_sel_wps(
1703 wpa_s
, reply
, max_len
, ndef
,
1704 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1708 if (os_strcmp(pos
, "P2P-CR") == 0) {
1709 return wpas_ctrl_nfc_get_handover_sel_p2p(
1710 wpa_s
, reply
, max_len
, ndef
, 0);
1713 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1714 return wpas_ctrl_nfc_get_handover_sel_p2p(
1715 wpa_s
, reply
, max_len
, ndef
, 1);
1717 #endif /* CONFIG_P2P */
1723 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1727 struct wpabuf
*req
, *sel
;
1729 char *pos
, *role
, *type
, *pos2
;
1732 int forced_freq
= 0;
1734 freq
= strstr(cmd
, " freq=");
1738 forced_freq
= atoi(freq
);
1740 #endif /* CONFIG_P2P */
1743 pos
= os_strchr(role
, ' ');
1745 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1751 pos
= os_strchr(type
, ' ');
1753 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1758 pos2
= os_strchr(pos
, ' ');
1760 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1765 len
= os_strlen(pos
);
1767 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1772 req
= wpabuf_alloc(len
);
1774 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1777 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1778 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1783 len
= os_strlen(pos2
);
1785 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1791 sel
= wpabuf_alloc(len
);
1793 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1797 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1798 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1804 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1805 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1807 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1808 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1810 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1812 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1814 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1815 #endif /* CONFIG_AP */
1817 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1819 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1820 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1822 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1824 #endif /* CONFIG_P2P */
1826 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1827 "reported: role=%s type=%s", role
, type
);
1834 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1839 #endif /* CONFIG_WPS_NFC */
1842 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1851 struct wps_new_ap_settings ap
;
1853 pin
= os_strchr(cmd
, ' ');
1858 if (hwaddr_aton(cmd
, bssid
)) {
1859 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1864 new_ssid
= os_strchr(pin
, ' ');
1865 if (new_ssid
== NULL
)
1866 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1869 new_auth
= os_strchr(new_ssid
, ' ');
1870 if (new_auth
== NULL
)
1874 new_encr
= os_strchr(new_auth
, ' ');
1875 if (new_encr
== NULL
)
1879 new_key
= os_strchr(new_encr
, ' ');
1880 if (new_key
== NULL
)
1884 os_memset(&ap
, 0, sizeof(ap
));
1885 ap
.ssid_hex
= new_ssid
;
1888 ap
.key_hex
= new_key
;
1889 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1894 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1895 char *cmd
, char *buf
,
1900 const char *pin_txt
;
1902 if (!wpa_s
->ap_iface
)
1905 pos
= os_strchr(cmd
, ' ');
1909 if (os_strcmp(cmd
, "disable") == 0) {
1910 wpas_wps_ap_pin_disable(wpa_s
);
1911 return os_snprintf(buf
, buflen
, "OK\n");
1914 if (os_strcmp(cmd
, "random") == 0) {
1916 timeout
= atoi(pos
);
1917 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1918 if (pin_txt
== NULL
)
1920 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1923 if (os_strcmp(cmd
, "get") == 0) {
1924 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1925 if (pin_txt
== NULL
)
1927 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1930 if (os_strcmp(cmd
, "set") == 0) {
1935 pos
= os_strchr(pos
, ' ');
1938 timeout
= atoi(pos
);
1940 if (os_strlen(pin
) > buflen
)
1942 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1944 return os_snprintf(buf
, buflen
, "%s", pin
);
1949 #endif /* CONFIG_AP */
1952 #ifdef CONFIG_WPS_ER
1953 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1956 char *uuid
= cmd
, *pin
, *pos
;
1957 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1958 pin
= os_strchr(uuid
, ' ');
1962 pos
= os_strchr(pin
, ' ');
1965 if (hwaddr_aton(pos
, addr_buf
) == 0)
1968 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1972 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1975 char *uuid
= cmd
, *pin
;
1976 pin
= os_strchr(uuid
, ' ');
1980 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1984 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1985 struct wpa_supplicant
*wpa_s
, char *cmd
)
1987 char *uuid
= cmd
, *id
;
1988 id
= os_strchr(uuid
, ' ');
1992 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1996 static int wpa_supplicant_ctrl_iface_wps_er_config(
1997 struct wpa_supplicant
*wpa_s
, char *cmd
)
2004 struct wps_new_ap_settings ap
;
2006 pin
= os_strchr(cmd
, ' ');
2011 new_ssid
= os_strchr(pin
, ' ');
2012 if (new_ssid
== NULL
)
2016 new_auth
= os_strchr(new_ssid
, ' ');
2017 if (new_auth
== NULL
)
2021 new_encr
= os_strchr(new_auth
, ' ');
2022 if (new_encr
== NULL
)
2026 new_key
= os_strchr(new_encr
, ' ');
2027 if (new_key
== NULL
)
2031 os_memset(&ap
, 0, sizeof(ap
));
2032 ap
.ssid_hex
= new_ssid
;
2035 ap
.key_hex
= new_key
;
2036 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
2040 #ifdef CONFIG_WPS_NFC
2041 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2042 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2049 uuid
= os_strchr(cmd
, ' ');
2054 if (os_strcmp(cmd
, "WPS") == 0)
2056 else if (os_strcmp(cmd
, "NDEF") == 0)
2061 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
2065 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
2067 reply
[res
++] = '\n';
2074 #endif /* CONFIG_WPS_NFC */
2075 #endif /* CONFIG_WPS_ER */
2077 #endif /* CONFIG_WPS */
2080 #ifdef CONFIG_IBSS_RSN
2081 static int wpa_supplicant_ctrl_iface_ibss_rsn(
2082 struct wpa_supplicant
*wpa_s
, char *addr
)
2086 if (hwaddr_aton(addr
, peer
)) {
2087 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
2088 "address '%s'", addr
);
2092 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
2095 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
2097 #endif /* CONFIG_IBSS_RSN */
2100 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
2103 #ifdef IEEE8021X_EAPOL
2106 struct wpa_ssid
*ssid
;
2108 pos
= os_strchr(rsp
, '-');
2113 pos
= os_strchr(pos
, ':');
2118 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
2119 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2120 (u8
*) pos
, os_strlen(pos
));
2122 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2124 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2129 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
2131 #else /* IEEE8021X_EAPOL */
2132 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
2134 #endif /* IEEE8021X_EAPOL */
2138 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
2140 char *buf
, size_t buflen
)
2142 char *pos
, *end
, tmp
[30];
2143 int res
, verbose
, wps
, ret
;
2146 #endif /* CONFIG_HS20 */
2150 if (os_strcmp(params
, "-DRIVER") == 0)
2151 return wpa_drv_status(wpa_s
, buf
, buflen
);
2152 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
2153 wps
= os_strcmp(params
, "-WPS") == 0;
2156 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
2157 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2158 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2159 MAC2STR(wpa_s
->bssid
));
2160 if (os_snprintf_error(end
- pos
, ret
))
2163 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2165 if (os_snprintf_error(end
- pos
, ret
))
2169 u8
*_ssid
= ssid
->ssid
;
2170 size_t ssid_len
= ssid
->ssid_len
;
2171 u8 ssid_buf
[SSID_MAX_LEN
];
2172 if (ssid_len
== 0) {
2173 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2180 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2181 wpa_ssid_txt(_ssid
, ssid_len
),
2183 if (os_snprintf_error(end
- pos
, ret
))
2187 if (wps
&& ssid
->passphrase
&&
2188 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2189 (ssid
->mode
== WPAS_MODE_AP
||
2190 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2191 ret
= os_snprintf(pos
, end
- pos
,
2194 if (os_snprintf_error(end
- pos
, ret
))
2199 ret
= os_snprintf(pos
, end
- pos
,
2202 if (os_snprintf_error(end
- pos
, ret
))
2207 switch (ssid
->mode
) {
2208 case WPAS_MODE_INFRA
:
2209 ret
= os_snprintf(pos
, end
- pos
,
2212 case WPAS_MODE_IBSS
:
2213 ret
= os_snprintf(pos
, end
- pos
,
2217 ret
= os_snprintf(pos
, end
- pos
,
2220 case WPAS_MODE_P2P_GO
:
2221 ret
= os_snprintf(pos
, end
- pos
,
2224 case WPAS_MODE_P2P_GROUP_FORMATION
:
2225 ret
= os_snprintf(pos
, end
- pos
,
2226 "mode=P2P GO - group "
2229 case WPAS_MODE_MESH
:
2230 ret
= os_snprintf(pos
, end
- pos
,
2237 if (os_snprintf_error(end
- pos
, ret
))
2242 if (wpa_s
->connection_set
&&
2243 (wpa_s
->connection_ht
|| wpa_s
->connection_vht
||
2244 wpa_s
->connection_he
)) {
2245 ret
= os_snprintf(pos
, end
- pos
,
2246 "wifi_generation=%u\n",
2247 wpa_s
->connection_he
? 6 :
2248 (wpa_s
->connection_vht
? 5 : 4));
2249 if (os_snprintf_error(end
- pos
, ret
))
2255 if (wpa_s
->ap_iface
) {
2256 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2260 #endif /* CONFIG_AP */
2261 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2265 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2268 #endif /* CONFIG_AP */
2269 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2270 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2271 wpa_s
->sme
.sae
.group
);
2272 if (os_snprintf_error(end
- pos
, ret
))
2276 #endif /* CONFIG_SAE */
2277 #endif /* CONFIG_SME */
2278 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2279 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2280 if (os_snprintf_error(end
- pos
, ret
))
2285 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2286 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2287 if (os_snprintf_error(end
- pos
, ret
))
2293 if (wpa_s
->global
->p2p
) {
2294 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2295 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2296 if (os_snprintf_error(end
- pos
, ret
))
2300 #endif /* CONFIG_P2P */
2302 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2303 MAC2STR(wpa_s
->own_addr
));
2304 if (os_snprintf_error(end
- pos
, ret
))
2309 if (wpa_s
->current_bss
&&
2310 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2311 HS20_IE_VENDOR_TYPE
)) &&
2312 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2313 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2316 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2317 release
= rel_num
+ 1;
2319 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2320 if (os_snprintf_error(end
- pos
, ret
))
2325 if (wpa_s
->current_ssid
) {
2326 struct wpa_cred
*cred
;
2329 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2332 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2335 if (cred
->provisioning_sp
) {
2336 ret
= os_snprintf(pos
, end
- pos
,
2337 "provisioning_sp=%s\n",
2338 cred
->provisioning_sp
);
2339 if (os_snprintf_error(end
- pos
, ret
))
2348 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2349 struct wpabuf
*names
=
2350 wpa_s
->current_bss
->anqp
->domain_name
;
2351 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2353 if (domain_name_list_contains(
2354 names
, cred
->domain
[i
], 1))
2357 if (i
== cred
->num_domain
)
2358 i
= 0; /* show first entry by default */
2360 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2362 if (os_snprintf_error(end
- pos
, ret
))
2367 if (wpa_s
->current_bss
== NULL
||
2368 wpa_s
->current_bss
->anqp
== NULL
)
2371 res
= interworking_home_sp_cred(
2373 wpa_s
->current_bss
->anqp
->domain_name
);
2381 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2382 if (os_snprintf_error(end
- pos
, ret
))
2389 #endif /* CONFIG_HS20 */
2391 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2392 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2393 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2399 #ifdef CONFIG_MACSEC
2400 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2403 #endif /* CONFIG_MACSEC */
2405 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2409 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2410 if (os_snprintf_error(end
- pos
, ret
))
2413 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2417 ret
= os_snprintf(pos
, end
- pos
, "\n");
2418 if (os_snprintf_error(end
- pos
, ret
))
2423 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2430 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2431 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2432 if (os_snprintf_error(end
- pos
, ret
))
2436 #endif /* CONFIG_WPS */
2438 if (wpa_s
->ieee80211ac
) {
2439 ret
= os_snprintf(pos
, end
- pos
, "ieee80211ac=1\n");
2440 if (os_snprintf_error(end
- pos
, ret
))
2447 * Allow using the STATUS command with default behavior, say for debug,
2448 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2449 * events with STATUS-NO_EVENTS.
2451 if (os_strcmp(params
, "-NO_EVENTS")) {
2452 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2453 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2454 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2456 MAC2STR(wpa_s
->bssid
),
2457 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2458 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2459 wpa_s
->current_ssid
->ssid_len
) : "");
2460 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2461 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2462 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2463 "- connection to " MACSTR
2464 " completed %s [id=%d id_str=%s]",
2465 MAC2STR(wpa_s
->bssid
), "(auth)",
2466 ssid
? ssid
->id
: -1,
2467 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2470 #endif /* ANDROID */
2476 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2481 struct wpa_ssid
*ssid
;
2484 /* cmd: "<network id> <BSSID>" */
2485 pos
= os_strchr(cmd
, ' ');
2490 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2491 if (hwaddr_aton(pos
, bssid
)) {
2492 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2496 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2498 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2503 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2504 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2510 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2511 char *cmd
, char *buf
,
2515 struct wpa_blacklist
*e
;
2519 /* cmd: "BLACKLIST [<BSSID>]" */
2523 e
= wpa_s
->blacklist
;
2525 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2527 if (os_snprintf_error(end
- pos
, ret
))
2536 if (os_strncmp(cmd
, "clear", 5) == 0) {
2537 wpa_blacklist_clear(wpa_s
);
2538 os_memcpy(buf
, "OK\n", 3);
2542 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2543 if (hwaddr_aton(cmd
, bssid
)) {
2544 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2549 * Add the BSSID twice, so its count will be 2, causing it to be
2550 * skipped when processing scan results.
2552 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2555 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2558 os_memcpy(buf
, "OK\n", 3);
2563 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2564 char *cmd
, char *buf
,
2567 char *pos
, *end
, *stamp
;
2570 /* cmd: "LOG_LEVEL [<level>]" */
2574 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2576 debug_level_str(wpa_debug_level
),
2577 wpa_debug_timestamp
);
2578 if (os_snprintf_error(end
- pos
, ret
))
2587 stamp
= os_strchr(cmd
, ' ');
2590 while (*stamp
== ' ') {
2595 if (os_strlen(cmd
)) {
2596 int level
= str_to_debug_level(cmd
);
2599 wpa_debug_level
= level
;
2602 if (stamp
&& os_strlen(stamp
))
2603 wpa_debug_timestamp
= atoi(stamp
);
2605 os_memcpy(buf
, "OK\n", 3);
2610 static int wpa_supplicant_ctrl_iface_list_networks(
2611 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2613 char *pos
, *end
, *prev
;
2614 struct wpa_ssid
*ssid
;
2619 ret
= os_snprintf(pos
, end
- pos
,
2620 "network id / ssid / bssid / flags\n");
2621 if (os_snprintf_error(end
- pos
, ret
))
2625 ssid
= wpa_s
->conf
->ssid
;
2627 /* skip over ssids until we find next one */
2628 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2629 int last_id
= atoi(cmd
+ 8);
2630 if (last_id
!= -1) {
2631 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2639 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2641 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2642 if (os_snprintf_error(end
- pos
, ret
))
2645 if (ssid
->bssid_set
) {
2646 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2647 MAC2STR(ssid
->bssid
));
2649 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2651 if (os_snprintf_error(end
- pos
, ret
))
2654 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2655 ssid
== wpa_s
->current_ssid
?
2657 ssid
->disabled
? "[DISABLED]" : "",
2658 ssid
->disabled_until
.sec
?
2659 "[TEMP-DISABLED]" : "",
2660 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2662 if (os_snprintf_error(end
- pos
, ret
))
2665 ret
= os_snprintf(pos
, end
- pos
, "\n");
2666 if (os_snprintf_error(end
- pos
, ret
))
2677 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2680 ret
= os_snprintf(pos
, end
- pos
, "-");
2681 if (os_snprintf_error(end
- pos
, ret
))
2684 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2692 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2693 const u8
*ie
, size_t ie_len
)
2695 struct wpa_ie_data data
;
2699 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2700 if (os_snprintf_error(end
- pos
, ret
))
2704 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2705 ret
= os_snprintf(pos
, end
- pos
, "?]");
2706 if (os_snprintf_error(end
- pos
, ret
))
2713 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2714 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2715 pos
== start
? "" : "+");
2716 if (os_snprintf_error(end
- pos
, ret
))
2720 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2721 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2722 pos
== start
? "" : "+");
2723 if (os_snprintf_error(end
- pos
, ret
))
2727 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2728 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2729 pos
== start
? "" : "+");
2730 if (os_snprintf_error(end
- pos
, ret
))
2734 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2735 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2736 pos
== start
? "" : "+");
2737 if (os_snprintf_error(end
- pos
, ret
))
2741 #ifdef CONFIG_IEEE80211R
2742 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2743 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2744 pos
== start
? "" : "+");
2745 if (os_snprintf_error(end
- pos
, ret
))
2749 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2750 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2751 pos
== start
? "" : "+");
2752 if (os_snprintf_error(end
- pos
, ret
))
2756 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2757 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2758 pos
== start
? "" : "+");
2759 if (os_snprintf_error(end
- pos
, ret
))
2763 #endif /* CONFIG_IEEE80211R */
2764 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2765 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2766 pos
== start
? "" : "+");
2767 if (os_snprintf_error(end
- pos
, ret
))
2771 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2772 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2773 pos
== start
? "" : "+");
2774 if (os_snprintf_error(end
- pos
, ret
))
2779 #ifdef CONFIG_SUITEB
2780 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2781 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2782 pos
== start
? "" : "+");
2783 if (os_snprintf_error(end
- pos
, ret
))
2787 #endif /* CONFIG_SUITEB */
2789 #ifdef CONFIG_SUITEB192
2790 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2791 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2792 pos
== start
? "" : "+");
2793 if (os_snprintf_error(end
- pos
, ret
))
2797 #endif /* CONFIG_SUITEB192 */
2800 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2801 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2802 pos
== start
? "" : "+");
2803 if (os_snprintf_error(end
- pos
, ret
))
2807 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2808 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2809 pos
== start
? "" : "+");
2810 if (os_snprintf_error(end
- pos
, ret
))
2814 #ifdef CONFIG_IEEE80211R
2815 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2816 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2817 pos
== start
? "" : "+");
2818 if (os_snprintf_error(end
- pos
, ret
))
2822 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2823 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2824 pos
== start
? "" : "+");
2825 if (os_snprintf_error(end
- pos
, ret
))
2829 #endif /* CONFIG_IEEE80211R */
2830 #endif /* CONFIG_FILS */
2833 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2834 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2835 pos
== start
? "" : "+");
2836 if (os_snprintf_error(end
- pos
, ret
))
2840 #endif /* CONFIG_OWE */
2843 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2844 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2845 pos
== start
? "" : "+");
2846 if (os_snprintf_error(end
- pos
, ret
))
2850 #endif /* CONFIG_DPP */
2852 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2853 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2854 pos
== start
? "" : "+");
2855 if (os_snprintf_error(end
- pos
, ret
))
2860 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2862 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2863 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2864 if (os_snprintf_error(end
- pos
, ret
))
2869 ret
= os_snprintf(pos
, end
- pos
, "]");
2870 if (os_snprintf_error(end
- pos
, ret
))
2879 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2880 char *pos
, char *end
,
2881 struct wpabuf
*wps_ie
)
2888 if (wps_is_selected_pbc_registrar(wps_ie
))
2890 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2892 else if (wps_is_selected_pin_registrar(wps_ie
))
2897 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2898 if (!os_snprintf_error(end
- pos
, ret
))
2900 wpabuf_free(wps_ie
);
2903 #endif /* CONFIG_WPS */
2906 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2907 char *pos
, char *end
,
2908 const struct wpa_bss
*bss
)
2911 struct wpabuf
*wps_ie
;
2912 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2913 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2914 #else /* CONFIG_WPS */
2916 #endif /* CONFIG_WPS */
2920 /* Format one result on one text line into a buffer. */
2921 static int wpa_supplicant_ctrl_iface_scan_result(
2922 struct wpa_supplicant
*wpa_s
,
2923 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2927 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
, *owe
;
2929 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2930 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2932 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2933 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2934 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2936 return 0; /* Do not show P2P listen discovery results here */
2941 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2942 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2943 if (os_snprintf_error(end
- pos
, ret
))
2946 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2948 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2949 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2951 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2954 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2956 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2957 osen_ie
, 2 + osen_ie
[1]);
2958 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
2960 ret
= os_snprintf(pos
, end
- pos
,
2961 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2962 if (os_snprintf_error(end
- pos
, ret
))
2966 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2967 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2968 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2969 if (os_snprintf_error(end
- pos
, ret
))
2974 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2975 if (os_snprintf_error(end
- pos
, ret
))
2979 if (bss_is_dmg(bss
)) {
2982 if (get_ie_ext((const u8
*) (bss
+ 1), bss
->ie_len
,
2983 WLAN_EID_EXT_EDMG_OPERATION
)) {
2984 ret
= os_snprintf(pos
, end
- pos
, "[EDMG]");
2985 if (os_snprintf_error(end
- pos
, ret
))
2990 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2991 if (os_snprintf_error(end
- pos
, ret
))
2994 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2995 case IEEE80211_CAP_DMG_IBSS
:
2998 case IEEE80211_CAP_DMG_AP
:
3001 case IEEE80211_CAP_DMG_PBSS
:
3008 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
3009 if (os_snprintf_error(end
- pos
, ret
))
3013 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3014 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3015 if (os_snprintf_error(end
- pos
, ret
))
3019 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3020 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3021 if (os_snprintf_error(end
- pos
, ret
))
3027 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3028 if (os_snprintf_error(end
- pos
, ret
))
3033 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
3034 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3035 if (os_snprintf_error(end
- pos
, ret
))
3039 #endif /* CONFIG_HS20 */
3041 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
3042 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
3043 if (os_snprintf_error(end
- pos
, ret
))
3047 #endif /* CONFIG_FILS */
3049 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
3050 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
3051 if (os_snprintf_error(end
- pos
, ret
))
3055 #endif /* CONFIG_FST */
3056 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
3057 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
3058 if (os_snprintf_error(end
- pos
, ret
))
3063 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
3064 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3065 if (os_snprintf_error(end
- pos
, ret
))
3069 ret
= os_snprintf(pos
, end
- pos
, "\n");
3070 if (os_snprintf_error(end
- pos
, ret
))
3078 static int wpa_supplicant_ctrl_iface_scan_results(
3079 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3082 struct wpa_bss
*bss
;
3087 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
3089 if (os_snprintf_error(end
- pos
, ret
))
3093 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
3094 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
3096 if (ret
< 0 || ret
>= end
- pos
)
3107 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3108 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
3110 char *pos
, ifname
[IFNAMSIZ
+ 1];
3114 pos
= os_strstr(cmd
, "ifname=");
3117 os_strlcpy(ifname
, pos
, sizeof(ifname
));
3120 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
3123 os_strlcpy(reply
, ifname
, max_len
);
3124 return os_strlen(ifname
);
3128 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3129 struct wpa_supplicant
*wpa_s
, char *cmd
)
3132 struct wpa_ssid
*ssid
;
3135 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
3137 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3139 wpa_printf(MSG_DEBUG
,
3140 "CTRL_IFACE: Could not find network id=%d", id
);
3143 if (ssid
->mode
!= WPAS_MODE_MESH
) {
3144 wpa_printf(MSG_DEBUG
,
3145 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3148 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3149 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
3150 wpa_printf(MSG_ERROR
,
3151 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3156 * TODO: If necessary write our own group_add function,
3157 * for now we can reuse select_network
3159 wpa_supplicant_select_network(wpa_s
, ssid
);
3165 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3166 struct wpa_supplicant
*wpa_s
, char *cmd
)
3168 struct wpa_supplicant
*orig
;
3169 struct wpa_global
*global
;
3172 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
3174 global
= wpa_s
->global
;
3177 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3178 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
3184 wpa_printf(MSG_ERROR
,
3185 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3189 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
3190 wpa_printf(MSG_ERROR
,
3191 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3195 wpa_s
->reassociate
= 0;
3196 wpa_s
->disconnected
= 1;
3197 wpa_supplicant_cancel_sched_scan(wpa_s
);
3198 wpa_supplicant_cancel_scan(wpa_s
);
3201 * TODO: If necessary write our own group_remove function,
3202 * for now we can reuse deauthenticate
3204 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3206 if (wpa_s
->mesh_if_created
)
3207 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3213 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3214 struct wpa_supplicant
*wpa_s
, char *cmd
)
3218 if (hwaddr_aton(cmd
, addr
) < 0)
3221 return wpas_mesh_peer_remove(wpa_s
, addr
);
3225 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3226 struct wpa_supplicant
*wpa_s
, char *cmd
)
3232 pos
= os_strstr(cmd
, " duration=");
3235 duration
= atoi(pos
+ 10);
3240 if (hwaddr_aton(cmd
, addr
))
3243 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3247 static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3248 struct wpa_supplicant
*wpa_s
, char *cmd
)
3250 struct ether_header
*eth
;
3254 size_t payload_len
= 0, len
;
3257 if (hwaddr_aton(cmd
, addr
))
3260 pos
= os_strstr(cmd
, " payload=");
3263 payload_len
= os_strlen(pos
);
3264 if (payload_len
& 1)
3270 len
= ETH_HLEN
+ payload_len
;
3271 buf
= os_malloc(len
);
3275 eth
= (struct ether_header
*) buf
;
3276 os_memcpy(eth
->ether_dhost
, addr
, ETH_ALEN
);
3277 os_memcpy(eth
->ether_shost
, wpa_s
->own_addr
, ETH_ALEN
);
3278 eth
->ether_type
= htons(ETH_P_802_3
);
3280 if (payload_len
&& hexstr2bin(pos
, buf
+ ETH_HLEN
, payload_len
) < 0)
3283 ret
= wpa_drv_mesh_link_probe(wpa_s
, addr
, buf
, len
);
3289 #endif /* CONFIG_MESH */
3292 static int wpa_supplicant_ctrl_iface_select_network(
3293 struct wpa_supplicant
*wpa_s
, char *cmd
)
3296 struct wpa_ssid
*ssid
;
3299 /* cmd: "<network id>" or "any" */
3300 if (os_strncmp(cmd
, "any", 3) == 0) {
3301 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3305 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3307 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3309 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3310 "network id=%d", id
);
3313 if (ssid
->disabled
== 2) {
3314 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3315 "SELECT_NETWORK with persistent P2P group");
3320 pos
= os_strstr(cmd
, " freq=");
3322 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3324 os_free(wpa_s
->select_network_scan_freqs
);
3325 wpa_s
->select_network_scan_freqs
= freqs
;
3329 wpa_s
->scan_min_time
.sec
= 0;
3330 wpa_s
->scan_min_time
.usec
= 0;
3331 wpa_supplicant_select_network(wpa_s
, ssid
);
3337 static int wpa_supplicant_ctrl_iface_enable_network(
3338 struct wpa_supplicant
*wpa_s
, char *cmd
)
3341 struct wpa_ssid
*ssid
;
3343 /* cmd: "<network id>" or "all" */
3344 if (os_strcmp(cmd
, "all") == 0) {
3345 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3349 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3351 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3353 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3354 "network id=%d", id
);
3357 if (ssid
->disabled
== 2) {
3358 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3359 "ENABLE_NETWORK with persistent P2P group");
3363 if (os_strstr(cmd
, " no-connect")) {
3368 wpa_s
->scan_min_time
.sec
= 0;
3369 wpa_s
->scan_min_time
.usec
= 0;
3370 wpa_supplicant_enable_network(wpa_s
, ssid
);
3376 static int wpa_supplicant_ctrl_iface_disable_network(
3377 struct wpa_supplicant
*wpa_s
, char *cmd
)
3380 struct wpa_ssid
*ssid
;
3382 /* cmd: "<network id>" or "all" */
3383 if (os_strcmp(cmd
, "all") == 0) {
3384 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3388 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3390 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3392 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3393 "network id=%d", id
);
3396 if (ssid
->disabled
== 2) {
3397 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3398 "DISABLE_NETWORK with persistent P2P "
3403 wpa_supplicant_disable_network(wpa_s
, ssid
);
3409 static int wpa_supplicant_ctrl_iface_add_network(
3410 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3412 struct wpa_ssid
*ssid
;
3415 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3417 ssid
= wpa_supplicant_add_network(wpa_s
);
3421 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3422 if (os_snprintf_error(buflen
, ret
))
3428 static int wpa_supplicant_ctrl_iface_remove_network(
3429 struct wpa_supplicant
*wpa_s
, char *cmd
)
3432 struct wpa_ssid
*ssid
;
3435 /* cmd: "<network id>" or "all" */
3436 if (os_strcmp(cmd
, "all") == 0) {
3437 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3438 if (wpa_s
->sched_scanning
)
3439 wpa_supplicant_cancel_sched_scan(wpa_s
);
3441 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3442 if (wpa_s
->current_ssid
) {
3444 wpa_s
->sme
.prev_bssid_set
= 0;
3445 #endif /* CONFIG_SME */
3446 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3447 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3448 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3449 wpa_s
->own_disconnect_req
= 1;
3450 wpa_supplicant_deauthenticate(
3451 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3453 ssid
= wpa_s
->conf
->ssid
;
3455 struct wpa_ssid
*remove_ssid
= ssid
;
3458 if (wpa_s
->last_ssid
== remove_ssid
)
3459 wpa_s
->last_ssid
= NULL
;
3460 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3461 wpa_config_remove_network(wpa_s
->conf
, id
);
3467 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3469 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3471 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3476 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3477 "network id=%d", id
);
3484 static int wpa_supplicant_ctrl_iface_update_network(
3485 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3486 char *name
, char *value
)
3490 ret
= wpa_config_set(ssid
, name
, value
, 0);
3492 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3493 "variable '%s'", name
);
3497 return 0; /* No change to the previously configured value */
3499 if (os_strcmp(name
, "bssid") != 0 &&
3500 os_strcmp(name
, "bssid_hint") != 0 &&
3501 os_strcmp(name
, "priority") != 0) {
3502 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3504 if (wpa_s
->current_ssid
== ssid
||
3505 wpa_s
->current_ssid
== NULL
) {
3507 * Invalidate the EAP session cache if anything in the
3508 * current or previously used configuration changes.
3510 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3514 if ((os_strcmp(name
, "psk") == 0 &&
3515 value
[0] == '"' && ssid
->ssid_len
) ||
3516 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3517 wpa_config_update_psk(ssid
);
3518 else if (os_strcmp(name
, "priority") == 0)
3519 wpa_config_update_prio_list(wpa_s
->conf
);
3525 static int wpa_supplicant_ctrl_iface_set_network(
3526 struct wpa_supplicant
*wpa_s
, char *cmd
)
3528 int id
, ret
, prev_bssid_set
, prev_disabled
;
3529 struct wpa_ssid
*ssid
;
3531 u8 prev_bssid
[ETH_ALEN
];
3533 /* cmd: "<network id> <variable name> <value>" */
3534 name
= os_strchr(cmd
, ' ');
3539 value
= os_strchr(name
, ' ');
3545 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3547 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3548 (u8
*) value
, os_strlen(value
));
3550 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3552 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3557 prev_bssid_set
= ssid
->bssid_set
;
3558 prev_disabled
= ssid
->disabled
;
3559 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3560 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3563 (ssid
->bssid_set
!= prev_bssid_set
||
3564 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3565 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3567 if (prev_disabled
!= ssid
->disabled
&&
3568 (prev_disabled
== 2 || ssid
->disabled
== 2))
3569 wpas_notify_network_type_changed(wpa_s
, ssid
);
3575 static int wpa_supplicant_ctrl_iface_get_network(
3576 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3580 struct wpa_ssid
*ssid
;
3583 /* cmd: "<network id> <variable name>" */
3584 name
= os_strchr(cmd
, ' ');
3585 if (name
== NULL
|| buflen
== 0)
3590 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3593 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3595 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3600 value
= wpa_config_get_no_key(ssid
, name
);
3601 if (value
== NULL
) {
3602 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3603 "variable '%s'", name
);
3607 res
= os_strlcpy(buf
, value
, buflen
);
3608 if (res
>= buflen
) {
3619 static int wpa_supplicant_ctrl_iface_dup_network(
3620 struct wpa_supplicant
*wpa_s
, char *cmd
,
3621 struct wpa_supplicant
*dst_wpa_s
)
3623 struct wpa_ssid
*ssid_s
, *ssid_d
;
3624 char *name
, *id
, *value
;
3625 int id_s
, id_d
, ret
;
3627 /* cmd: "<src network id> <dst network id> <variable name>" */
3628 id
= os_strchr(cmd
, ' ');
3633 name
= os_strchr(id
, ' ');
3641 wpa_printf(MSG_DEBUG
,
3642 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3643 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3645 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3646 if (ssid_s
== NULL
) {
3647 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3648 "network id=%d", id_s
);
3652 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3653 if (ssid_d
== NULL
) {
3654 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3655 "network id=%d", id_d
);
3659 value
= wpa_config_get(ssid_s
, name
);
3660 if (value
== NULL
) {
3661 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3662 "variable '%s'", name
);
3666 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3675 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3676 char *buf
, size_t buflen
)
3679 struct wpa_cred
*cred
;
3684 ret
= os_snprintf(pos
, end
- pos
,
3685 "cred id / realm / username / domain / imsi\n");
3686 if (os_snprintf_error(end
- pos
, ret
))
3690 cred
= wpa_s
->conf
->cred
;
3692 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3693 cred
->id
, cred
->realm
? cred
->realm
: "",
3694 cred
->username
? cred
->username
: "",
3695 cred
->domain
? cred
->domain
[0] : "",
3696 cred
->imsi
? cred
->imsi
: "");
3697 if (os_snprintf_error(end
- pos
, ret
))
3708 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3709 char *buf
, size_t buflen
)
3711 struct wpa_cred
*cred
;
3714 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3716 cred
= wpa_config_add_cred(wpa_s
->conf
);
3720 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3722 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3723 if (os_snprintf_error(buflen
, ret
))
3729 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3730 struct wpa_cred
*cred
)
3732 struct wpa_ssid
*ssid
;
3737 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3742 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3743 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3747 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3749 /* Remove any network entry created based on the removed credential */
3750 ssid
= wpa_s
->conf
->ssid
;
3752 if (ssid
->parent_cred
== cred
) {
3755 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3756 "used the removed credential", ssid
->id
);
3757 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3758 if (os_snprintf_error(sizeof(str
), res
))
3759 str
[sizeof(str
) - 1] = '\0';
3761 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3770 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3774 struct wpa_cred
*cred
, *prev
;
3776 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3777 * "provisioning_sp=<FQDN> */
3778 if (os_strcmp(cmd
, "all") == 0) {
3779 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3780 cred
= wpa_s
->conf
->cred
;
3784 wpas_ctrl_remove_cred(wpa_s
, prev
);
3789 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3790 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3792 cred
= wpa_s
->conf
->cred
;
3798 for (i
= 0; i
< prev
->num_domain
; i
++) {
3799 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3802 wpas_ctrl_remove_cred(wpa_s
, prev
);
3810 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3811 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3813 cred
= wpa_s
->conf
->cred
;
3817 if (prev
->provisioning_sp
&&
3818 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3819 wpas_ctrl_remove_cred(wpa_s
, prev
);
3825 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3827 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3828 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3832 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3836 struct wpa_cred
*cred
;
3839 /* cmd: "<cred id> <variable name> <value>" */
3840 name
= os_strchr(cmd
, ' ');
3845 value
= os_strchr(name
, ' ');
3851 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3853 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3854 (u8
*) value
, os_strlen(value
));
3856 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3858 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3863 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3864 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3865 "variable '%s'", name
);
3869 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3875 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3876 char *cmd
, char *buf
,
3881 struct wpa_cred
*cred
;
3884 /* cmd: "<cred id> <variable name>" */
3885 name
= os_strchr(cmd
, ' ');
3891 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3894 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3896 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3901 value
= wpa_config_get_cred_no_key(cred
, name
);
3902 if (value
== NULL
) {
3903 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3908 res
= os_strlcpy(buf
, value
, buflen
);
3909 if (res
>= buflen
) {
3920 #ifndef CONFIG_NO_CONFIG_WRITE
3921 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3925 if (!wpa_s
->conf
->update_config
) {
3926 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3927 "to update configuration (update_config=0)");
3931 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3933 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3934 "update configuration");
3936 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3942 #endif /* CONFIG_NO_CONFIG_WRITE */
3945 struct cipher_info
{
3951 static const struct cipher_info ciphers
[] = {
3952 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3953 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3954 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3955 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3956 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3957 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3959 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3960 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3961 #endif /* CONFIG_WEP */
3964 static const struct cipher_info ciphers_group_mgmt
[] = {
3965 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3966 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3967 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3968 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3972 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3973 struct wpa_driver_capa
*capa
,
3974 char *buf
, size_t buflen
)
3987 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3993 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3994 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3995 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3996 pos
== buf
? "" : " ",
3998 if (os_snprintf_error(end
- pos
, ret
))
4008 static int ctrl_iface_get_capability_group(int res
, char *strict
,
4009 struct wpa_driver_capa
*capa
,
4010 char *buf
, size_t buflen
)
4024 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
4025 #else /* CONFIG_WEP */
4026 len
= os_strlcpy(buf
, "CCMP TKIP", buflen
);
4027 #endif /* CONFIG_WEP */
4033 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
4034 if (capa
->enc
& ciphers
[i
].capa
) {
4035 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4036 pos
== buf
? "" : " ",
4038 if (os_snprintf_error(end
- pos
, ret
))
4048 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
4049 struct wpa_driver_capa
*capa
,
4050 char *buf
, size_t buflen
)
4062 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
4063 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
4064 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4065 pos
== buf
? "" : " ",
4066 ciphers_group_mgmt
[i
].name
);
4067 if (os_snprintf_error(end
- pos
, ret
))
4077 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
4078 struct wpa_driver_capa
*capa
,
4079 char *buf
, size_t buflen
)
4091 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4098 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
4099 if (os_snprintf_error(end
- pos
, ret
))
4103 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4104 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
4105 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
4106 if (os_snprintf_error(end
- pos
, ret
))
4111 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
4112 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4113 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
4114 if (os_snprintf_error(end
- pos
, ret
))
4119 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
4120 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
4121 if (os_snprintf_error(end
- pos
, ret
))
4126 #ifdef CONFIG_SUITEB
4127 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
4128 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
4129 if (os_snprintf_error(end
- pos
, ret
))
4133 #endif /* CONFIG_SUITEB */
4134 #ifdef CONFIG_SUITEB192
4135 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
4136 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
4137 if (os_snprintf_error(end
- pos
, ret
))
4141 #endif /* CONFIG_SUITEB192 */
4143 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
4144 ret
= os_snprintf(pos
, end
- pos
, " OWE");
4145 if (os_snprintf_error(end
- pos
, ret
))
4149 #endif /* CONFIG_OWE */
4151 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
4152 ret
= os_snprintf(pos
, end
- pos
, " DPP");
4153 if (os_snprintf_error(end
- pos
, ret
))
4157 #endif /* CONFIG_DPP */
4159 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
4160 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
4161 if (os_snprintf_error(end
- pos
, ret
))
4165 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
4166 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
4167 if (os_snprintf_error(end
- pos
, ret
))
4171 #ifdef CONFIG_IEEE80211R
4172 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
4173 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
4174 if (os_snprintf_error(end
- pos
, ret
))
4178 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
4179 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
4180 if (os_snprintf_error(end
- pos
, ret
))
4184 #endif /* CONFIG_IEEE80211R */
4185 #endif /* CONFIG_FILS */
4186 #ifdef CONFIG_IEEE80211R
4187 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
) {
4188 ret
= os_snprintf(pos
, end
- pos
, " FT-PSK");
4189 if (os_snprintf_error(end
- pos
, ret
))
4193 #endif /* CONFIG_IEEE80211R */
4195 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SAE
) {
4196 ret
= os_snprintf(pos
, end
- pos
, " SAE");
4197 if (os_snprintf_error(end
- pos
, ret
))
4201 #endif /* CONFIG_SAE */
4207 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
4208 struct wpa_driver_capa
*capa
,
4209 char *buf
, size_t buflen
)
4221 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
4227 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
4228 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4229 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
4230 pos
== buf
? "" : " ");
4231 if (os_snprintf_error(end
- pos
, ret
))
4236 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4237 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
4238 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
4239 pos
== buf
? "" : " ");
4240 if (os_snprintf_error(end
- pos
, ret
))
4249 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
4250 int res
, char *strict
,
4251 struct wpa_driver_capa
*capa
,
4252 char *buf
, size_t buflen
)
4264 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4270 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4271 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4272 pos
== buf
? "" : " ");
4273 if (os_snprintf_error(end
- pos
, ret
))
4278 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4279 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4280 pos
== buf
? "" : " ");
4281 if (os_snprintf_error(end
- pos
, ret
))
4286 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4287 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4288 pos
== buf
? "" : " ");
4289 if (os_snprintf_error(end
- pos
, ret
))
4295 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4296 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4297 pos
== buf
? "" : " ");
4298 if (os_snprintf_error(end
- pos
, ret
))
4302 #endif /* CONFIG_SAE */
4305 if (wpa_is_fils_supported(wpa_s
)) {
4306 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4307 pos
== buf
? "" : " ");
4308 if (os_snprintf_error(end
- pos
, ret
))
4313 #ifdef CONFIG_FILS_SK_PFS
4314 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4315 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4316 pos
== buf
? "" : " ");
4317 if (os_snprintf_error(end
- pos
, ret
))
4321 #endif /* CONFIG_FILS_SK_PFS */
4322 #endif /* CONFIG_FILS */
4328 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4329 struct wpa_driver_capa
*capa
,
4330 char *buf
, size_t buflen
)
4342 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4348 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4349 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4350 pos
== buf
? "" : " ");
4351 if (os_snprintf_error(end
- pos
, ret
))
4356 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4357 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4358 pos
== buf
? "" : " ");
4359 if (os_snprintf_error(end
- pos
, ret
))
4365 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4366 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4367 pos
== buf
? "" : " ");
4368 if (os_snprintf_error(end
- pos
, ret
))
4372 #endif /* CONFIG_MESH */
4378 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4379 char *buf
, size_t buflen
)
4381 struct hostapd_channel_data
*chnl
;
4383 char *pos
, *end
, *hmode
;
4388 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4389 switch (wpa_s
->hw
.modes
[j
].mode
) {
4390 case HOSTAPD_MODE_IEEE80211B
:
4393 case HOSTAPD_MODE_IEEE80211G
:
4396 case HOSTAPD_MODE_IEEE80211A
:
4399 case HOSTAPD_MODE_IEEE80211AD
:
4405 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4406 if (os_snprintf_error(end
- pos
, ret
))
4409 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4410 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4411 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4413 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4414 if (os_snprintf_error(end
- pos
, ret
))
4418 ret
= os_snprintf(pos
, end
- pos
, "\n");
4419 if (os_snprintf_error(end
- pos
, ret
))
4428 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4429 char *buf
, size_t buflen
)
4431 struct hostapd_channel_data
*chnl
;
4433 char *pos
, *end
, *hmode
;
4438 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4439 switch (wpa_s
->hw
.modes
[j
].mode
) {
4440 case HOSTAPD_MODE_IEEE80211B
:
4443 case HOSTAPD_MODE_IEEE80211G
:
4446 case HOSTAPD_MODE_IEEE80211A
:
4449 case HOSTAPD_MODE_IEEE80211AD
:
4455 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4457 if (os_snprintf_error(end
- pos
, ret
))
4460 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4461 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4462 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4464 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4465 chnl
[i
].chan
, chnl
[i
].freq
,
4466 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4468 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4471 if (os_snprintf_error(end
- pos
, ret
))
4475 ret
= os_snprintf(pos
, end
- pos
, "\n");
4476 if (os_snprintf_error(end
- pos
, ret
))
4485 static int wpa_supplicant_ctrl_iface_get_capability(
4486 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4489 struct wpa_driver_capa capa
;
4495 /* Determine whether or not strict checking was requested */
4496 len
= os_strlcpy(field
, _field
, sizeof(field
));
4497 if (len
>= sizeof(field
))
4499 strict
= os_strchr(field
, ' ');
4500 if (strict
!= NULL
) {
4502 if (os_strcmp(strict
, "strict") != 0)
4506 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4507 field
, strict
? strict
: "");
4509 if (os_strcmp(field
, "eap") == 0) {
4510 return eap_get_names(buf
, buflen
);
4513 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4515 if (os_strcmp(field
, "pairwise") == 0)
4516 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4519 if (os_strcmp(field
, "group") == 0)
4520 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4523 if (os_strcmp(field
, "group_mgmt") == 0)
4524 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4527 if (os_strcmp(field
, "key_mgmt") == 0)
4528 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4531 if (os_strcmp(field
, "proto") == 0)
4532 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4535 if (os_strcmp(field
, "auth_alg") == 0)
4536 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4537 &capa
, buf
, buflen
);
4539 if (os_strcmp(field
, "modes") == 0)
4540 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4543 if (os_strcmp(field
, "channels") == 0)
4544 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4546 if (os_strcmp(field
, "freq") == 0)
4547 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4550 if (os_strcmp(field
, "tdls") == 0)
4551 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4552 #endif /* CONFIG_TDLS */
4555 if (os_strcmp(field
, "erp") == 0) {
4556 res
= os_snprintf(buf
, buflen
, "ERP");
4557 if (os_snprintf_error(buflen
, res
))
4561 #endif /* CONFIG_EPR */
4564 if (os_strcmp(field
, "fips") == 0) {
4565 res
= os_snprintf(buf
, buflen
, "FIPS");
4566 if (os_snprintf_error(buflen
, res
))
4570 #endif /* CONFIG_FIPS */
4573 if (os_strcmp(field
, "acs") == 0) {
4574 res
= os_snprintf(buf
, buflen
, "ACS");
4575 if (os_snprintf_error(buflen
, res
))
4579 #endif /* CONFIG_ACS */
4582 if (os_strcmp(field
, "fils") == 0) {
4583 #ifdef CONFIG_FILS_SK_PFS
4584 if (wpa_is_fils_supported(wpa_s
) &&
4585 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4586 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4587 if (os_snprintf_error(buflen
, res
))
4591 #endif /* CONFIG_FILS_SK_PFS */
4593 if (wpa_is_fils_supported(wpa_s
)) {
4594 res
= os_snprintf(buf
, buflen
, "FILS");
4595 if (os_snprintf_error(buflen
, res
))
4600 #endif /* CONFIG_FILS */
4602 if (os_strcmp(field
, "multibss") == 0 && wpa_s
->multi_bss_support
) {
4603 res
= os_snprintf(buf
, buflen
, "MULTIBSS-STA");
4604 if (os_snprintf_error(buflen
, res
))
4610 if (os_strcmp(field
, "dpp") == 0) {
4612 res
= os_snprintf(buf
, buflen
, "DPP=2");
4613 #else /* CONFIG_DPP2 */
4614 res
= os_snprintf(buf
, buflen
, "DPP=1");
4615 #endif /* CONFIG_DPP2 */
4616 if (os_snprintf_error(buflen
, res
))
4620 #endif /* CONFIG_DPP */
4622 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4629 #ifdef CONFIG_INTERWORKING
4630 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4631 struct wpabuf
*data
)
4641 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4642 if (os_snprintf_error(end
- pos
, ret
))
4646 d
= wpabuf_head_u8(data
);
4647 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4648 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4649 if (os_snprintf_error(end
- pos
, ret
))
4654 ret
= os_snprintf(pos
, end
- pos
, "\n");
4655 if (os_snprintf_error(end
- pos
, ret
))
4661 #endif /* CONFIG_INTERWORKING */
4665 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4668 const u8
*ie
, *ie_end
;
4672 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4675 ie_end
= ie
+ 2 + ie
[1];
4677 if (ie_end
- ie
< 2)
4680 info
= WPA_GET_LE16(ie
);
4682 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4683 if (os_snprintf_error(end
- pos
, ret
))
4687 if (info
& BIT(7)) {
4688 /* Cache Identifier Included */
4689 if (ie_end
- ie
< 2)
4691 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4693 if (os_snprintf_error(end
- pos
, ret
))
4699 if (info
& BIT(8)) {
4700 /* HESSID Included */
4701 if (ie_end
- ie
< ETH_ALEN
)
4703 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4705 if (os_snprintf_error(end
- pos
, ret
))
4711 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4713 if (ie_end
- ie
< realms
* 2)
4715 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4716 if (os_snprintf_error(end
- pos
, ret
))
4720 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4725 ret
= os_snprintf(pos
, end
- pos
, "\n");
4726 if (os_snprintf_error(end
- pos
, ret
))
4733 #endif /* CONFIG_FILS */
4736 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4737 unsigned long mask
, char *buf
, size_t buflen
)
4742 const u8
*ie
, *ie2
, *osen_ie
, *mesh
, *owe
;
4747 if (mask
& WPA_BSS_MASK_ID
) {
4748 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4749 if (os_snprintf_error(end
- pos
, ret
))
4754 if (mask
& WPA_BSS_MASK_BSSID
) {
4755 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4756 MAC2STR(bss
->bssid
));
4757 if (os_snprintf_error(end
- pos
, ret
))
4762 if (mask
& WPA_BSS_MASK_FREQ
) {
4763 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4764 if (os_snprintf_error(end
- pos
, ret
))
4769 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4770 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4772 if (os_snprintf_error(end
- pos
, ret
))
4777 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4778 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4780 if (os_snprintf_error(end
- pos
, ret
))
4785 if (mask
& WPA_BSS_MASK_QUAL
) {
4786 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4787 if (os_snprintf_error(end
- pos
, ret
))
4792 if (mask
& WPA_BSS_MASK_NOISE
) {
4793 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4794 if (os_snprintf_error(end
- pos
, ret
))
4799 if (mask
& WPA_BSS_MASK_LEVEL
) {
4800 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4801 if (os_snprintf_error(end
- pos
, ret
))
4806 if (mask
& WPA_BSS_MASK_TSF
) {
4807 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4808 (unsigned long long) bss
->tsf
);
4809 if (os_snprintf_error(end
- pos
, ret
))
4814 if (mask
& WPA_BSS_MASK_AGE
) {
4815 struct os_reltime now
;
4817 os_get_reltime(&now
);
4818 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4819 (int) (now
.sec
- bss
->last_update
.sec
));
4820 if (os_snprintf_error(end
- pos
, ret
))
4825 if (mask
& WPA_BSS_MASK_IE
) {
4826 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4827 if (os_snprintf_error(end
- pos
, ret
))
4831 ie
= (const u8
*) (bss
+ 1);
4832 for (i
= 0; i
< bss
->ie_len
; i
++) {
4833 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4834 if (os_snprintf_error(end
- pos
, ret
))
4839 ret
= os_snprintf(pos
, end
- pos
, "\n");
4840 if (os_snprintf_error(end
- pos
, ret
))
4845 if (mask
& WPA_BSS_MASK_FLAGS
) {
4846 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4847 if (os_snprintf_error(end
- pos
, ret
))
4851 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4853 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4855 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4857 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4859 pos
= wpa_supplicant_ie_txt(pos
, end
,
4860 mesh
? "RSN" : "WPA2", ie2
,
4862 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4864 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4865 osen_ie
, 2 + osen_ie
[1]);
4866 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
4870 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4871 if (os_snprintf_error(end
- pos
, ret
))
4875 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4876 if (!ie
&& !ie2
&& !osen_ie
&&
4877 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4878 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4879 if (os_snprintf_error(end
- pos
, ret
))
4885 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4886 if (os_snprintf_error(end
- pos
, ret
))
4891 if (bss_is_dmg(bss
)) {
4893 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4894 if (os_snprintf_error(end
- pos
, ret
))
4897 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4898 case IEEE80211_CAP_DMG_IBSS
:
4901 case IEEE80211_CAP_DMG_AP
:
4904 case IEEE80211_CAP_DMG_PBSS
:
4911 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4912 if (os_snprintf_error(end
- pos
, ret
))
4916 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4917 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4918 if (os_snprintf_error(end
- pos
, ret
))
4922 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4923 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4924 if (os_snprintf_error(end
- pos
, ret
))
4929 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4930 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4931 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4932 if (os_snprintf_error(end
- pos
, ret
))
4937 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4938 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4939 if (os_snprintf_error(end
- pos
, ret
))
4943 #endif /* CONFIG_HS20 */
4945 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4946 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4947 if (os_snprintf_error(end
- pos
, ret
))
4951 #endif /* CONFIG_FILS */
4953 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
4954 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
4955 if (os_snprintf_error(end
- pos
, ret
))
4959 #endif /* CONFIG_FST */
4960 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
4961 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
4962 if (os_snprintf_error(end
- pos
, ret
))
4967 ret
= os_snprintf(pos
, end
- pos
, "\n");
4968 if (os_snprintf_error(end
- pos
, ret
))
4973 if (mask
& WPA_BSS_MASK_SSID
) {
4974 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4975 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4976 if (os_snprintf_error(end
- pos
, ret
))
4982 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4983 ie
= (const u8
*) (bss
+ 1);
4984 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4985 if (ret
>= end
- pos
)
4990 #endif /* CONFIG_WPS */
4993 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4994 ie
= (const u8
*) (bss
+ 1);
4995 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4996 if (ret
>= end
- pos
)
5001 #endif /* CONFIG_P2P */
5003 #ifdef CONFIG_WIFI_DISPLAY
5004 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
5006 ie
= (const u8
*) (bss
+ 1);
5007 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
5008 WFD_IE_VENDOR_TYPE
);
5010 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
5011 if (os_snprintf_error(end
- pos
, ret
)) {
5017 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
5022 ret
= os_snprintf(pos
, end
- pos
, "\n");
5023 if (os_snprintf_error(end
- pos
, ret
))
5028 #endif /* CONFIG_WIFI_DISPLAY */
5030 #ifdef CONFIG_INTERWORKING
5031 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
5032 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
5033 struct wpa_bss_anqp_elem
*elem
;
5035 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
5036 anqp
->capability_list
);
5037 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
5039 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
5040 anqp
->network_auth_type
);
5041 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
5042 anqp
->roaming_consortium
);
5043 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
5044 anqp
->ip_addr_type_availability
);
5045 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
5047 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
5048 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
5050 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
5051 anqp
->fils_realm_info
);
5053 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
5054 anqp
->hs20_capability_list
);
5055 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
5056 anqp
->hs20_operator_friendly_name
);
5057 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
5058 anqp
->hs20_wan_metrics
);
5059 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
5060 anqp
->hs20_connection_capability
);
5061 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
5062 anqp
->hs20_operating_class
);
5063 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
5064 anqp
->hs20_osu_providers_list
);
5065 pos
= anqp_add_hex(pos
, end
, "hs20_operator_icon_metadata",
5066 anqp
->hs20_operator_icon_metadata
);
5067 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_nai_list",
5068 anqp
->hs20_osu_providers_nai_list
);
5069 #endif /* CONFIG_HS20 */
5071 dl_list_for_each(elem
, &anqp
->anqp_elems
,
5072 struct wpa_bss_anqp_elem
, list
) {
5075 os_snprintf(title
, sizeof(title
), "anqp[%u]",
5077 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
5080 #endif /* CONFIG_INTERWORKING */
5083 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
5084 ie
= (const u8
*) (bss
+ 1);
5085 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
5086 if (ret
>= end
- pos
)
5091 #endif /* CONFIG_MESH */
5093 if (mask
& WPA_BSS_MASK_SNR
) {
5094 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
5095 if (os_snprintf_error(end
- pos
, ret
))
5100 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
5101 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
5102 bss
->est_throughput
);
5103 if (os_snprintf_error(end
- pos
, ret
))
5109 if (mask
& WPA_BSS_MASK_FST
) {
5110 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
5111 if (ret
< 0 || ret
>= end
- pos
)
5115 #endif /* CONFIG_FST */
5117 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
5118 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
5119 bss
->last_update_idx
);
5120 if (os_snprintf_error(end
- pos
, ret
))
5125 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
5126 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
5127 if (os_snprintf_error(end
- pos
, ret
))
5131 ie
= (const u8
*) (bss
+ 1);
5133 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
5134 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
5135 if (os_snprintf_error(end
- pos
, ret
))
5140 ret
= os_snprintf(pos
, end
- pos
, "\n");
5141 if (os_snprintf_error(end
- pos
, ret
))
5147 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
5148 ret
= print_fils_indication(bss
, pos
, end
);
5153 #endif /* CONFIG_FILS */
5155 if (mask
& WPA_BSS_MASK_DELIM
) {
5156 ret
= os_snprintf(pos
, end
- pos
, "====\n");
5157 if (os_snprintf_error(end
- pos
, ret
))
5166 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
5167 const char *cmd
, char *buf
,
5172 struct wpa_bss
*bss
;
5173 struct wpa_bss
*bsslast
= NULL
;
5174 struct dl_list
*next
;
5177 char *ctmp
, *end
= buf
+ buflen
;
5178 unsigned long mask
= WPA_BSS_MASK_ALL
;
5180 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
5181 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
5182 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
5184 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
5186 } else { /* N1-N2 */
5187 unsigned int id1
, id2
;
5189 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
5190 wpa_printf(MSG_INFO
, "Wrong BSS range "
5195 if (*(cmd
+ 6) == '-')
5198 id1
= atoi(cmd
+ 6);
5200 if (*ctmp
>= '0' && *ctmp
<= '9')
5203 id2
= (unsigned int) -1;
5204 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
5205 if (id2
== (unsigned int) -1)
5206 bsslast
= dl_list_last(&wpa_s
->bss_id
,
5210 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
5211 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
5212 struct wpa_bss
*tmp
= bss
;
5214 next
= tmp
->list_id
.next
;
5215 if (next
== &wpa_s
->bss_id
)
5217 tmp
= dl_list_entry(
5218 next
, struct wpa_bss
,
5227 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
5228 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5229 else if (os_strncmp(cmd
, "LAST", 4) == 0)
5230 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5231 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
5233 bss
= wpa_bss_get_id(wpa_s
, i
);
5234 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
5236 bss
= wpa_bss_get_id(wpa_s
, i
);
5238 next
= bss
->list_id
.next
;
5239 if (next
== &wpa_s
->bss_id
)
5242 bss
= dl_list_entry(next
, struct wpa_bss
,
5245 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
5246 bss
= wpa_s
->current_bss
;
5248 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
5249 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
5250 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
5253 #endif /* CONFIG_P2P */
5254 } else if (hwaddr_aton(cmd
, bssid
) == 0)
5255 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5257 struct wpa_bss
*tmp
;
5260 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
5270 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
5271 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
5273 mask
= WPA_BSS_MASK_ALL
;
5279 if (bsslast
== NULL
)
5282 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
5286 if (bss
== bsslast
) {
5287 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
5288 (bss
== dl_list_last(&wpa_s
->bss_id
,
5289 struct wpa_bss
, list_id
))) {
5292 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
5294 if (os_snprintf_error(end
- buf
+ 5, res
)) {
5295 wpa_printf(MSG_DEBUG
,
5296 "Could not add end delim");
5301 next
= bss
->list_id
.next
;
5302 if (next
== &wpa_s
->bss_id
)
5304 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
5305 } while (bss
&& len
);
5311 static int wpa_supplicant_ctrl_iface_ap_scan(
5312 struct wpa_supplicant
*wpa_s
, char *cmd
)
5314 int ap_scan
= atoi(cmd
);
5315 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5319 static int wpa_supplicant_ctrl_iface_scan_interval(
5320 struct wpa_supplicant
*wpa_s
, char *cmd
)
5322 int scan_int
= atoi(cmd
);
5323 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5327 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5328 struct wpa_supplicant
*wpa_s
, char *cmd
)
5330 int expire_age
= atoi(cmd
);
5331 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5335 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5336 struct wpa_supplicant
*wpa_s
, char *cmd
)
5338 int expire_count
= atoi(cmd
);
5339 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5343 static void wpa_supplicant_ctrl_iface_bss_flush(
5344 struct wpa_supplicant
*wpa_s
, char *cmd
)
5346 int flush_age
= atoi(cmd
);
5349 wpa_bss_flush(wpa_s
);
5351 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5355 #ifdef CONFIG_TESTING_OPTIONS
5356 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5358 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5359 /* MLME-DELETEKEYS.request */
5360 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
,
5362 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
,
5364 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
,
5366 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
,
5368 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
,
5370 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
,
5373 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5374 0, KEY_FLAG_PAIRWISE
);
5375 /* MLME-SETPROTECTION.request(None) */
5376 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5377 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5378 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5379 wpa_sm_drop_sa(wpa_s
->wpa
);
5381 #endif /* CONFIG_TESTING_OPTIONS */
5384 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5387 #ifdef CONFIG_NO_SCAN_PROCESSING
5389 #else /* CONFIG_NO_SCAN_PROCESSING */
5391 struct wpa_bss
*bss
;
5392 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5394 if (hwaddr_aton(addr
, bssid
)) {
5395 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5396 "address '%s'", addr
);
5400 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5403 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5404 "configuration known for the target AP");
5408 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5410 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5416 * TODO: Find best network configuration block from configuration to
5417 * allow roaming to other networks
5420 wpa_s
->reassociate
= 1;
5421 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5424 #endif /* CONFIG_NO_SCAN_PROCESSING */
5429 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5431 unsigned int timeout
= atoi(cmd
);
5432 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5433 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5434 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5436 unsigned int search_delay
;
5437 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5441 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5442 wpa_dbg(wpa_s
, MSG_INFO
,
5443 "Reject P2P_FIND since interface is disabled");
5446 if (os_strstr(cmd
, "type=social"))
5447 type
= P2P_FIND_ONLY_SOCIAL
;
5448 else if (os_strstr(cmd
, "type=progressive"))
5449 type
= P2P_FIND_PROGRESSIVE
;
5451 pos
= os_strstr(cmd
, "dev_id=");
5454 if (hwaddr_aton(pos
, dev_id
))
5459 pos
= os_strstr(cmd
, "dev_type=");
5462 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5464 _dev_type
= dev_type
;
5467 pos
= os_strstr(cmd
, "delay=");
5470 search_delay
= atoi(pos
);
5472 search_delay
= wpas_p2p_search_delay(wpa_s
);
5474 pos
= os_strstr(cmd
, "freq=");
5482 /* Must be searched for last, because it adds nul termination */
5483 pos
= os_strstr(cmd
, " seek=");
5486 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5489 _seek
[seek_count
++] = pos
;
5491 term
= os_strchr(pos
, ' ');
5495 pos
= os_strstr(term
+ 1, "seek=");
5499 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5504 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5505 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5509 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5511 const char *last
= NULL
;
5516 /* Expected predefined CPT names delimited by ':' */
5517 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5518 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5519 wpa_printf(MSG_ERROR
,
5520 "P2PS: CPT name list is too long, expected up to %d names",
5521 P2PS_FEATURE_CAPAB_CPT_MAX
);
5526 token_len
= last
- token
;
5528 if (token_len
== 3 &&
5529 os_memcmp(token
, "UDP", token_len
) == 0) {
5530 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5531 } else if (token_len
== 3 &&
5532 os_memcmp(token
, "MAC", token_len
) == 0) {
5533 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5535 wpa_printf(MSG_ERROR
,
5536 "P2PS: Unsupported CPT name '%s'", token
);
5541 if (isblank((unsigned char) *last
)) {
5551 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5553 struct p2ps_provision
*p2ps_prov
;
5555 size_t info_len
= 0;
5557 u8 role
= P2PS_SETUP_NONE
;
5558 long long unsigned val
;
5561 pos
= os_strstr(cmd
, "info=");
5564 info_len
= os_strlen(pos
);
5567 info
= os_malloc(info_len
+ 1);
5569 info_len
= utf8_unescape(pos
, info_len
,
5570 info
, info_len
+ 1);
5576 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5577 if (p2ps_prov
== NULL
) {
5583 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5584 p2ps_prov
->info
[info_len
] = '\0';
5588 pos
= os_strstr(cmd
, "status=");
5590 p2ps_prov
->status
= atoi(pos
+ 7);
5592 p2ps_prov
->status
= -1;
5594 pos
= os_strstr(cmd
, "adv_id=");
5595 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5597 p2ps_prov
->adv_id
= val
;
5599 pos
= os_strstr(cmd
, "method=");
5601 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5603 p2ps_prov
->method
= 0;
5605 pos
= os_strstr(cmd
, "session=");
5606 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5608 p2ps_prov
->session_id
= val
;
5610 pos
= os_strstr(cmd
, "adv_mac=");
5611 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5614 pos
= os_strstr(cmd
, "session_mac=");
5615 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5618 pos
= os_strstr(cmd
, "cpt=");
5620 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5621 p2ps_prov
->cpt_priority
))
5624 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5627 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5628 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5630 /* force conncap with tstCap (no sanity checks) */
5631 pos
= os_strstr(cmd
, "tstCap=");
5633 role
= strtol(pos
+ 7, NULL
, 16);
5635 pos
= os_strstr(cmd
, "role=");
5637 role
= strtol(pos
+ 5, NULL
, 16);
5638 if (role
!= P2PS_SETUP_CLIENT
&&
5639 role
!= P2PS_SETUP_GROUP_OWNER
)
5640 role
= P2PS_SETUP_NONE
;
5643 p2ps_prov
->role
= role
;
5653 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5656 struct p2ps_provision
*p2ps_prov
;
5659 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5661 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5663 if (hwaddr_aton(cmd
, addr
))
5670 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5674 if (p2ps_prov
->status
< 0) {
5679 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5684 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5687 struct p2ps_provision
*p2ps_prov
;
5690 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5691 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5694 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5695 if (hwaddr_aton(cmd
, addr
))
5702 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5706 p2ps_prov
->pd_seeker
= 1;
5708 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5713 static int parse_freq(int chwidth
, int freq2
)
5718 return CHANWIDTH_80P80MHZ
;
5724 return CHANWIDTH_USE_HT
;
5726 return CHANWIDTH_80MHZ
;
5728 return CHANWIDTH_160MHZ
;
5730 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5737 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5738 char *buf
, size_t buflen
)
5743 enum p2p_wps_method wps_method
;
5746 int persistent_group
, persistent_id
= -1;
5753 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5755 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5756 size_t group_ssid_len
= 0;
5759 if (!wpa_s
->global
->p2p_init_wpa_s
)
5761 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5762 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5763 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5764 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5767 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5768 * [persistent|persistent=<network id>]
5769 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5770 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
5772 if (hwaddr_aton(cmd
, addr
))
5780 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5781 pos2
= os_strstr(pos
, " persistent=");
5783 struct wpa_ssid
*ssid
;
5784 persistent_id
= atoi(pos2
+ 12);
5785 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5786 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5787 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5788 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5789 "SSID id=%d for persistent P2P group (GO)",
5794 join
= os_strstr(pos
, " join") != NULL
;
5795 auth
= os_strstr(pos
, " auth") != NULL
;
5796 automatic
= os_strstr(pos
, " auto") != NULL
;
5797 pd
= os_strstr(pos
, " provdisc") != NULL
;
5798 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5799 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5801 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
5802 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
5804 pos2
= os_strstr(pos
, " go_intent=");
5807 go_intent
= atoi(pos2
);
5808 if (go_intent
< 0 || go_intent
> 15)
5812 pos2
= os_strstr(pos
, " freq=");
5820 pos2
= os_strstr(pos
, " freq2=");
5822 freq2
= atoi(pos2
+ 7);
5824 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5826 chwidth
= atoi(pos2
+ 18);
5828 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5829 if (max_oper_chwidth
< 0)
5832 pos2
= os_strstr(pos
, " ssid=");
5837 end
= os_strchr(pos2
, ' ');
5839 group_ssid_len
= os_strlen(pos2
) / 2;
5841 group_ssid_len
= (end
- pos2
) / 2;
5842 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5843 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5845 group_ssid
= _group_ssid
;
5848 if (os_strncmp(pos
, "pin", 3) == 0) {
5849 /* Request random PIN (to be displayed) and enable the PIN */
5850 wps_method
= WPS_PIN_DISPLAY
;
5851 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5852 wps_method
= WPS_PBC
;
5853 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5854 wps_method
= WPS_P2PS
;
5857 pos
= os_strchr(pin
, ' ');
5858 wps_method
= WPS_PIN_KEYPAD
;
5861 if (os_strncmp(pos
, "display", 7) == 0)
5862 wps_method
= WPS_PIN_DISPLAY
;
5864 if (!wps_pin_str_valid(pin
)) {
5865 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5870 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5871 persistent_group
, automatic
, join
,
5872 auth
, go_intent
, freq
, freq2
, persistent_id
,
5873 pd
, ht40
, vht
, max_oper_chwidth
, he
, edmg
,
5874 group_ssid
, group_ssid_len
);
5875 if (new_pin
== -2) {
5876 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5879 if (new_pin
== -3) {
5880 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5885 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5886 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5887 if (os_snprintf_error(buflen
, ret
))
5892 os_memcpy(buf
, "OK\n", 3);
5897 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5899 unsigned int timeout
= atoi(cmd
);
5900 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5901 wpa_dbg(wpa_s
, MSG_INFO
,
5902 "Reject P2P_LISTEN since interface is disabled");
5905 return wpas_p2p_listen(wpa_s
, timeout
);
5909 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5913 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5915 /* <addr> <config method> [join|auto] */
5917 if (hwaddr_aton(cmd
, addr
))
5925 if (os_strstr(pos
, " join") != NULL
)
5926 use
= WPAS_P2P_PD_FOR_JOIN
;
5927 else if (os_strstr(pos
, " auto") != NULL
)
5928 use
= WPAS_P2P_PD_AUTO
;
5930 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5934 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5937 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5939 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5940 ssid
->passphrase
== NULL
)
5943 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5944 return os_strlen(buf
);
5948 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5949 char *buf
, size_t buflen
)
5953 u8 dst_buf
[ETH_ALEN
], *dst
;
5954 struct wpabuf
*tlvs
;
5958 if (hwaddr_aton(cmd
, dst_buf
))
5961 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5962 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5969 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5972 if (hexstr2bin(pos
, &version
, 1) < 0)
5978 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5979 #ifdef CONFIG_WIFI_DISPLAY
5980 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5981 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5982 #endif /* CONFIG_WIFI_DISPLAY */
5983 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5985 char *svc_info
= NULL
;
5989 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5992 pos
= os_strchr(pos
, ' ');
5993 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5998 pos
= os_strchr(svc_str
, ' ');
6003 /* All remaining data is the svc_info string */
6004 if (pos
&& pos
[0] && pos
[0] != ' ') {
6005 len
= os_strlen(pos
);
6007 /* Unescape in place */
6008 len
= utf8_unescape(pos
, len
, pos
, len
);
6015 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
6018 len
= os_strlen(pos
);
6022 tlvs
= wpabuf_alloc(len
);
6025 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
6030 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
6035 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
6036 if (os_snprintf_error(buflen
, res
))
6042 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
6045 long long unsigned val
;
6047 if (sscanf(cmd
, "%llx", &val
) != 1)
6050 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
6054 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6059 struct wpabuf
*resp_tlvs
;
6063 pos
= os_strchr(cmd
, ' ');
6071 if (hwaddr_aton(pos
, dst
))
6078 pos2
= os_strchr(pos
, ' ');
6082 dialog_token
= atoi(pos
);
6084 len
= os_strlen(pos2
);
6088 resp_tlvs
= wpabuf_alloc(len
);
6089 if (resp_tlvs
== NULL
)
6091 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
6092 wpabuf_free(resp_tlvs
);
6096 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
6097 wpabuf_free(resp_tlvs
);
6102 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
6105 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
6107 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
6112 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
6117 struct wpabuf
*query
, *resp
;
6119 pos
= os_strchr(cmd
, ' ');
6124 len
= os_strlen(cmd
);
6128 query
= wpabuf_alloc(len
);
6131 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6136 len
= os_strlen(pos
);
6142 resp
= wpabuf_alloc(len
);
6147 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
6153 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
6162 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6167 pos
= os_strchr(cmd
, ' ');
6172 if (hexstr2bin(cmd
, &version
, 1) < 0)
6175 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
6179 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
6180 u8 replace
, char *cmd
)
6184 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
6185 char *svc_info
= NULL
;
6187 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
6189 pos
= os_strchr(cmd
, ' ');
6194 /* Auto-Accept value is mandatory, and must be one of the
6195 * single values (0, 1, 2, 4) */
6196 auto_accept
= atoi(cmd
);
6197 switch (auto_accept
) {
6198 case P2PS_SETUP_NONE
: /* No auto-accept */
6199 case P2PS_SETUP_NEW
:
6200 case P2PS_SETUP_CLIENT
:
6201 case P2PS_SETUP_GROUP_OWNER
:
6207 /* Advertisement ID is mandatory */
6209 pos
= os_strchr(cmd
, ' ');
6214 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6215 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
6218 /* Only allow replacements if exist, and adds if not */
6219 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
6227 /* svc_state between 0 - 0xff is mandatory */
6228 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
6231 pos
= os_strchr(pos
, ' ');
6235 /* config_methods is mandatory */
6237 if (sscanf(pos
, "%x", &config_methods
) != 1)
6240 if (!(config_methods
&
6241 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
6244 pos
= os_strchr(pos
, ' ');
6251 /* Advertisement string is mandatory */
6252 if (!pos
[0] || pos
[0] == ' ')
6255 /* Terminate svc string */
6256 pos
= os_strchr(pos
, ' ');
6260 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
6262 pos
= os_strchr(pos
, ' ');
6266 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
6269 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
6273 /* Service and Response Information are optional */
6274 if (pos
&& pos
[0]) {
6277 /* Note the bare ' included, which cannot exist legally
6278 * in unescaped string. */
6279 svc_info
= os_strstr(pos
, "svc_info='");
6283 len
= os_strlen(svc_info
);
6284 utf8_unescape(svc_info
, len
, svc_info
, len
);
6288 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
6289 (u8
) svc_state
, (u16
) config_methods
,
6290 svc_info
, cpt_prio
);
6294 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6298 pos
= os_strchr(cmd
, ' ');
6303 if (os_strcmp(cmd
, "bonjour") == 0)
6304 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
6305 if (os_strcmp(cmd
, "upnp") == 0)
6306 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
6307 if (os_strcmp(cmd
, "asp") == 0)
6308 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
6309 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6314 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
6318 struct wpabuf
*query
;
6321 len
= os_strlen(cmd
);
6325 query
= wpabuf_alloc(len
);
6328 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6333 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6339 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6344 pos
= os_strchr(cmd
, ' ');
6349 if (hexstr2bin(cmd
, &version
, 1) < 0)
6352 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6356 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6360 if (os_strcmp(cmd
, "all") == 0) {
6361 wpas_p2p_service_flush_asp(wpa_s
);
6365 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6368 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6372 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6376 pos
= os_strchr(cmd
, ' ');
6381 if (os_strcmp(cmd
, "bonjour") == 0)
6382 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6383 if (os_strcmp(cmd
, "upnp") == 0)
6384 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6385 if (os_strcmp(cmd
, "asp") == 0)
6386 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6387 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6392 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6396 pos
= os_strchr(cmd
, ' ');
6401 if (os_strcmp(cmd
, "asp") == 0)
6402 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6404 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6409 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6415 if (hwaddr_aton(cmd
, addr
))
6418 return wpas_p2p_reject(wpa_s
, addr
);
6422 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6426 struct wpa_ssid
*ssid
;
6427 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6428 int freq
= 0, pref_freq
= 0;
6429 int ht40
, vht
, he
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6433 pos
= os_strstr(cmd
, " peer=");
6436 if (hwaddr_aton(pos
, peer
))
6440 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6441 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6442 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6443 "for persistent P2P group",
6448 pos
= os_strstr(cmd
, " freq=");
6456 pos
= os_strstr(cmd
, " pref=");
6459 pref_freq
= atoi(pos
);
6464 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6465 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6467 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
6468 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
6470 pos
= os_strstr(cmd
, "freq2=");
6472 freq2
= atoi(pos
+ 6);
6474 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6476 chwidth
= atoi(pos
+ 18);
6478 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6479 if (max_oper_chwidth
< 0)
6482 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6483 max_oper_chwidth
, pref_freq
, he
, edmg
);
6487 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6490 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6492 pos
= os_strstr(cmd
, " peer=");
6498 if (hwaddr_aton(pos
, peer
)) {
6499 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6503 pos
= os_strstr(pos
, " go_dev_addr=");
6506 if (hwaddr_aton(pos
, go_dev_addr
)) {
6507 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6511 go_dev
= go_dev_addr
;
6514 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6518 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6520 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6521 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6522 if (os_strncmp(cmd
, "group=", 6) == 0)
6523 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6529 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6530 int id
, int freq
, int vht_center_freq2
,
6531 int ht40
, int vht
, int vht_chwidth
,
6534 struct wpa_ssid
*ssid
;
6536 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6537 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6538 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6539 "for persistent P2P group",
6544 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6545 vht_center_freq2
, 0, ht40
, vht
,
6546 vht_chwidth
, he
, edmg
,
6551 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6553 int freq
= 0, persistent
= 0, group_id
= -1;
6554 int vht
= wpa_s
->conf
->p2p_go_vht
;
6555 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6556 int he
= wpa_s
->conf
->p2p_go_he
;
6557 int edmg
= wpa_s
->conf
->p2p_go_edmg
;
6558 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6559 char *token
, *context
= NULL
;
6562 #endif /* CONFIG_ACS */
6564 while ((token
= str_token(cmd
, " ", &context
))) {
6565 if (sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6566 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6567 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6570 } else if (os_strcmp(token
, "freq=acs") == 0) {
6572 #endif /* CONFIG_ACS */
6573 } else if (sscanf(token
, "freq=%d", &freq
) == 1) {
6575 } else if (os_strcmp(token
, "ht40") == 0) {
6577 } else if (os_strcmp(token
, "vht") == 0) {
6580 } else if (os_strcmp(token
, "he") == 0) {
6582 } else if (os_strcmp(token
, "edmg") == 0) {
6584 } else if (os_strcmp(token
, "persistent") == 0) {
6587 wpa_printf(MSG_DEBUG
,
6588 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6595 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_ACS_OFFLOAD
) &&
6596 (acs
|| freq
== 2 || freq
== 5)) {
6597 if (freq
== 2 && wpa_s
->best_24_freq
<= 0) {
6598 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211G
;
6599 wpa_s
->p2p_go_do_acs
= 1;
6601 } else if (freq
== 5 && wpa_s
->best_5_freq
<= 0) {
6602 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211A
;
6603 wpa_s
->p2p_go_do_acs
= 1;
6606 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211ANY
;
6607 wpa_s
->p2p_go_do_acs
= 1;
6610 wpa_s
->p2p_go_do_acs
= 0;
6612 #endif /* CONFIG_ACS */
6614 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6615 if (max_oper_chwidth
< 0)
6619 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6620 freq
, freq2
, ht40
, vht
,
6621 max_oper_chwidth
, he
,
6624 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6625 max_oper_chwidth
, he
, edmg
);
6629 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6630 char *buf
, size_t buflen
)
6632 u8 dev_addr
[ETH_ALEN
];
6633 struct wpa_ssid
*ssid
;
6637 ssid
= wpa_s
->current_ssid
;
6638 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6639 hwaddr_aton(cmd
, dev_addr
))
6642 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6645 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6646 if (os_snprintf_error(buflen
, res
))
6652 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6653 const u8
*p2p_dev_addr
)
6655 struct wpa_supplicant
*wpa_s
;
6657 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6658 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6666 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6667 char *buf
, size_t buflen
)
6669 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6671 const struct p2p_peer_info
*info
;
6673 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6674 struct wpa_ssid
*ssid
;
6677 if (!wpa_s
->global
->p2p
)
6680 if (os_strcmp(cmd
, "FIRST") == 0) {
6683 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6684 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6689 if (hwaddr_aton(cmd
, addr
) < 0)
6695 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6698 group_capab
= info
->group_capab
;
6701 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6702 wpa_printf(MSG_DEBUG
,
6703 "P2P: Could not find any BSS with p2p_dev_addr "
6704 MACSTR
", hence override group_capab from 0x%x to 0",
6705 MAC2STR(info
->p2p_device_addr
), group_capab
);
6712 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6718 "serial_number=%s\n"
6719 "config_methods=0x%x\n"
6721 "group_capab=0x%x\n"
6723 MAC2STR(info
->p2p_device_addr
),
6724 wps_dev_type_bin2str(info
->pri_dev_type
,
6725 devtype
, sizeof(devtype
)),
6730 info
->serial_number
,
6731 info
->config_methods
,
6735 if (os_snprintf_error(end
- pos
, res
))
6739 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6742 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6743 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6744 wps_dev_type_bin2str(t
, devtype
,
6746 if (os_snprintf_error(end
- pos
, res
))
6751 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6753 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6754 if (os_snprintf_error(end
- pos
, res
))
6759 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6764 if (info
->vendor_elems
) {
6765 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6766 if (os_snprintf_error(end
- pos
, res
))
6770 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6771 wpabuf_head(info
->vendor_elems
),
6772 wpabuf_len(info
->vendor_elems
));
6774 res
= os_snprintf(pos
, end
- pos
, "\n");
6775 if (os_snprintf_error(end
- pos
, res
))
6784 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6789 if (wpa_s
->global
->p2p
== NULL
)
6792 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6795 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6796 struct wpa_freq_range
*freq
;
6797 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6798 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6799 freq
->min
, freq
->max
);
6802 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6807 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6811 if (wpa_s
->global
->p2p
== NULL
)
6814 param
= os_strchr(cmd
, ' ');
6819 if (os_strcmp(cmd
, "discoverability") == 0) {
6820 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6825 if (os_strcmp(cmd
, "managed") == 0) {
6826 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6830 if (os_strcmp(cmd
, "listen_channel") == 0) {
6832 u8 channel
, op_class
;
6834 channel
= atoi(param
);
6835 pos
= os_strchr(param
, ' ');
6836 op_class
= pos
? atoi(pos
) : 81;
6838 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6842 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6843 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6847 if (os_strcmp(cmd
, "noa") == 0) {
6849 int count
, start
, duration
;
6850 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6851 count
= atoi(param
);
6852 pos
= os_strchr(param
, ',');
6857 pos
= os_strchr(pos
, ',');
6861 duration
= atoi(pos
);
6862 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6864 if (count
== 0 && duration
> 0)
6866 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6867 "start=%d duration=%d", count
, start
, duration
);
6868 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6871 if (os_strcmp(cmd
, "ps") == 0)
6872 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6874 if (os_strcmp(cmd
, "oppps") == 0)
6875 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6877 if (os_strcmp(cmd
, "ctwindow") == 0)
6878 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6880 if (os_strcmp(cmd
, "disabled") == 0) {
6881 wpa_s
->global
->p2p_disabled
= atoi(param
);
6882 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6883 wpa_s
->global
->p2p_disabled
?
6884 "disabled" : "enabled");
6885 if (wpa_s
->global
->p2p_disabled
) {
6886 wpas_p2p_stop_find(wpa_s
);
6887 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6888 p2p_flush(wpa_s
->global
->p2p
);
6893 if (os_strcmp(cmd
, "conc_pref") == 0) {
6894 if (os_strcmp(param
, "sta") == 0)
6895 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6896 else if (os_strcmp(param
, "p2p") == 0)
6897 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6899 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6902 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6907 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6908 wpa_s
->force_long_sd
= atoi(param
);
6912 if (os_strcmp(cmd
, "peer_filter") == 0) {
6914 if (hwaddr_aton(param
, addr
))
6916 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6920 if (os_strcmp(cmd
, "cross_connect") == 0)
6921 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6923 if (os_strcmp(cmd
, "go_apsd") == 0) {
6924 if (os_strcmp(param
, "disable") == 0)
6925 wpa_s
->set_ap_uapsd
= 0;
6927 wpa_s
->set_ap_uapsd
= 1;
6928 wpa_s
->ap_uapsd
= atoi(param
);
6933 if (os_strcmp(cmd
, "client_apsd") == 0) {
6934 if (os_strcmp(param
, "disable") == 0)
6935 wpa_s
->set_sta_uapsd
= 0;
6939 /* format: BE,BK,VI,VO;max SP Length */
6941 pos
= os_strchr(param
, ',');
6946 pos
= os_strchr(pos
, ',');
6951 pos
= os_strchr(pos
, ',');
6956 /* ignore max SP Length for now */
6958 wpa_s
->set_sta_uapsd
= 1;
6959 wpa_s
->sta_uapsd
= 0;
6961 wpa_s
->sta_uapsd
|= BIT(0);
6963 wpa_s
->sta_uapsd
|= BIT(1);
6965 wpa_s
->sta_uapsd
|= BIT(2);
6967 wpa_s
->sta_uapsd
|= BIT(3);
6972 if (os_strcmp(cmd
, "disallow_freq") == 0)
6973 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6975 if (os_strcmp(cmd
, "disc_int") == 0) {
6976 int min_disc_int
, max_disc_int
, max_disc_tu
;
6981 min_disc_int
= atoi(pos
);
6982 pos
= os_strchr(pos
, ' ');
6987 max_disc_int
= atoi(pos
);
6988 pos
= os_strchr(pos
, ' ');
6993 max_disc_tu
= atoi(pos
);
6995 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6996 max_disc_int
, max_disc_tu
);
6999 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
7000 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
7004 #ifdef CONFIG_WPS_NFC
7005 if (os_strcmp(cmd
, "nfc_tag") == 0)
7006 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
7007 #endif /* CONFIG_WPS_NFC */
7009 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
7010 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
7014 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
7017 op_class
= atoi(param
);
7018 param
= os_strchr(param
, ':');
7023 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
7028 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7035 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
7037 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
7038 wpa_s
->force_long_sd
= 0;
7040 #ifdef CONFIG_TESTING_OPTIONS
7041 os_free(wpa_s
->get_pref_freq_list_override
);
7042 wpa_s
->get_pref_freq_list_override
= NULL
;
7043 #endif /* CONFIG_TESTING_OPTIONS */
7045 wpas_p2p_stop_find(wpa_s
);
7046 wpa_s
->parent
->p2ps_method_config_any
= 0;
7047 if (wpa_s
->global
->p2p
)
7048 p2p_flush(wpa_s
->global
->p2p
);
7052 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
7055 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
7058 pos
= os_strchr(cmd
, ' ');
7064 pos2
= os_strchr(pos
, ' ');
7072 pos
= os_strchr(pos2
, ' ');
7080 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
7084 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
7087 unsigned int period
= 0, interval
= 0;
7090 pos
= os_strchr(cmd
, ' ');
7095 interval
= atoi(pos
);
7098 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
7102 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
7109 if (os_strncmp(pos
, "iface=", 6) == 0) {
7113 if (hwaddr_aton(pos
, peer
))
7116 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
7121 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
7123 int freq
= 0, period
= 0, interval
= 0, count
= 0;
7125 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
7127 wpa_printf(MSG_DEBUG
,
7128 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
7132 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
7135 #endif /* CONFIG_P2P */
7138 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
7140 struct wpa_freq_range_list ranges
;
7142 struct hostapd_hw_modes
*mode
;
7145 if (wpa_s
->hw
.modes
== NULL
)
7148 os_memset(&ranges
, 0, sizeof(ranges
));
7149 if (freq_range_list_parse(&ranges
, val
) < 0)
7152 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
7155 mode
= &wpa_s
->hw
.modes
[i
];
7156 for (j
= 0; j
< mode
->num_channels
; j
++) {
7159 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
7162 freq
= mode
->channels
[j
].freq
;
7163 if (!freq_range_list_includes(&ranges
, freq
))
7166 int_array_add_unique(&freqs
, freq
);
7170 os_free(ranges
.range
);
7175 #ifdef CONFIG_INTERWORKING
7177 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
7185 auto_sel
= os_strstr(param
, "auto") != NULL
;
7187 pos
= os_strstr(param
, "freq=");
7189 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
7196 return interworking_select(wpa_s
, auto_sel
, freqs
);
7200 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
7204 struct wpa_bss
*bss
;
7206 if (hwaddr_aton(dst
, bssid
)) {
7207 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
7211 bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
7213 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
7218 if (bss
->ssid_len
== 0) {
7221 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
7222 " does not have SSID information", MAC2STR(bssid
));
7224 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
7226 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
7227 bss
->ssid_len
> 0) {
7235 wpa_printf(MSG_DEBUG
,
7236 "Found another matching BSS entry with SSID");
7239 return interworking_connect(wpa_s
, bss
, only_add
);
7243 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7245 u8 dst_addr
[ETH_ALEN
];
7248 #define MAX_ANQP_INFO_ID 100
7249 u16 id
[MAX_ANQP_INFO_ID
];
7252 u32 mbo_subtypes
= 0;
7254 used
= hwaddr_aton2(dst
, dst_addr
);
7260 while (num_id
< MAX_ANQP_INFO_ID
) {
7261 if (os_strncmp(pos
, "hs20:", 5) == 0) {
7263 int num
= atoi(pos
+ 5);
7264 if (num
<= 0 || num
> 31)
7266 subtypes
|= BIT(num
);
7267 #else /* CONFIG_HS20 */
7269 #endif /* CONFIG_HS20 */
7270 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
7272 int num
= atoi(pos
+ 4);
7274 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
7276 mbo_subtypes
|= BIT(num
);
7277 #else /* CONFIG_MBO */
7279 #endif /* CONFIG_MBO */
7281 id
[num_id
] = atoi(pos
);
7285 pos
= os_strchr(pos
+ 1, ',');
7291 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
7294 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
7299 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
7301 u8 dst_addr
[ETH_ALEN
];
7302 struct wpabuf
*advproto
, *query
= NULL
;
7307 used
= hwaddr_aton2(cmd
, dst_addr
);
7315 /* Advertisement Protocol ID */
7316 end
= os_strchr(pos
, ' ');
7320 len
= os_strlen(pos
);
7326 advproto
= wpabuf_alloc(len
);
7327 if (advproto
== NULL
)
7329 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
7333 /* Optional Query Request */
7338 len
= os_strlen(pos
);
7345 query
= wpabuf_alloc(len
);
7348 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
7353 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
7356 wpabuf_free(advproto
);
7363 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7370 size_t resp_len
, start
, requested_len
;
7371 struct wpabuf
*resp
;
7374 used
= hwaddr_aton2(cmd
, addr
);
7381 dialog_token
= atoi(pos
);
7383 if (wpa_s
->last_gas_resp
&&
7384 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7385 dialog_token
== wpa_s
->last_gas_dialog_token
)
7386 resp
= wpa_s
->last_gas_resp
;
7387 else if (wpa_s
->prev_gas_resp
&&
7388 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7389 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7390 resp
= wpa_s
->prev_gas_resp
;
7394 resp_len
= wpabuf_len(resp
);
7396 requested_len
= resp_len
;
7398 pos
= os_strchr(pos
, ' ');
7401 if (start
> resp_len
)
7402 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7403 pos
= os_strchr(pos
, ',');
7407 requested_len
= atoi(pos
);
7408 if (start
+ requested_len
> resp_len
)
7409 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7412 if (requested_len
* 2 + 1 > buflen
)
7413 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7415 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7418 if (start
+ requested_len
== resp_len
) {
7420 * Free memory by dropping the response after it has been
7423 if (resp
== wpa_s
->prev_gas_resp
) {
7424 wpabuf_free(wpa_s
->prev_gas_resp
);
7425 wpa_s
->prev_gas_resp
= NULL
;
7427 wpabuf_free(wpa_s
->last_gas_resp
);
7428 wpa_s
->last_gas_resp
= NULL
;
7434 #endif /* CONFIG_INTERWORKING */
7439 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7441 u8 dst_addr
[ETH_ALEN
];
7446 used
= hwaddr_aton2(dst
, dst_addr
);
7453 int num
= atoi(pos
);
7454 if (num
<= 0 || num
> 31)
7456 subtypes
|= BIT(num
);
7457 pos
= os_strchr(pos
+ 1, ',');
7466 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7470 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7471 const u8
*addr
, const char *realm
)
7477 rlen
= os_strlen(realm
);
7479 buf
= os_malloc(len
);
7482 buf
[0] = 1; /* NAI Home Realm Count */
7483 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7485 os_memcpy(buf
+ 3, realm
, rlen
);
7487 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7488 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7497 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7500 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7501 u8 dst_addr
[ETH_ALEN
];
7507 used
= hwaddr_aton2(dst
, dst_addr
);
7511 while (dst
[used
] == ' ')
7513 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7514 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7517 len
= os_strlen(dst
+ used
);
7519 if (len
== 0 && cred
&& cred
->realm
)
7520 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7525 buf
= os_malloc(len
);
7528 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7533 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7534 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7542 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7545 u8 dst_addr
[ETH_ALEN
];
7547 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7549 used
= hwaddr_aton2(cmd
, dst_addr
);
7554 icon
= str_token(cmd
, " ", &ctx
);
7555 poffset
= str_token(cmd
, " ", &ctx
);
7556 psize
= str_token(cmd
, " ", &ctx
);
7557 if (!icon
|| !poffset
|| !psize
)
7560 wpa_s
->fetch_osu_icon_in_progress
= 0;
7561 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7566 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7568 u8 dst_addr
[ETH_ALEN
];
7573 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7575 used
= hwaddr_aton2(cmd
, dst_addr
);
7579 while (cmd
[used
] == ' ')
7581 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7583 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7587 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7589 u8 dst_addr
[ETH_ALEN
];
7593 used
= hwaddr_aton2(cmd
, dst_addr
);
7597 while (cmd
[used
] == ' ')
7601 wpa_s
->fetch_osu_icon_in_progress
= 0;
7602 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7603 (u8
*) icon
, os_strlen(icon
), inmem
);
7606 #endif /* CONFIG_HS20 */
7609 #ifdef CONFIG_AUTOSCAN
7611 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7614 enum wpa_states state
= wpa_s
->wpa_state
;
7615 char *new_params
= NULL
;
7617 if (os_strlen(cmd
) > 0) {
7618 new_params
= os_strdup(cmd
);
7619 if (new_params
== NULL
)
7623 os_free(wpa_s
->conf
->autoscan
);
7624 wpa_s
->conf
->autoscan
= new_params
;
7626 if (wpa_s
->conf
->autoscan
== NULL
)
7627 autoscan_deinit(wpa_s
);
7628 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7629 autoscan_init(wpa_s
, 1);
7630 else if (state
== WPA_SCANNING
)
7631 wpa_supplicant_reinit_autoscan(wpa_s
);
7633 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7634 wpa_supplicant_state_txt(state
));
7639 #endif /* CONFIG_AUTOSCAN */
7644 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7650 struct wpabuf
*tfs_req
= NULL
;
7652 if (os_strncmp(cmd
, "enter", 5) == 0)
7654 else if (os_strncmp(cmd
, "exit", 4) == 0)
7659 pos
= os_strstr(cmd
, " interval=");
7661 intval
= atoi(pos
+ 10);
7663 pos
= os_strstr(cmd
, " tfs_req=");
7668 end
= os_strchr(pos
, ' ');
7672 len
= os_strlen(pos
);
7676 tfs_req
= wpabuf_alloc(len
);
7677 if (tfs_req
== NULL
)
7679 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7680 wpabuf_free(tfs_req
);
7685 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7686 WNM_SLEEP_MODE_EXIT
, intval
,
7688 wpabuf_free(tfs_req
);
7694 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7696 int query_reason
, list
= 0;
7697 char *btm_candidates
= NULL
;
7699 query_reason
= atoi(cmd
);
7701 cmd
= os_strchr(cmd
, ' ');
7703 if (os_strncmp(cmd
, " list", 5) == 0)
7706 btm_candidates
= cmd
;
7709 wpa_printf(MSG_DEBUG
,
7710 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7711 query_reason
, list
? " candidate list" : "");
7713 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7719 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant
*wpa_s
,
7722 struct wpabuf
*elems
;
7725 elems
= wpabuf_parse_bin(cmd
);
7729 ret
= wnm_send_coloc_intf_report(wpa_s
, 0, elems
);
7734 #endif /* CONFIG_WNM */
7737 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7740 struct wpa_signal_info si
;
7744 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7751 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7752 "NOISE=%d\nFREQUENCY=%u\n",
7753 si
.current_signal
, si
.current_txrate
/ 1000,
7754 si
.current_noise
, si
.frequency
);
7755 if (os_snprintf_error(end
- pos
, ret
))
7759 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7760 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7761 channel_width_to_string(si
.chanwidth
));
7762 if (os_snprintf_error(end
- pos
, ret
))
7767 if (si
.center_frq1
> 0) {
7768 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ1=%d\n",
7770 if (os_snprintf_error(end
- pos
, ret
))
7775 if (si
.center_frq2
> 0) {
7776 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ2=%d\n",
7778 if (os_snprintf_error(end
- pos
, ret
))
7783 if (si
.avg_signal
) {
7784 ret
= os_snprintf(pos
, end
- pos
,
7785 "AVG_RSSI=%d\n", si
.avg_signal
);
7786 if (os_snprintf_error(end
- pos
, ret
))
7791 if (si
.avg_beacon_signal
) {
7792 ret
= os_snprintf(pos
, end
- pos
,
7793 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7794 if (os_snprintf_error(end
- pos
, ret
))
7803 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7810 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7811 wpa_printf(MSG_DEBUG
,
7812 "Reject SIGNAL_MONITOR command - bgscan is active");
7815 pos
= os_strstr(cmd
, "THRESHOLD=");
7817 threshold
= atoi(pos
+ 10);
7818 pos
= os_strstr(cmd
, "HYSTERESIS=");
7820 hysteresis
= atoi(pos
+ 11);
7821 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7825 #ifdef CONFIG_TESTING_OPTIONS
7826 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7827 enum wpa_driver_if_type if_type
,
7829 unsigned int *freq_list
)
7831 char *pos
= wpa_s
->get_pref_freq_list_override
;
7833 unsigned int count
= 0;
7835 /* Override string format:
7836 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7839 if (atoi(pos
) == (int) if_type
)
7841 pos
= os_strchr(pos
, ' ');
7847 pos
= os_strchr(pos
, ':');
7851 end
= os_strchr(pos
, ' ');
7852 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7853 freq_list
[count
++] = atoi(pos
);
7854 pos
= os_strchr(pos
, ',');
7862 #endif /* CONFIG_TESTING_OPTIONS */
7865 static int wpas_ctrl_iface_get_pref_freq_list(
7866 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7868 unsigned int freq_list
[100], num
= 100, i
;
7870 enum wpa_driver_if_type iface_type
;
7876 /* buf: "<interface_type>" */
7877 if (os_strcmp(cmd
, "STATION") == 0)
7878 iface_type
= WPA_IF_STATION
;
7879 else if (os_strcmp(cmd
, "AP") == 0)
7880 iface_type
= WPA_IF_AP_BSS
;
7881 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7882 iface_type
= WPA_IF_P2P_GO
;
7883 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7884 iface_type
= WPA_IF_P2P_CLIENT
;
7885 else if (os_strcmp(cmd
, "IBSS") == 0)
7886 iface_type
= WPA_IF_IBSS
;
7887 else if (os_strcmp(cmd
, "TDLS") == 0)
7888 iface_type
= WPA_IF_TDLS
;
7892 wpa_printf(MSG_DEBUG
,
7893 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7896 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7900 for (i
= 0; i
< num
; i
++) {
7901 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7902 i
> 0 ? "," : "", freq_list
[i
]);
7903 if (os_snprintf_error(end
- pos
, ret
))
7912 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7913 char *buf
, size_t buflen
)
7918 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7919 (long long unsigned) wpa_s
->drv_flags
);
7920 if (os_snprintf_error(buflen
, ret
))
7926 for (i
= 0; i
< 64; i
++) {
7927 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7928 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7929 driver_flag_to_string(1LLU << i
));
7930 if (os_snprintf_error(end
- pos
, ret
))
7940 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7943 struct hostap_sta_driver_data sta
;
7946 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7950 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7951 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7952 if (os_snprintf_error(buflen
, ret
))
7959 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7960 char *buf
, size_t buflen
)
7964 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7966 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7967 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7970 country
[0] = cmd
[8];
7971 country
[1] = cmd
[9];
7973 p2p_set_country(p2p
, country
);
7976 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7977 if (os_snprintf_error(buflen
, ret
))
7982 #endif /* ANDROID */
7985 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7986 char *buf
, size_t buflen
)
7991 unsigned int vendor_id
, subcmd
;
7992 struct wpabuf
*reply
;
7993 size_t data_len
= 0;
7995 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7996 vendor_id
= strtoul(cmd
, &pos
, 16);
7997 if (!isblank((unsigned char) *pos
))
8000 subcmd
= strtoul(pos
, &pos
, 10);
8003 if (!isblank((unsigned char) *pos
++))
8005 data_len
= os_strlen(pos
);
8010 data
= os_malloc(data_len
);
8014 if (hexstr2bin(pos
, data
, data_len
)) {
8015 wpa_printf(MSG_DEBUG
,
8016 "Vendor command: wrong parameter format");
8022 reply
= wpabuf_alloc((buflen
- 1) / 2);
8028 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
8032 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
8042 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
8045 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
8046 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
8047 #endif /* CONFIG_P2P */
8049 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
8051 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
8052 wpa_s
->ignore_post_flush_scan_res
= 1;
8054 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
8056 * Avoid possible auto connect re-connection on getting
8057 * disconnected due to state flush.
8059 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
8063 wpas_p2p_group_remove(p2p_wpa_s
, "*");
8064 wpas_p2p_cancel(p2p_wpa_s
);
8065 p2p_ctrl_flush(p2p_wpa_s
);
8066 wpas_p2p_service_flush(p2p_wpa_s
);
8067 p2p_wpa_s
->global
->p2p_disabled
= 0;
8068 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
8069 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
8070 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
8071 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
8072 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
8073 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
8074 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
8075 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
8076 #endif /* CONFIG_P2P */
8078 #ifdef CONFIG_WPS_TESTING
8079 wps_version_number
= 0x20;
8080 wps_testing_dummy_cred
= 0;
8081 wps_corrupt_pkhash
= 0;
8082 wps_force_auth_types_in_use
= 0;
8083 wps_force_encr_types_in_use
= 0;
8084 #endif /* CONFIG_WPS_TESTING */
8086 wpa_s
->wps_fragment_size
= 0;
8087 wpas_wps_cancel(wpa_s
);
8088 wps_registrar_flush(wpa_s
->wps
->registrar
);
8089 #endif /* CONFIG_WPS */
8090 wpa_s
->after_wps
= 0;
8091 wpa_s
->known_wps_freq
= 0;
8094 wpas_dpp_deinit(wpa_s
);
8095 wpa_s
->dpp_init_max_tries
= 0;
8096 wpa_s
->dpp_init_retry_time
= 0;
8097 wpa_s
->dpp_resp_wait_time
= 0;
8098 wpa_s
->dpp_resp_max_tries
= 0;
8099 wpa_s
->dpp_resp_retry_time
= 0;
8100 #ifdef CONFIG_TESTING_OPTIONS
8101 os_memset(dpp_pkex_own_mac_override
, 0, ETH_ALEN
);
8102 os_memset(dpp_pkex_peer_mac_override
, 0, ETH_ALEN
);
8103 dpp_pkex_ephemeral_key_override_len
= 0;
8104 dpp_protocol_key_override_len
= 0;
8105 dpp_nonce_override_len
= 0;
8106 #endif /* CONFIG_TESTING_OPTIONS */
8107 #endif /* CONFIG_DPP */
8110 #ifdef CONFIG_TDLS_TESTING
8112 #endif /* CONFIG_TDLS_TESTING */
8113 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
8114 wpa_tdls_enable(wpa_s
->wpa
, 1);
8115 #endif /* CONFIG_TDLS */
8117 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
8118 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
8119 wpa_s
->last_michael_mic_error
.sec
= 0;
8121 wpa_s
->no_keep_alive
= 0;
8122 wpa_s
->own_disconnect_req
= 0;
8123 wpa_s
->own_reconnect_req
= 0;
8124 wpa_s
->deny_ptk0_rekey
= 0;
8126 os_free(wpa_s
->disallow_aps_bssid
);
8127 wpa_s
->disallow_aps_bssid
= NULL
;
8128 wpa_s
->disallow_aps_bssid_count
= 0;
8129 os_free(wpa_s
->disallow_aps_ssid
);
8130 wpa_s
->disallow_aps_ssid
= NULL
;
8131 wpa_s
->disallow_aps_ssid_count
= 0;
8133 wpa_s
->set_sta_uapsd
= 0;
8134 wpa_s
->sta_uapsd
= 0;
8136 wpa_drv_radio_disable(wpa_s
, 0);
8137 wpa_blacklist_clear(wpa_s
);
8138 wpa_s
->extra_blacklist_count
= 0;
8139 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
8140 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
8141 wpa_config_flush_blobs(wpa_s
->conf
);
8142 wpa_s
->conf
->auto_interworking
= 0;
8143 wpa_s
->conf
->okc
= 0;
8145 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
8146 rsn_preauth_deinit(wpa_s
->wpa
);
8148 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
8149 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
8150 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
8151 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
8153 radio_remove_works(wpa_s
, NULL
, 1);
8154 wpa_s
->ext_work_in_progress
= 0;
8156 wpa_s
->next_ssid
= NULL
;
8158 #ifdef CONFIG_INTERWORKING
8160 hs20_cancel_fetch_osu(wpa_s
);
8161 hs20_del_icon(wpa_s
, NULL
, NULL
);
8162 #endif /* CONFIG_HS20 */
8163 #endif /* CONFIG_INTERWORKING */
8165 wpa_s
->ext_mgmt_frame_handling
= 0;
8166 wpa_s
->ext_eapol_frame_io
= 0;
8167 #ifdef CONFIG_TESTING_OPTIONS
8168 wpa_s
->extra_roc_dur
= 0;
8169 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
8170 wpa_s
->p2p_go_csa_on_inv
= 0;
8171 wpa_s
->ignore_auth_resp
= 0;
8172 wpa_s
->ignore_assoc_disallow
= 0;
8173 wpa_s
->testing_resend_assoc
= 0;
8174 wpa_s
->ignore_sae_h2e_only
= 0;
8175 wpa_s
->reject_btm_req_reason
= 0;
8176 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
8177 os_free(wpa_s
->get_pref_freq_list_override
);
8178 wpa_s
->get_pref_freq_list_override
= NULL
;
8179 wpabuf_free(wpa_s
->sae_commit_override
);
8180 wpa_s
->sae_commit_override
= NULL
;
8181 os_free(wpa_s
->extra_sae_rejected_groups
);
8182 wpa_s
->extra_sae_rejected_groups
= NULL
;
8183 wpabuf_free(wpa_s
->rsne_override_eapol
);
8184 wpa_s
->rsne_override_eapol
= NULL
;
8185 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
8186 wpa_s
->rsnxe_override_assoc
= NULL
;
8187 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
8188 wpa_s
->rsnxe_override_eapol
= NULL
;
8189 wpas_clear_driver_signal_override(wpa_s
);
8191 os_free(wpa_s
->dpp_config_obj_override
);
8192 wpa_s
->dpp_config_obj_override
= NULL
;
8193 os_free(wpa_s
->dpp_discovery_override
);
8194 wpa_s
->dpp_discovery_override
= NULL
;
8195 os_free(wpa_s
->dpp_groups_override
);
8196 wpa_s
->dpp_groups_override
= NULL
;
8197 dpp_test
= DPP_TEST_DISABLED
;
8198 #endif /* CONFIG_DPP */
8199 #endif /* CONFIG_TESTING_OPTIONS */
8201 wpa_s
->disconnected
= 0;
8202 os_free(wpa_s
->next_scan_freqs
);
8203 wpa_s
->next_scan_freqs
= NULL
;
8204 os_memset(wpa_s
->next_scan_bssid
, 0, ETH_ALEN
);
8205 wpa_s
->next_scan_bssid_wildcard_ssid
= 0;
8206 os_free(wpa_s
->select_network_scan_freqs
);
8207 wpa_s
->select_network_scan_freqs
= NULL
;
8209 wpa_bss_flush(wpa_s
);
8210 if (!dl_list_empty(&wpa_s
->bss
)) {
8211 wpa_printf(MSG_DEBUG
,
8212 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8213 MACSTR
" pending_bssid=" MACSTR
,
8214 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
8215 MAC2STR(wpa_s
->bssid
),
8216 MAC2STR(wpa_s
->pending_bssid
));
8219 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
8220 wpa_s
->wnmsleep_used
= 0;
8223 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
8224 wpa_s
->sme
.auth_alg
= 0;
8225 #endif /* CONFIG_SME */
8227 wpabuf_free(wpa_s
->ric_ies
);
8228 wpa_s
->ric_ies
= NULL
;
8230 wpa_supplicant_update_channel_list(wpa_s
, NULL
);
8232 free_bss_tmp_disallowed(wpa_s
);
8236 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
8237 char *buf
, size_t buflen
)
8239 struct wpa_radio_work
*work
;
8241 struct os_reltime now
, diff
;
8246 os_get_reltime(&now
);
8248 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8252 os_reltime_sub(&now
, &work
->time
, &diff
);
8253 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
8254 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
8255 work
->started
, diff
.sec
, diff
.usec
);
8256 if (os_snprintf_error(end
- pos
, ret
))
8265 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
8267 struct wpa_radio_work
*work
= eloop_ctx
;
8268 struct wpa_external_work
*ework
= work
->ctx
;
8270 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
8271 "Timing out external radio work %u (%s)",
8272 ework
->id
, work
->type
);
8273 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
8274 work
->wpa_s
->ext_work_in_progress
= 0;
8275 radio_work_done(work
);
8280 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
8282 struct wpa_external_work
*ework
= work
->ctx
;
8286 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8290 * work->type points to a buffer in ework, so need to replace
8291 * that here with a fixed string to avoid use of freed memory
8294 work
->type
= "freed-ext-work";
8300 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
8301 ework
->id
, ework
->type
);
8302 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
8303 work
->wpa_s
->ext_work_in_progress
= 1;
8304 if (!ework
->timeout
)
8305 ework
->timeout
= 10;
8306 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
8311 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
8312 char *buf
, size_t buflen
)
8314 struct wpa_external_work
*ework
;
8318 unsigned int freq
= 0;
8320 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8322 ework
= os_zalloc(sizeof(*ework
));
8326 pos
= os_strchr(cmd
, ' ');
8328 type_len
= pos
- cmd
;
8331 pos2
= os_strstr(pos
, "freq=");
8333 freq
= atoi(pos2
+ 5);
8335 pos2
= os_strstr(pos
, "timeout=");
8337 ework
->timeout
= atoi(pos2
+ 8);
8339 type_len
= os_strlen(cmd
);
8341 if (4 + type_len
>= sizeof(ework
->type
))
8342 type_len
= sizeof(ework
->type
) - 4 - 1;
8343 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
8344 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
8345 ework
->type
[4 + type_len
] = '\0';
8347 wpa_s
->ext_work_id
++;
8348 if (wpa_s
->ext_work_id
== 0)
8349 wpa_s
->ext_work_id
++;
8350 ework
->id
= wpa_s
->ext_work_id
;
8352 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
8358 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
8359 if (os_snprintf_error(buflen
, ret
))
8365 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
8367 struct wpa_radio_work
*work
;
8368 unsigned int id
= atoi(cmd
);
8370 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8372 struct wpa_external_work
*ework
;
8374 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8377 if (id
&& ework
->id
!= id
)
8379 wpa_dbg(wpa_s
, MSG_DEBUG
,
8380 "Completed external radio work %u (%s)",
8381 ework
->id
, ework
->type
);
8382 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
8383 wpa_s
->ext_work_in_progress
= 0;
8384 radio_work_done(work
);
8386 return 3; /* "OK\n" */
8393 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
8394 char *buf
, size_t buflen
)
8396 if (os_strcmp(cmd
, "show") == 0)
8397 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
8398 if (os_strncmp(cmd
, "add ", 4) == 0)
8399 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
8400 if (os_strncmp(cmd
, "done ", 5) == 0)
8401 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
8406 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
8408 struct wpa_radio_work
*work
, *tmp
;
8410 if (!wpa_s
|| !wpa_s
->radio
)
8413 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
8414 struct wpa_radio_work
, list
) {
8415 struct wpa_external_work
*ework
;
8417 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8420 wpa_dbg(wpa_s
, MSG_DEBUG
,
8421 "Flushing%s external radio work %u (%s)",
8422 work
->started
? " started" : "", ework
->id
,
8425 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8427 radio_work_done(work
);
8433 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8435 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8436 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8440 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8441 unsigned int *scan_id_count
, int scan_id
[])
8443 const char *pos
= value
;
8446 if (*pos
== ' ' || *pos
== '\0')
8448 if (*scan_id_count
== MAX_SCAN_ID
)
8450 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8451 pos
= os_strchr(pos
, ',');
8460 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8461 char *reply
, int reply_size
, int *reply_len
)
8464 unsigned int manual_scan_passive
= 0;
8465 unsigned int manual_scan_use_id
= 0;
8466 unsigned int manual_scan_only_new
= 0;
8467 unsigned int scan_only
= 0;
8468 unsigned int scan_id_count
= 0;
8469 int scan_id
[MAX_SCAN_ID
];
8470 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8471 struct wpa_scan_results
*scan_res
);
8472 int *manual_scan_freqs
= NULL
;
8473 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8474 unsigned int ssid_count
= 0;
8476 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8481 if (radio_work_pending(wpa_s
, "scan")) {
8482 wpa_printf(MSG_DEBUG
,
8483 "Pending scan scheduled - reject new request");
8484 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8488 #ifdef CONFIG_INTERWORKING
8489 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8490 wpa_printf(MSG_DEBUG
,
8491 "Interworking select in progress - reject new scan");
8492 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8495 #endif /* CONFIG_INTERWORKING */
8498 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8501 pos
= os_strstr(params
, "freq=");
8503 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8505 if (manual_scan_freqs
== NULL
) {
8511 pos
= os_strstr(params
, "passive=");
8513 manual_scan_passive
= !!atoi(pos
+ 8);
8515 pos
= os_strstr(params
, "use_id=");
8517 manual_scan_use_id
= atoi(pos
+ 7);
8519 pos
= os_strstr(params
, "only_new=1");
8521 manual_scan_only_new
= 1;
8523 pos
= os_strstr(params
, "scan_id=");
8524 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8530 pos
= os_strstr(params
, "bssid=");
8535 if (hwaddr_aton(pos
, bssid
)) {
8536 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8540 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8542 wpa_s
->next_scan_bssid_wildcard_ssid
=
8543 os_strstr(params
, "wildcard_ssid=1") != NULL
;
8547 while (pos
&& *pos
!= '\0') {
8548 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8554 if (*end
== '\0' || *end
== ' ')
8559 ns
= os_realloc_array(
8560 ssid
, ssid_count
+ 1,
8561 sizeof(struct wpa_ssid_value
));
8568 if ((end
- pos
) & 0x01 ||
8569 end
- pos
> 2 * SSID_MAX_LEN
||
8570 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8571 (end
- pos
) / 2) < 0) {
8572 wpa_printf(MSG_DEBUG
,
8573 "Invalid SSID value '%s'",
8578 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8579 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8580 ssid
[ssid_count
].ssid
,
8581 ssid
[ssid_count
].ssid_len
);
8586 pos
= os_strchr(pos
, ' ');
8592 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8593 os_free(wpa_s
->ssids_from_scan_req
);
8595 wpa_s
->ssids_from_scan_req
= ssid
;
8598 wpa_s
->ssids_from_scan_req
= NULL
;
8602 scan_res_handler
= scan_only_handler
;
8603 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8604 scan_res_handler
= NULL
;
8606 scan_res_handler
= wpa_s
->scan_res_handler
;
8608 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8609 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8610 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8611 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8612 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8613 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8614 wpa_s
->scan_id_count
= scan_id_count
;
8615 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8616 wpa_s
->scan_res_handler
= scan_res_handler
;
8617 os_free(wpa_s
->manual_scan_freqs
);
8618 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8619 manual_scan_freqs
= NULL
;
8621 wpa_s
->normal_scans
= 0;
8622 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8623 wpa_s
->after_wps
= 0;
8624 wpa_s
->known_wps_freq
= 0;
8625 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8626 if (wpa_s
->manual_scan_use_id
) {
8627 wpa_s
->manual_scan_id
++;
8628 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8629 wpa_s
->manual_scan_id
);
8630 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8631 wpa_s
->manual_scan_id
);
8633 } else if (wpa_s
->sched_scanning
) {
8634 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8635 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8636 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8637 wpa_s
->scan_id_count
= scan_id_count
;
8638 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8639 wpa_s
->scan_res_handler
= scan_res_handler
;
8640 os_free(wpa_s
->manual_scan_freqs
);
8641 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8642 manual_scan_freqs
= NULL
;
8644 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8645 wpa_supplicant_cancel_sched_scan(wpa_s
);
8646 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8647 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8648 if (wpa_s
->manual_scan_use_id
) {
8649 wpa_s
->manual_scan_id
++;
8650 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8651 wpa_s
->manual_scan_id
);
8652 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8653 wpa_s
->manual_scan_id
);
8656 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8657 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8661 os_free(manual_scan_freqs
);
8666 #ifdef CONFIG_TESTING_OPTIONS
8668 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8669 unsigned int freq
, const u8
*dst
,
8670 const u8
*src
, const u8
*bssid
,
8671 const u8
*data
, size_t data_len
,
8672 enum offchannel_send_action_result
8675 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8676 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8677 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8678 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8679 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8680 "NO_ACK" : "FAILED"));
8684 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8688 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8690 int freq
= 0, no_cck
= 0, wait_time
= 0;
8692 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8693 * <action=Action frame payload> */
8695 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8698 used
= hwaddr_aton2(pos
, da
);
8704 used
= hwaddr_aton2(pos
, bssid
);
8709 param
= os_strstr(pos
, " freq=");
8715 param
= os_strstr(pos
, " no_cck=");
8718 no_cck
= atoi(param
);
8721 param
= os_strstr(pos
, " wait_time=");
8724 wait_time
= atoi(param
);
8727 param
= os_strstr(pos
, " action=");
8732 len
= os_strlen(param
);
8737 buf
= os_malloc(len
);
8741 if (hexstr2bin(param
, buf
, len
) < 0) {
8746 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8747 buf
, len
, wait_time
,
8748 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8754 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8756 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8757 offchannel_send_action_done(wpa_s
);
8761 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8767 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8768 union wpa_event_data event
;
8770 if (!wpa_s
->ext_mgmt_frame_handling
)
8773 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8775 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8778 param
= os_strstr(pos
, "freq=");
8784 param
= os_strstr(pos
, " datarate=");
8787 datarate
= atoi(param
);
8790 param
= os_strstr(pos
, " ssi_signal=");
8793 ssi_signal
= atoi(param
);
8796 param
= os_strstr(pos
, " frame=");
8801 len
= os_strlen(param
);
8806 buf
= os_malloc(len
);
8810 if (hexstr2bin(param
, buf
, len
) < 0) {
8815 os_memset(&event
, 0, sizeof(event
));
8816 event
.rx_mgmt
.freq
= freq
;
8817 event
.rx_mgmt
.frame
= buf
;
8818 event
.rx_mgmt
.frame_len
= len
;
8819 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8820 event
.rx_mgmt
.datarate
= datarate
;
8821 wpa_s
->ext_mgmt_frame_handling
= 0;
8822 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8823 wpa_s
->ext_mgmt_frame_handling
= 1;
8831 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8834 struct wpa_scan_res
*res
;
8835 struct os_reltime now
;
8842 if (os_strcmp(param
, "START") == 0) {
8843 wpa_bss_update_start(wpa_s
);
8847 if (os_strcmp(param
, "END") == 0) {
8848 wpa_bss_update_end(wpa_s
, NULL
, 1);
8852 if (os_strncmp(param
, "BSS ", 4) != 0)
8856 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8860 pos
= os_strstr(param
, " flags=");
8862 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8864 pos
= os_strstr(param
, " bssid=");
8865 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8868 pos
= os_strstr(param
, " freq=");
8870 res
->freq
= atoi(pos
+ 6);
8872 pos
= os_strstr(param
, " beacon_int=");
8874 res
->beacon_int
= atoi(pos
+ 12);
8876 pos
= os_strstr(param
, " caps=");
8878 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8880 pos
= os_strstr(param
, " qual=");
8882 res
->qual
= atoi(pos
+ 6);
8884 pos
= os_strstr(param
, " noise=");
8886 res
->noise
= atoi(pos
+ 7);
8888 pos
= os_strstr(param
, " level=");
8890 res
->level
= atoi(pos
+ 7);
8892 pos
= os_strstr(param
, " tsf=");
8894 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8896 pos
= os_strstr(param
, " age=");
8898 res
->age
= atoi(pos
+ 5);
8900 pos
= os_strstr(param
, " est_throughput=");
8902 res
->est_throughput
= atoi(pos
+ 16);
8904 pos
= os_strstr(param
, " snr=");
8906 res
->snr
= atoi(pos
+ 5);
8908 pos
= os_strstr(param
, " parent_tsf=");
8910 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8912 pos
= os_strstr(param
, " tsf_bssid=");
8913 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8916 pos
= os_strstr(param
, " ie=");
8919 end
= os_strchr(pos
, ' ');
8921 end
= pos
+ os_strlen(pos
);
8922 res
->ie_len
= (end
- pos
) / 2;
8923 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8927 pos
= os_strstr(param
, " beacon_ie=");
8930 end
= os_strchr(pos
, ' ');
8932 end
= pos
+ os_strlen(pos
);
8933 res
->beacon_ie_len
= (end
- pos
) / 2;
8934 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8935 res
->beacon_ie_len
))
8939 os_get_reltime(&now
);
8940 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8949 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8952 union wpa_event_data event
;
8953 enum wpa_event_type ev
;
8955 /* <event name> [parameters..] */
8957 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8960 param
= os_strchr(pos
, ' ');
8964 os_memset(&event
, 0, sizeof(event
));
8966 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8967 ev
= EVENT_INTERFACE_ENABLED
;
8968 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8969 ev
= EVENT_INTERFACE_DISABLED
;
8970 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8971 ev
= EVENT_AVOID_FREQUENCIES
;
8974 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8976 wpa_supplicant_event(wpa_s
, ev
, &event
);
8977 os_free(event
.freq_range
.range
);
8979 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8980 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8982 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8987 wpa_supplicant_event(wpa_s
, ev
, &event
);
8993 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8996 u8 src
[ETH_ALEN
], *buf
;
9000 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
9003 used
= hwaddr_aton2(pos
, src
);
9010 len
= os_strlen(pos
);
9015 buf
= os_malloc(len
);
9019 if (hexstr2bin(pos
, buf
, len
) < 0) {
9024 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
9031 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
9035 const u16
*pos
= buf
;
9037 for (i
= 0; i
< len
/ 2; i
++)
9041 sum
= (sum
& 0xffff) + (sum
>> 16);
9043 return sum
^ 0xffff;
9047 #define HWSIM_PACKETLEN 1500
9048 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9050 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
9053 struct wpa_supplicant
*wpa_s
= ctx
;
9054 const struct ether_header
*eth
;
9060 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
9061 wpa_printf(MSG_DEBUG
,
9062 "test data: RX - ignore unexpected length %d",
9067 eth
= (const struct ether_header
*) buf
;
9068 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
9069 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
9071 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 || ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
9072 wpa_printf(MSG_DEBUG
,
9073 "test data: RX - ignore unexpect IP header");
9077 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
9078 if (*pos
!= (u8
) i
) {
9079 wpa_printf(MSG_DEBUG
,
9080 "test data: RX - ignore mismatching payload");
9086 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
9087 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
9088 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
9089 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
9093 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
9096 int enabled
= atoi(cmd
);
9101 if (wpa_s
->l2_test
) {
9102 l2_packet_deinit(wpa_s
->l2_test
);
9103 wpa_s
->l2_test
= NULL
;
9104 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
9112 pos
= os_strstr(cmd
, " ifname=");
9116 ifname
= wpa_s
->ifname
;
9118 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
9119 ETHERTYPE_IP
, wpas_data_test_rx
,
9121 if (wpa_s
->l2_test
== NULL
)
9124 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
9130 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
9132 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
9137 u8 buf
[2 + HWSIM_PACKETLEN
];
9138 struct ether_header
*eth
;
9142 size_t send_len
= HWSIM_IP_LEN
;
9144 if (wpa_s
->l2_test
== NULL
)
9147 /* format: <dst> <src> <tos> [len=<length>] */
9150 used
= hwaddr_aton2(pos
, dst
);
9156 used
= hwaddr_aton2(pos
, src
);
9161 val
= strtol(pos
, &pos2
, 0);
9162 if (val
< 0 || val
> 0xff)
9166 pos
= os_strstr(pos2
, " len=");
9169 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
9174 eth
= (struct ether_header
*) &buf
[2];
9175 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
9176 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
9177 eth
->ether_type
= htons(ETHERTYPE_IP
);
9178 ip
= (struct ip
*) (eth
+ 1);
9179 os_memset(ip
, 0, sizeof(*ip
));
9184 ip
->ip_len
= htons(send_len
);
9186 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9187 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9188 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
9189 dpos
= (u8
*) (ip
+ 1);
9190 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
9193 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
9194 sizeof(struct ether_header
) + send_len
) < 0)
9197 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
9198 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
9204 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
9208 struct ether_header
*eth
;
9209 struct l2_packet_data
*l2
= NULL
;
9214 len
= os_strlen(cmd
);
9215 if (len
& 1 || len
< ETH_HLEN
* 2)
9219 buf
= os_malloc(len
);
9223 if (hexstr2bin(cmd
, buf
, len
) < 0)
9226 eth
= (struct ether_header
*) buf
;
9227 ethertype
= ntohs(eth
->ether_type
);
9229 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
9230 wpas_data_test_rx
, wpa_s
, 1);
9234 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
9235 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
9238 l2_packet_deinit(l2
);
9241 return res
< 0 ? -1 : 0;
9245 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9247 #ifdef WPA_TRACE_BFD
9250 wpa_trace_fail_after
= atoi(cmd
);
9251 pos
= os_strchr(cmd
, ':');
9254 os_strlcpy(wpa_trace_fail_func
, pos
,
9255 sizeof(wpa_trace_fail_func
));
9257 wpa_trace_fail_after
= 0;
9260 #else /* WPA_TRACE_BFD */
9262 #endif /* WPA_TRACE_BFD */
9266 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
9267 char *buf
, size_t buflen
)
9269 #ifdef WPA_TRACE_BFD
9270 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
9271 wpa_trace_fail_func
);
9272 #else /* WPA_TRACE_BFD */
9274 #endif /* WPA_TRACE_BFD */
9278 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9280 #ifdef WPA_TRACE_BFD
9283 wpa_trace_test_fail_after
= atoi(cmd
);
9284 pos
= os_strchr(cmd
, ':');
9287 os_strlcpy(wpa_trace_test_fail_func
, pos
,
9288 sizeof(wpa_trace_test_fail_func
));
9290 wpa_trace_test_fail_after
= 0;
9293 #else /* WPA_TRACE_BFD */
9295 #endif /* WPA_TRACE_BFD */
9299 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
9300 char *buf
, size_t buflen
)
9302 #ifdef WPA_TRACE_BFD
9303 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
9304 wpa_trace_test_fail_func
);
9305 #else /* WPA_TRACE_BFD */
9307 #endif /* WPA_TRACE_BFD */
9311 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
9313 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9314 int i
, count
= (intptr_t) timeout_ctx
;
9316 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
9318 for (i
= 0; i
< count
; i
++) {
9319 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
9325 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9333 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
9334 (void *) (intptr_t) count
);
9338 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
9344 len
= os_strlen(cmd
);
9352 buf
= wpabuf_alloc(len
);
9356 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
9362 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
9367 static int wpas_ctrl_reset_pn(struct wpa_supplicant
*wpa_s
)
9369 u8 zero
[WPA_TK_MAX_LEN
];
9371 if (wpa_s
->last_tk_alg
== WPA_ALG_NONE
)
9374 wpa_printf(MSG_INFO
, "TESTING: Reset PN");
9375 os_memset(zero
, 0, sizeof(zero
));
9377 /* First, use a zero key to avoid any possible duplicate key avoidance
9379 if (wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9380 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9381 zero
, wpa_s
->last_tk_len
,
9382 KEY_FLAG_PAIRWISE_RX_TX
) < 0)
9385 /* Set the previously configured key to reset its TSC/RSC */
9386 return wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9387 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9388 wpa_s
->last_tk
, wpa_s
->last_tk_len
,
9389 KEY_FLAG_PAIRWISE_RX_TX
);
9393 static int wpas_ctrl_key_request(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9395 const char *pos
= cmd
;
9396 int error
, pairwise
;
9399 pos
= os_strchr(pos
, ' ');
9402 pairwise
= atoi(pos
);
9403 wpa_sm_key_request(wpa_s
->wpa
, error
, pairwise
);
9408 static int wpas_ctrl_resend_assoc(struct wpa_supplicant
*wpa_s
)
9411 struct wpa_driver_associate_params params
;
9414 os_memset(¶ms
, 0, sizeof(params
));
9415 params
.bssid
= wpa_s
->bssid
;
9416 params
.ssid
= wpa_s
->sme
.ssid
;
9417 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
9418 params
.freq
.freq
= wpa_s
->sme
.freq
;
9419 if (wpa_s
->last_assoc_req_wpa_ie
) {
9420 params
.wpa_ie
= wpabuf_head(wpa_s
->last_assoc_req_wpa_ie
);
9421 params
.wpa_ie_len
= wpabuf_len(wpa_s
->last_assoc_req_wpa_ie
);
9423 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
9424 params
.group_suite
= wpa_s
->group_cipher
;
9425 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
9426 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
9427 params
.wpa_proto
= wpa_s
->wpa_proto
;
9428 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
9429 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
9430 if (wpa_s
->sme
.prev_bssid_set
)
9431 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
9432 wpa_printf(MSG_INFO
, "TESTING: Resend association request");
9433 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
9434 wpa_s
->testing_resend_assoc
= 1;
9436 #else /* CONFIG_SME */
9438 #endif /* CONFIG_SME */
9441 #endif /* CONFIG_TESTING_OPTIONS */
9444 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
9450 struct ieee802_11_elems elems
;
9453 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9455 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9457 pos
= os_strchr(pos
, ' ');
9462 len
= os_strlen(pos
);
9469 buf
= wpabuf_alloc(len
);
9473 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
9478 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
9484 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
9485 wpa_s
->vendor_elem
[frame
] = buf
;
9486 wpas_vendor_elem_update(wpa_s
);
9490 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
9495 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
9497 wpas_vendor_elem_update(wpa_s
);
9503 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
9504 char *buf
, size_t buflen
)
9506 int frame
= atoi(cmd
);
9508 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9510 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9512 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9515 return wpa_snprintf_hex(buf
, buflen
,
9516 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
9517 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
9521 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
9527 struct ieee802_11_elems elems
;
9531 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9533 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9535 pos
= os_strchr(pos
, ' ');
9541 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9542 wpa_s
->vendor_elem
[frame
] = NULL
;
9543 wpas_vendor_elem_update(wpa_s
);
9547 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9550 len
= os_strlen(pos
);
9557 buf
= os_malloc(len
);
9561 if (hexstr2bin(pos
, buf
, len
) < 0) {
9566 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9571 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9577 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9579 struct wpa_supplicant
*wpa_s
= ctx
;
9584 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9586 * BSSID Information[4]
9587 * Operating Class[1]
9590 * Optional Subelements[variable]
9592 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9594 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9595 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9599 data
= wpabuf_head_u8(neighbor_rep
);
9600 len
= wpabuf_len(neighbor_rep
);
9602 while (len
>= 2 + NR_IE_MIN_LEN
) {
9604 char lci
[256 * 2 + 1];
9605 char civic
[256 * 2 + 1];
9606 u8 nr_len
= data
[1];
9607 const u8
*pos
= data
, *end
;
9609 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9610 nr_len
< NR_IE_MIN_LEN
) {
9611 wpa_dbg(wpa_s
, MSG_DEBUG
,
9612 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9617 if (2U + nr_len
> len
) {
9618 wpa_dbg(wpa_s
, MSG_DEBUG
,
9619 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9620 data
[0], len
, nr_len
);
9627 pos
+= NR_IE_MIN_LEN
;
9631 while (end
- pos
> 2) {
9636 if (s_len
> end
- pos
)
9638 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9639 /* Measurement Token[1] */
9640 /* Measurement Report Mode[1] */
9641 /* Measurement Type[1] */
9642 /* Measurement Report[variable] */
9644 case MEASURE_TYPE_LCI
:
9647 wpa_snprintf_hex(lci
, sizeof(lci
),
9650 case MEASURE_TYPE_LOCATION_CIVIC
:
9653 wpa_snprintf_hex(civic
, sizeof(civic
),
9662 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9664 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9665 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9666 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9668 lci
[0] ? " lci=" : "", lci
,
9669 civic
[0] ? " civic=" : "", civic
);
9676 wpabuf_free(neighbor_rep
);
9680 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9683 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9684 int ret
, lci
= 0, civic
= 0;
9687 ssid_s
= os_strstr(cmd
, "ssid=");
9689 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9690 wpa_msg(wpa_s
, MSG_INFO
,
9691 "CTRL: Send Neighbor Report: bad SSID");
9698 * Move cmd after the SSID text that may include "lci" or
9701 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9707 if (cmd
&& os_strstr(cmd
, "lci"))
9710 if (cmd
&& os_strstr(cmd
, "civic"))
9713 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9714 wpas_ctrl_neighbor_rep_cb
,
9721 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9723 eapol_sm_erp_flush(wpa_s
->eapol
);
9728 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9731 char *token
, *context
= NULL
;
9732 unsigned int enable
= ~0, type
= 0;
9733 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9734 u8
*addr
= NULL
, *mask
= NULL
;
9736 while ((token
= str_token(cmd
, " ", &context
))) {
9737 if (os_strcasecmp(token
, "scan") == 0) {
9738 type
|= MAC_ADDR_RAND_SCAN
;
9739 } else if (os_strcasecmp(token
, "sched") == 0) {
9740 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9741 } else if (os_strcasecmp(token
, "pno") == 0) {
9742 type
|= MAC_ADDR_RAND_PNO
;
9743 } else if (os_strcasecmp(token
, "all") == 0) {
9744 type
= wpa_s
->mac_addr_rand_supported
;
9745 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9746 enable
= atoi(token
+ 7);
9747 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9749 if (hwaddr_aton(token
+ 5, addr
)) {
9750 wpa_printf(MSG_INFO
,
9751 "CTRL: Invalid MAC address: %s",
9755 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9757 if (hwaddr_aton(token
+ 5, mask
)) {
9758 wpa_printf(MSG_INFO
,
9759 "CTRL: Invalid MAC address mask: %s",
9764 wpa_printf(MSG_INFO
,
9765 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9772 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9777 wpa_printf(MSG_INFO
,
9778 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9783 return wpas_disable_mac_addr_randomization(wpa_s
, type
);
9785 return wpas_enable_mac_addr_randomization(wpa_s
, type
, addr
, mask
);
9789 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9790 char *buf
, size_t buflen
)
9794 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9796 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9797 buflen
- reply_len
);
9798 #endif /* CONFIG_AP */
9803 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9805 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9807 wpas_ap_pmksa_cache_flush(wpa_s
);
9808 #endif /* CONFIG_AP */
9812 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9814 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9815 const char *cmd
, char *buf
, size_t buflen
)
9817 struct rsn_pmksa_cache_entry
*entry
;
9818 struct wpa_ssid
*ssid
;
9819 char *pos
, *pos2
, *end
;
9821 struct os_reltime now
;
9823 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9830 os_get_reltime(&now
);
9834 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9835 * <expiration in seconds> <akmp> <opportunistic>
9836 * [FILS Cache Identifier]
9839 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9840 entry
= entry
->next
) {
9841 if (entry
->network_ctx
!= ssid
)
9845 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9846 MAC2STR(entry
->aa
));
9847 if (os_snprintf_error(end
- pos2
, ret
))
9851 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9854 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9855 if (os_snprintf_error(end
- pos2
, ret
))
9859 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9862 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9863 (int) (entry
->reauth_time
- now
.sec
),
9864 (int) (entry
->expiration
- now
.sec
),
9866 entry
->opportunistic
);
9867 if (os_snprintf_error(end
- pos2
, ret
))
9871 if (entry
->fils_cache_id_set
) {
9872 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9873 entry
->fils_cache_id
[0],
9874 entry
->fils_cache_id
[1]);
9875 if (os_snprintf_error(end
- pos2
, ret
))
9880 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9881 if (os_snprintf_error(end
- pos2
, ret
))
9892 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9895 struct rsn_pmksa_cache_entry
*entry
;
9896 struct wpa_ssid
*ssid
;
9899 struct os_reltime now
;
9900 int reauth_time
= 0, expiration
= 0, i
;
9904 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9905 * <expiration in seconds> <akmp> <opportunistic>
9906 * [FILS Cache Identifier]
9909 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9913 pos
= os_strchr(cmd
, ' ');
9918 entry
= os_zalloc(sizeof(*entry
));
9922 if (hwaddr_aton(pos
, entry
->aa
))
9925 pos
= os_strchr(pos
, ' ');
9930 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9933 pos
= os_strchr(pos
, ' ');
9938 pos2
= os_strchr(pos
, ' ');
9941 entry
->pmk_len
= (pos2
- pos
) / 2;
9942 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9943 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9946 pos
= os_strchr(pos
, ' ');
9951 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9952 &entry
->akmp
, &entry
->opportunistic
) != 4)
9954 for (i
= 0; i
< 4; i
++) {
9955 pos
= os_strchr(pos
, ' ');
9964 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9965 FILS_CACHE_ID_LEN
) < 0)
9967 entry
->fils_cache_id_set
= 1;
9969 os_get_reltime(&now
);
9970 entry
->expiration
= now
.sec
+ expiration
;
9971 entry
->reauth_time
= now
.sec
+ reauth_time
;
9973 entry
->network_ctx
= ssid
;
9975 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9986 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9987 const char *cmd
, char *buf
,
9995 if (os_strcasecmp(cmd
, "any") == 0)
9996 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9998 if (hwaddr_aton(cmd
, spa
))
10001 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
10005 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
10009 * We do not check mesh interface existance because PMKSA should be
10010 * stored before wpa_s->ifmsh creation to suppress commit message
10013 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
10016 #endif /* CONFIG_MESH */
10017 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10021 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
10024 struct fils_hlp_req
*req
;
10027 /* format: <dst> <packet starting from ethertype> */
10029 req
= os_zalloc(sizeof(*req
));
10033 if (hwaddr_aton(cmd
, req
->dst
))
10036 pos
= os_strchr(cmd
, ' ');
10040 req
->pkt
= wpabuf_parse_bin(pos
);
10044 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
10047 wpabuf_free(req
->pkt
);
10051 #endif /* CONFIG_FILS */
10054 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
10056 if (os_strcmp(cmd
, "PING") == 0 ||
10057 os_strncmp(cmd
, "BSS ", 4) == 0 ||
10058 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
10059 os_strncmp(cmd
, "STATUS", 6) == 0 ||
10060 os_strncmp(cmd
, "STA ", 4) == 0 ||
10061 os_strncmp(cmd
, "STA-", 4) == 0)
10062 return MSG_EXCESSIVE
;
10067 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
10068 char *buf
, size_t *resp_len
)
10071 const int reply_size
= 4096;
10074 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
10075 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
10076 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
10077 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10078 if (wpa_debug_show_keys
)
10079 wpa_dbg(wpa_s
, MSG_DEBUG
,
10080 "Control interface command '%s'", buf
);
10082 wpa_dbg(wpa_s
, MSG_DEBUG
,
10083 "Control interface command '%s [REMOVED]'",
10084 os_strncmp(buf
, WPA_CTRL_RSP
,
10085 os_strlen(WPA_CTRL_RSP
)) == 0 ?
10087 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
10088 "SET_NETWORK" : "key-add"));
10089 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
10090 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
10091 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
10092 (const u8
*) buf
, os_strlen(buf
));
10094 int level
= wpas_ctrl_cmd_debug_level(buf
);
10095 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
10098 reply
= os_malloc(reply_size
);
10099 if (reply
== NULL
) {
10104 os_memcpy(reply
, "OK\n", 3);
10107 if (os_strcmp(buf
, "PING") == 0) {
10108 os_memcpy(reply
, "PONG\n", 5);
10110 } else if (os_strcmp(buf
, "IFNAME") == 0) {
10111 reply_len
= os_strlen(wpa_s
->ifname
);
10112 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
10113 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10114 if (wpa_debug_reopen_file() < 0)
10116 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
10117 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
10118 } else if (os_strcmp(buf
, "MIB") == 0) {
10119 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
10120 if (reply_len
>= 0) {
10121 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
10123 reply_size
- reply_len
);
10124 #ifdef CONFIG_MACSEC
10125 reply_len
+= ieee802_1x_kay_get_mib(
10126 wpa_s
->kay
, reply
+ reply_len
,
10127 reply_size
- reply_len
);
10128 #endif /* CONFIG_MACSEC */
10130 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
10131 reply_len
= wpa_supplicant_ctrl_iface_status(
10132 wpa_s
, buf
+ 6, reply
, reply_size
);
10133 } else if (os_strcmp(buf
, "PMKSA") == 0) {
10134 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
10135 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
10136 wpas_ctrl_iface_pmksa_flush(wpa_s
);
10137 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10138 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
10139 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
10140 reply
, reply_size
);
10141 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
10142 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
10145 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
10146 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
10147 reply
, reply_size
);
10148 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10149 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
10151 #endif /* CONFIG_MESH */
10152 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10153 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10154 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
10156 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
10157 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
10158 reply
, reply_size
);
10159 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
10160 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
10161 reply
, reply_size
);
10162 } else if (os_strcmp(buf
, "LOGON") == 0) {
10163 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
10164 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
10165 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
10166 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
10167 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10170 wpas_request_connection(wpa_s
);
10171 } else if (os_strcmp(buf
, "REATTACH") == 0) {
10172 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
10173 !wpa_s
->current_ssid
)
10176 wpa_s
->reattach
= 1;
10177 wpas_request_connection(wpa_s
);
10179 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
10180 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10182 else if (wpa_s
->disconnected
)
10183 wpas_request_connection(wpa_s
);
10184 #ifdef IEEE8021X_EAPOL
10185 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
10186 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
10188 #endif /* IEEE8021X_EAPOL */
10189 #ifdef CONFIG_IEEE80211R
10190 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
10191 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
10193 #endif /* CONFIG_IEEE80211R */
10195 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
10196 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
10198 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10202 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
10203 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
10205 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10209 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
10210 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
10213 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
10214 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
10215 wpa_s
, buf
+ 14, reply
, reply_size
);
10216 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
10217 if (wpas_wps_cancel(wpa_s
))
10219 #ifdef CONFIG_WPS_NFC
10220 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
10221 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
10223 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
10224 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
10226 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10227 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10228 wpa_s
, buf
+ 21, reply
, reply_size
);
10229 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
10230 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
10231 wpa_s
, buf
+ 14, reply
, reply_size
);
10232 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
10233 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
10236 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10237 reply_len
= wpas_ctrl_nfc_get_handover_req(
10238 wpa_s
, buf
+ 21, reply
, reply_size
);
10239 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10240 reply_len
= wpas_ctrl_nfc_get_handover_sel(
10241 wpa_s
, buf
+ 21, reply
, reply_size
);
10242 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
10243 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
10245 #endif /* CONFIG_WPS_NFC */
10246 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
10247 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
10250 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
10251 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
10252 wpa_s
, buf
+ 11, reply
, reply_size
);
10253 #endif /* CONFIG_AP */
10254 #ifdef CONFIG_WPS_ER
10255 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
10256 if (wpas_wps_er_start(wpa_s
, NULL
))
10258 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
10259 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
10261 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
10262 wpas_wps_er_stop(wpa_s
);
10263 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
10264 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
10266 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
10267 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
10269 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10271 } else if (ret
== -3) {
10272 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
10274 } else if (ret
== -4) {
10275 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
10279 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
10280 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
10282 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
10283 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
10286 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
10287 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
10289 #ifdef CONFIG_WPS_NFC
10290 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10291 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10292 wpa_s
, buf
+ 24, reply
, reply_size
);
10293 #endif /* CONFIG_WPS_NFC */
10294 #endif /* CONFIG_WPS_ER */
10295 #endif /* CONFIG_WPS */
10296 #ifdef CONFIG_IBSS_RSN
10297 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
10298 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
10300 #endif /* CONFIG_IBSS_RSN */
10302 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
10303 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10304 wpa_s
, buf
+ 19, reply
, reply_size
);
10305 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
10306 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10307 wpa_s
, "", reply
, reply_size
);
10308 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
10309 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
10311 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
10312 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
10315 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
10316 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
10318 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
10319 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
10321 } else if (os_strncmp(buf
, "MESH_LINK_PROBE ", 16) == 0) {
10322 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s
, buf
+ 16))
10324 #endif /* CONFIG_MESH */
10326 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
10327 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
10329 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
10330 if (p2p_ctrl_find(wpa_s
, ""))
10332 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
10333 wpas_p2p_stop_find(wpa_s
);
10334 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
10335 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
10337 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10338 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
10340 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
10341 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
10343 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
10344 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
10346 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
10347 if (p2p_ctrl_listen(wpa_s
, ""))
10349 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
10350 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
10352 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
10353 if (p2p_ctrl_group_add(wpa_s
, ""))
10355 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
10356 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
10358 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
10359 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
10361 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
10362 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
10364 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
10365 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
10366 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
10367 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
10369 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10370 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
10372 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
10373 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
10375 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
10376 wpas_p2p_sd_service_update(wpa_s
);
10377 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10378 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
10380 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
10381 wpas_p2p_service_flush(wpa_s
);
10382 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
10383 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
10385 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
10386 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
10388 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
10389 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
10391 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
10392 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
10394 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
10395 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
10397 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
10398 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
10400 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
10401 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
10403 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
10404 p2p_ctrl_flush(wpa_s
);
10405 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
10406 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
10408 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
10409 if (wpas_p2p_cancel(wpa_s
))
10411 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
10412 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
10414 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
10415 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
10417 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
10418 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
10420 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
10421 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
10423 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
10424 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
10426 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
10427 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
10429 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
10430 if (wpas_p2p_lo_stop(wpa_s
))
10432 #endif /* CONFIG_P2P */
10433 #ifdef CONFIG_WIFI_DISPLAY
10434 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
10435 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
10437 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
10438 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
10439 reply
, reply_size
);
10440 #endif /* CONFIG_WIFI_DISPLAY */
10441 #ifdef CONFIG_INTERWORKING
10442 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
10443 if (interworking_fetch_anqp(wpa_s
) < 0)
10445 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
10446 interworking_stop_fetch_anqp(wpa_s
);
10447 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
10448 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
10450 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
10451 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
10453 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
10454 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
10456 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10459 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
10463 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
10464 if (os_snprintf_error(reply_size
, reply_len
))
10467 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
10468 if (get_anqp(wpa_s
, buf
+ 9) < 0)
10470 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
10471 if (gas_request(wpa_s
, buf
+ 12) < 0)
10473 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
10474 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
10476 #endif /* CONFIG_INTERWORKING */
10478 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10479 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10481 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10482 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10484 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10485 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10487 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10488 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10490 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10491 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10492 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10493 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10495 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10496 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10498 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10499 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10501 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10502 hs20_cancel_fetch_osu(wpa_s
);
10503 #endif /* CONFIG_HS20 */
10504 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10506 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10507 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10511 * Notify response from timeout to allow the control
10512 * interface response to be sent first.
10514 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10517 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10518 if (wpa_supplicant_reload_configuration(wpa_s
))
10520 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10521 wpa_supplicant_terminate_proc(wpa_s
->global
);
10522 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10523 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10525 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10526 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10527 wpa_s
, buf
+ 9, reply
, reply_size
);
10528 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10529 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10530 wpa_s
, buf
+ 9, reply
, reply_size
);
10531 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10532 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10533 wpa_s
, buf
+ 14, reply
, reply_size
);
10534 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10535 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10536 wpa_s
, NULL
, reply
, reply_size
);
10537 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10538 wpas_request_disconnection(wpa_s
);
10539 } else if (os_strcmp(buf
, "SCAN") == 0) {
10540 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10541 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10542 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10543 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10544 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10545 wpa_s
, reply
, reply_size
);
10546 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10547 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10549 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10550 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10552 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10553 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10555 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10556 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10558 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10559 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10560 wpa_s
, reply
, reply_size
);
10561 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10562 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10564 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10565 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10567 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10568 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10569 wpa_s
, buf
+ 12, reply
, reply_size
);
10570 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10571 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10574 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10575 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10576 wpa_s
, reply
, reply_size
);
10577 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10578 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10579 wpa_s
, reply
, reply_size
);
10580 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10581 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10583 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10584 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10586 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10587 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10590 #ifndef CONFIG_NO_CONFIG_WRITE
10591 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10592 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10594 #endif /* CONFIG_NO_CONFIG_WRITE */
10595 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10596 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10597 wpa_s
, buf
+ 15, reply
, reply_size
);
10598 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10599 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10601 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10602 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10604 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10605 reply_len
= wpa_supplicant_global_iface_list(
10606 wpa_s
->global
, reply
, reply_size
);
10607 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10608 reply_len
= wpa_supplicant_global_iface_interfaces(
10609 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10610 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10611 reply_len
= wpa_supplicant_ctrl_iface_bss(
10612 wpa_s
, buf
+ 4, reply
, reply_size
);
10614 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10615 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10616 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10617 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10619 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10620 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10622 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10623 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10625 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10626 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10628 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10629 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10631 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10632 if (wpas_ap_stop_ap(wpa_s
))
10634 #endif /* CONFIG_AP */
10635 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10636 wpas_notify_suspend(wpa_s
->global
);
10637 } else if (os_strcmp(buf
, "RESUME") == 0) {
10638 wpas_notify_resume(wpa_s
->global
);
10639 #ifdef CONFIG_TESTING_OPTIONS
10640 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10641 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10642 #endif /* CONFIG_TESTING_OPTIONS */
10643 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10644 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10646 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10647 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10648 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10649 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10651 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10652 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10655 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10656 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10658 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10659 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10661 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10662 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10664 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10665 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10667 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10668 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10671 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10672 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10675 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10676 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10677 wpa_s
, buf
+ 17, reply
, reply_size
);
10678 #endif /* CONFIG_TDLS */
10679 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10680 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10681 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10682 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10684 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10685 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10687 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10688 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10690 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10691 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10693 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10694 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10696 #ifdef CONFIG_AUTOSCAN
10697 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10698 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10700 #endif /* CONFIG_AUTOSCAN */
10701 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10702 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10705 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10706 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10708 #endif /* ANDROID */
10709 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10710 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10712 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10713 pmksa_cache_clear_current(wpa_s
->wpa
);
10714 eapol_sm_request_reauth(wpa_s
->eapol
);
10716 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10717 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10719 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10720 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10722 } else if (os_strncmp(buf
, "COLOC_INTF_REPORT ", 18) == 0) {
10723 if (wpas_ctrl_iface_coloc_intf_report(wpa_s
, buf
+ 18))
10725 #endif /* CONFIG_WNM */
10726 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10727 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10728 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10729 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10731 #ifdef CONFIG_TESTING_OPTIONS
10732 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10733 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10735 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10736 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10737 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10738 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10740 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10741 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10743 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10744 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10746 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10747 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10749 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10750 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10752 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10753 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10755 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10756 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10758 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10759 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10760 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10761 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10763 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10764 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10765 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10766 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10768 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10769 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10771 } else if (os_strcmp(buf
, "RESET_PN") == 0) {
10772 if (wpas_ctrl_reset_pn(wpa_s
) < 0)
10774 } else if (os_strncmp(buf
, "KEY_REQUEST ", 12) == 0) {
10775 if (wpas_ctrl_key_request(wpa_s
, buf
+ 12) < 0)
10777 } else if (os_strcmp(buf
, "RESEND_ASSOC") == 0) {
10778 if (wpas_ctrl_resend_assoc(wpa_s
) < 0)
10780 } else if (os_strcmp(buf
, "UNPROT_DEAUTH") == 0) {
10781 sme_event_unprot_disconnect(
10782 wpa_s
, wpa_s
->bssid
, NULL
,
10783 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
10784 #endif /* CONFIG_TESTING_OPTIONS */
10785 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10786 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10788 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10789 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10791 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10792 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10794 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10795 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10797 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10798 wpas_ctrl_iface_erp_flush(wpa_s
);
10799 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10800 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10802 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10803 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10804 wpa_s
, buf
+ 19, reply
, reply_size
);
10806 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10807 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10809 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10810 wpas_flush_fils_hlp_req(wpa_s
);
10811 #endif /* CONFIG_FILS */
10813 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10816 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10820 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10821 if (os_snprintf_error(reply_size
, reply_len
))
10824 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
10827 res
= wpas_dpp_nfc_uri(wpa_s
, buf
+ 12);
10831 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10832 if (os_snprintf_error(reply_size
, reply_len
))
10835 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
10838 res
= wpas_dpp_nfc_handover_req(wpa_s
, buf
+ 20);
10842 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10843 if (os_snprintf_error(reply_size
, reply_len
))
10846 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
10849 res
= wpas_dpp_nfc_handover_sel(wpa_s
, buf
+ 20);
10853 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10854 if (os_snprintf_error(reply_size
, reply_len
))
10857 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10860 res
= dpp_bootstrap_gen(wpa_s
->dpp
, buf
+ 18);
10864 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10865 if (os_snprintf_error(reply_size
, reply_len
))
10868 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10869 if (dpp_bootstrap_remove(wpa_s
->dpp
, buf
+ 21) < 0)
10871 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10874 uri
= dpp_bootstrap_get_uri(wpa_s
->dpp
, atoi(buf
+ 22));
10878 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10879 if (os_snprintf_error(reply_size
, reply_len
))
10882 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10883 reply_len
= dpp_bootstrap_info(wpa_s
->dpp
, atoi(buf
+ 19),
10884 reply
, reply_size
);
10885 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10886 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10888 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10889 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10891 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10892 wpas_dpp_stop(wpa_s
);
10893 wpas_dpp_listen_stop(wpa_s
);
10894 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10897 res
= dpp_configurator_add(wpa_s
->dpp
, buf
+ 20);
10901 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10902 if (os_snprintf_error(reply_size
, reply_len
))
10905 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10906 if (dpp_configurator_remove(wpa_s
->dpp
, buf
+ 24) < 0)
10908 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10909 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 21) < 0)
10911 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10912 reply_len
= dpp_configurator_get_key_id(wpa_s
->dpp
,
10914 reply
, reply_size
);
10915 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10918 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10922 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10923 if (os_snprintf_error(reply_size
, reply_len
))
10926 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10927 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10930 } else if (os_strncmp(buf
, "DPP_CONTROLLER_START ", 21) == 0) {
10931 if (wpas_dpp_controller_start(wpa_s
, buf
+ 20) < 0)
10933 } else if (os_strcmp(buf
, "DPP_CONTROLLER_START") == 0) {
10934 if (wpas_dpp_controller_start(wpa_s
, NULL
) < 0)
10936 } else if (os_strcmp(buf
, "DPP_CONTROLLER_STOP") == 0) {
10937 dpp_controller_stop(wpa_s
->dpp
);
10938 #endif /* CONFIG_DPP2 */
10939 #endif /* CONFIG_DPP */
10941 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10945 if (reply_len
< 0) {
10946 os_memcpy(reply
, "FAIL\n", 5);
10950 *resp_len
= reply_len
;
10955 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10958 struct wpa_interface iface
;
10960 struct wpa_supplicant
*wpa_s
;
10961 unsigned int create_iface
= 0;
10962 u8 mac_addr
[ETH_ALEN
];
10963 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10966 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10967 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10969 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10971 os_memset(&iface
, 0, sizeof(iface
));
10974 iface
.ifname
= pos
= cmd
;
10975 pos
= os_strchr(pos
, '\t');
10978 if (iface
.ifname
[0] == '\0')
10983 iface
.confname
= pos
;
10984 pos
= os_strchr(pos
, '\t');
10987 if (iface
.confname
[0] == '\0')
10988 iface
.confname
= NULL
;
10992 iface
.driver
= pos
;
10993 pos
= os_strchr(pos
, '\t');
10996 if (iface
.driver
[0] == '\0')
10997 iface
.driver
= NULL
;
11001 iface
.ctrl_interface
= pos
;
11002 pos
= os_strchr(pos
, '\t');
11005 if (iface
.ctrl_interface
[0] == '\0')
11006 iface
.ctrl_interface
= NULL
;
11010 iface
.driver_param
= pos
;
11011 pos
= os_strchr(pos
, '\t');
11014 if (iface
.driver_param
[0] == '\0')
11015 iface
.driver_param
= NULL
;
11019 iface
.bridge_ifname
= pos
;
11020 pos
= os_strchr(pos
, '\t');
11023 if (iface
.bridge_ifname
[0] == '\0')
11024 iface
.bridge_ifname
= NULL
;
11029 pos
= os_strchr(pos
, '\t');
11035 if (os_strcmp(extra
, "create") == 0) {
11040 if (os_strcmp(pos
, "sta") == 0) {
11041 type
= WPA_IF_STATION
;
11042 } else if (os_strcmp(pos
, "ap") == 0) {
11043 type
= WPA_IF_AP_BSS
;
11045 wpa_printf(MSG_DEBUG
,
11046 "INTERFACE_ADD unsupported interface type: '%s'",
11051 wpa_printf(MSG_DEBUG
,
11052 "INTERFACE_ADD unsupported extra parameter: '%s'",
11058 if (create_iface
) {
11059 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
11061 if (!global
->ifaces
)
11063 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
11064 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
11065 wpa_printf(MSG_ERROR
,
11066 "CTRL_IFACE interface creation failed");
11070 wpa_printf(MSG_DEBUG
,
11071 "CTRL_IFACE interface '%s' created with MAC addr: "
11072 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
11075 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
11078 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
11081 wpa_s
->added_vif
= create_iface
;
11086 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
11091 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
11094 struct wpa_supplicant
*wpa_s
;
11096 unsigned int delete_iface
;
11098 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
11100 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
11103 delete_iface
= wpa_s
->added_vif
;
11104 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
11105 if (!ret
&& delete_iface
) {
11106 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
11108 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
11114 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
11116 struct wpa_interface_info
*prev
;
11120 iface
= iface
->next
;
11122 os_free(prev
->ifname
);
11123 os_free(prev
->desc
);
11129 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
11130 char *buf
, int len
)
11133 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
11136 for (i
= 0; wpa_drivers
[i
]; i
++) {
11137 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
11138 if (drv
->get_interfaces
== NULL
)
11140 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
11145 iface
= last
= tmp
;
11154 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
11155 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
11156 tmp
->drv_name
, tmp
->ifname
,
11157 tmp
->desc
? tmp
->desc
: "");
11158 if (os_snprintf_error(end
- pos
, res
)) {
11165 wpa_free_iface_info(iface
);
11171 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
11173 char *buf
, int len
)
11177 struct wpa_supplicant
*wpa_s
;
11181 show_ctrl
= !!os_strstr(input
, "ctrl");
11183 wpa_s
= global
->ifaces
;
11189 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
11191 wpa_s
->conf
->ctrl_interface
?
11192 wpa_s
->conf
->ctrl_interface
: "N/A");
11194 res
= os_snprintf(pos
, end
- pos
, "%s\n",
11197 if (os_snprintf_error(end
- pos
, res
)) {
11202 wpa_s
= wpa_s
->next
;
11208 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
11209 const char *ifname
,
11210 char *cmd
, size_t *resp_len
)
11212 struct wpa_supplicant
*wpa_s
;
11214 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11215 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
11219 if (wpa_s
== NULL
) {
11220 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
11222 *resp_len
= os_strlen(resp
);
11228 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
11232 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
11233 char *buf
, size_t *resp_len
)
11236 static const char * cmd
[] = {
11242 "P2P_GET_PASSPHRASE",
11243 "P2P_SERVICE_UPDATE",
11244 "P2P_SERVICE_FLUSH",
11247 "P2P_PRESENCE_REQ",
11251 #endif /* CONFIG_AP */
11254 static const char * prefix
[] = {
11257 #endif /* ANDROID */
11264 "P2P_GROUP_REMOVE ",
11266 "P2P_GROUP_MEMBER ",
11268 "P2P_SERV_DISC_REQ ",
11269 "P2P_SERV_DISC_CANCEL_REQ ",
11270 "P2P_SERV_DISC_RESP ",
11271 "P2P_SERV_DISC_EXTERNAL ",
11272 "P2P_SERVICE_ADD ",
11273 "P2P_SERVICE_DEL ",
11274 "P2P_SERVICE_REP ",
11279 "P2P_UNAUTHORIZE ",
11280 "P2P_PRESENCE_REQ ",
11282 "P2P_REMOVE_CLIENT ",
11284 "WPS_NFC_TAG_READ ",
11285 "NFC_GET_HANDOVER_SEL ",
11286 "NFC_GET_HANDOVER_REQ ",
11287 "NFC_REPORT_HANDOVER ",
11288 "P2P_ASP_PROVISION ",
11289 "P2P_ASP_PROVISION_RESP ",
11293 #endif /* CONFIG_AP */
11299 if (global
->p2p_init_wpa_s
== NULL
)
11302 for (i
= 0; !found
&& cmd
[i
]; i
++) {
11303 if (os_strcmp(buf
, cmd
[i
]) == 0)
11307 for (i
= 0; !found
&& prefix
[i
]; i
++) {
11308 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
11313 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11315 #endif /* CONFIG_P2P */
11320 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
11321 char *buf
, size_t *resp_len
)
11323 #ifdef CONFIG_WIFI_DISPLAY
11324 if (global
->p2p_init_wpa_s
== NULL
)
11326 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
11327 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
11328 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11330 #endif /* CONFIG_WIFI_DISPLAY */
11335 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
11336 char *buf
, size_t *resp_len
)
11340 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
11344 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
11352 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
11356 value
= os_strchr(cmd
, ' ');
11361 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
11363 #ifdef CONFIG_WIFI_DISPLAY
11364 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
11365 wifi_display_enable(global
, !!atoi(value
));
11368 #endif /* CONFIG_WIFI_DISPLAY */
11370 /* Restore cmd to its original value to allow redirection */
11377 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
11380 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
11384 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11385 * <variable name> */
11387 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
11388 p
= os_strchr(cmd
, ' ');
11393 wpa_s
[i
] = global
->ifaces
;
11394 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
11395 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
11400 wpa_printf(MSG_DEBUG
,
11401 "CTRL_IFACE: Could not find iface=%s", cmd
);
11408 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
11412 #ifndef CONFIG_NO_CONFIG_WRITE
11413 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
11415 int ret
= 0, saved
= 0;
11416 struct wpa_supplicant
*wpa_s
;
11418 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11419 if (!wpa_s
->conf
->update_config
) {
11420 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11424 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
11425 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11428 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11433 if (!saved
&& !ret
) {
11434 wpa_dbg(wpa_s
, MSG_DEBUG
,
11435 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11441 #endif /* CONFIG_NO_CONFIG_WRITE */
11444 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
11445 char *buf
, size_t buflen
)
11449 struct wpa_supplicant
*wpa_s
;
11452 end
= buf
+ buflen
;
11455 if (global
->p2p
&& !global
->p2p_disabled
) {
11456 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
11459 MAC2STR(global
->p2p_dev_addr
),
11460 p2p_get_state_txt(global
->p2p
));
11461 if (os_snprintf_error(end
- pos
, ret
))
11464 } else if (global
->p2p
) {
11465 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
11466 if (os_snprintf_error(end
- pos
, ret
))
11470 #endif /* CONFIG_P2P */
11472 #ifdef CONFIG_WIFI_DISPLAY
11473 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
11474 !!global
->wifi_display
);
11475 if (os_snprintf_error(end
- pos
, ret
))
11478 #endif /* CONFIG_WIFI_DISPLAY */
11480 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11481 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
11482 "address=" MACSTR
"\n",
11483 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
11484 if (os_snprintf_error(end
- pos
, ret
))
11495 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
11496 char *cmd
, char *buf
,
11499 char ifname
[IFNAMSIZ
+ 1];
11500 struct fst_iface_cfg cfg
;
11501 struct wpa_supplicant
*wpa_s
;
11502 struct fst_wpa_obj iface_obj
;
11504 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
11505 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11508 wpa_printf(MSG_INFO
, "FST: Already attached");
11511 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
11512 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
11515 return os_snprintf(buf
, reply_size
, "OK\n");
11523 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
11524 char *cmd
, char *buf
,
11527 char ifname
[IFNAMSIZ
+ 1];
11528 struct wpa_supplicant
*wpa_s
;
11530 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
11531 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11533 if (!fst_iface_detach(ifname
)) {
11535 return os_snprintf(buf
, reply_size
, "OK\n");
11543 #endif /* CONFIG_FST */
11546 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11547 char *buf
, size_t *resp_len
)
11550 const int reply_size
= 2048;
11552 int level
= MSG_DEBUG
;
11554 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11555 char *pos
= os_strchr(buf
+ 7, ' ');
11558 return wpas_global_ctrl_iface_ifname(global
,
11564 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11568 if (os_strcmp(buf
, "PING") == 0)
11569 level
= MSG_EXCESSIVE
;
11570 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11571 (const u8
*) buf
, os_strlen(buf
));
11573 reply
= os_malloc(reply_size
);
11574 if (reply
== NULL
) {
11579 os_memcpy(reply
, "OK\n", 3);
11582 if (os_strcmp(buf
, "PING") == 0) {
11583 os_memcpy(reply
, "PONG\n", 5);
11585 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11586 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11588 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11589 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11591 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11592 reply_len
= wpa_supplicant_global_iface_list(
11593 global
, reply
, reply_size
);
11594 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11595 reply_len
= wpa_supplicant_global_iface_interfaces(
11596 global
, buf
+ 10, reply
, reply_size
);
11598 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11599 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11602 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11603 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11606 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11607 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11608 #endif /* CONFIG_FST */
11609 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11610 wpa_supplicant_terminate_proc(global
);
11611 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11612 wpas_notify_suspend(global
);
11613 } else if (os_strcmp(buf
, "RESUME") == 0) {
11614 wpas_notify_resume(global
);
11615 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11616 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11618 if (global
->p2p_init_wpa_s
) {
11620 /* Check if P2P redirection would work for this
11622 return wpa_supplicant_ctrl_iface_process(
11623 global
->p2p_init_wpa_s
,
11626 #endif /* CONFIG_P2P */
11629 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11630 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11632 #ifndef CONFIG_NO_CONFIG_WRITE
11633 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11634 if (wpas_global_ctrl_iface_save_config(global
))
11636 #endif /* CONFIG_NO_CONFIG_WRITE */
11637 } else if (os_strcmp(buf
, "STATUS") == 0) {
11638 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11640 #ifdef CONFIG_MODULE_TESTS
11641 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11642 if (wpas_module_tests() < 0)
11644 #endif /* CONFIG_MODULE_TESTS */
11645 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11646 if (wpa_debug_reopen_file() < 0)
11649 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11653 if (reply_len
< 0) {
11654 os_memcpy(reply
, "FAIL\n", 5);
11658 *resp_len
= reply_len
;