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
, "reject_btm_req_reason") == 0) {
667 wpa_s
->reject_btm_req_reason
= atoi(value
);
668 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
669 os_free(wpa_s
->get_pref_freq_list_override
);
671 wpa_s
->get_pref_freq_list_override
= NULL
;
673 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
674 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
675 wpabuf_free(wpa_s
->sae_commit_override
);
676 if (value
[0] == '\0')
677 wpa_s
->sae_commit_override
= NULL
;
679 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
681 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
682 os_free(wpa_s
->dpp_config_obj_override
);
683 if (value
[0] == '\0')
684 wpa_s
->dpp_config_obj_override
= NULL
;
686 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
687 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
688 os_free(wpa_s
->dpp_discovery_override
);
689 if (value
[0] == '\0')
690 wpa_s
->dpp_discovery_override
= NULL
;
692 wpa_s
->dpp_discovery_override
= os_strdup(value
);
693 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
694 os_free(wpa_s
->dpp_groups_override
);
695 if (value
[0] == '\0')
696 wpa_s
->dpp_groups_override
= NULL
;
698 wpa_s
->dpp_groups_override
= os_strdup(value
);
699 } else if (os_strcasecmp(cmd
,
700 "dpp_ignore_netaccesskey_mismatch") == 0) {
701 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
702 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
703 dpp_test
= atoi(value
);
704 #endif /* CONFIG_DPP */
705 #endif /* CONFIG_TESTING_OPTIONS */
707 } else if (os_strcasecmp(cmd
, "disable_fils") == 0) {
708 wpa_s
->disable_fils
= !!atoi(value
);
709 wpa_drv_disable_fils(wpa_s
, wpa_s
->disable_fils
);
710 wpa_supplicant_set_default_scan_ies(wpa_s
);
711 #endif /* CONFIG_FILS */
712 #ifndef CONFIG_NO_CONFIG_BLOBS
713 } else if (os_strcmp(cmd
, "blob") == 0) {
714 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
715 #endif /* CONFIG_NO_CONFIG_BLOBS */
716 } else if (os_strcasecmp(cmd
, "setband") == 0) {
717 ret
= wpas_ctrl_set_band(wpa_s
, value
);
719 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
720 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
723 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
725 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
726 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
727 } else if (os_strcasecmp(cmd
, "oce") == 0) {
728 wpa_s
->conf
->oce
= atoi(value
);
729 if (wpa_s
->conf
->oce
) {
730 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
731 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
732 wpa_s
->enable_oce
= OCE_STA
;
734 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
736 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
737 /* TODO: Need to add STA-CFON support */
738 wpa_printf(MSG_ERROR
,
739 "OCE STA-CFON feature is not yet supported");
743 wpa_s
->enable_oce
= 0;
745 wpa_supplicant_set_default_scan_ies(wpa_s
);
746 #endif /* CONFIG_MBO */
747 } else if (os_strcasecmp(cmd
, "lci") == 0) {
748 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
749 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
750 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
751 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
752 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
753 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
754 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
755 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
756 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
757 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
758 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
760 } else if (os_strcasecmp(cmd
, "coloc_intf_elems") == 0) {
761 struct wpabuf
*elems
;
763 elems
= wpabuf_parse_bin(value
);
766 wnm_set_coloc_intf_elems(wpa_s
, elems
);
767 #endif /* CONFIG_WNM */
770 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
772 wpa_supplicant_update_config(wpa_s
);
779 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
780 char *cmd
, char *buf
, size_t buflen
)
784 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
786 if (os_strcmp(cmd
, "version") == 0) {
787 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
788 } else if (os_strcasecmp(cmd
, "country") == 0) {
789 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
790 res
= os_snprintf(buf
, buflen
, "%c%c",
791 wpa_s
->conf
->country
[0],
792 wpa_s
->conf
->country
[1]);
793 #ifdef CONFIG_WIFI_DISPLAY
794 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
796 if (wpa_s
->global
->p2p
== NULL
||
797 wpa_s
->global
->p2p_disabled
)
800 enabled
= wpa_s
->global
->wifi_display
;
801 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
802 #endif /* CONFIG_WIFI_DISPLAY */
803 #ifdef CONFIG_TESTING_GET_GTK
804 } else if (os_strcmp(cmd
, "gtk") == 0) {
805 if (wpa_s
->last_gtk_len
== 0)
807 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
808 wpa_s
->last_gtk_len
);
810 #endif /* CONFIG_TESTING_GET_GTK */
811 } else if (os_strcmp(cmd
, "tls_library") == 0) {
812 res
= tls_get_library_version(buf
, buflen
);
813 #ifdef CONFIG_TESTING_OPTIONS
814 } else if (os_strcmp(cmd
, "anonce") == 0) {
815 return wpa_snprintf_hex(buf
, buflen
,
816 wpa_sm_get_anonce(wpa_s
->wpa
),
818 #endif /* CONFIG_TESTING_OPTIONS */
820 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
823 if (os_snprintf_error(buflen
, res
))
829 #ifdef IEEE8021X_EAPOL
830 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
834 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
836 if (hwaddr_aton(addr
, bssid
)) {
837 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
842 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
843 rsn_preauth_deinit(wpa_s
->wpa
);
844 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
849 #endif /* IEEE8021X_EAPOL */
854 static int wpa_supplicant_ctrl_iface_tdls_discover(
855 struct wpa_supplicant
*wpa_s
, char *addr
)
860 if (hwaddr_aton(addr
, peer
)) {
861 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
862 "address '%s'", addr
);
866 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
869 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
870 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
872 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
878 static int wpa_supplicant_ctrl_iface_tdls_setup(
879 struct wpa_supplicant
*wpa_s
, char *addr
)
884 if (hwaddr_aton(addr
, peer
)) {
885 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
886 "address '%s'", addr
);
890 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
893 if ((wpa_s
->conf
->tdls_external_control
) &&
894 wpa_tdls_is_external_setup(wpa_s
->wpa
))
895 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
897 wpa_tdls_remove(wpa_s
->wpa
, peer
);
899 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
900 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
902 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
908 static int wpa_supplicant_ctrl_iface_tdls_teardown(
909 struct wpa_supplicant
*wpa_s
, char *addr
)
914 if (os_strcmp(addr
, "*") == 0) {
915 /* remove everyone */
916 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
917 wpa_tdls_teardown_peers(wpa_s
->wpa
);
921 if (hwaddr_aton(addr
, peer
)) {
922 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
923 "address '%s'", addr
);
927 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
930 if ((wpa_s
->conf
->tdls_external_control
) &&
931 wpa_tdls_is_external_setup(wpa_s
->wpa
))
932 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
934 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
935 ret
= wpa_tdls_teardown_link(
937 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
939 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
945 static int ctrl_iface_get_capability_tdls(
946 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
950 ret
= os_snprintf(buf
, buflen
, "%s\n",
951 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
953 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
954 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
955 if (os_snprintf_error(buflen
, ret
))
961 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
962 struct wpa_supplicant
*wpa_s
, char *cmd
)
965 struct hostapd_freq_params freq_params
;
969 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
971 "tdls_chanswitch: Only supported with external setup");
975 os_memset(&freq_params
, 0, sizeof(freq_params
));
977 pos
= os_strchr(cmd
, ' ');
982 oper_class
= strtol(pos
, &end
, 10);
985 "tdls_chanswitch: Invalid op class provided");
990 freq_params
.freq
= atoi(pos
);
991 if (freq_params
.freq
== 0) {
992 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
996 #define SET_FREQ_SETTING(str) \
998 const char *pos2 = os_strstr(pos, " " #str "="); \
1000 pos2 += sizeof(" " #str "=") - 1; \
1001 freq_params.str = atoi(pos2); \
1005 SET_FREQ_SETTING(center_freq1
);
1006 SET_FREQ_SETTING(center_freq2
);
1007 SET_FREQ_SETTING(bandwidth
);
1008 SET_FREQ_SETTING(sec_channel_offset
);
1009 #undef SET_FREQ_SETTING
1011 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
1012 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
1014 if (hwaddr_aton(cmd
, peer
)) {
1015 wpa_printf(MSG_DEBUG
,
1016 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1021 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1022 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1023 MAC2STR(peer
), oper_class
, freq_params
.freq
,
1024 freq_params
.center_freq1
, freq_params
.center_freq2
,
1025 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
1026 freq_params
.ht_enabled
? " HT" : "",
1027 freq_params
.vht_enabled
? " VHT" : "");
1029 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
1034 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1035 struct wpa_supplicant
*wpa_s
, char *cmd
)
1039 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1040 wpa_printf(MSG_INFO
,
1041 "tdls_chanswitch: Only supported with external setup");
1045 if (hwaddr_aton(cmd
, peer
)) {
1046 wpa_printf(MSG_DEBUG
,
1047 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1052 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1055 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1059 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1060 struct wpa_supplicant
*wpa_s
, const char *addr
,
1061 char *buf
, size_t buflen
)
1064 const char *tdls_status
;
1067 if (hwaddr_aton(addr
, peer
)) {
1068 wpa_printf(MSG_DEBUG
,
1069 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1073 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1076 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1077 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1078 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1079 if (os_snprintf_error(buflen
, ret
))
1085 #endif /* CONFIG_TDLS */
1088 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1090 char *token
, *context
= NULL
;
1091 struct wmm_ac_ts_setup_params params
= {
1096 while ((token
= str_token(cmd
, " ", &context
))) {
1097 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1098 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1099 sscanf(token
, "nominal_msdu_size=%i",
1100 ¶ms
.nominal_msdu_size
) == 1 ||
1101 sscanf(token
, "mean_data_rate=%i",
1102 ¶ms
.mean_data_rate
) == 1 ||
1103 sscanf(token
, "min_phy_rate=%i",
1104 ¶ms
.minimum_phy_rate
) == 1 ||
1105 sscanf(token
, "sba=%i",
1106 ¶ms
.surplus_bandwidth_allowance
) == 1)
1109 if (os_strcasecmp(token
, "downlink") == 0) {
1110 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1111 } else if (os_strcasecmp(token
, "uplink") == 0) {
1112 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1113 } else if (os_strcasecmp(token
, "bidi") == 0) {
1114 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1115 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1116 params
.fixed_nominal_msdu
= 1;
1118 wpa_printf(MSG_DEBUG
,
1119 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1126 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1130 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1132 u8 tsid
= atoi(cmd
);
1134 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1138 #ifdef CONFIG_IEEE80211R
1139 static int wpa_supplicant_ctrl_iface_ft_ds(
1140 struct wpa_supplicant
*wpa_s
, char *addr
)
1142 u8 target_ap
[ETH_ALEN
];
1143 struct wpa_bss
*bss
;
1146 if (hwaddr_aton(addr
, target_ap
)) {
1147 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1148 "address '%s'", addr
);
1152 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1154 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1156 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1160 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1162 #endif /* CONFIG_IEEE80211R */
1166 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1169 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1171 u8 p2p_dev_addr
[ETH_ALEN
];
1172 #endif /* CONFIG_P2P */
1174 u8
*_p2p_dev_addr
= NULL
;
1175 #endif /* CONFIG_AP */
1179 if (!cmd
|| os_strcmp(cmd
, "any") == 0 ||
1180 os_strncmp(cmd
, "any ", 4) == 0) {
1183 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1184 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1185 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1186 "P2P Device Address '%s'",
1190 _p2p_dev_addr
= p2p_dev_addr
;
1191 #endif /* CONFIG_P2P */
1192 } else if (os_strncmp(cmd
, "multi_ap=", 9) == 0) {
1194 multi_ap
= atoi(cmd
+ 9);
1195 } else if (hwaddr_aton(cmd
, bssid
)) {
1196 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1202 pos
= os_strstr(cmd
, " multi_ap=");
1205 multi_ap
= atoi(pos
);
1210 if (wpa_s
->ap_iface
)
1211 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1212 #endif /* CONFIG_AP */
1214 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0, multi_ap
);
1218 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1219 char *cmd
, char *buf
,
1222 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1226 pin
= os_strchr(cmd
, ' ');
1230 if (os_strcmp(cmd
, "any") == 0)
1232 else if (os_strcmp(cmd
, "get") == 0) {
1233 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1236 } else if (hwaddr_aton(cmd
, bssid
)) {
1237 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1243 if (wpa_s
->ap_iface
) {
1248 pos
= os_strchr(pin
, ' ');
1251 timeout
= atoi(pos
);
1255 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1256 buf
, buflen
, timeout
);
1258 #endif /* CONFIG_AP */
1261 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1265 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1266 if (os_snprintf_error(buflen
, ret
))
1271 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1276 /* Return the generated PIN */
1277 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1278 if (os_snprintf_error(buflen
, ret
))
1284 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1285 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1292 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1293 (u8
*) cmd
, os_strlen(cmd
));
1294 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1295 if (*pos
< '0' || *pos
> '9')
1299 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1303 if (len
!= 4 && len
!= 8) {
1304 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1310 unsigned int pin_val
;
1311 pin_val
= atoi(pin
);
1312 if (!wps_pin_valid(pin_val
)) {
1313 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1314 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1315 if (os_snprintf_error(buflen
, ret
))
1321 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1322 if (os_snprintf_error(buflen
, ret
))
1329 #ifdef CONFIG_WPS_NFC
1331 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1334 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1336 if (cmd
== NULL
|| cmd
[0] == '\0')
1338 else if (hwaddr_aton(cmd
, bssid
))
1341 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1346 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1347 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1354 pos
= os_strchr(cmd
, ' ');
1357 if (os_strcmp(cmd
, "WPS") == 0)
1359 else if (os_strcmp(cmd
, "NDEF") == 0)
1364 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1368 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1370 reply
[res
++] = '\n';
1379 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1380 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1386 if (os_strcmp(cmd
, "WPS") == 0)
1388 else if (os_strcmp(cmd
, "NDEF") == 0)
1393 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1397 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1399 reply
[res
++] = '\n';
1408 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1409 struct wpa_supplicant
*wpa_s
, char *pos
)
1415 int forced_freq
= 0;
1417 freq
= strstr(pos
, " freq=");
1421 forced_freq
= atoi(freq
);
1424 len
= os_strlen(pos
);
1429 buf
= wpabuf_alloc(len
);
1432 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1437 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1444 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1445 char *reply
, size_t max_len
,
1451 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1455 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1457 reply
[res
++] = '\n';
1467 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1468 char *reply
, size_t max_len
,
1474 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1476 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1480 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1482 reply
[res
++] = '\n';
1489 #endif /* CONFIG_P2P */
1492 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1493 char *cmd
, char *reply
,
1499 pos
= os_strchr(cmd
, ' ');
1504 if (os_strcmp(cmd
, "WPS") == 0)
1506 else if (os_strcmp(cmd
, "NDEF") == 0)
1511 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1514 return wpas_ctrl_nfc_get_handover_req_wps(
1515 wpa_s
, reply
, max_len
, ndef
);
1519 if (os_strcmp(pos
, "P2P-CR") == 0) {
1520 return wpas_ctrl_nfc_get_handover_req_p2p(
1521 wpa_s
, reply
, max_len
, ndef
);
1523 #endif /* CONFIG_P2P */
1529 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1530 char *reply
, size_t max_len
,
1531 int ndef
, int cr
, char *uuid
)
1536 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1540 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1542 reply
[res
++] = '\n';
1552 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1553 char *reply
, size_t max_len
,
1559 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1563 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1565 reply
[res
++] = '\n';
1572 #endif /* CONFIG_P2P */
1575 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1576 char *cmd
, char *reply
,
1582 pos
= os_strchr(cmd
, ' ');
1587 if (os_strcmp(cmd
, "WPS") == 0)
1589 else if (os_strcmp(cmd
, "NDEF") == 0)
1594 pos2
= os_strchr(pos
, ' ');
1597 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1600 return wpas_ctrl_nfc_get_handover_sel_wps(
1601 wpa_s
, reply
, max_len
, ndef
,
1602 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1606 if (os_strcmp(pos
, "P2P-CR") == 0) {
1607 return wpas_ctrl_nfc_get_handover_sel_p2p(
1608 wpa_s
, reply
, max_len
, ndef
, 0);
1611 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1612 return wpas_ctrl_nfc_get_handover_sel_p2p(
1613 wpa_s
, reply
, max_len
, ndef
, 1);
1615 #endif /* CONFIG_P2P */
1621 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1625 struct wpabuf
*req
, *sel
;
1627 char *pos
, *role
, *type
, *pos2
;
1630 int forced_freq
= 0;
1632 freq
= strstr(cmd
, " freq=");
1636 forced_freq
= atoi(freq
);
1638 #endif /* CONFIG_P2P */
1641 pos
= os_strchr(role
, ' ');
1643 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1649 pos
= os_strchr(type
, ' ');
1651 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1656 pos2
= os_strchr(pos
, ' ');
1658 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1663 len
= os_strlen(pos
);
1665 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1670 req
= wpabuf_alloc(len
);
1672 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1675 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1676 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1681 len
= os_strlen(pos2
);
1683 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1689 sel
= wpabuf_alloc(len
);
1691 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1695 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1696 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1702 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1703 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1705 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1706 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1708 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1710 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1712 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1713 #endif /* CONFIG_AP */
1715 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1717 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1718 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1720 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1722 #endif /* CONFIG_P2P */
1724 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1725 "reported: role=%s type=%s", role
, type
);
1732 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1737 #endif /* CONFIG_WPS_NFC */
1740 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1749 struct wps_new_ap_settings ap
;
1751 pin
= os_strchr(cmd
, ' ');
1756 if (hwaddr_aton(cmd
, bssid
)) {
1757 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1762 new_ssid
= os_strchr(pin
, ' ');
1763 if (new_ssid
== NULL
)
1764 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1767 new_auth
= os_strchr(new_ssid
, ' ');
1768 if (new_auth
== NULL
)
1772 new_encr
= os_strchr(new_auth
, ' ');
1773 if (new_encr
== NULL
)
1777 new_key
= os_strchr(new_encr
, ' ');
1778 if (new_key
== NULL
)
1782 os_memset(&ap
, 0, sizeof(ap
));
1783 ap
.ssid_hex
= new_ssid
;
1786 ap
.key_hex
= new_key
;
1787 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1792 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1793 char *cmd
, char *buf
,
1798 const char *pin_txt
;
1800 if (!wpa_s
->ap_iface
)
1803 pos
= os_strchr(cmd
, ' ');
1807 if (os_strcmp(cmd
, "disable") == 0) {
1808 wpas_wps_ap_pin_disable(wpa_s
);
1809 return os_snprintf(buf
, buflen
, "OK\n");
1812 if (os_strcmp(cmd
, "random") == 0) {
1814 timeout
= atoi(pos
);
1815 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1816 if (pin_txt
== NULL
)
1818 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1821 if (os_strcmp(cmd
, "get") == 0) {
1822 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1823 if (pin_txt
== NULL
)
1825 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1828 if (os_strcmp(cmd
, "set") == 0) {
1833 pos
= os_strchr(pos
, ' ');
1836 timeout
= atoi(pos
);
1838 if (os_strlen(pin
) > buflen
)
1840 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1842 return os_snprintf(buf
, buflen
, "%s", pin
);
1847 #endif /* CONFIG_AP */
1850 #ifdef CONFIG_WPS_ER
1851 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1854 char *uuid
= cmd
, *pin
, *pos
;
1855 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1856 pin
= os_strchr(uuid
, ' ');
1860 pos
= os_strchr(pin
, ' ');
1863 if (hwaddr_aton(pos
, addr_buf
) == 0)
1866 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1870 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1873 char *uuid
= cmd
, *pin
;
1874 pin
= os_strchr(uuid
, ' ');
1878 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1882 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1883 struct wpa_supplicant
*wpa_s
, char *cmd
)
1885 char *uuid
= cmd
, *id
;
1886 id
= os_strchr(uuid
, ' ');
1890 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1894 static int wpa_supplicant_ctrl_iface_wps_er_config(
1895 struct wpa_supplicant
*wpa_s
, char *cmd
)
1902 struct wps_new_ap_settings ap
;
1904 pin
= os_strchr(cmd
, ' ');
1909 new_ssid
= os_strchr(pin
, ' ');
1910 if (new_ssid
== NULL
)
1914 new_auth
= os_strchr(new_ssid
, ' ');
1915 if (new_auth
== NULL
)
1919 new_encr
= os_strchr(new_auth
, ' ');
1920 if (new_encr
== NULL
)
1924 new_key
= os_strchr(new_encr
, ' ');
1925 if (new_key
== NULL
)
1929 os_memset(&ap
, 0, sizeof(ap
));
1930 ap
.ssid_hex
= new_ssid
;
1933 ap
.key_hex
= new_key
;
1934 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1938 #ifdef CONFIG_WPS_NFC
1939 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1940 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1947 uuid
= os_strchr(cmd
, ' ');
1952 if (os_strcmp(cmd
, "WPS") == 0)
1954 else if (os_strcmp(cmd
, "NDEF") == 0)
1959 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1963 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1965 reply
[res
++] = '\n';
1972 #endif /* CONFIG_WPS_NFC */
1973 #endif /* CONFIG_WPS_ER */
1975 #endif /* CONFIG_WPS */
1978 #ifdef CONFIG_IBSS_RSN
1979 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1980 struct wpa_supplicant
*wpa_s
, char *addr
)
1984 if (hwaddr_aton(addr
, peer
)) {
1985 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1986 "address '%s'", addr
);
1990 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1993 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1995 #endif /* CONFIG_IBSS_RSN */
1998 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
2001 #ifdef IEEE8021X_EAPOL
2004 struct wpa_ssid
*ssid
;
2006 pos
= os_strchr(rsp
, '-');
2011 pos
= os_strchr(pos
, ':');
2016 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
2017 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2018 (u8
*) pos
, os_strlen(pos
));
2020 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2022 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2027 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
2029 #else /* IEEE8021X_EAPOL */
2030 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
2032 #endif /* IEEE8021X_EAPOL */
2036 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
2038 char *buf
, size_t buflen
)
2040 char *pos
, *end
, tmp
[30];
2041 int res
, verbose
, wps
, ret
;
2044 #endif /* CONFIG_HS20 */
2048 if (os_strcmp(params
, "-DRIVER") == 0)
2049 return wpa_drv_status(wpa_s
, buf
, buflen
);
2050 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
2051 wps
= os_strcmp(params
, "-WPS") == 0;
2054 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
2055 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2056 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2057 MAC2STR(wpa_s
->bssid
));
2058 if (os_snprintf_error(end
- pos
, ret
))
2061 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2063 if (os_snprintf_error(end
- pos
, ret
))
2067 u8
*_ssid
= ssid
->ssid
;
2068 size_t ssid_len
= ssid
->ssid_len
;
2069 u8 ssid_buf
[SSID_MAX_LEN
];
2070 if (ssid_len
== 0) {
2071 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2078 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2079 wpa_ssid_txt(_ssid
, ssid_len
),
2081 if (os_snprintf_error(end
- pos
, ret
))
2085 if (wps
&& ssid
->passphrase
&&
2086 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2087 (ssid
->mode
== WPAS_MODE_AP
||
2088 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2089 ret
= os_snprintf(pos
, end
- pos
,
2092 if (os_snprintf_error(end
- pos
, ret
))
2097 ret
= os_snprintf(pos
, end
- pos
,
2100 if (os_snprintf_error(end
- pos
, ret
))
2105 switch (ssid
->mode
) {
2106 case WPAS_MODE_INFRA
:
2107 ret
= os_snprintf(pos
, end
- pos
,
2110 case WPAS_MODE_IBSS
:
2111 ret
= os_snprintf(pos
, end
- pos
,
2115 ret
= os_snprintf(pos
, end
- pos
,
2118 case WPAS_MODE_P2P_GO
:
2119 ret
= os_snprintf(pos
, end
- pos
,
2122 case WPAS_MODE_P2P_GROUP_FORMATION
:
2123 ret
= os_snprintf(pos
, end
- pos
,
2124 "mode=P2P GO - group "
2127 case WPAS_MODE_MESH
:
2128 ret
= os_snprintf(pos
, end
- pos
,
2135 if (os_snprintf_error(end
- pos
, ret
))
2140 if (wpa_s
->connection_set
&&
2141 (wpa_s
->connection_ht
|| wpa_s
->connection_vht
||
2142 wpa_s
->connection_he
)) {
2143 ret
= os_snprintf(pos
, end
- pos
,
2144 "wifi_generation=%u\n",
2145 wpa_s
->connection_he
? 6 :
2146 (wpa_s
->connection_vht
? 5 : 4));
2147 if (os_snprintf_error(end
- pos
, ret
))
2153 if (wpa_s
->ap_iface
) {
2154 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2158 #endif /* CONFIG_AP */
2159 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2163 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2166 #endif /* CONFIG_AP */
2167 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2168 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2169 wpa_s
->sme
.sae
.group
);
2170 if (os_snprintf_error(end
- pos
, ret
))
2174 #endif /* CONFIG_SAE */
2175 #endif /* CONFIG_SME */
2176 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2177 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2178 if (os_snprintf_error(end
- pos
, ret
))
2183 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2184 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2185 if (os_snprintf_error(end
- pos
, ret
))
2191 if (wpa_s
->global
->p2p
) {
2192 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2193 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2194 if (os_snprintf_error(end
- pos
, ret
))
2198 #endif /* CONFIG_P2P */
2200 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2201 MAC2STR(wpa_s
->own_addr
));
2202 if (os_snprintf_error(end
- pos
, ret
))
2207 if (wpa_s
->current_bss
&&
2208 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2209 HS20_IE_VENDOR_TYPE
)) &&
2210 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2211 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2214 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2215 release
= rel_num
+ 1;
2217 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2218 if (os_snprintf_error(end
- pos
, ret
))
2223 if (wpa_s
->current_ssid
) {
2224 struct wpa_cred
*cred
;
2227 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2230 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2233 if (cred
->provisioning_sp
) {
2234 ret
= os_snprintf(pos
, end
- pos
,
2235 "provisioning_sp=%s\n",
2236 cred
->provisioning_sp
);
2237 if (os_snprintf_error(end
- pos
, ret
))
2246 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2247 struct wpabuf
*names
=
2248 wpa_s
->current_bss
->anqp
->domain_name
;
2249 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2251 if (domain_name_list_contains(
2252 names
, cred
->domain
[i
], 1))
2255 if (i
== cred
->num_domain
)
2256 i
= 0; /* show first entry by default */
2258 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2260 if (os_snprintf_error(end
- pos
, ret
))
2265 if (wpa_s
->current_bss
== NULL
||
2266 wpa_s
->current_bss
->anqp
== NULL
)
2269 res
= interworking_home_sp_cred(
2271 wpa_s
->current_bss
->anqp
->domain_name
);
2279 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2280 if (os_snprintf_error(end
- pos
, ret
))
2287 #endif /* CONFIG_HS20 */
2289 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2290 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2291 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2297 #ifdef CONFIG_MACSEC
2298 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2301 #endif /* CONFIG_MACSEC */
2303 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2307 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2308 if (os_snprintf_error(end
- pos
, ret
))
2311 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2315 ret
= os_snprintf(pos
, end
- pos
, "\n");
2316 if (os_snprintf_error(end
- pos
, ret
))
2321 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2328 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2329 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2330 if (os_snprintf_error(end
- pos
, ret
))
2334 #endif /* CONFIG_WPS */
2336 if (wpa_s
->ieee80211ac
) {
2337 ret
= os_snprintf(pos
, end
- pos
, "ieee80211ac=1\n");
2338 if (os_snprintf_error(end
- pos
, ret
))
2345 * Allow using the STATUS command with default behavior, say for debug,
2346 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2347 * events with STATUS-NO_EVENTS.
2349 if (os_strcmp(params
, "-NO_EVENTS")) {
2350 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2351 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2352 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2354 MAC2STR(wpa_s
->bssid
),
2355 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2356 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2357 wpa_s
->current_ssid
->ssid_len
) : "");
2358 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2359 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2360 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2361 "- connection to " MACSTR
2362 " completed %s [id=%d id_str=%s]",
2363 MAC2STR(wpa_s
->bssid
), "(auth)",
2364 ssid
? ssid
->id
: -1,
2365 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2368 #endif /* ANDROID */
2374 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2379 struct wpa_ssid
*ssid
;
2382 /* cmd: "<network id> <BSSID>" */
2383 pos
= os_strchr(cmd
, ' ');
2388 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2389 if (hwaddr_aton(pos
, bssid
)) {
2390 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2394 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2396 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2401 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2402 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2408 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2409 char *cmd
, char *buf
,
2413 struct wpa_blacklist
*e
;
2417 /* cmd: "BLACKLIST [<BSSID>]" */
2421 e
= wpa_s
->blacklist
;
2423 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2425 if (os_snprintf_error(end
- pos
, ret
))
2434 if (os_strncmp(cmd
, "clear", 5) == 0) {
2435 wpa_blacklist_clear(wpa_s
);
2436 os_memcpy(buf
, "OK\n", 3);
2440 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2441 if (hwaddr_aton(cmd
, bssid
)) {
2442 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2447 * Add the BSSID twice, so its count will be 2, causing it to be
2448 * skipped when processing scan results.
2450 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2453 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2456 os_memcpy(buf
, "OK\n", 3);
2461 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2462 char *cmd
, char *buf
,
2465 char *pos
, *end
, *stamp
;
2468 /* cmd: "LOG_LEVEL [<level>]" */
2472 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2474 debug_level_str(wpa_debug_level
),
2475 wpa_debug_timestamp
);
2476 if (os_snprintf_error(end
- pos
, ret
))
2485 stamp
= os_strchr(cmd
, ' ');
2488 while (*stamp
== ' ') {
2493 if (os_strlen(cmd
)) {
2494 int level
= str_to_debug_level(cmd
);
2497 wpa_debug_level
= level
;
2500 if (stamp
&& os_strlen(stamp
))
2501 wpa_debug_timestamp
= atoi(stamp
);
2503 os_memcpy(buf
, "OK\n", 3);
2508 static int wpa_supplicant_ctrl_iface_list_networks(
2509 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2511 char *pos
, *end
, *prev
;
2512 struct wpa_ssid
*ssid
;
2517 ret
= os_snprintf(pos
, end
- pos
,
2518 "network id / ssid / bssid / flags\n");
2519 if (os_snprintf_error(end
- pos
, ret
))
2523 ssid
= wpa_s
->conf
->ssid
;
2525 /* skip over ssids until we find next one */
2526 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2527 int last_id
= atoi(cmd
+ 8);
2528 if (last_id
!= -1) {
2529 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2537 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2539 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2540 if (os_snprintf_error(end
- pos
, ret
))
2543 if (ssid
->bssid_set
) {
2544 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2545 MAC2STR(ssid
->bssid
));
2547 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2549 if (os_snprintf_error(end
- pos
, ret
))
2552 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2553 ssid
== wpa_s
->current_ssid
?
2555 ssid
->disabled
? "[DISABLED]" : "",
2556 ssid
->disabled_until
.sec
?
2557 "[TEMP-DISABLED]" : "",
2558 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2560 if (os_snprintf_error(end
- pos
, ret
))
2563 ret
= os_snprintf(pos
, end
- pos
, "\n");
2564 if (os_snprintf_error(end
- pos
, ret
))
2575 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2578 ret
= os_snprintf(pos
, end
- pos
, "-");
2579 if (os_snprintf_error(end
- pos
, ret
))
2582 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2590 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2591 const u8
*ie
, size_t ie_len
)
2593 struct wpa_ie_data data
;
2597 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2598 if (os_snprintf_error(end
- pos
, ret
))
2602 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2603 ret
= os_snprintf(pos
, end
- pos
, "?]");
2604 if (os_snprintf_error(end
- pos
, ret
))
2611 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2612 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2613 pos
== start
? "" : "+");
2614 if (os_snprintf_error(end
- pos
, ret
))
2618 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2619 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2620 pos
== start
? "" : "+");
2621 if (os_snprintf_error(end
- pos
, ret
))
2625 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2626 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2627 pos
== start
? "" : "+");
2628 if (os_snprintf_error(end
- pos
, ret
))
2632 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2633 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2634 pos
== start
? "" : "+");
2635 if (os_snprintf_error(end
- pos
, ret
))
2639 #ifdef CONFIG_IEEE80211R
2640 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2641 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2642 pos
== start
? "" : "+");
2643 if (os_snprintf_error(end
- pos
, ret
))
2647 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2648 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2649 pos
== start
? "" : "+");
2650 if (os_snprintf_error(end
- pos
, ret
))
2654 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2655 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2656 pos
== start
? "" : "+");
2657 if (os_snprintf_error(end
- pos
, ret
))
2661 #endif /* CONFIG_IEEE80211R */
2662 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2663 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2664 pos
== start
? "" : "+");
2665 if (os_snprintf_error(end
- pos
, ret
))
2669 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2670 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2671 pos
== start
? "" : "+");
2672 if (os_snprintf_error(end
- pos
, ret
))
2677 #ifdef CONFIG_SUITEB
2678 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2679 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2680 pos
== start
? "" : "+");
2681 if (os_snprintf_error(end
- pos
, ret
))
2685 #endif /* CONFIG_SUITEB */
2687 #ifdef CONFIG_SUITEB192
2688 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2689 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2690 pos
== start
? "" : "+");
2691 if (os_snprintf_error(end
- pos
, ret
))
2695 #endif /* CONFIG_SUITEB192 */
2698 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2699 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2700 pos
== start
? "" : "+");
2701 if (os_snprintf_error(end
- pos
, ret
))
2705 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2706 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2707 pos
== start
? "" : "+");
2708 if (os_snprintf_error(end
- pos
, ret
))
2712 #ifdef CONFIG_IEEE80211R
2713 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2714 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2715 pos
== start
? "" : "+");
2716 if (os_snprintf_error(end
- pos
, ret
))
2720 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2721 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2722 pos
== start
? "" : "+");
2723 if (os_snprintf_error(end
- pos
, ret
))
2727 #endif /* CONFIG_IEEE80211R */
2728 #endif /* CONFIG_FILS */
2731 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2732 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2733 pos
== start
? "" : "+");
2734 if (os_snprintf_error(end
- pos
, ret
))
2738 #endif /* CONFIG_OWE */
2741 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2742 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2743 pos
== start
? "" : "+");
2744 if (os_snprintf_error(end
- pos
, ret
))
2748 #endif /* CONFIG_DPP */
2750 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2751 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2752 pos
== start
? "" : "+");
2753 if (os_snprintf_error(end
- pos
, ret
))
2758 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2760 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2761 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2762 if (os_snprintf_error(end
- pos
, ret
))
2767 ret
= os_snprintf(pos
, end
- pos
, "]");
2768 if (os_snprintf_error(end
- pos
, ret
))
2777 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2778 char *pos
, char *end
,
2779 struct wpabuf
*wps_ie
)
2786 if (wps_is_selected_pbc_registrar(wps_ie
))
2788 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2790 else if (wps_is_selected_pin_registrar(wps_ie
))
2795 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2796 if (!os_snprintf_error(end
- pos
, ret
))
2798 wpabuf_free(wps_ie
);
2801 #endif /* CONFIG_WPS */
2804 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2805 char *pos
, char *end
,
2806 const struct wpa_bss
*bss
)
2809 struct wpabuf
*wps_ie
;
2810 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2811 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2812 #else /* CONFIG_WPS */
2814 #endif /* CONFIG_WPS */
2818 /* Format one result on one text line into a buffer. */
2819 static int wpa_supplicant_ctrl_iface_scan_result(
2820 struct wpa_supplicant
*wpa_s
,
2821 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2825 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
, *owe
;
2827 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2828 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2830 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2831 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2832 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2834 return 0; /* Do not show P2P listen discovery results here */
2839 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2840 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2841 if (os_snprintf_error(end
- pos
, ret
))
2844 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2846 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2847 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2849 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2852 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2854 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2855 osen_ie
, 2 + osen_ie
[1]);
2856 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
2858 ret
= os_snprintf(pos
, end
- pos
,
2859 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2860 if (os_snprintf_error(end
- pos
, ret
))
2864 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2865 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2866 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2867 if (os_snprintf_error(end
- pos
, ret
))
2872 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2873 if (os_snprintf_error(end
- pos
, ret
))
2877 if (bss_is_dmg(bss
)) {
2880 if (get_ie_ext((const u8
*) (bss
+ 1), bss
->ie_len
,
2881 WLAN_EID_EXT_EDMG_OPERATION
)) {
2882 ret
= os_snprintf(pos
, end
- pos
, "[EDMG]");
2883 if (os_snprintf_error(end
- pos
, ret
))
2888 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2889 if (os_snprintf_error(end
- pos
, ret
))
2892 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2893 case IEEE80211_CAP_DMG_IBSS
:
2896 case IEEE80211_CAP_DMG_AP
:
2899 case IEEE80211_CAP_DMG_PBSS
:
2906 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2907 if (os_snprintf_error(end
- pos
, ret
))
2911 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2912 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2913 if (os_snprintf_error(end
- pos
, ret
))
2917 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2918 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2919 if (os_snprintf_error(end
- pos
, ret
))
2925 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2926 if (os_snprintf_error(end
- pos
, ret
))
2931 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2932 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2933 if (os_snprintf_error(end
- pos
, ret
))
2937 #endif /* CONFIG_HS20 */
2939 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2940 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2941 if (os_snprintf_error(end
- pos
, ret
))
2945 #endif /* CONFIG_FILS */
2947 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2948 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2949 if (os_snprintf_error(end
- pos
, ret
))
2953 #endif /* CONFIG_FST */
2954 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
2955 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
2956 if (os_snprintf_error(end
- pos
, ret
))
2961 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2962 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2963 if (os_snprintf_error(end
- pos
, ret
))
2967 ret
= os_snprintf(pos
, end
- pos
, "\n");
2968 if (os_snprintf_error(end
- pos
, ret
))
2976 static int wpa_supplicant_ctrl_iface_scan_results(
2977 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2980 struct wpa_bss
*bss
;
2985 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2987 if (os_snprintf_error(end
- pos
, ret
))
2991 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2992 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2994 if (ret
< 0 || ret
>= end
- pos
)
3005 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3006 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
3008 char *pos
, ifname
[IFNAMSIZ
+ 1];
3012 pos
= os_strstr(cmd
, "ifname=");
3015 os_strlcpy(ifname
, pos
, sizeof(ifname
));
3018 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
3021 os_strlcpy(reply
, ifname
, max_len
);
3022 return os_strlen(ifname
);
3026 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3027 struct wpa_supplicant
*wpa_s
, char *cmd
)
3030 struct wpa_ssid
*ssid
;
3033 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
3035 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3037 wpa_printf(MSG_DEBUG
,
3038 "CTRL_IFACE: Could not find network id=%d", id
);
3041 if (ssid
->mode
!= WPAS_MODE_MESH
) {
3042 wpa_printf(MSG_DEBUG
,
3043 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3046 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3047 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
3048 wpa_printf(MSG_ERROR
,
3049 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3054 * TODO: If necessary write our own group_add function,
3055 * for now we can reuse select_network
3057 wpa_supplicant_select_network(wpa_s
, ssid
);
3063 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3064 struct wpa_supplicant
*wpa_s
, char *cmd
)
3066 struct wpa_supplicant
*orig
;
3067 struct wpa_global
*global
;
3070 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
3072 global
= wpa_s
->global
;
3075 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3076 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
3082 wpa_printf(MSG_ERROR
,
3083 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3087 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
3088 wpa_printf(MSG_ERROR
,
3089 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3093 wpa_s
->reassociate
= 0;
3094 wpa_s
->disconnected
= 1;
3095 wpa_supplicant_cancel_sched_scan(wpa_s
);
3096 wpa_supplicant_cancel_scan(wpa_s
);
3099 * TODO: If necessary write our own group_remove function,
3100 * for now we can reuse deauthenticate
3102 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3104 if (wpa_s
->mesh_if_created
)
3105 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3111 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3112 struct wpa_supplicant
*wpa_s
, char *cmd
)
3116 if (hwaddr_aton(cmd
, addr
) < 0)
3119 return wpas_mesh_peer_remove(wpa_s
, addr
);
3123 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3124 struct wpa_supplicant
*wpa_s
, char *cmd
)
3130 pos
= os_strstr(cmd
, " duration=");
3133 duration
= atoi(pos
+ 10);
3138 if (hwaddr_aton(cmd
, addr
))
3141 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3145 static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3146 struct wpa_supplicant
*wpa_s
, char *cmd
)
3148 struct ether_header
*eth
;
3152 size_t payload_len
= 0, len
;
3155 if (hwaddr_aton(cmd
, addr
))
3158 pos
= os_strstr(cmd
, " payload=");
3161 payload_len
= os_strlen(pos
);
3162 if (payload_len
& 1)
3168 len
= ETH_HLEN
+ payload_len
;
3169 buf
= os_malloc(len
);
3173 eth
= (struct ether_header
*) buf
;
3174 os_memcpy(eth
->ether_dhost
, addr
, ETH_ALEN
);
3175 os_memcpy(eth
->ether_shost
, wpa_s
->own_addr
, ETH_ALEN
);
3176 eth
->ether_type
= htons(ETH_P_802_3
);
3178 if (payload_len
&& hexstr2bin(pos
, buf
+ ETH_HLEN
, payload_len
) < 0)
3181 ret
= wpa_drv_mesh_link_probe(wpa_s
, addr
, buf
, len
);
3187 #endif /* CONFIG_MESH */
3190 static int wpa_supplicant_ctrl_iface_select_network(
3191 struct wpa_supplicant
*wpa_s
, char *cmd
)
3194 struct wpa_ssid
*ssid
;
3197 /* cmd: "<network id>" or "any" */
3198 if (os_strncmp(cmd
, "any", 3) == 0) {
3199 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3203 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3205 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3207 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3208 "network id=%d", id
);
3211 if (ssid
->disabled
== 2) {
3212 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3213 "SELECT_NETWORK with persistent P2P group");
3218 pos
= os_strstr(cmd
, " freq=");
3220 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3222 os_free(wpa_s
->select_network_scan_freqs
);
3223 wpa_s
->select_network_scan_freqs
= freqs
;
3227 wpa_s
->scan_min_time
.sec
= 0;
3228 wpa_s
->scan_min_time
.usec
= 0;
3229 wpa_supplicant_select_network(wpa_s
, ssid
);
3235 static int wpa_supplicant_ctrl_iface_enable_network(
3236 struct wpa_supplicant
*wpa_s
, char *cmd
)
3239 struct wpa_ssid
*ssid
;
3241 /* cmd: "<network id>" or "all" */
3242 if (os_strcmp(cmd
, "all") == 0) {
3243 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3247 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3249 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3251 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3252 "network id=%d", id
);
3255 if (ssid
->disabled
== 2) {
3256 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3257 "ENABLE_NETWORK with persistent P2P group");
3261 if (os_strstr(cmd
, " no-connect")) {
3266 wpa_s
->scan_min_time
.sec
= 0;
3267 wpa_s
->scan_min_time
.usec
= 0;
3268 wpa_supplicant_enable_network(wpa_s
, ssid
);
3274 static int wpa_supplicant_ctrl_iface_disable_network(
3275 struct wpa_supplicant
*wpa_s
, char *cmd
)
3278 struct wpa_ssid
*ssid
;
3280 /* cmd: "<network id>" or "all" */
3281 if (os_strcmp(cmd
, "all") == 0) {
3282 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3286 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3288 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3290 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3291 "network id=%d", id
);
3294 if (ssid
->disabled
== 2) {
3295 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3296 "DISABLE_NETWORK with persistent P2P "
3301 wpa_supplicant_disable_network(wpa_s
, ssid
);
3307 static int wpa_supplicant_ctrl_iface_add_network(
3308 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3310 struct wpa_ssid
*ssid
;
3313 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3315 ssid
= wpa_supplicant_add_network(wpa_s
);
3319 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3320 if (os_snprintf_error(buflen
, ret
))
3326 static int wpa_supplicant_ctrl_iface_remove_network(
3327 struct wpa_supplicant
*wpa_s
, char *cmd
)
3330 struct wpa_ssid
*ssid
;
3333 /* cmd: "<network id>" or "all" */
3334 if (os_strcmp(cmd
, "all") == 0) {
3335 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3336 if (wpa_s
->sched_scanning
)
3337 wpa_supplicant_cancel_sched_scan(wpa_s
);
3339 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3340 if (wpa_s
->current_ssid
) {
3342 wpa_s
->sme
.prev_bssid_set
= 0;
3343 #endif /* CONFIG_SME */
3344 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3345 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3346 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3347 wpa_s
->own_disconnect_req
= 1;
3348 wpa_supplicant_deauthenticate(
3349 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3351 ssid
= wpa_s
->conf
->ssid
;
3353 struct wpa_ssid
*remove_ssid
= ssid
;
3356 if (wpa_s
->last_ssid
== remove_ssid
)
3357 wpa_s
->last_ssid
= NULL
;
3358 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3359 wpa_config_remove_network(wpa_s
->conf
, id
);
3365 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3367 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3369 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3374 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3375 "network id=%d", id
);
3382 static int wpa_supplicant_ctrl_iface_update_network(
3383 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3384 char *name
, char *value
)
3388 ret
= wpa_config_set(ssid
, name
, value
, 0);
3390 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3391 "variable '%s'", name
);
3395 return 0; /* No change to the previously configured value */
3397 if (os_strcmp(name
, "bssid") != 0 &&
3398 os_strcmp(name
, "bssid_hint") != 0 &&
3399 os_strcmp(name
, "priority") != 0) {
3400 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3402 if (wpa_s
->current_ssid
== ssid
||
3403 wpa_s
->current_ssid
== NULL
) {
3405 * Invalidate the EAP session cache if anything in the
3406 * current or previously used configuration changes.
3408 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3412 if ((os_strcmp(name
, "psk") == 0 &&
3413 value
[0] == '"' && ssid
->ssid_len
) ||
3414 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3415 wpa_config_update_psk(ssid
);
3416 else if (os_strcmp(name
, "priority") == 0)
3417 wpa_config_update_prio_list(wpa_s
->conf
);
3423 static int wpa_supplicant_ctrl_iface_set_network(
3424 struct wpa_supplicant
*wpa_s
, char *cmd
)
3426 int id
, ret
, prev_bssid_set
, prev_disabled
;
3427 struct wpa_ssid
*ssid
;
3429 u8 prev_bssid
[ETH_ALEN
];
3431 /* cmd: "<network id> <variable name> <value>" */
3432 name
= os_strchr(cmd
, ' ');
3437 value
= os_strchr(name
, ' ');
3443 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3445 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3446 (u8
*) value
, os_strlen(value
));
3448 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3450 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3455 prev_bssid_set
= ssid
->bssid_set
;
3456 prev_disabled
= ssid
->disabled
;
3457 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3458 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3461 (ssid
->bssid_set
!= prev_bssid_set
||
3462 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3463 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3465 if (prev_disabled
!= ssid
->disabled
&&
3466 (prev_disabled
== 2 || ssid
->disabled
== 2))
3467 wpas_notify_network_type_changed(wpa_s
, ssid
);
3473 static int wpa_supplicant_ctrl_iface_get_network(
3474 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3478 struct wpa_ssid
*ssid
;
3481 /* cmd: "<network id> <variable name>" */
3482 name
= os_strchr(cmd
, ' ');
3483 if (name
== NULL
|| buflen
== 0)
3488 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3491 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3493 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3498 value
= wpa_config_get_no_key(ssid
, name
);
3499 if (value
== NULL
) {
3500 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3501 "variable '%s'", name
);
3505 res
= os_strlcpy(buf
, value
, buflen
);
3506 if (res
>= buflen
) {
3517 static int wpa_supplicant_ctrl_iface_dup_network(
3518 struct wpa_supplicant
*wpa_s
, char *cmd
,
3519 struct wpa_supplicant
*dst_wpa_s
)
3521 struct wpa_ssid
*ssid_s
, *ssid_d
;
3522 char *name
, *id
, *value
;
3523 int id_s
, id_d
, ret
;
3525 /* cmd: "<src network id> <dst network id> <variable name>" */
3526 id
= os_strchr(cmd
, ' ');
3531 name
= os_strchr(id
, ' ');
3539 wpa_printf(MSG_DEBUG
,
3540 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3541 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3543 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3544 if (ssid_s
== NULL
) {
3545 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3546 "network id=%d", id_s
);
3550 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3551 if (ssid_d
== NULL
) {
3552 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3553 "network id=%d", id_d
);
3557 value
= wpa_config_get(ssid_s
, name
);
3558 if (value
== NULL
) {
3559 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3560 "variable '%s'", name
);
3564 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3573 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3574 char *buf
, size_t buflen
)
3577 struct wpa_cred
*cred
;
3582 ret
= os_snprintf(pos
, end
- pos
,
3583 "cred id / realm / username / domain / imsi\n");
3584 if (os_snprintf_error(end
- pos
, ret
))
3588 cred
= wpa_s
->conf
->cred
;
3590 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3591 cred
->id
, cred
->realm
? cred
->realm
: "",
3592 cred
->username
? cred
->username
: "",
3593 cred
->domain
? cred
->domain
[0] : "",
3594 cred
->imsi
? cred
->imsi
: "");
3595 if (os_snprintf_error(end
- pos
, ret
))
3606 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3607 char *buf
, size_t buflen
)
3609 struct wpa_cred
*cred
;
3612 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3614 cred
= wpa_config_add_cred(wpa_s
->conf
);
3618 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3620 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3621 if (os_snprintf_error(buflen
, ret
))
3627 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3628 struct wpa_cred
*cred
)
3630 struct wpa_ssid
*ssid
;
3635 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3640 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3641 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3645 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3647 /* Remove any network entry created based on the removed credential */
3648 ssid
= wpa_s
->conf
->ssid
;
3650 if (ssid
->parent_cred
== cred
) {
3653 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3654 "used the removed credential", ssid
->id
);
3655 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3656 if (os_snprintf_error(sizeof(str
), res
))
3657 str
[sizeof(str
) - 1] = '\0';
3659 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3668 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3672 struct wpa_cred
*cred
, *prev
;
3674 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3675 * "provisioning_sp=<FQDN> */
3676 if (os_strcmp(cmd
, "all") == 0) {
3677 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3678 cred
= wpa_s
->conf
->cred
;
3682 wpas_ctrl_remove_cred(wpa_s
, prev
);
3687 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3688 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3690 cred
= wpa_s
->conf
->cred
;
3696 for (i
= 0; i
< prev
->num_domain
; i
++) {
3697 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3700 wpas_ctrl_remove_cred(wpa_s
, prev
);
3708 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3709 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3711 cred
= wpa_s
->conf
->cred
;
3715 if (prev
->provisioning_sp
&&
3716 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3717 wpas_ctrl_remove_cred(wpa_s
, prev
);
3723 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3725 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3726 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3730 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3734 struct wpa_cred
*cred
;
3737 /* cmd: "<cred id> <variable name> <value>" */
3738 name
= os_strchr(cmd
, ' ');
3743 value
= os_strchr(name
, ' ');
3749 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3751 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3752 (u8
*) value
, os_strlen(value
));
3754 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3756 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3761 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3762 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3763 "variable '%s'", name
);
3767 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3773 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3774 char *cmd
, char *buf
,
3779 struct wpa_cred
*cred
;
3782 /* cmd: "<cred id> <variable name>" */
3783 name
= os_strchr(cmd
, ' ');
3789 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3792 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3794 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3799 value
= wpa_config_get_cred_no_key(cred
, name
);
3800 if (value
== NULL
) {
3801 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3806 res
= os_strlcpy(buf
, value
, buflen
);
3807 if (res
>= buflen
) {
3818 #ifndef CONFIG_NO_CONFIG_WRITE
3819 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3823 if (!wpa_s
->conf
->update_config
) {
3824 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3825 "to update configuration (update_config=0)");
3829 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3831 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3832 "update configuration");
3834 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3840 #endif /* CONFIG_NO_CONFIG_WRITE */
3843 struct cipher_info
{
3849 static const struct cipher_info ciphers
[] = {
3850 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3851 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3852 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3853 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3854 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3855 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3856 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3857 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3860 static const struct cipher_info ciphers_group_mgmt
[] = {
3861 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3862 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3863 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3864 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3868 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3869 struct wpa_driver_capa
*capa
,
3870 char *buf
, size_t buflen
)
3883 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3889 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3890 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3891 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3892 pos
== buf
? "" : " ",
3894 if (os_snprintf_error(end
- pos
, ret
))
3904 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3905 struct wpa_driver_capa
*capa
,
3906 char *buf
, size_t buflen
)
3919 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3925 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3926 if (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_mgmt(int res
, char *strict
,
3941 struct wpa_driver_capa
*capa
,
3942 char *buf
, size_t buflen
)
3954 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3955 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3956 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3957 pos
== buf
? "" : " ",
3958 ciphers_group_mgmt
[i
].name
);
3959 if (os_snprintf_error(end
- pos
, ret
))
3969 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3970 struct wpa_driver_capa
*capa
,
3971 char *buf
, size_t buflen
)
3983 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3990 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3991 if (os_snprintf_error(end
- pos
, ret
))
3995 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3996 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3997 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3998 if (os_snprintf_error(end
- pos
, ret
))
4003 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
4004 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4005 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
4006 if (os_snprintf_error(end
- pos
, ret
))
4011 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
4012 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
4013 if (os_snprintf_error(end
- pos
, ret
))
4018 #ifdef CONFIG_SUITEB
4019 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
4020 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
4021 if (os_snprintf_error(end
- pos
, ret
))
4025 #endif /* CONFIG_SUITEB */
4026 #ifdef CONFIG_SUITEB192
4027 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
4028 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
4029 if (os_snprintf_error(end
- pos
, ret
))
4033 #endif /* CONFIG_SUITEB192 */
4035 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
4036 ret
= os_snprintf(pos
, end
- pos
, " OWE");
4037 if (os_snprintf_error(end
- pos
, ret
))
4041 #endif /* CONFIG_OWE */
4043 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
4044 ret
= os_snprintf(pos
, end
- pos
, " DPP");
4045 if (os_snprintf_error(end
- pos
, ret
))
4049 #endif /* CONFIG_DPP */
4051 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
4052 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
4053 if (os_snprintf_error(end
- pos
, ret
))
4057 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
4058 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
4059 if (os_snprintf_error(end
- pos
, ret
))
4063 #ifdef CONFIG_IEEE80211R
4064 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
4065 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
4066 if (os_snprintf_error(end
- pos
, ret
))
4070 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
4071 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
4072 if (os_snprintf_error(end
- pos
, ret
))
4076 #endif /* CONFIG_IEEE80211R */
4077 #endif /* CONFIG_FILS */
4078 #ifdef CONFIG_IEEE80211R
4079 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
) {
4080 ret
= os_snprintf(pos
, end
- pos
, " FT-PSK");
4081 if (os_snprintf_error(end
- pos
, ret
))
4085 #endif /* CONFIG_IEEE80211R */
4087 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SAE
) {
4088 ret
= os_snprintf(pos
, end
- pos
, " SAE");
4089 if (os_snprintf_error(end
- pos
, ret
))
4093 #endif /* CONFIG_SAE */
4099 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
4100 struct wpa_driver_capa
*capa
,
4101 char *buf
, size_t buflen
)
4113 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
4119 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
4120 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4121 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
4122 pos
== buf
? "" : " ");
4123 if (os_snprintf_error(end
- pos
, ret
))
4128 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4129 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
4130 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
4131 pos
== buf
? "" : " ");
4132 if (os_snprintf_error(end
- pos
, ret
))
4141 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
4142 int res
, char *strict
,
4143 struct wpa_driver_capa
*capa
,
4144 char *buf
, size_t buflen
)
4156 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4162 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4163 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4164 pos
== buf
? "" : " ");
4165 if (os_snprintf_error(end
- pos
, ret
))
4170 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4171 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4172 pos
== buf
? "" : " ");
4173 if (os_snprintf_error(end
- pos
, ret
))
4178 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4179 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4180 pos
== buf
? "" : " ");
4181 if (os_snprintf_error(end
- pos
, ret
))
4187 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4188 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4189 pos
== buf
? "" : " ");
4190 if (os_snprintf_error(end
- pos
, ret
))
4194 #endif /* CONFIG_SAE */
4197 if (wpa_is_fils_supported(wpa_s
)) {
4198 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4199 pos
== buf
? "" : " ");
4200 if (os_snprintf_error(end
- pos
, ret
))
4205 #ifdef CONFIG_FILS_SK_PFS
4206 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4207 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4208 pos
== buf
? "" : " ");
4209 if (os_snprintf_error(end
- pos
, ret
))
4213 #endif /* CONFIG_FILS_SK_PFS */
4214 #endif /* CONFIG_FILS */
4220 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4221 struct wpa_driver_capa
*capa
,
4222 char *buf
, size_t buflen
)
4234 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4240 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4241 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4242 pos
== buf
? "" : " ");
4243 if (os_snprintf_error(end
- pos
, ret
))
4248 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4249 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4250 pos
== buf
? "" : " ");
4251 if (os_snprintf_error(end
- pos
, ret
))
4257 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4258 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4259 pos
== buf
? "" : " ");
4260 if (os_snprintf_error(end
- pos
, ret
))
4264 #endif /* CONFIG_MESH */
4270 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4271 char *buf
, size_t buflen
)
4273 struct hostapd_channel_data
*chnl
;
4275 char *pos
, *end
, *hmode
;
4280 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4281 switch (wpa_s
->hw
.modes
[j
].mode
) {
4282 case HOSTAPD_MODE_IEEE80211B
:
4285 case HOSTAPD_MODE_IEEE80211G
:
4288 case HOSTAPD_MODE_IEEE80211A
:
4291 case HOSTAPD_MODE_IEEE80211AD
:
4297 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4298 if (os_snprintf_error(end
- pos
, ret
))
4301 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4302 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4303 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4305 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4306 if (os_snprintf_error(end
- pos
, ret
))
4310 ret
= os_snprintf(pos
, end
- pos
, "\n");
4311 if (os_snprintf_error(end
- pos
, ret
))
4320 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4321 char *buf
, size_t buflen
)
4323 struct hostapd_channel_data
*chnl
;
4325 char *pos
, *end
, *hmode
;
4330 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4331 switch (wpa_s
->hw
.modes
[j
].mode
) {
4332 case HOSTAPD_MODE_IEEE80211B
:
4335 case HOSTAPD_MODE_IEEE80211G
:
4338 case HOSTAPD_MODE_IEEE80211A
:
4341 case HOSTAPD_MODE_IEEE80211AD
:
4347 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4349 if (os_snprintf_error(end
- pos
, ret
))
4352 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4353 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4354 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4356 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4357 chnl
[i
].chan
, chnl
[i
].freq
,
4358 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4360 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4363 if (os_snprintf_error(end
- pos
, ret
))
4367 ret
= os_snprintf(pos
, end
- pos
, "\n");
4368 if (os_snprintf_error(end
- pos
, ret
))
4377 static int wpa_supplicant_ctrl_iface_get_capability(
4378 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4381 struct wpa_driver_capa capa
;
4387 /* Determine whether or not strict checking was requested */
4388 len
= os_strlcpy(field
, _field
, sizeof(field
));
4389 if (len
>= sizeof(field
))
4391 strict
= os_strchr(field
, ' ');
4392 if (strict
!= NULL
) {
4394 if (os_strcmp(strict
, "strict") != 0)
4398 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4399 field
, strict
? strict
: "");
4401 if (os_strcmp(field
, "eap") == 0) {
4402 return eap_get_names(buf
, buflen
);
4405 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4407 if (os_strcmp(field
, "pairwise") == 0)
4408 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4411 if (os_strcmp(field
, "group") == 0)
4412 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4415 if (os_strcmp(field
, "group_mgmt") == 0)
4416 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4419 if (os_strcmp(field
, "key_mgmt") == 0)
4420 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4423 if (os_strcmp(field
, "proto") == 0)
4424 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4427 if (os_strcmp(field
, "auth_alg") == 0)
4428 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4429 &capa
, buf
, buflen
);
4431 if (os_strcmp(field
, "modes") == 0)
4432 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4435 if (os_strcmp(field
, "channels") == 0)
4436 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4438 if (os_strcmp(field
, "freq") == 0)
4439 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4442 if (os_strcmp(field
, "tdls") == 0)
4443 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4444 #endif /* CONFIG_TDLS */
4447 if (os_strcmp(field
, "erp") == 0) {
4448 res
= os_snprintf(buf
, buflen
, "ERP");
4449 if (os_snprintf_error(buflen
, res
))
4453 #endif /* CONFIG_EPR */
4456 if (os_strcmp(field
, "fips") == 0) {
4457 res
= os_snprintf(buf
, buflen
, "FIPS");
4458 if (os_snprintf_error(buflen
, res
))
4462 #endif /* CONFIG_FIPS */
4465 if (os_strcmp(field
, "acs") == 0) {
4466 res
= os_snprintf(buf
, buflen
, "ACS");
4467 if (os_snprintf_error(buflen
, res
))
4471 #endif /* CONFIG_ACS */
4474 if (os_strcmp(field
, "fils") == 0) {
4475 #ifdef CONFIG_FILS_SK_PFS
4476 if (wpa_is_fils_supported(wpa_s
) &&
4477 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4478 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4479 if (os_snprintf_error(buflen
, res
))
4483 #endif /* CONFIG_FILS_SK_PFS */
4485 if (wpa_is_fils_supported(wpa_s
)) {
4486 res
= os_snprintf(buf
, buflen
, "FILS");
4487 if (os_snprintf_error(buflen
, res
))
4492 #endif /* CONFIG_FILS */
4494 if (os_strcmp(field
, "multibss") == 0 && wpa_s
->multi_bss_support
) {
4495 res
= os_snprintf(buf
, buflen
, "MULTIBSS-STA");
4496 if (os_snprintf_error(buflen
, res
))
4502 if (os_strcmp(field
, "dpp") == 0) {
4504 res
= os_snprintf(buf
, buflen
, "DPP=2");
4505 #else /* CONFIG_DPP2 */
4506 res
= os_snprintf(buf
, buflen
, "DPP=1");
4507 #endif /* CONFIG_DPP2 */
4508 if (os_snprintf_error(buflen
, res
))
4512 #endif /* CONFIG_DPP */
4514 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4521 #ifdef CONFIG_INTERWORKING
4522 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4523 struct wpabuf
*data
)
4533 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4534 if (os_snprintf_error(end
- pos
, ret
))
4538 d
= wpabuf_head_u8(data
);
4539 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4540 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4541 if (os_snprintf_error(end
- pos
, ret
))
4546 ret
= os_snprintf(pos
, end
- pos
, "\n");
4547 if (os_snprintf_error(end
- pos
, ret
))
4553 #endif /* CONFIG_INTERWORKING */
4557 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4560 const u8
*ie
, *ie_end
;
4564 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4567 ie_end
= ie
+ 2 + ie
[1];
4569 if (ie_end
- ie
< 2)
4572 info
= WPA_GET_LE16(ie
);
4574 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4575 if (os_snprintf_error(end
- pos
, ret
))
4579 if (info
& BIT(7)) {
4580 /* Cache Identifier Included */
4581 if (ie_end
- ie
< 2)
4583 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4585 if (os_snprintf_error(end
- pos
, ret
))
4591 if (info
& BIT(8)) {
4592 /* HESSID Included */
4593 if (ie_end
- ie
< ETH_ALEN
)
4595 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4597 if (os_snprintf_error(end
- pos
, ret
))
4603 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4605 if (ie_end
- ie
< realms
* 2)
4607 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4608 if (os_snprintf_error(end
- pos
, ret
))
4612 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4617 ret
= os_snprintf(pos
, end
- pos
, "\n");
4618 if (os_snprintf_error(end
- pos
, ret
))
4625 #endif /* CONFIG_FILS */
4628 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4629 unsigned long mask
, char *buf
, size_t buflen
)
4634 const u8
*ie
, *ie2
, *osen_ie
, *mesh
, *owe
;
4639 if (mask
& WPA_BSS_MASK_ID
) {
4640 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4641 if (os_snprintf_error(end
- pos
, ret
))
4646 if (mask
& WPA_BSS_MASK_BSSID
) {
4647 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4648 MAC2STR(bss
->bssid
));
4649 if (os_snprintf_error(end
- pos
, ret
))
4654 if (mask
& WPA_BSS_MASK_FREQ
) {
4655 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4656 if (os_snprintf_error(end
- pos
, ret
))
4661 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4662 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4664 if (os_snprintf_error(end
- pos
, ret
))
4669 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4670 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4672 if (os_snprintf_error(end
- pos
, ret
))
4677 if (mask
& WPA_BSS_MASK_QUAL
) {
4678 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4679 if (os_snprintf_error(end
- pos
, ret
))
4684 if (mask
& WPA_BSS_MASK_NOISE
) {
4685 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4686 if (os_snprintf_error(end
- pos
, ret
))
4691 if (mask
& WPA_BSS_MASK_LEVEL
) {
4692 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4693 if (os_snprintf_error(end
- pos
, ret
))
4698 if (mask
& WPA_BSS_MASK_TSF
) {
4699 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4700 (unsigned long long) bss
->tsf
);
4701 if (os_snprintf_error(end
- pos
, ret
))
4706 if (mask
& WPA_BSS_MASK_AGE
) {
4707 struct os_reltime now
;
4709 os_get_reltime(&now
);
4710 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4711 (int) (now
.sec
- bss
->last_update
.sec
));
4712 if (os_snprintf_error(end
- pos
, ret
))
4717 if (mask
& WPA_BSS_MASK_IE
) {
4718 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4719 if (os_snprintf_error(end
- pos
, ret
))
4723 ie
= (const u8
*) (bss
+ 1);
4724 for (i
= 0; i
< bss
->ie_len
; i
++) {
4725 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4726 if (os_snprintf_error(end
- pos
, ret
))
4731 ret
= os_snprintf(pos
, end
- pos
, "\n");
4732 if (os_snprintf_error(end
- pos
, ret
))
4737 if (mask
& WPA_BSS_MASK_FLAGS
) {
4738 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4739 if (os_snprintf_error(end
- pos
, ret
))
4743 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4745 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4747 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4749 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4751 pos
= wpa_supplicant_ie_txt(pos
, end
,
4752 mesh
? "RSN" : "WPA2", ie2
,
4754 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4756 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4757 osen_ie
, 2 + osen_ie
[1]);
4758 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
4762 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4763 if (os_snprintf_error(end
- pos
, ret
))
4767 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4768 if (!ie
&& !ie2
&& !osen_ie
&&
4769 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4770 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4771 if (os_snprintf_error(end
- pos
, ret
))
4777 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4778 if (os_snprintf_error(end
- pos
, ret
))
4783 if (bss_is_dmg(bss
)) {
4785 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4786 if (os_snprintf_error(end
- pos
, ret
))
4789 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4790 case IEEE80211_CAP_DMG_IBSS
:
4793 case IEEE80211_CAP_DMG_AP
:
4796 case IEEE80211_CAP_DMG_PBSS
:
4803 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4804 if (os_snprintf_error(end
- pos
, ret
))
4808 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4809 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4810 if (os_snprintf_error(end
- pos
, ret
))
4814 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4815 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4816 if (os_snprintf_error(end
- pos
, ret
))
4821 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4822 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4823 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4824 if (os_snprintf_error(end
- pos
, ret
))
4829 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4830 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4831 if (os_snprintf_error(end
- pos
, ret
))
4835 #endif /* CONFIG_HS20 */
4837 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4838 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4839 if (os_snprintf_error(end
- pos
, ret
))
4843 #endif /* CONFIG_FILS */
4845 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
4846 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
4847 if (os_snprintf_error(end
- pos
, ret
))
4851 #endif /* CONFIG_FST */
4852 if (wpa_bss_ext_capab(bss
, WLAN_EXT_CAPAB_UTF_8_SSID
)) {
4853 ret
= os_snprintf(pos
, end
- pos
, "[UTF-8]");
4854 if (os_snprintf_error(end
- pos
, ret
))
4859 ret
= os_snprintf(pos
, end
- pos
, "\n");
4860 if (os_snprintf_error(end
- pos
, ret
))
4865 if (mask
& WPA_BSS_MASK_SSID
) {
4866 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4867 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4868 if (os_snprintf_error(end
- pos
, ret
))
4874 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4875 ie
= (const u8
*) (bss
+ 1);
4876 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4877 if (ret
>= end
- pos
)
4882 #endif /* CONFIG_WPS */
4885 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4886 ie
= (const u8
*) (bss
+ 1);
4887 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4888 if (ret
>= end
- pos
)
4893 #endif /* CONFIG_P2P */
4895 #ifdef CONFIG_WIFI_DISPLAY
4896 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4898 ie
= (const u8
*) (bss
+ 1);
4899 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4900 WFD_IE_VENDOR_TYPE
);
4902 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4903 if (os_snprintf_error(end
- pos
, ret
)) {
4909 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4914 ret
= os_snprintf(pos
, end
- pos
, "\n");
4915 if (os_snprintf_error(end
- pos
, ret
))
4920 #endif /* CONFIG_WIFI_DISPLAY */
4922 #ifdef CONFIG_INTERWORKING
4923 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4924 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4925 struct wpa_bss_anqp_elem
*elem
;
4927 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4928 anqp
->capability_list
);
4929 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4931 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4932 anqp
->network_auth_type
);
4933 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4934 anqp
->roaming_consortium
);
4935 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4936 anqp
->ip_addr_type_availability
);
4937 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4939 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4940 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4942 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4943 anqp
->fils_realm_info
);
4945 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4946 anqp
->hs20_capability_list
);
4947 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4948 anqp
->hs20_operator_friendly_name
);
4949 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4950 anqp
->hs20_wan_metrics
);
4951 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4952 anqp
->hs20_connection_capability
);
4953 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4954 anqp
->hs20_operating_class
);
4955 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4956 anqp
->hs20_osu_providers_list
);
4957 pos
= anqp_add_hex(pos
, end
, "hs20_operator_icon_metadata",
4958 anqp
->hs20_operator_icon_metadata
);
4959 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_nai_list",
4960 anqp
->hs20_osu_providers_nai_list
);
4961 #endif /* CONFIG_HS20 */
4963 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4964 struct wpa_bss_anqp_elem
, list
) {
4967 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4969 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4972 #endif /* CONFIG_INTERWORKING */
4975 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4976 ie
= (const u8
*) (bss
+ 1);
4977 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4978 if (ret
>= end
- pos
)
4983 #endif /* CONFIG_MESH */
4985 if (mask
& WPA_BSS_MASK_SNR
) {
4986 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4987 if (os_snprintf_error(end
- pos
, ret
))
4992 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4993 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4994 bss
->est_throughput
);
4995 if (os_snprintf_error(end
- pos
, ret
))
5001 if (mask
& WPA_BSS_MASK_FST
) {
5002 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
5003 if (ret
< 0 || ret
>= end
- pos
)
5007 #endif /* CONFIG_FST */
5009 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
5010 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
5011 bss
->last_update_idx
);
5012 if (os_snprintf_error(end
- pos
, ret
))
5017 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
5018 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
5019 if (os_snprintf_error(end
- pos
, ret
))
5023 ie
= (const u8
*) (bss
+ 1);
5025 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
5026 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
5027 if (os_snprintf_error(end
- pos
, ret
))
5032 ret
= os_snprintf(pos
, end
- pos
, "\n");
5033 if (os_snprintf_error(end
- pos
, ret
))
5039 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
5040 ret
= print_fils_indication(bss
, pos
, end
);
5045 #endif /* CONFIG_FILS */
5047 if (mask
& WPA_BSS_MASK_DELIM
) {
5048 ret
= os_snprintf(pos
, end
- pos
, "====\n");
5049 if (os_snprintf_error(end
- pos
, ret
))
5058 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
5059 const char *cmd
, char *buf
,
5064 struct wpa_bss
*bss
;
5065 struct wpa_bss
*bsslast
= NULL
;
5066 struct dl_list
*next
;
5069 char *ctmp
, *end
= buf
+ buflen
;
5070 unsigned long mask
= WPA_BSS_MASK_ALL
;
5072 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
5073 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
5074 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
5076 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
5078 } else { /* N1-N2 */
5079 unsigned int id1
, id2
;
5081 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
5082 wpa_printf(MSG_INFO
, "Wrong BSS range "
5087 if (*(cmd
+ 6) == '-')
5090 id1
= atoi(cmd
+ 6);
5092 if (*ctmp
>= '0' && *ctmp
<= '9')
5095 id2
= (unsigned int) -1;
5096 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
5097 if (id2
== (unsigned int) -1)
5098 bsslast
= dl_list_last(&wpa_s
->bss_id
,
5102 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
5103 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
5104 struct wpa_bss
*tmp
= bss
;
5106 next
= tmp
->list_id
.next
;
5107 if (next
== &wpa_s
->bss_id
)
5109 tmp
= dl_list_entry(
5110 next
, struct wpa_bss
,
5119 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
5120 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5121 else if (os_strncmp(cmd
, "LAST", 4) == 0)
5122 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5123 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
5125 bss
= wpa_bss_get_id(wpa_s
, i
);
5126 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
5128 bss
= wpa_bss_get_id(wpa_s
, i
);
5130 next
= bss
->list_id
.next
;
5131 if (next
== &wpa_s
->bss_id
)
5134 bss
= dl_list_entry(next
, struct wpa_bss
,
5137 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
5138 bss
= wpa_s
->current_bss
;
5140 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
5141 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
5142 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
5145 #endif /* CONFIG_P2P */
5146 } else if (hwaddr_aton(cmd
, bssid
) == 0)
5147 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5149 struct wpa_bss
*tmp
;
5152 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
5162 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
5163 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
5165 mask
= WPA_BSS_MASK_ALL
;
5171 if (bsslast
== NULL
)
5174 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
5178 if (bss
== bsslast
) {
5179 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
5180 (bss
== dl_list_last(&wpa_s
->bss_id
,
5181 struct wpa_bss
, list_id
))) {
5184 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
5186 if (os_snprintf_error(end
- buf
+ 5, res
)) {
5187 wpa_printf(MSG_DEBUG
,
5188 "Could not add end delim");
5193 next
= bss
->list_id
.next
;
5194 if (next
== &wpa_s
->bss_id
)
5196 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
5197 } while (bss
&& len
);
5203 static int wpa_supplicant_ctrl_iface_ap_scan(
5204 struct wpa_supplicant
*wpa_s
, char *cmd
)
5206 int ap_scan
= atoi(cmd
);
5207 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5211 static int wpa_supplicant_ctrl_iface_scan_interval(
5212 struct wpa_supplicant
*wpa_s
, char *cmd
)
5214 int scan_int
= atoi(cmd
);
5215 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5219 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5220 struct wpa_supplicant
*wpa_s
, char *cmd
)
5222 int expire_age
= atoi(cmd
);
5223 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5227 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5228 struct wpa_supplicant
*wpa_s
, char *cmd
)
5230 int expire_count
= atoi(cmd
);
5231 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5235 static void wpa_supplicant_ctrl_iface_bss_flush(
5236 struct wpa_supplicant
*wpa_s
, char *cmd
)
5238 int flush_age
= atoi(cmd
);
5241 wpa_bss_flush(wpa_s
);
5243 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5247 #ifdef CONFIG_TESTING_OPTIONS
5248 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5250 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5251 /* MLME-DELETEKEYS.request */
5252 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
5253 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
5254 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
5255 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
5256 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
5257 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
5259 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5261 /* MLME-SETPROTECTION.request(None) */
5262 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5263 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5264 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5265 wpa_sm_drop_sa(wpa_s
->wpa
);
5267 #endif /* CONFIG_TESTING_OPTIONS */
5270 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5273 #ifdef CONFIG_NO_SCAN_PROCESSING
5275 #else /* CONFIG_NO_SCAN_PROCESSING */
5277 struct wpa_bss
*bss
;
5278 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5280 if (hwaddr_aton(addr
, bssid
)) {
5281 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5282 "address '%s'", addr
);
5286 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5289 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5290 "configuration known for the target AP");
5294 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5296 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5302 * TODO: Find best network configuration block from configuration to
5303 * allow roaming to other networks
5306 wpa_s
->reassociate
= 1;
5307 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5310 #endif /* CONFIG_NO_SCAN_PROCESSING */
5315 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5317 unsigned int timeout
= atoi(cmd
);
5318 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5319 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5320 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5322 unsigned int search_delay
;
5323 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5327 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5328 wpa_dbg(wpa_s
, MSG_INFO
,
5329 "Reject P2P_FIND since interface is disabled");
5332 if (os_strstr(cmd
, "type=social"))
5333 type
= P2P_FIND_ONLY_SOCIAL
;
5334 else if (os_strstr(cmd
, "type=progressive"))
5335 type
= P2P_FIND_PROGRESSIVE
;
5337 pos
= os_strstr(cmd
, "dev_id=");
5340 if (hwaddr_aton(pos
, dev_id
))
5345 pos
= os_strstr(cmd
, "dev_type=");
5348 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5350 _dev_type
= dev_type
;
5353 pos
= os_strstr(cmd
, "delay=");
5356 search_delay
= atoi(pos
);
5358 search_delay
= wpas_p2p_search_delay(wpa_s
);
5360 pos
= os_strstr(cmd
, "freq=");
5368 /* Must be searched for last, because it adds nul termination */
5369 pos
= os_strstr(cmd
, " seek=");
5372 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5375 _seek
[seek_count
++] = pos
;
5377 term
= os_strchr(pos
, ' ');
5381 pos
= os_strstr(term
+ 1, "seek=");
5385 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5390 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5391 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5395 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5397 const char *last
= NULL
;
5402 /* Expected predefined CPT names delimited by ':' */
5403 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5404 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5405 wpa_printf(MSG_ERROR
,
5406 "P2PS: CPT name list is too long, expected up to %d names",
5407 P2PS_FEATURE_CAPAB_CPT_MAX
);
5412 token_len
= last
- token
;
5414 if (token_len
== 3 &&
5415 os_memcmp(token
, "UDP", token_len
) == 0) {
5416 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5417 } else if (token_len
== 3 &&
5418 os_memcmp(token
, "MAC", token_len
) == 0) {
5419 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5421 wpa_printf(MSG_ERROR
,
5422 "P2PS: Unsupported CPT name '%s'", token
);
5427 if (isblank((unsigned char) *last
)) {
5437 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5439 struct p2ps_provision
*p2ps_prov
;
5441 size_t info_len
= 0;
5443 u8 role
= P2PS_SETUP_NONE
;
5444 long long unsigned val
;
5447 pos
= os_strstr(cmd
, "info=");
5450 info_len
= os_strlen(pos
);
5453 info
= os_malloc(info_len
+ 1);
5455 info_len
= utf8_unescape(pos
, info_len
,
5456 info
, info_len
+ 1);
5462 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5463 if (p2ps_prov
== NULL
) {
5469 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5470 p2ps_prov
->info
[info_len
] = '\0';
5474 pos
= os_strstr(cmd
, "status=");
5476 p2ps_prov
->status
= atoi(pos
+ 7);
5478 p2ps_prov
->status
= -1;
5480 pos
= os_strstr(cmd
, "adv_id=");
5481 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5483 p2ps_prov
->adv_id
= val
;
5485 pos
= os_strstr(cmd
, "method=");
5487 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5489 p2ps_prov
->method
= 0;
5491 pos
= os_strstr(cmd
, "session=");
5492 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5494 p2ps_prov
->session_id
= val
;
5496 pos
= os_strstr(cmd
, "adv_mac=");
5497 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5500 pos
= os_strstr(cmd
, "session_mac=");
5501 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5504 pos
= os_strstr(cmd
, "cpt=");
5506 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5507 p2ps_prov
->cpt_priority
))
5510 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5513 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5514 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5516 /* force conncap with tstCap (no sanity checks) */
5517 pos
= os_strstr(cmd
, "tstCap=");
5519 role
= strtol(pos
+ 7, NULL
, 16);
5521 pos
= os_strstr(cmd
, "role=");
5523 role
= strtol(pos
+ 5, NULL
, 16);
5524 if (role
!= P2PS_SETUP_CLIENT
&&
5525 role
!= P2PS_SETUP_GROUP_OWNER
)
5526 role
= P2PS_SETUP_NONE
;
5529 p2ps_prov
->role
= role
;
5539 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5542 struct p2ps_provision
*p2ps_prov
;
5545 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5547 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5549 if (hwaddr_aton(cmd
, addr
))
5556 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5560 if (p2ps_prov
->status
< 0) {
5565 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5570 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5573 struct p2ps_provision
*p2ps_prov
;
5576 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5577 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5580 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5581 if (hwaddr_aton(cmd
, addr
))
5588 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5592 p2ps_prov
->pd_seeker
= 1;
5594 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5599 static int parse_freq(int chwidth
, int freq2
)
5604 return CHANWIDTH_80P80MHZ
;
5610 return CHANWIDTH_USE_HT
;
5612 return CHANWIDTH_80MHZ
;
5614 return CHANWIDTH_160MHZ
;
5616 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5623 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5624 char *buf
, size_t buflen
)
5629 enum p2p_wps_method wps_method
;
5632 int persistent_group
, persistent_id
= -1;
5639 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5640 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5641 size_t group_ssid_len
= 0;
5644 if (!wpa_s
->global
->p2p_init_wpa_s
)
5646 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5647 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5648 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5649 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5652 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5653 * [persistent|persistent=<network id>]
5654 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5655 * [ht40] [vht] [he] [auto] [ssid=<hexdump>] */
5657 if (hwaddr_aton(cmd
, addr
))
5665 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5666 pos2
= os_strstr(pos
, " persistent=");
5668 struct wpa_ssid
*ssid
;
5669 persistent_id
= atoi(pos2
+ 12);
5670 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5671 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5672 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5673 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5674 "SSID id=%d for persistent P2P group (GO)",
5679 join
= os_strstr(pos
, " join") != NULL
;
5680 auth
= os_strstr(pos
, " auth") != NULL
;
5681 automatic
= os_strstr(pos
, " auto") != NULL
;
5682 pd
= os_strstr(pos
, " provdisc") != NULL
;
5683 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5684 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5686 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
5688 pos2
= os_strstr(pos
, " go_intent=");
5691 go_intent
= atoi(pos2
);
5692 if (go_intent
< 0 || go_intent
> 15)
5696 pos2
= os_strstr(pos
, " freq=");
5704 pos2
= os_strstr(pos
, " freq2=");
5706 freq2
= atoi(pos2
+ 7);
5708 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5710 chwidth
= atoi(pos2
+ 18);
5712 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5713 if (max_oper_chwidth
< 0)
5716 pos2
= os_strstr(pos
, " ssid=");
5721 end
= os_strchr(pos2
, ' ');
5723 group_ssid_len
= os_strlen(pos2
) / 2;
5725 group_ssid_len
= (end
- pos2
) / 2;
5726 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5727 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5729 group_ssid
= _group_ssid
;
5732 if (os_strncmp(pos
, "pin", 3) == 0) {
5733 /* Request random PIN (to be displayed) and enable the PIN */
5734 wps_method
= WPS_PIN_DISPLAY
;
5735 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5736 wps_method
= WPS_PBC
;
5737 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5738 wps_method
= WPS_P2PS
;
5741 pos
= os_strchr(pin
, ' ');
5742 wps_method
= WPS_PIN_KEYPAD
;
5745 if (os_strncmp(pos
, "display", 7) == 0)
5746 wps_method
= WPS_PIN_DISPLAY
;
5748 if (!wps_pin_str_valid(pin
)) {
5749 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5754 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5755 persistent_group
, automatic
, join
,
5756 auth
, go_intent
, freq
, freq2
, persistent_id
,
5757 pd
, ht40
, vht
, max_oper_chwidth
, he
,
5758 group_ssid
, group_ssid_len
);
5759 if (new_pin
== -2) {
5760 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5763 if (new_pin
== -3) {
5764 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5769 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5770 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5771 if (os_snprintf_error(buflen
, ret
))
5776 os_memcpy(buf
, "OK\n", 3);
5781 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5783 unsigned int timeout
= atoi(cmd
);
5784 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5785 wpa_dbg(wpa_s
, MSG_INFO
,
5786 "Reject P2P_LISTEN since interface is disabled");
5789 return wpas_p2p_listen(wpa_s
, timeout
);
5793 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5797 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5799 /* <addr> <config method> [join|auto] */
5801 if (hwaddr_aton(cmd
, addr
))
5809 if (os_strstr(pos
, " join") != NULL
)
5810 use
= WPAS_P2P_PD_FOR_JOIN
;
5811 else if (os_strstr(pos
, " auto") != NULL
)
5812 use
= WPAS_P2P_PD_AUTO
;
5814 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5818 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5821 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5823 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5824 ssid
->passphrase
== NULL
)
5827 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5828 return os_strlen(buf
);
5832 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5833 char *buf
, size_t buflen
)
5837 u8 dst_buf
[ETH_ALEN
], *dst
;
5838 struct wpabuf
*tlvs
;
5842 if (hwaddr_aton(cmd
, dst_buf
))
5845 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5846 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5853 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5856 if (hexstr2bin(pos
, &version
, 1) < 0)
5862 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5863 #ifdef CONFIG_WIFI_DISPLAY
5864 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5865 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5866 #endif /* CONFIG_WIFI_DISPLAY */
5867 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5869 char *svc_info
= NULL
;
5873 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5876 pos
= os_strchr(pos
, ' ');
5877 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5882 pos
= os_strchr(svc_str
, ' ');
5887 /* All remaining data is the svc_info string */
5888 if (pos
&& pos
[0] && pos
[0] != ' ') {
5889 len
= os_strlen(pos
);
5891 /* Unescape in place */
5892 len
= utf8_unescape(pos
, len
, pos
, len
);
5899 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5902 len
= os_strlen(pos
);
5906 tlvs
= wpabuf_alloc(len
);
5909 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5914 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5919 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5920 if (os_snprintf_error(buflen
, res
))
5926 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5929 long long unsigned val
;
5931 if (sscanf(cmd
, "%llx", &val
) != 1)
5934 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5938 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5943 struct wpabuf
*resp_tlvs
;
5947 pos
= os_strchr(cmd
, ' ');
5955 if (hwaddr_aton(pos
, dst
))
5962 pos2
= os_strchr(pos
, ' ');
5966 dialog_token
= atoi(pos
);
5968 len
= os_strlen(pos2
);
5972 resp_tlvs
= wpabuf_alloc(len
);
5973 if (resp_tlvs
== NULL
)
5975 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5976 wpabuf_free(resp_tlvs
);
5980 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5981 wpabuf_free(resp_tlvs
);
5986 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5989 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5991 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5996 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
6001 struct wpabuf
*query
, *resp
;
6003 pos
= os_strchr(cmd
, ' ');
6008 len
= os_strlen(cmd
);
6012 query
= wpabuf_alloc(len
);
6015 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6020 len
= os_strlen(pos
);
6026 resp
= wpabuf_alloc(len
);
6031 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
6037 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
6046 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6051 pos
= os_strchr(cmd
, ' ');
6056 if (hexstr2bin(cmd
, &version
, 1) < 0)
6059 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
6063 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
6064 u8 replace
, char *cmd
)
6068 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
6069 char *svc_info
= NULL
;
6071 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
6073 pos
= os_strchr(cmd
, ' ');
6078 /* Auto-Accept value is mandatory, and must be one of the
6079 * single values (0, 1, 2, 4) */
6080 auto_accept
= atoi(cmd
);
6081 switch (auto_accept
) {
6082 case P2PS_SETUP_NONE
: /* No auto-accept */
6083 case P2PS_SETUP_NEW
:
6084 case P2PS_SETUP_CLIENT
:
6085 case P2PS_SETUP_GROUP_OWNER
:
6091 /* Advertisement ID is mandatory */
6093 pos
= os_strchr(cmd
, ' ');
6098 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6099 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
6102 /* Only allow replacements if exist, and adds if not */
6103 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
6111 /* svc_state between 0 - 0xff is mandatory */
6112 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
6115 pos
= os_strchr(pos
, ' ');
6119 /* config_methods is mandatory */
6121 if (sscanf(pos
, "%x", &config_methods
) != 1)
6124 if (!(config_methods
&
6125 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
6128 pos
= os_strchr(pos
, ' ');
6135 /* Advertisement string is mandatory */
6136 if (!pos
[0] || pos
[0] == ' ')
6139 /* Terminate svc string */
6140 pos
= os_strchr(pos
, ' ');
6144 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
6146 pos
= os_strchr(pos
, ' ');
6150 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
6153 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
6157 /* Service and Response Information are optional */
6158 if (pos
&& pos
[0]) {
6161 /* Note the bare ' included, which cannot exist legally
6162 * in unescaped string. */
6163 svc_info
= os_strstr(pos
, "svc_info='");
6167 len
= os_strlen(svc_info
);
6168 utf8_unescape(svc_info
, len
, svc_info
, len
);
6172 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
6173 (u8
) svc_state
, (u16
) config_methods
,
6174 svc_info
, cpt_prio
);
6178 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6182 pos
= os_strchr(cmd
, ' ');
6187 if (os_strcmp(cmd
, "bonjour") == 0)
6188 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
6189 if (os_strcmp(cmd
, "upnp") == 0)
6190 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
6191 if (os_strcmp(cmd
, "asp") == 0)
6192 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
6193 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6198 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
6202 struct wpabuf
*query
;
6205 len
= os_strlen(cmd
);
6209 query
= wpabuf_alloc(len
);
6212 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6217 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6223 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6228 pos
= os_strchr(cmd
, ' ');
6233 if (hexstr2bin(cmd
, &version
, 1) < 0)
6236 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6240 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6244 if (os_strcmp(cmd
, "all") == 0) {
6245 wpas_p2p_service_flush_asp(wpa_s
);
6249 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6252 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6256 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6260 pos
= os_strchr(cmd
, ' ');
6265 if (os_strcmp(cmd
, "bonjour") == 0)
6266 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6267 if (os_strcmp(cmd
, "upnp") == 0)
6268 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6269 if (os_strcmp(cmd
, "asp") == 0)
6270 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6271 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6276 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6280 pos
= os_strchr(cmd
, ' ');
6285 if (os_strcmp(cmd
, "asp") == 0)
6286 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6288 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6293 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6299 if (hwaddr_aton(cmd
, addr
))
6302 return wpas_p2p_reject(wpa_s
, addr
);
6306 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6310 struct wpa_ssid
*ssid
;
6311 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6312 int freq
= 0, pref_freq
= 0;
6313 int ht40
, vht
, he
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6316 pos
= os_strstr(cmd
, " peer=");
6319 if (hwaddr_aton(pos
, peer
))
6323 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6324 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6325 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6326 "for persistent P2P group",
6331 pos
= os_strstr(cmd
, " freq=");
6339 pos
= os_strstr(cmd
, " pref=");
6342 pref_freq
= atoi(pos
);
6347 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6348 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6350 he
= (os_strstr(cmd
, " he") != NULL
) || wpa_s
->conf
->p2p_go_he
;
6352 pos
= os_strstr(cmd
, "freq2=");
6354 freq2
= atoi(pos
+ 6);
6356 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6358 chwidth
= atoi(pos
+ 18);
6360 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6361 if (max_oper_chwidth
< 0)
6364 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6365 max_oper_chwidth
, pref_freq
, he
);
6369 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6372 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6374 pos
= os_strstr(cmd
, " peer=");
6380 if (hwaddr_aton(pos
, peer
)) {
6381 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6385 pos
= os_strstr(pos
, " go_dev_addr=");
6388 if (hwaddr_aton(pos
, go_dev_addr
)) {
6389 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6393 go_dev
= go_dev_addr
;
6396 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6400 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6402 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6403 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6404 if (os_strncmp(cmd
, "group=", 6) == 0)
6405 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6411 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6412 int id
, int freq
, int vht_center_freq2
,
6413 int ht40
, int vht
, int vht_chwidth
,
6416 struct wpa_ssid
*ssid
;
6418 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6419 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6420 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6421 "for persistent P2P group",
6426 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6427 vht_center_freq2
, 0, ht40
, vht
,
6428 vht_chwidth
, he
, NULL
, 0, 0);
6432 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6434 int freq
= 0, persistent
= 0, group_id
= -1;
6435 int vht
= wpa_s
->conf
->p2p_go_vht
;
6436 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6437 int he
= wpa_s
->conf
->p2p_go_he
;
6438 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6439 char *token
, *context
= NULL
;
6442 #endif /* CONFIG_ACS */
6444 while ((token
= str_token(cmd
, " ", &context
))) {
6445 if (sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6446 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6447 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6450 } else if (os_strcmp(token
, "freq=acs") == 0) {
6452 #endif /* CONFIG_ACS */
6453 } else if (sscanf(token
, "freq=%d", &freq
) == 1) {
6455 } else if (os_strcmp(token
, "ht40") == 0) {
6457 } else if (os_strcmp(token
, "vht") == 0) {
6460 } else if (os_strcmp(token
, "he") == 0) {
6462 } else if (os_strcmp(token
, "persistent") == 0) {
6465 wpa_printf(MSG_DEBUG
,
6466 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6473 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_ACS_OFFLOAD
) &&
6474 (acs
|| freq
== 2 || freq
== 5)) {
6475 if (freq
== 2 && wpa_s
->best_24_freq
<= 0) {
6476 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211G
;
6477 wpa_s
->p2p_go_do_acs
= 1;
6479 } else if (freq
== 5 && wpa_s
->best_5_freq
<= 0) {
6480 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211A
;
6481 wpa_s
->p2p_go_do_acs
= 1;
6484 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211ANY
;
6485 wpa_s
->p2p_go_do_acs
= 1;
6488 wpa_s
->p2p_go_do_acs
= 0;
6490 #endif /* CONFIG_ACS */
6492 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6493 if (max_oper_chwidth
< 0)
6497 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6498 freq
, freq2
, ht40
, vht
,
6499 max_oper_chwidth
, he
);
6501 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6502 max_oper_chwidth
, he
);
6506 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6507 char *buf
, size_t buflen
)
6509 u8 dev_addr
[ETH_ALEN
];
6510 struct wpa_ssid
*ssid
;
6514 ssid
= wpa_s
->current_ssid
;
6515 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6516 hwaddr_aton(cmd
, dev_addr
))
6519 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6522 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6523 if (os_snprintf_error(buflen
, res
))
6529 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6530 const u8
*p2p_dev_addr
)
6532 struct wpa_supplicant
*wpa_s
;
6534 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6535 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6543 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6544 char *buf
, size_t buflen
)
6546 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6548 const struct p2p_peer_info
*info
;
6550 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6551 struct wpa_ssid
*ssid
;
6554 if (!wpa_s
->global
->p2p
)
6557 if (os_strcmp(cmd
, "FIRST") == 0) {
6560 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6561 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6566 if (hwaddr_aton(cmd
, addr
) < 0)
6572 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6575 group_capab
= info
->group_capab
;
6578 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6579 wpa_printf(MSG_DEBUG
,
6580 "P2P: Could not find any BSS with p2p_dev_addr "
6581 MACSTR
", hence override group_capab from 0x%x to 0",
6582 MAC2STR(info
->p2p_device_addr
), group_capab
);
6589 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6595 "serial_number=%s\n"
6596 "config_methods=0x%x\n"
6598 "group_capab=0x%x\n"
6600 MAC2STR(info
->p2p_device_addr
),
6601 wps_dev_type_bin2str(info
->pri_dev_type
,
6602 devtype
, sizeof(devtype
)),
6607 info
->serial_number
,
6608 info
->config_methods
,
6612 if (os_snprintf_error(end
- pos
, res
))
6616 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6619 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6620 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6621 wps_dev_type_bin2str(t
, devtype
,
6623 if (os_snprintf_error(end
- pos
, res
))
6628 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6630 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6631 if (os_snprintf_error(end
- pos
, res
))
6636 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6641 if (info
->vendor_elems
) {
6642 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6643 if (os_snprintf_error(end
- pos
, res
))
6647 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6648 wpabuf_head(info
->vendor_elems
),
6649 wpabuf_len(info
->vendor_elems
));
6651 res
= os_snprintf(pos
, end
- pos
, "\n");
6652 if (os_snprintf_error(end
- pos
, res
))
6661 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6666 if (wpa_s
->global
->p2p
== NULL
)
6669 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6672 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6673 struct wpa_freq_range
*freq
;
6674 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6675 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6676 freq
->min
, freq
->max
);
6679 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6684 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6688 if (wpa_s
->global
->p2p
== NULL
)
6691 param
= os_strchr(cmd
, ' ');
6696 if (os_strcmp(cmd
, "discoverability") == 0) {
6697 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6702 if (os_strcmp(cmd
, "managed") == 0) {
6703 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6707 if (os_strcmp(cmd
, "listen_channel") == 0) {
6709 u8 channel
, op_class
;
6711 channel
= atoi(param
);
6712 pos
= os_strchr(param
, ' ');
6713 op_class
= pos
? atoi(pos
) : 81;
6715 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6719 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6720 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6724 if (os_strcmp(cmd
, "noa") == 0) {
6726 int count
, start
, duration
;
6727 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6728 count
= atoi(param
);
6729 pos
= os_strchr(param
, ',');
6734 pos
= os_strchr(pos
, ',');
6738 duration
= atoi(pos
);
6739 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6741 if (count
== 0 && duration
> 0)
6743 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6744 "start=%d duration=%d", count
, start
, duration
);
6745 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6748 if (os_strcmp(cmd
, "ps") == 0)
6749 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6751 if (os_strcmp(cmd
, "oppps") == 0)
6752 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6754 if (os_strcmp(cmd
, "ctwindow") == 0)
6755 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6757 if (os_strcmp(cmd
, "disabled") == 0) {
6758 wpa_s
->global
->p2p_disabled
= atoi(param
);
6759 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6760 wpa_s
->global
->p2p_disabled
?
6761 "disabled" : "enabled");
6762 if (wpa_s
->global
->p2p_disabled
) {
6763 wpas_p2p_stop_find(wpa_s
);
6764 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6765 p2p_flush(wpa_s
->global
->p2p
);
6770 if (os_strcmp(cmd
, "conc_pref") == 0) {
6771 if (os_strcmp(param
, "sta") == 0)
6772 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6773 else if (os_strcmp(param
, "p2p") == 0)
6774 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6776 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6779 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6784 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6785 wpa_s
->force_long_sd
= atoi(param
);
6789 if (os_strcmp(cmd
, "peer_filter") == 0) {
6791 if (hwaddr_aton(param
, addr
))
6793 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6797 if (os_strcmp(cmd
, "cross_connect") == 0)
6798 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6800 if (os_strcmp(cmd
, "go_apsd") == 0) {
6801 if (os_strcmp(param
, "disable") == 0)
6802 wpa_s
->set_ap_uapsd
= 0;
6804 wpa_s
->set_ap_uapsd
= 1;
6805 wpa_s
->ap_uapsd
= atoi(param
);
6810 if (os_strcmp(cmd
, "client_apsd") == 0) {
6811 if (os_strcmp(param
, "disable") == 0)
6812 wpa_s
->set_sta_uapsd
= 0;
6816 /* format: BE,BK,VI,VO;max SP Length */
6818 pos
= os_strchr(param
, ',');
6823 pos
= os_strchr(pos
, ',');
6828 pos
= os_strchr(pos
, ',');
6833 /* ignore max SP Length for now */
6835 wpa_s
->set_sta_uapsd
= 1;
6836 wpa_s
->sta_uapsd
= 0;
6838 wpa_s
->sta_uapsd
|= BIT(0);
6840 wpa_s
->sta_uapsd
|= BIT(1);
6842 wpa_s
->sta_uapsd
|= BIT(2);
6844 wpa_s
->sta_uapsd
|= BIT(3);
6849 if (os_strcmp(cmd
, "disallow_freq") == 0)
6850 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6852 if (os_strcmp(cmd
, "disc_int") == 0) {
6853 int min_disc_int
, max_disc_int
, max_disc_tu
;
6858 min_disc_int
= atoi(pos
);
6859 pos
= os_strchr(pos
, ' ');
6864 max_disc_int
= atoi(pos
);
6865 pos
= os_strchr(pos
, ' ');
6870 max_disc_tu
= atoi(pos
);
6872 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6873 max_disc_int
, max_disc_tu
);
6876 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6877 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6881 #ifdef CONFIG_WPS_NFC
6882 if (os_strcmp(cmd
, "nfc_tag") == 0)
6883 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6884 #endif /* CONFIG_WPS_NFC */
6886 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6887 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6891 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6894 op_class
= atoi(param
);
6895 param
= os_strchr(param
, ':');
6900 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6905 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6912 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6914 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6915 wpa_s
->force_long_sd
= 0;
6917 #ifdef CONFIG_TESTING_OPTIONS
6918 os_free(wpa_s
->get_pref_freq_list_override
);
6919 wpa_s
->get_pref_freq_list_override
= NULL
;
6920 #endif /* CONFIG_TESTING_OPTIONS */
6922 wpas_p2p_stop_find(wpa_s
);
6923 wpa_s
->parent
->p2ps_method_config_any
= 0;
6924 if (wpa_s
->global
->p2p
)
6925 p2p_flush(wpa_s
->global
->p2p
);
6929 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6932 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6935 pos
= os_strchr(cmd
, ' ');
6941 pos2
= os_strchr(pos
, ' ');
6949 pos
= os_strchr(pos2
, ' ');
6957 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6961 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6964 unsigned int period
= 0, interval
= 0;
6967 pos
= os_strchr(cmd
, ' ');
6972 interval
= atoi(pos
);
6975 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6979 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6986 if (os_strncmp(pos
, "iface=", 6) == 0) {
6990 if (hwaddr_aton(pos
, peer
))
6993 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6998 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
7000 int freq
= 0, period
= 0, interval
= 0, count
= 0;
7002 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
7004 wpa_printf(MSG_DEBUG
,
7005 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
7009 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
7012 #endif /* CONFIG_P2P */
7015 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
7017 struct wpa_freq_range_list ranges
;
7019 struct hostapd_hw_modes
*mode
;
7022 if (wpa_s
->hw
.modes
== NULL
)
7025 os_memset(&ranges
, 0, sizeof(ranges
));
7026 if (freq_range_list_parse(&ranges
, val
) < 0)
7029 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
7032 mode
= &wpa_s
->hw
.modes
[i
];
7033 for (j
= 0; j
< mode
->num_channels
; j
++) {
7036 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
7039 freq
= mode
->channels
[j
].freq
;
7040 if (!freq_range_list_includes(&ranges
, freq
))
7043 int_array_add_unique(&freqs
, freq
);
7047 os_free(ranges
.range
);
7052 #ifdef CONFIG_INTERWORKING
7054 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
7062 auto_sel
= os_strstr(param
, "auto") != NULL
;
7064 pos
= os_strstr(param
, "freq=");
7066 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
7073 return interworking_select(wpa_s
, auto_sel
, freqs
);
7077 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
7081 struct wpa_bss
*bss
;
7083 if (hwaddr_aton(dst
, bssid
)) {
7084 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
7088 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
7090 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
7095 if (bss
->ssid_len
== 0) {
7098 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
7099 " does not have SSID information", MAC2STR(bssid
));
7101 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
7103 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
7104 bss
->ssid_len
> 0) {
7112 wpa_printf(MSG_DEBUG
,
7113 "Found another matching BSS entry with SSID");
7116 return interworking_connect(wpa_s
, bss
, only_add
);
7120 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7122 u8 dst_addr
[ETH_ALEN
];
7125 #define MAX_ANQP_INFO_ID 100
7126 u16 id
[MAX_ANQP_INFO_ID
];
7129 u32 mbo_subtypes
= 0;
7131 used
= hwaddr_aton2(dst
, dst_addr
);
7137 while (num_id
< MAX_ANQP_INFO_ID
) {
7138 if (os_strncmp(pos
, "hs20:", 5) == 0) {
7140 int num
= atoi(pos
+ 5);
7141 if (num
<= 0 || num
> 31)
7143 subtypes
|= BIT(num
);
7144 #else /* CONFIG_HS20 */
7146 #endif /* CONFIG_HS20 */
7147 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
7149 int num
= atoi(pos
+ 4);
7151 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
7153 mbo_subtypes
|= BIT(num
);
7154 #else /* CONFIG_MBO */
7156 #endif /* CONFIG_MBO */
7158 id
[num_id
] = atoi(pos
);
7162 pos
= os_strchr(pos
+ 1, ',');
7168 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
7171 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
7176 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
7178 u8 dst_addr
[ETH_ALEN
];
7179 struct wpabuf
*advproto
, *query
= NULL
;
7184 used
= hwaddr_aton2(cmd
, dst_addr
);
7192 /* Advertisement Protocol ID */
7193 end
= os_strchr(pos
, ' ');
7197 len
= os_strlen(pos
);
7203 advproto
= wpabuf_alloc(len
);
7204 if (advproto
== NULL
)
7206 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
7210 /* Optional Query Request */
7215 len
= os_strlen(pos
);
7222 query
= wpabuf_alloc(len
);
7225 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
7230 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
7233 wpabuf_free(advproto
);
7240 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7247 size_t resp_len
, start
, requested_len
;
7248 struct wpabuf
*resp
;
7251 used
= hwaddr_aton2(cmd
, addr
);
7258 dialog_token
= atoi(pos
);
7260 if (wpa_s
->last_gas_resp
&&
7261 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7262 dialog_token
== wpa_s
->last_gas_dialog_token
)
7263 resp
= wpa_s
->last_gas_resp
;
7264 else if (wpa_s
->prev_gas_resp
&&
7265 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7266 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7267 resp
= wpa_s
->prev_gas_resp
;
7271 resp_len
= wpabuf_len(resp
);
7273 requested_len
= resp_len
;
7275 pos
= os_strchr(pos
, ' ');
7278 if (start
> resp_len
)
7279 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7280 pos
= os_strchr(pos
, ',');
7284 requested_len
= atoi(pos
);
7285 if (start
+ requested_len
> resp_len
)
7286 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7289 if (requested_len
* 2 + 1 > buflen
)
7290 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7292 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7295 if (start
+ requested_len
== resp_len
) {
7297 * Free memory by dropping the response after it has been
7300 if (resp
== wpa_s
->prev_gas_resp
) {
7301 wpabuf_free(wpa_s
->prev_gas_resp
);
7302 wpa_s
->prev_gas_resp
= NULL
;
7304 wpabuf_free(wpa_s
->last_gas_resp
);
7305 wpa_s
->last_gas_resp
= NULL
;
7311 #endif /* CONFIG_INTERWORKING */
7316 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7318 u8 dst_addr
[ETH_ALEN
];
7323 used
= hwaddr_aton2(dst
, dst_addr
);
7330 int num
= atoi(pos
);
7331 if (num
<= 0 || num
> 31)
7333 subtypes
|= BIT(num
);
7334 pos
= os_strchr(pos
+ 1, ',');
7343 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7347 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7348 const u8
*addr
, const char *realm
)
7354 rlen
= os_strlen(realm
);
7356 buf
= os_malloc(len
);
7359 buf
[0] = 1; /* NAI Home Realm Count */
7360 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7362 os_memcpy(buf
+ 3, realm
, rlen
);
7364 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7365 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7374 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7377 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7378 u8 dst_addr
[ETH_ALEN
];
7384 used
= hwaddr_aton2(dst
, dst_addr
);
7388 while (dst
[used
] == ' ')
7390 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7391 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7394 len
= os_strlen(dst
+ used
);
7396 if (len
== 0 && cred
&& cred
->realm
)
7397 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7402 buf
= os_malloc(len
);
7405 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7410 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7411 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7419 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7422 u8 dst_addr
[ETH_ALEN
];
7424 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7426 used
= hwaddr_aton2(cmd
, dst_addr
);
7431 icon
= str_token(cmd
, " ", &ctx
);
7432 poffset
= str_token(cmd
, " ", &ctx
);
7433 psize
= str_token(cmd
, " ", &ctx
);
7434 if (!icon
|| !poffset
|| !psize
)
7437 wpa_s
->fetch_osu_icon_in_progress
= 0;
7438 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7443 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7445 u8 dst_addr
[ETH_ALEN
];
7450 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7452 used
= hwaddr_aton2(cmd
, dst_addr
);
7456 while (cmd
[used
] == ' ')
7458 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7460 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7464 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7466 u8 dst_addr
[ETH_ALEN
];
7470 used
= hwaddr_aton2(cmd
, dst_addr
);
7474 while (cmd
[used
] == ' ')
7478 wpa_s
->fetch_osu_icon_in_progress
= 0;
7479 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7480 (u8
*) icon
, os_strlen(icon
), inmem
);
7483 #endif /* CONFIG_HS20 */
7486 #ifdef CONFIG_AUTOSCAN
7488 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7491 enum wpa_states state
= wpa_s
->wpa_state
;
7492 char *new_params
= NULL
;
7494 if (os_strlen(cmd
) > 0) {
7495 new_params
= os_strdup(cmd
);
7496 if (new_params
== NULL
)
7500 os_free(wpa_s
->conf
->autoscan
);
7501 wpa_s
->conf
->autoscan
= new_params
;
7503 if (wpa_s
->conf
->autoscan
== NULL
)
7504 autoscan_deinit(wpa_s
);
7505 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7506 autoscan_init(wpa_s
, 1);
7507 else if (state
== WPA_SCANNING
)
7508 wpa_supplicant_reinit_autoscan(wpa_s
);
7510 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7511 wpa_supplicant_state_txt(state
));
7516 #endif /* CONFIG_AUTOSCAN */
7521 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7527 struct wpabuf
*tfs_req
= NULL
;
7529 if (os_strncmp(cmd
, "enter", 5) == 0)
7531 else if (os_strncmp(cmd
, "exit", 4) == 0)
7536 pos
= os_strstr(cmd
, " interval=");
7538 intval
= atoi(pos
+ 10);
7540 pos
= os_strstr(cmd
, " tfs_req=");
7545 end
= os_strchr(pos
, ' ');
7549 len
= os_strlen(pos
);
7553 tfs_req
= wpabuf_alloc(len
);
7554 if (tfs_req
== NULL
)
7556 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7557 wpabuf_free(tfs_req
);
7562 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7563 WNM_SLEEP_MODE_EXIT
, intval
,
7565 wpabuf_free(tfs_req
);
7571 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7573 int query_reason
, list
= 0;
7574 char *btm_candidates
= NULL
;
7576 query_reason
= atoi(cmd
);
7578 cmd
= os_strchr(cmd
, ' ');
7580 if (os_strncmp(cmd
, " list", 5) == 0)
7583 btm_candidates
= cmd
;
7586 wpa_printf(MSG_DEBUG
,
7587 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7588 query_reason
, list
? " candidate list" : "");
7590 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7596 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant
*wpa_s
,
7599 struct wpabuf
*elems
;
7602 elems
= wpabuf_parse_bin(cmd
);
7606 ret
= wnm_send_coloc_intf_report(wpa_s
, 0, elems
);
7611 #endif /* CONFIG_WNM */
7614 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7617 struct wpa_signal_info si
;
7621 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7628 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7629 "NOISE=%d\nFREQUENCY=%u\n",
7630 si
.current_signal
, si
.current_txrate
/ 1000,
7631 si
.current_noise
, si
.frequency
);
7632 if (os_snprintf_error(end
- pos
, ret
))
7636 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7637 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7638 channel_width_to_string(si
.chanwidth
));
7639 if (os_snprintf_error(end
- pos
, ret
))
7644 if (si
.center_frq1
> 0) {
7645 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ1=%d\n",
7647 if (os_snprintf_error(end
- pos
, ret
))
7652 if (si
.center_frq2
> 0) {
7653 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ2=%d\n",
7655 if (os_snprintf_error(end
- pos
, ret
))
7660 if (si
.avg_signal
) {
7661 ret
= os_snprintf(pos
, end
- pos
,
7662 "AVG_RSSI=%d\n", si
.avg_signal
);
7663 if (os_snprintf_error(end
- pos
, ret
))
7668 if (si
.avg_beacon_signal
) {
7669 ret
= os_snprintf(pos
, end
- pos
,
7670 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7671 if (os_snprintf_error(end
- pos
, ret
))
7680 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7687 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7688 wpa_printf(MSG_DEBUG
,
7689 "Reject SIGNAL_MONITOR command - bgscan is active");
7692 pos
= os_strstr(cmd
, "THRESHOLD=");
7694 threshold
= atoi(pos
+ 10);
7695 pos
= os_strstr(cmd
, "HYSTERESIS=");
7697 hysteresis
= atoi(pos
+ 11);
7698 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7702 #ifdef CONFIG_TESTING_OPTIONS
7703 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7704 enum wpa_driver_if_type if_type
,
7706 unsigned int *freq_list
)
7708 char *pos
= wpa_s
->get_pref_freq_list_override
;
7710 unsigned int count
= 0;
7712 /* Override string format:
7713 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7716 if (atoi(pos
) == (int) if_type
)
7718 pos
= os_strchr(pos
, ' ');
7724 pos
= os_strchr(pos
, ':');
7728 end
= os_strchr(pos
, ' ');
7729 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7730 freq_list
[count
++] = atoi(pos
);
7731 pos
= os_strchr(pos
, ',');
7739 #endif /* CONFIG_TESTING_OPTIONS */
7742 static int wpas_ctrl_iface_get_pref_freq_list(
7743 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7745 unsigned int freq_list
[100], num
= 100, i
;
7747 enum wpa_driver_if_type iface_type
;
7753 /* buf: "<interface_type>" */
7754 if (os_strcmp(cmd
, "STATION") == 0)
7755 iface_type
= WPA_IF_STATION
;
7756 else if (os_strcmp(cmd
, "AP") == 0)
7757 iface_type
= WPA_IF_AP_BSS
;
7758 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7759 iface_type
= WPA_IF_P2P_GO
;
7760 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7761 iface_type
= WPA_IF_P2P_CLIENT
;
7762 else if (os_strcmp(cmd
, "IBSS") == 0)
7763 iface_type
= WPA_IF_IBSS
;
7764 else if (os_strcmp(cmd
, "TDLS") == 0)
7765 iface_type
= WPA_IF_TDLS
;
7769 wpa_printf(MSG_DEBUG
,
7770 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7773 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7777 for (i
= 0; i
< num
; i
++) {
7778 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7779 i
> 0 ? "," : "", freq_list
[i
]);
7780 if (os_snprintf_error(end
- pos
, ret
))
7789 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7790 char *buf
, size_t buflen
)
7795 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7796 (long long unsigned) wpa_s
->drv_flags
);
7797 if (os_snprintf_error(buflen
, ret
))
7803 for (i
= 0; i
< 64; i
++) {
7804 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7805 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7806 driver_flag_to_string(1LLU << i
));
7807 if (os_snprintf_error(end
- pos
, ret
))
7817 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7820 struct hostap_sta_driver_data sta
;
7823 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7827 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7828 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7829 if (os_snprintf_error(buflen
, ret
))
7836 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7837 char *buf
, size_t buflen
)
7841 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7843 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7844 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7847 country
[0] = cmd
[8];
7848 country
[1] = cmd
[9];
7850 p2p_set_country(p2p
, country
);
7853 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7854 if (os_snprintf_error(buflen
, ret
))
7859 #endif /* ANDROID */
7862 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7863 char *buf
, size_t buflen
)
7868 unsigned int vendor_id
, subcmd
;
7869 struct wpabuf
*reply
;
7870 size_t data_len
= 0;
7872 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7873 vendor_id
= strtoul(cmd
, &pos
, 16);
7874 if (!isblank((unsigned char) *pos
))
7877 subcmd
= strtoul(pos
, &pos
, 10);
7880 if (!isblank((unsigned char) *pos
++))
7882 data_len
= os_strlen(pos
);
7887 data
= os_malloc(data_len
);
7891 if (hexstr2bin(pos
, data
, data_len
)) {
7892 wpa_printf(MSG_DEBUG
,
7893 "Vendor command: wrong parameter format");
7899 reply
= wpabuf_alloc((buflen
- 1) / 2);
7905 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7909 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7919 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7922 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7923 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7924 #endif /* CONFIG_P2P */
7926 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7928 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7929 wpa_s
->ignore_post_flush_scan_res
= 1;
7931 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7933 * Avoid possible auto connect re-connection on getting
7934 * disconnected due to state flush.
7936 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7940 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7941 wpas_p2p_cancel(p2p_wpa_s
);
7942 p2p_ctrl_flush(p2p_wpa_s
);
7943 wpas_p2p_service_flush(p2p_wpa_s
);
7944 p2p_wpa_s
->global
->p2p_disabled
= 0;
7945 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7946 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7947 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7948 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7949 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7950 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7951 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7952 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7953 #endif /* CONFIG_P2P */
7955 #ifdef CONFIG_WPS_TESTING
7956 wps_version_number
= 0x20;
7957 wps_testing_dummy_cred
= 0;
7958 wps_corrupt_pkhash
= 0;
7959 wps_force_auth_types_in_use
= 0;
7960 wps_force_encr_types_in_use
= 0;
7961 #endif /* CONFIG_WPS_TESTING */
7963 wpa_s
->wps_fragment_size
= 0;
7964 wpas_wps_cancel(wpa_s
);
7965 wps_registrar_flush(wpa_s
->wps
->registrar
);
7966 #endif /* CONFIG_WPS */
7967 wpa_s
->after_wps
= 0;
7968 wpa_s
->known_wps_freq
= 0;
7971 wpas_dpp_deinit(wpa_s
);
7972 wpa_s
->dpp_init_max_tries
= 0;
7973 wpa_s
->dpp_init_retry_time
= 0;
7974 wpa_s
->dpp_resp_wait_time
= 0;
7975 wpa_s
->dpp_resp_max_tries
= 0;
7976 wpa_s
->dpp_resp_retry_time
= 0;
7977 #ifdef CONFIG_TESTING_OPTIONS
7978 os_memset(dpp_pkex_own_mac_override
, 0, ETH_ALEN
);
7979 os_memset(dpp_pkex_peer_mac_override
, 0, ETH_ALEN
);
7980 dpp_pkex_ephemeral_key_override_len
= 0;
7981 dpp_protocol_key_override_len
= 0;
7982 dpp_nonce_override_len
= 0;
7983 #endif /* CONFIG_TESTING_OPTIONS */
7984 #endif /* CONFIG_DPP */
7987 #ifdef CONFIG_TDLS_TESTING
7989 #endif /* CONFIG_TDLS_TESTING */
7990 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7991 wpa_tdls_enable(wpa_s
->wpa
, 1);
7992 #endif /* CONFIG_TDLS */
7994 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7995 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7997 wpa_s
->no_keep_alive
= 0;
7998 wpa_s
->own_disconnect_req
= 0;
8000 os_free(wpa_s
->disallow_aps_bssid
);
8001 wpa_s
->disallow_aps_bssid
= NULL
;
8002 wpa_s
->disallow_aps_bssid_count
= 0;
8003 os_free(wpa_s
->disallow_aps_ssid
);
8004 wpa_s
->disallow_aps_ssid
= NULL
;
8005 wpa_s
->disallow_aps_ssid_count
= 0;
8007 wpa_s
->set_sta_uapsd
= 0;
8008 wpa_s
->sta_uapsd
= 0;
8010 wpa_drv_radio_disable(wpa_s
, 0);
8011 wpa_blacklist_clear(wpa_s
);
8012 wpa_s
->extra_blacklist_count
= 0;
8013 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
8014 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
8015 wpa_config_flush_blobs(wpa_s
->conf
);
8016 wpa_s
->conf
->auto_interworking
= 0;
8017 wpa_s
->conf
->okc
= 0;
8019 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
8020 rsn_preauth_deinit(wpa_s
->wpa
);
8022 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
8023 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
8024 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
8025 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
8027 radio_remove_works(wpa_s
, NULL
, 1);
8028 wpa_s
->ext_work_in_progress
= 0;
8030 wpa_s
->next_ssid
= NULL
;
8032 #ifdef CONFIG_INTERWORKING
8034 hs20_cancel_fetch_osu(wpa_s
);
8035 hs20_del_icon(wpa_s
, NULL
, NULL
);
8036 #endif /* CONFIG_HS20 */
8037 #endif /* CONFIG_INTERWORKING */
8039 wpa_s
->ext_mgmt_frame_handling
= 0;
8040 wpa_s
->ext_eapol_frame_io
= 0;
8041 #ifdef CONFIG_TESTING_OPTIONS
8042 wpa_s
->extra_roc_dur
= 0;
8043 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
8044 wpa_s
->p2p_go_csa_on_inv
= 0;
8045 wpa_s
->ignore_auth_resp
= 0;
8046 wpa_s
->ignore_assoc_disallow
= 0;
8047 wpa_s
->testing_resend_assoc
= 0;
8048 wpa_s
->reject_btm_req_reason
= 0;
8049 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
8050 os_free(wpa_s
->get_pref_freq_list_override
);
8051 wpa_s
->get_pref_freq_list_override
= NULL
;
8052 wpabuf_free(wpa_s
->sae_commit_override
);
8053 wpa_s
->sae_commit_override
= NULL
;
8055 os_free(wpa_s
->dpp_config_obj_override
);
8056 wpa_s
->dpp_config_obj_override
= NULL
;
8057 os_free(wpa_s
->dpp_discovery_override
);
8058 wpa_s
->dpp_discovery_override
= NULL
;
8059 os_free(wpa_s
->dpp_groups_override
);
8060 wpa_s
->dpp_groups_override
= NULL
;
8061 dpp_test
= DPP_TEST_DISABLED
;
8062 #endif /* CONFIG_DPP */
8063 #endif /* CONFIG_TESTING_OPTIONS */
8065 wpa_s
->disconnected
= 0;
8066 os_free(wpa_s
->next_scan_freqs
);
8067 wpa_s
->next_scan_freqs
= NULL
;
8068 os_free(wpa_s
->select_network_scan_freqs
);
8069 wpa_s
->select_network_scan_freqs
= NULL
;
8071 wpa_bss_flush(wpa_s
);
8072 if (!dl_list_empty(&wpa_s
->bss
)) {
8073 wpa_printf(MSG_DEBUG
,
8074 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8075 MACSTR
" pending_bssid=" MACSTR
,
8076 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
8077 MAC2STR(wpa_s
->bssid
),
8078 MAC2STR(wpa_s
->pending_bssid
));
8081 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
8082 wpa_s
->wnmsleep_used
= 0;
8085 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
8086 #endif /* CONFIG_SME */
8088 wpabuf_free(wpa_s
->ric_ies
);
8089 wpa_s
->ric_ies
= NULL
;
8091 wpa_supplicant_update_channel_list(wpa_s
, NULL
);
8093 free_bss_tmp_disallowed(wpa_s
);
8097 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
8098 char *buf
, size_t buflen
)
8100 struct wpa_radio_work
*work
;
8102 struct os_reltime now
, diff
;
8107 os_get_reltime(&now
);
8109 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8113 os_reltime_sub(&now
, &work
->time
, &diff
);
8114 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
8115 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
8116 work
->started
, diff
.sec
, diff
.usec
);
8117 if (os_snprintf_error(end
- pos
, ret
))
8126 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
8128 struct wpa_radio_work
*work
= eloop_ctx
;
8129 struct wpa_external_work
*ework
= work
->ctx
;
8131 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
8132 "Timing out external radio work %u (%s)",
8133 ework
->id
, work
->type
);
8134 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
8135 work
->wpa_s
->ext_work_in_progress
= 0;
8136 radio_work_done(work
);
8141 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
8143 struct wpa_external_work
*ework
= work
->ctx
;
8147 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8151 * work->type points to a buffer in ework, so need to replace
8152 * that here with a fixed string to avoid use of freed memory
8155 work
->type
= "freed-ext-work";
8161 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
8162 ework
->id
, ework
->type
);
8163 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
8164 work
->wpa_s
->ext_work_in_progress
= 1;
8165 if (!ework
->timeout
)
8166 ework
->timeout
= 10;
8167 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
8172 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
8173 char *buf
, size_t buflen
)
8175 struct wpa_external_work
*ework
;
8179 unsigned int freq
= 0;
8181 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8183 ework
= os_zalloc(sizeof(*ework
));
8187 pos
= os_strchr(cmd
, ' ');
8189 type_len
= pos
- cmd
;
8192 pos2
= os_strstr(pos
, "freq=");
8194 freq
= atoi(pos2
+ 5);
8196 pos2
= os_strstr(pos
, "timeout=");
8198 ework
->timeout
= atoi(pos2
+ 8);
8200 type_len
= os_strlen(cmd
);
8202 if (4 + type_len
>= sizeof(ework
->type
))
8203 type_len
= sizeof(ework
->type
) - 4 - 1;
8204 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
8205 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
8206 ework
->type
[4 + type_len
] = '\0';
8208 wpa_s
->ext_work_id
++;
8209 if (wpa_s
->ext_work_id
== 0)
8210 wpa_s
->ext_work_id
++;
8211 ework
->id
= wpa_s
->ext_work_id
;
8213 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
8219 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
8220 if (os_snprintf_error(buflen
, ret
))
8226 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
8228 struct wpa_radio_work
*work
;
8229 unsigned int id
= atoi(cmd
);
8231 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8233 struct wpa_external_work
*ework
;
8235 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8238 if (id
&& ework
->id
!= id
)
8240 wpa_dbg(wpa_s
, MSG_DEBUG
,
8241 "Completed external radio work %u (%s)",
8242 ework
->id
, ework
->type
);
8243 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
8244 wpa_s
->ext_work_in_progress
= 0;
8245 radio_work_done(work
);
8247 return 3; /* "OK\n" */
8254 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
8255 char *buf
, size_t buflen
)
8257 if (os_strcmp(cmd
, "show") == 0)
8258 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
8259 if (os_strncmp(cmd
, "add ", 4) == 0)
8260 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
8261 if (os_strncmp(cmd
, "done ", 5) == 0)
8262 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
8267 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
8269 struct wpa_radio_work
*work
, *tmp
;
8271 if (!wpa_s
|| !wpa_s
->radio
)
8274 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
8275 struct wpa_radio_work
, list
) {
8276 struct wpa_external_work
*ework
;
8278 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8281 wpa_dbg(wpa_s
, MSG_DEBUG
,
8282 "Flushing%s external radio work %u (%s)",
8283 work
->started
? " started" : "", ework
->id
,
8286 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8288 radio_work_done(work
);
8294 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8296 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8297 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8301 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8302 unsigned int *scan_id_count
, int scan_id
[])
8304 const char *pos
= value
;
8307 if (*pos
== ' ' || *pos
== '\0')
8309 if (*scan_id_count
== MAX_SCAN_ID
)
8311 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8312 pos
= os_strchr(pos
, ',');
8321 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8322 char *reply
, int reply_size
, int *reply_len
)
8325 unsigned int manual_scan_passive
= 0;
8326 unsigned int manual_scan_use_id
= 0;
8327 unsigned int manual_scan_only_new
= 0;
8328 unsigned int scan_only
= 0;
8329 unsigned int scan_id_count
= 0;
8330 int scan_id
[MAX_SCAN_ID
];
8331 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8332 struct wpa_scan_results
*scan_res
);
8333 int *manual_scan_freqs
= NULL
;
8334 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8335 unsigned int ssid_count
= 0;
8337 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8342 if (radio_work_pending(wpa_s
, "scan")) {
8343 wpa_printf(MSG_DEBUG
,
8344 "Pending scan scheduled - reject new request");
8345 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8349 #ifdef CONFIG_INTERWORKING
8350 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8351 wpa_printf(MSG_DEBUG
,
8352 "Interworking select in progress - reject new scan");
8353 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8356 #endif /* CONFIG_INTERWORKING */
8359 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8362 pos
= os_strstr(params
, "freq=");
8364 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8366 if (manual_scan_freqs
== NULL
) {
8372 pos
= os_strstr(params
, "passive=");
8374 manual_scan_passive
= !!atoi(pos
+ 8);
8376 pos
= os_strstr(params
, "use_id=");
8378 manual_scan_use_id
= atoi(pos
+ 7);
8380 pos
= os_strstr(params
, "only_new=1");
8382 manual_scan_only_new
= 1;
8384 pos
= os_strstr(params
, "scan_id=");
8385 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8391 pos
= os_strstr(params
, "bssid=");
8396 if (hwaddr_aton(pos
, bssid
)) {
8397 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8401 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8405 while (pos
&& *pos
!= '\0') {
8406 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8412 if (*end
== '\0' || *end
== ' ')
8417 ns
= os_realloc_array(
8418 ssid
, ssid_count
+ 1,
8419 sizeof(struct wpa_ssid_value
));
8426 if ((end
- pos
) & 0x01 ||
8427 end
- pos
> 2 * SSID_MAX_LEN
||
8428 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8429 (end
- pos
) / 2) < 0) {
8430 wpa_printf(MSG_DEBUG
,
8431 "Invalid SSID value '%s'",
8436 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8437 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8438 ssid
[ssid_count
].ssid
,
8439 ssid
[ssid_count
].ssid_len
);
8444 pos
= os_strchr(pos
, ' ');
8450 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8451 os_free(wpa_s
->ssids_from_scan_req
);
8453 wpa_s
->ssids_from_scan_req
= ssid
;
8456 wpa_s
->ssids_from_scan_req
= NULL
;
8460 scan_res_handler
= scan_only_handler
;
8461 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8462 scan_res_handler
= NULL
;
8464 scan_res_handler
= wpa_s
->scan_res_handler
;
8466 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8467 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8468 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8469 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8470 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8471 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8472 wpa_s
->scan_id_count
= scan_id_count
;
8473 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8474 wpa_s
->scan_res_handler
= scan_res_handler
;
8475 os_free(wpa_s
->manual_scan_freqs
);
8476 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8477 manual_scan_freqs
= NULL
;
8479 wpa_s
->normal_scans
= 0;
8480 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8481 wpa_s
->after_wps
= 0;
8482 wpa_s
->known_wps_freq
= 0;
8483 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8484 if (wpa_s
->manual_scan_use_id
) {
8485 wpa_s
->manual_scan_id
++;
8486 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8487 wpa_s
->manual_scan_id
);
8488 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8489 wpa_s
->manual_scan_id
);
8491 } else if (wpa_s
->sched_scanning
) {
8492 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8493 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8494 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8495 wpa_s
->scan_id_count
= scan_id_count
;
8496 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8497 wpa_s
->scan_res_handler
= scan_res_handler
;
8498 os_free(wpa_s
->manual_scan_freqs
);
8499 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8500 manual_scan_freqs
= NULL
;
8502 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8503 wpa_supplicant_cancel_sched_scan(wpa_s
);
8504 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8505 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8506 if (wpa_s
->manual_scan_use_id
) {
8507 wpa_s
->manual_scan_id
++;
8508 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8509 wpa_s
->manual_scan_id
);
8510 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8511 wpa_s
->manual_scan_id
);
8514 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8515 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8519 os_free(manual_scan_freqs
);
8524 #ifdef CONFIG_TESTING_OPTIONS
8526 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8527 unsigned int freq
, const u8
*dst
,
8528 const u8
*src
, const u8
*bssid
,
8529 const u8
*data
, size_t data_len
,
8530 enum offchannel_send_action_result
8533 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8534 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8535 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8536 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8537 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8538 "NO_ACK" : "FAILED"));
8542 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8546 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8548 int freq
= 0, no_cck
= 0, wait_time
= 0;
8550 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8551 * <action=Action frame payload> */
8553 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8556 used
= hwaddr_aton2(pos
, da
);
8562 used
= hwaddr_aton2(pos
, bssid
);
8567 param
= os_strstr(pos
, " freq=");
8573 param
= os_strstr(pos
, " no_cck=");
8576 no_cck
= atoi(param
);
8579 param
= os_strstr(pos
, " wait_time=");
8582 wait_time
= atoi(param
);
8585 param
= os_strstr(pos
, " action=");
8590 len
= os_strlen(param
);
8595 buf
= os_malloc(len
);
8599 if (hexstr2bin(param
, buf
, len
) < 0) {
8604 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8605 buf
, len
, wait_time
,
8606 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8612 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8614 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8615 offchannel_send_action_done(wpa_s
);
8619 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8625 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8626 union wpa_event_data event
;
8628 if (!wpa_s
->ext_mgmt_frame_handling
)
8631 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8633 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8636 param
= os_strstr(pos
, "freq=");
8642 param
= os_strstr(pos
, " datarate=");
8645 datarate
= atoi(param
);
8648 param
= os_strstr(pos
, " ssi_signal=");
8651 ssi_signal
= atoi(param
);
8654 param
= os_strstr(pos
, " frame=");
8659 len
= os_strlen(param
);
8664 buf
= os_malloc(len
);
8668 if (hexstr2bin(param
, buf
, len
) < 0) {
8673 os_memset(&event
, 0, sizeof(event
));
8674 event
.rx_mgmt
.freq
= freq
;
8675 event
.rx_mgmt
.frame
= buf
;
8676 event
.rx_mgmt
.frame_len
= len
;
8677 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8678 event
.rx_mgmt
.datarate
= datarate
;
8679 wpa_s
->ext_mgmt_frame_handling
= 0;
8680 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8681 wpa_s
->ext_mgmt_frame_handling
= 1;
8689 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8692 struct wpa_scan_res
*res
;
8693 struct os_reltime now
;
8700 if (os_strcmp(param
, "START") == 0) {
8701 wpa_bss_update_start(wpa_s
);
8705 if (os_strcmp(param
, "END") == 0) {
8706 wpa_bss_update_end(wpa_s
, NULL
, 1);
8710 if (os_strncmp(param
, "BSS ", 4) != 0)
8714 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8718 pos
= os_strstr(param
, " flags=");
8720 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8722 pos
= os_strstr(param
, " bssid=");
8723 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8726 pos
= os_strstr(param
, " freq=");
8728 res
->freq
= atoi(pos
+ 6);
8730 pos
= os_strstr(param
, " beacon_int=");
8732 res
->beacon_int
= atoi(pos
+ 12);
8734 pos
= os_strstr(param
, " caps=");
8736 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8738 pos
= os_strstr(param
, " qual=");
8740 res
->qual
= atoi(pos
+ 6);
8742 pos
= os_strstr(param
, " noise=");
8744 res
->noise
= atoi(pos
+ 7);
8746 pos
= os_strstr(param
, " level=");
8748 res
->level
= atoi(pos
+ 7);
8750 pos
= os_strstr(param
, " tsf=");
8752 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8754 pos
= os_strstr(param
, " age=");
8756 res
->age
= atoi(pos
+ 5);
8758 pos
= os_strstr(param
, " est_throughput=");
8760 res
->est_throughput
= atoi(pos
+ 16);
8762 pos
= os_strstr(param
, " snr=");
8764 res
->snr
= atoi(pos
+ 5);
8766 pos
= os_strstr(param
, " parent_tsf=");
8768 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8770 pos
= os_strstr(param
, " tsf_bssid=");
8771 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8774 pos
= os_strstr(param
, " ie=");
8777 end
= os_strchr(pos
, ' ');
8779 end
= pos
+ os_strlen(pos
);
8780 res
->ie_len
= (end
- pos
) / 2;
8781 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8785 pos
= os_strstr(param
, " beacon_ie=");
8788 end
= os_strchr(pos
, ' ');
8790 end
= pos
+ os_strlen(pos
);
8791 res
->beacon_ie_len
= (end
- pos
) / 2;
8792 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8793 res
->beacon_ie_len
))
8797 os_get_reltime(&now
);
8798 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8807 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8810 union wpa_event_data event
;
8811 enum wpa_event_type ev
;
8813 /* <event name> [parameters..] */
8815 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8818 param
= os_strchr(pos
, ' ');
8822 os_memset(&event
, 0, sizeof(event
));
8824 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8825 ev
= EVENT_INTERFACE_ENABLED
;
8826 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8827 ev
= EVENT_INTERFACE_DISABLED
;
8828 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8829 ev
= EVENT_AVOID_FREQUENCIES
;
8832 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8834 wpa_supplicant_event(wpa_s
, ev
, &event
);
8835 os_free(event
.freq_range
.range
);
8837 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8838 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8840 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8845 wpa_supplicant_event(wpa_s
, ev
, &event
);
8851 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8854 u8 src
[ETH_ALEN
], *buf
;
8858 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8861 used
= hwaddr_aton2(pos
, src
);
8868 len
= os_strlen(pos
);
8873 buf
= os_malloc(len
);
8877 if (hexstr2bin(pos
, buf
, len
) < 0) {
8882 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8889 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8893 const u16
*pos
= buf
;
8895 for (i
= 0; i
< len
/ 2; i
++)
8899 sum
= (sum
& 0xffff) + (sum
>> 16);
8901 return sum
^ 0xffff;
8905 #define HWSIM_PACKETLEN 1500
8906 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8908 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8911 struct wpa_supplicant
*wpa_s
= ctx
;
8912 const struct ether_header
*eth
;
8918 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
8919 wpa_printf(MSG_DEBUG
,
8920 "test data: RX - ignore unexpected length %d",
8925 eth
= (const struct ether_header
*) buf
;
8926 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8927 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8929 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8930 ntohs(ip
.tot_len
) > HWSIM_IP_LEN
) {
8931 wpa_printf(MSG_DEBUG
,
8932 "test data: RX - ignore unexpect IP header");
8936 for (i
= 0; i
< ntohs(ip
.tot_len
) - sizeof(ip
); i
++) {
8937 if (*pos
!= (u8
) i
) {
8938 wpa_printf(MSG_DEBUG
,
8939 "test data: RX - ignore mismatching payload");
8945 if (ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8946 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.tot_len
));
8947 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
8948 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
8952 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8955 int enabled
= atoi(cmd
);
8960 if (wpa_s
->l2_test
) {
8961 l2_packet_deinit(wpa_s
->l2_test
);
8962 wpa_s
->l2_test
= NULL
;
8963 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8971 pos
= os_strstr(cmd
, " ifname=");
8975 ifname
= wpa_s
->ifname
;
8977 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8978 ETHERTYPE_IP
, wpas_data_test_rx
,
8980 if (wpa_s
->l2_test
== NULL
)
8983 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8989 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8991 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8996 u8 buf
[2 + HWSIM_PACKETLEN
];
8997 struct ether_header
*eth
;
9001 size_t send_len
= HWSIM_IP_LEN
;
9003 if (wpa_s
->l2_test
== NULL
)
9006 /* format: <dst> <src> <tos> [len=<length>] */
9009 used
= hwaddr_aton2(pos
, dst
);
9015 used
= hwaddr_aton2(pos
, src
);
9020 val
= strtol(pos
, &pos2
, 0);
9021 if (val
< 0 || val
> 0xff)
9025 pos
= os_strstr(pos2
, " len=");
9028 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
9033 eth
= (struct ether_header
*) &buf
[2];
9034 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
9035 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
9036 eth
->ether_type
= htons(ETHERTYPE_IP
);
9037 ip
= (struct iphdr
*) (eth
+ 1);
9038 os_memset(ip
, 0, sizeof(*ip
));
9043 ip
->tot_len
= htons(send_len
);
9045 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9046 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9047 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
9048 dpos
= (u8
*) (ip
+ 1);
9049 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
9052 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
9053 sizeof(struct ether_header
) + send_len
) < 0)
9056 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
9057 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
9063 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
9067 struct ether_header
*eth
;
9068 struct l2_packet_data
*l2
= NULL
;
9073 len
= os_strlen(cmd
);
9074 if (len
& 1 || len
< ETH_HLEN
* 2)
9078 buf
= os_malloc(len
);
9082 if (hexstr2bin(cmd
, buf
, len
) < 0)
9085 eth
= (struct ether_header
*) buf
;
9086 ethertype
= ntohs(eth
->ether_type
);
9088 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
9089 wpas_data_test_rx
, wpa_s
, 1);
9093 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
9094 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
9097 l2_packet_deinit(l2
);
9100 return res
< 0 ? -1 : 0;
9104 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9106 #ifdef WPA_TRACE_BFD
9109 wpa_trace_fail_after
= atoi(cmd
);
9110 pos
= os_strchr(cmd
, ':');
9113 os_strlcpy(wpa_trace_fail_func
, pos
,
9114 sizeof(wpa_trace_fail_func
));
9116 wpa_trace_fail_after
= 0;
9119 #else /* WPA_TRACE_BFD */
9121 #endif /* WPA_TRACE_BFD */
9125 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
9126 char *buf
, size_t buflen
)
9128 #ifdef WPA_TRACE_BFD
9129 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
9130 wpa_trace_fail_func
);
9131 #else /* WPA_TRACE_BFD */
9133 #endif /* WPA_TRACE_BFD */
9137 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9139 #ifdef WPA_TRACE_BFD
9142 wpa_trace_test_fail_after
= atoi(cmd
);
9143 pos
= os_strchr(cmd
, ':');
9146 os_strlcpy(wpa_trace_test_fail_func
, pos
,
9147 sizeof(wpa_trace_test_fail_func
));
9149 wpa_trace_test_fail_after
= 0;
9152 #else /* WPA_TRACE_BFD */
9154 #endif /* WPA_TRACE_BFD */
9158 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
9159 char *buf
, size_t buflen
)
9161 #ifdef WPA_TRACE_BFD
9162 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
9163 wpa_trace_test_fail_func
);
9164 #else /* WPA_TRACE_BFD */
9166 #endif /* WPA_TRACE_BFD */
9170 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
9172 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9173 int i
, count
= (intptr_t) timeout_ctx
;
9175 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
9177 for (i
= 0; i
< count
; i
++) {
9178 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
9184 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9192 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
9193 (void *) (intptr_t) count
);
9197 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
9203 len
= os_strlen(cmd
);
9211 buf
= wpabuf_alloc(len
);
9215 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
9221 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
9226 static int wpas_ctrl_reset_pn(struct wpa_supplicant
*wpa_s
)
9228 u8 zero
[WPA_TK_MAX_LEN
];
9230 if (wpa_s
->last_tk_alg
== WPA_ALG_NONE
)
9233 wpa_printf(MSG_INFO
, "TESTING: Reset PN");
9234 os_memset(zero
, 0, sizeof(zero
));
9236 /* First, use a zero key to avoid any possible duplicate key avoidance
9238 if (wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9239 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9240 zero
, wpa_s
->last_tk_len
) < 0)
9243 /* Set the previously configured key to reset its TSC/RSC */
9244 return wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9245 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9246 wpa_s
->last_tk
, wpa_s
->last_tk_len
);
9250 static int wpas_ctrl_key_request(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9252 const char *pos
= cmd
;
9253 int error
, pairwise
;
9256 pos
= os_strchr(pos
, ' ');
9259 pairwise
= atoi(pos
);
9260 wpa_sm_key_request(wpa_s
->wpa
, error
, pairwise
);
9265 static int wpas_ctrl_resend_assoc(struct wpa_supplicant
*wpa_s
)
9268 struct wpa_driver_associate_params params
;
9271 os_memset(¶ms
, 0, sizeof(params
));
9272 params
.bssid
= wpa_s
->bssid
;
9273 params
.ssid
= wpa_s
->sme
.ssid
;
9274 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
9275 params
.freq
.freq
= wpa_s
->sme
.freq
;
9276 if (wpa_s
->last_assoc_req_wpa_ie
) {
9277 params
.wpa_ie
= wpabuf_head(wpa_s
->last_assoc_req_wpa_ie
);
9278 params
.wpa_ie_len
= wpabuf_len(wpa_s
->last_assoc_req_wpa_ie
);
9280 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
9281 params
.group_suite
= wpa_s
->group_cipher
;
9282 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
9283 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
9284 params
.wpa_proto
= wpa_s
->wpa_proto
;
9285 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
9286 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
9287 if (wpa_s
->sme
.prev_bssid_set
)
9288 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
9289 wpa_printf(MSG_INFO
, "TESTING: Resend association request");
9290 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
9291 wpa_s
->testing_resend_assoc
= 1;
9293 #else /* CONFIG_SME */
9295 #endif /* CONFIG_SME */
9298 #endif /* CONFIG_TESTING_OPTIONS */
9301 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
9307 struct ieee802_11_elems elems
;
9310 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9312 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9314 pos
= os_strchr(pos
, ' ');
9319 len
= os_strlen(pos
);
9326 buf
= wpabuf_alloc(len
);
9330 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
9335 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
9341 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
9342 wpa_s
->vendor_elem
[frame
] = buf
;
9343 wpas_vendor_elem_update(wpa_s
);
9347 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
9352 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
9354 wpas_vendor_elem_update(wpa_s
);
9360 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
9361 char *buf
, size_t buflen
)
9363 int frame
= atoi(cmd
);
9365 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9367 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9369 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9372 return wpa_snprintf_hex(buf
, buflen
,
9373 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
9374 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
9378 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
9384 struct ieee802_11_elems elems
;
9388 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9390 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9392 pos
= os_strchr(pos
, ' ');
9398 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9399 wpa_s
->vendor_elem
[frame
] = NULL
;
9400 wpas_vendor_elem_update(wpa_s
);
9404 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9407 len
= os_strlen(pos
);
9414 buf
= os_malloc(len
);
9418 if (hexstr2bin(pos
, buf
, len
) < 0) {
9423 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9428 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9434 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9436 struct wpa_supplicant
*wpa_s
= ctx
;
9441 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9443 * BSSID Information[4]
9444 * Operating Class[1]
9447 * Optional Subelements[variable]
9449 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9451 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9452 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9456 data
= wpabuf_head_u8(neighbor_rep
);
9457 len
= wpabuf_len(neighbor_rep
);
9459 while (len
>= 2 + NR_IE_MIN_LEN
) {
9461 char lci
[256 * 2 + 1];
9462 char civic
[256 * 2 + 1];
9463 u8 nr_len
= data
[1];
9464 const u8
*pos
= data
, *end
;
9466 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9467 nr_len
< NR_IE_MIN_LEN
) {
9468 wpa_printf(MSG_DEBUG
,
9469 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9474 if (2U + nr_len
> len
) {
9475 wpa_printf(MSG_DEBUG
,
9476 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9477 data
[0], len
, nr_len
);
9484 pos
+= NR_IE_MIN_LEN
;
9488 while (end
- pos
> 2) {
9493 if (s_len
> end
- pos
)
9495 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9496 /* Measurement Token[1] */
9497 /* Measurement Report Mode[1] */
9498 /* Measurement Type[1] */
9499 /* Measurement Report[variable] */
9501 case MEASURE_TYPE_LCI
:
9504 wpa_snprintf_hex(lci
, sizeof(lci
),
9507 case MEASURE_TYPE_LOCATION_CIVIC
:
9510 wpa_snprintf_hex(civic
, sizeof(civic
),
9519 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9521 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9522 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9523 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9525 lci
[0] ? " lci=" : "", lci
,
9526 civic
[0] ? " civic=" : "", civic
);
9533 wpabuf_free(neighbor_rep
);
9537 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9540 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9541 int ret
, lci
= 0, civic
= 0;
9544 ssid_s
= os_strstr(cmd
, "ssid=");
9546 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9547 wpa_printf(MSG_ERROR
,
9548 "CTRL: Send Neighbor Report: bad SSID");
9555 * Move cmd after the SSID text that may include "lci" or
9558 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9564 if (cmd
&& os_strstr(cmd
, "lci"))
9567 if (cmd
&& os_strstr(cmd
, "civic"))
9570 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9571 wpas_ctrl_neighbor_rep_cb
,
9578 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9580 eapol_sm_erp_flush(wpa_s
->eapol
);
9585 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9588 char *token
, *context
= NULL
;
9589 unsigned int enable
= ~0, type
= 0;
9590 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9591 u8
*addr
= NULL
, *mask
= NULL
;
9593 while ((token
= str_token(cmd
, " ", &context
))) {
9594 if (os_strcasecmp(token
, "scan") == 0) {
9595 type
|= MAC_ADDR_RAND_SCAN
;
9596 } else if (os_strcasecmp(token
, "sched") == 0) {
9597 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9598 } else if (os_strcasecmp(token
, "pno") == 0) {
9599 type
|= MAC_ADDR_RAND_PNO
;
9600 } else if (os_strcasecmp(token
, "all") == 0) {
9601 type
= wpa_s
->mac_addr_rand_supported
;
9602 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9603 enable
= atoi(token
+ 7);
9604 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9606 if (hwaddr_aton(token
+ 5, addr
)) {
9607 wpa_printf(MSG_INFO
,
9608 "CTRL: Invalid MAC address: %s",
9612 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9614 if (hwaddr_aton(token
+ 5, mask
)) {
9615 wpa_printf(MSG_INFO
,
9616 "CTRL: Invalid MAC address mask: %s",
9621 wpa_printf(MSG_INFO
,
9622 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9629 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9634 wpa_printf(MSG_INFO
,
9635 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9640 return wpas_disable_mac_addr_randomization(wpa_s
, type
);
9642 return wpas_enable_mac_addr_randomization(wpa_s
, type
, addr
, mask
);
9646 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9647 char *buf
, size_t buflen
)
9651 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9653 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9654 buflen
- reply_len
);
9655 #endif /* CONFIG_AP */
9660 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9662 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9664 wpas_ap_pmksa_cache_flush(wpa_s
);
9665 #endif /* CONFIG_AP */
9669 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9671 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9672 const char *cmd
, char *buf
, size_t buflen
)
9674 struct rsn_pmksa_cache_entry
*entry
;
9675 struct wpa_ssid
*ssid
;
9676 char *pos
, *pos2
, *end
;
9678 struct os_reltime now
;
9680 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9687 os_get_reltime(&now
);
9691 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9692 * <expiration in seconds> <akmp> <opportunistic>
9693 * [FILS Cache Identifier]
9696 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9697 entry
= entry
->next
) {
9698 if (entry
->network_ctx
!= ssid
)
9702 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9703 MAC2STR(entry
->aa
));
9704 if (os_snprintf_error(end
- pos2
, ret
))
9708 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9711 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9712 if (os_snprintf_error(end
- pos2
, ret
))
9716 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9719 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9720 (int) (entry
->reauth_time
- now
.sec
),
9721 (int) (entry
->expiration
- now
.sec
),
9723 entry
->opportunistic
);
9724 if (os_snprintf_error(end
- pos2
, ret
))
9728 if (entry
->fils_cache_id_set
) {
9729 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9730 entry
->fils_cache_id
[0],
9731 entry
->fils_cache_id
[1]);
9732 if (os_snprintf_error(end
- pos2
, ret
))
9737 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9738 if (os_snprintf_error(end
- pos2
, ret
))
9749 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9752 struct rsn_pmksa_cache_entry
*entry
;
9753 struct wpa_ssid
*ssid
;
9756 struct os_reltime now
;
9757 int reauth_time
= 0, expiration
= 0, i
;
9761 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9762 * <expiration in seconds> <akmp> <opportunistic>
9763 * [FILS Cache Identifier]
9766 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9770 pos
= os_strchr(cmd
, ' ');
9775 entry
= os_zalloc(sizeof(*entry
));
9779 if (hwaddr_aton(pos
, entry
->aa
))
9782 pos
= os_strchr(pos
, ' ');
9787 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9790 pos
= os_strchr(pos
, ' ');
9795 pos2
= os_strchr(pos
, ' ');
9798 entry
->pmk_len
= (pos2
- pos
) / 2;
9799 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9800 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9803 pos
= os_strchr(pos
, ' ');
9808 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9809 &entry
->akmp
, &entry
->opportunistic
) != 4)
9811 for (i
= 0; i
< 4; i
++) {
9812 pos
= os_strchr(pos
, ' ');
9821 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9822 FILS_CACHE_ID_LEN
) < 0)
9824 entry
->fils_cache_id_set
= 1;
9826 os_get_reltime(&now
);
9827 entry
->expiration
= now
.sec
+ expiration
;
9828 entry
->reauth_time
= now
.sec
+ reauth_time
;
9830 entry
->network_ctx
= ssid
;
9832 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9843 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9844 const char *cmd
, char *buf
,
9852 if (os_strcasecmp(cmd
, "any") == 0)
9853 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9855 if (hwaddr_aton(cmd
, spa
))
9858 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9862 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9866 * We do not check mesh interface existance because PMKSA should be
9867 * stored before wpa_s->ifmsh creation to suppress commit message
9870 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9873 #endif /* CONFIG_MESH */
9874 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9878 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9881 struct fils_hlp_req
*req
;
9884 /* format: <dst> <packet starting from ethertype> */
9886 req
= os_zalloc(sizeof(*req
));
9890 if (hwaddr_aton(cmd
, req
->dst
))
9893 pos
= os_strchr(cmd
, ' ');
9897 req
->pkt
= wpabuf_parse_bin(pos
);
9901 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9904 wpabuf_free(req
->pkt
);
9908 #endif /* CONFIG_FILS */
9911 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9913 if (os_strcmp(cmd
, "PING") == 0 ||
9914 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9915 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9916 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9917 os_strncmp(cmd
, "STA ", 4) == 0 ||
9918 os_strncmp(cmd
, "STA-", 4) == 0)
9919 return MSG_EXCESSIVE
;
9924 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9925 char *buf
, size_t *resp_len
)
9928 const int reply_size
= 4096;
9931 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9932 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9933 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9934 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9935 if (wpa_debug_show_keys
)
9936 wpa_dbg(wpa_s
, MSG_DEBUG
,
9937 "Control interface command '%s'", buf
);
9939 wpa_dbg(wpa_s
, MSG_DEBUG
,
9940 "Control interface command '%s [REMOVED]'",
9941 os_strncmp(buf
, WPA_CTRL_RSP
,
9942 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9944 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9945 "SET_NETWORK" : "key-add"));
9946 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9947 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9948 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9949 (const u8
*) buf
, os_strlen(buf
));
9951 int level
= wpas_ctrl_cmd_debug_level(buf
);
9952 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9955 reply
= os_malloc(reply_size
);
9956 if (reply
== NULL
) {
9961 os_memcpy(reply
, "OK\n", 3);
9964 if (os_strcmp(buf
, "PING") == 0) {
9965 os_memcpy(reply
, "PONG\n", 5);
9967 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9968 reply_len
= os_strlen(wpa_s
->ifname
);
9969 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9970 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9971 if (wpa_debug_reopen_file() < 0)
9973 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9974 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9975 } else if (os_strcmp(buf
, "MIB") == 0) {
9976 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9977 if (reply_len
>= 0) {
9978 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9980 reply_size
- reply_len
);
9981 #ifdef CONFIG_MACSEC
9982 reply_len
+= ieee802_1x_kay_get_mib(
9983 wpa_s
->kay
, reply
+ reply_len
,
9984 reply_size
- reply_len
);
9985 #endif /* CONFIG_MACSEC */
9987 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9988 reply_len
= wpa_supplicant_ctrl_iface_status(
9989 wpa_s
, buf
+ 6, reply
, reply_size
);
9990 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9991 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9992 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9993 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9994 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9995 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9996 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9998 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9999 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
10002 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
10003 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
10004 reply
, reply_size
);
10005 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
10006 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
10008 #endif /* CONFIG_MESH */
10009 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10010 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10011 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
10013 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
10014 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
10015 reply
, reply_size
);
10016 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
10017 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
10018 reply
, reply_size
);
10019 } else if (os_strcmp(buf
, "LOGON") == 0) {
10020 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
10021 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
10022 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
10023 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
10024 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10027 wpas_request_connection(wpa_s
);
10028 } else if (os_strcmp(buf
, "REATTACH") == 0) {
10029 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
10030 !wpa_s
->current_ssid
)
10033 wpa_s
->reattach
= 1;
10034 wpas_request_connection(wpa_s
);
10036 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
10037 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
10039 else if (wpa_s
->disconnected
)
10040 wpas_request_connection(wpa_s
);
10041 #ifdef IEEE8021X_EAPOL
10042 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
10043 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
10045 #endif /* IEEE8021X_EAPOL */
10046 #ifdef CONFIG_IEEE80211R
10047 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
10048 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
10050 #endif /* CONFIG_IEEE80211R */
10052 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
10053 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
10055 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10059 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
10060 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
10062 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10066 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
10067 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
10070 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
10071 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
10072 wpa_s
, buf
+ 14, reply
, reply_size
);
10073 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
10074 if (wpas_wps_cancel(wpa_s
))
10076 #ifdef CONFIG_WPS_NFC
10077 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
10078 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
10080 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
10081 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
10083 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10084 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10085 wpa_s
, buf
+ 21, reply
, reply_size
);
10086 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
10087 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
10088 wpa_s
, buf
+ 14, reply
, reply_size
);
10089 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
10090 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
10093 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10094 reply_len
= wpas_ctrl_nfc_get_handover_req(
10095 wpa_s
, buf
+ 21, reply
, reply_size
);
10096 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10097 reply_len
= wpas_ctrl_nfc_get_handover_sel(
10098 wpa_s
, buf
+ 21, reply
, reply_size
);
10099 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
10100 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
10102 #endif /* CONFIG_WPS_NFC */
10103 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
10104 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
10107 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
10108 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
10109 wpa_s
, buf
+ 11, reply
, reply_size
);
10110 #endif /* CONFIG_AP */
10111 #ifdef CONFIG_WPS_ER
10112 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
10113 if (wpas_wps_er_start(wpa_s
, NULL
))
10115 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
10116 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
10118 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
10119 wpas_wps_er_stop(wpa_s
);
10120 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
10121 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
10123 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
10124 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
10126 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10128 } else if (ret
== -3) {
10129 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
10131 } else if (ret
== -4) {
10132 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
10136 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
10137 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
10139 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
10140 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
10143 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
10144 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
10146 #ifdef CONFIG_WPS_NFC
10147 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10148 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10149 wpa_s
, buf
+ 24, reply
, reply_size
);
10150 #endif /* CONFIG_WPS_NFC */
10151 #endif /* CONFIG_WPS_ER */
10152 #endif /* CONFIG_WPS */
10153 #ifdef CONFIG_IBSS_RSN
10154 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
10155 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
10157 #endif /* CONFIG_IBSS_RSN */
10159 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
10160 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10161 wpa_s
, buf
+ 19, reply
, reply_size
);
10162 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
10163 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10164 wpa_s
, "", reply
, reply_size
);
10165 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
10166 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
10168 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
10169 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
10172 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
10173 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
10175 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
10176 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
10178 } else if (os_strncmp(buf
, "MESH_LINK_PROBE ", 16) == 0) {
10179 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s
, buf
+ 16))
10181 #endif /* CONFIG_MESH */
10183 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
10184 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
10186 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
10187 if (p2p_ctrl_find(wpa_s
, ""))
10189 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
10190 wpas_p2p_stop_find(wpa_s
);
10191 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
10192 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
10194 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10195 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
10197 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
10198 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
10200 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
10201 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
10203 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
10204 if (p2p_ctrl_listen(wpa_s
, ""))
10206 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
10207 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
10209 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
10210 if (p2p_ctrl_group_add(wpa_s
, ""))
10212 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
10213 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
10215 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
10216 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
10218 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
10219 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
10221 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
10222 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
10223 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
10224 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
10226 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10227 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
10229 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
10230 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
10232 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
10233 wpas_p2p_sd_service_update(wpa_s
);
10234 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10235 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
10237 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
10238 wpas_p2p_service_flush(wpa_s
);
10239 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
10240 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
10242 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
10243 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
10245 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
10246 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
10248 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
10249 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
10251 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
10252 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
10254 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
10255 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
10257 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
10258 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
10260 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
10261 p2p_ctrl_flush(wpa_s
);
10262 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
10263 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
10265 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
10266 if (wpas_p2p_cancel(wpa_s
))
10268 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
10269 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
10271 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
10272 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
10274 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
10275 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
10277 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
10278 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
10280 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
10281 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
10283 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
10284 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
10286 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
10287 if (wpas_p2p_lo_stop(wpa_s
))
10289 #endif /* CONFIG_P2P */
10290 #ifdef CONFIG_WIFI_DISPLAY
10291 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
10292 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
10294 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
10295 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
10296 reply
, reply_size
);
10297 #endif /* CONFIG_WIFI_DISPLAY */
10298 #ifdef CONFIG_INTERWORKING
10299 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
10300 if (interworking_fetch_anqp(wpa_s
) < 0)
10302 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
10303 interworking_stop_fetch_anqp(wpa_s
);
10304 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
10305 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
10307 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
10308 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
10310 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
10311 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
10313 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10316 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
10320 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
10321 if (os_snprintf_error(reply_size
, reply_len
))
10324 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
10325 if (get_anqp(wpa_s
, buf
+ 9) < 0)
10327 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
10328 if (gas_request(wpa_s
, buf
+ 12) < 0)
10330 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
10331 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
10333 #endif /* CONFIG_INTERWORKING */
10335 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10336 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10338 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10339 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10341 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10342 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10344 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10345 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10347 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10348 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10349 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10350 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10352 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10353 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10355 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10356 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10358 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10359 hs20_cancel_fetch_osu(wpa_s
);
10360 #endif /* CONFIG_HS20 */
10361 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10363 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10364 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10368 * Notify response from timeout to allow the control
10369 * interface response to be sent first.
10371 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10374 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10375 if (wpa_supplicant_reload_configuration(wpa_s
))
10377 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10378 wpa_supplicant_terminate_proc(wpa_s
->global
);
10379 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10380 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10382 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10383 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10384 wpa_s
, buf
+ 9, reply
, reply_size
);
10385 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10386 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10387 wpa_s
, buf
+ 9, reply
, reply_size
);
10388 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10389 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10390 wpa_s
, buf
+ 14, reply
, reply_size
);
10391 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10392 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10393 wpa_s
, NULL
, reply
, reply_size
);
10394 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10395 wpas_request_disconnection(wpa_s
);
10396 } else if (os_strcmp(buf
, "SCAN") == 0) {
10397 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10398 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10399 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10400 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10401 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10402 wpa_s
, reply
, reply_size
);
10403 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10404 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10406 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10407 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10409 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10410 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10412 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10413 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10415 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10416 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10417 wpa_s
, reply
, reply_size
);
10418 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10419 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10421 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10422 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10424 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10425 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10426 wpa_s
, buf
+ 12, reply
, reply_size
);
10427 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10428 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10431 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10432 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10433 wpa_s
, reply
, reply_size
);
10434 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10435 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10436 wpa_s
, reply
, reply_size
);
10437 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10438 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10440 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10441 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10443 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10444 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10447 #ifndef CONFIG_NO_CONFIG_WRITE
10448 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10449 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10451 #endif /* CONFIG_NO_CONFIG_WRITE */
10452 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10453 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10454 wpa_s
, buf
+ 15, reply
, reply_size
);
10455 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10456 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10458 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10459 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10461 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10462 reply_len
= wpa_supplicant_global_iface_list(
10463 wpa_s
->global
, reply
, reply_size
);
10464 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10465 reply_len
= wpa_supplicant_global_iface_interfaces(
10466 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10467 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10468 reply_len
= wpa_supplicant_ctrl_iface_bss(
10469 wpa_s
, buf
+ 4, reply
, reply_size
);
10471 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10472 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10473 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10474 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10476 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10477 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10479 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10480 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10482 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10483 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10485 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10486 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10488 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10489 if (wpas_ap_stop_ap(wpa_s
))
10491 #endif /* CONFIG_AP */
10492 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10493 wpas_notify_suspend(wpa_s
->global
);
10494 } else if (os_strcmp(buf
, "RESUME") == 0) {
10495 wpas_notify_resume(wpa_s
->global
);
10496 #ifdef CONFIG_TESTING_OPTIONS
10497 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10498 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10499 #endif /* CONFIG_TESTING_OPTIONS */
10500 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10501 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10503 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10504 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10505 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10506 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10508 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10509 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10512 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10513 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10515 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10516 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10518 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10519 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10521 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10522 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10524 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10525 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10528 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10529 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10532 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10533 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10534 wpa_s
, buf
+ 17, reply
, reply_size
);
10535 #endif /* CONFIG_TDLS */
10536 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10537 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10538 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10539 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10541 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10542 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10544 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10545 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10547 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10548 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10550 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10551 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10553 #ifdef CONFIG_AUTOSCAN
10554 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10555 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10557 #endif /* CONFIG_AUTOSCAN */
10558 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10559 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10562 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10563 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10565 #endif /* ANDROID */
10566 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10567 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10569 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10570 pmksa_cache_clear_current(wpa_s
->wpa
);
10571 eapol_sm_request_reauth(wpa_s
->eapol
);
10573 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10574 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10576 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10577 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10579 } else if (os_strncmp(buf
, "COLOC_INTF_REPORT ", 18) == 0) {
10580 if (wpas_ctrl_iface_coloc_intf_report(wpa_s
, buf
+ 18))
10582 #endif /* CONFIG_WNM */
10583 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10584 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10585 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10586 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10588 #ifdef CONFIG_TESTING_OPTIONS
10589 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10590 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10592 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10593 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10594 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10595 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10597 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10598 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10600 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10601 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10603 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10604 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10606 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10607 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10609 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10610 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10612 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10613 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10615 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10616 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10617 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10618 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10620 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10621 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10622 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10623 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10625 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10626 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10628 } else if (os_strcmp(buf
, "RESET_PN") == 0) {
10629 if (wpas_ctrl_reset_pn(wpa_s
) < 0)
10631 } else if (os_strncmp(buf
, "KEY_REQUEST ", 12) == 0) {
10632 if (wpas_ctrl_key_request(wpa_s
, buf
+ 12) < 0)
10634 } else if (os_strcmp(buf
, "RESEND_ASSOC") == 0) {
10635 if (wpas_ctrl_resend_assoc(wpa_s
) < 0)
10637 } else if (os_strcmp(buf
, "UNPROT_DEAUTH") == 0) {
10638 sme_event_unprot_disconnect(
10639 wpa_s
, wpa_s
->bssid
, NULL
,
10640 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
10641 #endif /* CONFIG_TESTING_OPTIONS */
10642 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10643 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10645 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10646 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10648 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10649 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10651 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10652 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10654 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10655 wpas_ctrl_iface_erp_flush(wpa_s
);
10656 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10657 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10659 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10660 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10661 wpa_s
, buf
+ 19, reply
, reply_size
);
10663 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10664 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10666 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10667 wpas_flush_fils_hlp_req(wpa_s
);
10668 #endif /* CONFIG_FILS */
10670 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10673 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10677 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10678 if (os_snprintf_error(reply_size
, reply_len
))
10681 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10684 res
= dpp_bootstrap_gen(wpa_s
->dpp
, buf
+ 18);
10688 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10689 if (os_snprintf_error(reply_size
, reply_len
))
10692 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10693 if (dpp_bootstrap_remove(wpa_s
->dpp
, buf
+ 21) < 0)
10695 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10698 uri
= dpp_bootstrap_get_uri(wpa_s
->dpp
, atoi(buf
+ 22));
10702 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10703 if (os_snprintf_error(reply_size
, reply_len
))
10706 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10707 reply_len
= dpp_bootstrap_info(wpa_s
->dpp
, atoi(buf
+ 19),
10708 reply
, reply_size
);
10709 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10710 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10712 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10713 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10715 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10716 wpas_dpp_stop(wpa_s
);
10717 wpas_dpp_listen_stop(wpa_s
);
10718 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10721 res
= dpp_configurator_add(wpa_s
->dpp
, buf
+ 20);
10725 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10726 if (os_snprintf_error(reply_size
, reply_len
))
10729 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10730 if (dpp_configurator_remove(wpa_s
->dpp
, buf
+ 24) < 0)
10732 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10733 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 21) < 0)
10735 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10736 reply_len
= dpp_configurator_get_key_id(wpa_s
->dpp
,
10738 reply
, reply_size
);
10739 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10742 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10746 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10747 if (os_snprintf_error(reply_size
, reply_len
))
10750 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10751 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10754 } else if (os_strncmp(buf
, "DPP_CONTROLLER_START ", 21) == 0) {
10755 if (wpas_dpp_controller_start(wpa_s
, buf
+ 20) < 0)
10757 } else if (os_strcmp(buf
, "DPP_CONTROLLER_START") == 0) {
10758 if (wpas_dpp_controller_start(wpa_s
, NULL
) < 0)
10760 } else if (os_strcmp(buf
, "DPP_CONTROLLER_STOP") == 0) {
10761 dpp_controller_stop(wpa_s
->dpp
);
10762 #endif /* CONFIG_DPP2 */
10763 #endif /* CONFIG_DPP */
10765 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10769 if (reply_len
< 0) {
10770 os_memcpy(reply
, "FAIL\n", 5);
10774 *resp_len
= reply_len
;
10779 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10782 struct wpa_interface iface
;
10784 struct wpa_supplicant
*wpa_s
;
10785 unsigned int create_iface
= 0;
10786 u8 mac_addr
[ETH_ALEN
];
10787 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10790 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10791 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10793 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10795 os_memset(&iface
, 0, sizeof(iface
));
10798 iface
.ifname
= pos
= cmd
;
10799 pos
= os_strchr(pos
, '\t');
10802 if (iface
.ifname
[0] == '\0')
10807 iface
.confname
= pos
;
10808 pos
= os_strchr(pos
, '\t');
10811 if (iface
.confname
[0] == '\0')
10812 iface
.confname
= NULL
;
10816 iface
.driver
= pos
;
10817 pos
= os_strchr(pos
, '\t');
10820 if (iface
.driver
[0] == '\0')
10821 iface
.driver
= NULL
;
10825 iface
.ctrl_interface
= pos
;
10826 pos
= os_strchr(pos
, '\t');
10829 if (iface
.ctrl_interface
[0] == '\0')
10830 iface
.ctrl_interface
= NULL
;
10834 iface
.driver_param
= pos
;
10835 pos
= os_strchr(pos
, '\t');
10838 if (iface
.driver_param
[0] == '\0')
10839 iface
.driver_param
= NULL
;
10843 iface
.bridge_ifname
= pos
;
10844 pos
= os_strchr(pos
, '\t');
10847 if (iface
.bridge_ifname
[0] == '\0')
10848 iface
.bridge_ifname
= NULL
;
10853 pos
= os_strchr(pos
, '\t');
10859 if (os_strcmp(extra
, "create") == 0) {
10864 if (os_strcmp(pos
, "sta") == 0) {
10865 type
= WPA_IF_STATION
;
10866 } else if (os_strcmp(pos
, "ap") == 0) {
10867 type
= WPA_IF_AP_BSS
;
10869 wpa_printf(MSG_DEBUG
,
10870 "INTERFACE_ADD unsupported interface type: '%s'",
10875 wpa_printf(MSG_DEBUG
,
10876 "INTERFACE_ADD unsupported extra parameter: '%s'",
10882 if (create_iface
) {
10883 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10885 if (!global
->ifaces
)
10887 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10888 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10889 wpa_printf(MSG_ERROR
,
10890 "CTRL_IFACE interface creation failed");
10894 wpa_printf(MSG_DEBUG
,
10895 "CTRL_IFACE interface '%s' created with MAC addr: "
10896 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10899 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10902 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10905 wpa_s
->added_vif
= create_iface
;
10910 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10915 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10918 struct wpa_supplicant
*wpa_s
;
10920 unsigned int delete_iface
;
10922 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10924 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10927 delete_iface
= wpa_s
->added_vif
;
10928 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10929 if (!ret
&& delete_iface
) {
10930 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10932 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10938 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10940 struct wpa_interface_info
*prev
;
10944 iface
= iface
->next
;
10946 os_free(prev
->ifname
);
10947 os_free(prev
->desc
);
10953 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10954 char *buf
, int len
)
10957 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10960 for (i
= 0; wpa_drivers
[i
]; i
++) {
10961 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10962 if (drv
->get_interfaces
== NULL
)
10964 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10969 iface
= last
= tmp
;
10978 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10979 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10980 tmp
->drv_name
, tmp
->ifname
,
10981 tmp
->desc
? tmp
->desc
: "");
10982 if (os_snprintf_error(end
- pos
, res
)) {
10989 wpa_free_iface_info(iface
);
10995 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10997 char *buf
, int len
)
11001 struct wpa_supplicant
*wpa_s
;
11005 show_ctrl
= !!os_strstr(input
, "ctrl");
11007 wpa_s
= global
->ifaces
;
11013 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
11015 wpa_s
->conf
->ctrl_interface
?
11016 wpa_s
->conf
->ctrl_interface
: "N/A");
11018 res
= os_snprintf(pos
, end
- pos
, "%s\n",
11021 if (os_snprintf_error(end
- pos
, res
)) {
11026 wpa_s
= wpa_s
->next
;
11032 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
11033 const char *ifname
,
11034 char *cmd
, size_t *resp_len
)
11036 struct wpa_supplicant
*wpa_s
;
11038 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11039 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
11043 if (wpa_s
== NULL
) {
11044 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
11046 *resp_len
= os_strlen(resp
);
11052 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
11056 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
11057 char *buf
, size_t *resp_len
)
11060 static const char * cmd
[] = {
11066 "P2P_GET_PASSPHRASE",
11067 "P2P_SERVICE_UPDATE",
11068 "P2P_SERVICE_FLUSH",
11071 "P2P_PRESENCE_REQ",
11075 #endif /* CONFIG_AP */
11078 static const char * prefix
[] = {
11081 #endif /* ANDROID */
11088 "P2P_GROUP_REMOVE ",
11090 "P2P_GROUP_MEMBER ",
11092 "P2P_SERV_DISC_REQ ",
11093 "P2P_SERV_DISC_CANCEL_REQ ",
11094 "P2P_SERV_DISC_RESP ",
11095 "P2P_SERV_DISC_EXTERNAL ",
11096 "P2P_SERVICE_ADD ",
11097 "P2P_SERVICE_DEL ",
11098 "P2P_SERVICE_REP ",
11103 "P2P_UNAUTHORIZE ",
11104 "P2P_PRESENCE_REQ ",
11106 "P2P_REMOVE_CLIENT ",
11108 "WPS_NFC_TAG_READ ",
11109 "NFC_GET_HANDOVER_SEL ",
11110 "NFC_GET_HANDOVER_REQ ",
11111 "NFC_REPORT_HANDOVER ",
11112 "P2P_ASP_PROVISION ",
11113 "P2P_ASP_PROVISION_RESP ",
11117 #endif /* CONFIG_AP */
11123 if (global
->p2p_init_wpa_s
== NULL
)
11126 for (i
= 0; !found
&& cmd
[i
]; i
++) {
11127 if (os_strcmp(buf
, cmd
[i
]) == 0)
11131 for (i
= 0; !found
&& prefix
[i
]; i
++) {
11132 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
11137 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11139 #endif /* CONFIG_P2P */
11144 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
11145 char *buf
, size_t *resp_len
)
11147 #ifdef CONFIG_WIFI_DISPLAY
11148 if (global
->p2p_init_wpa_s
== NULL
)
11150 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
11151 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
11152 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11154 #endif /* CONFIG_WIFI_DISPLAY */
11159 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
11160 char *buf
, size_t *resp_len
)
11164 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
11168 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
11176 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
11180 value
= os_strchr(cmd
, ' ');
11185 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
11187 #ifdef CONFIG_WIFI_DISPLAY
11188 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
11189 wifi_display_enable(global
, !!atoi(value
));
11192 #endif /* CONFIG_WIFI_DISPLAY */
11194 /* Restore cmd to its original value to allow redirection */
11201 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
11204 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
11208 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11209 * <variable name> */
11211 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
11212 p
= os_strchr(cmd
, ' ');
11217 wpa_s
[i
] = global
->ifaces
;
11218 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
11219 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
11224 wpa_printf(MSG_DEBUG
,
11225 "CTRL_IFACE: Could not find iface=%s", cmd
);
11232 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
11236 #ifndef CONFIG_NO_CONFIG_WRITE
11237 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
11239 int ret
= 0, saved
= 0;
11240 struct wpa_supplicant
*wpa_s
;
11242 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11243 if (!wpa_s
->conf
->update_config
) {
11244 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11248 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
11249 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11252 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11257 if (!saved
&& !ret
) {
11258 wpa_dbg(wpa_s
, MSG_DEBUG
,
11259 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11265 #endif /* CONFIG_NO_CONFIG_WRITE */
11268 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
11269 char *buf
, size_t buflen
)
11273 struct wpa_supplicant
*wpa_s
;
11276 end
= buf
+ buflen
;
11279 if (global
->p2p
&& !global
->p2p_disabled
) {
11280 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
11283 MAC2STR(global
->p2p_dev_addr
),
11284 p2p_get_state_txt(global
->p2p
));
11285 if (os_snprintf_error(end
- pos
, ret
))
11288 } else if (global
->p2p
) {
11289 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
11290 if (os_snprintf_error(end
- pos
, ret
))
11294 #endif /* CONFIG_P2P */
11296 #ifdef CONFIG_WIFI_DISPLAY
11297 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
11298 !!global
->wifi_display
);
11299 if (os_snprintf_error(end
- pos
, ret
))
11302 #endif /* CONFIG_WIFI_DISPLAY */
11304 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11305 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
11306 "address=" MACSTR
"\n",
11307 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
11308 if (os_snprintf_error(end
- pos
, ret
))
11319 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
11320 char *cmd
, char *buf
,
11323 char ifname
[IFNAMSIZ
+ 1];
11324 struct fst_iface_cfg cfg
;
11325 struct wpa_supplicant
*wpa_s
;
11326 struct fst_wpa_obj iface_obj
;
11328 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
11329 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11332 wpa_printf(MSG_INFO
, "FST: Already attached");
11335 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
11336 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
11339 return os_snprintf(buf
, reply_size
, "OK\n");
11347 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
11348 char *cmd
, char *buf
,
11351 char ifname
[IFNAMSIZ
+ 1];
11352 struct wpa_supplicant
*wpa_s
;
11354 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
11355 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11357 if (!fst_iface_detach(ifname
)) {
11359 return os_snprintf(buf
, reply_size
, "OK\n");
11367 #endif /* CONFIG_FST */
11370 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11371 char *buf
, size_t *resp_len
)
11374 const int reply_size
= 2048;
11376 int level
= MSG_DEBUG
;
11378 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11379 char *pos
= os_strchr(buf
+ 7, ' ');
11382 return wpas_global_ctrl_iface_ifname(global
,
11388 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11392 if (os_strcmp(buf
, "PING") == 0)
11393 level
= MSG_EXCESSIVE
;
11394 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11395 (const u8
*) buf
, os_strlen(buf
));
11397 reply
= os_malloc(reply_size
);
11398 if (reply
== NULL
) {
11403 os_memcpy(reply
, "OK\n", 3);
11406 if (os_strcmp(buf
, "PING") == 0) {
11407 os_memcpy(reply
, "PONG\n", 5);
11409 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11410 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11412 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11413 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11415 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11416 reply_len
= wpa_supplicant_global_iface_list(
11417 global
, reply
, reply_size
);
11418 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11419 reply_len
= wpa_supplicant_global_iface_interfaces(
11420 global
, buf
+ 10, reply
, reply_size
);
11422 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11423 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11426 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11427 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11430 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11431 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11432 #endif /* CONFIG_FST */
11433 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11434 wpa_supplicant_terminate_proc(global
);
11435 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11436 wpas_notify_suspend(global
);
11437 } else if (os_strcmp(buf
, "RESUME") == 0) {
11438 wpas_notify_resume(global
);
11439 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11440 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11442 if (global
->p2p_init_wpa_s
) {
11444 /* Check if P2P redirection would work for this
11446 return wpa_supplicant_ctrl_iface_process(
11447 global
->p2p_init_wpa_s
,
11450 #endif /* CONFIG_P2P */
11453 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11454 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11456 #ifndef CONFIG_NO_CONFIG_WRITE
11457 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11458 if (wpas_global_ctrl_iface_save_config(global
))
11460 #endif /* CONFIG_NO_CONFIG_WRITE */
11461 } else if (os_strcmp(buf
, "STATUS") == 0) {
11462 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11464 #ifdef CONFIG_MODULE_TESTS
11465 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11466 if (wpas_module_tests() < 0)
11468 #endif /* CONFIG_MODULE_TESTS */
11469 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11470 if (wpa_debug_reopen_file() < 0)
11473 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11477 if (reply_len
< 0) {
11478 os_memcpy(reply
, "FAIL\n", 5);
11482 *resp_len
= reply_len
;