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"
60 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
62 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
65 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
69 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
72 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
79 if (hwaddr_aton(pos
, addr
)) {
83 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
89 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
92 pos
= os_strchr(pos
, ' ');
97 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
98 os_free(wpa_s
->bssid_filter
);
99 wpa_s
->bssid_filter
= filter
;
100 wpa_s
->bssid_filter_count
= count
;
106 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
109 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
110 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
111 size_t count
= 0, ssid_count
= 0;
115 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
116 * SSID_SPEC ::= ssid <SSID_HEX>
117 * BSSID_SPEC ::= bssid <BSSID_HEX>
124 if (os_strncmp(pos
, "bssid ", 6) == 0) {
127 res
= hwaddr_aton2(pos
, addr
);
131 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
132 "BSSID value '%s'", pos
);
136 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
143 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
145 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
151 if (*end
== '\0' || *end
== ' ')
156 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
157 sizeof(struct wpa_ssid_value
));
165 if ((end
- pos
) & 0x01 ||
166 end
- pos
> 2 * SSID_MAX_LEN
||
167 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
168 (end
- pos
) / 2) < 0) {
171 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
172 "SSID value '%s'", pos
);
175 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
176 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
177 ssid
[ssid_count
].ssid
,
178 ssid
[ssid_count
].ssid_len
);
182 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
189 pos
= os_strchr(pos
, ' ');
194 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
195 os_free(wpa_s
->disallow_aps_bssid
);
196 wpa_s
->disallow_aps_bssid
= bssid
;
197 wpa_s
->disallow_aps_bssid_count
= count
;
199 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
200 os_free(wpa_s
->disallow_aps_ssid
);
201 wpa_s
->disallow_aps_ssid
= ssid
;
202 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
204 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
207 c
= wpa_s
->current_ssid
;
208 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
211 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
212 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
215 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
216 "because current AP was marked disallowed");
219 wpa_s
->sme
.prev_bssid_set
= 0;
220 #endif /* CONFIG_SME */
221 wpa_s
->reassociate
= 1;
222 wpa_s
->own_disconnect_req
= 1;
223 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
224 wpa_supplicant_req_scan(wpa_s
, 0, 0);
230 #ifndef CONFIG_NO_CONFIG_BLOBS
231 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
234 struct wpa_config_blob
*blob
;
237 pos
= os_strchr(pos
, ' ');
241 len
= os_strlen(pos
);
245 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
246 blob
= os_zalloc(sizeof(*blob
));
249 blob
->name
= os_strdup(name
);
250 blob
->data
= os_malloc(len
/ 2);
251 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
252 wpa_config_free_blob(blob
);
256 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
257 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
258 wpa_config_free_blob(blob
);
263 wpa_config_set_blob(wpa_s
->conf
, blob
);
267 #endif /* CONFIG_NO_CONFIG_BLOBS */
270 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
278 params
= os_strchr(cmd
, ' ');
279 os_free(wpa_s
->manual_sched_scan_freqs
);
282 pos
= os_strstr(params
, "freq=");
284 freqs
= freq_range_to_channel_list(wpa_s
,
287 wpa_s
->manual_sched_scan_freqs
= freqs
;
288 ret
= wpas_start_pno(wpa_s
);
290 ret
= wpas_stop_pno(wpa_s
);
296 static int wpas_ctrl_set_band(struct wpa_supplicant
*wpa_s
, char *band
)
298 union wpa_event_data event
;
300 if (os_strcmp(band
, "AUTO") == 0)
301 wpa_s
->setband
= WPA_SETBAND_AUTO
;
302 else if (os_strcmp(band
, "5G") == 0)
303 wpa_s
->setband
= WPA_SETBAND_5G
;
304 else if (os_strcmp(band
, "2G") == 0)
305 wpa_s
->setband
= WPA_SETBAND_2G
;
309 if (wpa_drv_setband(wpa_s
, wpa_s
->setband
) == 0) {
310 os_memset(&event
, 0, sizeof(event
));
311 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
312 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
313 wpa_supplicant_event(wpa_s
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
320 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant
*wpa_s
,
325 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
326 wpabuf_free(wpa_s
->lci
);
331 lci
= wpabuf_parse_bin(cmd
);
335 if (os_get_reltime(&wpa_s
->lci_time
)) {
340 wpabuf_free(wpa_s
->lci
);
348 wpas_ctrl_set_relative_rssi(struct wpa_supplicant
*wpa_s
, const char *cmd
)
352 if (os_strcmp(cmd
, "disable") == 0) {
353 wpa_s
->srp
.relative_rssi_set
= 0;
357 relative_rssi
= atoi(cmd
);
358 if (relative_rssi
< 0 || relative_rssi
> 100)
360 wpa_s
->srp
.relative_rssi
= relative_rssi
;
361 wpa_s
->srp
.relative_rssi_set
= 1;
366 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant
*wpa_s
,
372 /* <band>:adjust_value */
373 pos
= os_strchr(cmd
, ':');
377 adjust_rssi
= atoi(pos
);
378 if (adjust_rssi
< -100 || adjust_rssi
> 100)
381 if (os_strncmp(cmd
, "2G", 2) == 0)
382 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_2G
;
383 else if (os_strncmp(cmd
, "5G", 2) == 0)
384 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_5G
;
388 wpa_s
->srp
.relative_adjust_rssi
= adjust_rssi
;
394 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant
*wpa_s
,
397 struct wpabuf
*ric_ies
;
399 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
400 wpabuf_free(wpa_s
->ric_ies
);
401 wpa_s
->ric_ies
= NULL
;
405 ric_ies
= wpabuf_parse_bin(cmd
);
409 wpabuf_free(wpa_s
->ric_ies
);
410 wpa_s
->ric_ies
= ric_ies
;
416 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
422 value
= os_strchr(cmd
, ' ');
427 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
428 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
429 eapol_sm_configure(wpa_s
->eapol
,
430 atoi(value
), -1, -1, -1);
431 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
432 eapol_sm_configure(wpa_s
->eapol
,
433 -1, atoi(value
), -1, -1);
434 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
435 eapol_sm_configure(wpa_s
->eapol
,
436 -1, -1, atoi(value
), -1);
437 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
438 eapol_sm_configure(wpa_s
->eapol
,
439 -1, -1, -1, atoi(value
));
440 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
441 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
446 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
448 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
450 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
455 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
457 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
458 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
463 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
465 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
466 wpa_s
->wps_fragment_size
= atoi(value
);
467 #ifdef CONFIG_WPS_TESTING
468 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
470 val
= strtol(value
, NULL
, 0);
471 if (val
< 0 || val
> 0xff) {
473 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
474 "wps_version_number %ld", val
);
476 wps_version_number
= val
;
477 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
479 (wps_version_number
& 0xf0) >> 4,
480 wps_version_number
& 0x0f);
482 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
483 wps_testing_dummy_cred
= atoi(value
);
484 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
485 wps_testing_dummy_cred
);
486 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
487 wps_corrupt_pkhash
= atoi(value
);
488 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
490 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
491 if (value
[0] == '\0') {
492 wps_force_auth_types_in_use
= 0;
494 wps_force_auth_types
= strtol(value
, NULL
, 0);
495 wps_force_auth_types_in_use
= 1;
497 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
498 if (value
[0] == '\0') {
499 wps_force_encr_types_in_use
= 0;
501 wps_force_encr_types
= strtol(value
, NULL
, 0);
502 wps_force_encr_types_in_use
= 1;
504 #endif /* CONFIG_WPS_TESTING */
505 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
506 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
509 #ifdef CONFIG_TDLS_TESTING
510 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
511 tdls_testing
= strtol(value
, NULL
, 0);
512 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
513 #endif /* CONFIG_TDLS_TESTING */
514 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
515 int disabled
= atoi(value
);
516 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
518 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
520 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
522 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
523 #endif /* CONFIG_TDLS */
524 } else if (os_strcasecmp(cmd
, "pno") == 0) {
525 ret
= wpas_ctrl_pno(wpa_s
, value
);
526 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
527 int disabled
= atoi(value
);
528 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
531 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
532 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
533 if (os_strcmp(value
, "disable") == 0)
534 wpa_s
->set_sta_uapsd
= 0;
538 /* format: BE,BK,VI,VO;max SP Length */
540 pos
= os_strchr(value
, ',');
545 pos
= os_strchr(pos
, ',');
550 pos
= os_strchr(pos
, ',');
555 /* ignore max SP Length for now */
557 wpa_s
->set_sta_uapsd
= 1;
558 wpa_s
->sta_uapsd
= 0;
560 wpa_s
->sta_uapsd
|= BIT(0);
562 wpa_s
->sta_uapsd
|= BIT(1);
564 wpa_s
->sta_uapsd
|= BIT(2);
566 wpa_s
->sta_uapsd
|= BIT(3);
568 } else if (os_strcasecmp(cmd
, "ps") == 0) {
569 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
570 #ifdef CONFIG_WIFI_DISPLAY
571 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
572 int enabled
= !!atoi(value
);
573 if (enabled
&& !wpa_s
->global
->p2p
)
576 wifi_display_enable(wpa_s
->global
, enabled
);
577 #endif /* CONFIG_WIFI_DISPLAY */
578 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
579 ret
= set_bssid_filter(wpa_s
, value
);
580 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
581 ret
= set_disallow_aps(wpa_s
, value
);
582 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
583 wpa_s
->no_keep_alive
= !!atoi(value
);
585 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
586 os_free(wpa_s
->dpp_configurator_params
);
587 wpa_s
->dpp_configurator_params
= os_strdup(value
);
588 } else if (os_strcasecmp(cmd
, "dpp_init_max_tries") == 0) {
589 wpa_s
->dpp_init_max_tries
= atoi(value
);
590 } else if (os_strcasecmp(cmd
, "dpp_init_retry_time") == 0) {
591 wpa_s
->dpp_init_retry_time
= atoi(value
);
592 } else if (os_strcasecmp(cmd
, "dpp_resp_wait_time") == 0) {
593 wpa_s
->dpp_resp_wait_time
= atoi(value
);
594 } else if (os_strcasecmp(cmd
, "dpp_resp_max_tries") == 0) {
595 wpa_s
->dpp_resp_max_tries
= atoi(value
);
596 } else if (os_strcasecmp(cmd
, "dpp_resp_retry_time") == 0) {
597 wpa_s
->dpp_resp_retry_time
= atoi(value
);
598 #ifdef CONFIG_TESTING_OPTIONS
599 } else if (os_strcasecmp(cmd
, "dpp_pkex_own_mac_override") == 0) {
600 if (hwaddr_aton(value
, dpp_pkex_own_mac_override
))
602 } else if (os_strcasecmp(cmd
, "dpp_pkex_peer_mac_override") == 0) {
603 if (hwaddr_aton(value
, dpp_pkex_peer_mac_override
))
605 } else if (os_strcasecmp(cmd
, "dpp_pkex_ephemeral_key_override") == 0) {
606 size_t hex_len
= os_strlen(value
);
609 2 * sizeof(dpp_pkex_ephemeral_key_override
))
611 else if (hexstr2bin(value
, dpp_pkex_ephemeral_key_override
,
615 dpp_pkex_ephemeral_key_override_len
= hex_len
/ 2;
616 } else if (os_strcasecmp(cmd
, "dpp_protocol_key_override") == 0) {
617 size_t hex_len
= os_strlen(value
);
619 if (hex_len
> 2 * sizeof(dpp_protocol_key_override
))
621 else if (hexstr2bin(value
, dpp_protocol_key_override
,
625 dpp_protocol_key_override_len
= hex_len
/ 2;
626 } else if (os_strcasecmp(cmd
, "dpp_nonce_override") == 0) {
627 size_t hex_len
= os_strlen(value
);
629 if (hex_len
> 2 * sizeof(dpp_nonce_override
))
631 else if (hexstr2bin(value
, dpp_nonce_override
, hex_len
/ 2))
634 dpp_nonce_override_len
= hex_len
/ 2;
635 #endif /* CONFIG_TESTING_OPTIONS */
636 #endif /* CONFIG_DPP */
637 #ifdef CONFIG_TESTING_OPTIONS
638 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
639 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
640 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
641 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
643 if (wpa_s
->ap_iface
) {
644 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
645 wpa_s
->ext_eapol_frame_io
;
647 #endif /* CONFIG_AP */
648 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
649 wpa_s
->extra_roc_dur
= atoi(value
);
650 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
651 wpa_s
->test_failure
= atoi(value
);
652 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
653 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
654 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
655 wpa_s
->ignore_auth_resp
= !!atoi(value
);
656 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
657 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
658 wpa_drv_ignore_assoc_disallow(wpa_s
,
659 wpa_s
->ignore_assoc_disallow
);
660 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
661 wpa_s
->reject_btm_req_reason
= atoi(value
);
662 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
663 os_free(wpa_s
->get_pref_freq_list_override
);
665 wpa_s
->get_pref_freq_list_override
= NULL
;
667 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
668 } else if (os_strcasecmp(cmd
, "sae_commit_override") == 0) {
669 wpabuf_free(wpa_s
->sae_commit_override
);
670 if (value
[0] == '\0')
671 wpa_s
->sae_commit_override
= NULL
;
673 wpa_s
->sae_commit_override
= wpabuf_parse_bin(value
);
675 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
676 os_free(wpa_s
->dpp_config_obj_override
);
677 if (value
[0] == '\0')
678 wpa_s
->dpp_config_obj_override
= NULL
;
680 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
681 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
682 os_free(wpa_s
->dpp_discovery_override
);
683 if (value
[0] == '\0')
684 wpa_s
->dpp_discovery_override
= NULL
;
686 wpa_s
->dpp_discovery_override
= os_strdup(value
);
687 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
688 os_free(wpa_s
->dpp_groups_override
);
689 if (value
[0] == '\0')
690 wpa_s
->dpp_groups_override
= NULL
;
692 wpa_s
->dpp_groups_override
= os_strdup(value
);
693 } else if (os_strcasecmp(cmd
,
694 "dpp_ignore_netaccesskey_mismatch") == 0) {
695 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
696 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
697 dpp_test
= atoi(value
);
698 #endif /* CONFIG_DPP */
699 #endif /* CONFIG_TESTING_OPTIONS */
701 } else if (os_strcasecmp(cmd
, "disable_fils") == 0) {
702 wpa_s
->disable_fils
= !!atoi(value
);
703 wpa_drv_disable_fils(wpa_s
, wpa_s
->disable_fils
);
704 wpa_supplicant_set_default_scan_ies(wpa_s
);
705 #endif /* CONFIG_FILS */
706 #ifndef CONFIG_NO_CONFIG_BLOBS
707 } else if (os_strcmp(cmd
, "blob") == 0) {
708 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
709 #endif /* CONFIG_NO_CONFIG_BLOBS */
710 } else if (os_strcasecmp(cmd
, "setband") == 0) {
711 ret
= wpas_ctrl_set_band(wpa_s
, value
);
713 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
714 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
717 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
719 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
720 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
721 } else if (os_strcasecmp(cmd
, "oce") == 0) {
722 wpa_s
->conf
->oce
= atoi(value
);
723 if (wpa_s
->conf
->oce
) {
724 if ((wpa_s
->conf
->oce
& OCE_STA
) &&
725 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OCE_STA
))
726 wpa_s
->enable_oce
= OCE_STA
;
728 if ((wpa_s
->conf
->oce
& OCE_STA_CFON
) &&
730 WPA_DRIVER_FLAGS_OCE_STA_CFON
)) {
731 /* TODO: Need to add STA-CFON support */
732 wpa_printf(MSG_ERROR
,
733 "OCE STA-CFON feature is not yet supported");
737 wpa_s
->enable_oce
= 0;
739 wpa_supplicant_set_default_scan_ies(wpa_s
);
740 #endif /* CONFIG_MBO */
741 } else if (os_strcasecmp(cmd
, "lci") == 0) {
742 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
743 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
744 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
745 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
746 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
747 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
748 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
749 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
750 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
751 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
752 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
755 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
757 wpa_supplicant_update_config(wpa_s
);
764 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
765 char *cmd
, char *buf
, size_t buflen
)
769 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
771 if (os_strcmp(cmd
, "version") == 0) {
772 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
773 } else if (os_strcasecmp(cmd
, "country") == 0) {
774 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
775 res
= os_snprintf(buf
, buflen
, "%c%c",
776 wpa_s
->conf
->country
[0],
777 wpa_s
->conf
->country
[1]);
778 #ifdef CONFIG_WIFI_DISPLAY
779 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
781 if (wpa_s
->global
->p2p
== NULL
||
782 wpa_s
->global
->p2p_disabled
)
785 enabled
= wpa_s
->global
->wifi_display
;
786 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
787 #endif /* CONFIG_WIFI_DISPLAY */
788 #ifdef CONFIG_TESTING_GET_GTK
789 } else if (os_strcmp(cmd
, "gtk") == 0) {
790 if (wpa_s
->last_gtk_len
== 0)
792 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
793 wpa_s
->last_gtk_len
);
795 #endif /* CONFIG_TESTING_GET_GTK */
796 } else if (os_strcmp(cmd
, "tls_library") == 0) {
797 res
= tls_get_library_version(buf
, buflen
);
798 #ifdef CONFIG_TESTING_OPTIONS
799 } else if (os_strcmp(cmd
, "anonce") == 0) {
800 return wpa_snprintf_hex(buf
, buflen
,
801 wpa_sm_get_anonce(wpa_s
->wpa
),
803 #endif /* CONFIG_TESTING_OPTIONS */
805 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
808 if (os_snprintf_error(buflen
, res
))
814 #ifdef IEEE8021X_EAPOL
815 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
819 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
821 if (hwaddr_aton(addr
, bssid
)) {
822 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
827 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
828 rsn_preauth_deinit(wpa_s
->wpa
);
829 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
834 #endif /* IEEE8021X_EAPOL */
839 static int wpa_supplicant_ctrl_iface_tdls_discover(
840 struct wpa_supplicant
*wpa_s
, char *addr
)
845 if (hwaddr_aton(addr
, peer
)) {
846 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
847 "address '%s'", addr
);
851 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
854 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
855 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
857 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
863 static int wpa_supplicant_ctrl_iface_tdls_setup(
864 struct wpa_supplicant
*wpa_s
, char *addr
)
869 if (hwaddr_aton(addr
, peer
)) {
870 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
871 "address '%s'", addr
);
875 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
878 if ((wpa_s
->conf
->tdls_external_control
) &&
879 wpa_tdls_is_external_setup(wpa_s
->wpa
))
880 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
882 wpa_tdls_remove(wpa_s
->wpa
, peer
);
884 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
885 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
887 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
893 static int wpa_supplicant_ctrl_iface_tdls_teardown(
894 struct wpa_supplicant
*wpa_s
, char *addr
)
899 if (os_strcmp(addr
, "*") == 0) {
900 /* remove everyone */
901 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
902 wpa_tdls_teardown_peers(wpa_s
->wpa
);
906 if (hwaddr_aton(addr
, peer
)) {
907 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
908 "address '%s'", addr
);
912 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
915 if ((wpa_s
->conf
->tdls_external_control
) &&
916 wpa_tdls_is_external_setup(wpa_s
->wpa
))
917 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
919 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
920 ret
= wpa_tdls_teardown_link(
922 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
924 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
930 static int ctrl_iface_get_capability_tdls(
931 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
935 ret
= os_snprintf(buf
, buflen
, "%s\n",
936 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
938 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
939 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
940 if (os_snprintf_error(buflen
, ret
))
946 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
947 struct wpa_supplicant
*wpa_s
, char *cmd
)
950 struct hostapd_freq_params freq_params
;
954 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
956 "tdls_chanswitch: Only supported with external setup");
960 os_memset(&freq_params
, 0, sizeof(freq_params
));
962 pos
= os_strchr(cmd
, ' ');
967 oper_class
= strtol(pos
, &end
, 10);
970 "tdls_chanswitch: Invalid op class provided");
975 freq_params
.freq
= atoi(pos
);
976 if (freq_params
.freq
== 0) {
977 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
981 #define SET_FREQ_SETTING(str) \
983 const char *pos2 = os_strstr(pos, " " #str "="); \
985 pos2 += sizeof(" " #str "=") - 1; \
986 freq_params.str = atoi(pos2); \
990 SET_FREQ_SETTING(center_freq1
);
991 SET_FREQ_SETTING(center_freq2
);
992 SET_FREQ_SETTING(bandwidth
);
993 SET_FREQ_SETTING(sec_channel_offset
);
994 #undef SET_FREQ_SETTING
996 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
997 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
999 if (hwaddr_aton(cmd
, peer
)) {
1000 wpa_printf(MSG_DEBUG
,
1001 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1006 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1007 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1008 MAC2STR(peer
), oper_class
, freq_params
.freq
,
1009 freq_params
.center_freq1
, freq_params
.center_freq2
,
1010 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
1011 freq_params
.ht_enabled
? " HT" : "",
1012 freq_params
.vht_enabled
? " VHT" : "");
1014 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
1019 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1020 struct wpa_supplicant
*wpa_s
, char *cmd
)
1024 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
1025 wpa_printf(MSG_INFO
,
1026 "tdls_chanswitch: Only supported with external setup");
1030 if (hwaddr_aton(cmd
, peer
)) {
1031 wpa_printf(MSG_DEBUG
,
1032 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1037 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
1040 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
1044 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1045 struct wpa_supplicant
*wpa_s
, const char *addr
,
1046 char *buf
, size_t buflen
)
1049 const char *tdls_status
;
1052 if (hwaddr_aton(addr
, peer
)) {
1053 wpa_printf(MSG_DEBUG
,
1054 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1058 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
1061 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
1062 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
1063 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
1064 if (os_snprintf_error(buflen
, ret
))
1070 #endif /* CONFIG_TDLS */
1073 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1075 char *token
, *context
= NULL
;
1076 struct wmm_ac_ts_setup_params params
= {
1081 while ((token
= str_token(cmd
, " ", &context
))) {
1082 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1083 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1084 sscanf(token
, "nominal_msdu_size=%i",
1085 ¶ms
.nominal_msdu_size
) == 1 ||
1086 sscanf(token
, "mean_data_rate=%i",
1087 ¶ms
.mean_data_rate
) == 1 ||
1088 sscanf(token
, "min_phy_rate=%i",
1089 ¶ms
.minimum_phy_rate
) == 1 ||
1090 sscanf(token
, "sba=%i",
1091 ¶ms
.surplus_bandwidth_allowance
) == 1)
1094 if (os_strcasecmp(token
, "downlink") == 0) {
1095 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1096 } else if (os_strcasecmp(token
, "uplink") == 0) {
1097 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1098 } else if (os_strcasecmp(token
, "bidi") == 0) {
1099 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1100 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1101 params
.fixed_nominal_msdu
= 1;
1103 wpa_printf(MSG_DEBUG
,
1104 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1111 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1115 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1117 u8 tsid
= atoi(cmd
);
1119 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1123 #ifdef CONFIG_IEEE80211R
1124 static int wpa_supplicant_ctrl_iface_ft_ds(
1125 struct wpa_supplicant
*wpa_s
, char *addr
)
1127 u8 target_ap
[ETH_ALEN
];
1128 struct wpa_bss
*bss
;
1131 if (hwaddr_aton(addr
, target_ap
)) {
1132 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1133 "address '%s'", addr
);
1137 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1139 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1141 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1145 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1147 #endif /* CONFIG_IEEE80211R */
1151 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1154 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1156 u8 p2p_dev_addr
[ETH_ALEN
];
1157 #endif /* CONFIG_P2P */
1159 u8
*_p2p_dev_addr
= NULL
;
1160 #endif /* CONFIG_AP */
1162 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
1165 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1166 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1167 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1168 "P2P Device Address '%s'",
1172 _p2p_dev_addr
= p2p_dev_addr
;
1173 #endif /* CONFIG_P2P */
1174 } else if (hwaddr_aton(cmd
, bssid
)) {
1175 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1181 if (wpa_s
->ap_iface
)
1182 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1183 #endif /* CONFIG_AP */
1185 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1189 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1190 char *cmd
, char *buf
,
1193 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1197 pin
= os_strchr(cmd
, ' ');
1201 if (os_strcmp(cmd
, "any") == 0)
1203 else if (os_strcmp(cmd
, "get") == 0) {
1204 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1207 } else if (hwaddr_aton(cmd
, bssid
)) {
1208 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1214 if (wpa_s
->ap_iface
) {
1219 pos
= os_strchr(pin
, ' ');
1222 timeout
= atoi(pos
);
1226 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1227 buf
, buflen
, timeout
);
1229 #endif /* CONFIG_AP */
1232 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1236 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1237 if (os_snprintf_error(buflen
, ret
))
1242 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1247 /* Return the generated PIN */
1248 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1249 if (os_snprintf_error(buflen
, ret
))
1255 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1256 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1263 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1264 (u8
*) cmd
, os_strlen(cmd
));
1265 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1266 if (*pos
< '0' || *pos
> '9')
1270 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1274 if (len
!= 4 && len
!= 8) {
1275 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1281 unsigned int pin_val
;
1282 pin_val
= atoi(pin
);
1283 if (!wps_pin_valid(pin_val
)) {
1284 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1285 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1286 if (os_snprintf_error(buflen
, ret
))
1292 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1293 if (os_snprintf_error(buflen
, ret
))
1300 #ifdef CONFIG_WPS_NFC
1302 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1305 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1307 if (cmd
== NULL
|| cmd
[0] == '\0')
1309 else if (hwaddr_aton(cmd
, bssid
))
1312 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1317 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1318 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1325 pos
= os_strchr(cmd
, ' ');
1328 if (os_strcmp(cmd
, "WPS") == 0)
1330 else if (os_strcmp(cmd
, "NDEF") == 0)
1335 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1339 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1341 reply
[res
++] = '\n';
1350 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1351 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1357 if (os_strcmp(cmd
, "WPS") == 0)
1359 else if (os_strcmp(cmd
, "NDEF") == 0)
1364 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1368 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1370 reply
[res
++] = '\n';
1379 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1380 struct wpa_supplicant
*wpa_s
, char *pos
)
1386 int forced_freq
= 0;
1388 freq
= strstr(pos
, " freq=");
1392 forced_freq
= atoi(freq
);
1395 len
= os_strlen(pos
);
1400 buf
= wpabuf_alloc(len
);
1403 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1408 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1415 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1416 char *reply
, size_t max_len
,
1422 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1426 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1428 reply
[res
++] = '\n';
1438 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1439 char *reply
, size_t max_len
,
1445 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1447 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1451 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1453 reply
[res
++] = '\n';
1460 #endif /* CONFIG_P2P */
1463 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1464 char *cmd
, char *reply
,
1470 pos
= os_strchr(cmd
, ' ');
1475 if (os_strcmp(cmd
, "WPS") == 0)
1477 else if (os_strcmp(cmd
, "NDEF") == 0)
1482 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1485 return wpas_ctrl_nfc_get_handover_req_wps(
1486 wpa_s
, reply
, max_len
, ndef
);
1490 if (os_strcmp(pos
, "P2P-CR") == 0) {
1491 return wpas_ctrl_nfc_get_handover_req_p2p(
1492 wpa_s
, reply
, max_len
, ndef
);
1494 #endif /* CONFIG_P2P */
1500 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1501 char *reply
, size_t max_len
,
1502 int ndef
, int cr
, char *uuid
)
1507 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1511 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1513 reply
[res
++] = '\n';
1523 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1524 char *reply
, size_t max_len
,
1530 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1534 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1536 reply
[res
++] = '\n';
1543 #endif /* CONFIG_P2P */
1546 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1547 char *cmd
, char *reply
,
1553 pos
= os_strchr(cmd
, ' ');
1558 if (os_strcmp(cmd
, "WPS") == 0)
1560 else if (os_strcmp(cmd
, "NDEF") == 0)
1565 pos2
= os_strchr(pos
, ' ');
1568 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1571 return wpas_ctrl_nfc_get_handover_sel_wps(
1572 wpa_s
, reply
, max_len
, ndef
,
1573 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1577 if (os_strcmp(pos
, "P2P-CR") == 0) {
1578 return wpas_ctrl_nfc_get_handover_sel_p2p(
1579 wpa_s
, reply
, max_len
, ndef
, 0);
1582 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1583 return wpas_ctrl_nfc_get_handover_sel_p2p(
1584 wpa_s
, reply
, max_len
, ndef
, 1);
1586 #endif /* CONFIG_P2P */
1592 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1596 struct wpabuf
*req
, *sel
;
1598 char *pos
, *role
, *type
, *pos2
;
1601 int forced_freq
= 0;
1603 freq
= strstr(cmd
, " freq=");
1607 forced_freq
= atoi(freq
);
1609 #endif /* CONFIG_P2P */
1612 pos
= os_strchr(role
, ' ');
1614 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1620 pos
= os_strchr(type
, ' ');
1622 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1627 pos2
= os_strchr(pos
, ' ');
1629 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1634 len
= os_strlen(pos
);
1636 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1641 req
= wpabuf_alloc(len
);
1643 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1646 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1647 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1652 len
= os_strlen(pos2
);
1654 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1660 sel
= wpabuf_alloc(len
);
1662 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1666 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1667 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1673 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1674 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1676 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1677 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1679 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1681 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1683 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1684 #endif /* CONFIG_AP */
1686 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1688 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1689 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1691 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1693 #endif /* CONFIG_P2P */
1695 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1696 "reported: role=%s type=%s", role
, type
);
1703 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1708 #endif /* CONFIG_WPS_NFC */
1711 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1720 struct wps_new_ap_settings ap
;
1722 pin
= os_strchr(cmd
, ' ');
1727 if (hwaddr_aton(cmd
, bssid
)) {
1728 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1733 new_ssid
= os_strchr(pin
, ' ');
1734 if (new_ssid
== NULL
)
1735 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1738 new_auth
= os_strchr(new_ssid
, ' ');
1739 if (new_auth
== NULL
)
1743 new_encr
= os_strchr(new_auth
, ' ');
1744 if (new_encr
== NULL
)
1748 new_key
= os_strchr(new_encr
, ' ');
1749 if (new_key
== NULL
)
1753 os_memset(&ap
, 0, sizeof(ap
));
1754 ap
.ssid_hex
= new_ssid
;
1757 ap
.key_hex
= new_key
;
1758 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1763 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1764 char *cmd
, char *buf
,
1769 const char *pin_txt
;
1771 if (!wpa_s
->ap_iface
)
1774 pos
= os_strchr(cmd
, ' ');
1778 if (os_strcmp(cmd
, "disable") == 0) {
1779 wpas_wps_ap_pin_disable(wpa_s
);
1780 return os_snprintf(buf
, buflen
, "OK\n");
1783 if (os_strcmp(cmd
, "random") == 0) {
1785 timeout
= atoi(pos
);
1786 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1787 if (pin_txt
== NULL
)
1789 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1792 if (os_strcmp(cmd
, "get") == 0) {
1793 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1794 if (pin_txt
== NULL
)
1796 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1799 if (os_strcmp(cmd
, "set") == 0) {
1804 pos
= os_strchr(pos
, ' ');
1807 timeout
= atoi(pos
);
1809 if (os_strlen(pin
) > buflen
)
1811 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1813 return os_snprintf(buf
, buflen
, "%s", pin
);
1818 #endif /* CONFIG_AP */
1821 #ifdef CONFIG_WPS_ER
1822 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1825 char *uuid
= cmd
, *pin
, *pos
;
1826 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1827 pin
= os_strchr(uuid
, ' ');
1831 pos
= os_strchr(pin
, ' ');
1834 if (hwaddr_aton(pos
, addr_buf
) == 0)
1837 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1841 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1844 char *uuid
= cmd
, *pin
;
1845 pin
= os_strchr(uuid
, ' ');
1849 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1853 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1854 struct wpa_supplicant
*wpa_s
, char *cmd
)
1856 char *uuid
= cmd
, *id
;
1857 id
= os_strchr(uuid
, ' ');
1861 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1865 static int wpa_supplicant_ctrl_iface_wps_er_config(
1866 struct wpa_supplicant
*wpa_s
, char *cmd
)
1873 struct wps_new_ap_settings ap
;
1875 pin
= os_strchr(cmd
, ' ');
1880 new_ssid
= os_strchr(pin
, ' ');
1881 if (new_ssid
== NULL
)
1885 new_auth
= os_strchr(new_ssid
, ' ');
1886 if (new_auth
== NULL
)
1890 new_encr
= os_strchr(new_auth
, ' ');
1891 if (new_encr
== NULL
)
1895 new_key
= os_strchr(new_encr
, ' ');
1896 if (new_key
== NULL
)
1900 os_memset(&ap
, 0, sizeof(ap
));
1901 ap
.ssid_hex
= new_ssid
;
1904 ap
.key_hex
= new_key
;
1905 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1909 #ifdef CONFIG_WPS_NFC
1910 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1911 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1918 uuid
= os_strchr(cmd
, ' ');
1923 if (os_strcmp(cmd
, "WPS") == 0)
1925 else if (os_strcmp(cmd
, "NDEF") == 0)
1930 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1934 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1936 reply
[res
++] = '\n';
1943 #endif /* CONFIG_WPS_NFC */
1944 #endif /* CONFIG_WPS_ER */
1946 #endif /* CONFIG_WPS */
1949 #ifdef CONFIG_IBSS_RSN
1950 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1951 struct wpa_supplicant
*wpa_s
, char *addr
)
1955 if (hwaddr_aton(addr
, peer
)) {
1956 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1957 "address '%s'", addr
);
1961 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1964 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1966 #endif /* CONFIG_IBSS_RSN */
1969 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1972 #ifdef IEEE8021X_EAPOL
1975 struct wpa_ssid
*ssid
;
1977 pos
= os_strchr(rsp
, '-');
1982 pos
= os_strchr(pos
, ':');
1987 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1988 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1989 (u8
*) pos
, os_strlen(pos
));
1991 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1993 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1998 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
2000 #else /* IEEE8021X_EAPOL */
2001 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
2003 #endif /* IEEE8021X_EAPOL */
2007 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
2009 char *buf
, size_t buflen
)
2011 char *pos
, *end
, tmp
[30];
2012 int res
, verbose
, wps
, ret
;
2015 #endif /* CONFIG_HS20 */
2019 if (os_strcmp(params
, "-DRIVER") == 0)
2020 return wpa_drv_status(wpa_s
, buf
, buflen
);
2021 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
2022 wps
= os_strcmp(params
, "-WPS") == 0;
2025 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
2026 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2027 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2028 MAC2STR(wpa_s
->bssid
));
2029 if (os_snprintf_error(end
- pos
, ret
))
2032 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
2034 if (os_snprintf_error(end
- pos
, ret
))
2038 u8
*_ssid
= ssid
->ssid
;
2039 size_t ssid_len
= ssid
->ssid_len
;
2040 u8 ssid_buf
[SSID_MAX_LEN
];
2041 if (ssid_len
== 0) {
2042 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
2049 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
2050 wpa_ssid_txt(_ssid
, ssid_len
),
2052 if (os_snprintf_error(end
- pos
, ret
))
2056 if (wps
&& ssid
->passphrase
&&
2057 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
2058 (ssid
->mode
== WPAS_MODE_AP
||
2059 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
2060 ret
= os_snprintf(pos
, end
- pos
,
2063 if (os_snprintf_error(end
- pos
, ret
))
2068 ret
= os_snprintf(pos
, end
- pos
,
2071 if (os_snprintf_error(end
- pos
, ret
))
2076 switch (ssid
->mode
) {
2077 case WPAS_MODE_INFRA
:
2078 ret
= os_snprintf(pos
, end
- pos
,
2081 case WPAS_MODE_IBSS
:
2082 ret
= os_snprintf(pos
, end
- pos
,
2086 ret
= os_snprintf(pos
, end
- pos
,
2089 case WPAS_MODE_P2P_GO
:
2090 ret
= os_snprintf(pos
, end
- pos
,
2093 case WPAS_MODE_P2P_GROUP_FORMATION
:
2094 ret
= os_snprintf(pos
, end
- pos
,
2095 "mode=P2P GO - group "
2098 case WPAS_MODE_MESH
:
2099 ret
= os_snprintf(pos
, end
- pos
,
2106 if (os_snprintf_error(end
- pos
, ret
))
2112 if (wpa_s
->ap_iface
) {
2113 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2117 #endif /* CONFIG_AP */
2118 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2122 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2125 #endif /* CONFIG_AP */
2126 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2127 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2128 wpa_s
->sme
.sae
.group
);
2129 if (os_snprintf_error(end
- pos
, ret
))
2133 #endif /* CONFIG_SAE */
2134 #endif /* CONFIG_SME */
2135 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2136 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2137 if (os_snprintf_error(end
- pos
, ret
))
2142 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2143 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2144 if (os_snprintf_error(end
- pos
, ret
))
2150 if (wpa_s
->global
->p2p
) {
2151 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2152 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2153 if (os_snprintf_error(end
- pos
, ret
))
2157 #endif /* CONFIG_P2P */
2159 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2160 MAC2STR(wpa_s
->own_addr
));
2161 if (os_snprintf_error(end
- pos
, ret
))
2166 if (wpa_s
->current_bss
&&
2167 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2168 HS20_IE_VENDOR_TYPE
)) &&
2169 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2170 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2173 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2174 release
= rel_num
+ 1;
2176 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2177 if (os_snprintf_error(end
- pos
, ret
))
2182 if (wpa_s
->current_ssid
) {
2183 struct wpa_cred
*cred
;
2186 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2189 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2192 if (cred
->provisioning_sp
) {
2193 ret
= os_snprintf(pos
, end
- pos
,
2194 "provisioning_sp=%s\n",
2195 cred
->provisioning_sp
);
2196 if (os_snprintf_error(end
- pos
, ret
))
2205 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2206 struct wpabuf
*names
=
2207 wpa_s
->current_bss
->anqp
->domain_name
;
2208 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2210 if (domain_name_list_contains(
2211 names
, cred
->domain
[i
], 1))
2214 if (i
== cred
->num_domain
)
2215 i
= 0; /* show first entry by default */
2217 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2219 if (os_snprintf_error(end
- pos
, ret
))
2224 if (wpa_s
->current_bss
== NULL
||
2225 wpa_s
->current_bss
->anqp
== NULL
)
2228 res
= interworking_home_sp_cred(
2230 wpa_s
->current_bss
->anqp
->domain_name
);
2238 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2239 if (os_snprintf_error(end
- pos
, ret
))
2246 #endif /* CONFIG_HS20 */
2248 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2249 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2250 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2256 #ifdef CONFIG_MACSEC
2257 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2260 #endif /* CONFIG_MACSEC */
2262 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2266 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2267 if (os_snprintf_error(end
- pos
, ret
))
2270 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2274 ret
= os_snprintf(pos
, end
- pos
, "\n");
2275 if (os_snprintf_error(end
- pos
, ret
))
2280 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2287 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2288 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2289 if (os_snprintf_error(end
- pos
, ret
))
2293 #endif /* CONFIG_WPS */
2297 * Allow using the STATUS command with default behavior, say for debug,
2298 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2299 * events with STATUS-NO_EVENTS.
2301 if (os_strcmp(params
, "-NO_EVENTS")) {
2302 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2303 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2304 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2306 MAC2STR(wpa_s
->bssid
),
2307 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2308 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2309 wpa_s
->current_ssid
->ssid_len
) : "");
2310 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2311 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2312 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2313 "- connection to " MACSTR
2314 " completed %s [id=%d id_str=%s]",
2315 MAC2STR(wpa_s
->bssid
), "(auth)",
2316 ssid
? ssid
->id
: -1,
2317 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2320 #endif /* ANDROID */
2326 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2331 struct wpa_ssid
*ssid
;
2334 /* cmd: "<network id> <BSSID>" */
2335 pos
= os_strchr(cmd
, ' ');
2340 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2341 if (hwaddr_aton(pos
, bssid
)) {
2342 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2346 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2348 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2353 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2354 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2360 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2361 char *cmd
, char *buf
,
2365 struct wpa_blacklist
*e
;
2369 /* cmd: "BLACKLIST [<BSSID>]" */
2373 e
= wpa_s
->blacklist
;
2375 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2377 if (os_snprintf_error(end
- pos
, ret
))
2386 if (os_strncmp(cmd
, "clear", 5) == 0) {
2387 wpa_blacklist_clear(wpa_s
);
2388 os_memcpy(buf
, "OK\n", 3);
2392 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2393 if (hwaddr_aton(cmd
, bssid
)) {
2394 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2399 * Add the BSSID twice, so its count will be 2, causing it to be
2400 * skipped when processing scan results.
2402 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2405 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2408 os_memcpy(buf
, "OK\n", 3);
2413 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2414 char *cmd
, char *buf
,
2417 char *pos
, *end
, *stamp
;
2420 /* cmd: "LOG_LEVEL [<level>]" */
2424 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2426 debug_level_str(wpa_debug_level
),
2427 wpa_debug_timestamp
);
2428 if (os_snprintf_error(end
- pos
, ret
))
2437 stamp
= os_strchr(cmd
, ' ');
2440 while (*stamp
== ' ') {
2445 if (os_strlen(cmd
)) {
2446 int level
= str_to_debug_level(cmd
);
2449 wpa_debug_level
= level
;
2452 if (stamp
&& os_strlen(stamp
))
2453 wpa_debug_timestamp
= atoi(stamp
);
2455 os_memcpy(buf
, "OK\n", 3);
2460 static int wpa_supplicant_ctrl_iface_list_networks(
2461 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2463 char *pos
, *end
, *prev
;
2464 struct wpa_ssid
*ssid
;
2469 ret
= os_snprintf(pos
, end
- pos
,
2470 "network id / ssid / bssid / flags\n");
2471 if (os_snprintf_error(end
- pos
, ret
))
2475 ssid
= wpa_s
->conf
->ssid
;
2477 /* skip over ssids until we find next one */
2478 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2479 int last_id
= atoi(cmd
+ 8);
2480 if (last_id
!= -1) {
2481 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2489 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2491 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2492 if (os_snprintf_error(end
- pos
, ret
))
2495 if (ssid
->bssid_set
) {
2496 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2497 MAC2STR(ssid
->bssid
));
2499 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2501 if (os_snprintf_error(end
- pos
, ret
))
2504 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2505 ssid
== wpa_s
->current_ssid
?
2507 ssid
->disabled
? "[DISABLED]" : "",
2508 ssid
->disabled_until
.sec
?
2509 "[TEMP-DISABLED]" : "",
2510 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2512 if (os_snprintf_error(end
- pos
, ret
))
2515 ret
= os_snprintf(pos
, end
- pos
, "\n");
2516 if (os_snprintf_error(end
- pos
, ret
))
2527 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2530 ret
= os_snprintf(pos
, end
- pos
, "-");
2531 if (os_snprintf_error(end
- pos
, ret
))
2534 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2542 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2543 const u8
*ie
, size_t ie_len
)
2545 struct wpa_ie_data data
;
2549 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2550 if (os_snprintf_error(end
- pos
, ret
))
2554 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2555 ret
= os_snprintf(pos
, end
- pos
, "?]");
2556 if (os_snprintf_error(end
- pos
, ret
))
2563 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2564 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2565 pos
== start
? "" : "+");
2566 if (os_snprintf_error(end
- pos
, ret
))
2570 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2571 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2572 pos
== start
? "" : "+");
2573 if (os_snprintf_error(end
- pos
, ret
))
2577 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2578 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2579 pos
== start
? "" : "+");
2580 if (os_snprintf_error(end
- pos
, ret
))
2584 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2585 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2586 pos
== start
? "" : "+");
2587 if (os_snprintf_error(end
- pos
, ret
))
2591 #ifdef CONFIG_IEEE80211R
2592 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2593 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2594 pos
== start
? "" : "+");
2595 if (os_snprintf_error(end
- pos
, ret
))
2599 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2600 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2601 pos
== start
? "" : "+");
2602 if (os_snprintf_error(end
- pos
, ret
))
2606 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2607 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2608 pos
== start
? "" : "+");
2609 if (os_snprintf_error(end
- pos
, ret
))
2613 #endif /* CONFIG_IEEE80211R */
2614 #ifdef CONFIG_IEEE80211W
2615 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2616 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2617 pos
== start
? "" : "+");
2618 if (os_snprintf_error(end
- pos
, ret
))
2622 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2623 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2624 pos
== start
? "" : "+");
2625 if (os_snprintf_error(end
- pos
, ret
))
2629 #endif /* CONFIG_IEEE80211W */
2631 #ifdef CONFIG_SUITEB
2632 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2633 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2634 pos
== start
? "" : "+");
2635 if (os_snprintf_error(end
- pos
, ret
))
2639 #endif /* CONFIG_SUITEB */
2641 #ifdef CONFIG_SUITEB192
2642 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2643 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2644 pos
== start
? "" : "+");
2645 if (os_snprintf_error(end
- pos
, ret
))
2649 #endif /* CONFIG_SUITEB192 */
2652 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2653 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2654 pos
== start
? "" : "+");
2655 if (os_snprintf_error(end
- pos
, ret
))
2659 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2660 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2661 pos
== start
? "" : "+");
2662 if (os_snprintf_error(end
- pos
, ret
))
2666 #ifdef CONFIG_IEEE80211R
2667 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2668 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2669 pos
== start
? "" : "+");
2670 if (os_snprintf_error(end
- pos
, ret
))
2674 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2675 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2676 pos
== start
? "" : "+");
2677 if (os_snprintf_error(end
- pos
, ret
))
2681 #endif /* CONFIG_IEEE80211R */
2682 #endif /* CONFIG_FILS */
2685 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2686 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2687 pos
== start
? "" : "+");
2688 if (os_snprintf_error(end
- pos
, ret
))
2692 #endif /* CONFIG_OWE */
2695 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2696 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2697 pos
== start
? "" : "+");
2698 if (os_snprintf_error(end
- pos
, ret
))
2702 #endif /* CONFIG_DPP */
2704 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2705 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2706 pos
== start
? "" : "+");
2707 if (os_snprintf_error(end
- pos
, ret
))
2712 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2714 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2715 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2716 if (os_snprintf_error(end
- pos
, ret
))
2721 ret
= os_snprintf(pos
, end
- pos
, "]");
2722 if (os_snprintf_error(end
- pos
, ret
))
2731 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2732 char *pos
, char *end
,
2733 struct wpabuf
*wps_ie
)
2740 if (wps_is_selected_pbc_registrar(wps_ie
))
2742 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2744 else if (wps_is_selected_pin_registrar(wps_ie
))
2749 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2750 if (!os_snprintf_error(end
- pos
, ret
))
2752 wpabuf_free(wps_ie
);
2755 #endif /* CONFIG_WPS */
2758 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2759 char *pos
, char *end
,
2760 const struct wpa_bss
*bss
)
2763 struct wpabuf
*wps_ie
;
2764 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2765 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2766 #else /* CONFIG_WPS */
2768 #endif /* CONFIG_WPS */
2772 /* Format one result on one text line into a buffer. */
2773 static int wpa_supplicant_ctrl_iface_scan_result(
2774 struct wpa_supplicant
*wpa_s
,
2775 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2779 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
, *owe
;
2781 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2782 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2784 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2785 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2786 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2788 return 0; /* Do not show P2P listen discovery results here */
2793 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2794 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2795 if (os_snprintf_error(end
- pos
, ret
))
2798 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2800 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2801 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2803 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2806 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2808 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2809 osen_ie
, 2 + osen_ie
[1]);
2810 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
2812 ret
= os_snprintf(pos
, end
- pos
,
2813 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2814 if (os_snprintf_error(end
- pos
, ret
))
2818 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2819 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2820 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2821 if (os_snprintf_error(end
- pos
, ret
))
2826 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2827 if (os_snprintf_error(end
- pos
, ret
))
2831 if (bss_is_dmg(bss
)) {
2833 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2834 if (os_snprintf_error(end
- pos
, ret
))
2837 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2838 case IEEE80211_CAP_DMG_IBSS
:
2841 case IEEE80211_CAP_DMG_AP
:
2844 case IEEE80211_CAP_DMG_PBSS
:
2851 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2852 if (os_snprintf_error(end
- pos
, ret
))
2856 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2857 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2858 if (os_snprintf_error(end
- pos
, ret
))
2862 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2863 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2864 if (os_snprintf_error(end
- pos
, ret
))
2870 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2871 if (os_snprintf_error(end
- pos
, ret
))
2876 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2877 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2878 if (os_snprintf_error(end
- pos
, ret
))
2882 #endif /* CONFIG_HS20 */
2884 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2885 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2886 if (os_snprintf_error(end
- pos
, ret
))
2890 #endif /* CONFIG_FILS */
2892 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2893 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2894 if (os_snprintf_error(end
- pos
, ret
))
2898 #endif /* CONFIG_FST */
2900 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2901 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2902 if (os_snprintf_error(end
- pos
, ret
))
2906 ret
= os_snprintf(pos
, end
- pos
, "\n");
2907 if (os_snprintf_error(end
- pos
, ret
))
2915 static int wpa_supplicant_ctrl_iface_scan_results(
2916 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2919 struct wpa_bss
*bss
;
2924 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2926 if (os_snprintf_error(end
- pos
, ret
))
2930 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2931 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2933 if (ret
< 0 || ret
>= end
- pos
)
2944 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2945 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2947 char *pos
, ifname
[IFNAMSIZ
+ 1];
2951 pos
= os_strstr(cmd
, "ifname=");
2954 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2957 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2960 os_strlcpy(reply
, ifname
, max_len
);
2961 return os_strlen(ifname
);
2965 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2966 struct wpa_supplicant
*wpa_s
, char *cmd
)
2969 struct wpa_ssid
*ssid
;
2972 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2974 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2976 wpa_printf(MSG_DEBUG
,
2977 "CTRL_IFACE: Could not find network id=%d", id
);
2980 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2981 wpa_printf(MSG_DEBUG
,
2982 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2985 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2986 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2987 wpa_printf(MSG_ERROR
,
2988 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2993 * TODO: If necessary write our own group_add function,
2994 * for now we can reuse select_network
2996 wpa_supplicant_select_network(wpa_s
, ssid
);
3002 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3003 struct wpa_supplicant
*wpa_s
, char *cmd
)
3005 struct wpa_supplicant
*orig
;
3006 struct wpa_global
*global
;
3009 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
3011 global
= wpa_s
->global
;
3014 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3015 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
3021 wpa_printf(MSG_ERROR
,
3022 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3026 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
3027 wpa_printf(MSG_ERROR
,
3028 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3032 wpa_s
->reassociate
= 0;
3033 wpa_s
->disconnected
= 1;
3034 wpa_supplicant_cancel_sched_scan(wpa_s
);
3035 wpa_supplicant_cancel_scan(wpa_s
);
3038 * TODO: If necessary write our own group_remove function,
3039 * for now we can reuse deauthenticate
3041 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3043 if (wpa_s
->mesh_if_created
)
3044 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
3050 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3051 struct wpa_supplicant
*wpa_s
, char *cmd
)
3055 if (hwaddr_aton(cmd
, addr
) < 0)
3058 return wpas_mesh_peer_remove(wpa_s
, addr
);
3062 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3063 struct wpa_supplicant
*wpa_s
, char *cmd
)
3069 pos
= os_strstr(cmd
, " duration=");
3072 duration
= atoi(pos
+ 10);
3077 if (hwaddr_aton(cmd
, addr
))
3080 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
3083 #endif /* CONFIG_MESH */
3086 static int wpa_supplicant_ctrl_iface_select_network(
3087 struct wpa_supplicant
*wpa_s
, char *cmd
)
3090 struct wpa_ssid
*ssid
;
3093 /* cmd: "<network id>" or "any" */
3094 if (os_strncmp(cmd
, "any", 3) == 0) {
3095 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3099 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3101 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3103 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3104 "network id=%d", id
);
3107 if (ssid
->disabled
== 2) {
3108 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3109 "SELECT_NETWORK with persistent P2P group");
3114 pos
= os_strstr(cmd
, " freq=");
3116 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3118 os_free(wpa_s
->select_network_scan_freqs
);
3119 wpa_s
->select_network_scan_freqs
= freqs
;
3123 wpa_s
->scan_min_time
.sec
= 0;
3124 wpa_s
->scan_min_time
.usec
= 0;
3125 wpa_supplicant_select_network(wpa_s
, ssid
);
3131 static int wpa_supplicant_ctrl_iface_enable_network(
3132 struct wpa_supplicant
*wpa_s
, char *cmd
)
3135 struct wpa_ssid
*ssid
;
3137 /* cmd: "<network id>" or "all" */
3138 if (os_strcmp(cmd
, "all") == 0) {
3139 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3143 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3145 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3147 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3148 "network id=%d", id
);
3151 if (ssid
->disabled
== 2) {
3152 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3153 "ENABLE_NETWORK with persistent P2P group");
3157 if (os_strstr(cmd
, " no-connect")) {
3162 wpa_s
->scan_min_time
.sec
= 0;
3163 wpa_s
->scan_min_time
.usec
= 0;
3164 wpa_supplicant_enable_network(wpa_s
, ssid
);
3170 static int wpa_supplicant_ctrl_iface_disable_network(
3171 struct wpa_supplicant
*wpa_s
, char *cmd
)
3174 struct wpa_ssid
*ssid
;
3176 /* cmd: "<network id>" or "all" */
3177 if (os_strcmp(cmd
, "all") == 0) {
3178 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3182 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3184 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3186 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3187 "network id=%d", id
);
3190 if (ssid
->disabled
== 2) {
3191 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3192 "DISABLE_NETWORK with persistent P2P "
3197 wpa_supplicant_disable_network(wpa_s
, ssid
);
3203 static int wpa_supplicant_ctrl_iface_add_network(
3204 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3206 struct wpa_ssid
*ssid
;
3209 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3211 ssid
= wpa_supplicant_add_network(wpa_s
);
3215 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3216 if (os_snprintf_error(buflen
, ret
))
3222 static int wpa_supplicant_ctrl_iface_remove_network(
3223 struct wpa_supplicant
*wpa_s
, char *cmd
)
3226 struct wpa_ssid
*ssid
;
3229 /* cmd: "<network id>" or "all" */
3230 if (os_strcmp(cmd
, "all") == 0) {
3231 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3232 if (wpa_s
->sched_scanning
)
3233 wpa_supplicant_cancel_sched_scan(wpa_s
);
3235 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3236 if (wpa_s
->current_ssid
) {
3238 wpa_s
->sme
.prev_bssid_set
= 0;
3239 #endif /* CONFIG_SME */
3240 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3241 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3242 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3243 wpa_s
->own_disconnect_req
= 1;
3244 wpa_supplicant_deauthenticate(
3245 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3247 ssid
= wpa_s
->conf
->ssid
;
3249 struct wpa_ssid
*remove_ssid
= ssid
;
3252 if (wpa_s
->last_ssid
== remove_ssid
)
3253 wpa_s
->last_ssid
= NULL
;
3254 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3255 wpa_config_remove_network(wpa_s
->conf
, id
);
3261 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3263 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3265 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3270 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3271 "network id=%d", id
);
3278 static int wpa_supplicant_ctrl_iface_update_network(
3279 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3280 char *name
, char *value
)
3284 ret
= wpa_config_set(ssid
, name
, value
, 0);
3286 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3287 "variable '%s'", name
);
3291 return 0; /* No change to the previously configured value */
3293 if (os_strcmp(name
, "bssid") != 0 &&
3294 os_strcmp(name
, "bssid_hint") != 0 &&
3295 os_strcmp(name
, "priority") != 0) {
3296 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3298 if (wpa_s
->current_ssid
== ssid
||
3299 wpa_s
->current_ssid
== NULL
) {
3301 * Invalidate the EAP session cache if anything in the
3302 * current or previously used configuration changes.
3304 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3308 if ((os_strcmp(name
, "psk") == 0 &&
3309 value
[0] == '"' && ssid
->ssid_len
) ||
3310 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3311 wpa_config_update_psk(ssid
);
3312 else if (os_strcmp(name
, "priority") == 0)
3313 wpa_config_update_prio_list(wpa_s
->conf
);
3319 static int wpa_supplicant_ctrl_iface_set_network(
3320 struct wpa_supplicant
*wpa_s
, char *cmd
)
3322 int id
, ret
, prev_bssid_set
, prev_disabled
;
3323 struct wpa_ssid
*ssid
;
3325 u8 prev_bssid
[ETH_ALEN
];
3327 /* cmd: "<network id> <variable name> <value>" */
3328 name
= os_strchr(cmd
, ' ');
3333 value
= os_strchr(name
, ' ');
3339 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3341 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3342 (u8
*) value
, os_strlen(value
));
3344 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3346 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3351 prev_bssid_set
= ssid
->bssid_set
;
3352 prev_disabled
= ssid
->disabled
;
3353 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3354 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3357 (ssid
->bssid_set
!= prev_bssid_set
||
3358 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3359 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3361 if (prev_disabled
!= ssid
->disabled
&&
3362 (prev_disabled
== 2 || ssid
->disabled
== 2))
3363 wpas_notify_network_type_changed(wpa_s
, ssid
);
3369 static int wpa_supplicant_ctrl_iface_get_network(
3370 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3374 struct wpa_ssid
*ssid
;
3377 /* cmd: "<network id> <variable name>" */
3378 name
= os_strchr(cmd
, ' ');
3379 if (name
== NULL
|| buflen
== 0)
3384 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3387 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3389 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3394 value
= wpa_config_get_no_key(ssid
, name
);
3395 if (value
== NULL
) {
3396 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3397 "variable '%s'", name
);
3401 res
= os_strlcpy(buf
, value
, buflen
);
3402 if (res
>= buflen
) {
3413 static int wpa_supplicant_ctrl_iface_dup_network(
3414 struct wpa_supplicant
*wpa_s
, char *cmd
,
3415 struct wpa_supplicant
*dst_wpa_s
)
3417 struct wpa_ssid
*ssid_s
, *ssid_d
;
3418 char *name
, *id
, *value
;
3419 int id_s
, id_d
, ret
;
3421 /* cmd: "<src network id> <dst network id> <variable name>" */
3422 id
= os_strchr(cmd
, ' ');
3427 name
= os_strchr(id
, ' ');
3435 wpa_printf(MSG_DEBUG
,
3436 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3437 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3439 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3440 if (ssid_s
== NULL
) {
3441 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3442 "network id=%d", id_s
);
3446 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3447 if (ssid_d
== NULL
) {
3448 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3449 "network id=%d", id_d
);
3453 value
= wpa_config_get(ssid_s
, name
);
3454 if (value
== NULL
) {
3455 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3456 "variable '%s'", name
);
3460 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3469 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3470 char *buf
, size_t buflen
)
3473 struct wpa_cred
*cred
;
3478 ret
= os_snprintf(pos
, end
- pos
,
3479 "cred id / realm / username / domain / imsi\n");
3480 if (os_snprintf_error(end
- pos
, ret
))
3484 cred
= wpa_s
->conf
->cred
;
3486 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3487 cred
->id
, cred
->realm
? cred
->realm
: "",
3488 cred
->username
? cred
->username
: "",
3489 cred
->domain
? cred
->domain
[0] : "",
3490 cred
->imsi
? cred
->imsi
: "");
3491 if (os_snprintf_error(end
- pos
, ret
))
3502 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3503 char *buf
, size_t buflen
)
3505 struct wpa_cred
*cred
;
3508 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3510 cred
= wpa_config_add_cred(wpa_s
->conf
);
3514 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3516 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3517 if (os_snprintf_error(buflen
, ret
))
3523 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3524 struct wpa_cred
*cred
)
3526 struct wpa_ssid
*ssid
;
3531 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3536 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3537 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3541 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3543 /* Remove any network entry created based on the removed credential */
3544 ssid
= wpa_s
->conf
->ssid
;
3546 if (ssid
->parent_cred
== cred
) {
3549 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3550 "used the removed credential", ssid
->id
);
3551 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3552 if (os_snprintf_error(sizeof(str
), res
))
3553 str
[sizeof(str
) - 1] = '\0';
3555 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3564 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3568 struct wpa_cred
*cred
, *prev
;
3570 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3571 * "provisioning_sp=<FQDN> */
3572 if (os_strcmp(cmd
, "all") == 0) {
3573 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3574 cred
= wpa_s
->conf
->cred
;
3578 wpas_ctrl_remove_cred(wpa_s
, prev
);
3583 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3584 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3586 cred
= wpa_s
->conf
->cred
;
3592 for (i
= 0; i
< prev
->num_domain
; i
++) {
3593 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3596 wpas_ctrl_remove_cred(wpa_s
, prev
);
3604 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3605 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3607 cred
= wpa_s
->conf
->cred
;
3611 if (prev
->provisioning_sp
&&
3612 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3613 wpas_ctrl_remove_cred(wpa_s
, prev
);
3619 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3621 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3622 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3626 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3630 struct wpa_cred
*cred
;
3633 /* cmd: "<cred id> <variable name> <value>" */
3634 name
= os_strchr(cmd
, ' ');
3639 value
= os_strchr(name
, ' ');
3645 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3647 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3648 (u8
*) value
, os_strlen(value
));
3650 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3652 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3657 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3658 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3659 "variable '%s'", name
);
3663 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3669 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3670 char *cmd
, char *buf
,
3675 struct wpa_cred
*cred
;
3678 /* cmd: "<cred id> <variable name>" */
3679 name
= os_strchr(cmd
, ' ');
3685 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3688 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3690 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3695 value
= wpa_config_get_cred_no_key(cred
, name
);
3696 if (value
== NULL
) {
3697 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3702 res
= os_strlcpy(buf
, value
, buflen
);
3703 if (res
>= buflen
) {
3714 #ifndef CONFIG_NO_CONFIG_WRITE
3715 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3719 if (!wpa_s
->conf
->update_config
) {
3720 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3721 "to update configuration (update_config=0)");
3725 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3727 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3728 "update configuration");
3730 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3736 #endif /* CONFIG_NO_CONFIG_WRITE */
3739 struct cipher_info
{
3745 static const struct cipher_info ciphers
[] = {
3746 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3747 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3748 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3749 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3750 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3751 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3752 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3753 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3756 static const struct cipher_info ciphers_group_mgmt
[] = {
3757 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3758 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3759 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3760 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3764 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3765 struct wpa_driver_capa
*capa
,
3766 char *buf
, size_t buflen
)
3779 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3785 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3786 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3787 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3788 pos
== buf
? "" : " ",
3790 if (os_snprintf_error(end
- pos
, ret
))
3800 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3801 struct wpa_driver_capa
*capa
,
3802 char *buf
, size_t buflen
)
3815 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3821 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3822 if (capa
->enc
& ciphers
[i
].capa
) {
3823 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3824 pos
== buf
? "" : " ",
3826 if (os_snprintf_error(end
- pos
, ret
))
3836 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3837 struct wpa_driver_capa
*capa
,
3838 char *buf
, size_t buflen
)
3850 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3851 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3852 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3853 pos
== buf
? "" : " ",
3854 ciphers_group_mgmt
[i
].name
);
3855 if (os_snprintf_error(end
- pos
, ret
))
3865 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3866 struct wpa_driver_capa
*capa
,
3867 char *buf
, size_t buflen
)
3879 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3886 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3887 if (os_snprintf_error(end
- pos
, ret
))
3891 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3892 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3893 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3894 if (os_snprintf_error(end
- pos
, ret
))
3899 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3900 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3901 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3902 if (os_snprintf_error(end
- pos
, ret
))
3907 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3908 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3909 if (os_snprintf_error(end
- pos
, ret
))
3914 #ifdef CONFIG_SUITEB
3915 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3916 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3917 if (os_snprintf_error(end
- pos
, ret
))
3921 #endif /* CONFIG_SUITEB */
3922 #ifdef CONFIG_SUITEB192
3923 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3924 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3925 if (os_snprintf_error(end
- pos
, ret
))
3929 #endif /* CONFIG_SUITEB192 */
3931 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
3932 ret
= os_snprintf(pos
, end
- pos
, " OWE");
3933 if (os_snprintf_error(end
- pos
, ret
))
3937 #endif /* CONFIG_OWE */
3939 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
3940 ret
= os_snprintf(pos
, end
- pos
, " DPP");
3941 if (os_snprintf_error(end
- pos
, ret
))
3945 #endif /* CONFIG_DPP */
3947 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256
) {
3948 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA256");
3949 if (os_snprintf_error(end
- pos
, ret
))
3953 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384
) {
3954 ret
= os_snprintf(pos
, end
- pos
, " FILS-SHA384");
3955 if (os_snprintf_error(end
- pos
, ret
))
3959 #ifdef CONFIG_IEEE80211R
3960 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256
) {
3961 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA256");
3962 if (os_snprintf_error(end
- pos
, ret
))
3966 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384
) {
3967 ret
= os_snprintf(pos
, end
- pos
, " FT-FILS-SHA384");
3968 if (os_snprintf_error(end
- pos
, ret
))
3972 #endif /* CONFIG_IEEE80211R */
3973 #endif /* CONFIG_FILS */
3979 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3980 struct wpa_driver_capa
*capa
,
3981 char *buf
, size_t buflen
)
3993 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3999 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
4000 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
4001 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
4002 pos
== buf
? "" : " ");
4003 if (os_snprintf_error(end
- pos
, ret
))
4008 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
4009 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
4010 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
4011 pos
== buf
? "" : " ");
4012 if (os_snprintf_error(end
- pos
, ret
))
4021 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
4022 int res
, char *strict
,
4023 struct wpa_driver_capa
*capa
,
4024 char *buf
, size_t buflen
)
4036 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
4042 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
4043 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
4044 pos
== buf
? "" : " ");
4045 if (os_snprintf_error(end
- pos
, ret
))
4050 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
4051 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
4052 pos
== buf
? "" : " ");
4053 if (os_snprintf_error(end
- pos
, ret
))
4058 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
4059 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
4060 pos
== buf
? "" : " ");
4061 if (os_snprintf_error(end
- pos
, ret
))
4067 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
4068 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
4069 pos
== buf
? "" : " ");
4070 if (os_snprintf_error(end
- pos
, ret
))
4074 #endif /* CONFIG_SAE */
4077 if (wpa_is_fils_supported(wpa_s
)) {
4078 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITHOUT_PFS",
4079 pos
== buf
? "" : " ");
4080 if (os_snprintf_error(end
- pos
, ret
))
4085 #ifdef CONFIG_FILS_SK_PFS
4086 if (wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4087 ret
= os_snprintf(pos
, end
- pos
, "%sFILS_SK_WITH_PFS",
4088 pos
== buf
? "" : " ");
4089 if (os_snprintf_error(end
- pos
, ret
))
4093 #endif /* CONFIG_FILS_SK_PFS */
4094 #endif /* CONFIG_FILS */
4100 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
4101 struct wpa_driver_capa
*capa
,
4102 char *buf
, size_t buflen
)
4114 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
4120 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
4121 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
4122 pos
== buf
? "" : " ");
4123 if (os_snprintf_error(end
- pos
, ret
))
4128 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
4129 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
4130 pos
== buf
? "" : " ");
4131 if (os_snprintf_error(end
- pos
, ret
))
4137 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4138 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4139 pos
== buf
? "" : " ");
4140 if (os_snprintf_error(end
- pos
, ret
))
4144 #endif /* CONFIG_MESH */
4150 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4151 char *buf
, size_t buflen
)
4153 struct hostapd_channel_data
*chnl
;
4155 char *pos
, *end
, *hmode
;
4160 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4161 switch (wpa_s
->hw
.modes
[j
].mode
) {
4162 case HOSTAPD_MODE_IEEE80211B
:
4165 case HOSTAPD_MODE_IEEE80211G
:
4168 case HOSTAPD_MODE_IEEE80211A
:
4171 case HOSTAPD_MODE_IEEE80211AD
:
4177 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4178 if (os_snprintf_error(end
- pos
, ret
))
4181 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4182 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4183 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4185 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4186 if (os_snprintf_error(end
- pos
, ret
))
4190 ret
= os_snprintf(pos
, end
- pos
, "\n");
4191 if (os_snprintf_error(end
- pos
, ret
))
4200 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4201 char *buf
, size_t buflen
)
4203 struct hostapd_channel_data
*chnl
;
4205 char *pos
, *end
, *hmode
;
4210 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4211 switch (wpa_s
->hw
.modes
[j
].mode
) {
4212 case HOSTAPD_MODE_IEEE80211B
:
4215 case HOSTAPD_MODE_IEEE80211G
:
4218 case HOSTAPD_MODE_IEEE80211A
:
4221 case HOSTAPD_MODE_IEEE80211AD
:
4227 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4229 if (os_snprintf_error(end
- pos
, ret
))
4232 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4233 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4234 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4236 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4237 chnl
[i
].chan
, chnl
[i
].freq
,
4238 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4240 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4243 if (os_snprintf_error(end
- pos
, ret
))
4247 ret
= os_snprintf(pos
, end
- pos
, "\n");
4248 if (os_snprintf_error(end
- pos
, ret
))
4257 static int wpa_supplicant_ctrl_iface_get_capability(
4258 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4261 struct wpa_driver_capa capa
;
4267 /* Determine whether or not strict checking was requested */
4268 len
= os_strlcpy(field
, _field
, sizeof(field
));
4269 if (len
>= sizeof(field
))
4271 strict
= os_strchr(field
, ' ');
4272 if (strict
!= NULL
) {
4274 if (os_strcmp(strict
, "strict") != 0)
4278 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4279 field
, strict
? strict
: "");
4281 if (os_strcmp(field
, "eap") == 0) {
4282 return eap_get_names(buf
, buflen
);
4285 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4287 if (os_strcmp(field
, "pairwise") == 0)
4288 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4291 if (os_strcmp(field
, "group") == 0)
4292 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4295 if (os_strcmp(field
, "group_mgmt") == 0)
4296 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4299 if (os_strcmp(field
, "key_mgmt") == 0)
4300 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4303 if (os_strcmp(field
, "proto") == 0)
4304 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4307 if (os_strcmp(field
, "auth_alg") == 0)
4308 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4309 &capa
, buf
, buflen
);
4311 if (os_strcmp(field
, "modes") == 0)
4312 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4315 if (os_strcmp(field
, "channels") == 0)
4316 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4318 if (os_strcmp(field
, "freq") == 0)
4319 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4322 if (os_strcmp(field
, "tdls") == 0)
4323 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4324 #endif /* CONFIG_TDLS */
4327 if (os_strcmp(field
, "erp") == 0) {
4328 res
= os_snprintf(buf
, buflen
, "ERP");
4329 if (os_snprintf_error(buflen
, res
))
4333 #endif /* CONFIG_EPR */
4336 if (os_strcmp(field
, "fips") == 0) {
4337 res
= os_snprintf(buf
, buflen
, "FIPS");
4338 if (os_snprintf_error(buflen
, res
))
4342 #endif /* CONFIG_FIPS */
4345 if (os_strcmp(field
, "acs") == 0) {
4346 res
= os_snprintf(buf
, buflen
, "ACS");
4347 if (os_snprintf_error(buflen
, res
))
4351 #endif /* CONFIG_ACS */
4354 if (os_strcmp(field
, "fils") == 0) {
4355 #ifdef CONFIG_FILS_SK_PFS
4356 if (wpa_is_fils_supported(wpa_s
) &&
4357 wpa_is_fils_sk_pfs_supported(wpa_s
)) {
4358 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4359 if (os_snprintf_error(buflen
, res
))
4363 #endif /* CONFIG_FILS_SK_PFS */
4365 if (wpa_is_fils_supported(wpa_s
)) {
4366 res
= os_snprintf(buf
, buflen
, "FILS");
4367 if (os_snprintf_error(buflen
, res
))
4372 #endif /* CONFIG_FILS */
4374 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4381 #ifdef CONFIG_INTERWORKING
4382 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4383 struct wpabuf
*data
)
4393 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4394 if (os_snprintf_error(end
- pos
, ret
))
4398 d
= wpabuf_head_u8(data
);
4399 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4400 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4401 if (os_snprintf_error(end
- pos
, ret
))
4406 ret
= os_snprintf(pos
, end
- pos
, "\n");
4407 if (os_snprintf_error(end
- pos
, ret
))
4413 #endif /* CONFIG_INTERWORKING */
4417 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4420 const u8
*ie
, *ie_end
;
4424 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4427 ie_end
= ie
+ 2 + ie
[1];
4429 if (ie_end
- ie
< 2)
4432 info
= WPA_GET_LE16(ie
);
4434 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4435 if (os_snprintf_error(end
- pos
, ret
))
4439 if (info
& BIT(7)) {
4440 /* Cache Identifier Included */
4441 if (ie_end
- ie
< 2)
4443 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4445 if (os_snprintf_error(end
- pos
, ret
))
4451 if (info
& BIT(8)) {
4452 /* HESSID Included */
4453 if (ie_end
- ie
< ETH_ALEN
)
4455 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4457 if (os_snprintf_error(end
- pos
, ret
))
4463 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4465 if (ie_end
- ie
< realms
* 2)
4467 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4468 if (os_snprintf_error(end
- pos
, ret
))
4472 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4477 ret
= os_snprintf(pos
, end
- pos
, "\n");
4478 if (os_snprintf_error(end
- pos
, ret
))
4485 #endif /* CONFIG_FILS */
4488 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4489 unsigned long mask
, char *buf
, size_t buflen
)
4494 const u8
*ie
, *ie2
, *osen_ie
, *mesh
, *owe
;
4499 if (mask
& WPA_BSS_MASK_ID
) {
4500 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4501 if (os_snprintf_error(end
- pos
, ret
))
4506 if (mask
& WPA_BSS_MASK_BSSID
) {
4507 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4508 MAC2STR(bss
->bssid
));
4509 if (os_snprintf_error(end
- pos
, ret
))
4514 if (mask
& WPA_BSS_MASK_FREQ
) {
4515 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4516 if (os_snprintf_error(end
- pos
, ret
))
4521 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4522 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4524 if (os_snprintf_error(end
- pos
, ret
))
4529 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4530 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4532 if (os_snprintf_error(end
- pos
, ret
))
4537 if (mask
& WPA_BSS_MASK_QUAL
) {
4538 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4539 if (os_snprintf_error(end
- pos
, ret
))
4544 if (mask
& WPA_BSS_MASK_NOISE
) {
4545 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4546 if (os_snprintf_error(end
- pos
, ret
))
4551 if (mask
& WPA_BSS_MASK_LEVEL
) {
4552 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4553 if (os_snprintf_error(end
- pos
, ret
))
4558 if (mask
& WPA_BSS_MASK_TSF
) {
4559 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4560 (unsigned long long) bss
->tsf
);
4561 if (os_snprintf_error(end
- pos
, ret
))
4566 if (mask
& WPA_BSS_MASK_AGE
) {
4567 struct os_reltime now
;
4569 os_get_reltime(&now
);
4570 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4571 (int) (now
.sec
- bss
->last_update
.sec
));
4572 if (os_snprintf_error(end
- pos
, ret
))
4577 if (mask
& WPA_BSS_MASK_IE
) {
4578 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4579 if (os_snprintf_error(end
- pos
, ret
))
4583 ie
= (const u8
*) (bss
+ 1);
4584 for (i
= 0; i
< bss
->ie_len
; i
++) {
4585 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4586 if (os_snprintf_error(end
- pos
, ret
))
4591 ret
= os_snprintf(pos
, end
- pos
, "\n");
4592 if (os_snprintf_error(end
- pos
, ret
))
4597 if (mask
& WPA_BSS_MASK_FLAGS
) {
4598 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4599 if (os_snprintf_error(end
- pos
, ret
))
4603 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4605 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4607 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4609 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4611 pos
= wpa_supplicant_ie_txt(pos
, end
,
4612 mesh
? "RSN" : "WPA2", ie2
,
4614 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4616 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4617 osen_ie
, 2 + osen_ie
[1]);
4618 owe
= wpa_bss_get_vendor_ie(bss
, OWE_IE_VENDOR_TYPE
);
4622 ie2
? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4623 if (os_snprintf_error(end
- pos
, ret
))
4627 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4628 if (!ie
&& !ie2
&& !osen_ie
&&
4629 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4630 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4631 if (os_snprintf_error(end
- pos
, ret
))
4637 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4638 if (os_snprintf_error(end
- pos
, ret
))
4643 if (bss_is_dmg(bss
)) {
4645 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4646 if (os_snprintf_error(end
- pos
, ret
))
4649 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4650 case IEEE80211_CAP_DMG_IBSS
:
4653 case IEEE80211_CAP_DMG_AP
:
4656 case IEEE80211_CAP_DMG_PBSS
:
4663 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4664 if (os_snprintf_error(end
- pos
, ret
))
4668 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4669 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4670 if (os_snprintf_error(end
- pos
, ret
))
4674 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4675 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4676 if (os_snprintf_error(end
- pos
, ret
))
4681 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4682 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4683 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4684 if (os_snprintf_error(end
- pos
, ret
))
4689 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4690 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4691 if (os_snprintf_error(end
- pos
, ret
))
4695 #endif /* CONFIG_HS20 */
4697 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4698 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4699 if (os_snprintf_error(end
- pos
, ret
))
4703 #endif /* CONFIG_FILS */
4705 ret
= os_snprintf(pos
, end
- pos
, "\n");
4706 if (os_snprintf_error(end
- pos
, ret
))
4711 if (mask
& WPA_BSS_MASK_SSID
) {
4712 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4713 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4714 if (os_snprintf_error(end
- pos
, ret
))
4720 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4721 ie
= (const u8
*) (bss
+ 1);
4722 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4723 if (ret
>= end
- pos
)
4728 #endif /* CONFIG_WPS */
4731 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4732 ie
= (const u8
*) (bss
+ 1);
4733 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4734 if (ret
>= end
- pos
)
4739 #endif /* CONFIG_P2P */
4741 #ifdef CONFIG_WIFI_DISPLAY
4742 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4744 ie
= (const u8
*) (bss
+ 1);
4745 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4746 WFD_IE_VENDOR_TYPE
);
4748 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4749 if (os_snprintf_error(end
- pos
, ret
)) {
4755 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4760 ret
= os_snprintf(pos
, end
- pos
, "\n");
4761 if (os_snprintf_error(end
- pos
, ret
))
4766 #endif /* CONFIG_WIFI_DISPLAY */
4768 #ifdef CONFIG_INTERWORKING
4769 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4770 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4771 struct wpa_bss_anqp_elem
*elem
;
4773 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4774 anqp
->capability_list
);
4775 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4777 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4778 anqp
->network_auth_type
);
4779 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4780 anqp
->roaming_consortium
);
4781 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4782 anqp
->ip_addr_type_availability
);
4783 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4785 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4786 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4788 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4789 anqp
->fils_realm_info
);
4791 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4792 anqp
->hs20_capability_list
);
4793 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4794 anqp
->hs20_operator_friendly_name
);
4795 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4796 anqp
->hs20_wan_metrics
);
4797 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4798 anqp
->hs20_connection_capability
);
4799 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4800 anqp
->hs20_operating_class
);
4801 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4802 anqp
->hs20_osu_providers_list
);
4803 pos
= anqp_add_hex(pos
, end
, "hs20_operator_icon_metadata",
4804 anqp
->hs20_operator_icon_metadata
);
4805 #endif /* CONFIG_HS20 */
4807 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4808 struct wpa_bss_anqp_elem
, list
) {
4811 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4813 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4816 #endif /* CONFIG_INTERWORKING */
4819 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4820 ie
= (const u8
*) (bss
+ 1);
4821 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4822 if (ret
>= end
- pos
)
4827 #endif /* CONFIG_MESH */
4829 if (mask
& WPA_BSS_MASK_SNR
) {
4830 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4831 if (os_snprintf_error(end
- pos
, ret
))
4836 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4837 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4838 bss
->est_throughput
);
4839 if (os_snprintf_error(end
- pos
, ret
))
4845 if (mask
& WPA_BSS_MASK_FST
) {
4846 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4847 if (ret
< 0 || ret
>= end
- pos
)
4851 #endif /* CONFIG_FST */
4853 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4854 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4855 bss
->last_update_idx
);
4856 if (os_snprintf_error(end
- pos
, ret
))
4861 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4862 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4863 if (os_snprintf_error(end
- pos
, ret
))
4867 ie
= (const u8
*) (bss
+ 1);
4869 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4870 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4871 if (os_snprintf_error(end
- pos
, ret
))
4876 ret
= os_snprintf(pos
, end
- pos
, "\n");
4877 if (os_snprintf_error(end
- pos
, ret
))
4883 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4884 ret
= print_fils_indication(bss
, pos
, end
);
4889 #endif /* CONFIG_FILS */
4891 if (mask
& WPA_BSS_MASK_DELIM
) {
4892 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4893 if (os_snprintf_error(end
- pos
, ret
))
4902 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4903 const char *cmd
, char *buf
,
4908 struct wpa_bss
*bss
;
4909 struct wpa_bss
*bsslast
= NULL
;
4910 struct dl_list
*next
;
4913 char *ctmp
, *end
= buf
+ buflen
;
4914 unsigned long mask
= WPA_BSS_MASK_ALL
;
4916 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4917 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4918 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4920 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4922 } else { /* N1-N2 */
4923 unsigned int id1
, id2
;
4925 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4926 wpa_printf(MSG_INFO
, "Wrong BSS range "
4931 if (*(cmd
+ 6) == '-')
4934 id1
= atoi(cmd
+ 6);
4936 if (*ctmp
>= '0' && *ctmp
<= '9')
4939 id2
= (unsigned int) -1;
4940 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4941 if (id2
== (unsigned int) -1)
4942 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4946 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4947 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4948 struct wpa_bss
*tmp
= bss
;
4950 next
= tmp
->list_id
.next
;
4951 if (next
== &wpa_s
->bss_id
)
4953 tmp
= dl_list_entry(
4954 next
, struct wpa_bss
,
4963 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4964 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4965 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4966 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4967 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4969 bss
= wpa_bss_get_id(wpa_s
, i
);
4970 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4972 bss
= wpa_bss_get_id(wpa_s
, i
);
4974 next
= bss
->list_id
.next
;
4975 if (next
== &wpa_s
->bss_id
)
4978 bss
= dl_list_entry(next
, struct wpa_bss
,
4981 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
4982 bss
= wpa_s
->current_bss
;
4984 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4985 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4986 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4989 #endif /* CONFIG_P2P */
4990 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4991 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4993 struct wpa_bss
*tmp
;
4996 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
5005 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
5006 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
5008 mask
= WPA_BSS_MASK_ALL
;
5014 if (bsslast
== NULL
)
5017 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
5021 if (bss
== bsslast
) {
5022 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
5023 (bss
== dl_list_last(&wpa_s
->bss_id
,
5024 struct wpa_bss
, list_id
))) {
5027 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
5029 if (os_snprintf_error(end
- buf
+ 5, res
)) {
5030 wpa_printf(MSG_DEBUG
,
5031 "Could not add end delim");
5036 next
= bss
->list_id
.next
;
5037 if (next
== &wpa_s
->bss_id
)
5039 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
5040 } while (bss
&& len
);
5046 static int wpa_supplicant_ctrl_iface_ap_scan(
5047 struct wpa_supplicant
*wpa_s
, char *cmd
)
5049 int ap_scan
= atoi(cmd
);
5050 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
5054 static int wpa_supplicant_ctrl_iface_scan_interval(
5055 struct wpa_supplicant
*wpa_s
, char *cmd
)
5057 int scan_int
= atoi(cmd
);
5058 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
5062 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5063 struct wpa_supplicant
*wpa_s
, char *cmd
)
5065 int expire_age
= atoi(cmd
);
5066 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
5070 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5071 struct wpa_supplicant
*wpa_s
, char *cmd
)
5073 int expire_count
= atoi(cmd
);
5074 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
5078 static void wpa_supplicant_ctrl_iface_bss_flush(
5079 struct wpa_supplicant
*wpa_s
, char *cmd
)
5081 int flush_age
= atoi(cmd
);
5084 wpa_bss_flush(wpa_s
);
5086 wpa_bss_flush_by_age(wpa_s
, flush_age
);
5090 #ifdef CONFIG_TESTING_OPTIONS
5091 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
5093 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
5094 /* MLME-DELETEKEYS.request */
5095 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
5096 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
5097 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
5098 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
5099 #ifdef CONFIG_IEEE80211W
5100 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
5101 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
5102 #endif /* CONFIG_IEEE80211W */
5104 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
5106 /* MLME-SETPROTECTION.request(None) */
5107 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
5108 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
5109 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
5110 wpa_sm_drop_sa(wpa_s
->wpa
);
5112 #endif /* CONFIG_TESTING_OPTIONS */
5115 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
5118 #ifdef CONFIG_NO_SCAN_PROCESSING
5120 #else /* CONFIG_NO_SCAN_PROCESSING */
5122 struct wpa_bss
*bss
;
5123 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5125 if (hwaddr_aton(addr
, bssid
)) {
5126 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
5127 "address '%s'", addr
);
5131 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
5134 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
5135 "configuration known for the target AP");
5139 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
5141 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
5147 * TODO: Find best network configuration block from configuration to
5148 * allow roaming to other networks
5151 wpa_s
->reassociate
= 1;
5152 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5155 #endif /* CONFIG_NO_SCAN_PROCESSING */
5160 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5162 unsigned int timeout
= atoi(cmd
);
5163 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5164 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5165 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5167 unsigned int search_delay
;
5168 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5172 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5173 wpa_dbg(wpa_s
, MSG_INFO
,
5174 "Reject P2P_FIND since interface is disabled");
5177 if (os_strstr(cmd
, "type=social"))
5178 type
= P2P_FIND_ONLY_SOCIAL
;
5179 else if (os_strstr(cmd
, "type=progressive"))
5180 type
= P2P_FIND_PROGRESSIVE
;
5182 pos
= os_strstr(cmd
, "dev_id=");
5185 if (hwaddr_aton(pos
, dev_id
))
5190 pos
= os_strstr(cmd
, "dev_type=");
5193 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5195 _dev_type
= dev_type
;
5198 pos
= os_strstr(cmd
, "delay=");
5201 search_delay
= atoi(pos
);
5203 search_delay
= wpas_p2p_search_delay(wpa_s
);
5205 pos
= os_strstr(cmd
, "freq=");
5213 /* Must be searched for last, because it adds nul termination */
5214 pos
= os_strstr(cmd
, " seek=");
5217 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5220 _seek
[seek_count
++] = pos
;
5222 term
= os_strchr(pos
, ' ');
5226 pos
= os_strstr(term
+ 1, "seek=");
5230 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5235 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5236 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5240 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5242 const char *last
= NULL
;
5247 /* Expected predefined CPT names delimited by ':' */
5248 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5249 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5250 wpa_printf(MSG_ERROR
,
5251 "P2PS: CPT name list is too long, expected up to %d names",
5252 P2PS_FEATURE_CAPAB_CPT_MAX
);
5257 token_len
= last
- token
;
5259 if (token_len
== 3 &&
5260 os_memcmp(token
, "UDP", token_len
) == 0) {
5261 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5262 } else if (token_len
== 3 &&
5263 os_memcmp(token
, "MAC", token_len
) == 0) {
5264 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5266 wpa_printf(MSG_ERROR
,
5267 "P2PS: Unsupported CPT name '%s'", token
);
5272 if (isblank((unsigned char) *last
)) {
5282 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5284 struct p2ps_provision
*p2ps_prov
;
5286 size_t info_len
= 0;
5288 u8 role
= P2PS_SETUP_NONE
;
5289 long long unsigned val
;
5292 pos
= os_strstr(cmd
, "info=");
5295 info_len
= os_strlen(pos
);
5298 info
= os_malloc(info_len
+ 1);
5300 info_len
= utf8_unescape(pos
, info_len
,
5301 info
, info_len
+ 1);
5307 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5308 if (p2ps_prov
== NULL
) {
5314 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5315 p2ps_prov
->info
[info_len
] = '\0';
5319 pos
= os_strstr(cmd
, "status=");
5321 p2ps_prov
->status
= atoi(pos
+ 7);
5323 p2ps_prov
->status
= -1;
5325 pos
= os_strstr(cmd
, "adv_id=");
5326 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5328 p2ps_prov
->adv_id
= val
;
5330 pos
= os_strstr(cmd
, "method=");
5332 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5334 p2ps_prov
->method
= 0;
5336 pos
= os_strstr(cmd
, "session=");
5337 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5339 p2ps_prov
->session_id
= val
;
5341 pos
= os_strstr(cmd
, "adv_mac=");
5342 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5345 pos
= os_strstr(cmd
, "session_mac=");
5346 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5349 pos
= os_strstr(cmd
, "cpt=");
5351 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5352 p2ps_prov
->cpt_priority
))
5355 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5358 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5359 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5361 /* force conncap with tstCap (no sanity checks) */
5362 pos
= os_strstr(cmd
, "tstCap=");
5364 role
= strtol(pos
+ 7, NULL
, 16);
5366 pos
= os_strstr(cmd
, "role=");
5368 role
= strtol(pos
+ 5, NULL
, 16);
5369 if (role
!= P2PS_SETUP_CLIENT
&&
5370 role
!= P2PS_SETUP_GROUP_OWNER
)
5371 role
= P2PS_SETUP_NONE
;
5374 p2ps_prov
->role
= role
;
5384 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5387 struct p2ps_provision
*p2ps_prov
;
5390 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5392 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5394 if (hwaddr_aton(cmd
, addr
))
5401 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5405 if (p2ps_prov
->status
< 0) {
5410 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5415 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5418 struct p2ps_provision
*p2ps_prov
;
5421 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5422 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5425 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5426 if (hwaddr_aton(cmd
, addr
))
5433 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5437 p2ps_prov
->pd_seeker
= 1;
5439 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5444 static int parse_freq(int chwidth
, int freq2
)
5449 return VHT_CHANWIDTH_80P80MHZ
;
5455 return VHT_CHANWIDTH_USE_HT
;
5457 return VHT_CHANWIDTH_80MHZ
;
5459 return VHT_CHANWIDTH_160MHZ
;
5461 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5468 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5469 char *buf
, size_t buflen
)
5474 enum p2p_wps_method wps_method
;
5477 int persistent_group
, persistent_id
= -1;
5484 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5485 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5486 size_t group_ssid_len
= 0;
5488 if (!wpa_s
->global
->p2p_init_wpa_s
)
5490 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5491 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5492 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5493 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5496 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5497 * [persistent|persistent=<network id>]
5498 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5499 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5501 if (hwaddr_aton(cmd
, addr
))
5509 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5510 pos2
= os_strstr(pos
, " persistent=");
5512 struct wpa_ssid
*ssid
;
5513 persistent_id
= atoi(pos2
+ 12);
5514 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5515 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5516 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5517 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5518 "SSID id=%d for persistent P2P group (GO)",
5523 join
= os_strstr(pos
, " join") != NULL
;
5524 auth
= os_strstr(pos
, " auth") != NULL
;
5525 automatic
= os_strstr(pos
, " auto") != NULL
;
5526 pd
= os_strstr(pos
, " provdisc") != NULL
;
5527 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5528 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5531 pos2
= os_strstr(pos
, " go_intent=");
5534 go_intent
= atoi(pos2
);
5535 if (go_intent
< 0 || go_intent
> 15)
5539 pos2
= os_strstr(pos
, " freq=");
5547 pos2
= os_strstr(pos
, " freq2=");
5549 freq2
= atoi(pos2
+ 7);
5551 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5553 chwidth
= atoi(pos2
+ 18);
5555 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5556 if (max_oper_chwidth
< 0)
5559 pos2
= os_strstr(pos
, " ssid=");
5564 end
= os_strchr(pos2
, ' ');
5566 group_ssid_len
= os_strlen(pos2
) / 2;
5568 group_ssid_len
= (end
- pos2
) / 2;
5569 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5570 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5572 group_ssid
= _group_ssid
;
5575 if (os_strncmp(pos
, "pin", 3) == 0) {
5576 /* Request random PIN (to be displayed) and enable the PIN */
5577 wps_method
= WPS_PIN_DISPLAY
;
5578 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5579 wps_method
= WPS_PBC
;
5580 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5581 wps_method
= WPS_P2PS
;
5584 pos
= os_strchr(pin
, ' ');
5585 wps_method
= WPS_PIN_KEYPAD
;
5588 if (os_strncmp(pos
, "display", 7) == 0)
5589 wps_method
= WPS_PIN_DISPLAY
;
5591 if (!wps_pin_str_valid(pin
)) {
5592 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5597 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5598 persistent_group
, automatic
, join
,
5599 auth
, go_intent
, freq
, freq2
, persistent_id
,
5600 pd
, ht40
, vht
, max_oper_chwidth
,
5601 group_ssid
, group_ssid_len
);
5602 if (new_pin
== -2) {
5603 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5606 if (new_pin
== -3) {
5607 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5612 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5613 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5614 if (os_snprintf_error(buflen
, ret
))
5619 os_memcpy(buf
, "OK\n", 3);
5624 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5626 unsigned int timeout
= atoi(cmd
);
5627 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5628 wpa_dbg(wpa_s
, MSG_INFO
,
5629 "Reject P2P_LISTEN since interface is disabled");
5632 return wpas_p2p_listen(wpa_s
, timeout
);
5636 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5640 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5642 /* <addr> <config method> [join|auto] */
5644 if (hwaddr_aton(cmd
, addr
))
5652 if (os_strstr(pos
, " join") != NULL
)
5653 use
= WPAS_P2P_PD_FOR_JOIN
;
5654 else if (os_strstr(pos
, " auto") != NULL
)
5655 use
= WPAS_P2P_PD_AUTO
;
5657 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5661 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5664 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5666 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5667 ssid
->passphrase
== NULL
)
5670 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5671 return os_strlen(buf
);
5675 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5676 char *buf
, size_t buflen
)
5680 u8 dst_buf
[ETH_ALEN
], *dst
;
5681 struct wpabuf
*tlvs
;
5685 if (hwaddr_aton(cmd
, dst_buf
))
5688 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5689 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5696 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5699 if (hexstr2bin(pos
, &version
, 1) < 0)
5705 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5706 #ifdef CONFIG_WIFI_DISPLAY
5707 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5708 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5709 #endif /* CONFIG_WIFI_DISPLAY */
5710 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5712 char *svc_info
= NULL
;
5716 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5719 pos
= os_strchr(pos
, ' ');
5720 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5725 pos
= os_strchr(svc_str
, ' ');
5730 /* All remaining data is the svc_info string */
5731 if (pos
&& pos
[0] && pos
[0] != ' ') {
5732 len
= os_strlen(pos
);
5734 /* Unescape in place */
5735 len
= utf8_unescape(pos
, len
, pos
, len
);
5742 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5745 len
= os_strlen(pos
);
5749 tlvs
= wpabuf_alloc(len
);
5752 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5757 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5762 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5763 if (os_snprintf_error(buflen
, res
))
5769 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5772 long long unsigned val
;
5774 if (sscanf(cmd
, "%llx", &val
) != 1)
5777 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5781 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5786 struct wpabuf
*resp_tlvs
;
5790 pos
= os_strchr(cmd
, ' ');
5798 if (hwaddr_aton(pos
, dst
))
5805 pos2
= os_strchr(pos
, ' ');
5809 dialog_token
= atoi(pos
);
5811 len
= os_strlen(pos2
);
5815 resp_tlvs
= wpabuf_alloc(len
);
5816 if (resp_tlvs
== NULL
)
5818 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5819 wpabuf_free(resp_tlvs
);
5823 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5824 wpabuf_free(resp_tlvs
);
5829 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5832 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5834 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5839 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5844 struct wpabuf
*query
, *resp
;
5846 pos
= os_strchr(cmd
, ' ');
5851 len
= os_strlen(cmd
);
5855 query
= wpabuf_alloc(len
);
5858 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5863 len
= os_strlen(pos
);
5869 resp
= wpabuf_alloc(len
);
5874 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5880 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5889 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5894 pos
= os_strchr(cmd
, ' ');
5899 if (hexstr2bin(cmd
, &version
, 1) < 0)
5902 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5906 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5907 u8 replace
, char *cmd
)
5911 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5912 char *svc_info
= NULL
;
5914 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5916 pos
= os_strchr(cmd
, ' ');
5921 /* Auto-Accept value is mandatory, and must be one of the
5922 * single values (0, 1, 2, 4) */
5923 auto_accept
= atoi(cmd
);
5924 switch (auto_accept
) {
5925 case P2PS_SETUP_NONE
: /* No auto-accept */
5926 case P2PS_SETUP_NEW
:
5927 case P2PS_SETUP_CLIENT
:
5928 case P2PS_SETUP_GROUP_OWNER
:
5934 /* Advertisement ID is mandatory */
5936 pos
= os_strchr(cmd
, ' ');
5941 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5942 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5945 /* Only allow replacements if exist, and adds if not */
5946 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5954 /* svc_state between 0 - 0xff is mandatory */
5955 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5958 pos
= os_strchr(pos
, ' ');
5962 /* config_methods is mandatory */
5964 if (sscanf(pos
, "%x", &config_methods
) != 1)
5967 if (!(config_methods
&
5968 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5971 pos
= os_strchr(pos
, ' ');
5978 /* Advertisement string is mandatory */
5979 if (!pos
[0] || pos
[0] == ' ')
5982 /* Terminate svc string */
5983 pos
= os_strchr(pos
, ' ');
5987 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5989 pos
= os_strchr(pos
, ' ');
5993 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5996 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
6000 /* Service and Response Information are optional */
6001 if (pos
&& pos
[0]) {
6004 /* Note the bare ' included, which cannot exist legally
6005 * in unescaped string. */
6006 svc_info
= os_strstr(pos
, "svc_info='");
6010 len
= os_strlen(svc_info
);
6011 utf8_unescape(svc_info
, len
, svc_info
, len
);
6015 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
6016 (u8
) svc_state
, (u16
) config_methods
,
6017 svc_info
, cpt_prio
);
6021 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6025 pos
= os_strchr(cmd
, ' ');
6030 if (os_strcmp(cmd
, "bonjour") == 0)
6031 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
6032 if (os_strcmp(cmd
, "upnp") == 0)
6033 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
6034 if (os_strcmp(cmd
, "asp") == 0)
6035 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
6036 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6041 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
6045 struct wpabuf
*query
;
6048 len
= os_strlen(cmd
);
6052 query
= wpabuf_alloc(len
);
6055 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
6060 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
6066 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6071 pos
= os_strchr(cmd
, ' ');
6076 if (hexstr2bin(cmd
, &version
, 1) < 0)
6079 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
6083 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
6087 if (os_strcmp(cmd
, "all") == 0) {
6088 wpas_p2p_service_flush_asp(wpa_s
);
6092 if (sscanf(cmd
, "%x", &adv_id
) != 1)
6095 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
6099 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
6103 pos
= os_strchr(cmd
, ' ');
6108 if (os_strcmp(cmd
, "bonjour") == 0)
6109 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
6110 if (os_strcmp(cmd
, "upnp") == 0)
6111 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
6112 if (os_strcmp(cmd
, "asp") == 0)
6113 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
6114 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6119 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
6123 pos
= os_strchr(cmd
, ' ');
6128 if (os_strcmp(cmd
, "asp") == 0)
6129 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
6131 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
6136 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
6142 if (hwaddr_aton(cmd
, addr
))
6145 return wpas_p2p_reject(wpa_s
, addr
);
6149 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6153 struct wpa_ssid
*ssid
;
6154 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6155 int freq
= 0, pref_freq
= 0;
6156 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6159 pos
= os_strstr(cmd
, " peer=");
6162 if (hwaddr_aton(pos
, peer
))
6166 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6167 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6168 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6169 "for persistent P2P group",
6174 pos
= os_strstr(cmd
, " freq=");
6182 pos
= os_strstr(cmd
, " pref=");
6185 pref_freq
= atoi(pos
);
6190 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6191 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6194 pos
= os_strstr(cmd
, "freq2=");
6196 freq2
= atoi(pos
+ 6);
6198 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6200 chwidth
= atoi(pos
+ 18);
6202 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6203 if (max_oper_chwidth
< 0)
6206 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6207 max_oper_chwidth
, pref_freq
);
6211 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6214 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6216 pos
= os_strstr(cmd
, " peer=");
6222 if (hwaddr_aton(pos
, peer
)) {
6223 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6227 pos
= os_strstr(pos
, " go_dev_addr=");
6230 if (hwaddr_aton(pos
, go_dev_addr
)) {
6231 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6235 go_dev
= go_dev_addr
;
6238 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6242 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6244 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6245 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6246 if (os_strncmp(cmd
, "group=", 6) == 0)
6247 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6253 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6254 int id
, int freq
, int vht_center_freq2
,
6255 int ht40
, int vht
, int vht_chwidth
)
6257 struct wpa_ssid
*ssid
;
6259 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6260 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6261 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6262 "for persistent P2P group",
6267 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6268 vht_center_freq2
, 0, ht40
, vht
,
6269 vht_chwidth
, NULL
, 0, 0);
6273 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6275 int freq
= 0, persistent
= 0, group_id
= -1;
6276 int vht
= wpa_s
->conf
->p2p_go_vht
;
6277 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6278 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6279 char *token
, *context
= NULL
;
6282 #endif /* CONFIG_ACS */
6284 while ((token
= str_token(cmd
, " ", &context
))) {
6285 if (sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6286 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6287 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6290 } else if (os_strcmp(token
, "freq=acs") == 0) {
6292 #endif /* CONFIG_ACS */
6293 } else if (sscanf(token
, "freq=%d", &freq
) == 1) {
6295 } else if (os_strcmp(token
, "ht40") == 0) {
6297 } else if (os_strcmp(token
, "vht") == 0) {
6300 } else if (os_strcmp(token
, "persistent") == 0) {
6303 wpa_printf(MSG_DEBUG
,
6304 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6311 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_ACS_OFFLOAD
) &&
6312 (acs
|| freq
== 2 || freq
== 5)) {
6313 if (freq
== 2 && wpa_s
->best_24_freq
<= 0) {
6314 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211G
;
6315 wpa_s
->p2p_go_do_acs
= 1;
6317 } else if (freq
== 5 && wpa_s
->best_5_freq
<= 0) {
6318 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211A
;
6319 wpa_s
->p2p_go_do_acs
= 1;
6322 wpa_s
->p2p_go_acs_band
= HOSTAPD_MODE_IEEE80211ANY
;
6323 wpa_s
->p2p_go_do_acs
= 1;
6326 #endif /* CONFIG_ACS */
6328 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6329 if (max_oper_chwidth
< 0)
6333 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6334 freq
, freq2
, ht40
, vht
,
6337 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6342 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6343 char *buf
, size_t buflen
)
6345 u8 dev_addr
[ETH_ALEN
];
6346 struct wpa_ssid
*ssid
;
6350 ssid
= wpa_s
->current_ssid
;
6351 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6352 hwaddr_aton(cmd
, dev_addr
))
6355 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6358 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6359 if (os_snprintf_error(buflen
, res
))
6365 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6366 const u8
*p2p_dev_addr
)
6368 struct wpa_supplicant
*wpa_s
;
6370 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6371 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6379 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6380 char *buf
, size_t buflen
)
6382 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6384 const struct p2p_peer_info
*info
;
6386 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6387 struct wpa_ssid
*ssid
;
6390 if (!wpa_s
->global
->p2p
)
6393 if (os_strcmp(cmd
, "FIRST") == 0) {
6396 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6397 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6402 if (hwaddr_aton(cmd
, addr
) < 0)
6408 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6411 group_capab
= info
->group_capab
;
6414 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6415 wpa_printf(MSG_DEBUG
,
6416 "P2P: Could not find any BSS with p2p_dev_addr "
6417 MACSTR
", hence override group_capab from 0x%x to 0",
6418 MAC2STR(info
->p2p_device_addr
), group_capab
);
6425 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6431 "serial_number=%s\n"
6432 "config_methods=0x%x\n"
6434 "group_capab=0x%x\n"
6436 MAC2STR(info
->p2p_device_addr
),
6437 wps_dev_type_bin2str(info
->pri_dev_type
,
6438 devtype
, sizeof(devtype
)),
6443 info
->serial_number
,
6444 info
->config_methods
,
6448 if (os_snprintf_error(end
- pos
, res
))
6452 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6455 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6456 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6457 wps_dev_type_bin2str(t
, devtype
,
6459 if (os_snprintf_error(end
- pos
, res
))
6464 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6466 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6467 if (os_snprintf_error(end
- pos
, res
))
6472 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6477 if (info
->vendor_elems
) {
6478 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6479 if (os_snprintf_error(end
- pos
, res
))
6483 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6484 wpabuf_head(info
->vendor_elems
),
6485 wpabuf_len(info
->vendor_elems
));
6487 res
= os_snprintf(pos
, end
- pos
, "\n");
6488 if (os_snprintf_error(end
- pos
, res
))
6497 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6502 if (wpa_s
->global
->p2p
== NULL
)
6505 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6508 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6509 struct wpa_freq_range
*freq
;
6510 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6511 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6512 freq
->min
, freq
->max
);
6515 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6520 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6524 if (wpa_s
->global
->p2p
== NULL
)
6527 param
= os_strchr(cmd
, ' ');
6532 if (os_strcmp(cmd
, "discoverability") == 0) {
6533 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6538 if (os_strcmp(cmd
, "managed") == 0) {
6539 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6543 if (os_strcmp(cmd
, "listen_channel") == 0) {
6545 u8 channel
, op_class
;
6547 channel
= atoi(param
);
6548 pos
= os_strchr(param
, ' ');
6549 op_class
= pos
? atoi(pos
) : 81;
6551 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6555 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6556 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6560 if (os_strcmp(cmd
, "noa") == 0) {
6562 int count
, start
, duration
;
6563 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6564 count
= atoi(param
);
6565 pos
= os_strchr(param
, ',');
6570 pos
= os_strchr(pos
, ',');
6574 duration
= atoi(pos
);
6575 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6577 if (count
== 0 && duration
> 0)
6579 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6580 "start=%d duration=%d", count
, start
, duration
);
6581 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6584 if (os_strcmp(cmd
, "ps") == 0)
6585 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6587 if (os_strcmp(cmd
, "oppps") == 0)
6588 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6590 if (os_strcmp(cmd
, "ctwindow") == 0)
6591 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6593 if (os_strcmp(cmd
, "disabled") == 0) {
6594 wpa_s
->global
->p2p_disabled
= atoi(param
);
6595 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6596 wpa_s
->global
->p2p_disabled
?
6597 "disabled" : "enabled");
6598 if (wpa_s
->global
->p2p_disabled
) {
6599 wpas_p2p_stop_find(wpa_s
);
6600 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6601 p2p_flush(wpa_s
->global
->p2p
);
6606 if (os_strcmp(cmd
, "conc_pref") == 0) {
6607 if (os_strcmp(param
, "sta") == 0)
6608 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6609 else if (os_strcmp(param
, "p2p") == 0)
6610 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6612 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6615 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6620 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6621 wpa_s
->force_long_sd
= atoi(param
);
6625 if (os_strcmp(cmd
, "peer_filter") == 0) {
6627 if (hwaddr_aton(param
, addr
))
6629 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6633 if (os_strcmp(cmd
, "cross_connect") == 0)
6634 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6636 if (os_strcmp(cmd
, "go_apsd") == 0) {
6637 if (os_strcmp(param
, "disable") == 0)
6638 wpa_s
->set_ap_uapsd
= 0;
6640 wpa_s
->set_ap_uapsd
= 1;
6641 wpa_s
->ap_uapsd
= atoi(param
);
6646 if (os_strcmp(cmd
, "client_apsd") == 0) {
6647 if (os_strcmp(param
, "disable") == 0)
6648 wpa_s
->set_sta_uapsd
= 0;
6652 /* format: BE,BK,VI,VO;max SP Length */
6654 pos
= os_strchr(param
, ',');
6659 pos
= os_strchr(pos
, ',');
6664 pos
= os_strchr(pos
, ',');
6669 /* ignore max SP Length for now */
6671 wpa_s
->set_sta_uapsd
= 1;
6672 wpa_s
->sta_uapsd
= 0;
6674 wpa_s
->sta_uapsd
|= BIT(0);
6676 wpa_s
->sta_uapsd
|= BIT(1);
6678 wpa_s
->sta_uapsd
|= BIT(2);
6680 wpa_s
->sta_uapsd
|= BIT(3);
6685 if (os_strcmp(cmd
, "disallow_freq") == 0)
6686 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6688 if (os_strcmp(cmd
, "disc_int") == 0) {
6689 int min_disc_int
, max_disc_int
, max_disc_tu
;
6694 min_disc_int
= atoi(pos
);
6695 pos
= os_strchr(pos
, ' ');
6700 max_disc_int
= atoi(pos
);
6701 pos
= os_strchr(pos
, ' ');
6706 max_disc_tu
= atoi(pos
);
6708 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6709 max_disc_int
, max_disc_tu
);
6712 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6713 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6717 #ifdef CONFIG_WPS_NFC
6718 if (os_strcmp(cmd
, "nfc_tag") == 0)
6719 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6720 #endif /* CONFIG_WPS_NFC */
6722 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6723 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6727 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6730 op_class
= atoi(param
);
6731 param
= os_strchr(param
, ':');
6736 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6741 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6748 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6750 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6751 wpa_s
->force_long_sd
= 0;
6753 #ifdef CONFIG_TESTING_OPTIONS
6754 os_free(wpa_s
->get_pref_freq_list_override
);
6755 wpa_s
->get_pref_freq_list_override
= NULL
;
6756 #endif /* CONFIG_TESTING_OPTIONS */
6758 wpas_p2p_stop_find(wpa_s
);
6759 wpa_s
->parent
->p2ps_method_config_any
= 0;
6760 if (wpa_s
->global
->p2p
)
6761 p2p_flush(wpa_s
->global
->p2p
);
6765 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6768 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6771 pos
= os_strchr(cmd
, ' ');
6777 pos2
= os_strchr(pos
, ' ');
6785 pos
= os_strchr(pos2
, ' ');
6793 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6797 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6800 unsigned int period
= 0, interval
= 0;
6803 pos
= os_strchr(cmd
, ' ');
6808 interval
= atoi(pos
);
6811 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6815 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6822 if (os_strncmp(pos
, "iface=", 6) == 0) {
6826 if (hwaddr_aton(pos
, peer
))
6829 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6834 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6836 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6838 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6840 wpa_printf(MSG_DEBUG
,
6841 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6845 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6848 #endif /* CONFIG_P2P */
6851 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6853 struct wpa_freq_range_list ranges
;
6855 struct hostapd_hw_modes
*mode
;
6858 if (wpa_s
->hw
.modes
== NULL
)
6861 os_memset(&ranges
, 0, sizeof(ranges
));
6862 if (freq_range_list_parse(&ranges
, val
) < 0)
6865 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6868 mode
= &wpa_s
->hw
.modes
[i
];
6869 for (j
= 0; j
< mode
->num_channels
; j
++) {
6872 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6875 freq
= mode
->channels
[j
].freq
;
6876 if (!freq_range_list_includes(&ranges
, freq
))
6879 int_array_add_unique(&freqs
, freq
);
6883 os_free(ranges
.range
);
6888 #ifdef CONFIG_INTERWORKING
6890 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6898 auto_sel
= os_strstr(param
, "auto") != NULL
;
6900 pos
= os_strstr(param
, "freq=");
6902 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6909 return interworking_select(wpa_s
, auto_sel
, freqs
);
6913 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6917 struct wpa_bss
*bss
;
6919 if (hwaddr_aton(dst
, bssid
)) {
6920 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6924 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6926 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6931 if (bss
->ssid_len
== 0) {
6934 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6935 " does not have SSID information", MAC2STR(bssid
));
6937 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6939 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6940 bss
->ssid_len
> 0) {
6948 wpa_printf(MSG_DEBUG
,
6949 "Found another matching BSS entry with SSID");
6952 return interworking_connect(wpa_s
, bss
, only_add
);
6956 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6958 u8 dst_addr
[ETH_ALEN
];
6961 #define MAX_ANQP_INFO_ID 100
6962 u16 id
[MAX_ANQP_INFO_ID
];
6965 u32 mbo_subtypes
= 0;
6967 used
= hwaddr_aton2(dst
, dst_addr
);
6973 while (num_id
< MAX_ANQP_INFO_ID
) {
6974 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6976 int num
= atoi(pos
+ 5);
6977 if (num
<= 0 || num
> 31)
6979 subtypes
|= BIT(num
);
6980 #else /* CONFIG_HS20 */
6982 #endif /* CONFIG_HS20 */
6983 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6985 int num
= atoi(pos
+ 4);
6987 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
6989 mbo_subtypes
|= BIT(num
);
6990 #else /* CONFIG_MBO */
6992 #endif /* CONFIG_MBO */
6994 id
[num_id
] = atoi(pos
);
6998 pos
= os_strchr(pos
+ 1, ',');
7004 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
7007 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
7012 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
7014 u8 dst_addr
[ETH_ALEN
];
7015 struct wpabuf
*advproto
, *query
= NULL
;
7020 used
= hwaddr_aton2(cmd
, dst_addr
);
7028 /* Advertisement Protocol ID */
7029 end
= os_strchr(pos
, ' ');
7033 len
= os_strlen(pos
);
7039 advproto
= wpabuf_alloc(len
);
7040 if (advproto
== NULL
)
7042 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
7046 /* Optional Query Request */
7051 len
= os_strlen(pos
);
7058 query
= wpabuf_alloc(len
);
7061 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
7066 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
7069 wpabuf_free(advproto
);
7076 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
7083 size_t resp_len
, start
, requested_len
;
7084 struct wpabuf
*resp
;
7087 used
= hwaddr_aton2(cmd
, addr
);
7094 dialog_token
= atoi(pos
);
7096 if (wpa_s
->last_gas_resp
&&
7097 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
7098 dialog_token
== wpa_s
->last_gas_dialog_token
)
7099 resp
= wpa_s
->last_gas_resp
;
7100 else if (wpa_s
->prev_gas_resp
&&
7101 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
7102 dialog_token
== wpa_s
->prev_gas_dialog_token
)
7103 resp
= wpa_s
->prev_gas_resp
;
7107 resp_len
= wpabuf_len(resp
);
7109 requested_len
= resp_len
;
7111 pos
= os_strchr(pos
, ' ');
7114 if (start
> resp_len
)
7115 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7116 pos
= os_strchr(pos
, ',');
7120 requested_len
= atoi(pos
);
7121 if (start
+ requested_len
> resp_len
)
7122 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
7125 if (requested_len
* 2 + 1 > buflen
)
7126 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
7128 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
7131 if (start
+ requested_len
== resp_len
) {
7133 * Free memory by dropping the response after it has been
7136 if (resp
== wpa_s
->prev_gas_resp
) {
7137 wpabuf_free(wpa_s
->prev_gas_resp
);
7138 wpa_s
->prev_gas_resp
= NULL
;
7140 wpabuf_free(wpa_s
->last_gas_resp
);
7141 wpa_s
->last_gas_resp
= NULL
;
7147 #endif /* CONFIG_INTERWORKING */
7152 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
7154 u8 dst_addr
[ETH_ALEN
];
7159 used
= hwaddr_aton2(dst
, dst_addr
);
7166 int num
= atoi(pos
);
7167 if (num
<= 0 || num
> 31)
7169 subtypes
|= BIT(num
);
7170 pos
= os_strchr(pos
+ 1, ',');
7179 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7183 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7184 const u8
*addr
, const char *realm
)
7190 rlen
= os_strlen(realm
);
7192 buf
= os_malloc(len
);
7195 buf
[0] = 1; /* NAI Home Realm Count */
7196 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7198 os_memcpy(buf
+ 3, realm
, rlen
);
7200 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7201 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7210 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7213 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7214 u8 dst_addr
[ETH_ALEN
];
7220 used
= hwaddr_aton2(dst
, dst_addr
);
7224 while (dst
[used
] == ' ')
7226 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7227 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7230 len
= os_strlen(dst
+ used
);
7232 if (len
== 0 && cred
&& cred
->realm
)
7233 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7238 buf
= os_malloc(len
);
7241 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7246 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7247 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7255 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7258 u8 dst_addr
[ETH_ALEN
];
7260 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7262 used
= hwaddr_aton2(cmd
, dst_addr
);
7267 icon
= str_token(cmd
, " ", &ctx
);
7268 poffset
= str_token(cmd
, " ", &ctx
);
7269 psize
= str_token(cmd
, " ", &ctx
);
7270 if (!icon
|| !poffset
|| !psize
)
7273 wpa_s
->fetch_osu_icon_in_progress
= 0;
7274 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7279 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7281 u8 dst_addr
[ETH_ALEN
];
7286 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7288 used
= hwaddr_aton2(cmd
, dst_addr
);
7292 while (cmd
[used
] == ' ')
7294 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7296 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7300 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7302 u8 dst_addr
[ETH_ALEN
];
7306 used
= hwaddr_aton2(cmd
, dst_addr
);
7310 while (cmd
[used
] == ' ')
7314 wpa_s
->fetch_osu_icon_in_progress
= 0;
7315 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7316 (u8
*) icon
, os_strlen(icon
), inmem
);
7319 #endif /* CONFIG_HS20 */
7322 #ifdef CONFIG_AUTOSCAN
7324 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7327 enum wpa_states state
= wpa_s
->wpa_state
;
7328 char *new_params
= NULL
;
7330 if (os_strlen(cmd
) > 0) {
7331 new_params
= os_strdup(cmd
);
7332 if (new_params
== NULL
)
7336 os_free(wpa_s
->conf
->autoscan
);
7337 wpa_s
->conf
->autoscan
= new_params
;
7339 if (wpa_s
->conf
->autoscan
== NULL
)
7340 autoscan_deinit(wpa_s
);
7341 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7342 autoscan_init(wpa_s
, 1);
7343 else if (state
== WPA_SCANNING
)
7344 wpa_supplicant_reinit_autoscan(wpa_s
);
7346 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7347 wpa_supplicant_state_txt(state
));
7352 #endif /* CONFIG_AUTOSCAN */
7357 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7363 struct wpabuf
*tfs_req
= NULL
;
7365 if (os_strncmp(cmd
, "enter", 5) == 0)
7367 else if (os_strncmp(cmd
, "exit", 4) == 0)
7372 pos
= os_strstr(cmd
, " interval=");
7374 intval
= atoi(pos
+ 10);
7376 pos
= os_strstr(cmd
, " tfs_req=");
7381 end
= os_strchr(pos
, ' ');
7385 len
= os_strlen(pos
);
7389 tfs_req
= wpabuf_alloc(len
);
7390 if (tfs_req
== NULL
)
7392 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7393 wpabuf_free(tfs_req
);
7398 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7399 WNM_SLEEP_MODE_EXIT
, intval
,
7401 wpabuf_free(tfs_req
);
7407 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7409 int query_reason
, list
= 0;
7410 char *btm_candidates
= NULL
;
7412 query_reason
= atoi(cmd
);
7414 cmd
= os_strchr(cmd
, ' ');
7416 if (os_strncmp(cmd
, " list", 5) == 0)
7419 btm_candidates
= cmd
;
7422 wpa_printf(MSG_DEBUG
,
7423 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7424 query_reason
, list
? " candidate list" : "");
7426 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7431 #endif /* CONFIG_WNM */
7434 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7437 struct wpa_signal_info si
;
7441 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7448 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7449 "NOISE=%d\nFREQUENCY=%u\n",
7450 si
.current_signal
, si
.current_txrate
/ 1000,
7451 si
.current_noise
, si
.frequency
);
7452 if (os_snprintf_error(end
- pos
, ret
))
7456 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7457 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7458 channel_width_to_string(si
.chanwidth
));
7459 if (os_snprintf_error(end
- pos
, ret
))
7464 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
7465 ret
= os_snprintf(pos
, end
- pos
,
7466 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7467 si
.center_frq1
, si
.center_frq2
);
7468 if (os_snprintf_error(end
- pos
, ret
))
7473 if (si
.avg_signal
) {
7474 ret
= os_snprintf(pos
, end
- pos
,
7475 "AVG_RSSI=%d\n", si
.avg_signal
);
7476 if (os_snprintf_error(end
- pos
, ret
))
7481 if (si
.avg_beacon_signal
) {
7482 ret
= os_snprintf(pos
, end
- pos
,
7483 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7484 if (os_snprintf_error(end
- pos
, ret
))
7493 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7500 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7501 wpa_printf(MSG_DEBUG
,
7502 "Reject SIGNAL_MONITOR command - bgscan is active");
7505 pos
= os_strstr(cmd
, "THRESHOLD=");
7507 threshold
= atoi(pos
+ 10);
7508 pos
= os_strstr(cmd
, "HYSTERESIS=");
7510 hysteresis
= atoi(pos
+ 11);
7511 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7515 #ifdef CONFIG_TESTING_OPTIONS
7516 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7517 enum wpa_driver_if_type if_type
,
7519 unsigned int *freq_list
)
7521 char *pos
= wpa_s
->get_pref_freq_list_override
;
7523 unsigned int count
= 0;
7525 /* Override string format:
7526 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7529 if (atoi(pos
) == (int) if_type
)
7531 pos
= os_strchr(pos
, ' ');
7537 pos
= os_strchr(pos
, ':');
7541 end
= os_strchr(pos
, ' ');
7542 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7543 freq_list
[count
++] = atoi(pos
);
7544 pos
= os_strchr(pos
, ',');
7552 #endif /* CONFIG_TESTING_OPTIONS */
7555 static int wpas_ctrl_iface_get_pref_freq_list(
7556 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7558 unsigned int freq_list
[100], num
= 100, i
;
7560 enum wpa_driver_if_type iface_type
;
7566 /* buf: "<interface_type>" */
7567 if (os_strcmp(cmd
, "STATION") == 0)
7568 iface_type
= WPA_IF_STATION
;
7569 else if (os_strcmp(cmd
, "AP") == 0)
7570 iface_type
= WPA_IF_AP_BSS
;
7571 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7572 iface_type
= WPA_IF_P2P_GO
;
7573 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7574 iface_type
= WPA_IF_P2P_CLIENT
;
7575 else if (os_strcmp(cmd
, "IBSS") == 0)
7576 iface_type
= WPA_IF_IBSS
;
7577 else if (os_strcmp(cmd
, "TDLS") == 0)
7578 iface_type
= WPA_IF_TDLS
;
7582 wpa_printf(MSG_DEBUG
,
7583 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7586 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7590 for (i
= 0; i
< num
; i
++) {
7591 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7592 i
> 0 ? "," : "", freq_list
[i
]);
7593 if (os_snprintf_error(end
- pos
, ret
))
7602 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7603 char *buf
, size_t buflen
)
7608 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7609 (long long unsigned) wpa_s
->drv_flags
);
7610 if (os_snprintf_error(buflen
, ret
))
7616 for (i
= 0; i
< 64; i
++) {
7617 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7618 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7619 driver_flag_to_string(1LLU << i
));
7620 if (os_snprintf_error(end
- pos
, ret
))
7630 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7633 struct hostap_sta_driver_data sta
;
7636 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7640 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7641 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7642 if (os_snprintf_error(buflen
, ret
))
7649 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7650 char *buf
, size_t buflen
)
7654 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7656 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7657 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7660 country
[0] = cmd
[8];
7661 country
[1] = cmd
[9];
7663 p2p_set_country(p2p
, country
);
7666 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7667 if (os_snprintf_error(buflen
, ret
))
7672 #endif /* ANDROID */
7675 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7676 char *buf
, size_t buflen
)
7681 unsigned int vendor_id
, subcmd
;
7682 struct wpabuf
*reply
;
7683 size_t data_len
= 0;
7685 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7686 vendor_id
= strtoul(cmd
, &pos
, 16);
7687 if (!isblank((unsigned char) *pos
))
7690 subcmd
= strtoul(pos
, &pos
, 10);
7693 if (!isblank((unsigned char) *pos
++))
7695 data_len
= os_strlen(pos
);
7700 data
= os_malloc(data_len
);
7704 if (hexstr2bin(pos
, data
, data_len
)) {
7705 wpa_printf(MSG_DEBUG
,
7706 "Vendor command: wrong parameter format");
7712 reply
= wpabuf_alloc((buflen
- 1) / 2);
7718 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7722 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7732 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7735 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7736 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7737 #endif /* CONFIG_P2P */
7739 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7741 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7742 wpa_s
->ignore_post_flush_scan_res
= 1;
7744 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7746 * Avoid possible auto connect re-connection on getting
7747 * disconnected due to state flush.
7749 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7753 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7754 wpas_p2p_cancel(p2p_wpa_s
);
7755 p2p_ctrl_flush(p2p_wpa_s
);
7756 wpas_p2p_service_flush(p2p_wpa_s
);
7757 p2p_wpa_s
->global
->p2p_disabled
= 0;
7758 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7759 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7760 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7761 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7762 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7763 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7764 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7765 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7766 #endif /* CONFIG_P2P */
7768 #ifdef CONFIG_WPS_TESTING
7769 wps_version_number
= 0x20;
7770 wps_testing_dummy_cred
= 0;
7771 wps_corrupt_pkhash
= 0;
7772 wps_force_auth_types_in_use
= 0;
7773 wps_force_encr_types_in_use
= 0;
7774 #endif /* CONFIG_WPS_TESTING */
7776 wpa_s
->wps_fragment_size
= 0;
7777 wpas_wps_cancel(wpa_s
);
7778 wps_registrar_flush(wpa_s
->wps
->registrar
);
7779 #endif /* CONFIG_WPS */
7780 wpa_s
->after_wps
= 0;
7781 wpa_s
->known_wps_freq
= 0;
7784 wpas_dpp_deinit(wpa_s
);
7785 wpa_s
->dpp_init_max_tries
= 0;
7786 wpa_s
->dpp_init_retry_time
= 0;
7787 wpa_s
->dpp_resp_wait_time
= 0;
7788 wpa_s
->dpp_resp_max_tries
= 0;
7789 wpa_s
->dpp_resp_retry_time
= 0;
7790 #ifdef CONFIG_TESTING_OPTIONS
7791 os_memset(dpp_pkex_own_mac_override
, 0, ETH_ALEN
);
7792 os_memset(dpp_pkex_peer_mac_override
, 0, ETH_ALEN
);
7793 dpp_pkex_ephemeral_key_override_len
= 0;
7794 dpp_protocol_key_override_len
= 0;
7795 dpp_nonce_override_len
= 0;
7796 #endif /* CONFIG_TESTING_OPTIONS */
7797 #endif /* CONFIG_DPP */
7800 #ifdef CONFIG_TDLS_TESTING
7802 #endif /* CONFIG_TDLS_TESTING */
7803 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7804 wpa_tdls_enable(wpa_s
->wpa
, 1);
7805 #endif /* CONFIG_TDLS */
7807 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7808 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7810 wpa_s
->no_keep_alive
= 0;
7811 wpa_s
->own_disconnect_req
= 0;
7813 os_free(wpa_s
->disallow_aps_bssid
);
7814 wpa_s
->disallow_aps_bssid
= NULL
;
7815 wpa_s
->disallow_aps_bssid_count
= 0;
7816 os_free(wpa_s
->disallow_aps_ssid
);
7817 wpa_s
->disallow_aps_ssid
= NULL
;
7818 wpa_s
->disallow_aps_ssid_count
= 0;
7820 wpa_s
->set_sta_uapsd
= 0;
7821 wpa_s
->sta_uapsd
= 0;
7823 wpa_drv_radio_disable(wpa_s
, 0);
7824 wpa_blacklist_clear(wpa_s
);
7825 wpa_s
->extra_blacklist_count
= 0;
7826 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7827 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7828 wpa_config_flush_blobs(wpa_s
->conf
);
7829 wpa_s
->conf
->auto_interworking
= 0;
7830 wpa_s
->conf
->okc
= 0;
7832 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7833 rsn_preauth_deinit(wpa_s
->wpa
);
7835 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7836 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7837 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7838 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7840 radio_remove_works(wpa_s
, NULL
, 1);
7841 wpa_s
->ext_work_in_progress
= 0;
7843 wpa_s
->next_ssid
= NULL
;
7845 #ifdef CONFIG_INTERWORKING
7847 hs20_cancel_fetch_osu(wpa_s
);
7848 hs20_del_icon(wpa_s
, NULL
, NULL
);
7849 #endif /* CONFIG_HS20 */
7850 #endif /* CONFIG_INTERWORKING */
7852 wpa_s
->ext_mgmt_frame_handling
= 0;
7853 wpa_s
->ext_eapol_frame_io
= 0;
7854 #ifdef CONFIG_TESTING_OPTIONS
7855 wpa_s
->extra_roc_dur
= 0;
7856 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7857 wpa_s
->p2p_go_csa_on_inv
= 0;
7858 wpa_s
->ignore_auth_resp
= 0;
7859 wpa_s
->ignore_assoc_disallow
= 0;
7860 wpa_s
->testing_resend_assoc
= 0;
7861 wpa_s
->reject_btm_req_reason
= 0;
7862 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7863 os_free(wpa_s
->get_pref_freq_list_override
);
7864 wpa_s
->get_pref_freq_list_override
= NULL
;
7865 wpabuf_free(wpa_s
->sae_commit_override
);
7866 wpa_s
->sae_commit_override
= NULL
;
7868 os_free(wpa_s
->dpp_config_obj_override
);
7869 wpa_s
->dpp_config_obj_override
= NULL
;
7870 os_free(wpa_s
->dpp_discovery_override
);
7871 wpa_s
->dpp_discovery_override
= NULL
;
7872 os_free(wpa_s
->dpp_groups_override
);
7873 wpa_s
->dpp_groups_override
= NULL
;
7874 dpp_test
= DPP_TEST_DISABLED
;
7875 #endif /* CONFIG_DPP */
7876 #endif /* CONFIG_TESTING_OPTIONS */
7878 wpa_s
->disconnected
= 0;
7879 os_free(wpa_s
->next_scan_freqs
);
7880 wpa_s
->next_scan_freqs
= NULL
;
7881 os_free(wpa_s
->select_network_scan_freqs
);
7882 wpa_s
->select_network_scan_freqs
= NULL
;
7884 wpa_bss_flush(wpa_s
);
7885 if (!dl_list_empty(&wpa_s
->bss
)) {
7886 wpa_printf(MSG_DEBUG
,
7887 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7888 MACSTR
" pending_bssid=" MACSTR
,
7889 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7890 MAC2STR(wpa_s
->bssid
),
7891 MAC2STR(wpa_s
->pending_bssid
));
7894 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7895 wpa_s
->wnmsleep_used
= 0;
7898 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7899 #endif /* CONFIG_SME */
7901 wpabuf_free(wpa_s
->ric_ies
);
7902 wpa_s
->ric_ies
= NULL
;
7906 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7907 char *buf
, size_t buflen
)
7909 struct wpa_radio_work
*work
;
7911 struct os_reltime now
, diff
;
7916 os_get_reltime(&now
);
7918 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7922 os_reltime_sub(&now
, &work
->time
, &diff
);
7923 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7924 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7925 work
->started
, diff
.sec
, diff
.usec
);
7926 if (os_snprintf_error(end
- pos
, ret
))
7935 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7937 struct wpa_radio_work
*work
= eloop_ctx
;
7938 struct wpa_external_work
*ework
= work
->ctx
;
7940 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7941 "Timing out external radio work %u (%s)",
7942 ework
->id
, work
->type
);
7943 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7944 work
->wpa_s
->ext_work_in_progress
= 0;
7945 radio_work_done(work
);
7950 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7952 struct wpa_external_work
*ework
= work
->ctx
;
7956 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7960 * work->type points to a buffer in ework, so need to replace
7961 * that here with a fixed string to avoid use of freed memory
7964 work
->type
= "freed-ext-work";
7970 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7971 ework
->id
, ework
->type
);
7972 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7973 work
->wpa_s
->ext_work_in_progress
= 1;
7974 if (!ework
->timeout
)
7975 ework
->timeout
= 10;
7976 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7981 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7982 char *buf
, size_t buflen
)
7984 struct wpa_external_work
*ework
;
7988 unsigned int freq
= 0;
7990 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7992 ework
= os_zalloc(sizeof(*ework
));
7996 pos
= os_strchr(cmd
, ' ');
7998 type_len
= pos
- cmd
;
8001 pos2
= os_strstr(pos
, "freq=");
8003 freq
= atoi(pos2
+ 5);
8005 pos2
= os_strstr(pos
, "timeout=");
8007 ework
->timeout
= atoi(pos2
+ 8);
8009 type_len
= os_strlen(cmd
);
8011 if (4 + type_len
>= sizeof(ework
->type
))
8012 type_len
= sizeof(ework
->type
) - 4 - 1;
8013 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
8014 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
8015 ework
->type
[4 + type_len
] = '\0';
8017 wpa_s
->ext_work_id
++;
8018 if (wpa_s
->ext_work_id
== 0)
8019 wpa_s
->ext_work_id
++;
8020 ework
->id
= wpa_s
->ext_work_id
;
8022 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
8028 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
8029 if (os_snprintf_error(buflen
, ret
))
8035 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
8037 struct wpa_radio_work
*work
;
8038 unsigned int id
= atoi(cmd
);
8040 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
8042 struct wpa_external_work
*ework
;
8044 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8047 if (id
&& ework
->id
!= id
)
8049 wpa_dbg(wpa_s
, MSG_DEBUG
,
8050 "Completed external radio work %u (%s)",
8051 ework
->id
, ework
->type
);
8052 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
8053 wpa_s
->ext_work_in_progress
= 0;
8054 radio_work_done(work
);
8056 return 3; /* "OK\n" */
8063 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
8064 char *buf
, size_t buflen
)
8066 if (os_strcmp(cmd
, "show") == 0)
8067 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
8068 if (os_strncmp(cmd
, "add ", 4) == 0)
8069 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
8070 if (os_strncmp(cmd
, "done ", 5) == 0)
8071 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
8076 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
8078 struct wpa_radio_work
*work
, *tmp
;
8080 if (!wpa_s
|| !wpa_s
->radio
)
8083 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
8084 struct wpa_radio_work
, list
) {
8085 struct wpa_external_work
*ework
;
8087 if (os_strncmp(work
->type
, "ext:", 4) != 0)
8090 wpa_dbg(wpa_s
, MSG_DEBUG
,
8091 "Flushing%s external radio work %u (%s)",
8092 work
->started
? " started" : "", ework
->id
,
8095 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
8097 radio_work_done(work
);
8103 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
8105 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8106 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
8110 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
8111 unsigned int *scan_id_count
, int scan_id
[])
8113 const char *pos
= value
;
8116 if (*pos
== ' ' || *pos
== '\0')
8118 if (*scan_id_count
== MAX_SCAN_ID
)
8120 scan_id
[(*scan_id_count
)++] = atoi(pos
);
8121 pos
= os_strchr(pos
, ',');
8130 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
8131 char *reply
, int reply_size
, int *reply_len
)
8134 unsigned int manual_scan_passive
= 0;
8135 unsigned int manual_scan_use_id
= 0;
8136 unsigned int manual_scan_only_new
= 0;
8137 unsigned int scan_only
= 0;
8138 unsigned int scan_id_count
= 0;
8139 int scan_id
[MAX_SCAN_ID
];
8140 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
8141 struct wpa_scan_results
*scan_res
);
8142 int *manual_scan_freqs
= NULL
;
8143 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
8144 unsigned int ssid_count
= 0;
8146 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
8151 if (radio_work_pending(wpa_s
, "scan")) {
8152 wpa_printf(MSG_DEBUG
,
8153 "Pending scan scheduled - reject new request");
8154 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8158 #ifdef CONFIG_INTERWORKING
8159 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
8160 wpa_printf(MSG_DEBUG
,
8161 "Interworking select in progress - reject new scan");
8162 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8165 #endif /* CONFIG_INTERWORKING */
8168 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
8171 pos
= os_strstr(params
, "freq=");
8173 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
8175 if (manual_scan_freqs
== NULL
) {
8181 pos
= os_strstr(params
, "passive=");
8183 manual_scan_passive
= !!atoi(pos
+ 8);
8185 pos
= os_strstr(params
, "use_id=");
8187 manual_scan_use_id
= atoi(pos
+ 7);
8189 pos
= os_strstr(params
, "only_new=1");
8191 manual_scan_only_new
= 1;
8193 pos
= os_strstr(params
, "scan_id=");
8194 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
8200 pos
= os_strstr(params
, "bssid=");
8205 if (hwaddr_aton(pos
, bssid
)) {
8206 wpa_printf(MSG_ERROR
, "Invalid BSSID %s", pos
);
8210 os_memcpy(wpa_s
->next_scan_bssid
, bssid
, ETH_ALEN
);
8214 while (pos
&& *pos
!= '\0') {
8215 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8221 if (*end
== '\0' || *end
== ' ')
8226 ns
= os_realloc_array(
8227 ssid
, ssid_count
+ 1,
8228 sizeof(struct wpa_ssid_value
));
8235 if ((end
- pos
) & 0x01 ||
8236 end
- pos
> 2 * SSID_MAX_LEN
||
8237 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8238 (end
- pos
) / 2) < 0) {
8239 wpa_printf(MSG_DEBUG
,
8240 "Invalid SSID value '%s'",
8245 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8246 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8247 ssid
[ssid_count
].ssid
,
8248 ssid
[ssid_count
].ssid_len
);
8253 pos
= os_strchr(pos
, ' ');
8259 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8260 os_free(wpa_s
->ssids_from_scan_req
);
8262 wpa_s
->ssids_from_scan_req
= ssid
;
8265 wpa_s
->ssids_from_scan_req
= NULL
;
8269 scan_res_handler
= scan_only_handler
;
8270 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8271 scan_res_handler
= NULL
;
8273 scan_res_handler
= wpa_s
->scan_res_handler
;
8275 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8276 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8277 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8278 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8279 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8280 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8281 wpa_s
->scan_id_count
= scan_id_count
;
8282 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8283 wpa_s
->scan_res_handler
= scan_res_handler
;
8284 os_free(wpa_s
->manual_scan_freqs
);
8285 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8286 manual_scan_freqs
= NULL
;
8288 wpa_s
->normal_scans
= 0;
8289 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8290 wpa_s
->after_wps
= 0;
8291 wpa_s
->known_wps_freq
= 0;
8292 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8293 if (wpa_s
->manual_scan_use_id
) {
8294 wpa_s
->manual_scan_id
++;
8295 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8296 wpa_s
->manual_scan_id
);
8297 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8298 wpa_s
->manual_scan_id
);
8300 } else if (wpa_s
->sched_scanning
) {
8301 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8302 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8303 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8304 wpa_s
->scan_id_count
= scan_id_count
;
8305 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8306 wpa_s
->scan_res_handler
= scan_res_handler
;
8307 os_free(wpa_s
->manual_scan_freqs
);
8308 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8309 manual_scan_freqs
= NULL
;
8311 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8312 wpa_supplicant_cancel_sched_scan(wpa_s
);
8313 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8314 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8315 if (wpa_s
->manual_scan_use_id
) {
8316 wpa_s
->manual_scan_id
++;
8317 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8318 wpa_s
->manual_scan_id
);
8319 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8320 wpa_s
->manual_scan_id
);
8323 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8324 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8328 os_free(manual_scan_freqs
);
8333 #ifdef CONFIG_TESTING_OPTIONS
8335 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8336 unsigned int freq
, const u8
*dst
,
8337 const u8
*src
, const u8
*bssid
,
8338 const u8
*data
, size_t data_len
,
8339 enum offchannel_send_action_result
8342 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8343 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8344 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8345 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8346 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8347 "NO_ACK" : "FAILED"));
8351 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8355 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8357 int freq
= 0, no_cck
= 0, wait_time
= 0;
8359 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8360 * <action=Action frame payload> */
8362 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8365 used
= hwaddr_aton2(pos
, da
);
8371 used
= hwaddr_aton2(pos
, bssid
);
8376 param
= os_strstr(pos
, " freq=");
8382 param
= os_strstr(pos
, " no_cck=");
8385 no_cck
= atoi(param
);
8388 param
= os_strstr(pos
, " wait_time=");
8391 wait_time
= atoi(param
);
8394 param
= os_strstr(pos
, " action=");
8399 len
= os_strlen(param
);
8404 buf
= os_malloc(len
);
8408 if (hexstr2bin(param
, buf
, len
) < 0) {
8413 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8414 buf
, len
, wait_time
,
8415 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8421 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8423 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8424 offchannel_send_action_done(wpa_s
);
8428 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8434 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8435 union wpa_event_data event
;
8437 if (!wpa_s
->ext_mgmt_frame_handling
)
8440 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8442 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8445 param
= os_strstr(pos
, "freq=");
8451 param
= os_strstr(pos
, " datarate=");
8454 datarate
= atoi(param
);
8457 param
= os_strstr(pos
, " ssi_signal=");
8460 ssi_signal
= atoi(param
);
8463 param
= os_strstr(pos
, " frame=");
8468 len
= os_strlen(param
);
8473 buf
= os_malloc(len
);
8477 if (hexstr2bin(param
, buf
, len
) < 0) {
8482 os_memset(&event
, 0, sizeof(event
));
8483 event
.rx_mgmt
.freq
= freq
;
8484 event
.rx_mgmt
.frame
= buf
;
8485 event
.rx_mgmt
.frame_len
= len
;
8486 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8487 event
.rx_mgmt
.datarate
= datarate
;
8488 wpa_s
->ext_mgmt_frame_handling
= 0;
8489 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8490 wpa_s
->ext_mgmt_frame_handling
= 1;
8498 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8501 struct wpa_scan_res
*res
;
8502 struct os_reltime now
;
8509 if (os_strcmp(param
, "START") == 0) {
8510 wpa_bss_update_start(wpa_s
);
8514 if (os_strcmp(param
, "END") == 0) {
8515 wpa_bss_update_end(wpa_s
, NULL
, 1);
8519 if (os_strncmp(param
, "BSS ", 4) != 0)
8523 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8527 pos
= os_strstr(param
, " flags=");
8529 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8531 pos
= os_strstr(param
, " bssid=");
8532 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8535 pos
= os_strstr(param
, " freq=");
8537 res
->freq
= atoi(pos
+ 6);
8539 pos
= os_strstr(param
, " beacon_int=");
8541 res
->beacon_int
= atoi(pos
+ 12);
8543 pos
= os_strstr(param
, " caps=");
8545 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8547 pos
= os_strstr(param
, " qual=");
8549 res
->qual
= atoi(pos
+ 6);
8551 pos
= os_strstr(param
, " noise=");
8553 res
->noise
= atoi(pos
+ 7);
8555 pos
= os_strstr(param
, " level=");
8557 res
->level
= atoi(pos
+ 7);
8559 pos
= os_strstr(param
, " tsf=");
8561 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8563 pos
= os_strstr(param
, " age=");
8565 res
->age
= atoi(pos
+ 5);
8567 pos
= os_strstr(param
, " est_throughput=");
8569 res
->est_throughput
= atoi(pos
+ 16);
8571 pos
= os_strstr(param
, " snr=");
8573 res
->snr
= atoi(pos
+ 5);
8575 pos
= os_strstr(param
, " parent_tsf=");
8577 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8579 pos
= os_strstr(param
, " tsf_bssid=");
8580 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8583 pos
= os_strstr(param
, " ie=");
8586 end
= os_strchr(pos
, ' ');
8588 end
= pos
+ os_strlen(pos
);
8589 res
->ie_len
= (end
- pos
) / 2;
8590 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8594 pos
= os_strstr(param
, " beacon_ie=");
8597 end
= os_strchr(pos
, ' ');
8599 end
= pos
+ os_strlen(pos
);
8600 res
->beacon_ie_len
= (end
- pos
) / 2;
8601 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8602 res
->beacon_ie_len
))
8606 os_get_reltime(&now
);
8607 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8616 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8619 union wpa_event_data event
;
8620 enum wpa_event_type ev
;
8622 /* <event name> [parameters..] */
8624 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8627 param
= os_strchr(pos
, ' ');
8631 os_memset(&event
, 0, sizeof(event
));
8633 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8634 ev
= EVENT_INTERFACE_ENABLED
;
8635 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8636 ev
= EVENT_INTERFACE_DISABLED
;
8637 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8638 ev
= EVENT_AVOID_FREQUENCIES
;
8641 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8643 wpa_supplicant_event(wpa_s
, ev
, &event
);
8644 os_free(event
.freq_range
.range
);
8646 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8647 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8649 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8654 wpa_supplicant_event(wpa_s
, ev
, &event
);
8660 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8663 u8 src
[ETH_ALEN
], *buf
;
8667 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8670 used
= hwaddr_aton2(pos
, src
);
8677 len
= os_strlen(pos
);
8682 buf
= os_malloc(len
);
8686 if (hexstr2bin(pos
, buf
, len
) < 0) {
8691 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8698 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8702 const u16
*pos
= buf
;
8704 for (i
= 0; i
< len
/ 2; i
++)
8708 sum
= (sum
& 0xffff) + (sum
>> 16);
8710 return sum
^ 0xffff;
8714 #define HWSIM_PACKETLEN 1500
8715 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8717 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8720 struct wpa_supplicant
*wpa_s
= ctx
;
8721 const struct ether_header
*eth
;
8726 if (len
!= HWSIM_PACKETLEN
)
8729 eth
= (const struct ether_header
*) buf
;
8730 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8731 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8733 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8734 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8737 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
8743 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
8744 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
8748 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8751 int enabled
= atoi(cmd
);
8756 if (wpa_s
->l2_test
) {
8757 l2_packet_deinit(wpa_s
->l2_test
);
8758 wpa_s
->l2_test
= NULL
;
8759 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8767 pos
= os_strstr(cmd
, " ifname=");
8771 ifname
= wpa_s
->ifname
;
8773 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8774 ETHERTYPE_IP
, wpas_data_test_rx
,
8776 if (wpa_s
->l2_test
== NULL
)
8779 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8785 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8787 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8792 u8 buf
[2 + HWSIM_PACKETLEN
];
8793 struct ether_header
*eth
;
8798 if (wpa_s
->l2_test
== NULL
)
8801 /* format: <dst> <src> <tos> */
8804 used
= hwaddr_aton2(pos
, dst
);
8810 used
= hwaddr_aton2(pos
, src
);
8815 val
= strtol(pos
, NULL
, 0);
8816 if (val
< 0 || val
> 0xff)
8820 eth
= (struct ether_header
*) &buf
[2];
8821 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8822 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8823 eth
->ether_type
= htons(ETHERTYPE_IP
);
8824 ip
= (struct iphdr
*) (eth
+ 1);
8825 os_memset(ip
, 0, sizeof(*ip
));
8830 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8832 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8833 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8834 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8835 dpos
= (u8
*) (ip
+ 1);
8836 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8839 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8840 HWSIM_PACKETLEN
) < 0)
8843 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8844 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8850 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8854 struct ether_header
*eth
;
8855 struct l2_packet_data
*l2
= NULL
;
8860 len
= os_strlen(cmd
);
8861 if (len
& 1 || len
< ETH_HLEN
* 2)
8865 buf
= os_malloc(len
);
8869 if (hexstr2bin(cmd
, buf
, len
) < 0)
8872 eth
= (struct ether_header
*) buf
;
8873 ethertype
= ntohs(eth
->ether_type
);
8875 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8876 wpas_data_test_rx
, wpa_s
, 1);
8880 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8881 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8884 l2_packet_deinit(l2
);
8887 return res
< 0 ? -1 : 0;
8891 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8893 #ifdef WPA_TRACE_BFD
8896 wpa_trace_fail_after
= atoi(cmd
);
8897 pos
= os_strchr(cmd
, ':');
8900 os_strlcpy(wpa_trace_fail_func
, pos
,
8901 sizeof(wpa_trace_fail_func
));
8903 wpa_trace_fail_after
= 0;
8906 #else /* WPA_TRACE_BFD */
8908 #endif /* WPA_TRACE_BFD */
8912 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8913 char *buf
, size_t buflen
)
8915 #ifdef WPA_TRACE_BFD
8916 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8917 wpa_trace_fail_func
);
8918 #else /* WPA_TRACE_BFD */
8920 #endif /* WPA_TRACE_BFD */
8924 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8926 #ifdef WPA_TRACE_BFD
8929 wpa_trace_test_fail_after
= atoi(cmd
);
8930 pos
= os_strchr(cmd
, ':');
8933 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8934 sizeof(wpa_trace_test_fail_func
));
8936 wpa_trace_test_fail_after
= 0;
8939 #else /* WPA_TRACE_BFD */
8941 #endif /* WPA_TRACE_BFD */
8945 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8946 char *buf
, size_t buflen
)
8948 #ifdef WPA_TRACE_BFD
8949 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8950 wpa_trace_test_fail_func
);
8951 #else /* WPA_TRACE_BFD */
8953 #endif /* WPA_TRACE_BFD */
8957 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8959 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8960 int i
, count
= (intptr_t) timeout_ctx
;
8962 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8964 for (i
= 0; i
< count
; i
++) {
8965 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8971 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8979 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8980 (void *) (intptr_t) count
);
8984 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8990 len
= os_strlen(cmd
);
8998 buf
= wpabuf_alloc(len
);
9002 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
9008 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
9013 static int wpas_ctrl_reset_pn(struct wpa_supplicant
*wpa_s
)
9015 u8 zero
[WPA_TK_MAX_LEN
];
9017 if (wpa_s
->last_tk_alg
== WPA_ALG_NONE
)
9020 wpa_printf(MSG_INFO
, "TESTING: Reset PN");
9021 os_memset(zero
, 0, sizeof(zero
));
9023 /* First, use a zero key to avoid any possible duplicate key avoidance
9025 if (wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9026 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9027 zero
, wpa_s
->last_tk_len
) < 0)
9030 /* Set the previously configured key to reset its TSC/RSC */
9031 return wpa_drv_set_key(wpa_s
, wpa_s
->last_tk_alg
, wpa_s
->last_tk_addr
,
9032 wpa_s
->last_tk_key_idx
, 1, zero
, 6,
9033 wpa_s
->last_tk
, wpa_s
->last_tk_len
);
9037 static int wpas_ctrl_key_request(struct wpa_supplicant
*wpa_s
, const char *cmd
)
9039 const char *pos
= cmd
;
9040 int error
, pairwise
;
9043 pos
= os_strchr(pos
, ' ');
9046 pairwise
= atoi(pos
);
9047 wpa_sm_key_request(wpa_s
->wpa
, error
, pairwise
);
9052 static int wpas_ctrl_resend_assoc(struct wpa_supplicant
*wpa_s
)
9055 struct wpa_driver_associate_params params
;
9058 os_memset(¶ms
, 0, sizeof(params
));
9059 params
.bssid
= wpa_s
->bssid
;
9060 params
.ssid
= wpa_s
->sme
.ssid
;
9061 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
9062 params
.freq
.freq
= wpa_s
->sme
.freq
;
9063 if (wpa_s
->last_assoc_req_wpa_ie
) {
9064 params
.wpa_ie
= wpabuf_head(wpa_s
->last_assoc_req_wpa_ie
);
9065 params
.wpa_ie_len
= wpabuf_len(wpa_s
->last_assoc_req_wpa_ie
);
9067 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
9068 params
.group_suite
= wpa_s
->group_cipher
;
9069 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
9070 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
9071 params
.wpa_proto
= wpa_s
->wpa_proto
;
9072 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
9073 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
9074 if (wpa_s
->sme
.prev_bssid_set
)
9075 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
9076 wpa_printf(MSG_INFO
, "TESTING: Resend association request");
9077 ret
= wpa_drv_associate(wpa_s
, ¶ms
);
9078 wpa_s
->testing_resend_assoc
= 1;
9080 #else /* CONFIG_SME */
9082 #endif /* CONFIG_SME */
9085 #endif /* CONFIG_TESTING_OPTIONS */
9088 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
9094 struct ieee802_11_elems elems
;
9097 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9099 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9101 pos
= os_strchr(pos
, ' ');
9106 len
= os_strlen(pos
);
9113 buf
= wpabuf_alloc(len
);
9117 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
9122 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
9128 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
9129 wpa_s
->vendor_elem
[frame
] = buf
;
9130 wpas_vendor_elem_update(wpa_s
);
9134 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
9139 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
9141 wpas_vendor_elem_update(wpa_s
);
9147 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
9148 char *buf
, size_t buflen
)
9150 int frame
= atoi(cmd
);
9152 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9154 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9156 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9159 return wpa_snprintf_hex(buf
, buflen
,
9160 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
9161 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
9165 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
9171 struct ieee802_11_elems elems
;
9175 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
9177 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
9179 pos
= os_strchr(pos
, ' ');
9185 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
9186 wpa_s
->vendor_elem
[frame
] = NULL
;
9187 wpas_vendor_elem_update(wpa_s
);
9191 if (wpa_s
->vendor_elem
[frame
] == NULL
)
9194 len
= os_strlen(pos
);
9201 buf
= os_malloc(len
);
9205 if (hexstr2bin(pos
, buf
, len
) < 0) {
9210 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
9215 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
9221 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
9223 struct wpa_supplicant
*wpa_s
= ctx
;
9228 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9230 * BSSID Information[4]
9231 * Operating Class[1]
9234 * Optional Subelements[variable]
9236 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9238 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
9239 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
9243 data
= wpabuf_head_u8(neighbor_rep
);
9244 len
= wpabuf_len(neighbor_rep
);
9246 while (len
>= 2 + NR_IE_MIN_LEN
) {
9248 char lci
[256 * 2 + 1];
9249 char civic
[256 * 2 + 1];
9250 u8 nr_len
= data
[1];
9251 const u8
*pos
= data
, *end
;
9253 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
9254 nr_len
< NR_IE_MIN_LEN
) {
9255 wpa_printf(MSG_DEBUG
,
9256 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9261 if (2U + nr_len
> len
) {
9262 wpa_printf(MSG_DEBUG
,
9263 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9264 data
[0], len
, nr_len
);
9271 pos
+= NR_IE_MIN_LEN
;
9275 while (end
- pos
> 2) {
9280 if (s_len
> end
- pos
)
9282 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
9283 /* Measurement Token[1] */
9284 /* Measurement Report Mode[1] */
9285 /* Measurement Type[1] */
9286 /* Measurement Report[variable] */
9288 case MEASURE_TYPE_LCI
:
9291 wpa_snprintf_hex(lci
, sizeof(lci
),
9294 case MEASURE_TYPE_LOCATION_CIVIC
:
9297 wpa_snprintf_hex(civic
, sizeof(civic
),
9306 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9308 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9309 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9310 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9312 lci
[0] ? " lci=" : "", lci
,
9313 civic
[0] ? " civic=" : "", civic
);
9320 wpabuf_free(neighbor_rep
);
9324 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9327 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9328 int ret
, lci
= 0, civic
= 0;
9331 ssid_s
= os_strstr(cmd
, "ssid=");
9333 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9334 wpa_printf(MSG_ERROR
,
9335 "CTRL: Send Neighbor Report: bad SSID");
9342 * Move cmd after the SSID text that may include "lci" or
9345 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9351 if (cmd
&& os_strstr(cmd
, "lci"))
9354 if (cmd
&& os_strstr(cmd
, "civic"))
9357 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9358 wpas_ctrl_neighbor_rep_cb
,
9365 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9367 eapol_sm_erp_flush(wpa_s
->eapol
);
9372 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9375 char *token
, *context
= NULL
;
9376 unsigned int enable
= ~0, type
= 0;
9377 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9378 u8
*addr
= NULL
, *mask
= NULL
;
9380 while ((token
= str_token(cmd
, " ", &context
))) {
9381 if (os_strcasecmp(token
, "scan") == 0) {
9382 type
|= MAC_ADDR_RAND_SCAN
;
9383 } else if (os_strcasecmp(token
, "sched") == 0) {
9384 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9385 } else if (os_strcasecmp(token
, "pno") == 0) {
9386 type
|= MAC_ADDR_RAND_PNO
;
9387 } else if (os_strcasecmp(token
, "all") == 0) {
9388 type
= wpa_s
->mac_addr_rand_supported
;
9389 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9390 enable
= atoi(token
+ 7);
9391 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9393 if (hwaddr_aton(token
+ 5, addr
)) {
9394 wpa_printf(MSG_INFO
,
9395 "CTRL: Invalid MAC address: %s",
9399 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9401 if (hwaddr_aton(token
+ 5, mask
)) {
9402 wpa_printf(MSG_INFO
,
9403 "CTRL: Invalid MAC address mask: %s",
9408 wpa_printf(MSG_INFO
,
9409 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9416 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9420 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
9421 wpa_printf(MSG_INFO
,
9422 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9423 type
, wpa_s
->mac_addr_rand_supported
);
9428 wpa_printf(MSG_INFO
,
9429 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9434 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
9436 if (type
& MAC_ADDR_RAND_PNO
) {
9437 wpas_stop_pno(wpa_s
);
9438 wpas_start_pno(wpa_s
);
9440 } else if (wpa_s
->sched_scanning
&&
9441 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
9442 wpas_scan_restart_sched_scan(wpa_s
);
9447 if ((addr
&& !mask
) || (!addr
&& mask
)) {
9448 wpa_printf(MSG_INFO
,
9449 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9453 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
9454 wpa_printf(MSG_INFO
,
9455 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9459 if (type
& MAC_ADDR_RAND_SCAN
) {
9460 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
9464 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
9465 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
9468 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
9469 wpas_scan_restart_sched_scan(wpa_s
);
9472 if (type
& MAC_ADDR_RAND_PNO
) {
9473 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
9476 wpas_stop_pno(wpa_s
);
9477 wpas_start_pno(wpa_s
);
9485 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9486 char *buf
, size_t buflen
)
9490 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9492 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9493 buflen
- reply_len
);
9494 #endif /* CONFIG_AP */
9499 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9501 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9503 wpas_ap_pmksa_cache_flush(wpa_s
);
9504 #endif /* CONFIG_AP */
9508 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9510 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9511 const char *cmd
, char *buf
, size_t buflen
)
9513 struct rsn_pmksa_cache_entry
*entry
;
9514 struct wpa_ssid
*ssid
;
9515 char *pos
, *pos2
, *end
;
9517 struct os_reltime now
;
9519 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9526 os_get_reltime(&now
);
9530 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9531 * <expiration in seconds> <akmp> <opportunistic>
9532 * [FILS Cache Identifier]
9535 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9536 entry
= entry
->next
) {
9537 if (entry
->network_ctx
!= ssid
)
9541 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9542 MAC2STR(entry
->aa
));
9543 if (os_snprintf_error(end
- pos2
, ret
))
9547 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9550 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9551 if (os_snprintf_error(end
- pos2
, ret
))
9555 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9558 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9559 (int) (entry
->reauth_time
- now
.sec
),
9560 (int) (entry
->expiration
- now
.sec
),
9562 entry
->opportunistic
);
9563 if (os_snprintf_error(end
- pos2
, ret
))
9567 if (entry
->fils_cache_id_set
) {
9568 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9569 entry
->fils_cache_id
[0],
9570 entry
->fils_cache_id
[1]);
9571 if (os_snprintf_error(end
- pos2
, ret
))
9576 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9577 if (os_snprintf_error(end
- pos2
, ret
))
9588 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9591 struct rsn_pmksa_cache_entry
*entry
;
9592 struct wpa_ssid
*ssid
;
9595 struct os_reltime now
;
9596 int reauth_time
= 0, expiration
= 0, i
;
9600 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9601 * <expiration in seconds> <akmp> <opportunistic>
9602 * [FILS Cache Identifier]
9605 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9609 pos
= os_strchr(cmd
, ' ');
9614 entry
= os_zalloc(sizeof(*entry
));
9618 if (hwaddr_aton(pos
, entry
->aa
))
9621 pos
= os_strchr(pos
, ' ');
9626 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9629 pos
= os_strchr(pos
, ' ');
9634 pos2
= os_strchr(pos
, ' ');
9637 entry
->pmk_len
= (pos2
- pos
) / 2;
9638 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9639 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9642 pos
= os_strchr(pos
, ' ');
9647 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9648 &entry
->akmp
, &entry
->opportunistic
) != 4)
9650 for (i
= 0; i
< 4; i
++) {
9651 pos
= os_strchr(pos
, ' ');
9660 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9661 FILS_CACHE_ID_LEN
) < 0)
9663 entry
->fils_cache_id_set
= 1;
9665 os_get_reltime(&now
);
9666 entry
->expiration
= now
.sec
+ expiration
;
9667 entry
->reauth_time
= now
.sec
+ reauth_time
;
9669 entry
->network_ctx
= ssid
;
9671 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9682 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9683 const char *cmd
, char *buf
,
9691 if (os_strcasecmp(cmd
, "any") == 0)
9692 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9694 if (hwaddr_aton(cmd
, spa
))
9697 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9701 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9705 * We do not check mesh interface existance because PMKSA should be
9706 * stored before wpa_s->ifmsh creation to suppress commit message
9709 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9712 #endif /* CONFIG_MESH */
9713 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9717 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9720 struct fils_hlp_req
*req
;
9723 /* format: <dst> <packet starting from ethertype> */
9725 req
= os_zalloc(sizeof(*req
));
9729 if (hwaddr_aton(cmd
, req
->dst
))
9732 pos
= os_strchr(cmd
, ' ');
9736 req
->pkt
= wpabuf_parse_bin(pos
);
9740 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9743 wpabuf_free(req
->pkt
);
9747 #endif /* CONFIG_FILS */
9750 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9752 if (os_strcmp(cmd
, "PING") == 0 ||
9753 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9754 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9755 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9756 os_strncmp(cmd
, "STA ", 4) == 0 ||
9757 os_strncmp(cmd
, "STA-", 4) == 0)
9758 return MSG_EXCESSIVE
;
9763 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9764 char *buf
, size_t *resp_len
)
9767 const int reply_size
= 4096;
9770 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9771 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9772 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9773 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9774 if (wpa_debug_show_keys
)
9775 wpa_dbg(wpa_s
, MSG_DEBUG
,
9776 "Control interface command '%s'", buf
);
9778 wpa_dbg(wpa_s
, MSG_DEBUG
,
9779 "Control interface command '%s [REMOVED]'",
9780 os_strncmp(buf
, WPA_CTRL_RSP
,
9781 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9783 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9784 "SET_NETWORK" : "key-add"));
9785 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9786 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9787 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9788 (const u8
*) buf
, os_strlen(buf
));
9790 int level
= wpas_ctrl_cmd_debug_level(buf
);
9791 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9794 reply
= os_malloc(reply_size
);
9795 if (reply
== NULL
) {
9800 os_memcpy(reply
, "OK\n", 3);
9803 if (os_strcmp(buf
, "PING") == 0) {
9804 os_memcpy(reply
, "PONG\n", 5);
9806 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9807 reply_len
= os_strlen(wpa_s
->ifname
);
9808 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9809 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9810 if (wpa_debug_reopen_file() < 0)
9812 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9813 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9814 } else if (os_strcmp(buf
, "MIB") == 0) {
9815 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9816 if (reply_len
>= 0) {
9817 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9819 reply_size
- reply_len
);
9821 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9822 reply_len
= wpa_supplicant_ctrl_iface_status(
9823 wpa_s
, buf
+ 6, reply
, reply_size
);
9824 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9825 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9826 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9827 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9828 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9829 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9830 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9832 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9833 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9836 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9837 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9839 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9840 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9842 #endif /* CONFIG_MESH */
9843 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9844 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9845 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9847 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9848 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9850 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9851 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9853 } else if (os_strcmp(buf
, "LOGON") == 0) {
9854 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9855 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9856 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9857 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9858 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9861 wpas_request_connection(wpa_s
);
9862 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9863 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9864 !wpa_s
->current_ssid
)
9867 wpa_s
->reattach
= 1;
9868 wpas_request_connection(wpa_s
);
9870 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9871 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9873 else if (wpa_s
->disconnected
)
9874 wpas_request_connection(wpa_s
);
9875 #ifdef IEEE8021X_EAPOL
9876 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9877 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9879 #endif /* IEEE8021X_EAPOL */
9880 #ifdef CONFIG_IEEE80211R
9881 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9882 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9884 #endif /* CONFIG_IEEE80211R */
9886 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9887 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9889 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9893 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9894 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9896 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9900 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9901 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9904 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9905 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9906 wpa_s
, buf
+ 14, reply
, reply_size
);
9907 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9908 if (wpas_wps_cancel(wpa_s
))
9910 #ifdef CONFIG_WPS_NFC
9911 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
9912 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
9914 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
9915 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
9917 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9918 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9919 wpa_s
, buf
+ 21, reply
, reply_size
);
9920 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
9921 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
9922 wpa_s
, buf
+ 14, reply
, reply_size
);
9923 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
9924 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
9927 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9928 reply_len
= wpas_ctrl_nfc_get_handover_req(
9929 wpa_s
, buf
+ 21, reply
, reply_size
);
9930 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9931 reply_len
= wpas_ctrl_nfc_get_handover_sel(
9932 wpa_s
, buf
+ 21, reply
, reply_size
);
9933 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
9934 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
9936 #endif /* CONFIG_WPS_NFC */
9937 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
9938 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
9941 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
9942 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
9943 wpa_s
, buf
+ 11, reply
, reply_size
);
9944 #endif /* CONFIG_AP */
9945 #ifdef CONFIG_WPS_ER
9946 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
9947 if (wpas_wps_er_start(wpa_s
, NULL
))
9949 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
9950 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
9952 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
9953 wpas_wps_er_stop(wpa_s
);
9954 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
9955 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
9957 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
9958 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
9960 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9962 } else if (ret
== -3) {
9963 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
9965 } else if (ret
== -4) {
9966 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
9970 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
9971 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
9973 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
9974 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
9977 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
9978 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
9980 #ifdef CONFIG_WPS_NFC
9981 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9982 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9983 wpa_s
, buf
+ 24, reply
, reply_size
);
9984 #endif /* CONFIG_WPS_NFC */
9985 #endif /* CONFIG_WPS_ER */
9986 #endif /* CONFIG_WPS */
9987 #ifdef CONFIG_IBSS_RSN
9988 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
9989 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
9991 #endif /* CONFIG_IBSS_RSN */
9993 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
9994 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9995 wpa_s
, buf
+ 19, reply
, reply_size
);
9996 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
9997 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9998 wpa_s
, "", reply
, reply_size
);
9999 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
10000 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
10002 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
10003 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
10006 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
10007 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
10009 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
10010 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
10012 #endif /* CONFIG_MESH */
10014 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
10015 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
10017 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
10018 if (p2p_ctrl_find(wpa_s
, ""))
10020 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
10021 wpas_p2p_stop_find(wpa_s
);
10022 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
10023 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
10025 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10026 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
10028 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
10029 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
10031 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
10032 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
10034 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
10035 if (p2p_ctrl_listen(wpa_s
, ""))
10037 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
10038 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
10040 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
10041 if (p2p_ctrl_group_add(wpa_s
, ""))
10043 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
10044 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
10046 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
10047 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
10049 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
10050 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
10052 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
10053 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
10054 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
10055 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
10057 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10058 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
10060 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
10061 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
10063 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
10064 wpas_p2p_sd_service_update(wpa_s
);
10065 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10066 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
10068 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
10069 wpas_p2p_service_flush(wpa_s
);
10070 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
10071 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
10073 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
10074 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
10076 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
10077 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
10079 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
10080 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
10082 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
10083 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
10085 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
10086 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
10088 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
10089 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
10091 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
10092 p2p_ctrl_flush(wpa_s
);
10093 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
10094 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
10096 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
10097 if (wpas_p2p_cancel(wpa_s
))
10099 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
10100 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
10102 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
10103 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
10105 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
10106 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
10108 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
10109 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
10111 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
10112 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
10114 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
10115 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
10117 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
10118 if (wpas_p2p_lo_stop(wpa_s
))
10120 #endif /* CONFIG_P2P */
10121 #ifdef CONFIG_WIFI_DISPLAY
10122 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
10123 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
10125 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
10126 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
10127 reply
, reply_size
);
10128 #endif /* CONFIG_WIFI_DISPLAY */
10129 #ifdef CONFIG_INTERWORKING
10130 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
10131 if (interworking_fetch_anqp(wpa_s
) < 0)
10133 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
10134 interworking_stop_fetch_anqp(wpa_s
);
10135 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
10136 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
10138 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
10139 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
10141 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
10142 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
10144 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10147 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
10151 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
10152 if (os_snprintf_error(reply_size
, reply_len
))
10155 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
10156 if (get_anqp(wpa_s
, buf
+ 9) < 0)
10158 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
10159 if (gas_request(wpa_s
, buf
+ 12) < 0)
10161 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
10162 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
10164 #endif /* CONFIG_INTERWORKING */
10166 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
10167 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
10169 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10170 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
10172 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
10173 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
10175 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
10176 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
10178 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
10179 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
10180 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
10181 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
10183 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
10184 if (hs20_fetch_osu(wpa_s
, 0) < 0)
10186 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
10187 if (hs20_fetch_osu(wpa_s
, 1) < 0)
10189 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
10190 hs20_cancel_fetch_osu(wpa_s
);
10191 #endif /* CONFIG_HS20 */
10192 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
10194 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10195 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
10199 * Notify response from timeout to allow the control
10200 * interface response to be sent first.
10202 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
10205 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
10206 if (wpa_supplicant_reload_configuration(wpa_s
))
10208 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10209 wpa_supplicant_terminate_proc(wpa_s
->global
);
10210 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
10211 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
10213 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
10214 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
10215 wpa_s
, buf
+ 9, reply
, reply_size
);
10216 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
10217 reply_len
= wpa_supplicant_ctrl_iface_log_level(
10218 wpa_s
, buf
+ 9, reply
, reply_size
);
10219 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
10220 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10221 wpa_s
, buf
+ 14, reply
, reply_size
);
10222 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
10223 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
10224 wpa_s
, NULL
, reply
, reply_size
);
10225 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
10226 wpas_request_disconnection(wpa_s
);
10227 } else if (os_strcmp(buf
, "SCAN") == 0) {
10228 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
10229 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
10230 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
10231 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
10232 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
10233 wpa_s
, reply
, reply_size
);
10234 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
10235 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
10237 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
10238 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
10240 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
10241 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
10243 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
10244 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
10246 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
10247 reply_len
= wpa_supplicant_ctrl_iface_add_network(
10248 wpa_s
, reply
, reply_size
);
10249 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
10250 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
10252 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
10253 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
10255 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
10256 reply_len
= wpa_supplicant_ctrl_iface_get_network(
10257 wpa_s
, buf
+ 12, reply
, reply_size
);
10258 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10259 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
10262 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
10263 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
10264 wpa_s
, reply
, reply_size
);
10265 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
10266 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
10267 wpa_s
, reply
, reply_size
);
10268 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
10269 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
10271 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
10272 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
10274 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
10275 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
10278 #ifndef CONFIG_NO_CONFIG_WRITE
10279 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10280 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
10282 #endif /* CONFIG_NO_CONFIG_WRITE */
10283 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
10284 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
10285 wpa_s
, buf
+ 15, reply
, reply_size
);
10286 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10287 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10289 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10290 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10292 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10293 reply_len
= wpa_supplicant_global_iface_list(
10294 wpa_s
->global
, reply
, reply_size
);
10295 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10296 reply_len
= wpa_supplicant_global_iface_interfaces(
10297 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10298 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10299 reply_len
= wpa_supplicant_ctrl_iface_bss(
10300 wpa_s
, buf
+ 4, reply
, reply_size
);
10302 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10303 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10304 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10305 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10307 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10308 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10310 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10311 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10313 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10314 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10316 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10317 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10319 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10320 if (wpas_ap_stop_ap(wpa_s
))
10322 #endif /* CONFIG_AP */
10323 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10324 wpas_notify_suspend(wpa_s
->global
);
10325 } else if (os_strcmp(buf
, "RESUME") == 0) {
10326 wpas_notify_resume(wpa_s
->global
);
10327 #ifdef CONFIG_TESTING_OPTIONS
10328 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10329 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10330 #endif /* CONFIG_TESTING_OPTIONS */
10331 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10332 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10334 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10335 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10336 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10337 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10339 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10340 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10343 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10344 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10346 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10347 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10349 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10350 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10352 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10353 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10355 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10356 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10359 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10360 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10363 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10364 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10365 wpa_s
, buf
+ 17, reply
, reply_size
);
10366 #endif /* CONFIG_TDLS */
10367 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10368 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10369 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10370 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10372 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10373 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10375 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10376 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10378 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10379 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10381 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10382 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10384 #ifdef CONFIG_AUTOSCAN
10385 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10386 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10388 #endif /* CONFIG_AUTOSCAN */
10389 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10390 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10393 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10394 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10396 #endif /* ANDROID */
10397 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10398 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10400 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10401 pmksa_cache_clear_current(wpa_s
->wpa
);
10402 eapol_sm_request_reauth(wpa_s
->eapol
);
10404 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10405 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10407 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10408 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10410 #endif /* CONFIG_WNM */
10411 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10412 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10413 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10414 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10416 #ifdef CONFIG_TESTING_OPTIONS
10417 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10418 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10420 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10421 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10422 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10423 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10425 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10426 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10428 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10429 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10431 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10432 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10434 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10435 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10437 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10438 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10440 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10441 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10443 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10444 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10445 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10446 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10448 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10449 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10450 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10451 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10453 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10454 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10456 } else if (os_strcmp(buf
, "RESET_PN") == 0) {
10457 if (wpas_ctrl_reset_pn(wpa_s
) < 0)
10459 } else if (os_strncmp(buf
, "KEY_REQUEST ", 12) == 0) {
10460 if (wpas_ctrl_key_request(wpa_s
, buf
+ 12) < 0)
10462 } else if (os_strcmp(buf
, "RESEND_ASSOC") == 0) {
10463 if (wpas_ctrl_resend_assoc(wpa_s
) < 0)
10465 #endif /* CONFIG_TESTING_OPTIONS */
10466 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10467 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10469 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10470 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10472 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10473 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10475 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10476 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10478 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10479 wpas_ctrl_iface_erp_flush(wpa_s
);
10480 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10481 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10483 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10484 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10485 wpa_s
, buf
+ 19, reply
, reply_size
);
10487 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10488 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10490 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10491 wpas_flush_fils_hlp_req(wpa_s
);
10492 #endif /* CONFIG_FILS */
10494 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10497 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10501 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10502 if (os_snprintf_error(reply_size
, reply_len
))
10505 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10508 res
= wpas_dpp_bootstrap_gen(wpa_s
, buf
+ 18);
10512 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10513 if (os_snprintf_error(reply_size
, reply_len
))
10516 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10517 if (wpas_dpp_bootstrap_remove(wpa_s
, buf
+ 21) < 0)
10519 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10522 uri
= wpas_dpp_bootstrap_get_uri(wpa_s
, atoi(buf
+ 22));
10526 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10527 if (os_snprintf_error(reply_size
, reply_len
))
10530 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10531 reply_len
= wpas_dpp_bootstrap_info(wpa_s
, atoi(buf
+ 19),
10532 reply
, reply_size
);
10533 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10534 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10536 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10537 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10539 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10540 wpas_dpp_stop(wpa_s
);
10541 wpas_dpp_listen_stop(wpa_s
);
10542 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10545 res
= wpas_dpp_configurator_add(wpa_s
, buf
+ 20);
10549 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10550 if (os_snprintf_error(reply_size
, reply_len
))
10553 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10554 if (wpas_dpp_configurator_remove(wpa_s
, buf
+ 24) < 0)
10556 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10557 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 22) < 0)
10559 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10560 reply_len
= wpas_dpp_configurator_get_key(wpa_s
, atoi(buf
+ 25),
10561 reply
, reply_size
);
10562 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10565 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10569 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10570 if (os_snprintf_error(reply_size
, reply_len
))
10573 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10574 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10576 #endif /* CONFIG_DPP */
10578 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10582 if (reply_len
< 0) {
10583 os_memcpy(reply
, "FAIL\n", 5);
10587 *resp_len
= reply_len
;
10592 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10595 struct wpa_interface iface
;
10597 struct wpa_supplicant
*wpa_s
;
10598 unsigned int create_iface
= 0;
10599 u8 mac_addr
[ETH_ALEN
];
10600 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10603 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10604 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10606 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10608 os_memset(&iface
, 0, sizeof(iface
));
10611 iface
.ifname
= pos
= cmd
;
10612 pos
= os_strchr(pos
, '\t');
10615 if (iface
.ifname
[0] == '\0')
10620 iface
.confname
= pos
;
10621 pos
= os_strchr(pos
, '\t');
10624 if (iface
.confname
[0] == '\0')
10625 iface
.confname
= NULL
;
10629 iface
.driver
= pos
;
10630 pos
= os_strchr(pos
, '\t');
10633 if (iface
.driver
[0] == '\0')
10634 iface
.driver
= NULL
;
10638 iface
.ctrl_interface
= pos
;
10639 pos
= os_strchr(pos
, '\t');
10642 if (iface
.ctrl_interface
[0] == '\0')
10643 iface
.ctrl_interface
= NULL
;
10647 iface
.driver_param
= pos
;
10648 pos
= os_strchr(pos
, '\t');
10651 if (iface
.driver_param
[0] == '\0')
10652 iface
.driver_param
= NULL
;
10656 iface
.bridge_ifname
= pos
;
10657 pos
= os_strchr(pos
, '\t');
10660 if (iface
.bridge_ifname
[0] == '\0')
10661 iface
.bridge_ifname
= NULL
;
10666 pos
= os_strchr(pos
, '\t');
10672 if (os_strcmp(extra
, "create") == 0) {
10677 if (os_strcmp(pos
, "sta") == 0) {
10678 type
= WPA_IF_STATION
;
10679 } else if (os_strcmp(pos
, "ap") == 0) {
10680 type
= WPA_IF_AP_BSS
;
10682 wpa_printf(MSG_DEBUG
,
10683 "INTERFACE_ADD unsupported interface type: '%s'",
10688 wpa_printf(MSG_DEBUG
,
10689 "INTERFACE_ADD unsupported extra parameter: '%s'",
10695 if (create_iface
) {
10696 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10698 if (!global
->ifaces
)
10700 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10701 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10702 wpa_printf(MSG_ERROR
,
10703 "CTRL_IFACE interface creation failed");
10707 wpa_printf(MSG_DEBUG
,
10708 "CTRL_IFACE interface '%s' created with MAC addr: "
10709 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10712 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10715 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10718 wpa_s
->added_vif
= create_iface
;
10723 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10728 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10731 struct wpa_supplicant
*wpa_s
;
10733 unsigned int delete_iface
;
10735 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10737 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10740 delete_iface
= wpa_s
->added_vif
;
10741 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10742 if (!ret
&& delete_iface
) {
10743 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10745 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10751 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10753 struct wpa_interface_info
*prev
;
10757 iface
= iface
->next
;
10759 os_free(prev
->ifname
);
10760 os_free(prev
->desc
);
10766 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10767 char *buf
, int len
)
10770 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10773 for (i
= 0; wpa_drivers
[i
]; i
++) {
10774 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10775 if (drv
->get_interfaces
== NULL
)
10777 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10782 iface
= last
= tmp
;
10791 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10792 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10793 tmp
->drv_name
, tmp
->ifname
,
10794 tmp
->desc
? tmp
->desc
: "");
10795 if (os_snprintf_error(end
- pos
, res
)) {
10802 wpa_free_iface_info(iface
);
10808 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10810 char *buf
, int len
)
10814 struct wpa_supplicant
*wpa_s
;
10818 show_ctrl
= !!os_strstr(input
, "ctrl");
10820 wpa_s
= global
->ifaces
;
10826 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10828 wpa_s
->conf
->ctrl_interface
?
10829 wpa_s
->conf
->ctrl_interface
: "N/A");
10831 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10834 if (os_snprintf_error(end
- pos
, res
)) {
10839 wpa_s
= wpa_s
->next
;
10845 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10846 const char *ifname
,
10847 char *cmd
, size_t *resp_len
)
10849 struct wpa_supplicant
*wpa_s
;
10851 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10852 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10856 if (wpa_s
== NULL
) {
10857 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10859 *resp_len
= os_strlen(resp
);
10865 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10869 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10870 char *buf
, size_t *resp_len
)
10873 static const char * cmd
[] = {
10879 "P2P_GET_PASSPHRASE",
10880 "P2P_SERVICE_UPDATE",
10881 "P2P_SERVICE_FLUSH",
10884 "P2P_PRESENCE_REQ",
10888 #endif /* CONFIG_AP */
10891 static const char * prefix
[] = {
10894 #endif /* ANDROID */
10901 "P2P_GROUP_REMOVE ",
10903 "P2P_GROUP_MEMBER ",
10905 "P2P_SERV_DISC_REQ ",
10906 "P2P_SERV_DISC_CANCEL_REQ ",
10907 "P2P_SERV_DISC_RESP ",
10908 "P2P_SERV_DISC_EXTERNAL ",
10909 "P2P_SERVICE_ADD ",
10910 "P2P_SERVICE_DEL ",
10911 "P2P_SERVICE_REP ",
10916 "P2P_UNAUTHORIZE ",
10917 "P2P_PRESENCE_REQ ",
10919 "P2P_REMOVE_CLIENT ",
10921 "WPS_NFC_TAG_READ ",
10922 "NFC_GET_HANDOVER_SEL ",
10923 "NFC_GET_HANDOVER_REQ ",
10924 "NFC_REPORT_HANDOVER ",
10925 "P2P_ASP_PROVISION ",
10926 "P2P_ASP_PROVISION_RESP ",
10930 #endif /* CONFIG_AP */
10936 if (global
->p2p_init_wpa_s
== NULL
)
10939 for (i
= 0; !found
&& cmd
[i
]; i
++) {
10940 if (os_strcmp(buf
, cmd
[i
]) == 0)
10944 for (i
= 0; !found
&& prefix
[i
]; i
++) {
10945 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
10950 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10952 #endif /* CONFIG_P2P */
10957 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
10958 char *buf
, size_t *resp_len
)
10960 #ifdef CONFIG_WIFI_DISPLAY
10961 if (global
->p2p_init_wpa_s
== NULL
)
10963 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
10964 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
10965 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10967 #endif /* CONFIG_WIFI_DISPLAY */
10972 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
10973 char *buf
, size_t *resp_len
)
10977 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
10981 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
10989 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
10993 value
= os_strchr(cmd
, ' ');
10998 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
11000 #ifdef CONFIG_WIFI_DISPLAY
11001 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
11002 wifi_display_enable(global
, !!atoi(value
));
11005 #endif /* CONFIG_WIFI_DISPLAY */
11007 /* Restore cmd to its original value to allow redirection */
11014 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
11017 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
11021 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11022 * <variable name> */
11024 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
11025 p
= os_strchr(cmd
, ' ');
11030 wpa_s
[i
] = global
->ifaces
;
11031 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
11032 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
11037 wpa_printf(MSG_DEBUG
,
11038 "CTRL_IFACE: Could not find iface=%s", cmd
);
11045 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
11049 #ifndef CONFIG_NO_CONFIG_WRITE
11050 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
11052 int ret
= 0, saved
= 0;
11053 struct wpa_supplicant
*wpa_s
;
11055 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11056 if (!wpa_s
->conf
->update_config
) {
11057 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11061 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
11062 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11065 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
11070 if (!saved
&& !ret
) {
11071 wpa_dbg(wpa_s
, MSG_DEBUG
,
11072 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11078 #endif /* CONFIG_NO_CONFIG_WRITE */
11081 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
11082 char *buf
, size_t buflen
)
11086 struct wpa_supplicant
*wpa_s
;
11089 end
= buf
+ buflen
;
11092 if (global
->p2p
&& !global
->p2p_disabled
) {
11093 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
11096 MAC2STR(global
->p2p_dev_addr
),
11097 p2p_get_state_txt(global
->p2p
));
11098 if (os_snprintf_error(end
- pos
, ret
))
11101 } else if (global
->p2p
) {
11102 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
11103 if (os_snprintf_error(end
- pos
, ret
))
11107 #endif /* CONFIG_P2P */
11109 #ifdef CONFIG_WIFI_DISPLAY
11110 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
11111 !!global
->wifi_display
);
11112 if (os_snprintf_error(end
- pos
, ret
))
11115 #endif /* CONFIG_WIFI_DISPLAY */
11117 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
11118 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
11119 "address=" MACSTR
"\n",
11120 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
11121 if (os_snprintf_error(end
- pos
, ret
))
11132 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
11133 char *cmd
, char *buf
,
11136 char ifname
[IFNAMSIZ
+ 1];
11137 struct fst_iface_cfg cfg
;
11138 struct wpa_supplicant
*wpa_s
;
11139 struct fst_wpa_obj iface_obj
;
11141 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
11142 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11145 wpa_printf(MSG_INFO
, "FST: Already attached");
11148 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
11149 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
11152 return os_snprintf(buf
, reply_size
, "OK\n");
11160 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
11161 char *cmd
, char *buf
,
11164 char ifname
[IFNAMSIZ
+ 1];
11165 struct wpa_supplicant
*wpa_s
;
11167 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
11168 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
11170 if (!fst_iface_detach(ifname
)) {
11172 return os_snprintf(buf
, reply_size
, "OK\n");
11180 #endif /* CONFIG_FST */
11183 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
11184 char *buf
, size_t *resp_len
)
11187 const int reply_size
= 2048;
11189 int level
= MSG_DEBUG
;
11191 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
11192 char *pos
= os_strchr(buf
+ 7, ' ');
11195 return wpas_global_ctrl_iface_ifname(global
,
11201 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
11205 if (os_strcmp(buf
, "PING") == 0)
11206 level
= MSG_EXCESSIVE
;
11207 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
11208 (const u8
*) buf
, os_strlen(buf
));
11210 reply
= os_malloc(reply_size
);
11211 if (reply
== NULL
) {
11216 os_memcpy(reply
, "OK\n", 3);
11219 if (os_strcmp(buf
, "PING") == 0) {
11220 os_memcpy(reply
, "PONG\n", 5);
11222 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
11223 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
11225 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
11226 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
11228 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
11229 reply_len
= wpa_supplicant_global_iface_list(
11230 global
, reply
, reply_size
);
11231 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
11232 reply_len
= wpa_supplicant_global_iface_interfaces(
11233 global
, buf
+ 10, reply
, reply_size
);
11235 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
11236 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
11239 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
11240 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
11243 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
11244 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
11245 #endif /* CONFIG_FST */
11246 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
11247 wpa_supplicant_terminate_proc(global
);
11248 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
11249 wpas_notify_suspend(global
);
11250 } else if (os_strcmp(buf
, "RESUME") == 0) {
11251 wpas_notify_resume(global
);
11252 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
11253 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
11255 if (global
->p2p_init_wpa_s
) {
11257 /* Check if P2P redirection would work for this
11259 return wpa_supplicant_ctrl_iface_process(
11260 global
->p2p_init_wpa_s
,
11263 #endif /* CONFIG_P2P */
11266 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
11267 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
11269 #ifndef CONFIG_NO_CONFIG_WRITE
11270 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
11271 if (wpas_global_ctrl_iface_save_config(global
))
11273 #endif /* CONFIG_NO_CONFIG_WRITE */
11274 } else if (os_strcmp(buf
, "STATUS") == 0) {
11275 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
11277 #ifdef CONFIG_MODULE_TESTS
11278 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
11279 if (wpas_module_tests() < 0)
11281 #endif /* CONFIG_MODULE_TESTS */
11282 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
11283 if (wpa_debug_reopen_file() < 0)
11286 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
11290 if (reply_len
< 0) {
11291 os_memcpy(reply
, "FAIL\n", 5);
11295 *resp_len
= reply_len
;