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"
56 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
58 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
61 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
64 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
67 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
74 if (hwaddr_aton(pos
, addr
)) {
78 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
84 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
87 pos
= os_strchr(pos
, ' ');
92 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
93 os_free(wpa_s
->bssid_filter
);
94 wpa_s
->bssid_filter
= filter
;
95 wpa_s
->bssid_filter_count
= count
;
101 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
104 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
105 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
106 size_t count
= 0, ssid_count
= 0;
110 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
111 * SSID_SPEC ::= ssid <SSID_HEX>
112 * BSSID_SPEC ::= bssid <BSSID_HEX>
119 if (os_strncmp(pos
, "bssid ", 6) == 0) {
122 res
= hwaddr_aton2(pos
, addr
);
126 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
127 "BSSID value '%s'", pos
);
131 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
138 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
140 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
146 if (*end
== '\0' || *end
== ' ')
151 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
152 sizeof(struct wpa_ssid_value
));
160 if ((end
- pos
) & 0x01 ||
161 end
- pos
> 2 * SSID_MAX_LEN
||
162 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
163 (end
- pos
) / 2) < 0) {
166 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
167 "SSID value '%s'", pos
);
170 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
171 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
172 ssid
[ssid_count
].ssid
,
173 ssid
[ssid_count
].ssid_len
);
177 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
184 pos
= os_strchr(pos
, ' ');
189 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
190 os_free(wpa_s
->disallow_aps_bssid
);
191 wpa_s
->disallow_aps_bssid
= bssid
;
192 wpa_s
->disallow_aps_bssid_count
= count
;
194 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
195 os_free(wpa_s
->disallow_aps_ssid
);
196 wpa_s
->disallow_aps_ssid
= ssid
;
197 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
199 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
202 c
= wpa_s
->current_ssid
;
203 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
206 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
207 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
210 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
211 "because current AP was marked disallowed");
214 wpa_s
->sme
.prev_bssid_set
= 0;
215 #endif /* CONFIG_SME */
216 wpa_s
->reassociate
= 1;
217 wpa_s
->own_disconnect_req
= 1;
218 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
219 wpa_supplicant_req_scan(wpa_s
, 0, 0);
225 #ifndef CONFIG_NO_CONFIG_BLOBS
226 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
229 struct wpa_config_blob
*blob
;
232 pos
= os_strchr(pos
, ' ');
236 len
= os_strlen(pos
);
240 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
241 blob
= os_zalloc(sizeof(*blob
));
244 blob
->name
= os_strdup(name
);
245 blob
->data
= os_malloc(len
/ 2);
246 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
247 wpa_config_free_blob(blob
);
251 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
252 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
253 wpa_config_free_blob(blob
);
258 wpa_config_set_blob(wpa_s
->conf
, blob
);
262 #endif /* CONFIG_NO_CONFIG_BLOBS */
265 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
273 params
= os_strchr(cmd
, ' ');
274 os_free(wpa_s
->manual_sched_scan_freqs
);
277 pos
= os_strstr(params
, "freq=");
279 freqs
= freq_range_to_channel_list(wpa_s
,
282 wpa_s
->manual_sched_scan_freqs
= freqs
;
283 ret
= wpas_start_pno(wpa_s
);
285 ret
= wpas_stop_pno(wpa_s
);
291 static int wpas_ctrl_set_band(struct wpa_supplicant
*wpa_s
, char *band
)
293 union wpa_event_data event
;
295 if (os_strcmp(band
, "AUTO") == 0)
296 wpa_s
->setband
= WPA_SETBAND_AUTO
;
297 else if (os_strcmp(band
, "5G") == 0)
298 wpa_s
->setband
= WPA_SETBAND_5G
;
299 else if (os_strcmp(band
, "2G") == 0)
300 wpa_s
->setband
= WPA_SETBAND_2G
;
304 if (wpa_drv_setband(wpa_s
, wpa_s
->setband
) == 0) {
305 os_memset(&event
, 0, sizeof(event
));
306 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
307 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
308 wpa_supplicant_event(wpa_s
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
315 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant
*wpa_s
,
320 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
321 wpabuf_free(wpa_s
->lci
);
326 lci
= wpabuf_parse_bin(cmd
);
330 if (os_get_reltime(&wpa_s
->lci_time
)) {
335 wpabuf_free(wpa_s
->lci
);
343 wpas_ctrl_set_relative_rssi(struct wpa_supplicant
*wpa_s
, const char *cmd
)
347 if (os_strcmp(cmd
, "disable") == 0) {
348 wpa_s
->srp
.relative_rssi_set
= 0;
352 relative_rssi
= atoi(cmd
);
353 if (relative_rssi
< 0 || relative_rssi
> 100)
355 wpa_s
->srp
.relative_rssi
= relative_rssi
;
356 wpa_s
->srp
.relative_rssi_set
= 1;
361 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant
*wpa_s
,
367 /* <band>:adjust_value */
368 pos
= os_strchr(cmd
, ':');
372 adjust_rssi
= atoi(pos
);
373 if (adjust_rssi
< -100 || adjust_rssi
> 100)
376 if (os_strncmp(cmd
, "2G", 2) == 0)
377 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_2G
;
378 else if (os_strncmp(cmd
, "5G", 2) == 0)
379 wpa_s
->srp
.relative_adjust_band
= WPA_SETBAND_5G
;
383 wpa_s
->srp
.relative_adjust_rssi
= adjust_rssi
;
389 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant
*wpa_s
,
392 struct wpabuf
*ric_ies
;
394 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
395 wpabuf_free(wpa_s
->ric_ies
);
396 wpa_s
->ric_ies
= NULL
;
400 ric_ies
= wpabuf_parse_bin(cmd
);
404 wpabuf_free(wpa_s
->ric_ies
);
405 wpa_s
->ric_ies
= ric_ies
;
411 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
417 value
= os_strchr(cmd
, ' ');
422 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
423 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
424 eapol_sm_configure(wpa_s
->eapol
,
425 atoi(value
), -1, -1, -1);
426 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
427 eapol_sm_configure(wpa_s
->eapol
,
428 -1, atoi(value
), -1, -1);
429 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
430 eapol_sm_configure(wpa_s
->eapol
,
431 -1, -1, atoi(value
), -1);
432 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
433 eapol_sm_configure(wpa_s
->eapol
,
434 -1, -1, -1, atoi(value
));
435 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
436 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
441 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
443 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
445 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
450 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
452 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
453 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
458 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
460 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
461 wpa_s
->wps_fragment_size
= atoi(value
);
462 #ifdef CONFIG_WPS_TESTING
463 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
465 val
= strtol(value
, NULL
, 0);
466 if (val
< 0 || val
> 0xff) {
468 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
469 "wps_version_number %ld", val
);
471 wps_version_number
= val
;
472 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
474 (wps_version_number
& 0xf0) >> 4,
475 wps_version_number
& 0x0f);
477 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
478 wps_testing_dummy_cred
= atoi(value
);
479 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
480 wps_testing_dummy_cred
);
481 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
482 wps_corrupt_pkhash
= atoi(value
);
483 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
485 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
486 if (value
[0] == '\0') {
487 wps_force_auth_types_in_use
= 0;
489 wps_force_auth_types
= strtol(value
, NULL
, 0);
490 wps_force_auth_types_in_use
= 1;
492 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
493 if (value
[0] == '\0') {
494 wps_force_encr_types_in_use
= 0;
496 wps_force_encr_types
= strtol(value
, NULL
, 0);
497 wps_force_encr_types_in_use
= 1;
499 #endif /* CONFIG_WPS_TESTING */
500 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
501 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
504 #ifdef CONFIG_TDLS_TESTING
505 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
506 tdls_testing
= strtol(value
, NULL
, 0);
507 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
508 #endif /* CONFIG_TDLS_TESTING */
509 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
510 int disabled
= atoi(value
);
511 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
513 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
515 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
517 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
518 #endif /* CONFIG_TDLS */
519 } else if (os_strcasecmp(cmd
, "pno") == 0) {
520 ret
= wpas_ctrl_pno(wpa_s
, value
);
521 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
522 int disabled
= atoi(value
);
523 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
526 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
527 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
528 if (os_strcmp(value
, "disable") == 0)
529 wpa_s
->set_sta_uapsd
= 0;
533 /* format: BE,BK,VI,VO;max SP Length */
535 pos
= os_strchr(value
, ',');
540 pos
= os_strchr(pos
, ',');
545 pos
= os_strchr(pos
, ',');
550 /* ignore max SP Length for now */
552 wpa_s
->set_sta_uapsd
= 1;
553 wpa_s
->sta_uapsd
= 0;
555 wpa_s
->sta_uapsd
|= BIT(0);
557 wpa_s
->sta_uapsd
|= BIT(1);
559 wpa_s
->sta_uapsd
|= BIT(2);
561 wpa_s
->sta_uapsd
|= BIT(3);
563 } else if (os_strcasecmp(cmd
, "ps") == 0) {
564 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
565 #ifdef CONFIG_WIFI_DISPLAY
566 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
567 int enabled
= !!atoi(value
);
568 if (enabled
&& !wpa_s
->global
->p2p
)
571 wifi_display_enable(wpa_s
->global
, enabled
);
572 #endif /* CONFIG_WIFI_DISPLAY */
573 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
574 ret
= set_bssid_filter(wpa_s
, value
);
575 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
576 ret
= set_disallow_aps(wpa_s
, value
);
577 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
578 wpa_s
->no_keep_alive
= !!atoi(value
);
579 #ifdef CONFIG_TESTING_OPTIONS
580 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
581 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
582 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
583 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
585 if (wpa_s
->ap_iface
) {
586 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
587 wpa_s
->ext_eapol_frame_io
;
589 #endif /* CONFIG_AP */
590 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
591 wpa_s
->extra_roc_dur
= atoi(value
);
592 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
593 wpa_s
->test_failure
= atoi(value
);
594 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
595 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
596 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
597 wpa_s
->ignore_auth_resp
= !!atoi(value
);
598 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
599 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
600 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
601 wpa_s
->reject_btm_req_reason
= atoi(value
);
602 } else if (os_strcasecmp(cmd
, "get_pref_freq_list_override") == 0) {
603 os_free(wpa_s
->get_pref_freq_list_override
);
605 wpa_s
->get_pref_freq_list_override
= NULL
;
607 wpa_s
->get_pref_freq_list_override
= os_strdup(value
);
608 #endif /* CONFIG_TESTING_OPTIONS */
609 #ifndef CONFIG_NO_CONFIG_BLOBS
610 } else if (os_strcmp(cmd
, "blob") == 0) {
611 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
612 #endif /* CONFIG_NO_CONFIG_BLOBS */
613 } else if (os_strcasecmp(cmd
, "setband") == 0) {
614 ret
= wpas_ctrl_set_band(wpa_s
, value
);
616 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
617 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
620 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
622 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
623 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
624 #endif /* CONFIG_MBO */
625 } else if (os_strcasecmp(cmd
, "lci") == 0) {
626 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
627 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
628 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
629 } else if (os_strcasecmp(cmd
, "relative_rssi") == 0) {
630 ret
= wpas_ctrl_set_relative_rssi(wpa_s
, value
);
631 } else if (os_strcasecmp(cmd
, "relative_band_adjust") == 0) {
632 ret
= wpas_ctrl_set_relative_band_adjust(wpa_s
, value
);
633 } else if (os_strcasecmp(cmd
, "ric_ies") == 0) {
634 ret
= wpas_ctrl_iface_set_ric_ies(wpa_s
, value
);
637 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
639 wpa_supplicant_update_config(wpa_s
);
646 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
647 char *cmd
, char *buf
, size_t buflen
)
651 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
653 if (os_strcmp(cmd
, "version") == 0) {
654 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
655 } else if (os_strcasecmp(cmd
, "country") == 0) {
656 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
657 res
= os_snprintf(buf
, buflen
, "%c%c",
658 wpa_s
->conf
->country
[0],
659 wpa_s
->conf
->country
[1]);
660 #ifdef CONFIG_WIFI_DISPLAY
661 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
663 if (wpa_s
->global
->p2p
== NULL
||
664 wpa_s
->global
->p2p_disabled
)
667 enabled
= wpa_s
->global
->wifi_display
;
668 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
669 #endif /* CONFIG_WIFI_DISPLAY */
670 #ifdef CONFIG_TESTING_GET_GTK
671 } else if (os_strcmp(cmd
, "gtk") == 0) {
672 if (wpa_s
->last_gtk_len
== 0)
674 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
675 wpa_s
->last_gtk_len
);
677 #endif /* CONFIG_TESTING_GET_GTK */
678 } else if (os_strcmp(cmd
, "tls_library") == 0) {
679 res
= tls_get_library_version(buf
, buflen
);
681 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
684 if (os_snprintf_error(buflen
, res
))
690 #ifdef IEEE8021X_EAPOL
691 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
695 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
697 if (hwaddr_aton(addr
, bssid
)) {
698 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
703 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
704 rsn_preauth_deinit(wpa_s
->wpa
);
705 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
710 #endif /* IEEE8021X_EAPOL */
713 #ifdef CONFIG_PEERKEY
714 /* MLME-STKSTART.request(peer) */
715 static int wpa_supplicant_ctrl_iface_stkstart(
716 struct wpa_supplicant
*wpa_s
, char *addr
)
720 if (hwaddr_aton(addr
, peer
)) {
721 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
722 "address '%s'", addr
);
726 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
729 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
731 #endif /* CONFIG_PEERKEY */
736 static int wpa_supplicant_ctrl_iface_tdls_discover(
737 struct wpa_supplicant
*wpa_s
, char *addr
)
742 if (hwaddr_aton(addr
, peer
)) {
743 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
744 "address '%s'", addr
);
748 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
751 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
752 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
754 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
760 static int wpa_supplicant_ctrl_iface_tdls_setup(
761 struct wpa_supplicant
*wpa_s
, char *addr
)
766 if (hwaddr_aton(addr
, peer
)) {
767 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
768 "address '%s'", addr
);
772 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
775 if ((wpa_s
->conf
->tdls_external_control
) &&
776 wpa_tdls_is_external_setup(wpa_s
->wpa
))
777 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
779 wpa_tdls_remove(wpa_s
->wpa
, peer
);
781 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
782 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
784 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
790 static int wpa_supplicant_ctrl_iface_tdls_teardown(
791 struct wpa_supplicant
*wpa_s
, char *addr
)
796 if (os_strcmp(addr
, "*") == 0) {
797 /* remove everyone */
798 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
799 wpa_tdls_teardown_peers(wpa_s
->wpa
);
803 if (hwaddr_aton(addr
, peer
)) {
804 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
805 "address '%s'", addr
);
809 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
812 if ((wpa_s
->conf
->tdls_external_control
) &&
813 wpa_tdls_is_external_setup(wpa_s
->wpa
))
814 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
816 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
817 ret
= wpa_tdls_teardown_link(
819 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
821 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
827 static int ctrl_iface_get_capability_tdls(
828 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
832 ret
= os_snprintf(buf
, buflen
, "%s\n",
833 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
835 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
836 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
837 if (os_snprintf_error(buflen
, ret
))
843 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
844 struct wpa_supplicant
*wpa_s
, char *cmd
)
847 struct hostapd_freq_params freq_params
;
851 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
853 "tdls_chanswitch: Only supported with external setup");
857 os_memset(&freq_params
, 0, sizeof(freq_params
));
859 pos
= os_strchr(cmd
, ' ');
864 oper_class
= strtol(pos
, &end
, 10);
867 "tdls_chanswitch: Invalid op class provided");
872 freq_params
.freq
= atoi(pos
);
873 if (freq_params
.freq
== 0) {
874 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
878 #define SET_FREQ_SETTING(str) \
880 const char *pos2 = os_strstr(pos, " " #str "="); \
882 pos2 += sizeof(" " #str "=") - 1; \
883 freq_params.str = atoi(pos2); \
887 SET_FREQ_SETTING(center_freq1
);
888 SET_FREQ_SETTING(center_freq2
);
889 SET_FREQ_SETTING(bandwidth
);
890 SET_FREQ_SETTING(sec_channel_offset
);
891 #undef SET_FREQ_SETTING
893 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
894 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
896 if (hwaddr_aton(cmd
, peer
)) {
897 wpa_printf(MSG_DEBUG
,
898 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
903 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
904 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
905 MAC2STR(peer
), oper_class
, freq_params
.freq
,
906 freq_params
.center_freq1
, freq_params
.center_freq2
,
907 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
908 freq_params
.ht_enabled
? " HT" : "",
909 freq_params
.vht_enabled
? " VHT" : "");
911 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
916 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
917 struct wpa_supplicant
*wpa_s
, char *cmd
)
921 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
923 "tdls_chanswitch: Only supported with external setup");
927 if (hwaddr_aton(cmd
, peer
)) {
928 wpa_printf(MSG_DEBUG
,
929 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
934 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
937 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
941 static int wpa_supplicant_ctrl_iface_tdls_link_status(
942 struct wpa_supplicant
*wpa_s
, const char *addr
,
943 char *buf
, size_t buflen
)
946 const char *tdls_status
;
949 if (hwaddr_aton(addr
, peer
)) {
950 wpa_printf(MSG_DEBUG
,
951 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
955 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
958 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
959 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
960 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
961 if (os_snprintf_error(buflen
, ret
))
967 #endif /* CONFIG_TDLS */
970 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
972 char *token
, *context
= NULL
;
973 struct wmm_ac_ts_setup_params params
= {
978 while ((token
= str_token(cmd
, " ", &context
))) {
979 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
980 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
981 sscanf(token
, "nominal_msdu_size=%i",
982 ¶ms
.nominal_msdu_size
) == 1 ||
983 sscanf(token
, "mean_data_rate=%i",
984 ¶ms
.mean_data_rate
) == 1 ||
985 sscanf(token
, "min_phy_rate=%i",
986 ¶ms
.minimum_phy_rate
) == 1 ||
987 sscanf(token
, "sba=%i",
988 ¶ms
.surplus_bandwidth_allowance
) == 1)
991 if (os_strcasecmp(token
, "downlink") == 0) {
992 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
993 } else if (os_strcasecmp(token
, "uplink") == 0) {
994 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
995 } else if (os_strcasecmp(token
, "bidi") == 0) {
996 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
997 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
998 params
.fixed_nominal_msdu
= 1;
1000 wpa_printf(MSG_DEBUG
,
1001 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1008 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
1012 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
1014 u8 tsid
= atoi(cmd
);
1016 return wpas_wmm_ac_delts(wpa_s
, tsid
);
1020 #ifdef CONFIG_IEEE80211R
1021 static int wpa_supplicant_ctrl_iface_ft_ds(
1022 struct wpa_supplicant
*wpa_s
, char *addr
)
1024 u8 target_ap
[ETH_ALEN
];
1025 struct wpa_bss
*bss
;
1028 if (hwaddr_aton(addr
, target_ap
)) {
1029 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
1030 "address '%s'", addr
);
1034 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
1036 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
1038 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
1042 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
1044 #endif /* CONFIG_IEEE80211R */
1048 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
1051 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1053 u8 p2p_dev_addr
[ETH_ALEN
];
1054 #endif /* CONFIG_P2P */
1056 u8
*_p2p_dev_addr
= NULL
;
1057 #endif /* CONFIG_AP */
1059 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
1062 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
1063 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
1064 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
1065 "P2P Device Address '%s'",
1069 _p2p_dev_addr
= p2p_dev_addr
;
1070 #endif /* CONFIG_P2P */
1071 } else if (hwaddr_aton(cmd
, bssid
)) {
1072 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1078 if (wpa_s
->ap_iface
)
1079 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
1080 #endif /* CONFIG_AP */
1082 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1086 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1087 char *cmd
, char *buf
,
1090 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1094 pin
= os_strchr(cmd
, ' ');
1098 if (os_strcmp(cmd
, "any") == 0)
1100 else if (os_strcmp(cmd
, "get") == 0) {
1101 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1104 } else if (hwaddr_aton(cmd
, bssid
)) {
1105 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1111 if (wpa_s
->ap_iface
) {
1116 pos
= os_strchr(pin
, ' ');
1119 timeout
= atoi(pos
);
1123 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1124 buf
, buflen
, timeout
);
1126 #endif /* CONFIG_AP */
1129 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1133 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1134 if (os_snprintf_error(buflen
, ret
))
1139 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1144 /* Return the generated PIN */
1145 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1146 if (os_snprintf_error(buflen
, ret
))
1152 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1153 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1160 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1161 (u8
*) cmd
, os_strlen(cmd
));
1162 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1163 if (*pos
< '0' || *pos
> '9')
1167 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1171 if (len
!= 4 && len
!= 8) {
1172 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1178 unsigned int pin_val
;
1179 pin_val
= atoi(pin
);
1180 if (!wps_pin_valid(pin_val
)) {
1181 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1182 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1183 if (os_snprintf_error(buflen
, ret
))
1189 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1190 if (os_snprintf_error(buflen
, ret
))
1197 #ifdef CONFIG_WPS_NFC
1199 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1202 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1204 if (cmd
== NULL
|| cmd
[0] == '\0')
1206 else if (hwaddr_aton(cmd
, bssid
))
1209 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1214 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1215 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1222 pos
= os_strchr(cmd
, ' ');
1225 if (os_strcmp(cmd
, "WPS") == 0)
1227 else if (os_strcmp(cmd
, "NDEF") == 0)
1232 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1236 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1238 reply
[res
++] = '\n';
1247 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1248 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1254 if (os_strcmp(cmd
, "WPS") == 0)
1256 else if (os_strcmp(cmd
, "NDEF") == 0)
1261 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1265 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1267 reply
[res
++] = '\n';
1276 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1277 struct wpa_supplicant
*wpa_s
, char *pos
)
1283 int forced_freq
= 0;
1285 freq
= strstr(pos
, " freq=");
1289 forced_freq
= atoi(freq
);
1292 len
= os_strlen(pos
);
1297 buf
= wpabuf_alloc(len
);
1300 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1305 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1312 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1313 char *reply
, size_t max_len
,
1319 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1323 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1325 reply
[res
++] = '\n';
1335 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1336 char *reply
, size_t max_len
,
1342 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1344 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1348 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1350 reply
[res
++] = '\n';
1357 #endif /* CONFIG_P2P */
1360 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1361 char *cmd
, char *reply
,
1367 pos
= os_strchr(cmd
, ' ');
1372 if (os_strcmp(cmd
, "WPS") == 0)
1374 else if (os_strcmp(cmd
, "NDEF") == 0)
1379 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1382 return wpas_ctrl_nfc_get_handover_req_wps(
1383 wpa_s
, reply
, max_len
, ndef
);
1387 if (os_strcmp(pos
, "P2P-CR") == 0) {
1388 return wpas_ctrl_nfc_get_handover_req_p2p(
1389 wpa_s
, reply
, max_len
, ndef
);
1391 #endif /* CONFIG_P2P */
1397 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1398 char *reply
, size_t max_len
,
1399 int ndef
, int cr
, char *uuid
)
1404 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1408 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1410 reply
[res
++] = '\n';
1420 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1421 char *reply
, size_t max_len
,
1427 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1431 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1433 reply
[res
++] = '\n';
1440 #endif /* CONFIG_P2P */
1443 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1444 char *cmd
, char *reply
,
1450 pos
= os_strchr(cmd
, ' ');
1455 if (os_strcmp(cmd
, "WPS") == 0)
1457 else if (os_strcmp(cmd
, "NDEF") == 0)
1462 pos2
= os_strchr(pos
, ' ');
1465 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1468 return wpas_ctrl_nfc_get_handover_sel_wps(
1469 wpa_s
, reply
, max_len
, ndef
,
1470 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1474 if (os_strcmp(pos
, "P2P-CR") == 0) {
1475 return wpas_ctrl_nfc_get_handover_sel_p2p(
1476 wpa_s
, reply
, max_len
, ndef
, 0);
1479 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1480 return wpas_ctrl_nfc_get_handover_sel_p2p(
1481 wpa_s
, reply
, max_len
, ndef
, 1);
1483 #endif /* CONFIG_P2P */
1489 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1493 struct wpabuf
*req
, *sel
;
1495 char *pos
, *role
, *type
, *pos2
;
1498 int forced_freq
= 0;
1500 freq
= strstr(cmd
, " freq=");
1504 forced_freq
= atoi(freq
);
1506 #endif /* CONFIG_P2P */
1509 pos
= os_strchr(role
, ' ');
1511 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1517 pos
= os_strchr(type
, ' ');
1519 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1524 pos2
= os_strchr(pos
, ' ');
1526 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1531 len
= os_strlen(pos
);
1533 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1538 req
= wpabuf_alloc(len
);
1540 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1543 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1544 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1549 len
= os_strlen(pos2
);
1551 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1557 sel
= wpabuf_alloc(len
);
1559 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1563 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1564 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1570 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1571 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1573 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1574 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1576 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1578 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1580 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1581 #endif /* CONFIG_AP */
1583 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1585 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1586 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1588 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1590 #endif /* CONFIG_P2P */
1592 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1593 "reported: role=%s type=%s", role
, type
);
1600 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1605 #endif /* CONFIG_WPS_NFC */
1608 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1617 struct wps_new_ap_settings ap
;
1619 pin
= os_strchr(cmd
, ' ');
1624 if (hwaddr_aton(cmd
, bssid
)) {
1625 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1630 new_ssid
= os_strchr(pin
, ' ');
1631 if (new_ssid
== NULL
)
1632 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1635 new_auth
= os_strchr(new_ssid
, ' ');
1636 if (new_auth
== NULL
)
1640 new_encr
= os_strchr(new_auth
, ' ');
1641 if (new_encr
== NULL
)
1645 new_key
= os_strchr(new_encr
, ' ');
1646 if (new_key
== NULL
)
1650 os_memset(&ap
, 0, sizeof(ap
));
1651 ap
.ssid_hex
= new_ssid
;
1654 ap
.key_hex
= new_key
;
1655 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1660 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1661 char *cmd
, char *buf
,
1666 const char *pin_txt
;
1668 if (!wpa_s
->ap_iface
)
1671 pos
= os_strchr(cmd
, ' ');
1675 if (os_strcmp(cmd
, "disable") == 0) {
1676 wpas_wps_ap_pin_disable(wpa_s
);
1677 return os_snprintf(buf
, buflen
, "OK\n");
1680 if (os_strcmp(cmd
, "random") == 0) {
1682 timeout
= atoi(pos
);
1683 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1684 if (pin_txt
== NULL
)
1686 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1689 if (os_strcmp(cmd
, "get") == 0) {
1690 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1691 if (pin_txt
== NULL
)
1693 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1696 if (os_strcmp(cmd
, "set") == 0) {
1701 pos
= os_strchr(pos
, ' ');
1704 timeout
= atoi(pos
);
1706 if (os_strlen(pin
) > buflen
)
1708 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1710 return os_snprintf(buf
, buflen
, "%s", pin
);
1715 #endif /* CONFIG_AP */
1718 #ifdef CONFIG_WPS_ER
1719 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1722 char *uuid
= cmd
, *pin
, *pos
;
1723 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1724 pin
= os_strchr(uuid
, ' ');
1728 pos
= os_strchr(pin
, ' ');
1731 if (hwaddr_aton(pos
, addr_buf
) == 0)
1734 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1738 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1741 char *uuid
= cmd
, *pin
;
1742 pin
= os_strchr(uuid
, ' ');
1746 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1750 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1751 struct wpa_supplicant
*wpa_s
, char *cmd
)
1753 char *uuid
= cmd
, *id
;
1754 id
= os_strchr(uuid
, ' ');
1758 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1762 static int wpa_supplicant_ctrl_iface_wps_er_config(
1763 struct wpa_supplicant
*wpa_s
, char *cmd
)
1770 struct wps_new_ap_settings ap
;
1772 pin
= os_strchr(cmd
, ' ');
1777 new_ssid
= os_strchr(pin
, ' ');
1778 if (new_ssid
== NULL
)
1782 new_auth
= os_strchr(new_ssid
, ' ');
1783 if (new_auth
== NULL
)
1787 new_encr
= os_strchr(new_auth
, ' ');
1788 if (new_encr
== NULL
)
1792 new_key
= os_strchr(new_encr
, ' ');
1793 if (new_key
== NULL
)
1797 os_memset(&ap
, 0, sizeof(ap
));
1798 ap
.ssid_hex
= new_ssid
;
1801 ap
.key_hex
= new_key
;
1802 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1806 #ifdef CONFIG_WPS_NFC
1807 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1808 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1815 uuid
= os_strchr(cmd
, ' ');
1820 if (os_strcmp(cmd
, "WPS") == 0)
1822 else if (os_strcmp(cmd
, "NDEF") == 0)
1827 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1831 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1833 reply
[res
++] = '\n';
1840 #endif /* CONFIG_WPS_NFC */
1841 #endif /* CONFIG_WPS_ER */
1843 #endif /* CONFIG_WPS */
1846 #ifdef CONFIG_IBSS_RSN
1847 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1848 struct wpa_supplicant
*wpa_s
, char *addr
)
1852 if (hwaddr_aton(addr
, peer
)) {
1853 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1854 "address '%s'", addr
);
1858 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1861 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1863 #endif /* CONFIG_IBSS_RSN */
1866 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1869 #ifdef IEEE8021X_EAPOL
1872 struct wpa_ssid
*ssid
;
1874 pos
= os_strchr(rsp
, '-');
1879 pos
= os_strchr(pos
, ':');
1884 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1885 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1886 (u8
*) pos
, os_strlen(pos
));
1888 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1890 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1895 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1897 #else /* IEEE8021X_EAPOL */
1898 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1900 #endif /* IEEE8021X_EAPOL */
1904 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1906 char *buf
, size_t buflen
)
1908 char *pos
, *end
, tmp
[30];
1909 int res
, verbose
, wps
, ret
;
1912 #endif /* CONFIG_HS20 */
1916 if (os_strcmp(params
, "-DRIVER") == 0)
1917 return wpa_drv_status(wpa_s
, buf
, buflen
);
1918 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1919 wps
= os_strcmp(params
, "-WPS") == 0;
1922 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1923 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1924 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1925 MAC2STR(wpa_s
->bssid
));
1926 if (os_snprintf_error(end
- pos
, ret
))
1929 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1931 if (os_snprintf_error(end
- pos
, ret
))
1935 u8
*_ssid
= ssid
->ssid
;
1936 size_t ssid_len
= ssid
->ssid_len
;
1937 u8 ssid_buf
[SSID_MAX_LEN
];
1938 if (ssid_len
== 0) {
1939 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1946 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1947 wpa_ssid_txt(_ssid
, ssid_len
),
1949 if (os_snprintf_error(end
- pos
, ret
))
1953 if (wps
&& ssid
->passphrase
&&
1954 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1955 (ssid
->mode
== WPAS_MODE_AP
||
1956 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1957 ret
= os_snprintf(pos
, end
- pos
,
1960 if (os_snprintf_error(end
- pos
, ret
))
1965 ret
= os_snprintf(pos
, end
- pos
,
1968 if (os_snprintf_error(end
- pos
, ret
))
1973 switch (ssid
->mode
) {
1974 case WPAS_MODE_INFRA
:
1975 ret
= os_snprintf(pos
, end
- pos
,
1978 case WPAS_MODE_IBSS
:
1979 ret
= os_snprintf(pos
, end
- pos
,
1983 ret
= os_snprintf(pos
, end
- pos
,
1986 case WPAS_MODE_P2P_GO
:
1987 ret
= os_snprintf(pos
, end
- pos
,
1990 case WPAS_MODE_P2P_GROUP_FORMATION
:
1991 ret
= os_snprintf(pos
, end
- pos
,
1992 "mode=P2P GO - group "
1995 case WPAS_MODE_MESH
:
1996 ret
= os_snprintf(pos
, end
- pos
,
2003 if (os_snprintf_error(end
- pos
, ret
))
2009 if (wpa_s
->ap_iface
) {
2010 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
2014 #endif /* CONFIG_AP */
2015 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2019 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
2022 #endif /* CONFIG_AP */
2023 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
2024 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
2025 wpa_s
->sme
.sae
.group
);
2026 if (os_snprintf_error(end
- pos
, ret
))
2030 #endif /* CONFIG_SAE */
2031 #endif /* CONFIG_SME */
2032 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
2033 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
2034 if (os_snprintf_error(end
- pos
, ret
))
2039 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
2040 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
2041 if (os_snprintf_error(end
- pos
, ret
))
2047 if (wpa_s
->global
->p2p
) {
2048 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
2049 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
2050 if (os_snprintf_error(end
- pos
, ret
))
2054 #endif /* CONFIG_P2P */
2056 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
2057 MAC2STR(wpa_s
->own_addr
));
2058 if (os_snprintf_error(end
- pos
, ret
))
2063 if (wpa_s
->current_bss
&&
2064 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
2065 HS20_IE_VENDOR_TYPE
)) &&
2066 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
2067 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
2070 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
2071 release
= rel_num
+ 1;
2073 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
2074 if (os_snprintf_error(end
- pos
, ret
))
2079 if (wpa_s
->current_ssid
) {
2080 struct wpa_cred
*cred
;
2083 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2086 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2089 if (cred
->provisioning_sp
) {
2090 ret
= os_snprintf(pos
, end
- pos
,
2091 "provisioning_sp=%s\n",
2092 cred
->provisioning_sp
);
2093 if (os_snprintf_error(end
- pos
, ret
))
2102 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2103 struct wpabuf
*names
=
2104 wpa_s
->current_bss
->anqp
->domain_name
;
2105 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2107 if (domain_name_list_contains(
2108 names
, cred
->domain
[i
], 1))
2111 if (i
== cred
->num_domain
)
2112 i
= 0; /* show first entry by default */
2114 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2116 if (os_snprintf_error(end
- pos
, ret
))
2121 if (wpa_s
->current_bss
== NULL
||
2122 wpa_s
->current_bss
->anqp
== NULL
)
2125 res
= interworking_home_sp_cred(
2127 wpa_s
->current_bss
->anqp
->domain_name
);
2135 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2136 if (os_snprintf_error(end
- pos
, ret
))
2143 #endif /* CONFIG_HS20 */
2145 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2146 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2147 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2153 #ifdef CONFIG_MACSEC
2154 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2157 #endif /* CONFIG_MACSEC */
2159 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2163 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2164 if (os_snprintf_error(end
- pos
, ret
))
2167 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2171 ret
= os_snprintf(pos
, end
- pos
, "\n");
2172 if (os_snprintf_error(end
- pos
, ret
))
2177 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2184 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2185 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2186 if (os_snprintf_error(end
- pos
, ret
))
2190 #endif /* CONFIG_WPS */
2194 * Allow using the STATUS command with default behavior, say for debug,
2195 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2196 * events with STATUS-NO_EVENTS.
2198 if (os_strcmp(params
, "-NO_EVENTS")) {
2199 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2200 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2201 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2203 MAC2STR(wpa_s
->bssid
),
2204 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2205 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2206 wpa_s
->current_ssid
->ssid_len
) : "");
2207 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2208 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2209 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2210 "- connection to " MACSTR
2211 " completed %s [id=%d id_str=%s]",
2212 MAC2STR(wpa_s
->bssid
), "(auth)",
2213 ssid
? ssid
->id
: -1,
2214 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2217 #endif /* ANDROID */
2223 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2228 struct wpa_ssid
*ssid
;
2231 /* cmd: "<network id> <BSSID>" */
2232 pos
= os_strchr(cmd
, ' ');
2237 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2238 if (hwaddr_aton(pos
, bssid
)) {
2239 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2243 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2245 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2250 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2251 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2257 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2258 char *cmd
, char *buf
,
2262 struct wpa_blacklist
*e
;
2266 /* cmd: "BLACKLIST [<BSSID>]" */
2270 e
= wpa_s
->blacklist
;
2272 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2274 if (os_snprintf_error(end
- pos
, ret
))
2283 if (os_strncmp(cmd
, "clear", 5) == 0) {
2284 wpa_blacklist_clear(wpa_s
);
2285 os_memcpy(buf
, "OK\n", 3);
2289 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2290 if (hwaddr_aton(cmd
, bssid
)) {
2291 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2296 * Add the BSSID twice, so its count will be 2, causing it to be
2297 * skipped when processing scan results.
2299 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2302 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2305 os_memcpy(buf
, "OK\n", 3);
2310 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2311 char *cmd
, char *buf
,
2314 char *pos
, *end
, *stamp
;
2317 /* cmd: "LOG_LEVEL [<level>]" */
2321 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2323 debug_level_str(wpa_debug_level
),
2324 wpa_debug_timestamp
);
2325 if (os_snprintf_error(end
- pos
, ret
))
2334 stamp
= os_strchr(cmd
, ' ');
2337 while (*stamp
== ' ') {
2342 if (os_strlen(cmd
)) {
2343 int level
= str_to_debug_level(cmd
);
2346 wpa_debug_level
= level
;
2349 if (stamp
&& os_strlen(stamp
))
2350 wpa_debug_timestamp
= atoi(stamp
);
2352 os_memcpy(buf
, "OK\n", 3);
2357 static int wpa_supplicant_ctrl_iface_list_networks(
2358 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2360 char *pos
, *end
, *prev
;
2361 struct wpa_ssid
*ssid
;
2366 ret
= os_snprintf(pos
, end
- pos
,
2367 "network id / ssid / bssid / flags\n");
2368 if (os_snprintf_error(end
- pos
, ret
))
2372 ssid
= wpa_s
->conf
->ssid
;
2374 /* skip over ssids until we find next one */
2375 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2376 int last_id
= atoi(cmd
+ 8);
2377 if (last_id
!= -1) {
2378 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2386 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2388 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2389 if (os_snprintf_error(end
- pos
, ret
))
2392 if (ssid
->bssid_set
) {
2393 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2394 MAC2STR(ssid
->bssid
));
2396 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2398 if (os_snprintf_error(end
- pos
, ret
))
2401 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2402 ssid
== wpa_s
->current_ssid
?
2404 ssid
->disabled
? "[DISABLED]" : "",
2405 ssid
->disabled_until
.sec
?
2406 "[TEMP-DISABLED]" : "",
2407 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2409 if (os_snprintf_error(end
- pos
, ret
))
2412 ret
= os_snprintf(pos
, end
- pos
, "\n");
2413 if (os_snprintf_error(end
- pos
, ret
))
2424 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2427 ret
= os_snprintf(pos
, end
- pos
, "-");
2428 if (os_snprintf_error(end
- pos
, ret
))
2431 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2439 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2440 const u8
*ie
, size_t ie_len
)
2442 struct wpa_ie_data data
;
2446 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2447 if (os_snprintf_error(end
- pos
, ret
))
2451 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2452 ret
= os_snprintf(pos
, end
- pos
, "?]");
2453 if (os_snprintf_error(end
- pos
, ret
))
2460 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2461 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2462 pos
== start
? "" : "+");
2463 if (os_snprintf_error(end
- pos
, ret
))
2467 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2468 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2469 pos
== start
? "" : "+");
2470 if (os_snprintf_error(end
- pos
, ret
))
2474 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2475 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2476 pos
== start
? "" : "+");
2477 if (os_snprintf_error(end
- pos
, ret
))
2481 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2482 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2483 pos
== start
? "" : "+");
2484 if (os_snprintf_error(end
- pos
, ret
))
2488 #ifdef CONFIG_IEEE80211R
2489 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2490 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2491 pos
== start
? "" : "+");
2492 if (os_snprintf_error(end
- pos
, ret
))
2496 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2497 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2498 pos
== start
? "" : "+");
2499 if (os_snprintf_error(end
- pos
, ret
))
2503 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2504 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2505 pos
== start
? "" : "+");
2506 if (os_snprintf_error(end
- pos
, ret
))
2510 #endif /* CONFIG_IEEE80211R */
2511 #ifdef CONFIG_IEEE80211W
2512 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2513 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2514 pos
== start
? "" : "+");
2515 if (os_snprintf_error(end
- pos
, ret
))
2519 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2520 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2521 pos
== start
? "" : "+");
2522 if (os_snprintf_error(end
- pos
, ret
))
2526 #endif /* CONFIG_IEEE80211W */
2528 #ifdef CONFIG_SUITEB
2529 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2530 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2531 pos
== start
? "" : "+");
2532 if (os_snprintf_error(end
- pos
, ret
))
2536 #endif /* CONFIG_SUITEB */
2538 #ifdef CONFIG_SUITEB192
2539 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2540 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2541 pos
== start
? "" : "+");
2542 if (os_snprintf_error(end
- pos
, ret
))
2546 #endif /* CONFIG_SUITEB192 */
2549 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2550 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2551 pos
== start
? "" : "+");
2552 if (os_snprintf_error(end
- pos
, ret
))
2556 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2557 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2558 pos
== start
? "" : "+");
2559 if (os_snprintf_error(end
- pos
, ret
))
2563 #ifdef CONFIG_IEEE80211R
2564 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2565 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2566 pos
== start
? "" : "+");
2567 if (os_snprintf_error(end
- pos
, ret
))
2571 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2572 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2573 pos
== start
? "" : "+");
2574 if (os_snprintf_error(end
- pos
, ret
))
2578 #endif /* CONFIG_IEEE80211R */
2579 #endif /* CONFIG_FILS */
2582 if (data
.key_mgmt
& WPA_KEY_MGMT_OWE
) {
2583 ret
= os_snprintf(pos
, end
- pos
, "%sOWE",
2584 pos
== start
? "" : "+");
2585 if (os_snprintf_error(end
- pos
, ret
))
2589 #endif /* CONFIG_OWE */
2591 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2592 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2593 pos
== start
? "" : "+");
2594 if (os_snprintf_error(end
- pos
, ret
))
2599 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2601 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2602 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2603 if (os_snprintf_error(end
- pos
, ret
))
2608 ret
= os_snprintf(pos
, end
- pos
, "]");
2609 if (os_snprintf_error(end
- pos
, ret
))
2618 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2619 char *pos
, char *end
,
2620 struct wpabuf
*wps_ie
)
2627 if (wps_is_selected_pbc_registrar(wps_ie
))
2629 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2631 else if (wps_is_selected_pin_registrar(wps_ie
))
2636 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2637 if (!os_snprintf_error(end
- pos
, ret
))
2639 wpabuf_free(wps_ie
);
2642 #endif /* CONFIG_WPS */
2645 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2646 char *pos
, char *end
,
2647 const struct wpa_bss
*bss
)
2650 struct wpabuf
*wps_ie
;
2651 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2652 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2653 #else /* CONFIG_WPS */
2655 #endif /* CONFIG_WPS */
2659 /* Format one result on one text line into a buffer. */
2660 static int wpa_supplicant_ctrl_iface_scan_result(
2661 struct wpa_supplicant
*wpa_s
,
2662 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2666 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
;
2668 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2669 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2671 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2672 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2673 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2675 return 0; /* Do not show P2P listen discovery results here */
2680 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2681 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2682 if (os_snprintf_error(end
- pos
, ret
))
2685 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2687 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2688 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2690 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2693 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2695 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2696 osen_ie
, 2 + osen_ie
[1]);
2697 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2698 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2699 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2700 if (os_snprintf_error(end
- pos
, ret
))
2705 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2706 if (os_snprintf_error(end
- pos
, ret
))
2710 if (bss_is_dmg(bss
)) {
2712 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2713 if (os_snprintf_error(end
- pos
, ret
))
2716 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2717 case IEEE80211_CAP_DMG_IBSS
:
2720 case IEEE80211_CAP_DMG_AP
:
2723 case IEEE80211_CAP_DMG_PBSS
:
2730 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2731 if (os_snprintf_error(end
- pos
, ret
))
2735 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2736 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2737 if (os_snprintf_error(end
- pos
, ret
))
2741 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2742 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2743 if (os_snprintf_error(end
- pos
, ret
))
2749 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2750 if (os_snprintf_error(end
- pos
, ret
))
2755 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2756 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2757 if (os_snprintf_error(end
- pos
, ret
))
2761 #endif /* CONFIG_HS20 */
2763 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2764 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2765 if (os_snprintf_error(end
- pos
, ret
))
2769 #endif /* CONFIG_FILS */
2771 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2772 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2773 if (os_snprintf_error(end
- pos
, ret
))
2777 #endif /* CONFIG_FST */
2779 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2780 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2781 if (os_snprintf_error(end
- pos
, ret
))
2785 ret
= os_snprintf(pos
, end
- pos
, "\n");
2786 if (os_snprintf_error(end
- pos
, ret
))
2794 static int wpa_supplicant_ctrl_iface_scan_results(
2795 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2798 struct wpa_bss
*bss
;
2803 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2805 if (os_snprintf_error(end
- pos
, ret
))
2809 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2810 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2812 if (ret
< 0 || ret
>= end
- pos
)
2823 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2824 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2826 char *pos
, ifname
[IFNAMSIZ
+ 1];
2830 pos
= os_strstr(cmd
, "ifname=");
2833 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2836 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2839 os_strlcpy(reply
, ifname
, max_len
);
2840 return os_strlen(ifname
);
2844 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2845 struct wpa_supplicant
*wpa_s
, char *cmd
)
2848 struct wpa_ssid
*ssid
;
2851 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2853 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2855 wpa_printf(MSG_DEBUG
,
2856 "CTRL_IFACE: Could not find network id=%d", id
);
2859 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2860 wpa_printf(MSG_DEBUG
,
2861 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2864 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2865 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2866 wpa_printf(MSG_ERROR
,
2867 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2872 * TODO: If necessary write our own group_add function,
2873 * for now we can reuse select_network
2875 wpa_supplicant_select_network(wpa_s
, ssid
);
2881 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2882 struct wpa_supplicant
*wpa_s
, char *cmd
)
2884 struct wpa_supplicant
*orig
;
2885 struct wpa_global
*global
;
2888 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2890 global
= wpa_s
->global
;
2893 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2894 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2900 wpa_printf(MSG_ERROR
,
2901 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2905 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2906 wpa_printf(MSG_ERROR
,
2907 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2911 wpa_s
->reassociate
= 0;
2912 wpa_s
->disconnected
= 1;
2913 wpa_supplicant_cancel_sched_scan(wpa_s
);
2914 wpa_supplicant_cancel_scan(wpa_s
);
2917 * TODO: If necessary write our own group_remove function,
2918 * for now we can reuse deauthenticate
2920 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2922 if (wpa_s
->mesh_if_created
)
2923 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
2929 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
2930 struct wpa_supplicant
*wpa_s
, char *cmd
)
2934 if (hwaddr_aton(cmd
, addr
) < 0)
2937 return wpas_mesh_peer_remove(wpa_s
, addr
);
2941 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
2942 struct wpa_supplicant
*wpa_s
, char *cmd
)
2948 pos
= os_strstr(cmd
, " duration=");
2951 duration
= atoi(pos
+ 10);
2956 if (hwaddr_aton(cmd
, addr
))
2959 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
2962 #endif /* CONFIG_MESH */
2965 static int wpa_supplicant_ctrl_iface_select_network(
2966 struct wpa_supplicant
*wpa_s
, char *cmd
)
2969 struct wpa_ssid
*ssid
;
2972 /* cmd: "<network id>" or "any" */
2973 if (os_strncmp(cmd
, "any", 3) == 0) {
2974 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2978 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2980 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2982 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2983 "network id=%d", id
);
2986 if (ssid
->disabled
== 2) {
2987 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2988 "SELECT_NETWORK with persistent P2P group");
2993 pos
= os_strstr(cmd
, " freq=");
2995 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
2997 os_free(wpa_s
->select_network_scan_freqs
);
2998 wpa_s
->select_network_scan_freqs
= freqs
;
3002 wpa_s
->scan_min_time
.sec
= 0;
3003 wpa_s
->scan_min_time
.usec
= 0;
3004 wpa_supplicant_select_network(wpa_s
, ssid
);
3010 static int wpa_supplicant_ctrl_iface_enable_network(
3011 struct wpa_supplicant
*wpa_s
, char *cmd
)
3014 struct wpa_ssid
*ssid
;
3016 /* cmd: "<network id>" or "all" */
3017 if (os_strcmp(cmd
, "all") == 0) {
3018 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
3022 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
3024 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3026 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3027 "network id=%d", id
);
3030 if (ssid
->disabled
== 2) {
3031 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3032 "ENABLE_NETWORK with persistent P2P group");
3036 if (os_strstr(cmd
, " no-connect")) {
3041 wpa_s
->scan_min_time
.sec
= 0;
3042 wpa_s
->scan_min_time
.usec
= 0;
3043 wpa_supplicant_enable_network(wpa_s
, ssid
);
3049 static int wpa_supplicant_ctrl_iface_disable_network(
3050 struct wpa_supplicant
*wpa_s
, char *cmd
)
3053 struct wpa_ssid
*ssid
;
3055 /* cmd: "<network id>" or "all" */
3056 if (os_strcmp(cmd
, "all") == 0) {
3057 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
3061 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
3063 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3065 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3066 "network id=%d", id
);
3069 if (ssid
->disabled
== 2) {
3070 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
3071 "DISABLE_NETWORK with persistent P2P "
3076 wpa_supplicant_disable_network(wpa_s
, ssid
);
3082 static int wpa_supplicant_ctrl_iface_add_network(
3083 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
3085 struct wpa_ssid
*ssid
;
3088 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3090 ssid
= wpa_supplicant_add_network(wpa_s
);
3094 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3095 if (os_snprintf_error(buflen
, ret
))
3101 static int wpa_supplicant_ctrl_iface_remove_network(
3102 struct wpa_supplicant
*wpa_s
, char *cmd
)
3105 struct wpa_ssid
*ssid
;
3108 /* cmd: "<network id>" or "all" */
3109 if (os_strcmp(cmd
, "all") == 0) {
3110 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3111 if (wpa_s
->sched_scanning
)
3112 wpa_supplicant_cancel_sched_scan(wpa_s
);
3114 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3115 if (wpa_s
->current_ssid
) {
3117 wpa_s
->sme
.prev_bssid_set
= 0;
3118 #endif /* CONFIG_SME */
3119 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3120 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3121 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3122 wpa_s
->own_disconnect_req
= 1;
3123 wpa_supplicant_deauthenticate(
3124 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3126 ssid
= wpa_s
->conf
->ssid
;
3128 struct wpa_ssid
*remove_ssid
= ssid
;
3131 if (wpa_s
->last_ssid
== remove_ssid
)
3132 wpa_s
->last_ssid
= NULL
;
3133 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3134 wpa_config_remove_network(wpa_s
->conf
, id
);
3140 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3142 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3144 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3149 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3150 "network id=%d", id
);
3157 static int wpa_supplicant_ctrl_iface_update_network(
3158 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3159 char *name
, char *value
)
3163 ret
= wpa_config_set(ssid
, name
, value
, 0);
3165 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3166 "variable '%s'", name
);
3170 return 0; /* No change to the previously configured value */
3172 if (os_strcmp(name
, "bssid") != 0 &&
3173 os_strcmp(name
, "priority") != 0) {
3174 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3176 if (wpa_s
->current_ssid
== ssid
||
3177 wpa_s
->current_ssid
== NULL
) {
3179 * Invalidate the EAP session cache if anything in the
3180 * current or previously used configuration changes.
3182 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3186 if ((os_strcmp(name
, "psk") == 0 &&
3187 value
[0] == '"' && ssid
->ssid_len
) ||
3188 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3189 wpa_config_update_psk(ssid
);
3190 else if (os_strcmp(name
, "priority") == 0)
3191 wpa_config_update_prio_list(wpa_s
->conf
);
3197 static int wpa_supplicant_ctrl_iface_set_network(
3198 struct wpa_supplicant
*wpa_s
, char *cmd
)
3200 int id
, ret
, prev_bssid_set
, prev_disabled
;
3201 struct wpa_ssid
*ssid
;
3203 u8 prev_bssid
[ETH_ALEN
];
3205 /* cmd: "<network id> <variable name> <value>" */
3206 name
= os_strchr(cmd
, ' ');
3211 value
= os_strchr(name
, ' ');
3217 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3219 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3220 (u8
*) value
, os_strlen(value
));
3222 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3224 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3229 prev_bssid_set
= ssid
->bssid_set
;
3230 prev_disabled
= ssid
->disabled
;
3231 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3232 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3235 (ssid
->bssid_set
!= prev_bssid_set
||
3236 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3237 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3239 if (prev_disabled
!= ssid
->disabled
&&
3240 (prev_disabled
== 2 || ssid
->disabled
== 2))
3241 wpas_notify_network_type_changed(wpa_s
, ssid
);
3247 static int wpa_supplicant_ctrl_iface_get_network(
3248 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3252 struct wpa_ssid
*ssid
;
3255 /* cmd: "<network id> <variable name>" */
3256 name
= os_strchr(cmd
, ' ');
3257 if (name
== NULL
|| buflen
== 0)
3262 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3265 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3267 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3272 value
= wpa_config_get_no_key(ssid
, name
);
3273 if (value
== NULL
) {
3274 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3275 "variable '%s'", name
);
3279 res
= os_strlcpy(buf
, value
, buflen
);
3280 if (res
>= buflen
) {
3291 static int wpa_supplicant_ctrl_iface_dup_network(
3292 struct wpa_supplicant
*wpa_s
, char *cmd
,
3293 struct wpa_supplicant
*dst_wpa_s
)
3295 struct wpa_ssid
*ssid_s
, *ssid_d
;
3296 char *name
, *id
, *value
;
3297 int id_s
, id_d
, ret
;
3299 /* cmd: "<src network id> <dst network id> <variable name>" */
3300 id
= os_strchr(cmd
, ' ');
3305 name
= os_strchr(id
, ' ');
3313 wpa_printf(MSG_DEBUG
,
3314 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3315 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3317 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3318 if (ssid_s
== NULL
) {
3319 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3320 "network id=%d", id_s
);
3324 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3325 if (ssid_d
== NULL
) {
3326 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3327 "network id=%d", id_d
);
3331 value
= wpa_config_get(ssid_s
, name
);
3332 if (value
== NULL
) {
3333 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3334 "variable '%s'", name
);
3338 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3347 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3348 char *buf
, size_t buflen
)
3351 struct wpa_cred
*cred
;
3356 ret
= os_snprintf(pos
, end
- pos
,
3357 "cred id / realm / username / domain / imsi\n");
3358 if (os_snprintf_error(end
- pos
, ret
))
3362 cred
= wpa_s
->conf
->cred
;
3364 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3365 cred
->id
, cred
->realm
? cred
->realm
: "",
3366 cred
->username
? cred
->username
: "",
3367 cred
->domain
? cred
->domain
[0] : "",
3368 cred
->imsi
? cred
->imsi
: "");
3369 if (os_snprintf_error(end
- pos
, ret
))
3380 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3381 char *buf
, size_t buflen
)
3383 struct wpa_cred
*cred
;
3386 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3388 cred
= wpa_config_add_cred(wpa_s
->conf
);
3392 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3394 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3395 if (os_snprintf_error(buflen
, ret
))
3401 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3402 struct wpa_cred
*cred
)
3404 struct wpa_ssid
*ssid
;
3409 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3414 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3415 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3419 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3421 /* Remove any network entry created based on the removed credential */
3422 ssid
= wpa_s
->conf
->ssid
;
3424 if (ssid
->parent_cred
== cred
) {
3427 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3428 "used the removed credential", ssid
->id
);
3429 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3430 if (os_snprintf_error(sizeof(str
), res
))
3431 str
[sizeof(str
) - 1] = '\0';
3433 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3442 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3446 struct wpa_cred
*cred
, *prev
;
3448 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3449 * "provisioning_sp=<FQDN> */
3450 if (os_strcmp(cmd
, "all") == 0) {
3451 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3452 cred
= wpa_s
->conf
->cred
;
3456 wpas_ctrl_remove_cred(wpa_s
, prev
);
3461 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3462 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3464 cred
= wpa_s
->conf
->cred
;
3470 for (i
= 0; i
< prev
->num_domain
; i
++) {
3471 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3474 wpas_ctrl_remove_cred(wpa_s
, prev
);
3482 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3483 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3485 cred
= wpa_s
->conf
->cred
;
3489 if (prev
->provisioning_sp
&&
3490 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3491 wpas_ctrl_remove_cred(wpa_s
, prev
);
3497 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3499 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3500 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3504 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3508 struct wpa_cred
*cred
;
3511 /* cmd: "<cred id> <variable name> <value>" */
3512 name
= os_strchr(cmd
, ' ');
3517 value
= os_strchr(name
, ' ');
3523 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3525 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3526 (u8
*) value
, os_strlen(value
));
3528 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3530 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3535 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3536 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3537 "variable '%s'", name
);
3541 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3547 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3548 char *cmd
, char *buf
,
3553 struct wpa_cred
*cred
;
3556 /* cmd: "<cred id> <variable name>" */
3557 name
= os_strchr(cmd
, ' ');
3563 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3566 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3568 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3573 value
= wpa_config_get_cred_no_key(cred
, name
);
3574 if (value
== NULL
) {
3575 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3580 res
= os_strlcpy(buf
, value
, buflen
);
3581 if (res
>= buflen
) {
3592 #ifndef CONFIG_NO_CONFIG_WRITE
3593 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3597 if (!wpa_s
->conf
->update_config
) {
3598 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3599 "to update configuration (update_config=0)");
3603 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3605 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3606 "update configuration");
3608 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3614 #endif /* CONFIG_NO_CONFIG_WRITE */
3617 struct cipher_info
{
3623 static const struct cipher_info ciphers
[] = {
3624 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3625 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3626 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3627 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3628 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3629 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3630 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3631 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3634 static const struct cipher_info ciphers_group_mgmt
[] = {
3635 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3636 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3637 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3638 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3642 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3643 struct wpa_driver_capa
*capa
,
3644 char *buf
, size_t buflen
)
3657 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3663 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3664 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3665 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3666 pos
== buf
? "" : " ",
3668 if (os_snprintf_error(end
- pos
, ret
))
3678 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3679 struct wpa_driver_capa
*capa
,
3680 char *buf
, size_t buflen
)
3693 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3699 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3700 if (capa
->enc
& ciphers
[i
].capa
) {
3701 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3702 pos
== buf
? "" : " ",
3704 if (os_snprintf_error(end
- pos
, ret
))
3714 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3715 struct wpa_driver_capa
*capa
,
3716 char *buf
, size_t buflen
)
3728 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3729 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3730 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3731 pos
== buf
? "" : " ",
3732 ciphers_group_mgmt
[i
].name
);
3733 if (os_snprintf_error(end
- pos
, ret
))
3743 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3744 struct wpa_driver_capa
*capa
,
3745 char *buf
, size_t buflen
)
3757 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3764 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3765 if (os_snprintf_error(end
- pos
, ret
))
3769 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3770 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3771 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3772 if (os_snprintf_error(end
- pos
, ret
))
3777 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3778 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3779 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3780 if (os_snprintf_error(end
- pos
, ret
))
3785 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3786 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3787 if (os_snprintf_error(end
- pos
, ret
))
3792 #ifdef CONFIG_SUITEB
3793 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3794 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3795 if (os_snprintf_error(end
- pos
, ret
))
3799 #endif /* CONFIG_SUITEB */
3800 #ifdef CONFIG_SUITEB192
3801 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3802 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3803 if (os_snprintf_error(end
- pos
, ret
))
3807 #endif /* CONFIG_SUITEB192 */
3809 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_OWE
) {
3810 ret
= os_snprintf(pos
, end
- pos
, " OWE");
3811 if (os_snprintf_error(end
- pos
, ret
))
3815 #endif /* CONFIG_OWE */
3821 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3822 struct wpa_driver_capa
*capa
,
3823 char *buf
, size_t buflen
)
3835 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3841 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3842 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3843 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3844 pos
== buf
? "" : " ");
3845 if (os_snprintf_error(end
- pos
, ret
))
3850 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3851 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3852 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3853 pos
== buf
? "" : " ");
3854 if (os_snprintf_error(end
- pos
, ret
))
3863 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
3864 int res
, char *strict
,
3865 struct wpa_driver_capa
*capa
,
3866 char *buf
, size_t buflen
)
3878 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3884 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3885 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3886 pos
== buf
? "" : " ");
3887 if (os_snprintf_error(end
- pos
, ret
))
3892 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3893 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3894 pos
== buf
? "" : " ");
3895 if (os_snprintf_error(end
- pos
, ret
))
3900 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3901 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3902 pos
== buf
? "" : " ");
3903 if (os_snprintf_error(end
- pos
, ret
))
3909 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
3910 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
3911 pos
== buf
? "" : " ");
3912 if (os_snprintf_error(end
- pos
, ret
))
3916 #endif /* CONFIG_SAE */
3922 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3923 struct wpa_driver_capa
*capa
,
3924 char *buf
, size_t buflen
)
3936 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3942 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3943 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3944 pos
== buf
? "" : " ");
3945 if (os_snprintf_error(end
- pos
, ret
))
3950 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3951 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3952 pos
== buf
? "" : " ");
3953 if (os_snprintf_error(end
- pos
, ret
))
3959 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
3960 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
3961 pos
== buf
? "" : " ");
3962 if (os_snprintf_error(end
- pos
, ret
))
3966 #endif /* CONFIG_MESH */
3972 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3973 char *buf
, size_t buflen
)
3975 struct hostapd_channel_data
*chnl
;
3977 char *pos
, *end
, *hmode
;
3982 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3983 switch (wpa_s
->hw
.modes
[j
].mode
) {
3984 case HOSTAPD_MODE_IEEE80211B
:
3987 case HOSTAPD_MODE_IEEE80211G
:
3990 case HOSTAPD_MODE_IEEE80211A
:
3993 case HOSTAPD_MODE_IEEE80211AD
:
3999 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
4000 if (os_snprintf_error(end
- pos
, ret
))
4003 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4004 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4005 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4007 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
4008 if (os_snprintf_error(end
- pos
, ret
))
4012 ret
= os_snprintf(pos
, end
- pos
, "\n");
4013 if (os_snprintf_error(end
- pos
, ret
))
4022 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
4023 char *buf
, size_t buflen
)
4025 struct hostapd_channel_data
*chnl
;
4027 char *pos
, *end
, *hmode
;
4032 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
4033 switch (wpa_s
->hw
.modes
[j
].mode
) {
4034 case HOSTAPD_MODE_IEEE80211B
:
4037 case HOSTAPD_MODE_IEEE80211G
:
4040 case HOSTAPD_MODE_IEEE80211A
:
4043 case HOSTAPD_MODE_IEEE80211AD
:
4049 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
4051 if (os_snprintf_error(end
- pos
, ret
))
4054 chnl
= wpa_s
->hw
.modes
[j
].channels
;
4055 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
4056 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
4058 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
4059 chnl
[i
].chan
, chnl
[i
].freq
,
4060 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
4062 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
4065 if (os_snprintf_error(end
- pos
, ret
))
4069 ret
= os_snprintf(pos
, end
- pos
, "\n");
4070 if (os_snprintf_error(end
- pos
, ret
))
4079 static int wpa_supplicant_ctrl_iface_get_capability(
4080 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
4083 struct wpa_driver_capa capa
;
4089 /* Determine whether or not strict checking was requested */
4090 len
= os_strlcpy(field
, _field
, sizeof(field
));
4091 if (len
>= sizeof(field
))
4093 strict
= os_strchr(field
, ' ');
4094 if (strict
!= NULL
) {
4096 if (os_strcmp(strict
, "strict") != 0)
4100 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4101 field
, strict
? strict
: "");
4103 if (os_strcmp(field
, "eap") == 0) {
4104 return eap_get_names(buf
, buflen
);
4107 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4109 if (os_strcmp(field
, "pairwise") == 0)
4110 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4113 if (os_strcmp(field
, "group") == 0)
4114 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4117 if (os_strcmp(field
, "group_mgmt") == 0)
4118 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4121 if (os_strcmp(field
, "key_mgmt") == 0)
4122 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4125 if (os_strcmp(field
, "proto") == 0)
4126 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4129 if (os_strcmp(field
, "auth_alg") == 0)
4130 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4131 &capa
, buf
, buflen
);
4133 if (os_strcmp(field
, "modes") == 0)
4134 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4137 if (os_strcmp(field
, "channels") == 0)
4138 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4140 if (os_strcmp(field
, "freq") == 0)
4141 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4144 if (os_strcmp(field
, "tdls") == 0)
4145 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4146 #endif /* CONFIG_TDLS */
4149 if (os_strcmp(field
, "erp") == 0) {
4150 res
= os_snprintf(buf
, buflen
, "ERP");
4151 if (os_snprintf_error(buflen
, res
))
4155 #endif /* CONFIG_EPR */
4158 if (os_strcmp(field
, "fips") == 0) {
4159 res
= os_snprintf(buf
, buflen
, "FIPS");
4160 if (os_snprintf_error(buflen
, res
))
4164 #endif /* CONFIG_FIPS */
4167 if (os_strcmp(field
, "acs") == 0) {
4168 res
= os_snprintf(buf
, buflen
, "ACS");
4169 if (os_snprintf_error(buflen
, res
))
4173 #endif /* CONFIG_ACS */
4176 if (os_strcmp(field
, "fils") == 0 &&
4177 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
)) {
4178 #ifdef CONFIG_FILS_SK_PFS
4179 res
= os_snprintf(buf
, buflen
, "FILS FILS-SK-PFS");
4180 #else /* CONFIG_FILS_SK_PFS */
4181 res
= os_snprintf(buf
, buflen
, "FILS");
4182 #endif /* CONFIG_FILS_SK_PFS */
4183 if (os_snprintf_error(buflen
, res
))
4187 #endif /* CONFIG_FILS */
4189 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4196 #ifdef CONFIG_INTERWORKING
4197 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4198 struct wpabuf
*data
)
4208 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4209 if (os_snprintf_error(end
- pos
, ret
))
4213 d
= wpabuf_head_u8(data
);
4214 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4215 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4216 if (os_snprintf_error(end
- pos
, ret
))
4221 ret
= os_snprintf(pos
, end
- pos
, "\n");
4222 if (os_snprintf_error(end
- pos
, ret
))
4228 #endif /* CONFIG_INTERWORKING */
4232 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4235 const u8
*ie
, *ie_end
;
4239 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4242 ie_end
= ie
+ 2 + ie
[1];
4244 if (ie_end
- ie
< 2)
4247 info
= WPA_GET_LE16(ie
);
4249 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4250 if (os_snprintf_error(end
- pos
, ret
))
4254 if (info
& BIT(7)) {
4255 /* Cache Identifier Included */
4256 if (ie_end
- ie
< 2)
4258 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4260 if (os_snprintf_error(end
- pos
, ret
))
4266 if (info
& BIT(8)) {
4267 /* HESSID Included */
4268 if (ie_end
- ie
< ETH_ALEN
)
4270 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4272 if (os_snprintf_error(end
- pos
, ret
))
4278 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4280 if (ie_end
- ie
< realms
* 2)
4282 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4283 if (os_snprintf_error(end
- pos
, ret
))
4287 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4292 ret
= os_snprintf(pos
, end
- pos
, "\n");
4293 if (os_snprintf_error(end
- pos
, ret
))
4300 #endif /* CONFIG_FILS */
4303 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4304 unsigned long mask
, char *buf
, size_t buflen
)
4309 const u8
*ie
, *ie2
, *osen_ie
, *mesh
;
4314 if (mask
& WPA_BSS_MASK_ID
) {
4315 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4316 if (os_snprintf_error(end
- pos
, ret
))
4321 if (mask
& WPA_BSS_MASK_BSSID
) {
4322 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4323 MAC2STR(bss
->bssid
));
4324 if (os_snprintf_error(end
- pos
, ret
))
4329 if (mask
& WPA_BSS_MASK_FREQ
) {
4330 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4331 if (os_snprintf_error(end
- pos
, ret
))
4336 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4337 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4339 if (os_snprintf_error(end
- pos
, ret
))
4344 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4345 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4347 if (os_snprintf_error(end
- pos
, ret
))
4352 if (mask
& WPA_BSS_MASK_QUAL
) {
4353 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4354 if (os_snprintf_error(end
- pos
, ret
))
4359 if (mask
& WPA_BSS_MASK_NOISE
) {
4360 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4361 if (os_snprintf_error(end
- pos
, ret
))
4366 if (mask
& WPA_BSS_MASK_LEVEL
) {
4367 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4368 if (os_snprintf_error(end
- pos
, ret
))
4373 if (mask
& WPA_BSS_MASK_TSF
) {
4374 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4375 (unsigned long long) bss
->tsf
);
4376 if (os_snprintf_error(end
- pos
, ret
))
4381 if (mask
& WPA_BSS_MASK_AGE
) {
4382 struct os_reltime now
;
4384 os_get_reltime(&now
);
4385 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4386 (int) (now
.sec
- bss
->last_update
.sec
));
4387 if (os_snprintf_error(end
- pos
, ret
))
4392 if (mask
& WPA_BSS_MASK_IE
) {
4393 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4394 if (os_snprintf_error(end
- pos
, ret
))
4398 ie
= (const u8
*) (bss
+ 1);
4399 for (i
= 0; i
< bss
->ie_len
; i
++) {
4400 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4401 if (os_snprintf_error(end
- pos
, ret
))
4406 ret
= os_snprintf(pos
, end
- pos
, "\n");
4407 if (os_snprintf_error(end
- pos
, ret
))
4412 if (mask
& WPA_BSS_MASK_FLAGS
) {
4413 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4414 if (os_snprintf_error(end
- pos
, ret
))
4418 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4420 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4422 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4424 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4426 pos
= wpa_supplicant_ie_txt(pos
, end
,
4427 mesh
? "RSN" : "WPA2", ie2
,
4429 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4431 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4432 osen_ie
, 2 + osen_ie
[1]);
4433 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4434 if (!ie
&& !ie2
&& !osen_ie
&&
4435 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4436 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4437 if (os_snprintf_error(end
- pos
, ret
))
4443 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4444 if (os_snprintf_error(end
- pos
, ret
))
4449 if (bss_is_dmg(bss
)) {
4451 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4452 if (os_snprintf_error(end
- pos
, ret
))
4455 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4456 case IEEE80211_CAP_DMG_IBSS
:
4459 case IEEE80211_CAP_DMG_AP
:
4462 case IEEE80211_CAP_DMG_PBSS
:
4469 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4470 if (os_snprintf_error(end
- pos
, ret
))
4474 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4475 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4476 if (os_snprintf_error(end
- pos
, ret
))
4480 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4481 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4482 if (os_snprintf_error(end
- pos
, ret
))
4487 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4488 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4489 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4490 if (os_snprintf_error(end
- pos
, ret
))
4495 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4496 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4497 if (os_snprintf_error(end
- pos
, ret
))
4501 #endif /* CONFIG_HS20 */
4503 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4504 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4505 if (os_snprintf_error(end
- pos
, ret
))
4509 #endif /* CONFIG_FILS */
4511 ret
= os_snprintf(pos
, end
- pos
, "\n");
4512 if (os_snprintf_error(end
- pos
, ret
))
4517 if (mask
& WPA_BSS_MASK_SSID
) {
4518 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4519 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4520 if (os_snprintf_error(end
- pos
, ret
))
4526 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4527 ie
= (const u8
*) (bss
+ 1);
4528 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4529 if (ret
>= end
- pos
)
4534 #endif /* CONFIG_WPS */
4537 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4538 ie
= (const u8
*) (bss
+ 1);
4539 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4540 if (ret
>= end
- pos
)
4545 #endif /* CONFIG_P2P */
4547 #ifdef CONFIG_WIFI_DISPLAY
4548 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4550 ie
= (const u8
*) (bss
+ 1);
4551 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4552 WFD_IE_VENDOR_TYPE
);
4554 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4555 if (os_snprintf_error(end
- pos
, ret
)) {
4561 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4566 ret
= os_snprintf(pos
, end
- pos
, "\n");
4567 if (os_snprintf_error(end
- pos
, ret
))
4572 #endif /* CONFIG_WIFI_DISPLAY */
4574 #ifdef CONFIG_INTERWORKING
4575 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4576 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4577 struct wpa_bss_anqp_elem
*elem
;
4579 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4580 anqp
->capability_list
);
4581 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4583 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4584 anqp
->network_auth_type
);
4585 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4586 anqp
->roaming_consortium
);
4587 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4588 anqp
->ip_addr_type_availability
);
4589 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4591 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4592 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4594 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4595 anqp
->fils_realm_info
);
4597 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4598 anqp
->hs20_capability_list
);
4599 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4600 anqp
->hs20_operator_friendly_name
);
4601 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4602 anqp
->hs20_wan_metrics
);
4603 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4604 anqp
->hs20_connection_capability
);
4605 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4606 anqp
->hs20_operating_class
);
4607 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4608 anqp
->hs20_osu_providers_list
);
4609 #endif /* CONFIG_HS20 */
4611 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4612 struct wpa_bss_anqp_elem
, list
) {
4615 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4617 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4620 #endif /* CONFIG_INTERWORKING */
4623 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4624 ie
= (const u8
*) (bss
+ 1);
4625 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4626 if (ret
>= end
- pos
)
4631 #endif /* CONFIG_MESH */
4633 if (mask
& WPA_BSS_MASK_SNR
) {
4634 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4635 if (os_snprintf_error(end
- pos
, ret
))
4640 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4641 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4642 bss
->est_throughput
);
4643 if (os_snprintf_error(end
- pos
, ret
))
4649 if (mask
& WPA_BSS_MASK_FST
) {
4650 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4651 if (ret
< 0 || ret
>= end
- pos
)
4655 #endif /* CONFIG_FST */
4657 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4658 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4659 bss
->last_update_idx
);
4660 if (os_snprintf_error(end
- pos
, ret
))
4665 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4666 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4667 if (os_snprintf_error(end
- pos
, ret
))
4671 ie
= (const u8
*) (bss
+ 1);
4673 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4674 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4675 if (os_snprintf_error(end
- pos
, ret
))
4680 ret
= os_snprintf(pos
, end
- pos
, "\n");
4681 if (os_snprintf_error(end
- pos
, ret
))
4687 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4688 ret
= print_fils_indication(bss
, pos
, end
);
4693 #endif /* CONFIG_FILS */
4695 if (mask
& WPA_BSS_MASK_DELIM
) {
4696 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4697 if (os_snprintf_error(end
- pos
, ret
))
4706 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4707 const char *cmd
, char *buf
,
4712 struct wpa_bss
*bss
;
4713 struct wpa_bss
*bsslast
= NULL
;
4714 struct dl_list
*next
;
4717 char *ctmp
, *end
= buf
+ buflen
;
4718 unsigned long mask
= WPA_BSS_MASK_ALL
;
4720 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4721 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4722 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4724 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4726 } else { /* N1-N2 */
4727 unsigned int id1
, id2
;
4729 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4730 wpa_printf(MSG_INFO
, "Wrong BSS range "
4735 if (*(cmd
+ 6) == '-')
4738 id1
= atoi(cmd
+ 6);
4740 if (*ctmp
>= '0' && *ctmp
<= '9')
4743 id2
= (unsigned int) -1;
4744 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4745 if (id2
== (unsigned int) -1)
4746 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4750 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4751 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4752 struct wpa_bss
*tmp
= bss
;
4754 next
= tmp
->list_id
.next
;
4755 if (next
== &wpa_s
->bss_id
)
4757 tmp
= dl_list_entry(
4758 next
, struct wpa_bss
,
4767 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4768 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4769 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4770 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4771 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4773 bss
= wpa_bss_get_id(wpa_s
, i
);
4774 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4776 bss
= wpa_bss_get_id(wpa_s
, i
);
4778 next
= bss
->list_id
.next
;
4779 if (next
== &wpa_s
->bss_id
)
4782 bss
= dl_list_entry(next
, struct wpa_bss
,
4785 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
4786 bss
= wpa_s
->current_bss
;
4788 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4789 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4790 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4793 #endif /* CONFIG_P2P */
4794 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4795 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4797 struct wpa_bss
*tmp
;
4800 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4809 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4810 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4812 mask
= WPA_BSS_MASK_ALL
;
4818 if (bsslast
== NULL
)
4821 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4825 if (bss
== bsslast
) {
4826 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4827 (bss
== dl_list_last(&wpa_s
->bss_id
,
4828 struct wpa_bss
, list_id
))) {
4831 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4833 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4834 wpa_printf(MSG_DEBUG
,
4835 "Could not add end delim");
4840 next
= bss
->list_id
.next
;
4841 if (next
== &wpa_s
->bss_id
)
4843 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4844 } while (bss
&& len
);
4850 static int wpa_supplicant_ctrl_iface_ap_scan(
4851 struct wpa_supplicant
*wpa_s
, char *cmd
)
4853 int ap_scan
= atoi(cmd
);
4854 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4858 static int wpa_supplicant_ctrl_iface_scan_interval(
4859 struct wpa_supplicant
*wpa_s
, char *cmd
)
4861 int scan_int
= atoi(cmd
);
4862 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4866 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4867 struct wpa_supplicant
*wpa_s
, char *cmd
)
4869 int expire_age
= atoi(cmd
);
4870 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4874 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4875 struct wpa_supplicant
*wpa_s
, char *cmd
)
4877 int expire_count
= atoi(cmd
);
4878 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4882 static void wpa_supplicant_ctrl_iface_bss_flush(
4883 struct wpa_supplicant
*wpa_s
, char *cmd
)
4885 int flush_age
= atoi(cmd
);
4888 wpa_bss_flush(wpa_s
);
4890 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4894 #ifdef CONFIG_TESTING_OPTIONS
4895 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4897 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4898 /* MLME-DELETEKEYS.request */
4899 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4900 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4901 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4902 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4903 #ifdef CONFIG_IEEE80211W
4904 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4905 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4906 #endif /* CONFIG_IEEE80211W */
4908 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4910 /* MLME-SETPROTECTION.request(None) */
4911 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4912 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4913 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4914 wpa_sm_drop_sa(wpa_s
->wpa
);
4916 #endif /* CONFIG_TESTING_OPTIONS */
4919 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4922 #ifdef CONFIG_NO_SCAN_PROCESSING
4924 #else /* CONFIG_NO_SCAN_PROCESSING */
4926 struct wpa_bss
*bss
;
4927 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4929 if (hwaddr_aton(addr
, bssid
)) {
4930 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4931 "address '%s'", addr
);
4935 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4938 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4939 "configuration known for the target AP");
4943 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4945 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4951 * TODO: Find best network configuration block from configuration to
4952 * allow roaming to other networks
4955 wpa_s
->reassociate
= 1;
4956 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4959 #endif /* CONFIG_NO_SCAN_PROCESSING */
4964 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
4966 unsigned int timeout
= atoi(cmd
);
4967 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
4968 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
4969 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
4971 unsigned int search_delay
;
4972 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
4976 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4977 wpa_dbg(wpa_s
, MSG_INFO
,
4978 "Reject P2P_FIND since interface is disabled");
4981 if (os_strstr(cmd
, "type=social"))
4982 type
= P2P_FIND_ONLY_SOCIAL
;
4983 else if (os_strstr(cmd
, "type=progressive"))
4984 type
= P2P_FIND_PROGRESSIVE
;
4986 pos
= os_strstr(cmd
, "dev_id=");
4989 if (hwaddr_aton(pos
, dev_id
))
4994 pos
= os_strstr(cmd
, "dev_type=");
4997 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
4999 _dev_type
= dev_type
;
5002 pos
= os_strstr(cmd
, "delay=");
5005 search_delay
= atoi(pos
);
5007 search_delay
= wpas_p2p_search_delay(wpa_s
);
5009 pos
= os_strstr(cmd
, "freq=");
5017 /* Must be searched for last, because it adds nul termination */
5018 pos
= os_strstr(cmd
, " seek=");
5021 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
5024 _seek
[seek_count
++] = pos
;
5026 term
= os_strchr(pos
, ' ');
5030 pos
= os_strstr(term
+ 1, "seek=");
5034 if (seek_count
> P2P_MAX_QUERY_HASH
) {
5039 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
5040 _dev_id
, search_delay
, seek_count
, seek
, freq
);
5044 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
5046 const char *last
= NULL
;
5051 /* Expected predefined CPT names delimited by ':' */
5052 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
5053 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
5054 wpa_printf(MSG_ERROR
,
5055 "P2PS: CPT name list is too long, expected up to %d names",
5056 P2PS_FEATURE_CAPAB_CPT_MAX
);
5061 token_len
= last
- token
;
5063 if (token_len
== 3 &&
5064 os_memcmp(token
, "UDP", token_len
) == 0) {
5065 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5066 } else if (token_len
== 3 &&
5067 os_memcmp(token
, "MAC", token_len
) == 0) {
5068 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
5070 wpa_printf(MSG_ERROR
,
5071 "P2PS: Unsupported CPT name '%s'", token
);
5076 if (isblank((unsigned char) *last
)) {
5086 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
5088 struct p2ps_provision
*p2ps_prov
;
5090 size_t info_len
= 0;
5092 u8 role
= P2PS_SETUP_NONE
;
5093 long long unsigned val
;
5096 pos
= os_strstr(cmd
, "info=");
5099 info_len
= os_strlen(pos
);
5102 info
= os_malloc(info_len
+ 1);
5104 info_len
= utf8_unescape(pos
, info_len
,
5105 info
, info_len
+ 1);
5111 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5112 if (p2ps_prov
== NULL
) {
5118 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5119 p2ps_prov
->info
[info_len
] = '\0';
5123 pos
= os_strstr(cmd
, "status=");
5125 p2ps_prov
->status
= atoi(pos
+ 7);
5127 p2ps_prov
->status
= -1;
5129 pos
= os_strstr(cmd
, "adv_id=");
5130 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5132 p2ps_prov
->adv_id
= val
;
5134 pos
= os_strstr(cmd
, "method=");
5136 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5138 p2ps_prov
->method
= 0;
5140 pos
= os_strstr(cmd
, "session=");
5141 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5143 p2ps_prov
->session_id
= val
;
5145 pos
= os_strstr(cmd
, "adv_mac=");
5146 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5149 pos
= os_strstr(cmd
, "session_mac=");
5150 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5153 pos
= os_strstr(cmd
, "cpt=");
5155 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5156 p2ps_prov
->cpt_priority
))
5159 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5162 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5163 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5165 /* force conncap with tstCap (no sanity checks) */
5166 pos
= os_strstr(cmd
, "tstCap=");
5168 role
= strtol(pos
+ 7, NULL
, 16);
5170 pos
= os_strstr(cmd
, "role=");
5172 role
= strtol(pos
+ 5, NULL
, 16);
5173 if (role
!= P2PS_SETUP_CLIENT
&&
5174 role
!= P2PS_SETUP_GROUP_OWNER
)
5175 role
= P2PS_SETUP_NONE
;
5178 p2ps_prov
->role
= role
;
5188 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5191 struct p2ps_provision
*p2ps_prov
;
5194 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5196 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5198 if (hwaddr_aton(cmd
, addr
))
5205 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5209 if (p2ps_prov
->status
< 0) {
5214 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5219 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5222 struct p2ps_provision
*p2ps_prov
;
5225 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5226 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5229 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5230 if (hwaddr_aton(cmd
, addr
))
5237 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5241 p2ps_prov
->pd_seeker
= 1;
5243 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5248 static int parse_freq(int chwidth
, int freq2
)
5253 return VHT_CHANWIDTH_80P80MHZ
;
5259 return VHT_CHANWIDTH_USE_HT
;
5261 return VHT_CHANWIDTH_80MHZ
;
5263 return VHT_CHANWIDTH_160MHZ
;
5265 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5272 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5273 char *buf
, size_t buflen
)
5278 enum p2p_wps_method wps_method
;
5281 int persistent_group
, persistent_id
= -1;
5288 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5289 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5290 size_t group_ssid_len
= 0;
5292 if (!wpa_s
->global
->p2p_init_wpa_s
)
5294 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5295 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5296 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5297 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5300 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5301 * [persistent|persistent=<network id>]
5302 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5303 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5305 if (hwaddr_aton(cmd
, addr
))
5313 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5314 pos2
= os_strstr(pos
, " persistent=");
5316 struct wpa_ssid
*ssid
;
5317 persistent_id
= atoi(pos2
+ 12);
5318 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5319 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5320 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5321 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5322 "SSID id=%d for persistent P2P group (GO)",
5327 join
= os_strstr(pos
, " join") != NULL
;
5328 auth
= os_strstr(pos
, " auth") != NULL
;
5329 automatic
= os_strstr(pos
, " auto") != NULL
;
5330 pd
= os_strstr(pos
, " provdisc") != NULL
;
5331 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5332 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5335 pos2
= os_strstr(pos
, " go_intent=");
5338 go_intent
= atoi(pos2
);
5339 if (go_intent
< 0 || go_intent
> 15)
5343 pos2
= os_strstr(pos
, " freq=");
5351 pos2
= os_strstr(pos
, " freq2=");
5353 freq2
= atoi(pos2
+ 7);
5355 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5357 chwidth
= atoi(pos2
+ 18);
5359 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5360 if (max_oper_chwidth
< 0)
5363 pos2
= os_strstr(pos
, " ssid=");
5368 end
= os_strchr(pos2
, ' ');
5370 group_ssid_len
= os_strlen(pos2
) / 2;
5372 group_ssid_len
= (end
- pos2
) / 2;
5373 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5374 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5376 group_ssid
= _group_ssid
;
5379 if (os_strncmp(pos
, "pin", 3) == 0) {
5380 /* Request random PIN (to be displayed) and enable the PIN */
5381 wps_method
= WPS_PIN_DISPLAY
;
5382 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5383 wps_method
= WPS_PBC
;
5384 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5385 wps_method
= WPS_P2PS
;
5388 pos
= os_strchr(pin
, ' ');
5389 wps_method
= WPS_PIN_KEYPAD
;
5392 if (os_strncmp(pos
, "display", 7) == 0)
5393 wps_method
= WPS_PIN_DISPLAY
;
5395 if (!wps_pin_str_valid(pin
)) {
5396 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5401 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5402 persistent_group
, automatic
, join
,
5403 auth
, go_intent
, freq
, freq2
, persistent_id
,
5404 pd
, ht40
, vht
, max_oper_chwidth
,
5405 group_ssid
, group_ssid_len
);
5406 if (new_pin
== -2) {
5407 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5410 if (new_pin
== -3) {
5411 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5416 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5417 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5418 if (os_snprintf_error(buflen
, ret
))
5423 os_memcpy(buf
, "OK\n", 3);
5428 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5430 unsigned int timeout
= atoi(cmd
);
5431 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5432 wpa_dbg(wpa_s
, MSG_INFO
,
5433 "Reject P2P_LISTEN since interface is disabled");
5436 return wpas_p2p_listen(wpa_s
, timeout
);
5440 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5444 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5446 /* <addr> <config method> [join|auto] */
5448 if (hwaddr_aton(cmd
, addr
))
5456 if (os_strstr(pos
, " join") != NULL
)
5457 use
= WPAS_P2P_PD_FOR_JOIN
;
5458 else if (os_strstr(pos
, " auto") != NULL
)
5459 use
= WPAS_P2P_PD_AUTO
;
5461 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5465 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5468 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5470 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5471 ssid
->passphrase
== NULL
)
5474 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5475 return os_strlen(buf
);
5479 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5480 char *buf
, size_t buflen
)
5484 u8 dst_buf
[ETH_ALEN
], *dst
;
5485 struct wpabuf
*tlvs
;
5489 if (hwaddr_aton(cmd
, dst_buf
))
5492 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5493 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5500 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5503 if (hexstr2bin(pos
, &version
, 1) < 0)
5509 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5510 #ifdef CONFIG_WIFI_DISPLAY
5511 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5512 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5513 #endif /* CONFIG_WIFI_DISPLAY */
5514 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5516 char *svc_info
= NULL
;
5520 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5523 pos
= os_strchr(pos
, ' ');
5524 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5529 pos
= os_strchr(svc_str
, ' ');
5534 /* All remaining data is the svc_info string */
5535 if (pos
&& pos
[0] && pos
[0] != ' ') {
5536 len
= os_strlen(pos
);
5538 /* Unescape in place */
5539 len
= utf8_unescape(pos
, len
, pos
, len
);
5546 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5549 len
= os_strlen(pos
);
5553 tlvs
= wpabuf_alloc(len
);
5556 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5561 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5566 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5567 if (os_snprintf_error(buflen
, res
))
5573 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5576 long long unsigned val
;
5578 if (sscanf(cmd
, "%llx", &val
) != 1)
5581 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5585 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5590 struct wpabuf
*resp_tlvs
;
5594 pos
= os_strchr(cmd
, ' ');
5602 if (hwaddr_aton(pos
, dst
))
5609 pos2
= os_strchr(pos
, ' ');
5613 dialog_token
= atoi(pos
);
5615 len
= os_strlen(pos2
);
5619 resp_tlvs
= wpabuf_alloc(len
);
5620 if (resp_tlvs
== NULL
)
5622 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5623 wpabuf_free(resp_tlvs
);
5627 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5628 wpabuf_free(resp_tlvs
);
5633 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5636 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5638 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5643 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5648 struct wpabuf
*query
, *resp
;
5650 pos
= os_strchr(cmd
, ' ');
5655 len
= os_strlen(cmd
);
5659 query
= wpabuf_alloc(len
);
5662 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5667 len
= os_strlen(pos
);
5673 resp
= wpabuf_alloc(len
);
5678 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5684 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5693 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5698 pos
= os_strchr(cmd
, ' ');
5703 if (hexstr2bin(cmd
, &version
, 1) < 0)
5706 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5710 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5711 u8 replace
, char *cmd
)
5715 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5716 char *svc_info
= NULL
;
5718 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5720 pos
= os_strchr(cmd
, ' ');
5725 /* Auto-Accept value is mandatory, and must be one of the
5726 * single values (0, 1, 2, 4) */
5727 auto_accept
= atoi(cmd
);
5728 switch (auto_accept
) {
5729 case P2PS_SETUP_NONE
: /* No auto-accept */
5730 case P2PS_SETUP_NEW
:
5731 case P2PS_SETUP_CLIENT
:
5732 case P2PS_SETUP_GROUP_OWNER
:
5738 /* Advertisement ID is mandatory */
5740 pos
= os_strchr(cmd
, ' ');
5745 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5746 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5749 /* Only allow replacements if exist, and adds if not */
5750 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5758 /* svc_state between 0 - 0xff is mandatory */
5759 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5762 pos
= os_strchr(pos
, ' ');
5766 /* config_methods is mandatory */
5768 if (sscanf(pos
, "%x", &config_methods
) != 1)
5771 if (!(config_methods
&
5772 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5775 pos
= os_strchr(pos
, ' ');
5782 /* Advertisement string is mandatory */
5783 if (!pos
[0] || pos
[0] == ' ')
5786 /* Terminate svc string */
5787 pos
= os_strchr(pos
, ' ');
5791 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5793 pos
= os_strchr(pos
, ' ');
5797 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5800 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5804 /* Service and Response Information are optional */
5805 if (pos
&& pos
[0]) {
5808 /* Note the bare ' included, which cannot exist legally
5809 * in unescaped string. */
5810 svc_info
= os_strstr(pos
, "svc_info='");
5814 len
= os_strlen(svc_info
);
5815 utf8_unescape(svc_info
, len
, svc_info
, len
);
5819 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
5820 (u8
) svc_state
, (u16
) config_methods
,
5821 svc_info
, cpt_prio
);
5825 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5829 pos
= os_strchr(cmd
, ' ');
5834 if (os_strcmp(cmd
, "bonjour") == 0)
5835 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
5836 if (os_strcmp(cmd
, "upnp") == 0)
5837 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
5838 if (os_strcmp(cmd
, "asp") == 0)
5839 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
5840 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5845 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
5849 struct wpabuf
*query
;
5852 len
= os_strlen(cmd
);
5856 query
= wpabuf_alloc(len
);
5859 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5864 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
5870 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5875 pos
= os_strchr(cmd
, ' ');
5880 if (hexstr2bin(cmd
, &version
, 1) < 0)
5883 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
5887 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5891 if (os_strcmp(cmd
, "all") == 0) {
5892 wpas_p2p_service_flush_asp(wpa_s
);
5896 if (sscanf(cmd
, "%x", &adv_id
) != 1)
5899 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
5903 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
5907 pos
= os_strchr(cmd
, ' ');
5912 if (os_strcmp(cmd
, "bonjour") == 0)
5913 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
5914 if (os_strcmp(cmd
, "upnp") == 0)
5915 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
5916 if (os_strcmp(cmd
, "asp") == 0)
5917 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
5918 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5923 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
5927 pos
= os_strchr(cmd
, ' ');
5932 if (os_strcmp(cmd
, "asp") == 0)
5933 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
5935 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5940 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
5946 if (hwaddr_aton(cmd
, addr
))
5949 return wpas_p2p_reject(wpa_s
, addr
);
5953 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
5957 struct wpa_ssid
*ssid
;
5958 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
5959 int freq
= 0, pref_freq
= 0;
5960 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5963 pos
= os_strstr(cmd
, " peer=");
5966 if (hwaddr_aton(pos
, peer
))
5970 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
5971 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
5972 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
5973 "for persistent P2P group",
5978 pos
= os_strstr(cmd
, " freq=");
5986 pos
= os_strstr(cmd
, " pref=");
5989 pref_freq
= atoi(pos
);
5994 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5995 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5998 pos
= os_strstr(cmd
, "freq2=");
6000 freq2
= atoi(pos
+ 6);
6002 pos
= os_strstr(cmd
, " max_oper_chwidth=");
6004 chwidth
= atoi(pos
+ 18);
6006 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6007 if (max_oper_chwidth
< 0)
6010 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
6011 max_oper_chwidth
, pref_freq
);
6015 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
6018 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
6020 pos
= os_strstr(cmd
, " peer=");
6026 if (hwaddr_aton(pos
, peer
)) {
6027 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
6031 pos
= os_strstr(pos
, " go_dev_addr=");
6034 if (hwaddr_aton(pos
, go_dev_addr
)) {
6035 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
6039 go_dev
= go_dev_addr
;
6042 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
6046 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
6048 if (os_strncmp(cmd
, "persistent=", 11) == 0)
6049 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
6050 if (os_strncmp(cmd
, "group=", 6) == 0)
6051 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
6057 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6058 int id
, int freq
, int vht_center_freq2
,
6059 int ht40
, int vht
, int vht_chwidth
)
6061 struct wpa_ssid
*ssid
;
6063 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
6064 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
6065 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
6066 "for persistent P2P group",
6071 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
6072 vht_center_freq2
, 0, ht40
, vht
,
6073 vht_chwidth
, NULL
, 0, 0);
6077 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6079 int freq
= 0, persistent
= 0, group_id
= -1;
6080 int vht
= wpa_s
->conf
->p2p_go_vht
;
6081 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
6082 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
6083 char *token
, *context
= NULL
;
6085 while ((token
= str_token(cmd
, " ", &context
))) {
6086 if (sscanf(token
, "freq=%d", &freq
) == 1 ||
6087 sscanf(token
, "freq2=%d", &freq2
) == 1 ||
6088 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
6089 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
6091 } else if (os_strcmp(token
, "ht40") == 0) {
6093 } else if (os_strcmp(token
, "vht") == 0) {
6096 } else if (os_strcmp(token
, "persistent") == 0) {
6099 wpa_printf(MSG_DEBUG
,
6100 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6106 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6107 if (max_oper_chwidth
< 0)
6111 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6112 freq
, freq2
, ht40
, vht
,
6115 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6120 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6121 char *buf
, size_t buflen
)
6123 u8 dev_addr
[ETH_ALEN
];
6124 struct wpa_ssid
*ssid
;
6128 ssid
= wpa_s
->current_ssid
;
6129 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6130 hwaddr_aton(cmd
, dev_addr
))
6133 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6136 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6137 if (os_snprintf_error(buflen
, res
))
6143 static int wpas_find_p2p_dev_addr_bss(struct wpa_global
*global
,
6144 const u8
*p2p_dev_addr
)
6146 struct wpa_supplicant
*wpa_s
;
6148 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6149 if (wpa_bss_get_p2p_dev_addr(wpa_s
, p2p_dev_addr
))
6157 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6158 char *buf
, size_t buflen
)
6160 u8 addr
[ETH_ALEN
], *addr_ptr
, group_capab
;
6162 const struct p2p_peer_info
*info
;
6164 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6165 struct wpa_ssid
*ssid
;
6168 if (!wpa_s
->global
->p2p
)
6171 if (os_strcmp(cmd
, "FIRST") == 0) {
6174 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6175 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6180 if (hwaddr_aton(cmd
, addr
) < 0)
6186 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6189 group_capab
= info
->group_capab
;
6192 !wpas_find_p2p_dev_addr_bss(wpa_s
->global
, info
->p2p_device_addr
)) {
6193 wpa_printf(MSG_DEBUG
,
6194 "P2P: Could not find any BSS with p2p_dev_addr "
6195 MACSTR
", hence override group_capab from 0x%x to 0",
6196 MAC2STR(info
->p2p_device_addr
), group_capab
);
6203 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6209 "serial_number=%s\n"
6210 "config_methods=0x%x\n"
6212 "group_capab=0x%x\n"
6214 MAC2STR(info
->p2p_device_addr
),
6215 wps_dev_type_bin2str(info
->pri_dev_type
,
6216 devtype
, sizeof(devtype
)),
6221 info
->serial_number
,
6222 info
->config_methods
,
6226 if (os_snprintf_error(end
- pos
, res
))
6230 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6233 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6234 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6235 wps_dev_type_bin2str(t
, devtype
,
6237 if (os_snprintf_error(end
- pos
, res
))
6242 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6244 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6245 if (os_snprintf_error(end
- pos
, res
))
6250 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6255 if (info
->vendor_elems
) {
6256 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6257 if (os_snprintf_error(end
- pos
, res
))
6261 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6262 wpabuf_head(info
->vendor_elems
),
6263 wpabuf_len(info
->vendor_elems
));
6265 res
= os_snprintf(pos
, end
- pos
, "\n");
6266 if (os_snprintf_error(end
- pos
, res
))
6275 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6280 if (wpa_s
->global
->p2p
== NULL
)
6283 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6286 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6287 struct wpa_freq_range
*freq
;
6288 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6289 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6290 freq
->min
, freq
->max
);
6293 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6298 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6302 if (wpa_s
->global
->p2p
== NULL
)
6305 param
= os_strchr(cmd
, ' ');
6310 if (os_strcmp(cmd
, "discoverability") == 0) {
6311 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6316 if (os_strcmp(cmd
, "managed") == 0) {
6317 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6321 if (os_strcmp(cmd
, "listen_channel") == 0) {
6323 u8 channel
, op_class
;
6325 channel
= atoi(param
);
6326 pos
= os_strchr(param
, ' ');
6327 op_class
= pos
? atoi(pos
) : 81;
6329 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6333 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6334 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6338 if (os_strcmp(cmd
, "noa") == 0) {
6340 int count
, start
, duration
;
6341 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6342 count
= atoi(param
);
6343 pos
= os_strchr(param
, ',');
6348 pos
= os_strchr(pos
, ',');
6352 duration
= atoi(pos
);
6353 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6355 if (count
== 0 && duration
> 0)
6357 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6358 "start=%d duration=%d", count
, start
, duration
);
6359 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6362 if (os_strcmp(cmd
, "ps") == 0)
6363 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6365 if (os_strcmp(cmd
, "oppps") == 0)
6366 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6368 if (os_strcmp(cmd
, "ctwindow") == 0)
6369 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6371 if (os_strcmp(cmd
, "disabled") == 0) {
6372 wpa_s
->global
->p2p_disabled
= atoi(param
);
6373 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6374 wpa_s
->global
->p2p_disabled
?
6375 "disabled" : "enabled");
6376 if (wpa_s
->global
->p2p_disabled
) {
6377 wpas_p2p_stop_find(wpa_s
);
6378 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6379 p2p_flush(wpa_s
->global
->p2p
);
6384 if (os_strcmp(cmd
, "conc_pref") == 0) {
6385 if (os_strcmp(param
, "sta") == 0)
6386 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6387 else if (os_strcmp(param
, "p2p") == 0)
6388 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6390 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6393 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6398 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6399 wpa_s
->force_long_sd
= atoi(param
);
6403 if (os_strcmp(cmd
, "peer_filter") == 0) {
6405 if (hwaddr_aton(param
, addr
))
6407 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6411 if (os_strcmp(cmd
, "cross_connect") == 0)
6412 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6414 if (os_strcmp(cmd
, "go_apsd") == 0) {
6415 if (os_strcmp(param
, "disable") == 0)
6416 wpa_s
->set_ap_uapsd
= 0;
6418 wpa_s
->set_ap_uapsd
= 1;
6419 wpa_s
->ap_uapsd
= atoi(param
);
6424 if (os_strcmp(cmd
, "client_apsd") == 0) {
6425 if (os_strcmp(param
, "disable") == 0)
6426 wpa_s
->set_sta_uapsd
= 0;
6430 /* format: BE,BK,VI,VO;max SP Length */
6432 pos
= os_strchr(param
, ',');
6437 pos
= os_strchr(pos
, ',');
6442 pos
= os_strchr(pos
, ',');
6447 /* ignore max SP Length for now */
6449 wpa_s
->set_sta_uapsd
= 1;
6450 wpa_s
->sta_uapsd
= 0;
6452 wpa_s
->sta_uapsd
|= BIT(0);
6454 wpa_s
->sta_uapsd
|= BIT(1);
6456 wpa_s
->sta_uapsd
|= BIT(2);
6458 wpa_s
->sta_uapsd
|= BIT(3);
6463 if (os_strcmp(cmd
, "disallow_freq") == 0)
6464 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6466 if (os_strcmp(cmd
, "disc_int") == 0) {
6467 int min_disc_int
, max_disc_int
, max_disc_tu
;
6472 min_disc_int
= atoi(pos
);
6473 pos
= os_strchr(pos
, ' ');
6478 max_disc_int
= atoi(pos
);
6479 pos
= os_strchr(pos
, ' ');
6484 max_disc_tu
= atoi(pos
);
6486 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6487 max_disc_int
, max_disc_tu
);
6490 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6491 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6495 #ifdef CONFIG_WPS_NFC
6496 if (os_strcmp(cmd
, "nfc_tag") == 0)
6497 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6498 #endif /* CONFIG_WPS_NFC */
6500 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6501 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6505 if (os_strcmp(cmd
, "override_pref_op_chan") == 0) {
6508 op_class
= atoi(param
);
6509 param
= os_strchr(param
, ':');
6514 p2p_set_override_pref_op_chan(wpa_s
->global
->p2p
, op_class
,
6519 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6526 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6528 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6529 wpa_s
->force_long_sd
= 0;
6530 wpas_p2p_stop_find(wpa_s
);
6531 wpa_s
->parent
->p2ps_method_config_any
= 0;
6532 if (wpa_s
->global
->p2p
)
6533 p2p_flush(wpa_s
->global
->p2p
);
6537 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6540 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6543 pos
= os_strchr(cmd
, ' ');
6549 pos2
= os_strchr(pos
, ' ');
6557 pos
= os_strchr(pos2
, ' ');
6565 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6569 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6572 unsigned int period
= 0, interval
= 0;
6575 pos
= os_strchr(cmd
, ' ');
6580 interval
= atoi(pos
);
6583 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6587 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6594 if (os_strncmp(pos
, "iface=", 6) == 0) {
6598 if (hwaddr_aton(pos
, peer
))
6601 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6606 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6608 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6610 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6612 wpa_printf(MSG_DEBUG
,
6613 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6617 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6620 #endif /* CONFIG_P2P */
6623 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6625 struct wpa_freq_range_list ranges
;
6627 struct hostapd_hw_modes
*mode
;
6630 if (wpa_s
->hw
.modes
== NULL
)
6633 os_memset(&ranges
, 0, sizeof(ranges
));
6634 if (freq_range_list_parse(&ranges
, val
) < 0)
6637 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6640 mode
= &wpa_s
->hw
.modes
[i
];
6641 for (j
= 0; j
< mode
->num_channels
; j
++) {
6644 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6647 freq
= mode
->channels
[j
].freq
;
6648 if (!freq_range_list_includes(&ranges
, freq
))
6651 int_array_add_unique(&freqs
, freq
);
6655 os_free(ranges
.range
);
6660 #ifdef CONFIG_INTERWORKING
6662 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6670 auto_sel
= os_strstr(param
, "auto") != NULL
;
6672 pos
= os_strstr(param
, "freq=");
6674 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6681 return interworking_select(wpa_s
, auto_sel
, freqs
);
6685 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6689 struct wpa_bss
*bss
;
6691 if (hwaddr_aton(dst
, bssid
)) {
6692 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6696 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6698 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6703 if (bss
->ssid_len
== 0) {
6706 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6707 " does not have SSID information", MAC2STR(bssid
));
6709 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6711 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6712 bss
->ssid_len
> 0) {
6720 wpa_printf(MSG_DEBUG
,
6721 "Found another matching BSS entry with SSID");
6724 return interworking_connect(wpa_s
, bss
, only_add
);
6728 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6730 u8 dst_addr
[ETH_ALEN
];
6733 #define MAX_ANQP_INFO_ID 100
6734 u16 id
[MAX_ANQP_INFO_ID
];
6737 u32 mbo_subtypes
= 0;
6739 used
= hwaddr_aton2(dst
, dst_addr
);
6745 while (num_id
< MAX_ANQP_INFO_ID
) {
6746 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6748 int num
= atoi(pos
+ 5);
6749 if (num
<= 0 || num
> 31)
6751 subtypes
|= BIT(num
);
6752 #else /* CONFIG_HS20 */
6754 #endif /* CONFIG_HS20 */
6755 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6757 int num
= atoi(pos
+ 4);
6759 if (num
<= 0 || num
> MAX_MBO_ANQP_SUBTYPE
)
6761 mbo_subtypes
|= BIT(num
);
6762 #else /* CONFIG_MBO */
6764 #endif /* CONFIG_MBO */
6766 id
[num_id
] = atoi(pos
);
6770 pos
= os_strchr(pos
+ 1, ',');
6776 if (num_id
== 0 && !subtypes
&& !mbo_subtypes
)
6779 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
6784 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
6786 u8 dst_addr
[ETH_ALEN
];
6787 struct wpabuf
*advproto
, *query
= NULL
;
6792 used
= hwaddr_aton2(cmd
, dst_addr
);
6800 /* Advertisement Protocol ID */
6801 end
= os_strchr(pos
, ' ');
6805 len
= os_strlen(pos
);
6811 advproto
= wpabuf_alloc(len
);
6812 if (advproto
== NULL
)
6814 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
6818 /* Optional Query Request */
6823 len
= os_strlen(pos
);
6830 query
= wpabuf_alloc(len
);
6833 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
6838 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
6841 wpabuf_free(advproto
);
6848 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
6855 size_t resp_len
, start
, requested_len
;
6856 struct wpabuf
*resp
;
6859 used
= hwaddr_aton2(cmd
, addr
);
6866 dialog_token
= atoi(pos
);
6868 if (wpa_s
->last_gas_resp
&&
6869 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
6870 dialog_token
== wpa_s
->last_gas_dialog_token
)
6871 resp
= wpa_s
->last_gas_resp
;
6872 else if (wpa_s
->prev_gas_resp
&&
6873 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
6874 dialog_token
== wpa_s
->prev_gas_dialog_token
)
6875 resp
= wpa_s
->prev_gas_resp
;
6879 resp_len
= wpabuf_len(resp
);
6881 requested_len
= resp_len
;
6883 pos
= os_strchr(pos
, ' ');
6886 if (start
> resp_len
)
6887 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6888 pos
= os_strchr(pos
, ',');
6892 requested_len
= atoi(pos
);
6893 if (start
+ requested_len
> resp_len
)
6894 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6897 if (requested_len
* 2 + 1 > buflen
)
6898 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
6900 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
6903 if (start
+ requested_len
== resp_len
) {
6905 * Free memory by dropping the response after it has been
6908 if (resp
== wpa_s
->prev_gas_resp
) {
6909 wpabuf_free(wpa_s
->prev_gas_resp
);
6910 wpa_s
->prev_gas_resp
= NULL
;
6912 wpabuf_free(wpa_s
->last_gas_resp
);
6913 wpa_s
->last_gas_resp
= NULL
;
6919 #endif /* CONFIG_INTERWORKING */
6924 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6926 u8 dst_addr
[ETH_ALEN
];
6931 used
= hwaddr_aton2(dst
, dst_addr
);
6938 int num
= atoi(pos
);
6939 if (num
<= 0 || num
> 31)
6941 subtypes
|= BIT(num
);
6942 pos
= os_strchr(pos
+ 1, ',');
6951 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
6955 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
6956 const u8
*addr
, const char *realm
)
6962 rlen
= os_strlen(realm
);
6964 buf
= os_malloc(len
);
6967 buf
[0] = 1; /* NAI Home Realm Count */
6968 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
6970 os_memcpy(buf
+ 3, realm
, rlen
);
6972 ret
= hs20_anqp_send_req(wpa_s
, addr
,
6973 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
6982 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
6985 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
6986 u8 dst_addr
[ETH_ALEN
];
6992 used
= hwaddr_aton2(dst
, dst_addr
);
6996 while (dst
[used
] == ' ')
6998 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
6999 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
7002 len
= os_strlen(dst
+ used
);
7004 if (len
== 0 && cred
&& cred
->realm
)
7005 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
7010 buf
= os_malloc(len
);
7013 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
7018 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
7019 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
7027 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
7030 u8 dst_addr
[ETH_ALEN
];
7032 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
7034 used
= hwaddr_aton2(cmd
, dst_addr
);
7039 icon
= str_token(cmd
, " ", &ctx
);
7040 poffset
= str_token(cmd
, " ", &ctx
);
7041 psize
= str_token(cmd
, " ", &ctx
);
7042 if (!icon
|| !poffset
|| !psize
)
7045 wpa_s
->fetch_osu_icon_in_progress
= 0;
7046 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
7051 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
7053 u8 dst_addr
[ETH_ALEN
];
7058 return hs20_del_icon(wpa_s
, NULL
, NULL
);
7060 used
= hwaddr_aton2(cmd
, dst_addr
);
7064 while (cmd
[used
] == ' ')
7066 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
7068 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
7072 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
7074 u8 dst_addr
[ETH_ALEN
];
7078 used
= hwaddr_aton2(cmd
, dst_addr
);
7082 while (cmd
[used
] == ' ')
7086 wpa_s
->fetch_osu_icon_in_progress
= 0;
7087 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
7088 (u8
*) icon
, os_strlen(icon
), inmem
);
7091 #endif /* CONFIG_HS20 */
7094 #ifdef CONFIG_AUTOSCAN
7096 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
7099 enum wpa_states state
= wpa_s
->wpa_state
;
7100 char *new_params
= NULL
;
7102 if (os_strlen(cmd
) > 0) {
7103 new_params
= os_strdup(cmd
);
7104 if (new_params
== NULL
)
7108 os_free(wpa_s
->conf
->autoscan
);
7109 wpa_s
->conf
->autoscan
= new_params
;
7111 if (wpa_s
->conf
->autoscan
== NULL
)
7112 autoscan_deinit(wpa_s
);
7113 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
7114 autoscan_init(wpa_s
, 1);
7115 else if (state
== WPA_SCANNING
)
7116 wpa_supplicant_reinit_autoscan(wpa_s
);
7118 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
7119 wpa_supplicant_state_txt(state
));
7124 #endif /* CONFIG_AUTOSCAN */
7129 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
7135 struct wpabuf
*tfs_req
= NULL
;
7137 if (os_strncmp(cmd
, "enter", 5) == 0)
7139 else if (os_strncmp(cmd
, "exit", 4) == 0)
7144 pos
= os_strstr(cmd
, " interval=");
7146 intval
= atoi(pos
+ 10);
7148 pos
= os_strstr(cmd
, " tfs_req=");
7153 end
= os_strchr(pos
, ' ');
7157 len
= os_strlen(pos
);
7161 tfs_req
= wpabuf_alloc(len
);
7162 if (tfs_req
== NULL
)
7164 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7165 wpabuf_free(tfs_req
);
7170 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7171 WNM_SLEEP_MODE_EXIT
, intval
,
7173 wpabuf_free(tfs_req
);
7179 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7181 int query_reason
, list
= 0;
7182 char *btm_candidates
= NULL
;
7184 query_reason
= atoi(cmd
);
7186 cmd
= os_strchr(cmd
, ' ');
7188 if (os_strncmp(cmd
, " list", 5) == 0)
7191 btm_candidates
= cmd
;
7194 wpa_printf(MSG_DEBUG
,
7195 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7196 query_reason
, list
? " candidate list" : "");
7198 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
,
7203 #endif /* CONFIG_WNM */
7206 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7209 struct wpa_signal_info si
;
7213 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7220 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7221 "NOISE=%d\nFREQUENCY=%u\n",
7222 si
.current_signal
, si
.current_txrate
/ 1000,
7223 si
.current_noise
, si
.frequency
);
7224 if (os_snprintf_error(end
- pos
, ret
))
7228 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7229 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7230 channel_width_to_string(si
.chanwidth
));
7231 if (os_snprintf_error(end
- pos
, ret
))
7236 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
7237 ret
= os_snprintf(pos
, end
- pos
,
7238 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7239 si
.center_frq1
, si
.center_frq2
);
7240 if (os_snprintf_error(end
- pos
, ret
))
7245 if (si
.avg_signal
) {
7246 ret
= os_snprintf(pos
, end
- pos
,
7247 "AVG_RSSI=%d\n", si
.avg_signal
);
7248 if (os_snprintf_error(end
- pos
, ret
))
7253 if (si
.avg_beacon_signal
) {
7254 ret
= os_snprintf(pos
, end
- pos
,
7255 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7256 if (os_snprintf_error(end
- pos
, ret
))
7265 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7272 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7273 wpa_printf(MSG_DEBUG
,
7274 "Reject SIGNAL_MONITOR command - bgscan is active");
7277 pos
= os_strstr(cmd
, "THRESHOLD=");
7279 threshold
= atoi(pos
+ 10);
7280 pos
= os_strstr(cmd
, "HYSTERESIS=");
7282 hysteresis
= atoi(pos
+ 11);
7283 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7287 #ifdef CONFIG_TESTING_OPTIONS
7288 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant
*wpa_s
,
7289 enum wpa_driver_if_type if_type
,
7291 unsigned int *freq_list
)
7293 char *pos
= wpa_s
->get_pref_freq_list_override
;
7295 unsigned int count
= 0;
7297 /* Override string format:
7298 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7301 if (atoi(pos
) == (int) if_type
)
7303 pos
= os_strchr(pos
, ' ');
7309 pos
= os_strchr(pos
, ':');
7313 end
= os_strchr(pos
, ' ');
7314 while (pos
&& (!end
|| pos
< end
) && count
< *num
) {
7315 freq_list
[count
++] = atoi(pos
);
7316 pos
= os_strchr(pos
, ',');
7324 #endif /* CONFIG_TESTING_OPTIONS */
7327 static int wpas_ctrl_iface_get_pref_freq_list(
7328 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7330 unsigned int freq_list
[100], num
= 100, i
;
7332 enum wpa_driver_if_type iface_type
;
7338 /* buf: "<interface_type>" */
7339 if (os_strcmp(cmd
, "STATION") == 0)
7340 iface_type
= WPA_IF_STATION
;
7341 else if (os_strcmp(cmd
, "AP") == 0)
7342 iface_type
= WPA_IF_AP_BSS
;
7343 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7344 iface_type
= WPA_IF_P2P_GO
;
7345 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7346 iface_type
= WPA_IF_P2P_CLIENT
;
7347 else if (os_strcmp(cmd
, "IBSS") == 0)
7348 iface_type
= WPA_IF_IBSS
;
7349 else if (os_strcmp(cmd
, "TDLS") == 0)
7350 iface_type
= WPA_IF_TDLS
;
7354 wpa_printf(MSG_DEBUG
,
7355 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7358 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7362 for (i
= 0; i
< num
; i
++) {
7363 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7364 i
> 0 ? "," : "", freq_list
[i
]);
7365 if (os_snprintf_error(end
- pos
, ret
))
7374 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7375 char *buf
, size_t buflen
)
7380 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7381 (long long unsigned) wpa_s
->drv_flags
);
7382 if (os_snprintf_error(buflen
, ret
))
7388 for (i
= 0; i
< 64; i
++) {
7389 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7390 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7391 driver_flag_to_string(1LLU << i
));
7392 if (os_snprintf_error(end
- pos
, ret
))
7402 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7405 struct hostap_sta_driver_data sta
;
7408 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7412 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7413 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7414 if (os_snprintf_error(buflen
, ret
))
7421 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7422 char *buf
, size_t buflen
)
7426 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7428 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7429 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7432 country
[0] = cmd
[8];
7433 country
[1] = cmd
[9];
7435 p2p_set_country(p2p
, country
);
7438 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7439 if (os_snprintf_error(buflen
, ret
))
7444 #endif /* ANDROID */
7447 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7448 char *buf
, size_t buflen
)
7453 unsigned int vendor_id
, subcmd
;
7454 struct wpabuf
*reply
;
7455 size_t data_len
= 0;
7457 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7458 vendor_id
= strtoul(cmd
, &pos
, 16);
7459 if (!isblank((unsigned char) *pos
))
7462 subcmd
= strtoul(pos
, &pos
, 10);
7465 if (!isblank((unsigned char) *pos
++))
7467 data_len
= os_strlen(pos
);
7472 data
= os_malloc(data_len
);
7476 if (hexstr2bin(pos
, data
, data_len
)) {
7477 wpa_printf(MSG_DEBUG
,
7478 "Vendor command: wrong parameter format");
7484 reply
= wpabuf_alloc((buflen
- 1) / 2);
7490 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7494 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7504 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7507 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7508 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7509 #endif /* CONFIG_P2P */
7511 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7513 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7514 wpa_s
->ignore_post_flush_scan_res
= 1;
7516 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7518 * Avoid possible auto connect re-connection on getting
7519 * disconnected due to state flush.
7521 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7525 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7526 wpas_p2p_cancel(p2p_wpa_s
);
7527 p2p_ctrl_flush(p2p_wpa_s
);
7528 wpas_p2p_service_flush(p2p_wpa_s
);
7529 p2p_wpa_s
->global
->p2p_disabled
= 0;
7530 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7531 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7532 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7533 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7534 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7535 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7536 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7537 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7538 #endif /* CONFIG_P2P */
7540 #ifdef CONFIG_WPS_TESTING
7541 wps_version_number
= 0x20;
7542 wps_testing_dummy_cred
= 0;
7543 wps_corrupt_pkhash
= 0;
7544 wps_force_auth_types_in_use
= 0;
7545 wps_force_encr_types_in_use
= 0;
7546 #endif /* CONFIG_WPS_TESTING */
7548 wpa_s
->wps_fragment_size
= 0;
7549 wpas_wps_cancel(wpa_s
);
7550 wps_registrar_flush(wpa_s
->wps
->registrar
);
7551 #endif /* CONFIG_WPS */
7552 wpa_s
->after_wps
= 0;
7553 wpa_s
->known_wps_freq
= 0;
7556 #ifdef CONFIG_TDLS_TESTING
7558 #endif /* CONFIG_TDLS_TESTING */
7559 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7560 wpa_tdls_enable(wpa_s
->wpa
, 1);
7561 #endif /* CONFIG_TDLS */
7563 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7564 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7566 wpa_s
->no_keep_alive
= 0;
7567 wpa_s
->own_disconnect_req
= 0;
7569 os_free(wpa_s
->disallow_aps_bssid
);
7570 wpa_s
->disallow_aps_bssid
= NULL
;
7571 wpa_s
->disallow_aps_bssid_count
= 0;
7572 os_free(wpa_s
->disallow_aps_ssid
);
7573 wpa_s
->disallow_aps_ssid
= NULL
;
7574 wpa_s
->disallow_aps_ssid_count
= 0;
7576 wpa_s
->set_sta_uapsd
= 0;
7577 wpa_s
->sta_uapsd
= 0;
7579 wpa_drv_radio_disable(wpa_s
, 0);
7580 wpa_blacklist_clear(wpa_s
);
7581 wpa_s
->extra_blacklist_count
= 0;
7582 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7583 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7584 wpa_config_flush_blobs(wpa_s
->conf
);
7585 wpa_s
->conf
->auto_interworking
= 0;
7586 wpa_s
->conf
->okc
= 0;
7588 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7589 rsn_preauth_deinit(wpa_s
->wpa
);
7591 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7592 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7593 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7594 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7596 radio_remove_works(wpa_s
, NULL
, 1);
7597 wpa_s
->ext_work_in_progress
= 0;
7599 wpa_s
->next_ssid
= NULL
;
7601 #ifdef CONFIG_INTERWORKING
7603 hs20_cancel_fetch_osu(wpa_s
);
7604 hs20_del_icon(wpa_s
, NULL
, NULL
);
7605 #endif /* CONFIG_HS20 */
7606 #endif /* CONFIG_INTERWORKING */
7608 wpa_s
->ext_mgmt_frame_handling
= 0;
7609 wpa_s
->ext_eapol_frame_io
= 0;
7610 #ifdef CONFIG_TESTING_OPTIONS
7611 wpa_s
->extra_roc_dur
= 0;
7612 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7613 wpa_s
->p2p_go_csa_on_inv
= 0;
7614 wpa_s
->ignore_auth_resp
= 0;
7615 wpa_s
->ignore_assoc_disallow
= 0;
7616 wpa_s
->reject_btm_req_reason
= 0;
7617 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7618 os_free(wpa_s
->get_pref_freq_list_override
);
7619 wpa_s
->get_pref_freq_list_override
= NULL
;
7620 #endif /* CONFIG_TESTING_OPTIONS */
7622 wpa_s
->disconnected
= 0;
7623 os_free(wpa_s
->next_scan_freqs
);
7624 wpa_s
->next_scan_freqs
= NULL
;
7625 os_free(wpa_s
->select_network_scan_freqs
);
7626 wpa_s
->select_network_scan_freqs
= NULL
;
7628 wpa_bss_flush(wpa_s
);
7629 if (!dl_list_empty(&wpa_s
->bss
)) {
7630 wpa_printf(MSG_DEBUG
,
7631 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7632 MACSTR
" pending_bssid=" MACSTR
,
7633 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7634 MAC2STR(wpa_s
->bssid
),
7635 MAC2STR(wpa_s
->pending_bssid
));
7638 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7639 wpa_s
->wnmsleep_used
= 0;
7642 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7643 #endif /* CONFIG_SME */
7645 wpabuf_free(wpa_s
->ric_ies
);
7646 wpa_s
->ric_ies
= NULL
;
7650 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7651 char *buf
, size_t buflen
)
7653 struct wpa_radio_work
*work
;
7655 struct os_reltime now
, diff
;
7660 os_get_reltime(&now
);
7662 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7666 os_reltime_sub(&now
, &work
->time
, &diff
);
7667 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7668 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7669 work
->started
, diff
.sec
, diff
.usec
);
7670 if (os_snprintf_error(end
- pos
, ret
))
7679 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7681 struct wpa_radio_work
*work
= eloop_ctx
;
7682 struct wpa_external_work
*ework
= work
->ctx
;
7684 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7685 "Timing out external radio work %u (%s)",
7686 ework
->id
, work
->type
);
7687 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7688 work
->wpa_s
->ext_work_in_progress
= 0;
7689 radio_work_done(work
);
7694 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7696 struct wpa_external_work
*ework
= work
->ctx
;
7700 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7704 * work->type points to a buffer in ework, so need to replace
7705 * that here with a fixed string to avoid use of freed memory
7708 work
->type
= "freed-ext-work";
7714 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7715 ework
->id
, ework
->type
);
7716 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7717 work
->wpa_s
->ext_work_in_progress
= 1;
7718 if (!ework
->timeout
)
7719 ework
->timeout
= 10;
7720 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7725 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7726 char *buf
, size_t buflen
)
7728 struct wpa_external_work
*ework
;
7732 unsigned int freq
= 0;
7734 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7736 ework
= os_zalloc(sizeof(*ework
));
7740 pos
= os_strchr(cmd
, ' ');
7742 type_len
= pos
- cmd
;
7745 pos2
= os_strstr(pos
, "freq=");
7747 freq
= atoi(pos2
+ 5);
7749 pos2
= os_strstr(pos
, "timeout=");
7751 ework
->timeout
= atoi(pos2
+ 8);
7753 type_len
= os_strlen(cmd
);
7755 if (4 + type_len
>= sizeof(ework
->type
))
7756 type_len
= sizeof(ework
->type
) - 4 - 1;
7757 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
7758 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
7759 ework
->type
[4 + type_len
] = '\0';
7761 wpa_s
->ext_work_id
++;
7762 if (wpa_s
->ext_work_id
== 0)
7763 wpa_s
->ext_work_id
++;
7764 ework
->id
= wpa_s
->ext_work_id
;
7766 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
7772 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
7773 if (os_snprintf_error(buflen
, ret
))
7779 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
7781 struct wpa_radio_work
*work
;
7782 unsigned int id
= atoi(cmd
);
7784 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7786 struct wpa_external_work
*ework
;
7788 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7791 if (id
&& ework
->id
!= id
)
7793 wpa_dbg(wpa_s
, MSG_DEBUG
,
7794 "Completed external radio work %u (%s)",
7795 ework
->id
, ework
->type
);
7796 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
7797 wpa_s
->ext_work_in_progress
= 0;
7798 radio_work_done(work
);
7800 return 3; /* "OK\n" */
7807 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
7808 char *buf
, size_t buflen
)
7810 if (os_strcmp(cmd
, "show") == 0)
7811 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
7812 if (os_strncmp(cmd
, "add ", 4) == 0)
7813 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
7814 if (os_strncmp(cmd
, "done ", 5) == 0)
7815 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
7820 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
7822 struct wpa_radio_work
*work
, *tmp
;
7824 if (!wpa_s
|| !wpa_s
->radio
)
7827 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
7828 struct wpa_radio_work
, list
) {
7829 struct wpa_external_work
*ework
;
7831 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7834 wpa_dbg(wpa_s
, MSG_DEBUG
,
7835 "Flushing%s external radio work %u (%s)",
7836 work
->started
? " started" : "", ework
->id
,
7839 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7841 radio_work_done(work
);
7847 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
7849 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7850 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
7854 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
7855 unsigned int *scan_id_count
, int scan_id
[])
7857 const char *pos
= value
;
7860 if (*pos
== ' ' || *pos
== '\0')
7862 if (*scan_id_count
== MAX_SCAN_ID
)
7864 scan_id
[(*scan_id_count
)++] = atoi(pos
);
7865 pos
= os_strchr(pos
, ',');
7874 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
7875 char *reply
, int reply_size
, int *reply_len
)
7878 unsigned int manual_scan_passive
= 0;
7879 unsigned int manual_scan_use_id
= 0;
7880 unsigned int manual_scan_only_new
= 0;
7881 unsigned int scan_only
= 0;
7882 unsigned int scan_id_count
= 0;
7883 int scan_id
[MAX_SCAN_ID
];
7884 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
7885 struct wpa_scan_results
*scan_res
);
7886 int *manual_scan_freqs
= NULL
;
7887 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
7888 unsigned int ssid_count
= 0;
7890 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
7895 if (radio_work_pending(wpa_s
, "scan")) {
7896 wpa_printf(MSG_DEBUG
,
7897 "Pending scan scheduled - reject new request");
7898 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7902 #ifdef CONFIG_INTERWORKING
7903 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
7904 wpa_printf(MSG_DEBUG
,
7905 "Interworking select in progress - reject new scan");
7906 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7909 #endif /* CONFIG_INTERWORKING */
7912 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
7915 pos
= os_strstr(params
, "freq=");
7917 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
7919 if (manual_scan_freqs
== NULL
) {
7925 pos
= os_strstr(params
, "passive=");
7927 manual_scan_passive
= !!atoi(pos
+ 8);
7929 pos
= os_strstr(params
, "use_id=");
7931 manual_scan_use_id
= atoi(pos
+ 7);
7933 pos
= os_strstr(params
, "only_new=1");
7935 manual_scan_only_new
= 1;
7937 pos
= os_strstr(params
, "scan_id=");
7938 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
7945 while (pos
&& *pos
!= '\0') {
7946 if (os_strncmp(pos
, "ssid ", 5) == 0) {
7952 if (*end
== '\0' || *end
== ' ')
7957 ns
= os_realloc_array(
7958 ssid
, ssid_count
+ 1,
7959 sizeof(struct wpa_ssid_value
));
7966 if ((end
- pos
) & 0x01 ||
7967 end
- pos
> 2 * SSID_MAX_LEN
||
7968 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
7969 (end
- pos
) / 2) < 0) {
7970 wpa_printf(MSG_DEBUG
,
7971 "Invalid SSID value '%s'",
7976 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
7977 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
7978 ssid
[ssid_count
].ssid
,
7979 ssid
[ssid_count
].ssid_len
);
7984 pos
= os_strchr(pos
, ' ');
7990 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
7991 os_free(wpa_s
->ssids_from_scan_req
);
7993 wpa_s
->ssids_from_scan_req
= ssid
;
7996 wpa_s
->ssids_from_scan_req
= NULL
;
8000 scan_res_handler
= scan_only_handler
;
8001 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
8002 scan_res_handler
= NULL
;
8004 scan_res_handler
= wpa_s
->scan_res_handler
;
8006 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
8007 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
8008 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
8009 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8010 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8011 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8012 wpa_s
->scan_id_count
= scan_id_count
;
8013 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8014 wpa_s
->scan_res_handler
= scan_res_handler
;
8015 os_free(wpa_s
->manual_scan_freqs
);
8016 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8017 manual_scan_freqs
= NULL
;
8019 wpa_s
->normal_scans
= 0;
8020 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8021 wpa_s
->after_wps
= 0;
8022 wpa_s
->known_wps_freq
= 0;
8023 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8024 if (wpa_s
->manual_scan_use_id
) {
8025 wpa_s
->manual_scan_id
++;
8026 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8027 wpa_s
->manual_scan_id
);
8028 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8029 wpa_s
->manual_scan_id
);
8031 } else if (wpa_s
->sched_scanning
) {
8032 wpa_s
->manual_scan_passive
= manual_scan_passive
;
8033 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
8034 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
8035 wpa_s
->scan_id_count
= scan_id_count
;
8036 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
8037 wpa_s
->scan_res_handler
= scan_res_handler
;
8038 os_free(wpa_s
->manual_scan_freqs
);
8039 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
8040 manual_scan_freqs
= NULL
;
8042 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
8043 wpa_supplicant_cancel_sched_scan(wpa_s
);
8044 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
8045 wpa_supplicant_req_scan(wpa_s
, 0, 0);
8046 if (wpa_s
->manual_scan_use_id
) {
8047 wpa_s
->manual_scan_id
++;
8048 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
8049 wpa_s
->manual_scan_id
);
8050 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
8051 wpa_s
->manual_scan_id
);
8054 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
8055 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
8059 os_free(manual_scan_freqs
);
8064 #ifdef CONFIG_TESTING_OPTIONS
8066 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
8067 unsigned int freq
, const u8
*dst
,
8068 const u8
*src
, const u8
*bssid
,
8069 const u8
*data
, size_t data_len
,
8070 enum offchannel_send_action_result
8073 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8074 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
8075 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
8076 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
8077 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
8078 "NO_ACK" : "FAILED"));
8082 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8086 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
8088 int freq
= 0, no_cck
= 0, wait_time
= 0;
8090 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8091 * <action=Action frame payload> */
8093 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
8096 used
= hwaddr_aton2(pos
, da
);
8102 used
= hwaddr_aton2(pos
, bssid
);
8107 param
= os_strstr(pos
, " freq=");
8113 param
= os_strstr(pos
, " no_cck=");
8116 no_cck
= atoi(param
);
8119 param
= os_strstr(pos
, " wait_time=");
8122 wait_time
= atoi(param
);
8125 param
= os_strstr(pos
, " action=");
8130 len
= os_strlen(param
);
8135 buf
= os_malloc(len
);
8139 if (hexstr2bin(param
, buf
, len
) < 0) {
8144 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
8145 buf
, len
, wait_time
,
8146 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
8152 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
8154 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
8155 offchannel_send_action_done(wpa_s
);
8159 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
8165 int freq
= 0, datarate
= 0, ssi_signal
= 0;
8166 union wpa_event_data event
;
8168 if (!wpa_s
->ext_mgmt_frame_handling
)
8171 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8173 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
8176 param
= os_strstr(pos
, "freq=");
8182 param
= os_strstr(pos
, " datarate=");
8185 datarate
= atoi(param
);
8188 param
= os_strstr(pos
, " ssi_signal=");
8191 ssi_signal
= atoi(param
);
8194 param
= os_strstr(pos
, " frame=");
8199 len
= os_strlen(param
);
8204 buf
= os_malloc(len
);
8208 if (hexstr2bin(param
, buf
, len
) < 0) {
8213 os_memset(&event
, 0, sizeof(event
));
8214 event
.rx_mgmt
.freq
= freq
;
8215 event
.rx_mgmt
.frame
= buf
;
8216 event
.rx_mgmt
.frame_len
= len
;
8217 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8218 event
.rx_mgmt
.datarate
= datarate
;
8219 wpa_s
->ext_mgmt_frame_handling
= 0;
8220 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8221 wpa_s
->ext_mgmt_frame_handling
= 1;
8229 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8232 struct wpa_scan_res
*res
;
8233 struct os_reltime now
;
8240 if (os_strcmp(param
, "START") == 0) {
8241 wpa_bss_update_start(wpa_s
);
8245 if (os_strcmp(param
, "END") == 0) {
8246 wpa_bss_update_end(wpa_s
, NULL
, 1);
8250 if (os_strncmp(param
, "BSS ", 4) != 0)
8254 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8258 pos
= os_strstr(param
, " flags=");
8260 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8262 pos
= os_strstr(param
, " bssid=");
8263 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8266 pos
= os_strstr(param
, " freq=");
8268 res
->freq
= atoi(pos
+ 6);
8270 pos
= os_strstr(param
, " beacon_int=");
8272 res
->beacon_int
= atoi(pos
+ 12);
8274 pos
= os_strstr(param
, " caps=");
8276 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8278 pos
= os_strstr(param
, " qual=");
8280 res
->qual
= atoi(pos
+ 6);
8282 pos
= os_strstr(param
, " noise=");
8284 res
->noise
= atoi(pos
+ 7);
8286 pos
= os_strstr(param
, " level=");
8288 res
->level
= atoi(pos
+ 7);
8290 pos
= os_strstr(param
, " tsf=");
8292 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8294 pos
= os_strstr(param
, " age=");
8296 res
->age
= atoi(pos
+ 5);
8298 pos
= os_strstr(param
, " est_throughput=");
8300 res
->est_throughput
= atoi(pos
+ 16);
8302 pos
= os_strstr(param
, " snr=");
8304 res
->snr
= atoi(pos
+ 5);
8306 pos
= os_strstr(param
, " parent_tsf=");
8308 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8310 pos
= os_strstr(param
, " tsf_bssid=");
8311 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8314 pos
= os_strstr(param
, " ie=");
8317 end
= os_strchr(pos
, ' ');
8319 end
= pos
+ os_strlen(pos
);
8320 res
->ie_len
= (end
- pos
) / 2;
8321 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8325 pos
= os_strstr(param
, " beacon_ie=");
8328 end
= os_strchr(pos
, ' ');
8330 end
= pos
+ os_strlen(pos
);
8331 res
->beacon_ie_len
= (end
- pos
) / 2;
8332 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8333 res
->beacon_ie_len
))
8337 os_get_reltime(&now
);
8338 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8347 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8350 union wpa_event_data event
;
8351 enum wpa_event_type ev
;
8353 /* <event name> [parameters..] */
8355 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8358 param
= os_strchr(pos
, ' ');
8362 os_memset(&event
, 0, sizeof(event
));
8364 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8365 ev
= EVENT_INTERFACE_ENABLED
;
8366 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8367 ev
= EVENT_INTERFACE_DISABLED
;
8368 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8369 ev
= EVENT_AVOID_FREQUENCIES
;
8372 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8374 wpa_supplicant_event(wpa_s
, ev
, &event
);
8375 os_free(event
.freq_range
.range
);
8377 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8378 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8380 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8385 wpa_supplicant_event(wpa_s
, ev
, &event
);
8391 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8394 u8 src
[ETH_ALEN
], *buf
;
8398 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8401 used
= hwaddr_aton2(pos
, src
);
8408 len
= os_strlen(pos
);
8413 buf
= os_malloc(len
);
8417 if (hexstr2bin(pos
, buf
, len
) < 0) {
8422 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8429 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8433 const u16
*pos
= buf
;
8435 for (i
= 0; i
< len
/ 2; i
++)
8439 sum
= (sum
& 0xffff) + (sum
>> 16);
8441 return sum
^ 0xffff;
8445 #define HWSIM_PACKETLEN 1500
8446 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8448 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8451 struct wpa_supplicant
*wpa_s
= ctx
;
8452 const struct ether_header
*eth
;
8457 if (len
!= HWSIM_PACKETLEN
)
8460 eth
= (const struct ether_header
*) buf
;
8461 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8462 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8464 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8465 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8468 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
8474 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
8475 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
8479 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8482 int enabled
= atoi(cmd
);
8487 if (wpa_s
->l2_test
) {
8488 l2_packet_deinit(wpa_s
->l2_test
);
8489 wpa_s
->l2_test
= NULL
;
8490 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8498 pos
= os_strstr(cmd
, " ifname=");
8502 ifname
= wpa_s
->ifname
;
8504 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8505 ETHERTYPE_IP
, wpas_data_test_rx
,
8507 if (wpa_s
->l2_test
== NULL
)
8510 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8516 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8518 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8523 u8 buf
[2 + HWSIM_PACKETLEN
];
8524 struct ether_header
*eth
;
8529 if (wpa_s
->l2_test
== NULL
)
8532 /* format: <dst> <src> <tos> */
8535 used
= hwaddr_aton2(pos
, dst
);
8541 used
= hwaddr_aton2(pos
, src
);
8546 val
= strtol(pos
, NULL
, 0);
8547 if (val
< 0 || val
> 0xff)
8551 eth
= (struct ether_header
*) &buf
[2];
8552 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8553 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8554 eth
->ether_type
= htons(ETHERTYPE_IP
);
8555 ip
= (struct iphdr
*) (eth
+ 1);
8556 os_memset(ip
, 0, sizeof(*ip
));
8561 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8563 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8564 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8565 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8566 dpos
= (u8
*) (ip
+ 1);
8567 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8570 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8571 HWSIM_PACKETLEN
) < 0)
8574 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8575 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8581 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8585 struct ether_header
*eth
;
8586 struct l2_packet_data
*l2
= NULL
;
8591 len
= os_strlen(cmd
);
8592 if (len
& 1 || len
< ETH_HLEN
* 2)
8596 buf
= os_malloc(len
);
8600 if (hexstr2bin(cmd
, buf
, len
) < 0)
8603 eth
= (struct ether_header
*) buf
;
8604 ethertype
= ntohs(eth
->ether_type
);
8606 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8607 wpas_data_test_rx
, wpa_s
, 1);
8611 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8612 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8615 l2_packet_deinit(l2
);
8618 return res
< 0 ? -1 : 0;
8622 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8624 #ifdef WPA_TRACE_BFD
8627 wpa_trace_fail_after
= atoi(cmd
);
8628 pos
= os_strchr(cmd
, ':');
8631 os_strlcpy(wpa_trace_fail_func
, pos
,
8632 sizeof(wpa_trace_fail_func
));
8634 wpa_trace_fail_after
= 0;
8637 #else /* WPA_TRACE_BFD */
8639 #endif /* WPA_TRACE_BFD */
8643 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8644 char *buf
, size_t buflen
)
8646 #ifdef WPA_TRACE_BFD
8647 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8648 wpa_trace_fail_func
);
8649 #else /* WPA_TRACE_BFD */
8651 #endif /* WPA_TRACE_BFD */
8655 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8657 #ifdef WPA_TRACE_BFD
8660 wpa_trace_test_fail_after
= atoi(cmd
);
8661 pos
= os_strchr(cmd
, ':');
8664 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8665 sizeof(wpa_trace_test_fail_func
));
8667 wpa_trace_test_fail_after
= 0;
8670 #else /* WPA_TRACE_BFD */
8672 #endif /* WPA_TRACE_BFD */
8676 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8677 char *buf
, size_t buflen
)
8679 #ifdef WPA_TRACE_BFD
8680 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8681 wpa_trace_test_fail_func
);
8682 #else /* WPA_TRACE_BFD */
8684 #endif /* WPA_TRACE_BFD */
8688 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8690 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8691 int i
, count
= (intptr_t) timeout_ctx
;
8693 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8695 for (i
= 0; i
< count
; i
++) {
8696 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8702 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8710 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8711 (void *) (intptr_t) count
);
8715 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8721 len
= os_strlen(cmd
);
8729 buf
= wpabuf_alloc(len
);
8733 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
8739 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
8743 #endif /* CONFIG_TESTING_OPTIONS */
8746 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
8752 struct ieee802_11_elems elems
;
8755 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8757 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8759 pos
= os_strchr(pos
, ' ');
8764 len
= os_strlen(pos
);
8771 buf
= wpabuf_alloc(len
);
8775 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
8780 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
8786 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
8787 wpa_s
->vendor_elem
[frame
] = buf
;
8788 wpas_vendor_elem_update(wpa_s
);
8792 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
8797 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
8799 wpas_vendor_elem_update(wpa_s
);
8805 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
8806 char *buf
, size_t buflen
)
8808 int frame
= atoi(cmd
);
8810 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8812 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8814 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8817 return wpa_snprintf_hex(buf
, buflen
,
8818 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
8819 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
8823 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
8829 struct ieee802_11_elems elems
;
8833 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8835 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8837 pos
= os_strchr(pos
, ' ');
8843 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
8844 wpa_s
->vendor_elem
[frame
] = NULL
;
8845 wpas_vendor_elem_update(wpa_s
);
8849 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8852 len
= os_strlen(pos
);
8859 buf
= os_malloc(len
);
8863 if (hexstr2bin(pos
, buf
, len
) < 0) {
8868 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
8873 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
8879 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
8881 struct wpa_supplicant
*wpa_s
= ctx
;
8886 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
8888 * BSSID Information[4]
8889 * Operating Class[1]
8892 * Optional Subelements[variable]
8894 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
8896 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
8897 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
8901 data
= wpabuf_head_u8(neighbor_rep
);
8902 len
= wpabuf_len(neighbor_rep
);
8904 while (len
>= 2 + NR_IE_MIN_LEN
) {
8906 char lci
[256 * 2 + 1];
8907 char civic
[256 * 2 + 1];
8908 u8 nr_len
= data
[1];
8909 const u8
*pos
= data
, *end
;
8911 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
8912 nr_len
< NR_IE_MIN_LEN
) {
8913 wpa_printf(MSG_DEBUG
,
8914 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
8919 if (2U + nr_len
> len
) {
8920 wpa_printf(MSG_DEBUG
,
8921 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
8922 data
[0], len
, nr_len
);
8929 pos
+= NR_IE_MIN_LEN
;
8933 while (end
- pos
> 2) {
8938 if (s_len
> end
- pos
)
8940 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
8941 /* Measurement Token[1] */
8942 /* Measurement Report Mode[1] */
8943 /* Measurement Type[1] */
8944 /* Measurement Report[variable] */
8946 case MEASURE_TYPE_LCI
:
8949 wpa_snprintf_hex(lci
, sizeof(lci
),
8952 case MEASURE_TYPE_LOCATION_CIVIC
:
8955 wpa_snprintf_hex(civic
, sizeof(civic
),
8964 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
8966 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
8967 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
8968 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
8970 lci
[0] ? " lci=" : "", lci
,
8971 civic
[0] ? " civic=" : "", civic
);
8978 wpabuf_free(neighbor_rep
);
8982 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
8985 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
8986 int ret
, lci
= 0, civic
= 0;
8989 ssid_s
= os_strstr(cmd
, "ssid=");
8991 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
8992 wpa_printf(MSG_ERROR
,
8993 "CTRL: Send Neighbor Report: bad SSID");
9000 * Move cmd after the SSID text that may include "lci" or
9003 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
9009 if (cmd
&& os_strstr(cmd
, "lci"))
9012 if (cmd
&& os_strstr(cmd
, "civic"))
9015 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
9016 wpas_ctrl_neighbor_rep_cb
,
9023 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
9025 eapol_sm_erp_flush(wpa_s
->eapol
);
9030 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
9033 char *token
, *context
= NULL
;
9034 unsigned int enable
= ~0, type
= 0;
9035 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
9036 u8
*addr
= NULL
, *mask
= NULL
;
9038 while ((token
= str_token(cmd
, " ", &context
))) {
9039 if (os_strcasecmp(token
, "scan") == 0) {
9040 type
|= MAC_ADDR_RAND_SCAN
;
9041 } else if (os_strcasecmp(token
, "sched") == 0) {
9042 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
9043 } else if (os_strcasecmp(token
, "pno") == 0) {
9044 type
|= MAC_ADDR_RAND_PNO
;
9045 } else if (os_strcasecmp(token
, "all") == 0) {
9046 type
= wpa_s
->mac_addr_rand_supported
;
9047 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
9048 enable
= atoi(token
+ 7);
9049 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
9051 if (hwaddr_aton(token
+ 5, addr
)) {
9052 wpa_printf(MSG_INFO
,
9053 "CTRL: Invalid MAC address: %s",
9057 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
9059 if (hwaddr_aton(token
+ 5, mask
)) {
9060 wpa_printf(MSG_INFO
,
9061 "CTRL: Invalid MAC address mask: %s",
9066 wpa_printf(MSG_INFO
,
9067 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9074 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
9078 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
9079 wpa_printf(MSG_INFO
,
9080 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
9081 type
, wpa_s
->mac_addr_rand_supported
);
9086 wpa_printf(MSG_INFO
,
9087 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9092 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
9094 if (type
& MAC_ADDR_RAND_PNO
) {
9095 wpas_stop_pno(wpa_s
);
9096 wpas_start_pno(wpa_s
);
9098 } else if (wpa_s
->sched_scanning
&&
9099 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
9100 wpas_scan_restart_sched_scan(wpa_s
);
9105 if ((addr
&& !mask
) || (!addr
&& mask
)) {
9106 wpa_printf(MSG_INFO
,
9107 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9111 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
9112 wpa_printf(MSG_INFO
,
9113 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9117 if (type
& MAC_ADDR_RAND_SCAN
) {
9118 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
9122 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
9123 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
9126 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
9127 wpas_scan_restart_sched_scan(wpa_s
);
9130 if (type
& MAC_ADDR_RAND_PNO
) {
9131 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
9134 wpas_stop_pno(wpa_s
);
9135 wpas_start_pno(wpa_s
);
9143 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
9144 char *buf
, size_t buflen
)
9148 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
9150 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
9151 buflen
- reply_len
);
9152 #endif /* CONFIG_AP */
9157 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
9159 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
9161 wpas_ap_pmksa_cache_flush(wpa_s
);
9162 #endif /* CONFIG_AP */
9166 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9168 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
9169 const char *cmd
, char *buf
, size_t buflen
)
9171 struct rsn_pmksa_cache_entry
*entry
;
9172 struct wpa_ssid
*ssid
;
9173 char *pos
, *pos2
, *end
;
9175 struct os_reltime now
;
9177 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9184 os_get_reltime(&now
);
9188 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9189 * <expiration in seconds> <akmp> <opportunistic>
9190 * [FILS Cache Identifier]
9193 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9194 entry
= entry
->next
) {
9195 if (entry
->network_ctx
!= ssid
)
9199 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9200 MAC2STR(entry
->aa
));
9201 if (os_snprintf_error(end
- pos2
, ret
))
9205 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9208 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9209 if (os_snprintf_error(end
- pos2
, ret
))
9213 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9216 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9217 (int) (entry
->reauth_time
- now
.sec
),
9218 (int) (entry
->expiration
- now
.sec
),
9220 entry
->opportunistic
);
9221 if (os_snprintf_error(end
- pos2
, ret
))
9225 if (entry
->fils_cache_id_set
) {
9226 ret
= os_snprintf(pos2
, end
- pos2
, " %02x%02x",
9227 entry
->fils_cache_id
[0],
9228 entry
->fils_cache_id
[1]);
9229 if (os_snprintf_error(end
- pos2
, ret
))
9234 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9235 if (os_snprintf_error(end
- pos2
, ret
))
9246 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9249 struct rsn_pmksa_cache_entry
*entry
;
9250 struct wpa_ssid
*ssid
;
9253 struct os_reltime now
;
9254 int reauth_time
= 0, expiration
= 0, i
;
9258 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9259 * <expiration in seconds> <akmp> <opportunistic>
9260 * [FILS Cache Identifier]
9263 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9267 pos
= os_strchr(cmd
, ' ');
9272 entry
= os_zalloc(sizeof(*entry
));
9276 if (hwaddr_aton(pos
, entry
->aa
))
9279 pos
= os_strchr(pos
, ' ');
9284 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9287 pos
= os_strchr(pos
, ' ');
9292 pos2
= os_strchr(pos
, ' ');
9295 entry
->pmk_len
= (pos2
- pos
) / 2;
9296 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9297 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9300 pos
= os_strchr(pos
, ' ');
9305 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9306 &entry
->akmp
, &entry
->opportunistic
) != 4)
9308 for (i
= 0; i
< 4; i
++) {
9309 pos
= os_strchr(pos
, ' ');
9318 if (hexstr2bin(pos
, entry
->fils_cache_id
,
9319 FILS_CACHE_ID_LEN
) < 0)
9321 entry
->fils_cache_id_set
= 1;
9323 os_get_reltime(&now
);
9324 entry
->expiration
= now
.sec
+ expiration
;
9325 entry
->reauth_time
= now
.sec
+ reauth_time
;
9327 entry
->network_ctx
= ssid
;
9329 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9340 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9341 const char *cmd
, char *buf
,
9349 if (os_strcasecmp(cmd
, "any") == 0)
9350 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9352 if (hwaddr_aton(cmd
, spa
))
9355 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9359 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9363 * We do not check mesh interface existance because PMKSA should be
9364 * stored before wpa_s->ifmsh creation to suppress commit message
9367 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9370 #endif /* CONFIG_MESH */
9371 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9375 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9378 struct fils_hlp_req
*req
;
9381 /* format: <dst> <packet starting from ethertype> */
9383 req
= os_zalloc(sizeof(*req
));
9387 if (hwaddr_aton(cmd
, req
->dst
))
9390 pos
= os_strchr(cmd
, ' ');
9394 req
->pkt
= wpabuf_parse_bin(pos
);
9398 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9401 wpabuf_free(req
->pkt
);
9405 #endif /* CONFIG_FILS */
9408 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9410 if (os_strcmp(cmd
, "PING") == 0 ||
9411 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9412 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9413 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9414 os_strncmp(cmd
, "STA ", 4) == 0 ||
9415 os_strncmp(cmd
, "STA-", 4) == 0)
9416 return MSG_EXCESSIVE
;
9421 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9422 char *buf
, size_t *resp_len
)
9425 const int reply_size
= 4096;
9428 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9429 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
9430 if (wpa_debug_show_keys
)
9431 wpa_dbg(wpa_s
, MSG_DEBUG
,
9432 "Control interface command '%s'", buf
);
9434 wpa_dbg(wpa_s
, MSG_DEBUG
,
9435 "Control interface command '%s [REMOVED]'",
9436 os_strncmp(buf
, WPA_CTRL_RSP
,
9437 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9438 WPA_CTRL_RSP
: "SET_NETWORK");
9439 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9440 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9441 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9442 (const u8
*) buf
, os_strlen(buf
));
9444 int level
= wpas_ctrl_cmd_debug_level(buf
);
9445 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9448 reply
= os_malloc(reply_size
);
9449 if (reply
== NULL
) {
9454 os_memcpy(reply
, "OK\n", 3);
9457 if (os_strcmp(buf
, "PING") == 0) {
9458 os_memcpy(reply
, "PONG\n", 5);
9460 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9461 reply_len
= os_strlen(wpa_s
->ifname
);
9462 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9463 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9464 if (wpa_debug_reopen_file() < 0)
9466 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9467 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9468 } else if (os_strcmp(buf
, "MIB") == 0) {
9469 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9470 if (reply_len
>= 0) {
9471 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9473 reply_size
- reply_len
);
9475 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9476 reply_len
= wpa_supplicant_ctrl_iface_status(
9477 wpa_s
, buf
+ 6, reply
, reply_size
);
9478 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9479 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9480 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9481 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9482 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9483 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9484 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9486 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9487 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9490 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9491 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9493 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9494 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9496 #endif /* CONFIG_MESH */
9497 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9498 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9499 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9501 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9502 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9504 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9505 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9507 } else if (os_strcmp(buf
, "LOGON") == 0) {
9508 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9509 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9510 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9511 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9512 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9515 wpas_request_connection(wpa_s
);
9516 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9517 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9518 !wpa_s
->current_ssid
)
9521 wpa_s
->reattach
= 1;
9522 wpas_request_connection(wpa_s
);
9524 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9525 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9527 else if (wpa_s
->disconnected
)
9528 wpas_request_connection(wpa_s
);
9529 #ifdef IEEE8021X_EAPOL
9530 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9531 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9533 #endif /* IEEE8021X_EAPOL */
9534 #ifdef CONFIG_PEERKEY
9535 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
9536 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
9538 #endif /* CONFIG_PEERKEY */
9539 #ifdef CONFIG_IEEE80211R
9540 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9541 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9543 #endif /* CONFIG_IEEE80211R */
9545 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9546 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9548 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9552 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9553 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9555 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9559 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9560 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9563 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9564 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9565 wpa_s
, buf
+ 14, reply
, reply_size
);
9566 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9567 if (wpas_wps_cancel(wpa_s
))
9569 #ifdef CONFIG_WPS_NFC
9570 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
9571 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
9573 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
9574 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
9576 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9577 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9578 wpa_s
, buf
+ 21, reply
, reply_size
);
9579 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
9580 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
9581 wpa_s
, buf
+ 14, reply
, reply_size
);
9582 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
9583 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
9586 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9587 reply_len
= wpas_ctrl_nfc_get_handover_req(
9588 wpa_s
, buf
+ 21, reply
, reply_size
);
9589 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9590 reply_len
= wpas_ctrl_nfc_get_handover_sel(
9591 wpa_s
, buf
+ 21, reply
, reply_size
);
9592 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
9593 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
9595 #endif /* CONFIG_WPS_NFC */
9596 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
9597 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
9600 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
9601 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
9602 wpa_s
, buf
+ 11, reply
, reply_size
);
9603 #endif /* CONFIG_AP */
9604 #ifdef CONFIG_WPS_ER
9605 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
9606 if (wpas_wps_er_start(wpa_s
, NULL
))
9608 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
9609 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
9611 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
9612 wpas_wps_er_stop(wpa_s
);
9613 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
9614 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
9616 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
9617 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
9619 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9621 } else if (ret
== -3) {
9622 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
9624 } else if (ret
== -4) {
9625 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
9629 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
9630 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
9632 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
9633 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
9636 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
9637 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
9639 #ifdef CONFIG_WPS_NFC
9640 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9641 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9642 wpa_s
, buf
+ 24, reply
, reply_size
);
9643 #endif /* CONFIG_WPS_NFC */
9644 #endif /* CONFIG_WPS_ER */
9645 #endif /* CONFIG_WPS */
9646 #ifdef CONFIG_IBSS_RSN
9647 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
9648 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
9650 #endif /* CONFIG_IBSS_RSN */
9652 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
9653 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9654 wpa_s
, buf
+ 19, reply
, reply_size
);
9655 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
9656 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9657 wpa_s
, "", reply
, reply_size
);
9658 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
9659 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
9661 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
9662 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
9665 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
9666 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
9668 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
9669 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
9671 #endif /* CONFIG_MESH */
9673 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
9674 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
9676 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
9677 if (p2p_ctrl_find(wpa_s
, ""))
9679 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
9680 wpas_p2p_stop_find(wpa_s
);
9681 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
9682 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
9684 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
9685 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
9687 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
9688 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
9690 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
9691 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
9693 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
9694 if (p2p_ctrl_listen(wpa_s
, ""))
9696 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
9697 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
9699 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
9700 if (p2p_ctrl_group_add(wpa_s
, ""))
9702 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
9703 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
9705 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
9706 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
9708 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
9709 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
9711 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
9712 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
9713 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
9714 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
9716 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
9717 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
9719 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
9720 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
9722 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
9723 wpas_p2p_sd_service_update(wpa_s
);
9724 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
9725 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
9727 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
9728 wpas_p2p_service_flush(wpa_s
);
9729 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
9730 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
9732 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
9733 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
9735 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
9736 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
9738 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
9739 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
9741 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
9742 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
9744 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
9745 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
9747 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
9748 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
9750 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
9751 p2p_ctrl_flush(wpa_s
);
9752 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
9753 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
9755 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
9756 if (wpas_p2p_cancel(wpa_s
))
9758 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
9759 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
9761 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
9762 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
9764 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
9765 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
9767 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
9768 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
9770 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
9771 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
9773 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
9774 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
9776 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
9777 if (wpas_p2p_lo_stop(wpa_s
))
9779 #endif /* CONFIG_P2P */
9780 #ifdef CONFIG_WIFI_DISPLAY
9781 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
9782 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
9784 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
9785 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
9787 #endif /* CONFIG_WIFI_DISPLAY */
9788 #ifdef CONFIG_INTERWORKING
9789 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
9790 if (interworking_fetch_anqp(wpa_s
) < 0)
9792 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
9793 interworking_stop_fetch_anqp(wpa_s
);
9794 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
9795 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
9797 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
9798 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
9800 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
9801 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
9803 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9806 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
9810 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
9811 if (os_snprintf_error(reply_size
, reply_len
))
9814 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
9815 if (get_anqp(wpa_s
, buf
+ 9) < 0)
9817 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
9818 if (gas_request(wpa_s
, buf
+ 12) < 0)
9820 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
9821 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
9823 #endif /* CONFIG_INTERWORKING */
9825 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
9826 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
9828 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
9829 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
9831 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
9832 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
9834 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
9835 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
9837 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
9838 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
9839 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
9840 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
9842 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
9843 if (hs20_fetch_osu(wpa_s
, 0) < 0)
9845 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
9846 if (hs20_fetch_osu(wpa_s
, 1) < 0)
9848 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
9849 hs20_cancel_fetch_osu(wpa_s
);
9850 #endif /* CONFIG_HS20 */
9851 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
9853 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
9854 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
9858 * Notify response from timeout to allow the control
9859 * interface response to be sent first.
9861 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
9864 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
9865 if (wpa_supplicant_reload_configuration(wpa_s
))
9867 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
9868 wpa_supplicant_terminate_proc(wpa_s
->global
);
9869 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
9870 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
9872 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
9873 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
9874 wpa_s
, buf
+ 9, reply
, reply_size
);
9875 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
9876 reply_len
= wpa_supplicant_ctrl_iface_log_level(
9877 wpa_s
, buf
+ 9, reply
, reply_size
);
9878 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
9879 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9880 wpa_s
, buf
+ 14, reply
, reply_size
);
9881 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
9882 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9883 wpa_s
, NULL
, reply
, reply_size
);
9884 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
9885 wpas_request_disconnection(wpa_s
);
9886 } else if (os_strcmp(buf
, "SCAN") == 0) {
9887 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
9888 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
9889 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
9890 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
9891 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
9892 wpa_s
, reply
, reply_size
);
9893 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
9894 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
9896 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
9897 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
9899 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
9900 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
9902 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
9903 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
9905 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
9906 reply_len
= wpa_supplicant_ctrl_iface_add_network(
9907 wpa_s
, reply
, reply_size
);
9908 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
9909 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
9911 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
9912 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
9914 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
9915 reply_len
= wpa_supplicant_ctrl_iface_get_network(
9916 wpa_s
, buf
+ 12, reply
, reply_size
);
9917 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
9918 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
9921 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
9922 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
9923 wpa_s
, reply
, reply_size
);
9924 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
9925 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
9926 wpa_s
, reply
, reply_size
);
9927 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
9928 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
9930 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
9931 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
9933 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
9934 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
9937 #ifndef CONFIG_NO_CONFIG_WRITE
9938 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
9939 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
9941 #endif /* CONFIG_NO_CONFIG_WRITE */
9942 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
9943 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
9944 wpa_s
, buf
+ 15, reply
, reply_size
);
9945 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
9946 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
9948 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
9949 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
9951 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
9952 reply_len
= wpa_supplicant_global_iface_list(
9953 wpa_s
->global
, reply
, reply_size
);
9954 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
9955 reply_len
= wpa_supplicant_global_iface_interfaces(
9956 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
9957 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
9958 reply_len
= wpa_supplicant_ctrl_iface_bss(
9959 wpa_s
, buf
+ 4, reply
, reply_size
);
9961 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
9962 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
9963 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
9964 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
9966 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
9967 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
9969 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
9970 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
9972 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
9973 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
9975 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
9976 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
9978 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
9979 if (wpas_ap_stop_ap(wpa_s
))
9981 #endif /* CONFIG_AP */
9982 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
9983 wpas_notify_suspend(wpa_s
->global
);
9984 } else if (os_strcmp(buf
, "RESUME") == 0) {
9985 wpas_notify_resume(wpa_s
->global
);
9986 #ifdef CONFIG_TESTING_OPTIONS
9987 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
9988 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
9989 #endif /* CONFIG_TESTING_OPTIONS */
9990 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
9991 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
9993 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
9994 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
9995 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
9996 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
9998 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
9999 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
10002 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
10003 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
10005 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
10006 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
10008 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
10009 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
10011 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
10012 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
10014 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
10015 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
10018 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10019 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
10022 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
10023 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
10024 wpa_s
, buf
+ 17, reply
, reply_size
);
10025 #endif /* CONFIG_TDLS */
10026 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
10027 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
10028 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
10029 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
10031 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
10032 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
10034 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
10035 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
10037 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
10038 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
10040 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
10041 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
10043 #ifdef CONFIG_AUTOSCAN
10044 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
10045 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
10047 #endif /* CONFIG_AUTOSCAN */
10048 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
10049 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
10052 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
10053 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
10055 #endif /* ANDROID */
10056 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
10057 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
10059 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
10060 pmksa_cache_clear_current(wpa_s
->wpa
);
10061 eapol_sm_request_reauth(wpa_s
->eapol
);
10063 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
10064 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
10066 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
10067 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
10069 #endif /* CONFIG_WNM */
10070 } else if (os_strcmp(buf
, "FLUSH") == 0) {
10071 wpa_supplicant_ctrl_iface_flush(wpa_s
);
10072 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
10073 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
10075 #ifdef CONFIG_TESTING_OPTIONS
10076 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
10077 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
10079 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
10080 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
10081 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
10082 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
10084 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
10085 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
10087 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
10088 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
10090 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
10091 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
10093 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
10094 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
10096 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
10097 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
10099 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
10100 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
10102 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
10103 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
10104 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
10105 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
10107 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
10108 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
10109 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
10110 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
10112 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
10113 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
10115 #endif /* CONFIG_TESTING_OPTIONS */
10116 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
10117 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
10119 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
10120 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
10122 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10123 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
10125 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
10126 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
10128 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
10129 wpas_ctrl_iface_erp_flush(wpa_s
);
10130 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
10131 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
10133 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
10134 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
10135 wpa_s
, buf
+ 19, reply
, reply_size
);
10137 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
10138 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
10140 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
10141 wpas_flush_fils_hlp_req(wpa_s
);
10142 #endif /* CONFIG_FILS */
10144 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10148 if (reply_len
< 0) {
10149 os_memcpy(reply
, "FAIL\n", 5);
10153 *resp_len
= reply_len
;
10158 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
10161 struct wpa_interface iface
;
10163 struct wpa_supplicant
*wpa_s
;
10164 unsigned int create_iface
= 0;
10165 u8 mac_addr
[ETH_ALEN
];
10166 enum wpa_driver_if_type type
= WPA_IF_STATION
;
10169 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
10170 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
10172 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
10174 os_memset(&iface
, 0, sizeof(iface
));
10177 iface
.ifname
= pos
= cmd
;
10178 pos
= os_strchr(pos
, '\t');
10181 if (iface
.ifname
[0] == '\0')
10186 iface
.confname
= pos
;
10187 pos
= os_strchr(pos
, '\t');
10190 if (iface
.confname
[0] == '\0')
10191 iface
.confname
= NULL
;
10195 iface
.driver
= pos
;
10196 pos
= os_strchr(pos
, '\t');
10199 if (iface
.driver
[0] == '\0')
10200 iface
.driver
= NULL
;
10204 iface
.ctrl_interface
= pos
;
10205 pos
= os_strchr(pos
, '\t');
10208 if (iface
.ctrl_interface
[0] == '\0')
10209 iface
.ctrl_interface
= NULL
;
10213 iface
.driver_param
= pos
;
10214 pos
= os_strchr(pos
, '\t');
10217 if (iface
.driver_param
[0] == '\0')
10218 iface
.driver_param
= NULL
;
10222 iface
.bridge_ifname
= pos
;
10223 pos
= os_strchr(pos
, '\t');
10226 if (iface
.bridge_ifname
[0] == '\0')
10227 iface
.bridge_ifname
= NULL
;
10232 pos
= os_strchr(pos
, '\t');
10238 if (os_strcmp(extra
, "create") == 0) {
10243 if (os_strcmp(pos
, "sta") == 0) {
10244 type
= WPA_IF_STATION
;
10245 } else if (os_strcmp(pos
, "ap") == 0) {
10246 type
= WPA_IF_AP_BSS
;
10248 wpa_printf(MSG_DEBUG
,
10249 "INTERFACE_ADD unsupported interface type: '%s'",
10254 wpa_printf(MSG_DEBUG
,
10255 "INTERFACE_ADD unsupported extra parameter: '%s'",
10261 if (create_iface
) {
10262 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10264 if (!global
->ifaces
)
10266 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10267 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10268 wpa_printf(MSG_ERROR
,
10269 "CTRL_IFACE interface creation failed");
10273 wpa_printf(MSG_DEBUG
,
10274 "CTRL_IFACE interface '%s' created with MAC addr: "
10275 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10278 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10281 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10284 wpa_s
->added_vif
= create_iface
;
10289 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10294 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10297 struct wpa_supplicant
*wpa_s
;
10299 unsigned int delete_iface
;
10301 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10303 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10306 delete_iface
= wpa_s
->added_vif
;
10307 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10308 if (!ret
&& delete_iface
) {
10309 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10311 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10317 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10319 struct wpa_interface_info
*prev
;
10323 iface
= iface
->next
;
10325 os_free(prev
->ifname
);
10326 os_free(prev
->desc
);
10332 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10333 char *buf
, int len
)
10336 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10339 for (i
= 0; wpa_drivers
[i
]; i
++) {
10340 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10341 if (drv
->get_interfaces
== NULL
)
10343 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10348 iface
= last
= tmp
;
10357 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10358 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10359 tmp
->drv_name
, tmp
->ifname
,
10360 tmp
->desc
? tmp
->desc
: "");
10361 if (os_snprintf_error(end
- pos
, res
)) {
10368 wpa_free_iface_info(iface
);
10374 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10376 char *buf
, int len
)
10380 struct wpa_supplicant
*wpa_s
;
10384 show_ctrl
= !!os_strstr(input
, "ctrl");
10386 wpa_s
= global
->ifaces
;
10392 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10394 wpa_s
->conf
->ctrl_interface
?
10395 wpa_s
->conf
->ctrl_interface
: "N/A");
10397 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10400 if (os_snprintf_error(end
- pos
, res
)) {
10405 wpa_s
= wpa_s
->next
;
10411 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10412 const char *ifname
,
10413 char *cmd
, size_t *resp_len
)
10415 struct wpa_supplicant
*wpa_s
;
10417 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10418 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10422 if (wpa_s
== NULL
) {
10423 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10425 *resp_len
= os_strlen(resp
);
10431 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10435 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10436 char *buf
, size_t *resp_len
)
10439 static const char * cmd
[] = {
10445 "P2P_GET_PASSPHRASE",
10446 "P2P_SERVICE_UPDATE",
10447 "P2P_SERVICE_FLUSH",
10450 "P2P_PRESENCE_REQ",
10454 #endif /* CONFIG_AP */
10457 static const char * prefix
[] = {
10460 #endif /* ANDROID */
10466 "P2P_GROUP_REMOVE ",
10468 "P2P_GROUP_MEMBER ",
10470 "P2P_SERV_DISC_REQ ",
10471 "P2P_SERV_DISC_CANCEL_REQ ",
10472 "P2P_SERV_DISC_RESP ",
10473 "P2P_SERV_DISC_EXTERNAL ",
10474 "P2P_SERVICE_ADD ",
10475 "P2P_SERVICE_DEL ",
10476 "P2P_SERVICE_REP ",
10481 "P2P_UNAUTHORIZE ",
10482 "P2P_PRESENCE_REQ ",
10484 "P2P_REMOVE_CLIENT ",
10486 "WPS_NFC_TAG_READ ",
10487 "NFC_GET_HANDOVER_SEL ",
10488 "NFC_GET_HANDOVER_REQ ",
10489 "NFC_REPORT_HANDOVER ",
10490 "P2P_ASP_PROVISION ",
10491 "P2P_ASP_PROVISION_RESP ",
10495 #endif /* CONFIG_AP */
10501 if (global
->p2p_init_wpa_s
== NULL
)
10504 for (i
= 0; !found
&& cmd
[i
]; i
++) {
10505 if (os_strcmp(buf
, cmd
[i
]) == 0)
10509 for (i
= 0; !found
&& prefix
[i
]; i
++) {
10510 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
10515 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10517 #endif /* CONFIG_P2P */
10522 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
10523 char *buf
, size_t *resp_len
)
10525 #ifdef CONFIG_WIFI_DISPLAY
10526 if (global
->p2p_init_wpa_s
== NULL
)
10528 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
10529 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
10530 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10532 #endif /* CONFIG_WIFI_DISPLAY */
10537 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
10538 char *buf
, size_t *resp_len
)
10542 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
10546 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
10554 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
10558 value
= os_strchr(cmd
, ' ');
10563 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
10565 #ifdef CONFIG_WIFI_DISPLAY
10566 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
10567 wifi_display_enable(global
, !!atoi(value
));
10570 #endif /* CONFIG_WIFI_DISPLAY */
10572 /* Restore cmd to its original value to allow redirection */
10579 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
10582 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
10586 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
10587 * <variable name> */
10589 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
10590 p
= os_strchr(cmd
, ' ');
10595 wpa_s
[i
] = global
->ifaces
;
10596 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
10597 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
10602 wpa_printf(MSG_DEBUG
,
10603 "CTRL_IFACE: Could not find iface=%s", cmd
);
10610 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
10614 #ifndef CONFIG_NO_CONFIG_WRITE
10615 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
10617 int ret
= 0, saved
= 0;
10618 struct wpa_supplicant
*wpa_s
;
10620 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10621 if (!wpa_s
->conf
->update_config
) {
10622 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
10626 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
10627 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
10630 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
10635 if (!saved
&& !ret
) {
10636 wpa_dbg(wpa_s
, MSG_DEBUG
,
10637 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
10643 #endif /* CONFIG_NO_CONFIG_WRITE */
10646 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
10647 char *buf
, size_t buflen
)
10651 struct wpa_supplicant
*wpa_s
;
10654 end
= buf
+ buflen
;
10657 if (global
->p2p
&& !global
->p2p_disabled
) {
10658 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
10661 MAC2STR(global
->p2p_dev_addr
),
10662 p2p_get_state_txt(global
->p2p
));
10663 if (os_snprintf_error(end
- pos
, ret
))
10666 } else if (global
->p2p
) {
10667 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
10668 if (os_snprintf_error(end
- pos
, ret
))
10672 #endif /* CONFIG_P2P */
10674 #ifdef CONFIG_WIFI_DISPLAY
10675 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
10676 !!global
->wifi_display
);
10677 if (os_snprintf_error(end
- pos
, ret
))
10680 #endif /* CONFIG_WIFI_DISPLAY */
10682 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10683 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
10684 "address=" MACSTR
"\n",
10685 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
10686 if (os_snprintf_error(end
- pos
, ret
))
10697 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
10698 char *cmd
, char *buf
,
10701 char ifname
[IFNAMSIZ
+ 1];
10702 struct fst_iface_cfg cfg
;
10703 struct wpa_supplicant
*wpa_s
;
10704 struct fst_wpa_obj iface_obj
;
10706 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
10707 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10710 wpa_printf(MSG_INFO
, "FST: Already attached");
10713 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
10714 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
10717 return os_snprintf(buf
, reply_size
, "OK\n");
10725 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
10726 char *cmd
, char *buf
,
10729 char ifname
[IFNAMSIZ
+ 1];
10730 struct wpa_supplicant
*wpa_s
;
10732 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
10733 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10735 if (!fst_iface_detach(ifname
)) {
10737 return os_snprintf(buf
, reply_size
, "OK\n");
10745 #endif /* CONFIG_FST */
10748 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
10749 char *buf
, size_t *resp_len
)
10752 const int reply_size
= 2048;
10754 int level
= MSG_DEBUG
;
10756 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
10757 char *pos
= os_strchr(buf
+ 7, ' ');
10760 return wpas_global_ctrl_iface_ifname(global
,
10766 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
10770 if (os_strcmp(buf
, "PING") == 0)
10771 level
= MSG_EXCESSIVE
;
10772 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
10773 (const u8
*) buf
, os_strlen(buf
));
10775 reply
= os_malloc(reply_size
);
10776 if (reply
== NULL
) {
10781 os_memcpy(reply
, "OK\n", 3);
10784 if (os_strcmp(buf
, "PING") == 0) {
10785 os_memcpy(reply
, "PONG\n", 5);
10787 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
10788 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
10790 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
10791 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
10793 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10794 reply_len
= wpa_supplicant_global_iface_list(
10795 global
, reply
, reply_size
);
10796 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10797 reply_len
= wpa_supplicant_global_iface_interfaces(
10798 global
, buf
+ 10, reply
, reply_size
);
10800 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
10801 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
10804 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
10805 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
10808 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
10809 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
10810 #endif /* CONFIG_FST */
10811 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10812 wpa_supplicant_terminate_proc(global
);
10813 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10814 wpas_notify_suspend(global
);
10815 } else if (os_strcmp(buf
, "RESUME") == 0) {
10816 wpas_notify_resume(global
);
10817 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10818 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
10820 if (global
->p2p_init_wpa_s
) {
10822 /* Check if P2P redirection would work for this
10824 return wpa_supplicant_ctrl_iface_process(
10825 global
->p2p_init_wpa_s
,
10828 #endif /* CONFIG_P2P */
10831 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10832 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
10834 #ifndef CONFIG_NO_CONFIG_WRITE
10835 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10836 if (wpas_global_ctrl_iface_save_config(global
))
10838 #endif /* CONFIG_NO_CONFIG_WRITE */
10839 } else if (os_strcmp(buf
, "STATUS") == 0) {
10840 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
10842 #ifdef CONFIG_MODULE_TESTS
10843 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
10844 if (wpas_module_tests() < 0)
10846 #endif /* CONFIG_MODULE_TESTS */
10847 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10848 if (wpa_debug_reopen_file() < 0)
10851 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10855 if (reply_len
< 0) {
10856 os_memcpy(reply
, "FAIL\n", 5);
10860 *resp_len
= reply_len
;