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
, "rsnxe_override_assoc") == 0) {
749 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
750 if (os_strcmp(value
, "NULL") == 0)
751 wpa_s
->rsnxe_override_assoc
= NULL
;
753 wpa_s
->rsnxe_override_assoc
= wpabuf_parse_bin(value
);
754 } else if (os_strcasecmp(cmd
, "rsnxe_override_eapol") == 0) {
755 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
756 if (os_strcmp(value
, "NULL") == 0)
757 wpa_s
->rsnxe_override_eapol
= NULL
;
759 wpa_s
->rsnxe_override_eapol
= wpabuf_parse_bin(value
);
760 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
761 wpa_s
->reject_btm_req_reason
= atoi(value
);
762 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
763 os_free(wpa_s
->get_pref_freq_list_override
);
765 wpa_s
->get_pref_freq_list_override
= NULL
;
767 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
768 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
769 wpabuf_free(wpa_s
->sae_commit_override
);
770 if (value
[0] == '\0')
771 wpa_s
->sae_commit_override
= NULL
;
773 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
774 } else if (os_strcasecmp(cmd
, "driver_signal_override") == 0) {
775 ret
= wpas_ctrl_iface_set_dso(wpa_s
, value
);
777 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
778 os_free(wpa_s
->dpp_config_obj_override
);
779 if (value
[0] == '\0')
780 wpa_s
->dpp_config_obj_override
= NULL
;
782 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
783 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
784 os_free(wpa_s
->dpp_discovery_override
);
785 if (value
[0] == '\0')
786 wpa_s
->dpp_discovery_override
= NULL
;
788 wpa_s
->dpp_discovery_override
= os_strdup(value
);
789 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
790 os_free(wpa_s
->dpp_groups_override
);
791 if (value
[0] == '\0')
792 wpa_s
->dpp_groups_override
= NULL
;
794 wpa_s
->dpp_groups_override
= os_strdup(value
);
795 } else if (os_strcasecmp(cmd
,
796 "dpp_ignore_netaccesskey_mismatch") == 0) {
797 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
798 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
799 dpp_test
= atoi(value
);
800 #endif /* CONFIG_DPP */
801 #endif /* CONFIG_TESTING_OPTIONS */
803 } else if (os_strcasecmp(cmd
, "disable_fils") == 0) {
804 wpa_s
->disable_fils
= !!atoi(value
);
805 wpa_drv_disable_fils(wpa_s
, wpa_s
->disable_fils
);
806 wpa_supplicant_set_default_scan_ies(wpa_s
);
807 #endif /* CONFIG_FILS */
808 #ifndef CONFIG_NO_CONFIG_BLOBS
809 } else if (os_strcmp(cmd
, "blob") == 0) {
810 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
811 #endif /* CONFIG_NO_CONFIG_BLOBS */
812 } else if (os_strcasecmp(cmd
, "setband") == 0) {
813 ret
= wpas_ctrl_set_band(wpa_s
, value
);
815 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
816 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
819 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
821 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
822 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
823 } else if (os_strcasecmp(cmd
, "oce") == 0) {
824 wpa_s
->conf
->oce
= atoi(value
);
825 if (wpa_s
->conf
->oce
) {
826 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
827 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
828 wpa_s
->enable_oce
= OCE_STA
;
830 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
832 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
833 /* TODO: Need to add STA-CFON support */
834 wpa_printf(MSG_ERROR
,
835 "OCE STA-CFON feature is not yet supported");
839 wpa_s
->enable_oce
= 0;
841 wpa_supplicant_set_default_scan_ies(wpa_s
);
842 #endif /* CONFIG_MBO */
843 } else if (os_strcasecmp(cmd
, "lci") == 0) {
844 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
845 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
846 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
847 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
848 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
849 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
850 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
851 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
852 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
853 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
854 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
856 } else if (os_strcasecmp(cmd
, "coloc_intf_elems") == 0) {
857 struct wpabuf
*elems
;
859 elems
= wpabuf_parse_bin(value
);
862 wnm_set_coloc_intf_elems(wpa_s
, elems
);
863 #endif /* CONFIG_WNM */
866 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
868 wpa_supplicant_update_config(wpa_s
);
875 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
876 char *cmd
, char *buf
, size_t buflen
)
880 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
882 if (os_strcmp(cmd
, "version") == 0) {
883 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
884 } else if (os_strcasecmp(cmd
, "country") == 0) {
885 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
886 res
= os_snprintf(buf
, buflen
, "%c%c",
887 wpa_s
->conf
->country
[0],
888 wpa_s
->conf
->country
[1]);
889 #ifdef CONFIG_WIFI_DISPLAY
890 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
892 if (wpa_s
->global
->p2p
== NULL
||
893 wpa_s
->global
->p2p_disabled
)
896 enabled
= wpa_s
->global
->wifi_display
;
897 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
898 #endif /* CONFIG_WIFI_DISPLAY */
899 #ifdef CONFIG_TESTING_GET_GTK
900 } else if (os_strcmp(cmd
, "gtk") == 0) {
901 if (wpa_s
->last_gtk_len
== 0)
903 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
904 wpa_s
->last_gtk_len
);
906 #endif /* CONFIG_TESTING_GET_GTK */
907 } else if (os_strcmp(cmd
, "tls_library") == 0) {
908 res
= tls_get_library_version(buf
, buflen
);
909 #ifdef CONFIG_TESTING_OPTIONS
910 } else if (os_strcmp(cmd
, "anonce") == 0) {
911 return wpa_snprintf_hex(buf
, buflen
,
912 wpa_sm_get_anonce(wpa_s
->wpa
),
914 #endif /* CONFIG_TESTING_OPTIONS */
916 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
919 if (os_snprintf_error(buflen
, res
))
925 #ifdef IEEE8021X_EAPOL
926 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
930 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
932 if (hwaddr_aton(addr
, bssid
)) {
933 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
938 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
939 rsn_preauth_deinit(wpa_s
->wpa
);
940 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
945 #endif /* IEEE8021X_EAPOL */
950 static int wpa_supplicant_ctrl_iface_tdls_discover(
951 struct wpa_supplicant
*wpa_s
, char *addr
)
956 if (hwaddr_aton(addr
, peer
)) {
957 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
958 "address '%s'", addr
);
962 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
965 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
966 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
968 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
974 static int wpa_supplicant_ctrl_iface_tdls_setup(
975 struct wpa_supplicant
*wpa_s
, char *addr
)
980 if (hwaddr_aton(addr
, peer
)) {
981 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
982 "address '%s'", addr
);
986 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
989 if ((wpa_s
->conf
->tdls_external_control
) &&
990 wpa_tdls_is_external_setup(wpa_s
->wpa
))
991 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
993 wpa_tdls_remove(wpa_s
->wpa
, peer
);
995 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
996 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
998 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
1004 static int wpa_supplicant_ctrl_iface_tdls_teardown(
1005 struct wpa_supplicant
*wpa_s
, char *addr
)
1010 if (os_strcmp(addr
, "*") == 0) {
1011 /* remove everyone */
1012 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
1013 wpa_tdls_teardown_peers(wpa_s
->wpa
);
1017 if (hwaddr_aton(addr
, peer
)) {
1018 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1019 "address '%s'", addr
);
1023 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
1026 if ((wpa_s
->conf
->tdls_external_control
) &&
1027 wpa_tdls_is_external_setup(wpa_s
->wpa
))
1028 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
1030 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
1031 ret
= wpa_tdls_teardown_link(
1033 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
1035 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
1041 static int ctrl_iface_get_capability_tdls(
1042 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1046 ret
= os_snprintf(buf
, buflen
, "%s\n",
1047 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
1049 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
1050 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
1051 if (os_snprintf_error(buflen
, ret
))
1057 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1058 struct wpa_supplicant
*wpa_s
, char *cmd
)
1061 struct hostapd_freq_params freq_params
;
1065 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1066 wpa_printf(MSG_INFO
,
1067 "tdls_chanswitch: Only supported with external setup");
1071 os_memset(&freq_params
, 0, sizeof(freq_params
));
1073 pos
= os_strchr(cmd
, ' ');
1078 oper_class
= strtol(pos
, &end
, 10);
1080 wpa_printf(MSG_INFO
,
1081 "tdls_chanswitch: Invalid op class provided");
1086 freq_params
.freq
= atoi(pos
);
1087 if (freq_params
.freq
== 0) {
1088 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
1092 #define SET_FREQ_SETTING(str) \
1094 const char *pos2 = os_strstr(pos, " " #str "="); \
1096 pos2 += sizeof(" " #str "=") - 1; \
1097 freq_params.str = atoi(pos2); \
1101 SET_FREQ_SETTING(center_freq1
);
1102 SET_FREQ_SETTING(center_freq2
);
1103 SET_FREQ_SETTING(bandwidth
);
1104 SET_FREQ_SETTING(sec_channel_offset
);
1105 #undef SET_FREQ_SETTING
1107 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
1108 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
1110 if (hwaddr_aton(cmd
, peer
)) {
1111 wpa_printf(MSG_DEBUG
,
1112 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1117 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1118 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1119 MAC2STR(peer
), oper_class
, freq_params
.freq
,
1120 freq_params
.center_freq1
, freq_params
.center_freq2
,
1121 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
1122 freq_params
.ht_enabled
? " HT" : "",
1123 freq_params
.vht_enabled
? " VHT" : "");
1125 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
1130 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1131 struct wpa_supplicant
*wpa_s
, char *cmd
)
1135 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1136 wpa_printf(MSG_INFO
,
1137 "tdls_chanswitch: Only supported with external setup");
1141 if (hwaddr_aton(cmd
, peer
)) {
1142 wpa_printf(MSG_DEBUG
,
1143 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1148 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1151 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1155 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1156 struct wpa_supplicant
*wpa_s
, const char *addr
,
1157 char *buf
, size_t buflen
)
1160 const char *tdls_status
;
1163 if (hwaddr_aton(addr
, peer
)) {
1164 wpa_printf(MSG_DEBUG
,
1165 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1169 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1172 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1173 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1174 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1175 if (os_snprintf_error(buflen
, ret
))
1181 #endif /* CONFIG_TDLS */
1184 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1186 char *token
, *context
= NULL
;
1187 struct wmm_ac_ts_setup_params params
= {
1192 while ((token
= str_token(cmd
, " ", &context
))) {
1193 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1194 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1195 sscanf(token
, "nominal_msdu_size=%i",
1196 ¶ms
.nominal_msdu_size
) == 1 ||
1197 sscanf(token
, "mean_data_rate=%i",
1198 ¶ms
.mean_data_rate
) == 1 ||
1199 sscanf(token
, "min_phy_rate=%i",
1200 ¶ms
.minimum_phy_rate
) == 1 ||
1201 sscanf(token
, "sba=%i",
1202 ¶ms
.surplus_bandwidth_allowance
) == 1)
1205 if (os_strcasecmp(token
, "downlink") == 0) {
1206 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1207 } else if (os_strcasecmp(token
, "uplink") == 0) {
1208 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1209 } else if (os_strcasecmp(token
, "bidi") == 0) {
1210 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1211 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1212 params
.fixed_nominal_msdu
= 1;
1214 wpa_printf(MSG_DEBUG
,
1215 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1222 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1226 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1228 u8 tsid
= atoi(cmd
);
1230 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1234 #ifdef CONFIG_IEEE80211R
1235 static int wpa_supplicant_ctrl_iface_ft_ds(
1236 struct wpa_supplicant
*wpa_s
, char *addr
)
1238 u8 target_ap
[ETH_ALEN
];
1239 struct wpa_bss
*bss
;
1242 if (hwaddr_aton(addr
, target_ap
)) {
1243 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1244 "address '%s'", addr
);
1248 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1250 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1252 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1256 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1258 #endif /* CONFIG_IEEE80211R */
1262 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1265 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1267 u8 p2p_dev_addr
[ETH_ALEN
];
1268 #endif /* CONFIG_P2P */
1270 u8
*_p2p_dev_addr
= NULL
;
1271 #endif /* CONFIG_AP */
1275 if (!cmd
|| os_strcmp(cmd
, "any") == 0 ||
1276 os_strncmp(cmd
, "any ", 4) == 0) {
1279 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1280 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1281 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1282 "P2P Device Address '%s'",
1286 _p2p_dev_addr
= p2p_dev_addr
;
1287 #endif /* CONFIG_P2P */
1288 } else if (os_strncmp(cmd
, "multi_ap=", 9) == 0) {
1290 multi_ap
= atoi(cmd
+ 9);
1291 } else if (hwaddr_aton(cmd
, bssid
)) {
1292 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1298 pos
= os_strstr(cmd
, " multi_ap=");
1301 multi_ap
= atoi(pos
);
1306 if (wpa_s
->ap_iface
)
1307 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1308 #endif /* CONFIG_AP */
1310 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0, multi_ap
);
1314 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1315 char *cmd
, char *buf
,
1318 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1322 pin
= os_strchr(cmd
, ' ');
1326 if (os_strcmp(cmd
, "any") == 0)
1328 else if (os_strcmp(cmd
, "get") == 0) {
1329 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1332 } else if (hwaddr_aton(cmd
, bssid
)) {
1333 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1339 if (wpa_s
->ap_iface
) {
1344 pos
= os_strchr(pin
, ' ');
1347 timeout
= atoi(pos
);
1351 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1352 buf
, buflen
, timeout
);
1354 #endif /* CONFIG_AP */
1357 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1361 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1362 if (os_snprintf_error(buflen
, ret
))
1367 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1372 /* Return the generated PIN */
1373 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1374 if (os_snprintf_error(buflen
, ret
))
1380 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1381 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1388 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1389 (u8
*) cmd
, os_strlen(cmd
));
1390 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1391 if (*pos
< '0' || *pos
> '9')
1395 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1399 if (len
!= 4 && len
!= 8) {
1400 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1406 unsigned int pin_val
;
1407 pin_val
= atoi(pin
);
1408 if (!wps_pin_valid(pin_val
)) {
1409 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1410 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1411 if (os_snprintf_error(buflen
, ret
))
1417 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1418 if (os_snprintf_error(buflen
, ret
))
1425 #ifdef CONFIG_WPS_NFC
1427 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1430 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1432 if (cmd
== NULL
|| cmd
[0] == '\0')
1434 else if (hwaddr_aton(cmd
, bssid
))
1437 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1442 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1443 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1450 pos
= os_strchr(cmd
, ' ');
1453 if (os_strcmp(cmd
, "WPS") == 0)
1455 else if (os_strcmp(cmd
, "NDEF") == 0)
1460 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1464 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1466 reply
[res
++] = '\n';
1475 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1476 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1482 if (os_strcmp(cmd
, "WPS") == 0)
1484 else if (os_strcmp(cmd
, "NDEF") == 0)
1489 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1493 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1495 reply
[res
++] = '\n';
1504 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1505 struct wpa_supplicant
*wpa_s
, char *pos
)
1511 int forced_freq
= 0;
1513 freq
= strstr(pos
, " freq=");
1517 forced_freq
= atoi(freq
);
1520 len
= os_strlen(pos
);
1525 buf
= wpabuf_alloc(len
);
1528 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1533 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1540 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1541 char *reply
, size_t max_len
,
1547 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1551 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1553 reply
[res
++] = '\n';
1563 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1564 char *reply
, size_t max_len
,
1570 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1572 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1576 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1578 reply
[res
++] = '\n';
1585 #endif /* CONFIG_P2P */
1588 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1589 char *cmd
, char *reply
,
1595 pos
= os_strchr(cmd
, ' ');
1600 if (os_strcmp(cmd
, "WPS") == 0)
1602 else if (os_strcmp(cmd
, "NDEF") == 0)
1607 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1610 return wpas_ctrl_nfc_get_handover_req_wps(
1611 wpa_s
, reply
, max_len
, ndef
);
1615 if (os_strcmp(pos
, "P2P-CR") == 0) {
1616 return wpas_ctrl_nfc_get_handover_req_p2p(
1617 wpa_s
, reply
, max_len
, ndef
);
1619 #endif /* CONFIG_P2P */
1625 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1626 char *reply
, size_t max_len
,
1627 int ndef
, int cr
, char *uuid
)
1632 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1636 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1638 reply
[res
++] = '\n';
1648 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1649 char *reply
, size_t max_len
,
1655 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1659 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1661 reply
[res
++] = '\n';
1668 #endif /* CONFIG_P2P */
1671 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1672 char *cmd
, char *reply
,
1678 pos
= os_strchr(cmd
, ' ');
1683 if (os_strcmp(cmd
, "WPS") == 0)
1685 else if (os_strcmp(cmd
, "NDEF") == 0)
1690 pos2
= os_strchr(pos
, ' ');
1693 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1696 return wpas_ctrl_nfc_get_handover_sel_wps(
1697 wpa_s
, reply
, max_len
, ndef
,
1698 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1702 if (os_strcmp(pos
, "P2P-CR") == 0) {
1703 return wpas_ctrl_nfc_get_handover_sel_p2p(
1704 wpa_s
, reply
, max_len
, ndef
, 0);
1707 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1708 return wpas_ctrl_nfc_get_handover_sel_p2p(
1709 wpa_s
, reply
, max_len
, ndef
, 1);
1711 #endif /* CONFIG_P2P */
1717 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1721 struct wpabuf
*req
, *sel
;
1723 char *pos
, *role
, *type
, *pos2
;
1726 int forced_freq
= 0;
1728 freq
= strstr(cmd
, " freq=");
1732 forced_freq
= atoi(freq
);
1734 #endif /* CONFIG_P2P */
1737 pos
= os_strchr(role
, ' ');
1739 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1745 pos
= os_strchr(type
, ' ');
1747 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1752 pos2
= os_strchr(pos
, ' ');
1754 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1759 len
= os_strlen(pos
);
1761 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1766 req
= wpabuf_alloc(len
);
1768 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1771 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1772 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1777 len
= os_strlen(pos2
);
1779 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1785 sel
= wpabuf_alloc(len
);
1787 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1791 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1792 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1798 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1799 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1801 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1802 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1804 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1806 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1808 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1809 #endif /* CONFIG_AP */
1811 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1813 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1814 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1816 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1818 #endif /* CONFIG_P2P */
1820 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1821 "reported: role=%s type=%s", role
, type
);
1828 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1833 #endif /* CONFIG_WPS_NFC */
1836 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1845 struct wps_new_ap_settings ap
;
1847 pin
= os_strchr(cmd
, ' ');
1852 if (hwaddr_aton(cmd
, bssid
)) {
1853 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1858 new_ssid
= os_strchr(pin
, ' ');
1859 if (new_ssid
== NULL
)
1860 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1863 new_auth
= os_strchr(new_ssid
, ' ');
1864 if (new_auth
== NULL
)
1868 new_encr
= os_strchr(new_auth
, ' ');
1869 if (new_encr
== NULL
)
1873 new_key
= os_strchr(new_encr
, ' ');
1874 if (new_key
== NULL
)
1878 os_memset(&ap
, 0, sizeof(ap
));
1879 ap
.ssid_hex
= new_ssid
;
1882 ap
.key_hex
= new_key
;
1883 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1888 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1889 char *cmd
, char *buf
,
1894 const char *pin_txt
;
1896 if (!wpa_s
->ap_iface
)
1899 pos
= os_strchr(cmd
, ' ');
1903 if (os_strcmp(cmd
, "disable") == 0) {
1904 wpas_wps_ap_pin_disable(wpa_s
);
1905 return os_snprintf(buf
, buflen
, "OK\n");
1908 if (os_strcmp(cmd
, "random") == 0) {
1910 timeout
= atoi(pos
);
1911 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1912 if (pin_txt
== NULL
)
1914 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1917 if (os_strcmp(cmd
, "get") == 0) {
1918 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1919 if (pin_txt
== NULL
)
1921 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1924 if (os_strcmp(cmd
, "set") == 0) {
1929 pos
= os_strchr(pos
, ' ');
1932 timeout
= atoi(pos
);
1934 if (os_strlen(pin
) > buflen
)
1936 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1938 return os_snprintf(buf
, buflen
, "%s", pin
);
1943 #endif /* CONFIG_AP */
1946 #ifdef CONFIG_WPS_ER
1947 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1950 char *uuid
= cmd
, *pin
, *pos
;
1951 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1952 pin
= os_strchr(uuid
, ' ');
1956 pos
= os_strchr(pin
, ' ');
1959 if (hwaddr_aton(pos
, addr_buf
) == 0)
1962 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1966 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1969 char *uuid
= cmd
, *pin
;
1970 pin
= os_strchr(uuid
, ' ');
1974 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1978 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1979 struct wpa_supplicant
*wpa_s
, char *cmd
)
1981 char *uuid
= cmd
, *id
;
1982 id
= os_strchr(uuid
, ' ');
1986 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1990 static int wpa_supplicant_ctrl_iface_wps_er_config(
1991 struct wpa_supplicant
*wpa_s
, char *cmd
)
1998 struct wps_new_ap_settings ap
;
2000 pin
= os_strchr(cmd
, ' ');
2005 new_ssid
= os_strchr(pin
, ' ');
2006 if (new_ssid
== NULL
)
2010 new_auth
= os_strchr(new_ssid
, ' ');
2011 if (new_auth
== NULL
)
2015 new_encr
= os_strchr(new_auth
, ' ');
2016 if (new_encr
== NULL
)
2020 new_key
= os_strchr(new_encr
, ' ');
2021 if (new_key
== NULL
)
2025 os_memset(&ap
, 0, sizeof(ap
));
2026 ap
.ssid_hex
= new_ssid
;
2029 ap
.key_hex
= new_key
;
2030 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
2034 #ifdef CONFIG_WPS_NFC
2035 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2036 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2043 uuid
= os_strchr(cmd
, ' ');
2048 if (os_strcmp(cmd
, "WPS") == 0)
2050 else if (os_strcmp(cmd
, "NDEF") == 0)
2055 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
2059 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
2061 reply
[res
++] = '\n';
2068 #endif /* CONFIG_WPS_NFC */
2069 #endif /* CONFIG_WPS_ER */
2071 #endif /* CONFIG_WPS */
2074 #ifdef CONFIG_IBSS_RSN
2075 static int wpa_supplicant_ctrl_iface_ibss_rsn(
2076 struct wpa_supplicant
*wpa_s
, char *addr
)
2080 if (hwaddr_aton(addr
, peer
)) {
2081 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
2082 "address '%s'", addr
);
2086 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
2089 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
2091 #endif /* CONFIG_IBSS_RSN */
2094 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
2097 #ifdef IEEE8021X_EAPOL
2100 struct wpa_ssid
*ssid
;
2102 pos
= os_strchr(rsp
, '-');
2107 pos
= os_strchr(pos
, ':');
2112 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
2113 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2114 (u8
*) pos
, os_strlen(pos
));
2116 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2118 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2123 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
2125 #else /* IEEE8021X_EAPOL */
2126 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
2128 #endif /* IEEE8021X_EAPOL */
2132 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
2134 char *buf
, size_t buflen
)
2136 char *pos
, *end
, tmp
[30];
2137 int res
, verbose
, wps
, ret
;
2140 #endif /* CONFIG_HS20 */
2144 if (os_strcmp(params
, "-DRIVER") == 0)
2145 return wpa_drv_status(wpa_s
, buf
, buflen
);
2146 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
2147 wps
= os_strcmp(params
, "-WPS") == 0;
2150 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
2151 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2152 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2153 MAC2STR(wpa_s
->bssid
));
2154 if (os_snprintf_error(end
- pos
, ret
))
2157 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2159 if (os_snprintf_error(end
- pos
, ret
))
2163 u8
*_ssid
= ssid
->ssid
;
2164 size_t ssid_len
= ssid
->ssid_len
;
2165 u8 ssid_buf
[SSID_MAX_LEN
];
2166 if (ssid_len
== 0) {
2167 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2174 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2175 wpa_ssid_txt(_ssid
, ssid_len
),
2177 if (os_snprintf_error(end
- pos
, ret
))
2181 if (wps
&& ssid
->passphrase
&&
2182 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2183 (ssid
->mode
== WPAS_MODE_AP
||
2184 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2185 ret
= os_snprintf(pos
, end
- pos
,
2188 if (os_snprintf_error(end
- pos
, ret
))
2193 ret
= os_snprintf(pos
, end
- pos
,
2196 if (os_snprintf_error(end
- pos
, ret
))
2201 switch (ssid
->mode
) {
2202 case WPAS_MODE_INFRA
:
2203 ret
= os_snprintf(pos
, end
- pos
,
2206 case WPAS_MODE_IBSS
:
2207 ret
= os_snprintf(pos
, end
- pos
,
2211 ret
= os_snprintf(pos
, end
- pos
,
2214 case WPAS_MODE_P2P_GO
:
2215 ret
= os_snprintf(pos
, end
- pos
,
2218 case WPAS_MODE_P2P_GROUP_FORMATION
:
2219 ret
= os_snprintf(pos
, end
- pos
,
2220 "mode=P2P GO - group "
2223 case WPAS_MODE_MESH
:
2224 ret
= os_snprintf(pos
, end
- pos
,
2231 if (os_snprintf_error(end
- pos
, ret
))
2236 if (wpa_s
->connection_set
&&
2237 (wpa_s
->connection_ht
|| wpa_s
->connection_vht
||
2238 wpa_s
->connection_he
)) {
2239 ret
= os_snprintf(pos
, end
- pos
,
2240 "wifi_generation=%u\n",
2241 wpa_s
->connection_he
? 6 :
2242 (wpa_s
->connection_vht
? 5 : 4));
2243 if (os_snprintf_error(end
- pos
, ret
))
2249 if (wpa_s
->ap_iface
) {
2250 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2254 #endif /* CONFIG_AP */
2255 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2259 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2262 #endif /* CONFIG_AP */
2263 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2264 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2265 wpa_s
->sme
.sae
.group
);
2266 if (os_snprintf_error(end
- pos
, ret
))
2270 #endif /* CONFIG_SAE */
2271 #endif /* CONFIG_SME */
2272 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2273 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2274 if (os_snprintf_error(end
- pos
, ret
))
2279 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2280 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2281 if (os_snprintf_error(end
- pos
, ret
))
2287 if (wpa_s
->global
->p2p
) {
2288 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2289 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2290 if (os_snprintf_error(end
- pos
, ret
))
2294 #endif /* CONFIG_P2P */
2296 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2297 MAC2STR(wpa_s
->own_addr
));
2298 if (os_snprintf_error(end
- pos
, ret
))
2303 if (wpa_s
->current_bss
&&
2304 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2305 HS20_IE_VENDOR_TYPE
)) &&
2306 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2307 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2310 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2311 release
= rel_num
+ 1;
2313 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2314 if (os_snprintf_error(end
- pos
, ret
))
2319 if (wpa_s
->current_ssid
) {
2320 struct wpa_cred
*cred
;
2323 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2326 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2329 if (cred
->provisioning_sp
) {
2330 ret
= os_snprintf(pos
, end
- pos
,
2331 "provisioning_sp=%s\n",
2332 cred
->provisioning_sp
);
2333 if (os_snprintf_error(end
- pos
, ret
))
2342 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2343 struct wpabuf
*names
=
2344 wpa_s
->current_bss
->anqp
->domain_name
;
2345 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2347 if (domain_name_list_contains(
2348 names
, cred
->domain
[i
], 1))
2351 if (i
== cred
->num_domain
)
2352 i
= 0; /* show first entry by default */
2354 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2356 if (os_snprintf_error(end
- pos
, ret
))
2361 if (wpa_s
->current_bss
== NULL
||
2362 wpa_s
->current_bss
->anqp
== NULL
)
2365 res
= interworking_home_sp_cred(
2367 wpa_s
->current_bss
->anqp
->domain_name
);
2375 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2376 if (os_snprintf_error(end
- pos
, ret
))
2383 #endif /* CONFIG_HS20 */
2385 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2386 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2387 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2393 #ifdef CONFIG_MACSEC
2394 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2397 #endif /* CONFIG_MACSEC */
2399 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2403 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2404 if (os_snprintf_error(end
- pos
, ret
))
2407 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2411 ret
= os_snprintf(pos
, end
- pos
, "\n");
2412 if (os_snprintf_error(end
- pos
, ret
))
2417 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2424 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2425 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2426 if (os_snprintf_error(end
- pos
, ret
))
2430 #endif /* CONFIG_WPS */
2432 if (wpa_s
->ieee80211ac
) {
2433 ret
= os_snprintf(pos
, end
- pos
, "ieee80211ac=1\n");
2434 if (os_snprintf_error(end
- pos
, ret
))
2441 * Allow using the STATUS command with default behavior, say for debug,
2442 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2443 * events with STATUS-NO_EVENTS.
2445 if (os_strcmp(params
, "-NO_EVENTS")) {
2446 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2447 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2448 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2450 MAC2STR(wpa_s
->bssid
),
2451 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2452 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2453 wpa_s
->current_ssid
->ssid_len
) : "");
2454 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2455 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2456 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2457 "- connection to " MACSTR
2458 " completed %s [id=%d id_str=%s]",
2459 MAC2STR(wpa_s
->bssid
), "(auth)",
2460 ssid
? ssid
->id
: -1,
2461 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2464 #endif /* ANDROID */
2470 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2475 struct wpa_ssid
*ssid
;
2478 /* cmd: "<network id> <BSSID>" */
2479 pos
= os_strchr(cmd
, ' ');
2484 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2485 if (hwaddr_aton(pos
, bssid
)) {
2486 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2490 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2492 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2497 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2498 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2504 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2505 char *cmd
, char *buf
,
2509 struct wpa_blacklist
*e
;
2513 /* cmd: "BLACKLIST [<BSSID>]" */
2517 e
= wpa_s
->blacklist
;
2519 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2521 if (os_snprintf_error(end
- pos
, ret
))
2530 if (os_strncmp(cmd
, "clear", 5) == 0) {
2531 wpa_blacklist_clear(wpa_s
);
2532 os_memcpy(buf
, "OK\n", 3);
2536 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2537 if (hwaddr_aton(cmd
, bssid
)) {
2538 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2543 * Add the BSSID twice, so its count will be 2, causing it to be
2544 * skipped when processing scan results.
2546 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2549 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2552 os_memcpy(buf
, "OK\n", 3);
2557 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2558 char *cmd
, char *buf
,
2561 char *pos
, *end
, *stamp
;
2564 /* cmd: "LOG_LEVEL [<level>]" */
2568 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2570 debug_level_str(wpa_debug_level
),
2571 wpa_debug_timestamp
);
2572 if (os_snprintf_error(end
- pos
, ret
))
2581 stamp
= os_strchr(cmd
, ' ');
2584 while (*stamp
== ' ') {
2589 if (os_strlen(cmd
)) {
2590 int level
= str_to_debug_level(cmd
);
2593 wpa_debug_level
= level
;
2596 if (stamp
&& os_strlen(stamp
))
2597 wpa_debug_timestamp
= atoi(stamp
);
2599 os_memcpy(buf
, "OK\n", 3);
2604 static int wpa_supplicant_ctrl_iface_list_networks(
2605 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2607 char *pos
, *end
, *prev
;
2608 struct wpa_ssid
*ssid
;
2613 ret
= os_snprintf(pos
, end
- pos
,
2614 "network id / ssid / bssid / flags\n");
2615 if (os_snprintf_error(end
- pos
, ret
))
2619 ssid
= wpa_s
->conf
->ssid
;
2621 /* skip over ssids until we find next one */
2622 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2623 int last_id
= atoi(cmd
+ 8);
2624 if (last_id
!= -1) {
2625 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2633 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2635 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2636 if (os_snprintf_error(end
- pos
, ret
))
2639 if (ssid
->bssid_set
) {
2640 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2641 MAC2STR(ssid
->bssid
));
2643 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2645 if (os_snprintf_error(end
- pos
, ret
))
2648 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2649 ssid
== wpa_s
->current_ssid
?
2651 ssid
->disabled
? "[DISABLED]" : "",
2652 ssid
->disabled_until
.sec
?
2653 "[TEMP-DISABLED]" : "",
2654 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2656 if (os_snprintf_error(end
- pos
, ret
))
2659 ret
= os_snprintf(pos
, end
- pos
, "\n");
2660 if (os_snprintf_error(end
- pos
, ret
))
2671 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2674 ret
= os_snprintf(pos
, end
- pos
, "-");
2675 if (os_snprintf_error(end
- pos
, ret
))
2678 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2686 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2687 const u8
*ie
, size_t ie_len
)
2689 struct wpa_ie_data data
;
2693 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2694 if (os_snprintf_error(end
- pos
, ret
))
2698 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2699 ret
= os_snprintf(pos
, end
- pos
, "?]");
2700 if (os_snprintf_error(end
- pos
, ret
))
2707 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2708 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2709 pos
== start
? "" : "+");
2710 if (os_snprintf_error(end
- pos
, ret
))
2714 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2715 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2716 pos
== start
? "" : "+");
2717 if (os_snprintf_error(end
- pos
, ret
))
2721 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2722 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2723 pos
== start
? "" : "+");
2724 if (os_snprintf_error(end
- pos
, ret
))
2728 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2729 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2730 pos
== start
? "" : "+");
2731 if (os_snprintf_error(end
- pos
, ret
))
2735 #ifdef CONFIG_IEEE80211R
2736 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2737 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2738 pos
== start
? "" : "+");
2739 if (os_snprintf_error(end
- pos
, ret
))
2743 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2744 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2745 pos
== start
? "" : "+");
2746 if (os_snprintf_error(end
- pos
, ret
))
2750 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2751 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2752 pos
== start
? "" : "+");
2753 if (os_snprintf_error(end
- pos
, ret
))
2757 #endif /* CONFIG_IEEE80211R */
2758 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2759 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2760 pos
== start
? "" : "+");
2761 if (os_snprintf_error(end
- pos
, ret
))
2765 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2766 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2767 pos
== start
? "" : "+");
2768 if (os_snprintf_error(end
- pos
, ret
))
2773 #ifdef CONFIG_SUITEB
2774 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2775 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2776 pos
== start
? "" : "+");
2777 if (os_snprintf_error(end
- pos
, ret
))
2781 #endif /* CONFIG_SUITEB */
2783 #ifdef CONFIG_SUITEB192
2784 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2785 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2786 pos
== start
? "" : "+");
2787 if (os_snprintf_error(end
- pos
, ret
))
2791 #endif /* CONFIG_SUITEB192 */
2794 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2795 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2796 pos
== start
? "" : "+");
2797 if (os_snprintf_error(end
- pos
, ret
))
2801 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2802 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2803 pos
== start
? "" : "+");
2804 if (os_snprintf_error(end
- pos
, ret
))
2808 #ifdef CONFIG_IEEE80211R
2809 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2810 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2811 pos
== start
? "" : "+");
2812 if (os_snprintf_error(end
- pos
, ret
))
2816 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2817 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2818 pos
== start
? "" : "+");
2819 if (os_snprintf_error(end
- pos
, ret
))
2823 #endif /* CONFIG_IEEE80211R */
2824 #endif /* CONFIG_FILS */
2827 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2828 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2829 pos
== start
? "" : "+");
2830 if (os_snprintf_error(end
- pos
, ret
))
2834 #endif /* CONFIG_OWE */
2837 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2838 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2839 pos
== start
? "" : "+");
2840 if (os_snprintf_error(end
- pos
, ret
))
2844 #endif /* CONFIG_DPP */
2846 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2847 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2848 pos
== start
? "" : "+");
2849 if (os_snprintf_error(end
- pos
, ret
))
2854 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2856 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2857 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2858 if (os_snprintf_error(end
- pos
, ret
))
2863 ret
= os_snprintf(pos
, end
- pos
, "]");
2864 if (os_snprintf_error(end
- pos
, ret
))
2873 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2874 char *pos
, char *end
,
2875 struct wpabuf
*wps_ie
)
2882 if (wps_is_selected_pbc_registrar(wps_ie
))
2884 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2886 else if (wps_is_selected_pin_registrar(wps_ie
))
2891 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2892 if (!os_snprintf_error(end
- pos
, ret
))
2894 wpabuf_free(wps_ie
);
2897 #endif /* CONFIG_WPS */
2900 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2901 char *pos
, char *end
,
2902 const struct wpa_bss
*bss
)
2905 struct wpabuf
*wps_ie
;
2906 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2907 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2908 #else /* CONFIG_WPS */
2910 #endif /* CONFIG_WPS */
2914 /* Format one result on one text line into a buffer. */
2915 static int wpa_supplicant_ctrl_iface_scan_result(
2916 struct wpa_supplicant
*wpa_s
,
2917 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2921 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
, *owe
;
2923 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2924 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2926 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2927 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2928 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2930 return 0; /* Do not show P2P listen discovery results here */
2935 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2936 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2937 if (os_snprintf_error(end
- pos
, ret
))
2940 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2942 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2943 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2945 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2948 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2950 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2951 osen_ie
, 2 + osen_ie
[1]);
2952 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
2954 ret
= os_snprintf(pos
, end
- pos
,
2955 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2956 if (os_snprintf_error(end
- pos
, ret
))
2960 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2961 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2962 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2963 if (os_snprintf_error(end
- pos
, ret
))
2968 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2969 if (os_snprintf_error(end
- pos
, ret
))
2973 if (bss_is_dmg(bss
)) {
2976 if (get_ie_ext((const u8
*) (bss
+ 1), bss
->ie_len
,
2977 WLAN_EID_EXT_EDMG_OPERATION
)) {
2978 ret
= os_snprintf(pos
, end
- pos
, "[EDMG]");
2979 if (os_snprintf_error(end
- pos
, ret
))
2984 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2985 if (os_snprintf_error(end
- pos
, ret
))
2988 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2989 case IEEE80211_CAP_DMG_IBSS
:
2992 case IEEE80211_CAP_DMG_AP
:
2995 case IEEE80211_CAP_DMG_PBSS
:
3002 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
3003 if (os_snprintf_error(end
- pos
, ret
))
3007 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3008 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3009 if (os_snprintf_error(end
- pos
, ret
))
3013 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3014 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3015 if (os_snprintf_error(end
- pos
, ret
))
3021 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3022 if (os_snprintf_error(end
- pos
, ret
))
3027 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
3028 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3029 if (os_snprintf_error(end
- pos
, ret
))
3033 #endif /* CONFIG_HS20 */
3035 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
3036 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
3037 if (os_snprintf_error(end
- pos
, ret
))
3041 #endif /* CONFIG_FILS */
3043 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
3044 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
3045 if (os_snprintf_error(end
- pos
, ret
))
3049 #endif /* CONFIG_FST */
3050 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
3051 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
3052 if (os_snprintf_error(end
- pos
, ret
))
3057 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
3058 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3059 if (os_snprintf_error(end
- pos
, ret
))
3063 ret
= os_snprintf(pos
, end
- pos
, "\n");
3064 if (os_snprintf_error(end
- pos
, ret
))
3072 static int wpa_supplicant_ctrl_iface_scan_results(
3073 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3076 struct wpa_bss
*bss
;
3081 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
3083 if (os_snprintf_error(end
- pos
, ret
))
3087 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
3088 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
3090 if (ret
< 0 || ret
>= end
- pos
)
3101 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3102 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
3104 char *pos
, ifname
[IFNAMSIZ
+ 1];
3108 pos
= os_strstr(cmd
, "ifname=");
3111 os_strlcpy(ifname
, pos
, sizeof(ifname
));
3114 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
3117 os_strlcpy(reply
, ifname
, max_len
);
3118 return os_strlen(ifname
);
3122 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3123 struct wpa_supplicant
*wpa_s
, char *cmd
)
3126 struct wpa_ssid
*ssid
;
3129 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
3131 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3133 wpa_printf(MSG_DEBUG
,
3134 "CTRL_IFACE: Could not find network id=%d", id
);
3137 if (ssid
->mode
!= WPAS_MODE_MESH
) {
3138 wpa_printf(MSG_DEBUG
,
3139 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3142 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3143 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
3144 wpa_printf(MSG_ERROR
,
3145 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3150 * TODO: If necessary write our own group_add function,
3151 * for now we can reuse select_network
3153 wpa_supplicant_select_network(wpa_s
, ssid
);
3159 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3160 struct wpa_supplicant
*wpa_s
, char *cmd
)
3162 struct wpa_supplicant
*orig
;
3163 struct wpa_global
*global
;
3166 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
3168 global
= wpa_s
->global
;
3171 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3172 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
3178 wpa_printf(MSG_ERROR
,
3179 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3183 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
3184 wpa_printf(MSG_ERROR
,
3185 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3189 wpa_s
->reassociate
= 0;
3190 wpa_s
->disconnected
= 1;
3191 wpa_supplicant_cancel_sched_scan(wpa_s
);
3192 wpa_supplicant_cancel_scan(wpa_s
);
3195 * TODO: If necessary write our own group_remove function,
3196 * for now we can reuse deauthenticate
3198 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3200 if (wpa_s
->mesh_if_created
)
3201 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3207 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3208 struct wpa_supplicant
*wpa_s
, char *cmd
)
3212 if (hwaddr_aton(cmd
, addr
) < 0)
3215 return wpas_mesh_peer_remove(wpa_s
, addr
);
3219 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3220 struct wpa_supplicant
*wpa_s
, char *cmd
)
3226 pos
= os_strstr(cmd
, " duration=");
3229 duration
= atoi(pos
+ 10);
3234 if (hwaddr_aton(cmd
, addr
))
3237 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3241 static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3242 struct wpa_supplicant
*wpa_s
, char *cmd
)
3244 struct ether_header
*eth
;
3248 size_t payload_len
= 0, len
;
3251 if (hwaddr_aton(cmd
, addr
))
3254 pos
= os_strstr(cmd
, " payload=");
3257 payload_len
= os_strlen(pos
);
3258 if (payload_len
& 1)
3264 len
= ETH_HLEN
+ payload_len
;
3265 buf
= os_malloc(len
);
3269 eth
= (struct ether_header
*) buf
;
3270 os_memcpy(eth
->ether_dhost
, addr
, ETH_ALEN
);
3271 os_memcpy(eth
->ether_shost
, wpa_s
->own_addr
, ETH_ALEN
);
3272 eth
->ether_type
= htons(ETH_P_802_3
);
3274 if (payload_len
&& hexstr2bin(pos
, buf
+ ETH_HLEN
, payload_len
) < 0)
3277 ret
= wpa_drv_mesh_link_probe(wpa_s
, addr
, buf
, len
);
3283 #endif /* CONFIG_MESH */
3286 static int wpa_supplicant_ctrl_iface_select_network(
3287 struct wpa_supplicant
*wpa_s
, char *cmd
)
3290 struct wpa_ssid
*ssid
;
3293 /* cmd: "<network id>" or "any" */
3294 if (os_strncmp(cmd
, "any", 3) == 0) {
3295 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3299 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3301 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3303 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3304 "network id=%d", id
);
3307 if (ssid
->disabled
== 2) {
3308 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3309 "SELECT_NETWORK with persistent P2P group");
3314 pos
= os_strstr(cmd
, " freq=");
3316 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3318 os_free(wpa_s
->select_network_scan_freqs
);
3319 wpa_s
->select_network_scan_freqs
= freqs
;
3323 wpa_s
->scan_min_time
.sec
= 0;
3324 wpa_s
->scan_min_time
.usec
= 0;
3325 wpa_supplicant_select_network(wpa_s
, ssid
);
3331 static int wpa_supplicant_ctrl_iface_enable_network(
3332 struct wpa_supplicant
*wpa_s
, char *cmd
)
3335 struct wpa_ssid
*ssid
;
3337 /* cmd: "<network id>" or "all" */
3338 if (os_strcmp(cmd
, "all") == 0) {
3339 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3343 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3345 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3347 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3348 "network id=%d", id
);
3351 if (ssid
->disabled
== 2) {
3352 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3353 "ENABLE_NETWORK with persistent P2P group");
3357 if (os_strstr(cmd
, " no-connect")) {
3362 wpa_s
->scan_min_time
.sec
= 0;
3363 wpa_s
->scan_min_time
.usec
= 0;
3364 wpa_supplicant_enable_network(wpa_s
, ssid
);
3370 static int wpa_supplicant_ctrl_iface_disable_network(
3371 struct wpa_supplicant
*wpa_s
, char *cmd
)
3374 struct wpa_ssid
*ssid
;
3376 /* cmd: "<network id>" or "all" */
3377 if (os_strcmp(cmd
, "all") == 0) {
3378 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3382 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3384 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3386 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3387 "network id=%d", id
);
3390 if (ssid
->disabled
== 2) {
3391 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3392 "DISABLE_NETWORK with persistent P2P "
3397 wpa_supplicant_disable_network(wpa_s
, ssid
);
3403 static int wpa_supplicant_ctrl_iface_add_network(
3404 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3406 struct wpa_ssid
*ssid
;
3409 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3411 ssid
= wpa_supplicant_add_network(wpa_s
);
3415 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3416 if (os_snprintf_error(buflen
, ret
))
3422 static int wpa_supplicant_ctrl_iface_remove_network(
3423 struct wpa_supplicant
*wpa_s
, char *cmd
)
3426 struct wpa_ssid
*ssid
;
3429 /* cmd: "<network id>" or "all" */
3430 if (os_strcmp(cmd
, "all") == 0) {
3431 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3432 if (wpa_s
->sched_scanning
)
3433 wpa_supplicant_cancel_sched_scan(wpa_s
);
3435 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3436 if (wpa_s
->current_ssid
) {
3438 wpa_s
->sme
.prev_bssid_set
= 0;
3439 #endif /* CONFIG_SME */
3440 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3441 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3442 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3443 wpa_s
->own_disconnect_req
= 1;
3444 wpa_supplicant_deauthenticate(
3445 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3447 ssid
= wpa_s
->conf
->ssid
;
3449 struct wpa_ssid
*remove_ssid
= ssid
;
3452 if (wpa_s
->last_ssid
== remove_ssid
)
3453 wpa_s
->last_ssid
= NULL
;
3454 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3455 wpa_config_remove_network(wpa_s
->conf
, id
);
3461 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3463 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3465 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3470 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3471 "network id=%d", id
);
3478 static int wpa_supplicant_ctrl_iface_update_network(
3479 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3480 char *name
, char *value
)
3484 ret
= wpa_config_set(ssid
, name
, value
, 0);
3486 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3487 "variable '%s'", name
);
3491 return 0; /* No change to the previously configured value */
3493 if (os_strcmp(name
, "bssid") != 0 &&
3494 os_strcmp(name
, "bssid_hint") != 0 &&
3495 os_strcmp(name
, "priority") != 0) {
3496 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3498 if (wpa_s
->current_ssid
== ssid
||
3499 wpa_s
->current_ssid
== NULL
) {
3501 * Invalidate the EAP session cache if anything in the
3502 * current or previously used configuration changes.
3504 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3508 if ((os_strcmp(name
, "psk") == 0 &&
3509 value
[0] == '"' && ssid
->ssid_len
) ||
3510 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3511 wpa_config_update_psk(ssid
);
3512 else if (os_strcmp(name
, "priority") == 0)
3513 wpa_config_update_prio_list(wpa_s
->conf
);
3519 static int wpa_supplicant_ctrl_iface_set_network(
3520 struct wpa_supplicant
*wpa_s
, char *cmd
)
3522 int id
, ret
, prev_bssid_set
, prev_disabled
;
3523 struct wpa_ssid
*ssid
;
3525 u8 prev_bssid
[ETH_ALEN
];
3527 /* cmd: "<network id> <variable name> <value>" */
3528 name
= os_strchr(cmd
, ' ');
3533 value
= os_strchr(name
, ' ');
3539 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3541 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3542 (u8
*) value
, os_strlen(value
));
3544 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3546 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3551 prev_bssid_set
= ssid
->bssid_set
;
3552 prev_disabled
= ssid
->disabled
;
3553 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3554 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3557 (ssid
->bssid_set
!= prev_bssid_set
||
3558 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3559 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3561 if (prev_disabled
!= ssid
->disabled
&&
3562 (prev_disabled
== 2 || ssid
->disabled
== 2))
3563 wpas_notify_network_type_changed(wpa_s
, ssid
);
3569 static int wpa_supplicant_ctrl_iface_get_network(
3570 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3574 struct wpa_ssid
*ssid
;
3577 /* cmd: "<network id> <variable name>" */
3578 name
= os_strchr(cmd
, ' ');
3579 if (name
== NULL
|| buflen
== 0)
3584 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3587 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3589 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3594 value
= wpa_config_get_no_key(ssid
, name
);
3595 if (value
== NULL
) {
3596 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3597 "variable '%s'", name
);
3601 res
= os_strlcpy(buf
, value
, buflen
);
3602 if (res
>= buflen
) {
3613 static int wpa_supplicant_ctrl_iface_dup_network(
3614 struct wpa_supplicant
*wpa_s
, char *cmd
,
3615 struct wpa_supplicant
*dst_wpa_s
)
3617 struct wpa_ssid
*ssid_s
, *ssid_d
;
3618 char *name
, *id
, *value
;
3619 int id_s
, id_d
, ret
;
3621 /* cmd: "<src network id> <dst network id> <variable name>" */
3622 id
= os_strchr(cmd
, ' ');
3627 name
= os_strchr(id
, ' ');
3635 wpa_printf(MSG_DEBUG
,
3636 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3637 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3639 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3640 if (ssid_s
== NULL
) {
3641 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3642 "network id=%d", id_s
);
3646 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3647 if (ssid_d
== NULL
) {
3648 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3649 "network id=%d", id_d
);
3653 value
= wpa_config_get(ssid_s
, name
);
3654 if (value
== NULL
) {
3655 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3656 "variable '%s'", name
);
3660 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3669 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3670 char *buf
, size_t buflen
)
3673 struct wpa_cred
*cred
;
3678 ret
= os_snprintf(pos
, end
- pos
,
3679 "cred id / realm / username / domain / imsi\n");
3680 if (os_snprintf_error(end
- pos
, ret
))
3684 cred
= wpa_s
->conf
->cred
;
3686 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3687 cred
->id
, cred
->realm
? cred
->realm
: "",
3688 cred
->username
? cred
->username
: "",
3689 cred
->domain
? cred
->domain
[0] : "",
3690 cred
->imsi
? cred
->imsi
: "");
3691 if (os_snprintf_error(end
- pos
, ret
))
3702 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3703 char *buf
, size_t buflen
)
3705 struct wpa_cred
*cred
;
3708 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3710 cred
= wpa_config_add_cred(wpa_s
->conf
);
3714 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3716 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3717 if (os_snprintf_error(buflen
, ret
))
3723 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3724 struct wpa_cred
*cred
)
3726 struct wpa_ssid
*ssid
;
3731 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3736 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3737 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3741 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3743 /* Remove any network entry created based on the removed credential */
3744 ssid
= wpa_s
->conf
->ssid
;
3746 if (ssid
->parent_cred
== cred
) {
3749 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3750 "used the removed credential", ssid
->id
);
3751 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3752 if (os_snprintf_error(sizeof(str
), res
))
3753 str
[sizeof(str
) - 1] = '\0';
3755 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3764 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3768 struct wpa_cred
*cred
, *prev
;
3770 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3771 * "provisioning_sp=<FQDN> */
3772 if (os_strcmp(cmd
, "all") == 0) {
3773 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3774 cred
= wpa_s
->conf
->cred
;
3778 wpas_ctrl_remove_cred(wpa_s
, prev
);
3783 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3784 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3786 cred
= wpa_s
->conf
->cred
;
3792 for (i
= 0; i
< prev
->num_domain
; i
++) {
3793 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3796 wpas_ctrl_remove_cred(wpa_s
, prev
);
3804 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3805 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3807 cred
= wpa_s
->conf
->cred
;
3811 if (prev
->provisioning_sp
&&
3812 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3813 wpas_ctrl_remove_cred(wpa_s
, prev
);
3819 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3821 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3822 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3826 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3830 struct wpa_cred
*cred
;
3833 /* cmd: "<cred id> <variable name> <value>" */
3834 name
= os_strchr(cmd
, ' ');
3839 value
= os_strchr(name
, ' ');
3845 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3847 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3848 (u8
*) value
, os_strlen(value
));
3850 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3852 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3857 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3858 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3859 "variable '%s'", name
);
3863 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3869 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3870 char *cmd
, char *buf
,
3875 struct wpa_cred
*cred
;
3878 /* cmd: "<cred id> <variable name>" */
3879 name
= os_strchr(cmd
, ' ');
3885 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3888 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3890 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3895 value
= wpa_config_get_cred_no_key(cred
, name
);
3896 if (value
== NULL
) {
3897 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3902 res
= os_strlcpy(buf
, value
, buflen
);
3903 if (res
>= buflen
) {
3914 #ifndef CONFIG_NO_CONFIG_WRITE
3915 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3919 if (!wpa_s
->conf
->update_config
) {
3920 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3921 "to update configuration (update_config=0)");
3925 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3927 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3928 "update configuration");
3930 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3936 #endif /* CONFIG_NO_CONFIG_WRITE */
3939 struct cipher_info
{
3945 static const struct cipher_info ciphers
[] = {
3946 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3947 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3948 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3949 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3950 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3951 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3952 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3953 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3956 static const struct cipher_info ciphers_group_mgmt
[] = {
3957 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3958 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3959 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3960 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3964 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3965 struct wpa_driver_capa
*capa
,
3966 char *buf
, size_t buflen
)
3979 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3985 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3986 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3987 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3988 pos
== buf
? "" : " ",
3990 if (os_snprintf_error(end
- pos
, ret
))
4000 static int ctrl_iface_get_capability_group(int res
, char *strict
,
4001 struct wpa_driver_capa
*capa
,
4002 char *buf
, size_t buflen
)
4015 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
4021 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
4022 if (capa
->enc
& ciphers
[i
].capa
) {
4023 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4024 pos
== buf
? "" : " ",
4026 if (os_snprintf_error(end
- pos
, ret
))
4036 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
4037 struct wpa_driver_capa
*capa
,
4038 char *buf
, size_t buflen
)
4050 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
4051 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
4052 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
4053 pos
== buf
? "" : " ",
4054 ciphers_group_mgmt
[i
].name
);
4055 if (os_snprintf_error(end
- pos
, ret
))
4065 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
4066 struct wpa_driver_capa
*capa
,
4067 char *buf
, size_t buflen
)
4079 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4086 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
4087 if (os_snprintf_error(end
- pos
, ret
))
4091 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4092 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
4093 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
4094 if (os_snprintf_error(end
- pos
, ret
))
4099 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
4100 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4101 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
4102 if (os_snprintf_error(end
- pos
, ret
))
4107 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
4108 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
4109 if (os_snprintf_error(end
- pos
, ret
))
4114 #ifdef CONFIG_SUITEB
4115 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
4116 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
4117 if (os_snprintf_error(end
- pos
, ret
))
4121 #endif /* CONFIG_SUITEB */
4122 #ifdef CONFIG_SUITEB192
4123 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
4124 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
4125 if (os_snprintf_error(end
- pos
, ret
))
4129 #endif /* CONFIG_SUITEB192 */
4131 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
4132 ret
= os_snprintf(pos
, end
- pos
, " OWE");
4133 if (os_snprintf_error(end
- pos
, ret
))
4137 #endif /* CONFIG_OWE */
4139 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
4140 ret
= os_snprintf(pos
, end
- pos
, " DPP");
4141 if (os_snprintf_error(end
- pos
, ret
))
4145 #endif /* CONFIG_DPP */
4147 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
4148 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
4149 if (os_snprintf_error(end
- pos
, ret
))
4153 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
4154 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
4155 if (os_snprintf_error(end
- pos
, ret
))
4159 #ifdef CONFIG_IEEE80211R
4160 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
4161 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
4162 if (os_snprintf_error(end
- pos
, ret
))
4166 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
4167 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
4168 if (os_snprintf_error(end
- pos
, ret
))
4172 #endif /* CONFIG_IEEE80211R */
4173 #endif /* CONFIG_FILS */
4174 #ifdef CONFIG_IEEE80211R
4175 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
) {
4176 ret
= os_snprintf(pos
, end
- pos
, " FT-PSK");
4177 if (os_snprintf_error(end
- pos
, ret
))
4181 #endif /* CONFIG_IEEE80211R */
4183 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SAE
) {
4184 ret
= os_snprintf(pos
, end
- pos
, " SAE");
4185 if (os_snprintf_error(end
- pos
, ret
))
4189 #endif /* CONFIG_SAE */
4195 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
4196 struct wpa_driver_capa
*capa
,
4197 char *buf
, size_t buflen
)
4209 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
4215 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
4216 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4217 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
4218 pos
== buf
? "" : " ");
4219 if (os_snprintf_error(end
- pos
, ret
))
4224 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4225 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
4226 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
4227 pos
== buf
? "" : " ");
4228 if (os_snprintf_error(end
- pos
, ret
))
4237 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
4238 int res
, char *strict
,
4239 struct wpa_driver_capa
*capa
,
4240 char *buf
, size_t buflen
)
4252 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4258 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4259 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4260 pos
== buf
? "" : " ");
4261 if (os_snprintf_error(end
- pos
, ret
))
4266 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4267 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4268 pos
== buf
? "" : " ");
4269 if (os_snprintf_error(end
- pos
, ret
))
4274 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4275 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4276 pos
== buf
? "" : " ");
4277 if (os_snprintf_error(end
- pos
, ret
))
4283 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4284 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4285 pos
== buf
? "" : " ");
4286 if (os_snprintf_error(end
- pos
, ret
))
4290 #endif /* CONFIG_SAE */
4293 if (wpa_is_fils_supported(wpa_s
)) {
4294 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4295 pos
== buf
? "" : " ");
4296 if (os_snprintf_error(end
- pos
, ret
))
4301 #ifdef CONFIG_FILS_SK_PFS
4302 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4303 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4304 pos
== buf
? "" : " ");
4305 if (os_snprintf_error(end
- pos
, ret
))
4309 #endif /* CONFIG_FILS_SK_PFS */
4310 #endif /* CONFIG_FILS */
4316 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4317 struct wpa_driver_capa
*capa
,
4318 char *buf
, size_t buflen
)
4330 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4336 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4337 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4338 pos
== buf
? "" : " ");
4339 if (os_snprintf_error(end
- pos
, ret
))
4344 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4345 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4346 pos
== buf
? "" : " ");
4347 if (os_snprintf_error(end
- pos
, ret
))
4353 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4354 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4355 pos
== buf
? "" : " ");
4356 if (os_snprintf_error(end
- pos
, ret
))
4360 #endif /* CONFIG_MESH */
4366 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4367 char *buf
, size_t buflen
)
4369 struct hostapd_channel_data
*chnl
;
4371 char *pos
, *end
, *hmode
;
4376 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4377 switch (wpa_s
->hw
.modes
[j
].mode
) {
4378 case HOSTAPD_MODE_IEEE80211B
:
4381 case HOSTAPD_MODE_IEEE80211G
:
4384 case HOSTAPD_MODE_IEEE80211A
:
4387 case HOSTAPD_MODE_IEEE80211AD
:
4393 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4394 if (os_snprintf_error(end
- pos
, ret
))
4397 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4398 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4399 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4401 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4402 if (os_snprintf_error(end
- pos
, ret
))
4406 ret
= os_snprintf(pos
, end
- pos
, "\n");
4407 if (os_snprintf_error(end
- pos
, ret
))
4416 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4417 char *buf
, size_t buflen
)
4419 struct hostapd_channel_data
*chnl
;
4421 char *pos
, *end
, *hmode
;
4426 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4427 switch (wpa_s
->hw
.modes
[j
].mode
) {
4428 case HOSTAPD_MODE_IEEE80211B
:
4431 case HOSTAPD_MODE_IEEE80211G
:
4434 case HOSTAPD_MODE_IEEE80211A
:
4437 case HOSTAPD_MODE_IEEE80211AD
:
4443 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4445 if (os_snprintf_error(end
- pos
, ret
))
4448 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4449 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4450 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4452 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4453 chnl
[i
].chan
, chnl
[i
].freq
,
4454 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4456 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4459 if (os_snprintf_error(end
- pos
, ret
))
4463 ret
= os_snprintf(pos
, end
- pos
, "\n");
4464 if (os_snprintf_error(end
- pos
, ret
))
4473 static int wpa_supplicant_ctrl_iface_get_capability(
4474 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4477 struct wpa_driver_capa capa
;
4483 /* Determine whether or not strict checking was requested */
4484 len
= os_strlcpy(field
, _field
, sizeof(field
));
4485 if (len
>= sizeof(field
))
4487 strict
= os_strchr(field
, ' ');
4488 if (strict
!= NULL
) {
4490 if (os_strcmp(strict
, "strict") != 0)
4494 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4495 field
, strict
? strict
: "");
4497 if (os_strcmp(field
, "eap") == 0) {
4498 return eap_get_names(buf
, buflen
);
4501 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4503 if (os_strcmp(field
, "pairwise") == 0)
4504 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4507 if (os_strcmp(field
, "group") == 0)
4508 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4511 if (os_strcmp(field
, "group_mgmt") == 0)
4512 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4515 if (os_strcmp(field
, "key_mgmt") == 0)
4516 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4519 if (os_strcmp(field
, "proto") == 0)
4520 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4523 if (os_strcmp(field
, "auth_alg") == 0)
4524 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4525 &capa
, buf
, buflen
);
4527 if (os_strcmp(field
, "modes") == 0)
4528 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4531 if (os_strcmp(field
, "channels") == 0)
4532 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4534 if (os_strcmp(field
, "freq") == 0)
4535 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4538 if (os_strcmp(field
, "tdls") == 0)
4539 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4540 #endif /* CONFIG_TDLS */
4543 if (os_strcmp(field
, "erp") == 0) {
4544 res
= os_snprintf(buf
, buflen
, "ERP");
4545 if (os_snprintf_error(buflen
, res
))
4549 #endif /* CONFIG_EPR */
4552 if (os_strcmp(field
, "fips") == 0) {
4553 res
= os_snprintf(buf
, buflen
, "FIPS");
4554 if (os_snprintf_error(buflen
, res
))
4558 #endif /* CONFIG_FIPS */
4561 if (os_strcmp(field
, "acs") == 0) {
4562 res
= os_snprintf(buf
, buflen
, "ACS");
4563 if (os_snprintf_error(buflen
, res
))
4567 #endif /* CONFIG_ACS */
4570 if (os_strcmp(field
, "fils") == 0) {
4571 #ifdef CONFIG_FILS_SK_PFS
4572 if (wpa_is_fils_supported(wpa_s
) &&
4573 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4574 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4575 if (os_snprintf_error(buflen
, res
))
4579 #endif /* CONFIG_FILS_SK_PFS */
4581 if (wpa_is_fils_supported(wpa_s
)) {
4582 res
= os_snprintf(buf
, buflen
, "FILS");
4583 if (os_snprintf_error(buflen
, res
))
4588 #endif /* CONFIG_FILS */
4590 if (os_strcmp(field
, "multibss") == 0 && wpa_s
->multi_bss_support
) {
4591 res
= os_snprintf(buf
, buflen
, "MULTIBSS-STA");
4592 if (os_snprintf_error(buflen
, res
))
4598 if (os_strcmp(field
, "dpp") == 0) {
4600 res
= os_snprintf(buf
, buflen
, "DPP=2");
4601 #else /* CONFIG_DPP2 */
4602 res
= os_snprintf(buf
, buflen
, "DPP=1");
4603 #endif /* CONFIG_DPP2 */
4604 if (os_snprintf_error(buflen
, res
))
4608 #endif /* CONFIG_DPP */
4610 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4617 #ifdef CONFIG_INTERWORKING
4618 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4619 struct wpabuf
*data
)
4629 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4630 if (os_snprintf_error(end
- pos
, ret
))
4634 d
= wpabuf_head_u8(data
);
4635 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4636 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4637 if (os_snprintf_error(end
- pos
, ret
))
4642 ret
= os_snprintf(pos
, end
- pos
, "\n");
4643 if (os_snprintf_error(end
- pos
, ret
))
4649 #endif /* CONFIG_INTERWORKING */
4653 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4656 const u8
*ie
, *ie_end
;
4660 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4663 ie_end
= ie
+ 2 + ie
[1];
4665 if (ie_end
- ie
< 2)
4668 info
= WPA_GET_LE16(ie
);
4670 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4671 if (os_snprintf_error(end
- pos
, ret
))
4675 if (info
& BIT(7)) {
4676 /* Cache Identifier Included */
4677 if (ie_end
- ie
< 2)
4679 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4681 if (os_snprintf_error(end
- pos
, ret
))
4687 if (info
& BIT(8)) {
4688 /* HESSID Included */
4689 if (ie_end
- ie
< ETH_ALEN
)
4691 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4693 if (os_snprintf_error(end
- pos
, ret
))
4699 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4701 if (ie_end
- ie
< realms
* 2)
4703 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4704 if (os_snprintf_error(end
- pos
, ret
))
4708 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4713 ret
= os_snprintf(pos
, end
- pos
, "\n");
4714 if (os_snprintf_error(end
- pos
, ret
))
4721 #endif /* CONFIG_FILS */
4724 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4725 unsigned long mask
, char *buf
, size_t buflen
)
4730 const u8
*ie
, *ie2
, *osen_ie
, *mesh
, *owe
;
4735 if (mask
& WPA_BSS_MASK_ID
) {
4736 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4737 if (os_snprintf_error(end
- pos
, ret
))
4742 if (mask
& WPA_BSS_MASK_BSSID
) {
4743 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4744 MAC2STR(bss
->bssid
));
4745 if (os_snprintf_error(end
- pos
, ret
))
4750 if (mask
& WPA_BSS_MASK_FREQ
) {
4751 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4752 if (os_snprintf_error(end
- pos
, ret
))
4757 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4758 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4760 if (os_snprintf_error(end
- pos
, ret
))
4765 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4766 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4768 if (os_snprintf_error(end
- pos
, ret
))
4773 if (mask
& WPA_BSS_MASK_QUAL
) {
4774 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4775 if (os_snprintf_error(end
- pos
, ret
))
4780 if (mask
& WPA_BSS_MASK_NOISE
) {
4781 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4782 if (os_snprintf_error(end
- pos
, ret
))
4787 if (mask
& WPA_BSS_MASK_LEVEL
) {
4788 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4789 if (os_snprintf_error(end
- pos
, ret
))
4794 if (mask
& WPA_BSS_MASK_TSF
) {
4795 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4796 (unsigned long long) bss
->tsf
);
4797 if (os_snprintf_error(end
- pos
, ret
))
4802 if (mask
& WPA_BSS_MASK_AGE
) {
4803 struct os_reltime now
;
4805 os_get_reltime(&now
);
4806 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4807 (int) (now
.sec
- bss
->last_update
.sec
));
4808 if (os_snprintf_error(end
- pos
, ret
))
4813 if (mask
& WPA_BSS_MASK_IE
) {
4814 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4815 if (os_snprintf_error(end
- pos
, ret
))
4819 ie
= (const u8
*) (bss
+ 1);
4820 for (i
= 0; i
< bss
->ie_len
; i
++) {
4821 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4822 if (os_snprintf_error(end
- pos
, ret
))
4827 ret
= os_snprintf(pos
, end
- pos
, "\n");
4828 if (os_snprintf_error(end
- pos
, ret
))
4833 if (mask
& WPA_BSS_MASK_FLAGS
) {
4834 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4835 if (os_snprintf_error(end
- pos
, ret
))
4839 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4841 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4843 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4845 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4847 pos
= wpa_supplicant_ie_txt(pos
, end
,
4848 mesh
? "RSN" : "WPA2", ie2
,
4850 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4852 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4853 osen_ie
, 2 + osen_ie
[1]);
4854 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
4858 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4859 if (os_snprintf_error(end
- pos
, ret
))
4863 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4864 if (!ie
&& !ie2
&& !osen_ie
&&
4865 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4866 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4867 if (os_snprintf_error(end
- pos
, ret
))
4873 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4874 if (os_snprintf_error(end
- pos
, ret
))
4879 if (bss_is_dmg(bss
)) {
4881 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4882 if (os_snprintf_error(end
- pos
, ret
))
4885 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4886 case IEEE80211_CAP_DMG_IBSS
:
4889 case IEEE80211_CAP_DMG_AP
:
4892 case IEEE80211_CAP_DMG_PBSS
:
4899 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4900 if (os_snprintf_error(end
- pos
, ret
))
4904 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4905 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4906 if (os_snprintf_error(end
- pos
, ret
))
4910 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4911 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4912 if (os_snprintf_error(end
- pos
, ret
))
4917 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4918 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4919 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4920 if (os_snprintf_error(end
- pos
, ret
))
4925 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4926 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4927 if (os_snprintf_error(end
- pos
, ret
))
4931 #endif /* CONFIG_HS20 */
4933 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4934 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4935 if (os_snprintf_error(end
- pos
, ret
))
4939 #endif /* CONFIG_FILS */
4941 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
4942 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
4943 if (os_snprintf_error(end
- pos
, ret
))
4947 #endif /* CONFIG_FST */
4948 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
4949 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
4950 if (os_snprintf_error(end
- pos
, ret
))
4955 ret
= os_snprintf(pos
, end
- pos
, "\n");
4956 if (os_snprintf_error(end
- pos
, ret
))
4961 if (mask
& WPA_BSS_MASK_SSID
) {
4962 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4963 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4964 if (os_snprintf_error(end
- pos
, ret
))
4970 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4971 ie
= (const u8
*) (bss
+ 1);
4972 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4973 if (ret
>= end
- pos
)
4978 #endif /* CONFIG_WPS */
4981 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4982 ie
= (const u8
*) (bss
+ 1);
4983 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4984 if (ret
>= end
- pos
)
4989 #endif /* CONFIG_P2P */
4991 #ifdef CONFIG_WIFI_DISPLAY
4992 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4994 ie
= (const u8
*) (bss
+ 1);
4995 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4996 WFD_IE_VENDOR_TYPE
);
4998 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4999 if (os_snprintf_error(end
- pos
, ret
)) {
5005 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
5010 ret
= os_snprintf(pos
, end
- pos
, "\n");
5011 if (os_snprintf_error(end
- pos
, ret
))
5016 #endif /* CONFIG_WIFI_DISPLAY */
5018 #ifdef CONFIG_INTERWORKING
5019 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
5020 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
5021 struct wpa_bss_anqp_elem
*elem
;
5023 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
5024 anqp
->capability_list
);
5025 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
5027 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
5028 anqp
->network_auth_type
);
5029 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
5030 anqp
->roaming_consortium
);
5031 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
5032 anqp
->ip_addr_type_availability
);
5033 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
5035 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
5036 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
5038 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
5039 anqp
->fils_realm_info
);
5041 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
5042 anqp
->hs20_capability_list
);
5043 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
5044 anqp
->hs20_operator_friendly_name
);
5045 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
5046 anqp
->hs20_wan_metrics
);
5047 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
5048 anqp
->hs20_connection_capability
);
5049 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
5050 anqp
->hs20_operating_class
);
5051 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
5052 anqp
->hs20_osu_providers_list
);
5053 pos
= anqp_add_hex(pos
, end
, "hs20_operator_icon_metadata",
5054 anqp
->hs20_operator_icon_metadata
);
5055 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_nai_list",
5056 anqp
->hs20_osu_providers_nai_list
);
5057 #endif /* CONFIG_HS20 */
5059 dl_list_for_each(elem
, &anqp
->anqp_elems
,
5060 struct wpa_bss_anqp_elem
, list
) {
5063 os_snprintf(title
, sizeof(title
), "anqp[%u]",
5065 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
5068 #endif /* CONFIG_INTERWORKING */
5071 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
5072 ie
= (const u8
*) (bss
+ 1);
5073 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
5074 if (ret
>= end
- pos
)
5079 #endif /* CONFIG_MESH */
5081 if (mask
& WPA_BSS_MASK_SNR
) {
5082 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
5083 if (os_snprintf_error(end
- pos
, ret
))
5088 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
5089 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
5090 bss
->est_throughput
);
5091 if (os_snprintf_error(end
- pos
, ret
))
5097 if (mask
& WPA_BSS_MASK_FST
) {
5098 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
5099 if (ret
< 0 || ret
>= end
- pos
)
5103 #endif /* CONFIG_FST */
5105 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
5106 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
5107 bss
->last_update_idx
);
5108 if (os_snprintf_error(end
- pos
, ret
))
5113 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
5114 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
5115 if (os_snprintf_error(end
- pos
, ret
))
5119 ie
= (const u8
*) (bss
+ 1);
5121 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
5122 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
5123 if (os_snprintf_error(end
- pos
, ret
))
5128 ret
= os_snprintf(pos
, end
- pos
, "\n");
5129 if (os_snprintf_error(end
- pos
, ret
))
5135 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
5136 ret
= print_fils_indication(bss
, pos
, end
);
5141 #endif /* CONFIG_FILS */
5143 if (mask
& WPA_BSS_MASK_DELIM
) {
5144 ret
= os_snprintf(pos
, end
- pos
, "====\n");
5145 if (os_snprintf_error(end
- pos
, ret
))
5154 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
5155 const char *cmd
, char *buf
,
5160 struct wpa_bss
*bss
;
5161 struct wpa_bss
*bsslast
= NULL
;
5162 struct dl_list
*next
;
5165 char *ctmp
, *end
= buf
+ buflen
;
5166 unsigned long mask
= WPA_BSS_MASK_ALL
;
5168 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
5169 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
5170 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
5172 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
5174 } else { /* N1-N2 */
5175 unsigned int id1
, id2
;
5177 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
5178 wpa_printf(MSG_INFO
, "Wrong BSS range "
5183 if (*(cmd
+ 6) == '-')
5186 id1
= atoi(cmd
+ 6);
5188 if (*ctmp
>= '0' && *ctmp
<= '9')
5191 id2
= (unsigned int) -1;
5192 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
5193 if (id2
== (unsigned int) -1)
5194 bsslast
= dl_list_last(&wpa_s
->bss_id
,
5198 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
5199 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
5200 struct wpa_bss
*tmp
= bss
;
5202 next
= tmp
->list_id
.next
;
5203 if (next
== &wpa_s
->bss_id
)
5205 tmp
= dl_list_entry(
5206 next
, struct wpa_bss
,
5215 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
5216 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5217 else if (os_strncmp(cmd
, "LAST", 4) == 0)
5218 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5219 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
5221 bss
= wpa_bss_get_id(wpa_s
, i
);
5222 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
5224 bss
= wpa_bss_get_id(wpa_s
, i
);
5226 next
= bss
->list_id
.next
;
5227 if (next
== &wpa_s
->bss_id
)
5230 bss
= dl_list_entry(next
, struct wpa_bss
,
5233 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
5234 bss
= wpa_s
->current_bss
;
5236 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
5237 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
5238 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
5241 #endif /* CONFIG_P2P */
5242 } else if (hwaddr_aton(cmd
, bssid
) == 0)
5243 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5245 struct wpa_bss
*tmp
;
5248 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
5258 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
5259 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
5261 mask
= WPA_BSS_MASK_ALL
;
5267 if (bsslast
== NULL
)
5270 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
5274 if (bss
== bsslast
) {
5275 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
5276 (bss
== dl_list_last(&wpa_s
->bss_id
,
5277 struct wpa_bss
, list_id
))) {
5280 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
5282 if (os_snprintf_error(end
- buf
+ 5, res
)) {
5283 wpa_printf(MSG_DEBUG
,
5284 "Could not add end delim");
5289 next
= bss
->list_id
.next
;
5290 if (next
== &wpa_s
->bss_id
)
5292 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
5293 } while (bss
&& len
);
5299 static int wpa_supplicant_ctrl_iface_ap_scan(
5300 struct wpa_supplicant
*wpa_s
, char *cmd
)
5302 int ap_scan
= atoi(cmd
);
5303 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5307 static int wpa_supplicant_ctrl_iface_scan_interval(
5308 struct wpa_supplicant
*wpa_s
, char *cmd
)
5310 int scan_int
= atoi(cmd
);
5311 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5315 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5316 struct wpa_supplicant
*wpa_s
, char *cmd
)
5318 int expire_age
= atoi(cmd
);
5319 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5323 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5324 struct wpa_supplicant
*wpa_s
, char *cmd
)
5326 int expire_count
= atoi(cmd
);
5327 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5331 static void wpa_supplicant_ctrl_iface_bss_flush(
5332 struct wpa_supplicant
*wpa_s
, char *cmd
)
5334 int flush_age
= atoi(cmd
);
5337 wpa_bss_flush(wpa_s
);
5339 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5343 #ifdef CONFIG_TESTING_OPTIONS
5344 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5346 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5347 /* MLME-DELETEKEYS.request */
5348 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
,
5350 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
,
5352 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
,
5354 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
,
5356 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
,
5358 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
,
5361 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5362 0, KEY_FLAG_PAIRWISE
);
5363 /* MLME-SETPROTECTION.request(None) */
5364 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5365 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5366 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5367 wpa_sm_drop_sa(wpa_s
->wpa
);
5369 #endif /* CONFIG_TESTING_OPTIONS */
5372 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5375 #ifdef CONFIG_NO_SCAN_PROCESSING
5377 #else /* CONFIG_NO_SCAN_PROCESSING */
5379 struct wpa_bss
*bss
;
5380 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5382 if (hwaddr_aton(addr
, bssid
)) {
5383 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5384 "address '%s'", addr
);
5388 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5391 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5392 "configuration known for the target AP");
5396 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5398 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5404 * TODO: Find best network configuration block from configuration to
5405 * allow roaming to other networks
5408 wpa_s
->reassociate
= 1;
5409 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5412 #endif /* CONFIG_NO_SCAN_PROCESSING */
5417 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5419 unsigned int timeout
= atoi(cmd
);
5420 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5421 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5422 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5424 unsigned int search_delay
;
5425 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5429 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5430 wpa_dbg(wpa_s
, MSG_INFO
,
5431 "Reject P2P_FIND since interface is disabled");
5434 if (os_strstr(cmd
, "type=social"))
5435 type
= P2P_FIND_ONLY_SOCIAL
;
5436 else if (os_strstr(cmd
, "type=progressive"))
5437 type
= P2P_FIND_PROGRESSIVE
;
5439 pos
= os_strstr(cmd
, "dev_id=");
5442 if (hwaddr_aton(pos
, dev_id
))
5447 pos
= os_strstr(cmd
, "dev_type=");
5450 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5452 _dev_type
= dev_type
;
5455 pos
= os_strstr(cmd
, "delay=");
5458 search_delay
= atoi(pos
);
5460 search_delay
= wpas_p2p_search_delay(wpa_s
);
5462 pos
= os_strstr(cmd
, "freq=");
5470 /* Must be searched for last, because it adds nul termination */
5471 pos
= os_strstr(cmd
, " seek=");
5474 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5477 _seek
[seek_count
++] = pos
;
5479 term
= os_strchr(pos
, ' ');
5483 pos
= os_strstr(term
+ 1, "seek=");
5487 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5492 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5493 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5497 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5499 const char *last
= NULL
;
5504 /* Expected predefined CPT names delimited by ':' */
5505 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5506 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5507 wpa_printf(MSG_ERROR
,
5508 "P2PS: CPT name list is too long, expected up to %d names",
5509 P2PS_FEATURE_CAPAB_CPT_MAX
);
5514 token_len
= last
- token
;
5516 if (token_len
== 3 &&
5517 os_memcmp(token
, "UDP", token_len
) == 0) {
5518 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5519 } else if (token_len
== 3 &&
5520 os_memcmp(token
, "MAC", token_len
) == 0) {
5521 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5523 wpa_printf(MSG_ERROR
,
5524 "P2PS: Unsupported CPT name '%s'", token
);
5529 if (isblank((unsigned char) *last
)) {
5539 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5541 struct p2ps_provision
*p2ps_prov
;
5543 size_t info_len
= 0;
5545 u8 role
= P2PS_SETUP_NONE
;
5546 long long unsigned val
;
5549 pos
= os_strstr(cmd
, "info=");
5552 info_len
= os_strlen(pos
);
5555 info
= os_malloc(info_len
+ 1);
5557 info_len
= utf8_unescape(pos
, info_len
,
5558 info
, info_len
+ 1);
5564 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5565 if (p2ps_prov
== NULL
) {
5571 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5572 p2ps_prov
->info
[info_len
] = '\0';
5576 pos
= os_strstr(cmd
, "status=");
5578 p2ps_prov
->status
= atoi(pos
+ 7);
5580 p2ps_prov
->status
= -1;
5582 pos
= os_strstr(cmd
, "adv_id=");
5583 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5585 p2ps_prov
->adv_id
= val
;
5587 pos
= os_strstr(cmd
, "method=");
5589 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5591 p2ps_prov
->method
= 0;
5593 pos
= os_strstr(cmd
, "session=");
5594 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5596 p2ps_prov
->session_id
= val
;
5598 pos
= os_strstr(cmd
, "adv_mac=");
5599 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5602 pos
= os_strstr(cmd
, "session_mac=");
5603 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5606 pos
= os_strstr(cmd
, "cpt=");
5608 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5609 p2ps_prov
->cpt_priority
))
5612 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5615 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5616 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5618 /* force conncap with tstCap (no sanity checks) */
5619 pos
= os_strstr(cmd
, "tstCap=");
5621 role
= strtol(pos
+ 7, NULL
, 16);
5623 pos
= os_strstr(cmd
, "role=");
5625 role
= strtol(pos
+ 5, NULL
, 16);
5626 if (role
!= P2PS_SETUP_CLIENT
&&
5627 role
!= P2PS_SETUP_GROUP_OWNER
)
5628 role
= P2PS_SETUP_NONE
;
5631 p2ps_prov
->role
= role
;
5641 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5644 struct p2ps_provision
*p2ps_prov
;
5647 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5649 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5651 if (hwaddr_aton(cmd
, addr
))
5658 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5662 if (p2ps_prov
->status
< 0) {
5667 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5672 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5675 struct p2ps_provision
*p2ps_prov
;
5678 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5679 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5682 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5683 if (hwaddr_aton(cmd
, addr
))
5690 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5694 p2ps_prov
->pd_seeker
= 1;
5696 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5701 static int parse_freq(int chwidth
, int freq2
)
5706 return CHANWIDTH_80P80MHZ
;
5712 return CHANWIDTH_USE_HT
;
5714 return CHANWIDTH_80MHZ
;
5716 return CHANWIDTH_160MHZ
;
5718 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5725 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5726 char *buf
, size_t buflen
)
5731 enum p2p_wps_method wps_method
;
5734 int persistent_group
, persistent_id
= -1;
5741 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5743 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5744 size_t group_ssid_len
= 0;
5747 if (!wpa_s
->global
->p2p_init_wpa_s
)
5749 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5750 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5751 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5752 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5755 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5756 * [persistent|persistent=<network id>]
5757 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5758 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
5760 if (hwaddr_aton(cmd
, addr
))
5768 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5769 pos2
= os_strstr(pos
, " persistent=");
5771 struct wpa_ssid
*ssid
;
5772 persistent_id
= atoi(pos2
+ 12);
5773 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5774 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5775 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5776 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5777 "SSID id=%d for persistent P2P group (GO)",
5782 join
= os_strstr(pos
, " join") != NULL
;
5783 auth
= os_strstr(pos
, " auth") != NULL
;
5784 automatic
= os_strstr(pos
, " auto") != NULL
;
5785 pd
= os_strstr(pos
, " provdisc") != NULL
;
5786 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5787 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5789 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
5790 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
5792 pos2
= os_strstr(pos
, " go_intent=");
5795 go_intent
= atoi(pos2
);
5796 if (go_intent
< 0 || go_intent
> 15)
5800 pos2
= os_strstr(pos
, " freq=");
5808 pos2
= os_strstr(pos
, " freq2=");
5810 freq2
= atoi(pos2
+ 7);
5812 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5814 chwidth
= atoi(pos2
+ 18);
5816 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5817 if (max_oper_chwidth
< 0)
5820 pos2
= os_strstr(pos
, " ssid=");
5825 end
= os_strchr(pos2
, ' ');
5827 group_ssid_len
= os_strlen(pos2
) / 2;
5829 group_ssid_len
= (end
- pos2
) / 2;
5830 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5831 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5833 group_ssid
= _group_ssid
;
5836 if (os_strncmp(pos
, "pin", 3) == 0) {
5837 /* Request random PIN (to be displayed) and enable the PIN */
5838 wps_method
= WPS_PIN_DISPLAY
;
5839 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5840 wps_method
= WPS_PBC
;
5841 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5842 wps_method
= WPS_P2PS
;
5845 pos
= os_strchr(pin
, ' ');
5846 wps_method
= WPS_PIN_KEYPAD
;
5849 if (os_strncmp(pos
, "display", 7) == 0)
5850 wps_method
= WPS_PIN_DISPLAY
;
5852 if (!wps_pin_str_valid(pin
)) {
5853 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5858 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5859 persistent_group
, automatic
, join
,
5860 auth
, go_intent
, freq
, freq2
, persistent_id
,
5861 pd
, ht40
, vht
, max_oper_chwidth
, he
, edmg
,
5862 group_ssid
, group_ssid_len
);
5863 if (new_pin
== -2) {
5864 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5867 if (new_pin
== -3) {
5868 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5873 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5874 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5875 if (os_snprintf_error(buflen
, ret
))
5880 os_memcpy(buf
, "OK\n", 3);
5885 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5887 unsigned int timeout
= atoi(cmd
);
5888 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5889 wpa_dbg(wpa_s
, MSG_INFO
,
5890 "Reject P2P_LISTEN since interface is disabled");
5893 return wpas_p2p_listen(wpa_s
, timeout
);
5897 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5901 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5903 /* <addr> <config method> [join|auto] */
5905 if (hwaddr_aton(cmd
, addr
))
5913 if (os_strstr(pos
, " join") != NULL
)
5914 use
= WPAS_P2P_PD_FOR_JOIN
;
5915 else if (os_strstr(pos
, " auto") != NULL
)
5916 use
= WPAS_P2P_PD_AUTO
;
5918 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5922 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5925 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5927 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5928 ssid
->passphrase
== NULL
)
5931 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5932 return os_strlen(buf
);
5936 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5937 char *buf
, size_t buflen
)
5941 u8 dst_buf
[ETH_ALEN
], *dst
;
5942 struct wpabuf
*tlvs
;
5946 if (hwaddr_aton(cmd
, dst_buf
))
5949 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5950 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5957 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5960 if (hexstr2bin(pos
, &version
, 1) < 0)
5966 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5967 #ifdef CONFIG_WIFI_DISPLAY
5968 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5969 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5970 #endif /* CONFIG_WIFI_DISPLAY */
5971 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5973 char *svc_info
= NULL
;
5977 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5980 pos
= os_strchr(pos
, ' ');
5981 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5986 pos
= os_strchr(svc_str
, ' ');
5991 /* All remaining data is the svc_info string */
5992 if (pos
&& pos
[0] && pos
[0] != ' ') {
5993 len
= os_strlen(pos
);
5995 /* Unescape in place */
5996 len
= utf8_unescape(pos
, len
, pos
, len
);
6003 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
6006 len
= os_strlen(pos
);
6010 tlvs
= wpabuf_alloc(len
);
6013 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
6018 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
6023 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
6024 if (os_snprintf_error(buflen
, res
))
6030 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
6033 long long unsigned val
;
6035 if (sscanf(cmd
, "%llx", &val
) != 1)
6038 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
6042 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6047 struct wpabuf
*resp_tlvs
;
6051 pos
= os_strchr(cmd
, ' ');
6059 if (hwaddr_aton(pos
, dst
))
6066 pos2
= os_strchr(pos
, ' ');
6070 dialog_token
= atoi(pos
);
6072 len
= os_strlen(pos2
);
6076 resp_tlvs
= wpabuf_alloc(len
);
6077 if (resp_tlvs
== NULL
)
6079 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
6080 wpabuf_free(resp_tlvs
);
6084 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
6085 wpabuf_free(resp_tlvs
);
6090 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
6093 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
6095 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
6100 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
6105 struct wpabuf
*query
, *resp
;
6107 pos
= os_strchr(cmd
, ' ');
6112 len
= os_strlen(cmd
);
6116 query
= wpabuf_alloc(len
);
6119 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6124 len
= os_strlen(pos
);
6130 resp
= wpabuf_alloc(len
);
6135 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
6141 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
6150 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6155 pos
= os_strchr(cmd
, ' ');
6160 if (hexstr2bin(cmd
, &version
, 1) < 0)
6163 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
6167 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
6168 u8 replace
, char *cmd
)
6172 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
6173 char *svc_info
= NULL
;
6175 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
6177 pos
= os_strchr(cmd
, ' ');
6182 /* Auto-Accept value is mandatory, and must be one of the
6183 * single values (0, 1, 2, 4) */
6184 auto_accept
= atoi(cmd
);
6185 switch (auto_accept
) {
6186 case P2PS_SETUP_NONE
: /* No auto-accept */
6187 case P2PS_SETUP_NEW
:
6188 case P2PS_SETUP_CLIENT
:
6189 case P2PS_SETUP_GROUP_OWNER
:
6195 /* Advertisement ID is mandatory */
6197 pos
= os_strchr(cmd
, ' ');
6202 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6203 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
6206 /* Only allow replacements if exist, and adds if not */
6207 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
6215 /* svc_state between 0 - 0xff is mandatory */
6216 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
6219 pos
= os_strchr(pos
, ' ');
6223 /* config_methods is mandatory */
6225 if (sscanf(pos
, "%x", &config_methods
) != 1)
6228 if (!(config_methods
&
6229 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
6232 pos
= os_strchr(pos
, ' ');
6239 /* Advertisement string is mandatory */
6240 if (!pos
[0] || pos
[0] == ' ')
6243 /* Terminate svc string */
6244 pos
= os_strchr(pos
, ' ');
6248 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
6250 pos
= os_strchr(pos
, ' ');
6254 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
6257 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
6261 /* Service and Response Information are optional */
6262 if (pos
&& pos
[0]) {
6265 /* Note the bare ' included, which cannot exist legally
6266 * in unescaped string. */
6267 svc_info
= os_strstr(pos
, "svc_info='");
6271 len
= os_strlen(svc_info
);
6272 utf8_unescape(svc_info
, len
, svc_info
, len
);
6276 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
6277 (u8
) svc_state
, (u16
) config_methods
,
6278 svc_info
, cpt_prio
);
6282 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6286 pos
= os_strchr(cmd
, ' ');
6291 if (os_strcmp(cmd
, "bonjour") == 0)
6292 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
6293 if (os_strcmp(cmd
, "upnp") == 0)
6294 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
6295 if (os_strcmp(cmd
, "asp") == 0)
6296 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
6297 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6302 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
6306 struct wpabuf
*query
;
6309 len
= os_strlen(cmd
);
6313 query
= wpabuf_alloc(len
);
6316 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6321 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6327 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6332 pos
= os_strchr(cmd
, ' ');
6337 if (hexstr2bin(cmd
, &version
, 1) < 0)
6340 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6344 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6348 if (os_strcmp(cmd
, "all") == 0) {
6349 wpas_p2p_service_flush_asp(wpa_s
);
6353 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6356 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6360 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6364 pos
= os_strchr(cmd
, ' ');
6369 if (os_strcmp(cmd
, "bonjour") == 0)
6370 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6371 if (os_strcmp(cmd
, "upnp") == 0)
6372 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6373 if (os_strcmp(cmd
, "asp") == 0)
6374 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6375 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6380 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6384 pos
= os_strchr(cmd
, ' ');
6389 if (os_strcmp(cmd
, "asp") == 0)
6390 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6392 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6397 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6403 if (hwaddr_aton(cmd
, addr
))
6406 return wpas_p2p_reject(wpa_s
, addr
);
6410 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6414 struct wpa_ssid
*ssid
;
6415 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6416 int freq
= 0, pref_freq
= 0;
6417 int ht40
, vht
, he
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6421 pos
= os_strstr(cmd
, " peer=");
6424 if (hwaddr_aton(pos
, peer
))
6428 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6429 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6430 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6431 "for persistent P2P group",
6436 pos
= os_strstr(cmd
, " freq=");
6444 pos
= os_strstr(cmd
, " pref=");
6447 pref_freq
= atoi(pos
);
6452 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6453 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6455 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
6456 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
6458 pos
= os_strstr(cmd
, "freq2=");
6460 freq2
= atoi(pos
+ 6);
6462 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6464 chwidth
= atoi(pos
+ 18);
6466 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6467 if (max_oper_chwidth
< 0)
6470 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6471 max_oper_chwidth
, pref_freq
, he
, edmg
);
6475 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6478 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6480 pos
= os_strstr(cmd
, " peer=");
6486 if (hwaddr_aton(pos
, peer
)) {
6487 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6491 pos
= os_strstr(pos
, " go_dev_addr=");
6494 if (hwaddr_aton(pos
, go_dev_addr
)) {
6495 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6499 go_dev
= go_dev_addr
;
6502 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6506 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6508 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6509 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6510 if (os_strncmp(cmd
, "group=", 6) == 0)
6511 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6517 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6518 int id
, int freq
, int vht_center_freq2
,
6519 int ht40
, int vht
, int vht_chwidth
,
6522 struct wpa_ssid
*ssid
;
6524 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6525 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6526 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6527 "for persistent P2P group",
6532 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6533 vht_center_freq2
, 0, ht40
, vht
,
6534 vht_chwidth
, he
, edmg
,
6539 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6541 int freq
= 0, persistent
= 0, group_id
= -1;
6542 int vht
= wpa_s
->conf
->p2p_go_vht
;
6543 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6544 int he
= wpa_s
->conf
->p2p_go_he
;
6545 int edmg
= wpa_s
->conf
->p2p_go_edmg
;
6546 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6547 char *token
, *context
= NULL
;
6550 #endif /* CONFIG_ACS */
6552 while ((token
= str_token(cmd
, " ", &context
))) {
6553 if (sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6554 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6555 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6558 } else if (os_strcmp(token
, "freq=acs") == 0) {
6560 #endif /* CONFIG_ACS */
6561 } else if (sscanf(token
, "freq=%d", &freq
) == 1) {
6563 } else if (os_strcmp(token
, "ht40") == 0) {
6565 } else if (os_strcmp(token
, "vht") == 0) {
6568 } else if (os_strcmp(token
, "he") == 0) {
6570 } else if (os_strcmp(token
, "edmg") == 0) {
6572 } else if (os_strcmp(token
, "persistent") == 0) {
6575 wpa_printf(MSG_DEBUG
,
6576 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6583 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_ACS_OFFLOAD
) &&
6584 (acs
|| freq
== 2 || freq
== 5)) {
6585 if (freq
== 2 && wpa_s
->best_24_freq
<= 0) {
6586 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211G
;
6587 wpa_s
->p2p_go_do_acs
= 1;
6589 } else if (freq
== 5 && wpa_s
->best_5_freq
<= 0) {
6590 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211A
;
6591 wpa_s
->p2p_go_do_acs
= 1;
6594 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211ANY
;
6595 wpa_s
->p2p_go_do_acs
= 1;
6598 wpa_s
->p2p_go_do_acs
= 0;
6600 #endif /* CONFIG_ACS */
6602 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6603 if (max_oper_chwidth
< 0)
6607 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6608 freq
, freq2
, ht40
, vht
,
6609 max_oper_chwidth
, he
,
6612 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6613 max_oper_chwidth
, he
, edmg
);
6617 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6618 char *buf
, size_t buflen
)
6620 u8 dev_addr
[ETH_ALEN
];
6621 struct wpa_ssid
*ssid
;
6625 ssid
= wpa_s
->current_ssid
;
6626 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6627 hwaddr_aton(cmd
, dev_addr
))
6630 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6633 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6634 if (os_snprintf_error(buflen
, res
))
6640 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6641 const u8
*p2p_dev_addr
)
6643 struct wpa_supplicant
*wpa_s
;
6645 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6646 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6654 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6655 char *buf
, size_t buflen
)
6657 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6659 const struct p2p_peer_info
*info
;
6661 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6662 struct wpa_ssid
*ssid
;
6665 if (!wpa_s
->global
->p2p
)
6668 if (os_strcmp(cmd
, "FIRST") == 0) {
6671 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6672 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6677 if (hwaddr_aton(cmd
, addr
) < 0)
6683 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6686 group_capab
= info
->group_capab
;
6689 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6690 wpa_printf(MSG_DEBUG
,
6691 "P2P: Could not find any BSS with p2p_dev_addr "
6692 MACSTR
", hence override group_capab from 0x%x to 0",
6693 MAC2STR(info
->p2p_device_addr
), group_capab
);
6700 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6706 "serial_number=%s\n"
6707 "config_methods=0x%x\n"
6709 "group_capab=0x%x\n"
6711 MAC2STR(info
->p2p_device_addr
),
6712 wps_dev_type_bin2str(info
->pri_dev_type
,
6713 devtype
, sizeof(devtype
)),
6718 info
->serial_number
,
6719 info
->config_methods
,
6723 if (os_snprintf_error(end
- pos
, res
))
6727 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6730 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6731 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6732 wps_dev_type_bin2str(t
, devtype
,
6734 if (os_snprintf_error(end
- pos
, res
))
6739 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6741 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6742 if (os_snprintf_error(end
- pos
, res
))
6747 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6752 if (info
->vendor_elems
) {
6753 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6754 if (os_snprintf_error(end
- pos
, res
))
6758 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6759 wpabuf_head(info
->vendor_elems
),
6760 wpabuf_len(info
->vendor_elems
));
6762 res
= os_snprintf(pos
, end
- pos
, "\n");
6763 if (os_snprintf_error(end
- pos
, res
))
6772 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6777 if (wpa_s
->global
->p2p
== NULL
)
6780 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6783 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6784 struct wpa_freq_range
*freq
;
6785 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6786 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6787 freq
->min
, freq
->max
);
6790 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6795 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6799 if (wpa_s
->global
->p2p
== NULL
)
6802 param
= os_strchr(cmd
, ' ');
6807 if (os_strcmp(cmd
, "discoverability") == 0) {
6808 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6813 if (os_strcmp(cmd
, "managed") == 0) {
6814 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6818 if (os_strcmp(cmd
, "listen_channel") == 0) {
6820 u8 channel
, op_class
;
6822 channel
= atoi(param
);
6823 pos
= os_strchr(param
, ' ');
6824 op_class
= pos
? atoi(pos
) : 81;
6826 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6830 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6831 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6835 if (os_strcmp(cmd
, "noa") == 0) {
6837 int count
, start
, duration
;
6838 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6839 count
= atoi(param
);
6840 pos
= os_strchr(param
, ',');
6845 pos
= os_strchr(pos
, ',');
6849 duration
= atoi(pos
);
6850 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6852 if (count
== 0 && duration
> 0)
6854 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6855 "start=%d duration=%d", count
, start
, duration
);
6856 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6859 if (os_strcmp(cmd
, "ps") == 0)
6860 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6862 if (os_strcmp(cmd
, "oppps") == 0)
6863 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6865 if (os_strcmp(cmd
, "ctwindow") == 0)
6866 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6868 if (os_strcmp(cmd
, "disabled") == 0) {
6869 wpa_s
->global
->p2p_disabled
= atoi(param
);
6870 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6871 wpa_s
->global
->p2p_disabled
?
6872 "disabled" : "enabled");
6873 if (wpa_s
->global
->p2p_disabled
) {
6874 wpas_p2p_stop_find(wpa_s
);
6875 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6876 p2p_flush(wpa_s
->global
->p2p
);
6881 if (os_strcmp(cmd
, "conc_pref") == 0) {
6882 if (os_strcmp(param
, "sta") == 0)
6883 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6884 else if (os_strcmp(param
, "p2p") == 0)
6885 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6887 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6890 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6895 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6896 wpa_s
->force_long_sd
= atoi(param
);
6900 if (os_strcmp(cmd
, "peer_filter") == 0) {
6902 if (hwaddr_aton(param
, addr
))
6904 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6908 if (os_strcmp(cmd
, "cross_connect") == 0)
6909 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6911 if (os_strcmp(cmd
, "go_apsd") == 0) {
6912 if (os_strcmp(param
, "disable") == 0)
6913 wpa_s
->set_ap_uapsd
= 0;
6915 wpa_s
->set_ap_uapsd
= 1;
6916 wpa_s
->ap_uapsd
= atoi(param
);
6921 if (os_strcmp(cmd
, "client_apsd") == 0) {
6922 if (os_strcmp(param
, "disable") == 0)
6923 wpa_s
->set_sta_uapsd
= 0;
6927 /* format: BE,BK,VI,VO;max SP Length */
6929 pos
= os_strchr(param
, ',');
6934 pos
= os_strchr(pos
, ',');
6939 pos
= os_strchr(pos
, ',');
6944 /* ignore max SP Length for now */
6946 wpa_s
->set_sta_uapsd
= 1;
6947 wpa_s
->sta_uapsd
= 0;
6949 wpa_s
->sta_uapsd
|= BIT(0);
6951 wpa_s
->sta_uapsd
|= BIT(1);
6953 wpa_s
->sta_uapsd
|= BIT(2);
6955 wpa_s
->sta_uapsd
|= BIT(3);
6960 if (os_strcmp(cmd
, "disallow_freq") == 0)
6961 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6963 if (os_strcmp(cmd
, "disc_int") == 0) {
6964 int min_disc_int
, max_disc_int
, max_disc_tu
;
6969 min_disc_int
= atoi(pos
);
6970 pos
= os_strchr(pos
, ' ');
6975 max_disc_int
= atoi(pos
);
6976 pos
= os_strchr(pos
, ' ');
6981 max_disc_tu
= atoi(pos
);
6983 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6984 max_disc_int
, max_disc_tu
);
6987 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6988 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6992 #ifdef CONFIG_WPS_NFC
6993 if (os_strcmp(cmd
, "nfc_tag") == 0)
6994 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6995 #endif /* CONFIG_WPS_NFC */
6997 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6998 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
7002 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
7005 op_class
= atoi(param
);
7006 param
= os_strchr(param
, ':');
7011 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
7016 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7023 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
7025 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
7026 wpa_s
->force_long_sd
= 0;
7028 #ifdef CONFIG_TESTING_OPTIONS
7029 os_free(wpa_s
->get_pref_freq_list_override
);
7030 wpa_s
->get_pref_freq_list_override
= NULL
;
7031 #endif /* CONFIG_TESTING_OPTIONS */
7033 wpas_p2p_stop_find(wpa_s
);
7034 wpa_s
->parent
->p2ps_method_config_any
= 0;
7035 if (wpa_s
->global
->p2p
)
7036 p2p_flush(wpa_s
->global
->p2p
);
7040 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
7043 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
7046 pos
= os_strchr(cmd
, ' ');
7052 pos2
= os_strchr(pos
, ' ');
7060 pos
= os_strchr(pos2
, ' ');
7068 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
7072 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
7075 unsigned int period
= 0, interval
= 0;
7078 pos
= os_strchr(cmd
, ' ');
7083 interval
= atoi(pos
);
7086 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
7090 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
7097 if (os_strncmp(pos
, "iface=", 6) == 0) {
7101 if (hwaddr_aton(pos
, peer
))
7104 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
7109 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
7111 int freq
= 0, period
= 0, interval
= 0, count
= 0;
7113 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
7115 wpa_printf(MSG_DEBUG
,
7116 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
7120 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
7123 #endif /* CONFIG_P2P */
7126 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
7128 struct wpa_freq_range_list ranges
;
7130 struct hostapd_hw_modes
*mode
;
7133 if (wpa_s
->hw
.modes
== NULL
)
7136 os_memset(&ranges
, 0, sizeof(ranges
));
7137 if (freq_range_list_parse(&ranges
, val
) < 0)
7140 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
7143 mode
= &wpa_s
->hw
.modes
[i
];
7144 for (j
= 0; j
< mode
->num_channels
; j
++) {
7147 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
7150 freq
= mode
->channels
[j
].freq
;
7151 if (!freq_range_list_includes(&ranges
, freq
))
7154 int_array_add_unique(&freqs
, freq
);
7158 os_free(ranges
.range
);
7163 #ifdef CONFIG_INTERWORKING
7165 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
7173 auto_sel
= os_strstr(param
, "auto") != NULL
;
7175 pos
= os_strstr(param
, "freq=");
7177 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
7184 return interworking_select(wpa_s
, auto_sel
, freqs
);
7188 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
7192 struct wpa_bss
*bss
;
7194 if (hwaddr_aton(dst
, bssid
)) {
7195 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
7199 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
7201 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
7206 if (bss
->ssid_len
== 0) {
7209 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
7210 " does not have SSID information", MAC2STR(bssid
));
7212 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
7214 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
7215 bss
->ssid_len
> 0) {
7223 wpa_printf(MSG_DEBUG
,
7224 "Found another matching BSS entry with SSID");
7227 return interworking_connect(wpa_s
, bss
, only_add
);
7231 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7233 u8 dst_addr
[ETH_ALEN
];
7236 #define MAX_ANQP_INFO_ID 100
7237 u16 id
[MAX_ANQP_INFO_ID
];
7240 u32 mbo_subtypes
= 0;
7242 used
= hwaddr_aton2(dst
, dst_addr
);
7248 while (num_id
< MAX_ANQP_INFO_ID
) {
7249 if (os_strncmp(pos
, "hs20:", 5) == 0) {
7251 int num
= atoi(pos
+ 5);
7252 if (num
<= 0 || num
> 31)
7254 subtypes
|= BIT(num
);
7255 #else /* CONFIG_HS20 */
7257 #endif /* CONFIG_HS20 */
7258 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
7260 int num
= atoi(pos
+ 4);
7262 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
7264 mbo_subtypes
|= BIT(num
);
7265 #else /* CONFIG_MBO */
7267 #endif /* CONFIG_MBO */
7269 id
[num_id
] = atoi(pos
);
7273 pos
= os_strchr(pos
+ 1, ',');
7279 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
7282 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
7287 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
7289 u8 dst_addr
[ETH_ALEN
];
7290 struct wpabuf
*advproto
, *query
= NULL
;
7295 used
= hwaddr_aton2(cmd
, dst_addr
);
7303 /* Advertisement Protocol ID */
7304 end
= os_strchr(pos
, ' ');
7308 len
= os_strlen(pos
);
7314 advproto
= wpabuf_alloc(len
);
7315 if (advproto
== NULL
)
7317 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
7321 /* Optional Query Request */
7326 len
= os_strlen(pos
);
7333 query
= wpabuf_alloc(len
);
7336 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
7341 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
7344 wpabuf_free(advproto
);
7351 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7358 size_t resp_len
, start
, requested_len
;
7359 struct wpabuf
*resp
;
7362 used
= hwaddr_aton2(cmd
, addr
);
7369 dialog_token
= atoi(pos
);
7371 if (wpa_s
->last_gas_resp
&&
7372 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7373 dialog_token
== wpa_s
->last_gas_dialog_token
)
7374 resp
= wpa_s
->last_gas_resp
;
7375 else if (wpa_s
->prev_gas_resp
&&
7376 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7377 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7378 resp
= wpa_s
->prev_gas_resp
;
7382 resp_len
= wpabuf_len(resp
);
7384 requested_len
= resp_len
;
7386 pos
= os_strchr(pos
, ' ');
7389 if (start
> resp_len
)
7390 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7391 pos
= os_strchr(pos
, ',');
7395 requested_len
= atoi(pos
);
7396 if (start
+ requested_len
> resp_len
)
7397 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7400 if (requested_len
* 2 + 1 > buflen
)
7401 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7403 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7406 if (start
+ requested_len
== resp_len
) {
7408 * Free memory by dropping the response after it has been
7411 if (resp
== wpa_s
->prev_gas_resp
) {
7412 wpabuf_free(wpa_s
->prev_gas_resp
);
7413 wpa_s
->prev_gas_resp
= NULL
;
7415 wpabuf_free(wpa_s
->last_gas_resp
);
7416 wpa_s
->last_gas_resp
= NULL
;
7422 #endif /* CONFIG_INTERWORKING */
7427 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7429 u8 dst_addr
[ETH_ALEN
];
7434 used
= hwaddr_aton2(dst
, dst_addr
);
7441 int num
= atoi(pos
);
7442 if (num
<= 0 || num
> 31)
7444 subtypes
|= BIT(num
);
7445 pos
= os_strchr(pos
+ 1, ',');
7454 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7458 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7459 const u8
*addr
, const char *realm
)
7465 rlen
= os_strlen(realm
);
7467 buf
= os_malloc(len
);
7470 buf
[0] = 1; /* NAI Home Realm Count */
7471 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7473 os_memcpy(buf
+ 3, realm
, rlen
);
7475 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7476 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7485 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7488 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7489 u8 dst_addr
[ETH_ALEN
];
7495 used
= hwaddr_aton2(dst
, dst_addr
);
7499 while (dst
[used
] == ' ')
7501 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7502 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7505 len
= os_strlen(dst
+ used
);
7507 if (len
== 0 && cred
&& cred
->realm
)
7508 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7513 buf
= os_malloc(len
);
7516 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7521 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7522 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7530 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7533 u8 dst_addr
[ETH_ALEN
];
7535 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7537 used
= hwaddr_aton2(cmd
, dst_addr
);
7542 icon
= str_token(cmd
, " ", &ctx
);
7543 poffset
= str_token(cmd
, " ", &ctx
);
7544 psize
= str_token(cmd
, " ", &ctx
);
7545 if (!icon
|| !poffset
|| !psize
)
7548 wpa_s
->fetch_osu_icon_in_progress
= 0;
7549 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7554 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7556 u8 dst_addr
[ETH_ALEN
];
7561 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7563 used
= hwaddr_aton2(cmd
, dst_addr
);
7567 while (cmd
[used
] == ' ')
7569 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7571 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7575 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7577 u8 dst_addr
[ETH_ALEN
];
7581 used
= hwaddr_aton2(cmd
, dst_addr
);
7585 while (cmd
[used
] == ' ')
7589 wpa_s
->fetch_osu_icon_in_progress
= 0;
7590 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7591 (u8
*) icon
, os_strlen(icon
), inmem
);
7594 #endif /* CONFIG_HS20 */
7597 #ifdef CONFIG_AUTOSCAN
7599 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7602 enum wpa_states state
= wpa_s
->wpa_state
;
7603 char *new_params
= NULL
;
7605 if (os_strlen(cmd
) > 0) {
7606 new_params
= os_strdup(cmd
);
7607 if (new_params
== NULL
)
7611 os_free(wpa_s
->conf
->autoscan
);
7612 wpa_s
->conf
->autoscan
= new_params
;
7614 if (wpa_s
->conf
->autoscan
== NULL
)
7615 autoscan_deinit(wpa_s
);
7616 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7617 autoscan_init(wpa_s
, 1);
7618 else if (state
== WPA_SCANNING
)
7619 wpa_supplicant_reinit_autoscan(wpa_s
);
7621 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7622 wpa_supplicant_state_txt(state
));
7627 #endif /* CONFIG_AUTOSCAN */
7632 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7638 struct wpabuf
*tfs_req
= NULL
;
7640 if (os_strncmp(cmd
, "enter", 5) == 0)
7642 else if (os_strncmp(cmd
, "exit", 4) == 0)
7647 pos
= os_strstr(cmd
, " interval=");
7649 intval
= atoi(pos
+ 10);
7651 pos
= os_strstr(cmd
, " tfs_req=");
7656 end
= os_strchr(pos
, ' ');
7660 len
= os_strlen(pos
);
7664 tfs_req
= wpabuf_alloc(len
);
7665 if (tfs_req
== NULL
)
7667 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7668 wpabuf_free(tfs_req
);
7673 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7674 WNM_SLEEP_MODE_EXIT
, intval
,
7676 wpabuf_free(tfs_req
);
7682 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7684 int query_reason
, list
= 0;
7685 char *btm_candidates
= NULL
;
7687 query_reason
= atoi(cmd
);
7689 cmd
= os_strchr(cmd
, ' ');
7691 if (os_strncmp(cmd
, " list", 5) == 0)
7694 btm_candidates
= cmd
;
7697 wpa_printf(MSG_DEBUG
,
7698 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7699 query_reason
, list
? " candidate list" : "");
7701 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7707 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant
*wpa_s
,
7710 struct wpabuf
*elems
;
7713 elems
= wpabuf_parse_bin(cmd
);
7717 ret
= wnm_send_coloc_intf_report(wpa_s
, 0, elems
);
7722 #endif /* CONFIG_WNM */
7725 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7728 struct wpa_signal_info si
;
7732 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7739 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7740 "NOISE=%d\nFREQUENCY=%u\n",
7741 si
.current_signal
, si
.current_txrate
/ 1000,
7742 si
.current_noise
, si
.frequency
);
7743 if (os_snprintf_error(end
- pos
, ret
))
7747 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7748 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7749 channel_width_to_string(si
.chanwidth
));
7750 if (os_snprintf_error(end
- pos
, ret
))
7755 if (si
.center_frq1
> 0) {
7756 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ1=%d\n",
7758 if (os_snprintf_error(end
- pos
, ret
))
7763 if (si
.center_frq2
> 0) {
7764 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ2=%d\n",
7766 if (os_snprintf_error(end
- pos
, ret
))
7771 if (si
.avg_signal
) {
7772 ret
= os_snprintf(pos
, end
- pos
,
7773 "AVG_RSSI=%d\n", si
.avg_signal
);
7774 if (os_snprintf_error(end
- pos
, ret
))
7779 if (si
.avg_beacon_signal
) {
7780 ret
= os_snprintf(pos
, end
- pos
,
7781 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7782 if (os_snprintf_error(end
- pos
, ret
))
7791 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7798 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7799 wpa_printf(MSG_DEBUG
,
7800 "Reject SIGNAL_MONITOR command - bgscan is active");
7803 pos
= os_strstr(cmd
, "THRESHOLD=");
7805 threshold
= atoi(pos
+ 10);
7806 pos
= os_strstr(cmd
, "HYSTERESIS=");
7808 hysteresis
= atoi(pos
+ 11);
7809 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7813 #ifdef CONFIG_TESTING_OPTIONS
7814 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7815 enum wpa_driver_if_type if_type
,
7817 unsigned int *freq_list
)
7819 char *pos
= wpa_s
->get_pref_freq_list_override
;
7821 unsigned int count
= 0;
7823 /* Override string format:
7824 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7827 if (atoi(pos
) == (int) if_type
)
7829 pos
= os_strchr(pos
, ' ');
7835 pos
= os_strchr(pos
, ':');
7839 end
= os_strchr(pos
, ' ');
7840 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7841 freq_list
[count
++] = atoi(pos
);
7842 pos
= os_strchr(pos
, ',');
7850 #endif /* CONFIG_TESTING_OPTIONS */
7853 static int wpas_ctrl_iface_get_pref_freq_list(
7854 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7856 unsigned int freq_list
[100], num
= 100, i
;
7858 enum wpa_driver_if_type iface_type
;
7864 /* buf: "<interface_type>" */
7865 if (os_strcmp(cmd
, "STATION") == 0)
7866 iface_type
= WPA_IF_STATION
;
7867 else if (os_strcmp(cmd
, "AP") == 0)
7868 iface_type
= WPA_IF_AP_BSS
;
7869 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7870 iface_type
= WPA_IF_P2P_GO
;
7871 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7872 iface_type
= WPA_IF_P2P_CLIENT
;
7873 else if (os_strcmp(cmd
, "IBSS") == 0)
7874 iface_type
= WPA_IF_IBSS
;
7875 else if (os_strcmp(cmd
, "TDLS") == 0)
7876 iface_type
= WPA_IF_TDLS
;
7880 wpa_printf(MSG_DEBUG
,
7881 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7884 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7888 for (i
= 0; i
< num
; i
++) {
7889 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7890 i
> 0 ? "," : "", freq_list
[i
]);
7891 if (os_snprintf_error(end
- pos
, ret
))
7900 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7901 char *buf
, size_t buflen
)
7906 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7907 (long long unsigned) wpa_s
->drv_flags
);
7908 if (os_snprintf_error(buflen
, ret
))
7914 for (i
= 0; i
< 64; i
++) {
7915 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7916 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7917 driver_flag_to_string(1LLU << i
));
7918 if (os_snprintf_error(end
- pos
, ret
))
7928 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7931 struct hostap_sta_driver_data sta
;
7934 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7938 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7939 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7940 if (os_snprintf_error(buflen
, ret
))
7947 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7948 char *buf
, size_t buflen
)
7952 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7954 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7955 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7958 country
[0] = cmd
[8];
7959 country
[1] = cmd
[9];
7961 p2p_set_country(p2p
, country
);
7964 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7965 if (os_snprintf_error(buflen
, ret
))
7970 #endif /* ANDROID */
7973 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7974 char *buf
, size_t buflen
)
7979 unsigned int vendor_id
, subcmd
;
7980 struct wpabuf
*reply
;
7981 size_t data_len
= 0;
7983 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7984 vendor_id
= strtoul(cmd
, &pos
, 16);
7985 if (!isblank((unsigned char) *pos
))
7988 subcmd
= strtoul(pos
, &pos
, 10);
7991 if (!isblank((unsigned char) *pos
++))
7993 data_len
= os_strlen(pos
);
7998 data
= os_malloc(data_len
);
8002 if (hexstr2bin(pos
, data
, data_len
)) {
8003 wpa_printf(MSG_DEBUG
,
8004 "Vendor command: wrong parameter format");
8010 reply
= wpabuf_alloc((buflen
- 1) / 2);
8016 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
8020 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
8030 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
8033 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
8034 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
8035 #endif /* CONFIG_P2P */
8037 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
8039 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
8040 wpa_s
->ignore_post_flush_scan_res
= 1;
8042 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
8044 * Avoid possible auto connect re-connection on getting
8045 * disconnected due to state flush.
8047 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
8051 wpas_p2p_group_remove(p2p_wpa_s
, "*");
8052 wpas_p2p_cancel(p2p_wpa_s
);
8053 p2p_ctrl_flush(p2p_wpa_s
);
8054 wpas_p2p_service_flush(p2p_wpa_s
);
8055 p2p_wpa_s
->global
->p2p_disabled
= 0;
8056 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
8057 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
8058 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
8059 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
8060 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
8061 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
8062 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
8063 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
8064 #endif /* CONFIG_P2P */
8066 #ifdef CONFIG_WPS_TESTING
8067 wps_version_number
= 0x20;
8068 wps_testing_dummy_cred
= 0;
8069 wps_corrupt_pkhash
= 0;
8070 wps_force_auth_types_in_use
= 0;
8071 wps_force_encr_types_in_use
= 0;
8072 #endif /* CONFIG_WPS_TESTING */
8074 wpa_s
->wps_fragment_size
= 0;
8075 wpas_wps_cancel(wpa_s
);
8076 wps_registrar_flush(wpa_s
->wps
->registrar
);
8077 #endif /* CONFIG_WPS */
8078 wpa_s
->after_wps
= 0;
8079 wpa_s
->known_wps_freq
= 0;
8082 wpas_dpp_deinit(wpa_s
);
8083 wpa_s
->dpp_init_max_tries
= 0;
8084 wpa_s
->dpp_init_retry_time
= 0;
8085 wpa_s
->dpp_resp_wait_time
= 0;
8086 wpa_s
->dpp_resp_max_tries
= 0;
8087 wpa_s
->dpp_resp_retry_time
= 0;
8088 #ifdef CONFIG_TESTING_OPTIONS
8089 os_memset(dpp_pkex_own_mac_override
, 0, ETH_ALEN
);
8090 os_memset(dpp_pkex_peer_mac_override
, 0, ETH_ALEN
);
8091 dpp_pkex_ephemeral_key_override_len
= 0;
8092 dpp_protocol_key_override_len
= 0;
8093 dpp_nonce_override_len
= 0;
8094 #endif /* CONFIG_TESTING_OPTIONS */
8095 #endif /* CONFIG_DPP */
8098 #ifdef CONFIG_TDLS_TESTING
8100 #endif /* CONFIG_TDLS_TESTING */
8101 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
8102 wpa_tdls_enable(wpa_s
->wpa
, 1);
8103 #endif /* CONFIG_TDLS */
8105 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
8106 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
8107 wpa_s
->last_michael_mic_error
.sec
= 0;
8109 wpa_s
->no_keep_alive
= 0;
8110 wpa_s
->own_disconnect_req
= 0;
8112 os_free(wpa_s
->disallow_aps_bssid
);
8113 wpa_s
->disallow_aps_bssid
= NULL
;
8114 wpa_s
->disallow_aps_bssid_count
= 0;
8115 os_free(wpa_s
->disallow_aps_ssid
);
8116 wpa_s
->disallow_aps_ssid
= NULL
;
8117 wpa_s
->disallow_aps_ssid_count
= 0;
8119 wpa_s
->set_sta_uapsd
= 0;
8120 wpa_s
->sta_uapsd
= 0;
8122 wpa_drv_radio_disable(wpa_s
, 0);
8123 wpa_blacklist_clear(wpa_s
);
8124 wpa_s
->extra_blacklist_count
= 0;
8125 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
8126 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
8127 wpa_config_flush_blobs(wpa_s
->conf
);
8128 wpa_s
->conf
->auto_interworking
= 0;
8129 wpa_s
->conf
->okc
= 0;
8131 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
8132 rsn_preauth_deinit(wpa_s
->wpa
);
8134 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
8135 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
8136 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
8137 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
8139 radio_remove_works(wpa_s
, NULL
, 1);
8140 wpa_s
->ext_work_in_progress
= 0;
8142 wpa_s
->next_ssid
= NULL
;
8144 #ifdef CONFIG_INTERWORKING
8146 hs20_cancel_fetch_osu(wpa_s
);
8147 hs20_del_icon(wpa_s
, NULL
, NULL
);
8148 #endif /* CONFIG_HS20 */
8149 #endif /* CONFIG_INTERWORKING */
8151 wpa_s
->ext_mgmt_frame_handling
= 0;
8152 wpa_s
->ext_eapol_frame_io
= 0;
8153 #ifdef CONFIG_TESTING_OPTIONS
8154 wpa_s
->extra_roc_dur
= 0;
8155 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
8156 wpa_s
->p2p_go_csa_on_inv
= 0;
8157 wpa_s
->ignore_auth_resp
= 0;
8158 wpa_s
->ignore_assoc_disallow
= 0;
8159 wpa_s
->testing_resend_assoc
= 0;
8160 wpa_s
->ignore_sae_h2e_only
= 0;
8161 wpa_s
->reject_btm_req_reason
= 0;
8162 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
8163 os_free(wpa_s
->get_pref_freq_list_override
);
8164 wpa_s
->get_pref_freq_list_override
= NULL
;
8165 wpabuf_free(wpa_s
->sae_commit_override
);
8166 wpa_s
->sae_commit_override
= NULL
;
8167 os_free(wpa_s
->extra_sae_rejected_groups
);
8168 wpa_s
->extra_sae_rejected_groups
= NULL
;
8169 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
8170 wpa_s
->rsnxe_override_assoc
= NULL
;
8171 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
8172 wpa_s
->rsnxe_override_eapol
= NULL
;
8173 wpas_clear_driver_signal_override(wpa_s
);
8175 os_free(wpa_s
->dpp_config_obj_override
);
8176 wpa_s
->dpp_config_obj_override
= NULL
;
8177 os_free(wpa_s
->dpp_discovery_override
);
8178 wpa_s
->dpp_discovery_override
= NULL
;
8179 os_free(wpa_s
->dpp_groups_override
);
8180 wpa_s
->dpp_groups_override
= NULL
;
8181 dpp_test
= DPP_TEST_DISABLED
;
8182 #endif /* CONFIG_DPP */
8183 #endif /* CONFIG_TESTING_OPTIONS */
8185 wpa_s
->disconnected
= 0;
8186 os_free(wpa_s
->next_scan_freqs
);
8187 wpa_s
->next_scan_freqs
= NULL
;
8188 os_free(wpa_s
->select_network_scan_freqs
);
8189 wpa_s
->select_network_scan_freqs
= NULL
;
8191 wpa_bss_flush(wpa_s
);
8192 if (!dl_list_empty(&wpa_s
->bss
)) {
8193 wpa_printf(MSG_DEBUG
,
8194 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8195 MACSTR
" pending_bssid=" MACSTR
,
8196 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
8197 MAC2STR(wpa_s
->bssid
),
8198 MAC2STR(wpa_s
->pending_bssid
));
8201 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
8202 wpa_s
->wnmsleep_used
= 0;
8205 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
8206 wpa_s
->sme
.auth_alg
= 0;
8207 #endif /* CONFIG_SME */
8209 wpabuf_free(wpa_s
->ric_ies
);
8210 wpa_s
->ric_ies
= NULL
;
8212 wpa_supplicant_update_channel_list(wpa_s
, NULL
);
8214 free_bss_tmp_disallowed(wpa_s
);
8218 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
8219 char *buf
, size_t buflen
)
8221 struct wpa_radio_work
*work
;
8223 struct os_reltime now
, diff
;
8228 os_get_reltime(&now
);
8230 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8234 os_reltime_sub(&now
, &work
->time
, &diff
);
8235 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
8236 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
8237 work
->started
, diff
.sec
, diff
.usec
);
8238 if (os_snprintf_error(end
- pos
, ret
))
8247 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
8249 struct wpa_radio_work
*work
= eloop_ctx
;
8250 struct wpa_external_work
*ework
= work
->ctx
;
8252 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
8253 "Timing out external radio work %u (%s)",
8254 ework
->id
, work
->type
);
8255 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
8256 work
->wpa_s
->ext_work_in_progress
= 0;
8257 radio_work_done(work
);
8262 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
8264 struct wpa_external_work
*ework
= work
->ctx
;
8268 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8272 * work->type points to a buffer in ework, so need to replace
8273 * that here with a fixed string to avoid use of freed memory
8276 work
->type
= "freed-ext-work";
8282 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
8283 ework
->id
, ework
->type
);
8284 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
8285 work
->wpa_s
->ext_work_in_progress
= 1;
8286 if (!ework
->timeout
)
8287 ework
->timeout
= 10;
8288 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
8293 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
8294 char *buf
, size_t buflen
)
8296 struct wpa_external_work
*ework
;
8300 unsigned int freq
= 0;
8302 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8304 ework
= os_zalloc(sizeof(*ework
));
8308 pos
= os_strchr(cmd
, ' ');
8310 type_len
= pos
- cmd
;
8313 pos2
= os_strstr(pos
, "freq=");
8315 freq
= atoi(pos2
+ 5);
8317 pos2
= os_strstr(pos
, "timeout=");
8319 ework
->timeout
= atoi(pos2
+ 8);
8321 type_len
= os_strlen(cmd
);
8323 if (4 + type_len
>= sizeof(ework
->type
))
8324 type_len
= sizeof(ework
->type
) - 4 - 1;
8325 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
8326 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
8327 ework
->type
[4 + type_len
] = '\0';
8329 wpa_s
->ext_work_id
++;
8330 if (wpa_s
->ext_work_id
== 0)
8331 wpa_s
->ext_work_id
++;
8332 ework
->id
= wpa_s
->ext_work_id
;
8334 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
8340 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
8341 if (os_snprintf_error(buflen
, ret
))
8347 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
8349 struct wpa_radio_work
*work
;
8350 unsigned int id
= atoi(cmd
);
8352 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8354 struct wpa_external_work
*ework
;
8356 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8359 if (id
&& ework
->id
!= id
)
8361 wpa_dbg(wpa_s
, MSG_DEBUG
,
8362 "Completed external radio work %u (%s)",
8363 ework
->id
, ework
->type
);
8364 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
8365 wpa_s
->ext_work_in_progress
= 0;
8366 radio_work_done(work
);
8368 return 3; /* "OK\n" */
8375 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
8376 char *buf
, size_t buflen
)
8378 if (os_strcmp(cmd
, "show") == 0)
8379 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
8380 if (os_strncmp(cmd
, "add ", 4) == 0)
8381 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
8382 if (os_strncmp(cmd
, "done ", 5) == 0)
8383 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
8388 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
8390 struct wpa_radio_work
*work
, *tmp
;
8392 if (!wpa_s
|| !wpa_s
->radio
)
8395 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
8396 struct wpa_radio_work
, list
) {
8397 struct wpa_external_work
*ework
;
8399 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8402 wpa_dbg(wpa_s
, MSG_DEBUG
,
8403 "Flushing%s external radio work %u (%s)",
8404 work
->started
? " started" : "", ework
->id
,
8407 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8409 radio_work_done(work
);
8415 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8417 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8418 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8422 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8423 unsigned int *scan_id_count
, int scan_id
[])
8425 const char *pos
= value
;
8428 if (*pos
== ' ' || *pos
== '\0')
8430 if (*scan_id_count
== MAX_SCAN_ID
)
8432 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8433 pos
= os_strchr(pos
, ',');
8442 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8443 char *reply
, int reply_size
, int *reply_len
)
8446 unsigned int manual_scan_passive
= 0;
8447 unsigned int manual_scan_use_id
= 0;
8448 unsigned int manual_scan_only_new
= 0;
8449 unsigned int scan_only
= 0;
8450 unsigned int scan_id_count
= 0;
8451 int scan_id
[MAX_SCAN_ID
];
8452 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8453 struct wpa_scan_results
*scan_res
);
8454 int *manual_scan_freqs
= NULL
;
8455 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8456 unsigned int ssid_count
= 0;
8458 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8463 if (radio_work_pending(wpa_s
, "scan")) {
8464 wpa_printf(MSG_DEBUG
,
8465 "Pending scan scheduled - reject new request");
8466 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8470 #ifdef CONFIG_INTERWORKING
8471 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8472 wpa_printf(MSG_DEBUG
,
8473 "Interworking select in progress - reject new scan");
8474 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8477 #endif /* CONFIG_INTERWORKING */
8480 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8483 pos
= os_strstr(params
, "freq=");
8485 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8487 if (manual_scan_freqs
== NULL
) {
8493 pos
= os_strstr(params
, "passive=");
8495 manual_scan_passive
= !!atoi(pos
+ 8);
8497 pos
= os_strstr(params
, "use_id=");
8499 manual_scan_use_id
= atoi(pos
+ 7);
8501 pos
= os_strstr(params
, "only_new=1");
8503 manual_scan_only_new
= 1;
8505 pos
= os_strstr(params
, "scan_id=");
8506 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8512 pos
= os_strstr(params
, "bssid=");
8517 if (hwaddr_aton(pos
, bssid
)) {
8518 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8522 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8526 while (pos
&& *pos
!= '\0') {
8527 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8533 if (*end
== '\0' || *end
== ' ')
8538 ns
= os_realloc_array(
8539 ssid
, ssid_count
+ 1,
8540 sizeof(struct wpa_ssid_value
));
8547 if ((end
- pos
) & 0x01 ||
8548 end
- pos
> 2 * SSID_MAX_LEN
||
8549 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8550 (end
- pos
) / 2) < 0) {
8551 wpa_printf(MSG_DEBUG
,
8552 "Invalid SSID value '%s'",
8557 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8558 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8559 ssid
[ssid_count
].ssid
,
8560 ssid
[ssid_count
].ssid_len
);
8565 pos
= os_strchr(pos
, ' ');
8571 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8572 os_free(wpa_s
->ssids_from_scan_req
);
8574 wpa_s
->ssids_from_scan_req
= ssid
;
8577 wpa_s
->ssids_from_scan_req
= NULL
;
8581 scan_res_handler
= scan_only_handler
;
8582 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8583 scan_res_handler
= NULL
;
8585 scan_res_handler
= wpa_s
->scan_res_handler
;
8587 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8588 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8589 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8590 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8591 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8592 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8593 wpa_s
->scan_id_count
= scan_id_count
;
8594 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8595 wpa_s
->scan_res_handler
= scan_res_handler
;
8596 os_free(wpa_s
->manual_scan_freqs
);
8597 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8598 manual_scan_freqs
= NULL
;
8600 wpa_s
->normal_scans
= 0;
8601 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8602 wpa_s
->after_wps
= 0;
8603 wpa_s
->known_wps_freq
= 0;
8604 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8605 if (wpa_s
->manual_scan_use_id
) {
8606 wpa_s
->manual_scan_id
++;
8607 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8608 wpa_s
->manual_scan_id
);
8609 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8610 wpa_s
->manual_scan_id
);
8612 } else if (wpa_s
->sched_scanning
) {
8613 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8614 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8615 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8616 wpa_s
->scan_id_count
= scan_id_count
;
8617 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8618 wpa_s
->scan_res_handler
= scan_res_handler
;
8619 os_free(wpa_s
->manual_scan_freqs
);
8620 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8621 manual_scan_freqs
= NULL
;
8623 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8624 wpa_supplicant_cancel_sched_scan(wpa_s
);
8625 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8626 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8627 if (wpa_s
->manual_scan_use_id
) {
8628 wpa_s
->manual_scan_id
++;
8629 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8630 wpa_s
->manual_scan_id
);
8631 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8632 wpa_s
->manual_scan_id
);
8635 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8636 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8640 os_free(manual_scan_freqs
);
8645 #ifdef CONFIG_TESTING_OPTIONS
8647 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8648 unsigned int freq
, const u8
*dst
,
8649 const u8
*src
, const u8
*bssid
,
8650 const u8
*data
, size_t data_len
,
8651 enum offchannel_send_action_result
8654 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8655 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8656 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8657 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8658 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8659 "NO_ACK" : "FAILED"));
8663 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8667 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8669 int freq
= 0, no_cck
= 0, wait_time
= 0;
8671 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8672 * <action=Action frame payload> */
8674 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8677 used
= hwaddr_aton2(pos
, da
);
8683 used
= hwaddr_aton2(pos
, bssid
);
8688 param
= os_strstr(pos
, " freq=");
8694 param
= os_strstr(pos
, " no_cck=");
8697 no_cck
= atoi(param
);
8700 param
= os_strstr(pos
, " wait_time=");
8703 wait_time
= atoi(param
);
8706 param
= os_strstr(pos
, " action=");
8711 len
= os_strlen(param
);
8716 buf
= os_malloc(len
);
8720 if (hexstr2bin(param
, buf
, len
) < 0) {
8725 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8726 buf
, len
, wait_time
,
8727 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8733 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8735 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8736 offchannel_send_action_done(wpa_s
);
8740 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8746 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8747 union wpa_event_data event
;
8749 if (!wpa_s
->ext_mgmt_frame_handling
)
8752 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8754 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8757 param
= os_strstr(pos
, "freq=");
8763 param
= os_strstr(pos
, " datarate=");
8766 datarate
= atoi(param
);
8769 param
= os_strstr(pos
, " ssi_signal=");
8772 ssi_signal
= atoi(param
);
8775 param
= os_strstr(pos
, " frame=");
8780 len
= os_strlen(param
);
8785 buf
= os_malloc(len
);
8789 if (hexstr2bin(param
, buf
, len
) < 0) {
8794 os_memset(&event
, 0, sizeof(event
));
8795 event
.rx_mgmt
.freq
= freq
;
8796 event
.rx_mgmt
.frame
= buf
;
8797 event
.rx_mgmt
.frame_len
= len
;
8798 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8799 event
.rx_mgmt
.datarate
= datarate
;
8800 wpa_s
->ext_mgmt_frame_handling
= 0;
8801 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8802 wpa_s
->ext_mgmt_frame_handling
= 1;
8810 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8813 struct wpa_scan_res
*res
;
8814 struct os_reltime now
;
8821 if (os_strcmp(param
, "START") == 0) {
8822 wpa_bss_update_start(wpa_s
);
8826 if (os_strcmp(param
, "END") == 0) {
8827 wpa_bss_update_end(wpa_s
, NULL
, 1);
8831 if (os_strncmp(param
, "BSS ", 4) != 0)
8835 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8839 pos
= os_strstr(param
, " flags=");
8841 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8843 pos
= os_strstr(param
, " bssid=");
8844 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8847 pos
= os_strstr(param
, " freq=");
8849 res
->freq
= atoi(pos
+ 6);
8851 pos
= os_strstr(param
, " beacon_int=");
8853 res
->beacon_int
= atoi(pos
+ 12);
8855 pos
= os_strstr(param
, " caps=");
8857 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8859 pos
= os_strstr(param
, " qual=");
8861 res
->qual
= atoi(pos
+ 6);
8863 pos
= os_strstr(param
, " noise=");
8865 res
->noise
= atoi(pos
+ 7);
8867 pos
= os_strstr(param
, " level=");
8869 res
->level
= atoi(pos
+ 7);
8871 pos
= os_strstr(param
, " tsf=");
8873 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8875 pos
= os_strstr(param
, " age=");
8877 res
->age
= atoi(pos
+ 5);
8879 pos
= os_strstr(param
, " est_throughput=");
8881 res
->est_throughput
= atoi(pos
+ 16);
8883 pos
= os_strstr(param
, " snr=");
8885 res
->snr
= atoi(pos
+ 5);
8887 pos
= os_strstr(param
, " parent_tsf=");
8889 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8891 pos
= os_strstr(param
, " tsf_bssid=");
8892 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8895 pos
= os_strstr(param
, " ie=");
8898 end
= os_strchr(pos
, ' ');
8900 end
= pos
+ os_strlen(pos
);
8901 res
->ie_len
= (end
- pos
) / 2;
8902 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8906 pos
= os_strstr(param
, " beacon_ie=");
8909 end
= os_strchr(pos
, ' ');
8911 end
= pos
+ os_strlen(pos
);
8912 res
->beacon_ie_len
= (end
- pos
) / 2;
8913 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8914 res
->beacon_ie_len
))
8918 os_get_reltime(&now
);
8919 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8928 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8931 union wpa_event_data event
;
8932 enum wpa_event_type ev
;
8934 /* <event name> [parameters..] */
8936 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8939 param
= os_strchr(pos
, ' ');
8943 os_memset(&event
, 0, sizeof(event
));
8945 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8946 ev
= EVENT_INTERFACE_ENABLED
;
8947 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8948 ev
= EVENT_INTERFACE_DISABLED
;
8949 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8950 ev
= EVENT_AVOID_FREQUENCIES
;
8953 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8955 wpa_supplicant_event(wpa_s
, ev
, &event
);
8956 os_free(event
.freq_range
.range
);
8958 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8959 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8961 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8966 wpa_supplicant_event(wpa_s
, ev
, &event
);
8972 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8975 u8 src
[ETH_ALEN
], *buf
;
8979 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8982 used
= hwaddr_aton2(pos
, src
);
8989 len
= os_strlen(pos
);
8994 buf
= os_malloc(len
);
8998 if (hexstr2bin(pos
, buf
, len
) < 0) {
9003 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
9010 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
9014 const u16
*pos
= buf
;
9016 for (i
= 0; i
< len
/ 2; i
++)
9020 sum
= (sum
& 0xffff) + (sum
>> 16);
9022 return sum
^ 0xffff;
9026 #define HWSIM_PACKETLEN 1500
9027 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9029 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
9032 struct wpa_supplicant
*wpa_s
= ctx
;
9033 const struct ether_header
*eth
;
9039 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
9040 wpa_printf(MSG_DEBUG
,
9041 "test data: RX - ignore unexpected length %d",
9046 eth
= (const struct ether_header
*) buf
;
9047 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
9048 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
9050 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 || ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
9051 wpa_printf(MSG_DEBUG
,
9052 "test data: RX - ignore unexpect IP header");
9056 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
9057 if (*pos
!= (u8
) i
) {
9058 wpa_printf(MSG_DEBUG
,
9059 "test data: RX - ignore mismatching payload");
9065 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
9066 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
9067 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
9068 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
9072 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
9075 int enabled
= atoi(cmd
);
9080 if (wpa_s
->l2_test
) {
9081 l2_packet_deinit(wpa_s
->l2_test
);
9082 wpa_s
->l2_test
= NULL
;
9083 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
9091 pos
= os_strstr(cmd
, " ifname=");
9095 ifname
= wpa_s
->ifname
;
9097 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
9098 ETHERTYPE_IP
, wpas_data_test_rx
,
9100 if (wpa_s
->l2_test
== NULL
)
9103 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
9109 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
9111 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
9116 u8 buf
[2 + HWSIM_PACKETLEN
];
9117 struct ether_header
*eth
;
9121 size_t send_len
= HWSIM_IP_LEN
;
9123 if (wpa_s
->l2_test
== NULL
)
9126 /* format: <dst> <src> <tos> [len=<length>] */
9129 used
= hwaddr_aton2(pos
, dst
);
9135 used
= hwaddr_aton2(pos
, src
);
9140 val
= strtol(pos
, &pos2
, 0);
9141 if (val
< 0 || val
> 0xff)
9145 pos
= os_strstr(pos2
, " len=");
9148 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
9153 eth
= (struct ether_header
*) &buf
[2];
9154 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
9155 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
9156 eth
->ether_type
= htons(ETHERTYPE_IP
);
9157 ip
= (struct ip
*) (eth
+ 1);
9158 os_memset(ip
, 0, sizeof(*ip
));
9163 ip
->ip_len
= htons(send_len
);
9165 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9166 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9167 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
9168 dpos
= (u8
*) (ip
+ 1);
9169 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
9172 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
9173 sizeof(struct ether_header
) + send_len
) < 0)
9176 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
9177 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
9183 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
9187 struct ether_header
*eth
;
9188 struct l2_packet_data
*l2
= NULL
;
9193 len
= os_strlen(cmd
);
9194 if (len
& 1 || len
< ETH_HLEN
* 2)
9198 buf
= os_malloc(len
);
9202 if (hexstr2bin(cmd
, buf
, len
) < 0)
9205 eth
= (struct ether_header
*) buf
;
9206 ethertype
= ntohs(eth
->ether_type
);
9208 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
9209 wpas_data_test_rx
, wpa_s
, 1);
9213 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
9214 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
9217 l2_packet_deinit(l2
);
9220 return res
< 0 ? -1 : 0;
9224 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9226 #ifdef WPA_TRACE_BFD
9229 wpa_trace_fail_after
= atoi(cmd
);
9230 pos
= os_strchr(cmd
, ':');
9233 os_strlcpy(wpa_trace_fail_func
, pos
,
9234 sizeof(wpa_trace_fail_func
));
9236 wpa_trace_fail_after
= 0;
9239 #else /* WPA_TRACE_BFD */
9241 #endif /* WPA_TRACE_BFD */
9245 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
9246 char *buf
, size_t buflen
)
9248 #ifdef WPA_TRACE_BFD
9249 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
9250 wpa_trace_fail_func
);
9251 #else /* WPA_TRACE_BFD */
9253 #endif /* WPA_TRACE_BFD */
9257 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9259 #ifdef WPA_TRACE_BFD
9262 wpa_trace_test_fail_after
= atoi(cmd
);
9263 pos
= os_strchr(cmd
, ':');
9266 os_strlcpy(wpa_trace_test_fail_func
, pos
,
9267 sizeof(wpa_trace_test_fail_func
));
9269 wpa_trace_test_fail_after
= 0;
9272 #else /* WPA_TRACE_BFD */
9274 #endif /* WPA_TRACE_BFD */
9278 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
9279 char *buf
, size_t buflen
)
9281 #ifdef WPA_TRACE_BFD
9282 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
9283 wpa_trace_test_fail_func
);
9284 #else /* WPA_TRACE_BFD */
9286 #endif /* WPA_TRACE_BFD */
9290 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
9292 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9293 int i
, count
= (intptr_t) timeout_ctx
;
9295 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
9297 for (i
= 0; i
< count
; i
++) {
9298 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
9304 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9312 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
9313 (void *) (intptr_t) count
);
9317 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
9323 len
= os_strlen(cmd
);
9331 buf
= wpabuf_alloc(len
);
9335 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
9341 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
9346 static int wpas_ctrl_reset_pn(struct wpa_supplicant
*wpa_s
)
9348 u8 zero
[WPA_TK_MAX_LEN
];
9350 if (wpa_s
->last_tk_alg
== WPA_ALG_NONE
)
9353 wpa_printf(MSG_INFO
, "TESTING: Reset PN");
9354 os_memset(zero
, 0, sizeof(zero
));
9356 /* First, use a zero key to avoid any possible duplicate key avoidance
9358 if (wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9359 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9360 zero
, wpa_s
->last_tk_len
,
9361 KEY_FLAG_PAIRWISE_RX_TX
) < 0)
9364 /* Set the previously configured key to reset its TSC/RSC */
9365 return wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9366 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9367 wpa_s
->last_tk
, wpa_s
->last_tk_len
,
9368 KEY_FLAG_PAIRWISE_RX_TX
);
9372 static int wpas_ctrl_key_request(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9374 const char *pos
= cmd
;
9375 int error
, pairwise
;
9378 pos
= os_strchr(pos
, ' ');
9381 pairwise
= atoi(pos
);
9382 wpa_sm_key_request(wpa_s
->wpa
, error
, pairwise
);
9387 static int wpas_ctrl_resend_assoc(struct wpa_supplicant
*wpa_s
)
9390 struct wpa_driver_associate_params params
;
9393 os_memset(¶ms
, 0, sizeof(params
));
9394 params
.bssid
= wpa_s
->bssid
;
9395 params
.ssid
= wpa_s
->sme
.ssid
;
9396 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
9397 params
.freq
.freq
= wpa_s
->sme
.freq
;
9398 if (wpa_s
->last_assoc_req_wpa_ie
) {
9399 params
.wpa_ie
= wpabuf_head(wpa_s
->last_assoc_req_wpa_ie
);
9400 params
.wpa_ie_len
= wpabuf_len(wpa_s
->last_assoc_req_wpa_ie
);
9402 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
9403 params
.group_suite
= wpa_s
->group_cipher
;
9404 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
9405 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
9406 params
.wpa_proto
= wpa_s
->wpa_proto
;
9407 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
9408 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
9409 if (wpa_s
->sme
.prev_bssid_set
)
9410 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
9411 wpa_printf(MSG_INFO
, "TESTING: Resend association request");
9412 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
9413 wpa_s
->testing_resend_assoc
= 1;
9415 #else /* CONFIG_SME */
9417 #endif /* CONFIG_SME */
9420 #endif /* CONFIG_TESTING_OPTIONS */
9423 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
9429 struct ieee802_11_elems elems
;
9432 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9434 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9436 pos
= os_strchr(pos
, ' ');
9441 len
= os_strlen(pos
);
9448 buf
= wpabuf_alloc(len
);
9452 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
9457 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
9463 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
9464 wpa_s
->vendor_elem
[frame
] = buf
;
9465 wpas_vendor_elem_update(wpa_s
);
9469 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
9474 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
9476 wpas_vendor_elem_update(wpa_s
);
9482 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
9483 char *buf
, size_t buflen
)
9485 int frame
= atoi(cmd
);
9487 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9489 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9491 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9494 return wpa_snprintf_hex(buf
, buflen
,
9495 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
9496 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
9500 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
9506 struct ieee802_11_elems elems
;
9510 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9512 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9514 pos
= os_strchr(pos
, ' ');
9520 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9521 wpa_s
->vendor_elem
[frame
] = NULL
;
9522 wpas_vendor_elem_update(wpa_s
);
9526 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9529 len
= os_strlen(pos
);
9536 buf
= os_malloc(len
);
9540 if (hexstr2bin(pos
, buf
, len
) < 0) {
9545 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9550 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9556 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9558 struct wpa_supplicant
*wpa_s
= ctx
;
9563 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9565 * BSSID Information[4]
9566 * Operating Class[1]
9569 * Optional Subelements[variable]
9571 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9573 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9574 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9578 data
= wpabuf_head_u8(neighbor_rep
);
9579 len
= wpabuf_len(neighbor_rep
);
9581 while (len
>= 2 + NR_IE_MIN_LEN
) {
9583 char lci
[256 * 2 + 1];
9584 char civic
[256 * 2 + 1];
9585 u8 nr_len
= data
[1];
9586 const u8
*pos
= data
, *end
;
9588 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9589 nr_len
< NR_IE_MIN_LEN
) {
9590 wpa_dbg(wpa_s
, MSG_DEBUG
,
9591 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9596 if (2U + nr_len
> len
) {
9597 wpa_dbg(wpa_s
, MSG_DEBUG
,
9598 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9599 data
[0], len
, nr_len
);
9606 pos
+= NR_IE_MIN_LEN
;
9610 while (end
- pos
> 2) {
9615 if (s_len
> end
- pos
)
9617 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9618 /* Measurement Token[1] */
9619 /* Measurement Report Mode[1] */
9620 /* Measurement Type[1] */
9621 /* Measurement Report[variable] */
9623 case MEASURE_TYPE_LCI
:
9626 wpa_snprintf_hex(lci
, sizeof(lci
),
9629 case MEASURE_TYPE_LOCATION_CIVIC
:
9632 wpa_snprintf_hex(civic
, sizeof(civic
),
9641 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9643 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9644 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9645 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9647 lci
[0] ? " lci=" : "", lci
,
9648 civic
[0] ? " civic=" : "", civic
);
9655 wpabuf_free(neighbor_rep
);
9659 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9662 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9663 int ret
, lci
= 0, civic
= 0;
9666 ssid_s
= os_strstr(cmd
, "ssid=");
9668 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9669 wpa_msg(wpa_s
, MSG_INFO
,
9670 "CTRL: Send Neighbor Report: bad SSID");
9677 * Move cmd after the SSID text that may include "lci" or
9680 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9686 if (cmd
&& os_strstr(cmd
, "lci"))
9689 if (cmd
&& os_strstr(cmd
, "civic"))
9692 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9693 wpas_ctrl_neighbor_rep_cb
,
9700 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9702 eapol_sm_erp_flush(wpa_s
->eapol
);
9707 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9710 char *token
, *context
= NULL
;
9711 unsigned int enable
= ~0, type
= 0;
9712 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9713 u8
*addr
= NULL
, *mask
= NULL
;
9715 while ((token
= str_token(cmd
, " ", &context
))) {
9716 if (os_strcasecmp(token
, "scan") == 0) {
9717 type
|= MAC_ADDR_RAND_SCAN
;
9718 } else if (os_strcasecmp(token
, "sched") == 0) {
9719 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9720 } else if (os_strcasecmp(token
, "pno") == 0) {
9721 type
|= MAC_ADDR_RAND_PNO
;
9722 } else if (os_strcasecmp(token
, "all") == 0) {
9723 type
= wpa_s
->mac_addr_rand_supported
;
9724 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9725 enable
= atoi(token
+ 7);
9726 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9728 if (hwaddr_aton(token
+ 5, addr
)) {
9729 wpa_printf(MSG_INFO
,
9730 "CTRL: Invalid MAC address: %s",
9734 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9736 if (hwaddr_aton(token
+ 5, mask
)) {
9737 wpa_printf(MSG_INFO
,
9738 "CTRL: Invalid MAC address mask: %s",
9743 wpa_printf(MSG_INFO
,
9744 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9751 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9756 wpa_printf(MSG_INFO
,
9757 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9762 return wpas_disable_mac_addr_randomization(wpa_s
, type
);
9764 return wpas_enable_mac_addr_randomization(wpa_s
, type
, addr
, mask
);
9768 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9769 char *buf
, size_t buflen
)
9773 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9775 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9776 buflen
- reply_len
);
9777 #endif /* CONFIG_AP */
9782 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9784 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9786 wpas_ap_pmksa_cache_flush(wpa_s
);
9787 #endif /* CONFIG_AP */
9791 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9793 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9794 const char *cmd
, char *buf
, size_t buflen
)
9796 struct rsn_pmksa_cache_entry
*entry
;
9797 struct wpa_ssid
*ssid
;
9798 char *pos
, *pos2
, *end
;
9800 struct os_reltime now
;
9802 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9809 os_get_reltime(&now
);
9813 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9814 * <expiration in seconds> <akmp> <opportunistic>
9815 * [FILS Cache Identifier]
9818 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9819 entry
= entry
->next
) {
9820 if (entry
->network_ctx
!= ssid
)
9824 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9825 MAC2STR(entry
->aa
));
9826 if (os_snprintf_error(end
- pos2
, ret
))
9830 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9833 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9834 if (os_snprintf_error(end
- pos2
, ret
))
9838 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9841 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9842 (int) (entry
->reauth_time
- now
.sec
),
9843 (int) (entry
->expiration
- now
.sec
),
9845 entry
->opportunistic
);
9846 if (os_snprintf_error(end
- pos2
, ret
))
9850 if (entry
->fils_cache_id_set
) {
9851 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9852 entry
->fils_cache_id
[0],
9853 entry
->fils_cache_id
[1]);
9854 if (os_snprintf_error(end
- pos2
, ret
))
9859 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9860 if (os_snprintf_error(end
- pos2
, ret
))
9871 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9874 struct rsn_pmksa_cache_entry
*entry
;
9875 struct wpa_ssid
*ssid
;
9878 struct os_reltime now
;
9879 int reauth_time
= 0, expiration
= 0, i
;
9883 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9884 * <expiration in seconds> <akmp> <opportunistic>
9885 * [FILS Cache Identifier]
9888 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9892 pos
= os_strchr(cmd
, ' ');
9897 entry
= os_zalloc(sizeof(*entry
));
9901 if (hwaddr_aton(pos
, entry
->aa
))
9904 pos
= os_strchr(pos
, ' ');
9909 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9912 pos
= os_strchr(pos
, ' ');
9917 pos2
= os_strchr(pos
, ' ');
9920 entry
->pmk_len
= (pos2
- pos
) / 2;
9921 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9922 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9925 pos
= os_strchr(pos
, ' ');
9930 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9931 &entry
->akmp
, &entry
->opportunistic
) != 4)
9933 for (i
= 0; i
< 4; i
++) {
9934 pos
= os_strchr(pos
, ' ');
9943 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9944 FILS_CACHE_ID_LEN
) < 0)
9946 entry
->fils_cache_id_set
= 1;
9948 os_get_reltime(&now
);
9949 entry
->expiration
= now
.sec
+ expiration
;
9950 entry
->reauth_time
= now
.sec
+ reauth_time
;
9952 entry
->network_ctx
= ssid
;
9954 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9965 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9966 const char *cmd
, char *buf
,
9974 if (os_strcasecmp(cmd
, "any") == 0)
9975 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9977 if (hwaddr_aton(cmd
, spa
))
9980 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9984 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9988 * We do not check mesh interface existance because PMKSA should be
9989 * stored before wpa_s->ifmsh creation to suppress commit message
9992 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9995 #endif /* CONFIG_MESH */
9996 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10000 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
10003 struct fils_hlp_req
*req
;
10006 /* format: <dst> <packet starting from ethertype> */
10008 req
= os_zalloc(sizeof(*req
));
10012 if (hwaddr_aton(cmd
, req
->dst
))
10015 pos
= os_strchr(cmd
, ' ');
10019 req
->pkt
= wpabuf_parse_bin(pos
);
10023 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
10026 wpabuf_free(req
->pkt
);
10030 #endif /* CONFIG_FILS */
10033 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
10035 if (os_strcmp(cmd
, "PING") == 0 ||
10036 os_strncmp(cmd
, "BSS ", 4) == 0 ||
10037 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
10038 os_strncmp(cmd
, "STATUS", 6) == 0 ||
10039 os_strncmp(cmd
, "STA ", 4) == 0 ||
10040 os_strncmp(cmd
, "STA-", 4) == 0)
10041 return MSG_EXCESSIVE
;
10046 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
10047 char *buf
, size_t *resp_len
)
10050 const int reply_size
= 4096;
10053 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
10054 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
10055 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
10056 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10057 if (wpa_debug_show_keys
)
10058 wpa_dbg(wpa_s
, MSG_DEBUG
,
10059 "Control interface command '%s'", buf
);
10061 wpa_dbg(wpa_s
, MSG_DEBUG
,
10062 "Control interface command '%s [REMOVED]'",
10063 os_strncmp(buf
, WPA_CTRL_RSP
,
10064 os_strlen(WPA_CTRL_RSP
)) == 0 ?
10066 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
10067 "SET_NETWORK" : "key-add"));
10068 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
10069 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
10070 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
10071 (const u8
*) buf
, os_strlen(buf
));
10073 int level
= wpas_ctrl_cmd_debug_level(buf
);
10074 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
10077 reply
= os_malloc(reply_size
);
10078 if (reply
== NULL
) {
10083 os_memcpy(reply
, "OK\n", 3);
10086 if (os_strcmp(buf
, "PING") == 0) {
10087 os_memcpy(reply
, "PONG\n", 5);
10089 } else if (os_strcmp(buf
, "IFNAME") == 0) {
10090 reply_len
= os_strlen(wpa_s
->ifname
);
10091 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
10092 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10093 if (wpa_debug_reopen_file() < 0)
10095 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
10096 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
10097 } else if (os_strcmp(buf
, "MIB") == 0) {
10098 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
10099 if (reply_len
>= 0) {
10100 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
10102 reply_size
- reply_len
);
10103 #ifdef CONFIG_MACSEC
10104 reply_len
+= ieee802_1x_kay_get_mib(
10105 wpa_s
->kay
, reply
+ reply_len
,
10106 reply_size
- reply_len
);
10107 #endif /* CONFIG_MACSEC */
10109 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
10110 reply_len
= wpa_supplicant_ctrl_iface_status(
10111 wpa_s
, buf
+ 6, reply
, reply_size
);
10112 } else if (os_strcmp(buf
, "PMKSA") == 0) {
10113 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
10114 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
10115 wpas_ctrl_iface_pmksa_flush(wpa_s
);
10116 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10117 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
10118 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
10119 reply
, reply_size
);
10120 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
10121 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
10124 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
10125 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
10126 reply
, reply_size
);
10127 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10128 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
10130 #endif /* CONFIG_MESH */
10131 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10132 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10133 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
10135 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
10136 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
10137 reply
, reply_size
);
10138 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
10139 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
10140 reply
, reply_size
);
10141 } else if (os_strcmp(buf
, "LOGON") == 0) {
10142 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
10143 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
10144 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
10145 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
10146 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10149 wpas_request_connection(wpa_s
);
10150 } else if (os_strcmp(buf
, "REATTACH") == 0) {
10151 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
10152 !wpa_s
->current_ssid
)
10155 wpa_s
->reattach
= 1;
10156 wpas_request_connection(wpa_s
);
10158 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
10159 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10161 else if (wpa_s
->disconnected
)
10162 wpas_request_connection(wpa_s
);
10163 #ifdef IEEE8021X_EAPOL
10164 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
10165 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
10167 #endif /* IEEE8021X_EAPOL */
10168 #ifdef CONFIG_IEEE80211R
10169 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
10170 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
10172 #endif /* CONFIG_IEEE80211R */
10174 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
10175 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
10177 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10181 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
10182 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
10184 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10188 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
10189 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
10192 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
10193 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
10194 wpa_s
, buf
+ 14, reply
, reply_size
);
10195 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
10196 if (wpas_wps_cancel(wpa_s
))
10198 #ifdef CONFIG_WPS_NFC
10199 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
10200 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
10202 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
10203 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
10205 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10206 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10207 wpa_s
, buf
+ 21, reply
, reply_size
);
10208 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
10209 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
10210 wpa_s
, buf
+ 14, reply
, reply_size
);
10211 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
10212 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
10215 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10216 reply_len
= wpas_ctrl_nfc_get_handover_req(
10217 wpa_s
, buf
+ 21, reply
, reply_size
);
10218 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10219 reply_len
= wpas_ctrl_nfc_get_handover_sel(
10220 wpa_s
, buf
+ 21, reply
, reply_size
);
10221 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
10222 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
10224 #endif /* CONFIG_WPS_NFC */
10225 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
10226 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
10229 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
10230 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
10231 wpa_s
, buf
+ 11, reply
, reply_size
);
10232 #endif /* CONFIG_AP */
10233 #ifdef CONFIG_WPS_ER
10234 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
10235 if (wpas_wps_er_start(wpa_s
, NULL
))
10237 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
10238 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
10240 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
10241 wpas_wps_er_stop(wpa_s
);
10242 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
10243 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
10245 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
10246 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
10248 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10250 } else if (ret
== -3) {
10251 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
10253 } else if (ret
== -4) {
10254 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
10258 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
10259 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
10261 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
10262 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
10265 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
10266 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
10268 #ifdef CONFIG_WPS_NFC
10269 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10270 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10271 wpa_s
, buf
+ 24, reply
, reply_size
);
10272 #endif /* CONFIG_WPS_NFC */
10273 #endif /* CONFIG_WPS_ER */
10274 #endif /* CONFIG_WPS */
10275 #ifdef CONFIG_IBSS_RSN
10276 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
10277 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
10279 #endif /* CONFIG_IBSS_RSN */
10281 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
10282 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10283 wpa_s
, buf
+ 19, reply
, reply_size
);
10284 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
10285 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10286 wpa_s
, "", reply
, reply_size
);
10287 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
10288 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
10290 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
10291 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
10294 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
10295 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
10297 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
10298 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
10300 } else if (os_strncmp(buf
, "MESH_LINK_PROBE ", 16) == 0) {
10301 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s
, buf
+ 16))
10303 #endif /* CONFIG_MESH */
10305 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
10306 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
10308 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
10309 if (p2p_ctrl_find(wpa_s
, ""))
10311 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
10312 wpas_p2p_stop_find(wpa_s
);
10313 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
10314 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
10316 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10317 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
10319 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
10320 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
10322 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
10323 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
10325 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
10326 if (p2p_ctrl_listen(wpa_s
, ""))
10328 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
10329 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
10331 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
10332 if (p2p_ctrl_group_add(wpa_s
, ""))
10334 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
10335 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
10337 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
10338 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
10340 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
10341 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
10343 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
10344 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
10345 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
10346 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
10348 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10349 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
10351 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
10352 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
10354 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
10355 wpas_p2p_sd_service_update(wpa_s
);
10356 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10357 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
10359 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
10360 wpas_p2p_service_flush(wpa_s
);
10361 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
10362 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
10364 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
10365 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
10367 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
10368 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
10370 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
10371 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
10373 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
10374 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
10376 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
10377 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
10379 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
10380 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
10382 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
10383 p2p_ctrl_flush(wpa_s
);
10384 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
10385 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
10387 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
10388 if (wpas_p2p_cancel(wpa_s
))
10390 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
10391 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
10393 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
10394 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
10396 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
10397 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
10399 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
10400 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
10402 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
10403 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
10405 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
10406 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
10408 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
10409 if (wpas_p2p_lo_stop(wpa_s
))
10411 #endif /* CONFIG_P2P */
10412 #ifdef CONFIG_WIFI_DISPLAY
10413 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
10414 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
10416 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
10417 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
10418 reply
, reply_size
);
10419 #endif /* CONFIG_WIFI_DISPLAY */
10420 #ifdef CONFIG_INTERWORKING
10421 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
10422 if (interworking_fetch_anqp(wpa_s
) < 0)
10424 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
10425 interworking_stop_fetch_anqp(wpa_s
);
10426 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
10427 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
10429 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
10430 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
10432 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
10433 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
10435 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10438 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
10442 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
10443 if (os_snprintf_error(reply_size
, reply_len
))
10446 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
10447 if (get_anqp(wpa_s
, buf
+ 9) < 0)
10449 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
10450 if (gas_request(wpa_s
, buf
+ 12) < 0)
10452 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
10453 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
10455 #endif /* CONFIG_INTERWORKING */
10457 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10458 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10460 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10461 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10463 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10464 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10466 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10467 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10469 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10470 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10471 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10472 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10474 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10475 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10477 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10478 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10480 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10481 hs20_cancel_fetch_osu(wpa_s
);
10482 #endif /* CONFIG_HS20 */
10483 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10485 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10486 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10490 * Notify response from timeout to allow the control
10491 * interface response to be sent first.
10493 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10496 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10497 if (wpa_supplicant_reload_configuration(wpa_s
))
10499 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10500 wpa_supplicant_terminate_proc(wpa_s
->global
);
10501 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10502 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10504 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10505 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10506 wpa_s
, buf
+ 9, reply
, reply_size
);
10507 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10508 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10509 wpa_s
, buf
+ 9, reply
, reply_size
);
10510 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10511 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10512 wpa_s
, buf
+ 14, reply
, reply_size
);
10513 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10514 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10515 wpa_s
, NULL
, reply
, reply_size
);
10516 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10517 wpas_request_disconnection(wpa_s
);
10518 } else if (os_strcmp(buf
, "SCAN") == 0) {
10519 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10520 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10521 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10522 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10523 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10524 wpa_s
, reply
, reply_size
);
10525 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10526 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10528 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10529 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10531 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10532 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10534 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10535 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10537 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10538 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10539 wpa_s
, reply
, reply_size
);
10540 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10541 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10543 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10544 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10546 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10547 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10548 wpa_s
, buf
+ 12, reply
, reply_size
);
10549 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10550 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10553 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10554 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10555 wpa_s
, reply
, reply_size
);
10556 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10557 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10558 wpa_s
, reply
, reply_size
);
10559 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10560 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10562 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10563 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10565 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10566 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10569 #ifndef CONFIG_NO_CONFIG_WRITE
10570 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10571 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10573 #endif /* CONFIG_NO_CONFIG_WRITE */
10574 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10575 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10576 wpa_s
, buf
+ 15, reply
, reply_size
);
10577 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10578 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10580 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10581 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10583 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10584 reply_len
= wpa_supplicant_global_iface_list(
10585 wpa_s
->global
, reply
, reply_size
);
10586 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10587 reply_len
= wpa_supplicant_global_iface_interfaces(
10588 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10589 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10590 reply_len
= wpa_supplicant_ctrl_iface_bss(
10591 wpa_s
, buf
+ 4, reply
, reply_size
);
10593 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10594 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10595 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10596 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10598 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10599 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10601 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10602 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10604 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10605 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10607 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10608 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10610 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10611 if (wpas_ap_stop_ap(wpa_s
))
10613 #endif /* CONFIG_AP */
10614 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10615 wpas_notify_suspend(wpa_s
->global
);
10616 } else if (os_strcmp(buf
, "RESUME") == 0) {
10617 wpas_notify_resume(wpa_s
->global
);
10618 #ifdef CONFIG_TESTING_OPTIONS
10619 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10620 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10621 #endif /* CONFIG_TESTING_OPTIONS */
10622 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10623 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10625 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10626 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10627 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10628 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10630 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10631 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10634 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10635 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10637 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10638 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10640 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10641 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10643 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10644 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10646 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10647 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10650 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10651 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10654 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10655 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10656 wpa_s
, buf
+ 17, reply
, reply_size
);
10657 #endif /* CONFIG_TDLS */
10658 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10659 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10660 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10661 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10663 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10664 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10666 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10667 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10669 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10670 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10672 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10673 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10675 #ifdef CONFIG_AUTOSCAN
10676 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10677 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10679 #endif /* CONFIG_AUTOSCAN */
10680 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10681 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10684 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10685 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10687 #endif /* ANDROID */
10688 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10689 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10691 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10692 pmksa_cache_clear_current(wpa_s
->wpa
);
10693 eapol_sm_request_reauth(wpa_s
->eapol
);
10695 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10696 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10698 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10699 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10701 } else if (os_strncmp(buf
, "COLOC_INTF_REPORT ", 18) == 0) {
10702 if (wpas_ctrl_iface_coloc_intf_report(wpa_s
, buf
+ 18))
10704 #endif /* CONFIG_WNM */
10705 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10706 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10707 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10708 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10710 #ifdef CONFIG_TESTING_OPTIONS
10711 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10712 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10714 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10715 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10716 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10717 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10719 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10720 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10722 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10723 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10725 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10726 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10728 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10729 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10731 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10732 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10734 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10735 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10737 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10738 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10739 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10740 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10742 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10743 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10744 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10745 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10747 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10748 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10750 } else if (os_strcmp(buf
, "RESET_PN") == 0) {
10751 if (wpas_ctrl_reset_pn(wpa_s
) < 0)
10753 } else if (os_strncmp(buf
, "KEY_REQUEST ", 12) == 0) {
10754 if (wpas_ctrl_key_request(wpa_s
, buf
+ 12) < 0)
10756 } else if (os_strcmp(buf
, "RESEND_ASSOC") == 0) {
10757 if (wpas_ctrl_resend_assoc(wpa_s
) < 0)
10759 } else if (os_strcmp(buf
, "UNPROT_DEAUTH") == 0) {
10760 sme_event_unprot_disconnect(
10761 wpa_s
, wpa_s
->bssid
, NULL
,
10762 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
10763 #endif /* CONFIG_TESTING_OPTIONS */
10764 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10765 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10767 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10768 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10770 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10771 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10773 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10774 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10776 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10777 wpas_ctrl_iface_erp_flush(wpa_s
);
10778 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10779 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10781 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10782 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10783 wpa_s
, buf
+ 19, reply
, reply_size
);
10785 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10786 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10788 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10789 wpas_flush_fils_hlp_req(wpa_s
);
10790 #endif /* CONFIG_FILS */
10792 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10795 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10799 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10800 if (os_snprintf_error(reply_size
, reply_len
))
10803 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
10806 res
= wpas_dpp_nfc_uri(wpa_s
, buf
+ 12);
10810 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10811 if (os_snprintf_error(reply_size
, reply_len
))
10814 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
10817 res
= wpas_dpp_nfc_handover_req(wpa_s
, buf
+ 20);
10821 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10822 if (os_snprintf_error(reply_size
, reply_len
))
10825 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
10828 res
= wpas_dpp_nfc_handover_sel(wpa_s
, buf
+ 20);
10832 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10833 if (os_snprintf_error(reply_size
, reply_len
))
10836 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10839 res
= dpp_bootstrap_gen(wpa_s
->dpp
, buf
+ 18);
10843 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10844 if (os_snprintf_error(reply_size
, reply_len
))
10847 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10848 if (dpp_bootstrap_remove(wpa_s
->dpp
, buf
+ 21) < 0)
10850 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10853 uri
= dpp_bootstrap_get_uri(wpa_s
->dpp
, atoi(buf
+ 22));
10857 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10858 if (os_snprintf_error(reply_size
, reply_len
))
10861 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10862 reply_len
= dpp_bootstrap_info(wpa_s
->dpp
, atoi(buf
+ 19),
10863 reply
, reply_size
);
10864 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10865 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10867 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10868 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10870 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10871 wpas_dpp_stop(wpa_s
);
10872 wpas_dpp_listen_stop(wpa_s
);
10873 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10876 res
= dpp_configurator_add(wpa_s
->dpp
, buf
+ 20);
10880 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10881 if (os_snprintf_error(reply_size
, reply_len
))
10884 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10885 if (dpp_configurator_remove(wpa_s
->dpp
, buf
+ 24) < 0)
10887 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10888 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 21) < 0)
10890 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10891 reply_len
= dpp_configurator_get_key_id(wpa_s
->dpp
,
10893 reply
, reply_size
);
10894 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10897 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
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_PKEX_REMOVE ", 16) == 0) {
10906 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10909 } else if (os_strncmp(buf
, "DPP_CONTROLLER_START ", 21) == 0) {
10910 if (wpas_dpp_controller_start(wpa_s
, buf
+ 20) < 0)
10912 } else if (os_strcmp(buf
, "DPP_CONTROLLER_START") == 0) {
10913 if (wpas_dpp_controller_start(wpa_s
, NULL
) < 0)
10915 } else if (os_strcmp(buf
, "DPP_CONTROLLER_STOP") == 0) {
10916 dpp_controller_stop(wpa_s
->dpp
);
10917 #endif /* CONFIG_DPP2 */
10918 #endif /* CONFIG_DPP */
10920 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10924 if (reply_len
< 0) {
10925 os_memcpy(reply
, "FAIL\n", 5);
10929 *resp_len
= reply_len
;
10934 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10937 struct wpa_interface iface
;
10939 struct wpa_supplicant
*wpa_s
;
10940 unsigned int create_iface
= 0;
10941 u8 mac_addr
[ETH_ALEN
];
10942 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10945 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10946 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10948 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10950 os_memset(&iface
, 0, sizeof(iface
));
10953 iface
.ifname
= pos
= cmd
;
10954 pos
= os_strchr(pos
, '\t');
10957 if (iface
.ifname
[0] == '\0')
10962 iface
.confname
= pos
;
10963 pos
= os_strchr(pos
, '\t');
10966 if (iface
.confname
[0] == '\0')
10967 iface
.confname
= NULL
;
10971 iface
.driver
= pos
;
10972 pos
= os_strchr(pos
, '\t');
10975 if (iface
.driver
[0] == '\0')
10976 iface
.driver
= NULL
;
10980 iface
.ctrl_interface
= pos
;
10981 pos
= os_strchr(pos
, '\t');
10984 if (iface
.ctrl_interface
[0] == '\0')
10985 iface
.ctrl_interface
= NULL
;
10989 iface
.driver_param
= pos
;
10990 pos
= os_strchr(pos
, '\t');
10993 if (iface
.driver_param
[0] == '\0')
10994 iface
.driver_param
= NULL
;
10998 iface
.bridge_ifname
= pos
;
10999 pos
= os_strchr(pos
, '\t');
11002 if (iface
.bridge_ifname
[0] == '\0')
11003 iface
.bridge_ifname
= NULL
;
11008 pos
= os_strchr(pos
, '\t');
11014 if (os_strcmp(extra
, "create") == 0) {
11019 if (os_strcmp(pos
, "sta") == 0) {
11020 type
= WPA_IF_STATION
;
11021 } else if (os_strcmp(pos
, "ap") == 0) {
11022 type
= WPA_IF_AP_BSS
;
11024 wpa_printf(MSG_DEBUG
,
11025 "INTERFACE_ADD unsupported interface type: '%s'",
11030 wpa_printf(MSG_DEBUG
,
11031 "INTERFACE_ADD unsupported extra parameter: '%s'",
11037 if (create_iface
) {
11038 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
11040 if (!global
->ifaces
)
11042 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
11043 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
11044 wpa_printf(MSG_ERROR
,
11045 "CTRL_IFACE interface creation failed");
11049 wpa_printf(MSG_DEBUG
,
11050 "CTRL_IFACE interface '%s' created with MAC addr: "
11051 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
11054 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
11057 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
11060 wpa_s
->added_vif
= create_iface
;
11065 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
11070 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
11073 struct wpa_supplicant
*wpa_s
;
11075 unsigned int delete_iface
;
11077 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
11079 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
11082 delete_iface
= wpa_s
->added_vif
;
11083 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
11084 if (!ret
&& delete_iface
) {
11085 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
11087 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
11093 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
11095 struct wpa_interface_info
*prev
;
11099 iface
= iface
->next
;
11101 os_free(prev
->ifname
);
11102 os_free(prev
->desc
);
11108 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
11109 char *buf
, int len
)
11112 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
11115 for (i
= 0; wpa_drivers
[i
]; i
++) {
11116 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
11117 if (drv
->get_interfaces
== NULL
)
11119 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
11124 iface
= last
= tmp
;
11133 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
11134 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
11135 tmp
->drv_name
, tmp
->ifname
,
11136 tmp
->desc
? tmp
->desc
: "");
11137 if (os_snprintf_error(end
- pos
, res
)) {
11144 wpa_free_iface_info(iface
);
11150 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
11152 char *buf
, int len
)
11156 struct wpa_supplicant
*wpa_s
;
11160 show_ctrl
= !!os_strstr(input
, "ctrl");
11162 wpa_s
= global
->ifaces
;
11168 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
11170 wpa_s
->conf
->ctrl_interface
?
11171 wpa_s
->conf
->ctrl_interface
: "N/A");
11173 res
= os_snprintf(pos
, end
- pos
, "%s\n",
11176 if (os_snprintf_error(end
- pos
, res
)) {
11181 wpa_s
= wpa_s
->next
;
11187 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
11188 const char *ifname
,
11189 char *cmd
, size_t *resp_len
)
11191 struct wpa_supplicant
*wpa_s
;
11193 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11194 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
11198 if (wpa_s
== NULL
) {
11199 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
11201 *resp_len
= os_strlen(resp
);
11207 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
11211 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
11212 char *buf
, size_t *resp_len
)
11215 static const char * cmd
[] = {
11221 "P2P_GET_PASSPHRASE",
11222 "P2P_SERVICE_UPDATE",
11223 "P2P_SERVICE_FLUSH",
11226 "P2P_PRESENCE_REQ",
11230 #endif /* CONFIG_AP */
11233 static const char * prefix
[] = {
11236 #endif /* ANDROID */
11243 "P2P_GROUP_REMOVE ",
11245 "P2P_GROUP_MEMBER ",
11247 "P2P_SERV_DISC_REQ ",
11248 "P2P_SERV_DISC_CANCEL_REQ ",
11249 "P2P_SERV_DISC_RESP ",
11250 "P2P_SERV_DISC_EXTERNAL ",
11251 "P2P_SERVICE_ADD ",
11252 "P2P_SERVICE_DEL ",
11253 "P2P_SERVICE_REP ",
11258 "P2P_UNAUTHORIZE ",
11259 "P2P_PRESENCE_REQ ",
11261 "P2P_REMOVE_CLIENT ",
11263 "WPS_NFC_TAG_READ ",
11264 "NFC_GET_HANDOVER_SEL ",
11265 "NFC_GET_HANDOVER_REQ ",
11266 "NFC_REPORT_HANDOVER ",
11267 "P2P_ASP_PROVISION ",
11268 "P2P_ASP_PROVISION_RESP ",
11272 #endif /* CONFIG_AP */
11278 if (global
->p2p_init_wpa_s
== NULL
)
11281 for (i
= 0; !found
&& cmd
[i
]; i
++) {
11282 if (os_strcmp(buf
, cmd
[i
]) == 0)
11286 for (i
= 0; !found
&& prefix
[i
]; i
++) {
11287 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
11292 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11294 #endif /* CONFIG_P2P */
11299 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
11300 char *buf
, size_t *resp_len
)
11302 #ifdef CONFIG_WIFI_DISPLAY
11303 if (global
->p2p_init_wpa_s
== NULL
)
11305 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
11306 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
11307 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11309 #endif /* CONFIG_WIFI_DISPLAY */
11314 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
11315 char *buf
, size_t *resp_len
)
11319 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
11323 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
11331 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
11335 value
= os_strchr(cmd
, ' ');
11340 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
11342 #ifdef CONFIG_WIFI_DISPLAY
11343 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
11344 wifi_display_enable(global
, !!atoi(value
));
11347 #endif /* CONFIG_WIFI_DISPLAY */
11349 /* Restore cmd to its original value to allow redirection */
11356 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
11359 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
11363 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11364 * <variable name> */
11366 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
11367 p
= os_strchr(cmd
, ' ');
11372 wpa_s
[i
] = global
->ifaces
;
11373 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
11374 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
11379 wpa_printf(MSG_DEBUG
,
11380 "CTRL_IFACE: Could not find iface=%s", cmd
);
11387 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
11391 #ifndef CONFIG_NO_CONFIG_WRITE
11392 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
11394 int ret
= 0, saved
= 0;
11395 struct wpa_supplicant
*wpa_s
;
11397 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11398 if (!wpa_s
->conf
->update_config
) {
11399 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11403 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
11404 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11407 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11412 if (!saved
&& !ret
) {
11413 wpa_dbg(wpa_s
, MSG_DEBUG
,
11414 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11420 #endif /* CONFIG_NO_CONFIG_WRITE */
11423 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
11424 char *buf
, size_t buflen
)
11428 struct wpa_supplicant
*wpa_s
;
11431 end
= buf
+ buflen
;
11434 if (global
->p2p
&& !global
->p2p_disabled
) {
11435 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
11438 MAC2STR(global
->p2p_dev_addr
),
11439 p2p_get_state_txt(global
->p2p
));
11440 if (os_snprintf_error(end
- pos
, ret
))
11443 } else if (global
->p2p
) {
11444 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
11445 if (os_snprintf_error(end
- pos
, ret
))
11449 #endif /* CONFIG_P2P */
11451 #ifdef CONFIG_WIFI_DISPLAY
11452 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
11453 !!global
->wifi_display
);
11454 if (os_snprintf_error(end
- pos
, ret
))
11457 #endif /* CONFIG_WIFI_DISPLAY */
11459 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11460 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
11461 "address=" MACSTR
"\n",
11462 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
11463 if (os_snprintf_error(end
- pos
, ret
))
11474 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
11475 char *cmd
, char *buf
,
11478 char ifname
[IFNAMSIZ
+ 1];
11479 struct fst_iface_cfg cfg
;
11480 struct wpa_supplicant
*wpa_s
;
11481 struct fst_wpa_obj iface_obj
;
11483 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
11484 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11487 wpa_printf(MSG_INFO
, "FST: Already attached");
11490 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
11491 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
11494 return os_snprintf(buf
, reply_size
, "OK\n");
11502 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
11503 char *cmd
, char *buf
,
11506 char ifname
[IFNAMSIZ
+ 1];
11507 struct wpa_supplicant
*wpa_s
;
11509 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
11510 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11512 if (!fst_iface_detach(ifname
)) {
11514 return os_snprintf(buf
, reply_size
, "OK\n");
11522 #endif /* CONFIG_FST */
11525 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11526 char *buf
, size_t *resp_len
)
11529 const int reply_size
= 2048;
11531 int level
= MSG_DEBUG
;
11533 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11534 char *pos
= os_strchr(buf
+ 7, ' ');
11537 return wpas_global_ctrl_iface_ifname(global
,
11543 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11547 if (os_strcmp(buf
, "PING") == 0)
11548 level
= MSG_EXCESSIVE
;
11549 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11550 (const u8
*) buf
, os_strlen(buf
));
11552 reply
= os_malloc(reply_size
);
11553 if (reply
== NULL
) {
11558 os_memcpy(reply
, "OK\n", 3);
11561 if (os_strcmp(buf
, "PING") == 0) {
11562 os_memcpy(reply
, "PONG\n", 5);
11564 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11565 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11567 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11568 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11570 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11571 reply_len
= wpa_supplicant_global_iface_list(
11572 global
, reply
, reply_size
);
11573 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11574 reply_len
= wpa_supplicant_global_iface_interfaces(
11575 global
, buf
+ 10, reply
, reply_size
);
11577 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11578 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11581 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11582 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11585 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11586 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11587 #endif /* CONFIG_FST */
11588 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11589 wpa_supplicant_terminate_proc(global
);
11590 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11591 wpas_notify_suspend(global
);
11592 } else if (os_strcmp(buf
, "RESUME") == 0) {
11593 wpas_notify_resume(global
);
11594 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11595 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11597 if (global
->p2p_init_wpa_s
) {
11599 /* Check if P2P redirection would work for this
11601 return wpa_supplicant_ctrl_iface_process(
11602 global
->p2p_init_wpa_s
,
11605 #endif /* CONFIG_P2P */
11608 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11609 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11611 #ifndef CONFIG_NO_CONFIG_WRITE
11612 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11613 if (wpas_global_ctrl_iface_save_config(global
))
11615 #endif /* CONFIG_NO_CONFIG_WRITE */
11616 } else if (os_strcmp(buf
, "STATUS") == 0) {
11617 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11619 #ifdef CONFIG_MODULE_TESTS
11620 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11621 if (wpas_module_tests() < 0)
11623 #endif /* CONFIG_MODULE_TESTS */
11624 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11625 if (wpa_debug_reopen_file() < 0)
11628 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11632 if (reply_len
< 0) {
11633 os_memcpy(reply
, "FAIL\n", 5);
11637 *resp_len
= reply_len
;