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
);
580 #ifdef CONFIG_TESTING_OPTIONS
581 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
582 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
583 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
584 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
586 if (wpa_s
->ap_iface
) {
587 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
588 wpa_s
->ext_eapol_frame_io
;
590 #endif /* CONFIG_AP */
591 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
592 wpa_s
->extra_roc_dur
= atoi(value
);
593 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
594 wpa_s
->test_failure
= atoi(value
);
595 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
596 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
597 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
598 wpa_s
->ignore_auth_resp
= !!atoi(value
);
599 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
600 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
601 wpa_drv_ignore_assoc_disallow(wpa_s
,
602 wpa_s
->ignore_assoc_disallow
);
603 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
604 wpa_s
->reject_btm_req_reason
= atoi(value
);
605 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
606 os_free(wpa_s
->get_pref_freq_list_override
);
608 wpa_s
->get_pref_freq_list_override
= NULL
;
610 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
612 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
613 os_free(wpa_s
->dpp_config_obj_override
);
614 wpa_s
->dpp_config_obj_override
= os_strdup(value
);
615 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
616 os_free(wpa_s
->dpp_discovery_override
);
617 wpa_s
->dpp_discovery_override
= os_strdup(value
);
618 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
619 os_free(wpa_s
->dpp_groups_override
);
620 wpa_s
->dpp_groups_override
= os_strdup(value
);
621 } else if (os_strcasecmp(cmd
, "dpp_devices_override") == 0) {
622 os_free(wpa_s
->dpp_devices_override
);
623 wpa_s
->dpp_devices_override
= os_strdup(value
);
624 } else if (os_strcasecmp(cmd
,
625 "dpp_ignore_netaccesskey_mismatch") == 0) {
626 wpa_s
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
627 #endif /* CONFIG_DPP */
628 #endif /* CONFIG_TESTING_OPTIONS */
629 #ifndef CONFIG_NO_CONFIG_BLOBS
630 } else if (os_strcmp(cmd
, "blob") == 0) {
631 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
632 #endif /* CONFIG_NO_CONFIG_BLOBS */
633 } else if (os_strcasecmp(cmd
, "setband") == 0) {
634 ret
= wpas_ctrl_set_band(wpa_s
, value
);
636 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
637 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
640 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
642 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
643 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
644 #endif /* CONFIG_MBO */
645 } else if (os_strcasecmp(cmd
, "lci") == 0) {
646 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
647 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
648 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
649 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
650 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
651 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
652 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
653 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
654 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
655 } else if (os_strcasecmp(cmd
, "roaming") == 0) {
656 ret
= wpa_drv_roaming(wpa_s
, atoi(value
), NULL
);
659 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
661 wpa_supplicant_update_config(wpa_s
);
668 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
669 char *cmd
, char *buf
, size_t buflen
)
673 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
675 if (os_strcmp(cmd
, "version") == 0) {
676 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
677 } else if (os_strcasecmp(cmd
, "country") == 0) {
678 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
679 res
= os_snprintf(buf
, buflen
, "%c%c",
680 wpa_s
->conf
->country
[0],
681 wpa_s
->conf
->country
[1]);
682 #ifdef CONFIG_WIFI_DISPLAY
683 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
685 if (wpa_s
->global
->p2p
== NULL
||
686 wpa_s
->global
->p2p_disabled
)
689 enabled
= wpa_s
->global
->wifi_display
;
690 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
691 #endif /* CONFIG_WIFI_DISPLAY */
692 #ifdef CONFIG_TESTING_GET_GTK
693 } else if (os_strcmp(cmd
, "gtk") == 0) {
694 if (wpa_s
->last_gtk_len
== 0)
696 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
697 wpa_s
->last_gtk_len
);
699 #endif /* CONFIG_TESTING_GET_GTK */
700 } else if (os_strcmp(cmd
, "tls_library") == 0) {
701 res
= tls_get_library_version(buf
, buflen
);
703 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
706 if (os_snprintf_error(buflen
, res
))
712 #ifdef IEEE8021X_EAPOL
713 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
717 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
719 if (hwaddr_aton(addr
, bssid
)) {
720 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
725 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
726 rsn_preauth_deinit(wpa_s
->wpa
);
727 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
732 #endif /* IEEE8021X_EAPOL */
735 #ifdef CONFIG_PEERKEY
736 /* MLME-STKSTART.request(peer) */
737 static int wpa_supplicant_ctrl_iface_stkstart(
738 struct wpa_supplicant
*wpa_s
, char *addr
)
742 if (hwaddr_aton(addr
, peer
)) {
743 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
744 "address '%s'", addr
);
748 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
751 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
753 #endif /* CONFIG_PEERKEY */
758 static int wpa_supplicant_ctrl_iface_tdls_discover(
759 struct wpa_supplicant
*wpa_s
, char *addr
)
764 if (hwaddr_aton(addr
, peer
)) {
765 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
766 "address '%s'", addr
);
770 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
773 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
774 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
776 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
782 static int wpa_supplicant_ctrl_iface_tdls_setup(
783 struct wpa_supplicant
*wpa_s
, char *addr
)
788 if (hwaddr_aton(addr
, peer
)) {
789 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
790 "address '%s'", addr
);
794 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
797 if ((wpa_s
->conf
->tdls_external_control
) &&
798 wpa_tdls_is_external_setup(wpa_s
->wpa
))
799 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
801 wpa_tdls_remove(wpa_s
->wpa
, peer
);
803 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
804 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
806 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
812 static int wpa_supplicant_ctrl_iface_tdls_teardown(
813 struct wpa_supplicant
*wpa_s
, char *addr
)
818 if (os_strcmp(addr
, "*") == 0) {
819 /* remove everyone */
820 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
821 wpa_tdls_teardown_peers(wpa_s
->wpa
);
825 if (hwaddr_aton(addr
, peer
)) {
826 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
827 "address '%s'", addr
);
831 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
834 if ((wpa_s
->conf
->tdls_external_control
) &&
835 wpa_tdls_is_external_setup(wpa_s
->wpa
))
836 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
838 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
839 ret
= wpa_tdls_teardown_link(
841 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
843 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
849 static int ctrl_iface_get_capability_tdls(
850 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
854 ret
= os_snprintf(buf
, buflen
, "%s\n",
855 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
857 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
858 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
859 if (os_snprintf_error(buflen
, ret
))
865 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
866 struct wpa_supplicant
*wpa_s
, char *cmd
)
869 struct hostapd_freq_params freq_params
;
873 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
875 "tdls_chanswitch: Only supported with external setup");
879 os_memset(&freq_params
, 0, sizeof(freq_params
));
881 pos
= os_strchr(cmd
, ' ');
886 oper_class
= strtol(pos
, &end
, 10);
889 "tdls_chanswitch: Invalid op class provided");
894 freq_params
.freq
= atoi(pos
);
895 if (freq_params
.freq
== 0) {
896 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
900 #define SET_FREQ_SETTING(str) \
902 const char *pos2 = os_strstr(pos, " " #str "="); \
904 pos2 += sizeof(" " #str "=") - 1; \
905 freq_params.str = atoi(pos2); \
909 SET_FREQ_SETTING(center_freq1
);
910 SET_FREQ_SETTING(center_freq2
);
911 SET_FREQ_SETTING(bandwidth
);
912 SET_FREQ_SETTING(sec_channel_offset
);
913 #undef SET_FREQ_SETTING
915 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
916 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
918 if (hwaddr_aton(cmd
, peer
)) {
919 wpa_printf(MSG_DEBUG
,
920 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
925 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
926 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
927 MAC2STR(peer
), oper_class
, freq_params
.freq
,
928 freq_params
.center_freq1
, freq_params
.center_freq2
,
929 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
930 freq_params
.ht_enabled
? " HT" : "",
931 freq_params
.vht_enabled
? " VHT" : "");
933 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
938 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
939 struct wpa_supplicant
*wpa_s
, char *cmd
)
943 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
945 "tdls_chanswitch: Only supported with external setup");
949 if (hwaddr_aton(cmd
, peer
)) {
950 wpa_printf(MSG_DEBUG
,
951 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
956 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
959 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
963 static int wpa_supplicant_ctrl_iface_tdls_link_status(
964 struct wpa_supplicant
*wpa_s
, const char *addr
,
965 char *buf
, size_t buflen
)
968 const char *tdls_status
;
971 if (hwaddr_aton(addr
, peer
)) {
972 wpa_printf(MSG_DEBUG
,
973 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
977 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
980 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
981 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
982 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
983 if (os_snprintf_error(buflen
, ret
))
989 #endif /* CONFIG_TDLS */
992 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
994 char *token
, *context
= NULL
;
995 struct wmm_ac_ts_setup_params params
= {
1000 while ((token
= str_token(cmd
, " ", &context
))) {
1001 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
1002 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
1003 sscanf(token
, "nominal_msdu_size=%i",
1004 ¶ms
.nominal_msdu_size
) == 1 ||
1005 sscanf(token
, "mean_data_rate=%i",
1006 ¶ms
.mean_data_rate
) == 1 ||
1007 sscanf(token
, "min_phy_rate=%i",
1008 ¶ms
.minimum_phy_rate
) == 1 ||
1009 sscanf(token
, "sba=%i",
1010 ¶ms
.surplus_bandwidth_allowance
) == 1)
1013 if (os_strcasecmp(token
, "downlink") == 0) {
1014 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
1015 } else if (os_strcasecmp(token
, "uplink") == 0) {
1016 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
1017 } else if (os_strcasecmp(token
, "bidi") == 0) {
1018 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
1019 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
1020 params
.fixed_nominal_msdu
= 1;
1022 wpa_printf(MSG_DEBUG
,
1023 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1030 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1034 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1036 u8 tsid
= atoi(cmd
);
1038 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1042 #ifdef CONFIG_IEEE80211R
1043 static int wpa_supplicant_ctrl_iface_ft_ds(
1044 struct wpa_supplicant
*wpa_s
, char *addr
)
1046 u8 target_ap
[ETH_ALEN
];
1047 struct wpa_bss
*bss
;
1050 if (hwaddr_aton(addr
, target_ap
)) {
1051 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1052 "address '%s'", addr
);
1056 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1058 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1060 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1064 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1066 #endif /* CONFIG_IEEE80211R */
1070 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1073 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1075 u8 p2p_dev_addr
[ETH_ALEN
];
1076 #endif /* CONFIG_P2P */
1078 u8
*_p2p_dev_addr
= NULL
;
1079 #endif /* CONFIG_AP */
1081 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
1084 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1085 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1086 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1087 "P2P Device Address '%s'",
1091 _p2p_dev_addr
= p2p_dev_addr
;
1092 #endif /* CONFIG_P2P */
1093 } else if (hwaddr_aton(cmd
, bssid
)) {
1094 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1100 if (wpa_s
->ap_iface
)
1101 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1102 #endif /* CONFIG_AP */
1104 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1108 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1109 char *cmd
, char *buf
,
1112 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1116 pin
= os_strchr(cmd
, ' ');
1120 if (os_strcmp(cmd
, "any") == 0)
1122 else if (os_strcmp(cmd
, "get") == 0) {
1123 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1126 } else if (hwaddr_aton(cmd
, bssid
)) {
1127 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1133 if (wpa_s
->ap_iface
) {
1138 pos
= os_strchr(pin
, ' ');
1141 timeout
= atoi(pos
);
1145 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1146 buf
, buflen
, timeout
);
1148 #endif /* CONFIG_AP */
1151 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1155 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1156 if (os_snprintf_error(buflen
, ret
))
1161 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1166 /* Return the generated PIN */
1167 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1168 if (os_snprintf_error(buflen
, ret
))
1174 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1175 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1182 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1183 (u8
*) cmd
, os_strlen(cmd
));
1184 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1185 if (*pos
< '0' || *pos
> '9')
1189 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1193 if (len
!= 4 && len
!= 8) {
1194 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1200 unsigned int pin_val
;
1201 pin_val
= atoi(pin
);
1202 if (!wps_pin_valid(pin_val
)) {
1203 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1204 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1205 if (os_snprintf_error(buflen
, ret
))
1211 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1212 if (os_snprintf_error(buflen
, ret
))
1219 #ifdef CONFIG_WPS_NFC
1221 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1224 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1226 if (cmd
== NULL
|| cmd
[0] == '\0')
1228 else if (hwaddr_aton(cmd
, bssid
))
1231 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1236 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1237 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1244 pos
= os_strchr(cmd
, ' ');
1247 if (os_strcmp(cmd
, "WPS") == 0)
1249 else if (os_strcmp(cmd
, "NDEF") == 0)
1254 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1258 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1260 reply
[res
++] = '\n';
1269 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1270 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1276 if (os_strcmp(cmd
, "WPS") == 0)
1278 else if (os_strcmp(cmd
, "NDEF") == 0)
1283 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1287 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1289 reply
[res
++] = '\n';
1298 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1299 struct wpa_supplicant
*wpa_s
, char *pos
)
1305 int forced_freq
= 0;
1307 freq
= strstr(pos
, " freq=");
1311 forced_freq
= atoi(freq
);
1314 len
= os_strlen(pos
);
1319 buf
= wpabuf_alloc(len
);
1322 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1327 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1334 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1335 char *reply
, size_t max_len
,
1341 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1345 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1347 reply
[res
++] = '\n';
1357 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1358 char *reply
, size_t max_len
,
1364 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1366 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1370 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1372 reply
[res
++] = '\n';
1379 #endif /* CONFIG_P2P */
1382 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1383 char *cmd
, char *reply
,
1389 pos
= os_strchr(cmd
, ' ');
1394 if (os_strcmp(cmd
, "WPS") == 0)
1396 else if (os_strcmp(cmd
, "NDEF") == 0)
1401 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1404 return wpas_ctrl_nfc_get_handover_req_wps(
1405 wpa_s
, reply
, max_len
, ndef
);
1409 if (os_strcmp(pos
, "P2P-CR") == 0) {
1410 return wpas_ctrl_nfc_get_handover_req_p2p(
1411 wpa_s
, reply
, max_len
, ndef
);
1413 #endif /* CONFIG_P2P */
1419 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1420 char *reply
, size_t max_len
,
1421 int ndef
, int cr
, char *uuid
)
1426 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1430 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1432 reply
[res
++] = '\n';
1442 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1443 char *reply
, size_t max_len
,
1449 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1453 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1455 reply
[res
++] = '\n';
1462 #endif /* CONFIG_P2P */
1465 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1466 char *cmd
, char *reply
,
1472 pos
= os_strchr(cmd
, ' ');
1477 if (os_strcmp(cmd
, "WPS") == 0)
1479 else if (os_strcmp(cmd
, "NDEF") == 0)
1484 pos2
= os_strchr(pos
, ' ');
1487 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1490 return wpas_ctrl_nfc_get_handover_sel_wps(
1491 wpa_s
, reply
, max_len
, ndef
,
1492 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1496 if (os_strcmp(pos
, "P2P-CR") == 0) {
1497 return wpas_ctrl_nfc_get_handover_sel_p2p(
1498 wpa_s
, reply
, max_len
, ndef
, 0);
1501 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1502 return wpas_ctrl_nfc_get_handover_sel_p2p(
1503 wpa_s
, reply
, max_len
, ndef
, 1);
1505 #endif /* CONFIG_P2P */
1511 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1515 struct wpabuf
*req
, *sel
;
1517 char *pos
, *role
, *type
, *pos2
;
1520 int forced_freq
= 0;
1522 freq
= strstr(cmd
, " freq=");
1526 forced_freq
= atoi(freq
);
1528 #endif /* CONFIG_P2P */
1531 pos
= os_strchr(role
, ' ');
1533 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1539 pos
= os_strchr(type
, ' ');
1541 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1546 pos2
= os_strchr(pos
, ' ');
1548 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1553 len
= os_strlen(pos
);
1555 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1560 req
= wpabuf_alloc(len
);
1562 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1565 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1566 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1571 len
= os_strlen(pos2
);
1573 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1579 sel
= wpabuf_alloc(len
);
1581 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1585 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1586 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1592 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1593 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1595 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1596 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1598 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1600 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1602 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1603 #endif /* CONFIG_AP */
1605 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1607 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1608 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1610 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1612 #endif /* CONFIG_P2P */
1614 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1615 "reported: role=%s type=%s", role
, type
);
1622 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1627 #endif /* CONFIG_WPS_NFC */
1630 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1639 struct wps_new_ap_settings ap
;
1641 pin
= os_strchr(cmd
, ' ');
1646 if (hwaddr_aton(cmd
, bssid
)) {
1647 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1652 new_ssid
= os_strchr(pin
, ' ');
1653 if (new_ssid
== NULL
)
1654 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1657 new_auth
= os_strchr(new_ssid
, ' ');
1658 if (new_auth
== NULL
)
1662 new_encr
= os_strchr(new_auth
, ' ');
1663 if (new_encr
== NULL
)
1667 new_key
= os_strchr(new_encr
, ' ');
1668 if (new_key
== NULL
)
1672 os_memset(&ap
, 0, sizeof(ap
));
1673 ap
.ssid_hex
= new_ssid
;
1676 ap
.key_hex
= new_key
;
1677 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1682 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1683 char *cmd
, char *buf
,
1688 const char *pin_txt
;
1690 if (!wpa_s
->ap_iface
)
1693 pos
= os_strchr(cmd
, ' ');
1697 if (os_strcmp(cmd
, "disable") == 0) {
1698 wpas_wps_ap_pin_disable(wpa_s
);
1699 return os_snprintf(buf
, buflen
, "OK\n");
1702 if (os_strcmp(cmd
, "random") == 0) {
1704 timeout
= atoi(pos
);
1705 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1706 if (pin_txt
== NULL
)
1708 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1711 if (os_strcmp(cmd
, "get") == 0) {
1712 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1713 if (pin_txt
== NULL
)
1715 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1718 if (os_strcmp(cmd
, "set") == 0) {
1723 pos
= os_strchr(pos
, ' ');
1726 timeout
= atoi(pos
);
1728 if (os_strlen(pin
) > buflen
)
1730 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1732 return os_snprintf(buf
, buflen
, "%s", pin
);
1737 #endif /* CONFIG_AP */
1740 #ifdef CONFIG_WPS_ER
1741 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1744 char *uuid
= cmd
, *pin
, *pos
;
1745 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1746 pin
= os_strchr(uuid
, ' ');
1750 pos
= os_strchr(pin
, ' ');
1753 if (hwaddr_aton(pos
, addr_buf
) == 0)
1756 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1760 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1763 char *uuid
= cmd
, *pin
;
1764 pin
= os_strchr(uuid
, ' ');
1768 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1772 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1773 struct wpa_supplicant
*wpa_s
, char *cmd
)
1775 char *uuid
= cmd
, *id
;
1776 id
= os_strchr(uuid
, ' ');
1780 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1784 static int wpa_supplicant_ctrl_iface_wps_er_config(
1785 struct wpa_supplicant
*wpa_s
, char *cmd
)
1792 struct wps_new_ap_settings ap
;
1794 pin
= os_strchr(cmd
, ' ');
1799 new_ssid
= os_strchr(pin
, ' ');
1800 if (new_ssid
== NULL
)
1804 new_auth
= os_strchr(new_ssid
, ' ');
1805 if (new_auth
== NULL
)
1809 new_encr
= os_strchr(new_auth
, ' ');
1810 if (new_encr
== NULL
)
1814 new_key
= os_strchr(new_encr
, ' ');
1815 if (new_key
== NULL
)
1819 os_memset(&ap
, 0, sizeof(ap
));
1820 ap
.ssid_hex
= new_ssid
;
1823 ap
.key_hex
= new_key
;
1824 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1828 #ifdef CONFIG_WPS_NFC
1829 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1830 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1837 uuid
= os_strchr(cmd
, ' ');
1842 if (os_strcmp(cmd
, "WPS") == 0)
1844 else if (os_strcmp(cmd
, "NDEF") == 0)
1849 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1853 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1855 reply
[res
++] = '\n';
1862 #endif /* CONFIG_WPS_NFC */
1863 #endif /* CONFIG_WPS_ER */
1865 #endif /* CONFIG_WPS */
1868 #ifdef CONFIG_IBSS_RSN
1869 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1870 struct wpa_supplicant
*wpa_s
, char *addr
)
1874 if (hwaddr_aton(addr
, peer
)) {
1875 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1876 "address '%s'", addr
);
1880 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1883 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1885 #endif /* CONFIG_IBSS_RSN */
1888 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1891 #ifdef IEEE8021X_EAPOL
1894 struct wpa_ssid
*ssid
;
1896 pos
= os_strchr(rsp
, '-');
1901 pos
= os_strchr(pos
, ':');
1906 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1907 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1908 (u8
*) pos
, os_strlen(pos
));
1910 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1912 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1917 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1919 #else /* IEEE8021X_EAPOL */
1920 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1922 #endif /* IEEE8021X_EAPOL */
1926 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1928 char *buf
, size_t buflen
)
1930 char *pos
, *end
, tmp
[30];
1931 int res
, verbose
, wps
, ret
;
1934 #endif /* CONFIG_HS20 */
1938 if (os_strcmp(params
, "-DRIVER") == 0)
1939 return wpa_drv_status(wpa_s
, buf
, buflen
);
1940 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1941 wps
= os_strcmp(params
, "-WPS") == 0;
1944 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1945 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1946 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1947 MAC2STR(wpa_s
->bssid
));
1948 if (os_snprintf_error(end
- pos
, ret
))
1951 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1953 if (os_snprintf_error(end
- pos
, ret
))
1957 u8
*_ssid
= ssid
->ssid
;
1958 size_t ssid_len
= ssid
->ssid_len
;
1959 u8 ssid_buf
[SSID_MAX_LEN
];
1960 if (ssid_len
== 0) {
1961 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1968 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1969 wpa_ssid_txt(_ssid
, ssid_len
),
1971 if (os_snprintf_error(end
- pos
, ret
))
1975 if (wps
&& ssid
->passphrase
&&
1976 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1977 (ssid
->mode
== WPAS_MODE_AP
||
1978 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1979 ret
= os_snprintf(pos
, end
- pos
,
1982 if (os_snprintf_error(end
- pos
, ret
))
1987 ret
= os_snprintf(pos
, end
- pos
,
1990 if (os_snprintf_error(end
- pos
, ret
))
1995 switch (ssid
->mode
) {
1996 case WPAS_MODE_INFRA
:
1997 ret
= os_snprintf(pos
, end
- pos
,
2000 case WPAS_MODE_IBSS
:
2001 ret
= os_snprintf(pos
, end
- pos
,
2005 ret
= os_snprintf(pos
, end
- pos
,
2008 case WPAS_MODE_P2P_GO
:
2009 ret
= os_snprintf(pos
, end
- pos
,
2012 case WPAS_MODE_P2P_GROUP_FORMATION
:
2013 ret
= os_snprintf(pos
, end
- pos
,
2014 "mode=P2P GO - group "
2017 case WPAS_MODE_MESH
:
2018 ret
= os_snprintf(pos
, end
- pos
,
2025 if (os_snprintf_error(end
- pos
, ret
))
2031 if (wpa_s
->ap_iface
) {
2032 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2036 #endif /* CONFIG_AP */
2037 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2041 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2044 #endif /* CONFIG_AP */
2045 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2046 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2047 wpa_s
->sme
.sae
.group
);
2048 if (os_snprintf_error(end
- pos
, ret
))
2052 #endif /* CONFIG_SAE */
2053 #endif /* CONFIG_SME */
2054 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2055 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2056 if (os_snprintf_error(end
- pos
, ret
))
2061 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2062 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2063 if (os_snprintf_error(end
- pos
, ret
))
2069 if (wpa_s
->global
->p2p
) {
2070 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2071 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2072 if (os_snprintf_error(end
- pos
, ret
))
2076 #endif /* CONFIG_P2P */
2078 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2079 MAC2STR(wpa_s
->own_addr
));
2080 if (os_snprintf_error(end
- pos
, ret
))
2085 if (wpa_s
->current_bss
&&
2086 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2087 HS20_IE_VENDOR_TYPE
)) &&
2088 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2089 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2092 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2093 release
= rel_num
+ 1;
2095 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2096 if (os_snprintf_error(end
- pos
, ret
))
2101 if (wpa_s
->current_ssid
) {
2102 struct wpa_cred
*cred
;
2105 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2108 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2111 if (cred
->provisioning_sp
) {
2112 ret
= os_snprintf(pos
, end
- pos
,
2113 "provisioning_sp=%s\n",
2114 cred
->provisioning_sp
);
2115 if (os_snprintf_error(end
- pos
, ret
))
2124 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2125 struct wpabuf
*names
=
2126 wpa_s
->current_bss
->anqp
->domain_name
;
2127 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2129 if (domain_name_list_contains(
2130 names
, cred
->domain
[i
], 1))
2133 if (i
== cred
->num_domain
)
2134 i
= 0; /* show first entry by default */
2136 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2138 if (os_snprintf_error(end
- pos
, ret
))
2143 if (wpa_s
->current_bss
== NULL
||
2144 wpa_s
->current_bss
->anqp
== NULL
)
2147 res
= interworking_home_sp_cred(
2149 wpa_s
->current_bss
->anqp
->domain_name
);
2157 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2158 if (os_snprintf_error(end
- pos
, ret
))
2165 #endif /* CONFIG_HS20 */
2167 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2168 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2169 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2175 #ifdef CONFIG_MACSEC
2176 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2179 #endif /* CONFIG_MACSEC */
2181 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2185 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2186 if (os_snprintf_error(end
- pos
, ret
))
2189 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2193 ret
= os_snprintf(pos
, end
- pos
, "\n");
2194 if (os_snprintf_error(end
- pos
, ret
))
2199 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2206 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2207 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2208 if (os_snprintf_error(end
- pos
, ret
))
2212 #endif /* CONFIG_WPS */
2216 * Allow using the STATUS command with default behavior, say for debug,
2217 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2218 * events with STATUS-NO_EVENTS.
2220 if (os_strcmp(params
, "-NO_EVENTS")) {
2221 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2222 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2223 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2225 MAC2STR(wpa_s
->bssid
),
2226 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2227 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2228 wpa_s
->current_ssid
->ssid_len
) : "");
2229 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2230 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2231 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2232 "- connection to " MACSTR
2233 " completed %s [id=%d id_str=%s]",
2234 MAC2STR(wpa_s
->bssid
), "(auth)",
2235 ssid
? ssid
->id
: -1,
2236 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2239 #endif /* ANDROID */
2245 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2250 struct wpa_ssid
*ssid
;
2253 /* cmd: "<network id> <BSSID>" */
2254 pos
= os_strchr(cmd
, ' ');
2259 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2260 if (hwaddr_aton(pos
, bssid
)) {
2261 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2265 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2267 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2272 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2273 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2279 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2280 char *cmd
, char *buf
,
2284 struct wpa_blacklist
*e
;
2288 /* cmd: "BLACKLIST [<BSSID>]" */
2292 e
= wpa_s
->blacklist
;
2294 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2296 if (os_snprintf_error(end
- pos
, ret
))
2305 if (os_strncmp(cmd
, "clear", 5) == 0) {
2306 wpa_blacklist_clear(wpa_s
);
2307 os_memcpy(buf
, "OK\n", 3);
2311 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2312 if (hwaddr_aton(cmd
, bssid
)) {
2313 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2318 * Add the BSSID twice, so its count will be 2, causing it to be
2319 * skipped when processing scan results.
2321 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2324 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2327 os_memcpy(buf
, "OK\n", 3);
2332 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2333 char *cmd
, char *buf
,
2336 char *pos
, *end
, *stamp
;
2339 /* cmd: "LOG_LEVEL [<level>]" */
2343 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2345 debug_level_str(wpa_debug_level
),
2346 wpa_debug_timestamp
);
2347 if (os_snprintf_error(end
- pos
, ret
))
2356 stamp
= os_strchr(cmd
, ' ');
2359 while (*stamp
== ' ') {
2364 if (os_strlen(cmd
)) {
2365 int level
= str_to_debug_level(cmd
);
2368 wpa_debug_level
= level
;
2371 if (stamp
&& os_strlen(stamp
))
2372 wpa_debug_timestamp
= atoi(stamp
);
2374 os_memcpy(buf
, "OK\n", 3);
2379 static int wpa_supplicant_ctrl_iface_list_networks(
2380 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2382 char *pos
, *end
, *prev
;
2383 struct wpa_ssid
*ssid
;
2388 ret
= os_snprintf(pos
, end
- pos
,
2389 "network id / ssid / bssid / flags\n");
2390 if (os_snprintf_error(end
- pos
, ret
))
2394 ssid
= wpa_s
->conf
->ssid
;
2396 /* skip over ssids until we find next one */
2397 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2398 int last_id
= atoi(cmd
+ 8);
2399 if (last_id
!= -1) {
2400 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2408 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2410 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2411 if (os_snprintf_error(end
- pos
, ret
))
2414 if (ssid
->bssid_set
) {
2415 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2416 MAC2STR(ssid
->bssid
));
2418 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2420 if (os_snprintf_error(end
- pos
, ret
))
2423 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2424 ssid
== wpa_s
->current_ssid
?
2426 ssid
->disabled
? "[DISABLED]" : "",
2427 ssid
->disabled_until
.sec
?
2428 "[TEMP-DISABLED]" : "",
2429 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2431 if (os_snprintf_error(end
- pos
, ret
))
2434 ret
= os_snprintf(pos
, end
- pos
, "\n");
2435 if (os_snprintf_error(end
- pos
, ret
))
2446 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2449 ret
= os_snprintf(pos
, end
- pos
, "-");
2450 if (os_snprintf_error(end
- pos
, ret
))
2453 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2461 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2462 const u8
*ie
, size_t ie_len
)
2464 struct wpa_ie_data data
;
2468 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2469 if (os_snprintf_error(end
- pos
, ret
))
2473 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2474 ret
= os_snprintf(pos
, end
- pos
, "?]");
2475 if (os_snprintf_error(end
- pos
, ret
))
2482 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2483 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2484 pos
== start
? "" : "+");
2485 if (os_snprintf_error(end
- pos
, ret
))
2489 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2490 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2491 pos
== start
? "" : "+");
2492 if (os_snprintf_error(end
- pos
, ret
))
2496 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2497 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2498 pos
== start
? "" : "+");
2499 if (os_snprintf_error(end
- pos
, ret
))
2503 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2504 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2505 pos
== start
? "" : "+");
2506 if (os_snprintf_error(end
- pos
, ret
))
2510 #ifdef CONFIG_IEEE80211R
2511 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2512 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2513 pos
== start
? "" : "+");
2514 if (os_snprintf_error(end
- pos
, ret
))
2518 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2519 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2520 pos
== start
? "" : "+");
2521 if (os_snprintf_error(end
- pos
, ret
))
2525 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2526 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2527 pos
== start
? "" : "+");
2528 if (os_snprintf_error(end
- pos
, ret
))
2532 #endif /* CONFIG_IEEE80211R */
2533 #ifdef CONFIG_IEEE80211W
2534 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2535 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2536 pos
== start
? "" : "+");
2537 if (os_snprintf_error(end
- pos
, ret
))
2541 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2542 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2543 pos
== start
? "" : "+");
2544 if (os_snprintf_error(end
- pos
, ret
))
2548 #endif /* CONFIG_IEEE80211W */
2550 #ifdef CONFIG_SUITEB
2551 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2552 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2553 pos
== start
? "" : "+");
2554 if (os_snprintf_error(end
- pos
, ret
))
2558 #endif /* CONFIG_SUITEB */
2560 #ifdef CONFIG_SUITEB192
2561 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2562 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2563 pos
== start
? "" : "+");
2564 if (os_snprintf_error(end
- pos
, ret
))
2568 #endif /* CONFIG_SUITEB192 */
2571 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2572 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2573 pos
== start
? "" : "+");
2574 if (os_snprintf_error(end
- pos
, ret
))
2578 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2579 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2580 pos
== start
? "" : "+");
2581 if (os_snprintf_error(end
- pos
, ret
))
2585 #ifdef CONFIG_IEEE80211R
2586 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2587 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2588 pos
== start
? "" : "+");
2589 if (os_snprintf_error(end
- pos
, ret
))
2593 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2594 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2595 pos
== start
? "" : "+");
2596 if (os_snprintf_error(end
- pos
, ret
))
2600 #endif /* CONFIG_IEEE80211R */
2601 #endif /* CONFIG_FILS */
2604 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2605 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2606 pos
== start
? "" : "+");
2607 if (os_snprintf_error(end
- pos
, ret
))
2611 #endif /* CONFIG_OWE */
2614 if (data
.key_mgmt
& WPA_KEY_MGMT_DPP
) {
2615 ret
= os_snprintf(pos
, end
- pos
, "%sDPP",
2616 pos
== start
? "" : "+");
2617 if (os_snprintf_error(end
- pos
, ret
))
2621 #endif /* CONFIG_DPP */
2623 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2624 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2625 pos
== start
? "" : "+");
2626 if (os_snprintf_error(end
- pos
, ret
))
2631 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2633 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2634 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2635 if (os_snprintf_error(end
- pos
, ret
))
2640 ret
= os_snprintf(pos
, end
- pos
, "]");
2641 if (os_snprintf_error(end
- pos
, ret
))
2650 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2651 char *pos
, char *end
,
2652 struct wpabuf
*wps_ie
)
2659 if (wps_is_selected_pbc_registrar(wps_ie
))
2661 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2663 else if (wps_is_selected_pin_registrar(wps_ie
))
2668 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2669 if (!os_snprintf_error(end
- pos
, ret
))
2671 wpabuf_free(wps_ie
);
2674 #endif /* CONFIG_WPS */
2677 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2678 char *pos
, char *end
,
2679 const struct wpa_bss
*bss
)
2682 struct wpabuf
*wps_ie
;
2683 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2684 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2685 #else /* CONFIG_WPS */
2687 #endif /* CONFIG_WPS */
2691 /* Format one result on one text line into a buffer. */
2692 static int wpa_supplicant_ctrl_iface_scan_result(
2693 struct wpa_supplicant
*wpa_s
,
2694 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2698 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
;
2700 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2701 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2703 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2704 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2705 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2707 return 0; /* Do not show P2P listen discovery results here */
2712 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2713 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2714 if (os_snprintf_error(end
- pos
, ret
))
2717 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2719 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2720 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2722 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2725 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2727 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2728 osen_ie
, 2 + osen_ie
[1]);
2729 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2730 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2731 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2732 if (os_snprintf_error(end
- pos
, ret
))
2737 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2738 if (os_snprintf_error(end
- pos
, ret
))
2742 if (bss_is_dmg(bss
)) {
2744 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2745 if (os_snprintf_error(end
- pos
, ret
))
2748 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2749 case IEEE80211_CAP_DMG_IBSS
:
2752 case IEEE80211_CAP_DMG_AP
:
2755 case IEEE80211_CAP_DMG_PBSS
:
2762 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2763 if (os_snprintf_error(end
- pos
, ret
))
2767 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2768 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2769 if (os_snprintf_error(end
- pos
, ret
))
2773 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2774 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2775 if (os_snprintf_error(end
- pos
, ret
))
2781 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2782 if (os_snprintf_error(end
- pos
, ret
))
2787 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2788 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2789 if (os_snprintf_error(end
- pos
, ret
))
2793 #endif /* CONFIG_HS20 */
2795 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2796 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2797 if (os_snprintf_error(end
- pos
, ret
))
2801 #endif /* CONFIG_FILS */
2803 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2804 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2805 if (os_snprintf_error(end
- pos
, ret
))
2809 #endif /* CONFIG_FST */
2811 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2812 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2813 if (os_snprintf_error(end
- pos
, ret
))
2817 ret
= os_snprintf(pos
, end
- pos
, "\n");
2818 if (os_snprintf_error(end
- pos
, ret
))
2826 static int wpa_supplicant_ctrl_iface_scan_results(
2827 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2830 struct wpa_bss
*bss
;
2835 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2837 if (os_snprintf_error(end
- pos
, ret
))
2841 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2842 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2844 if (ret
< 0 || ret
>= end
- pos
)
2855 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2856 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2858 char *pos
, ifname
[IFNAMSIZ
+ 1];
2862 pos
= os_strstr(cmd
, "ifname=");
2865 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2868 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2871 os_strlcpy(reply
, ifname
, max_len
);
2872 return os_strlen(ifname
);
2876 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2877 struct wpa_supplicant
*wpa_s
, char *cmd
)
2880 struct wpa_ssid
*ssid
;
2883 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2885 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2887 wpa_printf(MSG_DEBUG
,
2888 "CTRL_IFACE: Could not find network id=%d", id
);
2891 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2892 wpa_printf(MSG_DEBUG
,
2893 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2896 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2897 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2898 wpa_printf(MSG_ERROR
,
2899 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2904 * TODO: If necessary write our own group_add function,
2905 * for now we can reuse select_network
2907 wpa_supplicant_select_network(wpa_s
, ssid
);
2913 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2914 struct wpa_supplicant
*wpa_s
, char *cmd
)
2916 struct wpa_supplicant
*orig
;
2917 struct wpa_global
*global
;
2920 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2922 global
= wpa_s
->global
;
2925 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2926 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2932 wpa_printf(MSG_ERROR
,
2933 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2937 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2938 wpa_printf(MSG_ERROR
,
2939 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2943 wpa_s
->reassociate
= 0;
2944 wpa_s
->disconnected
= 1;
2945 wpa_supplicant_cancel_sched_scan(wpa_s
);
2946 wpa_supplicant_cancel_scan(wpa_s
);
2949 * TODO: If necessary write our own group_remove function,
2950 * for now we can reuse deauthenticate
2952 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2954 if (wpa_s
->mesh_if_created
)
2955 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
2961 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
2962 struct wpa_supplicant
*wpa_s
, char *cmd
)
2966 if (hwaddr_aton(cmd
, addr
) < 0)
2969 return wpas_mesh_peer_remove(wpa_s
, addr
);
2973 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
2974 struct wpa_supplicant
*wpa_s
, char *cmd
)
2980 pos
= os_strstr(cmd
, " duration=");
2983 duration
= atoi(pos
+ 10);
2988 if (hwaddr_aton(cmd
, addr
))
2991 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
2994 #endif /* CONFIG_MESH */
2997 static int wpa_supplicant_ctrl_iface_select_network(
2998 struct wpa_supplicant
*wpa_s
, char *cmd
)
3001 struct wpa_ssid
*ssid
;
3004 /* cmd: "<network id>" or "any" */
3005 if (os_strncmp(cmd
, "any", 3) == 0) {
3006 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
3010 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
3012 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3014 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3015 "network id=%d", id
);
3018 if (ssid
->disabled
== 2) {
3019 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3020 "SELECT_NETWORK with persistent P2P group");
3025 pos
= os_strstr(cmd
, " freq=");
3027 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
3029 os_free(wpa_s
->select_network_scan_freqs
);
3030 wpa_s
->select_network_scan_freqs
= freqs
;
3034 wpa_s
->scan_min_time
.sec
= 0;
3035 wpa_s
->scan_min_time
.usec
= 0;
3036 wpa_supplicant_select_network(wpa_s
, ssid
);
3042 static int wpa_supplicant_ctrl_iface_enable_network(
3043 struct wpa_supplicant
*wpa_s
, char *cmd
)
3046 struct wpa_ssid
*ssid
;
3048 /* cmd: "<network id>" or "all" */
3049 if (os_strcmp(cmd
, "all") == 0) {
3050 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3054 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3056 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3058 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3059 "network id=%d", id
);
3062 if (ssid
->disabled
== 2) {
3063 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3064 "ENABLE_NETWORK with persistent P2P group");
3068 if (os_strstr(cmd
, " no-connect")) {
3073 wpa_s
->scan_min_time
.sec
= 0;
3074 wpa_s
->scan_min_time
.usec
= 0;
3075 wpa_supplicant_enable_network(wpa_s
, ssid
);
3081 static int wpa_supplicant_ctrl_iface_disable_network(
3082 struct wpa_supplicant
*wpa_s
, char *cmd
)
3085 struct wpa_ssid
*ssid
;
3087 /* cmd: "<network id>" or "all" */
3088 if (os_strcmp(cmd
, "all") == 0) {
3089 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3093 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3095 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3097 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3098 "network id=%d", id
);
3101 if (ssid
->disabled
== 2) {
3102 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3103 "DISABLE_NETWORK with persistent P2P "
3108 wpa_supplicant_disable_network(wpa_s
, ssid
);
3114 static int wpa_supplicant_ctrl_iface_add_network(
3115 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3117 struct wpa_ssid
*ssid
;
3120 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3122 ssid
= wpa_supplicant_add_network(wpa_s
);
3126 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3127 if (os_snprintf_error(buflen
, ret
))
3133 static int wpa_supplicant_ctrl_iface_remove_network(
3134 struct wpa_supplicant
*wpa_s
, char *cmd
)
3137 struct wpa_ssid
*ssid
;
3140 /* cmd: "<network id>" or "all" */
3141 if (os_strcmp(cmd
, "all") == 0) {
3142 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3143 if (wpa_s
->sched_scanning
)
3144 wpa_supplicant_cancel_sched_scan(wpa_s
);
3146 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3147 if (wpa_s
->current_ssid
) {
3149 wpa_s
->sme
.prev_bssid_set
= 0;
3150 #endif /* CONFIG_SME */
3151 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3152 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3153 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3154 wpa_s
->own_disconnect_req
= 1;
3155 wpa_supplicant_deauthenticate(
3156 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3158 ssid
= wpa_s
->conf
->ssid
;
3160 struct wpa_ssid
*remove_ssid
= ssid
;
3163 if (wpa_s
->last_ssid
== remove_ssid
)
3164 wpa_s
->last_ssid
= NULL
;
3165 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3166 wpa_config_remove_network(wpa_s
->conf
, id
);
3172 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3174 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3176 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3181 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3182 "network id=%d", id
);
3189 static int wpa_supplicant_ctrl_iface_update_network(
3190 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3191 char *name
, char *value
)
3195 ret
= wpa_config_set(ssid
, name
, value
, 0);
3197 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3198 "variable '%s'", name
);
3202 return 0; /* No change to the previously configured value */
3204 if (os_strcmp(name
, "bssid") != 0 &&
3205 os_strcmp(name
, "bssid_hint") != 0 &&
3206 os_strcmp(name
, "priority") != 0) {
3207 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3209 if (wpa_s
->current_ssid
== ssid
||
3210 wpa_s
->current_ssid
== NULL
) {
3212 * Invalidate the EAP session cache if anything in the
3213 * current or previously used configuration changes.
3215 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3219 if ((os_strcmp(name
, "psk") == 0 &&
3220 value
[0] == '"' && ssid
->ssid_len
) ||
3221 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3222 wpa_config_update_psk(ssid
);
3223 else if (os_strcmp(name
, "priority") == 0)
3224 wpa_config_update_prio_list(wpa_s
->conf
);
3230 static int wpa_supplicant_ctrl_iface_set_network(
3231 struct wpa_supplicant
*wpa_s
, char *cmd
)
3233 int id
, ret
, prev_bssid_set
, prev_disabled
;
3234 struct wpa_ssid
*ssid
;
3236 u8 prev_bssid
[ETH_ALEN
];
3238 /* cmd: "<network id> <variable name> <value>" */
3239 name
= os_strchr(cmd
, ' ');
3244 value
= os_strchr(name
, ' ');
3250 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3252 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3253 (u8
*) value
, os_strlen(value
));
3255 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3257 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3262 prev_bssid_set
= ssid
->bssid_set
;
3263 prev_disabled
= ssid
->disabled
;
3264 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3265 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3268 (ssid
->bssid_set
!= prev_bssid_set
||
3269 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3270 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3272 if (prev_disabled
!= ssid
->disabled
&&
3273 (prev_disabled
== 2 || ssid
->disabled
== 2))
3274 wpas_notify_network_type_changed(wpa_s
, ssid
);
3280 static int wpa_supplicant_ctrl_iface_get_network(
3281 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3285 struct wpa_ssid
*ssid
;
3288 /* cmd: "<network id> <variable name>" */
3289 name
= os_strchr(cmd
, ' ');
3290 if (name
== NULL
|| buflen
== 0)
3295 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3298 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3300 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3305 value
= wpa_config_get_no_key(ssid
, name
);
3306 if (value
== NULL
) {
3307 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3308 "variable '%s'", name
);
3312 res
= os_strlcpy(buf
, value
, buflen
);
3313 if (res
>= buflen
) {
3324 static int wpa_supplicant_ctrl_iface_dup_network(
3325 struct wpa_supplicant
*wpa_s
, char *cmd
,
3326 struct wpa_supplicant
*dst_wpa_s
)
3328 struct wpa_ssid
*ssid_s
, *ssid_d
;
3329 char *name
, *id
, *value
;
3330 int id_s
, id_d
, ret
;
3332 /* cmd: "<src network id> <dst network id> <variable name>" */
3333 id
= os_strchr(cmd
, ' ');
3338 name
= os_strchr(id
, ' ');
3346 wpa_printf(MSG_DEBUG
,
3347 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3348 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3350 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3351 if (ssid_s
== NULL
) {
3352 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3353 "network id=%d", id_s
);
3357 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3358 if (ssid_d
== NULL
) {
3359 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3360 "network id=%d", id_d
);
3364 value
= wpa_config_get(ssid_s
, name
);
3365 if (value
== NULL
) {
3366 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3367 "variable '%s'", name
);
3371 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3380 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3381 char *buf
, size_t buflen
)
3384 struct wpa_cred
*cred
;
3389 ret
= os_snprintf(pos
, end
- pos
,
3390 "cred id / realm / username / domain / imsi\n");
3391 if (os_snprintf_error(end
- pos
, ret
))
3395 cred
= wpa_s
->conf
->cred
;
3397 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3398 cred
->id
, cred
->realm
? cred
->realm
: "",
3399 cred
->username
? cred
->username
: "",
3400 cred
->domain
? cred
->domain
[0] : "",
3401 cred
->imsi
? cred
->imsi
: "");
3402 if (os_snprintf_error(end
- pos
, ret
))
3413 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3414 char *buf
, size_t buflen
)
3416 struct wpa_cred
*cred
;
3419 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3421 cred
= wpa_config_add_cred(wpa_s
->conf
);
3425 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3427 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3428 if (os_snprintf_error(buflen
, ret
))
3434 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3435 struct wpa_cred
*cred
)
3437 struct wpa_ssid
*ssid
;
3442 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3447 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3448 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3452 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3454 /* Remove any network entry created based on the removed credential */
3455 ssid
= wpa_s
->conf
->ssid
;
3457 if (ssid
->parent_cred
== cred
) {
3460 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3461 "used the removed credential", ssid
->id
);
3462 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3463 if (os_snprintf_error(sizeof(str
), res
))
3464 str
[sizeof(str
) - 1] = '\0';
3466 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3475 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3479 struct wpa_cred
*cred
, *prev
;
3481 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3482 * "provisioning_sp=<FQDN> */
3483 if (os_strcmp(cmd
, "all") == 0) {
3484 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3485 cred
= wpa_s
->conf
->cred
;
3489 wpas_ctrl_remove_cred(wpa_s
, prev
);
3494 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3495 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3497 cred
= wpa_s
->conf
->cred
;
3503 for (i
= 0; i
< prev
->num_domain
; i
++) {
3504 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3507 wpas_ctrl_remove_cred(wpa_s
, prev
);
3515 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3516 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3518 cred
= wpa_s
->conf
->cred
;
3522 if (prev
->provisioning_sp
&&
3523 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3524 wpas_ctrl_remove_cred(wpa_s
, prev
);
3530 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3532 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3533 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3537 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3541 struct wpa_cred
*cred
;
3544 /* cmd: "<cred id> <variable name> <value>" */
3545 name
= os_strchr(cmd
, ' ');
3550 value
= os_strchr(name
, ' ');
3556 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3558 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3559 (u8
*) value
, os_strlen(value
));
3561 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3563 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3568 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3569 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3570 "variable '%s'", name
);
3574 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3580 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3581 char *cmd
, char *buf
,
3586 struct wpa_cred
*cred
;
3589 /* cmd: "<cred id> <variable name>" */
3590 name
= os_strchr(cmd
, ' ');
3596 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3599 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3601 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3606 value
= wpa_config_get_cred_no_key(cred
, name
);
3607 if (value
== NULL
) {
3608 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3613 res
= os_strlcpy(buf
, value
, buflen
);
3614 if (res
>= buflen
) {
3625 #ifndef CONFIG_NO_CONFIG_WRITE
3626 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3630 if (!wpa_s
->conf
->update_config
) {
3631 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3632 "to update configuration (update_config=0)");
3636 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3638 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3639 "update configuration");
3641 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3647 #endif /* CONFIG_NO_CONFIG_WRITE */
3650 struct cipher_info
{
3656 static const struct cipher_info ciphers
[] = {
3657 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3658 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3659 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3660 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3661 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3662 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3663 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3664 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3667 static const struct cipher_info ciphers_group_mgmt
[] = {
3668 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3669 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3670 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3671 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3675 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3676 struct wpa_driver_capa
*capa
,
3677 char *buf
, size_t buflen
)
3690 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3696 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3697 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3698 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3699 pos
== buf
? "" : " ",
3701 if (os_snprintf_error(end
- pos
, ret
))
3711 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3712 struct wpa_driver_capa
*capa
,
3713 char *buf
, size_t buflen
)
3726 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3732 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3733 if (capa
->enc
& ciphers
[i
].capa
) {
3734 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3735 pos
== buf
? "" : " ",
3737 if (os_snprintf_error(end
- pos
, ret
))
3747 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3748 struct wpa_driver_capa
*capa
,
3749 char *buf
, size_t buflen
)
3761 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3762 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3763 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3764 pos
== buf
? "" : " ",
3765 ciphers_group_mgmt
[i
].name
);
3766 if (os_snprintf_error(end
- pos
, ret
))
3776 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3777 struct wpa_driver_capa
*capa
,
3778 char *buf
, size_t buflen
)
3790 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3797 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3798 if (os_snprintf_error(end
- pos
, ret
))
3802 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3803 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3804 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3805 if (os_snprintf_error(end
- pos
, ret
))
3810 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3811 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3812 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3813 if (os_snprintf_error(end
- pos
, ret
))
3818 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3819 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3820 if (os_snprintf_error(end
- pos
, ret
))
3825 #ifdef CONFIG_SUITEB
3826 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3827 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3828 if (os_snprintf_error(end
- pos
, ret
))
3832 #endif /* CONFIG_SUITEB */
3833 #ifdef CONFIG_SUITEB192
3834 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3835 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3836 if (os_snprintf_error(end
- pos
, ret
))
3840 #endif /* CONFIG_SUITEB192 */
3842 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
3843 ret
= os_snprintf(pos
, end
- pos
, " OWE");
3844 if (os_snprintf_error(end
- pos
, ret
))
3848 #endif /* CONFIG_OWE */
3850 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_DPP
) {
3851 ret
= os_snprintf(pos
, end
- pos
, " DPP");
3852 if (os_snprintf_error(end
- pos
, ret
))
3856 #endif /* CONFIG_DPP */
3862 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3863 struct wpa_driver_capa
*capa
,
3864 char *buf
, size_t buflen
)
3876 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3882 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3883 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3884 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3885 pos
== buf
? "" : " ");
3886 if (os_snprintf_error(end
- pos
, ret
))
3891 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3892 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3893 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3894 pos
== buf
? "" : " ");
3895 if (os_snprintf_error(end
- pos
, ret
))
3904 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
3905 int res
, char *strict
,
3906 struct wpa_driver_capa
*capa
,
3907 char *buf
, size_t buflen
)
3919 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3925 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3926 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3927 pos
== buf
? "" : " ");
3928 if (os_snprintf_error(end
- pos
, ret
))
3933 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3934 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3935 pos
== buf
? "" : " ");
3936 if (os_snprintf_error(end
- pos
, ret
))
3941 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3942 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3943 pos
== buf
? "" : " ");
3944 if (os_snprintf_error(end
- pos
, ret
))
3950 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
3951 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
3952 pos
== buf
? "" : " ");
3953 if (os_snprintf_error(end
- pos
, ret
))
3957 #endif /* CONFIG_SAE */
3963 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3964 struct wpa_driver_capa
*capa
,
3965 char *buf
, size_t buflen
)
3977 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3983 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3984 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3985 pos
== buf
? "" : " ");
3986 if (os_snprintf_error(end
- pos
, ret
))
3991 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3992 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3993 pos
== buf
? "" : " ");
3994 if (os_snprintf_error(end
- pos
, ret
))
4000 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
4001 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
4002 pos
== buf
? "" : " ");
4003 if (os_snprintf_error(end
- pos
, ret
))
4007 #endif /* CONFIG_MESH */
4013 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
4014 char *buf
, size_t buflen
)
4016 struct hostapd_channel_data
*chnl
;
4018 char *pos
, *end
, *hmode
;
4023 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4024 switch (wpa_s
->hw
.modes
[j
].mode
) {
4025 case HOSTAPD_MODE_IEEE80211B
:
4028 case HOSTAPD_MODE_IEEE80211G
:
4031 case HOSTAPD_MODE_IEEE80211A
:
4034 case HOSTAPD_MODE_IEEE80211AD
:
4040 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4041 if (os_snprintf_error(end
- pos
, ret
))
4044 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4045 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4046 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4048 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4049 if (os_snprintf_error(end
- pos
, ret
))
4053 ret
= os_snprintf(pos
, end
- pos
, "\n");
4054 if (os_snprintf_error(end
- pos
, ret
))
4063 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4064 char *buf
, size_t buflen
)
4066 struct hostapd_channel_data
*chnl
;
4068 char *pos
, *end
, *hmode
;
4073 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4074 switch (wpa_s
->hw
.modes
[j
].mode
) {
4075 case HOSTAPD_MODE_IEEE80211B
:
4078 case HOSTAPD_MODE_IEEE80211G
:
4081 case HOSTAPD_MODE_IEEE80211A
:
4084 case HOSTAPD_MODE_IEEE80211AD
:
4090 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4092 if (os_snprintf_error(end
- pos
, ret
))
4095 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4096 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4097 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4099 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4100 chnl
[i
].chan
, chnl
[i
].freq
,
4101 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4103 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4106 if (os_snprintf_error(end
- pos
, ret
))
4110 ret
= os_snprintf(pos
, end
- pos
, "\n");
4111 if (os_snprintf_error(end
- pos
, ret
))
4120 static int wpa_supplicant_ctrl_iface_get_capability(
4121 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4124 struct wpa_driver_capa capa
;
4130 /* Determine whether or not strict checking was requested */
4131 len
= os_strlcpy(field
, _field
, sizeof(field
));
4132 if (len
>= sizeof(field
))
4134 strict
= os_strchr(field
, ' ');
4135 if (strict
!= NULL
) {
4137 if (os_strcmp(strict
, "strict") != 0)
4141 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4142 field
, strict
? strict
: "");
4144 if (os_strcmp(field
, "eap") == 0) {
4145 return eap_get_names(buf
, buflen
);
4148 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4150 if (os_strcmp(field
, "pairwise") == 0)
4151 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4154 if (os_strcmp(field
, "group") == 0)
4155 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4158 if (os_strcmp(field
, "group_mgmt") == 0)
4159 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4162 if (os_strcmp(field
, "key_mgmt") == 0)
4163 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4166 if (os_strcmp(field
, "proto") == 0)
4167 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4170 if (os_strcmp(field
, "auth_alg") == 0)
4171 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4172 &capa
, buf
, buflen
);
4174 if (os_strcmp(field
, "modes") == 0)
4175 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4178 if (os_strcmp(field
, "channels") == 0)
4179 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4181 if (os_strcmp(field
, "freq") == 0)
4182 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4185 if (os_strcmp(field
, "tdls") == 0)
4186 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4187 #endif /* CONFIG_TDLS */
4190 if (os_strcmp(field
, "erp") == 0) {
4191 res
= os_snprintf(buf
, buflen
, "ERP");
4192 if (os_snprintf_error(buflen
, res
))
4196 #endif /* CONFIG_EPR */
4199 if (os_strcmp(field
, "fips") == 0) {
4200 res
= os_snprintf(buf
, buflen
, "FIPS");
4201 if (os_snprintf_error(buflen
, res
))
4205 #endif /* CONFIG_FIPS */
4208 if (os_strcmp(field
, "acs") == 0) {
4209 res
= os_snprintf(buf
, buflen
, "ACS");
4210 if (os_snprintf_error(buflen
, res
))
4214 #endif /* CONFIG_ACS */
4217 if (os_strcmp(field
, "fils") == 0 &&
4218 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
)) {
4219 #ifdef CONFIG_FILS_SK_PFS
4220 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4221 #else /* CONFIG_FILS_SK_PFS */
4222 res
= os_snprintf(buf
, buflen
, "FILS");
4223 #endif /* CONFIG_FILS_SK_PFS */
4224 if (os_snprintf_error(buflen
, res
))
4228 #endif /* CONFIG_FILS */
4230 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4237 #ifdef CONFIG_INTERWORKING
4238 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4239 struct wpabuf
*data
)
4249 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4250 if (os_snprintf_error(end
- pos
, ret
))
4254 d
= wpabuf_head_u8(data
);
4255 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4256 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4257 if (os_snprintf_error(end
- pos
, ret
))
4262 ret
= os_snprintf(pos
, end
- pos
, "\n");
4263 if (os_snprintf_error(end
- pos
, ret
))
4269 #endif /* CONFIG_INTERWORKING */
4273 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4276 const u8
*ie
, *ie_end
;
4280 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4283 ie_end
= ie
+ 2 + ie
[1];
4285 if (ie_end
- ie
< 2)
4288 info
= WPA_GET_LE16(ie
);
4290 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4291 if (os_snprintf_error(end
- pos
, ret
))
4295 if (info
& BIT(7)) {
4296 /* Cache Identifier Included */
4297 if (ie_end
- ie
< 2)
4299 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4301 if (os_snprintf_error(end
- pos
, ret
))
4307 if (info
& BIT(8)) {
4308 /* HESSID Included */
4309 if (ie_end
- ie
< ETH_ALEN
)
4311 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4313 if (os_snprintf_error(end
- pos
, ret
))
4319 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4321 if (ie_end
- ie
< realms
* 2)
4323 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4324 if (os_snprintf_error(end
- pos
, ret
))
4328 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4333 ret
= os_snprintf(pos
, end
- pos
, "\n");
4334 if (os_snprintf_error(end
- pos
, ret
))
4341 #endif /* CONFIG_FILS */
4344 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4345 unsigned long mask
, char *buf
, size_t buflen
)
4350 const u8
*ie
, *ie2
, *osen_ie
, *mesh
;
4355 if (mask
& WPA_BSS_MASK_ID
) {
4356 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4357 if (os_snprintf_error(end
- pos
, ret
))
4362 if (mask
& WPA_BSS_MASK_BSSID
) {
4363 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4364 MAC2STR(bss
->bssid
));
4365 if (os_snprintf_error(end
- pos
, ret
))
4370 if (mask
& WPA_BSS_MASK_FREQ
) {
4371 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4372 if (os_snprintf_error(end
- pos
, ret
))
4377 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4378 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4380 if (os_snprintf_error(end
- pos
, ret
))
4385 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4386 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4388 if (os_snprintf_error(end
- pos
, ret
))
4393 if (mask
& WPA_BSS_MASK_QUAL
) {
4394 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4395 if (os_snprintf_error(end
- pos
, ret
))
4400 if (mask
& WPA_BSS_MASK_NOISE
) {
4401 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4402 if (os_snprintf_error(end
- pos
, ret
))
4407 if (mask
& WPA_BSS_MASK_LEVEL
) {
4408 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4409 if (os_snprintf_error(end
- pos
, ret
))
4414 if (mask
& WPA_BSS_MASK_TSF
) {
4415 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4416 (unsigned long long) bss
->tsf
);
4417 if (os_snprintf_error(end
- pos
, ret
))
4422 if (mask
& WPA_BSS_MASK_AGE
) {
4423 struct os_reltime now
;
4425 os_get_reltime(&now
);
4426 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4427 (int) (now
.sec
- bss
->last_update
.sec
));
4428 if (os_snprintf_error(end
- pos
, ret
))
4433 if (mask
& WPA_BSS_MASK_IE
) {
4434 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4435 if (os_snprintf_error(end
- pos
, ret
))
4439 ie
= (const u8
*) (bss
+ 1);
4440 for (i
= 0; i
< bss
->ie_len
; i
++) {
4441 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4442 if (os_snprintf_error(end
- pos
, ret
))
4447 ret
= os_snprintf(pos
, end
- pos
, "\n");
4448 if (os_snprintf_error(end
- pos
, ret
))
4453 if (mask
& WPA_BSS_MASK_FLAGS
) {
4454 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4455 if (os_snprintf_error(end
- pos
, ret
))
4459 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4461 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4463 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4465 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4467 pos
= wpa_supplicant_ie_txt(pos
, end
,
4468 mesh
? "RSN" : "WPA2", ie2
,
4470 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4472 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4473 osen_ie
, 2 + osen_ie
[1]);
4474 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4475 if (!ie
&& !ie2
&& !osen_ie
&&
4476 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4477 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4478 if (os_snprintf_error(end
- pos
, ret
))
4484 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4485 if (os_snprintf_error(end
- pos
, ret
))
4490 if (bss_is_dmg(bss
)) {
4492 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4493 if (os_snprintf_error(end
- pos
, ret
))
4496 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4497 case IEEE80211_CAP_DMG_IBSS
:
4500 case IEEE80211_CAP_DMG_AP
:
4503 case IEEE80211_CAP_DMG_PBSS
:
4510 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4511 if (os_snprintf_error(end
- pos
, ret
))
4515 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4516 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4517 if (os_snprintf_error(end
- pos
, ret
))
4521 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4522 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4523 if (os_snprintf_error(end
- pos
, ret
))
4528 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4529 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4530 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4531 if (os_snprintf_error(end
- pos
, ret
))
4536 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4537 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4538 if (os_snprintf_error(end
- pos
, ret
))
4542 #endif /* CONFIG_HS20 */
4544 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4545 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4546 if (os_snprintf_error(end
- pos
, ret
))
4550 #endif /* CONFIG_FILS */
4552 ret
= os_snprintf(pos
, end
- pos
, "\n");
4553 if (os_snprintf_error(end
- pos
, ret
))
4558 if (mask
& WPA_BSS_MASK_SSID
) {
4559 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4560 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4561 if (os_snprintf_error(end
- pos
, ret
))
4567 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4568 ie
= (const u8
*) (bss
+ 1);
4569 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4570 if (ret
>= end
- pos
)
4575 #endif /* CONFIG_WPS */
4578 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4579 ie
= (const u8
*) (bss
+ 1);
4580 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4581 if (ret
>= end
- pos
)
4586 #endif /* CONFIG_P2P */
4588 #ifdef CONFIG_WIFI_DISPLAY
4589 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4591 ie
= (const u8
*) (bss
+ 1);
4592 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4593 WFD_IE_VENDOR_TYPE
);
4595 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4596 if (os_snprintf_error(end
- pos
, ret
)) {
4602 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4607 ret
= os_snprintf(pos
, end
- pos
, "\n");
4608 if (os_snprintf_error(end
- pos
, ret
))
4613 #endif /* CONFIG_WIFI_DISPLAY */
4615 #ifdef CONFIG_INTERWORKING
4616 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4617 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4618 struct wpa_bss_anqp_elem
*elem
;
4620 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4621 anqp
->capability_list
);
4622 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4624 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4625 anqp
->network_auth_type
);
4626 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4627 anqp
->roaming_consortium
);
4628 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4629 anqp
->ip_addr_type_availability
);
4630 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4632 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4633 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4635 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4636 anqp
->fils_realm_info
);
4638 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4639 anqp
->hs20_capability_list
);
4640 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4641 anqp
->hs20_operator_friendly_name
);
4642 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4643 anqp
->hs20_wan_metrics
);
4644 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4645 anqp
->hs20_connection_capability
);
4646 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4647 anqp
->hs20_operating_class
);
4648 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4649 anqp
->hs20_osu_providers_list
);
4650 #endif /* CONFIG_HS20 */
4652 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4653 struct wpa_bss_anqp_elem
, list
) {
4656 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4658 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4661 #endif /* CONFIG_INTERWORKING */
4664 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4665 ie
= (const u8
*) (bss
+ 1);
4666 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4667 if (ret
>= end
- pos
)
4672 #endif /* CONFIG_MESH */
4674 if (mask
& WPA_BSS_MASK_SNR
) {
4675 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4676 if (os_snprintf_error(end
- pos
, ret
))
4681 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4682 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4683 bss
->est_throughput
);
4684 if (os_snprintf_error(end
- pos
, ret
))
4690 if (mask
& WPA_BSS_MASK_FST
) {
4691 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4692 if (ret
< 0 || ret
>= end
- pos
)
4696 #endif /* CONFIG_FST */
4698 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4699 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4700 bss
->last_update_idx
);
4701 if (os_snprintf_error(end
- pos
, ret
))
4706 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4707 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4708 if (os_snprintf_error(end
- pos
, ret
))
4712 ie
= (const u8
*) (bss
+ 1);
4714 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4715 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4716 if (os_snprintf_error(end
- pos
, ret
))
4721 ret
= os_snprintf(pos
, end
- pos
, "\n");
4722 if (os_snprintf_error(end
- pos
, ret
))
4728 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4729 ret
= print_fils_indication(bss
, pos
, end
);
4734 #endif /* CONFIG_FILS */
4736 if (mask
& WPA_BSS_MASK_DELIM
) {
4737 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4738 if (os_snprintf_error(end
- pos
, ret
))
4747 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4748 const char *cmd
, char *buf
,
4753 struct wpa_bss
*bss
;
4754 struct wpa_bss
*bsslast
= NULL
;
4755 struct dl_list
*next
;
4758 char *ctmp
, *end
= buf
+ buflen
;
4759 unsigned long mask
= WPA_BSS_MASK_ALL
;
4761 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4762 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4763 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4765 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4767 } else { /* N1-N2 */
4768 unsigned int id1
, id2
;
4770 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4771 wpa_printf(MSG_INFO
, "Wrong BSS range "
4776 if (*(cmd
+ 6) == '-')
4779 id1
= atoi(cmd
+ 6);
4781 if (*ctmp
>= '0' && *ctmp
<= '9')
4784 id2
= (unsigned int) -1;
4785 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4786 if (id2
== (unsigned int) -1)
4787 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4791 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4792 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4793 struct wpa_bss
*tmp
= bss
;
4795 next
= tmp
->list_id
.next
;
4796 if (next
== &wpa_s
->bss_id
)
4798 tmp
= dl_list_entry(
4799 next
, struct wpa_bss
,
4808 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4809 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4810 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4811 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4812 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4814 bss
= wpa_bss_get_id(wpa_s
, i
);
4815 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4817 bss
= wpa_bss_get_id(wpa_s
, i
);
4819 next
= bss
->list_id
.next
;
4820 if (next
== &wpa_s
->bss_id
)
4823 bss
= dl_list_entry(next
, struct wpa_bss
,
4826 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
4827 bss
= wpa_s
->current_bss
;
4829 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4830 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4831 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4834 #endif /* CONFIG_P2P */
4835 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4836 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4838 struct wpa_bss
*tmp
;
4841 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4850 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4851 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4853 mask
= WPA_BSS_MASK_ALL
;
4859 if (bsslast
== NULL
)
4862 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4866 if (bss
== bsslast
) {
4867 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4868 (bss
== dl_list_last(&wpa_s
->bss_id
,
4869 struct wpa_bss
, list_id
))) {
4872 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4874 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4875 wpa_printf(MSG_DEBUG
,
4876 "Could not add end delim");
4881 next
= bss
->list_id
.next
;
4882 if (next
== &wpa_s
->bss_id
)
4884 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4885 } while (bss
&& len
);
4891 static int wpa_supplicant_ctrl_iface_ap_scan(
4892 struct wpa_supplicant
*wpa_s
, char *cmd
)
4894 int ap_scan
= atoi(cmd
);
4895 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4899 static int wpa_supplicant_ctrl_iface_scan_interval(
4900 struct wpa_supplicant
*wpa_s
, char *cmd
)
4902 int scan_int
= atoi(cmd
);
4903 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4907 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4908 struct wpa_supplicant
*wpa_s
, char *cmd
)
4910 int expire_age
= atoi(cmd
);
4911 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4915 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4916 struct wpa_supplicant
*wpa_s
, char *cmd
)
4918 int expire_count
= atoi(cmd
);
4919 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4923 static void wpa_supplicant_ctrl_iface_bss_flush(
4924 struct wpa_supplicant
*wpa_s
, char *cmd
)
4926 int flush_age
= atoi(cmd
);
4929 wpa_bss_flush(wpa_s
);
4931 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4935 #ifdef CONFIG_TESTING_OPTIONS
4936 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4938 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4939 /* MLME-DELETEKEYS.request */
4940 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4941 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4942 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4943 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4944 #ifdef CONFIG_IEEE80211W
4945 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4946 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4947 #endif /* CONFIG_IEEE80211W */
4949 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4951 /* MLME-SETPROTECTION.request(None) */
4952 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4953 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4954 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4955 wpa_sm_drop_sa(wpa_s
->wpa
);
4957 #endif /* CONFIG_TESTING_OPTIONS */
4960 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4963 #ifdef CONFIG_NO_SCAN_PROCESSING
4965 #else /* CONFIG_NO_SCAN_PROCESSING */
4967 struct wpa_bss
*bss
;
4968 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4970 if (hwaddr_aton(addr
, bssid
)) {
4971 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4972 "address '%s'", addr
);
4976 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4979 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4980 "configuration known for the target AP");
4984 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4986 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4992 * TODO: Find best network configuration block from configuration to
4993 * allow roaming to other networks
4996 wpa_s
->reassociate
= 1;
4997 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
5000 #endif /* CONFIG_NO_SCAN_PROCESSING */
5005 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
5007 unsigned int timeout
= atoi(cmd
);
5008 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
5009 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
5010 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
5012 unsigned int search_delay
;
5013 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
5017 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5018 wpa_dbg(wpa_s
, MSG_INFO
,
5019 "Reject P2P_FIND since interface is disabled");
5022 if (os_strstr(cmd
, "type=social"))
5023 type
= P2P_FIND_ONLY_SOCIAL
;
5024 else if (os_strstr(cmd
, "type=progressive"))
5025 type
= P2P_FIND_PROGRESSIVE
;
5027 pos
= os_strstr(cmd
, "dev_id=");
5030 if (hwaddr_aton(pos
, dev_id
))
5035 pos
= os_strstr(cmd
, "dev_type=");
5038 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
5040 _dev_type
= dev_type
;
5043 pos
= os_strstr(cmd
, "delay=");
5046 search_delay
= atoi(pos
);
5048 search_delay
= wpas_p2p_search_delay(wpa_s
);
5050 pos
= os_strstr(cmd
, "freq=");
5058 /* Must be searched for last, because it adds nul termination */
5059 pos
= os_strstr(cmd
, " seek=");
5062 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5065 _seek
[seek_count
++] = pos
;
5067 term
= os_strchr(pos
, ' ');
5071 pos
= os_strstr(term
+ 1, "seek=");
5075 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5080 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5081 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5085 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5087 const char *last
= NULL
;
5092 /* Expected predefined CPT names delimited by ':' */
5093 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5094 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5095 wpa_printf(MSG_ERROR
,
5096 "P2PS: CPT name list is too long, expected up to %d names",
5097 P2PS_FEATURE_CAPAB_CPT_MAX
);
5102 token_len
= last
- token
;
5104 if (token_len
== 3 &&
5105 os_memcmp(token
, "UDP", token_len
) == 0) {
5106 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5107 } else if (token_len
== 3 &&
5108 os_memcmp(token
, "MAC", token_len
) == 0) {
5109 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5111 wpa_printf(MSG_ERROR
,
5112 "P2PS: Unsupported CPT name '%s'", token
);
5117 if (isblank((unsigned char) *last
)) {
5127 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5129 struct p2ps_provision
*p2ps_prov
;
5131 size_t info_len
= 0;
5133 u8 role
= P2PS_SETUP_NONE
;
5134 long long unsigned val
;
5137 pos
= os_strstr(cmd
, "info=");
5140 info_len
= os_strlen(pos
);
5143 info
= os_malloc(info_len
+ 1);
5145 info_len
= utf8_unescape(pos
, info_len
,
5146 info
, info_len
+ 1);
5152 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5153 if (p2ps_prov
== NULL
) {
5159 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5160 p2ps_prov
->info
[info_len
] = '\0';
5164 pos
= os_strstr(cmd
, "status=");
5166 p2ps_prov
->status
= atoi(pos
+ 7);
5168 p2ps_prov
->status
= -1;
5170 pos
= os_strstr(cmd
, "adv_id=");
5171 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5173 p2ps_prov
->adv_id
= val
;
5175 pos
= os_strstr(cmd
, "method=");
5177 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5179 p2ps_prov
->method
= 0;
5181 pos
= os_strstr(cmd
, "session=");
5182 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5184 p2ps_prov
->session_id
= val
;
5186 pos
= os_strstr(cmd
, "adv_mac=");
5187 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5190 pos
= os_strstr(cmd
, "session_mac=");
5191 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5194 pos
= os_strstr(cmd
, "cpt=");
5196 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5197 p2ps_prov
->cpt_priority
))
5200 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5203 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5204 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5206 /* force conncap with tstCap (no sanity checks) */
5207 pos
= os_strstr(cmd
, "tstCap=");
5209 role
= strtol(pos
+ 7, NULL
, 16);
5211 pos
= os_strstr(cmd
, "role=");
5213 role
= strtol(pos
+ 5, NULL
, 16);
5214 if (role
!= P2PS_SETUP_CLIENT
&&
5215 role
!= P2PS_SETUP_GROUP_OWNER
)
5216 role
= P2PS_SETUP_NONE
;
5219 p2ps_prov
->role
= role
;
5229 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5232 struct p2ps_provision
*p2ps_prov
;
5235 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5237 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5239 if (hwaddr_aton(cmd
, addr
))
5246 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5250 if (p2ps_prov
->status
< 0) {
5255 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5260 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5263 struct p2ps_provision
*p2ps_prov
;
5266 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5267 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5270 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5271 if (hwaddr_aton(cmd
, addr
))
5278 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5282 p2ps_prov
->pd_seeker
= 1;
5284 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5289 static int parse_freq(int chwidth
, int freq2
)
5294 return VHT_CHANWIDTH_80P80MHZ
;
5300 return VHT_CHANWIDTH_USE_HT
;
5302 return VHT_CHANWIDTH_80MHZ
;
5304 return VHT_CHANWIDTH_160MHZ
;
5306 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5313 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5314 char *buf
, size_t buflen
)
5319 enum p2p_wps_method wps_method
;
5322 int persistent_group
, persistent_id
= -1;
5329 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5330 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5331 size_t group_ssid_len
= 0;
5333 if (!wpa_s
->global
->p2p_init_wpa_s
)
5335 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5336 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5337 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5338 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5341 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5342 * [persistent|persistent=<network id>]
5343 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5344 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5346 if (hwaddr_aton(cmd
, addr
))
5354 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5355 pos2
= os_strstr(pos
, " persistent=");
5357 struct wpa_ssid
*ssid
;
5358 persistent_id
= atoi(pos2
+ 12);
5359 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5360 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5361 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5362 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5363 "SSID id=%d for persistent P2P group (GO)",
5368 join
= os_strstr(pos
, " join") != NULL
;
5369 auth
= os_strstr(pos
, " auth") != NULL
;
5370 automatic
= os_strstr(pos
, " auto") != NULL
;
5371 pd
= os_strstr(pos
, " provdisc") != NULL
;
5372 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5373 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5376 pos2
= os_strstr(pos
, " go_intent=");
5379 go_intent
= atoi(pos2
);
5380 if (go_intent
< 0 || go_intent
> 15)
5384 pos2
= os_strstr(pos
, " freq=");
5392 pos2
= os_strstr(pos
, " freq2=");
5394 freq2
= atoi(pos2
+ 7);
5396 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5398 chwidth
= atoi(pos2
+ 18);
5400 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5401 if (max_oper_chwidth
< 0)
5404 pos2
= os_strstr(pos
, " ssid=");
5409 end
= os_strchr(pos2
, ' ');
5411 group_ssid_len
= os_strlen(pos2
) / 2;
5413 group_ssid_len
= (end
- pos2
) / 2;
5414 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5415 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5417 group_ssid
= _group_ssid
;
5420 if (os_strncmp(pos
, "pin", 3) == 0) {
5421 /* Request random PIN (to be displayed) and enable the PIN */
5422 wps_method
= WPS_PIN_DISPLAY
;
5423 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5424 wps_method
= WPS_PBC
;
5425 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5426 wps_method
= WPS_P2PS
;
5429 pos
= os_strchr(pin
, ' ');
5430 wps_method
= WPS_PIN_KEYPAD
;
5433 if (os_strncmp(pos
, "display", 7) == 0)
5434 wps_method
= WPS_PIN_DISPLAY
;
5436 if (!wps_pin_str_valid(pin
)) {
5437 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5442 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5443 persistent_group
, automatic
, join
,
5444 auth
, go_intent
, freq
, freq2
, persistent_id
,
5445 pd
, ht40
, vht
, max_oper_chwidth
,
5446 group_ssid
, group_ssid_len
);
5447 if (new_pin
== -2) {
5448 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5451 if (new_pin
== -3) {
5452 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5457 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5458 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5459 if (os_snprintf_error(buflen
, ret
))
5464 os_memcpy(buf
, "OK\n", 3);
5469 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5471 unsigned int timeout
= atoi(cmd
);
5472 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5473 wpa_dbg(wpa_s
, MSG_INFO
,
5474 "Reject P2P_LISTEN since interface is disabled");
5477 return wpas_p2p_listen(wpa_s
, timeout
);
5481 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5485 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5487 /* <addr> <config method> [join|auto] */
5489 if (hwaddr_aton(cmd
, addr
))
5497 if (os_strstr(pos
, " join") != NULL
)
5498 use
= WPAS_P2P_PD_FOR_JOIN
;
5499 else if (os_strstr(pos
, " auto") != NULL
)
5500 use
= WPAS_P2P_PD_AUTO
;
5502 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5506 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5509 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5511 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5512 ssid
->passphrase
== NULL
)
5515 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5516 return os_strlen(buf
);
5520 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5521 char *buf
, size_t buflen
)
5525 u8 dst_buf
[ETH_ALEN
], *dst
;
5526 struct wpabuf
*tlvs
;
5530 if (hwaddr_aton(cmd
, dst_buf
))
5533 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5534 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5541 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5544 if (hexstr2bin(pos
, &version
, 1) < 0)
5550 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5551 #ifdef CONFIG_WIFI_DISPLAY
5552 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5553 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5554 #endif /* CONFIG_WIFI_DISPLAY */
5555 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5557 char *svc_info
= NULL
;
5561 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5564 pos
= os_strchr(pos
, ' ');
5565 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5570 pos
= os_strchr(svc_str
, ' ');
5575 /* All remaining data is the svc_info string */
5576 if (pos
&& pos
[0] && pos
[0] != ' ') {
5577 len
= os_strlen(pos
);
5579 /* Unescape in place */
5580 len
= utf8_unescape(pos
, len
, pos
, len
);
5587 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5590 len
= os_strlen(pos
);
5594 tlvs
= wpabuf_alloc(len
);
5597 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5602 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5607 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5608 if (os_snprintf_error(buflen
, res
))
5614 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5617 long long unsigned val
;
5619 if (sscanf(cmd
, "%llx", &val
) != 1)
5622 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5626 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5631 struct wpabuf
*resp_tlvs
;
5635 pos
= os_strchr(cmd
, ' ');
5643 if (hwaddr_aton(pos
, dst
))
5650 pos2
= os_strchr(pos
, ' ');
5654 dialog_token
= atoi(pos
);
5656 len
= os_strlen(pos2
);
5660 resp_tlvs
= wpabuf_alloc(len
);
5661 if (resp_tlvs
== NULL
)
5663 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5664 wpabuf_free(resp_tlvs
);
5668 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5669 wpabuf_free(resp_tlvs
);
5674 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5677 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5679 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5684 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5689 struct wpabuf
*query
, *resp
;
5691 pos
= os_strchr(cmd
, ' ');
5696 len
= os_strlen(cmd
);
5700 query
= wpabuf_alloc(len
);
5703 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5708 len
= os_strlen(pos
);
5714 resp
= wpabuf_alloc(len
);
5719 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5725 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5734 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5739 pos
= os_strchr(cmd
, ' ');
5744 if (hexstr2bin(cmd
, &version
, 1) < 0)
5747 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5751 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5752 u8 replace
, char *cmd
)
5756 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5757 char *svc_info
= NULL
;
5759 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5761 pos
= os_strchr(cmd
, ' ');
5766 /* Auto-Accept value is mandatory, and must be one of the
5767 * single values (0, 1, 2, 4) */
5768 auto_accept
= atoi(cmd
);
5769 switch (auto_accept
) {
5770 case P2PS_SETUP_NONE
: /* No auto-accept */
5771 case P2PS_SETUP_NEW
:
5772 case P2PS_SETUP_CLIENT
:
5773 case P2PS_SETUP_GROUP_OWNER
:
5779 /* Advertisement ID is mandatory */
5781 pos
= os_strchr(cmd
, ' ');
5786 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5787 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5790 /* Only allow replacements if exist, and adds if not */
5791 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5799 /* svc_state between 0 - 0xff is mandatory */
5800 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5803 pos
= os_strchr(pos
, ' ');
5807 /* config_methods is mandatory */
5809 if (sscanf(pos
, "%x", &config_methods
) != 1)
5812 if (!(config_methods
&
5813 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5816 pos
= os_strchr(pos
, ' ');
5823 /* Advertisement string is mandatory */
5824 if (!pos
[0] || pos
[0] == ' ')
5827 /* Terminate svc string */
5828 pos
= os_strchr(pos
, ' ');
5832 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5834 pos
= os_strchr(pos
, ' ');
5838 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5841 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5845 /* Service and Response Information are optional */
5846 if (pos
&& pos
[0]) {
5849 /* Note the bare ' included, which cannot exist legally
5850 * in unescaped string. */
5851 svc_info
= os_strstr(pos
, "svc_info='");
5855 len
= os_strlen(svc_info
);
5856 utf8_unescape(svc_info
, len
, svc_info
, len
);
5860 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
5861 (u8
) svc_state
, (u16
) config_methods
,
5862 svc_info
, cpt_prio
);
5866 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5870 pos
= os_strchr(cmd
, ' ');
5875 if (os_strcmp(cmd
, "bonjour") == 0)
5876 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
5877 if (os_strcmp(cmd
, "upnp") == 0)
5878 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
5879 if (os_strcmp(cmd
, "asp") == 0)
5880 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
5881 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5886 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
5890 struct wpabuf
*query
;
5893 len
= os_strlen(cmd
);
5897 query
= wpabuf_alloc(len
);
5900 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5905 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
5911 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5916 pos
= os_strchr(cmd
, ' ');
5921 if (hexstr2bin(cmd
, &version
, 1) < 0)
5924 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
5928 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5932 if (os_strcmp(cmd
, "all") == 0) {
5933 wpas_p2p_service_flush_asp(wpa_s
);
5937 if (sscanf(cmd
, "%x", &adv_id
) != 1)
5940 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
5944 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
5948 pos
= os_strchr(cmd
, ' ');
5953 if (os_strcmp(cmd
, "bonjour") == 0)
5954 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
5955 if (os_strcmp(cmd
, "upnp") == 0)
5956 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
5957 if (os_strcmp(cmd
, "asp") == 0)
5958 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
5959 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5964 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
5968 pos
= os_strchr(cmd
, ' ');
5973 if (os_strcmp(cmd
, "asp") == 0)
5974 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
5976 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5981 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
5987 if (hwaddr_aton(cmd
, addr
))
5990 return wpas_p2p_reject(wpa_s
, addr
);
5994 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
5998 struct wpa_ssid
*ssid
;
5999 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
6000 int freq
= 0, pref_freq
= 0;
6001 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6004 pos
= os_strstr(cmd
, " peer=");
6007 if (hwaddr_aton(pos
, peer
))
6011 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6012 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6013 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6014 "for persistent P2P group",
6019 pos
= os_strstr(cmd
, " freq=");
6027 pos
= os_strstr(cmd
, " pref=");
6030 pref_freq
= atoi(pos
);
6035 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
6036 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
6039 pos
= os_strstr(cmd
, "freq2=");
6041 freq2
= atoi(pos
+ 6);
6043 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6045 chwidth
= atoi(pos
+ 18);
6047 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6048 if (max_oper_chwidth
< 0)
6051 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6052 max_oper_chwidth
, pref_freq
);
6056 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6059 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6061 pos
= os_strstr(cmd
, " peer=");
6067 if (hwaddr_aton(pos
, peer
)) {
6068 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6072 pos
= os_strstr(pos
, " go_dev_addr=");
6075 if (hwaddr_aton(pos
, go_dev_addr
)) {
6076 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6080 go_dev
= go_dev_addr
;
6083 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6087 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6089 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6090 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6091 if (os_strncmp(cmd
, "group=", 6) == 0)
6092 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6098 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6099 int id
, int freq
, int vht_center_freq2
,
6100 int ht40
, int vht
, int vht_chwidth
)
6102 struct wpa_ssid
*ssid
;
6104 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6105 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6106 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6107 "for persistent P2P group",
6112 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6113 vht_center_freq2
, 0, ht40
, vht
,
6114 vht_chwidth
, NULL
, 0, 0);
6118 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6120 int freq
= 0, persistent
= 0, group_id
= -1;
6121 int vht
= wpa_s
->conf
->p2p_go_vht
;
6122 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6123 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6124 char *token
, *context
= NULL
;
6126 while ((token
= str_token(cmd
, " ", &context
))) {
6127 if (sscanf(token
, "freq=%d", &freq
) == 1 ||
6128 sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6129 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6130 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6132 } else if (os_strcmp(token
, "ht40") == 0) {
6134 } else if (os_strcmp(token
, "vht") == 0) {
6137 } else if (os_strcmp(token
, "persistent") == 0) {
6140 wpa_printf(MSG_DEBUG
,
6141 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6147 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6148 if (max_oper_chwidth
< 0)
6152 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6153 freq
, freq2
, ht40
, vht
,
6156 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6161 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6162 char *buf
, size_t buflen
)
6164 u8 dev_addr
[ETH_ALEN
];
6165 struct wpa_ssid
*ssid
;
6169 ssid
= wpa_s
->current_ssid
;
6170 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6171 hwaddr_aton(cmd
, dev_addr
))
6174 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6177 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6178 if (os_snprintf_error(buflen
, res
))
6184 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6185 const u8
*p2p_dev_addr
)
6187 struct wpa_supplicant
*wpa_s
;
6189 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6190 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6198 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6199 char *buf
, size_t buflen
)
6201 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6203 const struct p2p_peer_info
*info
;
6205 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6206 struct wpa_ssid
*ssid
;
6209 if (!wpa_s
->global
->p2p
)
6212 if (os_strcmp(cmd
, "FIRST") == 0) {
6215 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6216 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6221 if (hwaddr_aton(cmd
, addr
) < 0)
6227 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6230 group_capab
= info
->group_capab
;
6233 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6234 wpa_printf(MSG_DEBUG
,
6235 "P2P: Could not find any BSS with p2p_dev_addr "
6236 MACSTR
", hence override group_capab from 0x%x to 0",
6237 MAC2STR(info
->p2p_device_addr
), group_capab
);
6244 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6250 "serial_number=%s\n"
6251 "config_methods=0x%x\n"
6253 "group_capab=0x%x\n"
6255 MAC2STR(info
->p2p_device_addr
),
6256 wps_dev_type_bin2str(info
->pri_dev_type
,
6257 devtype
, sizeof(devtype
)),
6262 info
->serial_number
,
6263 info
->config_methods
,
6267 if (os_snprintf_error(end
- pos
, res
))
6271 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6274 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6275 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6276 wps_dev_type_bin2str(t
, devtype
,
6278 if (os_snprintf_error(end
- pos
, res
))
6283 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6285 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6286 if (os_snprintf_error(end
- pos
, res
))
6291 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6296 if (info
->vendor_elems
) {
6297 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6298 if (os_snprintf_error(end
- pos
, res
))
6302 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6303 wpabuf_head(info
->vendor_elems
),
6304 wpabuf_len(info
->vendor_elems
));
6306 res
= os_snprintf(pos
, end
- pos
, "\n");
6307 if (os_snprintf_error(end
- pos
, res
))
6316 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6321 if (wpa_s
->global
->p2p
== NULL
)
6324 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6327 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6328 struct wpa_freq_range
*freq
;
6329 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6330 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6331 freq
->min
, freq
->max
);
6334 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6339 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6343 if (wpa_s
->global
->p2p
== NULL
)
6346 param
= os_strchr(cmd
, ' ');
6351 if (os_strcmp(cmd
, "discoverability") == 0) {
6352 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6357 if (os_strcmp(cmd
, "managed") == 0) {
6358 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6362 if (os_strcmp(cmd
, "listen_channel") == 0) {
6364 u8 channel
, op_class
;
6366 channel
= atoi(param
);
6367 pos
= os_strchr(param
, ' ');
6368 op_class
= pos
? atoi(pos
) : 81;
6370 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6374 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6375 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6379 if (os_strcmp(cmd
, "noa") == 0) {
6381 int count
, start
, duration
;
6382 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6383 count
= atoi(param
);
6384 pos
= os_strchr(param
, ',');
6389 pos
= os_strchr(pos
, ',');
6393 duration
= atoi(pos
);
6394 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6396 if (count
== 0 && duration
> 0)
6398 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6399 "start=%d duration=%d", count
, start
, duration
);
6400 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6403 if (os_strcmp(cmd
, "ps") == 0)
6404 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6406 if (os_strcmp(cmd
, "oppps") == 0)
6407 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6409 if (os_strcmp(cmd
, "ctwindow") == 0)
6410 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6412 if (os_strcmp(cmd
, "disabled") == 0) {
6413 wpa_s
->global
->p2p_disabled
= atoi(param
);
6414 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6415 wpa_s
->global
->p2p_disabled
?
6416 "disabled" : "enabled");
6417 if (wpa_s
->global
->p2p_disabled
) {
6418 wpas_p2p_stop_find(wpa_s
);
6419 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6420 p2p_flush(wpa_s
->global
->p2p
);
6425 if (os_strcmp(cmd
, "conc_pref") == 0) {
6426 if (os_strcmp(param
, "sta") == 0)
6427 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6428 else if (os_strcmp(param
, "p2p") == 0)
6429 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6431 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6434 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6439 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6440 wpa_s
->force_long_sd
= atoi(param
);
6444 if (os_strcmp(cmd
, "peer_filter") == 0) {
6446 if (hwaddr_aton(param
, addr
))
6448 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6452 if (os_strcmp(cmd
, "cross_connect") == 0)
6453 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6455 if (os_strcmp(cmd
, "go_apsd") == 0) {
6456 if (os_strcmp(param
, "disable") == 0)
6457 wpa_s
->set_ap_uapsd
= 0;
6459 wpa_s
->set_ap_uapsd
= 1;
6460 wpa_s
->ap_uapsd
= atoi(param
);
6465 if (os_strcmp(cmd
, "client_apsd") == 0) {
6466 if (os_strcmp(param
, "disable") == 0)
6467 wpa_s
->set_sta_uapsd
= 0;
6471 /* format: BE,BK,VI,VO;max SP Length */
6473 pos
= os_strchr(param
, ',');
6478 pos
= os_strchr(pos
, ',');
6483 pos
= os_strchr(pos
, ',');
6488 /* ignore max SP Length for now */
6490 wpa_s
->set_sta_uapsd
= 1;
6491 wpa_s
->sta_uapsd
= 0;
6493 wpa_s
->sta_uapsd
|= BIT(0);
6495 wpa_s
->sta_uapsd
|= BIT(1);
6497 wpa_s
->sta_uapsd
|= BIT(2);
6499 wpa_s
->sta_uapsd
|= BIT(3);
6504 if (os_strcmp(cmd
, "disallow_freq") == 0)
6505 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6507 if (os_strcmp(cmd
, "disc_int") == 0) {
6508 int min_disc_int
, max_disc_int
, max_disc_tu
;
6513 min_disc_int
= atoi(pos
);
6514 pos
= os_strchr(pos
, ' ');
6519 max_disc_int
= atoi(pos
);
6520 pos
= os_strchr(pos
, ' ');
6525 max_disc_tu
= atoi(pos
);
6527 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6528 max_disc_int
, max_disc_tu
);
6531 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6532 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6536 #ifdef CONFIG_WPS_NFC
6537 if (os_strcmp(cmd
, "nfc_tag") == 0)
6538 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6539 #endif /* CONFIG_WPS_NFC */
6541 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6542 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6546 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6549 op_class
= atoi(param
);
6550 param
= os_strchr(param
, ':');
6555 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6560 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6567 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6569 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6570 wpa_s
->force_long_sd
= 0;
6571 wpas_p2p_stop_find(wpa_s
);
6572 wpa_s
->parent
->p2ps_method_config_any
= 0;
6573 if (wpa_s
->global
->p2p
)
6574 p2p_flush(wpa_s
->global
->p2p
);
6578 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6581 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6584 pos
= os_strchr(cmd
, ' ');
6590 pos2
= os_strchr(pos
, ' ');
6598 pos
= os_strchr(pos2
, ' ');
6606 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6610 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6613 unsigned int period
= 0, interval
= 0;
6616 pos
= os_strchr(cmd
, ' ');
6621 interval
= atoi(pos
);
6624 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6628 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6635 if (os_strncmp(pos
, "iface=", 6) == 0) {
6639 if (hwaddr_aton(pos
, peer
))
6642 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6647 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6649 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6651 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6653 wpa_printf(MSG_DEBUG
,
6654 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6658 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6661 #endif /* CONFIG_P2P */
6664 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6666 struct wpa_freq_range_list ranges
;
6668 struct hostapd_hw_modes
*mode
;
6671 if (wpa_s
->hw
.modes
== NULL
)
6674 os_memset(&ranges
, 0, sizeof(ranges
));
6675 if (freq_range_list_parse(&ranges
, val
) < 0)
6678 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6681 mode
= &wpa_s
->hw
.modes
[i
];
6682 for (j
= 0; j
< mode
->num_channels
; j
++) {
6685 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6688 freq
= mode
->channels
[j
].freq
;
6689 if (!freq_range_list_includes(&ranges
, freq
))
6692 int_array_add_unique(&freqs
, freq
);
6696 os_free(ranges
.range
);
6701 #ifdef CONFIG_INTERWORKING
6703 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6711 auto_sel
= os_strstr(param
, "auto") != NULL
;
6713 pos
= os_strstr(param
, "freq=");
6715 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6722 return interworking_select(wpa_s
, auto_sel
, freqs
);
6726 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6730 struct wpa_bss
*bss
;
6732 if (hwaddr_aton(dst
, bssid
)) {
6733 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6737 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6739 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6744 if (bss
->ssid_len
== 0) {
6747 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6748 " does not have SSID information", MAC2STR(bssid
));
6750 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6752 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6753 bss
->ssid_len
> 0) {
6761 wpa_printf(MSG_DEBUG
,
6762 "Found another matching BSS entry with SSID");
6765 return interworking_connect(wpa_s
, bss
, only_add
);
6769 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6771 u8 dst_addr
[ETH_ALEN
];
6774 #define MAX_ANQP_INFO_ID 100
6775 u16 id
[MAX_ANQP_INFO_ID
];
6778 u32 mbo_subtypes
= 0;
6780 used
= hwaddr_aton2(dst
, dst_addr
);
6786 while (num_id
< MAX_ANQP_INFO_ID
) {
6787 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6789 int num
= atoi(pos
+ 5);
6790 if (num
<= 0 || num
> 31)
6792 subtypes
|= BIT(num
);
6793 #else /* CONFIG_HS20 */
6795 #endif /* CONFIG_HS20 */
6796 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6798 int num
= atoi(pos
+ 4);
6800 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
6802 mbo_subtypes
|= BIT(num
);
6803 #else /* CONFIG_MBO */
6805 #endif /* CONFIG_MBO */
6807 id
[num_id
] = atoi(pos
);
6811 pos
= os_strchr(pos
+ 1, ',');
6817 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
6820 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
6825 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
6827 u8 dst_addr
[ETH_ALEN
];
6828 struct wpabuf
*advproto
, *query
= NULL
;
6833 used
= hwaddr_aton2(cmd
, dst_addr
);
6841 /* Advertisement Protocol ID */
6842 end
= os_strchr(pos
, ' ');
6846 len
= os_strlen(pos
);
6852 advproto
= wpabuf_alloc(len
);
6853 if (advproto
== NULL
)
6855 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
6859 /* Optional Query Request */
6864 len
= os_strlen(pos
);
6871 query
= wpabuf_alloc(len
);
6874 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
6879 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
6882 wpabuf_free(advproto
);
6889 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
6896 size_t resp_len
, start
, requested_len
;
6897 struct wpabuf
*resp
;
6900 used
= hwaddr_aton2(cmd
, addr
);
6907 dialog_token
= atoi(pos
);
6909 if (wpa_s
->last_gas_resp
&&
6910 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
6911 dialog_token
== wpa_s
->last_gas_dialog_token
)
6912 resp
= wpa_s
->last_gas_resp
;
6913 else if (wpa_s
->prev_gas_resp
&&
6914 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
6915 dialog_token
== wpa_s
->prev_gas_dialog_token
)
6916 resp
= wpa_s
->prev_gas_resp
;
6920 resp_len
= wpabuf_len(resp
);
6922 requested_len
= resp_len
;
6924 pos
= os_strchr(pos
, ' ');
6927 if (start
> resp_len
)
6928 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6929 pos
= os_strchr(pos
, ',');
6933 requested_len
= atoi(pos
);
6934 if (start
+ requested_len
> resp_len
)
6935 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6938 if (requested_len
* 2 + 1 > buflen
)
6939 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
6941 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
6944 if (start
+ requested_len
== resp_len
) {
6946 * Free memory by dropping the response after it has been
6949 if (resp
== wpa_s
->prev_gas_resp
) {
6950 wpabuf_free(wpa_s
->prev_gas_resp
);
6951 wpa_s
->prev_gas_resp
= NULL
;
6953 wpabuf_free(wpa_s
->last_gas_resp
);
6954 wpa_s
->last_gas_resp
= NULL
;
6960 #endif /* CONFIG_INTERWORKING */
6965 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6967 u8 dst_addr
[ETH_ALEN
];
6972 used
= hwaddr_aton2(dst
, dst_addr
);
6979 int num
= atoi(pos
);
6980 if (num
<= 0 || num
> 31)
6982 subtypes
|= BIT(num
);
6983 pos
= os_strchr(pos
+ 1, ',');
6992 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
6996 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
6997 const u8
*addr
, const char *realm
)
7003 rlen
= os_strlen(realm
);
7005 buf
= os_malloc(len
);
7008 buf
[0] = 1; /* NAI Home Realm Count */
7009 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
7011 os_memcpy(buf
+ 3, realm
, rlen
);
7013 ret
= hs20_anqp_send_req(wpa_s
, addr
,
7014 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7023 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
7026 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
7027 u8 dst_addr
[ETH_ALEN
];
7033 used
= hwaddr_aton2(dst
, dst_addr
);
7037 while (dst
[used
] == ' ')
7039 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
7040 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7043 len
= os_strlen(dst
+ used
);
7045 if (len
== 0 && cred
&& cred
->realm
)
7046 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7051 buf
= os_malloc(len
);
7054 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7059 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7060 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7068 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7071 u8 dst_addr
[ETH_ALEN
];
7073 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7075 used
= hwaddr_aton2(cmd
, dst_addr
);
7080 icon
= str_token(cmd
, " ", &ctx
);
7081 poffset
= str_token(cmd
, " ", &ctx
);
7082 psize
= str_token(cmd
, " ", &ctx
);
7083 if (!icon
|| !poffset
|| !psize
)
7086 wpa_s
->fetch_osu_icon_in_progress
= 0;
7087 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7092 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7094 u8 dst_addr
[ETH_ALEN
];
7099 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7101 used
= hwaddr_aton2(cmd
, dst_addr
);
7105 while (cmd
[used
] == ' ')
7107 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7109 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7113 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7115 u8 dst_addr
[ETH_ALEN
];
7119 used
= hwaddr_aton2(cmd
, dst_addr
);
7123 while (cmd
[used
] == ' ')
7127 wpa_s
->fetch_osu_icon_in_progress
= 0;
7128 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7129 (u8
*) icon
, os_strlen(icon
), inmem
);
7132 #endif /* CONFIG_HS20 */
7135 #ifdef CONFIG_AUTOSCAN
7137 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7140 enum wpa_states state
= wpa_s
->wpa_state
;
7141 char *new_params
= NULL
;
7143 if (os_strlen(cmd
) > 0) {
7144 new_params
= os_strdup(cmd
);
7145 if (new_params
== NULL
)
7149 os_free(wpa_s
->conf
->autoscan
);
7150 wpa_s
->conf
->autoscan
= new_params
;
7152 if (wpa_s
->conf
->autoscan
== NULL
)
7153 autoscan_deinit(wpa_s
);
7154 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7155 autoscan_init(wpa_s
, 1);
7156 else if (state
== WPA_SCANNING
)
7157 wpa_supplicant_reinit_autoscan(wpa_s
);
7159 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7160 wpa_supplicant_state_txt(state
));
7165 #endif /* CONFIG_AUTOSCAN */
7170 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7176 struct wpabuf
*tfs_req
= NULL
;
7178 if (os_strncmp(cmd
, "enter", 5) == 0)
7180 else if (os_strncmp(cmd
, "exit", 4) == 0)
7185 pos
= os_strstr(cmd
, " interval=");
7187 intval
= atoi(pos
+ 10);
7189 pos
= os_strstr(cmd
, " tfs_req=");
7194 end
= os_strchr(pos
, ' ');
7198 len
= os_strlen(pos
);
7202 tfs_req
= wpabuf_alloc(len
);
7203 if (tfs_req
== NULL
)
7205 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7206 wpabuf_free(tfs_req
);
7211 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7212 WNM_SLEEP_MODE_EXIT
, intval
,
7214 wpabuf_free(tfs_req
);
7220 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7222 int query_reason
, list
= 0;
7223 char *btm_candidates
= NULL
;
7225 query_reason
= atoi(cmd
);
7227 cmd
= os_strchr(cmd
, ' ');
7229 if (os_strncmp(cmd
, " list", 5) == 0)
7232 btm_candidates
= cmd
;
7235 wpa_printf(MSG_DEBUG
,
7236 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7237 query_reason
, list
? " candidate list" : "");
7239 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7244 #endif /* CONFIG_WNM */
7247 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7250 struct wpa_signal_info si
;
7254 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7261 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7262 "NOISE=%d\nFREQUENCY=%u\n",
7263 si
.current_signal
, si
.current_txrate
/ 1000,
7264 si
.current_noise
, si
.frequency
);
7265 if (os_snprintf_error(end
- pos
, ret
))
7269 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7270 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7271 channel_width_to_string(si
.chanwidth
));
7272 if (os_snprintf_error(end
- pos
, ret
))
7277 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
7278 ret
= os_snprintf(pos
, end
- pos
,
7279 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7280 si
.center_frq1
, si
.center_frq2
);
7281 if (os_snprintf_error(end
- pos
, ret
))
7286 if (si
.avg_signal
) {
7287 ret
= os_snprintf(pos
, end
- pos
,
7288 "AVG_RSSI=%d\n", si
.avg_signal
);
7289 if (os_snprintf_error(end
- pos
, ret
))
7294 if (si
.avg_beacon_signal
) {
7295 ret
= os_snprintf(pos
, end
- pos
,
7296 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7297 if (os_snprintf_error(end
- pos
, ret
))
7306 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7313 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7314 wpa_printf(MSG_DEBUG
,
7315 "Reject SIGNAL_MONITOR command - bgscan is active");
7318 pos
= os_strstr(cmd
, "THRESHOLD=");
7320 threshold
= atoi(pos
+ 10);
7321 pos
= os_strstr(cmd
, "HYSTERESIS=");
7323 hysteresis
= atoi(pos
+ 11);
7324 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7328 #ifdef CONFIG_TESTING_OPTIONS
7329 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7330 enum wpa_driver_if_type if_type
,
7332 unsigned int *freq_list
)
7334 char *pos
= wpa_s
->get_pref_freq_list_override
;
7336 unsigned int count
= 0;
7338 /* Override string format:
7339 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7342 if (atoi(pos
) == (int) if_type
)
7344 pos
= os_strchr(pos
, ' ');
7350 pos
= os_strchr(pos
, ':');
7354 end
= os_strchr(pos
, ' ');
7355 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7356 freq_list
[count
++] = atoi(pos
);
7357 pos
= os_strchr(pos
, ',');
7365 #endif /* CONFIG_TESTING_OPTIONS */
7368 static int wpas_ctrl_iface_get_pref_freq_list(
7369 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7371 unsigned int freq_list
[100], num
= 100, i
;
7373 enum wpa_driver_if_type iface_type
;
7379 /* buf: "<interface_type>" */
7380 if (os_strcmp(cmd
, "STATION") == 0)
7381 iface_type
= WPA_IF_STATION
;
7382 else if (os_strcmp(cmd
, "AP") == 0)
7383 iface_type
= WPA_IF_AP_BSS
;
7384 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7385 iface_type
= WPA_IF_P2P_GO
;
7386 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7387 iface_type
= WPA_IF_P2P_CLIENT
;
7388 else if (os_strcmp(cmd
, "IBSS") == 0)
7389 iface_type
= WPA_IF_IBSS
;
7390 else if (os_strcmp(cmd
, "TDLS") == 0)
7391 iface_type
= WPA_IF_TDLS
;
7395 wpa_printf(MSG_DEBUG
,
7396 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7399 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7403 for (i
= 0; i
< num
; i
++) {
7404 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7405 i
> 0 ? "," : "", freq_list
[i
]);
7406 if (os_snprintf_error(end
- pos
, ret
))
7415 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7416 char *buf
, size_t buflen
)
7421 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7422 (long long unsigned) wpa_s
->drv_flags
);
7423 if (os_snprintf_error(buflen
, ret
))
7429 for (i
= 0; i
< 64; i
++) {
7430 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7431 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7432 driver_flag_to_string(1LLU << i
));
7433 if (os_snprintf_error(end
- pos
, ret
))
7443 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7446 struct hostap_sta_driver_data sta
;
7449 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7453 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7454 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7455 if (os_snprintf_error(buflen
, ret
))
7462 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7463 char *buf
, size_t buflen
)
7467 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7469 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7470 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7473 country
[0] = cmd
[8];
7474 country
[1] = cmd
[9];
7476 p2p_set_country(p2p
, country
);
7479 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7480 if (os_snprintf_error(buflen
, ret
))
7485 #endif /* ANDROID */
7488 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7489 char *buf
, size_t buflen
)
7494 unsigned int vendor_id
, subcmd
;
7495 struct wpabuf
*reply
;
7496 size_t data_len
= 0;
7498 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7499 vendor_id
= strtoul(cmd
, &pos
, 16);
7500 if (!isblank((unsigned char) *pos
))
7503 subcmd
= strtoul(pos
, &pos
, 10);
7506 if (!isblank((unsigned char) *pos
++))
7508 data_len
= os_strlen(pos
);
7513 data
= os_malloc(data_len
);
7517 if (hexstr2bin(pos
, data
, data_len
)) {
7518 wpa_printf(MSG_DEBUG
,
7519 "Vendor command: wrong parameter format");
7525 reply
= wpabuf_alloc((buflen
- 1) / 2);
7531 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7535 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7545 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7548 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7549 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7550 #endif /* CONFIG_P2P */
7552 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7554 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7555 wpa_s
->ignore_post_flush_scan_res
= 1;
7557 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7559 * Avoid possible auto connect re-connection on getting
7560 * disconnected due to state flush.
7562 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7566 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7567 wpas_p2p_cancel(p2p_wpa_s
);
7568 p2p_ctrl_flush(p2p_wpa_s
);
7569 wpas_p2p_service_flush(p2p_wpa_s
);
7570 p2p_wpa_s
->global
->p2p_disabled
= 0;
7571 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7572 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7573 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7574 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7575 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7576 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7577 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7578 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7579 #endif /* CONFIG_P2P */
7581 #ifdef CONFIG_WPS_TESTING
7582 wps_version_number
= 0x20;
7583 wps_testing_dummy_cred
= 0;
7584 wps_corrupt_pkhash
= 0;
7585 wps_force_auth_types_in_use
= 0;
7586 wps_force_encr_types_in_use
= 0;
7587 #endif /* CONFIG_WPS_TESTING */
7589 wpa_s
->wps_fragment_size
= 0;
7590 wpas_wps_cancel(wpa_s
);
7591 wps_registrar_flush(wpa_s
->wps
->registrar
);
7592 #endif /* CONFIG_WPS */
7593 wpa_s
->after_wps
= 0;
7594 wpa_s
->known_wps_freq
= 0;
7597 wpas_dpp_deinit(wpa_s
);
7598 #endif /* CONFIG_DPP */
7601 #ifdef CONFIG_TDLS_TESTING
7603 #endif /* CONFIG_TDLS_TESTING */
7604 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7605 wpa_tdls_enable(wpa_s
->wpa
, 1);
7606 #endif /* CONFIG_TDLS */
7608 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7609 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7611 wpa_s
->no_keep_alive
= 0;
7612 wpa_s
->own_disconnect_req
= 0;
7614 os_free(wpa_s
->disallow_aps_bssid
);
7615 wpa_s
->disallow_aps_bssid
= NULL
;
7616 wpa_s
->disallow_aps_bssid_count
= 0;
7617 os_free(wpa_s
->disallow_aps_ssid
);
7618 wpa_s
->disallow_aps_ssid
= NULL
;
7619 wpa_s
->disallow_aps_ssid_count
= 0;
7621 wpa_s
->set_sta_uapsd
= 0;
7622 wpa_s
->sta_uapsd
= 0;
7624 wpa_drv_radio_disable(wpa_s
, 0);
7625 wpa_blacklist_clear(wpa_s
);
7626 wpa_s
->extra_blacklist_count
= 0;
7627 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7628 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7629 wpa_config_flush_blobs(wpa_s
->conf
);
7630 wpa_s
->conf
->auto_interworking
= 0;
7631 wpa_s
->conf
->okc
= 0;
7633 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7634 rsn_preauth_deinit(wpa_s
->wpa
);
7636 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7637 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7638 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7639 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7641 radio_remove_works(wpa_s
, NULL
, 1);
7642 wpa_s
->ext_work_in_progress
= 0;
7644 wpa_s
->next_ssid
= NULL
;
7646 #ifdef CONFIG_INTERWORKING
7648 hs20_cancel_fetch_osu(wpa_s
);
7649 hs20_del_icon(wpa_s
, NULL
, NULL
);
7650 #endif /* CONFIG_HS20 */
7651 #endif /* CONFIG_INTERWORKING */
7653 wpa_s
->ext_mgmt_frame_handling
= 0;
7654 wpa_s
->ext_eapol_frame_io
= 0;
7655 #ifdef CONFIG_TESTING_OPTIONS
7656 wpa_s
->extra_roc_dur
= 0;
7657 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7658 wpa_s
->p2p_go_csa_on_inv
= 0;
7659 wpa_s
->ignore_auth_resp
= 0;
7660 wpa_s
->ignore_assoc_disallow
= 0;
7661 wpa_s
->reject_btm_req_reason
= 0;
7662 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7663 os_free(wpa_s
->get_pref_freq_list_override
);
7664 wpa_s
->get_pref_freq_list_override
= NULL
;
7665 #endif /* CONFIG_TESTING_OPTIONS */
7667 wpa_s
->disconnected
= 0;
7668 os_free(wpa_s
->next_scan_freqs
);
7669 wpa_s
->next_scan_freqs
= NULL
;
7670 os_free(wpa_s
->select_network_scan_freqs
);
7671 wpa_s
->select_network_scan_freqs
= NULL
;
7673 wpa_bss_flush(wpa_s
);
7674 if (!dl_list_empty(&wpa_s
->bss
)) {
7675 wpa_printf(MSG_DEBUG
,
7676 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7677 MACSTR
" pending_bssid=" MACSTR
,
7678 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7679 MAC2STR(wpa_s
->bssid
),
7680 MAC2STR(wpa_s
->pending_bssid
));
7683 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7684 wpa_s
->wnmsleep_used
= 0;
7687 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7688 #endif /* CONFIG_SME */
7690 wpabuf_free(wpa_s
->ric_ies
);
7691 wpa_s
->ric_ies
= NULL
;
7695 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7696 char *buf
, size_t buflen
)
7698 struct wpa_radio_work
*work
;
7700 struct os_reltime now
, diff
;
7705 os_get_reltime(&now
);
7707 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7711 os_reltime_sub(&now
, &work
->time
, &diff
);
7712 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7713 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7714 work
->started
, diff
.sec
, diff
.usec
);
7715 if (os_snprintf_error(end
- pos
, ret
))
7724 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7726 struct wpa_radio_work
*work
= eloop_ctx
;
7727 struct wpa_external_work
*ework
= work
->ctx
;
7729 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7730 "Timing out external radio work %u (%s)",
7731 ework
->id
, work
->type
);
7732 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7733 work
->wpa_s
->ext_work_in_progress
= 0;
7734 radio_work_done(work
);
7739 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7741 struct wpa_external_work
*ework
= work
->ctx
;
7745 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7749 * work->type points to a buffer in ework, so need to replace
7750 * that here with a fixed string to avoid use of freed memory
7753 work
->type
= "freed-ext-work";
7759 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7760 ework
->id
, ework
->type
);
7761 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7762 work
->wpa_s
->ext_work_in_progress
= 1;
7763 if (!ework
->timeout
)
7764 ework
->timeout
= 10;
7765 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7770 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7771 char *buf
, size_t buflen
)
7773 struct wpa_external_work
*ework
;
7777 unsigned int freq
= 0;
7779 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7781 ework
= os_zalloc(sizeof(*ework
));
7785 pos
= os_strchr(cmd
, ' ');
7787 type_len
= pos
- cmd
;
7790 pos2
= os_strstr(pos
, "freq=");
7792 freq
= atoi(pos2
+ 5);
7794 pos2
= os_strstr(pos
, "timeout=");
7796 ework
->timeout
= atoi(pos2
+ 8);
7798 type_len
= os_strlen(cmd
);
7800 if (4 + type_len
>= sizeof(ework
->type
))
7801 type_len
= sizeof(ework
->type
) - 4 - 1;
7802 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
7803 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
7804 ework
->type
[4 + type_len
] = '\0';
7806 wpa_s
->ext_work_id
++;
7807 if (wpa_s
->ext_work_id
== 0)
7808 wpa_s
->ext_work_id
++;
7809 ework
->id
= wpa_s
->ext_work_id
;
7811 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
7817 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
7818 if (os_snprintf_error(buflen
, ret
))
7824 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
7826 struct wpa_radio_work
*work
;
7827 unsigned int id
= atoi(cmd
);
7829 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7831 struct wpa_external_work
*ework
;
7833 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7836 if (id
&& ework
->id
!= id
)
7838 wpa_dbg(wpa_s
, MSG_DEBUG
,
7839 "Completed external radio work %u (%s)",
7840 ework
->id
, ework
->type
);
7841 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
7842 wpa_s
->ext_work_in_progress
= 0;
7843 radio_work_done(work
);
7845 return 3; /* "OK\n" */
7852 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
7853 char *buf
, size_t buflen
)
7855 if (os_strcmp(cmd
, "show") == 0)
7856 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
7857 if (os_strncmp(cmd
, "add ", 4) == 0)
7858 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
7859 if (os_strncmp(cmd
, "done ", 5) == 0)
7860 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
7865 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
7867 struct wpa_radio_work
*work
, *tmp
;
7869 if (!wpa_s
|| !wpa_s
->radio
)
7872 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
7873 struct wpa_radio_work
, list
) {
7874 struct wpa_external_work
*ework
;
7876 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7879 wpa_dbg(wpa_s
, MSG_DEBUG
,
7880 "Flushing%s external radio work %u (%s)",
7881 work
->started
? " started" : "", ework
->id
,
7884 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7886 radio_work_done(work
);
7892 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
7894 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7895 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
7899 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
7900 unsigned int *scan_id_count
, int scan_id
[])
7902 const char *pos
= value
;
7905 if (*pos
== ' ' || *pos
== '\0')
7907 if (*scan_id_count
== MAX_SCAN_ID
)
7909 scan_id
[(*scan_id_count
)++] = atoi(pos
);
7910 pos
= os_strchr(pos
, ',');
7919 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
7920 char *reply
, int reply_size
, int *reply_len
)
7923 unsigned int manual_scan_passive
= 0;
7924 unsigned int manual_scan_use_id
= 0;
7925 unsigned int manual_scan_only_new
= 0;
7926 unsigned int scan_only
= 0;
7927 unsigned int scan_id_count
= 0;
7928 int scan_id
[MAX_SCAN_ID
];
7929 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
7930 struct wpa_scan_results
*scan_res
);
7931 int *manual_scan_freqs
= NULL
;
7932 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
7933 unsigned int ssid_count
= 0;
7935 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
7940 if (radio_work_pending(wpa_s
, "scan")) {
7941 wpa_printf(MSG_DEBUG
,
7942 "Pending scan scheduled - reject new request");
7943 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7947 #ifdef CONFIG_INTERWORKING
7948 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
7949 wpa_printf(MSG_DEBUG
,
7950 "Interworking select in progress - reject new scan");
7951 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7954 #endif /* CONFIG_INTERWORKING */
7957 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
7960 pos
= os_strstr(params
, "freq=");
7962 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
7964 if (manual_scan_freqs
== NULL
) {
7970 pos
= os_strstr(params
, "passive=");
7972 manual_scan_passive
= !!atoi(pos
+ 8);
7974 pos
= os_strstr(params
, "use_id=");
7976 manual_scan_use_id
= atoi(pos
+ 7);
7978 pos
= os_strstr(params
, "only_new=1");
7980 manual_scan_only_new
= 1;
7982 pos
= os_strstr(params
, "scan_id=");
7983 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
7990 while (pos
&& *pos
!= '\0') {
7991 if (os_strncmp(pos
, "ssid ", 5) == 0) {
7997 if (*end
== '\0' || *end
== ' ')
8002 ns
= os_realloc_array(
8003 ssid
, ssid_count
+ 1,
8004 sizeof(struct wpa_ssid_value
));
8011 if ((end
- pos
) & 0x01 ||
8012 end
- pos
> 2 * SSID_MAX_LEN
||
8013 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
8014 (end
- pos
) / 2) < 0) {
8015 wpa_printf(MSG_DEBUG
,
8016 "Invalid SSID value '%s'",
8021 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
8022 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
8023 ssid
[ssid_count
].ssid
,
8024 ssid
[ssid_count
].ssid_len
);
8029 pos
= os_strchr(pos
, ' ');
8035 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
8036 os_free(wpa_s
->ssids_from_scan_req
);
8038 wpa_s
->ssids_from_scan_req
= ssid
;
8041 wpa_s
->ssids_from_scan_req
= NULL
;
8045 scan_res_handler
= scan_only_handler
;
8046 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8047 scan_res_handler
= NULL
;
8049 scan_res_handler
= wpa_s
->scan_res_handler
;
8051 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8052 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8053 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8054 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8055 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8056 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8057 wpa_s
->scan_id_count
= scan_id_count
;
8058 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8059 wpa_s
->scan_res_handler
= scan_res_handler
;
8060 os_free(wpa_s
->manual_scan_freqs
);
8061 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8062 manual_scan_freqs
= NULL
;
8064 wpa_s
->normal_scans
= 0;
8065 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8066 wpa_s
->after_wps
= 0;
8067 wpa_s
->known_wps_freq
= 0;
8068 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8069 if (wpa_s
->manual_scan_use_id
) {
8070 wpa_s
->manual_scan_id
++;
8071 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8072 wpa_s
->manual_scan_id
);
8073 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8074 wpa_s
->manual_scan_id
);
8076 } else if (wpa_s
->sched_scanning
) {
8077 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8078 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8079 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8080 wpa_s
->scan_id_count
= scan_id_count
;
8081 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8082 wpa_s
->scan_res_handler
= scan_res_handler
;
8083 os_free(wpa_s
->manual_scan_freqs
);
8084 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8085 manual_scan_freqs
= NULL
;
8087 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8088 wpa_supplicant_cancel_sched_scan(wpa_s
);
8089 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8090 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8091 if (wpa_s
->manual_scan_use_id
) {
8092 wpa_s
->manual_scan_id
++;
8093 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8094 wpa_s
->manual_scan_id
);
8095 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8096 wpa_s
->manual_scan_id
);
8099 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8100 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8104 os_free(manual_scan_freqs
);
8109 #ifdef CONFIG_TESTING_OPTIONS
8111 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8112 unsigned int freq
, const u8
*dst
,
8113 const u8
*src
, const u8
*bssid
,
8114 const u8
*data
, size_t data_len
,
8115 enum offchannel_send_action_result
8118 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8119 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8120 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8121 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8122 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8123 "NO_ACK" : "FAILED"));
8127 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8131 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8133 int freq
= 0, no_cck
= 0, wait_time
= 0;
8135 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8136 * <action=Action frame payload> */
8138 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8141 used
= hwaddr_aton2(pos
, da
);
8147 used
= hwaddr_aton2(pos
, bssid
);
8152 param
= os_strstr(pos
, " freq=");
8158 param
= os_strstr(pos
, " no_cck=");
8161 no_cck
= atoi(param
);
8164 param
= os_strstr(pos
, " wait_time=");
8167 wait_time
= atoi(param
);
8170 param
= os_strstr(pos
, " action=");
8175 len
= os_strlen(param
);
8180 buf
= os_malloc(len
);
8184 if (hexstr2bin(param
, buf
, len
) < 0) {
8189 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8190 buf
, len
, wait_time
,
8191 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8197 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8199 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8200 offchannel_send_action_done(wpa_s
);
8204 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8210 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8211 union wpa_event_data event
;
8213 if (!wpa_s
->ext_mgmt_frame_handling
)
8216 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8218 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8221 param
= os_strstr(pos
, "freq=");
8227 param
= os_strstr(pos
, " datarate=");
8230 datarate
= atoi(param
);
8233 param
= os_strstr(pos
, " ssi_signal=");
8236 ssi_signal
= atoi(param
);
8239 param
= os_strstr(pos
, " frame=");
8244 len
= os_strlen(param
);
8249 buf
= os_malloc(len
);
8253 if (hexstr2bin(param
, buf
, len
) < 0) {
8258 os_memset(&event
, 0, sizeof(event
));
8259 event
.rx_mgmt
.freq
= freq
;
8260 event
.rx_mgmt
.frame
= buf
;
8261 event
.rx_mgmt
.frame_len
= len
;
8262 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8263 event
.rx_mgmt
.datarate
= datarate
;
8264 wpa_s
->ext_mgmt_frame_handling
= 0;
8265 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8266 wpa_s
->ext_mgmt_frame_handling
= 1;
8274 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8277 struct wpa_scan_res
*res
;
8278 struct os_reltime now
;
8285 if (os_strcmp(param
, "START") == 0) {
8286 wpa_bss_update_start(wpa_s
);
8290 if (os_strcmp(param
, "END") == 0) {
8291 wpa_bss_update_end(wpa_s
, NULL
, 1);
8295 if (os_strncmp(param
, "BSS ", 4) != 0)
8299 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8303 pos
= os_strstr(param
, " flags=");
8305 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8307 pos
= os_strstr(param
, " bssid=");
8308 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8311 pos
= os_strstr(param
, " freq=");
8313 res
->freq
= atoi(pos
+ 6);
8315 pos
= os_strstr(param
, " beacon_int=");
8317 res
->beacon_int
= atoi(pos
+ 12);
8319 pos
= os_strstr(param
, " caps=");
8321 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8323 pos
= os_strstr(param
, " qual=");
8325 res
->qual
= atoi(pos
+ 6);
8327 pos
= os_strstr(param
, " noise=");
8329 res
->noise
= atoi(pos
+ 7);
8331 pos
= os_strstr(param
, " level=");
8333 res
->level
= atoi(pos
+ 7);
8335 pos
= os_strstr(param
, " tsf=");
8337 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8339 pos
= os_strstr(param
, " age=");
8341 res
->age
= atoi(pos
+ 5);
8343 pos
= os_strstr(param
, " est_throughput=");
8345 res
->est_throughput
= atoi(pos
+ 16);
8347 pos
= os_strstr(param
, " snr=");
8349 res
->snr
= atoi(pos
+ 5);
8351 pos
= os_strstr(param
, " parent_tsf=");
8353 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8355 pos
= os_strstr(param
, " tsf_bssid=");
8356 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8359 pos
= os_strstr(param
, " ie=");
8362 end
= os_strchr(pos
, ' ');
8364 end
= pos
+ os_strlen(pos
);
8365 res
->ie_len
= (end
- pos
) / 2;
8366 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8370 pos
= os_strstr(param
, " beacon_ie=");
8373 end
= os_strchr(pos
, ' ');
8375 end
= pos
+ os_strlen(pos
);
8376 res
->beacon_ie_len
= (end
- pos
) / 2;
8377 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8378 res
->beacon_ie_len
))
8382 os_get_reltime(&now
);
8383 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8392 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8395 union wpa_event_data event
;
8396 enum wpa_event_type ev
;
8398 /* <event name> [parameters..] */
8400 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8403 param
= os_strchr(pos
, ' ');
8407 os_memset(&event
, 0, sizeof(event
));
8409 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8410 ev
= EVENT_INTERFACE_ENABLED
;
8411 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8412 ev
= EVENT_INTERFACE_DISABLED
;
8413 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8414 ev
= EVENT_AVOID_FREQUENCIES
;
8417 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8419 wpa_supplicant_event(wpa_s
, ev
, &event
);
8420 os_free(event
.freq_range
.range
);
8422 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8423 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8425 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8430 wpa_supplicant_event(wpa_s
, ev
, &event
);
8436 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8439 u8 src
[ETH_ALEN
], *buf
;
8443 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8446 used
= hwaddr_aton2(pos
, src
);
8453 len
= os_strlen(pos
);
8458 buf
= os_malloc(len
);
8462 if (hexstr2bin(pos
, buf
, len
) < 0) {
8467 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8474 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8478 const u16
*pos
= buf
;
8480 for (i
= 0; i
< len
/ 2; i
++)
8484 sum
= (sum
& 0xffff) + (sum
>> 16);
8486 return sum
^ 0xffff;
8490 #define HWSIM_PACKETLEN 1500
8491 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8493 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8496 struct wpa_supplicant
*wpa_s
= ctx
;
8497 const struct ether_header
*eth
;
8502 if (len
!= HWSIM_PACKETLEN
)
8505 eth
= (const struct ether_header
*) buf
;
8506 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8507 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8509 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8510 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8513 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
8519 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
8520 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
8524 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8527 int enabled
= atoi(cmd
);
8532 if (wpa_s
->l2_test
) {
8533 l2_packet_deinit(wpa_s
->l2_test
);
8534 wpa_s
->l2_test
= NULL
;
8535 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8543 pos
= os_strstr(cmd
, " ifname=");
8547 ifname
= wpa_s
->ifname
;
8549 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8550 ETHERTYPE_IP
, wpas_data_test_rx
,
8552 if (wpa_s
->l2_test
== NULL
)
8555 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8561 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8563 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8568 u8 buf
[2 + HWSIM_PACKETLEN
];
8569 struct ether_header
*eth
;
8574 if (wpa_s
->l2_test
== NULL
)
8577 /* format: <dst> <src> <tos> */
8580 used
= hwaddr_aton2(pos
, dst
);
8586 used
= hwaddr_aton2(pos
, src
);
8591 val
= strtol(pos
, NULL
, 0);
8592 if (val
< 0 || val
> 0xff)
8596 eth
= (struct ether_header
*) &buf
[2];
8597 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8598 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8599 eth
->ether_type
= htons(ETHERTYPE_IP
);
8600 ip
= (struct iphdr
*) (eth
+ 1);
8601 os_memset(ip
, 0, sizeof(*ip
));
8606 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8608 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8609 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8610 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8611 dpos
= (u8
*) (ip
+ 1);
8612 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8615 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8616 HWSIM_PACKETLEN
) < 0)
8619 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8620 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8626 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8630 struct ether_header
*eth
;
8631 struct l2_packet_data
*l2
= NULL
;
8636 len
= os_strlen(cmd
);
8637 if (len
& 1 || len
< ETH_HLEN
* 2)
8641 buf
= os_malloc(len
);
8645 if (hexstr2bin(cmd
, buf
, len
) < 0)
8648 eth
= (struct ether_header
*) buf
;
8649 ethertype
= ntohs(eth
->ether_type
);
8651 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8652 wpas_data_test_rx
, wpa_s
, 1);
8656 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8657 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8660 l2_packet_deinit(l2
);
8663 return res
< 0 ? -1 : 0;
8667 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8669 #ifdef WPA_TRACE_BFD
8672 wpa_trace_fail_after
= atoi(cmd
);
8673 pos
= os_strchr(cmd
, ':');
8676 os_strlcpy(wpa_trace_fail_func
, pos
,
8677 sizeof(wpa_trace_fail_func
));
8679 wpa_trace_fail_after
= 0;
8682 #else /* WPA_TRACE_BFD */
8684 #endif /* WPA_TRACE_BFD */
8688 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8689 char *buf
, size_t buflen
)
8691 #ifdef WPA_TRACE_BFD
8692 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8693 wpa_trace_fail_func
);
8694 #else /* WPA_TRACE_BFD */
8696 #endif /* WPA_TRACE_BFD */
8700 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8702 #ifdef WPA_TRACE_BFD
8705 wpa_trace_test_fail_after
= atoi(cmd
);
8706 pos
= os_strchr(cmd
, ':');
8709 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8710 sizeof(wpa_trace_test_fail_func
));
8712 wpa_trace_test_fail_after
= 0;
8715 #else /* WPA_TRACE_BFD */
8717 #endif /* WPA_TRACE_BFD */
8721 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8722 char *buf
, size_t buflen
)
8724 #ifdef WPA_TRACE_BFD
8725 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8726 wpa_trace_test_fail_func
);
8727 #else /* WPA_TRACE_BFD */
8729 #endif /* WPA_TRACE_BFD */
8733 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8735 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8736 int i
, count
= (intptr_t) timeout_ctx
;
8738 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8740 for (i
= 0; i
< count
; i
++) {
8741 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8747 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8755 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8756 (void *) (intptr_t) count
);
8760 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8766 len
= os_strlen(cmd
);
8774 buf
= wpabuf_alloc(len
);
8778 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
8784 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
8788 #endif /* CONFIG_TESTING_OPTIONS */
8791 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
8797 struct ieee802_11_elems elems
;
8800 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8802 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8804 pos
= os_strchr(pos
, ' ');
8809 len
= os_strlen(pos
);
8816 buf
= wpabuf_alloc(len
);
8820 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
8825 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
8831 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
8832 wpa_s
->vendor_elem
[frame
] = buf
;
8833 wpas_vendor_elem_update(wpa_s
);
8837 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
8842 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
8844 wpas_vendor_elem_update(wpa_s
);
8850 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
8851 char *buf
, size_t buflen
)
8853 int frame
= atoi(cmd
);
8855 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8857 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8859 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8862 return wpa_snprintf_hex(buf
, buflen
,
8863 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
8864 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
8868 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
8874 struct ieee802_11_elems elems
;
8878 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8880 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8882 pos
= os_strchr(pos
, ' ');
8888 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
8889 wpa_s
->vendor_elem
[frame
] = NULL
;
8890 wpas_vendor_elem_update(wpa_s
);
8894 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8897 len
= os_strlen(pos
);
8904 buf
= os_malloc(len
);
8908 if (hexstr2bin(pos
, buf
, len
) < 0) {
8913 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
8918 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
8924 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
8926 struct wpa_supplicant
*wpa_s
= ctx
;
8931 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
8933 * BSSID Information[4]
8934 * Operating Class[1]
8937 * Optional Subelements[variable]
8939 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
8941 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
8942 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
8946 data
= wpabuf_head_u8(neighbor_rep
);
8947 len
= wpabuf_len(neighbor_rep
);
8949 while (len
>= 2 + NR_IE_MIN_LEN
) {
8951 char lci
[256 * 2 + 1];
8952 char civic
[256 * 2 + 1];
8953 u8 nr_len
= data
[1];
8954 const u8
*pos
= data
, *end
;
8956 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
8957 nr_len
< NR_IE_MIN_LEN
) {
8958 wpa_printf(MSG_DEBUG
,
8959 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
8964 if (2U + nr_len
> len
) {
8965 wpa_printf(MSG_DEBUG
,
8966 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
8967 data
[0], len
, nr_len
);
8974 pos
+= NR_IE_MIN_LEN
;
8978 while (end
- pos
> 2) {
8983 if (s_len
> end
- pos
)
8985 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
8986 /* Measurement Token[1] */
8987 /* Measurement Report Mode[1] */
8988 /* Measurement Type[1] */
8989 /* Measurement Report[variable] */
8991 case MEASURE_TYPE_LCI
:
8994 wpa_snprintf_hex(lci
, sizeof(lci
),
8997 case MEASURE_TYPE_LOCATION_CIVIC
:
9000 wpa_snprintf_hex(civic
, sizeof(civic
),
9009 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
9011 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9012 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
9013 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
9015 lci
[0] ? " lci=" : "", lci
,
9016 civic
[0] ? " civic=" : "", civic
);
9023 wpabuf_free(neighbor_rep
);
9027 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
9030 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
9031 int ret
, lci
= 0, civic
= 0;
9034 ssid_s
= os_strstr(cmd
, "ssid=");
9036 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
9037 wpa_printf(MSG_ERROR
,
9038 "CTRL: Send Neighbor Report: bad SSID");
9045 * Move cmd after the SSID text that may include "lci" or
9048 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9054 if (cmd
&& os_strstr(cmd
, "lci"))
9057 if (cmd
&& os_strstr(cmd
, "civic"))
9060 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9061 wpas_ctrl_neighbor_rep_cb
,
9068 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9070 eapol_sm_erp_flush(wpa_s
->eapol
);
9075 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9078 char *token
, *context
= NULL
;
9079 unsigned int enable
= ~0, type
= 0;
9080 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9081 u8
*addr
= NULL
, *mask
= NULL
;
9083 while ((token
= str_token(cmd
, " ", &context
))) {
9084 if (os_strcasecmp(token
, "scan") == 0) {
9085 type
|= MAC_ADDR_RAND_SCAN
;
9086 } else if (os_strcasecmp(token
, "sched") == 0) {
9087 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9088 } else if (os_strcasecmp(token
, "pno") == 0) {
9089 type
|= MAC_ADDR_RAND_PNO
;
9090 } else if (os_strcasecmp(token
, "all") == 0) {
9091 type
= wpa_s
->mac_addr_rand_supported
;
9092 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9093 enable
= atoi(token
+ 7);
9094 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9096 if (hwaddr_aton(token
+ 5, addr
)) {
9097 wpa_printf(MSG_INFO
,
9098 "CTRL: Invalid MAC address: %s",
9102 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9104 if (hwaddr_aton(token
+ 5, mask
)) {
9105 wpa_printf(MSG_INFO
,
9106 "CTRL: Invalid MAC address mask: %s",
9111 wpa_printf(MSG_INFO
,
9112 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9119 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9123 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
9124 wpa_printf(MSG_INFO
,
9125 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9126 type
, wpa_s
->mac_addr_rand_supported
);
9131 wpa_printf(MSG_INFO
,
9132 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9137 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
9139 if (type
& MAC_ADDR_RAND_PNO
) {
9140 wpas_stop_pno(wpa_s
);
9141 wpas_start_pno(wpa_s
);
9143 } else if (wpa_s
->sched_scanning
&&
9144 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
9145 wpas_scan_restart_sched_scan(wpa_s
);
9150 if ((addr
&& !mask
) || (!addr
&& mask
)) {
9151 wpa_printf(MSG_INFO
,
9152 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9156 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
9157 wpa_printf(MSG_INFO
,
9158 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9162 if (type
& MAC_ADDR_RAND_SCAN
) {
9163 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
9167 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
9168 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
9171 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
9172 wpas_scan_restart_sched_scan(wpa_s
);
9175 if (type
& MAC_ADDR_RAND_PNO
) {
9176 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
9179 wpas_stop_pno(wpa_s
);
9180 wpas_start_pno(wpa_s
);
9188 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9189 char *buf
, size_t buflen
)
9193 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9195 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9196 buflen
- reply_len
);
9197 #endif /* CONFIG_AP */
9202 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9204 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9206 wpas_ap_pmksa_cache_flush(wpa_s
);
9207 #endif /* CONFIG_AP */
9211 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9213 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9214 const char *cmd
, char *buf
, size_t buflen
)
9216 struct rsn_pmksa_cache_entry
*entry
;
9217 struct wpa_ssid
*ssid
;
9218 char *pos
, *pos2
, *end
;
9220 struct os_reltime now
;
9222 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9229 os_get_reltime(&now
);
9233 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9234 * <expiration in seconds> <akmp> <opportunistic>
9235 * [FILS Cache Identifier]
9238 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9239 entry
= entry
->next
) {
9240 if (entry
->network_ctx
!= ssid
)
9244 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9245 MAC2STR(entry
->aa
));
9246 if (os_snprintf_error(end
- pos2
, ret
))
9250 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9253 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9254 if (os_snprintf_error(end
- pos2
, ret
))
9258 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9261 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9262 (int) (entry
->reauth_time
- now
.sec
),
9263 (int) (entry
->expiration
- now
.sec
),
9265 entry
->opportunistic
);
9266 if (os_snprintf_error(end
- pos2
, ret
))
9270 if (entry
->fils_cache_id_set
) {
9271 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9272 entry
->fils_cache_id
[0],
9273 entry
->fils_cache_id
[1]);
9274 if (os_snprintf_error(end
- pos2
, ret
))
9279 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9280 if (os_snprintf_error(end
- pos2
, ret
))
9291 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9294 struct rsn_pmksa_cache_entry
*entry
;
9295 struct wpa_ssid
*ssid
;
9298 struct os_reltime now
;
9299 int reauth_time
= 0, expiration
= 0, i
;
9303 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9304 * <expiration in seconds> <akmp> <opportunistic>
9305 * [FILS Cache Identifier]
9308 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9312 pos
= os_strchr(cmd
, ' ');
9317 entry
= os_zalloc(sizeof(*entry
));
9321 if (hwaddr_aton(pos
, entry
->aa
))
9324 pos
= os_strchr(pos
, ' ');
9329 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9332 pos
= os_strchr(pos
, ' ');
9337 pos2
= os_strchr(pos
, ' ');
9340 entry
->pmk_len
= (pos2
- pos
) / 2;
9341 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9342 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9345 pos
= os_strchr(pos
, ' ');
9350 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9351 &entry
->akmp
, &entry
->opportunistic
) != 4)
9353 for (i
= 0; i
< 4; i
++) {
9354 pos
= os_strchr(pos
, ' ');
9363 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9364 FILS_CACHE_ID_LEN
) < 0)
9366 entry
->fils_cache_id_set
= 1;
9368 os_get_reltime(&now
);
9369 entry
->expiration
= now
.sec
+ expiration
;
9370 entry
->reauth_time
= now
.sec
+ reauth_time
;
9372 entry
->network_ctx
= ssid
;
9374 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9385 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9386 const char *cmd
, char *buf
,
9394 if (os_strcasecmp(cmd
, "any") == 0)
9395 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9397 if (hwaddr_aton(cmd
, spa
))
9400 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9404 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9408 * We do not check mesh interface existance because PMKSA should be
9409 * stored before wpa_s->ifmsh creation to suppress commit message
9412 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9415 #endif /* CONFIG_MESH */
9416 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9420 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9423 struct fils_hlp_req
*req
;
9426 /* format: <dst> <packet starting from ethertype> */
9428 req
= os_zalloc(sizeof(*req
));
9432 if (hwaddr_aton(cmd
, req
->dst
))
9435 pos
= os_strchr(cmd
, ' ');
9439 req
->pkt
= wpabuf_parse_bin(pos
);
9443 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9446 wpabuf_free(req
->pkt
);
9450 #endif /* CONFIG_FILS */
9453 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9455 if (os_strcmp(cmd
, "PING") == 0 ||
9456 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9457 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9458 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9459 os_strncmp(cmd
, "STA ", 4) == 0 ||
9460 os_strncmp(cmd
, "STA-", 4) == 0)
9461 return MSG_EXCESSIVE
;
9466 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9467 char *buf
, size_t *resp_len
)
9470 const int reply_size
= 4096;
9473 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9474 os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ||
9475 os_strncmp(buf
, "PMKSA_ADD ", 10) == 0 ||
9476 os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9477 if (wpa_debug_show_keys
)
9478 wpa_dbg(wpa_s
, MSG_DEBUG
,
9479 "Control interface command '%s'", buf
);
9481 wpa_dbg(wpa_s
, MSG_DEBUG
,
9482 "Control interface command '%s [REMOVED]'",
9483 os_strncmp(buf
, WPA_CTRL_RSP
,
9484 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9486 (os_strncmp(buf
, "SET_NETWORK ", 12) == 0 ?
9487 "SET_NETWORK" : "key-add"));
9488 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9489 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9490 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9491 (const u8
*) buf
, os_strlen(buf
));
9493 int level
= wpas_ctrl_cmd_debug_level(buf
);
9494 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9497 reply
= os_malloc(reply_size
);
9498 if (reply
== NULL
) {
9503 os_memcpy(reply
, "OK\n", 3);
9506 if (os_strcmp(buf
, "PING") == 0) {
9507 os_memcpy(reply
, "PONG\n", 5);
9509 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9510 reply_len
= os_strlen(wpa_s
->ifname
);
9511 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9512 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9513 if (wpa_debug_reopen_file() < 0)
9515 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9516 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9517 } else if (os_strcmp(buf
, "MIB") == 0) {
9518 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9519 if (reply_len
>= 0) {
9520 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9522 reply_size
- reply_len
);
9524 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9525 reply_len
= wpa_supplicant_ctrl_iface_status(
9526 wpa_s
, buf
+ 6, reply
, reply_size
);
9527 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9528 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9529 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9530 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9531 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9532 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9533 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9535 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9536 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9539 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9540 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9542 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9543 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9545 #endif /* CONFIG_MESH */
9546 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9547 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9548 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9550 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9551 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9553 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9554 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9556 } else if (os_strcmp(buf
, "LOGON") == 0) {
9557 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9558 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9559 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9560 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9561 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9564 wpas_request_connection(wpa_s
);
9565 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9566 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9567 !wpa_s
->current_ssid
)
9570 wpa_s
->reattach
= 1;
9571 wpas_request_connection(wpa_s
);
9573 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9574 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9576 else if (wpa_s
->disconnected
)
9577 wpas_request_connection(wpa_s
);
9578 #ifdef IEEE8021X_EAPOL
9579 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9580 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9582 #endif /* IEEE8021X_EAPOL */
9583 #ifdef CONFIG_PEERKEY
9584 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
9585 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
9587 #endif /* CONFIG_PEERKEY */
9588 #ifdef CONFIG_IEEE80211R
9589 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9590 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9592 #endif /* CONFIG_IEEE80211R */
9594 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9595 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9597 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9601 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9602 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9604 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9608 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9609 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9612 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9613 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9614 wpa_s
, buf
+ 14, reply
, reply_size
);
9615 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9616 if (wpas_wps_cancel(wpa_s
))
9618 #ifdef CONFIG_WPS_NFC
9619 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
9620 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
9622 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
9623 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
9625 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9626 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9627 wpa_s
, buf
+ 21, reply
, reply_size
);
9628 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
9629 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
9630 wpa_s
, buf
+ 14, reply
, reply_size
);
9631 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
9632 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
9635 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9636 reply_len
= wpas_ctrl_nfc_get_handover_req(
9637 wpa_s
, buf
+ 21, reply
, reply_size
);
9638 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9639 reply_len
= wpas_ctrl_nfc_get_handover_sel(
9640 wpa_s
, buf
+ 21, reply
, reply_size
);
9641 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
9642 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
9644 #endif /* CONFIG_WPS_NFC */
9645 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
9646 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
9649 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
9650 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
9651 wpa_s
, buf
+ 11, reply
, reply_size
);
9652 #endif /* CONFIG_AP */
9653 #ifdef CONFIG_WPS_ER
9654 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
9655 if (wpas_wps_er_start(wpa_s
, NULL
))
9657 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
9658 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
9660 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
9661 wpas_wps_er_stop(wpa_s
);
9662 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
9663 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
9665 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
9666 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
9668 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9670 } else if (ret
== -3) {
9671 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
9673 } else if (ret
== -4) {
9674 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
9678 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
9679 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
9681 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
9682 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
9685 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
9686 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
9688 #ifdef CONFIG_WPS_NFC
9689 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9690 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9691 wpa_s
, buf
+ 24, reply
, reply_size
);
9692 #endif /* CONFIG_WPS_NFC */
9693 #endif /* CONFIG_WPS_ER */
9694 #endif /* CONFIG_WPS */
9695 #ifdef CONFIG_IBSS_RSN
9696 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
9697 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
9699 #endif /* CONFIG_IBSS_RSN */
9701 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
9702 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9703 wpa_s
, buf
+ 19, reply
, reply_size
);
9704 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
9705 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9706 wpa_s
, "", reply
, reply_size
);
9707 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
9708 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
9710 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
9711 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
9714 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
9715 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
9717 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
9718 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
9720 #endif /* CONFIG_MESH */
9722 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
9723 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
9725 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
9726 if (p2p_ctrl_find(wpa_s
, ""))
9728 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
9729 wpas_p2p_stop_find(wpa_s
);
9730 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
9731 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
9733 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
9734 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
9736 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
9737 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
9739 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
9740 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
9742 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
9743 if (p2p_ctrl_listen(wpa_s
, ""))
9745 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
9746 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
9748 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
9749 if (p2p_ctrl_group_add(wpa_s
, ""))
9751 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
9752 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
9754 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
9755 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
9757 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
9758 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
9760 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
9761 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
9762 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
9763 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
9765 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
9766 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
9768 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
9769 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
9771 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
9772 wpas_p2p_sd_service_update(wpa_s
);
9773 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
9774 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
9776 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
9777 wpas_p2p_service_flush(wpa_s
);
9778 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
9779 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
9781 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
9782 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
9784 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
9785 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
9787 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
9788 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
9790 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
9791 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
9793 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
9794 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
9796 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
9797 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
9799 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
9800 p2p_ctrl_flush(wpa_s
);
9801 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
9802 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
9804 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
9805 if (wpas_p2p_cancel(wpa_s
))
9807 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
9808 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
9810 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
9811 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
9813 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
9814 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
9816 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
9817 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
9819 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
9820 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
9822 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
9823 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
9825 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
9826 if (wpas_p2p_lo_stop(wpa_s
))
9828 #endif /* CONFIG_P2P */
9829 #ifdef CONFIG_WIFI_DISPLAY
9830 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
9831 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
9833 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
9834 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
9836 #endif /* CONFIG_WIFI_DISPLAY */
9837 #ifdef CONFIG_INTERWORKING
9838 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
9839 if (interworking_fetch_anqp(wpa_s
) < 0)
9841 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
9842 interworking_stop_fetch_anqp(wpa_s
);
9843 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
9844 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
9846 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
9847 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
9849 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
9850 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
9852 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9855 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
9859 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
9860 if (os_snprintf_error(reply_size
, reply_len
))
9863 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
9864 if (get_anqp(wpa_s
, buf
+ 9) < 0)
9866 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
9867 if (gas_request(wpa_s
, buf
+ 12) < 0)
9869 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
9870 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
9872 #endif /* CONFIG_INTERWORKING */
9874 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
9875 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
9877 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
9878 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
9880 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
9881 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
9883 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
9884 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
9886 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
9887 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
9888 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
9889 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
9891 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
9892 if (hs20_fetch_osu(wpa_s
, 0) < 0)
9894 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
9895 if (hs20_fetch_osu(wpa_s
, 1) < 0)
9897 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
9898 hs20_cancel_fetch_osu(wpa_s
);
9899 #endif /* CONFIG_HS20 */
9900 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
9902 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
9903 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
9907 * Notify response from timeout to allow the control
9908 * interface response to be sent first.
9910 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
9913 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
9914 if (wpa_supplicant_reload_configuration(wpa_s
))
9916 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
9917 wpa_supplicant_terminate_proc(wpa_s
->global
);
9918 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
9919 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
9921 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
9922 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
9923 wpa_s
, buf
+ 9, reply
, reply_size
);
9924 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
9925 reply_len
= wpa_supplicant_ctrl_iface_log_level(
9926 wpa_s
, buf
+ 9, reply
, reply_size
);
9927 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
9928 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9929 wpa_s
, buf
+ 14, reply
, reply_size
);
9930 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
9931 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9932 wpa_s
, NULL
, reply
, reply_size
);
9933 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
9934 wpas_request_disconnection(wpa_s
);
9935 } else if (os_strcmp(buf
, "SCAN") == 0) {
9936 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
9937 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
9938 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
9939 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
9940 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
9941 wpa_s
, reply
, reply_size
);
9942 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
9943 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
9945 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
9946 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
9948 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
9949 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
9951 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
9952 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
9954 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
9955 reply_len
= wpa_supplicant_ctrl_iface_add_network(
9956 wpa_s
, reply
, reply_size
);
9957 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
9958 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
9960 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
9961 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
9963 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
9964 reply_len
= wpa_supplicant_ctrl_iface_get_network(
9965 wpa_s
, buf
+ 12, reply
, reply_size
);
9966 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
9967 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
9970 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
9971 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
9972 wpa_s
, reply
, reply_size
);
9973 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
9974 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
9975 wpa_s
, reply
, reply_size
);
9976 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
9977 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
9979 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
9980 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
9982 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
9983 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
9986 #ifndef CONFIG_NO_CONFIG_WRITE
9987 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
9988 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
9990 #endif /* CONFIG_NO_CONFIG_WRITE */
9991 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
9992 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
9993 wpa_s
, buf
+ 15, reply
, reply_size
);
9994 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
9995 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
9997 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
9998 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
10000 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10001 reply_len
= wpa_supplicant_global_iface_list(
10002 wpa_s
->global
, reply
, reply_size
);
10003 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10004 reply_len
= wpa_supplicant_global_iface_interfaces(
10005 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
10006 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
10007 reply_len
= wpa_supplicant_ctrl_iface_bss(
10008 wpa_s
, buf
+ 4, reply
, reply_size
);
10010 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
10011 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
10012 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
10013 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
10015 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
10016 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
10018 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
10019 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
10021 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
10022 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
10024 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
10025 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
10027 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
10028 if (wpas_ap_stop_ap(wpa_s
))
10030 #endif /* CONFIG_AP */
10031 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10032 wpas_notify_suspend(wpa_s
->global
);
10033 } else if (os_strcmp(buf
, "RESUME") == 0) {
10034 wpas_notify_resume(wpa_s
->global
);
10035 #ifdef CONFIG_TESTING_OPTIONS
10036 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
10037 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
10038 #endif /* CONFIG_TESTING_OPTIONS */
10039 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
10040 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
10042 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
10043 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
10044 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
10045 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
10047 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
10048 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10051 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10052 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10054 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10055 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10057 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10058 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10060 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10061 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10063 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10064 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10067 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10068 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10071 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10072 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10073 wpa_s
, buf
+ 17, reply
, reply_size
);
10074 #endif /* CONFIG_TDLS */
10075 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10076 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10077 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10078 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10080 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10081 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10083 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10084 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10086 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10087 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10089 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10090 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10092 #ifdef CONFIG_AUTOSCAN
10093 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10094 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10096 #endif /* CONFIG_AUTOSCAN */
10097 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10098 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10101 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10102 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10104 #endif /* ANDROID */
10105 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10106 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10108 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10109 pmksa_cache_clear_current(wpa_s
->wpa
);
10110 eapol_sm_request_reauth(wpa_s
->eapol
);
10112 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10113 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10115 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10116 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10118 #endif /* CONFIG_WNM */
10119 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10120 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10121 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10122 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10124 #ifdef CONFIG_TESTING_OPTIONS
10125 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10126 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10128 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10129 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10130 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10131 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10133 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10134 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10136 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10137 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10139 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10140 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10142 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10143 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10145 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10146 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10148 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10149 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10151 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10152 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10153 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10154 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10156 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10157 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10158 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10159 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10161 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10162 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10164 #endif /* CONFIG_TESTING_OPTIONS */
10165 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10166 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10168 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10169 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10171 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10172 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10174 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10175 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10177 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10178 wpas_ctrl_iface_erp_flush(wpa_s
);
10179 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10180 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10182 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10183 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10184 wpa_s
, buf
+ 19, reply
, reply_size
);
10186 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10187 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10189 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10190 wpas_flush_fils_hlp_req(wpa_s
);
10191 #endif /* CONFIG_FILS */
10193 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
10196 res
= wpas_dpp_qr_code(wpa_s
, buf
+ 12);
10200 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10201 if (os_snprintf_error(reply_size
, reply_len
))
10204 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10207 res
= wpas_dpp_bootstrap_gen(wpa_s
, buf
+ 18);
10211 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10212 if (os_snprintf_error(reply_size
, reply_len
))
10215 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10216 if (wpas_dpp_bootstrap_remove(wpa_s
, buf
+ 21) < 0)
10218 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10221 uri
= wpas_dpp_bootstrap_get_uri(wpa_s
, atoi(buf
+ 22));
10225 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
10226 if (os_snprintf_error(reply_size
, reply_len
))
10229 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10230 reply_len
= wpas_dpp_bootstrap_info(wpa_s
, atoi(buf
+ 19),
10231 reply
, reply_size
);
10232 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
10233 if (wpas_dpp_auth_init(wpa_s
, buf
+ 13) < 0)
10235 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
10236 if (wpas_dpp_listen(wpa_s
, buf
+ 11) < 0)
10238 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
10239 wpas_dpp_listen_stop(wpa_s
);
10240 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10243 res
= wpas_dpp_configurator_add(wpa_s
, buf
+ 20);
10247 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10248 if (os_snprintf_error(reply_size
, reply_len
))
10251 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10252 if (wpas_dpp_configurator_remove(wpa_s
, buf
+ 24) < 0)
10254 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
10257 res
= wpas_dpp_pkex_add(wpa_s
, buf
+ 12);
10261 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
10262 if (os_snprintf_error(reply_size
, reply_len
))
10265 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
10266 if (wpas_dpp_pkex_remove(wpa_s
, buf
+ 16) < 0)
10268 #endif /* CONFIG_DPP */
10270 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10274 if (reply_len
< 0) {
10275 os_memcpy(reply
, "FAIL\n", 5);
10279 *resp_len
= reply_len
;
10284 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10287 struct wpa_interface iface
;
10289 struct wpa_supplicant
*wpa_s
;
10290 unsigned int create_iface
= 0;
10291 u8 mac_addr
[ETH_ALEN
];
10292 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10295 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10296 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10298 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10300 os_memset(&iface
, 0, sizeof(iface
));
10303 iface
.ifname
= pos
= cmd
;
10304 pos
= os_strchr(pos
, '\t');
10307 if (iface
.ifname
[0] == '\0')
10312 iface
.confname
= pos
;
10313 pos
= os_strchr(pos
, '\t');
10316 if (iface
.confname
[0] == '\0')
10317 iface
.confname
= NULL
;
10321 iface
.driver
= pos
;
10322 pos
= os_strchr(pos
, '\t');
10325 if (iface
.driver
[0] == '\0')
10326 iface
.driver
= NULL
;
10330 iface
.ctrl_interface
= pos
;
10331 pos
= os_strchr(pos
, '\t');
10334 if (iface
.ctrl_interface
[0] == '\0')
10335 iface
.ctrl_interface
= NULL
;
10339 iface
.driver_param
= pos
;
10340 pos
= os_strchr(pos
, '\t');
10343 if (iface
.driver_param
[0] == '\0')
10344 iface
.driver_param
= NULL
;
10348 iface
.bridge_ifname
= pos
;
10349 pos
= os_strchr(pos
, '\t');
10352 if (iface
.bridge_ifname
[0] == '\0')
10353 iface
.bridge_ifname
= NULL
;
10358 pos
= os_strchr(pos
, '\t');
10364 if (os_strcmp(extra
, "create") == 0) {
10369 if (os_strcmp(pos
, "sta") == 0) {
10370 type
= WPA_IF_STATION
;
10371 } else if (os_strcmp(pos
, "ap") == 0) {
10372 type
= WPA_IF_AP_BSS
;
10374 wpa_printf(MSG_DEBUG
,
10375 "INTERFACE_ADD unsupported interface type: '%s'",
10380 wpa_printf(MSG_DEBUG
,
10381 "INTERFACE_ADD unsupported extra parameter: '%s'",
10387 if (create_iface
) {
10388 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10390 if (!global
->ifaces
)
10392 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10393 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10394 wpa_printf(MSG_ERROR
,
10395 "CTRL_IFACE interface creation failed");
10399 wpa_printf(MSG_DEBUG
,
10400 "CTRL_IFACE interface '%s' created with MAC addr: "
10401 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10404 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10407 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10410 wpa_s
->added_vif
= create_iface
;
10415 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10420 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10423 struct wpa_supplicant
*wpa_s
;
10425 unsigned int delete_iface
;
10427 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10429 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10432 delete_iface
= wpa_s
->added_vif
;
10433 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10434 if (!ret
&& delete_iface
) {
10435 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10437 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10443 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10445 struct wpa_interface_info
*prev
;
10449 iface
= iface
->next
;
10451 os_free(prev
->ifname
);
10452 os_free(prev
->desc
);
10458 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10459 char *buf
, int len
)
10462 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10465 for (i
= 0; wpa_drivers
[i
]; i
++) {
10466 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10467 if (drv
->get_interfaces
== NULL
)
10469 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10474 iface
= last
= tmp
;
10483 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10484 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10485 tmp
->drv_name
, tmp
->ifname
,
10486 tmp
->desc
? tmp
->desc
: "");
10487 if (os_snprintf_error(end
- pos
, res
)) {
10494 wpa_free_iface_info(iface
);
10500 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10502 char *buf
, int len
)
10506 struct wpa_supplicant
*wpa_s
;
10510 show_ctrl
= !!os_strstr(input
, "ctrl");
10512 wpa_s
= global
->ifaces
;
10518 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10520 wpa_s
->conf
->ctrl_interface
?
10521 wpa_s
->conf
->ctrl_interface
: "N/A");
10523 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10526 if (os_snprintf_error(end
- pos
, res
)) {
10531 wpa_s
= wpa_s
->next
;
10537 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10538 const char *ifname
,
10539 char *cmd
, size_t *resp_len
)
10541 struct wpa_supplicant
*wpa_s
;
10543 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10544 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10548 if (wpa_s
== NULL
) {
10549 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10551 *resp_len
= os_strlen(resp
);
10557 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10561 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10562 char *buf
, size_t *resp_len
)
10565 static const char * cmd
[] = {
10571 "P2P_GET_PASSPHRASE",
10572 "P2P_SERVICE_UPDATE",
10573 "P2P_SERVICE_FLUSH",
10576 "P2P_PRESENCE_REQ",
10580 #endif /* CONFIG_AP */
10583 static const char * prefix
[] = {
10586 #endif /* ANDROID */
10593 "P2P_GROUP_REMOVE ",
10595 "P2P_GROUP_MEMBER ",
10597 "P2P_SERV_DISC_REQ ",
10598 "P2P_SERV_DISC_CANCEL_REQ ",
10599 "P2P_SERV_DISC_RESP ",
10600 "P2P_SERV_DISC_EXTERNAL ",
10601 "P2P_SERVICE_ADD ",
10602 "P2P_SERVICE_DEL ",
10603 "P2P_SERVICE_REP ",
10608 "P2P_UNAUTHORIZE ",
10609 "P2P_PRESENCE_REQ ",
10611 "P2P_REMOVE_CLIENT ",
10613 "WPS_NFC_TAG_READ ",
10614 "NFC_GET_HANDOVER_SEL ",
10615 "NFC_GET_HANDOVER_REQ ",
10616 "NFC_REPORT_HANDOVER ",
10617 "P2P_ASP_PROVISION ",
10618 "P2P_ASP_PROVISION_RESP ",
10622 #endif /* CONFIG_AP */
10628 if (global
->p2p_init_wpa_s
== NULL
)
10631 for (i
= 0; !found
&& cmd
[i
]; i
++) {
10632 if (os_strcmp(buf
, cmd
[i
]) == 0)
10636 for (i
= 0; !found
&& prefix
[i
]; i
++) {
10637 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
10642 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10644 #endif /* CONFIG_P2P */
10649 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
10650 char *buf
, size_t *resp_len
)
10652 #ifdef CONFIG_WIFI_DISPLAY
10653 if (global
->p2p_init_wpa_s
== NULL
)
10655 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
10656 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
10657 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10659 #endif /* CONFIG_WIFI_DISPLAY */
10664 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
10665 char *buf
, size_t *resp_len
)
10669 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
10673 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
10681 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
10685 value
= os_strchr(cmd
, ' ');
10690 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
10692 #ifdef CONFIG_WIFI_DISPLAY
10693 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
10694 wifi_display_enable(global
, !!atoi(value
));
10697 #endif /* CONFIG_WIFI_DISPLAY */
10699 /* Restore cmd to its original value to allow redirection */
10706 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
10709 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
10713 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
10714 * <variable name> */
10716 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
10717 p
= os_strchr(cmd
, ' ');
10722 wpa_s
[i
] = global
->ifaces
;
10723 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
10724 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
10729 wpa_printf(MSG_DEBUG
,
10730 "CTRL_IFACE: Could not find iface=%s", cmd
);
10737 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
10741 #ifndef CONFIG_NO_CONFIG_WRITE
10742 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
10744 int ret
= 0, saved
= 0;
10745 struct wpa_supplicant
*wpa_s
;
10747 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10748 if (!wpa_s
->conf
->update_config
) {
10749 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
10753 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
10754 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
10757 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
10762 if (!saved
&& !ret
) {
10763 wpa_dbg(wpa_s
, MSG_DEBUG
,
10764 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
10770 #endif /* CONFIG_NO_CONFIG_WRITE */
10773 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
10774 char *buf
, size_t buflen
)
10778 struct wpa_supplicant
*wpa_s
;
10781 end
= buf
+ buflen
;
10784 if (global
->p2p
&& !global
->p2p_disabled
) {
10785 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
10788 MAC2STR(global
->p2p_dev_addr
),
10789 p2p_get_state_txt(global
->p2p
));
10790 if (os_snprintf_error(end
- pos
, ret
))
10793 } else if (global
->p2p
) {
10794 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
10795 if (os_snprintf_error(end
- pos
, ret
))
10799 #endif /* CONFIG_P2P */
10801 #ifdef CONFIG_WIFI_DISPLAY
10802 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
10803 !!global
->wifi_display
);
10804 if (os_snprintf_error(end
- pos
, ret
))
10807 #endif /* CONFIG_WIFI_DISPLAY */
10809 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10810 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
10811 "address=" MACSTR
"\n",
10812 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
10813 if (os_snprintf_error(end
- pos
, ret
))
10824 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
10825 char *cmd
, char *buf
,
10828 char ifname
[IFNAMSIZ
+ 1];
10829 struct fst_iface_cfg cfg
;
10830 struct wpa_supplicant
*wpa_s
;
10831 struct fst_wpa_obj iface_obj
;
10833 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
10834 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10837 wpa_printf(MSG_INFO
, "FST: Already attached");
10840 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
10841 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
10844 return os_snprintf(buf
, reply_size
, "OK\n");
10852 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
10853 char *cmd
, char *buf
,
10856 char ifname
[IFNAMSIZ
+ 1];
10857 struct wpa_supplicant
*wpa_s
;
10859 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
10860 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10862 if (!fst_iface_detach(ifname
)) {
10864 return os_snprintf(buf
, reply_size
, "OK\n");
10872 #endif /* CONFIG_FST */
10875 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
10876 char *buf
, size_t *resp_len
)
10879 const int reply_size
= 2048;
10881 int level
= MSG_DEBUG
;
10883 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
10884 char *pos
= os_strchr(buf
+ 7, ' ');
10887 return wpas_global_ctrl_iface_ifname(global
,
10893 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
10897 if (os_strcmp(buf
, "PING") == 0)
10898 level
= MSG_EXCESSIVE
;
10899 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
10900 (const u8
*) buf
, os_strlen(buf
));
10902 reply
= os_malloc(reply_size
);
10903 if (reply
== NULL
) {
10908 os_memcpy(reply
, "OK\n", 3);
10911 if (os_strcmp(buf
, "PING") == 0) {
10912 os_memcpy(reply
, "PONG\n", 5);
10914 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
10915 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
10917 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
10918 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
10920 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10921 reply_len
= wpa_supplicant_global_iface_list(
10922 global
, reply
, reply_size
);
10923 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10924 reply_len
= wpa_supplicant_global_iface_interfaces(
10925 global
, buf
+ 10, reply
, reply_size
);
10927 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
10928 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
10931 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
10932 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
10935 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
10936 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
10937 #endif /* CONFIG_FST */
10938 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10939 wpa_supplicant_terminate_proc(global
);
10940 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10941 wpas_notify_suspend(global
);
10942 } else if (os_strcmp(buf
, "RESUME") == 0) {
10943 wpas_notify_resume(global
);
10944 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10945 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
10947 if (global
->p2p_init_wpa_s
) {
10949 /* Check if P2P redirection would work for this
10951 return wpa_supplicant_ctrl_iface_process(
10952 global
->p2p_init_wpa_s
,
10955 #endif /* CONFIG_P2P */
10958 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10959 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
10961 #ifndef CONFIG_NO_CONFIG_WRITE
10962 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10963 if (wpas_global_ctrl_iface_save_config(global
))
10965 #endif /* CONFIG_NO_CONFIG_WRITE */
10966 } else if (os_strcmp(buf
, "STATUS") == 0) {
10967 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
10969 #ifdef CONFIG_MODULE_TESTS
10970 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
10971 if (wpas_module_tests() < 0)
10973 #endif /* CONFIG_MODULE_TESTS */
10974 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10975 if (wpa_debug_reopen_file() < 0)
10978 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10982 if (reply_len
< 0) {
10983 os_memcpy(reply
, "FAIL\n", 5);
10987 *resp_len
= reply_len
;