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 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
428 value
= os_strchr(cmd
, ' ');
433 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
434 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
435 eapol_sm_configure(wpa_s
->eapol
,
436 atoi(value
), -1, -1, -1);
437 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
438 eapol_sm_configure(wpa_s
->eapol
,
439 -1, atoi(value
), -1, -1);
440 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
441 eapol_sm_configure(wpa_s
->eapol
,
442 -1, -1, atoi(value
), -1);
443 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
444 eapol_sm_configure(wpa_s
->eapol
,
445 -1, -1, -1, atoi(value
));
446 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
447 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
452 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
454 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
456 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
461 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
463 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
464 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
469 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
471 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
472 wpa_s
->wps_fragment_size
= atoi(value
);
473 #ifdef CONFIG_WPS_TESTING
474 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
476 val
= strtol(value
, NULL
, 0);
477 if (val
< 0 || val
> 0xff) {
479 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
480 "wps_version_number %ld", val
);
482 wps_version_number
= val
;
483 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
485 (wps_version_number
& 0xf0) >> 4,
486 wps_version_number
& 0x0f);
488 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
489 wps_testing_dummy_cred
= atoi(value
);
490 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
491 wps_testing_dummy_cred
);
492 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
493 wps_corrupt_pkhash
= atoi(value
);
494 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
496 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
497 if (value
[0] == '\0') {
498 wps_force_auth_types_in_use
= 0;
500 wps_force_auth_types
= strtol(value
, NULL
, 0);
501 wps_force_auth_types_in_use
= 1;
503 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
504 if (value
[0] == '\0') {
505 wps_force_encr_types_in_use
= 0;
507 wps_force_encr_types
= strtol(value
, NULL
, 0);
508 wps_force_encr_types_in_use
= 1;
510 #endif /* CONFIG_WPS_TESTING */
511 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
512 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
515 #ifdef CONFIG_TDLS_TESTING
516 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
517 tdls_testing
= strtol(value
, NULL
, 0);
518 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
519 #endif /* CONFIG_TDLS_TESTING */
520 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
521 int disabled
= atoi(value
);
522 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
524 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
526 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
528 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
529 #endif /* CONFIG_TDLS */
530 } else if (os_strcasecmp(cmd
, "pno") == 0) {
531 ret
= wpas_ctrl_pno(wpa_s
, value
);
532 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
533 int disabled
= atoi(value
);
534 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
537 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
538 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
539 if (os_strcmp(value
, "disable") == 0)
540 wpa_s
->set_sta_uapsd
= 0;
544 /* format: BE,BK,VI,VO;max SP Length */
546 pos
= os_strchr(value
, ',');
551 pos
= os_strchr(pos
, ',');
556 pos
= os_strchr(pos
, ',');
561 /* ignore max SP Length for now */
563 wpa_s
->set_sta_uapsd
= 1;
564 wpa_s
->sta_uapsd
= 0;
566 wpa_s
->sta_uapsd
|= BIT(0);
568 wpa_s
->sta_uapsd
|= BIT(1);
570 wpa_s
->sta_uapsd
|= BIT(2);
572 wpa_s
->sta_uapsd
|= BIT(3);
574 } else if (os_strcasecmp(cmd
, "ps") == 0) {
575 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
576 #ifdef CONFIG_WIFI_DISPLAY
577 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
578 int enabled
= !!atoi(value
);
579 if (enabled
&& !wpa_s
->global
->p2p
)
582 wifi_display_enable(wpa_s
->global
, enabled
);
583 #endif /* CONFIG_WIFI_DISPLAY */
584 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
585 ret
= set_bssid_filter(wpa_s
, value
);
586 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
587 ret
= set_disallow_aps(wpa_s
, value
);
588 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
589 wpa_s
->no_keep_alive
= !!atoi(value
);
591 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
592 os_free(wpa_s
->dpp_configurator_params
);
593 wpa_s
->dpp_configurator_params
= os_strdup(value
);
594 } else if (os_strcasecmp(cmd
, "dpp_init_max_tries") == 0) {
595 wpa_s
->dpp_init_max_tries
= atoi(value
);
596 } else if (os_strcasecmp(cmd
, "dpp_init_retry_time") == 0) {
597 wpa_s
->dpp_init_retry_time
= atoi(value
);
598 } else if (os_strcasecmp(cmd
, "dpp_resp_wait_time") == 0) {
599 wpa_s
->dpp_resp_wait_time
= atoi(value
);
600 } else if (os_strcasecmp(cmd
, "dpp_resp_max_tries") == 0) {
601 wpa_s
->dpp_resp_max_tries
= atoi(value
);
602 } else if (os_strcasecmp(cmd
, "dpp_resp_retry_time") == 0) {
603 wpa_s
->dpp_resp_retry_time
= atoi(value
);
604 #ifdef CONFIG_TESTING_OPTIONS
605 } else if (os_strcasecmp(cmd
, "dpp_pkex_own_mac_override") == 0) {
606 if (hwaddr_aton(value
, dpp_pkex_own_mac_override
))
608 } else if (os_strcasecmp(cmd
, "dpp_pkex_peer_mac_override") == 0) {
609 if (hwaddr_aton(value
, dpp_pkex_peer_mac_override
))
611 } else if (os_strcasecmp(cmd
, "dpp_pkex_ephemeral_key_override") == 0) {
612 size_t hex_len
= os_strlen(value
);
615 2 * sizeof(dpp_pkex_ephemeral_key_override
))
617 else if (hexstr2bin(value
, dpp_pkex_ephemeral_key_override
,
621 dpp_pkex_ephemeral_key_override_len
= hex_len
/ 2;
622 } else if (os_strcasecmp(cmd
, "dpp_protocol_key_override") == 0) {
623 size_t hex_len
= os_strlen(value
);
625 if (hex_len
> 2 * sizeof(dpp_protocol_key_override
))
627 else if (hexstr2bin(value
, dpp_protocol_key_override
,
631 dpp_protocol_key_override_len
= hex_len
/ 2;
632 } else if (os_strcasecmp(cmd
, "dpp_nonce_override") == 0) {
633 size_t hex_len
= os_strlen(value
);
635 if (hex_len
> 2 * sizeof(dpp_nonce_override
))
637 else if (hexstr2bin(value
, dpp_nonce_override
, hex_len
/ 2))
640 dpp_nonce_override_len
= hex_len
/ 2;
641 #endif /* CONFIG_TESTING_OPTIONS */
642 #endif /* CONFIG_DPP */
643 #ifdef CONFIG_TESTING_OPTIONS
644 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
645 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
646 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
647 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
649 if (wpa_s
->ap_iface
) {
650 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
651 wpa_s
->ext_eapol_frame_io
;
653 #endif /* CONFIG_AP */
654 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
655 wpa_s
->extra_roc_dur
= atoi(value
);
656 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
657 wpa_s
->test_failure
= atoi(value
);
658 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
659 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
660 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
661 wpa_s
->ignore_auth_resp
= !!atoi(value
);
662 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
663 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
664 wpa_drv_ignore_assoc_disallow(wpa_s
,
665 wpa_s
->ignore_assoc_disallow
);
666 } else if (os_strcasecmp(cmd
, "ignore_sae_h2e_only") == 0) {
667 wpa_s
->ignore_sae_h2e_only
= !!atoi(value
);
668 } else if (os_strcasecmp(cmd
, "extra_sae_rejected_groups") == 0) {
671 os_free(wpa_s
->extra_sae_rejected_groups
);
672 wpa_s
->extra_sae_rejected_groups
= NULL
;
674 while (pos
&& pos
[0]) {
678 wpa_printf(MSG_DEBUG
,
679 "TESTING: Extra rejection of SAE group %d",
682 int_array_add_unique(
683 &wpa_s
->extra_sae_rejected_groups
,
685 pos
= os_strchr(pos
, ' ');
690 } else if (os_strcasecmp(cmd
, "rsnxe_override_assoc") == 0) {
691 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
692 if (os_strcmp(value
, "NULL") == 0)
693 wpa_s
->rsnxe_override_assoc
= NULL
;
695 wpa_s
->rsnxe_override_assoc
= wpabuf_parse_bin(value
);
696 } else if (os_strcasecmp(cmd
, "rsnxe_override_eapol") == 0) {
697 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
698 if (os_strcmp(value
, "NULL") == 0)
699 wpa_s
->rsnxe_override_eapol
= NULL
;
701 wpa_s
->rsnxe_override_eapol
= wpabuf_parse_bin(value
);
702 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
703 wpa_s
->reject_btm_req_reason
= atoi(value
);
704 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
705 os_free(wpa_s
->get_pref_freq_list_override
);
707 wpa_s
->get_pref_freq_list_override
= NULL
;
709 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
710 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
711 wpabuf_free(wpa_s
->sae_commit_override
);
712 if (value
[0] == '\0')
713 wpa_s
->sae_commit_override
= NULL
;
715 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
717 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
718 os_free(wpa_s
->dpp_config_obj_override
);
719 if (value
[0] == '\0')
720 wpa_s
->dpp_config_obj_override
= NULL
;
722 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
723 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
724 os_free(wpa_s
->dpp_discovery_override
);
725 if (value
[0] == '\0')
726 wpa_s
->dpp_discovery_override
= NULL
;
728 wpa_s
->dpp_discovery_override
= os_strdup(value
);
729 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
730 os_free(wpa_s
->dpp_groups_override
);
731 if (value
[0] == '\0')
732 wpa_s
->dpp_groups_override
= NULL
;
734 wpa_s
->dpp_groups_override
= os_strdup(value
);
735 } else if (os_strcasecmp(cmd
,
736 "dpp_ignore_netaccesskey_mismatch") == 0) {
737 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
738 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
739 dpp_test
= atoi(value
);
740 #endif /* CONFIG_DPP */
741 #endif /* CONFIG_TESTING_OPTIONS */
743 } else if (os_strcasecmp(cmd
, "disable_fils") == 0) {
744 wpa_s
->disable_fils
= !!atoi(value
);
745 wpa_drv_disable_fils(wpa_s
, wpa_s
->disable_fils
);
746 wpa_supplicant_set_default_scan_ies(wpa_s
);
747 #endif /* CONFIG_FILS */
748 #ifndef CONFIG_NO_CONFIG_BLOBS
749 } else if (os_strcmp(cmd
, "blob") == 0) {
750 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
751 #endif /* CONFIG_NO_CONFIG_BLOBS */
752 } else if (os_strcasecmp(cmd
, "setband") == 0) {
753 ret
= wpas_ctrl_set_band(wpa_s
, value
);
755 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
756 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
759 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
761 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
762 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
763 } else if (os_strcasecmp(cmd
, "oce") == 0) {
764 wpa_s
->conf
->oce
= atoi(value
);
765 if (wpa_s
->conf
->oce
) {
766 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
767 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
768 wpa_s
->enable_oce
= OCE_STA
;
770 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
772 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
773 /* TODO: Need to add STA-CFON support */
774 wpa_printf(MSG_ERROR
,
775 "OCE STA-CFON feature is not yet supported");
779 wpa_s
->enable_oce
= 0;
781 wpa_supplicant_set_default_scan_ies(wpa_s
);
782 #endif /* CONFIG_MBO */
783 } else if (os_strcasecmp(cmd
, "lci") == 0) {
784 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
785 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
786 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
787 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
788 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
789 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
790 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
791 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
792 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
793 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
794 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
796 } else if (os_strcasecmp(cmd
, "coloc_intf_elems") == 0) {
797 struct wpabuf
*elems
;
799 elems
= wpabuf_parse_bin(value
);
802 wnm_set_coloc_intf_elems(wpa_s
, elems
);
803 #endif /* CONFIG_WNM */
806 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
808 wpa_supplicant_update_config(wpa_s
);
815 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
816 char *cmd
, char *buf
, size_t buflen
)
820 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
822 if (os_strcmp(cmd
, "version") == 0) {
823 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
824 } else if (os_strcasecmp(cmd
, "country") == 0) {
825 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
826 res
= os_snprintf(buf
, buflen
, "%c%c",
827 wpa_s
->conf
->country
[0],
828 wpa_s
->conf
->country
[1]);
829 #ifdef CONFIG_WIFI_DISPLAY
830 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
832 if (wpa_s
->global
->p2p
== NULL
||
833 wpa_s
->global
->p2p_disabled
)
836 enabled
= wpa_s
->global
->wifi_display
;
837 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
838 #endif /* CONFIG_WIFI_DISPLAY */
839 #ifdef CONFIG_TESTING_GET_GTK
840 } else if (os_strcmp(cmd
, "gtk") == 0) {
841 if (wpa_s
->last_gtk_len
== 0)
843 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
844 wpa_s
->last_gtk_len
);
846 #endif /* CONFIG_TESTING_GET_GTK */
847 } else if (os_strcmp(cmd
, "tls_library") == 0) {
848 res
= tls_get_library_version(buf
, buflen
);
849 #ifdef CONFIG_TESTING_OPTIONS
850 } else if (os_strcmp(cmd
, "anonce") == 0) {
851 return wpa_snprintf_hex(buf
, buflen
,
852 wpa_sm_get_anonce(wpa_s
->wpa
),
854 #endif /* CONFIG_TESTING_OPTIONS */
856 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
859 if (os_snprintf_error(buflen
, res
))
865 #ifdef IEEE8021X_EAPOL
866 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
870 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
872 if (hwaddr_aton(addr
, bssid
)) {
873 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
878 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
879 rsn_preauth_deinit(wpa_s
->wpa
);
880 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
885 #endif /* IEEE8021X_EAPOL */
890 static int wpa_supplicant_ctrl_iface_tdls_discover(
891 struct wpa_supplicant
*wpa_s
, char *addr
)
896 if (hwaddr_aton(addr
, peer
)) {
897 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
898 "address '%s'", addr
);
902 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
905 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
906 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
908 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
914 static int wpa_supplicant_ctrl_iface_tdls_setup(
915 struct wpa_supplicant
*wpa_s
, char *addr
)
920 if (hwaddr_aton(addr
, peer
)) {
921 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
922 "address '%s'", addr
);
926 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
929 if ((wpa_s
->conf
->tdls_external_control
) &&
930 wpa_tdls_is_external_setup(wpa_s
->wpa
))
931 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
933 wpa_tdls_remove(wpa_s
->wpa
, peer
);
935 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
936 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
938 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
944 static int wpa_supplicant_ctrl_iface_tdls_teardown(
945 struct wpa_supplicant
*wpa_s
, char *addr
)
950 if (os_strcmp(addr
, "*") == 0) {
951 /* remove everyone */
952 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
953 wpa_tdls_teardown_peers(wpa_s
->wpa
);
957 if (hwaddr_aton(addr
, peer
)) {
958 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
959 "address '%s'", addr
);
963 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
966 if ((wpa_s
->conf
->tdls_external_control
) &&
967 wpa_tdls_is_external_setup(wpa_s
->wpa
))
968 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
970 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
971 ret
= wpa_tdls_teardown_link(
973 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
975 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
981 static int ctrl_iface_get_capability_tdls(
982 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
986 ret
= os_snprintf(buf
, buflen
, "%s\n",
987 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
989 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
990 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
991 if (os_snprintf_error(buflen
, ret
))
997 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
998 struct wpa_supplicant
*wpa_s
, char *cmd
)
1001 struct hostapd_freq_params freq_params
;
1005 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1006 wpa_printf(MSG_INFO
,
1007 "tdls_chanswitch: Only supported with external setup");
1011 os_memset(&freq_params
, 0, sizeof(freq_params
));
1013 pos
= os_strchr(cmd
, ' ');
1018 oper_class
= strtol(pos
, &end
, 10);
1020 wpa_printf(MSG_INFO
,
1021 "tdls_chanswitch: Invalid op class provided");
1026 freq_params
.freq
= atoi(pos
);
1027 if (freq_params
.freq
== 0) {
1028 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
1032 #define SET_FREQ_SETTING(str) \
1034 const char *pos2 = os_strstr(pos, " " #str "="); \
1036 pos2 += sizeof(" " #str "=") - 1; \
1037 freq_params.str = atoi(pos2); \
1041 SET_FREQ_SETTING(center_freq1
);
1042 SET_FREQ_SETTING(center_freq2
);
1043 SET_FREQ_SETTING(bandwidth
);
1044 SET_FREQ_SETTING(sec_channel_offset
);
1045 #undef SET_FREQ_SETTING
1047 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
1048 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
1050 if (hwaddr_aton(cmd
, peer
)) {
1051 wpa_printf(MSG_DEBUG
,
1052 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1057 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1058 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1059 MAC2STR(peer
), oper_class
, freq_params
.freq
,
1060 freq_params
.center_freq1
, freq_params
.center_freq2
,
1061 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
1062 freq_params
.ht_enabled
? " HT" : "",
1063 freq_params
.vht_enabled
? " VHT" : "");
1065 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
1070 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1071 struct wpa_supplicant
*wpa_s
, char *cmd
)
1075 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1076 wpa_printf(MSG_INFO
,
1077 "tdls_chanswitch: Only supported with external setup");
1081 if (hwaddr_aton(cmd
, peer
)) {
1082 wpa_printf(MSG_DEBUG
,
1083 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1088 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1091 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1095 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1096 struct wpa_supplicant
*wpa_s
, const char *addr
,
1097 char *buf
, size_t buflen
)
1100 const char *tdls_status
;
1103 if (hwaddr_aton(addr
, peer
)) {
1104 wpa_printf(MSG_DEBUG
,
1105 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1109 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1112 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1113 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1114 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1115 if (os_snprintf_error(buflen
, ret
))
1121 #endif /* CONFIG_TDLS */
1124 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1126 char *token
, *context
= NULL
;
1127 struct wmm_ac_ts_setup_params params
= {
1132 while ((token
= str_token(cmd
, " ", &context
))) {
1133 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1134 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1135 sscanf(token
, "nominal_msdu_size=%i",
1136 ¶ms
.nominal_msdu_size
) == 1 ||
1137 sscanf(token
, "mean_data_rate=%i",
1138 ¶ms
.mean_data_rate
) == 1 ||
1139 sscanf(token
, "min_phy_rate=%i",
1140 ¶ms
.minimum_phy_rate
) == 1 ||
1141 sscanf(token
, "sba=%i",
1142 ¶ms
.surplus_bandwidth_allowance
) == 1)
1145 if (os_strcasecmp(token
, "downlink") == 0) {
1146 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1147 } else if (os_strcasecmp(token
, "uplink") == 0) {
1148 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1149 } else if (os_strcasecmp(token
, "bidi") == 0) {
1150 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1151 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1152 params
.fixed_nominal_msdu
= 1;
1154 wpa_printf(MSG_DEBUG
,
1155 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1162 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1166 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1168 u8 tsid
= atoi(cmd
);
1170 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1174 #ifdef CONFIG_IEEE80211R
1175 static int wpa_supplicant_ctrl_iface_ft_ds(
1176 struct wpa_supplicant
*wpa_s
, char *addr
)
1178 u8 target_ap
[ETH_ALEN
];
1179 struct wpa_bss
*bss
;
1182 if (hwaddr_aton(addr
, target_ap
)) {
1183 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1184 "address '%s'", addr
);
1188 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1190 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1192 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1196 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1198 #endif /* CONFIG_IEEE80211R */
1202 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1205 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1207 u8 p2p_dev_addr
[ETH_ALEN
];
1208 #endif /* CONFIG_P2P */
1210 u8
*_p2p_dev_addr
= NULL
;
1211 #endif /* CONFIG_AP */
1215 if (!cmd
|| os_strcmp(cmd
, "any") == 0 ||
1216 os_strncmp(cmd
, "any ", 4) == 0) {
1219 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1220 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1221 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1222 "P2P Device Address '%s'",
1226 _p2p_dev_addr
= p2p_dev_addr
;
1227 #endif /* CONFIG_P2P */
1228 } else if (os_strncmp(cmd
, "multi_ap=", 9) == 0) {
1230 multi_ap
= atoi(cmd
+ 9);
1231 } else if (hwaddr_aton(cmd
, bssid
)) {
1232 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1238 pos
= os_strstr(cmd
, " multi_ap=");
1241 multi_ap
= atoi(pos
);
1246 if (wpa_s
->ap_iface
)
1247 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1248 #endif /* CONFIG_AP */
1250 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0, multi_ap
);
1254 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1255 char *cmd
, char *buf
,
1258 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1262 pin
= os_strchr(cmd
, ' ');
1266 if (os_strcmp(cmd
, "any") == 0)
1268 else if (os_strcmp(cmd
, "get") == 0) {
1269 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1272 } else if (hwaddr_aton(cmd
, bssid
)) {
1273 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1279 if (wpa_s
->ap_iface
) {
1284 pos
= os_strchr(pin
, ' ');
1287 timeout
= atoi(pos
);
1291 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1292 buf
, buflen
, timeout
);
1294 #endif /* CONFIG_AP */
1297 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1301 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1302 if (os_snprintf_error(buflen
, ret
))
1307 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1312 /* Return the generated PIN */
1313 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1314 if (os_snprintf_error(buflen
, ret
))
1320 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1321 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1328 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1329 (u8
*) cmd
, os_strlen(cmd
));
1330 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1331 if (*pos
< '0' || *pos
> '9')
1335 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1339 if (len
!= 4 && len
!= 8) {
1340 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1346 unsigned int pin_val
;
1347 pin_val
= atoi(pin
);
1348 if (!wps_pin_valid(pin_val
)) {
1349 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1350 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1351 if (os_snprintf_error(buflen
, ret
))
1357 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1358 if (os_snprintf_error(buflen
, ret
))
1365 #ifdef CONFIG_WPS_NFC
1367 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1370 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1372 if (cmd
== NULL
|| cmd
[0] == '\0')
1374 else if (hwaddr_aton(cmd
, bssid
))
1377 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1382 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1383 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1390 pos
= os_strchr(cmd
, ' ');
1393 if (os_strcmp(cmd
, "WPS") == 0)
1395 else if (os_strcmp(cmd
, "NDEF") == 0)
1400 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1404 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1406 reply
[res
++] = '\n';
1415 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1416 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1422 if (os_strcmp(cmd
, "WPS") == 0)
1424 else if (os_strcmp(cmd
, "NDEF") == 0)
1429 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1433 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1435 reply
[res
++] = '\n';
1444 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1445 struct wpa_supplicant
*wpa_s
, char *pos
)
1451 int forced_freq
= 0;
1453 freq
= strstr(pos
, " freq=");
1457 forced_freq
= atoi(freq
);
1460 len
= os_strlen(pos
);
1465 buf
= wpabuf_alloc(len
);
1468 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1473 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1480 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1481 char *reply
, size_t max_len
,
1487 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1491 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1493 reply
[res
++] = '\n';
1503 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1504 char *reply
, size_t max_len
,
1510 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1512 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1516 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1518 reply
[res
++] = '\n';
1525 #endif /* CONFIG_P2P */
1528 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1529 char *cmd
, char *reply
,
1535 pos
= os_strchr(cmd
, ' ');
1540 if (os_strcmp(cmd
, "WPS") == 0)
1542 else if (os_strcmp(cmd
, "NDEF") == 0)
1547 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1550 return wpas_ctrl_nfc_get_handover_req_wps(
1551 wpa_s
, reply
, max_len
, ndef
);
1555 if (os_strcmp(pos
, "P2P-CR") == 0) {
1556 return wpas_ctrl_nfc_get_handover_req_p2p(
1557 wpa_s
, reply
, max_len
, ndef
);
1559 #endif /* CONFIG_P2P */
1565 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1566 char *reply
, size_t max_len
,
1567 int ndef
, int cr
, char *uuid
)
1572 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1576 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1578 reply
[res
++] = '\n';
1588 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1589 char *reply
, size_t max_len
,
1595 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1599 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1601 reply
[res
++] = '\n';
1608 #endif /* CONFIG_P2P */
1611 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1612 char *cmd
, char *reply
,
1618 pos
= os_strchr(cmd
, ' ');
1623 if (os_strcmp(cmd
, "WPS") == 0)
1625 else if (os_strcmp(cmd
, "NDEF") == 0)
1630 pos2
= os_strchr(pos
, ' ');
1633 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1636 return wpas_ctrl_nfc_get_handover_sel_wps(
1637 wpa_s
, reply
, max_len
, ndef
,
1638 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1642 if (os_strcmp(pos
, "P2P-CR") == 0) {
1643 return wpas_ctrl_nfc_get_handover_sel_p2p(
1644 wpa_s
, reply
, max_len
, ndef
, 0);
1647 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1648 return wpas_ctrl_nfc_get_handover_sel_p2p(
1649 wpa_s
, reply
, max_len
, ndef
, 1);
1651 #endif /* CONFIG_P2P */
1657 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1661 struct wpabuf
*req
, *sel
;
1663 char *pos
, *role
, *type
, *pos2
;
1666 int forced_freq
= 0;
1668 freq
= strstr(cmd
, " freq=");
1672 forced_freq
= atoi(freq
);
1674 #endif /* CONFIG_P2P */
1677 pos
= os_strchr(role
, ' ');
1679 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1685 pos
= os_strchr(type
, ' ');
1687 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1692 pos2
= os_strchr(pos
, ' ');
1694 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1699 len
= os_strlen(pos
);
1701 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1706 req
= wpabuf_alloc(len
);
1708 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1711 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1712 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1717 len
= os_strlen(pos2
);
1719 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1725 sel
= wpabuf_alloc(len
);
1727 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1731 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1732 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1738 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1739 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1741 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1742 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1744 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1746 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1748 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1749 #endif /* CONFIG_AP */
1751 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1753 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1754 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1756 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1758 #endif /* CONFIG_P2P */
1760 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1761 "reported: role=%s type=%s", role
, type
);
1768 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1773 #endif /* CONFIG_WPS_NFC */
1776 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1785 struct wps_new_ap_settings ap
;
1787 pin
= os_strchr(cmd
, ' ');
1792 if (hwaddr_aton(cmd
, bssid
)) {
1793 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1798 new_ssid
= os_strchr(pin
, ' ');
1799 if (new_ssid
== NULL
)
1800 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1803 new_auth
= os_strchr(new_ssid
, ' ');
1804 if (new_auth
== NULL
)
1808 new_encr
= os_strchr(new_auth
, ' ');
1809 if (new_encr
== NULL
)
1813 new_key
= os_strchr(new_encr
, ' ');
1814 if (new_key
== NULL
)
1818 os_memset(&ap
, 0, sizeof(ap
));
1819 ap
.ssid_hex
= new_ssid
;
1822 ap
.key_hex
= new_key
;
1823 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1828 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1829 char *cmd
, char *buf
,
1834 const char *pin_txt
;
1836 if (!wpa_s
->ap_iface
)
1839 pos
= os_strchr(cmd
, ' ');
1843 if (os_strcmp(cmd
, "disable") == 0) {
1844 wpas_wps_ap_pin_disable(wpa_s
);
1845 return os_snprintf(buf
, buflen
, "OK\n");
1848 if (os_strcmp(cmd
, "random") == 0) {
1850 timeout
= atoi(pos
);
1851 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1852 if (pin_txt
== NULL
)
1854 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1857 if (os_strcmp(cmd
, "get") == 0) {
1858 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1859 if (pin_txt
== NULL
)
1861 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1864 if (os_strcmp(cmd
, "set") == 0) {
1869 pos
= os_strchr(pos
, ' ');
1872 timeout
= atoi(pos
);
1874 if (os_strlen(pin
) > buflen
)
1876 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1878 return os_snprintf(buf
, buflen
, "%s", pin
);
1883 #endif /* CONFIG_AP */
1886 #ifdef CONFIG_WPS_ER
1887 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1890 char *uuid
= cmd
, *pin
, *pos
;
1891 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1892 pin
= os_strchr(uuid
, ' ');
1896 pos
= os_strchr(pin
, ' ');
1899 if (hwaddr_aton(pos
, addr_buf
) == 0)
1902 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1906 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1909 char *uuid
= cmd
, *pin
;
1910 pin
= os_strchr(uuid
, ' ');
1914 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1918 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1919 struct wpa_supplicant
*wpa_s
, char *cmd
)
1921 char *uuid
= cmd
, *id
;
1922 id
= os_strchr(uuid
, ' ');
1926 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1930 static int wpa_supplicant_ctrl_iface_wps_er_config(
1931 struct wpa_supplicant
*wpa_s
, char *cmd
)
1938 struct wps_new_ap_settings ap
;
1940 pin
= os_strchr(cmd
, ' ');
1945 new_ssid
= os_strchr(pin
, ' ');
1946 if (new_ssid
== NULL
)
1950 new_auth
= os_strchr(new_ssid
, ' ');
1951 if (new_auth
== NULL
)
1955 new_encr
= os_strchr(new_auth
, ' ');
1956 if (new_encr
== NULL
)
1960 new_key
= os_strchr(new_encr
, ' ');
1961 if (new_key
== NULL
)
1965 os_memset(&ap
, 0, sizeof(ap
));
1966 ap
.ssid_hex
= new_ssid
;
1969 ap
.key_hex
= new_key
;
1970 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1974 #ifdef CONFIG_WPS_NFC
1975 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1976 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1983 uuid
= os_strchr(cmd
, ' ');
1988 if (os_strcmp(cmd
, "WPS") == 0)
1990 else if (os_strcmp(cmd
, "NDEF") == 0)
1995 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1999 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
2001 reply
[res
++] = '\n';
2008 #endif /* CONFIG_WPS_NFC */
2009 #endif /* CONFIG_WPS_ER */
2011 #endif /* CONFIG_WPS */
2014 #ifdef CONFIG_IBSS_RSN
2015 static int wpa_supplicant_ctrl_iface_ibss_rsn(
2016 struct wpa_supplicant
*wpa_s
, char *addr
)
2020 if (hwaddr_aton(addr
, peer
)) {
2021 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
2022 "address '%s'", addr
);
2026 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
2029 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
2031 #endif /* CONFIG_IBSS_RSN */
2034 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
2037 #ifdef IEEE8021X_EAPOL
2040 struct wpa_ssid
*ssid
;
2042 pos
= os_strchr(rsp
, '-');
2047 pos
= os_strchr(pos
, ':');
2052 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
2053 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2054 (u8
*) pos
, os_strlen(pos
));
2056 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2058 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2063 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
2065 #else /* IEEE8021X_EAPOL */
2066 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
2068 #endif /* IEEE8021X_EAPOL */
2072 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
2074 char *buf
, size_t buflen
)
2076 char *pos
, *end
, tmp
[30];
2077 int res
, verbose
, wps
, ret
;
2080 #endif /* CONFIG_HS20 */
2084 if (os_strcmp(params
, "-DRIVER") == 0)
2085 return wpa_drv_status(wpa_s
, buf
, buflen
);
2086 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
2087 wps
= os_strcmp(params
, "-WPS") == 0;
2090 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
2091 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2092 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2093 MAC2STR(wpa_s
->bssid
));
2094 if (os_snprintf_error(end
- pos
, ret
))
2097 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2099 if (os_snprintf_error(end
- pos
, ret
))
2103 u8
*_ssid
= ssid
->ssid
;
2104 size_t ssid_len
= ssid
->ssid_len
;
2105 u8 ssid_buf
[SSID_MAX_LEN
];
2106 if (ssid_len
== 0) {
2107 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2114 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2115 wpa_ssid_txt(_ssid
, ssid_len
),
2117 if (os_snprintf_error(end
- pos
, ret
))
2121 if (wps
&& ssid
->passphrase
&&
2122 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2123 (ssid
->mode
== WPAS_MODE_AP
||
2124 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2125 ret
= os_snprintf(pos
, end
- pos
,
2128 if (os_snprintf_error(end
- pos
, ret
))
2133 ret
= os_snprintf(pos
, end
- pos
,
2136 if (os_snprintf_error(end
- pos
, ret
))
2141 switch (ssid
->mode
) {
2142 case WPAS_MODE_INFRA
:
2143 ret
= os_snprintf(pos
, end
- pos
,
2146 case WPAS_MODE_IBSS
:
2147 ret
= os_snprintf(pos
, end
- pos
,
2151 ret
= os_snprintf(pos
, end
- pos
,
2154 case WPAS_MODE_P2P_GO
:
2155 ret
= os_snprintf(pos
, end
- pos
,
2158 case WPAS_MODE_P2P_GROUP_FORMATION
:
2159 ret
= os_snprintf(pos
, end
- pos
,
2160 "mode=P2P GO - group "
2163 case WPAS_MODE_MESH
:
2164 ret
= os_snprintf(pos
, end
- pos
,
2171 if (os_snprintf_error(end
- pos
, ret
))
2176 if (wpa_s
->connection_set
&&
2177 (wpa_s
->connection_ht
|| wpa_s
->connection_vht
||
2178 wpa_s
->connection_he
)) {
2179 ret
= os_snprintf(pos
, end
- pos
,
2180 "wifi_generation=%u\n",
2181 wpa_s
->connection_he
? 6 :
2182 (wpa_s
->connection_vht
? 5 : 4));
2183 if (os_snprintf_error(end
- pos
, ret
))
2189 if (wpa_s
->ap_iface
) {
2190 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2194 #endif /* CONFIG_AP */
2195 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2199 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2202 #endif /* CONFIG_AP */
2203 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2204 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2205 wpa_s
->sme
.sae
.group
);
2206 if (os_snprintf_error(end
- pos
, ret
))
2210 #endif /* CONFIG_SAE */
2211 #endif /* CONFIG_SME */
2212 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2213 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2214 if (os_snprintf_error(end
- pos
, ret
))
2219 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2220 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2221 if (os_snprintf_error(end
- pos
, ret
))
2227 if (wpa_s
->global
->p2p
) {
2228 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2229 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2230 if (os_snprintf_error(end
- pos
, ret
))
2234 #endif /* CONFIG_P2P */
2236 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2237 MAC2STR(wpa_s
->own_addr
));
2238 if (os_snprintf_error(end
- pos
, ret
))
2243 if (wpa_s
->current_bss
&&
2244 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2245 HS20_IE_VENDOR_TYPE
)) &&
2246 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2247 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2250 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2251 release
= rel_num
+ 1;
2253 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2254 if (os_snprintf_error(end
- pos
, ret
))
2259 if (wpa_s
->current_ssid
) {
2260 struct wpa_cred
*cred
;
2263 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2266 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2269 if (cred
->provisioning_sp
) {
2270 ret
= os_snprintf(pos
, end
- pos
,
2271 "provisioning_sp=%s\n",
2272 cred
->provisioning_sp
);
2273 if (os_snprintf_error(end
- pos
, ret
))
2282 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2283 struct wpabuf
*names
=
2284 wpa_s
->current_bss
->anqp
->domain_name
;
2285 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2287 if (domain_name_list_contains(
2288 names
, cred
->domain
[i
], 1))
2291 if (i
== cred
->num_domain
)
2292 i
= 0; /* show first entry by default */
2294 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2296 if (os_snprintf_error(end
- pos
, ret
))
2301 if (wpa_s
->current_bss
== NULL
||
2302 wpa_s
->current_bss
->anqp
== NULL
)
2305 res
= interworking_home_sp_cred(
2307 wpa_s
->current_bss
->anqp
->domain_name
);
2315 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2316 if (os_snprintf_error(end
- pos
, ret
))
2323 #endif /* CONFIG_HS20 */
2325 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2326 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2327 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2333 #ifdef CONFIG_MACSEC
2334 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2337 #endif /* CONFIG_MACSEC */
2339 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2343 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2344 if (os_snprintf_error(end
- pos
, ret
))
2347 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2351 ret
= os_snprintf(pos
, end
- pos
, "\n");
2352 if (os_snprintf_error(end
- pos
, ret
))
2357 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2364 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2365 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2366 if (os_snprintf_error(end
- pos
, ret
))
2370 #endif /* CONFIG_WPS */
2372 if (wpa_s
->ieee80211ac
) {
2373 ret
= os_snprintf(pos
, end
- pos
, "ieee80211ac=1\n");
2374 if (os_snprintf_error(end
- pos
, ret
))
2381 * Allow using the STATUS command with default behavior, say for debug,
2382 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2383 * events with STATUS-NO_EVENTS.
2385 if (os_strcmp(params
, "-NO_EVENTS")) {
2386 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2387 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2388 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2390 MAC2STR(wpa_s
->bssid
),
2391 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2392 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2393 wpa_s
->current_ssid
->ssid_len
) : "");
2394 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2395 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2396 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2397 "- connection to " MACSTR
2398 " completed %s [id=%d id_str=%s]",
2399 MAC2STR(wpa_s
->bssid
), "(auth)",
2400 ssid
? ssid
->id
: -1,
2401 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2404 #endif /* ANDROID */
2410 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2415 struct wpa_ssid
*ssid
;
2418 /* cmd: "<network id> <BSSID>" */
2419 pos
= os_strchr(cmd
, ' ');
2424 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2425 if (hwaddr_aton(pos
, bssid
)) {
2426 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2430 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2432 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2437 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2438 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2444 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2445 char *cmd
, char *buf
,
2449 struct wpa_blacklist
*e
;
2453 /* cmd: "BLACKLIST [<BSSID>]" */
2457 e
= wpa_s
->blacklist
;
2459 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2461 if (os_snprintf_error(end
- pos
, ret
))
2470 if (os_strncmp(cmd
, "clear", 5) == 0) {
2471 wpa_blacklist_clear(wpa_s
);
2472 os_memcpy(buf
, "OK\n", 3);
2476 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2477 if (hwaddr_aton(cmd
, bssid
)) {
2478 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2483 * Add the BSSID twice, so its count will be 2, causing it to be
2484 * skipped when processing scan results.
2486 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2489 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2492 os_memcpy(buf
, "OK\n", 3);
2497 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2498 char *cmd
, char *buf
,
2501 char *pos
, *end
, *stamp
;
2504 /* cmd: "LOG_LEVEL [<level>]" */
2508 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2510 debug_level_str(wpa_debug_level
),
2511 wpa_debug_timestamp
);
2512 if (os_snprintf_error(end
- pos
, ret
))
2521 stamp
= os_strchr(cmd
, ' ');
2524 while (*stamp
== ' ') {
2529 if (os_strlen(cmd
)) {
2530 int level
= str_to_debug_level(cmd
);
2533 wpa_debug_level
= level
;
2536 if (stamp
&& os_strlen(stamp
))
2537 wpa_debug_timestamp
= atoi(stamp
);
2539 os_memcpy(buf
, "OK\n", 3);
2544 static int wpa_supplicant_ctrl_iface_list_networks(
2545 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2547 char *pos
, *end
, *prev
;
2548 struct wpa_ssid
*ssid
;
2553 ret
= os_snprintf(pos
, end
- pos
,
2554 "network id / ssid / bssid / flags\n");
2555 if (os_snprintf_error(end
- pos
, ret
))
2559 ssid
= wpa_s
->conf
->ssid
;
2561 /* skip over ssids until we find next one */
2562 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2563 int last_id
= atoi(cmd
+ 8);
2564 if (last_id
!= -1) {
2565 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2573 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2575 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2576 if (os_snprintf_error(end
- pos
, ret
))
2579 if (ssid
->bssid_set
) {
2580 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2581 MAC2STR(ssid
->bssid
));
2583 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2585 if (os_snprintf_error(end
- pos
, ret
))
2588 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2589 ssid
== wpa_s
->current_ssid
?
2591 ssid
->disabled
? "[DISABLED]" : "",
2592 ssid
->disabled_until
.sec
?
2593 "[TEMP-DISABLED]" : "",
2594 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2596 if (os_snprintf_error(end
- pos
, ret
))
2599 ret
= os_snprintf(pos
, end
- pos
, "\n");
2600 if (os_snprintf_error(end
- pos
, ret
))
2611 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2614 ret
= os_snprintf(pos
, end
- pos
, "-");
2615 if (os_snprintf_error(end
- pos
, ret
))
2618 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2626 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2627 const u8
*ie
, size_t ie_len
)
2629 struct wpa_ie_data data
;
2633 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2634 if (os_snprintf_error(end
- pos
, ret
))
2638 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2639 ret
= os_snprintf(pos
, end
- pos
, "?]");
2640 if (os_snprintf_error(end
- pos
, ret
))
2647 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2648 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2649 pos
== start
? "" : "+");
2650 if (os_snprintf_error(end
- pos
, ret
))
2654 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2655 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2656 pos
== start
? "" : "+");
2657 if (os_snprintf_error(end
- pos
, ret
))
2661 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2662 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2663 pos
== start
? "" : "+");
2664 if (os_snprintf_error(end
- pos
, ret
))
2668 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2669 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2670 pos
== start
? "" : "+");
2671 if (os_snprintf_error(end
- pos
, ret
))
2675 #ifdef CONFIG_IEEE80211R
2676 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2677 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2678 pos
== start
? "" : "+");
2679 if (os_snprintf_error(end
- pos
, ret
))
2683 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2684 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2685 pos
== start
? "" : "+");
2686 if (os_snprintf_error(end
- pos
, ret
))
2690 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2691 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2692 pos
== start
? "" : "+");
2693 if (os_snprintf_error(end
- pos
, ret
))
2697 #endif /* CONFIG_IEEE80211R */
2698 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2699 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2700 pos
== start
? "" : "+");
2701 if (os_snprintf_error(end
- pos
, ret
))
2705 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2706 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2707 pos
== start
? "" : "+");
2708 if (os_snprintf_error(end
- pos
, ret
))
2713 #ifdef CONFIG_SUITEB
2714 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2715 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2716 pos
== start
? "" : "+");
2717 if (os_snprintf_error(end
- pos
, ret
))
2721 #endif /* CONFIG_SUITEB */
2723 #ifdef CONFIG_SUITEB192
2724 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2725 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2726 pos
== start
? "" : "+");
2727 if (os_snprintf_error(end
- pos
, ret
))
2731 #endif /* CONFIG_SUITEB192 */
2734 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2735 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2736 pos
== start
? "" : "+");
2737 if (os_snprintf_error(end
- pos
, ret
))
2741 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2742 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2743 pos
== start
? "" : "+");
2744 if (os_snprintf_error(end
- pos
, ret
))
2748 #ifdef CONFIG_IEEE80211R
2749 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2750 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2751 pos
== start
? "" : "+");
2752 if (os_snprintf_error(end
- pos
, ret
))
2756 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2757 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2758 pos
== start
? "" : "+");
2759 if (os_snprintf_error(end
- pos
, ret
))
2763 #endif /* CONFIG_IEEE80211R */
2764 #endif /* CONFIG_FILS */
2767 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2768 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2769 pos
== start
? "" : "+");
2770 if (os_snprintf_error(end
- pos
, ret
))
2774 #endif /* CONFIG_OWE */
2777 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2778 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2779 pos
== start
? "" : "+");
2780 if (os_snprintf_error(end
- pos
, ret
))
2784 #endif /* CONFIG_DPP */
2786 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2787 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2788 pos
== start
? "" : "+");
2789 if (os_snprintf_error(end
- pos
, ret
))
2794 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2796 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2797 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2798 if (os_snprintf_error(end
- pos
, ret
))
2803 ret
= os_snprintf(pos
, end
- pos
, "]");
2804 if (os_snprintf_error(end
- pos
, ret
))
2813 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2814 char *pos
, char *end
,
2815 struct wpabuf
*wps_ie
)
2822 if (wps_is_selected_pbc_registrar(wps_ie
))
2824 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2826 else if (wps_is_selected_pin_registrar(wps_ie
))
2831 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2832 if (!os_snprintf_error(end
- pos
, ret
))
2834 wpabuf_free(wps_ie
);
2837 #endif /* CONFIG_WPS */
2840 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2841 char *pos
, char *end
,
2842 const struct wpa_bss
*bss
)
2845 struct wpabuf
*wps_ie
;
2846 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2847 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2848 #else /* CONFIG_WPS */
2850 #endif /* CONFIG_WPS */
2854 /* Format one result on one text line into a buffer. */
2855 static int wpa_supplicant_ctrl_iface_scan_result(
2856 struct wpa_supplicant
*wpa_s
,
2857 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2861 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
, *owe
;
2863 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2864 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2866 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2867 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2868 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2870 return 0; /* Do not show P2P listen discovery results here */
2875 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2876 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2877 if (os_snprintf_error(end
- pos
, ret
))
2880 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2882 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2883 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2885 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2888 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2890 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2891 osen_ie
, 2 + osen_ie
[1]);
2892 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
2894 ret
= os_snprintf(pos
, end
- pos
,
2895 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2896 if (os_snprintf_error(end
- pos
, ret
))
2900 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2901 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2902 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2903 if (os_snprintf_error(end
- pos
, ret
))
2908 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2909 if (os_snprintf_error(end
- pos
, ret
))
2913 if (bss_is_dmg(bss
)) {
2916 if (get_ie_ext((const u8
*) (bss
+ 1), bss
->ie_len
,
2917 WLAN_EID_EXT_EDMG_OPERATION
)) {
2918 ret
= os_snprintf(pos
, end
- pos
, "[EDMG]");
2919 if (os_snprintf_error(end
- pos
, ret
))
2924 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2925 if (os_snprintf_error(end
- pos
, ret
))
2928 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2929 case IEEE80211_CAP_DMG_IBSS
:
2932 case IEEE80211_CAP_DMG_AP
:
2935 case IEEE80211_CAP_DMG_PBSS
:
2942 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2943 if (os_snprintf_error(end
- pos
, ret
))
2947 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2948 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2949 if (os_snprintf_error(end
- pos
, ret
))
2953 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2954 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2955 if (os_snprintf_error(end
- pos
, ret
))
2961 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2962 if (os_snprintf_error(end
- pos
, ret
))
2967 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2968 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2969 if (os_snprintf_error(end
- pos
, ret
))
2973 #endif /* CONFIG_HS20 */
2975 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2976 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2977 if (os_snprintf_error(end
- pos
, ret
))
2981 #endif /* CONFIG_FILS */
2983 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2984 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2985 if (os_snprintf_error(end
- pos
, ret
))
2989 #endif /* CONFIG_FST */
2990 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
2991 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
2992 if (os_snprintf_error(end
- pos
, ret
))
2997 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2998 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2999 if (os_snprintf_error(end
- pos
, ret
))
3003 ret
= os_snprintf(pos
, end
- pos
, "\n");
3004 if (os_snprintf_error(end
- pos
, ret
))
3012 static int wpa_supplicant_ctrl_iface_scan_results(
3013 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3016 struct wpa_bss
*bss
;
3021 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
3023 if (os_snprintf_error(end
- pos
, ret
))
3027 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
3028 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
3030 if (ret
< 0 || ret
>= end
- pos
)
3041 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3042 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
3044 char *pos
, ifname
[IFNAMSIZ
+ 1];
3048 pos
= os_strstr(cmd
, "ifname=");
3051 os_strlcpy(ifname
, pos
, sizeof(ifname
));
3054 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
3057 os_strlcpy(reply
, ifname
, max_len
);
3058 return os_strlen(ifname
);
3062 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3063 struct wpa_supplicant
*wpa_s
, char *cmd
)
3066 struct wpa_ssid
*ssid
;
3069 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
3071 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3073 wpa_printf(MSG_DEBUG
,
3074 "CTRL_IFACE: Could not find network id=%d", id
);
3077 if (ssid
->mode
!= WPAS_MODE_MESH
) {
3078 wpa_printf(MSG_DEBUG
,
3079 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3082 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3083 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
3084 wpa_printf(MSG_ERROR
,
3085 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3090 * TODO: If necessary write our own group_add function,
3091 * for now we can reuse select_network
3093 wpa_supplicant_select_network(wpa_s
, ssid
);
3099 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3100 struct wpa_supplicant
*wpa_s
, char *cmd
)
3102 struct wpa_supplicant
*orig
;
3103 struct wpa_global
*global
;
3106 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
3108 global
= wpa_s
->global
;
3111 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3112 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
3118 wpa_printf(MSG_ERROR
,
3119 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3123 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
3124 wpa_printf(MSG_ERROR
,
3125 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3129 wpa_s
->reassociate
= 0;
3130 wpa_s
->disconnected
= 1;
3131 wpa_supplicant_cancel_sched_scan(wpa_s
);
3132 wpa_supplicant_cancel_scan(wpa_s
);
3135 * TODO: If necessary write our own group_remove function,
3136 * for now we can reuse deauthenticate
3138 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3140 if (wpa_s
->mesh_if_created
)
3141 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3147 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3148 struct wpa_supplicant
*wpa_s
, char *cmd
)
3152 if (hwaddr_aton(cmd
, addr
) < 0)
3155 return wpas_mesh_peer_remove(wpa_s
, addr
);
3159 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3160 struct wpa_supplicant
*wpa_s
, char *cmd
)
3166 pos
= os_strstr(cmd
, " duration=");
3169 duration
= atoi(pos
+ 10);
3174 if (hwaddr_aton(cmd
, addr
))
3177 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3181 static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3182 struct wpa_supplicant
*wpa_s
, char *cmd
)
3184 struct ether_header
*eth
;
3188 size_t payload_len
= 0, len
;
3191 if (hwaddr_aton(cmd
, addr
))
3194 pos
= os_strstr(cmd
, " payload=");
3197 payload_len
= os_strlen(pos
);
3198 if (payload_len
& 1)
3204 len
= ETH_HLEN
+ payload_len
;
3205 buf
= os_malloc(len
);
3209 eth
= (struct ether_header
*) buf
;
3210 os_memcpy(eth
->ether_dhost
, addr
, ETH_ALEN
);
3211 os_memcpy(eth
->ether_shost
, wpa_s
->own_addr
, ETH_ALEN
);
3212 eth
->ether_type
= htons(ETH_P_802_3
);
3214 if (payload_len
&& hexstr2bin(pos
, buf
+ ETH_HLEN
, payload_len
) < 0)
3217 ret
= wpa_drv_mesh_link_probe(wpa_s
, addr
, buf
, len
);
3223 #endif /* CONFIG_MESH */
3226 static int wpa_supplicant_ctrl_iface_select_network(
3227 struct wpa_supplicant
*wpa_s
, char *cmd
)
3230 struct wpa_ssid
*ssid
;
3233 /* cmd: "<network id>" or "any" */
3234 if (os_strncmp(cmd
, "any", 3) == 0) {
3235 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3239 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3241 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3243 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3244 "network id=%d", id
);
3247 if (ssid
->disabled
== 2) {
3248 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3249 "SELECT_NETWORK with persistent P2P group");
3254 pos
= os_strstr(cmd
, " freq=");
3256 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3258 os_free(wpa_s
->select_network_scan_freqs
);
3259 wpa_s
->select_network_scan_freqs
= freqs
;
3263 wpa_s
->scan_min_time
.sec
= 0;
3264 wpa_s
->scan_min_time
.usec
= 0;
3265 wpa_supplicant_select_network(wpa_s
, ssid
);
3271 static int wpa_supplicant_ctrl_iface_enable_network(
3272 struct wpa_supplicant
*wpa_s
, char *cmd
)
3275 struct wpa_ssid
*ssid
;
3277 /* cmd: "<network id>" or "all" */
3278 if (os_strcmp(cmd
, "all") == 0) {
3279 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3283 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3285 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3287 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3288 "network id=%d", id
);
3291 if (ssid
->disabled
== 2) {
3292 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3293 "ENABLE_NETWORK with persistent P2P group");
3297 if (os_strstr(cmd
, " no-connect")) {
3302 wpa_s
->scan_min_time
.sec
= 0;
3303 wpa_s
->scan_min_time
.usec
= 0;
3304 wpa_supplicant_enable_network(wpa_s
, ssid
);
3310 static int wpa_supplicant_ctrl_iface_disable_network(
3311 struct wpa_supplicant
*wpa_s
, char *cmd
)
3314 struct wpa_ssid
*ssid
;
3316 /* cmd: "<network id>" or "all" */
3317 if (os_strcmp(cmd
, "all") == 0) {
3318 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3322 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3324 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3326 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3327 "network id=%d", id
);
3330 if (ssid
->disabled
== 2) {
3331 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3332 "DISABLE_NETWORK with persistent P2P "
3337 wpa_supplicant_disable_network(wpa_s
, ssid
);
3343 static int wpa_supplicant_ctrl_iface_add_network(
3344 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3346 struct wpa_ssid
*ssid
;
3349 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3351 ssid
= wpa_supplicant_add_network(wpa_s
);
3355 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3356 if (os_snprintf_error(buflen
, ret
))
3362 static int wpa_supplicant_ctrl_iface_remove_network(
3363 struct wpa_supplicant
*wpa_s
, char *cmd
)
3366 struct wpa_ssid
*ssid
;
3369 /* cmd: "<network id>" or "all" */
3370 if (os_strcmp(cmd
, "all") == 0) {
3371 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3372 if (wpa_s
->sched_scanning
)
3373 wpa_supplicant_cancel_sched_scan(wpa_s
);
3375 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3376 if (wpa_s
->current_ssid
) {
3378 wpa_s
->sme
.prev_bssid_set
= 0;
3379 #endif /* CONFIG_SME */
3380 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3381 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3382 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3383 wpa_s
->own_disconnect_req
= 1;
3384 wpa_supplicant_deauthenticate(
3385 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3387 ssid
= wpa_s
->conf
->ssid
;
3389 struct wpa_ssid
*remove_ssid
= ssid
;
3392 if (wpa_s
->last_ssid
== remove_ssid
)
3393 wpa_s
->last_ssid
= NULL
;
3394 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3395 wpa_config_remove_network(wpa_s
->conf
, id
);
3401 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3403 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3405 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3410 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3411 "network id=%d", id
);
3418 static int wpa_supplicant_ctrl_iface_update_network(
3419 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3420 char *name
, char *value
)
3424 ret
= wpa_config_set(ssid
, name
, value
, 0);
3426 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3427 "variable '%s'", name
);
3431 return 0; /* No change to the previously configured value */
3433 if (os_strcmp(name
, "bssid") != 0 &&
3434 os_strcmp(name
, "bssid_hint") != 0 &&
3435 os_strcmp(name
, "priority") != 0) {
3436 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3438 if (wpa_s
->current_ssid
== ssid
||
3439 wpa_s
->current_ssid
== NULL
) {
3441 * Invalidate the EAP session cache if anything in the
3442 * current or previously used configuration changes.
3444 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3448 if ((os_strcmp(name
, "psk") == 0 &&
3449 value
[0] == '"' && ssid
->ssid_len
) ||
3450 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3451 wpa_config_update_psk(ssid
);
3452 else if (os_strcmp(name
, "priority") == 0)
3453 wpa_config_update_prio_list(wpa_s
->conf
);
3459 static int wpa_supplicant_ctrl_iface_set_network(
3460 struct wpa_supplicant
*wpa_s
, char *cmd
)
3462 int id
, ret
, prev_bssid_set
, prev_disabled
;
3463 struct wpa_ssid
*ssid
;
3465 u8 prev_bssid
[ETH_ALEN
];
3467 /* cmd: "<network id> <variable name> <value>" */
3468 name
= os_strchr(cmd
, ' ');
3473 value
= os_strchr(name
, ' ');
3479 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3481 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3482 (u8
*) value
, os_strlen(value
));
3484 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3486 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3491 prev_bssid_set
= ssid
->bssid_set
;
3492 prev_disabled
= ssid
->disabled
;
3493 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3494 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3497 (ssid
->bssid_set
!= prev_bssid_set
||
3498 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3499 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3501 if (prev_disabled
!= ssid
->disabled
&&
3502 (prev_disabled
== 2 || ssid
->disabled
== 2))
3503 wpas_notify_network_type_changed(wpa_s
, ssid
);
3509 static int wpa_supplicant_ctrl_iface_get_network(
3510 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3514 struct wpa_ssid
*ssid
;
3517 /* cmd: "<network id> <variable name>" */
3518 name
= os_strchr(cmd
, ' ');
3519 if (name
== NULL
|| buflen
== 0)
3524 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3527 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3529 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3534 value
= wpa_config_get_no_key(ssid
, name
);
3535 if (value
== NULL
) {
3536 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3537 "variable '%s'", name
);
3541 res
= os_strlcpy(buf
, value
, buflen
);
3542 if (res
>= buflen
) {
3553 static int wpa_supplicant_ctrl_iface_dup_network(
3554 struct wpa_supplicant
*wpa_s
, char *cmd
,
3555 struct wpa_supplicant
*dst_wpa_s
)
3557 struct wpa_ssid
*ssid_s
, *ssid_d
;
3558 char *name
, *id
, *value
;
3559 int id_s
, id_d
, ret
;
3561 /* cmd: "<src network id> <dst network id> <variable name>" */
3562 id
= os_strchr(cmd
, ' ');
3567 name
= os_strchr(id
, ' ');
3575 wpa_printf(MSG_DEBUG
,
3576 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3577 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3579 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3580 if (ssid_s
== NULL
) {
3581 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3582 "network id=%d", id_s
);
3586 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3587 if (ssid_d
== NULL
) {
3588 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3589 "network id=%d", id_d
);
3593 value
= wpa_config_get(ssid_s
, name
);
3594 if (value
== NULL
) {
3595 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3596 "variable '%s'", name
);
3600 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3609 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3610 char *buf
, size_t buflen
)
3613 struct wpa_cred
*cred
;
3618 ret
= os_snprintf(pos
, end
- pos
,
3619 "cred id / realm / username / domain / imsi\n");
3620 if (os_snprintf_error(end
- pos
, ret
))
3624 cred
= wpa_s
->conf
->cred
;
3626 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3627 cred
->id
, cred
->realm
? cred
->realm
: "",
3628 cred
->username
? cred
->username
: "",
3629 cred
->domain
? cred
->domain
[0] : "",
3630 cred
->imsi
? cred
->imsi
: "");
3631 if (os_snprintf_error(end
- pos
, ret
))
3642 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3643 char *buf
, size_t buflen
)
3645 struct wpa_cred
*cred
;
3648 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3650 cred
= wpa_config_add_cred(wpa_s
->conf
);
3654 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3656 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3657 if (os_snprintf_error(buflen
, ret
))
3663 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3664 struct wpa_cred
*cred
)
3666 struct wpa_ssid
*ssid
;
3671 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3676 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3677 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3681 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3683 /* Remove any network entry created based on the removed credential */
3684 ssid
= wpa_s
->conf
->ssid
;
3686 if (ssid
->parent_cred
== cred
) {
3689 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3690 "used the removed credential", ssid
->id
);
3691 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3692 if (os_snprintf_error(sizeof(str
), res
))
3693 str
[sizeof(str
) - 1] = '\0';
3695 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3704 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3708 struct wpa_cred
*cred
, *prev
;
3710 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3711 * "provisioning_sp=<FQDN> */
3712 if (os_strcmp(cmd
, "all") == 0) {
3713 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3714 cred
= wpa_s
->conf
->cred
;
3718 wpas_ctrl_remove_cred(wpa_s
, prev
);
3723 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3724 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3726 cred
= wpa_s
->conf
->cred
;
3732 for (i
= 0; i
< prev
->num_domain
; i
++) {
3733 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3736 wpas_ctrl_remove_cred(wpa_s
, prev
);
3744 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3745 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3747 cred
= wpa_s
->conf
->cred
;
3751 if (prev
->provisioning_sp
&&
3752 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3753 wpas_ctrl_remove_cred(wpa_s
, prev
);
3759 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3761 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3762 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3766 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3770 struct wpa_cred
*cred
;
3773 /* cmd: "<cred id> <variable name> <value>" */
3774 name
= os_strchr(cmd
, ' ');
3779 value
= os_strchr(name
, ' ');
3785 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3787 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3788 (u8
*) value
, os_strlen(value
));
3790 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3792 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3797 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3798 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3799 "variable '%s'", name
);
3803 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3809 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3810 char *cmd
, char *buf
,
3815 struct wpa_cred
*cred
;
3818 /* cmd: "<cred id> <variable name>" */
3819 name
= os_strchr(cmd
, ' ');
3825 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3828 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3830 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3835 value
= wpa_config_get_cred_no_key(cred
, name
);
3836 if (value
== NULL
) {
3837 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3842 res
= os_strlcpy(buf
, value
, buflen
);
3843 if (res
>= buflen
) {
3854 #ifndef CONFIG_NO_CONFIG_WRITE
3855 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3859 if (!wpa_s
->conf
->update_config
) {
3860 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3861 "to update configuration (update_config=0)");
3865 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3867 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3868 "update configuration");
3870 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3876 #endif /* CONFIG_NO_CONFIG_WRITE */
3879 struct cipher_info
{
3885 static const struct cipher_info ciphers
[] = {
3886 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3887 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3888 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3889 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3890 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3891 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3892 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3893 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3896 static const struct cipher_info ciphers_group_mgmt
[] = {
3897 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3898 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3899 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3900 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3904 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3905 struct wpa_driver_capa
*capa
,
3906 char *buf
, size_t buflen
)
3919 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3925 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3926 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3927 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3928 pos
== buf
? "" : " ",
3930 if (os_snprintf_error(end
- pos
, ret
))
3940 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3941 struct wpa_driver_capa
*capa
,
3942 char *buf
, size_t buflen
)
3955 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3961 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3962 if (capa
->enc
& ciphers
[i
].capa
) {
3963 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3964 pos
== buf
? "" : " ",
3966 if (os_snprintf_error(end
- pos
, ret
))
3976 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3977 struct wpa_driver_capa
*capa
,
3978 char *buf
, size_t buflen
)
3990 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3991 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3992 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3993 pos
== buf
? "" : " ",
3994 ciphers_group_mgmt
[i
].name
);
3995 if (os_snprintf_error(end
- pos
, ret
))
4005 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
4006 struct wpa_driver_capa
*capa
,
4007 char *buf
, size_t buflen
)
4019 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4026 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
4027 if (os_snprintf_error(end
- pos
, ret
))
4031 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4032 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
4033 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
4034 if (os_snprintf_error(end
- pos
, ret
))
4039 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
4040 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4041 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
4042 if (os_snprintf_error(end
- pos
, ret
))
4047 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
4048 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
4049 if (os_snprintf_error(end
- pos
, ret
))
4054 #ifdef CONFIG_SUITEB
4055 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
4056 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
4057 if (os_snprintf_error(end
- pos
, ret
))
4061 #endif /* CONFIG_SUITEB */
4062 #ifdef CONFIG_SUITEB192
4063 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
4064 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
4065 if (os_snprintf_error(end
- pos
, ret
))
4069 #endif /* CONFIG_SUITEB192 */
4071 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
4072 ret
= os_snprintf(pos
, end
- pos
, " OWE");
4073 if (os_snprintf_error(end
- pos
, ret
))
4077 #endif /* CONFIG_OWE */
4079 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
4080 ret
= os_snprintf(pos
, end
- pos
, " DPP");
4081 if (os_snprintf_error(end
- pos
, ret
))
4085 #endif /* CONFIG_DPP */
4087 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
4088 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
4089 if (os_snprintf_error(end
- pos
, ret
))
4093 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
4094 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
4095 if (os_snprintf_error(end
- pos
, ret
))
4099 #ifdef CONFIG_IEEE80211R
4100 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
4101 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
4102 if (os_snprintf_error(end
- pos
, ret
))
4106 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
4107 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
4108 if (os_snprintf_error(end
- pos
, ret
))
4112 #endif /* CONFIG_IEEE80211R */
4113 #endif /* CONFIG_FILS */
4114 #ifdef CONFIG_IEEE80211R
4115 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
) {
4116 ret
= os_snprintf(pos
, end
- pos
, " FT-PSK");
4117 if (os_snprintf_error(end
- pos
, ret
))
4121 #endif /* CONFIG_IEEE80211R */
4123 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SAE
) {
4124 ret
= os_snprintf(pos
, end
- pos
, " SAE");
4125 if (os_snprintf_error(end
- pos
, ret
))
4129 #endif /* CONFIG_SAE */
4135 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
4136 struct wpa_driver_capa
*capa
,
4137 char *buf
, size_t buflen
)
4149 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
4155 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
4156 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4157 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
4158 pos
== buf
? "" : " ");
4159 if (os_snprintf_error(end
- pos
, ret
))
4164 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4165 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
4166 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
4167 pos
== buf
? "" : " ");
4168 if (os_snprintf_error(end
- pos
, ret
))
4177 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
4178 int res
, char *strict
,
4179 struct wpa_driver_capa
*capa
,
4180 char *buf
, size_t buflen
)
4192 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4198 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4199 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4200 pos
== buf
? "" : " ");
4201 if (os_snprintf_error(end
- pos
, ret
))
4206 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4207 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4208 pos
== buf
? "" : " ");
4209 if (os_snprintf_error(end
- pos
, ret
))
4214 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4215 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4216 pos
== buf
? "" : " ");
4217 if (os_snprintf_error(end
- pos
, ret
))
4223 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4224 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4225 pos
== buf
? "" : " ");
4226 if (os_snprintf_error(end
- pos
, ret
))
4230 #endif /* CONFIG_SAE */
4233 if (wpa_is_fils_supported(wpa_s
)) {
4234 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4235 pos
== buf
? "" : " ");
4236 if (os_snprintf_error(end
- pos
, ret
))
4241 #ifdef CONFIG_FILS_SK_PFS
4242 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4243 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4244 pos
== buf
? "" : " ");
4245 if (os_snprintf_error(end
- pos
, ret
))
4249 #endif /* CONFIG_FILS_SK_PFS */
4250 #endif /* CONFIG_FILS */
4256 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4257 struct wpa_driver_capa
*capa
,
4258 char *buf
, size_t buflen
)
4270 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4276 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4277 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4278 pos
== buf
? "" : " ");
4279 if (os_snprintf_error(end
- pos
, ret
))
4284 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4285 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4286 pos
== buf
? "" : " ");
4287 if (os_snprintf_error(end
- pos
, ret
))
4293 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4294 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4295 pos
== buf
? "" : " ");
4296 if (os_snprintf_error(end
- pos
, ret
))
4300 #endif /* CONFIG_MESH */
4306 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4307 char *buf
, size_t buflen
)
4309 struct hostapd_channel_data
*chnl
;
4311 char *pos
, *end
, *hmode
;
4316 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4317 switch (wpa_s
->hw
.modes
[j
].mode
) {
4318 case HOSTAPD_MODE_IEEE80211B
:
4321 case HOSTAPD_MODE_IEEE80211G
:
4324 case HOSTAPD_MODE_IEEE80211A
:
4327 case HOSTAPD_MODE_IEEE80211AD
:
4333 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4334 if (os_snprintf_error(end
- pos
, ret
))
4337 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4338 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4339 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4341 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4342 if (os_snprintf_error(end
- pos
, ret
))
4346 ret
= os_snprintf(pos
, end
- pos
, "\n");
4347 if (os_snprintf_error(end
- pos
, ret
))
4356 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4357 char *buf
, size_t buflen
)
4359 struct hostapd_channel_data
*chnl
;
4361 char *pos
, *end
, *hmode
;
4366 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4367 switch (wpa_s
->hw
.modes
[j
].mode
) {
4368 case HOSTAPD_MODE_IEEE80211B
:
4371 case HOSTAPD_MODE_IEEE80211G
:
4374 case HOSTAPD_MODE_IEEE80211A
:
4377 case HOSTAPD_MODE_IEEE80211AD
:
4383 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4385 if (os_snprintf_error(end
- pos
, ret
))
4388 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4389 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4390 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4392 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4393 chnl
[i
].chan
, chnl
[i
].freq
,
4394 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4396 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4399 if (os_snprintf_error(end
- pos
, ret
))
4403 ret
= os_snprintf(pos
, end
- pos
, "\n");
4404 if (os_snprintf_error(end
- pos
, ret
))
4413 static int wpa_supplicant_ctrl_iface_get_capability(
4414 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4417 struct wpa_driver_capa capa
;
4423 /* Determine whether or not strict checking was requested */
4424 len
= os_strlcpy(field
, _field
, sizeof(field
));
4425 if (len
>= sizeof(field
))
4427 strict
= os_strchr(field
, ' ');
4428 if (strict
!= NULL
) {
4430 if (os_strcmp(strict
, "strict") != 0)
4434 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4435 field
, strict
? strict
: "");
4437 if (os_strcmp(field
, "eap") == 0) {
4438 return eap_get_names(buf
, buflen
);
4441 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4443 if (os_strcmp(field
, "pairwise") == 0)
4444 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4447 if (os_strcmp(field
, "group") == 0)
4448 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4451 if (os_strcmp(field
, "group_mgmt") == 0)
4452 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4455 if (os_strcmp(field
, "key_mgmt") == 0)
4456 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4459 if (os_strcmp(field
, "proto") == 0)
4460 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4463 if (os_strcmp(field
, "auth_alg") == 0)
4464 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4465 &capa
, buf
, buflen
);
4467 if (os_strcmp(field
, "modes") == 0)
4468 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4471 if (os_strcmp(field
, "channels") == 0)
4472 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4474 if (os_strcmp(field
, "freq") == 0)
4475 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4478 if (os_strcmp(field
, "tdls") == 0)
4479 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4480 #endif /* CONFIG_TDLS */
4483 if (os_strcmp(field
, "erp") == 0) {
4484 res
= os_snprintf(buf
, buflen
, "ERP");
4485 if (os_snprintf_error(buflen
, res
))
4489 #endif /* CONFIG_EPR */
4492 if (os_strcmp(field
, "fips") == 0) {
4493 res
= os_snprintf(buf
, buflen
, "FIPS");
4494 if (os_snprintf_error(buflen
, res
))
4498 #endif /* CONFIG_FIPS */
4501 if (os_strcmp(field
, "acs") == 0) {
4502 res
= os_snprintf(buf
, buflen
, "ACS");
4503 if (os_snprintf_error(buflen
, res
))
4507 #endif /* CONFIG_ACS */
4510 if (os_strcmp(field
, "fils") == 0) {
4511 #ifdef CONFIG_FILS_SK_PFS
4512 if (wpa_is_fils_supported(wpa_s
) &&
4513 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4514 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4515 if (os_snprintf_error(buflen
, res
))
4519 #endif /* CONFIG_FILS_SK_PFS */
4521 if (wpa_is_fils_supported(wpa_s
)) {
4522 res
= os_snprintf(buf
, buflen
, "FILS");
4523 if (os_snprintf_error(buflen
, res
))
4528 #endif /* CONFIG_FILS */
4530 if (os_strcmp(field
, "multibss") == 0 && wpa_s
->multi_bss_support
) {
4531 res
= os_snprintf(buf
, buflen
, "MULTIBSS-STA");
4532 if (os_snprintf_error(buflen
, res
))
4538 if (os_strcmp(field
, "dpp") == 0) {
4540 res
= os_snprintf(buf
, buflen
, "DPP=2");
4541 #else /* CONFIG_DPP2 */
4542 res
= os_snprintf(buf
, buflen
, "DPP=1");
4543 #endif /* CONFIG_DPP2 */
4544 if (os_snprintf_error(buflen
, res
))
4548 #endif /* CONFIG_DPP */
4550 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4557 #ifdef CONFIG_INTERWORKING
4558 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4559 struct wpabuf
*data
)
4569 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4570 if (os_snprintf_error(end
- pos
, ret
))
4574 d
= wpabuf_head_u8(data
);
4575 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4576 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4577 if (os_snprintf_error(end
- pos
, ret
))
4582 ret
= os_snprintf(pos
, end
- pos
, "\n");
4583 if (os_snprintf_error(end
- pos
, ret
))
4589 #endif /* CONFIG_INTERWORKING */
4593 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4596 const u8
*ie
, *ie_end
;
4600 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4603 ie_end
= ie
+ 2 + ie
[1];
4605 if (ie_end
- ie
< 2)
4608 info
= WPA_GET_LE16(ie
);
4610 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4611 if (os_snprintf_error(end
- pos
, ret
))
4615 if (info
& BIT(7)) {
4616 /* Cache Identifier Included */
4617 if (ie_end
- ie
< 2)
4619 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4621 if (os_snprintf_error(end
- pos
, ret
))
4627 if (info
& BIT(8)) {
4628 /* HESSID Included */
4629 if (ie_end
- ie
< ETH_ALEN
)
4631 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4633 if (os_snprintf_error(end
- pos
, ret
))
4639 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4641 if (ie_end
- ie
< realms
* 2)
4643 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4644 if (os_snprintf_error(end
- pos
, ret
))
4648 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4653 ret
= os_snprintf(pos
, end
- pos
, "\n");
4654 if (os_snprintf_error(end
- pos
, ret
))
4661 #endif /* CONFIG_FILS */
4664 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4665 unsigned long mask
, char *buf
, size_t buflen
)
4670 const u8
*ie
, *ie2
, *osen_ie
, *mesh
, *owe
;
4675 if (mask
& WPA_BSS_MASK_ID
) {
4676 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4677 if (os_snprintf_error(end
- pos
, ret
))
4682 if (mask
& WPA_BSS_MASK_BSSID
) {
4683 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4684 MAC2STR(bss
->bssid
));
4685 if (os_snprintf_error(end
- pos
, ret
))
4690 if (mask
& WPA_BSS_MASK_FREQ
) {
4691 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4692 if (os_snprintf_error(end
- pos
, ret
))
4697 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4698 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4700 if (os_snprintf_error(end
- pos
, ret
))
4705 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4706 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4708 if (os_snprintf_error(end
- pos
, ret
))
4713 if (mask
& WPA_BSS_MASK_QUAL
) {
4714 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4715 if (os_snprintf_error(end
- pos
, ret
))
4720 if (mask
& WPA_BSS_MASK_NOISE
) {
4721 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4722 if (os_snprintf_error(end
- pos
, ret
))
4727 if (mask
& WPA_BSS_MASK_LEVEL
) {
4728 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4729 if (os_snprintf_error(end
- pos
, ret
))
4734 if (mask
& WPA_BSS_MASK_TSF
) {
4735 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4736 (unsigned long long) bss
->tsf
);
4737 if (os_snprintf_error(end
- pos
, ret
))
4742 if (mask
& WPA_BSS_MASK_AGE
) {
4743 struct os_reltime now
;
4745 os_get_reltime(&now
);
4746 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4747 (int) (now
.sec
- bss
->last_update
.sec
));
4748 if (os_snprintf_error(end
- pos
, ret
))
4753 if (mask
& WPA_BSS_MASK_IE
) {
4754 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4755 if (os_snprintf_error(end
- pos
, ret
))
4759 ie
= (const u8
*) (bss
+ 1);
4760 for (i
= 0; i
< bss
->ie_len
; i
++) {
4761 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4762 if (os_snprintf_error(end
- pos
, ret
))
4767 ret
= os_snprintf(pos
, end
- pos
, "\n");
4768 if (os_snprintf_error(end
- pos
, ret
))
4773 if (mask
& WPA_BSS_MASK_FLAGS
) {
4774 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4775 if (os_snprintf_error(end
- pos
, ret
))
4779 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4781 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4783 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4785 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4787 pos
= wpa_supplicant_ie_txt(pos
, end
,
4788 mesh
? "RSN" : "WPA2", ie2
,
4790 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4792 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4793 osen_ie
, 2 + osen_ie
[1]);
4794 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
4798 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4799 if (os_snprintf_error(end
- pos
, ret
))
4803 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4804 if (!ie
&& !ie2
&& !osen_ie
&&
4805 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4806 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4807 if (os_snprintf_error(end
- pos
, ret
))
4813 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4814 if (os_snprintf_error(end
- pos
, ret
))
4819 if (bss_is_dmg(bss
)) {
4821 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4822 if (os_snprintf_error(end
- pos
, ret
))
4825 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4826 case IEEE80211_CAP_DMG_IBSS
:
4829 case IEEE80211_CAP_DMG_AP
:
4832 case IEEE80211_CAP_DMG_PBSS
:
4839 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4840 if (os_snprintf_error(end
- pos
, ret
))
4844 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4845 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4846 if (os_snprintf_error(end
- pos
, ret
))
4850 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4851 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4852 if (os_snprintf_error(end
- pos
, ret
))
4857 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4858 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4859 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4860 if (os_snprintf_error(end
- pos
, ret
))
4865 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4866 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4867 if (os_snprintf_error(end
- pos
, ret
))
4871 #endif /* CONFIG_HS20 */
4873 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4874 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4875 if (os_snprintf_error(end
- pos
, ret
))
4879 #endif /* CONFIG_FILS */
4881 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
4882 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
4883 if (os_snprintf_error(end
- pos
, ret
))
4887 #endif /* CONFIG_FST */
4888 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
4889 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
4890 if (os_snprintf_error(end
- pos
, ret
))
4895 ret
= os_snprintf(pos
, end
- pos
, "\n");
4896 if (os_snprintf_error(end
- pos
, ret
))
4901 if (mask
& WPA_BSS_MASK_SSID
) {
4902 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4903 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4904 if (os_snprintf_error(end
- pos
, ret
))
4910 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4911 ie
= (const u8
*) (bss
+ 1);
4912 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4913 if (ret
>= end
- pos
)
4918 #endif /* CONFIG_WPS */
4921 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4922 ie
= (const u8
*) (bss
+ 1);
4923 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4924 if (ret
>= end
- pos
)
4929 #endif /* CONFIG_P2P */
4931 #ifdef CONFIG_WIFI_DISPLAY
4932 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4934 ie
= (const u8
*) (bss
+ 1);
4935 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4936 WFD_IE_VENDOR_TYPE
);
4938 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4939 if (os_snprintf_error(end
- pos
, ret
)) {
4945 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4950 ret
= os_snprintf(pos
, end
- pos
, "\n");
4951 if (os_snprintf_error(end
- pos
, ret
))
4956 #endif /* CONFIG_WIFI_DISPLAY */
4958 #ifdef CONFIG_INTERWORKING
4959 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4960 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4961 struct wpa_bss_anqp_elem
*elem
;
4963 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4964 anqp
->capability_list
);
4965 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4967 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4968 anqp
->network_auth_type
);
4969 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4970 anqp
->roaming_consortium
);
4971 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4972 anqp
->ip_addr_type_availability
);
4973 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4975 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4976 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4978 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4979 anqp
->fils_realm_info
);
4981 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4982 anqp
->hs20_capability_list
);
4983 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4984 anqp
->hs20_operator_friendly_name
);
4985 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4986 anqp
->hs20_wan_metrics
);
4987 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4988 anqp
->hs20_connection_capability
);
4989 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4990 anqp
->hs20_operating_class
);
4991 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4992 anqp
->hs20_osu_providers_list
);
4993 pos
= anqp_add_hex(pos
, end
, "hs20_operator_icon_metadata",
4994 anqp
->hs20_operator_icon_metadata
);
4995 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_nai_list",
4996 anqp
->hs20_osu_providers_nai_list
);
4997 #endif /* CONFIG_HS20 */
4999 dl_list_for_each(elem
, &anqp
->anqp_elems
,
5000 struct wpa_bss_anqp_elem
, list
) {
5003 os_snprintf(title
, sizeof(title
), "anqp[%u]",
5005 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
5008 #endif /* CONFIG_INTERWORKING */
5011 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
5012 ie
= (const u8
*) (bss
+ 1);
5013 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
5014 if (ret
>= end
- pos
)
5019 #endif /* CONFIG_MESH */
5021 if (mask
& WPA_BSS_MASK_SNR
) {
5022 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
5023 if (os_snprintf_error(end
- pos
, ret
))
5028 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
5029 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
5030 bss
->est_throughput
);
5031 if (os_snprintf_error(end
- pos
, ret
))
5037 if (mask
& WPA_BSS_MASK_FST
) {
5038 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
5039 if (ret
< 0 || ret
>= end
- pos
)
5043 #endif /* CONFIG_FST */
5045 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
5046 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
5047 bss
->last_update_idx
);
5048 if (os_snprintf_error(end
- pos
, ret
))
5053 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
5054 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
5055 if (os_snprintf_error(end
- pos
, ret
))
5059 ie
= (const u8
*) (bss
+ 1);
5061 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
5062 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
5063 if (os_snprintf_error(end
- pos
, ret
))
5068 ret
= os_snprintf(pos
, end
- pos
, "\n");
5069 if (os_snprintf_error(end
- pos
, ret
))
5075 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
5076 ret
= print_fils_indication(bss
, pos
, end
);
5081 #endif /* CONFIG_FILS */
5083 if (mask
& WPA_BSS_MASK_DELIM
) {
5084 ret
= os_snprintf(pos
, end
- pos
, "====\n");
5085 if (os_snprintf_error(end
- pos
, ret
))
5094 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
5095 const char *cmd
, char *buf
,
5100 struct wpa_bss
*bss
;
5101 struct wpa_bss
*bsslast
= NULL
;
5102 struct dl_list
*next
;
5105 char *ctmp
, *end
= buf
+ buflen
;
5106 unsigned long mask
= WPA_BSS_MASK_ALL
;
5108 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
5109 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
5110 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
5112 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
5114 } else { /* N1-N2 */
5115 unsigned int id1
, id2
;
5117 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
5118 wpa_printf(MSG_INFO
, "Wrong BSS range "
5123 if (*(cmd
+ 6) == '-')
5126 id1
= atoi(cmd
+ 6);
5128 if (*ctmp
>= '0' && *ctmp
<= '9')
5131 id2
= (unsigned int) -1;
5132 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
5133 if (id2
== (unsigned int) -1)
5134 bsslast
= dl_list_last(&wpa_s
->bss_id
,
5138 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
5139 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
5140 struct wpa_bss
*tmp
= bss
;
5142 next
= tmp
->list_id
.next
;
5143 if (next
== &wpa_s
->bss_id
)
5145 tmp
= dl_list_entry(
5146 next
, struct wpa_bss
,
5155 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
5156 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5157 else if (os_strncmp(cmd
, "LAST", 4) == 0)
5158 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5159 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
5161 bss
= wpa_bss_get_id(wpa_s
, i
);
5162 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
5164 bss
= wpa_bss_get_id(wpa_s
, i
);
5166 next
= bss
->list_id
.next
;
5167 if (next
== &wpa_s
->bss_id
)
5170 bss
= dl_list_entry(next
, struct wpa_bss
,
5173 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
5174 bss
= wpa_s
->current_bss
;
5176 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
5177 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
5178 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
5181 #endif /* CONFIG_P2P */
5182 } else if (hwaddr_aton(cmd
, bssid
) == 0)
5183 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5185 struct wpa_bss
*tmp
;
5188 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
5198 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
5199 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
5201 mask
= WPA_BSS_MASK_ALL
;
5207 if (bsslast
== NULL
)
5210 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
5214 if (bss
== bsslast
) {
5215 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
5216 (bss
== dl_list_last(&wpa_s
->bss_id
,
5217 struct wpa_bss
, list_id
))) {
5220 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
5222 if (os_snprintf_error(end
- buf
+ 5, res
)) {
5223 wpa_printf(MSG_DEBUG
,
5224 "Could not add end delim");
5229 next
= bss
->list_id
.next
;
5230 if (next
== &wpa_s
->bss_id
)
5232 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
5233 } while (bss
&& len
);
5239 static int wpa_supplicant_ctrl_iface_ap_scan(
5240 struct wpa_supplicant
*wpa_s
, char *cmd
)
5242 int ap_scan
= atoi(cmd
);
5243 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5247 static int wpa_supplicant_ctrl_iface_scan_interval(
5248 struct wpa_supplicant
*wpa_s
, char *cmd
)
5250 int scan_int
= atoi(cmd
);
5251 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5255 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5256 struct wpa_supplicant
*wpa_s
, char *cmd
)
5258 int expire_age
= atoi(cmd
);
5259 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5263 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5264 struct wpa_supplicant
*wpa_s
, char *cmd
)
5266 int expire_count
= atoi(cmd
);
5267 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5271 static void wpa_supplicant_ctrl_iface_bss_flush(
5272 struct wpa_supplicant
*wpa_s
, char *cmd
)
5274 int flush_age
= atoi(cmd
);
5277 wpa_bss_flush(wpa_s
);
5279 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5283 #ifdef CONFIG_TESTING_OPTIONS
5284 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5286 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5287 /* MLME-DELETEKEYS.request */
5288 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
5289 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
5290 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
5291 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
5292 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
5293 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
5295 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5297 /* MLME-SETPROTECTION.request(None) */
5298 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5299 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5300 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5301 wpa_sm_drop_sa(wpa_s
->wpa
);
5303 #endif /* CONFIG_TESTING_OPTIONS */
5306 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5309 #ifdef CONFIG_NO_SCAN_PROCESSING
5311 #else /* CONFIG_NO_SCAN_PROCESSING */
5313 struct wpa_bss
*bss
;
5314 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5316 if (hwaddr_aton(addr
, bssid
)) {
5317 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5318 "address '%s'", addr
);
5322 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5325 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5326 "configuration known for the target AP");
5330 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5332 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5338 * TODO: Find best network configuration block from configuration to
5339 * allow roaming to other networks
5342 wpa_s
->reassociate
= 1;
5343 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5346 #endif /* CONFIG_NO_SCAN_PROCESSING */
5351 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5353 unsigned int timeout
= atoi(cmd
);
5354 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5355 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5356 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5358 unsigned int search_delay
;
5359 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5363 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5364 wpa_dbg(wpa_s
, MSG_INFO
,
5365 "Reject P2P_FIND since interface is disabled");
5368 if (os_strstr(cmd
, "type=social"))
5369 type
= P2P_FIND_ONLY_SOCIAL
;
5370 else if (os_strstr(cmd
, "type=progressive"))
5371 type
= P2P_FIND_PROGRESSIVE
;
5373 pos
= os_strstr(cmd
, "dev_id=");
5376 if (hwaddr_aton(pos
, dev_id
))
5381 pos
= os_strstr(cmd
, "dev_type=");
5384 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5386 _dev_type
= dev_type
;
5389 pos
= os_strstr(cmd
, "delay=");
5392 search_delay
= atoi(pos
);
5394 search_delay
= wpas_p2p_search_delay(wpa_s
);
5396 pos
= os_strstr(cmd
, "freq=");
5404 /* Must be searched for last, because it adds nul termination */
5405 pos
= os_strstr(cmd
, " seek=");
5408 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5411 _seek
[seek_count
++] = pos
;
5413 term
= os_strchr(pos
, ' ');
5417 pos
= os_strstr(term
+ 1, "seek=");
5421 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5426 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5427 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5431 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5433 const char *last
= NULL
;
5438 /* Expected predefined CPT names delimited by ':' */
5439 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5440 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5441 wpa_printf(MSG_ERROR
,
5442 "P2PS: CPT name list is too long, expected up to %d names",
5443 P2PS_FEATURE_CAPAB_CPT_MAX
);
5448 token_len
= last
- token
;
5450 if (token_len
== 3 &&
5451 os_memcmp(token
, "UDP", token_len
) == 0) {
5452 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5453 } else if (token_len
== 3 &&
5454 os_memcmp(token
, "MAC", token_len
) == 0) {
5455 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5457 wpa_printf(MSG_ERROR
,
5458 "P2PS: Unsupported CPT name '%s'", token
);
5463 if (isblank((unsigned char) *last
)) {
5473 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5475 struct p2ps_provision
*p2ps_prov
;
5477 size_t info_len
= 0;
5479 u8 role
= P2PS_SETUP_NONE
;
5480 long long unsigned val
;
5483 pos
= os_strstr(cmd
, "info=");
5486 info_len
= os_strlen(pos
);
5489 info
= os_malloc(info_len
+ 1);
5491 info_len
= utf8_unescape(pos
, info_len
,
5492 info
, info_len
+ 1);
5498 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5499 if (p2ps_prov
== NULL
) {
5505 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5506 p2ps_prov
->info
[info_len
] = '\0';
5510 pos
= os_strstr(cmd
, "status=");
5512 p2ps_prov
->status
= atoi(pos
+ 7);
5514 p2ps_prov
->status
= -1;
5516 pos
= os_strstr(cmd
, "adv_id=");
5517 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5519 p2ps_prov
->adv_id
= val
;
5521 pos
= os_strstr(cmd
, "method=");
5523 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5525 p2ps_prov
->method
= 0;
5527 pos
= os_strstr(cmd
, "session=");
5528 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5530 p2ps_prov
->session_id
= val
;
5532 pos
= os_strstr(cmd
, "adv_mac=");
5533 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5536 pos
= os_strstr(cmd
, "session_mac=");
5537 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5540 pos
= os_strstr(cmd
, "cpt=");
5542 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5543 p2ps_prov
->cpt_priority
))
5546 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5549 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5550 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5552 /* force conncap with tstCap (no sanity checks) */
5553 pos
= os_strstr(cmd
, "tstCap=");
5555 role
= strtol(pos
+ 7, NULL
, 16);
5557 pos
= os_strstr(cmd
, "role=");
5559 role
= strtol(pos
+ 5, NULL
, 16);
5560 if (role
!= P2PS_SETUP_CLIENT
&&
5561 role
!= P2PS_SETUP_GROUP_OWNER
)
5562 role
= P2PS_SETUP_NONE
;
5565 p2ps_prov
->role
= role
;
5575 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5578 struct p2ps_provision
*p2ps_prov
;
5581 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5583 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5585 if (hwaddr_aton(cmd
, addr
))
5592 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5596 if (p2ps_prov
->status
< 0) {
5601 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5606 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5609 struct p2ps_provision
*p2ps_prov
;
5612 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5613 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5616 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5617 if (hwaddr_aton(cmd
, addr
))
5624 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5628 p2ps_prov
->pd_seeker
= 1;
5630 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5635 static int parse_freq(int chwidth
, int freq2
)
5640 return CHANWIDTH_80P80MHZ
;
5646 return CHANWIDTH_USE_HT
;
5648 return CHANWIDTH_80MHZ
;
5650 return CHANWIDTH_160MHZ
;
5652 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5659 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5660 char *buf
, size_t buflen
)
5665 enum p2p_wps_method wps_method
;
5668 int persistent_group
, persistent_id
= -1;
5675 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5677 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5678 size_t group_ssid_len
= 0;
5681 if (!wpa_s
->global
->p2p_init_wpa_s
)
5683 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5684 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5685 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5686 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5689 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5690 * [persistent|persistent=<network id>]
5691 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5692 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
5694 if (hwaddr_aton(cmd
, addr
))
5702 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5703 pos2
= os_strstr(pos
, " persistent=");
5705 struct wpa_ssid
*ssid
;
5706 persistent_id
= atoi(pos2
+ 12);
5707 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5708 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5709 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5710 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5711 "SSID id=%d for persistent P2P group (GO)",
5716 join
= os_strstr(pos
, " join") != NULL
;
5717 auth
= os_strstr(pos
, " auth") != NULL
;
5718 automatic
= os_strstr(pos
, " auto") != NULL
;
5719 pd
= os_strstr(pos
, " provdisc") != NULL
;
5720 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5721 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5723 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
5724 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
5726 pos2
= os_strstr(pos
, " go_intent=");
5729 go_intent
= atoi(pos2
);
5730 if (go_intent
< 0 || go_intent
> 15)
5734 pos2
= os_strstr(pos
, " freq=");
5742 pos2
= os_strstr(pos
, " freq2=");
5744 freq2
= atoi(pos2
+ 7);
5746 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5748 chwidth
= atoi(pos2
+ 18);
5750 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5751 if (max_oper_chwidth
< 0)
5754 pos2
= os_strstr(pos
, " ssid=");
5759 end
= os_strchr(pos2
, ' ');
5761 group_ssid_len
= os_strlen(pos2
) / 2;
5763 group_ssid_len
= (end
- pos2
) / 2;
5764 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5765 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5767 group_ssid
= _group_ssid
;
5770 if (os_strncmp(pos
, "pin", 3) == 0) {
5771 /* Request random PIN (to be displayed) and enable the PIN */
5772 wps_method
= WPS_PIN_DISPLAY
;
5773 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5774 wps_method
= WPS_PBC
;
5775 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5776 wps_method
= WPS_P2PS
;
5779 pos
= os_strchr(pin
, ' ');
5780 wps_method
= WPS_PIN_KEYPAD
;
5783 if (os_strncmp(pos
, "display", 7) == 0)
5784 wps_method
= WPS_PIN_DISPLAY
;
5786 if (!wps_pin_str_valid(pin
)) {
5787 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5792 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5793 persistent_group
, automatic
, join
,
5794 auth
, go_intent
, freq
, freq2
, persistent_id
,
5795 pd
, ht40
, vht
, max_oper_chwidth
, he
, edmg
,
5796 group_ssid
, group_ssid_len
);
5797 if (new_pin
== -2) {
5798 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5801 if (new_pin
== -3) {
5802 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5807 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5808 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5809 if (os_snprintf_error(buflen
, ret
))
5814 os_memcpy(buf
, "OK\n", 3);
5819 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5821 unsigned int timeout
= atoi(cmd
);
5822 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5823 wpa_dbg(wpa_s
, MSG_INFO
,
5824 "Reject P2P_LISTEN since interface is disabled");
5827 return wpas_p2p_listen(wpa_s
, timeout
);
5831 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5835 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5837 /* <addr> <config method> [join|auto] */
5839 if (hwaddr_aton(cmd
, addr
))
5847 if (os_strstr(pos
, " join") != NULL
)
5848 use
= WPAS_P2P_PD_FOR_JOIN
;
5849 else if (os_strstr(pos
, " auto") != NULL
)
5850 use
= WPAS_P2P_PD_AUTO
;
5852 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5856 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5859 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5861 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5862 ssid
->passphrase
== NULL
)
5865 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5866 return os_strlen(buf
);
5870 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5871 char *buf
, size_t buflen
)
5875 u8 dst_buf
[ETH_ALEN
], *dst
;
5876 struct wpabuf
*tlvs
;
5880 if (hwaddr_aton(cmd
, dst_buf
))
5883 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5884 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5891 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5894 if (hexstr2bin(pos
, &version
, 1) < 0)
5900 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5901 #ifdef CONFIG_WIFI_DISPLAY
5902 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5903 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5904 #endif /* CONFIG_WIFI_DISPLAY */
5905 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5907 char *svc_info
= NULL
;
5911 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5914 pos
= os_strchr(pos
, ' ');
5915 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5920 pos
= os_strchr(svc_str
, ' ');
5925 /* All remaining data is the svc_info string */
5926 if (pos
&& pos
[0] && pos
[0] != ' ') {
5927 len
= os_strlen(pos
);
5929 /* Unescape in place */
5930 len
= utf8_unescape(pos
, len
, pos
, len
);
5937 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5940 len
= os_strlen(pos
);
5944 tlvs
= wpabuf_alloc(len
);
5947 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5952 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5957 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5958 if (os_snprintf_error(buflen
, res
))
5964 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5967 long long unsigned val
;
5969 if (sscanf(cmd
, "%llx", &val
) != 1)
5972 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5976 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5981 struct wpabuf
*resp_tlvs
;
5985 pos
= os_strchr(cmd
, ' ');
5993 if (hwaddr_aton(pos
, dst
))
6000 pos2
= os_strchr(pos
, ' ');
6004 dialog_token
= atoi(pos
);
6006 len
= os_strlen(pos2
);
6010 resp_tlvs
= wpabuf_alloc(len
);
6011 if (resp_tlvs
== NULL
)
6013 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
6014 wpabuf_free(resp_tlvs
);
6018 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
6019 wpabuf_free(resp_tlvs
);
6024 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
6027 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
6029 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
6034 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
6039 struct wpabuf
*query
, *resp
;
6041 pos
= os_strchr(cmd
, ' ');
6046 len
= os_strlen(cmd
);
6050 query
= wpabuf_alloc(len
);
6053 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6058 len
= os_strlen(pos
);
6064 resp
= wpabuf_alloc(len
);
6069 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
6075 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
6084 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6089 pos
= os_strchr(cmd
, ' ');
6094 if (hexstr2bin(cmd
, &version
, 1) < 0)
6097 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
6101 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
6102 u8 replace
, char *cmd
)
6106 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
6107 char *svc_info
= NULL
;
6109 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
6111 pos
= os_strchr(cmd
, ' ');
6116 /* Auto-Accept value is mandatory, and must be one of the
6117 * single values (0, 1, 2, 4) */
6118 auto_accept
= atoi(cmd
);
6119 switch (auto_accept
) {
6120 case P2PS_SETUP_NONE
: /* No auto-accept */
6121 case P2PS_SETUP_NEW
:
6122 case P2PS_SETUP_CLIENT
:
6123 case P2PS_SETUP_GROUP_OWNER
:
6129 /* Advertisement ID is mandatory */
6131 pos
= os_strchr(cmd
, ' ');
6136 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6137 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
6140 /* Only allow replacements if exist, and adds if not */
6141 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
6149 /* svc_state between 0 - 0xff is mandatory */
6150 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
6153 pos
= os_strchr(pos
, ' ');
6157 /* config_methods is mandatory */
6159 if (sscanf(pos
, "%x", &config_methods
) != 1)
6162 if (!(config_methods
&
6163 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
6166 pos
= os_strchr(pos
, ' ');
6173 /* Advertisement string is mandatory */
6174 if (!pos
[0] || pos
[0] == ' ')
6177 /* Terminate svc string */
6178 pos
= os_strchr(pos
, ' ');
6182 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
6184 pos
= os_strchr(pos
, ' ');
6188 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
6191 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
6195 /* Service and Response Information are optional */
6196 if (pos
&& pos
[0]) {
6199 /* Note the bare ' included, which cannot exist legally
6200 * in unescaped string. */
6201 svc_info
= os_strstr(pos
, "svc_info='");
6205 len
= os_strlen(svc_info
);
6206 utf8_unescape(svc_info
, len
, svc_info
, len
);
6210 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
6211 (u8
) svc_state
, (u16
) config_methods
,
6212 svc_info
, cpt_prio
);
6216 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6220 pos
= os_strchr(cmd
, ' ');
6225 if (os_strcmp(cmd
, "bonjour") == 0)
6226 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
6227 if (os_strcmp(cmd
, "upnp") == 0)
6228 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
6229 if (os_strcmp(cmd
, "asp") == 0)
6230 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
6231 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6236 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
6240 struct wpabuf
*query
;
6243 len
= os_strlen(cmd
);
6247 query
= wpabuf_alloc(len
);
6250 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6255 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6261 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6266 pos
= os_strchr(cmd
, ' ');
6271 if (hexstr2bin(cmd
, &version
, 1) < 0)
6274 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6278 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6282 if (os_strcmp(cmd
, "all") == 0) {
6283 wpas_p2p_service_flush_asp(wpa_s
);
6287 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6290 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6294 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6298 pos
= os_strchr(cmd
, ' ');
6303 if (os_strcmp(cmd
, "bonjour") == 0)
6304 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6305 if (os_strcmp(cmd
, "upnp") == 0)
6306 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6307 if (os_strcmp(cmd
, "asp") == 0)
6308 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6309 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6314 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6318 pos
= os_strchr(cmd
, ' ');
6323 if (os_strcmp(cmd
, "asp") == 0)
6324 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6326 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6331 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6337 if (hwaddr_aton(cmd
, addr
))
6340 return wpas_p2p_reject(wpa_s
, addr
);
6344 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6348 struct wpa_ssid
*ssid
;
6349 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6350 int freq
= 0, pref_freq
= 0;
6351 int ht40
, vht
, he
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6355 pos
= os_strstr(cmd
, " peer=");
6358 if (hwaddr_aton(pos
, peer
))
6362 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6363 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6364 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6365 "for persistent P2P group",
6370 pos
= os_strstr(cmd
, " freq=");
6378 pos
= os_strstr(cmd
, " pref=");
6381 pref_freq
= atoi(pos
);
6386 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6387 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6389 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
6390 edmg
= (os_strstr(cmd
, " edmg") != NULL
) || wpa_s
->conf
->p2p_go_edmg
;
6392 pos
= os_strstr(cmd
, "freq2=");
6394 freq2
= atoi(pos
+ 6);
6396 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6398 chwidth
= atoi(pos
+ 18);
6400 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6401 if (max_oper_chwidth
< 0)
6404 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6405 max_oper_chwidth
, pref_freq
, he
, edmg
);
6409 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6412 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6414 pos
= os_strstr(cmd
, " peer=");
6420 if (hwaddr_aton(pos
, peer
)) {
6421 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6425 pos
= os_strstr(pos
, " go_dev_addr=");
6428 if (hwaddr_aton(pos
, go_dev_addr
)) {
6429 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6433 go_dev
= go_dev_addr
;
6436 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6440 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6442 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6443 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6444 if (os_strncmp(cmd
, "group=", 6) == 0)
6445 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6451 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6452 int id
, int freq
, int vht_center_freq2
,
6453 int ht40
, int vht
, int vht_chwidth
,
6456 struct wpa_ssid
*ssid
;
6458 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6459 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6460 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6461 "for persistent P2P group",
6466 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6467 vht_center_freq2
, 0, ht40
, vht
,
6468 vht_chwidth
, he
, edmg
,
6473 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6475 int freq
= 0, persistent
= 0, group_id
= -1;
6476 int vht
= wpa_s
->conf
->p2p_go_vht
;
6477 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6478 int he
= wpa_s
->conf
->p2p_go_he
;
6479 int edmg
= wpa_s
->conf
->p2p_go_edmg
;
6480 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6481 char *token
, *context
= NULL
;
6484 #endif /* CONFIG_ACS */
6486 while ((token
= str_token(cmd
, " ", &context
))) {
6487 if (sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6488 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6489 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6492 } else if (os_strcmp(token
, "freq=acs") == 0) {
6494 #endif /* CONFIG_ACS */
6495 } else if (sscanf(token
, "freq=%d", &freq
) == 1) {
6497 } else if (os_strcmp(token
, "ht40") == 0) {
6499 } else if (os_strcmp(token
, "vht") == 0) {
6502 } else if (os_strcmp(token
, "he") == 0) {
6504 } else if (os_strcmp(token
, "edmg") == 0) {
6506 } else if (os_strcmp(token
, "persistent") == 0) {
6509 wpa_printf(MSG_DEBUG
,
6510 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6517 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_ACS_OFFLOAD
) &&
6518 (acs
|| freq
== 2 || freq
== 5)) {
6519 if (freq
== 2 && wpa_s
->best_24_freq
<= 0) {
6520 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211G
;
6521 wpa_s
->p2p_go_do_acs
= 1;
6523 } else if (freq
== 5 && wpa_s
->best_5_freq
<= 0) {
6524 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211A
;
6525 wpa_s
->p2p_go_do_acs
= 1;
6528 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211ANY
;
6529 wpa_s
->p2p_go_do_acs
= 1;
6532 wpa_s
->p2p_go_do_acs
= 0;
6534 #endif /* CONFIG_ACS */
6536 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6537 if (max_oper_chwidth
< 0)
6541 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6542 freq
, freq2
, ht40
, vht
,
6543 max_oper_chwidth
, he
,
6546 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6547 max_oper_chwidth
, he
, edmg
);
6551 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6552 char *buf
, size_t buflen
)
6554 u8 dev_addr
[ETH_ALEN
];
6555 struct wpa_ssid
*ssid
;
6559 ssid
= wpa_s
->current_ssid
;
6560 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6561 hwaddr_aton(cmd
, dev_addr
))
6564 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6567 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6568 if (os_snprintf_error(buflen
, res
))
6574 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6575 const u8
*p2p_dev_addr
)
6577 struct wpa_supplicant
*wpa_s
;
6579 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6580 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6588 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6589 char *buf
, size_t buflen
)
6591 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6593 const struct p2p_peer_info
*info
;
6595 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6596 struct wpa_ssid
*ssid
;
6599 if (!wpa_s
->global
->p2p
)
6602 if (os_strcmp(cmd
, "FIRST") == 0) {
6605 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6606 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6611 if (hwaddr_aton(cmd
, addr
) < 0)
6617 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6620 group_capab
= info
->group_capab
;
6623 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6624 wpa_printf(MSG_DEBUG
,
6625 "P2P: Could not find any BSS with p2p_dev_addr "
6626 MACSTR
", hence override group_capab from 0x%x to 0",
6627 MAC2STR(info
->p2p_device_addr
), group_capab
);
6634 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6640 "serial_number=%s\n"
6641 "config_methods=0x%x\n"
6643 "group_capab=0x%x\n"
6645 MAC2STR(info
->p2p_device_addr
),
6646 wps_dev_type_bin2str(info
->pri_dev_type
,
6647 devtype
, sizeof(devtype
)),
6652 info
->serial_number
,
6653 info
->config_methods
,
6657 if (os_snprintf_error(end
- pos
, res
))
6661 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6664 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6665 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6666 wps_dev_type_bin2str(t
, devtype
,
6668 if (os_snprintf_error(end
- pos
, res
))
6673 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6675 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6676 if (os_snprintf_error(end
- pos
, res
))
6681 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6686 if (info
->vendor_elems
) {
6687 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6688 if (os_snprintf_error(end
- pos
, res
))
6692 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6693 wpabuf_head(info
->vendor_elems
),
6694 wpabuf_len(info
->vendor_elems
));
6696 res
= os_snprintf(pos
, end
- pos
, "\n");
6697 if (os_snprintf_error(end
- pos
, res
))
6706 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6711 if (wpa_s
->global
->p2p
== NULL
)
6714 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6717 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6718 struct wpa_freq_range
*freq
;
6719 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6720 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6721 freq
->min
, freq
->max
);
6724 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6729 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6733 if (wpa_s
->global
->p2p
== NULL
)
6736 param
= os_strchr(cmd
, ' ');
6741 if (os_strcmp(cmd
, "discoverability") == 0) {
6742 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6747 if (os_strcmp(cmd
, "managed") == 0) {
6748 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6752 if (os_strcmp(cmd
, "listen_channel") == 0) {
6754 u8 channel
, op_class
;
6756 channel
= atoi(param
);
6757 pos
= os_strchr(param
, ' ');
6758 op_class
= pos
? atoi(pos
) : 81;
6760 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6764 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6765 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6769 if (os_strcmp(cmd
, "noa") == 0) {
6771 int count
, start
, duration
;
6772 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6773 count
= atoi(param
);
6774 pos
= os_strchr(param
, ',');
6779 pos
= os_strchr(pos
, ',');
6783 duration
= atoi(pos
);
6784 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6786 if (count
== 0 && duration
> 0)
6788 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6789 "start=%d duration=%d", count
, start
, duration
);
6790 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6793 if (os_strcmp(cmd
, "ps") == 0)
6794 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6796 if (os_strcmp(cmd
, "oppps") == 0)
6797 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6799 if (os_strcmp(cmd
, "ctwindow") == 0)
6800 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6802 if (os_strcmp(cmd
, "disabled") == 0) {
6803 wpa_s
->global
->p2p_disabled
= atoi(param
);
6804 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6805 wpa_s
->global
->p2p_disabled
?
6806 "disabled" : "enabled");
6807 if (wpa_s
->global
->p2p_disabled
) {
6808 wpas_p2p_stop_find(wpa_s
);
6809 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6810 p2p_flush(wpa_s
->global
->p2p
);
6815 if (os_strcmp(cmd
, "conc_pref") == 0) {
6816 if (os_strcmp(param
, "sta") == 0)
6817 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6818 else if (os_strcmp(param
, "p2p") == 0)
6819 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6821 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6824 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6829 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6830 wpa_s
->force_long_sd
= atoi(param
);
6834 if (os_strcmp(cmd
, "peer_filter") == 0) {
6836 if (hwaddr_aton(param
, addr
))
6838 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6842 if (os_strcmp(cmd
, "cross_connect") == 0)
6843 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6845 if (os_strcmp(cmd
, "go_apsd") == 0) {
6846 if (os_strcmp(param
, "disable") == 0)
6847 wpa_s
->set_ap_uapsd
= 0;
6849 wpa_s
->set_ap_uapsd
= 1;
6850 wpa_s
->ap_uapsd
= atoi(param
);
6855 if (os_strcmp(cmd
, "client_apsd") == 0) {
6856 if (os_strcmp(param
, "disable") == 0)
6857 wpa_s
->set_sta_uapsd
= 0;
6861 /* format: BE,BK,VI,VO;max SP Length */
6863 pos
= os_strchr(param
, ',');
6868 pos
= os_strchr(pos
, ',');
6873 pos
= os_strchr(pos
, ',');
6878 /* ignore max SP Length for now */
6880 wpa_s
->set_sta_uapsd
= 1;
6881 wpa_s
->sta_uapsd
= 0;
6883 wpa_s
->sta_uapsd
|= BIT(0);
6885 wpa_s
->sta_uapsd
|= BIT(1);
6887 wpa_s
->sta_uapsd
|= BIT(2);
6889 wpa_s
->sta_uapsd
|= BIT(3);
6894 if (os_strcmp(cmd
, "disallow_freq") == 0)
6895 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6897 if (os_strcmp(cmd
, "disc_int") == 0) {
6898 int min_disc_int
, max_disc_int
, max_disc_tu
;
6903 min_disc_int
= atoi(pos
);
6904 pos
= os_strchr(pos
, ' ');
6909 max_disc_int
= atoi(pos
);
6910 pos
= os_strchr(pos
, ' ');
6915 max_disc_tu
= atoi(pos
);
6917 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6918 max_disc_int
, max_disc_tu
);
6921 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6922 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6926 #ifdef CONFIG_WPS_NFC
6927 if (os_strcmp(cmd
, "nfc_tag") == 0)
6928 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6929 #endif /* CONFIG_WPS_NFC */
6931 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6932 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6936 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6939 op_class
= atoi(param
);
6940 param
= os_strchr(param
, ':');
6945 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6950 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6957 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6959 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6960 wpa_s
->force_long_sd
= 0;
6962 #ifdef CONFIG_TESTING_OPTIONS
6963 os_free(wpa_s
->get_pref_freq_list_override
);
6964 wpa_s
->get_pref_freq_list_override
= NULL
;
6965 #endif /* CONFIG_TESTING_OPTIONS */
6967 wpas_p2p_stop_find(wpa_s
);
6968 wpa_s
->parent
->p2ps_method_config_any
= 0;
6969 if (wpa_s
->global
->p2p
)
6970 p2p_flush(wpa_s
->global
->p2p
);
6974 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6977 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6980 pos
= os_strchr(cmd
, ' ');
6986 pos2
= os_strchr(pos
, ' ');
6994 pos
= os_strchr(pos2
, ' ');
7002 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
7006 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
7009 unsigned int period
= 0, interval
= 0;
7012 pos
= os_strchr(cmd
, ' ');
7017 interval
= atoi(pos
);
7020 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
7024 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
7031 if (os_strncmp(pos
, "iface=", 6) == 0) {
7035 if (hwaddr_aton(pos
, peer
))
7038 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
7043 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
7045 int freq
= 0, period
= 0, interval
= 0, count
= 0;
7047 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
7049 wpa_printf(MSG_DEBUG
,
7050 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
7054 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
7057 #endif /* CONFIG_P2P */
7060 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
7062 struct wpa_freq_range_list ranges
;
7064 struct hostapd_hw_modes
*mode
;
7067 if (wpa_s
->hw
.modes
== NULL
)
7070 os_memset(&ranges
, 0, sizeof(ranges
));
7071 if (freq_range_list_parse(&ranges
, val
) < 0)
7074 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
7077 mode
= &wpa_s
->hw
.modes
[i
];
7078 for (j
= 0; j
< mode
->num_channels
; j
++) {
7081 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
7084 freq
= mode
->channels
[j
].freq
;
7085 if (!freq_range_list_includes(&ranges
, freq
))
7088 int_array_add_unique(&freqs
, freq
);
7092 os_free(ranges
.range
);
7097 #ifdef CONFIG_INTERWORKING
7099 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
7107 auto_sel
= os_strstr(param
, "auto") != NULL
;
7109 pos
= os_strstr(param
, "freq=");
7111 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
7118 return interworking_select(wpa_s
, auto_sel
, freqs
);
7122 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
7126 struct wpa_bss
*bss
;
7128 if (hwaddr_aton(dst
, bssid
)) {
7129 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
7133 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
7135 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
7140 if (bss
->ssid_len
== 0) {
7143 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
7144 " does not have SSID information", MAC2STR(bssid
));
7146 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
7148 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
7149 bss
->ssid_len
> 0) {
7157 wpa_printf(MSG_DEBUG
,
7158 "Found another matching BSS entry with SSID");
7161 return interworking_connect(wpa_s
, bss
, only_add
);
7165 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7167 u8 dst_addr
[ETH_ALEN
];
7170 #define MAX_ANQP_INFO_ID 100
7171 u16 id
[MAX_ANQP_INFO_ID
];
7174 u32 mbo_subtypes
= 0;
7176 used
= hwaddr_aton2(dst
, dst_addr
);
7182 while (num_id
< MAX_ANQP_INFO_ID
) {
7183 if (os_strncmp(pos
, "hs20:", 5) == 0) {
7185 int num
= atoi(pos
+ 5);
7186 if (num
<= 0 || num
> 31)
7188 subtypes
|= BIT(num
);
7189 #else /* CONFIG_HS20 */
7191 #endif /* CONFIG_HS20 */
7192 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
7194 int num
= atoi(pos
+ 4);
7196 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
7198 mbo_subtypes
|= BIT(num
);
7199 #else /* CONFIG_MBO */
7201 #endif /* CONFIG_MBO */
7203 id
[num_id
] = atoi(pos
);
7207 pos
= os_strchr(pos
+ 1, ',');
7213 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
7216 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
7221 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
7223 u8 dst_addr
[ETH_ALEN
];
7224 struct wpabuf
*advproto
, *query
= NULL
;
7229 used
= hwaddr_aton2(cmd
, dst_addr
);
7237 /* Advertisement Protocol ID */
7238 end
= os_strchr(pos
, ' ');
7242 len
= os_strlen(pos
);
7248 advproto
= wpabuf_alloc(len
);
7249 if (advproto
== NULL
)
7251 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
7255 /* Optional Query Request */
7260 len
= os_strlen(pos
);
7267 query
= wpabuf_alloc(len
);
7270 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
7275 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
7278 wpabuf_free(advproto
);
7285 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7292 size_t resp_len
, start
, requested_len
;
7293 struct wpabuf
*resp
;
7296 used
= hwaddr_aton2(cmd
, addr
);
7303 dialog_token
= atoi(pos
);
7305 if (wpa_s
->last_gas_resp
&&
7306 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7307 dialog_token
== wpa_s
->last_gas_dialog_token
)
7308 resp
= wpa_s
->last_gas_resp
;
7309 else if (wpa_s
->prev_gas_resp
&&
7310 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7311 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7312 resp
= wpa_s
->prev_gas_resp
;
7316 resp_len
= wpabuf_len(resp
);
7318 requested_len
= resp_len
;
7320 pos
= os_strchr(pos
, ' ');
7323 if (start
> resp_len
)
7324 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7325 pos
= os_strchr(pos
, ',');
7329 requested_len
= atoi(pos
);
7330 if (start
+ requested_len
> resp_len
)
7331 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7334 if (requested_len
* 2 + 1 > buflen
)
7335 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7337 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7340 if (start
+ requested_len
== resp_len
) {
7342 * Free memory by dropping the response after it has been
7345 if (resp
== wpa_s
->prev_gas_resp
) {
7346 wpabuf_free(wpa_s
->prev_gas_resp
);
7347 wpa_s
->prev_gas_resp
= NULL
;
7349 wpabuf_free(wpa_s
->last_gas_resp
);
7350 wpa_s
->last_gas_resp
= NULL
;
7356 #endif /* CONFIG_INTERWORKING */
7361 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7363 u8 dst_addr
[ETH_ALEN
];
7368 used
= hwaddr_aton2(dst
, dst_addr
);
7375 int num
= atoi(pos
);
7376 if (num
<= 0 || num
> 31)
7378 subtypes
|= BIT(num
);
7379 pos
= os_strchr(pos
+ 1, ',');
7388 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7392 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7393 const u8
*addr
, const char *realm
)
7399 rlen
= os_strlen(realm
);
7401 buf
= os_malloc(len
);
7404 buf
[0] = 1; /* NAI Home Realm Count */
7405 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7407 os_memcpy(buf
+ 3, realm
, rlen
);
7409 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7410 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7419 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7422 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7423 u8 dst_addr
[ETH_ALEN
];
7429 used
= hwaddr_aton2(dst
, dst_addr
);
7433 while (dst
[used
] == ' ')
7435 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7436 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7439 len
= os_strlen(dst
+ used
);
7441 if (len
== 0 && cred
&& cred
->realm
)
7442 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7447 buf
= os_malloc(len
);
7450 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7455 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7456 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7464 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7467 u8 dst_addr
[ETH_ALEN
];
7469 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7471 used
= hwaddr_aton2(cmd
, dst_addr
);
7476 icon
= str_token(cmd
, " ", &ctx
);
7477 poffset
= str_token(cmd
, " ", &ctx
);
7478 psize
= str_token(cmd
, " ", &ctx
);
7479 if (!icon
|| !poffset
|| !psize
)
7482 wpa_s
->fetch_osu_icon_in_progress
= 0;
7483 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7488 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7490 u8 dst_addr
[ETH_ALEN
];
7495 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7497 used
= hwaddr_aton2(cmd
, dst_addr
);
7501 while (cmd
[used
] == ' ')
7503 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7505 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7509 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7511 u8 dst_addr
[ETH_ALEN
];
7515 used
= hwaddr_aton2(cmd
, dst_addr
);
7519 while (cmd
[used
] == ' ')
7523 wpa_s
->fetch_osu_icon_in_progress
= 0;
7524 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7525 (u8
*) icon
, os_strlen(icon
), inmem
);
7528 #endif /* CONFIG_HS20 */
7531 #ifdef CONFIG_AUTOSCAN
7533 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7536 enum wpa_states state
= wpa_s
->wpa_state
;
7537 char *new_params
= NULL
;
7539 if (os_strlen(cmd
) > 0) {
7540 new_params
= os_strdup(cmd
);
7541 if (new_params
== NULL
)
7545 os_free(wpa_s
->conf
->autoscan
);
7546 wpa_s
->conf
->autoscan
= new_params
;
7548 if (wpa_s
->conf
->autoscan
== NULL
)
7549 autoscan_deinit(wpa_s
);
7550 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7551 autoscan_init(wpa_s
, 1);
7552 else if (state
== WPA_SCANNING
)
7553 wpa_supplicant_reinit_autoscan(wpa_s
);
7555 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7556 wpa_supplicant_state_txt(state
));
7561 #endif /* CONFIG_AUTOSCAN */
7566 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7572 struct wpabuf
*tfs_req
= NULL
;
7574 if (os_strncmp(cmd
, "enter", 5) == 0)
7576 else if (os_strncmp(cmd
, "exit", 4) == 0)
7581 pos
= os_strstr(cmd
, " interval=");
7583 intval
= atoi(pos
+ 10);
7585 pos
= os_strstr(cmd
, " tfs_req=");
7590 end
= os_strchr(pos
, ' ');
7594 len
= os_strlen(pos
);
7598 tfs_req
= wpabuf_alloc(len
);
7599 if (tfs_req
== NULL
)
7601 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7602 wpabuf_free(tfs_req
);
7607 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7608 WNM_SLEEP_MODE_EXIT
, intval
,
7610 wpabuf_free(tfs_req
);
7616 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7618 int query_reason
, list
= 0;
7619 char *btm_candidates
= NULL
;
7621 query_reason
= atoi(cmd
);
7623 cmd
= os_strchr(cmd
, ' ');
7625 if (os_strncmp(cmd
, " list", 5) == 0)
7628 btm_candidates
= cmd
;
7631 wpa_printf(MSG_DEBUG
,
7632 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7633 query_reason
, list
? " candidate list" : "");
7635 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7641 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant
*wpa_s
,
7644 struct wpabuf
*elems
;
7647 elems
= wpabuf_parse_bin(cmd
);
7651 ret
= wnm_send_coloc_intf_report(wpa_s
, 0, elems
);
7656 #endif /* CONFIG_WNM */
7659 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7662 struct wpa_signal_info si
;
7666 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7673 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7674 "NOISE=%d\nFREQUENCY=%u\n",
7675 si
.current_signal
, si
.current_txrate
/ 1000,
7676 si
.current_noise
, si
.frequency
);
7677 if (os_snprintf_error(end
- pos
, ret
))
7681 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7682 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7683 channel_width_to_string(si
.chanwidth
));
7684 if (os_snprintf_error(end
- pos
, ret
))
7689 if (si
.center_frq1
> 0) {
7690 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ1=%d\n",
7692 if (os_snprintf_error(end
- pos
, ret
))
7697 if (si
.center_frq2
> 0) {
7698 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ2=%d\n",
7700 if (os_snprintf_error(end
- pos
, ret
))
7705 if (si
.avg_signal
) {
7706 ret
= os_snprintf(pos
, end
- pos
,
7707 "AVG_RSSI=%d\n", si
.avg_signal
);
7708 if (os_snprintf_error(end
- pos
, ret
))
7713 if (si
.avg_beacon_signal
) {
7714 ret
= os_snprintf(pos
, end
- pos
,
7715 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7716 if (os_snprintf_error(end
- pos
, ret
))
7725 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7732 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7733 wpa_printf(MSG_DEBUG
,
7734 "Reject SIGNAL_MONITOR command - bgscan is active");
7737 pos
= os_strstr(cmd
, "THRESHOLD=");
7739 threshold
= atoi(pos
+ 10);
7740 pos
= os_strstr(cmd
, "HYSTERESIS=");
7742 hysteresis
= atoi(pos
+ 11);
7743 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7747 #ifdef CONFIG_TESTING_OPTIONS
7748 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7749 enum wpa_driver_if_type if_type
,
7751 unsigned int *freq_list
)
7753 char *pos
= wpa_s
->get_pref_freq_list_override
;
7755 unsigned int count
= 0;
7757 /* Override string format:
7758 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7761 if (atoi(pos
) == (int) if_type
)
7763 pos
= os_strchr(pos
, ' ');
7769 pos
= os_strchr(pos
, ':');
7773 end
= os_strchr(pos
, ' ');
7774 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7775 freq_list
[count
++] = atoi(pos
);
7776 pos
= os_strchr(pos
, ',');
7784 #endif /* CONFIG_TESTING_OPTIONS */
7787 static int wpas_ctrl_iface_get_pref_freq_list(
7788 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7790 unsigned int freq_list
[100], num
= 100, i
;
7792 enum wpa_driver_if_type iface_type
;
7798 /* buf: "<interface_type>" */
7799 if (os_strcmp(cmd
, "STATION") == 0)
7800 iface_type
= WPA_IF_STATION
;
7801 else if (os_strcmp(cmd
, "AP") == 0)
7802 iface_type
= WPA_IF_AP_BSS
;
7803 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7804 iface_type
= WPA_IF_P2P_GO
;
7805 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7806 iface_type
= WPA_IF_P2P_CLIENT
;
7807 else if (os_strcmp(cmd
, "IBSS") == 0)
7808 iface_type
= WPA_IF_IBSS
;
7809 else if (os_strcmp(cmd
, "TDLS") == 0)
7810 iface_type
= WPA_IF_TDLS
;
7814 wpa_printf(MSG_DEBUG
,
7815 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7818 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7822 for (i
= 0; i
< num
; i
++) {
7823 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7824 i
> 0 ? "," : "", freq_list
[i
]);
7825 if (os_snprintf_error(end
- pos
, ret
))
7834 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7835 char *buf
, size_t buflen
)
7840 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7841 (long long unsigned) wpa_s
->drv_flags
);
7842 if (os_snprintf_error(buflen
, ret
))
7848 for (i
= 0; i
< 64; i
++) {
7849 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7850 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7851 driver_flag_to_string(1LLU << i
));
7852 if (os_snprintf_error(end
- pos
, ret
))
7862 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7865 struct hostap_sta_driver_data sta
;
7868 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7872 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7873 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7874 if (os_snprintf_error(buflen
, ret
))
7881 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7882 char *buf
, size_t buflen
)
7886 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7888 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7889 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7892 country
[0] = cmd
[8];
7893 country
[1] = cmd
[9];
7895 p2p_set_country(p2p
, country
);
7898 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7899 if (os_snprintf_error(buflen
, ret
))
7904 #endif /* ANDROID */
7907 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7908 char *buf
, size_t buflen
)
7913 unsigned int vendor_id
, subcmd
;
7914 struct wpabuf
*reply
;
7915 size_t data_len
= 0;
7917 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7918 vendor_id
= strtoul(cmd
, &pos
, 16);
7919 if (!isblank((unsigned char) *pos
))
7922 subcmd
= strtoul(pos
, &pos
, 10);
7925 if (!isblank((unsigned char) *pos
++))
7927 data_len
= os_strlen(pos
);
7932 data
= os_malloc(data_len
);
7936 if (hexstr2bin(pos
, data
, data_len
)) {
7937 wpa_printf(MSG_DEBUG
,
7938 "Vendor command: wrong parameter format");
7944 reply
= wpabuf_alloc((buflen
- 1) / 2);
7950 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7954 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7964 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7967 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7968 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7969 #endif /* CONFIG_P2P */
7971 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7973 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7974 wpa_s
->ignore_post_flush_scan_res
= 1;
7976 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7978 * Avoid possible auto connect re-connection on getting
7979 * disconnected due to state flush.
7981 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7985 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7986 wpas_p2p_cancel(p2p_wpa_s
);
7987 p2p_ctrl_flush(p2p_wpa_s
);
7988 wpas_p2p_service_flush(p2p_wpa_s
);
7989 p2p_wpa_s
->global
->p2p_disabled
= 0;
7990 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7991 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7992 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7993 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7994 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7995 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7996 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7997 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7998 #endif /* CONFIG_P2P */
8000 #ifdef CONFIG_WPS_TESTING
8001 wps_version_number
= 0x20;
8002 wps_testing_dummy_cred
= 0;
8003 wps_corrupt_pkhash
= 0;
8004 wps_force_auth_types_in_use
= 0;
8005 wps_force_encr_types_in_use
= 0;
8006 #endif /* CONFIG_WPS_TESTING */
8008 wpa_s
->wps_fragment_size
= 0;
8009 wpas_wps_cancel(wpa_s
);
8010 wps_registrar_flush(wpa_s
->wps
->registrar
);
8011 #endif /* CONFIG_WPS */
8012 wpa_s
->after_wps
= 0;
8013 wpa_s
->known_wps_freq
= 0;
8016 wpas_dpp_deinit(wpa_s
);
8017 wpa_s
->dpp_init_max_tries
= 0;
8018 wpa_s
->dpp_init_retry_time
= 0;
8019 wpa_s
->dpp_resp_wait_time
= 0;
8020 wpa_s
->dpp_resp_max_tries
= 0;
8021 wpa_s
->dpp_resp_retry_time
= 0;
8022 #ifdef CONFIG_TESTING_OPTIONS
8023 os_memset(dpp_pkex_own_mac_override
, 0, ETH_ALEN
);
8024 os_memset(dpp_pkex_peer_mac_override
, 0, ETH_ALEN
);
8025 dpp_pkex_ephemeral_key_override_len
= 0;
8026 dpp_protocol_key_override_len
= 0;
8027 dpp_nonce_override_len
= 0;
8028 #endif /* CONFIG_TESTING_OPTIONS */
8029 #endif /* CONFIG_DPP */
8032 #ifdef CONFIG_TDLS_TESTING
8034 #endif /* CONFIG_TDLS_TESTING */
8035 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
8036 wpa_tdls_enable(wpa_s
->wpa
, 1);
8037 #endif /* CONFIG_TDLS */
8039 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
8040 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
8041 wpa_s
->last_michael_mic_error
.sec
= 0;
8043 wpa_s
->no_keep_alive
= 0;
8044 wpa_s
->own_disconnect_req
= 0;
8046 os_free(wpa_s
->disallow_aps_bssid
);
8047 wpa_s
->disallow_aps_bssid
= NULL
;
8048 wpa_s
->disallow_aps_bssid_count
= 0;
8049 os_free(wpa_s
->disallow_aps_ssid
);
8050 wpa_s
->disallow_aps_ssid
= NULL
;
8051 wpa_s
->disallow_aps_ssid_count
= 0;
8053 wpa_s
->set_sta_uapsd
= 0;
8054 wpa_s
->sta_uapsd
= 0;
8056 wpa_drv_radio_disable(wpa_s
, 0);
8057 wpa_blacklist_clear(wpa_s
);
8058 wpa_s
->extra_blacklist_count
= 0;
8059 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
8060 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
8061 wpa_config_flush_blobs(wpa_s
->conf
);
8062 wpa_s
->conf
->auto_interworking
= 0;
8063 wpa_s
->conf
->okc
= 0;
8065 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
8066 rsn_preauth_deinit(wpa_s
->wpa
);
8068 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
8069 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
8070 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
8071 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
8073 radio_remove_works(wpa_s
, NULL
, 1);
8074 wpa_s
->ext_work_in_progress
= 0;
8076 wpa_s
->next_ssid
= NULL
;
8078 #ifdef CONFIG_INTERWORKING
8080 hs20_cancel_fetch_osu(wpa_s
);
8081 hs20_del_icon(wpa_s
, NULL
, NULL
);
8082 #endif /* CONFIG_HS20 */
8083 #endif /* CONFIG_INTERWORKING */
8085 wpa_s
->ext_mgmt_frame_handling
= 0;
8086 wpa_s
->ext_eapol_frame_io
= 0;
8087 #ifdef CONFIG_TESTING_OPTIONS
8088 wpa_s
->extra_roc_dur
= 0;
8089 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
8090 wpa_s
->p2p_go_csa_on_inv
= 0;
8091 wpa_s
->ignore_auth_resp
= 0;
8092 wpa_s
->ignore_assoc_disallow
= 0;
8093 wpa_s
->testing_resend_assoc
= 0;
8094 wpa_s
->ignore_sae_h2e_only
= 0;
8095 wpa_s
->reject_btm_req_reason
= 0;
8096 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
8097 os_free(wpa_s
->get_pref_freq_list_override
);
8098 wpa_s
->get_pref_freq_list_override
= NULL
;
8099 wpabuf_free(wpa_s
->sae_commit_override
);
8100 wpa_s
->sae_commit_override
= NULL
;
8101 os_free(wpa_s
->extra_sae_rejected_groups
);
8102 wpa_s
->extra_sae_rejected_groups
= NULL
;
8103 wpabuf_free(wpa_s
->rsnxe_override_assoc
);
8104 wpa_s
->rsnxe_override_assoc
= NULL
;
8105 wpabuf_free(wpa_s
->rsnxe_override_eapol
);
8106 wpa_s
->rsnxe_override_eapol
= NULL
;
8108 os_free(wpa_s
->dpp_config_obj_override
);
8109 wpa_s
->dpp_config_obj_override
= NULL
;
8110 os_free(wpa_s
->dpp_discovery_override
);
8111 wpa_s
->dpp_discovery_override
= NULL
;
8112 os_free(wpa_s
->dpp_groups_override
);
8113 wpa_s
->dpp_groups_override
= NULL
;
8114 dpp_test
= DPP_TEST_DISABLED
;
8115 #endif /* CONFIG_DPP */
8116 #endif /* CONFIG_TESTING_OPTIONS */
8118 wpa_s
->disconnected
= 0;
8119 os_free(wpa_s
->next_scan_freqs
);
8120 wpa_s
->next_scan_freqs
= NULL
;
8121 os_free(wpa_s
->select_network_scan_freqs
);
8122 wpa_s
->select_network_scan_freqs
= NULL
;
8124 wpa_bss_flush(wpa_s
);
8125 if (!dl_list_empty(&wpa_s
->bss
)) {
8126 wpa_printf(MSG_DEBUG
,
8127 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8128 MACSTR
" pending_bssid=" MACSTR
,
8129 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
8130 MAC2STR(wpa_s
->bssid
),
8131 MAC2STR(wpa_s
->pending_bssid
));
8134 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
8135 wpa_s
->wnmsleep_used
= 0;
8138 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
8139 wpa_s
->sme
.auth_alg
= 0;
8140 #endif /* CONFIG_SME */
8142 wpabuf_free(wpa_s
->ric_ies
);
8143 wpa_s
->ric_ies
= NULL
;
8145 wpa_supplicant_update_channel_list(wpa_s
, NULL
);
8147 free_bss_tmp_disallowed(wpa_s
);
8151 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
8152 char *buf
, size_t buflen
)
8154 struct wpa_radio_work
*work
;
8156 struct os_reltime now
, diff
;
8161 os_get_reltime(&now
);
8163 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8167 os_reltime_sub(&now
, &work
->time
, &diff
);
8168 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
8169 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
8170 work
->started
, diff
.sec
, diff
.usec
);
8171 if (os_snprintf_error(end
- pos
, ret
))
8180 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
8182 struct wpa_radio_work
*work
= eloop_ctx
;
8183 struct wpa_external_work
*ework
= work
->ctx
;
8185 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
8186 "Timing out external radio work %u (%s)",
8187 ework
->id
, work
->type
);
8188 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
8189 work
->wpa_s
->ext_work_in_progress
= 0;
8190 radio_work_done(work
);
8195 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
8197 struct wpa_external_work
*ework
= work
->ctx
;
8201 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8205 * work->type points to a buffer in ework, so need to replace
8206 * that here with a fixed string to avoid use of freed memory
8209 work
->type
= "freed-ext-work";
8215 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
8216 ework
->id
, ework
->type
);
8217 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
8218 work
->wpa_s
->ext_work_in_progress
= 1;
8219 if (!ework
->timeout
)
8220 ework
->timeout
= 10;
8221 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
8226 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
8227 char *buf
, size_t buflen
)
8229 struct wpa_external_work
*ework
;
8233 unsigned int freq
= 0;
8235 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8237 ework
= os_zalloc(sizeof(*ework
));
8241 pos
= os_strchr(cmd
, ' ');
8243 type_len
= pos
- cmd
;
8246 pos2
= os_strstr(pos
, "freq=");
8248 freq
= atoi(pos2
+ 5);
8250 pos2
= os_strstr(pos
, "timeout=");
8252 ework
->timeout
= atoi(pos2
+ 8);
8254 type_len
= os_strlen(cmd
);
8256 if (4 + type_len
>= sizeof(ework
->type
))
8257 type_len
= sizeof(ework
->type
) - 4 - 1;
8258 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
8259 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
8260 ework
->type
[4 + type_len
] = '\0';
8262 wpa_s
->ext_work_id
++;
8263 if (wpa_s
->ext_work_id
== 0)
8264 wpa_s
->ext_work_id
++;
8265 ework
->id
= wpa_s
->ext_work_id
;
8267 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
8273 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
8274 if (os_snprintf_error(buflen
, ret
))
8280 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
8282 struct wpa_radio_work
*work
;
8283 unsigned int id
= atoi(cmd
);
8285 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8287 struct wpa_external_work
*ework
;
8289 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8292 if (id
&& ework
->id
!= id
)
8294 wpa_dbg(wpa_s
, MSG_DEBUG
,
8295 "Completed external radio work %u (%s)",
8296 ework
->id
, ework
->type
);
8297 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
8298 wpa_s
->ext_work_in_progress
= 0;
8299 radio_work_done(work
);
8301 return 3; /* "OK\n" */
8308 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
8309 char *buf
, size_t buflen
)
8311 if (os_strcmp(cmd
, "show") == 0)
8312 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
8313 if (os_strncmp(cmd
, "add ", 4) == 0)
8314 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
8315 if (os_strncmp(cmd
, "done ", 5) == 0)
8316 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
8321 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
8323 struct wpa_radio_work
*work
, *tmp
;
8325 if (!wpa_s
|| !wpa_s
->radio
)
8328 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
8329 struct wpa_radio_work
, list
) {
8330 struct wpa_external_work
*ework
;
8332 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8335 wpa_dbg(wpa_s
, MSG_DEBUG
,
8336 "Flushing%s external radio work %u (%s)",
8337 work
->started
? " started" : "", ework
->id
,
8340 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8342 radio_work_done(work
);
8348 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8350 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8351 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8355 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8356 unsigned int *scan_id_count
, int scan_id
[])
8358 const char *pos
= value
;
8361 if (*pos
== ' ' || *pos
== '\0')
8363 if (*scan_id_count
== MAX_SCAN_ID
)
8365 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8366 pos
= os_strchr(pos
, ',');
8375 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8376 char *reply
, int reply_size
, int *reply_len
)
8379 unsigned int manual_scan_passive
= 0;
8380 unsigned int manual_scan_use_id
= 0;
8381 unsigned int manual_scan_only_new
= 0;
8382 unsigned int scan_only
= 0;
8383 unsigned int scan_id_count
= 0;
8384 int scan_id
[MAX_SCAN_ID
];
8385 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8386 struct wpa_scan_results
*scan_res
);
8387 int *manual_scan_freqs
= NULL
;
8388 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8389 unsigned int ssid_count
= 0;
8391 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8396 if (radio_work_pending(wpa_s
, "scan")) {
8397 wpa_printf(MSG_DEBUG
,
8398 "Pending scan scheduled - reject new request");
8399 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8403 #ifdef CONFIG_INTERWORKING
8404 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8405 wpa_printf(MSG_DEBUG
,
8406 "Interworking select in progress - reject new scan");
8407 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8410 #endif /* CONFIG_INTERWORKING */
8413 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8416 pos
= os_strstr(params
, "freq=");
8418 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8420 if (manual_scan_freqs
== NULL
) {
8426 pos
= os_strstr(params
, "passive=");
8428 manual_scan_passive
= !!atoi(pos
+ 8);
8430 pos
= os_strstr(params
, "use_id=");
8432 manual_scan_use_id
= atoi(pos
+ 7);
8434 pos
= os_strstr(params
, "only_new=1");
8436 manual_scan_only_new
= 1;
8438 pos
= os_strstr(params
, "scan_id=");
8439 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8445 pos
= os_strstr(params
, "bssid=");
8450 if (hwaddr_aton(pos
, bssid
)) {
8451 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8455 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8459 while (pos
&& *pos
!= '\0') {
8460 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8466 if (*end
== '\0' || *end
== ' ')
8471 ns
= os_realloc_array(
8472 ssid
, ssid_count
+ 1,
8473 sizeof(struct wpa_ssid_value
));
8480 if ((end
- pos
) & 0x01 ||
8481 end
- pos
> 2 * SSID_MAX_LEN
||
8482 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8483 (end
- pos
) / 2) < 0) {
8484 wpa_printf(MSG_DEBUG
,
8485 "Invalid SSID value '%s'",
8490 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8491 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8492 ssid
[ssid_count
].ssid
,
8493 ssid
[ssid_count
].ssid_len
);
8498 pos
= os_strchr(pos
, ' ');
8504 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8505 os_free(wpa_s
->ssids_from_scan_req
);
8507 wpa_s
->ssids_from_scan_req
= ssid
;
8510 wpa_s
->ssids_from_scan_req
= NULL
;
8514 scan_res_handler
= scan_only_handler
;
8515 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8516 scan_res_handler
= NULL
;
8518 scan_res_handler
= wpa_s
->scan_res_handler
;
8520 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8521 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8522 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8523 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8524 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8525 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8526 wpa_s
->scan_id_count
= scan_id_count
;
8527 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8528 wpa_s
->scan_res_handler
= scan_res_handler
;
8529 os_free(wpa_s
->manual_scan_freqs
);
8530 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8531 manual_scan_freqs
= NULL
;
8533 wpa_s
->normal_scans
= 0;
8534 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8535 wpa_s
->after_wps
= 0;
8536 wpa_s
->known_wps_freq
= 0;
8537 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8538 if (wpa_s
->manual_scan_use_id
) {
8539 wpa_s
->manual_scan_id
++;
8540 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8541 wpa_s
->manual_scan_id
);
8542 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8543 wpa_s
->manual_scan_id
);
8545 } else if (wpa_s
->sched_scanning
) {
8546 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8547 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8548 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8549 wpa_s
->scan_id_count
= scan_id_count
;
8550 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8551 wpa_s
->scan_res_handler
= scan_res_handler
;
8552 os_free(wpa_s
->manual_scan_freqs
);
8553 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8554 manual_scan_freqs
= NULL
;
8556 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8557 wpa_supplicant_cancel_sched_scan(wpa_s
);
8558 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8559 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8560 if (wpa_s
->manual_scan_use_id
) {
8561 wpa_s
->manual_scan_id
++;
8562 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8563 wpa_s
->manual_scan_id
);
8564 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8565 wpa_s
->manual_scan_id
);
8568 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8569 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8573 os_free(manual_scan_freqs
);
8578 #ifdef CONFIG_TESTING_OPTIONS
8580 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8581 unsigned int freq
, const u8
*dst
,
8582 const u8
*src
, const u8
*bssid
,
8583 const u8
*data
, size_t data_len
,
8584 enum offchannel_send_action_result
8587 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8588 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8589 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8590 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8591 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8592 "NO_ACK" : "FAILED"));
8596 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8600 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8602 int freq
= 0, no_cck
= 0, wait_time
= 0;
8604 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8605 * <action=Action frame payload> */
8607 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8610 used
= hwaddr_aton2(pos
, da
);
8616 used
= hwaddr_aton2(pos
, bssid
);
8621 param
= os_strstr(pos
, " freq=");
8627 param
= os_strstr(pos
, " no_cck=");
8630 no_cck
= atoi(param
);
8633 param
= os_strstr(pos
, " wait_time=");
8636 wait_time
= atoi(param
);
8639 param
= os_strstr(pos
, " action=");
8644 len
= os_strlen(param
);
8649 buf
= os_malloc(len
);
8653 if (hexstr2bin(param
, buf
, len
) < 0) {
8658 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8659 buf
, len
, wait_time
,
8660 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8666 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8668 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8669 offchannel_send_action_done(wpa_s
);
8673 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8679 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8680 union wpa_event_data event
;
8682 if (!wpa_s
->ext_mgmt_frame_handling
)
8685 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8687 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8690 param
= os_strstr(pos
, "freq=");
8696 param
= os_strstr(pos
, " datarate=");
8699 datarate
= atoi(param
);
8702 param
= os_strstr(pos
, " ssi_signal=");
8705 ssi_signal
= atoi(param
);
8708 param
= os_strstr(pos
, " frame=");
8713 len
= os_strlen(param
);
8718 buf
= os_malloc(len
);
8722 if (hexstr2bin(param
, buf
, len
) < 0) {
8727 os_memset(&event
, 0, sizeof(event
));
8728 event
.rx_mgmt
.freq
= freq
;
8729 event
.rx_mgmt
.frame
= buf
;
8730 event
.rx_mgmt
.frame_len
= len
;
8731 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8732 event
.rx_mgmt
.datarate
= datarate
;
8733 wpa_s
->ext_mgmt_frame_handling
= 0;
8734 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8735 wpa_s
->ext_mgmt_frame_handling
= 1;
8743 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8746 struct wpa_scan_res
*res
;
8747 struct os_reltime now
;
8754 if (os_strcmp(param
, "START") == 0) {
8755 wpa_bss_update_start(wpa_s
);
8759 if (os_strcmp(param
, "END") == 0) {
8760 wpa_bss_update_end(wpa_s
, NULL
, 1);
8764 if (os_strncmp(param
, "BSS ", 4) != 0)
8768 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8772 pos
= os_strstr(param
, " flags=");
8774 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8776 pos
= os_strstr(param
, " bssid=");
8777 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8780 pos
= os_strstr(param
, " freq=");
8782 res
->freq
= atoi(pos
+ 6);
8784 pos
= os_strstr(param
, " beacon_int=");
8786 res
->beacon_int
= atoi(pos
+ 12);
8788 pos
= os_strstr(param
, " caps=");
8790 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8792 pos
= os_strstr(param
, " qual=");
8794 res
->qual
= atoi(pos
+ 6);
8796 pos
= os_strstr(param
, " noise=");
8798 res
->noise
= atoi(pos
+ 7);
8800 pos
= os_strstr(param
, " level=");
8802 res
->level
= atoi(pos
+ 7);
8804 pos
= os_strstr(param
, " tsf=");
8806 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8808 pos
= os_strstr(param
, " age=");
8810 res
->age
= atoi(pos
+ 5);
8812 pos
= os_strstr(param
, " est_throughput=");
8814 res
->est_throughput
= atoi(pos
+ 16);
8816 pos
= os_strstr(param
, " snr=");
8818 res
->snr
= atoi(pos
+ 5);
8820 pos
= os_strstr(param
, " parent_tsf=");
8822 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8824 pos
= os_strstr(param
, " tsf_bssid=");
8825 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8828 pos
= os_strstr(param
, " ie=");
8831 end
= os_strchr(pos
, ' ');
8833 end
= pos
+ os_strlen(pos
);
8834 res
->ie_len
= (end
- pos
) / 2;
8835 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8839 pos
= os_strstr(param
, " beacon_ie=");
8842 end
= os_strchr(pos
, ' ');
8844 end
= pos
+ os_strlen(pos
);
8845 res
->beacon_ie_len
= (end
- pos
) / 2;
8846 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8847 res
->beacon_ie_len
))
8851 os_get_reltime(&now
);
8852 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8861 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8864 union wpa_event_data event
;
8865 enum wpa_event_type ev
;
8867 /* <event name> [parameters..] */
8869 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8872 param
= os_strchr(pos
, ' ');
8876 os_memset(&event
, 0, sizeof(event
));
8878 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8879 ev
= EVENT_INTERFACE_ENABLED
;
8880 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8881 ev
= EVENT_INTERFACE_DISABLED
;
8882 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8883 ev
= EVENT_AVOID_FREQUENCIES
;
8886 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8888 wpa_supplicant_event(wpa_s
, ev
, &event
);
8889 os_free(event
.freq_range
.range
);
8891 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8892 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8894 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8899 wpa_supplicant_event(wpa_s
, ev
, &event
);
8905 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8908 u8 src
[ETH_ALEN
], *buf
;
8912 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8915 used
= hwaddr_aton2(pos
, src
);
8922 len
= os_strlen(pos
);
8927 buf
= os_malloc(len
);
8931 if (hexstr2bin(pos
, buf
, len
) < 0) {
8936 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8943 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8947 const u16
*pos
= buf
;
8949 for (i
= 0; i
< len
/ 2; i
++)
8953 sum
= (sum
& 0xffff) + (sum
>> 16);
8955 return sum
^ 0xffff;
8959 #define HWSIM_PACKETLEN 1500
8960 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8962 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8965 struct wpa_supplicant
*wpa_s
= ctx
;
8966 const struct ether_header
*eth
;
8972 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
8973 wpa_printf(MSG_DEBUG
,
8974 "test data: RX - ignore unexpected length %d",
8979 eth
= (const struct ether_header
*) buf
;
8980 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8981 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8983 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 || ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
8984 wpa_printf(MSG_DEBUG
,
8985 "test data: RX - ignore unexpect IP header");
8989 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
8990 if (*pos
!= (u8
) i
) {
8991 wpa_printf(MSG_DEBUG
,
8992 "test data: RX - ignore mismatching payload");
8998 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
8999 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
9000 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
9001 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
9005 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
9008 int enabled
= atoi(cmd
);
9013 if (wpa_s
->l2_test
) {
9014 l2_packet_deinit(wpa_s
->l2_test
);
9015 wpa_s
->l2_test
= NULL
;
9016 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
9024 pos
= os_strstr(cmd
, " ifname=");
9028 ifname
= wpa_s
->ifname
;
9030 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
9031 ETHERTYPE_IP
, wpas_data_test_rx
,
9033 if (wpa_s
->l2_test
== NULL
)
9036 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
9042 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
9044 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
9049 u8 buf
[2 + HWSIM_PACKETLEN
];
9050 struct ether_header
*eth
;
9054 size_t send_len
= HWSIM_IP_LEN
;
9056 if (wpa_s
->l2_test
== NULL
)
9059 /* format: <dst> <src> <tos> [len=<length>] */
9062 used
= hwaddr_aton2(pos
, dst
);
9068 used
= hwaddr_aton2(pos
, src
);
9073 val
= strtol(pos
, &pos2
, 0);
9074 if (val
< 0 || val
> 0xff)
9078 pos
= os_strstr(pos2
, " len=");
9081 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
9086 eth
= (struct ether_header
*) &buf
[2];
9087 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
9088 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
9089 eth
->ether_type
= htons(ETHERTYPE_IP
);
9090 ip
= (struct ip
*) (eth
+ 1);
9091 os_memset(ip
, 0, sizeof(*ip
));
9096 ip
->ip_len
= htons(send_len
);
9098 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9099 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9100 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
9101 dpos
= (u8
*) (ip
+ 1);
9102 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
9105 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
9106 sizeof(struct ether_header
) + send_len
) < 0)
9109 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
9110 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
9116 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
9120 struct ether_header
*eth
;
9121 struct l2_packet_data
*l2
= NULL
;
9126 len
= os_strlen(cmd
);
9127 if (len
& 1 || len
< ETH_HLEN
* 2)
9131 buf
= os_malloc(len
);
9135 if (hexstr2bin(cmd
, buf
, len
) < 0)
9138 eth
= (struct ether_header
*) buf
;
9139 ethertype
= ntohs(eth
->ether_type
);
9141 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
9142 wpas_data_test_rx
, wpa_s
, 1);
9146 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
9147 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
9150 l2_packet_deinit(l2
);
9153 return res
< 0 ? -1 : 0;
9157 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9159 #ifdef WPA_TRACE_BFD
9162 wpa_trace_fail_after
= atoi(cmd
);
9163 pos
= os_strchr(cmd
, ':');
9166 os_strlcpy(wpa_trace_fail_func
, pos
,
9167 sizeof(wpa_trace_fail_func
));
9169 wpa_trace_fail_after
= 0;
9172 #else /* WPA_TRACE_BFD */
9174 #endif /* WPA_TRACE_BFD */
9178 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
9179 char *buf
, size_t buflen
)
9181 #ifdef WPA_TRACE_BFD
9182 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
9183 wpa_trace_fail_func
);
9184 #else /* WPA_TRACE_BFD */
9186 #endif /* WPA_TRACE_BFD */
9190 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9192 #ifdef WPA_TRACE_BFD
9195 wpa_trace_test_fail_after
= atoi(cmd
);
9196 pos
= os_strchr(cmd
, ':');
9199 os_strlcpy(wpa_trace_test_fail_func
, pos
,
9200 sizeof(wpa_trace_test_fail_func
));
9202 wpa_trace_test_fail_after
= 0;
9205 #else /* WPA_TRACE_BFD */
9207 #endif /* WPA_TRACE_BFD */
9211 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
9212 char *buf
, size_t buflen
)
9214 #ifdef WPA_TRACE_BFD
9215 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
9216 wpa_trace_test_fail_func
);
9217 #else /* WPA_TRACE_BFD */
9219 #endif /* WPA_TRACE_BFD */
9223 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
9225 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9226 int i
, count
= (intptr_t) timeout_ctx
;
9228 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
9230 for (i
= 0; i
< count
; i
++) {
9231 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
9237 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9245 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
9246 (void *) (intptr_t) count
);
9250 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
9256 len
= os_strlen(cmd
);
9264 buf
= wpabuf_alloc(len
);
9268 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
9274 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
9279 static int wpas_ctrl_reset_pn(struct wpa_supplicant
*wpa_s
)
9281 u8 zero
[WPA_TK_MAX_LEN
];
9283 if (wpa_s
->last_tk_alg
== WPA_ALG_NONE
)
9286 wpa_printf(MSG_INFO
, "TESTING: Reset PN");
9287 os_memset(zero
, 0, sizeof(zero
));
9289 /* First, use a zero key to avoid any possible duplicate key avoidance
9291 if (wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9292 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9293 zero
, wpa_s
->last_tk_len
) < 0)
9296 /* Set the previously configured key to reset its TSC/RSC */
9297 return wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9298 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9299 wpa_s
->last_tk
, wpa_s
->last_tk_len
);
9303 static int wpas_ctrl_key_request(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9305 const char *pos
= cmd
;
9306 int error
, pairwise
;
9309 pos
= os_strchr(pos
, ' ');
9312 pairwise
= atoi(pos
);
9313 wpa_sm_key_request(wpa_s
->wpa
, error
, pairwise
);
9318 static int wpas_ctrl_resend_assoc(struct wpa_supplicant
*wpa_s
)
9321 struct wpa_driver_associate_params params
;
9324 os_memset(¶ms
, 0, sizeof(params
));
9325 params
.bssid
= wpa_s
->bssid
;
9326 params
.ssid
= wpa_s
->sme
.ssid
;
9327 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
9328 params
.freq
.freq
= wpa_s
->sme
.freq
;
9329 if (wpa_s
->last_assoc_req_wpa_ie
) {
9330 params
.wpa_ie
= wpabuf_head(wpa_s
->last_assoc_req_wpa_ie
);
9331 params
.wpa_ie_len
= wpabuf_len(wpa_s
->last_assoc_req_wpa_ie
);
9333 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
9334 params
.group_suite
= wpa_s
->group_cipher
;
9335 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
9336 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
9337 params
.wpa_proto
= wpa_s
->wpa_proto
;
9338 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
9339 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
9340 if (wpa_s
->sme
.prev_bssid_set
)
9341 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
9342 wpa_printf(MSG_INFO
, "TESTING: Resend association request");
9343 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
9344 wpa_s
->testing_resend_assoc
= 1;
9346 #else /* CONFIG_SME */
9348 #endif /* CONFIG_SME */
9351 #endif /* CONFIG_TESTING_OPTIONS */
9354 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
9360 struct ieee802_11_elems elems
;
9363 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9365 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9367 pos
= os_strchr(pos
, ' ');
9372 len
= os_strlen(pos
);
9379 buf
= wpabuf_alloc(len
);
9383 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
9388 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
9394 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
9395 wpa_s
->vendor_elem
[frame
] = buf
;
9396 wpas_vendor_elem_update(wpa_s
);
9400 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
9405 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
9407 wpas_vendor_elem_update(wpa_s
);
9413 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
9414 char *buf
, size_t buflen
)
9416 int frame
= atoi(cmd
);
9418 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9420 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9422 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9425 return wpa_snprintf_hex(buf
, buflen
,
9426 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
9427 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
9431 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
9437 struct ieee802_11_elems elems
;
9441 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9443 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9445 pos
= os_strchr(pos
, ' ');
9451 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9452 wpa_s
->vendor_elem
[frame
] = NULL
;
9453 wpas_vendor_elem_update(wpa_s
);
9457 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9460 len
= os_strlen(pos
);
9467 buf
= os_malloc(len
);
9471 if (hexstr2bin(pos
, buf
, len
) < 0) {
9476 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9481 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9487 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9489 struct wpa_supplicant
*wpa_s
= ctx
;
9494 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9496 * BSSID Information[4]
9497 * Operating Class[1]
9500 * Optional Subelements[variable]
9502 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9504 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9505 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9509 data
= wpabuf_head_u8(neighbor_rep
);
9510 len
= wpabuf_len(neighbor_rep
);
9512 while (len
>= 2 + NR_IE_MIN_LEN
) {
9514 char lci
[256 * 2 + 1];
9515 char civic
[256 * 2 + 1];
9516 u8 nr_len
= data
[1];
9517 const u8
*pos
= data
, *end
;
9519 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9520 nr_len
< NR_IE_MIN_LEN
) {
9521 wpa_dbg(wpa_s
, MSG_DEBUG
,
9522 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9527 if (2U + nr_len
> len
) {
9528 wpa_dbg(wpa_s
, MSG_DEBUG
,
9529 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9530 data
[0], len
, nr_len
);
9537 pos
+= NR_IE_MIN_LEN
;
9541 while (end
- pos
> 2) {
9546 if (s_len
> end
- pos
)
9548 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9549 /* Measurement Token[1] */
9550 /* Measurement Report Mode[1] */
9551 /* Measurement Type[1] */
9552 /* Measurement Report[variable] */
9554 case MEASURE_TYPE_LCI
:
9557 wpa_snprintf_hex(lci
, sizeof(lci
),
9560 case MEASURE_TYPE_LOCATION_CIVIC
:
9563 wpa_snprintf_hex(civic
, sizeof(civic
),
9572 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9574 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9575 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9576 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9578 lci
[0] ? " lci=" : "", lci
,
9579 civic
[0] ? " civic=" : "", civic
);
9586 wpabuf_free(neighbor_rep
);
9590 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9593 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9594 int ret
, lci
= 0, civic
= 0;
9597 ssid_s
= os_strstr(cmd
, "ssid=");
9599 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9600 wpa_msg(wpa_s
, MSG_INFO
,
9601 "CTRL: Send Neighbor Report: bad SSID");
9608 * Move cmd after the SSID text that may include "lci" or
9611 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9617 if (cmd
&& os_strstr(cmd
, "lci"))
9620 if (cmd
&& os_strstr(cmd
, "civic"))
9623 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9624 wpas_ctrl_neighbor_rep_cb
,
9631 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9633 eapol_sm_erp_flush(wpa_s
->eapol
);
9638 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9641 char *token
, *context
= NULL
;
9642 unsigned int enable
= ~0, type
= 0;
9643 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9644 u8
*addr
= NULL
, *mask
= NULL
;
9646 while ((token
= str_token(cmd
, " ", &context
))) {
9647 if (os_strcasecmp(token
, "scan") == 0) {
9648 type
|= MAC_ADDR_RAND_SCAN
;
9649 } else if (os_strcasecmp(token
, "sched") == 0) {
9650 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9651 } else if (os_strcasecmp(token
, "pno") == 0) {
9652 type
|= MAC_ADDR_RAND_PNO
;
9653 } else if (os_strcasecmp(token
, "all") == 0) {
9654 type
= wpa_s
->mac_addr_rand_supported
;
9655 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9656 enable
= atoi(token
+ 7);
9657 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9659 if (hwaddr_aton(token
+ 5, addr
)) {
9660 wpa_printf(MSG_INFO
,
9661 "CTRL: Invalid MAC address: %s",
9665 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9667 if (hwaddr_aton(token
+ 5, mask
)) {
9668 wpa_printf(MSG_INFO
,
9669 "CTRL: Invalid MAC address mask: %s",
9674 wpa_printf(MSG_INFO
,
9675 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9682 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9687 wpa_printf(MSG_INFO
,
9688 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9693 return wpas_disable_mac_addr_randomization(wpa_s
, type
);
9695 return wpas_enable_mac_addr_randomization(wpa_s
, type
, addr
, mask
);
9699 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9700 char *buf
, size_t buflen
)
9704 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9706 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9707 buflen
- reply_len
);
9708 #endif /* CONFIG_AP */
9713 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9715 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9717 wpas_ap_pmksa_cache_flush(wpa_s
);
9718 #endif /* CONFIG_AP */
9722 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9724 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9725 const char *cmd
, char *buf
, size_t buflen
)
9727 struct rsn_pmksa_cache_entry
*entry
;
9728 struct wpa_ssid
*ssid
;
9729 char *pos
, *pos2
, *end
;
9731 struct os_reltime now
;
9733 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9740 os_get_reltime(&now
);
9744 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9745 * <expiration in seconds> <akmp> <opportunistic>
9746 * [FILS Cache Identifier]
9749 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9750 entry
= entry
->next
) {
9751 if (entry
->network_ctx
!= ssid
)
9755 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9756 MAC2STR(entry
->aa
));
9757 if (os_snprintf_error(end
- pos2
, ret
))
9761 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9764 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9765 if (os_snprintf_error(end
- pos2
, ret
))
9769 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9772 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9773 (int) (entry
->reauth_time
- now
.sec
),
9774 (int) (entry
->expiration
- now
.sec
),
9776 entry
->opportunistic
);
9777 if (os_snprintf_error(end
- pos2
, ret
))
9781 if (entry
->fils_cache_id_set
) {
9782 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9783 entry
->fils_cache_id
[0],
9784 entry
->fils_cache_id
[1]);
9785 if (os_snprintf_error(end
- pos2
, ret
))
9790 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9791 if (os_snprintf_error(end
- pos2
, ret
))
9802 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9805 struct rsn_pmksa_cache_entry
*entry
;
9806 struct wpa_ssid
*ssid
;
9809 struct os_reltime now
;
9810 int reauth_time
= 0, expiration
= 0, i
;
9814 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9815 * <expiration in seconds> <akmp> <opportunistic>
9816 * [FILS Cache Identifier]
9819 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9823 pos
= os_strchr(cmd
, ' ');
9828 entry
= os_zalloc(sizeof(*entry
));
9832 if (hwaddr_aton(pos
, entry
->aa
))
9835 pos
= os_strchr(pos
, ' ');
9840 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9843 pos
= os_strchr(pos
, ' ');
9848 pos2
= os_strchr(pos
, ' ');
9851 entry
->pmk_len
= (pos2
- pos
) / 2;
9852 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9853 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9856 pos
= os_strchr(pos
, ' ');
9861 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9862 &entry
->akmp
, &entry
->opportunistic
) != 4)
9864 for (i
= 0; i
< 4; i
++) {
9865 pos
= os_strchr(pos
, ' ');
9874 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9875 FILS_CACHE_ID_LEN
) < 0)
9877 entry
->fils_cache_id_set
= 1;
9879 os_get_reltime(&now
);
9880 entry
->expiration
= now
.sec
+ expiration
;
9881 entry
->reauth_time
= now
.sec
+ reauth_time
;
9883 entry
->network_ctx
= ssid
;
9885 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9896 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9897 const char *cmd
, char *buf
,
9905 if (os_strcasecmp(cmd
, "any") == 0)
9906 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9908 if (hwaddr_aton(cmd
, spa
))
9911 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9915 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9919 * We do not check mesh interface existance because PMKSA should be
9920 * stored before wpa_s->ifmsh creation to suppress commit message
9923 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9926 #endif /* CONFIG_MESH */
9927 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9931 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9934 struct fils_hlp_req
*req
;
9937 /* format: <dst> <packet starting from ethertype> */
9939 req
= os_zalloc(sizeof(*req
));
9943 if (hwaddr_aton(cmd
, req
->dst
))
9946 pos
= os_strchr(cmd
, ' ');
9950 req
->pkt
= wpabuf_parse_bin(pos
);
9954 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9957 wpabuf_free(req
->pkt
);
9961 #endif /* CONFIG_FILS */
9964 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9966 if (os_strcmp(cmd
, "PING") == 0 ||
9967 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9968 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9969 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9970 os_strncmp(cmd
, "STA ", 4) == 0 ||
9971 os_strncmp(cmd
, "STA-", 4) == 0)
9972 return MSG_EXCESSIVE
;
9977 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9978 char *buf
, size_t *resp_len
)
9981 const int reply_size
= 4096;
9984 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9985 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9986 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9987 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9988 if (wpa_debug_show_keys
)
9989 wpa_dbg(wpa_s
, MSG_DEBUG
,
9990 "Control interface command '%s'", buf
);
9992 wpa_dbg(wpa_s
, MSG_DEBUG
,
9993 "Control interface command '%s [REMOVED]'",
9994 os_strncmp(buf
, WPA_CTRL_RSP
,
9995 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9997 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9998 "SET_NETWORK" : "key-add"));
9999 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
10000 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
10001 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
10002 (const u8
*) buf
, os_strlen(buf
));
10004 int level
= wpas_ctrl_cmd_debug_level(buf
);
10005 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
10008 reply
= os_malloc(reply_size
);
10009 if (reply
== NULL
) {
10014 os_memcpy(reply
, "OK\n", 3);
10017 if (os_strcmp(buf
, "PING") == 0) {
10018 os_memcpy(reply
, "PONG\n", 5);
10020 } else if (os_strcmp(buf
, "IFNAME") == 0) {
10021 reply_len
= os_strlen(wpa_s
->ifname
);
10022 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
10023 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10024 if (wpa_debug_reopen_file() < 0)
10026 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
10027 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
10028 } else if (os_strcmp(buf
, "MIB") == 0) {
10029 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
10030 if (reply_len
>= 0) {
10031 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
10033 reply_size
- reply_len
);
10034 #ifdef CONFIG_MACSEC
10035 reply_len
+= ieee802_1x_kay_get_mib(
10036 wpa_s
->kay
, reply
+ reply_len
,
10037 reply_size
- reply_len
);
10038 #endif /* CONFIG_MACSEC */
10040 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
10041 reply_len
= wpa_supplicant_ctrl_iface_status(
10042 wpa_s
, buf
+ 6, reply
, reply_size
);
10043 } else if (os_strcmp(buf
, "PMKSA") == 0) {
10044 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
10045 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
10046 wpas_ctrl_iface_pmksa_flush(wpa_s
);
10047 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10048 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
10049 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
10050 reply
, reply_size
);
10051 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
10052 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
10055 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
10056 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
10057 reply
, reply_size
);
10058 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10059 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
10061 #endif /* CONFIG_MESH */
10062 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10063 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10064 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
10066 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
10067 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
10068 reply
, reply_size
);
10069 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
10070 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
10071 reply
, reply_size
);
10072 } else if (os_strcmp(buf
, "LOGON") == 0) {
10073 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
10074 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
10075 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
10076 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
10077 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10080 wpas_request_connection(wpa_s
);
10081 } else if (os_strcmp(buf
, "REATTACH") == 0) {
10082 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
10083 !wpa_s
->current_ssid
)
10086 wpa_s
->reattach
= 1;
10087 wpas_request_connection(wpa_s
);
10089 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
10090 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10092 else if (wpa_s
->disconnected
)
10093 wpas_request_connection(wpa_s
);
10094 #ifdef IEEE8021X_EAPOL
10095 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
10096 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
10098 #endif /* IEEE8021X_EAPOL */
10099 #ifdef CONFIG_IEEE80211R
10100 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
10101 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
10103 #endif /* CONFIG_IEEE80211R */
10105 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
10106 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
10108 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10112 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
10113 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
10115 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10119 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
10120 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
10123 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
10124 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
10125 wpa_s
, buf
+ 14, reply
, reply_size
);
10126 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
10127 if (wpas_wps_cancel(wpa_s
))
10129 #ifdef CONFIG_WPS_NFC
10130 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
10131 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
10133 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
10134 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
10136 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10137 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10138 wpa_s
, buf
+ 21, reply
, reply_size
);
10139 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
10140 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
10141 wpa_s
, buf
+ 14, reply
, reply_size
);
10142 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
10143 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
10146 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10147 reply_len
= wpas_ctrl_nfc_get_handover_req(
10148 wpa_s
, buf
+ 21, reply
, reply_size
);
10149 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10150 reply_len
= wpas_ctrl_nfc_get_handover_sel(
10151 wpa_s
, buf
+ 21, reply
, reply_size
);
10152 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
10153 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
10155 #endif /* CONFIG_WPS_NFC */
10156 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
10157 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
10160 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
10161 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
10162 wpa_s
, buf
+ 11, reply
, reply_size
);
10163 #endif /* CONFIG_AP */
10164 #ifdef CONFIG_WPS_ER
10165 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
10166 if (wpas_wps_er_start(wpa_s
, NULL
))
10168 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
10169 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
10171 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
10172 wpas_wps_er_stop(wpa_s
);
10173 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
10174 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
10176 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
10177 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
10179 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10181 } else if (ret
== -3) {
10182 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
10184 } else if (ret
== -4) {
10185 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
10189 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
10190 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
10192 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
10193 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
10196 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
10197 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
10199 #ifdef CONFIG_WPS_NFC
10200 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10201 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10202 wpa_s
, buf
+ 24, reply
, reply_size
);
10203 #endif /* CONFIG_WPS_NFC */
10204 #endif /* CONFIG_WPS_ER */
10205 #endif /* CONFIG_WPS */
10206 #ifdef CONFIG_IBSS_RSN
10207 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
10208 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
10210 #endif /* CONFIG_IBSS_RSN */
10212 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
10213 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10214 wpa_s
, buf
+ 19, reply
, reply_size
);
10215 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
10216 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10217 wpa_s
, "", reply
, reply_size
);
10218 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
10219 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
10221 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
10222 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
10225 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
10226 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
10228 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
10229 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
10231 } else if (os_strncmp(buf
, "MESH_LINK_PROBE ", 16) == 0) {
10232 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s
, buf
+ 16))
10234 #endif /* CONFIG_MESH */
10236 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
10237 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
10239 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
10240 if (p2p_ctrl_find(wpa_s
, ""))
10242 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
10243 wpas_p2p_stop_find(wpa_s
);
10244 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
10245 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
10247 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10248 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
10250 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
10251 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
10253 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
10254 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
10256 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
10257 if (p2p_ctrl_listen(wpa_s
, ""))
10259 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
10260 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
10262 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
10263 if (p2p_ctrl_group_add(wpa_s
, ""))
10265 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
10266 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
10268 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
10269 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
10271 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
10272 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
10274 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
10275 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
10276 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
10277 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
10279 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10280 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
10282 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
10283 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
10285 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
10286 wpas_p2p_sd_service_update(wpa_s
);
10287 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10288 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
10290 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
10291 wpas_p2p_service_flush(wpa_s
);
10292 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
10293 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
10295 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
10296 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
10298 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
10299 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
10301 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
10302 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
10304 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
10305 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
10307 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
10308 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
10310 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
10311 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
10313 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
10314 p2p_ctrl_flush(wpa_s
);
10315 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
10316 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
10318 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
10319 if (wpas_p2p_cancel(wpa_s
))
10321 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
10322 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
10324 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
10325 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
10327 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
10328 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
10330 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
10331 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
10333 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
10334 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
10336 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
10337 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
10339 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
10340 if (wpas_p2p_lo_stop(wpa_s
))
10342 #endif /* CONFIG_P2P */
10343 #ifdef CONFIG_WIFI_DISPLAY
10344 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
10345 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
10347 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
10348 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
10349 reply
, reply_size
);
10350 #endif /* CONFIG_WIFI_DISPLAY */
10351 #ifdef CONFIG_INTERWORKING
10352 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
10353 if (interworking_fetch_anqp(wpa_s
) < 0)
10355 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
10356 interworking_stop_fetch_anqp(wpa_s
);
10357 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
10358 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
10360 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
10361 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
10363 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
10364 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
10366 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10369 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
10373 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
10374 if (os_snprintf_error(reply_size
, reply_len
))
10377 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
10378 if (get_anqp(wpa_s
, buf
+ 9) < 0)
10380 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
10381 if (gas_request(wpa_s
, buf
+ 12) < 0)
10383 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
10384 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
10386 #endif /* CONFIG_INTERWORKING */
10388 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10389 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10391 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10392 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10394 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10395 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10397 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10398 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10400 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10401 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10402 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10403 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10405 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10406 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10408 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10409 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10411 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10412 hs20_cancel_fetch_osu(wpa_s
);
10413 #endif /* CONFIG_HS20 */
10414 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10416 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10417 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10421 * Notify response from timeout to allow the control
10422 * interface response to be sent first.
10424 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10427 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10428 if (wpa_supplicant_reload_configuration(wpa_s
))
10430 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10431 wpa_supplicant_terminate_proc(wpa_s
->global
);
10432 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10433 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10435 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10436 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10437 wpa_s
, buf
+ 9, reply
, reply_size
);
10438 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10439 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10440 wpa_s
, buf
+ 9, reply
, reply_size
);
10441 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10442 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10443 wpa_s
, buf
+ 14, reply
, reply_size
);
10444 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10445 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10446 wpa_s
, NULL
, reply
, reply_size
);
10447 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10448 wpas_request_disconnection(wpa_s
);
10449 } else if (os_strcmp(buf
, "SCAN") == 0) {
10450 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10451 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10452 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10453 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10454 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10455 wpa_s
, reply
, reply_size
);
10456 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10457 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10459 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10460 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10462 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10463 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10465 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10466 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10468 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10469 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10470 wpa_s
, reply
, reply_size
);
10471 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10472 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10474 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10475 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10477 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10478 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10479 wpa_s
, buf
+ 12, reply
, reply_size
);
10480 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10481 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10484 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10485 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10486 wpa_s
, reply
, reply_size
);
10487 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10488 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10489 wpa_s
, reply
, reply_size
);
10490 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10491 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10493 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10494 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10496 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10497 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10500 #ifndef CONFIG_NO_CONFIG_WRITE
10501 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10502 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10504 #endif /* CONFIG_NO_CONFIG_WRITE */
10505 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10506 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10507 wpa_s
, buf
+ 15, reply
, reply_size
);
10508 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10509 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10511 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10512 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10514 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10515 reply_len
= wpa_supplicant_global_iface_list(
10516 wpa_s
->global
, reply
, reply_size
);
10517 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10518 reply_len
= wpa_supplicant_global_iface_interfaces(
10519 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10520 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10521 reply_len
= wpa_supplicant_ctrl_iface_bss(
10522 wpa_s
, buf
+ 4, reply
, reply_size
);
10524 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10525 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10526 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10527 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10529 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10530 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10532 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10533 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10535 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10536 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10538 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10539 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10541 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10542 if (wpas_ap_stop_ap(wpa_s
))
10544 #endif /* CONFIG_AP */
10545 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10546 wpas_notify_suspend(wpa_s
->global
);
10547 } else if (os_strcmp(buf
, "RESUME") == 0) {
10548 wpas_notify_resume(wpa_s
->global
);
10549 #ifdef CONFIG_TESTING_OPTIONS
10550 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10551 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10552 #endif /* CONFIG_TESTING_OPTIONS */
10553 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10554 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10556 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10557 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10558 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10559 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10561 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10562 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10565 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10566 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10568 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10569 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10571 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10572 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10574 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10575 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10577 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10578 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10581 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10582 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10585 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10586 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10587 wpa_s
, buf
+ 17, reply
, reply_size
);
10588 #endif /* CONFIG_TDLS */
10589 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10590 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10591 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10592 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10594 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10595 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10597 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10598 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10600 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10601 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10603 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10604 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10606 #ifdef CONFIG_AUTOSCAN
10607 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10608 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10610 #endif /* CONFIG_AUTOSCAN */
10611 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10612 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10615 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10616 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10618 #endif /* ANDROID */
10619 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10620 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10622 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10623 pmksa_cache_clear_current(wpa_s
->wpa
);
10624 eapol_sm_request_reauth(wpa_s
->eapol
);
10626 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10627 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10629 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10630 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10632 } else if (os_strncmp(buf
, "COLOC_INTF_REPORT ", 18) == 0) {
10633 if (wpas_ctrl_iface_coloc_intf_report(wpa_s
, buf
+ 18))
10635 #endif /* CONFIG_WNM */
10636 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10637 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10638 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10639 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10641 #ifdef CONFIG_TESTING_OPTIONS
10642 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10643 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10645 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10646 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10647 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10648 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10650 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10651 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10653 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10654 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10656 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10657 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10659 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10660 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10662 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10663 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10665 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10666 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10668 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10669 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10670 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10671 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10673 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10674 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10675 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10676 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10678 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10679 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10681 } else if (os_strcmp(buf
, "RESET_PN") == 0) {
10682 if (wpas_ctrl_reset_pn(wpa_s
) < 0)
10684 } else if (os_strncmp(buf
, "KEY_REQUEST ", 12) == 0) {
10685 if (wpas_ctrl_key_request(wpa_s
, buf
+ 12) < 0)
10687 } else if (os_strcmp(buf
, "RESEND_ASSOC") == 0) {
10688 if (wpas_ctrl_resend_assoc(wpa_s
) < 0)
10690 } else if (os_strcmp(buf
, "UNPROT_DEAUTH") == 0) {
10691 sme_event_unprot_disconnect(
10692 wpa_s
, wpa_s
->bssid
, NULL
,
10693 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
10694 #endif /* CONFIG_TESTING_OPTIONS */
10695 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10696 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10698 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10699 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10701 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10702 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10704 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10705 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10707 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10708 wpas_ctrl_iface_erp_flush(wpa_s
);
10709 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10710 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10712 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10713 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10714 wpa_s
, buf
+ 19, reply
, reply_size
);
10716 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10717 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10719 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10720 wpas_flush_fils_hlp_req(wpa_s
);
10721 #endif /* CONFIG_FILS */
10723 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10726 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10730 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10731 if (os_snprintf_error(reply_size
, reply_len
))
10734 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
10737 res
= wpas_dpp_nfc_uri(wpa_s
, buf
+ 12);
10741 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10742 if (os_snprintf_error(reply_size
, reply_len
))
10745 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10748 res
= dpp_bootstrap_gen(wpa_s
->dpp
, buf
+ 18);
10752 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10753 if (os_snprintf_error(reply_size
, reply_len
))
10756 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10757 if (dpp_bootstrap_remove(wpa_s
->dpp
, buf
+ 21) < 0)
10759 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10762 uri
= dpp_bootstrap_get_uri(wpa_s
->dpp
, atoi(buf
+ 22));
10766 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10767 if (os_snprintf_error(reply_size
, reply_len
))
10770 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10771 reply_len
= dpp_bootstrap_info(wpa_s
->dpp
, atoi(buf
+ 19),
10772 reply
, reply_size
);
10773 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10774 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10776 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10777 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10779 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10780 wpas_dpp_stop(wpa_s
);
10781 wpas_dpp_listen_stop(wpa_s
);
10782 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10785 res
= dpp_configurator_add(wpa_s
->dpp
, buf
+ 20);
10789 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10790 if (os_snprintf_error(reply_size
, reply_len
))
10793 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10794 if (dpp_configurator_remove(wpa_s
->dpp
, buf
+ 24) < 0)
10796 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10797 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 21) < 0)
10799 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10800 reply_len
= dpp_configurator_get_key_id(wpa_s
->dpp
,
10802 reply
, reply_size
);
10803 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10806 res
= wpas_dpp_pkex_add(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_PKEX_REMOVE ", 16) == 0) {
10815 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10818 } else if (os_strncmp(buf
, "DPP_CONTROLLER_START ", 21) == 0) {
10819 if (wpas_dpp_controller_start(wpa_s
, buf
+ 20) < 0)
10821 } else if (os_strcmp(buf
, "DPP_CONTROLLER_START") == 0) {
10822 if (wpas_dpp_controller_start(wpa_s
, NULL
) < 0)
10824 } else if (os_strcmp(buf
, "DPP_CONTROLLER_STOP") == 0) {
10825 dpp_controller_stop(wpa_s
->dpp
);
10826 #endif /* CONFIG_DPP2 */
10827 #endif /* CONFIG_DPP */
10829 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10833 if (reply_len
< 0) {
10834 os_memcpy(reply
, "FAIL\n", 5);
10838 *resp_len
= reply_len
;
10843 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10846 struct wpa_interface iface
;
10848 struct wpa_supplicant
*wpa_s
;
10849 unsigned int create_iface
= 0;
10850 u8 mac_addr
[ETH_ALEN
];
10851 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10854 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10855 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10857 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10859 os_memset(&iface
, 0, sizeof(iface
));
10862 iface
.ifname
= pos
= cmd
;
10863 pos
= os_strchr(pos
, '\t');
10866 if (iface
.ifname
[0] == '\0')
10871 iface
.confname
= pos
;
10872 pos
= os_strchr(pos
, '\t');
10875 if (iface
.confname
[0] == '\0')
10876 iface
.confname
= NULL
;
10880 iface
.driver
= pos
;
10881 pos
= os_strchr(pos
, '\t');
10884 if (iface
.driver
[0] == '\0')
10885 iface
.driver
= NULL
;
10889 iface
.ctrl_interface
= pos
;
10890 pos
= os_strchr(pos
, '\t');
10893 if (iface
.ctrl_interface
[0] == '\0')
10894 iface
.ctrl_interface
= NULL
;
10898 iface
.driver_param
= pos
;
10899 pos
= os_strchr(pos
, '\t');
10902 if (iface
.driver_param
[0] == '\0')
10903 iface
.driver_param
= NULL
;
10907 iface
.bridge_ifname
= pos
;
10908 pos
= os_strchr(pos
, '\t');
10911 if (iface
.bridge_ifname
[0] == '\0')
10912 iface
.bridge_ifname
= NULL
;
10917 pos
= os_strchr(pos
, '\t');
10923 if (os_strcmp(extra
, "create") == 0) {
10928 if (os_strcmp(pos
, "sta") == 0) {
10929 type
= WPA_IF_STATION
;
10930 } else if (os_strcmp(pos
, "ap") == 0) {
10931 type
= WPA_IF_AP_BSS
;
10933 wpa_printf(MSG_DEBUG
,
10934 "INTERFACE_ADD unsupported interface type: '%s'",
10939 wpa_printf(MSG_DEBUG
,
10940 "INTERFACE_ADD unsupported extra parameter: '%s'",
10946 if (create_iface
) {
10947 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10949 if (!global
->ifaces
)
10951 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10952 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10953 wpa_printf(MSG_ERROR
,
10954 "CTRL_IFACE interface creation failed");
10958 wpa_printf(MSG_DEBUG
,
10959 "CTRL_IFACE interface '%s' created with MAC addr: "
10960 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10963 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10966 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10969 wpa_s
->added_vif
= create_iface
;
10974 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10979 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10982 struct wpa_supplicant
*wpa_s
;
10984 unsigned int delete_iface
;
10986 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10988 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10991 delete_iface
= wpa_s
->added_vif
;
10992 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10993 if (!ret
&& delete_iface
) {
10994 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10996 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
11002 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
11004 struct wpa_interface_info
*prev
;
11008 iface
= iface
->next
;
11010 os_free(prev
->ifname
);
11011 os_free(prev
->desc
);
11017 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
11018 char *buf
, int len
)
11021 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
11024 for (i
= 0; wpa_drivers
[i
]; i
++) {
11025 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
11026 if (drv
->get_interfaces
== NULL
)
11028 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
11033 iface
= last
= tmp
;
11042 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
11043 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
11044 tmp
->drv_name
, tmp
->ifname
,
11045 tmp
->desc
? tmp
->desc
: "");
11046 if (os_snprintf_error(end
- pos
, res
)) {
11053 wpa_free_iface_info(iface
);
11059 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
11061 char *buf
, int len
)
11065 struct wpa_supplicant
*wpa_s
;
11069 show_ctrl
= !!os_strstr(input
, "ctrl");
11071 wpa_s
= global
->ifaces
;
11077 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
11079 wpa_s
->conf
->ctrl_interface
?
11080 wpa_s
->conf
->ctrl_interface
: "N/A");
11082 res
= os_snprintf(pos
, end
- pos
, "%s\n",
11085 if (os_snprintf_error(end
- pos
, res
)) {
11090 wpa_s
= wpa_s
->next
;
11096 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
11097 const char *ifname
,
11098 char *cmd
, size_t *resp_len
)
11100 struct wpa_supplicant
*wpa_s
;
11102 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11103 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
11107 if (wpa_s
== NULL
) {
11108 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
11110 *resp_len
= os_strlen(resp
);
11116 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
11120 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
11121 char *buf
, size_t *resp_len
)
11124 static const char * cmd
[] = {
11130 "P2P_GET_PASSPHRASE",
11131 "P2P_SERVICE_UPDATE",
11132 "P2P_SERVICE_FLUSH",
11135 "P2P_PRESENCE_REQ",
11139 #endif /* CONFIG_AP */
11142 static const char * prefix
[] = {
11145 #endif /* ANDROID */
11152 "P2P_GROUP_REMOVE ",
11154 "P2P_GROUP_MEMBER ",
11156 "P2P_SERV_DISC_REQ ",
11157 "P2P_SERV_DISC_CANCEL_REQ ",
11158 "P2P_SERV_DISC_RESP ",
11159 "P2P_SERV_DISC_EXTERNAL ",
11160 "P2P_SERVICE_ADD ",
11161 "P2P_SERVICE_DEL ",
11162 "P2P_SERVICE_REP ",
11167 "P2P_UNAUTHORIZE ",
11168 "P2P_PRESENCE_REQ ",
11170 "P2P_REMOVE_CLIENT ",
11172 "WPS_NFC_TAG_READ ",
11173 "NFC_GET_HANDOVER_SEL ",
11174 "NFC_GET_HANDOVER_REQ ",
11175 "NFC_REPORT_HANDOVER ",
11176 "P2P_ASP_PROVISION ",
11177 "P2P_ASP_PROVISION_RESP ",
11181 #endif /* CONFIG_AP */
11187 if (global
->p2p_init_wpa_s
== NULL
)
11190 for (i
= 0; !found
&& cmd
[i
]; i
++) {
11191 if (os_strcmp(buf
, cmd
[i
]) == 0)
11195 for (i
= 0; !found
&& prefix
[i
]; i
++) {
11196 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
11201 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11203 #endif /* CONFIG_P2P */
11208 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
11209 char *buf
, size_t *resp_len
)
11211 #ifdef CONFIG_WIFI_DISPLAY
11212 if (global
->p2p_init_wpa_s
== NULL
)
11214 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
11215 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
11216 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11218 #endif /* CONFIG_WIFI_DISPLAY */
11223 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
11224 char *buf
, size_t *resp_len
)
11228 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
11232 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
11240 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
11244 value
= os_strchr(cmd
, ' ');
11249 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
11251 #ifdef CONFIG_WIFI_DISPLAY
11252 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
11253 wifi_display_enable(global
, !!atoi(value
));
11256 #endif /* CONFIG_WIFI_DISPLAY */
11258 /* Restore cmd to its original value to allow redirection */
11265 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
11268 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
11272 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11273 * <variable name> */
11275 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
11276 p
= os_strchr(cmd
, ' ');
11281 wpa_s
[i
] = global
->ifaces
;
11282 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
11283 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
11288 wpa_printf(MSG_DEBUG
,
11289 "CTRL_IFACE: Could not find iface=%s", cmd
);
11296 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
11300 #ifndef CONFIG_NO_CONFIG_WRITE
11301 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
11303 int ret
= 0, saved
= 0;
11304 struct wpa_supplicant
*wpa_s
;
11306 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11307 if (!wpa_s
->conf
->update_config
) {
11308 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11312 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
11313 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11316 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11321 if (!saved
&& !ret
) {
11322 wpa_dbg(wpa_s
, MSG_DEBUG
,
11323 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11329 #endif /* CONFIG_NO_CONFIG_WRITE */
11332 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
11333 char *buf
, size_t buflen
)
11337 struct wpa_supplicant
*wpa_s
;
11340 end
= buf
+ buflen
;
11343 if (global
->p2p
&& !global
->p2p_disabled
) {
11344 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
11347 MAC2STR(global
->p2p_dev_addr
),
11348 p2p_get_state_txt(global
->p2p
));
11349 if (os_snprintf_error(end
- pos
, ret
))
11352 } else if (global
->p2p
) {
11353 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
11354 if (os_snprintf_error(end
- pos
, ret
))
11358 #endif /* CONFIG_P2P */
11360 #ifdef CONFIG_WIFI_DISPLAY
11361 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
11362 !!global
->wifi_display
);
11363 if (os_snprintf_error(end
- pos
, ret
))
11366 #endif /* CONFIG_WIFI_DISPLAY */
11368 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11369 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
11370 "address=" MACSTR
"\n",
11371 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
11372 if (os_snprintf_error(end
- pos
, ret
))
11383 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
11384 char *cmd
, char *buf
,
11387 char ifname
[IFNAMSIZ
+ 1];
11388 struct fst_iface_cfg cfg
;
11389 struct wpa_supplicant
*wpa_s
;
11390 struct fst_wpa_obj iface_obj
;
11392 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
11393 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11396 wpa_printf(MSG_INFO
, "FST: Already attached");
11399 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
11400 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
11403 return os_snprintf(buf
, reply_size
, "OK\n");
11411 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
11412 char *cmd
, char *buf
,
11415 char ifname
[IFNAMSIZ
+ 1];
11416 struct wpa_supplicant
*wpa_s
;
11418 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
11419 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11421 if (!fst_iface_detach(ifname
)) {
11423 return os_snprintf(buf
, reply_size
, "OK\n");
11431 #endif /* CONFIG_FST */
11434 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11435 char *buf
, size_t *resp_len
)
11438 const int reply_size
= 2048;
11440 int level
= MSG_DEBUG
;
11442 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11443 char *pos
= os_strchr(buf
+ 7, ' ');
11446 return wpas_global_ctrl_iface_ifname(global
,
11452 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11456 if (os_strcmp(buf
, "PING") == 0)
11457 level
= MSG_EXCESSIVE
;
11458 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11459 (const u8
*) buf
, os_strlen(buf
));
11461 reply
= os_malloc(reply_size
);
11462 if (reply
== NULL
) {
11467 os_memcpy(reply
, "OK\n", 3);
11470 if (os_strcmp(buf
, "PING") == 0) {
11471 os_memcpy(reply
, "PONG\n", 5);
11473 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11474 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11476 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11477 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11479 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11480 reply_len
= wpa_supplicant_global_iface_list(
11481 global
, reply
, reply_size
);
11482 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11483 reply_len
= wpa_supplicant_global_iface_interfaces(
11484 global
, buf
+ 10, reply
, reply_size
);
11486 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11487 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11490 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11491 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11494 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11495 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11496 #endif /* CONFIG_FST */
11497 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11498 wpa_supplicant_terminate_proc(global
);
11499 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11500 wpas_notify_suspend(global
);
11501 } else if (os_strcmp(buf
, "RESUME") == 0) {
11502 wpas_notify_resume(global
);
11503 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11504 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11506 if (global
->p2p_init_wpa_s
) {
11508 /* Check if P2P redirection would work for this
11510 return wpa_supplicant_ctrl_iface_process(
11511 global
->p2p_init_wpa_s
,
11514 #endif /* CONFIG_P2P */
11517 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11518 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11520 #ifndef CONFIG_NO_CONFIG_WRITE
11521 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11522 if (wpas_global_ctrl_iface_save_config(global
))
11524 #endif /* CONFIG_NO_CONFIG_WRITE */
11525 } else if (os_strcmp(buf
, "STATUS") == 0) {
11526 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11528 #ifdef CONFIG_MODULE_TESTS
11529 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11530 if (wpas_module_tests() < 0)
11532 #endif /* CONFIG_MODULE_TESTS */
11533 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11534 if (wpa_debug_reopen_file() < 0)
11537 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11541 if (reply_len
< 0) {
11542 os_memcpy(reply
, "FAIL\n", 5);
11546 *resp_len
= reply_len
;