2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2015, 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 <net/ethernet.h>
12 #include <netinet/ip.h>
13 #endif /* CONFIG_TESTING_OPTIONS */
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "utils/uuid.h"
18 #include "utils/module_tests.h"
19 #include "common/version.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/ieee802_11_common.h"
22 #include "common/wpa_ctrl.h"
24 #include "common/dpp.h"
25 #endif /* CONFIG_DPP */
26 #include "crypto/tls.h"
27 #include "ap/hostapd.h"
28 #include "eap_peer/eap.h"
29 #include "eapol_supp/eapol_supp_sm.h"
30 #include "rsn_supp/wpa.h"
31 #include "rsn_supp/preauth.h"
32 #include "rsn_supp/pmksa_cache.h"
33 #include "l2_packet/l2_packet.h"
36 #include "fst/fst_ctrl_iface.h"
38 #include "wpa_supplicant_i.h"
40 #include "wps_supplicant.h"
43 #include "p2p_supplicant.h"
45 #include "hs20_supplicant.h"
46 #include "wifi_display.h"
50 #include "ctrl_iface.h"
51 #include "interworking.h"
52 #include "blacklist.h"
55 #include "offchannel.h"
56 #include "drivers/driver.h"
58 #include "dpp_supplicant.h"
61 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
63 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
66 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
70 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
73 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
80 if (hwaddr_aton(pos
, addr
)) {
84 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
90 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
93 pos
= os_strchr(pos
, ' ');
98 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
99 os_free(wpa_s
->bssid_filter
);
100 wpa_s
->bssid_filter
= filter
;
101 wpa_s
->bssid_filter_count
= count
;
107 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
110 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
111 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
112 size_t count
= 0, ssid_count
= 0;
116 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
117 * SSID_SPEC ::= ssid <SSID_HEX>
118 * BSSID_SPEC ::= bssid <BSSID_HEX>
125 if (os_strncmp(pos
, "bssid ", 6) == 0) {
128 res
= hwaddr_aton2(pos
, addr
);
132 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
133 "BSSID value '%s'", pos
);
137 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
144 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
146 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
152 if (*end
== '\0' || *end
== ' ')
157 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
158 sizeof(struct wpa_ssid_value
));
166 if ((end
- pos
) & 0x01 ||
167 end
- pos
> 2 * SSID_MAX_LEN
||
168 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
169 (end
- pos
) / 2) < 0) {
172 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
173 "SSID value '%s'", pos
);
176 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
177 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
178 ssid
[ssid_count
].ssid
,
179 ssid
[ssid_count
].ssid_len
);
183 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
190 pos
= os_strchr(pos
, ' ');
195 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
196 os_free(wpa_s
->disallow_aps_bssid
);
197 wpa_s
->disallow_aps_bssid
= bssid
;
198 wpa_s
->disallow_aps_bssid_count
= count
;
200 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
201 os_free(wpa_s
->disallow_aps_ssid
);
202 wpa_s
->disallow_aps_ssid
= ssid
;
203 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
205 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
208 c
= wpa_s
->current_ssid
;
209 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
212 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
213 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
216 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
217 "because current AP was marked disallowed");
220 wpa_s
->sme
.prev_bssid_set
= 0;
221 #endif /* CONFIG_SME */
222 wpa_s
->reassociate
= 1;
223 wpa_s
->own_disconnect_req
= 1;
224 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
225 wpa_supplicant_req_scan(wpa_s
, 0, 0);
231 #ifndef CONFIG_NO_CONFIG_BLOBS
232 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
235 struct wpa_config_blob
*blob
;
238 pos
= os_strchr(pos
, ' ');
242 len
= os_strlen(pos
);
246 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
247 blob
= os_zalloc(sizeof(*blob
));
250 blob
->name
= os_strdup(name
);
251 blob
->data
= os_malloc(len
/ 2);
252 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
253 wpa_config_free_blob(blob
);
257 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
258 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
259 wpa_config_free_blob(blob
);
264 wpa_config_set_blob(wpa_s
->conf
, blob
);
268 #endif /* CONFIG_NO_CONFIG_BLOBS */
271 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
279 params
= os_strchr(cmd
, ' ');
280 os_free(wpa_s
->manual_sched_scan_freqs
);
283 pos
= os_strstr(params
, "freq=");
285 freqs
= freq_range_to_channel_list(wpa_s
,
288 wpa_s
->manual_sched_scan_freqs
= freqs
;
289 ret
= wpas_start_pno(wpa_s
);
291 ret
= wpas_stop_pno(wpa_s
);
297 static int wpas_ctrl_set_band(struct wpa_supplicant
*wpa_s
, char *band
)
299 union wpa_event_data event
;
301 if (os_strcmp(band
, "AUTO") == 0)
302 wpa_s
->setband
= WPA_SETBAND_AUTO
;
303 else if (os_strcmp(band
, "5G") == 0)
304 wpa_s
->setband
= WPA_SETBAND_5G
;
305 else if (os_strcmp(band
, "2G") == 0)
306 wpa_s
->setband
= WPA_SETBAND_2G
;
310 if (wpa_drv_setband(wpa_s
, wpa_s
->setband
) == 0) {
311 os_memset(&event
, 0, sizeof(event
));
312 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
313 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
314 wpa_supplicant_event(wpa_s
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
321 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant
*wpa_s
,
326 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
327 wpabuf_free(wpa_s
->lci
);
332 lci
= wpabuf_parse_bin(cmd
);
336 if (os_get_reltime(&wpa_s
->lci_time
)) {
341 wpabuf_free(wpa_s
->lci
);
349 wpas_ctrl_set_relative_rssi(struct wpa_supplicant
*wpa_s
, const char *cmd
)
353 if (os_strcmp(cmd
, "disable") == 0) {
354 wpa_s
->srp
.relative_rssi_set
= 0;
358 relative_rssi
= atoi(cmd
);
359 if (relative_rssi
< 0 || relative_rssi
> 100)
361 wpa_s
->srp
.relative_rssi
= relative_rssi
;
362 wpa_s
->srp
.relative_rssi_set
= 1;
367 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant
*wpa_s
,
373 /* <band>:adjust_value */
374 pos
= os_strchr(cmd
, ':');
378 adjust_rssi
= atoi(pos
);
379 if (adjust_rssi
< -100 || adjust_rssi
> 100)
382 if (os_strncmp(cmd
, "2G", 2) == 0)
383 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_2G
;
384 else if (os_strncmp(cmd
, "5G", 2) == 0)
385 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_5G
;
389 wpa_s
->srp
.relative_adjust_rssi
= adjust_rssi
;
395 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant
*wpa_s
,
398 struct wpabuf
*ric_ies
;
400 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
401 wpabuf_free(wpa_s
->ric_ies
);
402 wpa_s
->ric_ies
= NULL
;
406 ric_ies
= wpabuf_parse_bin(cmd
);
410 wpabuf_free(wpa_s
->ric_ies
);
411 wpa_s
->ric_ies
= ric_ies
;
417 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
423 value
= os_strchr(cmd
, ' ');
428 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
429 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
430 eapol_sm_configure(wpa_s
->eapol
,
431 atoi(value
), -1, -1, -1);
432 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
433 eapol_sm_configure(wpa_s
->eapol
,
434 -1, atoi(value
), -1, -1);
435 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
436 eapol_sm_configure(wpa_s
->eapol
,
437 -1, -1, atoi(value
), -1);
438 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
439 eapol_sm_configure(wpa_s
->eapol
,
440 -1, -1, -1, atoi(value
));
441 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
442 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
447 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
449 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
451 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
456 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
458 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
459 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
464 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
466 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
467 wpa_s
->wps_fragment_size
= atoi(value
);
468 #ifdef CONFIG_WPS_TESTING
469 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
471 val
= strtol(value
, NULL
, 0);
472 if (val
< 0 || val
> 0xff) {
474 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
475 "wps_version_number %ld", val
);
477 wps_version_number
= val
;
478 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
480 (wps_version_number
& 0xf0) >> 4,
481 wps_version_number
& 0x0f);
483 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
484 wps_testing_dummy_cred
= atoi(value
);
485 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
486 wps_testing_dummy_cred
);
487 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
488 wps_corrupt_pkhash
= atoi(value
);
489 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
491 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
492 if (value
[0] == '\0') {
493 wps_force_auth_types_in_use
= 0;
495 wps_force_auth_types
= strtol(value
, NULL
, 0);
496 wps_force_auth_types_in_use
= 1;
498 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
499 if (value
[0] == '\0') {
500 wps_force_encr_types_in_use
= 0;
502 wps_force_encr_types
= strtol(value
, NULL
, 0);
503 wps_force_encr_types_in_use
= 1;
505 #endif /* CONFIG_WPS_TESTING */
506 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
507 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
510 #ifdef CONFIG_TDLS_TESTING
511 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
512 tdls_testing
= strtol(value
, NULL
, 0);
513 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
514 #endif /* CONFIG_TDLS_TESTING */
515 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
516 int disabled
= atoi(value
);
517 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
519 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
521 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
523 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
524 #endif /* CONFIG_TDLS */
525 } else if (os_strcasecmp(cmd
, "pno") == 0) {
526 ret
= wpas_ctrl_pno(wpa_s
, value
);
527 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
528 int disabled
= atoi(value
);
529 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
532 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
533 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
534 if (os_strcmp(value
, "disable") == 0)
535 wpa_s
->set_sta_uapsd
= 0;
539 /* format: BE,BK,VI,VO;max SP Length */
541 pos
= os_strchr(value
, ',');
546 pos
= os_strchr(pos
, ',');
551 pos
= os_strchr(pos
, ',');
556 /* ignore max SP Length for now */
558 wpa_s
->set_sta_uapsd
= 1;
559 wpa_s
->sta_uapsd
= 0;
561 wpa_s
->sta_uapsd
|= BIT(0);
563 wpa_s
->sta_uapsd
|= BIT(1);
565 wpa_s
->sta_uapsd
|= BIT(2);
567 wpa_s
->sta_uapsd
|= BIT(3);
569 } else if (os_strcasecmp(cmd
, "ps") == 0) {
570 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
571 #ifdef CONFIG_WIFI_DISPLAY
572 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
573 int enabled
= !!atoi(value
);
574 if (enabled
&& !wpa_s
->global
->p2p
)
577 wifi_display_enable(wpa_s
->global
, enabled
);
578 #endif /* CONFIG_WIFI_DISPLAY */
579 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
580 ret
= set_bssid_filter(wpa_s
, value
);
581 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
582 ret
= set_disallow_aps(wpa_s
, value
);
583 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
584 wpa_s
->no_keep_alive
= !!atoi(value
);
586 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
587 os_free(wpa_s
->dpp_configurator_params
);
588 wpa_s
->dpp_configurator_params
= os_strdup(value
);
589 } else if (os_strcasecmp(cmd
, "dpp_init_max_tries") == 0) {
590 wpa_s
->dpp_init_max_tries
= atoi(value
);
591 } else if (os_strcasecmp(cmd
, "dpp_init_retry_time") == 0) {
592 wpa_s
->dpp_init_retry_time
= atoi(value
);
593 } else if (os_strcasecmp(cmd
, "dpp_resp_wait_time") == 0) {
594 wpa_s
->dpp_resp_wait_time
= atoi(value
);
595 } else if (os_strcasecmp(cmd
, "dpp_resp_max_tries") == 0) {
596 wpa_s
->dpp_resp_max_tries
= atoi(value
);
597 } else if (os_strcasecmp(cmd
, "dpp_resp_retry_time") == 0) {
598 wpa_s
->dpp_resp_retry_time
= atoi(value
);
599 #ifdef CONFIG_TESTING_OPTIONS
600 } else if (os_strcasecmp(cmd
, "dpp_pkex_own_mac_override") == 0) {
601 if (hwaddr_aton(value
, dpp_pkex_own_mac_override
))
603 } else if (os_strcasecmp(cmd
, "dpp_pkex_peer_mac_override") == 0) {
604 if (hwaddr_aton(value
, dpp_pkex_peer_mac_override
))
606 } else if (os_strcasecmp(cmd
, "dpp_pkex_ephemeral_key_override") == 0) {
607 size_t hex_len
= os_strlen(value
);
610 2 * sizeof(dpp_pkex_ephemeral_key_override
))
612 else if (hexstr2bin(value
, dpp_pkex_ephemeral_key_override
,
616 dpp_pkex_ephemeral_key_override_len
= hex_len
/ 2;
617 } else if (os_strcasecmp(cmd
, "dpp_protocol_key_override") == 0) {
618 size_t hex_len
= os_strlen(value
);
620 if (hex_len
> 2 * sizeof(dpp_protocol_key_override
))
622 else if (hexstr2bin(value
, dpp_protocol_key_override
,
626 dpp_protocol_key_override_len
= hex_len
/ 2;
627 } else if (os_strcasecmp(cmd
, "dpp_nonce_override") == 0) {
628 size_t hex_len
= os_strlen(value
);
630 if (hex_len
> 2 * sizeof(dpp_nonce_override
))
632 else if (hexstr2bin(value
, dpp_nonce_override
, hex_len
/ 2))
635 dpp_nonce_override_len
= hex_len
/ 2;
636 #endif /* CONFIG_TESTING_OPTIONS */
637 #endif /* CONFIG_DPP */
638 #ifdef CONFIG_TESTING_OPTIONS
639 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
640 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
641 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
642 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
644 if (wpa_s
->ap_iface
) {
645 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
646 wpa_s
->ext_eapol_frame_io
;
648 #endif /* CONFIG_AP */
649 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
650 wpa_s
->extra_roc_dur
= atoi(value
);
651 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
652 wpa_s
->test_failure
= atoi(value
);
653 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
654 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
655 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
656 wpa_s
->ignore_auth_resp
= !!atoi(value
);
657 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
658 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
659 wpa_drv_ignore_assoc_disallow(wpa_s
,
660 wpa_s
->ignore_assoc_disallow
);
661 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
662 wpa_s
->reject_btm_req_reason
= atoi(value
);
663 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
664 os_free(wpa_s
->get_pref_freq_list_override
);
666 wpa_s
->get_pref_freq_list_override
= NULL
;
668 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
669 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
670 wpabuf_free(wpa_s
->sae_commit_override
);
671 if (value
[0] == '\0')
672 wpa_s
->sae_commit_override
= NULL
;
674 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
676 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
677 os_free(wpa_s
->dpp_config_obj_override
);
678 if (value
[0] == '\0')
679 wpa_s
->dpp_config_obj_override
= NULL
;
681 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
682 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
683 os_free(wpa_s
->dpp_discovery_override
);
684 if (value
[0] == '\0')
685 wpa_s
->dpp_discovery_override
= NULL
;
687 wpa_s
->dpp_discovery_override
= os_strdup(value
);
688 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
689 os_free(wpa_s
->dpp_groups_override
);
690 if (value
[0] == '\0')
691 wpa_s
->dpp_groups_override
= NULL
;
693 wpa_s
->dpp_groups_override
= os_strdup(value
);
694 } else if (os_strcasecmp(cmd
,
695 "dpp_ignore_netaccesskey_mismatch") == 0) {
696 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
697 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
698 dpp_test
= atoi(value
);
699 #endif /* CONFIG_DPP */
700 #endif /* CONFIG_TESTING_OPTIONS */
702 } else if (os_strcasecmp(cmd
, "disable_fils") == 0) {
703 wpa_s
->disable_fils
= !!atoi(value
);
704 wpa_drv_disable_fils(wpa_s
, wpa_s
->disable_fils
);
705 wpa_supplicant_set_default_scan_ies(wpa_s
);
706 #endif /* CONFIG_FILS */
707 #ifndef CONFIG_NO_CONFIG_BLOBS
708 } else if (os_strcmp(cmd
, "blob") == 0) {
709 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
710 #endif /* CONFIG_NO_CONFIG_BLOBS */
711 } else if (os_strcasecmp(cmd
, "setband") == 0) {
712 ret
= wpas_ctrl_set_band(wpa_s
, value
);
714 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
715 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
718 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
720 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
721 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
722 } else if (os_strcasecmp(cmd
, "oce") == 0) {
723 wpa_s
->conf
->oce
= atoi(value
);
724 if (wpa_s
->conf
->oce
) {
725 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
726 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
727 wpa_s
->enable_oce
= OCE_STA
;
729 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
731 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
732 /* TODO: Need to add STA-CFON support */
733 wpa_printf(MSG_ERROR
,
734 "OCE STA-CFON feature is not yet supported");
738 wpa_s
->enable_oce
= 0;
740 wpa_supplicant_set_default_scan_ies(wpa_s
);
741 #endif /* CONFIG_MBO */
742 } else if (os_strcasecmp(cmd
, "lci") == 0) {
743 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
744 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
745 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
746 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
747 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
748 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
749 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
750 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
751 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
752 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
753 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
755 } else if (os_strcasecmp(cmd
, "coloc_intf_elems") == 0) {
756 struct wpabuf
*elems
;
758 elems
= wpabuf_parse_bin(value
);
761 wnm_set_coloc_intf_elems(wpa_s
, elems
);
762 #endif /* CONFIG_WNM */
765 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
767 wpa_supplicant_update_config(wpa_s
);
774 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
775 char *cmd
, char *buf
, size_t buflen
)
779 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
781 if (os_strcmp(cmd
, "version") == 0) {
782 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
783 } else if (os_strcasecmp(cmd
, "country") == 0) {
784 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
785 res
= os_snprintf(buf
, buflen
, "%c%c",
786 wpa_s
->conf
->country
[0],
787 wpa_s
->conf
->country
[1]);
788 #ifdef CONFIG_WIFI_DISPLAY
789 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
791 if (wpa_s
->global
->p2p
== NULL
||
792 wpa_s
->global
->p2p_disabled
)
795 enabled
= wpa_s
->global
->wifi_display
;
796 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
797 #endif /* CONFIG_WIFI_DISPLAY */
798 #ifdef CONFIG_TESTING_GET_GTK
799 } else if (os_strcmp(cmd
, "gtk") == 0) {
800 if (wpa_s
->last_gtk_len
== 0)
802 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
803 wpa_s
->last_gtk_len
);
805 #endif /* CONFIG_TESTING_GET_GTK */
806 } else if (os_strcmp(cmd
, "tls_library") == 0) {
807 res
= tls_get_library_version(buf
, buflen
);
808 #ifdef CONFIG_TESTING_OPTIONS
809 } else if (os_strcmp(cmd
, "anonce") == 0) {
810 return wpa_snprintf_hex(buf
, buflen
,
811 wpa_sm_get_anonce(wpa_s
->wpa
),
813 #endif /* CONFIG_TESTING_OPTIONS */
815 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
818 if (os_snprintf_error(buflen
, res
))
824 #ifdef IEEE8021X_EAPOL
825 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
829 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
831 if (hwaddr_aton(addr
, bssid
)) {
832 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
837 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
838 rsn_preauth_deinit(wpa_s
->wpa
);
839 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
844 #endif /* IEEE8021X_EAPOL */
849 static int wpa_supplicant_ctrl_iface_tdls_discover(
850 struct wpa_supplicant
*wpa_s
, char *addr
)
855 if (hwaddr_aton(addr
, peer
)) {
856 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
857 "address '%s'", addr
);
861 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
864 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
865 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
867 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
873 static int wpa_supplicant_ctrl_iface_tdls_setup(
874 struct wpa_supplicant
*wpa_s
, char *addr
)
879 if (hwaddr_aton(addr
, peer
)) {
880 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
881 "address '%s'", addr
);
885 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
888 if ((wpa_s
->conf
->tdls_external_control
) &&
889 wpa_tdls_is_external_setup(wpa_s
->wpa
))
890 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
892 wpa_tdls_remove(wpa_s
->wpa
, peer
);
894 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
895 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
897 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
903 static int wpa_supplicant_ctrl_iface_tdls_teardown(
904 struct wpa_supplicant
*wpa_s
, char *addr
)
909 if (os_strcmp(addr
, "*") == 0) {
910 /* remove everyone */
911 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
912 wpa_tdls_teardown_peers(wpa_s
->wpa
);
916 if (hwaddr_aton(addr
, peer
)) {
917 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
918 "address '%s'", addr
);
922 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
925 if ((wpa_s
->conf
->tdls_external_control
) &&
926 wpa_tdls_is_external_setup(wpa_s
->wpa
))
927 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
929 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
930 ret
= wpa_tdls_teardown_link(
932 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
934 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
940 static int ctrl_iface_get_capability_tdls(
941 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
945 ret
= os_snprintf(buf
, buflen
, "%s\n",
946 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
948 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
949 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
950 if (os_snprintf_error(buflen
, ret
))
956 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
957 struct wpa_supplicant
*wpa_s
, char *cmd
)
960 struct hostapd_freq_params freq_params
;
964 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
966 "tdls_chanswitch: Only supported with external setup");
970 os_memset(&freq_params
, 0, sizeof(freq_params
));
972 pos
= os_strchr(cmd
, ' ');
977 oper_class
= strtol(pos
, &end
, 10);
980 "tdls_chanswitch: Invalid op class provided");
985 freq_params
.freq
= atoi(pos
);
986 if (freq_params
.freq
== 0) {
987 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
991 #define SET_FREQ_SETTING(str) \
993 const char *pos2 = os_strstr(pos, " " #str "="); \
995 pos2 += sizeof(" " #str "=") - 1; \
996 freq_params.str = atoi(pos2); \
1000 SET_FREQ_SETTING(center_freq1
);
1001 SET_FREQ_SETTING(center_freq2
);
1002 SET_FREQ_SETTING(bandwidth
);
1003 SET_FREQ_SETTING(sec_channel_offset
);
1004 #undef SET_FREQ_SETTING
1006 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
1007 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
1009 if (hwaddr_aton(cmd
, peer
)) {
1010 wpa_printf(MSG_DEBUG
,
1011 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1016 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1017 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1018 MAC2STR(peer
), oper_class
, freq_params
.freq
,
1019 freq_params
.center_freq1
, freq_params
.center_freq2
,
1020 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
1021 freq_params
.ht_enabled
? " HT" : "",
1022 freq_params
.vht_enabled
? " VHT" : "");
1024 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
1029 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1030 struct wpa_supplicant
*wpa_s
, char *cmd
)
1034 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1035 wpa_printf(MSG_INFO
,
1036 "tdls_chanswitch: Only supported with external setup");
1040 if (hwaddr_aton(cmd
, peer
)) {
1041 wpa_printf(MSG_DEBUG
,
1042 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1047 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1050 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1054 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1055 struct wpa_supplicant
*wpa_s
, const char *addr
,
1056 char *buf
, size_t buflen
)
1059 const char *tdls_status
;
1062 if (hwaddr_aton(addr
, peer
)) {
1063 wpa_printf(MSG_DEBUG
,
1064 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1068 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1071 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1072 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1073 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1074 if (os_snprintf_error(buflen
, ret
))
1080 #endif /* CONFIG_TDLS */
1083 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1085 char *token
, *context
= NULL
;
1086 struct wmm_ac_ts_setup_params params
= {
1091 while ((token
= str_token(cmd
, " ", &context
))) {
1092 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1093 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1094 sscanf(token
, "nominal_msdu_size=%i",
1095 ¶ms
.nominal_msdu_size
) == 1 ||
1096 sscanf(token
, "mean_data_rate=%i",
1097 ¶ms
.mean_data_rate
) == 1 ||
1098 sscanf(token
, "min_phy_rate=%i",
1099 ¶ms
.minimum_phy_rate
) == 1 ||
1100 sscanf(token
, "sba=%i",
1101 ¶ms
.surplus_bandwidth_allowance
) == 1)
1104 if (os_strcasecmp(token
, "downlink") == 0) {
1105 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1106 } else if (os_strcasecmp(token
, "uplink") == 0) {
1107 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1108 } else if (os_strcasecmp(token
, "bidi") == 0) {
1109 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1110 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1111 params
.fixed_nominal_msdu
= 1;
1113 wpa_printf(MSG_DEBUG
,
1114 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1121 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1125 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1127 u8 tsid
= atoi(cmd
);
1129 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1133 #ifdef CONFIG_IEEE80211R
1134 static int wpa_supplicant_ctrl_iface_ft_ds(
1135 struct wpa_supplicant
*wpa_s
, char *addr
)
1137 u8 target_ap
[ETH_ALEN
];
1138 struct wpa_bss
*bss
;
1141 if (hwaddr_aton(addr
, target_ap
)) {
1142 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1143 "address '%s'", addr
);
1147 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1149 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1151 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1155 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1157 #endif /* CONFIG_IEEE80211R */
1161 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1164 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1166 u8 p2p_dev_addr
[ETH_ALEN
];
1167 #endif /* CONFIG_P2P */
1169 u8
*_p2p_dev_addr
= NULL
;
1170 #endif /* CONFIG_AP */
1172 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
1175 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1176 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1177 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1178 "P2P Device Address '%s'",
1182 _p2p_dev_addr
= p2p_dev_addr
;
1183 #endif /* CONFIG_P2P */
1184 } else if (hwaddr_aton(cmd
, bssid
)) {
1185 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1191 if (wpa_s
->ap_iface
)
1192 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1193 #endif /* CONFIG_AP */
1195 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1199 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1200 char *cmd
, char *buf
,
1203 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1207 pin
= os_strchr(cmd
, ' ');
1211 if (os_strcmp(cmd
, "any") == 0)
1213 else if (os_strcmp(cmd
, "get") == 0) {
1214 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1217 } else if (hwaddr_aton(cmd
, bssid
)) {
1218 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1224 if (wpa_s
->ap_iface
) {
1229 pos
= os_strchr(pin
, ' ');
1232 timeout
= atoi(pos
);
1236 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1237 buf
, buflen
, timeout
);
1239 #endif /* CONFIG_AP */
1242 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1246 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1247 if (os_snprintf_error(buflen
, ret
))
1252 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1257 /* Return the generated PIN */
1258 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1259 if (os_snprintf_error(buflen
, ret
))
1265 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1266 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1273 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1274 (u8
*) cmd
, os_strlen(cmd
));
1275 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1276 if (*pos
< '0' || *pos
> '9')
1280 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1284 if (len
!= 4 && len
!= 8) {
1285 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1291 unsigned int pin_val
;
1292 pin_val
= atoi(pin
);
1293 if (!wps_pin_valid(pin_val
)) {
1294 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1295 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1296 if (os_snprintf_error(buflen
, ret
))
1302 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1303 if (os_snprintf_error(buflen
, ret
))
1310 #ifdef CONFIG_WPS_NFC
1312 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1315 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1317 if (cmd
== NULL
|| cmd
[0] == '\0')
1319 else if (hwaddr_aton(cmd
, bssid
))
1322 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1327 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1328 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1335 pos
= os_strchr(cmd
, ' ');
1338 if (os_strcmp(cmd
, "WPS") == 0)
1340 else if (os_strcmp(cmd
, "NDEF") == 0)
1345 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1349 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1351 reply
[res
++] = '\n';
1360 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1361 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1367 if (os_strcmp(cmd
, "WPS") == 0)
1369 else if (os_strcmp(cmd
, "NDEF") == 0)
1374 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1378 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1380 reply
[res
++] = '\n';
1389 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1390 struct wpa_supplicant
*wpa_s
, char *pos
)
1396 int forced_freq
= 0;
1398 freq
= strstr(pos
, " freq=");
1402 forced_freq
= atoi(freq
);
1405 len
= os_strlen(pos
);
1410 buf
= wpabuf_alloc(len
);
1413 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1418 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1425 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1426 char *reply
, size_t max_len
,
1432 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1436 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1438 reply
[res
++] = '\n';
1448 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1449 char *reply
, size_t max_len
,
1455 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1457 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1461 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1463 reply
[res
++] = '\n';
1470 #endif /* CONFIG_P2P */
1473 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1474 char *cmd
, char *reply
,
1480 pos
= os_strchr(cmd
, ' ');
1485 if (os_strcmp(cmd
, "WPS") == 0)
1487 else if (os_strcmp(cmd
, "NDEF") == 0)
1492 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1495 return wpas_ctrl_nfc_get_handover_req_wps(
1496 wpa_s
, reply
, max_len
, ndef
);
1500 if (os_strcmp(pos
, "P2P-CR") == 0) {
1501 return wpas_ctrl_nfc_get_handover_req_p2p(
1502 wpa_s
, reply
, max_len
, ndef
);
1504 #endif /* CONFIG_P2P */
1510 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1511 char *reply
, size_t max_len
,
1512 int ndef
, int cr
, char *uuid
)
1517 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1521 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1523 reply
[res
++] = '\n';
1533 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1534 char *reply
, size_t max_len
,
1540 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1544 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1546 reply
[res
++] = '\n';
1553 #endif /* CONFIG_P2P */
1556 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1557 char *cmd
, char *reply
,
1563 pos
= os_strchr(cmd
, ' ');
1568 if (os_strcmp(cmd
, "WPS") == 0)
1570 else if (os_strcmp(cmd
, "NDEF") == 0)
1575 pos2
= os_strchr(pos
, ' ');
1578 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1581 return wpas_ctrl_nfc_get_handover_sel_wps(
1582 wpa_s
, reply
, max_len
, ndef
,
1583 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1587 if (os_strcmp(pos
, "P2P-CR") == 0) {
1588 return wpas_ctrl_nfc_get_handover_sel_p2p(
1589 wpa_s
, reply
, max_len
, ndef
, 0);
1592 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1593 return wpas_ctrl_nfc_get_handover_sel_p2p(
1594 wpa_s
, reply
, max_len
, ndef
, 1);
1596 #endif /* CONFIG_P2P */
1602 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1606 struct wpabuf
*req
, *sel
;
1608 char *pos
, *role
, *type
, *pos2
;
1611 int forced_freq
= 0;
1613 freq
= strstr(cmd
, " freq=");
1617 forced_freq
= atoi(freq
);
1619 #endif /* CONFIG_P2P */
1622 pos
= os_strchr(role
, ' ');
1624 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1630 pos
= os_strchr(type
, ' ');
1632 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1637 pos2
= os_strchr(pos
, ' ');
1639 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1644 len
= os_strlen(pos
);
1646 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1651 req
= wpabuf_alloc(len
);
1653 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1656 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1657 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1662 len
= os_strlen(pos2
);
1664 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1670 sel
= wpabuf_alloc(len
);
1672 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1676 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1677 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1683 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1684 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1686 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1687 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1689 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1691 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1693 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1694 #endif /* CONFIG_AP */
1696 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1698 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1699 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1701 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1703 #endif /* CONFIG_P2P */
1705 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1706 "reported: role=%s type=%s", role
, type
);
1713 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1718 #endif /* CONFIG_WPS_NFC */
1721 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1730 struct wps_new_ap_settings ap
;
1732 pin
= os_strchr(cmd
, ' ');
1737 if (hwaddr_aton(cmd
, bssid
)) {
1738 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1743 new_ssid
= os_strchr(pin
, ' ');
1744 if (new_ssid
== NULL
)
1745 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1748 new_auth
= os_strchr(new_ssid
, ' ');
1749 if (new_auth
== NULL
)
1753 new_encr
= os_strchr(new_auth
, ' ');
1754 if (new_encr
== NULL
)
1758 new_key
= os_strchr(new_encr
, ' ');
1759 if (new_key
== NULL
)
1763 os_memset(&ap
, 0, sizeof(ap
));
1764 ap
.ssid_hex
= new_ssid
;
1767 ap
.key_hex
= new_key
;
1768 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1773 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1774 char *cmd
, char *buf
,
1779 const char *pin_txt
;
1781 if (!wpa_s
->ap_iface
)
1784 pos
= os_strchr(cmd
, ' ');
1788 if (os_strcmp(cmd
, "disable") == 0) {
1789 wpas_wps_ap_pin_disable(wpa_s
);
1790 return os_snprintf(buf
, buflen
, "OK\n");
1793 if (os_strcmp(cmd
, "random") == 0) {
1795 timeout
= atoi(pos
);
1796 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1797 if (pin_txt
== NULL
)
1799 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1802 if (os_strcmp(cmd
, "get") == 0) {
1803 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1804 if (pin_txt
== NULL
)
1806 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1809 if (os_strcmp(cmd
, "set") == 0) {
1814 pos
= os_strchr(pos
, ' ');
1817 timeout
= atoi(pos
);
1819 if (os_strlen(pin
) > buflen
)
1821 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1823 return os_snprintf(buf
, buflen
, "%s", pin
);
1828 #endif /* CONFIG_AP */
1831 #ifdef CONFIG_WPS_ER
1832 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1835 char *uuid
= cmd
, *pin
, *pos
;
1836 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1837 pin
= os_strchr(uuid
, ' ');
1841 pos
= os_strchr(pin
, ' ');
1844 if (hwaddr_aton(pos
, addr_buf
) == 0)
1847 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1851 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1854 char *uuid
= cmd
, *pin
;
1855 pin
= os_strchr(uuid
, ' ');
1859 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1863 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1864 struct wpa_supplicant
*wpa_s
, char *cmd
)
1866 char *uuid
= cmd
, *id
;
1867 id
= os_strchr(uuid
, ' ');
1871 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1875 static int wpa_supplicant_ctrl_iface_wps_er_config(
1876 struct wpa_supplicant
*wpa_s
, char *cmd
)
1883 struct wps_new_ap_settings ap
;
1885 pin
= os_strchr(cmd
, ' ');
1890 new_ssid
= os_strchr(pin
, ' ');
1891 if (new_ssid
== NULL
)
1895 new_auth
= os_strchr(new_ssid
, ' ');
1896 if (new_auth
== NULL
)
1900 new_encr
= os_strchr(new_auth
, ' ');
1901 if (new_encr
== NULL
)
1905 new_key
= os_strchr(new_encr
, ' ');
1906 if (new_key
== NULL
)
1910 os_memset(&ap
, 0, sizeof(ap
));
1911 ap
.ssid_hex
= new_ssid
;
1914 ap
.key_hex
= new_key
;
1915 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1919 #ifdef CONFIG_WPS_NFC
1920 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1921 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1928 uuid
= os_strchr(cmd
, ' ');
1933 if (os_strcmp(cmd
, "WPS") == 0)
1935 else if (os_strcmp(cmd
, "NDEF") == 0)
1940 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1944 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1946 reply
[res
++] = '\n';
1953 #endif /* CONFIG_WPS_NFC */
1954 #endif /* CONFIG_WPS_ER */
1956 #endif /* CONFIG_WPS */
1959 #ifdef CONFIG_IBSS_RSN
1960 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1961 struct wpa_supplicant
*wpa_s
, char *addr
)
1965 if (hwaddr_aton(addr
, peer
)) {
1966 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1967 "address '%s'", addr
);
1971 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1974 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1976 #endif /* CONFIG_IBSS_RSN */
1979 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1982 #ifdef IEEE8021X_EAPOL
1985 struct wpa_ssid
*ssid
;
1987 pos
= os_strchr(rsp
, '-');
1992 pos
= os_strchr(pos
, ':');
1997 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1998 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1999 (u8
*) pos
, os_strlen(pos
));
2001 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2003 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2008 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
2010 #else /* IEEE8021X_EAPOL */
2011 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
2013 #endif /* IEEE8021X_EAPOL */
2017 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
2019 char *buf
, size_t buflen
)
2021 char *pos
, *end
, tmp
[30];
2022 int res
, verbose
, wps
, ret
;
2025 #endif /* CONFIG_HS20 */
2029 if (os_strcmp(params
, "-DRIVER") == 0)
2030 return wpa_drv_status(wpa_s
, buf
, buflen
);
2031 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
2032 wps
= os_strcmp(params
, "-WPS") == 0;
2035 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
2036 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2037 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2038 MAC2STR(wpa_s
->bssid
));
2039 if (os_snprintf_error(end
- pos
, ret
))
2042 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2044 if (os_snprintf_error(end
- pos
, ret
))
2048 u8
*_ssid
= ssid
->ssid
;
2049 size_t ssid_len
= ssid
->ssid_len
;
2050 u8 ssid_buf
[SSID_MAX_LEN
];
2051 if (ssid_len
== 0) {
2052 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2059 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2060 wpa_ssid_txt(_ssid
, ssid_len
),
2062 if (os_snprintf_error(end
- pos
, ret
))
2066 if (wps
&& ssid
->passphrase
&&
2067 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2068 (ssid
->mode
== WPAS_MODE_AP
||
2069 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2070 ret
= os_snprintf(pos
, end
- pos
,
2073 if (os_snprintf_error(end
- pos
, ret
))
2078 ret
= os_snprintf(pos
, end
- pos
,
2081 if (os_snprintf_error(end
- pos
, ret
))
2086 switch (ssid
->mode
) {
2087 case WPAS_MODE_INFRA
:
2088 ret
= os_snprintf(pos
, end
- pos
,
2091 case WPAS_MODE_IBSS
:
2092 ret
= os_snprintf(pos
, end
- pos
,
2096 ret
= os_snprintf(pos
, end
- pos
,
2099 case WPAS_MODE_P2P_GO
:
2100 ret
= os_snprintf(pos
, end
- pos
,
2103 case WPAS_MODE_P2P_GROUP_FORMATION
:
2104 ret
= os_snprintf(pos
, end
- pos
,
2105 "mode=P2P GO - group "
2108 case WPAS_MODE_MESH
:
2109 ret
= os_snprintf(pos
, end
- pos
,
2116 if (os_snprintf_error(end
- pos
, ret
))
2122 if (wpa_s
->ap_iface
) {
2123 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2127 #endif /* CONFIG_AP */
2128 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2132 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2135 #endif /* CONFIG_AP */
2136 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2137 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2138 wpa_s
->sme
.sae
.group
);
2139 if (os_snprintf_error(end
- pos
, ret
))
2143 #endif /* CONFIG_SAE */
2144 #endif /* CONFIG_SME */
2145 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2146 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2147 if (os_snprintf_error(end
- pos
, ret
))
2152 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2153 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2154 if (os_snprintf_error(end
- pos
, ret
))
2160 if (wpa_s
->global
->p2p
) {
2161 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2162 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2163 if (os_snprintf_error(end
- pos
, ret
))
2167 #endif /* CONFIG_P2P */
2169 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2170 MAC2STR(wpa_s
->own_addr
));
2171 if (os_snprintf_error(end
- pos
, ret
))
2176 if (wpa_s
->current_bss
&&
2177 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2178 HS20_IE_VENDOR_TYPE
)) &&
2179 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2180 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2183 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2184 release
= rel_num
+ 1;
2186 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2187 if (os_snprintf_error(end
- pos
, ret
))
2192 if (wpa_s
->current_ssid
) {
2193 struct wpa_cred
*cred
;
2196 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2199 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2202 if (cred
->provisioning_sp
) {
2203 ret
= os_snprintf(pos
, end
- pos
,
2204 "provisioning_sp=%s\n",
2205 cred
->provisioning_sp
);
2206 if (os_snprintf_error(end
- pos
, ret
))
2215 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2216 struct wpabuf
*names
=
2217 wpa_s
->current_bss
->anqp
->domain_name
;
2218 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2220 if (domain_name_list_contains(
2221 names
, cred
->domain
[i
], 1))
2224 if (i
== cred
->num_domain
)
2225 i
= 0; /* show first entry by default */
2227 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2229 if (os_snprintf_error(end
- pos
, ret
))
2234 if (wpa_s
->current_bss
== NULL
||
2235 wpa_s
->current_bss
->anqp
== NULL
)
2238 res
= interworking_home_sp_cred(
2240 wpa_s
->current_bss
->anqp
->domain_name
);
2248 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2249 if (os_snprintf_error(end
- pos
, ret
))
2256 #endif /* CONFIG_HS20 */
2258 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2259 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2260 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2266 #ifdef CONFIG_MACSEC
2267 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2270 #endif /* CONFIG_MACSEC */
2272 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2276 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2277 if (os_snprintf_error(end
- pos
, ret
))
2280 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2284 ret
= os_snprintf(pos
, end
- pos
, "\n");
2285 if (os_snprintf_error(end
- pos
, ret
))
2290 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2297 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2298 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2299 if (os_snprintf_error(end
- pos
, ret
))
2303 #endif /* CONFIG_WPS */
2305 if (wpa_s
->ieee80211ac
) {
2306 ret
= os_snprintf(pos
, end
- pos
, "ieee80211ac=1\n");
2307 if (os_snprintf_error(end
- pos
, ret
))
2314 * Allow using the STATUS command with default behavior, say for debug,
2315 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2316 * events with STATUS-NO_EVENTS.
2318 if (os_strcmp(params
, "-NO_EVENTS")) {
2319 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2320 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2321 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2323 MAC2STR(wpa_s
->bssid
),
2324 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2325 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2326 wpa_s
->current_ssid
->ssid_len
) : "");
2327 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2328 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2329 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2330 "- connection to " MACSTR
2331 " completed %s [id=%d id_str=%s]",
2332 MAC2STR(wpa_s
->bssid
), "(auth)",
2333 ssid
? ssid
->id
: -1,
2334 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2337 #endif /* ANDROID */
2343 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2348 struct wpa_ssid
*ssid
;
2351 /* cmd: "<network id> <BSSID>" */
2352 pos
= os_strchr(cmd
, ' ');
2357 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2358 if (hwaddr_aton(pos
, bssid
)) {
2359 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2363 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2365 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2370 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2371 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2377 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2378 char *cmd
, char *buf
,
2382 struct wpa_blacklist
*e
;
2386 /* cmd: "BLACKLIST [<BSSID>]" */
2390 e
= wpa_s
->blacklist
;
2392 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2394 if (os_snprintf_error(end
- pos
, ret
))
2403 if (os_strncmp(cmd
, "clear", 5) == 0) {
2404 wpa_blacklist_clear(wpa_s
);
2405 os_memcpy(buf
, "OK\n", 3);
2409 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2410 if (hwaddr_aton(cmd
, bssid
)) {
2411 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2416 * Add the BSSID twice, so its count will be 2, causing it to be
2417 * skipped when processing scan results.
2419 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2422 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2425 os_memcpy(buf
, "OK\n", 3);
2430 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2431 char *cmd
, char *buf
,
2434 char *pos
, *end
, *stamp
;
2437 /* cmd: "LOG_LEVEL [<level>]" */
2441 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2443 debug_level_str(wpa_debug_level
),
2444 wpa_debug_timestamp
);
2445 if (os_snprintf_error(end
- pos
, ret
))
2454 stamp
= os_strchr(cmd
, ' ');
2457 while (*stamp
== ' ') {
2462 if (os_strlen(cmd
)) {
2463 int level
= str_to_debug_level(cmd
);
2466 wpa_debug_level
= level
;
2469 if (stamp
&& os_strlen(stamp
))
2470 wpa_debug_timestamp
= atoi(stamp
);
2472 os_memcpy(buf
, "OK\n", 3);
2477 static int wpa_supplicant_ctrl_iface_list_networks(
2478 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2480 char *pos
, *end
, *prev
;
2481 struct wpa_ssid
*ssid
;
2486 ret
= os_snprintf(pos
, end
- pos
,
2487 "network id / ssid / bssid / flags\n");
2488 if (os_snprintf_error(end
- pos
, ret
))
2492 ssid
= wpa_s
->conf
->ssid
;
2494 /* skip over ssids until we find next one */
2495 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2496 int last_id
= atoi(cmd
+ 8);
2497 if (last_id
!= -1) {
2498 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2506 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2508 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2509 if (os_snprintf_error(end
- pos
, ret
))
2512 if (ssid
->bssid_set
) {
2513 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2514 MAC2STR(ssid
->bssid
));
2516 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2518 if (os_snprintf_error(end
- pos
, ret
))
2521 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2522 ssid
== wpa_s
->current_ssid
?
2524 ssid
->disabled
? "[DISABLED]" : "",
2525 ssid
->disabled_until
.sec
?
2526 "[TEMP-DISABLED]" : "",
2527 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2529 if (os_snprintf_error(end
- pos
, ret
))
2532 ret
= os_snprintf(pos
, end
- pos
, "\n");
2533 if (os_snprintf_error(end
- pos
, ret
))
2544 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2547 ret
= os_snprintf(pos
, end
- pos
, "-");
2548 if (os_snprintf_error(end
- pos
, ret
))
2551 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2559 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2560 const u8
*ie
, size_t ie_len
)
2562 struct wpa_ie_data data
;
2566 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2567 if (os_snprintf_error(end
- pos
, ret
))
2571 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2572 ret
= os_snprintf(pos
, end
- pos
, "?]");
2573 if (os_snprintf_error(end
- pos
, ret
))
2580 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2581 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2582 pos
== start
? "" : "+");
2583 if (os_snprintf_error(end
- pos
, ret
))
2587 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2588 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2589 pos
== start
? "" : "+");
2590 if (os_snprintf_error(end
- pos
, ret
))
2594 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2595 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2596 pos
== start
? "" : "+");
2597 if (os_snprintf_error(end
- pos
, ret
))
2601 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2602 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2603 pos
== start
? "" : "+");
2604 if (os_snprintf_error(end
- pos
, ret
))
2608 #ifdef CONFIG_IEEE80211R
2609 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2610 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2611 pos
== start
? "" : "+");
2612 if (os_snprintf_error(end
- pos
, ret
))
2616 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2617 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2618 pos
== start
? "" : "+");
2619 if (os_snprintf_error(end
- pos
, ret
))
2623 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2624 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2625 pos
== start
? "" : "+");
2626 if (os_snprintf_error(end
- pos
, ret
))
2630 #endif /* CONFIG_IEEE80211R */
2631 #ifdef CONFIG_IEEE80211W
2632 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2633 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2634 pos
== start
? "" : "+");
2635 if (os_snprintf_error(end
- pos
, ret
))
2639 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2640 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2641 pos
== start
? "" : "+");
2642 if (os_snprintf_error(end
- pos
, ret
))
2646 #endif /* CONFIG_IEEE80211W */
2648 #ifdef CONFIG_SUITEB
2649 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2650 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2651 pos
== start
? "" : "+");
2652 if (os_snprintf_error(end
- pos
, ret
))
2656 #endif /* CONFIG_SUITEB */
2658 #ifdef CONFIG_SUITEB192
2659 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2660 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2661 pos
== start
? "" : "+");
2662 if (os_snprintf_error(end
- pos
, ret
))
2666 #endif /* CONFIG_SUITEB192 */
2669 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2670 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2671 pos
== start
? "" : "+");
2672 if (os_snprintf_error(end
- pos
, ret
))
2676 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2677 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2678 pos
== start
? "" : "+");
2679 if (os_snprintf_error(end
- pos
, ret
))
2683 #ifdef CONFIG_IEEE80211R
2684 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2685 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2686 pos
== start
? "" : "+");
2687 if (os_snprintf_error(end
- pos
, ret
))
2691 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2692 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2693 pos
== start
? "" : "+");
2694 if (os_snprintf_error(end
- pos
, ret
))
2698 #endif /* CONFIG_IEEE80211R */
2699 #endif /* CONFIG_FILS */
2702 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2703 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2704 pos
== start
? "" : "+");
2705 if (os_snprintf_error(end
- pos
, ret
))
2709 #endif /* CONFIG_OWE */
2712 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2713 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2714 pos
== start
? "" : "+");
2715 if (os_snprintf_error(end
- pos
, ret
))
2719 #endif /* CONFIG_DPP */
2721 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2722 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2723 pos
== start
? "" : "+");
2724 if (os_snprintf_error(end
- pos
, ret
))
2729 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2731 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2732 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2733 if (os_snprintf_error(end
- pos
, ret
))
2738 ret
= os_snprintf(pos
, end
- pos
, "]");
2739 if (os_snprintf_error(end
- pos
, ret
))
2748 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2749 char *pos
, char *end
,
2750 struct wpabuf
*wps_ie
)
2757 if (wps_is_selected_pbc_registrar(wps_ie
))
2759 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2761 else if (wps_is_selected_pin_registrar(wps_ie
))
2766 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2767 if (!os_snprintf_error(end
- pos
, ret
))
2769 wpabuf_free(wps_ie
);
2772 #endif /* CONFIG_WPS */
2775 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2776 char *pos
, char *end
,
2777 const struct wpa_bss
*bss
)
2780 struct wpabuf
*wps_ie
;
2781 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2782 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2783 #else /* CONFIG_WPS */
2785 #endif /* CONFIG_WPS */
2789 /* Format one result on one text line into a buffer. */
2790 static int wpa_supplicant_ctrl_iface_scan_result(
2791 struct wpa_supplicant
*wpa_s
,
2792 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2796 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
, *owe
;
2798 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2799 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2801 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2802 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2803 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2805 return 0; /* Do not show P2P listen discovery results here */
2810 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2811 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2812 if (os_snprintf_error(end
- pos
, ret
))
2815 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2817 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2818 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2820 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2823 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2825 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2826 osen_ie
, 2 + osen_ie
[1]);
2827 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
2829 ret
= os_snprintf(pos
, end
- pos
,
2830 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2831 if (os_snprintf_error(end
- pos
, ret
))
2835 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2836 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2837 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2838 if (os_snprintf_error(end
- pos
, ret
))
2843 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2844 if (os_snprintf_error(end
- pos
, ret
))
2848 if (bss_is_dmg(bss
)) {
2850 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2851 if (os_snprintf_error(end
- pos
, ret
))
2854 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2855 case IEEE80211_CAP_DMG_IBSS
:
2858 case IEEE80211_CAP_DMG_AP
:
2861 case IEEE80211_CAP_DMG_PBSS
:
2868 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2869 if (os_snprintf_error(end
- pos
, ret
))
2873 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2874 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2875 if (os_snprintf_error(end
- pos
, ret
))
2879 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2880 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2881 if (os_snprintf_error(end
- pos
, ret
))
2887 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2888 if (os_snprintf_error(end
- pos
, ret
))
2893 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2894 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2895 if (os_snprintf_error(end
- pos
, ret
))
2899 #endif /* CONFIG_HS20 */
2901 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2902 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2903 if (os_snprintf_error(end
- pos
, ret
))
2907 #endif /* CONFIG_FILS */
2909 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2910 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2911 if (os_snprintf_error(end
- pos
, ret
))
2915 #endif /* CONFIG_FST */
2917 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2918 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2919 if (os_snprintf_error(end
- pos
, ret
))
2923 ret
= os_snprintf(pos
, end
- pos
, "\n");
2924 if (os_snprintf_error(end
- pos
, ret
))
2932 static int wpa_supplicant_ctrl_iface_scan_results(
2933 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2936 struct wpa_bss
*bss
;
2941 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2943 if (os_snprintf_error(end
- pos
, ret
))
2947 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2948 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2950 if (ret
< 0 || ret
>= end
- pos
)
2961 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2962 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2964 char *pos
, ifname
[IFNAMSIZ
+ 1];
2968 pos
= os_strstr(cmd
, "ifname=");
2971 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2974 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2977 os_strlcpy(reply
, ifname
, max_len
);
2978 return os_strlen(ifname
);
2982 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2983 struct wpa_supplicant
*wpa_s
, char *cmd
)
2986 struct wpa_ssid
*ssid
;
2989 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2991 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2993 wpa_printf(MSG_DEBUG
,
2994 "CTRL_IFACE: Could not find network id=%d", id
);
2997 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2998 wpa_printf(MSG_DEBUG
,
2999 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3002 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
3003 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
3004 wpa_printf(MSG_ERROR
,
3005 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3010 * TODO: If necessary write our own group_add function,
3011 * for now we can reuse select_network
3013 wpa_supplicant_select_network(wpa_s
, ssid
);
3019 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3020 struct wpa_supplicant
*wpa_s
, char *cmd
)
3022 struct wpa_supplicant
*orig
;
3023 struct wpa_global
*global
;
3026 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
3028 global
= wpa_s
->global
;
3031 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3032 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
3038 wpa_printf(MSG_ERROR
,
3039 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3043 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
3044 wpa_printf(MSG_ERROR
,
3045 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3049 wpa_s
->reassociate
= 0;
3050 wpa_s
->disconnected
= 1;
3051 wpa_supplicant_cancel_sched_scan(wpa_s
);
3052 wpa_supplicant_cancel_scan(wpa_s
);
3055 * TODO: If necessary write our own group_remove function,
3056 * for now we can reuse deauthenticate
3058 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3060 if (wpa_s
->mesh_if_created
)
3061 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3067 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3068 struct wpa_supplicant
*wpa_s
, char *cmd
)
3072 if (hwaddr_aton(cmd
, addr
) < 0)
3075 return wpas_mesh_peer_remove(wpa_s
, addr
);
3079 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3080 struct wpa_supplicant
*wpa_s
, char *cmd
)
3086 pos
= os_strstr(cmd
, " duration=");
3089 duration
= atoi(pos
+ 10);
3094 if (hwaddr_aton(cmd
, addr
))
3097 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3100 #endif /* CONFIG_MESH */
3103 static int wpa_supplicant_ctrl_iface_select_network(
3104 struct wpa_supplicant
*wpa_s
, char *cmd
)
3107 struct wpa_ssid
*ssid
;
3110 /* cmd: "<network id>" or "any" */
3111 if (os_strncmp(cmd
, "any", 3) == 0) {
3112 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3116 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3118 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3120 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3121 "network id=%d", id
);
3124 if (ssid
->disabled
== 2) {
3125 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3126 "SELECT_NETWORK with persistent P2P group");
3131 pos
= os_strstr(cmd
, " freq=");
3133 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3135 os_free(wpa_s
->select_network_scan_freqs
);
3136 wpa_s
->select_network_scan_freqs
= freqs
;
3140 wpa_s
->scan_min_time
.sec
= 0;
3141 wpa_s
->scan_min_time
.usec
= 0;
3142 wpa_supplicant_select_network(wpa_s
, ssid
);
3148 static int wpa_supplicant_ctrl_iface_enable_network(
3149 struct wpa_supplicant
*wpa_s
, char *cmd
)
3152 struct wpa_ssid
*ssid
;
3154 /* cmd: "<network id>" or "all" */
3155 if (os_strcmp(cmd
, "all") == 0) {
3156 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3160 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3162 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3164 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3165 "network id=%d", id
);
3168 if (ssid
->disabled
== 2) {
3169 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3170 "ENABLE_NETWORK with persistent P2P group");
3174 if (os_strstr(cmd
, " no-connect")) {
3179 wpa_s
->scan_min_time
.sec
= 0;
3180 wpa_s
->scan_min_time
.usec
= 0;
3181 wpa_supplicant_enable_network(wpa_s
, ssid
);
3187 static int wpa_supplicant_ctrl_iface_disable_network(
3188 struct wpa_supplicant
*wpa_s
, char *cmd
)
3191 struct wpa_ssid
*ssid
;
3193 /* cmd: "<network id>" or "all" */
3194 if (os_strcmp(cmd
, "all") == 0) {
3195 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3199 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3201 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3203 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3204 "network id=%d", id
);
3207 if (ssid
->disabled
== 2) {
3208 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3209 "DISABLE_NETWORK with persistent P2P "
3214 wpa_supplicant_disable_network(wpa_s
, ssid
);
3220 static int wpa_supplicant_ctrl_iface_add_network(
3221 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3223 struct wpa_ssid
*ssid
;
3226 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3228 ssid
= wpa_supplicant_add_network(wpa_s
);
3232 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3233 if (os_snprintf_error(buflen
, ret
))
3239 static int wpa_supplicant_ctrl_iface_remove_network(
3240 struct wpa_supplicant
*wpa_s
, char *cmd
)
3243 struct wpa_ssid
*ssid
;
3246 /* cmd: "<network id>" or "all" */
3247 if (os_strcmp(cmd
, "all") == 0) {
3248 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3249 if (wpa_s
->sched_scanning
)
3250 wpa_supplicant_cancel_sched_scan(wpa_s
);
3252 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3253 if (wpa_s
->current_ssid
) {
3255 wpa_s
->sme
.prev_bssid_set
= 0;
3256 #endif /* CONFIG_SME */
3257 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3258 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3259 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3260 wpa_s
->own_disconnect_req
= 1;
3261 wpa_supplicant_deauthenticate(
3262 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3264 ssid
= wpa_s
->conf
->ssid
;
3266 struct wpa_ssid
*remove_ssid
= ssid
;
3269 if (wpa_s
->last_ssid
== remove_ssid
)
3270 wpa_s
->last_ssid
= NULL
;
3271 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3272 wpa_config_remove_network(wpa_s
->conf
, id
);
3278 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3280 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3282 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3287 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3288 "network id=%d", id
);
3295 static int wpa_supplicant_ctrl_iface_update_network(
3296 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3297 char *name
, char *value
)
3301 ret
= wpa_config_set(ssid
, name
, value
, 0);
3303 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3304 "variable '%s'", name
);
3308 return 0; /* No change to the previously configured value */
3310 if (os_strcmp(name
, "bssid") != 0 &&
3311 os_strcmp(name
, "bssid_hint") != 0 &&
3312 os_strcmp(name
, "priority") != 0) {
3313 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3315 if (wpa_s
->current_ssid
== ssid
||
3316 wpa_s
->current_ssid
== NULL
) {
3318 * Invalidate the EAP session cache if anything in the
3319 * current or previously used configuration changes.
3321 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3325 if ((os_strcmp(name
, "psk") == 0 &&
3326 value
[0] == '"' && ssid
->ssid_len
) ||
3327 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3328 wpa_config_update_psk(ssid
);
3329 else if (os_strcmp(name
, "priority") == 0)
3330 wpa_config_update_prio_list(wpa_s
->conf
);
3336 static int wpa_supplicant_ctrl_iface_set_network(
3337 struct wpa_supplicant
*wpa_s
, char *cmd
)
3339 int id
, ret
, prev_bssid_set
, prev_disabled
;
3340 struct wpa_ssid
*ssid
;
3342 u8 prev_bssid
[ETH_ALEN
];
3344 /* cmd: "<network id> <variable name> <value>" */
3345 name
= os_strchr(cmd
, ' ');
3350 value
= os_strchr(name
, ' ');
3356 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3358 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3359 (u8
*) value
, os_strlen(value
));
3361 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3363 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3368 prev_bssid_set
= ssid
->bssid_set
;
3369 prev_disabled
= ssid
->disabled
;
3370 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3371 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3374 (ssid
->bssid_set
!= prev_bssid_set
||
3375 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3376 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3378 if (prev_disabled
!= ssid
->disabled
&&
3379 (prev_disabled
== 2 || ssid
->disabled
== 2))
3380 wpas_notify_network_type_changed(wpa_s
, ssid
);
3386 static int wpa_supplicant_ctrl_iface_get_network(
3387 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3391 struct wpa_ssid
*ssid
;
3394 /* cmd: "<network id> <variable name>" */
3395 name
= os_strchr(cmd
, ' ');
3396 if (name
== NULL
|| buflen
== 0)
3401 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3404 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3406 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3411 value
= wpa_config_get_no_key(ssid
, name
);
3412 if (value
== NULL
) {
3413 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3414 "variable '%s'", name
);
3418 res
= os_strlcpy(buf
, value
, buflen
);
3419 if (res
>= buflen
) {
3430 static int wpa_supplicant_ctrl_iface_dup_network(
3431 struct wpa_supplicant
*wpa_s
, char *cmd
,
3432 struct wpa_supplicant
*dst_wpa_s
)
3434 struct wpa_ssid
*ssid_s
, *ssid_d
;
3435 char *name
, *id
, *value
;
3436 int id_s
, id_d
, ret
;
3438 /* cmd: "<src network id> <dst network id> <variable name>" */
3439 id
= os_strchr(cmd
, ' ');
3444 name
= os_strchr(id
, ' ');
3452 wpa_printf(MSG_DEBUG
,
3453 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3454 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3456 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3457 if (ssid_s
== NULL
) {
3458 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3459 "network id=%d", id_s
);
3463 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3464 if (ssid_d
== NULL
) {
3465 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3466 "network id=%d", id_d
);
3470 value
= wpa_config_get(ssid_s
, name
);
3471 if (value
== NULL
) {
3472 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3473 "variable '%s'", name
);
3477 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3486 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3487 char *buf
, size_t buflen
)
3490 struct wpa_cred
*cred
;
3495 ret
= os_snprintf(pos
, end
- pos
,
3496 "cred id / realm / username / domain / imsi\n");
3497 if (os_snprintf_error(end
- pos
, ret
))
3501 cred
= wpa_s
->conf
->cred
;
3503 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3504 cred
->id
, cred
->realm
? cred
->realm
: "",
3505 cred
->username
? cred
->username
: "",
3506 cred
->domain
? cred
->domain
[0] : "",
3507 cred
->imsi
? cred
->imsi
: "");
3508 if (os_snprintf_error(end
- pos
, ret
))
3519 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3520 char *buf
, size_t buflen
)
3522 struct wpa_cred
*cred
;
3525 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3527 cred
= wpa_config_add_cred(wpa_s
->conf
);
3531 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3533 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3534 if (os_snprintf_error(buflen
, ret
))
3540 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3541 struct wpa_cred
*cred
)
3543 struct wpa_ssid
*ssid
;
3548 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3553 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3554 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3558 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3560 /* Remove any network entry created based on the removed credential */
3561 ssid
= wpa_s
->conf
->ssid
;
3563 if (ssid
->parent_cred
== cred
) {
3566 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3567 "used the removed credential", ssid
->id
);
3568 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3569 if (os_snprintf_error(sizeof(str
), res
))
3570 str
[sizeof(str
) - 1] = '\0';
3572 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3581 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3585 struct wpa_cred
*cred
, *prev
;
3587 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3588 * "provisioning_sp=<FQDN> */
3589 if (os_strcmp(cmd
, "all") == 0) {
3590 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3591 cred
= wpa_s
->conf
->cred
;
3595 wpas_ctrl_remove_cred(wpa_s
, prev
);
3600 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3601 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3603 cred
= wpa_s
->conf
->cred
;
3609 for (i
= 0; i
< prev
->num_domain
; i
++) {
3610 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3613 wpas_ctrl_remove_cred(wpa_s
, prev
);
3621 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3622 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3624 cred
= wpa_s
->conf
->cred
;
3628 if (prev
->provisioning_sp
&&
3629 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3630 wpas_ctrl_remove_cred(wpa_s
, prev
);
3636 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3638 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3639 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3643 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3647 struct wpa_cred
*cred
;
3650 /* cmd: "<cred id> <variable name> <value>" */
3651 name
= os_strchr(cmd
, ' ');
3656 value
= os_strchr(name
, ' ');
3662 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3664 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3665 (u8
*) value
, os_strlen(value
));
3667 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3669 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3674 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3675 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3676 "variable '%s'", name
);
3680 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3686 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3687 char *cmd
, char *buf
,
3692 struct wpa_cred
*cred
;
3695 /* cmd: "<cred id> <variable name>" */
3696 name
= os_strchr(cmd
, ' ');
3702 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3705 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3707 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3712 value
= wpa_config_get_cred_no_key(cred
, name
);
3713 if (value
== NULL
) {
3714 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3719 res
= os_strlcpy(buf
, value
, buflen
);
3720 if (res
>= buflen
) {
3731 #ifndef CONFIG_NO_CONFIG_WRITE
3732 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3736 if (!wpa_s
->conf
->update_config
) {
3737 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3738 "to update configuration (update_config=0)");
3742 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3744 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3745 "update configuration");
3747 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3753 #endif /* CONFIG_NO_CONFIG_WRITE */
3756 struct cipher_info
{
3762 static const struct cipher_info ciphers
[] = {
3763 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3764 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3765 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3766 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3767 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3768 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3769 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3770 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3773 static const struct cipher_info ciphers_group_mgmt
[] = {
3774 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3775 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3776 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3777 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3781 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3782 struct wpa_driver_capa
*capa
,
3783 char *buf
, size_t buflen
)
3796 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3802 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3803 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3804 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3805 pos
== buf
? "" : " ",
3807 if (os_snprintf_error(end
- pos
, ret
))
3817 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3818 struct wpa_driver_capa
*capa
,
3819 char *buf
, size_t buflen
)
3832 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3838 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3839 if (capa
->enc
& ciphers
[i
].capa
) {
3840 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3841 pos
== buf
? "" : " ",
3843 if (os_snprintf_error(end
- pos
, ret
))
3853 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3854 struct wpa_driver_capa
*capa
,
3855 char *buf
, size_t buflen
)
3867 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3868 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3869 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3870 pos
== buf
? "" : " ",
3871 ciphers_group_mgmt
[i
].name
);
3872 if (os_snprintf_error(end
- pos
, ret
))
3882 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3883 struct wpa_driver_capa
*capa
,
3884 char *buf
, size_t buflen
)
3896 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3903 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3904 if (os_snprintf_error(end
- pos
, ret
))
3908 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3909 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3910 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3911 if (os_snprintf_error(end
- pos
, ret
))
3916 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3917 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3918 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3919 if (os_snprintf_error(end
- pos
, ret
))
3924 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3925 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3926 if (os_snprintf_error(end
- pos
, ret
))
3931 #ifdef CONFIG_SUITEB
3932 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3933 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3934 if (os_snprintf_error(end
- pos
, ret
))
3938 #endif /* CONFIG_SUITEB */
3939 #ifdef CONFIG_SUITEB192
3940 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3941 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3942 if (os_snprintf_error(end
- pos
, ret
))
3946 #endif /* CONFIG_SUITEB192 */
3948 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
3949 ret
= os_snprintf(pos
, end
- pos
, " OWE");
3950 if (os_snprintf_error(end
- pos
, ret
))
3954 #endif /* CONFIG_OWE */
3956 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
3957 ret
= os_snprintf(pos
, end
- pos
, " DPP");
3958 if (os_snprintf_error(end
- pos
, ret
))
3962 #endif /* CONFIG_DPP */
3964 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
3965 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
3966 if (os_snprintf_error(end
- pos
, ret
))
3970 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
3971 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
3972 if (os_snprintf_error(end
- pos
, ret
))
3976 #ifdef CONFIG_IEEE80211R
3977 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
3978 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
3979 if (os_snprintf_error(end
- pos
, ret
))
3983 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
3984 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
3985 if (os_snprintf_error(end
- pos
, ret
))
3989 #endif /* CONFIG_IEEE80211R */
3990 #endif /* CONFIG_FILS */
3992 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SAE
) {
3993 ret
= os_snprintf(pos
, end
- pos
, " SAE");
3994 if (os_snprintf_error(end
- pos
, ret
))
3998 #endif /* CONFIG_SAE */
4004 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
4005 struct wpa_driver_capa
*capa
,
4006 char *buf
, size_t buflen
)
4018 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
4024 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
4025 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4026 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
4027 pos
== buf
? "" : " ");
4028 if (os_snprintf_error(end
- pos
, ret
))
4033 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4034 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
4035 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
4036 pos
== buf
? "" : " ");
4037 if (os_snprintf_error(end
- pos
, ret
))
4046 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
4047 int res
, char *strict
,
4048 struct wpa_driver_capa
*capa
,
4049 char *buf
, size_t buflen
)
4061 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4067 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4068 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4069 pos
== buf
? "" : " ");
4070 if (os_snprintf_error(end
- pos
, ret
))
4075 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4076 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4077 pos
== buf
? "" : " ");
4078 if (os_snprintf_error(end
- pos
, ret
))
4083 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4084 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4085 pos
== buf
? "" : " ");
4086 if (os_snprintf_error(end
- pos
, ret
))
4092 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4093 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4094 pos
== buf
? "" : " ");
4095 if (os_snprintf_error(end
- pos
, ret
))
4099 #endif /* CONFIG_SAE */
4102 if (wpa_is_fils_supported(wpa_s
)) {
4103 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4104 pos
== buf
? "" : " ");
4105 if (os_snprintf_error(end
- pos
, ret
))
4110 #ifdef CONFIG_FILS_SK_PFS
4111 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4112 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4113 pos
== buf
? "" : " ");
4114 if (os_snprintf_error(end
- pos
, ret
))
4118 #endif /* CONFIG_FILS_SK_PFS */
4119 #endif /* CONFIG_FILS */
4125 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4126 struct wpa_driver_capa
*capa
,
4127 char *buf
, size_t buflen
)
4139 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4145 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4146 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4147 pos
== buf
? "" : " ");
4148 if (os_snprintf_error(end
- pos
, ret
))
4153 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4154 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4155 pos
== buf
? "" : " ");
4156 if (os_snprintf_error(end
- pos
, ret
))
4162 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4163 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4164 pos
== buf
? "" : " ");
4165 if (os_snprintf_error(end
- pos
, ret
))
4169 #endif /* CONFIG_MESH */
4175 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4176 char *buf
, size_t buflen
)
4178 struct hostapd_channel_data
*chnl
;
4180 char *pos
, *end
, *hmode
;
4185 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4186 switch (wpa_s
->hw
.modes
[j
].mode
) {
4187 case HOSTAPD_MODE_IEEE80211B
:
4190 case HOSTAPD_MODE_IEEE80211G
:
4193 case HOSTAPD_MODE_IEEE80211A
:
4196 case HOSTAPD_MODE_IEEE80211AD
:
4202 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4203 if (os_snprintf_error(end
- pos
, ret
))
4206 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4207 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4208 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4210 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4211 if (os_snprintf_error(end
- pos
, ret
))
4215 ret
= os_snprintf(pos
, end
- pos
, "\n");
4216 if (os_snprintf_error(end
- pos
, ret
))
4225 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4226 char *buf
, size_t buflen
)
4228 struct hostapd_channel_data
*chnl
;
4230 char *pos
, *end
, *hmode
;
4235 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4236 switch (wpa_s
->hw
.modes
[j
].mode
) {
4237 case HOSTAPD_MODE_IEEE80211B
:
4240 case HOSTAPD_MODE_IEEE80211G
:
4243 case HOSTAPD_MODE_IEEE80211A
:
4246 case HOSTAPD_MODE_IEEE80211AD
:
4252 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4254 if (os_snprintf_error(end
- pos
, ret
))
4257 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4258 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4259 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4261 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4262 chnl
[i
].chan
, chnl
[i
].freq
,
4263 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4265 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4268 if (os_snprintf_error(end
- pos
, ret
))
4272 ret
= os_snprintf(pos
, end
- pos
, "\n");
4273 if (os_snprintf_error(end
- pos
, ret
))
4282 static int wpa_supplicant_ctrl_iface_get_capability(
4283 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4286 struct wpa_driver_capa capa
;
4292 /* Determine whether or not strict checking was requested */
4293 len
= os_strlcpy(field
, _field
, sizeof(field
));
4294 if (len
>= sizeof(field
))
4296 strict
= os_strchr(field
, ' ');
4297 if (strict
!= NULL
) {
4299 if (os_strcmp(strict
, "strict") != 0)
4303 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4304 field
, strict
? strict
: "");
4306 if (os_strcmp(field
, "eap") == 0) {
4307 return eap_get_names(buf
, buflen
);
4310 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4312 if (os_strcmp(field
, "pairwise") == 0)
4313 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4316 if (os_strcmp(field
, "group") == 0)
4317 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4320 if (os_strcmp(field
, "group_mgmt") == 0)
4321 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4324 if (os_strcmp(field
, "key_mgmt") == 0)
4325 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4328 if (os_strcmp(field
, "proto") == 0)
4329 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4332 if (os_strcmp(field
, "auth_alg") == 0)
4333 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4334 &capa
, buf
, buflen
);
4336 if (os_strcmp(field
, "modes") == 0)
4337 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4340 if (os_strcmp(field
, "channels") == 0)
4341 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4343 if (os_strcmp(field
, "freq") == 0)
4344 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4347 if (os_strcmp(field
, "tdls") == 0)
4348 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4349 #endif /* CONFIG_TDLS */
4352 if (os_strcmp(field
, "erp") == 0) {
4353 res
= os_snprintf(buf
, buflen
, "ERP");
4354 if (os_snprintf_error(buflen
, res
))
4358 #endif /* CONFIG_EPR */
4361 if (os_strcmp(field
, "fips") == 0) {
4362 res
= os_snprintf(buf
, buflen
, "FIPS");
4363 if (os_snprintf_error(buflen
, res
))
4367 #endif /* CONFIG_FIPS */
4370 if (os_strcmp(field
, "acs") == 0) {
4371 res
= os_snprintf(buf
, buflen
, "ACS");
4372 if (os_snprintf_error(buflen
, res
))
4376 #endif /* CONFIG_ACS */
4379 if (os_strcmp(field
, "fils") == 0) {
4380 #ifdef CONFIG_FILS_SK_PFS
4381 if (wpa_is_fils_supported(wpa_s
) &&
4382 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4383 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4384 if (os_snprintf_error(buflen
, res
))
4388 #endif /* CONFIG_FILS_SK_PFS */
4390 if (wpa_is_fils_supported(wpa_s
)) {
4391 res
= os_snprintf(buf
, buflen
, "FILS");
4392 if (os_snprintf_error(buflen
, res
))
4397 #endif /* CONFIG_FILS */
4399 if (os_strcmp(field
, "multibss") == 0 && wpa_s
->multi_bss_support
) {
4400 res
= os_snprintf(buf
, buflen
, "MULTIBSS-STA");
4401 if (os_snprintf_error(buflen
, res
))
4406 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4413 #ifdef CONFIG_INTERWORKING
4414 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4415 struct wpabuf
*data
)
4425 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4426 if (os_snprintf_error(end
- pos
, ret
))
4430 d
= wpabuf_head_u8(data
);
4431 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4432 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4433 if (os_snprintf_error(end
- pos
, ret
))
4438 ret
= os_snprintf(pos
, end
- pos
, "\n");
4439 if (os_snprintf_error(end
- pos
, ret
))
4445 #endif /* CONFIG_INTERWORKING */
4449 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4452 const u8
*ie
, *ie_end
;
4456 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4459 ie_end
= ie
+ 2 + ie
[1];
4461 if (ie_end
- ie
< 2)
4464 info
= WPA_GET_LE16(ie
);
4466 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4467 if (os_snprintf_error(end
- pos
, ret
))
4471 if (info
& BIT(7)) {
4472 /* Cache Identifier Included */
4473 if (ie_end
- ie
< 2)
4475 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4477 if (os_snprintf_error(end
- pos
, ret
))
4483 if (info
& BIT(8)) {
4484 /* HESSID Included */
4485 if (ie_end
- ie
< ETH_ALEN
)
4487 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4489 if (os_snprintf_error(end
- pos
, ret
))
4495 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4497 if (ie_end
- ie
< realms
* 2)
4499 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4500 if (os_snprintf_error(end
- pos
, ret
))
4504 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4509 ret
= os_snprintf(pos
, end
- pos
, "\n");
4510 if (os_snprintf_error(end
- pos
, ret
))
4517 #endif /* CONFIG_FILS */
4520 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4521 unsigned long mask
, char *buf
, size_t buflen
)
4526 const u8
*ie
, *ie2
, *osen_ie
, *mesh
, *owe
;
4531 if (mask
& WPA_BSS_MASK_ID
) {
4532 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4533 if (os_snprintf_error(end
- pos
, ret
))
4538 if (mask
& WPA_BSS_MASK_BSSID
) {
4539 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4540 MAC2STR(bss
->bssid
));
4541 if (os_snprintf_error(end
- pos
, ret
))
4546 if (mask
& WPA_BSS_MASK_FREQ
) {
4547 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4548 if (os_snprintf_error(end
- pos
, ret
))
4553 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4554 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4556 if (os_snprintf_error(end
- pos
, ret
))
4561 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4562 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4564 if (os_snprintf_error(end
- pos
, ret
))
4569 if (mask
& WPA_BSS_MASK_QUAL
) {
4570 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4571 if (os_snprintf_error(end
- pos
, ret
))
4576 if (mask
& WPA_BSS_MASK_NOISE
) {
4577 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4578 if (os_snprintf_error(end
- pos
, ret
))
4583 if (mask
& WPA_BSS_MASK_LEVEL
) {
4584 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4585 if (os_snprintf_error(end
- pos
, ret
))
4590 if (mask
& WPA_BSS_MASK_TSF
) {
4591 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4592 (unsigned long long) bss
->tsf
);
4593 if (os_snprintf_error(end
- pos
, ret
))
4598 if (mask
& WPA_BSS_MASK_AGE
) {
4599 struct os_reltime now
;
4601 os_get_reltime(&now
);
4602 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4603 (int) (now
.sec
- bss
->last_update
.sec
));
4604 if (os_snprintf_error(end
- pos
, ret
))
4609 if (mask
& WPA_BSS_MASK_IE
) {
4610 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4611 if (os_snprintf_error(end
- pos
, ret
))
4615 ie
= (const u8
*) (bss
+ 1);
4616 for (i
= 0; i
< bss
->ie_len
; i
++) {
4617 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4618 if (os_snprintf_error(end
- pos
, ret
))
4623 ret
= os_snprintf(pos
, end
- pos
, "\n");
4624 if (os_snprintf_error(end
- pos
, ret
))
4629 if (mask
& WPA_BSS_MASK_FLAGS
) {
4630 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4631 if (os_snprintf_error(end
- pos
, ret
))
4635 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4637 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4639 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4641 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4643 pos
= wpa_supplicant_ie_txt(pos
, end
,
4644 mesh
? "RSN" : "WPA2", ie2
,
4646 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4648 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4649 osen_ie
, 2 + osen_ie
[1]);
4650 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
4654 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4655 if (os_snprintf_error(end
- pos
, ret
))
4659 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4660 if (!ie
&& !ie2
&& !osen_ie
&&
4661 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4662 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4663 if (os_snprintf_error(end
- pos
, ret
))
4669 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4670 if (os_snprintf_error(end
- pos
, ret
))
4675 if (bss_is_dmg(bss
)) {
4677 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4678 if (os_snprintf_error(end
- pos
, ret
))
4681 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4682 case IEEE80211_CAP_DMG_IBSS
:
4685 case IEEE80211_CAP_DMG_AP
:
4688 case IEEE80211_CAP_DMG_PBSS
:
4695 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4696 if (os_snprintf_error(end
- pos
, ret
))
4700 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4701 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4702 if (os_snprintf_error(end
- pos
, ret
))
4706 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4707 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4708 if (os_snprintf_error(end
- pos
, ret
))
4713 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4714 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4715 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4716 if (os_snprintf_error(end
- pos
, ret
))
4721 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4722 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4723 if (os_snprintf_error(end
- pos
, ret
))
4727 #endif /* CONFIG_HS20 */
4729 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4730 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4731 if (os_snprintf_error(end
- pos
, ret
))
4735 #endif /* CONFIG_FILS */
4737 ret
= os_snprintf(pos
, end
- pos
, "\n");
4738 if (os_snprintf_error(end
- pos
, ret
))
4743 if (mask
& WPA_BSS_MASK_SSID
) {
4744 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4745 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4746 if (os_snprintf_error(end
- pos
, ret
))
4752 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4753 ie
= (const u8
*) (bss
+ 1);
4754 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4755 if (ret
>= end
- pos
)
4760 #endif /* CONFIG_WPS */
4763 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4764 ie
= (const u8
*) (bss
+ 1);
4765 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4766 if (ret
>= end
- pos
)
4771 #endif /* CONFIG_P2P */
4773 #ifdef CONFIG_WIFI_DISPLAY
4774 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4776 ie
= (const u8
*) (bss
+ 1);
4777 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4778 WFD_IE_VENDOR_TYPE
);
4780 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4781 if (os_snprintf_error(end
- pos
, ret
)) {
4787 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4792 ret
= os_snprintf(pos
, end
- pos
, "\n");
4793 if (os_snprintf_error(end
- pos
, ret
))
4798 #endif /* CONFIG_WIFI_DISPLAY */
4800 #ifdef CONFIG_INTERWORKING
4801 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4802 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4803 struct wpa_bss_anqp_elem
*elem
;
4805 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4806 anqp
->capability_list
);
4807 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4809 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4810 anqp
->network_auth_type
);
4811 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4812 anqp
->roaming_consortium
);
4813 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4814 anqp
->ip_addr_type_availability
);
4815 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4817 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4818 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4820 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4821 anqp
->fils_realm_info
);
4823 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4824 anqp
->hs20_capability_list
);
4825 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4826 anqp
->hs20_operator_friendly_name
);
4827 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4828 anqp
->hs20_wan_metrics
);
4829 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4830 anqp
->hs20_connection_capability
);
4831 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4832 anqp
->hs20_operating_class
);
4833 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4834 anqp
->hs20_osu_providers_list
);
4835 pos
= anqp_add_hex(pos
, end
, "hs20_operator_icon_metadata",
4836 anqp
->hs20_operator_icon_metadata
);
4837 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_nai_list",
4838 anqp
->hs20_osu_providers_nai_list
);
4839 #endif /* CONFIG_HS20 */
4841 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4842 struct wpa_bss_anqp_elem
, list
) {
4845 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4847 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4850 #endif /* CONFIG_INTERWORKING */
4853 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4854 ie
= (const u8
*) (bss
+ 1);
4855 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4856 if (ret
>= end
- pos
)
4861 #endif /* CONFIG_MESH */
4863 if (mask
& WPA_BSS_MASK_SNR
) {
4864 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4865 if (os_snprintf_error(end
- pos
, ret
))
4870 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4871 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4872 bss
->est_throughput
);
4873 if (os_snprintf_error(end
- pos
, ret
))
4879 if (mask
& WPA_BSS_MASK_FST
) {
4880 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4881 if (ret
< 0 || ret
>= end
- pos
)
4885 #endif /* CONFIG_FST */
4887 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4888 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4889 bss
->last_update_idx
);
4890 if (os_snprintf_error(end
- pos
, ret
))
4895 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4896 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4897 if (os_snprintf_error(end
- pos
, ret
))
4901 ie
= (const u8
*) (bss
+ 1);
4903 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4904 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4905 if (os_snprintf_error(end
- pos
, ret
))
4910 ret
= os_snprintf(pos
, end
- pos
, "\n");
4911 if (os_snprintf_error(end
- pos
, ret
))
4917 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4918 ret
= print_fils_indication(bss
, pos
, end
);
4923 #endif /* CONFIG_FILS */
4925 if (mask
& WPA_BSS_MASK_DELIM
) {
4926 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4927 if (os_snprintf_error(end
- pos
, ret
))
4936 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4937 const char *cmd
, char *buf
,
4942 struct wpa_bss
*bss
;
4943 struct wpa_bss
*bsslast
= NULL
;
4944 struct dl_list
*next
;
4947 char *ctmp
, *end
= buf
+ buflen
;
4948 unsigned long mask
= WPA_BSS_MASK_ALL
;
4950 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4951 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4952 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4954 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4956 } else { /* N1-N2 */
4957 unsigned int id1
, id2
;
4959 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4960 wpa_printf(MSG_INFO
, "Wrong BSS range "
4965 if (*(cmd
+ 6) == '-')
4968 id1
= atoi(cmd
+ 6);
4970 if (*ctmp
>= '0' && *ctmp
<= '9')
4973 id2
= (unsigned int) -1;
4974 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4975 if (id2
== (unsigned int) -1)
4976 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4980 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4981 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4982 struct wpa_bss
*tmp
= bss
;
4984 next
= tmp
->list_id
.next
;
4985 if (next
== &wpa_s
->bss_id
)
4987 tmp
= dl_list_entry(
4988 next
, struct wpa_bss
,
4997 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4998 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4999 else if (os_strncmp(cmd
, "LAST", 4) == 0)
5000 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
5001 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
5003 bss
= wpa_bss_get_id(wpa_s
, i
);
5004 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
5006 bss
= wpa_bss_get_id(wpa_s
, i
);
5008 next
= bss
->list_id
.next
;
5009 if (next
== &wpa_s
->bss_id
)
5012 bss
= dl_list_entry(next
, struct wpa_bss
,
5015 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
5016 bss
= wpa_s
->current_bss
;
5018 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
5019 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
5020 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
5023 #endif /* CONFIG_P2P */
5024 } else if (hwaddr_aton(cmd
, bssid
) == 0)
5025 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5027 struct wpa_bss
*tmp
;
5030 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
5039 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
5040 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
5042 mask
= WPA_BSS_MASK_ALL
;
5048 if (bsslast
== NULL
)
5051 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
5055 if (bss
== bsslast
) {
5056 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
5057 (bss
== dl_list_last(&wpa_s
->bss_id
,
5058 struct wpa_bss
, list_id
))) {
5061 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
5063 if (os_snprintf_error(end
- buf
+ 5, res
)) {
5064 wpa_printf(MSG_DEBUG
,
5065 "Could not add end delim");
5070 next
= bss
->list_id
.next
;
5071 if (next
== &wpa_s
->bss_id
)
5073 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
5074 } while (bss
&& len
);
5080 static int wpa_supplicant_ctrl_iface_ap_scan(
5081 struct wpa_supplicant
*wpa_s
, char *cmd
)
5083 int ap_scan
= atoi(cmd
);
5084 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5088 static int wpa_supplicant_ctrl_iface_scan_interval(
5089 struct wpa_supplicant
*wpa_s
, char *cmd
)
5091 int scan_int
= atoi(cmd
);
5092 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5096 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5097 struct wpa_supplicant
*wpa_s
, char *cmd
)
5099 int expire_age
= atoi(cmd
);
5100 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5104 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5105 struct wpa_supplicant
*wpa_s
, char *cmd
)
5107 int expire_count
= atoi(cmd
);
5108 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5112 static void wpa_supplicant_ctrl_iface_bss_flush(
5113 struct wpa_supplicant
*wpa_s
, char *cmd
)
5115 int flush_age
= atoi(cmd
);
5118 wpa_bss_flush(wpa_s
);
5120 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5124 #ifdef CONFIG_TESTING_OPTIONS
5125 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5127 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5128 /* MLME-DELETEKEYS.request */
5129 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
5130 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
5131 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
5132 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
5133 #ifdef CONFIG_IEEE80211W
5134 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
5135 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
5136 #endif /* CONFIG_IEEE80211W */
5138 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5140 /* MLME-SETPROTECTION.request(None) */
5141 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5142 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5143 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5144 wpa_sm_drop_sa(wpa_s
->wpa
);
5146 #endif /* CONFIG_TESTING_OPTIONS */
5149 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5152 #ifdef CONFIG_NO_SCAN_PROCESSING
5154 #else /* CONFIG_NO_SCAN_PROCESSING */
5156 struct wpa_bss
*bss
;
5157 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5159 if (hwaddr_aton(addr
, bssid
)) {
5160 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5161 "address '%s'", addr
);
5165 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5168 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5169 "configuration known for the target AP");
5173 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5175 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5181 * TODO: Find best network configuration block from configuration to
5182 * allow roaming to other networks
5185 wpa_s
->reassociate
= 1;
5186 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5189 #endif /* CONFIG_NO_SCAN_PROCESSING */
5194 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5196 unsigned int timeout
= atoi(cmd
);
5197 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5198 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5199 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5201 unsigned int search_delay
;
5202 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5206 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5207 wpa_dbg(wpa_s
, MSG_INFO
,
5208 "Reject P2P_FIND since interface is disabled");
5211 if (os_strstr(cmd
, "type=social"))
5212 type
= P2P_FIND_ONLY_SOCIAL
;
5213 else if (os_strstr(cmd
, "type=progressive"))
5214 type
= P2P_FIND_PROGRESSIVE
;
5216 pos
= os_strstr(cmd
, "dev_id=");
5219 if (hwaddr_aton(pos
, dev_id
))
5224 pos
= os_strstr(cmd
, "dev_type=");
5227 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5229 _dev_type
= dev_type
;
5232 pos
= os_strstr(cmd
, "delay=");
5235 search_delay
= atoi(pos
);
5237 search_delay
= wpas_p2p_search_delay(wpa_s
);
5239 pos
= os_strstr(cmd
, "freq=");
5247 /* Must be searched for last, because it adds nul termination */
5248 pos
= os_strstr(cmd
, " seek=");
5251 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5254 _seek
[seek_count
++] = pos
;
5256 term
= os_strchr(pos
, ' ');
5260 pos
= os_strstr(term
+ 1, "seek=");
5264 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5269 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5270 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5274 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5276 const char *last
= NULL
;
5281 /* Expected predefined CPT names delimited by ':' */
5282 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5283 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5284 wpa_printf(MSG_ERROR
,
5285 "P2PS: CPT name list is too long, expected up to %d names",
5286 P2PS_FEATURE_CAPAB_CPT_MAX
);
5291 token_len
= last
- token
;
5293 if (token_len
== 3 &&
5294 os_memcmp(token
, "UDP", token_len
) == 0) {
5295 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5296 } else if (token_len
== 3 &&
5297 os_memcmp(token
, "MAC", token_len
) == 0) {
5298 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5300 wpa_printf(MSG_ERROR
,
5301 "P2PS: Unsupported CPT name '%s'", token
);
5306 if (isblank((unsigned char) *last
)) {
5316 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5318 struct p2ps_provision
*p2ps_prov
;
5320 size_t info_len
= 0;
5322 u8 role
= P2PS_SETUP_NONE
;
5323 long long unsigned val
;
5326 pos
= os_strstr(cmd
, "info=");
5329 info_len
= os_strlen(pos
);
5332 info
= os_malloc(info_len
+ 1);
5334 info_len
= utf8_unescape(pos
, info_len
,
5335 info
, info_len
+ 1);
5341 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5342 if (p2ps_prov
== NULL
) {
5348 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5349 p2ps_prov
->info
[info_len
] = '\0';
5353 pos
= os_strstr(cmd
, "status=");
5355 p2ps_prov
->status
= atoi(pos
+ 7);
5357 p2ps_prov
->status
= -1;
5359 pos
= os_strstr(cmd
, "adv_id=");
5360 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5362 p2ps_prov
->adv_id
= val
;
5364 pos
= os_strstr(cmd
, "method=");
5366 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5368 p2ps_prov
->method
= 0;
5370 pos
= os_strstr(cmd
, "session=");
5371 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5373 p2ps_prov
->session_id
= val
;
5375 pos
= os_strstr(cmd
, "adv_mac=");
5376 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5379 pos
= os_strstr(cmd
, "session_mac=");
5380 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5383 pos
= os_strstr(cmd
, "cpt=");
5385 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5386 p2ps_prov
->cpt_priority
))
5389 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5392 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5393 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5395 /* force conncap with tstCap (no sanity checks) */
5396 pos
= os_strstr(cmd
, "tstCap=");
5398 role
= strtol(pos
+ 7, NULL
, 16);
5400 pos
= os_strstr(cmd
, "role=");
5402 role
= strtol(pos
+ 5, NULL
, 16);
5403 if (role
!= P2PS_SETUP_CLIENT
&&
5404 role
!= P2PS_SETUP_GROUP_OWNER
)
5405 role
= P2PS_SETUP_NONE
;
5408 p2ps_prov
->role
= role
;
5418 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5421 struct p2ps_provision
*p2ps_prov
;
5424 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5426 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5428 if (hwaddr_aton(cmd
, addr
))
5435 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5439 if (p2ps_prov
->status
< 0) {
5444 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5449 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5452 struct p2ps_provision
*p2ps_prov
;
5455 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5456 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5459 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5460 if (hwaddr_aton(cmd
, addr
))
5467 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5471 p2ps_prov
->pd_seeker
= 1;
5473 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5478 static int parse_freq(int chwidth
, int freq2
)
5483 return VHT_CHANWIDTH_80P80MHZ
;
5489 return VHT_CHANWIDTH_USE_HT
;
5491 return VHT_CHANWIDTH_80MHZ
;
5493 return VHT_CHANWIDTH_160MHZ
;
5495 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5502 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5503 char *buf
, size_t buflen
)
5508 enum p2p_wps_method wps_method
;
5511 int persistent_group
, persistent_id
= -1;
5518 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5519 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5520 size_t group_ssid_len
= 0;
5522 if (!wpa_s
->global
->p2p_init_wpa_s
)
5524 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5525 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5526 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5527 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5530 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5531 * [persistent|persistent=<network id>]
5532 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5533 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5535 if (hwaddr_aton(cmd
, addr
))
5543 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5544 pos2
= os_strstr(pos
, " persistent=");
5546 struct wpa_ssid
*ssid
;
5547 persistent_id
= atoi(pos2
+ 12);
5548 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5549 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5550 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5551 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5552 "SSID id=%d for persistent P2P group (GO)",
5557 join
= os_strstr(pos
, " join") != NULL
;
5558 auth
= os_strstr(pos
, " auth") != NULL
;
5559 automatic
= os_strstr(pos
, " auto") != NULL
;
5560 pd
= os_strstr(pos
, " provdisc") != NULL
;
5561 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5562 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5565 pos2
= os_strstr(pos
, " go_intent=");
5568 go_intent
= atoi(pos2
);
5569 if (go_intent
< 0 || go_intent
> 15)
5573 pos2
= os_strstr(pos
, " freq=");
5581 pos2
= os_strstr(pos
, " freq2=");
5583 freq2
= atoi(pos2
+ 7);
5585 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5587 chwidth
= atoi(pos2
+ 18);
5589 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5590 if (max_oper_chwidth
< 0)
5593 pos2
= os_strstr(pos
, " ssid=");
5598 end
= os_strchr(pos2
, ' ');
5600 group_ssid_len
= os_strlen(pos2
) / 2;
5602 group_ssid_len
= (end
- pos2
) / 2;
5603 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5604 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5606 group_ssid
= _group_ssid
;
5609 if (os_strncmp(pos
, "pin", 3) == 0) {
5610 /* Request random PIN (to be displayed) and enable the PIN */
5611 wps_method
= WPS_PIN_DISPLAY
;
5612 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5613 wps_method
= WPS_PBC
;
5614 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5615 wps_method
= WPS_P2PS
;
5618 pos
= os_strchr(pin
, ' ');
5619 wps_method
= WPS_PIN_KEYPAD
;
5622 if (os_strncmp(pos
, "display", 7) == 0)
5623 wps_method
= WPS_PIN_DISPLAY
;
5625 if (!wps_pin_str_valid(pin
)) {
5626 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5631 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5632 persistent_group
, automatic
, join
,
5633 auth
, go_intent
, freq
, freq2
, persistent_id
,
5634 pd
, ht40
, vht
, max_oper_chwidth
,
5635 group_ssid
, group_ssid_len
);
5636 if (new_pin
== -2) {
5637 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5640 if (new_pin
== -3) {
5641 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5646 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5647 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5648 if (os_snprintf_error(buflen
, ret
))
5653 os_memcpy(buf
, "OK\n", 3);
5658 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5660 unsigned int timeout
= atoi(cmd
);
5661 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5662 wpa_dbg(wpa_s
, MSG_INFO
,
5663 "Reject P2P_LISTEN since interface is disabled");
5666 return wpas_p2p_listen(wpa_s
, timeout
);
5670 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5674 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5676 /* <addr> <config method> [join|auto] */
5678 if (hwaddr_aton(cmd
, addr
))
5686 if (os_strstr(pos
, " join") != NULL
)
5687 use
= WPAS_P2P_PD_FOR_JOIN
;
5688 else if (os_strstr(pos
, " auto") != NULL
)
5689 use
= WPAS_P2P_PD_AUTO
;
5691 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5695 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5698 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5700 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5701 ssid
->passphrase
== NULL
)
5704 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5705 return os_strlen(buf
);
5709 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5710 char *buf
, size_t buflen
)
5714 u8 dst_buf
[ETH_ALEN
], *dst
;
5715 struct wpabuf
*tlvs
;
5719 if (hwaddr_aton(cmd
, dst_buf
))
5722 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5723 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5730 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5733 if (hexstr2bin(pos
, &version
, 1) < 0)
5739 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5740 #ifdef CONFIG_WIFI_DISPLAY
5741 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5742 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5743 #endif /* CONFIG_WIFI_DISPLAY */
5744 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5746 char *svc_info
= NULL
;
5750 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5753 pos
= os_strchr(pos
, ' ');
5754 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5759 pos
= os_strchr(svc_str
, ' ');
5764 /* All remaining data is the svc_info string */
5765 if (pos
&& pos
[0] && pos
[0] != ' ') {
5766 len
= os_strlen(pos
);
5768 /* Unescape in place */
5769 len
= utf8_unescape(pos
, len
, pos
, len
);
5776 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5779 len
= os_strlen(pos
);
5783 tlvs
= wpabuf_alloc(len
);
5786 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5791 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5796 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5797 if (os_snprintf_error(buflen
, res
))
5803 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5806 long long unsigned val
;
5808 if (sscanf(cmd
, "%llx", &val
) != 1)
5811 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5815 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5820 struct wpabuf
*resp_tlvs
;
5824 pos
= os_strchr(cmd
, ' ');
5832 if (hwaddr_aton(pos
, dst
))
5839 pos2
= os_strchr(pos
, ' ');
5843 dialog_token
= atoi(pos
);
5845 len
= os_strlen(pos2
);
5849 resp_tlvs
= wpabuf_alloc(len
);
5850 if (resp_tlvs
== NULL
)
5852 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5853 wpabuf_free(resp_tlvs
);
5857 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5858 wpabuf_free(resp_tlvs
);
5863 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5866 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5868 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5873 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5878 struct wpabuf
*query
, *resp
;
5880 pos
= os_strchr(cmd
, ' ');
5885 len
= os_strlen(cmd
);
5889 query
= wpabuf_alloc(len
);
5892 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5897 len
= os_strlen(pos
);
5903 resp
= wpabuf_alloc(len
);
5908 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5914 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5923 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5928 pos
= os_strchr(cmd
, ' ');
5933 if (hexstr2bin(cmd
, &version
, 1) < 0)
5936 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5940 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5941 u8 replace
, char *cmd
)
5945 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5946 char *svc_info
= NULL
;
5948 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5950 pos
= os_strchr(cmd
, ' ');
5955 /* Auto-Accept value is mandatory, and must be one of the
5956 * single values (0, 1, 2, 4) */
5957 auto_accept
= atoi(cmd
);
5958 switch (auto_accept
) {
5959 case P2PS_SETUP_NONE
: /* No auto-accept */
5960 case P2PS_SETUP_NEW
:
5961 case P2PS_SETUP_CLIENT
:
5962 case P2PS_SETUP_GROUP_OWNER
:
5968 /* Advertisement ID is mandatory */
5970 pos
= os_strchr(cmd
, ' ');
5975 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5976 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5979 /* Only allow replacements if exist, and adds if not */
5980 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5988 /* svc_state between 0 - 0xff is mandatory */
5989 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5992 pos
= os_strchr(pos
, ' ');
5996 /* config_methods is mandatory */
5998 if (sscanf(pos
, "%x", &config_methods
) != 1)
6001 if (!(config_methods
&
6002 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
6005 pos
= os_strchr(pos
, ' ');
6012 /* Advertisement string is mandatory */
6013 if (!pos
[0] || pos
[0] == ' ')
6016 /* Terminate svc string */
6017 pos
= os_strchr(pos
, ' ');
6021 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
6023 pos
= os_strchr(pos
, ' ');
6027 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
6030 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
6034 /* Service and Response Information are optional */
6035 if (pos
&& pos
[0]) {
6038 /* Note the bare ' included, which cannot exist legally
6039 * in unescaped string. */
6040 svc_info
= os_strstr(pos
, "svc_info='");
6044 len
= os_strlen(svc_info
);
6045 utf8_unescape(svc_info
, len
, svc_info
, len
);
6049 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
6050 (u8
) svc_state
, (u16
) config_methods
,
6051 svc_info
, cpt_prio
);
6055 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6059 pos
= os_strchr(cmd
, ' ');
6064 if (os_strcmp(cmd
, "bonjour") == 0)
6065 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
6066 if (os_strcmp(cmd
, "upnp") == 0)
6067 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
6068 if (os_strcmp(cmd
, "asp") == 0)
6069 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
6070 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6075 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
6079 struct wpabuf
*query
;
6082 len
= os_strlen(cmd
);
6086 query
= wpabuf_alloc(len
);
6089 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6094 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6100 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6105 pos
= os_strchr(cmd
, ' ');
6110 if (hexstr2bin(cmd
, &version
, 1) < 0)
6113 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6117 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6121 if (os_strcmp(cmd
, "all") == 0) {
6122 wpas_p2p_service_flush_asp(wpa_s
);
6126 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6129 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6133 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6137 pos
= os_strchr(cmd
, ' ');
6142 if (os_strcmp(cmd
, "bonjour") == 0)
6143 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6144 if (os_strcmp(cmd
, "upnp") == 0)
6145 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6146 if (os_strcmp(cmd
, "asp") == 0)
6147 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6148 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6153 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6157 pos
= os_strchr(cmd
, ' ');
6162 if (os_strcmp(cmd
, "asp") == 0)
6163 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6165 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6170 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6176 if (hwaddr_aton(cmd
, addr
))
6179 return wpas_p2p_reject(wpa_s
, addr
);
6183 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6187 struct wpa_ssid
*ssid
;
6188 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6189 int freq
= 0, pref_freq
= 0;
6190 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6193 pos
= os_strstr(cmd
, " peer=");
6196 if (hwaddr_aton(pos
, peer
))
6200 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6201 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6202 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6203 "for persistent P2P group",
6208 pos
= os_strstr(cmd
, " freq=");
6216 pos
= os_strstr(cmd
, " pref=");
6219 pref_freq
= atoi(pos
);
6224 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6225 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6228 pos
= os_strstr(cmd
, "freq2=");
6230 freq2
= atoi(pos
+ 6);
6232 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6234 chwidth
= atoi(pos
+ 18);
6236 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6237 if (max_oper_chwidth
< 0)
6240 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6241 max_oper_chwidth
, pref_freq
);
6245 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6248 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6250 pos
= os_strstr(cmd
, " peer=");
6256 if (hwaddr_aton(pos
, peer
)) {
6257 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6261 pos
= os_strstr(pos
, " go_dev_addr=");
6264 if (hwaddr_aton(pos
, go_dev_addr
)) {
6265 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6269 go_dev
= go_dev_addr
;
6272 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6276 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6278 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6279 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6280 if (os_strncmp(cmd
, "group=", 6) == 0)
6281 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6287 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6288 int id
, int freq
, int vht_center_freq2
,
6289 int ht40
, int vht
, int vht_chwidth
)
6291 struct wpa_ssid
*ssid
;
6293 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6294 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6295 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6296 "for persistent P2P group",
6301 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6302 vht_center_freq2
, 0, ht40
, vht
,
6303 vht_chwidth
, NULL
, 0, 0);
6307 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6309 int freq
= 0, persistent
= 0, group_id
= -1;
6310 int vht
= wpa_s
->conf
->p2p_go_vht
;
6311 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6312 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6313 char *token
, *context
= NULL
;
6316 #endif /* CONFIG_ACS */
6318 while ((token
= str_token(cmd
, " ", &context
))) {
6319 if (sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6320 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6321 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6324 } else if (os_strcmp(token
, "freq=acs") == 0) {
6326 #endif /* CONFIG_ACS */
6327 } else if (sscanf(token
, "freq=%d", &freq
) == 1) {
6329 } else if (os_strcmp(token
, "ht40") == 0) {
6331 } else if (os_strcmp(token
, "vht") == 0) {
6334 } else if (os_strcmp(token
, "persistent") == 0) {
6337 wpa_printf(MSG_DEBUG
,
6338 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6345 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_ACS_OFFLOAD
) &&
6346 (acs
|| freq
== 2 || freq
== 5)) {
6347 if (freq
== 2 && wpa_s
->best_24_freq
<= 0) {
6348 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211G
;
6349 wpa_s
->p2p_go_do_acs
= 1;
6351 } else if (freq
== 5 && wpa_s
->best_5_freq
<= 0) {
6352 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211A
;
6353 wpa_s
->p2p_go_do_acs
= 1;
6356 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211ANY
;
6357 wpa_s
->p2p_go_do_acs
= 1;
6360 #endif /* CONFIG_ACS */
6362 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6363 if (max_oper_chwidth
< 0)
6367 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6368 freq
, freq2
, ht40
, vht
,
6371 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6376 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6377 char *buf
, size_t buflen
)
6379 u8 dev_addr
[ETH_ALEN
];
6380 struct wpa_ssid
*ssid
;
6384 ssid
= wpa_s
->current_ssid
;
6385 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6386 hwaddr_aton(cmd
, dev_addr
))
6389 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6392 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6393 if (os_snprintf_error(buflen
, res
))
6399 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6400 const u8
*p2p_dev_addr
)
6402 struct wpa_supplicant
*wpa_s
;
6404 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6405 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6413 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6414 char *buf
, size_t buflen
)
6416 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6418 const struct p2p_peer_info
*info
;
6420 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6421 struct wpa_ssid
*ssid
;
6424 if (!wpa_s
->global
->p2p
)
6427 if (os_strcmp(cmd
, "FIRST") == 0) {
6430 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6431 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6436 if (hwaddr_aton(cmd
, addr
) < 0)
6442 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6445 group_capab
= info
->group_capab
;
6448 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6449 wpa_printf(MSG_DEBUG
,
6450 "P2P: Could not find any BSS with p2p_dev_addr "
6451 MACSTR
", hence override group_capab from 0x%x to 0",
6452 MAC2STR(info
->p2p_device_addr
), group_capab
);
6459 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6465 "serial_number=%s\n"
6466 "config_methods=0x%x\n"
6468 "group_capab=0x%x\n"
6470 MAC2STR(info
->p2p_device_addr
),
6471 wps_dev_type_bin2str(info
->pri_dev_type
,
6472 devtype
, sizeof(devtype
)),
6477 info
->serial_number
,
6478 info
->config_methods
,
6482 if (os_snprintf_error(end
- pos
, res
))
6486 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6489 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6490 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6491 wps_dev_type_bin2str(t
, devtype
,
6493 if (os_snprintf_error(end
- pos
, res
))
6498 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6500 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6501 if (os_snprintf_error(end
- pos
, res
))
6506 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6511 if (info
->vendor_elems
) {
6512 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6513 if (os_snprintf_error(end
- pos
, res
))
6517 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6518 wpabuf_head(info
->vendor_elems
),
6519 wpabuf_len(info
->vendor_elems
));
6521 res
= os_snprintf(pos
, end
- pos
, "\n");
6522 if (os_snprintf_error(end
- pos
, res
))
6531 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6536 if (wpa_s
->global
->p2p
== NULL
)
6539 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6542 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6543 struct wpa_freq_range
*freq
;
6544 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6545 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6546 freq
->min
, freq
->max
);
6549 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6554 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6558 if (wpa_s
->global
->p2p
== NULL
)
6561 param
= os_strchr(cmd
, ' ');
6566 if (os_strcmp(cmd
, "discoverability") == 0) {
6567 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6572 if (os_strcmp(cmd
, "managed") == 0) {
6573 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6577 if (os_strcmp(cmd
, "listen_channel") == 0) {
6579 u8 channel
, op_class
;
6581 channel
= atoi(param
);
6582 pos
= os_strchr(param
, ' ');
6583 op_class
= pos
? atoi(pos
) : 81;
6585 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6589 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6590 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6594 if (os_strcmp(cmd
, "noa") == 0) {
6596 int count
, start
, duration
;
6597 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6598 count
= atoi(param
);
6599 pos
= os_strchr(param
, ',');
6604 pos
= os_strchr(pos
, ',');
6608 duration
= atoi(pos
);
6609 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6611 if (count
== 0 && duration
> 0)
6613 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6614 "start=%d duration=%d", count
, start
, duration
);
6615 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6618 if (os_strcmp(cmd
, "ps") == 0)
6619 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6621 if (os_strcmp(cmd
, "oppps") == 0)
6622 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6624 if (os_strcmp(cmd
, "ctwindow") == 0)
6625 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6627 if (os_strcmp(cmd
, "disabled") == 0) {
6628 wpa_s
->global
->p2p_disabled
= atoi(param
);
6629 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6630 wpa_s
->global
->p2p_disabled
?
6631 "disabled" : "enabled");
6632 if (wpa_s
->global
->p2p_disabled
) {
6633 wpas_p2p_stop_find(wpa_s
);
6634 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6635 p2p_flush(wpa_s
->global
->p2p
);
6640 if (os_strcmp(cmd
, "conc_pref") == 0) {
6641 if (os_strcmp(param
, "sta") == 0)
6642 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6643 else if (os_strcmp(param
, "p2p") == 0)
6644 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6646 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6649 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6654 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6655 wpa_s
->force_long_sd
= atoi(param
);
6659 if (os_strcmp(cmd
, "peer_filter") == 0) {
6661 if (hwaddr_aton(param
, addr
))
6663 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6667 if (os_strcmp(cmd
, "cross_connect") == 0)
6668 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6670 if (os_strcmp(cmd
, "go_apsd") == 0) {
6671 if (os_strcmp(param
, "disable") == 0)
6672 wpa_s
->set_ap_uapsd
= 0;
6674 wpa_s
->set_ap_uapsd
= 1;
6675 wpa_s
->ap_uapsd
= atoi(param
);
6680 if (os_strcmp(cmd
, "client_apsd") == 0) {
6681 if (os_strcmp(param
, "disable") == 0)
6682 wpa_s
->set_sta_uapsd
= 0;
6686 /* format: BE,BK,VI,VO;max SP Length */
6688 pos
= os_strchr(param
, ',');
6693 pos
= os_strchr(pos
, ',');
6698 pos
= os_strchr(pos
, ',');
6703 /* ignore max SP Length for now */
6705 wpa_s
->set_sta_uapsd
= 1;
6706 wpa_s
->sta_uapsd
= 0;
6708 wpa_s
->sta_uapsd
|= BIT(0);
6710 wpa_s
->sta_uapsd
|= BIT(1);
6712 wpa_s
->sta_uapsd
|= BIT(2);
6714 wpa_s
->sta_uapsd
|= BIT(3);
6719 if (os_strcmp(cmd
, "disallow_freq") == 0)
6720 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6722 if (os_strcmp(cmd
, "disc_int") == 0) {
6723 int min_disc_int
, max_disc_int
, max_disc_tu
;
6728 min_disc_int
= atoi(pos
);
6729 pos
= os_strchr(pos
, ' ');
6734 max_disc_int
= atoi(pos
);
6735 pos
= os_strchr(pos
, ' ');
6740 max_disc_tu
= atoi(pos
);
6742 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6743 max_disc_int
, max_disc_tu
);
6746 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6747 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6751 #ifdef CONFIG_WPS_NFC
6752 if (os_strcmp(cmd
, "nfc_tag") == 0)
6753 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6754 #endif /* CONFIG_WPS_NFC */
6756 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6757 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6761 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6764 op_class
= atoi(param
);
6765 param
= os_strchr(param
, ':');
6770 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6775 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6782 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6784 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6785 wpa_s
->force_long_sd
= 0;
6787 #ifdef CONFIG_TESTING_OPTIONS
6788 os_free(wpa_s
->get_pref_freq_list_override
);
6789 wpa_s
->get_pref_freq_list_override
= NULL
;
6790 #endif /* CONFIG_TESTING_OPTIONS */
6792 wpas_p2p_stop_find(wpa_s
);
6793 wpa_s
->parent
->p2ps_method_config_any
= 0;
6794 if (wpa_s
->global
->p2p
)
6795 p2p_flush(wpa_s
->global
->p2p
);
6799 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6802 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6805 pos
= os_strchr(cmd
, ' ');
6811 pos2
= os_strchr(pos
, ' ');
6819 pos
= os_strchr(pos2
, ' ');
6827 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6831 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6834 unsigned int period
= 0, interval
= 0;
6837 pos
= os_strchr(cmd
, ' ');
6842 interval
= atoi(pos
);
6845 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6849 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6856 if (os_strncmp(pos
, "iface=", 6) == 0) {
6860 if (hwaddr_aton(pos
, peer
))
6863 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6868 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6870 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6872 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6874 wpa_printf(MSG_DEBUG
,
6875 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6879 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6882 #endif /* CONFIG_P2P */
6885 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6887 struct wpa_freq_range_list ranges
;
6889 struct hostapd_hw_modes
*mode
;
6892 if (wpa_s
->hw
.modes
== NULL
)
6895 os_memset(&ranges
, 0, sizeof(ranges
));
6896 if (freq_range_list_parse(&ranges
, val
) < 0)
6899 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6902 mode
= &wpa_s
->hw
.modes
[i
];
6903 for (j
= 0; j
< mode
->num_channels
; j
++) {
6906 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6909 freq
= mode
->channels
[j
].freq
;
6910 if (!freq_range_list_includes(&ranges
, freq
))
6913 int_array_add_unique(&freqs
, freq
);
6917 os_free(ranges
.range
);
6922 #ifdef CONFIG_INTERWORKING
6924 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6932 auto_sel
= os_strstr(param
, "auto") != NULL
;
6934 pos
= os_strstr(param
, "freq=");
6936 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6943 return interworking_select(wpa_s
, auto_sel
, freqs
);
6947 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6951 struct wpa_bss
*bss
;
6953 if (hwaddr_aton(dst
, bssid
)) {
6954 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6958 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6960 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6965 if (bss
->ssid_len
== 0) {
6968 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6969 " does not have SSID information", MAC2STR(bssid
));
6971 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6973 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6974 bss
->ssid_len
> 0) {
6982 wpa_printf(MSG_DEBUG
,
6983 "Found another matching BSS entry with SSID");
6986 return interworking_connect(wpa_s
, bss
, only_add
);
6990 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6992 u8 dst_addr
[ETH_ALEN
];
6995 #define MAX_ANQP_INFO_ID 100
6996 u16 id
[MAX_ANQP_INFO_ID
];
6999 u32 mbo_subtypes
= 0;
7001 used
= hwaddr_aton2(dst
, dst_addr
);
7007 while (num_id
< MAX_ANQP_INFO_ID
) {
7008 if (os_strncmp(pos
, "hs20:", 5) == 0) {
7010 int num
= atoi(pos
+ 5);
7011 if (num
<= 0 || num
> 31)
7013 subtypes
|= BIT(num
);
7014 #else /* CONFIG_HS20 */
7016 #endif /* CONFIG_HS20 */
7017 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
7019 int num
= atoi(pos
+ 4);
7021 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
7023 mbo_subtypes
|= BIT(num
);
7024 #else /* CONFIG_MBO */
7026 #endif /* CONFIG_MBO */
7028 id
[num_id
] = atoi(pos
);
7032 pos
= os_strchr(pos
+ 1, ',');
7038 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
7041 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
7046 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
7048 u8 dst_addr
[ETH_ALEN
];
7049 struct wpabuf
*advproto
, *query
= NULL
;
7054 used
= hwaddr_aton2(cmd
, dst_addr
);
7062 /* Advertisement Protocol ID */
7063 end
= os_strchr(pos
, ' ');
7067 len
= os_strlen(pos
);
7073 advproto
= wpabuf_alloc(len
);
7074 if (advproto
== NULL
)
7076 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
7080 /* Optional Query Request */
7085 len
= os_strlen(pos
);
7092 query
= wpabuf_alloc(len
);
7095 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
7100 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
7103 wpabuf_free(advproto
);
7110 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7117 size_t resp_len
, start
, requested_len
;
7118 struct wpabuf
*resp
;
7121 used
= hwaddr_aton2(cmd
, addr
);
7128 dialog_token
= atoi(pos
);
7130 if (wpa_s
->last_gas_resp
&&
7131 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7132 dialog_token
== wpa_s
->last_gas_dialog_token
)
7133 resp
= wpa_s
->last_gas_resp
;
7134 else if (wpa_s
->prev_gas_resp
&&
7135 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7136 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7137 resp
= wpa_s
->prev_gas_resp
;
7141 resp_len
= wpabuf_len(resp
);
7143 requested_len
= resp_len
;
7145 pos
= os_strchr(pos
, ' ');
7148 if (start
> resp_len
)
7149 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7150 pos
= os_strchr(pos
, ',');
7154 requested_len
= atoi(pos
);
7155 if (start
+ requested_len
> resp_len
)
7156 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7159 if (requested_len
* 2 + 1 > buflen
)
7160 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7162 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7165 if (start
+ requested_len
== resp_len
) {
7167 * Free memory by dropping the response after it has been
7170 if (resp
== wpa_s
->prev_gas_resp
) {
7171 wpabuf_free(wpa_s
->prev_gas_resp
);
7172 wpa_s
->prev_gas_resp
= NULL
;
7174 wpabuf_free(wpa_s
->last_gas_resp
);
7175 wpa_s
->last_gas_resp
= NULL
;
7181 #endif /* CONFIG_INTERWORKING */
7186 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7188 u8 dst_addr
[ETH_ALEN
];
7193 used
= hwaddr_aton2(dst
, dst_addr
);
7200 int num
= atoi(pos
);
7201 if (num
<= 0 || num
> 31)
7203 subtypes
|= BIT(num
);
7204 pos
= os_strchr(pos
+ 1, ',');
7213 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7217 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7218 const u8
*addr
, const char *realm
)
7224 rlen
= os_strlen(realm
);
7226 buf
= os_malloc(len
);
7229 buf
[0] = 1; /* NAI Home Realm Count */
7230 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7232 os_memcpy(buf
+ 3, realm
, rlen
);
7234 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7235 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7244 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7247 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7248 u8 dst_addr
[ETH_ALEN
];
7254 used
= hwaddr_aton2(dst
, dst_addr
);
7258 while (dst
[used
] == ' ')
7260 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7261 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7264 len
= os_strlen(dst
+ used
);
7266 if (len
== 0 && cred
&& cred
->realm
)
7267 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7272 buf
= os_malloc(len
);
7275 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7280 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7281 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7289 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7292 u8 dst_addr
[ETH_ALEN
];
7294 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7296 used
= hwaddr_aton2(cmd
, dst_addr
);
7301 icon
= str_token(cmd
, " ", &ctx
);
7302 poffset
= str_token(cmd
, " ", &ctx
);
7303 psize
= str_token(cmd
, " ", &ctx
);
7304 if (!icon
|| !poffset
|| !psize
)
7307 wpa_s
->fetch_osu_icon_in_progress
= 0;
7308 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7313 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7315 u8 dst_addr
[ETH_ALEN
];
7320 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7322 used
= hwaddr_aton2(cmd
, dst_addr
);
7326 while (cmd
[used
] == ' ')
7328 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7330 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7334 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7336 u8 dst_addr
[ETH_ALEN
];
7340 used
= hwaddr_aton2(cmd
, dst_addr
);
7344 while (cmd
[used
] == ' ')
7348 wpa_s
->fetch_osu_icon_in_progress
= 0;
7349 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7350 (u8
*) icon
, os_strlen(icon
), inmem
);
7353 #endif /* CONFIG_HS20 */
7356 #ifdef CONFIG_AUTOSCAN
7358 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7361 enum wpa_states state
= wpa_s
->wpa_state
;
7362 char *new_params
= NULL
;
7364 if (os_strlen(cmd
) > 0) {
7365 new_params
= os_strdup(cmd
);
7366 if (new_params
== NULL
)
7370 os_free(wpa_s
->conf
->autoscan
);
7371 wpa_s
->conf
->autoscan
= new_params
;
7373 if (wpa_s
->conf
->autoscan
== NULL
)
7374 autoscan_deinit(wpa_s
);
7375 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7376 autoscan_init(wpa_s
, 1);
7377 else if (state
== WPA_SCANNING
)
7378 wpa_supplicant_reinit_autoscan(wpa_s
);
7380 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7381 wpa_supplicant_state_txt(state
));
7386 #endif /* CONFIG_AUTOSCAN */
7391 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7397 struct wpabuf
*tfs_req
= NULL
;
7399 if (os_strncmp(cmd
, "enter", 5) == 0)
7401 else if (os_strncmp(cmd
, "exit", 4) == 0)
7406 pos
= os_strstr(cmd
, " interval=");
7408 intval
= atoi(pos
+ 10);
7410 pos
= os_strstr(cmd
, " tfs_req=");
7415 end
= os_strchr(pos
, ' ');
7419 len
= os_strlen(pos
);
7423 tfs_req
= wpabuf_alloc(len
);
7424 if (tfs_req
== NULL
)
7426 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7427 wpabuf_free(tfs_req
);
7432 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7433 WNM_SLEEP_MODE_EXIT
, intval
,
7435 wpabuf_free(tfs_req
);
7441 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7443 int query_reason
, list
= 0;
7444 char *btm_candidates
= NULL
;
7446 query_reason
= atoi(cmd
);
7448 cmd
= os_strchr(cmd
, ' ');
7450 if (os_strncmp(cmd
, " list", 5) == 0)
7453 btm_candidates
= cmd
;
7456 wpa_printf(MSG_DEBUG
,
7457 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7458 query_reason
, list
? " candidate list" : "");
7460 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7466 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant
*wpa_s
,
7469 struct wpabuf
*elems
;
7472 elems
= wpabuf_parse_bin(cmd
);
7476 ret
= wnm_send_coloc_intf_report(wpa_s
, 0, elems
);
7481 #endif /* CONFIG_WNM */
7484 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7487 struct wpa_signal_info si
;
7491 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7498 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7499 "NOISE=%d\nFREQUENCY=%u\n",
7500 si
.current_signal
, si
.current_txrate
/ 1000,
7501 si
.current_noise
, si
.frequency
);
7502 if (os_snprintf_error(end
- pos
, ret
))
7506 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7507 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7508 channel_width_to_string(si
.chanwidth
));
7509 if (os_snprintf_error(end
- pos
, ret
))
7514 if (si
.center_frq1
> 0) {
7515 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ1=%d\n",
7517 if (os_snprintf_error(end
- pos
, ret
))
7522 if (si
.center_frq2
> 0) {
7523 ret
= os_snprintf(pos
, end
- pos
, "CENTER_FRQ2=%d\n",
7525 if (os_snprintf_error(end
- pos
, ret
))
7530 if (si
.avg_signal
) {
7531 ret
= os_snprintf(pos
, end
- pos
,
7532 "AVG_RSSI=%d\n", si
.avg_signal
);
7533 if (os_snprintf_error(end
- pos
, ret
))
7538 if (si
.avg_beacon_signal
) {
7539 ret
= os_snprintf(pos
, end
- pos
,
7540 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7541 if (os_snprintf_error(end
- pos
, ret
))
7550 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7557 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7558 wpa_printf(MSG_DEBUG
,
7559 "Reject SIGNAL_MONITOR command - bgscan is active");
7562 pos
= os_strstr(cmd
, "THRESHOLD=");
7564 threshold
= atoi(pos
+ 10);
7565 pos
= os_strstr(cmd
, "HYSTERESIS=");
7567 hysteresis
= atoi(pos
+ 11);
7568 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7572 #ifdef CONFIG_TESTING_OPTIONS
7573 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7574 enum wpa_driver_if_type if_type
,
7576 unsigned int *freq_list
)
7578 char *pos
= wpa_s
->get_pref_freq_list_override
;
7580 unsigned int count
= 0;
7582 /* Override string format:
7583 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7586 if (atoi(pos
) == (int) if_type
)
7588 pos
= os_strchr(pos
, ' ');
7594 pos
= os_strchr(pos
, ':');
7598 end
= os_strchr(pos
, ' ');
7599 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7600 freq_list
[count
++] = atoi(pos
);
7601 pos
= os_strchr(pos
, ',');
7609 #endif /* CONFIG_TESTING_OPTIONS */
7612 static int wpas_ctrl_iface_get_pref_freq_list(
7613 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7615 unsigned int freq_list
[100], num
= 100, i
;
7617 enum wpa_driver_if_type iface_type
;
7623 /* buf: "<interface_type>" */
7624 if (os_strcmp(cmd
, "STATION") == 0)
7625 iface_type
= WPA_IF_STATION
;
7626 else if (os_strcmp(cmd
, "AP") == 0)
7627 iface_type
= WPA_IF_AP_BSS
;
7628 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7629 iface_type
= WPA_IF_P2P_GO
;
7630 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7631 iface_type
= WPA_IF_P2P_CLIENT
;
7632 else if (os_strcmp(cmd
, "IBSS") == 0)
7633 iface_type
= WPA_IF_IBSS
;
7634 else if (os_strcmp(cmd
, "TDLS") == 0)
7635 iface_type
= WPA_IF_TDLS
;
7639 wpa_printf(MSG_DEBUG
,
7640 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7643 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7647 for (i
= 0; i
< num
; i
++) {
7648 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7649 i
> 0 ? "," : "", freq_list
[i
]);
7650 if (os_snprintf_error(end
- pos
, ret
))
7659 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7660 char *buf
, size_t buflen
)
7665 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7666 (long long unsigned) wpa_s
->drv_flags
);
7667 if (os_snprintf_error(buflen
, ret
))
7673 for (i
= 0; i
< 64; i
++) {
7674 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7675 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7676 driver_flag_to_string(1LLU << i
));
7677 if (os_snprintf_error(end
- pos
, ret
))
7687 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7690 struct hostap_sta_driver_data sta
;
7693 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7697 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7698 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7699 if (os_snprintf_error(buflen
, ret
))
7706 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7707 char *buf
, size_t buflen
)
7711 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7713 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7714 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7717 country
[0] = cmd
[8];
7718 country
[1] = cmd
[9];
7720 p2p_set_country(p2p
, country
);
7723 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7724 if (os_snprintf_error(buflen
, ret
))
7729 #endif /* ANDROID */
7732 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7733 char *buf
, size_t buflen
)
7738 unsigned int vendor_id
, subcmd
;
7739 struct wpabuf
*reply
;
7740 size_t data_len
= 0;
7742 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7743 vendor_id
= strtoul(cmd
, &pos
, 16);
7744 if (!isblank((unsigned char) *pos
))
7747 subcmd
= strtoul(pos
, &pos
, 10);
7750 if (!isblank((unsigned char) *pos
++))
7752 data_len
= os_strlen(pos
);
7757 data
= os_malloc(data_len
);
7761 if (hexstr2bin(pos
, data
, data_len
)) {
7762 wpa_printf(MSG_DEBUG
,
7763 "Vendor command: wrong parameter format");
7769 reply
= wpabuf_alloc((buflen
- 1) / 2);
7775 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7779 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7789 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7792 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7793 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7794 #endif /* CONFIG_P2P */
7796 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7798 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7799 wpa_s
->ignore_post_flush_scan_res
= 1;
7801 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7803 * Avoid possible auto connect re-connection on getting
7804 * disconnected due to state flush.
7806 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7810 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7811 wpas_p2p_cancel(p2p_wpa_s
);
7812 p2p_ctrl_flush(p2p_wpa_s
);
7813 wpas_p2p_service_flush(p2p_wpa_s
);
7814 p2p_wpa_s
->global
->p2p_disabled
= 0;
7815 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7816 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7817 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7818 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7819 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7820 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7821 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7822 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7823 #endif /* CONFIG_P2P */
7825 #ifdef CONFIG_WPS_TESTING
7826 wps_version_number
= 0x20;
7827 wps_testing_dummy_cred
= 0;
7828 wps_corrupt_pkhash
= 0;
7829 wps_force_auth_types_in_use
= 0;
7830 wps_force_encr_types_in_use
= 0;
7831 #endif /* CONFIG_WPS_TESTING */
7833 wpa_s
->wps_fragment_size
= 0;
7834 wpas_wps_cancel(wpa_s
);
7835 wps_registrar_flush(wpa_s
->wps
->registrar
);
7836 #endif /* CONFIG_WPS */
7837 wpa_s
->after_wps
= 0;
7838 wpa_s
->known_wps_freq
= 0;
7841 wpas_dpp_deinit(wpa_s
);
7842 wpa_s
->dpp_init_max_tries
= 0;
7843 wpa_s
->dpp_init_retry_time
= 0;
7844 wpa_s
->dpp_resp_wait_time
= 0;
7845 wpa_s
->dpp_resp_max_tries
= 0;
7846 wpa_s
->dpp_resp_retry_time
= 0;
7847 #ifdef CONFIG_TESTING_OPTIONS
7848 os_memset(dpp_pkex_own_mac_override
, 0, ETH_ALEN
);
7849 os_memset(dpp_pkex_peer_mac_override
, 0, ETH_ALEN
);
7850 dpp_pkex_ephemeral_key_override_len
= 0;
7851 dpp_protocol_key_override_len
= 0;
7852 dpp_nonce_override_len
= 0;
7853 #endif /* CONFIG_TESTING_OPTIONS */
7854 #endif /* CONFIG_DPP */
7857 #ifdef CONFIG_TDLS_TESTING
7859 #endif /* CONFIG_TDLS_TESTING */
7860 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7861 wpa_tdls_enable(wpa_s
->wpa
, 1);
7862 #endif /* CONFIG_TDLS */
7864 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7865 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7867 wpa_s
->no_keep_alive
= 0;
7868 wpa_s
->own_disconnect_req
= 0;
7870 os_free(wpa_s
->disallow_aps_bssid
);
7871 wpa_s
->disallow_aps_bssid
= NULL
;
7872 wpa_s
->disallow_aps_bssid_count
= 0;
7873 os_free(wpa_s
->disallow_aps_ssid
);
7874 wpa_s
->disallow_aps_ssid
= NULL
;
7875 wpa_s
->disallow_aps_ssid_count
= 0;
7877 wpa_s
->set_sta_uapsd
= 0;
7878 wpa_s
->sta_uapsd
= 0;
7880 wpa_drv_radio_disable(wpa_s
, 0);
7881 wpa_blacklist_clear(wpa_s
);
7882 wpa_s
->extra_blacklist_count
= 0;
7883 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7884 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7885 wpa_config_flush_blobs(wpa_s
->conf
);
7886 wpa_s
->conf
->auto_interworking
= 0;
7887 wpa_s
->conf
->okc
= 0;
7889 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7890 rsn_preauth_deinit(wpa_s
->wpa
);
7892 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7893 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7894 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7895 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7897 radio_remove_works(wpa_s
, NULL
, 1);
7898 wpa_s
->ext_work_in_progress
= 0;
7900 wpa_s
->next_ssid
= NULL
;
7902 #ifdef CONFIG_INTERWORKING
7904 hs20_cancel_fetch_osu(wpa_s
);
7905 hs20_del_icon(wpa_s
, NULL
, NULL
);
7906 #endif /* CONFIG_HS20 */
7907 #endif /* CONFIG_INTERWORKING */
7909 wpa_s
->ext_mgmt_frame_handling
= 0;
7910 wpa_s
->ext_eapol_frame_io
= 0;
7911 #ifdef CONFIG_TESTING_OPTIONS
7912 wpa_s
->extra_roc_dur
= 0;
7913 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7914 wpa_s
->p2p_go_csa_on_inv
= 0;
7915 wpa_s
->ignore_auth_resp
= 0;
7916 wpa_s
->ignore_assoc_disallow
= 0;
7917 wpa_s
->testing_resend_assoc
= 0;
7918 wpa_s
->reject_btm_req_reason
= 0;
7919 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7920 os_free(wpa_s
->get_pref_freq_list_override
);
7921 wpa_s
->get_pref_freq_list_override
= NULL
;
7922 wpabuf_free(wpa_s
->sae_commit_override
);
7923 wpa_s
->sae_commit_override
= NULL
;
7925 os_free(wpa_s
->dpp_config_obj_override
);
7926 wpa_s
->dpp_config_obj_override
= NULL
;
7927 os_free(wpa_s
->dpp_discovery_override
);
7928 wpa_s
->dpp_discovery_override
= NULL
;
7929 os_free(wpa_s
->dpp_groups_override
);
7930 wpa_s
->dpp_groups_override
= NULL
;
7931 dpp_test
= DPP_TEST_DISABLED
;
7932 #endif /* CONFIG_DPP */
7933 #endif /* CONFIG_TESTING_OPTIONS */
7935 wpa_s
->disconnected
= 0;
7936 os_free(wpa_s
->next_scan_freqs
);
7937 wpa_s
->next_scan_freqs
= NULL
;
7938 os_free(wpa_s
->select_network_scan_freqs
);
7939 wpa_s
->select_network_scan_freqs
= NULL
;
7941 wpa_bss_flush(wpa_s
);
7942 if (!dl_list_empty(&wpa_s
->bss
)) {
7943 wpa_printf(MSG_DEBUG
,
7944 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7945 MACSTR
" pending_bssid=" MACSTR
,
7946 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7947 MAC2STR(wpa_s
->bssid
),
7948 MAC2STR(wpa_s
->pending_bssid
));
7951 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7952 wpa_s
->wnmsleep_used
= 0;
7955 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7956 #endif /* CONFIG_SME */
7958 wpabuf_free(wpa_s
->ric_ies
);
7959 wpa_s
->ric_ies
= NULL
;
7961 wpa_supplicant_update_channel_list(wpa_s
, NULL
);
7963 free_bss_tmp_disallowed(wpa_s
);
7967 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7968 char *buf
, size_t buflen
)
7970 struct wpa_radio_work
*work
;
7972 struct os_reltime now
, diff
;
7977 os_get_reltime(&now
);
7979 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7983 os_reltime_sub(&now
, &work
->time
, &diff
);
7984 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7985 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7986 work
->started
, diff
.sec
, diff
.usec
);
7987 if (os_snprintf_error(end
- pos
, ret
))
7996 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7998 struct wpa_radio_work
*work
= eloop_ctx
;
7999 struct wpa_external_work
*ework
= work
->ctx
;
8001 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
8002 "Timing out external radio work %u (%s)",
8003 ework
->id
, work
->type
);
8004 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
8005 work
->wpa_s
->ext_work_in_progress
= 0;
8006 radio_work_done(work
);
8011 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
8013 struct wpa_external_work
*ework
= work
->ctx
;
8017 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8021 * work->type points to a buffer in ework, so need to replace
8022 * that here with a fixed string to avoid use of freed memory
8025 work
->type
= "freed-ext-work";
8031 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
8032 ework
->id
, ework
->type
);
8033 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
8034 work
->wpa_s
->ext_work_in_progress
= 1;
8035 if (!ework
->timeout
)
8036 ework
->timeout
= 10;
8037 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
8042 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
8043 char *buf
, size_t buflen
)
8045 struct wpa_external_work
*ework
;
8049 unsigned int freq
= 0;
8051 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8053 ework
= os_zalloc(sizeof(*ework
));
8057 pos
= os_strchr(cmd
, ' ');
8059 type_len
= pos
- cmd
;
8062 pos2
= os_strstr(pos
, "freq=");
8064 freq
= atoi(pos2
+ 5);
8066 pos2
= os_strstr(pos
, "timeout=");
8068 ework
->timeout
= atoi(pos2
+ 8);
8070 type_len
= os_strlen(cmd
);
8072 if (4 + type_len
>= sizeof(ework
->type
))
8073 type_len
= sizeof(ework
->type
) - 4 - 1;
8074 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
8075 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
8076 ework
->type
[4 + type_len
] = '\0';
8078 wpa_s
->ext_work_id
++;
8079 if (wpa_s
->ext_work_id
== 0)
8080 wpa_s
->ext_work_id
++;
8081 ework
->id
= wpa_s
->ext_work_id
;
8083 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
8089 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
8090 if (os_snprintf_error(buflen
, ret
))
8096 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
8098 struct wpa_radio_work
*work
;
8099 unsigned int id
= atoi(cmd
);
8101 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8103 struct wpa_external_work
*ework
;
8105 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8108 if (id
&& ework
->id
!= id
)
8110 wpa_dbg(wpa_s
, MSG_DEBUG
,
8111 "Completed external radio work %u (%s)",
8112 ework
->id
, ework
->type
);
8113 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
8114 wpa_s
->ext_work_in_progress
= 0;
8115 radio_work_done(work
);
8117 return 3; /* "OK\n" */
8124 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
8125 char *buf
, size_t buflen
)
8127 if (os_strcmp(cmd
, "show") == 0)
8128 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
8129 if (os_strncmp(cmd
, "add ", 4) == 0)
8130 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
8131 if (os_strncmp(cmd
, "done ", 5) == 0)
8132 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
8137 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
8139 struct wpa_radio_work
*work
, *tmp
;
8141 if (!wpa_s
|| !wpa_s
->radio
)
8144 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
8145 struct wpa_radio_work
, list
) {
8146 struct wpa_external_work
*ework
;
8148 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8151 wpa_dbg(wpa_s
, MSG_DEBUG
,
8152 "Flushing%s external radio work %u (%s)",
8153 work
->started
? " started" : "", ework
->id
,
8156 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8158 radio_work_done(work
);
8164 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8166 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8167 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8171 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8172 unsigned int *scan_id_count
, int scan_id
[])
8174 const char *pos
= value
;
8177 if (*pos
== ' ' || *pos
== '\0')
8179 if (*scan_id_count
== MAX_SCAN_ID
)
8181 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8182 pos
= os_strchr(pos
, ',');
8191 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8192 char *reply
, int reply_size
, int *reply_len
)
8195 unsigned int manual_scan_passive
= 0;
8196 unsigned int manual_scan_use_id
= 0;
8197 unsigned int manual_scan_only_new
= 0;
8198 unsigned int scan_only
= 0;
8199 unsigned int scan_id_count
= 0;
8200 int scan_id
[MAX_SCAN_ID
];
8201 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8202 struct wpa_scan_results
*scan_res
);
8203 int *manual_scan_freqs
= NULL
;
8204 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8205 unsigned int ssid_count
= 0;
8207 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8212 if (radio_work_pending(wpa_s
, "scan")) {
8213 wpa_printf(MSG_DEBUG
,
8214 "Pending scan scheduled - reject new request");
8215 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8219 #ifdef CONFIG_INTERWORKING
8220 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8221 wpa_printf(MSG_DEBUG
,
8222 "Interworking select in progress - reject new scan");
8223 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8226 #endif /* CONFIG_INTERWORKING */
8229 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8232 pos
= os_strstr(params
, "freq=");
8234 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8236 if (manual_scan_freqs
== NULL
) {
8242 pos
= os_strstr(params
, "passive=");
8244 manual_scan_passive
= !!atoi(pos
+ 8);
8246 pos
= os_strstr(params
, "use_id=");
8248 manual_scan_use_id
= atoi(pos
+ 7);
8250 pos
= os_strstr(params
, "only_new=1");
8252 manual_scan_only_new
= 1;
8254 pos
= os_strstr(params
, "scan_id=");
8255 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8261 pos
= os_strstr(params
, "bssid=");
8266 if (hwaddr_aton(pos
, bssid
)) {
8267 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8271 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8275 while (pos
&& *pos
!= '\0') {
8276 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8282 if (*end
== '\0' || *end
== ' ')
8287 ns
= os_realloc_array(
8288 ssid
, ssid_count
+ 1,
8289 sizeof(struct wpa_ssid_value
));
8296 if ((end
- pos
) & 0x01 ||
8297 end
- pos
> 2 * SSID_MAX_LEN
||
8298 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8299 (end
- pos
) / 2) < 0) {
8300 wpa_printf(MSG_DEBUG
,
8301 "Invalid SSID value '%s'",
8306 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8307 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8308 ssid
[ssid_count
].ssid
,
8309 ssid
[ssid_count
].ssid_len
);
8314 pos
= os_strchr(pos
, ' ');
8320 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8321 os_free(wpa_s
->ssids_from_scan_req
);
8323 wpa_s
->ssids_from_scan_req
= ssid
;
8326 wpa_s
->ssids_from_scan_req
= NULL
;
8330 scan_res_handler
= scan_only_handler
;
8331 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8332 scan_res_handler
= NULL
;
8334 scan_res_handler
= wpa_s
->scan_res_handler
;
8336 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8337 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8338 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8339 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8340 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8341 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8342 wpa_s
->scan_id_count
= scan_id_count
;
8343 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8344 wpa_s
->scan_res_handler
= scan_res_handler
;
8345 os_free(wpa_s
->manual_scan_freqs
);
8346 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8347 manual_scan_freqs
= NULL
;
8349 wpa_s
->normal_scans
= 0;
8350 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8351 wpa_s
->after_wps
= 0;
8352 wpa_s
->known_wps_freq
= 0;
8353 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8354 if (wpa_s
->manual_scan_use_id
) {
8355 wpa_s
->manual_scan_id
++;
8356 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8357 wpa_s
->manual_scan_id
);
8358 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8359 wpa_s
->manual_scan_id
);
8361 } else if (wpa_s
->sched_scanning
) {
8362 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8363 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8364 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8365 wpa_s
->scan_id_count
= scan_id_count
;
8366 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8367 wpa_s
->scan_res_handler
= scan_res_handler
;
8368 os_free(wpa_s
->manual_scan_freqs
);
8369 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8370 manual_scan_freqs
= NULL
;
8372 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8373 wpa_supplicant_cancel_sched_scan(wpa_s
);
8374 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8375 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8376 if (wpa_s
->manual_scan_use_id
) {
8377 wpa_s
->manual_scan_id
++;
8378 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8379 wpa_s
->manual_scan_id
);
8380 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8381 wpa_s
->manual_scan_id
);
8384 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8385 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8389 os_free(manual_scan_freqs
);
8394 #ifdef CONFIG_TESTING_OPTIONS
8396 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8397 unsigned int freq
, const u8
*dst
,
8398 const u8
*src
, const u8
*bssid
,
8399 const u8
*data
, size_t data_len
,
8400 enum offchannel_send_action_result
8403 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8404 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8405 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8406 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8407 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8408 "NO_ACK" : "FAILED"));
8412 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8416 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8418 int freq
= 0, no_cck
= 0, wait_time
= 0;
8420 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8421 * <action=Action frame payload> */
8423 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8426 used
= hwaddr_aton2(pos
, da
);
8432 used
= hwaddr_aton2(pos
, bssid
);
8437 param
= os_strstr(pos
, " freq=");
8443 param
= os_strstr(pos
, " no_cck=");
8446 no_cck
= atoi(param
);
8449 param
= os_strstr(pos
, " wait_time=");
8452 wait_time
= atoi(param
);
8455 param
= os_strstr(pos
, " action=");
8460 len
= os_strlen(param
);
8465 buf
= os_malloc(len
);
8469 if (hexstr2bin(param
, buf
, len
) < 0) {
8474 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8475 buf
, len
, wait_time
,
8476 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8482 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8484 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8485 offchannel_send_action_done(wpa_s
);
8489 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8495 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8496 union wpa_event_data event
;
8498 if (!wpa_s
->ext_mgmt_frame_handling
)
8501 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8503 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8506 param
= os_strstr(pos
, "freq=");
8512 param
= os_strstr(pos
, " datarate=");
8515 datarate
= atoi(param
);
8518 param
= os_strstr(pos
, " ssi_signal=");
8521 ssi_signal
= atoi(param
);
8524 param
= os_strstr(pos
, " frame=");
8529 len
= os_strlen(param
);
8534 buf
= os_malloc(len
);
8538 if (hexstr2bin(param
, buf
, len
) < 0) {
8543 os_memset(&event
, 0, sizeof(event
));
8544 event
.rx_mgmt
.freq
= freq
;
8545 event
.rx_mgmt
.frame
= buf
;
8546 event
.rx_mgmt
.frame_len
= len
;
8547 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8548 event
.rx_mgmt
.datarate
= datarate
;
8549 wpa_s
->ext_mgmt_frame_handling
= 0;
8550 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8551 wpa_s
->ext_mgmt_frame_handling
= 1;
8559 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8562 struct wpa_scan_res
*res
;
8563 struct os_reltime now
;
8570 if (os_strcmp(param
, "START") == 0) {
8571 wpa_bss_update_start(wpa_s
);
8575 if (os_strcmp(param
, "END") == 0) {
8576 wpa_bss_update_end(wpa_s
, NULL
, 1);
8580 if (os_strncmp(param
, "BSS ", 4) != 0)
8584 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8588 pos
= os_strstr(param
, " flags=");
8590 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8592 pos
= os_strstr(param
, " bssid=");
8593 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8596 pos
= os_strstr(param
, " freq=");
8598 res
->freq
= atoi(pos
+ 6);
8600 pos
= os_strstr(param
, " beacon_int=");
8602 res
->beacon_int
= atoi(pos
+ 12);
8604 pos
= os_strstr(param
, " caps=");
8606 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8608 pos
= os_strstr(param
, " qual=");
8610 res
->qual
= atoi(pos
+ 6);
8612 pos
= os_strstr(param
, " noise=");
8614 res
->noise
= atoi(pos
+ 7);
8616 pos
= os_strstr(param
, " level=");
8618 res
->level
= atoi(pos
+ 7);
8620 pos
= os_strstr(param
, " tsf=");
8622 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8624 pos
= os_strstr(param
, " age=");
8626 res
->age
= atoi(pos
+ 5);
8628 pos
= os_strstr(param
, " est_throughput=");
8630 res
->est_throughput
= atoi(pos
+ 16);
8632 pos
= os_strstr(param
, " snr=");
8634 res
->snr
= atoi(pos
+ 5);
8636 pos
= os_strstr(param
, " parent_tsf=");
8638 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8640 pos
= os_strstr(param
, " tsf_bssid=");
8641 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8644 pos
= os_strstr(param
, " ie=");
8647 end
= os_strchr(pos
, ' ');
8649 end
= pos
+ os_strlen(pos
);
8650 res
->ie_len
= (end
- pos
) / 2;
8651 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8655 pos
= os_strstr(param
, " beacon_ie=");
8658 end
= os_strchr(pos
, ' ');
8660 end
= pos
+ os_strlen(pos
);
8661 res
->beacon_ie_len
= (end
- pos
) / 2;
8662 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8663 res
->beacon_ie_len
))
8667 os_get_reltime(&now
);
8668 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8677 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8680 union wpa_event_data event
;
8681 enum wpa_event_type ev
;
8683 /* <event name> [parameters..] */
8685 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8688 param
= os_strchr(pos
, ' ');
8692 os_memset(&event
, 0, sizeof(event
));
8694 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8695 ev
= EVENT_INTERFACE_ENABLED
;
8696 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8697 ev
= EVENT_INTERFACE_DISABLED
;
8698 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8699 ev
= EVENT_AVOID_FREQUENCIES
;
8702 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8704 wpa_supplicant_event(wpa_s
, ev
, &event
);
8705 os_free(event
.freq_range
.range
);
8707 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8708 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8710 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8715 wpa_supplicant_event(wpa_s
, ev
, &event
);
8721 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8724 u8 src
[ETH_ALEN
], *buf
;
8728 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8731 used
= hwaddr_aton2(pos
, src
);
8738 len
= os_strlen(pos
);
8743 buf
= os_malloc(len
);
8747 if (hexstr2bin(pos
, buf
, len
) < 0) {
8752 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8759 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8763 const u16
*pos
= buf
;
8765 for (i
= 0; i
< len
/ 2; i
++)
8769 sum
= (sum
& 0xffff) + (sum
>> 16);
8771 return sum
^ 0xffff;
8775 #define HWSIM_PACKETLEN 1500
8776 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8778 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8781 struct wpa_supplicant
*wpa_s
= ctx
;
8782 const struct ether_header
*eth
;
8788 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
8789 wpa_printf(MSG_DEBUG
,
8790 "test data: RX - ignore unexpected length %d",
8795 eth
= (const struct ether_header
*) buf
;
8796 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8797 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8799 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8800 ntohs(ip
.tot_len
) > HWSIM_IP_LEN
) {
8801 wpa_printf(MSG_DEBUG
,
8802 "test data: RX - ignore unexpect IP header");
8806 for (i
= 0; i
< ntohs(ip
.tot_len
) - sizeof(ip
); i
++) {
8807 if (*pos
!= (u8
) i
) {
8808 wpa_printf(MSG_DEBUG
,
8809 "test data: RX - ignore mismatching payload");
8815 if (ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8816 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.tot_len
));
8817 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
8818 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
8822 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8825 int enabled
= atoi(cmd
);
8830 if (wpa_s
->l2_test
) {
8831 l2_packet_deinit(wpa_s
->l2_test
);
8832 wpa_s
->l2_test
= NULL
;
8833 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8841 pos
= os_strstr(cmd
, " ifname=");
8845 ifname
= wpa_s
->ifname
;
8847 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8848 ETHERTYPE_IP
, wpas_data_test_rx
,
8850 if (wpa_s
->l2_test
== NULL
)
8853 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8859 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8861 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8866 u8 buf
[2 + HWSIM_PACKETLEN
];
8867 struct ether_header
*eth
;
8871 size_t send_len
= HWSIM_IP_LEN
;
8873 if (wpa_s
->l2_test
== NULL
)
8876 /* format: <dst> <src> <tos> [len=<length>] */
8879 used
= hwaddr_aton2(pos
, dst
);
8885 used
= hwaddr_aton2(pos
, src
);
8890 val
= strtol(pos
, &pos2
, 0);
8891 if (val
< 0 || val
> 0xff)
8895 pos
= os_strstr(pos2
, " len=");
8898 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
8903 eth
= (struct ether_header
*) &buf
[2];
8904 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8905 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8906 eth
->ether_type
= htons(ETHERTYPE_IP
);
8907 ip
= (struct iphdr
*) (eth
+ 1);
8908 os_memset(ip
, 0, sizeof(*ip
));
8913 ip
->tot_len
= htons(send_len
);
8915 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8916 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8917 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8918 dpos
= (u8
*) (ip
+ 1);
8919 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
8922 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8923 sizeof(struct ether_header
) + send_len
) < 0)
8926 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8927 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8933 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8937 struct ether_header
*eth
;
8938 struct l2_packet_data
*l2
= NULL
;
8943 len
= os_strlen(cmd
);
8944 if (len
& 1 || len
< ETH_HLEN
* 2)
8948 buf
= os_malloc(len
);
8952 if (hexstr2bin(cmd
, buf
, len
) < 0)
8955 eth
= (struct ether_header
*) buf
;
8956 ethertype
= ntohs(eth
->ether_type
);
8958 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8959 wpas_data_test_rx
, wpa_s
, 1);
8963 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8964 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8967 l2_packet_deinit(l2
);
8970 return res
< 0 ? -1 : 0;
8974 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8976 #ifdef WPA_TRACE_BFD
8979 wpa_trace_fail_after
= atoi(cmd
);
8980 pos
= os_strchr(cmd
, ':');
8983 os_strlcpy(wpa_trace_fail_func
, pos
,
8984 sizeof(wpa_trace_fail_func
));
8986 wpa_trace_fail_after
= 0;
8989 #else /* WPA_TRACE_BFD */
8991 #endif /* WPA_TRACE_BFD */
8995 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8996 char *buf
, size_t buflen
)
8998 #ifdef WPA_TRACE_BFD
8999 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
9000 wpa_trace_fail_func
);
9001 #else /* WPA_TRACE_BFD */
9003 #endif /* WPA_TRACE_BFD */
9007 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
9009 #ifdef WPA_TRACE_BFD
9012 wpa_trace_test_fail_after
= atoi(cmd
);
9013 pos
= os_strchr(cmd
, ':');
9016 os_strlcpy(wpa_trace_test_fail_func
, pos
,
9017 sizeof(wpa_trace_test_fail_func
));
9019 wpa_trace_test_fail_after
= 0;
9022 #else /* WPA_TRACE_BFD */
9024 #endif /* WPA_TRACE_BFD */
9028 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
9029 char *buf
, size_t buflen
)
9031 #ifdef WPA_TRACE_BFD
9032 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
9033 wpa_trace_test_fail_func
);
9034 #else /* WPA_TRACE_BFD */
9036 #endif /* WPA_TRACE_BFD */
9040 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
9042 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9043 int i
, count
= (intptr_t) timeout_ctx
;
9045 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
9047 for (i
= 0; i
< count
; i
++) {
9048 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
9054 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9062 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
9063 (void *) (intptr_t) count
);
9067 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
9073 len
= os_strlen(cmd
);
9081 buf
= wpabuf_alloc(len
);
9085 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
9091 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
9096 static int wpas_ctrl_reset_pn(struct wpa_supplicant
*wpa_s
)
9098 u8 zero
[WPA_TK_MAX_LEN
];
9100 if (wpa_s
->last_tk_alg
== WPA_ALG_NONE
)
9103 wpa_printf(MSG_INFO
, "TESTING: Reset PN");
9104 os_memset(zero
, 0, sizeof(zero
));
9106 /* First, use a zero key to avoid any possible duplicate key avoidance
9108 if (wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9109 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9110 zero
, wpa_s
->last_tk_len
) < 0)
9113 /* Set the previously configured key to reset its TSC/RSC */
9114 return wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9115 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9116 wpa_s
->last_tk
, wpa_s
->last_tk_len
);
9120 static int wpas_ctrl_key_request(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9122 const char *pos
= cmd
;
9123 int error
, pairwise
;
9126 pos
= os_strchr(pos
, ' ');
9129 pairwise
= atoi(pos
);
9130 wpa_sm_key_request(wpa_s
->wpa
, error
, pairwise
);
9135 static int wpas_ctrl_resend_assoc(struct wpa_supplicant
*wpa_s
)
9138 struct wpa_driver_associate_params params
;
9141 os_memset(¶ms
, 0, sizeof(params
));
9142 params
.bssid
= wpa_s
->bssid
;
9143 params
.ssid
= wpa_s
->sme
.ssid
;
9144 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
9145 params
.freq
.freq
= wpa_s
->sme
.freq
;
9146 if (wpa_s
->last_assoc_req_wpa_ie
) {
9147 params
.wpa_ie
= wpabuf_head(wpa_s
->last_assoc_req_wpa_ie
);
9148 params
.wpa_ie_len
= wpabuf_len(wpa_s
->last_assoc_req_wpa_ie
);
9150 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
9151 params
.group_suite
= wpa_s
->group_cipher
;
9152 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
9153 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
9154 params
.wpa_proto
= wpa_s
->wpa_proto
;
9155 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
9156 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
9157 if (wpa_s
->sme
.prev_bssid_set
)
9158 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
9159 wpa_printf(MSG_INFO
, "TESTING: Resend association request");
9160 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
9161 wpa_s
->testing_resend_assoc
= 1;
9163 #else /* CONFIG_SME */
9165 #endif /* CONFIG_SME */
9168 #endif /* CONFIG_TESTING_OPTIONS */
9171 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
9177 struct ieee802_11_elems elems
;
9180 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9182 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9184 pos
= os_strchr(pos
, ' ');
9189 len
= os_strlen(pos
);
9196 buf
= wpabuf_alloc(len
);
9200 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
9205 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
9211 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
9212 wpa_s
->vendor_elem
[frame
] = buf
;
9213 wpas_vendor_elem_update(wpa_s
);
9217 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
9222 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
9224 wpas_vendor_elem_update(wpa_s
);
9230 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
9231 char *buf
, size_t buflen
)
9233 int frame
= atoi(cmd
);
9235 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9237 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9239 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9242 return wpa_snprintf_hex(buf
, buflen
,
9243 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
9244 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
9248 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
9254 struct ieee802_11_elems elems
;
9258 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9260 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9262 pos
= os_strchr(pos
, ' ');
9268 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9269 wpa_s
->vendor_elem
[frame
] = NULL
;
9270 wpas_vendor_elem_update(wpa_s
);
9274 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9277 len
= os_strlen(pos
);
9284 buf
= os_malloc(len
);
9288 if (hexstr2bin(pos
, buf
, len
) < 0) {
9293 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9298 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9304 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9306 struct wpa_supplicant
*wpa_s
= ctx
;
9311 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9313 * BSSID Information[4]
9314 * Operating Class[1]
9317 * Optional Subelements[variable]
9319 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9321 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9322 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9326 data
= wpabuf_head_u8(neighbor_rep
);
9327 len
= wpabuf_len(neighbor_rep
);
9329 while (len
>= 2 + NR_IE_MIN_LEN
) {
9331 char lci
[256 * 2 + 1];
9332 char civic
[256 * 2 + 1];
9333 u8 nr_len
= data
[1];
9334 const u8
*pos
= data
, *end
;
9336 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9337 nr_len
< NR_IE_MIN_LEN
) {
9338 wpa_printf(MSG_DEBUG
,
9339 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9344 if (2U + nr_len
> len
) {
9345 wpa_printf(MSG_DEBUG
,
9346 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9347 data
[0], len
, nr_len
);
9354 pos
+= NR_IE_MIN_LEN
;
9358 while (end
- pos
> 2) {
9363 if (s_len
> end
- pos
)
9365 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9366 /* Measurement Token[1] */
9367 /* Measurement Report Mode[1] */
9368 /* Measurement Type[1] */
9369 /* Measurement Report[variable] */
9371 case MEASURE_TYPE_LCI
:
9374 wpa_snprintf_hex(lci
, sizeof(lci
),
9377 case MEASURE_TYPE_LOCATION_CIVIC
:
9380 wpa_snprintf_hex(civic
, sizeof(civic
),
9389 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9391 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9392 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9393 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9395 lci
[0] ? " lci=" : "", lci
,
9396 civic
[0] ? " civic=" : "", civic
);
9403 wpabuf_free(neighbor_rep
);
9407 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9410 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9411 int ret
, lci
= 0, civic
= 0;
9414 ssid_s
= os_strstr(cmd
, "ssid=");
9416 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9417 wpa_printf(MSG_ERROR
,
9418 "CTRL: Send Neighbor Report: bad SSID");
9425 * Move cmd after the SSID text that may include "lci" or
9428 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9434 if (cmd
&& os_strstr(cmd
, "lci"))
9437 if (cmd
&& os_strstr(cmd
, "civic"))
9440 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9441 wpas_ctrl_neighbor_rep_cb
,
9448 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9450 eapol_sm_erp_flush(wpa_s
->eapol
);
9455 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9458 char *token
, *context
= NULL
;
9459 unsigned int enable
= ~0, type
= 0;
9460 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9461 u8
*addr
= NULL
, *mask
= NULL
;
9463 while ((token
= str_token(cmd
, " ", &context
))) {
9464 if (os_strcasecmp(token
, "scan") == 0) {
9465 type
|= MAC_ADDR_RAND_SCAN
;
9466 } else if (os_strcasecmp(token
, "sched") == 0) {
9467 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9468 } else if (os_strcasecmp(token
, "pno") == 0) {
9469 type
|= MAC_ADDR_RAND_PNO
;
9470 } else if (os_strcasecmp(token
, "all") == 0) {
9471 type
= wpa_s
->mac_addr_rand_supported
;
9472 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9473 enable
= atoi(token
+ 7);
9474 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9476 if (hwaddr_aton(token
+ 5, addr
)) {
9477 wpa_printf(MSG_INFO
,
9478 "CTRL: Invalid MAC address: %s",
9482 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9484 if (hwaddr_aton(token
+ 5, mask
)) {
9485 wpa_printf(MSG_INFO
,
9486 "CTRL: Invalid MAC address mask: %s",
9491 wpa_printf(MSG_INFO
,
9492 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9499 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9503 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
9504 wpa_printf(MSG_INFO
,
9505 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9506 type
, wpa_s
->mac_addr_rand_supported
);
9511 wpa_printf(MSG_INFO
,
9512 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9517 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
9519 if (type
& MAC_ADDR_RAND_PNO
) {
9520 wpas_stop_pno(wpa_s
);
9521 wpas_start_pno(wpa_s
);
9523 } else if (wpa_s
->sched_scanning
&&
9524 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
9525 wpas_scan_restart_sched_scan(wpa_s
);
9530 if ((addr
&& !mask
) || (!addr
&& mask
)) {
9531 wpa_printf(MSG_INFO
,
9532 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9536 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
9537 wpa_printf(MSG_INFO
,
9538 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9542 if (type
& MAC_ADDR_RAND_SCAN
) {
9543 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
9547 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
9548 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
9551 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
9552 wpas_scan_restart_sched_scan(wpa_s
);
9555 if (type
& MAC_ADDR_RAND_PNO
) {
9556 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
9559 wpas_stop_pno(wpa_s
);
9560 wpas_start_pno(wpa_s
);
9568 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9569 char *buf
, size_t buflen
)
9573 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9575 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9576 buflen
- reply_len
);
9577 #endif /* CONFIG_AP */
9582 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9584 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9586 wpas_ap_pmksa_cache_flush(wpa_s
);
9587 #endif /* CONFIG_AP */
9591 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9593 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9594 const char *cmd
, char *buf
, size_t buflen
)
9596 struct rsn_pmksa_cache_entry
*entry
;
9597 struct wpa_ssid
*ssid
;
9598 char *pos
, *pos2
, *end
;
9600 struct os_reltime now
;
9602 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9609 os_get_reltime(&now
);
9613 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9614 * <expiration in seconds> <akmp> <opportunistic>
9615 * [FILS Cache Identifier]
9618 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9619 entry
= entry
->next
) {
9620 if (entry
->network_ctx
!= ssid
)
9624 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9625 MAC2STR(entry
->aa
));
9626 if (os_snprintf_error(end
- pos2
, ret
))
9630 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9633 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9634 if (os_snprintf_error(end
- pos2
, ret
))
9638 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9641 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9642 (int) (entry
->reauth_time
- now
.sec
),
9643 (int) (entry
->expiration
- now
.sec
),
9645 entry
->opportunistic
);
9646 if (os_snprintf_error(end
- pos2
, ret
))
9650 if (entry
->fils_cache_id_set
) {
9651 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9652 entry
->fils_cache_id
[0],
9653 entry
->fils_cache_id
[1]);
9654 if (os_snprintf_error(end
- pos2
, ret
))
9659 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9660 if (os_snprintf_error(end
- pos2
, ret
))
9671 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9674 struct rsn_pmksa_cache_entry
*entry
;
9675 struct wpa_ssid
*ssid
;
9678 struct os_reltime now
;
9679 int reauth_time
= 0, expiration
= 0, i
;
9683 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9684 * <expiration in seconds> <akmp> <opportunistic>
9685 * [FILS Cache Identifier]
9688 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9692 pos
= os_strchr(cmd
, ' ');
9697 entry
= os_zalloc(sizeof(*entry
));
9701 if (hwaddr_aton(pos
, entry
->aa
))
9704 pos
= os_strchr(pos
, ' ');
9709 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9712 pos
= os_strchr(pos
, ' ');
9717 pos2
= os_strchr(pos
, ' ');
9720 entry
->pmk_len
= (pos2
- pos
) / 2;
9721 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9722 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9725 pos
= os_strchr(pos
, ' ');
9730 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9731 &entry
->akmp
, &entry
->opportunistic
) != 4)
9733 for (i
= 0; i
< 4; i
++) {
9734 pos
= os_strchr(pos
, ' ');
9743 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9744 FILS_CACHE_ID_LEN
) < 0)
9746 entry
->fils_cache_id_set
= 1;
9748 os_get_reltime(&now
);
9749 entry
->expiration
= now
.sec
+ expiration
;
9750 entry
->reauth_time
= now
.sec
+ reauth_time
;
9752 entry
->network_ctx
= ssid
;
9754 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9765 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9766 const char *cmd
, char *buf
,
9774 if (os_strcasecmp(cmd
, "any") == 0)
9775 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9777 if (hwaddr_aton(cmd
, spa
))
9780 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9784 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9788 * We do not check mesh interface existance because PMKSA should be
9789 * stored before wpa_s->ifmsh creation to suppress commit message
9792 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9795 #endif /* CONFIG_MESH */
9796 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9800 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9803 struct fils_hlp_req
*req
;
9806 /* format: <dst> <packet starting from ethertype> */
9808 req
= os_zalloc(sizeof(*req
));
9812 if (hwaddr_aton(cmd
, req
->dst
))
9815 pos
= os_strchr(cmd
, ' ');
9819 req
->pkt
= wpabuf_parse_bin(pos
);
9823 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9826 wpabuf_free(req
->pkt
);
9830 #endif /* CONFIG_FILS */
9833 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9835 if (os_strcmp(cmd
, "PING") == 0 ||
9836 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9837 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9838 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9839 os_strncmp(cmd
, "STA ", 4) == 0 ||
9840 os_strncmp(cmd
, "STA-", 4) == 0)
9841 return MSG_EXCESSIVE
;
9846 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9847 char *buf
, size_t *resp_len
)
9850 const int reply_size
= 4096;
9853 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9854 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9855 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9856 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9857 if (wpa_debug_show_keys
)
9858 wpa_dbg(wpa_s
, MSG_DEBUG
,
9859 "Control interface command '%s'", buf
);
9861 wpa_dbg(wpa_s
, MSG_DEBUG
,
9862 "Control interface command '%s [REMOVED]'",
9863 os_strncmp(buf
, WPA_CTRL_RSP
,
9864 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9866 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9867 "SET_NETWORK" : "key-add"));
9868 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9869 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9870 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9871 (const u8
*) buf
, os_strlen(buf
));
9873 int level
= wpas_ctrl_cmd_debug_level(buf
);
9874 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9877 reply
= os_malloc(reply_size
);
9878 if (reply
== NULL
) {
9883 os_memcpy(reply
, "OK\n", 3);
9886 if (os_strcmp(buf
, "PING") == 0) {
9887 os_memcpy(reply
, "PONG\n", 5);
9889 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9890 reply_len
= os_strlen(wpa_s
->ifname
);
9891 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9892 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9893 if (wpa_debug_reopen_file() < 0)
9895 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9896 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9897 } else if (os_strcmp(buf
, "MIB") == 0) {
9898 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9899 if (reply_len
>= 0) {
9900 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9902 reply_size
- reply_len
);
9903 #ifdef CONFIG_MACSEC
9904 reply_len
+= ieee802_1x_kay_get_mib(
9905 wpa_s
->kay
, reply
+ reply_len
,
9906 reply_size
- reply_len
);
9907 #endif /* CONFIG_MACSEC */
9909 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9910 reply_len
= wpa_supplicant_ctrl_iface_status(
9911 wpa_s
, buf
+ 6, reply
, reply_size
);
9912 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9913 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9914 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9915 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9916 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9917 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9918 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9920 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9921 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9924 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9925 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9927 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9928 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9930 #endif /* CONFIG_MESH */
9931 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9932 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9933 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9935 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9936 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9938 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9939 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9941 } else if (os_strcmp(buf
, "LOGON") == 0) {
9942 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9943 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9944 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9945 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9946 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9949 wpas_request_connection(wpa_s
);
9950 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9951 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9952 !wpa_s
->current_ssid
)
9955 wpa_s
->reattach
= 1;
9956 wpas_request_connection(wpa_s
);
9958 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9959 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9961 else if (wpa_s
->disconnected
)
9962 wpas_request_connection(wpa_s
);
9963 #ifdef IEEE8021X_EAPOL
9964 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9965 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9967 #endif /* IEEE8021X_EAPOL */
9968 #ifdef CONFIG_IEEE80211R
9969 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9970 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9972 #endif /* CONFIG_IEEE80211R */
9974 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9975 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9977 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9981 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9982 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9984 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9988 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9989 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9992 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9993 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9994 wpa_s
, buf
+ 14, reply
, reply_size
);
9995 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9996 if (wpas_wps_cancel(wpa_s
))
9998 #ifdef CONFIG_WPS_NFC
9999 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
10000 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
10002 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
10003 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
10005 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10006 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10007 wpa_s
, buf
+ 21, reply
, reply_size
);
10008 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
10009 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
10010 wpa_s
, buf
+ 14, reply
, reply_size
);
10011 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
10012 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
10015 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10016 reply_len
= wpas_ctrl_nfc_get_handover_req(
10017 wpa_s
, buf
+ 21, reply
, reply_size
);
10018 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10019 reply_len
= wpas_ctrl_nfc_get_handover_sel(
10020 wpa_s
, buf
+ 21, reply
, reply_size
);
10021 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
10022 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
10024 #endif /* CONFIG_WPS_NFC */
10025 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
10026 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
10029 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
10030 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
10031 wpa_s
, buf
+ 11, reply
, reply_size
);
10032 #endif /* CONFIG_AP */
10033 #ifdef CONFIG_WPS_ER
10034 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
10035 if (wpas_wps_er_start(wpa_s
, NULL
))
10037 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
10038 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
10040 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
10041 wpas_wps_er_stop(wpa_s
);
10042 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
10043 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
10045 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
10046 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
10048 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
10050 } else if (ret
== -3) {
10051 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
10053 } else if (ret
== -4) {
10054 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
10058 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
10059 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
10061 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
10062 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
10065 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
10066 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
10068 #ifdef CONFIG_WPS_NFC
10069 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10070 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10071 wpa_s
, buf
+ 24, reply
, reply_size
);
10072 #endif /* CONFIG_WPS_NFC */
10073 #endif /* CONFIG_WPS_ER */
10074 #endif /* CONFIG_WPS */
10075 #ifdef CONFIG_IBSS_RSN
10076 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
10077 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
10079 #endif /* CONFIG_IBSS_RSN */
10081 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
10082 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10083 wpa_s
, buf
+ 19, reply
, reply_size
);
10084 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
10085 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
10086 wpa_s
, "", reply
, reply_size
);
10087 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
10088 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
10090 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
10091 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
10094 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
10095 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
10097 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
10098 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
10100 #endif /* CONFIG_MESH */
10102 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
10103 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
10105 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
10106 if (p2p_ctrl_find(wpa_s
, ""))
10108 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
10109 wpas_p2p_stop_find(wpa_s
);
10110 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
10111 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
10113 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10114 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
10116 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
10117 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
10119 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
10120 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
10122 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
10123 if (p2p_ctrl_listen(wpa_s
, ""))
10125 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
10126 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
10128 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
10129 if (p2p_ctrl_group_add(wpa_s
, ""))
10131 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
10132 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
10134 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
10135 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
10137 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
10138 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
10140 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
10141 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
10142 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
10143 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
10145 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10146 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
10148 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
10149 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
10151 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
10152 wpas_p2p_sd_service_update(wpa_s
);
10153 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10154 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
10156 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
10157 wpas_p2p_service_flush(wpa_s
);
10158 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
10159 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
10161 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
10162 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
10164 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
10165 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
10167 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
10168 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
10170 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
10171 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
10173 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
10174 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
10176 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
10177 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
10179 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
10180 p2p_ctrl_flush(wpa_s
);
10181 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
10182 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
10184 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
10185 if (wpas_p2p_cancel(wpa_s
))
10187 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
10188 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
10190 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
10191 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
10193 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
10194 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
10196 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
10197 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
10199 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
10200 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
10202 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
10203 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
10205 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
10206 if (wpas_p2p_lo_stop(wpa_s
))
10208 #endif /* CONFIG_P2P */
10209 #ifdef CONFIG_WIFI_DISPLAY
10210 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
10211 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
10213 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
10214 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
10215 reply
, reply_size
);
10216 #endif /* CONFIG_WIFI_DISPLAY */
10217 #ifdef CONFIG_INTERWORKING
10218 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
10219 if (interworking_fetch_anqp(wpa_s
) < 0)
10221 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
10222 interworking_stop_fetch_anqp(wpa_s
);
10223 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
10224 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
10226 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
10227 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
10229 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
10230 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
10232 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10235 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
10239 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
10240 if (os_snprintf_error(reply_size
, reply_len
))
10243 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
10244 if (get_anqp(wpa_s
, buf
+ 9) < 0)
10246 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
10247 if (gas_request(wpa_s
, buf
+ 12) < 0)
10249 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
10250 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
10252 #endif /* CONFIG_INTERWORKING */
10254 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10255 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10257 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10258 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10260 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10261 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10263 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10264 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10266 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10267 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10268 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10269 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10271 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10272 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10274 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10275 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10277 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10278 hs20_cancel_fetch_osu(wpa_s
);
10279 #endif /* CONFIG_HS20 */
10280 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10282 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10283 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10287 * Notify response from timeout to allow the control
10288 * interface response to be sent first.
10290 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10293 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10294 if (wpa_supplicant_reload_configuration(wpa_s
))
10296 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10297 wpa_supplicant_terminate_proc(wpa_s
->global
);
10298 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10299 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10301 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10302 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10303 wpa_s
, buf
+ 9, reply
, reply_size
);
10304 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10305 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10306 wpa_s
, buf
+ 9, reply
, reply_size
);
10307 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10308 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10309 wpa_s
, buf
+ 14, reply
, reply_size
);
10310 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10311 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10312 wpa_s
, NULL
, reply
, reply_size
);
10313 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10314 wpas_request_disconnection(wpa_s
);
10315 } else if (os_strcmp(buf
, "SCAN") == 0) {
10316 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10317 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10318 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10319 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10320 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10321 wpa_s
, reply
, reply_size
);
10322 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10323 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10325 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10326 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10328 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10329 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10331 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10332 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10334 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10335 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10336 wpa_s
, reply
, reply_size
);
10337 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10338 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10340 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10341 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10343 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10344 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10345 wpa_s
, buf
+ 12, reply
, reply_size
);
10346 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10347 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10350 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10351 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10352 wpa_s
, reply
, reply_size
);
10353 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10354 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10355 wpa_s
, reply
, reply_size
);
10356 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10357 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10359 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10360 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10362 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10363 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10366 #ifndef CONFIG_NO_CONFIG_WRITE
10367 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10368 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10370 #endif /* CONFIG_NO_CONFIG_WRITE */
10371 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10372 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10373 wpa_s
, buf
+ 15, reply
, reply_size
);
10374 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10375 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10377 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10378 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10380 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10381 reply_len
= wpa_supplicant_global_iface_list(
10382 wpa_s
->global
, reply
, reply_size
);
10383 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10384 reply_len
= wpa_supplicant_global_iface_interfaces(
10385 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10386 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10387 reply_len
= wpa_supplicant_ctrl_iface_bss(
10388 wpa_s
, buf
+ 4, reply
, reply_size
);
10390 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10391 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10392 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10393 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10395 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10396 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10398 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10399 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10401 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10402 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10404 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10405 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10407 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10408 if (wpas_ap_stop_ap(wpa_s
))
10410 #endif /* CONFIG_AP */
10411 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10412 wpas_notify_suspend(wpa_s
->global
);
10413 } else if (os_strcmp(buf
, "RESUME") == 0) {
10414 wpas_notify_resume(wpa_s
->global
);
10415 #ifdef CONFIG_TESTING_OPTIONS
10416 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10417 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10418 #endif /* CONFIG_TESTING_OPTIONS */
10419 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10420 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10422 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10423 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10424 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10425 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10427 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10428 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10431 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10432 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10434 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10435 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10437 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10438 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10440 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10441 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10443 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10444 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10447 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10448 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10451 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10452 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10453 wpa_s
, buf
+ 17, reply
, reply_size
);
10454 #endif /* CONFIG_TDLS */
10455 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10456 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10457 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10458 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10460 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10461 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10463 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10464 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10466 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10467 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10469 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10470 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10472 #ifdef CONFIG_AUTOSCAN
10473 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10474 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10476 #endif /* CONFIG_AUTOSCAN */
10477 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10478 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10481 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10482 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10484 #endif /* ANDROID */
10485 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10486 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10488 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10489 pmksa_cache_clear_current(wpa_s
->wpa
);
10490 eapol_sm_request_reauth(wpa_s
->eapol
);
10492 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10493 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10495 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10496 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10498 } else if (os_strncmp(buf
, "COLOC_INTF_REPORT ", 18) == 0) {
10499 if (wpas_ctrl_iface_coloc_intf_report(wpa_s
, buf
+ 18))
10501 #endif /* CONFIG_WNM */
10502 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10503 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10504 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10505 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10507 #ifdef CONFIG_TESTING_OPTIONS
10508 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10509 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10511 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10512 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10513 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10514 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10516 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10517 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10519 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10520 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10522 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10523 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10525 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10526 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10528 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10529 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10531 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10532 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10534 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10535 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10536 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10537 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10539 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10540 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10541 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10542 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10544 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10545 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10547 } else if (os_strcmp(buf
, "RESET_PN") == 0) {
10548 if (wpas_ctrl_reset_pn(wpa_s
) < 0)
10550 } else if (os_strncmp(buf
, "KEY_REQUEST ", 12) == 0) {
10551 if (wpas_ctrl_key_request(wpa_s
, buf
+ 12) < 0)
10553 } else if (os_strcmp(buf
, "RESEND_ASSOC") == 0) {
10554 if (wpas_ctrl_resend_assoc(wpa_s
) < 0)
10556 } else if (os_strcmp(buf
, "UNPROT_DEAUTH") == 0) {
10557 sme_event_unprot_disconnect(
10558 wpa_s
, wpa_s
->bssid
, NULL
,
10559 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
);
10560 #endif /* CONFIG_TESTING_OPTIONS */
10561 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10562 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10564 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10565 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10567 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10568 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10570 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10571 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10573 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10574 wpas_ctrl_iface_erp_flush(wpa_s
);
10575 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10576 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10578 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10579 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10580 wpa_s
, buf
+ 19, reply
, reply_size
);
10582 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10583 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10585 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10586 wpas_flush_fils_hlp_req(wpa_s
);
10587 #endif /* CONFIG_FILS */
10589 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10592 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10596 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10597 if (os_snprintf_error(reply_size
, reply_len
))
10600 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10603 res
= wpas_dpp_bootstrap_gen(wpa_s
, buf
+ 18);
10607 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10608 if (os_snprintf_error(reply_size
, reply_len
))
10611 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10612 if (wpas_dpp_bootstrap_remove(wpa_s
, buf
+ 21) < 0)
10614 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10617 uri
= wpas_dpp_bootstrap_get_uri(wpa_s
, atoi(buf
+ 22));
10621 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10622 if (os_snprintf_error(reply_size
, reply_len
))
10625 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10626 reply_len
= wpas_dpp_bootstrap_info(wpa_s
, atoi(buf
+ 19),
10627 reply
, reply_size
);
10628 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10629 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10631 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10632 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10634 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10635 wpas_dpp_stop(wpa_s
);
10636 wpas_dpp_listen_stop(wpa_s
);
10637 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10640 res
= wpas_dpp_configurator_add(wpa_s
, buf
+ 20);
10644 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10645 if (os_snprintf_error(reply_size
, reply_len
))
10648 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10649 if (wpas_dpp_configurator_remove(wpa_s
, buf
+ 24) < 0)
10651 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10652 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 21) < 0)
10654 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10655 reply_len
= wpas_dpp_configurator_get_key(wpa_s
, atoi(buf
+ 25),
10656 reply
, reply_size
);
10657 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10660 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10664 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10665 if (os_snprintf_error(reply_size
, reply_len
))
10668 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10669 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10671 #endif /* CONFIG_DPP */
10673 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10677 if (reply_len
< 0) {
10678 os_memcpy(reply
, "FAIL\n", 5);
10682 *resp_len
= reply_len
;
10687 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10690 struct wpa_interface iface
;
10692 struct wpa_supplicant
*wpa_s
;
10693 unsigned int create_iface
= 0;
10694 u8 mac_addr
[ETH_ALEN
];
10695 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10698 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10699 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10701 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10703 os_memset(&iface
, 0, sizeof(iface
));
10706 iface
.ifname
= pos
= cmd
;
10707 pos
= os_strchr(pos
, '\t');
10710 if (iface
.ifname
[0] == '\0')
10715 iface
.confname
= pos
;
10716 pos
= os_strchr(pos
, '\t');
10719 if (iface
.confname
[0] == '\0')
10720 iface
.confname
= NULL
;
10724 iface
.driver
= pos
;
10725 pos
= os_strchr(pos
, '\t');
10728 if (iface
.driver
[0] == '\0')
10729 iface
.driver
= NULL
;
10733 iface
.ctrl_interface
= pos
;
10734 pos
= os_strchr(pos
, '\t');
10737 if (iface
.ctrl_interface
[0] == '\0')
10738 iface
.ctrl_interface
= NULL
;
10742 iface
.driver_param
= pos
;
10743 pos
= os_strchr(pos
, '\t');
10746 if (iface
.driver_param
[0] == '\0')
10747 iface
.driver_param
= NULL
;
10751 iface
.bridge_ifname
= pos
;
10752 pos
= os_strchr(pos
, '\t');
10755 if (iface
.bridge_ifname
[0] == '\0')
10756 iface
.bridge_ifname
= NULL
;
10761 pos
= os_strchr(pos
, '\t');
10767 if (os_strcmp(extra
, "create") == 0) {
10772 if (os_strcmp(pos
, "sta") == 0) {
10773 type
= WPA_IF_STATION
;
10774 } else if (os_strcmp(pos
, "ap") == 0) {
10775 type
= WPA_IF_AP_BSS
;
10777 wpa_printf(MSG_DEBUG
,
10778 "INTERFACE_ADD unsupported interface type: '%s'",
10783 wpa_printf(MSG_DEBUG
,
10784 "INTERFACE_ADD unsupported extra parameter: '%s'",
10790 if (create_iface
) {
10791 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10793 if (!global
->ifaces
)
10795 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10796 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10797 wpa_printf(MSG_ERROR
,
10798 "CTRL_IFACE interface creation failed");
10802 wpa_printf(MSG_DEBUG
,
10803 "CTRL_IFACE interface '%s' created with MAC addr: "
10804 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10807 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10810 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10813 wpa_s
->added_vif
= create_iface
;
10818 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10823 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10826 struct wpa_supplicant
*wpa_s
;
10828 unsigned int delete_iface
;
10830 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10832 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10835 delete_iface
= wpa_s
->added_vif
;
10836 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10837 if (!ret
&& delete_iface
) {
10838 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10840 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10846 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10848 struct wpa_interface_info
*prev
;
10852 iface
= iface
->next
;
10854 os_free(prev
->ifname
);
10855 os_free(prev
->desc
);
10861 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10862 char *buf
, int len
)
10865 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10868 for (i
= 0; wpa_drivers
[i
]; i
++) {
10869 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10870 if (drv
->get_interfaces
== NULL
)
10872 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10877 iface
= last
= tmp
;
10886 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10887 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10888 tmp
->drv_name
, tmp
->ifname
,
10889 tmp
->desc
? tmp
->desc
: "");
10890 if (os_snprintf_error(end
- pos
, res
)) {
10897 wpa_free_iface_info(iface
);
10903 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10905 char *buf
, int len
)
10909 struct wpa_supplicant
*wpa_s
;
10913 show_ctrl
= !!os_strstr(input
, "ctrl");
10915 wpa_s
= global
->ifaces
;
10921 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10923 wpa_s
->conf
->ctrl_interface
?
10924 wpa_s
->conf
->ctrl_interface
: "N/A");
10926 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10929 if (os_snprintf_error(end
- pos
, res
)) {
10934 wpa_s
= wpa_s
->next
;
10940 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10941 const char *ifname
,
10942 char *cmd
, size_t *resp_len
)
10944 struct wpa_supplicant
*wpa_s
;
10946 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10947 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10951 if (wpa_s
== NULL
) {
10952 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10954 *resp_len
= os_strlen(resp
);
10960 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10964 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10965 char *buf
, size_t *resp_len
)
10968 static const char * cmd
[] = {
10974 "P2P_GET_PASSPHRASE",
10975 "P2P_SERVICE_UPDATE",
10976 "P2P_SERVICE_FLUSH",
10979 "P2P_PRESENCE_REQ",
10983 #endif /* CONFIG_AP */
10986 static const char * prefix
[] = {
10989 #endif /* ANDROID */
10996 "P2P_GROUP_REMOVE ",
10998 "P2P_GROUP_MEMBER ",
11000 "P2P_SERV_DISC_REQ ",
11001 "P2P_SERV_DISC_CANCEL_REQ ",
11002 "P2P_SERV_DISC_RESP ",
11003 "P2P_SERV_DISC_EXTERNAL ",
11004 "P2P_SERVICE_ADD ",
11005 "P2P_SERVICE_DEL ",
11006 "P2P_SERVICE_REP ",
11011 "P2P_UNAUTHORIZE ",
11012 "P2P_PRESENCE_REQ ",
11014 "P2P_REMOVE_CLIENT ",
11016 "WPS_NFC_TAG_READ ",
11017 "NFC_GET_HANDOVER_SEL ",
11018 "NFC_GET_HANDOVER_REQ ",
11019 "NFC_REPORT_HANDOVER ",
11020 "P2P_ASP_PROVISION ",
11021 "P2P_ASP_PROVISION_RESP ",
11025 #endif /* CONFIG_AP */
11031 if (global
->p2p_init_wpa_s
== NULL
)
11034 for (i
= 0; !found
&& cmd
[i
]; i
++) {
11035 if (os_strcmp(buf
, cmd
[i
]) == 0)
11039 for (i
= 0; !found
&& prefix
[i
]; i
++) {
11040 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
11045 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11047 #endif /* CONFIG_P2P */
11052 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
11053 char *buf
, size_t *resp_len
)
11055 #ifdef CONFIG_WIFI_DISPLAY
11056 if (global
->p2p_init_wpa_s
== NULL
)
11058 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
11059 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
11060 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
11062 #endif /* CONFIG_WIFI_DISPLAY */
11067 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
11068 char *buf
, size_t *resp_len
)
11072 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
11076 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
11084 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
11088 value
= os_strchr(cmd
, ' ');
11093 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
11095 #ifdef CONFIG_WIFI_DISPLAY
11096 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
11097 wifi_display_enable(global
, !!atoi(value
));
11100 #endif /* CONFIG_WIFI_DISPLAY */
11102 /* Restore cmd to its original value to allow redirection */
11109 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
11112 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
11116 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11117 * <variable name> */
11119 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
11120 p
= os_strchr(cmd
, ' ');
11125 wpa_s
[i
] = global
->ifaces
;
11126 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
11127 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
11132 wpa_printf(MSG_DEBUG
,
11133 "CTRL_IFACE: Could not find iface=%s", cmd
);
11140 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
11144 #ifndef CONFIG_NO_CONFIG_WRITE
11145 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
11147 int ret
= 0, saved
= 0;
11148 struct wpa_supplicant
*wpa_s
;
11150 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11151 if (!wpa_s
->conf
->update_config
) {
11152 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11156 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
11157 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11160 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11165 if (!saved
&& !ret
) {
11166 wpa_dbg(wpa_s
, MSG_DEBUG
,
11167 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11173 #endif /* CONFIG_NO_CONFIG_WRITE */
11176 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
11177 char *buf
, size_t buflen
)
11181 struct wpa_supplicant
*wpa_s
;
11184 end
= buf
+ buflen
;
11187 if (global
->p2p
&& !global
->p2p_disabled
) {
11188 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
11191 MAC2STR(global
->p2p_dev_addr
),
11192 p2p_get_state_txt(global
->p2p
));
11193 if (os_snprintf_error(end
- pos
, ret
))
11196 } else if (global
->p2p
) {
11197 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
11198 if (os_snprintf_error(end
- pos
, ret
))
11202 #endif /* CONFIG_P2P */
11204 #ifdef CONFIG_WIFI_DISPLAY
11205 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
11206 !!global
->wifi_display
);
11207 if (os_snprintf_error(end
- pos
, ret
))
11210 #endif /* CONFIG_WIFI_DISPLAY */
11212 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11213 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
11214 "address=" MACSTR
"\n",
11215 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
11216 if (os_snprintf_error(end
- pos
, ret
))
11227 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
11228 char *cmd
, char *buf
,
11231 char ifname
[IFNAMSIZ
+ 1];
11232 struct fst_iface_cfg cfg
;
11233 struct wpa_supplicant
*wpa_s
;
11234 struct fst_wpa_obj iface_obj
;
11236 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
11237 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11240 wpa_printf(MSG_INFO
, "FST: Already attached");
11243 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
11244 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
11247 return os_snprintf(buf
, reply_size
, "OK\n");
11255 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
11256 char *cmd
, char *buf
,
11259 char ifname
[IFNAMSIZ
+ 1];
11260 struct wpa_supplicant
*wpa_s
;
11262 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
11263 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11265 if (!fst_iface_detach(ifname
)) {
11267 return os_snprintf(buf
, reply_size
, "OK\n");
11275 #endif /* CONFIG_FST */
11278 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11279 char *buf
, size_t *resp_len
)
11282 const int reply_size
= 2048;
11284 int level
= MSG_DEBUG
;
11286 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11287 char *pos
= os_strchr(buf
+ 7, ' ');
11290 return wpas_global_ctrl_iface_ifname(global
,
11296 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11300 if (os_strcmp(buf
, "PING") == 0)
11301 level
= MSG_EXCESSIVE
;
11302 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11303 (const u8
*) buf
, os_strlen(buf
));
11305 reply
= os_malloc(reply_size
);
11306 if (reply
== NULL
) {
11311 os_memcpy(reply
, "OK\n", 3);
11314 if (os_strcmp(buf
, "PING") == 0) {
11315 os_memcpy(reply
, "PONG\n", 5);
11317 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11318 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11320 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11321 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11323 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11324 reply_len
= wpa_supplicant_global_iface_list(
11325 global
, reply
, reply_size
);
11326 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11327 reply_len
= wpa_supplicant_global_iface_interfaces(
11328 global
, buf
+ 10, reply
, reply_size
);
11330 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11331 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11334 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11335 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11338 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11339 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11340 #endif /* CONFIG_FST */
11341 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11342 wpa_supplicant_terminate_proc(global
);
11343 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11344 wpas_notify_suspend(global
);
11345 } else if (os_strcmp(buf
, "RESUME") == 0) {
11346 wpas_notify_resume(global
);
11347 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11348 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11350 if (global
->p2p_init_wpa_s
) {
11352 /* Check if P2P redirection would work for this
11354 return wpa_supplicant_ctrl_iface_process(
11355 global
->p2p_init_wpa_s
,
11358 #endif /* CONFIG_P2P */
11361 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11362 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11364 #ifndef CONFIG_NO_CONFIG_WRITE
11365 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11366 if (wpas_global_ctrl_iface_save_config(global
))
11368 #endif /* CONFIG_NO_CONFIG_WRITE */
11369 } else if (os_strcmp(buf
, "STATUS") == 0) {
11370 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11372 #ifdef CONFIG_MODULE_TESTS
11373 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11374 if (wpas_module_tests() < 0)
11376 #endif /* CONFIG_MODULE_TESTS */
11377 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11378 if (wpa_debug_reopen_file() < 0)
11381 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11385 if (reply_len
< 0) {
11386 os_memcpy(reply
, "FAIL\n", 5);
11390 *resp_len
= reply_len
;