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"
23 #include "crypto/tls.h"
24 #include "ap/hostapd.h"
25 #include "eap_peer/eap.h"
26 #include "eapol_supp/eapol_supp_sm.h"
27 #include "rsn_supp/wpa.h"
28 #include "rsn_supp/preauth.h"
29 #include "rsn_supp/pmksa_cache.h"
30 #include "l2_packet/l2_packet.h"
33 #include "fst/fst_ctrl_iface.h"
35 #include "wpa_supplicant_i.h"
37 #include "wps_supplicant.h"
40 #include "p2p_supplicant.h"
42 #include "hs20_supplicant.h"
43 #include "wifi_display.h"
47 #include "ctrl_iface.h"
48 #include "interworking.h"
49 #include "blacklist.h"
52 #include "offchannel.h"
53 #include "drivers/driver.h"
55 #include "dpp_supplicant.h"
57 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
59 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
62 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
65 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
68 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
75 if (hwaddr_aton(pos
, addr
)) {
79 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
85 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
88 pos
= os_strchr(pos
, ' ');
93 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
94 os_free(wpa_s
->bssid_filter
);
95 wpa_s
->bssid_filter
= filter
;
96 wpa_s
->bssid_filter_count
= count
;
102 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
105 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
106 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
107 size_t count
= 0, ssid_count
= 0;
111 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
112 * SSID_SPEC ::= ssid <SSID_HEX>
113 * BSSID_SPEC ::= bssid <BSSID_HEX>
120 if (os_strncmp(pos
, "bssid ", 6) == 0) {
123 res
= hwaddr_aton2(pos
, addr
);
127 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
128 "BSSID value '%s'", pos
);
132 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
139 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
141 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
147 if (*end
== '\0' || *end
== ' ')
152 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
153 sizeof(struct wpa_ssid_value
));
161 if ((end
- pos
) & 0x01 ||
162 end
- pos
> 2 * SSID_MAX_LEN
||
163 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
164 (end
- pos
) / 2) < 0) {
167 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
168 "SSID value '%s'", pos
);
171 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
172 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
173 ssid
[ssid_count
].ssid
,
174 ssid
[ssid_count
].ssid_len
);
178 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
185 pos
= os_strchr(pos
, ' ');
190 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
191 os_free(wpa_s
->disallow_aps_bssid
);
192 wpa_s
->disallow_aps_bssid
= bssid
;
193 wpa_s
->disallow_aps_bssid_count
= count
;
195 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
196 os_free(wpa_s
->disallow_aps_ssid
);
197 wpa_s
->disallow_aps_ssid
= ssid
;
198 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
200 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
203 c
= wpa_s
->current_ssid
;
204 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
207 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
208 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
211 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
212 "because current AP was marked disallowed");
215 wpa_s
->sme
.prev_bssid_set
= 0;
216 #endif /* CONFIG_SME */
217 wpa_s
->reassociate
= 1;
218 wpa_s
->own_disconnect_req
= 1;
219 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
220 wpa_supplicant_req_scan(wpa_s
, 0, 0);
226 #ifndef CONFIG_NO_CONFIG_BLOBS
227 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
230 struct wpa_config_blob
*blob
;
233 pos
= os_strchr(pos
, ' ');
237 len
= os_strlen(pos
);
241 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
242 blob
= os_zalloc(sizeof(*blob
));
245 blob
->name
= os_strdup(name
);
246 blob
->data
= os_malloc(len
/ 2);
247 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
248 wpa_config_free_blob(blob
);
252 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
253 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
254 wpa_config_free_blob(blob
);
259 wpa_config_set_blob(wpa_s
->conf
, blob
);
263 #endif /* CONFIG_NO_CONFIG_BLOBS */
266 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
274 params
= os_strchr(cmd
, ' ');
275 os_free(wpa_s
->manual_sched_scan_freqs
);
278 pos
= os_strstr(params
, "freq=");
280 freqs
= freq_range_to_channel_list(wpa_s
,
283 wpa_s
->manual_sched_scan_freqs
= freqs
;
284 ret
= wpas_start_pno(wpa_s
);
286 ret
= wpas_stop_pno(wpa_s
);
292 static int wpas_ctrl_set_band(struct wpa_supplicant
*wpa_s
, char *band
)
294 union wpa_event_data event
;
296 if (os_strcmp(band
, "AUTO") == 0)
297 wpa_s
->setband
= WPA_SETBAND_AUTO
;
298 else if (os_strcmp(band
, "5G") == 0)
299 wpa_s
->setband
= WPA_SETBAND_5G
;
300 else if (os_strcmp(band
, "2G") == 0)
301 wpa_s
->setband
= WPA_SETBAND_2G
;
305 if (wpa_drv_setband(wpa_s
, wpa_s
->setband
) == 0) {
306 os_memset(&event
, 0, sizeof(event
));
307 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
308 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
309 wpa_supplicant_event(wpa_s
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
316 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant
*wpa_s
,
321 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
322 wpabuf_free(wpa_s
->lci
);
327 lci
= wpabuf_parse_bin(cmd
);
331 if (os_get_reltime(&wpa_s
->lci_time
)) {
336 wpabuf_free(wpa_s
->lci
);
344 wpas_ctrl_set_relative_rssi(struct wpa_supplicant
*wpa_s
, const char *cmd
)
348 if (os_strcmp(cmd
, "disable") == 0) {
349 wpa_s
->srp
.relative_rssi_set
= 0;
353 relative_rssi
= atoi(cmd
);
354 if (relative_rssi
< 0 || relative_rssi
> 100)
356 wpa_s
->srp
.relative_rssi
= relative_rssi
;
357 wpa_s
->srp
.relative_rssi_set
= 1;
362 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant
*wpa_s
,
368 /* <band>:adjust_value */
369 pos
= os_strchr(cmd
, ':');
373 adjust_rssi
= atoi(pos
);
374 if (adjust_rssi
< -100 || adjust_rssi
> 100)
377 if (os_strncmp(cmd
, "2G", 2) == 0)
378 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_2G
;
379 else if (os_strncmp(cmd
, "5G", 2) == 0)
380 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_5G
;
384 wpa_s
->srp
.relative_adjust_rssi
= adjust_rssi
;
390 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant
*wpa_s
,
393 struct wpabuf
*ric_ies
;
395 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
396 wpabuf_free(wpa_s
->ric_ies
);
397 wpa_s
->ric_ies
= NULL
;
401 ric_ies
= wpabuf_parse_bin(cmd
);
405 wpabuf_free(wpa_s
->ric_ies
);
406 wpa_s
->ric_ies
= ric_ies
;
412 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
418 value
= os_strchr(cmd
, ' ');
423 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
424 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
425 eapol_sm_configure(wpa_s
->eapol
,
426 atoi(value
), -1, -1, -1);
427 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
428 eapol_sm_configure(wpa_s
->eapol
,
429 -1, atoi(value
), -1, -1);
430 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
431 eapol_sm_configure(wpa_s
->eapol
,
432 -1, -1, atoi(value
), -1);
433 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
434 eapol_sm_configure(wpa_s
->eapol
,
435 -1, -1, -1, atoi(value
));
436 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
437 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
442 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
444 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
446 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
451 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
453 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
454 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
459 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
461 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
462 wpa_s
->wps_fragment_size
= atoi(value
);
463 #ifdef CONFIG_WPS_TESTING
464 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
466 val
= strtol(value
, NULL
, 0);
467 if (val
< 0 || val
> 0xff) {
469 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
470 "wps_version_number %ld", val
);
472 wps_version_number
= val
;
473 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
475 (wps_version_number
& 0xf0) >> 4,
476 wps_version_number
& 0x0f);
478 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
479 wps_testing_dummy_cred
= atoi(value
);
480 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
481 wps_testing_dummy_cred
);
482 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
483 wps_corrupt_pkhash
= atoi(value
);
484 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
486 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
487 if (value
[0] == '\0') {
488 wps_force_auth_types_in_use
= 0;
490 wps_force_auth_types
= strtol(value
, NULL
, 0);
491 wps_force_auth_types_in_use
= 1;
493 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
494 if (value
[0] == '\0') {
495 wps_force_encr_types_in_use
= 0;
497 wps_force_encr_types
= strtol(value
, NULL
, 0);
498 wps_force_encr_types_in_use
= 1;
500 #endif /* CONFIG_WPS_TESTING */
501 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
502 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
505 #ifdef CONFIG_TDLS_TESTING
506 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
507 tdls_testing
= strtol(value
, NULL
, 0);
508 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
509 #endif /* CONFIG_TDLS_TESTING */
510 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
511 int disabled
= atoi(value
);
512 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
514 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
516 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
518 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
519 #endif /* CONFIG_TDLS */
520 } else if (os_strcasecmp(cmd
, "pno") == 0) {
521 ret
= wpas_ctrl_pno(wpa_s
, value
);
522 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
523 int disabled
= atoi(value
);
524 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
527 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
528 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
529 if (os_strcmp(value
, "disable") == 0)
530 wpa_s
->set_sta_uapsd
= 0;
534 /* format: BE,BK,VI,VO;max SP Length */
536 pos
= os_strchr(value
, ',');
541 pos
= os_strchr(pos
, ',');
546 pos
= os_strchr(pos
, ',');
551 /* ignore max SP Length for now */
553 wpa_s
->set_sta_uapsd
= 1;
554 wpa_s
->sta_uapsd
= 0;
556 wpa_s
->sta_uapsd
|= BIT(0);
558 wpa_s
->sta_uapsd
|= BIT(1);
560 wpa_s
->sta_uapsd
|= BIT(2);
562 wpa_s
->sta_uapsd
|= BIT(3);
564 } else if (os_strcasecmp(cmd
, "ps") == 0) {
565 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
566 #ifdef CONFIG_WIFI_DISPLAY
567 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
568 int enabled
= !!atoi(value
);
569 if (enabled
&& !wpa_s
->global
->p2p
)
572 wifi_display_enable(wpa_s
->global
, enabled
);
573 #endif /* CONFIG_WIFI_DISPLAY */
574 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
575 ret
= set_bssid_filter(wpa_s
, value
);
576 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
577 ret
= set_disallow_aps(wpa_s
, value
);
578 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
579 wpa_s
->no_keep_alive
= !!atoi(value
);
581 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
582 os_free(wpa_s
->dpp_configurator_params
);
583 wpa_s
->dpp_configurator_params
= os_strdup(value
);
584 #endif /* CONFIG_DPP */
585 #ifdef CONFIG_TESTING_OPTIONS
586 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
587 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
588 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
589 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
591 if (wpa_s
->ap_iface
) {
592 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
593 wpa_s
->ext_eapol_frame_io
;
595 #endif /* CONFIG_AP */
596 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
597 wpa_s
->extra_roc_dur
= atoi(value
);
598 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
599 wpa_s
->test_failure
= atoi(value
);
600 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
601 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
602 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
603 wpa_s
->ignore_auth_resp
= !!atoi(value
);
604 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
605 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
606 wpa_drv_ignore_assoc_disallow(wpa_s
,
607 wpa_s
->ignore_assoc_disallow
);
608 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
609 wpa_s
->reject_btm_req_reason
= atoi(value
);
610 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
611 os_free(wpa_s
->get_pref_freq_list_override
);
613 wpa_s
->get_pref_freq_list_override
= NULL
;
615 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
617 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
618 os_free(wpa_s
->dpp_config_obj_override
);
619 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
620 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
621 os_free(wpa_s
->dpp_discovery_override
);
622 wpa_s
->dpp_discovery_override
= os_strdup(value
);
623 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
624 os_free(wpa_s
->dpp_groups_override
);
625 wpa_s
->dpp_groups_override
= os_strdup(value
);
626 } else if (os_strcasecmp(cmd
, "dpp_devices_override") == 0) {
627 os_free(wpa_s
->dpp_devices_override
);
628 wpa_s
->dpp_devices_override
= os_strdup(value
);
629 } else if (os_strcasecmp(cmd
,
630 "dpp_ignore_netaccesskey_mismatch") == 0) {
631 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
632 #endif /* CONFIG_DPP */
633 #endif /* CONFIG_TESTING_OPTIONS */
634 #ifndef CONFIG_NO_CONFIG_BLOBS
635 } else if (os_strcmp(cmd
, "blob") == 0) {
636 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
637 #endif /* CONFIG_NO_CONFIG_BLOBS */
638 } else if (os_strcasecmp(cmd
, "setband") == 0) {
639 ret
= wpas_ctrl_set_band(wpa_s
, value
);
641 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
642 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
645 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
647 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
648 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
649 #endif /* CONFIG_MBO */
650 } else if (os_strcasecmp(cmd
, "lci") == 0) {
651 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
652 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
653 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
654 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
655 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
656 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
657 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
658 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
659 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
660 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
661 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
664 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
666 wpa_supplicant_update_config(wpa_s
);
673 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
674 char *cmd
, char *buf
, size_t buflen
)
678 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
680 if (os_strcmp(cmd
, "version") == 0) {
681 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
682 } else if (os_strcasecmp(cmd
, "country") == 0) {
683 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
684 res
= os_snprintf(buf
, buflen
, "%c%c",
685 wpa_s
->conf
->country
[0],
686 wpa_s
->conf
->country
[1]);
687 #ifdef CONFIG_WIFI_DISPLAY
688 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
690 if (wpa_s
->global
->p2p
== NULL
||
691 wpa_s
->global
->p2p_disabled
)
694 enabled
= wpa_s
->global
->wifi_display
;
695 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
696 #endif /* CONFIG_WIFI_DISPLAY */
697 #ifdef CONFIG_TESTING_GET_GTK
698 } else if (os_strcmp(cmd
, "gtk") == 0) {
699 if (wpa_s
->last_gtk_len
== 0)
701 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
702 wpa_s
->last_gtk_len
);
704 #endif /* CONFIG_TESTING_GET_GTK */
705 } else if (os_strcmp(cmd
, "tls_library") == 0) {
706 res
= tls_get_library_version(buf
, buflen
);
708 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
711 if (os_snprintf_error(buflen
, res
))
717 #ifdef IEEE8021X_EAPOL
718 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
722 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
724 if (hwaddr_aton(addr
, bssid
)) {
725 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
730 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
731 rsn_preauth_deinit(wpa_s
->wpa
);
732 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
737 #endif /* IEEE8021X_EAPOL */
740 #ifdef CONFIG_PEERKEY
741 /* MLME-STKSTART.request(peer) */
742 static int wpa_supplicant_ctrl_iface_stkstart(
743 struct wpa_supplicant
*wpa_s
, char *addr
)
747 if (hwaddr_aton(addr
, peer
)) {
748 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
749 "address '%s'", addr
);
753 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
756 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
758 #endif /* CONFIG_PEERKEY */
763 static int wpa_supplicant_ctrl_iface_tdls_discover(
764 struct wpa_supplicant
*wpa_s
, char *addr
)
769 if (hwaddr_aton(addr
, peer
)) {
770 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
771 "address '%s'", addr
);
775 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
778 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
779 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
781 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
787 static int wpa_supplicant_ctrl_iface_tdls_setup(
788 struct wpa_supplicant
*wpa_s
, char *addr
)
793 if (hwaddr_aton(addr
, peer
)) {
794 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
795 "address '%s'", addr
);
799 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
802 if ((wpa_s
->conf
->tdls_external_control
) &&
803 wpa_tdls_is_external_setup(wpa_s
->wpa
))
804 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
806 wpa_tdls_remove(wpa_s
->wpa
, peer
);
808 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
809 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
811 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
817 static int wpa_supplicant_ctrl_iface_tdls_teardown(
818 struct wpa_supplicant
*wpa_s
, char *addr
)
823 if (os_strcmp(addr
, "*") == 0) {
824 /* remove everyone */
825 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
826 wpa_tdls_teardown_peers(wpa_s
->wpa
);
830 if (hwaddr_aton(addr
, peer
)) {
831 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
832 "address '%s'", addr
);
836 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
839 if ((wpa_s
->conf
->tdls_external_control
) &&
840 wpa_tdls_is_external_setup(wpa_s
->wpa
))
841 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
843 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
844 ret
= wpa_tdls_teardown_link(
846 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
848 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
854 static int ctrl_iface_get_capability_tdls(
855 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
859 ret
= os_snprintf(buf
, buflen
, "%s\n",
860 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
862 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
863 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
864 if (os_snprintf_error(buflen
, ret
))
870 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
871 struct wpa_supplicant
*wpa_s
, char *cmd
)
874 struct hostapd_freq_params freq_params
;
878 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
880 "tdls_chanswitch: Only supported with external setup");
884 os_memset(&freq_params
, 0, sizeof(freq_params
));
886 pos
= os_strchr(cmd
, ' ');
891 oper_class
= strtol(pos
, &end
, 10);
894 "tdls_chanswitch: Invalid op class provided");
899 freq_params
.freq
= atoi(pos
);
900 if (freq_params
.freq
== 0) {
901 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
905 #define SET_FREQ_SETTING(str) \
907 const char *pos2 = os_strstr(pos, " " #str "="); \
909 pos2 += sizeof(" " #str "=") - 1; \
910 freq_params.str = atoi(pos2); \
914 SET_FREQ_SETTING(center_freq1
);
915 SET_FREQ_SETTING(center_freq2
);
916 SET_FREQ_SETTING(bandwidth
);
917 SET_FREQ_SETTING(sec_channel_offset
);
918 #undef SET_FREQ_SETTING
920 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
921 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
923 if (hwaddr_aton(cmd
, peer
)) {
924 wpa_printf(MSG_DEBUG
,
925 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
930 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
931 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
932 MAC2STR(peer
), oper_class
, freq_params
.freq
,
933 freq_params
.center_freq1
, freq_params
.center_freq2
,
934 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
935 freq_params
.ht_enabled
? " HT" : "",
936 freq_params
.vht_enabled
? " VHT" : "");
938 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
943 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
944 struct wpa_supplicant
*wpa_s
, char *cmd
)
948 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
950 "tdls_chanswitch: Only supported with external setup");
954 if (hwaddr_aton(cmd
, peer
)) {
955 wpa_printf(MSG_DEBUG
,
956 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
961 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
964 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
968 static int wpa_supplicant_ctrl_iface_tdls_link_status(
969 struct wpa_supplicant
*wpa_s
, const char *addr
,
970 char *buf
, size_t buflen
)
973 const char *tdls_status
;
976 if (hwaddr_aton(addr
, peer
)) {
977 wpa_printf(MSG_DEBUG
,
978 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
982 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
985 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
986 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
987 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
988 if (os_snprintf_error(buflen
, ret
))
994 #endif /* CONFIG_TDLS */
997 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
999 char *token
, *context
= NULL
;
1000 struct wmm_ac_ts_setup_params params
= {
1005 while ((token
= str_token(cmd
, " ", &context
))) {
1006 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1007 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1008 sscanf(token
, "nominal_msdu_size=%i",
1009 ¶ms
.nominal_msdu_size
) == 1 ||
1010 sscanf(token
, "mean_data_rate=%i",
1011 ¶ms
.mean_data_rate
) == 1 ||
1012 sscanf(token
, "min_phy_rate=%i",
1013 ¶ms
.minimum_phy_rate
) == 1 ||
1014 sscanf(token
, "sba=%i",
1015 ¶ms
.surplus_bandwidth_allowance
) == 1)
1018 if (os_strcasecmp(token
, "downlink") == 0) {
1019 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1020 } else if (os_strcasecmp(token
, "uplink") == 0) {
1021 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1022 } else if (os_strcasecmp(token
, "bidi") == 0) {
1023 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1024 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1025 params
.fixed_nominal_msdu
= 1;
1027 wpa_printf(MSG_DEBUG
,
1028 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1035 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1039 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1041 u8 tsid
= atoi(cmd
);
1043 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1047 #ifdef CONFIG_IEEE80211R
1048 static int wpa_supplicant_ctrl_iface_ft_ds(
1049 struct wpa_supplicant
*wpa_s
, char *addr
)
1051 u8 target_ap
[ETH_ALEN
];
1052 struct wpa_bss
*bss
;
1055 if (hwaddr_aton(addr
, target_ap
)) {
1056 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1057 "address '%s'", addr
);
1061 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1063 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1065 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1069 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1071 #endif /* CONFIG_IEEE80211R */
1075 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1078 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1080 u8 p2p_dev_addr
[ETH_ALEN
];
1081 #endif /* CONFIG_P2P */
1083 u8
*_p2p_dev_addr
= NULL
;
1084 #endif /* CONFIG_AP */
1086 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
1089 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1090 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1091 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1092 "P2P Device Address '%s'",
1096 _p2p_dev_addr
= p2p_dev_addr
;
1097 #endif /* CONFIG_P2P */
1098 } else if (hwaddr_aton(cmd
, bssid
)) {
1099 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1105 if (wpa_s
->ap_iface
)
1106 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1107 #endif /* CONFIG_AP */
1109 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1113 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1114 char *cmd
, char *buf
,
1117 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1121 pin
= os_strchr(cmd
, ' ');
1125 if (os_strcmp(cmd
, "any") == 0)
1127 else if (os_strcmp(cmd
, "get") == 0) {
1128 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1131 } else if (hwaddr_aton(cmd
, bssid
)) {
1132 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1138 if (wpa_s
->ap_iface
) {
1143 pos
= os_strchr(pin
, ' ');
1146 timeout
= atoi(pos
);
1150 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1151 buf
, buflen
, timeout
);
1153 #endif /* CONFIG_AP */
1156 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1160 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1161 if (os_snprintf_error(buflen
, ret
))
1166 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1171 /* Return the generated PIN */
1172 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1173 if (os_snprintf_error(buflen
, ret
))
1179 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1180 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1187 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1188 (u8
*) cmd
, os_strlen(cmd
));
1189 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1190 if (*pos
< '0' || *pos
> '9')
1194 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1198 if (len
!= 4 && len
!= 8) {
1199 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1205 unsigned int pin_val
;
1206 pin_val
= atoi(pin
);
1207 if (!wps_pin_valid(pin_val
)) {
1208 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1209 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1210 if (os_snprintf_error(buflen
, ret
))
1216 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1217 if (os_snprintf_error(buflen
, ret
))
1224 #ifdef CONFIG_WPS_NFC
1226 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1229 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1231 if (cmd
== NULL
|| cmd
[0] == '\0')
1233 else if (hwaddr_aton(cmd
, bssid
))
1236 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1241 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1242 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1249 pos
= os_strchr(cmd
, ' ');
1252 if (os_strcmp(cmd
, "WPS") == 0)
1254 else if (os_strcmp(cmd
, "NDEF") == 0)
1259 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1263 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1265 reply
[res
++] = '\n';
1274 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1275 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1281 if (os_strcmp(cmd
, "WPS") == 0)
1283 else if (os_strcmp(cmd
, "NDEF") == 0)
1288 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1292 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1294 reply
[res
++] = '\n';
1303 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1304 struct wpa_supplicant
*wpa_s
, char *pos
)
1310 int forced_freq
= 0;
1312 freq
= strstr(pos
, " freq=");
1316 forced_freq
= atoi(freq
);
1319 len
= os_strlen(pos
);
1324 buf
= wpabuf_alloc(len
);
1327 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1332 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1339 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1340 char *reply
, size_t max_len
,
1346 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1350 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1352 reply
[res
++] = '\n';
1362 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1363 char *reply
, size_t max_len
,
1369 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1371 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1375 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1377 reply
[res
++] = '\n';
1384 #endif /* CONFIG_P2P */
1387 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1388 char *cmd
, char *reply
,
1394 pos
= os_strchr(cmd
, ' ');
1399 if (os_strcmp(cmd
, "WPS") == 0)
1401 else if (os_strcmp(cmd
, "NDEF") == 0)
1406 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1409 return wpas_ctrl_nfc_get_handover_req_wps(
1410 wpa_s
, reply
, max_len
, ndef
);
1414 if (os_strcmp(pos
, "P2P-CR") == 0) {
1415 return wpas_ctrl_nfc_get_handover_req_p2p(
1416 wpa_s
, reply
, max_len
, ndef
);
1418 #endif /* CONFIG_P2P */
1424 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1425 char *reply
, size_t max_len
,
1426 int ndef
, int cr
, char *uuid
)
1431 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1435 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1437 reply
[res
++] = '\n';
1447 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1448 char *reply
, size_t max_len
,
1454 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1458 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1460 reply
[res
++] = '\n';
1467 #endif /* CONFIG_P2P */
1470 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1471 char *cmd
, char *reply
,
1477 pos
= os_strchr(cmd
, ' ');
1482 if (os_strcmp(cmd
, "WPS") == 0)
1484 else if (os_strcmp(cmd
, "NDEF") == 0)
1489 pos2
= os_strchr(pos
, ' ');
1492 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1495 return wpas_ctrl_nfc_get_handover_sel_wps(
1496 wpa_s
, reply
, max_len
, ndef
,
1497 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1501 if (os_strcmp(pos
, "P2P-CR") == 0) {
1502 return wpas_ctrl_nfc_get_handover_sel_p2p(
1503 wpa_s
, reply
, max_len
, ndef
, 0);
1506 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1507 return wpas_ctrl_nfc_get_handover_sel_p2p(
1508 wpa_s
, reply
, max_len
, ndef
, 1);
1510 #endif /* CONFIG_P2P */
1516 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1520 struct wpabuf
*req
, *sel
;
1522 char *pos
, *role
, *type
, *pos2
;
1525 int forced_freq
= 0;
1527 freq
= strstr(cmd
, " freq=");
1531 forced_freq
= atoi(freq
);
1533 #endif /* CONFIG_P2P */
1536 pos
= os_strchr(role
, ' ');
1538 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1544 pos
= os_strchr(type
, ' ');
1546 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1551 pos2
= os_strchr(pos
, ' ');
1553 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1558 len
= os_strlen(pos
);
1560 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1565 req
= wpabuf_alloc(len
);
1567 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1570 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1571 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1576 len
= os_strlen(pos2
);
1578 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1584 sel
= wpabuf_alloc(len
);
1586 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1590 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1591 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1597 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1598 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1600 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1601 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1603 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1605 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1607 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1608 #endif /* CONFIG_AP */
1610 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1612 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1613 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1615 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1617 #endif /* CONFIG_P2P */
1619 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1620 "reported: role=%s type=%s", role
, type
);
1627 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1632 #endif /* CONFIG_WPS_NFC */
1635 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1644 struct wps_new_ap_settings ap
;
1646 pin
= os_strchr(cmd
, ' ');
1651 if (hwaddr_aton(cmd
, bssid
)) {
1652 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1657 new_ssid
= os_strchr(pin
, ' ');
1658 if (new_ssid
== NULL
)
1659 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1662 new_auth
= os_strchr(new_ssid
, ' ');
1663 if (new_auth
== NULL
)
1667 new_encr
= os_strchr(new_auth
, ' ');
1668 if (new_encr
== NULL
)
1672 new_key
= os_strchr(new_encr
, ' ');
1673 if (new_key
== NULL
)
1677 os_memset(&ap
, 0, sizeof(ap
));
1678 ap
.ssid_hex
= new_ssid
;
1681 ap
.key_hex
= new_key
;
1682 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1687 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1688 char *cmd
, char *buf
,
1693 const char *pin_txt
;
1695 if (!wpa_s
->ap_iface
)
1698 pos
= os_strchr(cmd
, ' ');
1702 if (os_strcmp(cmd
, "disable") == 0) {
1703 wpas_wps_ap_pin_disable(wpa_s
);
1704 return os_snprintf(buf
, buflen
, "OK\n");
1707 if (os_strcmp(cmd
, "random") == 0) {
1709 timeout
= atoi(pos
);
1710 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1711 if (pin_txt
== NULL
)
1713 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1716 if (os_strcmp(cmd
, "get") == 0) {
1717 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1718 if (pin_txt
== NULL
)
1720 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1723 if (os_strcmp(cmd
, "set") == 0) {
1728 pos
= os_strchr(pos
, ' ');
1731 timeout
= atoi(pos
);
1733 if (os_strlen(pin
) > buflen
)
1735 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1737 return os_snprintf(buf
, buflen
, "%s", pin
);
1742 #endif /* CONFIG_AP */
1745 #ifdef CONFIG_WPS_ER
1746 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1749 char *uuid
= cmd
, *pin
, *pos
;
1750 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1751 pin
= os_strchr(uuid
, ' ');
1755 pos
= os_strchr(pin
, ' ');
1758 if (hwaddr_aton(pos
, addr_buf
) == 0)
1761 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1765 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1768 char *uuid
= cmd
, *pin
;
1769 pin
= os_strchr(uuid
, ' ');
1773 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1777 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1778 struct wpa_supplicant
*wpa_s
, char *cmd
)
1780 char *uuid
= cmd
, *id
;
1781 id
= os_strchr(uuid
, ' ');
1785 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1789 static int wpa_supplicant_ctrl_iface_wps_er_config(
1790 struct wpa_supplicant
*wpa_s
, char *cmd
)
1797 struct wps_new_ap_settings ap
;
1799 pin
= os_strchr(cmd
, ' ');
1804 new_ssid
= os_strchr(pin
, ' ');
1805 if (new_ssid
== NULL
)
1809 new_auth
= os_strchr(new_ssid
, ' ');
1810 if (new_auth
== NULL
)
1814 new_encr
= os_strchr(new_auth
, ' ');
1815 if (new_encr
== NULL
)
1819 new_key
= os_strchr(new_encr
, ' ');
1820 if (new_key
== NULL
)
1824 os_memset(&ap
, 0, sizeof(ap
));
1825 ap
.ssid_hex
= new_ssid
;
1828 ap
.key_hex
= new_key
;
1829 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1833 #ifdef CONFIG_WPS_NFC
1834 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1835 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1842 uuid
= os_strchr(cmd
, ' ');
1847 if (os_strcmp(cmd
, "WPS") == 0)
1849 else if (os_strcmp(cmd
, "NDEF") == 0)
1854 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1858 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1860 reply
[res
++] = '\n';
1867 #endif /* CONFIG_WPS_NFC */
1868 #endif /* CONFIG_WPS_ER */
1870 #endif /* CONFIG_WPS */
1873 #ifdef CONFIG_IBSS_RSN
1874 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1875 struct wpa_supplicant
*wpa_s
, char *addr
)
1879 if (hwaddr_aton(addr
, peer
)) {
1880 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1881 "address '%s'", addr
);
1885 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1888 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1890 #endif /* CONFIG_IBSS_RSN */
1893 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1896 #ifdef IEEE8021X_EAPOL
1899 struct wpa_ssid
*ssid
;
1901 pos
= os_strchr(rsp
, '-');
1906 pos
= os_strchr(pos
, ':');
1911 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1912 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1913 (u8
*) pos
, os_strlen(pos
));
1915 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1917 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1922 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1924 #else /* IEEE8021X_EAPOL */
1925 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1927 #endif /* IEEE8021X_EAPOL */
1931 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1933 char *buf
, size_t buflen
)
1935 char *pos
, *end
, tmp
[30];
1936 int res
, verbose
, wps
, ret
;
1939 #endif /* CONFIG_HS20 */
1943 if (os_strcmp(params
, "-DRIVER") == 0)
1944 return wpa_drv_status(wpa_s
, buf
, buflen
);
1945 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1946 wps
= os_strcmp(params
, "-WPS") == 0;
1949 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1950 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1951 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1952 MAC2STR(wpa_s
->bssid
));
1953 if (os_snprintf_error(end
- pos
, ret
))
1956 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1958 if (os_snprintf_error(end
- pos
, ret
))
1962 u8
*_ssid
= ssid
->ssid
;
1963 size_t ssid_len
= ssid
->ssid_len
;
1964 u8 ssid_buf
[SSID_MAX_LEN
];
1965 if (ssid_len
== 0) {
1966 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1973 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1974 wpa_ssid_txt(_ssid
, ssid_len
),
1976 if (os_snprintf_error(end
- pos
, ret
))
1980 if (wps
&& ssid
->passphrase
&&
1981 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1982 (ssid
->mode
== WPAS_MODE_AP
||
1983 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1984 ret
= os_snprintf(pos
, end
- pos
,
1987 if (os_snprintf_error(end
- pos
, ret
))
1992 ret
= os_snprintf(pos
, end
- pos
,
1995 if (os_snprintf_error(end
- pos
, ret
))
2000 switch (ssid
->mode
) {
2001 case WPAS_MODE_INFRA
:
2002 ret
= os_snprintf(pos
, end
- pos
,
2005 case WPAS_MODE_IBSS
:
2006 ret
= os_snprintf(pos
, end
- pos
,
2010 ret
= os_snprintf(pos
, end
- pos
,
2013 case WPAS_MODE_P2P_GO
:
2014 ret
= os_snprintf(pos
, end
- pos
,
2017 case WPAS_MODE_P2P_GROUP_FORMATION
:
2018 ret
= os_snprintf(pos
, end
- pos
,
2019 "mode=P2P GO - group "
2022 case WPAS_MODE_MESH
:
2023 ret
= os_snprintf(pos
, end
- pos
,
2030 if (os_snprintf_error(end
- pos
, ret
))
2036 if (wpa_s
->ap_iface
) {
2037 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2041 #endif /* CONFIG_AP */
2042 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2046 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2049 #endif /* CONFIG_AP */
2050 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2051 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2052 wpa_s
->sme
.sae
.group
);
2053 if (os_snprintf_error(end
- pos
, ret
))
2057 #endif /* CONFIG_SAE */
2058 #endif /* CONFIG_SME */
2059 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2060 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2061 if (os_snprintf_error(end
- pos
, ret
))
2066 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2067 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2068 if (os_snprintf_error(end
- pos
, ret
))
2074 if (wpa_s
->global
->p2p
) {
2075 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2076 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2077 if (os_snprintf_error(end
- pos
, ret
))
2081 #endif /* CONFIG_P2P */
2083 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2084 MAC2STR(wpa_s
->own_addr
));
2085 if (os_snprintf_error(end
- pos
, ret
))
2090 if (wpa_s
->current_bss
&&
2091 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2092 HS20_IE_VENDOR_TYPE
)) &&
2093 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2094 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2097 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2098 release
= rel_num
+ 1;
2100 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2101 if (os_snprintf_error(end
- pos
, ret
))
2106 if (wpa_s
->current_ssid
) {
2107 struct wpa_cred
*cred
;
2110 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2113 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2116 if (cred
->provisioning_sp
) {
2117 ret
= os_snprintf(pos
, end
- pos
,
2118 "provisioning_sp=%s\n",
2119 cred
->provisioning_sp
);
2120 if (os_snprintf_error(end
- pos
, ret
))
2129 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2130 struct wpabuf
*names
=
2131 wpa_s
->current_bss
->anqp
->domain_name
;
2132 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2134 if (domain_name_list_contains(
2135 names
, cred
->domain
[i
], 1))
2138 if (i
== cred
->num_domain
)
2139 i
= 0; /* show first entry by default */
2141 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2143 if (os_snprintf_error(end
- pos
, ret
))
2148 if (wpa_s
->current_bss
== NULL
||
2149 wpa_s
->current_bss
->anqp
== NULL
)
2152 res
= interworking_home_sp_cred(
2154 wpa_s
->current_bss
->anqp
->domain_name
);
2162 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2163 if (os_snprintf_error(end
- pos
, ret
))
2170 #endif /* CONFIG_HS20 */
2172 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2173 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2174 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2180 #ifdef CONFIG_MACSEC
2181 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2184 #endif /* CONFIG_MACSEC */
2186 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2190 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2191 if (os_snprintf_error(end
- pos
, ret
))
2194 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2198 ret
= os_snprintf(pos
, end
- pos
, "\n");
2199 if (os_snprintf_error(end
- pos
, ret
))
2204 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2211 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2212 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2213 if (os_snprintf_error(end
- pos
, ret
))
2217 #endif /* CONFIG_WPS */
2221 * Allow using the STATUS command with default behavior, say for debug,
2222 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2223 * events with STATUS-NO_EVENTS.
2225 if (os_strcmp(params
, "-NO_EVENTS")) {
2226 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2227 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2228 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2230 MAC2STR(wpa_s
->bssid
),
2231 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2232 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2233 wpa_s
->current_ssid
->ssid_len
) : "");
2234 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2235 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2236 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2237 "- connection to " MACSTR
2238 " completed %s [id=%d id_str=%s]",
2239 MAC2STR(wpa_s
->bssid
), "(auth)",
2240 ssid
? ssid
->id
: -1,
2241 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2244 #endif /* ANDROID */
2250 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2255 struct wpa_ssid
*ssid
;
2258 /* cmd: "<network id> <BSSID>" */
2259 pos
= os_strchr(cmd
, ' ');
2264 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2265 if (hwaddr_aton(pos
, bssid
)) {
2266 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2270 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2272 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2277 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2278 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2284 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2285 char *cmd
, char *buf
,
2289 struct wpa_blacklist
*e
;
2293 /* cmd: "BLACKLIST [<BSSID>]" */
2297 e
= wpa_s
->blacklist
;
2299 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2301 if (os_snprintf_error(end
- pos
, ret
))
2310 if (os_strncmp(cmd
, "clear", 5) == 0) {
2311 wpa_blacklist_clear(wpa_s
);
2312 os_memcpy(buf
, "OK\n", 3);
2316 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2317 if (hwaddr_aton(cmd
, bssid
)) {
2318 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2323 * Add the BSSID twice, so its count will be 2, causing it to be
2324 * skipped when processing scan results.
2326 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2329 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2332 os_memcpy(buf
, "OK\n", 3);
2337 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2338 char *cmd
, char *buf
,
2341 char *pos
, *end
, *stamp
;
2344 /* cmd: "LOG_LEVEL [<level>]" */
2348 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2350 debug_level_str(wpa_debug_level
),
2351 wpa_debug_timestamp
);
2352 if (os_snprintf_error(end
- pos
, ret
))
2361 stamp
= os_strchr(cmd
, ' ');
2364 while (*stamp
== ' ') {
2369 if (os_strlen(cmd
)) {
2370 int level
= str_to_debug_level(cmd
);
2373 wpa_debug_level
= level
;
2376 if (stamp
&& os_strlen(stamp
))
2377 wpa_debug_timestamp
= atoi(stamp
);
2379 os_memcpy(buf
, "OK\n", 3);
2384 static int wpa_supplicant_ctrl_iface_list_networks(
2385 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2387 char *pos
, *end
, *prev
;
2388 struct wpa_ssid
*ssid
;
2393 ret
= os_snprintf(pos
, end
- pos
,
2394 "network id / ssid / bssid / flags\n");
2395 if (os_snprintf_error(end
- pos
, ret
))
2399 ssid
= wpa_s
->conf
->ssid
;
2401 /* skip over ssids until we find next one */
2402 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2403 int last_id
= atoi(cmd
+ 8);
2404 if (last_id
!= -1) {
2405 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2413 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2415 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2416 if (os_snprintf_error(end
- pos
, ret
))
2419 if (ssid
->bssid_set
) {
2420 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2421 MAC2STR(ssid
->bssid
));
2423 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2425 if (os_snprintf_error(end
- pos
, ret
))
2428 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2429 ssid
== wpa_s
->current_ssid
?
2431 ssid
->disabled
? "[DISABLED]" : "",
2432 ssid
->disabled_until
.sec
?
2433 "[TEMP-DISABLED]" : "",
2434 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2436 if (os_snprintf_error(end
- pos
, ret
))
2439 ret
= os_snprintf(pos
, end
- pos
, "\n");
2440 if (os_snprintf_error(end
- pos
, ret
))
2451 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2454 ret
= os_snprintf(pos
, end
- pos
, "-");
2455 if (os_snprintf_error(end
- pos
, ret
))
2458 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2466 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2467 const u8
*ie
, size_t ie_len
)
2469 struct wpa_ie_data data
;
2473 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2474 if (os_snprintf_error(end
- pos
, ret
))
2478 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2479 ret
= os_snprintf(pos
, end
- pos
, "?]");
2480 if (os_snprintf_error(end
- pos
, ret
))
2487 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2488 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2489 pos
== start
? "" : "+");
2490 if (os_snprintf_error(end
- pos
, ret
))
2494 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2495 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2496 pos
== start
? "" : "+");
2497 if (os_snprintf_error(end
- pos
, ret
))
2501 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2502 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2503 pos
== start
? "" : "+");
2504 if (os_snprintf_error(end
- pos
, ret
))
2508 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2509 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2510 pos
== start
? "" : "+");
2511 if (os_snprintf_error(end
- pos
, ret
))
2515 #ifdef CONFIG_IEEE80211R
2516 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2517 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2518 pos
== start
? "" : "+");
2519 if (os_snprintf_error(end
- pos
, ret
))
2523 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2524 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2525 pos
== start
? "" : "+");
2526 if (os_snprintf_error(end
- pos
, ret
))
2530 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2531 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2532 pos
== start
? "" : "+");
2533 if (os_snprintf_error(end
- pos
, ret
))
2537 #endif /* CONFIG_IEEE80211R */
2538 #ifdef CONFIG_IEEE80211W
2539 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2540 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2541 pos
== start
? "" : "+");
2542 if (os_snprintf_error(end
- pos
, ret
))
2546 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2547 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2548 pos
== start
? "" : "+");
2549 if (os_snprintf_error(end
- pos
, ret
))
2553 #endif /* CONFIG_IEEE80211W */
2555 #ifdef CONFIG_SUITEB
2556 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2557 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2558 pos
== start
? "" : "+");
2559 if (os_snprintf_error(end
- pos
, ret
))
2563 #endif /* CONFIG_SUITEB */
2565 #ifdef CONFIG_SUITEB192
2566 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2567 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2568 pos
== start
? "" : "+");
2569 if (os_snprintf_error(end
- pos
, ret
))
2573 #endif /* CONFIG_SUITEB192 */
2576 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2577 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2578 pos
== start
? "" : "+");
2579 if (os_snprintf_error(end
- pos
, ret
))
2583 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2584 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2585 pos
== start
? "" : "+");
2586 if (os_snprintf_error(end
- pos
, ret
))
2590 #ifdef CONFIG_IEEE80211R
2591 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2592 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2593 pos
== start
? "" : "+");
2594 if (os_snprintf_error(end
- pos
, ret
))
2598 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2599 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2600 pos
== start
? "" : "+");
2601 if (os_snprintf_error(end
- pos
, ret
))
2605 #endif /* CONFIG_IEEE80211R */
2606 #endif /* CONFIG_FILS */
2609 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2610 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2611 pos
== start
? "" : "+");
2612 if (os_snprintf_error(end
- pos
, ret
))
2616 #endif /* CONFIG_OWE */
2619 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2620 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2621 pos
== start
? "" : "+");
2622 if (os_snprintf_error(end
- pos
, ret
))
2626 #endif /* CONFIG_DPP */
2628 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2629 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2630 pos
== start
? "" : "+");
2631 if (os_snprintf_error(end
- pos
, ret
))
2636 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2638 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2639 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2640 if (os_snprintf_error(end
- pos
, ret
))
2645 ret
= os_snprintf(pos
, end
- pos
, "]");
2646 if (os_snprintf_error(end
- pos
, ret
))
2655 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2656 char *pos
, char *end
,
2657 struct wpabuf
*wps_ie
)
2664 if (wps_is_selected_pbc_registrar(wps_ie
))
2666 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2668 else if (wps_is_selected_pin_registrar(wps_ie
))
2673 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2674 if (!os_snprintf_error(end
- pos
, ret
))
2676 wpabuf_free(wps_ie
);
2679 #endif /* CONFIG_WPS */
2682 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2683 char *pos
, char *end
,
2684 const struct wpa_bss
*bss
)
2687 struct wpabuf
*wps_ie
;
2688 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2689 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2690 #else /* CONFIG_WPS */
2692 #endif /* CONFIG_WPS */
2696 /* Format one result on one text line into a buffer. */
2697 static int wpa_supplicant_ctrl_iface_scan_result(
2698 struct wpa_supplicant
*wpa_s
,
2699 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2703 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
;
2705 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2706 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2708 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2709 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2710 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2712 return 0; /* Do not show P2P listen discovery results here */
2717 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2718 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2719 if (os_snprintf_error(end
- pos
, ret
))
2722 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2724 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2725 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2727 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2730 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2732 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2733 osen_ie
, 2 + osen_ie
[1]);
2734 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2735 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2736 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2737 if (os_snprintf_error(end
- pos
, ret
))
2742 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2743 if (os_snprintf_error(end
- pos
, ret
))
2747 if (bss_is_dmg(bss
)) {
2749 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2750 if (os_snprintf_error(end
- pos
, ret
))
2753 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2754 case IEEE80211_CAP_DMG_IBSS
:
2757 case IEEE80211_CAP_DMG_AP
:
2760 case IEEE80211_CAP_DMG_PBSS
:
2767 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2768 if (os_snprintf_error(end
- pos
, ret
))
2772 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2773 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2774 if (os_snprintf_error(end
- pos
, ret
))
2778 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2779 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2780 if (os_snprintf_error(end
- pos
, ret
))
2786 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2787 if (os_snprintf_error(end
- pos
, ret
))
2792 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2793 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2794 if (os_snprintf_error(end
- pos
, ret
))
2798 #endif /* CONFIG_HS20 */
2800 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2801 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2802 if (os_snprintf_error(end
- pos
, ret
))
2806 #endif /* CONFIG_FILS */
2808 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2809 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2810 if (os_snprintf_error(end
- pos
, ret
))
2814 #endif /* CONFIG_FST */
2816 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2817 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2818 if (os_snprintf_error(end
- pos
, ret
))
2822 ret
= os_snprintf(pos
, end
- pos
, "\n");
2823 if (os_snprintf_error(end
- pos
, ret
))
2831 static int wpa_supplicant_ctrl_iface_scan_results(
2832 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2835 struct wpa_bss
*bss
;
2840 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2842 if (os_snprintf_error(end
- pos
, ret
))
2846 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2847 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2849 if (ret
< 0 || ret
>= end
- pos
)
2860 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2861 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2863 char *pos
, ifname
[IFNAMSIZ
+ 1];
2867 pos
= os_strstr(cmd
, "ifname=");
2870 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2873 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2876 os_strlcpy(reply
, ifname
, max_len
);
2877 return os_strlen(ifname
);
2881 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2882 struct wpa_supplicant
*wpa_s
, char *cmd
)
2885 struct wpa_ssid
*ssid
;
2888 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2890 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2892 wpa_printf(MSG_DEBUG
,
2893 "CTRL_IFACE: Could not find network id=%d", id
);
2896 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2897 wpa_printf(MSG_DEBUG
,
2898 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2901 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2902 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2903 wpa_printf(MSG_ERROR
,
2904 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2909 * TODO: If necessary write our own group_add function,
2910 * for now we can reuse select_network
2912 wpa_supplicant_select_network(wpa_s
, ssid
);
2918 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2919 struct wpa_supplicant
*wpa_s
, char *cmd
)
2921 struct wpa_supplicant
*orig
;
2922 struct wpa_global
*global
;
2925 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2927 global
= wpa_s
->global
;
2930 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2931 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2937 wpa_printf(MSG_ERROR
,
2938 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2942 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2943 wpa_printf(MSG_ERROR
,
2944 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2948 wpa_s
->reassociate
= 0;
2949 wpa_s
->disconnected
= 1;
2950 wpa_supplicant_cancel_sched_scan(wpa_s
);
2951 wpa_supplicant_cancel_scan(wpa_s
);
2954 * TODO: If necessary write our own group_remove function,
2955 * for now we can reuse deauthenticate
2957 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2959 if (wpa_s
->mesh_if_created
)
2960 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
2966 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
2967 struct wpa_supplicant
*wpa_s
, char *cmd
)
2971 if (hwaddr_aton(cmd
, addr
) < 0)
2974 return wpas_mesh_peer_remove(wpa_s
, addr
);
2978 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
2979 struct wpa_supplicant
*wpa_s
, char *cmd
)
2985 pos
= os_strstr(cmd
, " duration=");
2988 duration
= atoi(pos
+ 10);
2993 if (hwaddr_aton(cmd
, addr
))
2996 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
2999 #endif /* CONFIG_MESH */
3002 static int wpa_supplicant_ctrl_iface_select_network(
3003 struct wpa_supplicant
*wpa_s
, char *cmd
)
3006 struct wpa_ssid
*ssid
;
3009 /* cmd: "<network id>" or "any" */
3010 if (os_strncmp(cmd
, "any", 3) == 0) {
3011 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3015 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3017 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3019 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3020 "network id=%d", id
);
3023 if (ssid
->disabled
== 2) {
3024 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3025 "SELECT_NETWORK with persistent P2P group");
3030 pos
= os_strstr(cmd
, " freq=");
3032 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3034 os_free(wpa_s
->select_network_scan_freqs
);
3035 wpa_s
->select_network_scan_freqs
= freqs
;
3039 wpa_s
->scan_min_time
.sec
= 0;
3040 wpa_s
->scan_min_time
.usec
= 0;
3041 wpa_supplicant_select_network(wpa_s
, ssid
);
3047 static int wpa_supplicant_ctrl_iface_enable_network(
3048 struct wpa_supplicant
*wpa_s
, char *cmd
)
3051 struct wpa_ssid
*ssid
;
3053 /* cmd: "<network id>" or "all" */
3054 if (os_strcmp(cmd
, "all") == 0) {
3055 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3059 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3061 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3063 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3064 "network id=%d", id
);
3067 if (ssid
->disabled
== 2) {
3068 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3069 "ENABLE_NETWORK with persistent P2P group");
3073 if (os_strstr(cmd
, " no-connect")) {
3078 wpa_s
->scan_min_time
.sec
= 0;
3079 wpa_s
->scan_min_time
.usec
= 0;
3080 wpa_supplicant_enable_network(wpa_s
, ssid
);
3086 static int wpa_supplicant_ctrl_iface_disable_network(
3087 struct wpa_supplicant
*wpa_s
, char *cmd
)
3090 struct wpa_ssid
*ssid
;
3092 /* cmd: "<network id>" or "all" */
3093 if (os_strcmp(cmd
, "all") == 0) {
3094 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3098 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3100 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3102 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3103 "network id=%d", id
);
3106 if (ssid
->disabled
== 2) {
3107 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3108 "DISABLE_NETWORK with persistent P2P "
3113 wpa_supplicant_disable_network(wpa_s
, ssid
);
3119 static int wpa_supplicant_ctrl_iface_add_network(
3120 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3122 struct wpa_ssid
*ssid
;
3125 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3127 ssid
= wpa_supplicant_add_network(wpa_s
);
3131 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3132 if (os_snprintf_error(buflen
, ret
))
3138 static int wpa_supplicant_ctrl_iface_remove_network(
3139 struct wpa_supplicant
*wpa_s
, char *cmd
)
3142 struct wpa_ssid
*ssid
;
3145 /* cmd: "<network id>" or "all" */
3146 if (os_strcmp(cmd
, "all") == 0) {
3147 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3148 if (wpa_s
->sched_scanning
)
3149 wpa_supplicant_cancel_sched_scan(wpa_s
);
3151 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3152 if (wpa_s
->current_ssid
) {
3154 wpa_s
->sme
.prev_bssid_set
= 0;
3155 #endif /* CONFIG_SME */
3156 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3157 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3158 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3159 wpa_s
->own_disconnect_req
= 1;
3160 wpa_supplicant_deauthenticate(
3161 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3163 ssid
= wpa_s
->conf
->ssid
;
3165 struct wpa_ssid
*remove_ssid
= ssid
;
3168 if (wpa_s
->last_ssid
== remove_ssid
)
3169 wpa_s
->last_ssid
= NULL
;
3170 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3171 wpa_config_remove_network(wpa_s
->conf
, id
);
3177 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3179 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3181 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3186 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3187 "network id=%d", id
);
3194 static int wpa_supplicant_ctrl_iface_update_network(
3195 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3196 char *name
, char *value
)
3200 ret
= wpa_config_set(ssid
, name
, value
, 0);
3202 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3203 "variable '%s'", name
);
3207 return 0; /* No change to the previously configured value */
3209 if (os_strcmp(name
, "bssid") != 0 &&
3210 os_strcmp(name
, "bssid_hint") != 0 &&
3211 os_strcmp(name
, "priority") != 0) {
3212 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3214 if (wpa_s
->current_ssid
== ssid
||
3215 wpa_s
->current_ssid
== NULL
) {
3217 * Invalidate the EAP session cache if anything in the
3218 * current or previously used configuration changes.
3220 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3224 if ((os_strcmp(name
, "psk") == 0 &&
3225 value
[0] == '"' && ssid
->ssid_len
) ||
3226 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3227 wpa_config_update_psk(ssid
);
3228 else if (os_strcmp(name
, "priority") == 0)
3229 wpa_config_update_prio_list(wpa_s
->conf
);
3235 static int wpa_supplicant_ctrl_iface_set_network(
3236 struct wpa_supplicant
*wpa_s
, char *cmd
)
3238 int id
, ret
, prev_bssid_set
, prev_disabled
;
3239 struct wpa_ssid
*ssid
;
3241 u8 prev_bssid
[ETH_ALEN
];
3243 /* cmd: "<network id> <variable name> <value>" */
3244 name
= os_strchr(cmd
, ' ');
3249 value
= os_strchr(name
, ' ');
3255 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3257 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3258 (u8
*) value
, os_strlen(value
));
3260 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3262 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3267 prev_bssid_set
= ssid
->bssid_set
;
3268 prev_disabled
= ssid
->disabled
;
3269 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3270 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3273 (ssid
->bssid_set
!= prev_bssid_set
||
3274 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3275 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3277 if (prev_disabled
!= ssid
->disabled
&&
3278 (prev_disabled
== 2 || ssid
->disabled
== 2))
3279 wpas_notify_network_type_changed(wpa_s
, ssid
);
3285 static int wpa_supplicant_ctrl_iface_get_network(
3286 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3290 struct wpa_ssid
*ssid
;
3293 /* cmd: "<network id> <variable name>" */
3294 name
= os_strchr(cmd
, ' ');
3295 if (name
== NULL
|| buflen
== 0)
3300 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3303 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3305 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3310 value
= wpa_config_get_no_key(ssid
, name
);
3311 if (value
== NULL
) {
3312 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3313 "variable '%s'", name
);
3317 res
= os_strlcpy(buf
, value
, buflen
);
3318 if (res
>= buflen
) {
3329 static int wpa_supplicant_ctrl_iface_dup_network(
3330 struct wpa_supplicant
*wpa_s
, char *cmd
,
3331 struct wpa_supplicant
*dst_wpa_s
)
3333 struct wpa_ssid
*ssid_s
, *ssid_d
;
3334 char *name
, *id
, *value
;
3335 int id_s
, id_d
, ret
;
3337 /* cmd: "<src network id> <dst network id> <variable name>" */
3338 id
= os_strchr(cmd
, ' ');
3343 name
= os_strchr(id
, ' ');
3351 wpa_printf(MSG_DEBUG
,
3352 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3353 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3355 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3356 if (ssid_s
== NULL
) {
3357 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3358 "network id=%d", id_s
);
3362 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3363 if (ssid_d
== NULL
) {
3364 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3365 "network id=%d", id_d
);
3369 value
= wpa_config_get(ssid_s
, name
);
3370 if (value
== NULL
) {
3371 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3372 "variable '%s'", name
);
3376 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3385 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3386 char *buf
, size_t buflen
)
3389 struct wpa_cred
*cred
;
3394 ret
= os_snprintf(pos
, end
- pos
,
3395 "cred id / realm / username / domain / imsi\n");
3396 if (os_snprintf_error(end
- pos
, ret
))
3400 cred
= wpa_s
->conf
->cred
;
3402 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3403 cred
->id
, cred
->realm
? cred
->realm
: "",
3404 cred
->username
? cred
->username
: "",
3405 cred
->domain
? cred
->domain
[0] : "",
3406 cred
->imsi
? cred
->imsi
: "");
3407 if (os_snprintf_error(end
- pos
, ret
))
3418 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3419 char *buf
, size_t buflen
)
3421 struct wpa_cred
*cred
;
3424 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3426 cred
= wpa_config_add_cred(wpa_s
->conf
);
3430 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3432 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3433 if (os_snprintf_error(buflen
, ret
))
3439 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3440 struct wpa_cred
*cred
)
3442 struct wpa_ssid
*ssid
;
3447 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3452 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3453 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3457 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3459 /* Remove any network entry created based on the removed credential */
3460 ssid
= wpa_s
->conf
->ssid
;
3462 if (ssid
->parent_cred
== cred
) {
3465 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3466 "used the removed credential", ssid
->id
);
3467 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3468 if (os_snprintf_error(sizeof(str
), res
))
3469 str
[sizeof(str
) - 1] = '\0';
3471 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3480 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3484 struct wpa_cred
*cred
, *prev
;
3486 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3487 * "provisioning_sp=<FQDN> */
3488 if (os_strcmp(cmd
, "all") == 0) {
3489 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3490 cred
= wpa_s
->conf
->cred
;
3494 wpas_ctrl_remove_cred(wpa_s
, prev
);
3499 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3500 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3502 cred
= wpa_s
->conf
->cred
;
3508 for (i
= 0; i
< prev
->num_domain
; i
++) {
3509 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3512 wpas_ctrl_remove_cred(wpa_s
, prev
);
3520 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3521 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3523 cred
= wpa_s
->conf
->cred
;
3527 if (prev
->provisioning_sp
&&
3528 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3529 wpas_ctrl_remove_cred(wpa_s
, prev
);
3535 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3537 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3538 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3542 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3546 struct wpa_cred
*cred
;
3549 /* cmd: "<cred id> <variable name> <value>" */
3550 name
= os_strchr(cmd
, ' ');
3555 value
= os_strchr(name
, ' ');
3561 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3563 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3564 (u8
*) value
, os_strlen(value
));
3566 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3568 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3573 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3574 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3575 "variable '%s'", name
);
3579 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3585 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3586 char *cmd
, char *buf
,
3591 struct wpa_cred
*cred
;
3594 /* cmd: "<cred id> <variable name>" */
3595 name
= os_strchr(cmd
, ' ');
3601 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3604 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3606 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3611 value
= wpa_config_get_cred_no_key(cred
, name
);
3612 if (value
== NULL
) {
3613 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3618 res
= os_strlcpy(buf
, value
, buflen
);
3619 if (res
>= buflen
) {
3630 #ifndef CONFIG_NO_CONFIG_WRITE
3631 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3635 if (!wpa_s
->conf
->update_config
) {
3636 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3637 "to update configuration (update_config=0)");
3641 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3643 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3644 "update configuration");
3646 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3652 #endif /* CONFIG_NO_CONFIG_WRITE */
3655 struct cipher_info
{
3661 static const struct cipher_info ciphers
[] = {
3662 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3663 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3664 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3665 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3666 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3667 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3668 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3669 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3672 static const struct cipher_info ciphers_group_mgmt
[] = {
3673 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3674 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3675 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3676 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3680 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3681 struct wpa_driver_capa
*capa
,
3682 char *buf
, size_t buflen
)
3695 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3701 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3702 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3703 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3704 pos
== buf
? "" : " ",
3706 if (os_snprintf_error(end
- pos
, ret
))
3716 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3717 struct wpa_driver_capa
*capa
,
3718 char *buf
, size_t buflen
)
3731 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3737 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3738 if (capa
->enc
& ciphers
[i
].capa
) {
3739 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3740 pos
== buf
? "" : " ",
3742 if (os_snprintf_error(end
- pos
, ret
))
3752 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3753 struct wpa_driver_capa
*capa
,
3754 char *buf
, size_t buflen
)
3766 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3767 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3768 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3769 pos
== buf
? "" : " ",
3770 ciphers_group_mgmt
[i
].name
);
3771 if (os_snprintf_error(end
- pos
, ret
))
3781 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3782 struct wpa_driver_capa
*capa
,
3783 char *buf
, size_t buflen
)
3795 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3802 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3803 if (os_snprintf_error(end
- pos
, ret
))
3807 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3808 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3809 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3810 if (os_snprintf_error(end
- pos
, ret
))
3815 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3816 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3817 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3818 if (os_snprintf_error(end
- pos
, ret
))
3823 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3824 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3825 if (os_snprintf_error(end
- pos
, ret
))
3830 #ifdef CONFIG_SUITEB
3831 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3832 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3833 if (os_snprintf_error(end
- pos
, ret
))
3837 #endif /* CONFIG_SUITEB */
3838 #ifdef CONFIG_SUITEB192
3839 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3840 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3841 if (os_snprintf_error(end
- pos
, ret
))
3845 #endif /* CONFIG_SUITEB192 */
3847 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
3848 ret
= os_snprintf(pos
, end
- pos
, " OWE");
3849 if (os_snprintf_error(end
- pos
, ret
))
3853 #endif /* CONFIG_OWE */
3855 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
3856 ret
= os_snprintf(pos
, end
- pos
, " DPP");
3857 if (os_snprintf_error(end
- pos
, ret
))
3861 #endif /* CONFIG_DPP */
3867 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3868 struct wpa_driver_capa
*capa
,
3869 char *buf
, size_t buflen
)
3881 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3887 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3888 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3889 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3890 pos
== buf
? "" : " ");
3891 if (os_snprintf_error(end
- pos
, ret
))
3896 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3897 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3898 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3899 pos
== buf
? "" : " ");
3900 if (os_snprintf_error(end
- pos
, ret
))
3909 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
3910 int res
, char *strict
,
3911 struct wpa_driver_capa
*capa
,
3912 char *buf
, size_t buflen
)
3924 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3930 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3931 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3932 pos
== buf
? "" : " ");
3933 if (os_snprintf_error(end
- pos
, ret
))
3938 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3939 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3940 pos
== buf
? "" : " ");
3941 if (os_snprintf_error(end
- pos
, ret
))
3946 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3947 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3948 pos
== buf
? "" : " ");
3949 if (os_snprintf_error(end
- pos
, ret
))
3955 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
3956 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
3957 pos
== buf
? "" : " ");
3958 if (os_snprintf_error(end
- pos
, ret
))
3962 #endif /* CONFIG_SAE */
3968 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3969 struct wpa_driver_capa
*capa
,
3970 char *buf
, size_t buflen
)
3982 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3988 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3989 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3990 pos
== buf
? "" : " ");
3991 if (os_snprintf_error(end
- pos
, ret
))
3996 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3997 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3998 pos
== buf
? "" : " ");
3999 if (os_snprintf_error(end
- pos
, ret
))
4005 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4006 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4007 pos
== buf
? "" : " ");
4008 if (os_snprintf_error(end
- pos
, ret
))
4012 #endif /* CONFIG_MESH */
4018 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4019 char *buf
, size_t buflen
)
4021 struct hostapd_channel_data
*chnl
;
4023 char *pos
, *end
, *hmode
;
4028 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4029 switch (wpa_s
->hw
.modes
[j
].mode
) {
4030 case HOSTAPD_MODE_IEEE80211B
:
4033 case HOSTAPD_MODE_IEEE80211G
:
4036 case HOSTAPD_MODE_IEEE80211A
:
4039 case HOSTAPD_MODE_IEEE80211AD
:
4045 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4046 if (os_snprintf_error(end
- pos
, ret
))
4049 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4050 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4051 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4053 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4054 if (os_snprintf_error(end
- pos
, ret
))
4058 ret
= os_snprintf(pos
, end
- pos
, "\n");
4059 if (os_snprintf_error(end
- pos
, ret
))
4068 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4069 char *buf
, size_t buflen
)
4071 struct hostapd_channel_data
*chnl
;
4073 char *pos
, *end
, *hmode
;
4078 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4079 switch (wpa_s
->hw
.modes
[j
].mode
) {
4080 case HOSTAPD_MODE_IEEE80211B
:
4083 case HOSTAPD_MODE_IEEE80211G
:
4086 case HOSTAPD_MODE_IEEE80211A
:
4089 case HOSTAPD_MODE_IEEE80211AD
:
4095 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4097 if (os_snprintf_error(end
- pos
, ret
))
4100 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4101 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4102 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4104 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4105 chnl
[i
].chan
, chnl
[i
].freq
,
4106 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4108 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4111 if (os_snprintf_error(end
- pos
, ret
))
4115 ret
= os_snprintf(pos
, end
- pos
, "\n");
4116 if (os_snprintf_error(end
- pos
, ret
))
4125 static int wpa_supplicant_ctrl_iface_get_capability(
4126 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4129 struct wpa_driver_capa capa
;
4135 /* Determine whether or not strict checking was requested */
4136 len
= os_strlcpy(field
, _field
, sizeof(field
));
4137 if (len
>= sizeof(field
))
4139 strict
= os_strchr(field
, ' ');
4140 if (strict
!= NULL
) {
4142 if (os_strcmp(strict
, "strict") != 0)
4146 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4147 field
, strict
? strict
: "");
4149 if (os_strcmp(field
, "eap") == 0) {
4150 return eap_get_names(buf
, buflen
);
4153 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4155 if (os_strcmp(field
, "pairwise") == 0)
4156 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4159 if (os_strcmp(field
, "group") == 0)
4160 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4163 if (os_strcmp(field
, "group_mgmt") == 0)
4164 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4167 if (os_strcmp(field
, "key_mgmt") == 0)
4168 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4171 if (os_strcmp(field
, "proto") == 0)
4172 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4175 if (os_strcmp(field
, "auth_alg") == 0)
4176 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4177 &capa
, buf
, buflen
);
4179 if (os_strcmp(field
, "modes") == 0)
4180 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4183 if (os_strcmp(field
, "channels") == 0)
4184 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4186 if (os_strcmp(field
, "freq") == 0)
4187 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4190 if (os_strcmp(field
, "tdls") == 0)
4191 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4192 #endif /* CONFIG_TDLS */
4195 if (os_strcmp(field
, "erp") == 0) {
4196 res
= os_snprintf(buf
, buflen
, "ERP");
4197 if (os_snprintf_error(buflen
, res
))
4201 #endif /* CONFIG_EPR */
4204 if (os_strcmp(field
, "fips") == 0) {
4205 res
= os_snprintf(buf
, buflen
, "FIPS");
4206 if (os_snprintf_error(buflen
, res
))
4210 #endif /* CONFIG_FIPS */
4213 if (os_strcmp(field
, "acs") == 0) {
4214 res
= os_snprintf(buf
, buflen
, "ACS");
4215 if (os_snprintf_error(buflen
, res
))
4219 #endif /* CONFIG_ACS */
4222 if (os_strcmp(field
, "fils") == 0 &&
4223 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
)) {
4224 #ifdef CONFIG_FILS_SK_PFS
4225 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4226 #else /* CONFIG_FILS_SK_PFS */
4227 res
= os_snprintf(buf
, buflen
, "FILS");
4228 #endif /* CONFIG_FILS_SK_PFS */
4229 if (os_snprintf_error(buflen
, res
))
4233 #endif /* CONFIG_FILS */
4235 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4242 #ifdef CONFIG_INTERWORKING
4243 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4244 struct wpabuf
*data
)
4254 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4255 if (os_snprintf_error(end
- pos
, ret
))
4259 d
= wpabuf_head_u8(data
);
4260 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4261 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4262 if (os_snprintf_error(end
- pos
, ret
))
4267 ret
= os_snprintf(pos
, end
- pos
, "\n");
4268 if (os_snprintf_error(end
- pos
, ret
))
4274 #endif /* CONFIG_INTERWORKING */
4278 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4281 const u8
*ie
, *ie_end
;
4285 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4288 ie_end
= ie
+ 2 + ie
[1];
4290 if (ie_end
- ie
< 2)
4293 info
= WPA_GET_LE16(ie
);
4295 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4296 if (os_snprintf_error(end
- pos
, ret
))
4300 if (info
& BIT(7)) {
4301 /* Cache Identifier Included */
4302 if (ie_end
- ie
< 2)
4304 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4306 if (os_snprintf_error(end
- pos
, ret
))
4312 if (info
& BIT(8)) {
4313 /* HESSID Included */
4314 if (ie_end
- ie
< ETH_ALEN
)
4316 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4318 if (os_snprintf_error(end
- pos
, ret
))
4324 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4326 if (ie_end
- ie
< realms
* 2)
4328 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4329 if (os_snprintf_error(end
- pos
, ret
))
4333 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4338 ret
= os_snprintf(pos
, end
- pos
, "\n");
4339 if (os_snprintf_error(end
- pos
, ret
))
4346 #endif /* CONFIG_FILS */
4349 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4350 unsigned long mask
, char *buf
, size_t buflen
)
4355 const u8
*ie
, *ie2
, *osen_ie
, *mesh
;
4360 if (mask
& WPA_BSS_MASK_ID
) {
4361 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4362 if (os_snprintf_error(end
- pos
, ret
))
4367 if (mask
& WPA_BSS_MASK_BSSID
) {
4368 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4369 MAC2STR(bss
->bssid
));
4370 if (os_snprintf_error(end
- pos
, ret
))
4375 if (mask
& WPA_BSS_MASK_FREQ
) {
4376 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4377 if (os_snprintf_error(end
- pos
, ret
))
4382 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4383 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4385 if (os_snprintf_error(end
- pos
, ret
))
4390 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4391 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4393 if (os_snprintf_error(end
- pos
, ret
))
4398 if (mask
& WPA_BSS_MASK_QUAL
) {
4399 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4400 if (os_snprintf_error(end
- pos
, ret
))
4405 if (mask
& WPA_BSS_MASK_NOISE
) {
4406 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4407 if (os_snprintf_error(end
- pos
, ret
))
4412 if (mask
& WPA_BSS_MASK_LEVEL
) {
4413 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4414 if (os_snprintf_error(end
- pos
, ret
))
4419 if (mask
& WPA_BSS_MASK_TSF
) {
4420 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4421 (unsigned long long) bss
->tsf
);
4422 if (os_snprintf_error(end
- pos
, ret
))
4427 if (mask
& WPA_BSS_MASK_AGE
) {
4428 struct os_reltime now
;
4430 os_get_reltime(&now
);
4431 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4432 (int) (now
.sec
- bss
->last_update
.sec
));
4433 if (os_snprintf_error(end
- pos
, ret
))
4438 if (mask
& WPA_BSS_MASK_IE
) {
4439 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4440 if (os_snprintf_error(end
- pos
, ret
))
4444 ie
= (const u8
*) (bss
+ 1);
4445 for (i
= 0; i
< bss
->ie_len
; i
++) {
4446 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4447 if (os_snprintf_error(end
- pos
, ret
))
4452 ret
= os_snprintf(pos
, end
- pos
, "\n");
4453 if (os_snprintf_error(end
- pos
, ret
))
4458 if (mask
& WPA_BSS_MASK_FLAGS
) {
4459 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4460 if (os_snprintf_error(end
- pos
, ret
))
4464 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4466 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4468 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4470 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4472 pos
= wpa_supplicant_ie_txt(pos
, end
,
4473 mesh
? "RSN" : "WPA2", ie2
,
4475 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4477 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4478 osen_ie
, 2 + osen_ie
[1]);
4479 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4480 if (!ie
&& !ie2
&& !osen_ie
&&
4481 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4482 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4483 if (os_snprintf_error(end
- pos
, ret
))
4489 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4490 if (os_snprintf_error(end
- pos
, ret
))
4495 if (bss_is_dmg(bss
)) {
4497 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4498 if (os_snprintf_error(end
- pos
, ret
))
4501 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4502 case IEEE80211_CAP_DMG_IBSS
:
4505 case IEEE80211_CAP_DMG_AP
:
4508 case IEEE80211_CAP_DMG_PBSS
:
4515 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4516 if (os_snprintf_error(end
- pos
, ret
))
4520 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4521 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4522 if (os_snprintf_error(end
- pos
, ret
))
4526 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4527 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4528 if (os_snprintf_error(end
- pos
, ret
))
4533 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4534 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4535 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4536 if (os_snprintf_error(end
- pos
, ret
))
4541 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4542 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4543 if (os_snprintf_error(end
- pos
, ret
))
4547 #endif /* CONFIG_HS20 */
4549 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4550 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4551 if (os_snprintf_error(end
- pos
, ret
))
4555 #endif /* CONFIG_FILS */
4557 ret
= os_snprintf(pos
, end
- pos
, "\n");
4558 if (os_snprintf_error(end
- pos
, ret
))
4563 if (mask
& WPA_BSS_MASK_SSID
) {
4564 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4565 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4566 if (os_snprintf_error(end
- pos
, ret
))
4572 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4573 ie
= (const u8
*) (bss
+ 1);
4574 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4575 if (ret
>= end
- pos
)
4580 #endif /* CONFIG_WPS */
4583 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4584 ie
= (const u8
*) (bss
+ 1);
4585 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4586 if (ret
>= end
- pos
)
4591 #endif /* CONFIG_P2P */
4593 #ifdef CONFIG_WIFI_DISPLAY
4594 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4596 ie
= (const u8
*) (bss
+ 1);
4597 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4598 WFD_IE_VENDOR_TYPE
);
4600 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4601 if (os_snprintf_error(end
- pos
, ret
)) {
4607 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4612 ret
= os_snprintf(pos
, end
- pos
, "\n");
4613 if (os_snprintf_error(end
- pos
, ret
))
4618 #endif /* CONFIG_WIFI_DISPLAY */
4620 #ifdef CONFIG_INTERWORKING
4621 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4622 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4623 struct wpa_bss_anqp_elem
*elem
;
4625 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4626 anqp
->capability_list
);
4627 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4629 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4630 anqp
->network_auth_type
);
4631 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4632 anqp
->roaming_consortium
);
4633 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4634 anqp
->ip_addr_type_availability
);
4635 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4637 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4638 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4640 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4641 anqp
->fils_realm_info
);
4643 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4644 anqp
->hs20_capability_list
);
4645 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4646 anqp
->hs20_operator_friendly_name
);
4647 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4648 anqp
->hs20_wan_metrics
);
4649 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4650 anqp
->hs20_connection_capability
);
4651 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4652 anqp
->hs20_operating_class
);
4653 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4654 anqp
->hs20_osu_providers_list
);
4655 #endif /* CONFIG_HS20 */
4657 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4658 struct wpa_bss_anqp_elem
, list
) {
4661 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4663 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4666 #endif /* CONFIG_INTERWORKING */
4669 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4670 ie
= (const u8
*) (bss
+ 1);
4671 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4672 if (ret
>= end
- pos
)
4677 #endif /* CONFIG_MESH */
4679 if (mask
& WPA_BSS_MASK_SNR
) {
4680 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4681 if (os_snprintf_error(end
- pos
, ret
))
4686 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4687 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4688 bss
->est_throughput
);
4689 if (os_snprintf_error(end
- pos
, ret
))
4695 if (mask
& WPA_BSS_MASK_FST
) {
4696 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4697 if (ret
< 0 || ret
>= end
- pos
)
4701 #endif /* CONFIG_FST */
4703 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4704 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4705 bss
->last_update_idx
);
4706 if (os_snprintf_error(end
- pos
, ret
))
4711 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4712 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4713 if (os_snprintf_error(end
- pos
, ret
))
4717 ie
= (const u8
*) (bss
+ 1);
4719 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4720 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4721 if (os_snprintf_error(end
- pos
, ret
))
4726 ret
= os_snprintf(pos
, end
- pos
, "\n");
4727 if (os_snprintf_error(end
- pos
, ret
))
4733 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4734 ret
= print_fils_indication(bss
, pos
, end
);
4739 #endif /* CONFIG_FILS */
4741 if (mask
& WPA_BSS_MASK_DELIM
) {
4742 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4743 if (os_snprintf_error(end
- pos
, ret
))
4752 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4753 const char *cmd
, char *buf
,
4758 struct wpa_bss
*bss
;
4759 struct wpa_bss
*bsslast
= NULL
;
4760 struct dl_list
*next
;
4763 char *ctmp
, *end
= buf
+ buflen
;
4764 unsigned long mask
= WPA_BSS_MASK_ALL
;
4766 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4767 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4768 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4770 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4772 } else { /* N1-N2 */
4773 unsigned int id1
, id2
;
4775 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4776 wpa_printf(MSG_INFO
, "Wrong BSS range "
4781 if (*(cmd
+ 6) == '-')
4784 id1
= atoi(cmd
+ 6);
4786 if (*ctmp
>= '0' && *ctmp
<= '9')
4789 id2
= (unsigned int) -1;
4790 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4791 if (id2
== (unsigned int) -1)
4792 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4796 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4797 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4798 struct wpa_bss
*tmp
= bss
;
4800 next
= tmp
->list_id
.next
;
4801 if (next
== &wpa_s
->bss_id
)
4803 tmp
= dl_list_entry(
4804 next
, struct wpa_bss
,
4813 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4814 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4815 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4816 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4817 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4819 bss
= wpa_bss_get_id(wpa_s
, i
);
4820 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4822 bss
= wpa_bss_get_id(wpa_s
, i
);
4824 next
= bss
->list_id
.next
;
4825 if (next
== &wpa_s
->bss_id
)
4828 bss
= dl_list_entry(next
, struct wpa_bss
,
4831 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
4832 bss
= wpa_s
->current_bss
;
4834 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4835 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4836 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4839 #endif /* CONFIG_P2P */
4840 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4841 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4843 struct wpa_bss
*tmp
;
4846 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4855 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4856 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4858 mask
= WPA_BSS_MASK_ALL
;
4864 if (bsslast
== NULL
)
4867 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4871 if (bss
== bsslast
) {
4872 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4873 (bss
== dl_list_last(&wpa_s
->bss_id
,
4874 struct wpa_bss
, list_id
))) {
4877 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4879 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4880 wpa_printf(MSG_DEBUG
,
4881 "Could not add end delim");
4886 next
= bss
->list_id
.next
;
4887 if (next
== &wpa_s
->bss_id
)
4889 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4890 } while (bss
&& len
);
4896 static int wpa_supplicant_ctrl_iface_ap_scan(
4897 struct wpa_supplicant
*wpa_s
, char *cmd
)
4899 int ap_scan
= atoi(cmd
);
4900 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4904 static int wpa_supplicant_ctrl_iface_scan_interval(
4905 struct wpa_supplicant
*wpa_s
, char *cmd
)
4907 int scan_int
= atoi(cmd
);
4908 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4912 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4913 struct wpa_supplicant
*wpa_s
, char *cmd
)
4915 int expire_age
= atoi(cmd
);
4916 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4920 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4921 struct wpa_supplicant
*wpa_s
, char *cmd
)
4923 int expire_count
= atoi(cmd
);
4924 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4928 static void wpa_supplicant_ctrl_iface_bss_flush(
4929 struct wpa_supplicant
*wpa_s
, char *cmd
)
4931 int flush_age
= atoi(cmd
);
4934 wpa_bss_flush(wpa_s
);
4936 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4940 #ifdef CONFIG_TESTING_OPTIONS
4941 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4943 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4944 /* MLME-DELETEKEYS.request */
4945 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4946 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4947 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4948 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4949 #ifdef CONFIG_IEEE80211W
4950 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4951 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4952 #endif /* CONFIG_IEEE80211W */
4954 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4956 /* MLME-SETPROTECTION.request(None) */
4957 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4958 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4959 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4960 wpa_sm_drop_sa(wpa_s
->wpa
);
4962 #endif /* CONFIG_TESTING_OPTIONS */
4965 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4968 #ifdef CONFIG_NO_SCAN_PROCESSING
4970 #else /* CONFIG_NO_SCAN_PROCESSING */
4972 struct wpa_bss
*bss
;
4973 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4975 if (hwaddr_aton(addr
, bssid
)) {
4976 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4977 "address '%s'", addr
);
4981 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4984 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4985 "configuration known for the target AP");
4989 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4991 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4997 * TODO: Find best network configuration block from configuration to
4998 * allow roaming to other networks
5001 wpa_s
->reassociate
= 1;
5002 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5005 #endif /* CONFIG_NO_SCAN_PROCESSING */
5010 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5012 unsigned int timeout
= atoi(cmd
);
5013 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5014 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5015 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5017 unsigned int search_delay
;
5018 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5022 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5023 wpa_dbg(wpa_s
, MSG_INFO
,
5024 "Reject P2P_FIND since interface is disabled");
5027 if (os_strstr(cmd
, "type=social"))
5028 type
= P2P_FIND_ONLY_SOCIAL
;
5029 else if (os_strstr(cmd
, "type=progressive"))
5030 type
= P2P_FIND_PROGRESSIVE
;
5032 pos
= os_strstr(cmd
, "dev_id=");
5035 if (hwaddr_aton(pos
, dev_id
))
5040 pos
= os_strstr(cmd
, "dev_type=");
5043 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5045 _dev_type
= dev_type
;
5048 pos
= os_strstr(cmd
, "delay=");
5051 search_delay
= atoi(pos
);
5053 search_delay
= wpas_p2p_search_delay(wpa_s
);
5055 pos
= os_strstr(cmd
, "freq=");
5063 /* Must be searched for last, because it adds nul termination */
5064 pos
= os_strstr(cmd
, " seek=");
5067 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5070 _seek
[seek_count
++] = pos
;
5072 term
= os_strchr(pos
, ' ');
5076 pos
= os_strstr(term
+ 1, "seek=");
5080 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5085 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5086 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5090 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5092 const char *last
= NULL
;
5097 /* Expected predefined CPT names delimited by ':' */
5098 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5099 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5100 wpa_printf(MSG_ERROR
,
5101 "P2PS: CPT name list is too long, expected up to %d names",
5102 P2PS_FEATURE_CAPAB_CPT_MAX
);
5107 token_len
= last
- token
;
5109 if (token_len
== 3 &&
5110 os_memcmp(token
, "UDP", token_len
) == 0) {
5111 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5112 } else if (token_len
== 3 &&
5113 os_memcmp(token
, "MAC", token_len
) == 0) {
5114 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5116 wpa_printf(MSG_ERROR
,
5117 "P2PS: Unsupported CPT name '%s'", token
);
5122 if (isblank((unsigned char) *last
)) {
5132 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5134 struct p2ps_provision
*p2ps_prov
;
5136 size_t info_len
= 0;
5138 u8 role
= P2PS_SETUP_NONE
;
5139 long long unsigned val
;
5142 pos
= os_strstr(cmd
, "info=");
5145 info_len
= os_strlen(pos
);
5148 info
= os_malloc(info_len
+ 1);
5150 info_len
= utf8_unescape(pos
, info_len
,
5151 info
, info_len
+ 1);
5157 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5158 if (p2ps_prov
== NULL
) {
5164 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5165 p2ps_prov
->info
[info_len
] = '\0';
5169 pos
= os_strstr(cmd
, "status=");
5171 p2ps_prov
->status
= atoi(pos
+ 7);
5173 p2ps_prov
->status
= -1;
5175 pos
= os_strstr(cmd
, "adv_id=");
5176 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5178 p2ps_prov
->adv_id
= val
;
5180 pos
= os_strstr(cmd
, "method=");
5182 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5184 p2ps_prov
->method
= 0;
5186 pos
= os_strstr(cmd
, "session=");
5187 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5189 p2ps_prov
->session_id
= val
;
5191 pos
= os_strstr(cmd
, "adv_mac=");
5192 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5195 pos
= os_strstr(cmd
, "session_mac=");
5196 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5199 pos
= os_strstr(cmd
, "cpt=");
5201 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5202 p2ps_prov
->cpt_priority
))
5205 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5208 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5209 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5211 /* force conncap with tstCap (no sanity checks) */
5212 pos
= os_strstr(cmd
, "tstCap=");
5214 role
= strtol(pos
+ 7, NULL
, 16);
5216 pos
= os_strstr(cmd
, "role=");
5218 role
= strtol(pos
+ 5, NULL
, 16);
5219 if (role
!= P2PS_SETUP_CLIENT
&&
5220 role
!= P2PS_SETUP_GROUP_OWNER
)
5221 role
= P2PS_SETUP_NONE
;
5224 p2ps_prov
->role
= role
;
5234 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5237 struct p2ps_provision
*p2ps_prov
;
5240 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5242 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5244 if (hwaddr_aton(cmd
, addr
))
5251 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5255 if (p2ps_prov
->status
< 0) {
5260 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5265 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5268 struct p2ps_provision
*p2ps_prov
;
5271 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5272 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5275 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5276 if (hwaddr_aton(cmd
, addr
))
5283 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5287 p2ps_prov
->pd_seeker
= 1;
5289 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5294 static int parse_freq(int chwidth
, int freq2
)
5299 return VHT_CHANWIDTH_80P80MHZ
;
5305 return VHT_CHANWIDTH_USE_HT
;
5307 return VHT_CHANWIDTH_80MHZ
;
5309 return VHT_CHANWIDTH_160MHZ
;
5311 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5318 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5319 char *buf
, size_t buflen
)
5324 enum p2p_wps_method wps_method
;
5327 int persistent_group
, persistent_id
= -1;
5334 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5335 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5336 size_t group_ssid_len
= 0;
5338 if (!wpa_s
->global
->p2p_init_wpa_s
)
5340 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5341 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5342 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5343 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5346 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5347 * [persistent|persistent=<network id>]
5348 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5349 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5351 if (hwaddr_aton(cmd
, addr
))
5359 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5360 pos2
= os_strstr(pos
, " persistent=");
5362 struct wpa_ssid
*ssid
;
5363 persistent_id
= atoi(pos2
+ 12);
5364 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5365 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5366 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5367 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5368 "SSID id=%d for persistent P2P group (GO)",
5373 join
= os_strstr(pos
, " join") != NULL
;
5374 auth
= os_strstr(pos
, " auth") != NULL
;
5375 automatic
= os_strstr(pos
, " auto") != NULL
;
5376 pd
= os_strstr(pos
, " provdisc") != NULL
;
5377 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5378 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5381 pos2
= os_strstr(pos
, " go_intent=");
5384 go_intent
= atoi(pos2
);
5385 if (go_intent
< 0 || go_intent
> 15)
5389 pos2
= os_strstr(pos
, " freq=");
5397 pos2
= os_strstr(pos
, " freq2=");
5399 freq2
= atoi(pos2
+ 7);
5401 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5403 chwidth
= atoi(pos2
+ 18);
5405 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5406 if (max_oper_chwidth
< 0)
5409 pos2
= os_strstr(pos
, " ssid=");
5414 end
= os_strchr(pos2
, ' ');
5416 group_ssid_len
= os_strlen(pos2
) / 2;
5418 group_ssid_len
= (end
- pos2
) / 2;
5419 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5420 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5422 group_ssid
= _group_ssid
;
5425 if (os_strncmp(pos
, "pin", 3) == 0) {
5426 /* Request random PIN (to be displayed) and enable the PIN */
5427 wps_method
= WPS_PIN_DISPLAY
;
5428 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5429 wps_method
= WPS_PBC
;
5430 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5431 wps_method
= WPS_P2PS
;
5434 pos
= os_strchr(pin
, ' ');
5435 wps_method
= WPS_PIN_KEYPAD
;
5438 if (os_strncmp(pos
, "display", 7) == 0)
5439 wps_method
= WPS_PIN_DISPLAY
;
5441 if (!wps_pin_str_valid(pin
)) {
5442 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5447 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5448 persistent_group
, automatic
, join
,
5449 auth
, go_intent
, freq
, freq2
, persistent_id
,
5450 pd
, ht40
, vht
, max_oper_chwidth
,
5451 group_ssid
, group_ssid_len
);
5452 if (new_pin
== -2) {
5453 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5456 if (new_pin
== -3) {
5457 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5462 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5463 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5464 if (os_snprintf_error(buflen
, ret
))
5469 os_memcpy(buf
, "OK\n", 3);
5474 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5476 unsigned int timeout
= atoi(cmd
);
5477 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5478 wpa_dbg(wpa_s
, MSG_INFO
,
5479 "Reject P2P_LISTEN since interface is disabled");
5482 return wpas_p2p_listen(wpa_s
, timeout
);
5486 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5490 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5492 /* <addr> <config method> [join|auto] */
5494 if (hwaddr_aton(cmd
, addr
))
5502 if (os_strstr(pos
, " join") != NULL
)
5503 use
= WPAS_P2P_PD_FOR_JOIN
;
5504 else if (os_strstr(pos
, " auto") != NULL
)
5505 use
= WPAS_P2P_PD_AUTO
;
5507 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5511 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5514 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5516 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5517 ssid
->passphrase
== NULL
)
5520 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5521 return os_strlen(buf
);
5525 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5526 char *buf
, size_t buflen
)
5530 u8 dst_buf
[ETH_ALEN
], *dst
;
5531 struct wpabuf
*tlvs
;
5535 if (hwaddr_aton(cmd
, dst_buf
))
5538 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5539 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5546 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5549 if (hexstr2bin(pos
, &version
, 1) < 0)
5555 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5556 #ifdef CONFIG_WIFI_DISPLAY
5557 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5558 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5559 #endif /* CONFIG_WIFI_DISPLAY */
5560 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5562 char *svc_info
= NULL
;
5566 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5569 pos
= os_strchr(pos
, ' ');
5570 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5575 pos
= os_strchr(svc_str
, ' ');
5580 /* All remaining data is the svc_info string */
5581 if (pos
&& pos
[0] && pos
[0] != ' ') {
5582 len
= os_strlen(pos
);
5584 /* Unescape in place */
5585 len
= utf8_unescape(pos
, len
, pos
, len
);
5592 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5595 len
= os_strlen(pos
);
5599 tlvs
= wpabuf_alloc(len
);
5602 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5607 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5612 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5613 if (os_snprintf_error(buflen
, res
))
5619 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5622 long long unsigned val
;
5624 if (sscanf(cmd
, "%llx", &val
) != 1)
5627 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5631 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5636 struct wpabuf
*resp_tlvs
;
5640 pos
= os_strchr(cmd
, ' ');
5648 if (hwaddr_aton(pos
, dst
))
5655 pos2
= os_strchr(pos
, ' ');
5659 dialog_token
= atoi(pos
);
5661 len
= os_strlen(pos2
);
5665 resp_tlvs
= wpabuf_alloc(len
);
5666 if (resp_tlvs
== NULL
)
5668 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5669 wpabuf_free(resp_tlvs
);
5673 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5674 wpabuf_free(resp_tlvs
);
5679 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5682 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5684 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5689 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5694 struct wpabuf
*query
, *resp
;
5696 pos
= os_strchr(cmd
, ' ');
5701 len
= os_strlen(cmd
);
5705 query
= wpabuf_alloc(len
);
5708 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5713 len
= os_strlen(pos
);
5719 resp
= wpabuf_alloc(len
);
5724 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5730 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5739 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5744 pos
= os_strchr(cmd
, ' ');
5749 if (hexstr2bin(cmd
, &version
, 1) < 0)
5752 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5756 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5757 u8 replace
, char *cmd
)
5761 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5762 char *svc_info
= NULL
;
5764 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5766 pos
= os_strchr(cmd
, ' ');
5771 /* Auto-Accept value is mandatory, and must be one of the
5772 * single values (0, 1, 2, 4) */
5773 auto_accept
= atoi(cmd
);
5774 switch (auto_accept
) {
5775 case P2PS_SETUP_NONE
: /* No auto-accept */
5776 case P2PS_SETUP_NEW
:
5777 case P2PS_SETUP_CLIENT
:
5778 case P2PS_SETUP_GROUP_OWNER
:
5784 /* Advertisement ID is mandatory */
5786 pos
= os_strchr(cmd
, ' ');
5791 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5792 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5795 /* Only allow replacements if exist, and adds if not */
5796 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5804 /* svc_state between 0 - 0xff is mandatory */
5805 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5808 pos
= os_strchr(pos
, ' ');
5812 /* config_methods is mandatory */
5814 if (sscanf(pos
, "%x", &config_methods
) != 1)
5817 if (!(config_methods
&
5818 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5821 pos
= os_strchr(pos
, ' ');
5828 /* Advertisement string is mandatory */
5829 if (!pos
[0] || pos
[0] == ' ')
5832 /* Terminate svc string */
5833 pos
= os_strchr(pos
, ' ');
5837 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5839 pos
= os_strchr(pos
, ' ');
5843 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5846 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5850 /* Service and Response Information are optional */
5851 if (pos
&& pos
[0]) {
5854 /* Note the bare ' included, which cannot exist legally
5855 * in unescaped string. */
5856 svc_info
= os_strstr(pos
, "svc_info='");
5860 len
= os_strlen(svc_info
);
5861 utf8_unescape(svc_info
, len
, svc_info
, len
);
5865 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
5866 (u8
) svc_state
, (u16
) config_methods
,
5867 svc_info
, cpt_prio
);
5871 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5875 pos
= os_strchr(cmd
, ' ');
5880 if (os_strcmp(cmd
, "bonjour") == 0)
5881 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
5882 if (os_strcmp(cmd
, "upnp") == 0)
5883 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
5884 if (os_strcmp(cmd
, "asp") == 0)
5885 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
5886 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5891 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
5895 struct wpabuf
*query
;
5898 len
= os_strlen(cmd
);
5902 query
= wpabuf_alloc(len
);
5905 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5910 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
5916 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5921 pos
= os_strchr(cmd
, ' ');
5926 if (hexstr2bin(cmd
, &version
, 1) < 0)
5929 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
5933 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5937 if (os_strcmp(cmd
, "all") == 0) {
5938 wpas_p2p_service_flush_asp(wpa_s
);
5942 if (sscanf(cmd
, "%x", &adv_id
) != 1)
5945 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
5949 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
5953 pos
= os_strchr(cmd
, ' ');
5958 if (os_strcmp(cmd
, "bonjour") == 0)
5959 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
5960 if (os_strcmp(cmd
, "upnp") == 0)
5961 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
5962 if (os_strcmp(cmd
, "asp") == 0)
5963 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
5964 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5969 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
5973 pos
= os_strchr(cmd
, ' ');
5978 if (os_strcmp(cmd
, "asp") == 0)
5979 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
5981 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5986 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
5992 if (hwaddr_aton(cmd
, addr
))
5995 return wpas_p2p_reject(wpa_s
, addr
);
5999 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
6003 struct wpa_ssid
*ssid
;
6004 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6005 int freq
= 0, pref_freq
= 0;
6006 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6009 pos
= os_strstr(cmd
, " peer=");
6012 if (hwaddr_aton(pos
, peer
))
6016 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6017 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6018 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6019 "for persistent P2P group",
6024 pos
= os_strstr(cmd
, " freq=");
6032 pos
= os_strstr(cmd
, " pref=");
6035 pref_freq
= atoi(pos
);
6040 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6041 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6044 pos
= os_strstr(cmd
, "freq2=");
6046 freq2
= atoi(pos
+ 6);
6048 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6050 chwidth
= atoi(pos
+ 18);
6052 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6053 if (max_oper_chwidth
< 0)
6056 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6057 max_oper_chwidth
, pref_freq
);
6061 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6064 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6066 pos
= os_strstr(cmd
, " peer=");
6072 if (hwaddr_aton(pos
, peer
)) {
6073 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6077 pos
= os_strstr(pos
, " go_dev_addr=");
6080 if (hwaddr_aton(pos
, go_dev_addr
)) {
6081 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6085 go_dev
= go_dev_addr
;
6088 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6092 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6094 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6095 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6096 if (os_strncmp(cmd
, "group=", 6) == 0)
6097 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6103 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6104 int id
, int freq
, int vht_center_freq2
,
6105 int ht40
, int vht
, int vht_chwidth
)
6107 struct wpa_ssid
*ssid
;
6109 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6110 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6111 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6112 "for persistent P2P group",
6117 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6118 vht_center_freq2
, 0, ht40
, vht
,
6119 vht_chwidth
, NULL
, 0, 0);
6123 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6125 int freq
= 0, persistent
= 0, group_id
= -1;
6126 int vht
= wpa_s
->conf
->p2p_go_vht
;
6127 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6128 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6129 char *token
, *context
= NULL
;
6131 while ((token
= str_token(cmd
, " ", &context
))) {
6132 if (sscanf(token
, "freq=%d", &freq
) == 1 ||
6133 sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6134 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6135 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6137 } else if (os_strcmp(token
, "ht40") == 0) {
6139 } else if (os_strcmp(token
, "vht") == 0) {
6142 } else if (os_strcmp(token
, "persistent") == 0) {
6145 wpa_printf(MSG_DEBUG
,
6146 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6152 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6153 if (max_oper_chwidth
< 0)
6157 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6158 freq
, freq2
, ht40
, vht
,
6161 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6166 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6167 char *buf
, size_t buflen
)
6169 u8 dev_addr
[ETH_ALEN
];
6170 struct wpa_ssid
*ssid
;
6174 ssid
= wpa_s
->current_ssid
;
6175 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6176 hwaddr_aton(cmd
, dev_addr
))
6179 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6182 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6183 if (os_snprintf_error(buflen
, res
))
6189 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6190 const u8
*p2p_dev_addr
)
6192 struct wpa_supplicant
*wpa_s
;
6194 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6195 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6203 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6204 char *buf
, size_t buflen
)
6206 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6208 const struct p2p_peer_info
*info
;
6210 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6211 struct wpa_ssid
*ssid
;
6214 if (!wpa_s
->global
->p2p
)
6217 if (os_strcmp(cmd
, "FIRST") == 0) {
6220 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6221 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6226 if (hwaddr_aton(cmd
, addr
) < 0)
6232 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6235 group_capab
= info
->group_capab
;
6238 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6239 wpa_printf(MSG_DEBUG
,
6240 "P2P: Could not find any BSS with p2p_dev_addr "
6241 MACSTR
", hence override group_capab from 0x%x to 0",
6242 MAC2STR(info
->p2p_device_addr
), group_capab
);
6249 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6255 "serial_number=%s\n"
6256 "config_methods=0x%x\n"
6258 "group_capab=0x%x\n"
6260 MAC2STR(info
->p2p_device_addr
),
6261 wps_dev_type_bin2str(info
->pri_dev_type
,
6262 devtype
, sizeof(devtype
)),
6267 info
->serial_number
,
6268 info
->config_methods
,
6272 if (os_snprintf_error(end
- pos
, res
))
6276 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6279 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6280 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6281 wps_dev_type_bin2str(t
, devtype
,
6283 if (os_snprintf_error(end
- pos
, res
))
6288 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6290 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6291 if (os_snprintf_error(end
- pos
, res
))
6296 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6301 if (info
->vendor_elems
) {
6302 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6303 if (os_snprintf_error(end
- pos
, res
))
6307 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6308 wpabuf_head(info
->vendor_elems
),
6309 wpabuf_len(info
->vendor_elems
));
6311 res
= os_snprintf(pos
, end
- pos
, "\n");
6312 if (os_snprintf_error(end
- pos
, res
))
6321 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6326 if (wpa_s
->global
->p2p
== NULL
)
6329 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6332 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6333 struct wpa_freq_range
*freq
;
6334 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6335 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6336 freq
->min
, freq
->max
);
6339 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6344 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6348 if (wpa_s
->global
->p2p
== NULL
)
6351 param
= os_strchr(cmd
, ' ');
6356 if (os_strcmp(cmd
, "discoverability") == 0) {
6357 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6362 if (os_strcmp(cmd
, "managed") == 0) {
6363 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6367 if (os_strcmp(cmd
, "listen_channel") == 0) {
6369 u8 channel
, op_class
;
6371 channel
= atoi(param
);
6372 pos
= os_strchr(param
, ' ');
6373 op_class
= pos
? atoi(pos
) : 81;
6375 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6379 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6380 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6384 if (os_strcmp(cmd
, "noa") == 0) {
6386 int count
, start
, duration
;
6387 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6388 count
= atoi(param
);
6389 pos
= os_strchr(param
, ',');
6394 pos
= os_strchr(pos
, ',');
6398 duration
= atoi(pos
);
6399 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6401 if (count
== 0 && duration
> 0)
6403 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6404 "start=%d duration=%d", count
, start
, duration
);
6405 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6408 if (os_strcmp(cmd
, "ps") == 0)
6409 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6411 if (os_strcmp(cmd
, "oppps") == 0)
6412 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6414 if (os_strcmp(cmd
, "ctwindow") == 0)
6415 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6417 if (os_strcmp(cmd
, "disabled") == 0) {
6418 wpa_s
->global
->p2p_disabled
= atoi(param
);
6419 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6420 wpa_s
->global
->p2p_disabled
?
6421 "disabled" : "enabled");
6422 if (wpa_s
->global
->p2p_disabled
) {
6423 wpas_p2p_stop_find(wpa_s
);
6424 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6425 p2p_flush(wpa_s
->global
->p2p
);
6430 if (os_strcmp(cmd
, "conc_pref") == 0) {
6431 if (os_strcmp(param
, "sta") == 0)
6432 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6433 else if (os_strcmp(param
, "p2p") == 0)
6434 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6436 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6439 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6444 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6445 wpa_s
->force_long_sd
= atoi(param
);
6449 if (os_strcmp(cmd
, "peer_filter") == 0) {
6451 if (hwaddr_aton(param
, addr
))
6453 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6457 if (os_strcmp(cmd
, "cross_connect") == 0)
6458 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6460 if (os_strcmp(cmd
, "go_apsd") == 0) {
6461 if (os_strcmp(param
, "disable") == 0)
6462 wpa_s
->set_ap_uapsd
= 0;
6464 wpa_s
->set_ap_uapsd
= 1;
6465 wpa_s
->ap_uapsd
= atoi(param
);
6470 if (os_strcmp(cmd
, "client_apsd") == 0) {
6471 if (os_strcmp(param
, "disable") == 0)
6472 wpa_s
->set_sta_uapsd
= 0;
6476 /* format: BE,BK,VI,VO;max SP Length */
6478 pos
= os_strchr(param
, ',');
6483 pos
= os_strchr(pos
, ',');
6488 pos
= os_strchr(pos
, ',');
6493 /* ignore max SP Length for now */
6495 wpa_s
->set_sta_uapsd
= 1;
6496 wpa_s
->sta_uapsd
= 0;
6498 wpa_s
->sta_uapsd
|= BIT(0);
6500 wpa_s
->sta_uapsd
|= BIT(1);
6502 wpa_s
->sta_uapsd
|= BIT(2);
6504 wpa_s
->sta_uapsd
|= BIT(3);
6509 if (os_strcmp(cmd
, "disallow_freq") == 0)
6510 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6512 if (os_strcmp(cmd
, "disc_int") == 0) {
6513 int min_disc_int
, max_disc_int
, max_disc_tu
;
6518 min_disc_int
= atoi(pos
);
6519 pos
= os_strchr(pos
, ' ');
6524 max_disc_int
= atoi(pos
);
6525 pos
= os_strchr(pos
, ' ');
6530 max_disc_tu
= atoi(pos
);
6532 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6533 max_disc_int
, max_disc_tu
);
6536 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6537 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6541 #ifdef CONFIG_WPS_NFC
6542 if (os_strcmp(cmd
, "nfc_tag") == 0)
6543 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6544 #endif /* CONFIG_WPS_NFC */
6546 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6547 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6551 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6554 op_class
= atoi(param
);
6555 param
= os_strchr(param
, ':');
6560 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6565 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6572 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6574 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6575 wpa_s
->force_long_sd
= 0;
6576 wpas_p2p_stop_find(wpa_s
);
6577 wpa_s
->parent
->p2ps_method_config_any
= 0;
6578 if (wpa_s
->global
->p2p
)
6579 p2p_flush(wpa_s
->global
->p2p
);
6583 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6586 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6589 pos
= os_strchr(cmd
, ' ');
6595 pos2
= os_strchr(pos
, ' ');
6603 pos
= os_strchr(pos2
, ' ');
6611 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6615 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6618 unsigned int period
= 0, interval
= 0;
6621 pos
= os_strchr(cmd
, ' ');
6626 interval
= atoi(pos
);
6629 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6633 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6640 if (os_strncmp(pos
, "iface=", 6) == 0) {
6644 if (hwaddr_aton(pos
, peer
))
6647 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6652 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6654 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6656 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6658 wpa_printf(MSG_DEBUG
,
6659 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6663 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6666 #endif /* CONFIG_P2P */
6669 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6671 struct wpa_freq_range_list ranges
;
6673 struct hostapd_hw_modes
*mode
;
6676 if (wpa_s
->hw
.modes
== NULL
)
6679 os_memset(&ranges
, 0, sizeof(ranges
));
6680 if (freq_range_list_parse(&ranges
, val
) < 0)
6683 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6686 mode
= &wpa_s
->hw
.modes
[i
];
6687 for (j
= 0; j
< mode
->num_channels
; j
++) {
6690 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6693 freq
= mode
->channels
[j
].freq
;
6694 if (!freq_range_list_includes(&ranges
, freq
))
6697 int_array_add_unique(&freqs
, freq
);
6701 os_free(ranges
.range
);
6706 #ifdef CONFIG_INTERWORKING
6708 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6716 auto_sel
= os_strstr(param
, "auto") != NULL
;
6718 pos
= os_strstr(param
, "freq=");
6720 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6727 return interworking_select(wpa_s
, auto_sel
, freqs
);
6731 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6735 struct wpa_bss
*bss
;
6737 if (hwaddr_aton(dst
, bssid
)) {
6738 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6742 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6744 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6749 if (bss
->ssid_len
== 0) {
6752 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6753 " does not have SSID information", MAC2STR(bssid
));
6755 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6757 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6758 bss
->ssid_len
> 0) {
6766 wpa_printf(MSG_DEBUG
,
6767 "Found another matching BSS entry with SSID");
6770 return interworking_connect(wpa_s
, bss
, only_add
);
6774 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6776 u8 dst_addr
[ETH_ALEN
];
6779 #define MAX_ANQP_INFO_ID 100
6780 u16 id
[MAX_ANQP_INFO_ID
];
6783 u32 mbo_subtypes
= 0;
6785 used
= hwaddr_aton2(dst
, dst_addr
);
6791 while (num_id
< MAX_ANQP_INFO_ID
) {
6792 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6794 int num
= atoi(pos
+ 5);
6795 if (num
<= 0 || num
> 31)
6797 subtypes
|= BIT(num
);
6798 #else /* CONFIG_HS20 */
6800 #endif /* CONFIG_HS20 */
6801 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6803 int num
= atoi(pos
+ 4);
6805 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
6807 mbo_subtypes
|= BIT(num
);
6808 #else /* CONFIG_MBO */
6810 #endif /* CONFIG_MBO */
6812 id
[num_id
] = atoi(pos
);
6816 pos
= os_strchr(pos
+ 1, ',');
6822 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
6825 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
6830 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
6832 u8 dst_addr
[ETH_ALEN
];
6833 struct wpabuf
*advproto
, *query
= NULL
;
6838 used
= hwaddr_aton2(cmd
, dst_addr
);
6846 /* Advertisement Protocol ID */
6847 end
= os_strchr(pos
, ' ');
6851 len
= os_strlen(pos
);
6857 advproto
= wpabuf_alloc(len
);
6858 if (advproto
== NULL
)
6860 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
6864 /* Optional Query Request */
6869 len
= os_strlen(pos
);
6876 query
= wpabuf_alloc(len
);
6879 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
6884 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
6887 wpabuf_free(advproto
);
6894 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
6901 size_t resp_len
, start
, requested_len
;
6902 struct wpabuf
*resp
;
6905 used
= hwaddr_aton2(cmd
, addr
);
6912 dialog_token
= atoi(pos
);
6914 if (wpa_s
->last_gas_resp
&&
6915 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
6916 dialog_token
== wpa_s
->last_gas_dialog_token
)
6917 resp
= wpa_s
->last_gas_resp
;
6918 else if (wpa_s
->prev_gas_resp
&&
6919 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
6920 dialog_token
== wpa_s
->prev_gas_dialog_token
)
6921 resp
= wpa_s
->prev_gas_resp
;
6925 resp_len
= wpabuf_len(resp
);
6927 requested_len
= resp_len
;
6929 pos
= os_strchr(pos
, ' ');
6932 if (start
> resp_len
)
6933 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6934 pos
= os_strchr(pos
, ',');
6938 requested_len
= atoi(pos
);
6939 if (start
+ requested_len
> resp_len
)
6940 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6943 if (requested_len
* 2 + 1 > buflen
)
6944 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
6946 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
6949 if (start
+ requested_len
== resp_len
) {
6951 * Free memory by dropping the response after it has been
6954 if (resp
== wpa_s
->prev_gas_resp
) {
6955 wpabuf_free(wpa_s
->prev_gas_resp
);
6956 wpa_s
->prev_gas_resp
= NULL
;
6958 wpabuf_free(wpa_s
->last_gas_resp
);
6959 wpa_s
->last_gas_resp
= NULL
;
6965 #endif /* CONFIG_INTERWORKING */
6970 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6972 u8 dst_addr
[ETH_ALEN
];
6977 used
= hwaddr_aton2(dst
, dst_addr
);
6984 int num
= atoi(pos
);
6985 if (num
<= 0 || num
> 31)
6987 subtypes
|= BIT(num
);
6988 pos
= os_strchr(pos
+ 1, ',');
6997 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
7001 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7002 const u8
*addr
, const char *realm
)
7008 rlen
= os_strlen(realm
);
7010 buf
= os_malloc(len
);
7013 buf
[0] = 1; /* NAI Home Realm Count */
7014 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7016 os_memcpy(buf
+ 3, realm
, rlen
);
7018 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7019 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7028 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7031 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7032 u8 dst_addr
[ETH_ALEN
];
7038 used
= hwaddr_aton2(dst
, dst_addr
);
7042 while (dst
[used
] == ' ')
7044 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7045 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7048 len
= os_strlen(dst
+ used
);
7050 if (len
== 0 && cred
&& cred
->realm
)
7051 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7056 buf
= os_malloc(len
);
7059 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7064 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7065 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7073 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7076 u8 dst_addr
[ETH_ALEN
];
7078 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7080 used
= hwaddr_aton2(cmd
, dst_addr
);
7085 icon
= str_token(cmd
, " ", &ctx
);
7086 poffset
= str_token(cmd
, " ", &ctx
);
7087 psize
= str_token(cmd
, " ", &ctx
);
7088 if (!icon
|| !poffset
|| !psize
)
7091 wpa_s
->fetch_osu_icon_in_progress
= 0;
7092 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7097 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7099 u8 dst_addr
[ETH_ALEN
];
7104 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7106 used
= hwaddr_aton2(cmd
, dst_addr
);
7110 while (cmd
[used
] == ' ')
7112 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7114 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7118 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7120 u8 dst_addr
[ETH_ALEN
];
7124 used
= hwaddr_aton2(cmd
, dst_addr
);
7128 while (cmd
[used
] == ' ')
7132 wpa_s
->fetch_osu_icon_in_progress
= 0;
7133 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7134 (u8
*) icon
, os_strlen(icon
), inmem
);
7137 #endif /* CONFIG_HS20 */
7140 #ifdef CONFIG_AUTOSCAN
7142 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7145 enum wpa_states state
= wpa_s
->wpa_state
;
7146 char *new_params
= NULL
;
7148 if (os_strlen(cmd
) > 0) {
7149 new_params
= os_strdup(cmd
);
7150 if (new_params
== NULL
)
7154 os_free(wpa_s
->conf
->autoscan
);
7155 wpa_s
->conf
->autoscan
= new_params
;
7157 if (wpa_s
->conf
->autoscan
== NULL
)
7158 autoscan_deinit(wpa_s
);
7159 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7160 autoscan_init(wpa_s
, 1);
7161 else if (state
== WPA_SCANNING
)
7162 wpa_supplicant_reinit_autoscan(wpa_s
);
7164 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7165 wpa_supplicant_state_txt(state
));
7170 #endif /* CONFIG_AUTOSCAN */
7175 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7181 struct wpabuf
*tfs_req
= NULL
;
7183 if (os_strncmp(cmd
, "enter", 5) == 0)
7185 else if (os_strncmp(cmd
, "exit", 4) == 0)
7190 pos
= os_strstr(cmd
, " interval=");
7192 intval
= atoi(pos
+ 10);
7194 pos
= os_strstr(cmd
, " tfs_req=");
7199 end
= os_strchr(pos
, ' ');
7203 len
= os_strlen(pos
);
7207 tfs_req
= wpabuf_alloc(len
);
7208 if (tfs_req
== NULL
)
7210 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7211 wpabuf_free(tfs_req
);
7216 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7217 WNM_SLEEP_MODE_EXIT
, intval
,
7219 wpabuf_free(tfs_req
);
7225 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7227 int query_reason
, list
= 0;
7228 char *btm_candidates
= NULL
;
7230 query_reason
= atoi(cmd
);
7232 cmd
= os_strchr(cmd
, ' ');
7234 if (os_strncmp(cmd
, " list", 5) == 0)
7237 btm_candidates
= cmd
;
7240 wpa_printf(MSG_DEBUG
,
7241 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7242 query_reason
, list
? " candidate list" : "");
7244 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7249 #endif /* CONFIG_WNM */
7252 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7255 struct wpa_signal_info si
;
7259 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7266 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7267 "NOISE=%d\nFREQUENCY=%u\n",
7268 si
.current_signal
, si
.current_txrate
/ 1000,
7269 si
.current_noise
, si
.frequency
);
7270 if (os_snprintf_error(end
- pos
, ret
))
7274 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7275 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7276 channel_width_to_string(si
.chanwidth
));
7277 if (os_snprintf_error(end
- pos
, ret
))
7282 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
7283 ret
= os_snprintf(pos
, end
- pos
,
7284 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7285 si
.center_frq1
, si
.center_frq2
);
7286 if (os_snprintf_error(end
- pos
, ret
))
7291 if (si
.avg_signal
) {
7292 ret
= os_snprintf(pos
, end
- pos
,
7293 "AVG_RSSI=%d\n", si
.avg_signal
);
7294 if (os_snprintf_error(end
- pos
, ret
))
7299 if (si
.avg_beacon_signal
) {
7300 ret
= os_snprintf(pos
, end
- pos
,
7301 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7302 if (os_snprintf_error(end
- pos
, ret
))
7311 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7318 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7319 wpa_printf(MSG_DEBUG
,
7320 "Reject SIGNAL_MONITOR command - bgscan is active");
7323 pos
= os_strstr(cmd
, "THRESHOLD=");
7325 threshold
= atoi(pos
+ 10);
7326 pos
= os_strstr(cmd
, "HYSTERESIS=");
7328 hysteresis
= atoi(pos
+ 11);
7329 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7333 #ifdef CONFIG_TESTING_OPTIONS
7334 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7335 enum wpa_driver_if_type if_type
,
7337 unsigned int *freq_list
)
7339 char *pos
= wpa_s
->get_pref_freq_list_override
;
7341 unsigned int count
= 0;
7343 /* Override string format:
7344 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7347 if (atoi(pos
) == (int) if_type
)
7349 pos
= os_strchr(pos
, ' ');
7355 pos
= os_strchr(pos
, ':');
7359 end
= os_strchr(pos
, ' ');
7360 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7361 freq_list
[count
++] = atoi(pos
);
7362 pos
= os_strchr(pos
, ',');
7370 #endif /* CONFIG_TESTING_OPTIONS */
7373 static int wpas_ctrl_iface_get_pref_freq_list(
7374 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7376 unsigned int freq_list
[100], num
= 100, i
;
7378 enum wpa_driver_if_type iface_type
;
7384 /* buf: "<interface_type>" */
7385 if (os_strcmp(cmd
, "STATION") == 0)
7386 iface_type
= WPA_IF_STATION
;
7387 else if (os_strcmp(cmd
, "AP") == 0)
7388 iface_type
= WPA_IF_AP_BSS
;
7389 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7390 iface_type
= WPA_IF_P2P_GO
;
7391 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7392 iface_type
= WPA_IF_P2P_CLIENT
;
7393 else if (os_strcmp(cmd
, "IBSS") == 0)
7394 iface_type
= WPA_IF_IBSS
;
7395 else if (os_strcmp(cmd
, "TDLS") == 0)
7396 iface_type
= WPA_IF_TDLS
;
7400 wpa_printf(MSG_DEBUG
,
7401 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7404 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7408 for (i
= 0; i
< num
; i
++) {
7409 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7410 i
> 0 ? "," : "", freq_list
[i
]);
7411 if (os_snprintf_error(end
- pos
, ret
))
7420 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7421 char *buf
, size_t buflen
)
7426 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7427 (long long unsigned) wpa_s
->drv_flags
);
7428 if (os_snprintf_error(buflen
, ret
))
7434 for (i
= 0; i
< 64; i
++) {
7435 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7436 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7437 driver_flag_to_string(1LLU << i
));
7438 if (os_snprintf_error(end
- pos
, ret
))
7448 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7451 struct hostap_sta_driver_data sta
;
7454 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7458 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7459 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7460 if (os_snprintf_error(buflen
, ret
))
7467 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7468 char *buf
, size_t buflen
)
7472 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7474 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7475 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7478 country
[0] = cmd
[8];
7479 country
[1] = cmd
[9];
7481 p2p_set_country(p2p
, country
);
7484 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7485 if (os_snprintf_error(buflen
, ret
))
7490 #endif /* ANDROID */
7493 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7494 char *buf
, size_t buflen
)
7499 unsigned int vendor_id
, subcmd
;
7500 struct wpabuf
*reply
;
7501 size_t data_len
= 0;
7503 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7504 vendor_id
= strtoul(cmd
, &pos
, 16);
7505 if (!isblank((unsigned char) *pos
))
7508 subcmd
= strtoul(pos
, &pos
, 10);
7511 if (!isblank((unsigned char) *pos
++))
7513 data_len
= os_strlen(pos
);
7518 data
= os_malloc(data_len
);
7522 if (hexstr2bin(pos
, data
, data_len
)) {
7523 wpa_printf(MSG_DEBUG
,
7524 "Vendor command: wrong parameter format");
7530 reply
= wpabuf_alloc((buflen
- 1) / 2);
7536 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7540 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7550 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7553 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7554 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7555 #endif /* CONFIG_P2P */
7557 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7559 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7560 wpa_s
->ignore_post_flush_scan_res
= 1;
7562 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7564 * Avoid possible auto connect re-connection on getting
7565 * disconnected due to state flush.
7567 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7571 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7572 wpas_p2p_cancel(p2p_wpa_s
);
7573 p2p_ctrl_flush(p2p_wpa_s
);
7574 wpas_p2p_service_flush(p2p_wpa_s
);
7575 p2p_wpa_s
->global
->p2p_disabled
= 0;
7576 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7577 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7578 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7579 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7580 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7581 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7582 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7583 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7584 #endif /* CONFIG_P2P */
7586 #ifdef CONFIG_WPS_TESTING
7587 wps_version_number
= 0x20;
7588 wps_testing_dummy_cred
= 0;
7589 wps_corrupt_pkhash
= 0;
7590 wps_force_auth_types_in_use
= 0;
7591 wps_force_encr_types_in_use
= 0;
7592 #endif /* CONFIG_WPS_TESTING */
7594 wpa_s
->wps_fragment_size
= 0;
7595 wpas_wps_cancel(wpa_s
);
7596 wps_registrar_flush(wpa_s
->wps
->registrar
);
7597 #endif /* CONFIG_WPS */
7598 wpa_s
->after_wps
= 0;
7599 wpa_s
->known_wps_freq
= 0;
7602 wpas_dpp_deinit(wpa_s
);
7603 #endif /* CONFIG_DPP */
7606 #ifdef CONFIG_TDLS_TESTING
7608 #endif /* CONFIG_TDLS_TESTING */
7609 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7610 wpa_tdls_enable(wpa_s
->wpa
, 1);
7611 #endif /* CONFIG_TDLS */
7613 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7614 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7616 wpa_s
->no_keep_alive
= 0;
7617 wpa_s
->own_disconnect_req
= 0;
7619 os_free(wpa_s
->disallow_aps_bssid
);
7620 wpa_s
->disallow_aps_bssid
= NULL
;
7621 wpa_s
->disallow_aps_bssid_count
= 0;
7622 os_free(wpa_s
->disallow_aps_ssid
);
7623 wpa_s
->disallow_aps_ssid
= NULL
;
7624 wpa_s
->disallow_aps_ssid_count
= 0;
7626 wpa_s
->set_sta_uapsd
= 0;
7627 wpa_s
->sta_uapsd
= 0;
7629 wpa_drv_radio_disable(wpa_s
, 0);
7630 wpa_blacklist_clear(wpa_s
);
7631 wpa_s
->extra_blacklist_count
= 0;
7632 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7633 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7634 wpa_config_flush_blobs(wpa_s
->conf
);
7635 wpa_s
->conf
->auto_interworking
= 0;
7636 wpa_s
->conf
->okc
= 0;
7638 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7639 rsn_preauth_deinit(wpa_s
->wpa
);
7641 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7642 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7643 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7644 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7646 radio_remove_works(wpa_s
, NULL
, 1);
7647 wpa_s
->ext_work_in_progress
= 0;
7649 wpa_s
->next_ssid
= NULL
;
7651 #ifdef CONFIG_INTERWORKING
7653 hs20_cancel_fetch_osu(wpa_s
);
7654 hs20_del_icon(wpa_s
, NULL
, NULL
);
7655 #endif /* CONFIG_HS20 */
7656 #endif /* CONFIG_INTERWORKING */
7658 wpa_s
->ext_mgmt_frame_handling
= 0;
7659 wpa_s
->ext_eapol_frame_io
= 0;
7660 #ifdef CONFIG_TESTING_OPTIONS
7661 wpa_s
->extra_roc_dur
= 0;
7662 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7663 wpa_s
->p2p_go_csa_on_inv
= 0;
7664 wpa_s
->ignore_auth_resp
= 0;
7665 wpa_s
->ignore_assoc_disallow
= 0;
7666 wpa_s
->reject_btm_req_reason
= 0;
7667 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7668 os_free(wpa_s
->get_pref_freq_list_override
);
7669 wpa_s
->get_pref_freq_list_override
= NULL
;
7670 #endif /* CONFIG_TESTING_OPTIONS */
7672 wpa_s
->disconnected
= 0;
7673 os_free(wpa_s
->next_scan_freqs
);
7674 wpa_s
->next_scan_freqs
= NULL
;
7675 os_free(wpa_s
->select_network_scan_freqs
);
7676 wpa_s
->select_network_scan_freqs
= NULL
;
7678 wpa_bss_flush(wpa_s
);
7679 if (!dl_list_empty(&wpa_s
->bss
)) {
7680 wpa_printf(MSG_DEBUG
,
7681 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7682 MACSTR
" pending_bssid=" MACSTR
,
7683 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7684 MAC2STR(wpa_s
->bssid
),
7685 MAC2STR(wpa_s
->pending_bssid
));
7688 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7689 wpa_s
->wnmsleep_used
= 0;
7692 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7693 #endif /* CONFIG_SME */
7695 wpabuf_free(wpa_s
->ric_ies
);
7696 wpa_s
->ric_ies
= NULL
;
7700 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7701 char *buf
, size_t buflen
)
7703 struct wpa_radio_work
*work
;
7705 struct os_reltime now
, diff
;
7710 os_get_reltime(&now
);
7712 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7716 os_reltime_sub(&now
, &work
->time
, &diff
);
7717 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7718 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7719 work
->started
, diff
.sec
, diff
.usec
);
7720 if (os_snprintf_error(end
- pos
, ret
))
7729 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7731 struct wpa_radio_work
*work
= eloop_ctx
;
7732 struct wpa_external_work
*ework
= work
->ctx
;
7734 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7735 "Timing out external radio work %u (%s)",
7736 ework
->id
, work
->type
);
7737 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7738 work
->wpa_s
->ext_work_in_progress
= 0;
7739 radio_work_done(work
);
7744 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7746 struct wpa_external_work
*ework
= work
->ctx
;
7750 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7754 * work->type points to a buffer in ework, so need to replace
7755 * that here with a fixed string to avoid use of freed memory
7758 work
->type
= "freed-ext-work";
7764 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7765 ework
->id
, ework
->type
);
7766 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7767 work
->wpa_s
->ext_work_in_progress
= 1;
7768 if (!ework
->timeout
)
7769 ework
->timeout
= 10;
7770 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7775 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7776 char *buf
, size_t buflen
)
7778 struct wpa_external_work
*ework
;
7782 unsigned int freq
= 0;
7784 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7786 ework
= os_zalloc(sizeof(*ework
));
7790 pos
= os_strchr(cmd
, ' ');
7792 type_len
= pos
- cmd
;
7795 pos2
= os_strstr(pos
, "freq=");
7797 freq
= atoi(pos2
+ 5);
7799 pos2
= os_strstr(pos
, "timeout=");
7801 ework
->timeout
= atoi(pos2
+ 8);
7803 type_len
= os_strlen(cmd
);
7805 if (4 + type_len
>= sizeof(ework
->type
))
7806 type_len
= sizeof(ework
->type
) - 4 - 1;
7807 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
7808 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
7809 ework
->type
[4 + type_len
] = '\0';
7811 wpa_s
->ext_work_id
++;
7812 if (wpa_s
->ext_work_id
== 0)
7813 wpa_s
->ext_work_id
++;
7814 ework
->id
= wpa_s
->ext_work_id
;
7816 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
7822 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
7823 if (os_snprintf_error(buflen
, ret
))
7829 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
7831 struct wpa_radio_work
*work
;
7832 unsigned int id
= atoi(cmd
);
7834 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7836 struct wpa_external_work
*ework
;
7838 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7841 if (id
&& ework
->id
!= id
)
7843 wpa_dbg(wpa_s
, MSG_DEBUG
,
7844 "Completed external radio work %u (%s)",
7845 ework
->id
, ework
->type
);
7846 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
7847 wpa_s
->ext_work_in_progress
= 0;
7848 radio_work_done(work
);
7850 return 3; /* "OK\n" */
7857 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
7858 char *buf
, size_t buflen
)
7860 if (os_strcmp(cmd
, "show") == 0)
7861 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
7862 if (os_strncmp(cmd
, "add ", 4) == 0)
7863 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
7864 if (os_strncmp(cmd
, "done ", 5) == 0)
7865 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
7870 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
7872 struct wpa_radio_work
*work
, *tmp
;
7874 if (!wpa_s
|| !wpa_s
->radio
)
7877 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
7878 struct wpa_radio_work
, list
) {
7879 struct wpa_external_work
*ework
;
7881 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7884 wpa_dbg(wpa_s
, MSG_DEBUG
,
7885 "Flushing%s external radio work %u (%s)",
7886 work
->started
? " started" : "", ework
->id
,
7889 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7891 radio_work_done(work
);
7897 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
7899 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7900 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
7904 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
7905 unsigned int *scan_id_count
, int scan_id
[])
7907 const char *pos
= value
;
7910 if (*pos
== ' ' || *pos
== '\0')
7912 if (*scan_id_count
== MAX_SCAN_ID
)
7914 scan_id
[(*scan_id_count
)++] = atoi(pos
);
7915 pos
= os_strchr(pos
, ',');
7924 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
7925 char *reply
, int reply_size
, int *reply_len
)
7928 unsigned int manual_scan_passive
= 0;
7929 unsigned int manual_scan_use_id
= 0;
7930 unsigned int manual_scan_only_new
= 0;
7931 unsigned int scan_only
= 0;
7932 unsigned int scan_id_count
= 0;
7933 int scan_id
[MAX_SCAN_ID
];
7934 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
7935 struct wpa_scan_results
*scan_res
);
7936 int *manual_scan_freqs
= NULL
;
7937 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
7938 unsigned int ssid_count
= 0;
7940 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
7945 if (radio_work_pending(wpa_s
, "scan")) {
7946 wpa_printf(MSG_DEBUG
,
7947 "Pending scan scheduled - reject new request");
7948 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7952 #ifdef CONFIG_INTERWORKING
7953 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
7954 wpa_printf(MSG_DEBUG
,
7955 "Interworking select in progress - reject new scan");
7956 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7959 #endif /* CONFIG_INTERWORKING */
7962 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
7965 pos
= os_strstr(params
, "freq=");
7967 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
7969 if (manual_scan_freqs
== NULL
) {
7975 pos
= os_strstr(params
, "passive=");
7977 manual_scan_passive
= !!atoi(pos
+ 8);
7979 pos
= os_strstr(params
, "use_id=");
7981 manual_scan_use_id
= atoi(pos
+ 7);
7983 pos
= os_strstr(params
, "only_new=1");
7985 manual_scan_only_new
= 1;
7987 pos
= os_strstr(params
, "scan_id=");
7988 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
7995 while (pos
&& *pos
!= '\0') {
7996 if (os_strncmp(pos
, "ssid ", 5) == 0) {
8002 if (*end
== '\0' || *end
== ' ')
8007 ns
= os_realloc_array(
8008 ssid
, ssid_count
+ 1,
8009 sizeof(struct wpa_ssid_value
));
8016 if ((end
- pos
) & 0x01 ||
8017 end
- pos
> 2 * SSID_MAX_LEN
||
8018 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8019 (end
- pos
) / 2) < 0) {
8020 wpa_printf(MSG_DEBUG
,
8021 "Invalid SSID value '%s'",
8026 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8027 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8028 ssid
[ssid_count
].ssid
,
8029 ssid
[ssid_count
].ssid_len
);
8034 pos
= os_strchr(pos
, ' ');
8040 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8041 os_free(wpa_s
->ssids_from_scan_req
);
8043 wpa_s
->ssids_from_scan_req
= ssid
;
8046 wpa_s
->ssids_from_scan_req
= NULL
;
8050 scan_res_handler
= scan_only_handler
;
8051 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8052 scan_res_handler
= NULL
;
8054 scan_res_handler
= wpa_s
->scan_res_handler
;
8056 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8057 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8058 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8059 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8060 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8061 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8062 wpa_s
->scan_id_count
= scan_id_count
;
8063 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8064 wpa_s
->scan_res_handler
= scan_res_handler
;
8065 os_free(wpa_s
->manual_scan_freqs
);
8066 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8067 manual_scan_freqs
= NULL
;
8069 wpa_s
->normal_scans
= 0;
8070 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8071 wpa_s
->after_wps
= 0;
8072 wpa_s
->known_wps_freq
= 0;
8073 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8074 if (wpa_s
->manual_scan_use_id
) {
8075 wpa_s
->manual_scan_id
++;
8076 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8077 wpa_s
->manual_scan_id
);
8078 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8079 wpa_s
->manual_scan_id
);
8081 } else if (wpa_s
->sched_scanning
) {
8082 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8083 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8084 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8085 wpa_s
->scan_id_count
= scan_id_count
;
8086 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8087 wpa_s
->scan_res_handler
= scan_res_handler
;
8088 os_free(wpa_s
->manual_scan_freqs
);
8089 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8090 manual_scan_freqs
= NULL
;
8092 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8093 wpa_supplicant_cancel_sched_scan(wpa_s
);
8094 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8095 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8096 if (wpa_s
->manual_scan_use_id
) {
8097 wpa_s
->manual_scan_id
++;
8098 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8099 wpa_s
->manual_scan_id
);
8100 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8101 wpa_s
->manual_scan_id
);
8104 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8105 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8109 os_free(manual_scan_freqs
);
8114 #ifdef CONFIG_TESTING_OPTIONS
8116 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8117 unsigned int freq
, const u8
*dst
,
8118 const u8
*src
, const u8
*bssid
,
8119 const u8
*data
, size_t data_len
,
8120 enum offchannel_send_action_result
8123 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8124 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8125 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8126 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8127 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8128 "NO_ACK" : "FAILED"));
8132 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8136 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8138 int freq
= 0, no_cck
= 0, wait_time
= 0;
8140 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8141 * <action=Action frame payload> */
8143 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8146 used
= hwaddr_aton2(pos
, da
);
8152 used
= hwaddr_aton2(pos
, bssid
);
8157 param
= os_strstr(pos
, " freq=");
8163 param
= os_strstr(pos
, " no_cck=");
8166 no_cck
= atoi(param
);
8169 param
= os_strstr(pos
, " wait_time=");
8172 wait_time
= atoi(param
);
8175 param
= os_strstr(pos
, " action=");
8180 len
= os_strlen(param
);
8185 buf
= os_malloc(len
);
8189 if (hexstr2bin(param
, buf
, len
) < 0) {
8194 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8195 buf
, len
, wait_time
,
8196 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8202 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8204 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8205 offchannel_send_action_done(wpa_s
);
8209 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8215 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8216 union wpa_event_data event
;
8218 if (!wpa_s
->ext_mgmt_frame_handling
)
8221 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8223 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8226 param
= os_strstr(pos
, "freq=");
8232 param
= os_strstr(pos
, " datarate=");
8235 datarate
= atoi(param
);
8238 param
= os_strstr(pos
, " ssi_signal=");
8241 ssi_signal
= atoi(param
);
8244 param
= os_strstr(pos
, " frame=");
8249 len
= os_strlen(param
);
8254 buf
= os_malloc(len
);
8258 if (hexstr2bin(param
, buf
, len
) < 0) {
8263 os_memset(&event
, 0, sizeof(event
));
8264 event
.rx_mgmt
.freq
= freq
;
8265 event
.rx_mgmt
.frame
= buf
;
8266 event
.rx_mgmt
.frame_len
= len
;
8267 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8268 event
.rx_mgmt
.datarate
= datarate
;
8269 wpa_s
->ext_mgmt_frame_handling
= 0;
8270 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8271 wpa_s
->ext_mgmt_frame_handling
= 1;
8279 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8282 struct wpa_scan_res
*res
;
8283 struct os_reltime now
;
8290 if (os_strcmp(param
, "START") == 0) {
8291 wpa_bss_update_start(wpa_s
);
8295 if (os_strcmp(param
, "END") == 0) {
8296 wpa_bss_update_end(wpa_s
, NULL
, 1);
8300 if (os_strncmp(param
, "BSS ", 4) != 0)
8304 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8308 pos
= os_strstr(param
, " flags=");
8310 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8312 pos
= os_strstr(param
, " bssid=");
8313 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8316 pos
= os_strstr(param
, " freq=");
8318 res
->freq
= atoi(pos
+ 6);
8320 pos
= os_strstr(param
, " beacon_int=");
8322 res
->beacon_int
= atoi(pos
+ 12);
8324 pos
= os_strstr(param
, " caps=");
8326 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8328 pos
= os_strstr(param
, " qual=");
8330 res
->qual
= atoi(pos
+ 6);
8332 pos
= os_strstr(param
, " noise=");
8334 res
->noise
= atoi(pos
+ 7);
8336 pos
= os_strstr(param
, " level=");
8338 res
->level
= atoi(pos
+ 7);
8340 pos
= os_strstr(param
, " tsf=");
8342 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8344 pos
= os_strstr(param
, " age=");
8346 res
->age
= atoi(pos
+ 5);
8348 pos
= os_strstr(param
, " est_throughput=");
8350 res
->est_throughput
= atoi(pos
+ 16);
8352 pos
= os_strstr(param
, " snr=");
8354 res
->snr
= atoi(pos
+ 5);
8356 pos
= os_strstr(param
, " parent_tsf=");
8358 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8360 pos
= os_strstr(param
, " tsf_bssid=");
8361 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8364 pos
= os_strstr(param
, " ie=");
8367 end
= os_strchr(pos
, ' ');
8369 end
= pos
+ os_strlen(pos
);
8370 res
->ie_len
= (end
- pos
) / 2;
8371 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8375 pos
= os_strstr(param
, " beacon_ie=");
8378 end
= os_strchr(pos
, ' ');
8380 end
= pos
+ os_strlen(pos
);
8381 res
->beacon_ie_len
= (end
- pos
) / 2;
8382 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8383 res
->beacon_ie_len
))
8387 os_get_reltime(&now
);
8388 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8397 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8400 union wpa_event_data event
;
8401 enum wpa_event_type ev
;
8403 /* <event name> [parameters..] */
8405 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8408 param
= os_strchr(pos
, ' ');
8412 os_memset(&event
, 0, sizeof(event
));
8414 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8415 ev
= EVENT_INTERFACE_ENABLED
;
8416 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8417 ev
= EVENT_INTERFACE_DISABLED
;
8418 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8419 ev
= EVENT_AVOID_FREQUENCIES
;
8422 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8424 wpa_supplicant_event(wpa_s
, ev
, &event
);
8425 os_free(event
.freq_range
.range
);
8427 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8428 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8430 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8435 wpa_supplicant_event(wpa_s
, ev
, &event
);
8441 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8444 u8 src
[ETH_ALEN
], *buf
;
8448 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8451 used
= hwaddr_aton2(pos
, src
);
8458 len
= os_strlen(pos
);
8463 buf
= os_malloc(len
);
8467 if (hexstr2bin(pos
, buf
, len
) < 0) {
8472 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8479 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8483 const u16
*pos
= buf
;
8485 for (i
= 0; i
< len
/ 2; i
++)
8489 sum
= (sum
& 0xffff) + (sum
>> 16);
8491 return sum
^ 0xffff;
8495 #define HWSIM_PACKETLEN 1500
8496 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8498 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8501 struct wpa_supplicant
*wpa_s
= ctx
;
8502 const struct ether_header
*eth
;
8507 if (len
!= HWSIM_PACKETLEN
)
8510 eth
= (const struct ether_header
*) buf
;
8511 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8512 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8514 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8515 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8518 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
8524 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
8525 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
8529 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8532 int enabled
= atoi(cmd
);
8537 if (wpa_s
->l2_test
) {
8538 l2_packet_deinit(wpa_s
->l2_test
);
8539 wpa_s
->l2_test
= NULL
;
8540 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8548 pos
= os_strstr(cmd
, " ifname=");
8552 ifname
= wpa_s
->ifname
;
8554 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8555 ETHERTYPE_IP
, wpas_data_test_rx
,
8557 if (wpa_s
->l2_test
== NULL
)
8560 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8566 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8568 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8573 u8 buf
[2 + HWSIM_PACKETLEN
];
8574 struct ether_header
*eth
;
8579 if (wpa_s
->l2_test
== NULL
)
8582 /* format: <dst> <src> <tos> */
8585 used
= hwaddr_aton2(pos
, dst
);
8591 used
= hwaddr_aton2(pos
, src
);
8596 val
= strtol(pos
, NULL
, 0);
8597 if (val
< 0 || val
> 0xff)
8601 eth
= (struct ether_header
*) &buf
[2];
8602 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8603 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8604 eth
->ether_type
= htons(ETHERTYPE_IP
);
8605 ip
= (struct iphdr
*) (eth
+ 1);
8606 os_memset(ip
, 0, sizeof(*ip
));
8611 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8613 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8614 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8615 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8616 dpos
= (u8
*) (ip
+ 1);
8617 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8620 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8621 HWSIM_PACKETLEN
) < 0)
8624 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8625 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8631 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8635 struct ether_header
*eth
;
8636 struct l2_packet_data
*l2
= NULL
;
8641 len
= os_strlen(cmd
);
8642 if (len
& 1 || len
< ETH_HLEN
* 2)
8646 buf
= os_malloc(len
);
8650 if (hexstr2bin(cmd
, buf
, len
) < 0)
8653 eth
= (struct ether_header
*) buf
;
8654 ethertype
= ntohs(eth
->ether_type
);
8656 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8657 wpas_data_test_rx
, wpa_s
, 1);
8661 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8662 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8665 l2_packet_deinit(l2
);
8668 return res
< 0 ? -1 : 0;
8672 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8674 #ifdef WPA_TRACE_BFD
8677 wpa_trace_fail_after
= atoi(cmd
);
8678 pos
= os_strchr(cmd
, ':');
8681 os_strlcpy(wpa_trace_fail_func
, pos
,
8682 sizeof(wpa_trace_fail_func
));
8684 wpa_trace_fail_after
= 0;
8687 #else /* WPA_TRACE_BFD */
8689 #endif /* WPA_TRACE_BFD */
8693 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8694 char *buf
, size_t buflen
)
8696 #ifdef WPA_TRACE_BFD
8697 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8698 wpa_trace_fail_func
);
8699 #else /* WPA_TRACE_BFD */
8701 #endif /* WPA_TRACE_BFD */
8705 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8707 #ifdef WPA_TRACE_BFD
8710 wpa_trace_test_fail_after
= atoi(cmd
);
8711 pos
= os_strchr(cmd
, ':');
8714 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8715 sizeof(wpa_trace_test_fail_func
));
8717 wpa_trace_test_fail_after
= 0;
8720 #else /* WPA_TRACE_BFD */
8722 #endif /* WPA_TRACE_BFD */
8726 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8727 char *buf
, size_t buflen
)
8729 #ifdef WPA_TRACE_BFD
8730 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8731 wpa_trace_test_fail_func
);
8732 #else /* WPA_TRACE_BFD */
8734 #endif /* WPA_TRACE_BFD */
8738 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8740 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8741 int i
, count
= (intptr_t) timeout_ctx
;
8743 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8745 for (i
= 0; i
< count
; i
++) {
8746 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8752 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8760 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8761 (void *) (intptr_t) count
);
8765 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8771 len
= os_strlen(cmd
);
8779 buf
= wpabuf_alloc(len
);
8783 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
8789 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
8793 #endif /* CONFIG_TESTING_OPTIONS */
8796 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
8802 struct ieee802_11_elems elems
;
8805 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8807 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8809 pos
= os_strchr(pos
, ' ');
8814 len
= os_strlen(pos
);
8821 buf
= wpabuf_alloc(len
);
8825 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
8830 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
8836 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
8837 wpa_s
->vendor_elem
[frame
] = buf
;
8838 wpas_vendor_elem_update(wpa_s
);
8842 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
8847 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
8849 wpas_vendor_elem_update(wpa_s
);
8855 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
8856 char *buf
, size_t buflen
)
8858 int frame
= atoi(cmd
);
8860 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8862 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8864 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8867 return wpa_snprintf_hex(buf
, buflen
,
8868 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
8869 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
8873 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
8879 struct ieee802_11_elems elems
;
8883 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8885 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8887 pos
= os_strchr(pos
, ' ');
8893 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
8894 wpa_s
->vendor_elem
[frame
] = NULL
;
8895 wpas_vendor_elem_update(wpa_s
);
8899 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8902 len
= os_strlen(pos
);
8909 buf
= os_malloc(len
);
8913 if (hexstr2bin(pos
, buf
, len
) < 0) {
8918 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
8923 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
8929 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
8931 struct wpa_supplicant
*wpa_s
= ctx
;
8936 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
8938 * BSSID Information[4]
8939 * Operating Class[1]
8942 * Optional Subelements[variable]
8944 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
8946 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
8947 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
8951 data
= wpabuf_head_u8(neighbor_rep
);
8952 len
= wpabuf_len(neighbor_rep
);
8954 while (len
>= 2 + NR_IE_MIN_LEN
) {
8956 char lci
[256 * 2 + 1];
8957 char civic
[256 * 2 + 1];
8958 u8 nr_len
= data
[1];
8959 const u8
*pos
= data
, *end
;
8961 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
8962 nr_len
< NR_IE_MIN_LEN
) {
8963 wpa_printf(MSG_DEBUG
,
8964 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
8969 if (2U + nr_len
> len
) {
8970 wpa_printf(MSG_DEBUG
,
8971 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
8972 data
[0], len
, nr_len
);
8979 pos
+= NR_IE_MIN_LEN
;
8983 while (end
- pos
> 2) {
8988 if (s_len
> end
- pos
)
8990 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
8991 /* Measurement Token[1] */
8992 /* Measurement Report Mode[1] */
8993 /* Measurement Type[1] */
8994 /* Measurement Report[variable] */
8996 case MEASURE_TYPE_LCI
:
8999 wpa_snprintf_hex(lci
, sizeof(lci
),
9002 case MEASURE_TYPE_LOCATION_CIVIC
:
9005 wpa_snprintf_hex(civic
, sizeof(civic
),
9014 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9016 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9017 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9018 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9020 lci
[0] ? " lci=" : "", lci
,
9021 civic
[0] ? " civic=" : "", civic
);
9028 wpabuf_free(neighbor_rep
);
9032 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9035 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9036 int ret
, lci
= 0, civic
= 0;
9039 ssid_s
= os_strstr(cmd
, "ssid=");
9041 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9042 wpa_printf(MSG_ERROR
,
9043 "CTRL: Send Neighbor Report: bad SSID");
9050 * Move cmd after the SSID text that may include "lci" or
9053 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9059 if (cmd
&& os_strstr(cmd
, "lci"))
9062 if (cmd
&& os_strstr(cmd
, "civic"))
9065 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9066 wpas_ctrl_neighbor_rep_cb
,
9073 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9075 eapol_sm_erp_flush(wpa_s
->eapol
);
9080 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9083 char *token
, *context
= NULL
;
9084 unsigned int enable
= ~0, type
= 0;
9085 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9086 u8
*addr
= NULL
, *mask
= NULL
;
9088 while ((token
= str_token(cmd
, " ", &context
))) {
9089 if (os_strcasecmp(token
, "scan") == 0) {
9090 type
|= MAC_ADDR_RAND_SCAN
;
9091 } else if (os_strcasecmp(token
, "sched") == 0) {
9092 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9093 } else if (os_strcasecmp(token
, "pno") == 0) {
9094 type
|= MAC_ADDR_RAND_PNO
;
9095 } else if (os_strcasecmp(token
, "all") == 0) {
9096 type
= wpa_s
->mac_addr_rand_supported
;
9097 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9098 enable
= atoi(token
+ 7);
9099 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9101 if (hwaddr_aton(token
+ 5, addr
)) {
9102 wpa_printf(MSG_INFO
,
9103 "CTRL: Invalid MAC address: %s",
9107 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9109 if (hwaddr_aton(token
+ 5, mask
)) {
9110 wpa_printf(MSG_INFO
,
9111 "CTRL: Invalid MAC address mask: %s",
9116 wpa_printf(MSG_INFO
,
9117 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9124 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9128 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
9129 wpa_printf(MSG_INFO
,
9130 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9131 type
, wpa_s
->mac_addr_rand_supported
);
9136 wpa_printf(MSG_INFO
,
9137 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9142 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
9144 if (type
& MAC_ADDR_RAND_PNO
) {
9145 wpas_stop_pno(wpa_s
);
9146 wpas_start_pno(wpa_s
);
9148 } else if (wpa_s
->sched_scanning
&&
9149 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
9150 wpas_scan_restart_sched_scan(wpa_s
);
9155 if ((addr
&& !mask
) || (!addr
&& mask
)) {
9156 wpa_printf(MSG_INFO
,
9157 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9161 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
9162 wpa_printf(MSG_INFO
,
9163 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9167 if (type
& MAC_ADDR_RAND_SCAN
) {
9168 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
9172 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
9173 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
9176 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
9177 wpas_scan_restart_sched_scan(wpa_s
);
9180 if (type
& MAC_ADDR_RAND_PNO
) {
9181 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
9184 wpas_stop_pno(wpa_s
);
9185 wpas_start_pno(wpa_s
);
9193 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9194 char *buf
, size_t buflen
)
9198 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9200 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9201 buflen
- reply_len
);
9202 #endif /* CONFIG_AP */
9207 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9209 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9211 wpas_ap_pmksa_cache_flush(wpa_s
);
9212 #endif /* CONFIG_AP */
9216 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9218 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9219 const char *cmd
, char *buf
, size_t buflen
)
9221 struct rsn_pmksa_cache_entry
*entry
;
9222 struct wpa_ssid
*ssid
;
9223 char *pos
, *pos2
, *end
;
9225 struct os_reltime now
;
9227 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9234 os_get_reltime(&now
);
9238 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9239 * <expiration in seconds> <akmp> <opportunistic>
9240 * [FILS Cache Identifier]
9243 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9244 entry
= entry
->next
) {
9245 if (entry
->network_ctx
!= ssid
)
9249 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9250 MAC2STR(entry
->aa
));
9251 if (os_snprintf_error(end
- pos2
, ret
))
9255 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9258 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9259 if (os_snprintf_error(end
- pos2
, ret
))
9263 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9266 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9267 (int) (entry
->reauth_time
- now
.sec
),
9268 (int) (entry
->expiration
- now
.sec
),
9270 entry
->opportunistic
);
9271 if (os_snprintf_error(end
- pos2
, ret
))
9275 if (entry
->fils_cache_id_set
) {
9276 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9277 entry
->fils_cache_id
[0],
9278 entry
->fils_cache_id
[1]);
9279 if (os_snprintf_error(end
- pos2
, ret
))
9284 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9285 if (os_snprintf_error(end
- pos2
, ret
))
9296 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9299 struct rsn_pmksa_cache_entry
*entry
;
9300 struct wpa_ssid
*ssid
;
9303 struct os_reltime now
;
9304 int reauth_time
= 0, expiration
= 0, i
;
9308 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9309 * <expiration in seconds> <akmp> <opportunistic>
9310 * [FILS Cache Identifier]
9313 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9317 pos
= os_strchr(cmd
, ' ');
9322 entry
= os_zalloc(sizeof(*entry
));
9326 if (hwaddr_aton(pos
, entry
->aa
))
9329 pos
= os_strchr(pos
, ' ');
9334 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9337 pos
= os_strchr(pos
, ' ');
9342 pos2
= os_strchr(pos
, ' ');
9345 entry
->pmk_len
= (pos2
- pos
) / 2;
9346 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9347 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9350 pos
= os_strchr(pos
, ' ');
9355 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9356 &entry
->akmp
, &entry
->opportunistic
) != 4)
9358 for (i
= 0; i
< 4; i
++) {
9359 pos
= os_strchr(pos
, ' ');
9368 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9369 FILS_CACHE_ID_LEN
) < 0)
9371 entry
->fils_cache_id_set
= 1;
9373 os_get_reltime(&now
);
9374 entry
->expiration
= now
.sec
+ expiration
;
9375 entry
->reauth_time
= now
.sec
+ reauth_time
;
9377 entry
->network_ctx
= ssid
;
9379 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9390 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9391 const char *cmd
, char *buf
,
9399 if (os_strcasecmp(cmd
, "any") == 0)
9400 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9402 if (hwaddr_aton(cmd
, spa
))
9405 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9409 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9413 * We do not check mesh interface existance because PMKSA should be
9414 * stored before wpa_s->ifmsh creation to suppress commit message
9417 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9420 #endif /* CONFIG_MESH */
9421 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9425 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9428 struct fils_hlp_req
*req
;
9431 /* format: <dst> <packet starting from ethertype> */
9433 req
= os_zalloc(sizeof(*req
));
9437 if (hwaddr_aton(cmd
, req
->dst
))
9440 pos
= os_strchr(cmd
, ' ');
9444 req
->pkt
= wpabuf_parse_bin(pos
);
9448 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9451 wpabuf_free(req
->pkt
);
9455 #endif /* CONFIG_FILS */
9458 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9460 if (os_strcmp(cmd
, "PING") == 0 ||
9461 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9462 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9463 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9464 os_strncmp(cmd
, "STA ", 4) == 0 ||
9465 os_strncmp(cmd
, "STA-", 4) == 0)
9466 return MSG_EXCESSIVE
;
9471 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9472 char *buf
, size_t *resp_len
)
9475 const int reply_size
= 4096;
9478 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9479 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9480 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9481 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9482 if (wpa_debug_show_keys
)
9483 wpa_dbg(wpa_s
, MSG_DEBUG
,
9484 "Control interface command '%s'", buf
);
9486 wpa_dbg(wpa_s
, MSG_DEBUG
,
9487 "Control interface command '%s [REMOVED]'",
9488 os_strncmp(buf
, WPA_CTRL_RSP
,
9489 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9491 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9492 "SET_NETWORK" : "key-add"));
9493 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9494 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9495 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9496 (const u8
*) buf
, os_strlen(buf
));
9498 int level
= wpas_ctrl_cmd_debug_level(buf
);
9499 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9502 reply
= os_malloc(reply_size
);
9503 if (reply
== NULL
) {
9508 os_memcpy(reply
, "OK\n", 3);
9511 if (os_strcmp(buf
, "PING") == 0) {
9512 os_memcpy(reply
, "PONG\n", 5);
9514 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9515 reply_len
= os_strlen(wpa_s
->ifname
);
9516 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9517 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9518 if (wpa_debug_reopen_file() < 0)
9520 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9521 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9522 } else if (os_strcmp(buf
, "MIB") == 0) {
9523 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9524 if (reply_len
>= 0) {
9525 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9527 reply_size
- reply_len
);
9529 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9530 reply_len
= wpa_supplicant_ctrl_iface_status(
9531 wpa_s
, buf
+ 6, reply
, reply_size
);
9532 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9533 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9534 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9535 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9536 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9537 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9538 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9540 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9541 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9544 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9545 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9547 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9548 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9550 #endif /* CONFIG_MESH */
9551 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9552 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9553 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9555 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9556 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9558 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9559 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9561 } else if (os_strcmp(buf
, "LOGON") == 0) {
9562 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9563 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9564 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9565 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9566 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9569 wpas_request_connection(wpa_s
);
9570 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9571 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9572 !wpa_s
->current_ssid
)
9575 wpa_s
->reattach
= 1;
9576 wpas_request_connection(wpa_s
);
9578 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9579 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9581 else if (wpa_s
->disconnected
)
9582 wpas_request_connection(wpa_s
);
9583 #ifdef IEEE8021X_EAPOL
9584 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9585 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9587 #endif /* IEEE8021X_EAPOL */
9588 #ifdef CONFIG_PEERKEY
9589 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
9590 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
9592 #endif /* CONFIG_PEERKEY */
9593 #ifdef CONFIG_IEEE80211R
9594 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9595 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9597 #endif /* CONFIG_IEEE80211R */
9599 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9600 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9602 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9606 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9607 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9609 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9613 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9614 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9617 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9618 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9619 wpa_s
, buf
+ 14, reply
, reply_size
);
9620 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9621 if (wpas_wps_cancel(wpa_s
))
9623 #ifdef CONFIG_WPS_NFC
9624 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
9625 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
9627 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
9628 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
9630 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9631 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9632 wpa_s
, buf
+ 21, reply
, reply_size
);
9633 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
9634 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
9635 wpa_s
, buf
+ 14, reply
, reply_size
);
9636 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
9637 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
9640 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9641 reply_len
= wpas_ctrl_nfc_get_handover_req(
9642 wpa_s
, buf
+ 21, reply
, reply_size
);
9643 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9644 reply_len
= wpas_ctrl_nfc_get_handover_sel(
9645 wpa_s
, buf
+ 21, reply
, reply_size
);
9646 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
9647 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
9649 #endif /* CONFIG_WPS_NFC */
9650 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
9651 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
9654 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
9655 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
9656 wpa_s
, buf
+ 11, reply
, reply_size
);
9657 #endif /* CONFIG_AP */
9658 #ifdef CONFIG_WPS_ER
9659 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
9660 if (wpas_wps_er_start(wpa_s
, NULL
))
9662 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
9663 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
9665 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
9666 wpas_wps_er_stop(wpa_s
);
9667 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
9668 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
9670 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
9671 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
9673 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9675 } else if (ret
== -3) {
9676 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
9678 } else if (ret
== -4) {
9679 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
9683 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
9684 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
9686 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
9687 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
9690 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
9691 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
9693 #ifdef CONFIG_WPS_NFC
9694 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9695 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9696 wpa_s
, buf
+ 24, reply
, reply_size
);
9697 #endif /* CONFIG_WPS_NFC */
9698 #endif /* CONFIG_WPS_ER */
9699 #endif /* CONFIG_WPS */
9700 #ifdef CONFIG_IBSS_RSN
9701 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
9702 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
9704 #endif /* CONFIG_IBSS_RSN */
9706 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
9707 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9708 wpa_s
, buf
+ 19, reply
, reply_size
);
9709 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
9710 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9711 wpa_s
, "", reply
, reply_size
);
9712 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
9713 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
9715 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
9716 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
9719 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
9720 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
9722 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
9723 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
9725 #endif /* CONFIG_MESH */
9727 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
9728 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
9730 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
9731 if (p2p_ctrl_find(wpa_s
, ""))
9733 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
9734 wpas_p2p_stop_find(wpa_s
);
9735 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
9736 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
9738 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
9739 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
9741 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
9742 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
9744 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
9745 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
9747 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
9748 if (p2p_ctrl_listen(wpa_s
, ""))
9750 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
9751 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
9753 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
9754 if (p2p_ctrl_group_add(wpa_s
, ""))
9756 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
9757 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
9759 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
9760 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
9762 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
9763 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
9765 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
9766 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
9767 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
9768 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
9770 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
9771 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
9773 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
9774 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
9776 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
9777 wpas_p2p_sd_service_update(wpa_s
);
9778 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
9779 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
9781 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
9782 wpas_p2p_service_flush(wpa_s
);
9783 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
9784 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
9786 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
9787 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
9789 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
9790 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
9792 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
9793 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
9795 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
9796 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
9798 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
9799 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
9801 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
9802 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
9804 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
9805 p2p_ctrl_flush(wpa_s
);
9806 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
9807 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
9809 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
9810 if (wpas_p2p_cancel(wpa_s
))
9812 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
9813 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
9815 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
9816 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
9818 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
9819 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
9821 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
9822 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
9824 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
9825 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
9827 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
9828 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
9830 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
9831 if (wpas_p2p_lo_stop(wpa_s
))
9833 #endif /* CONFIG_P2P */
9834 #ifdef CONFIG_WIFI_DISPLAY
9835 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
9836 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
9838 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
9839 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
9841 #endif /* CONFIG_WIFI_DISPLAY */
9842 #ifdef CONFIG_INTERWORKING
9843 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
9844 if (interworking_fetch_anqp(wpa_s
) < 0)
9846 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
9847 interworking_stop_fetch_anqp(wpa_s
);
9848 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
9849 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
9851 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
9852 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
9854 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
9855 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
9857 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9860 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
9864 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
9865 if (os_snprintf_error(reply_size
, reply_len
))
9868 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
9869 if (get_anqp(wpa_s
, buf
+ 9) < 0)
9871 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
9872 if (gas_request(wpa_s
, buf
+ 12) < 0)
9874 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
9875 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
9877 #endif /* CONFIG_INTERWORKING */
9879 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
9880 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
9882 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
9883 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
9885 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
9886 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
9888 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
9889 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
9891 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
9892 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
9893 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
9894 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
9896 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
9897 if (hs20_fetch_osu(wpa_s
, 0) < 0)
9899 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
9900 if (hs20_fetch_osu(wpa_s
, 1) < 0)
9902 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
9903 hs20_cancel_fetch_osu(wpa_s
);
9904 #endif /* CONFIG_HS20 */
9905 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
9907 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
9908 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
9912 * Notify response from timeout to allow the control
9913 * interface response to be sent first.
9915 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
9918 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
9919 if (wpa_supplicant_reload_configuration(wpa_s
))
9921 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
9922 wpa_supplicant_terminate_proc(wpa_s
->global
);
9923 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
9924 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
9926 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
9927 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
9928 wpa_s
, buf
+ 9, reply
, reply_size
);
9929 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
9930 reply_len
= wpa_supplicant_ctrl_iface_log_level(
9931 wpa_s
, buf
+ 9, reply
, reply_size
);
9932 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
9933 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9934 wpa_s
, buf
+ 14, reply
, reply_size
);
9935 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
9936 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9937 wpa_s
, NULL
, reply
, reply_size
);
9938 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
9939 wpas_request_disconnection(wpa_s
);
9940 } else if (os_strcmp(buf
, "SCAN") == 0) {
9941 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
9942 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
9943 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
9944 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
9945 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
9946 wpa_s
, reply
, reply_size
);
9947 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
9948 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
9950 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
9951 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
9953 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
9954 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
9956 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
9957 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
9959 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
9960 reply_len
= wpa_supplicant_ctrl_iface_add_network(
9961 wpa_s
, reply
, reply_size
);
9962 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
9963 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
9965 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
9966 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
9968 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
9969 reply_len
= wpa_supplicant_ctrl_iface_get_network(
9970 wpa_s
, buf
+ 12, reply
, reply_size
);
9971 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
9972 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
9975 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
9976 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
9977 wpa_s
, reply
, reply_size
);
9978 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
9979 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
9980 wpa_s
, reply
, reply_size
);
9981 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
9982 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
9984 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
9985 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
9987 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
9988 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
9991 #ifndef CONFIG_NO_CONFIG_WRITE
9992 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
9993 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
9995 #endif /* CONFIG_NO_CONFIG_WRITE */
9996 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
9997 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
9998 wpa_s
, buf
+ 15, reply
, reply_size
);
9999 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
10000 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
10002 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
10003 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10005 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10006 reply_len
= wpa_supplicant_global_iface_list(
10007 wpa_s
->global
, reply
, reply_size
);
10008 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10009 reply_len
= wpa_supplicant_global_iface_interfaces(
10010 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10011 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10012 reply_len
= wpa_supplicant_ctrl_iface_bss(
10013 wpa_s
, buf
+ 4, reply
, reply_size
);
10015 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10016 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10017 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10018 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10020 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10021 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10023 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10024 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10026 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10027 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10029 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10030 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10032 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10033 if (wpas_ap_stop_ap(wpa_s
))
10035 #endif /* CONFIG_AP */
10036 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10037 wpas_notify_suspend(wpa_s
->global
);
10038 } else if (os_strcmp(buf
, "RESUME") == 0) {
10039 wpas_notify_resume(wpa_s
->global
);
10040 #ifdef CONFIG_TESTING_OPTIONS
10041 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10042 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10043 #endif /* CONFIG_TESTING_OPTIONS */
10044 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10045 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10047 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10048 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10049 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10050 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10052 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10053 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10056 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10057 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10059 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10060 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10062 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10063 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10065 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10066 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10068 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10069 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10072 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10073 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10076 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10077 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10078 wpa_s
, buf
+ 17, reply
, reply_size
);
10079 #endif /* CONFIG_TDLS */
10080 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10081 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10082 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10083 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10085 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10086 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10088 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10089 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10091 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10092 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10094 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10095 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10097 #ifdef CONFIG_AUTOSCAN
10098 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10099 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10101 #endif /* CONFIG_AUTOSCAN */
10102 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10103 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10106 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10107 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10109 #endif /* ANDROID */
10110 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10111 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10113 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10114 pmksa_cache_clear_current(wpa_s
->wpa
);
10115 eapol_sm_request_reauth(wpa_s
->eapol
);
10117 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10118 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10120 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10121 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10123 #endif /* CONFIG_WNM */
10124 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10125 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10126 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10127 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10129 #ifdef CONFIG_TESTING_OPTIONS
10130 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10131 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10133 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10134 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10135 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10136 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10138 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10139 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10141 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10142 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10144 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10145 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10147 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10148 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10150 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10151 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10153 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10154 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10156 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10157 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10158 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10159 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10161 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10162 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10163 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10164 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10166 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10167 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10169 #endif /* CONFIG_TESTING_OPTIONS */
10170 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10171 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10173 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10174 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10176 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10177 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10179 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10180 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10182 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10183 wpas_ctrl_iface_erp_flush(wpa_s
);
10184 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10185 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10187 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10188 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10189 wpa_s
, buf
+ 19, reply
, reply_size
);
10191 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10192 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10194 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10195 wpas_flush_fils_hlp_req(wpa_s
);
10196 #endif /* CONFIG_FILS */
10198 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10201 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10205 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10206 if (os_snprintf_error(reply_size
, reply_len
))
10209 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10212 res
= wpas_dpp_bootstrap_gen(wpa_s
, buf
+ 18);
10216 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10217 if (os_snprintf_error(reply_size
, reply_len
))
10220 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10221 if (wpas_dpp_bootstrap_remove(wpa_s
, buf
+ 21) < 0)
10223 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10226 uri
= wpas_dpp_bootstrap_get_uri(wpa_s
, atoi(buf
+ 22));
10230 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10231 if (os_snprintf_error(reply_size
, reply_len
))
10234 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10235 reply_len
= wpas_dpp_bootstrap_info(wpa_s
, atoi(buf
+ 19),
10236 reply
, reply_size
);
10237 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10238 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10240 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10241 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10243 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10244 wpas_dpp_listen_stop(wpa_s
);
10245 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10248 res
= wpas_dpp_configurator_add(wpa_s
, buf
+ 20);
10252 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10253 if (os_snprintf_error(reply_size
, reply_len
))
10256 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10257 if (wpas_dpp_configurator_remove(wpa_s
, buf
+ 24) < 0)
10259 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
10260 if (wpas_dpp_configurator_sign(wpa_s
, buf
+ 22) < 0)
10262 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10265 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10269 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10270 if (os_snprintf_error(reply_size
, reply_len
))
10273 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10274 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10276 #endif /* CONFIG_DPP */
10278 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10282 if (reply_len
< 0) {
10283 os_memcpy(reply
, "FAIL\n", 5);
10287 *resp_len
= reply_len
;
10292 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10295 struct wpa_interface iface
;
10297 struct wpa_supplicant
*wpa_s
;
10298 unsigned int create_iface
= 0;
10299 u8 mac_addr
[ETH_ALEN
];
10300 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10303 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10304 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10306 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10308 os_memset(&iface
, 0, sizeof(iface
));
10311 iface
.ifname
= pos
= cmd
;
10312 pos
= os_strchr(pos
, '\t');
10315 if (iface
.ifname
[0] == '\0')
10320 iface
.confname
= pos
;
10321 pos
= os_strchr(pos
, '\t');
10324 if (iface
.confname
[0] == '\0')
10325 iface
.confname
= NULL
;
10329 iface
.driver
= pos
;
10330 pos
= os_strchr(pos
, '\t');
10333 if (iface
.driver
[0] == '\0')
10334 iface
.driver
= NULL
;
10338 iface
.ctrl_interface
= pos
;
10339 pos
= os_strchr(pos
, '\t');
10342 if (iface
.ctrl_interface
[0] == '\0')
10343 iface
.ctrl_interface
= NULL
;
10347 iface
.driver_param
= pos
;
10348 pos
= os_strchr(pos
, '\t');
10351 if (iface
.driver_param
[0] == '\0')
10352 iface
.driver_param
= NULL
;
10356 iface
.bridge_ifname
= pos
;
10357 pos
= os_strchr(pos
, '\t');
10360 if (iface
.bridge_ifname
[0] == '\0')
10361 iface
.bridge_ifname
= NULL
;
10366 pos
= os_strchr(pos
, '\t');
10372 if (os_strcmp(extra
, "create") == 0) {
10377 if (os_strcmp(pos
, "sta") == 0) {
10378 type
= WPA_IF_STATION
;
10379 } else if (os_strcmp(pos
, "ap") == 0) {
10380 type
= WPA_IF_AP_BSS
;
10382 wpa_printf(MSG_DEBUG
,
10383 "INTERFACE_ADD unsupported interface type: '%s'",
10388 wpa_printf(MSG_DEBUG
,
10389 "INTERFACE_ADD unsupported extra parameter: '%s'",
10395 if (create_iface
) {
10396 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10398 if (!global
->ifaces
)
10400 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10401 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10402 wpa_printf(MSG_ERROR
,
10403 "CTRL_IFACE interface creation failed");
10407 wpa_printf(MSG_DEBUG
,
10408 "CTRL_IFACE interface '%s' created with MAC addr: "
10409 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10412 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10415 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10418 wpa_s
->added_vif
= create_iface
;
10423 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10428 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10431 struct wpa_supplicant
*wpa_s
;
10433 unsigned int delete_iface
;
10435 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10437 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10440 delete_iface
= wpa_s
->added_vif
;
10441 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10442 if (!ret
&& delete_iface
) {
10443 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10445 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10451 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10453 struct wpa_interface_info
*prev
;
10457 iface
= iface
->next
;
10459 os_free(prev
->ifname
);
10460 os_free(prev
->desc
);
10466 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10467 char *buf
, int len
)
10470 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10473 for (i
= 0; wpa_drivers
[i
]; i
++) {
10474 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10475 if (drv
->get_interfaces
== NULL
)
10477 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10482 iface
= last
= tmp
;
10491 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10492 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10493 tmp
->drv_name
, tmp
->ifname
,
10494 tmp
->desc
? tmp
->desc
: "");
10495 if (os_snprintf_error(end
- pos
, res
)) {
10502 wpa_free_iface_info(iface
);
10508 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10510 char *buf
, int len
)
10514 struct wpa_supplicant
*wpa_s
;
10518 show_ctrl
= !!os_strstr(input
, "ctrl");
10520 wpa_s
= global
->ifaces
;
10526 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10528 wpa_s
->conf
->ctrl_interface
?
10529 wpa_s
->conf
->ctrl_interface
: "N/A");
10531 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10534 if (os_snprintf_error(end
- pos
, res
)) {
10539 wpa_s
= wpa_s
->next
;
10545 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10546 const char *ifname
,
10547 char *cmd
, size_t *resp_len
)
10549 struct wpa_supplicant
*wpa_s
;
10551 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10552 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10556 if (wpa_s
== NULL
) {
10557 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10559 *resp_len
= os_strlen(resp
);
10565 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10569 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10570 char *buf
, size_t *resp_len
)
10573 static const char * cmd
[] = {
10579 "P2P_GET_PASSPHRASE",
10580 "P2P_SERVICE_UPDATE",
10581 "P2P_SERVICE_FLUSH",
10584 "P2P_PRESENCE_REQ",
10588 #endif /* CONFIG_AP */
10591 static const char * prefix
[] = {
10594 #endif /* ANDROID */
10601 "P2P_GROUP_REMOVE ",
10603 "P2P_GROUP_MEMBER ",
10605 "P2P_SERV_DISC_REQ ",
10606 "P2P_SERV_DISC_CANCEL_REQ ",
10607 "P2P_SERV_DISC_RESP ",
10608 "P2P_SERV_DISC_EXTERNAL ",
10609 "P2P_SERVICE_ADD ",
10610 "P2P_SERVICE_DEL ",
10611 "P2P_SERVICE_REP ",
10616 "P2P_UNAUTHORIZE ",
10617 "P2P_PRESENCE_REQ ",
10619 "P2P_REMOVE_CLIENT ",
10621 "WPS_NFC_TAG_READ ",
10622 "NFC_GET_HANDOVER_SEL ",
10623 "NFC_GET_HANDOVER_REQ ",
10624 "NFC_REPORT_HANDOVER ",
10625 "P2P_ASP_PROVISION ",
10626 "P2P_ASP_PROVISION_RESP ",
10630 #endif /* CONFIG_AP */
10636 if (global
->p2p_init_wpa_s
== NULL
)
10639 for (i
= 0; !found
&& cmd
[i
]; i
++) {
10640 if (os_strcmp(buf
, cmd
[i
]) == 0)
10644 for (i
= 0; !found
&& prefix
[i
]; i
++) {
10645 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
10650 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10652 #endif /* CONFIG_P2P */
10657 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
10658 char *buf
, size_t *resp_len
)
10660 #ifdef CONFIG_WIFI_DISPLAY
10661 if (global
->p2p_init_wpa_s
== NULL
)
10663 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
10664 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
10665 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10667 #endif /* CONFIG_WIFI_DISPLAY */
10672 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
10673 char *buf
, size_t *resp_len
)
10677 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
10681 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
10689 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
10693 value
= os_strchr(cmd
, ' ');
10698 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
10700 #ifdef CONFIG_WIFI_DISPLAY
10701 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
10702 wifi_display_enable(global
, !!atoi(value
));
10705 #endif /* CONFIG_WIFI_DISPLAY */
10707 /* Restore cmd to its original value to allow redirection */
10714 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
10717 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
10721 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
10722 * <variable name> */
10724 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
10725 p
= os_strchr(cmd
, ' ');
10730 wpa_s
[i
] = global
->ifaces
;
10731 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
10732 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
10737 wpa_printf(MSG_DEBUG
,
10738 "CTRL_IFACE: Could not find iface=%s", cmd
);
10745 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
10749 #ifndef CONFIG_NO_CONFIG_WRITE
10750 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
10752 int ret
= 0, saved
= 0;
10753 struct wpa_supplicant
*wpa_s
;
10755 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10756 if (!wpa_s
->conf
->update_config
) {
10757 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
10761 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
10762 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
10765 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
10770 if (!saved
&& !ret
) {
10771 wpa_dbg(wpa_s
, MSG_DEBUG
,
10772 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
10778 #endif /* CONFIG_NO_CONFIG_WRITE */
10781 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
10782 char *buf
, size_t buflen
)
10786 struct wpa_supplicant
*wpa_s
;
10789 end
= buf
+ buflen
;
10792 if (global
->p2p
&& !global
->p2p_disabled
) {
10793 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
10796 MAC2STR(global
->p2p_dev_addr
),
10797 p2p_get_state_txt(global
->p2p
));
10798 if (os_snprintf_error(end
- pos
, ret
))
10801 } else if (global
->p2p
) {
10802 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
10803 if (os_snprintf_error(end
- pos
, ret
))
10807 #endif /* CONFIG_P2P */
10809 #ifdef CONFIG_WIFI_DISPLAY
10810 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
10811 !!global
->wifi_display
);
10812 if (os_snprintf_error(end
- pos
, ret
))
10815 #endif /* CONFIG_WIFI_DISPLAY */
10817 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10818 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
10819 "address=" MACSTR
"\n",
10820 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
10821 if (os_snprintf_error(end
- pos
, ret
))
10832 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
10833 char *cmd
, char *buf
,
10836 char ifname
[IFNAMSIZ
+ 1];
10837 struct fst_iface_cfg cfg
;
10838 struct wpa_supplicant
*wpa_s
;
10839 struct fst_wpa_obj iface_obj
;
10841 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
10842 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10845 wpa_printf(MSG_INFO
, "FST: Already attached");
10848 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
10849 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
10852 return os_snprintf(buf
, reply_size
, "OK\n");
10860 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
10861 char *cmd
, char *buf
,
10864 char ifname
[IFNAMSIZ
+ 1];
10865 struct wpa_supplicant
*wpa_s
;
10867 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
10868 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10870 if (!fst_iface_detach(ifname
)) {
10872 return os_snprintf(buf
, reply_size
, "OK\n");
10880 #endif /* CONFIG_FST */
10883 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
10884 char *buf
, size_t *resp_len
)
10887 const int reply_size
= 2048;
10889 int level
= MSG_DEBUG
;
10891 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
10892 char *pos
= os_strchr(buf
+ 7, ' ');
10895 return wpas_global_ctrl_iface_ifname(global
,
10901 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
10905 if (os_strcmp(buf
, "PING") == 0)
10906 level
= MSG_EXCESSIVE
;
10907 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
10908 (const u8
*) buf
, os_strlen(buf
));
10910 reply
= os_malloc(reply_size
);
10911 if (reply
== NULL
) {
10916 os_memcpy(reply
, "OK\n", 3);
10919 if (os_strcmp(buf
, "PING") == 0) {
10920 os_memcpy(reply
, "PONG\n", 5);
10922 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
10923 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
10925 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
10926 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
10928 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10929 reply_len
= wpa_supplicant_global_iface_list(
10930 global
, reply
, reply_size
);
10931 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10932 reply_len
= wpa_supplicant_global_iface_interfaces(
10933 global
, buf
+ 10, reply
, reply_size
);
10935 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
10936 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
10939 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
10940 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
10943 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
10944 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
10945 #endif /* CONFIG_FST */
10946 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10947 wpa_supplicant_terminate_proc(global
);
10948 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10949 wpas_notify_suspend(global
);
10950 } else if (os_strcmp(buf
, "RESUME") == 0) {
10951 wpas_notify_resume(global
);
10952 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10953 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
10955 if (global
->p2p_init_wpa_s
) {
10957 /* Check if P2P redirection would work for this
10959 return wpa_supplicant_ctrl_iface_process(
10960 global
->p2p_init_wpa_s
,
10963 #endif /* CONFIG_P2P */
10966 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10967 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
10969 #ifndef CONFIG_NO_CONFIG_WRITE
10970 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10971 if (wpas_global_ctrl_iface_save_config(global
))
10973 #endif /* CONFIG_NO_CONFIG_WRITE */
10974 } else if (os_strcmp(buf
, "STATUS") == 0) {
10975 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
10977 #ifdef CONFIG_MODULE_TESTS
10978 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
10979 if (wpas_module_tests() < 0)
10981 #endif /* CONFIG_MODULE_TESTS */
10982 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10983 if (wpa_debug_reopen_file() < 0)
10986 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10990 if (reply_len
< 0) {
10991 os_memcpy(reply
, "FAIL\n", 5);
10995 *resp_len
= reply_len
;