2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2014, 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 "common/version.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
21 #include "common/wpa_ctrl.h"
22 #include "ap/hostapd.h"
23 #include "eap_peer/eap.h"
24 #include "eapol_supp/eapol_supp_sm.h"
25 #include "rsn_supp/wpa.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "l2_packet/l2_packet.h"
31 #include "wpa_supplicant_i.h"
33 #include "wps_supplicant.h"
36 #include "p2p_supplicant.h"
38 #include "hs20_supplicant.h"
39 #include "wifi_display.h"
43 #include "ctrl_iface.h"
44 #include "interworking.h"
45 #include "blacklist.h"
48 #include "offchannel.h"
49 #include "drivers/driver.h"
52 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
54 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
56 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
59 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
62 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
69 if (hwaddr_aton(pos
, addr
)) {
73 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
79 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
82 pos
= os_strchr(pos
, ' ');
87 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
88 os_free(wpa_s
->bssid_filter
);
89 wpa_s
->bssid_filter
= filter
;
90 wpa_s
->bssid_filter_count
= count
;
96 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
99 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
100 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
101 size_t count
= 0, ssid_count
= 0;
105 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
106 * SSID_SPEC ::= ssid <SSID_HEX>
107 * BSSID_SPEC ::= bssid <BSSID_HEX>
114 if (os_strncmp(pos
, "bssid ", 6) == 0) {
117 res
= hwaddr_aton2(pos
, addr
);
121 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
122 "BSSID value '%s'", pos
);
126 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
133 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
135 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
141 if (*end
== '\0' || *end
== ' ')
146 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
147 sizeof(struct wpa_ssid_value
));
155 if ((end
- pos
) & 0x01 || end
- pos
> 2 * 32 ||
156 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
157 (end
- pos
) / 2) < 0) {
160 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
161 "SSID value '%s'", pos
);
164 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
165 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
166 ssid
[ssid_count
].ssid
,
167 ssid
[ssid_count
].ssid_len
);
171 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
178 pos
= os_strchr(pos
, ' ');
183 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
184 os_free(wpa_s
->disallow_aps_bssid
);
185 wpa_s
->disallow_aps_bssid
= bssid
;
186 wpa_s
->disallow_aps_bssid_count
= count
;
188 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
189 os_free(wpa_s
->disallow_aps_ssid
);
190 wpa_s
->disallow_aps_ssid
= ssid
;
191 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
193 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
196 c
= wpa_s
->current_ssid
;
197 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
200 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
201 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
204 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
205 "because current AP was marked disallowed");
208 wpa_s
->sme
.prev_bssid_set
= 0;
209 #endif /* CONFIG_SME */
210 wpa_s
->reassociate
= 1;
211 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
212 wpa_supplicant_req_scan(wpa_s
, 0, 0);
218 #ifndef CONFIG_NO_CONFIG_BLOBS
219 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
222 struct wpa_config_blob
*blob
;
225 pos
= os_strchr(pos
, ' ');
229 len
= os_strlen(pos
);
233 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
234 blob
= os_zalloc(sizeof(*blob
));
237 blob
->name
= os_strdup(name
);
238 blob
->data
= os_malloc(len
/ 2);
239 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
240 wpa_config_free_blob(blob
);
244 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
245 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
246 wpa_config_free_blob(blob
);
251 wpa_config_set_blob(wpa_s
->conf
, blob
);
255 #endif /* CONFIG_NO_CONFIG_BLOBS */
258 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
266 params
= os_strchr(cmd
, ' ');
267 os_free(wpa_s
->manual_sched_scan_freqs
);
270 pos
= os_strstr(params
, "freq=");
272 freqs
= freq_range_to_channel_list(wpa_s
,
275 wpa_s
->manual_sched_scan_freqs
= freqs
;
276 ret
= wpas_start_pno(wpa_s
);
278 ret
= wpas_stop_pno(wpa_s
);
284 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
290 value
= os_strchr(cmd
, ' ');
295 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
296 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
297 eapol_sm_configure(wpa_s
->eapol
,
298 atoi(value
), -1, -1, -1);
299 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
300 eapol_sm_configure(wpa_s
->eapol
,
301 -1, atoi(value
), -1, -1);
302 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
303 eapol_sm_configure(wpa_s
->eapol
,
304 -1, -1, atoi(value
), -1);
305 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
306 eapol_sm_configure(wpa_s
->eapol
,
307 -1, -1, -1, atoi(value
));
308 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
309 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
312 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
314 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
317 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
318 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
320 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
321 wpa_s
->wps_fragment_size
= atoi(value
);
322 #ifdef CONFIG_WPS_TESTING
323 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
325 val
= strtol(value
, NULL
, 0);
326 if (val
< 0 || val
> 0xff) {
328 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
329 "wps_version_number %ld", val
);
331 wps_version_number
= val
;
332 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
334 (wps_version_number
& 0xf0) >> 4,
335 wps_version_number
& 0x0f);
337 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
338 wps_testing_dummy_cred
= atoi(value
);
339 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
340 wps_testing_dummy_cred
);
341 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
342 wps_corrupt_pkhash
= atoi(value
);
343 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
345 #endif /* CONFIG_WPS_TESTING */
346 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
347 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
350 #ifdef CONFIG_TDLS_TESTING
351 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
352 extern unsigned int tdls_testing
;
353 tdls_testing
= strtol(value
, NULL
, 0);
354 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
355 #endif /* CONFIG_TDLS_TESTING */
356 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
357 int disabled
= atoi(value
);
358 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
360 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
362 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
364 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
365 #endif /* CONFIG_TDLS */
366 } else if (os_strcasecmp(cmd
, "pno") == 0) {
367 ret
= wpas_ctrl_pno(wpa_s
, value
);
368 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
369 int disabled
= atoi(value
);
370 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
373 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
374 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
375 if (os_strcmp(value
, "disable") == 0)
376 wpa_s
->set_sta_uapsd
= 0;
380 /* format: BE,BK,VI,VO;max SP Length */
382 pos
= os_strchr(value
, ',');
387 pos
= os_strchr(pos
, ',');
392 pos
= os_strchr(pos
, ',');
397 /* ignore max SP Length for now */
399 wpa_s
->set_sta_uapsd
= 1;
400 wpa_s
->sta_uapsd
= 0;
402 wpa_s
->sta_uapsd
|= BIT(0);
404 wpa_s
->sta_uapsd
|= BIT(1);
406 wpa_s
->sta_uapsd
|= BIT(2);
408 wpa_s
->sta_uapsd
|= BIT(3);
410 } else if (os_strcasecmp(cmd
, "ps") == 0) {
411 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
412 #ifdef CONFIG_WIFI_DISPLAY
413 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
414 int enabled
= !!atoi(value
);
415 if (enabled
&& !wpa_s
->global
->p2p
)
418 wifi_display_enable(wpa_s
->global
, enabled
);
419 #endif /* CONFIG_WIFI_DISPLAY */
420 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
421 ret
= set_bssid_filter(wpa_s
, value
);
422 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
423 ret
= set_disallow_aps(wpa_s
, value
);
424 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
425 wpa_s
->no_keep_alive
= !!atoi(value
);
426 #ifdef CONFIG_TESTING_OPTIONS
427 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
428 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
429 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
430 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
432 if (wpa_s
->ap_iface
) {
433 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
434 wpa_s
->ext_eapol_frame_io
;
436 #endif /* CONFIG_AP */
437 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
438 wpa_s
->extra_roc_dur
= atoi(value
);
439 #endif /* CONFIG_TESTING_OPTIONS */
440 #ifndef CONFIG_NO_CONFIG_BLOBS
441 } else if (os_strcmp(cmd
, "blob") == 0) {
442 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
443 #endif /* CONFIG_NO_CONFIG_BLOBS */
444 } else if (os_strcasecmp(cmd
, "setband") == 0) {
445 if (os_strcmp(value
, "AUTO") == 0)
446 wpa_s
->setband
= WPA_SETBAND_AUTO
;
447 else if (os_strcmp(value
, "5G") == 0)
448 wpa_s
->setband
= WPA_SETBAND_5G
;
449 else if (os_strcmp(value
, "2G") == 0)
450 wpa_s
->setband
= WPA_SETBAND_2G
;
455 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
457 wpa_supplicant_update_config(wpa_s
);
464 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
465 char *cmd
, char *buf
, size_t buflen
)
469 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
471 if (os_strcmp(cmd
, "version") == 0) {
472 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
473 } else if (os_strcasecmp(cmd
, "country") == 0) {
474 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
475 res
= os_snprintf(buf
, buflen
, "%c%c",
476 wpa_s
->conf
->country
[0],
477 wpa_s
->conf
->country
[1]);
478 #ifdef CONFIG_WIFI_DISPLAY
479 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
481 if (wpa_s
->global
->p2p
== NULL
||
482 wpa_s
->global
->p2p_disabled
)
485 enabled
= wpa_s
->global
->wifi_display
;
486 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
487 #endif /* CONFIG_WIFI_DISPLAY */
488 #ifdef CONFIG_TESTING_GET_GTK
489 } else if (os_strcmp(cmd
, "gtk") == 0) {
490 if (wpa_s
->last_gtk_len
== 0)
492 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
493 wpa_s
->last_gtk_len
);
495 #endif /* CONFIG_TESTING_GET_GTK */
498 if (os_snprintf_error(buflen
, res
))
504 #ifdef IEEE8021X_EAPOL
505 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
509 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
511 if (hwaddr_aton(addr
, bssid
)) {
512 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
517 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
518 rsn_preauth_deinit(wpa_s
->wpa
);
519 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
524 #endif /* IEEE8021X_EAPOL */
527 #ifdef CONFIG_PEERKEY
528 /* MLME-STKSTART.request(peer) */
529 static int wpa_supplicant_ctrl_iface_stkstart(
530 struct wpa_supplicant
*wpa_s
, char *addr
)
534 if (hwaddr_aton(addr
, peer
)) {
535 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
536 "address '%s'", addr
);
540 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
543 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
545 #endif /* CONFIG_PEERKEY */
550 static int wpa_supplicant_ctrl_iface_tdls_discover(
551 struct wpa_supplicant
*wpa_s
, char *addr
)
556 if (hwaddr_aton(addr
, peer
)) {
557 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
558 "address '%s'", addr
);
562 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
565 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
566 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
568 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
574 static int wpa_supplicant_ctrl_iface_tdls_setup(
575 struct wpa_supplicant
*wpa_s
, char *addr
)
580 if (hwaddr_aton(addr
, peer
)) {
581 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
582 "address '%s'", addr
);
586 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
589 if ((wpa_s
->conf
->tdls_external_control
) &&
590 wpa_tdls_is_external_setup(wpa_s
->wpa
))
591 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
593 wpa_tdls_remove(wpa_s
->wpa
, peer
);
595 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
596 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
598 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
604 static int wpa_supplicant_ctrl_iface_tdls_teardown(
605 struct wpa_supplicant
*wpa_s
, char *addr
)
610 if (os_strcmp(addr
, "*") == 0) {
611 /* remove everyone */
612 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
613 wpa_tdls_teardown_peers(wpa_s
->wpa
);
617 if (hwaddr_aton(addr
, peer
)) {
618 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
619 "address '%s'", addr
);
623 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
626 if ((wpa_s
->conf
->tdls_external_control
) &&
627 wpa_tdls_is_external_setup(wpa_s
->wpa
))
628 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
630 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
631 ret
= wpa_tdls_teardown_link(
633 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
635 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
641 static int ctrl_iface_get_capability_tdls(
642 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
646 ret
= os_snprintf(buf
, buflen
, "%s\n",
647 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
649 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
650 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
651 if (os_snprintf_error(buflen
, ret
))
656 #endif /* CONFIG_TDLS */
659 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
661 char *token
, *context
= NULL
;
662 struct wmm_ac_ts_setup_params params
= {
667 while ((token
= str_token(cmd
, " ", &context
))) {
668 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
669 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
670 sscanf(token
, "nominal_msdu_size=%i",
671 ¶ms
.nominal_msdu_size
) == 1 ||
672 sscanf(token
, "mean_data_rate=%i",
673 ¶ms
.mean_data_rate
) == 1 ||
674 sscanf(token
, "min_phy_rate=%i",
675 ¶ms
.minimum_phy_rate
) == 1 ||
676 sscanf(token
, "sba=%i",
677 ¶ms
.surplus_bandwidth_allowance
) == 1)
680 if (os_strcasecmp(token
, "downlink") == 0) {
681 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
682 } else if (os_strcasecmp(token
, "uplink") == 0) {
683 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
684 } else if (os_strcasecmp(token
, "bidi") == 0) {
685 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
686 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
687 params
.fixed_nominal_msdu
= 1;
689 wpa_printf(MSG_DEBUG
,
690 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
697 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
701 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
705 return wpas_wmm_ac_delts(wpa_s
, tsid
);
709 #ifdef CONFIG_IEEE80211R
710 static int wpa_supplicant_ctrl_iface_ft_ds(
711 struct wpa_supplicant
*wpa_s
, char *addr
)
713 u8 target_ap
[ETH_ALEN
];
717 if (hwaddr_aton(addr
, target_ap
)) {
718 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
719 "address '%s'", addr
);
723 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
725 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
727 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
731 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
733 #endif /* CONFIG_IEEE80211R */
737 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
740 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
742 u8 p2p_dev_addr
[ETH_ALEN
];
743 #endif /* CONFIG_P2P */
745 u8
*_p2p_dev_addr
= NULL
;
746 #endif /* CONFIG_AP */
748 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
751 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
752 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
753 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
754 "P2P Device Address '%s'",
758 _p2p_dev_addr
= p2p_dev_addr
;
759 #endif /* CONFIG_P2P */
760 } else if (hwaddr_aton(cmd
, bssid
)) {
761 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
768 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
769 #endif /* CONFIG_AP */
771 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
775 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
776 char *cmd
, char *buf
,
779 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
783 pin
= os_strchr(cmd
, ' ');
787 if (os_strcmp(cmd
, "any") == 0)
789 else if (os_strcmp(cmd
, "get") == 0) {
790 ret
= wps_generate_pin();
792 } else if (hwaddr_aton(cmd
, bssid
)) {
793 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
799 if (wpa_s
->ap_iface
) {
804 pos
= os_strchr(pin
, ' ');
811 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
812 buf
, buflen
, timeout
);
814 #endif /* CONFIG_AP */
817 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
821 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
822 if (os_snprintf_error(buflen
, ret
))
827 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
832 /* Return the generated PIN */
833 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
834 if (os_snprintf_error(buflen
, ret
))
840 static int wpa_supplicant_ctrl_iface_wps_check_pin(
841 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
848 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
849 (u8
*) cmd
, os_strlen(cmd
));
850 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
851 if (*pos
< '0' || *pos
> '9')
855 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
859 if (len
!= 4 && len
!= 8) {
860 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
866 unsigned int pin_val
;
868 if (!wps_pin_valid(pin_val
)) {
869 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
870 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
871 if (os_snprintf_error(buflen
, ret
))
877 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
878 if (os_snprintf_error(buflen
, ret
))
885 #ifdef CONFIG_WPS_NFC
887 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
890 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
892 if (cmd
== NULL
|| cmd
[0] == '\0')
894 else if (hwaddr_aton(cmd
, bssid
))
897 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
902 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
903 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
910 pos
= os_strchr(cmd
, ' ');
913 if (os_strcmp(cmd
, "WPS") == 0)
915 else if (os_strcmp(cmd
, "NDEF") == 0)
920 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
924 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
935 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
936 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
942 if (os_strcmp(cmd
, "WPS") == 0)
944 else if (os_strcmp(cmd
, "NDEF") == 0)
949 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
953 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
964 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
965 struct wpa_supplicant
*wpa_s
, char *pos
)
973 freq
= strstr(pos
, " freq=");
977 forced_freq
= atoi(freq
);
980 len
= os_strlen(pos
);
985 buf
= wpabuf_alloc(len
);
988 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
993 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1000 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1001 char *reply
, size_t max_len
,
1007 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1011 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1013 reply
[res
++] = '\n';
1023 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1024 char *reply
, size_t max_len
,
1030 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1032 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1036 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1038 reply
[res
++] = '\n';
1045 #endif /* CONFIG_P2P */
1048 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1049 char *cmd
, char *reply
,
1055 pos
= os_strchr(cmd
, ' ');
1060 if (os_strcmp(cmd
, "WPS") == 0)
1062 else if (os_strcmp(cmd
, "NDEF") == 0)
1067 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1070 return wpas_ctrl_nfc_get_handover_req_wps(
1071 wpa_s
, reply
, max_len
, ndef
);
1075 if (os_strcmp(pos
, "P2P-CR") == 0) {
1076 return wpas_ctrl_nfc_get_handover_req_p2p(
1077 wpa_s
, reply
, max_len
, ndef
);
1079 #endif /* CONFIG_P2P */
1085 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1086 char *reply
, size_t max_len
,
1087 int ndef
, int cr
, char *uuid
)
1092 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1096 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1098 reply
[res
++] = '\n';
1108 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1109 char *reply
, size_t max_len
,
1115 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1119 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1121 reply
[res
++] = '\n';
1128 #endif /* CONFIG_P2P */
1131 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1132 char *cmd
, char *reply
,
1138 pos
= os_strchr(cmd
, ' ');
1143 if (os_strcmp(cmd
, "WPS") == 0)
1145 else if (os_strcmp(cmd
, "NDEF") == 0)
1150 pos2
= os_strchr(pos
, ' ');
1153 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1156 return wpas_ctrl_nfc_get_handover_sel_wps(
1157 wpa_s
, reply
, max_len
, ndef
,
1158 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1162 if (os_strcmp(pos
, "P2P-CR") == 0) {
1163 return wpas_ctrl_nfc_get_handover_sel_p2p(
1164 wpa_s
, reply
, max_len
, ndef
, 0);
1167 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1168 return wpas_ctrl_nfc_get_handover_sel_p2p(
1169 wpa_s
, reply
, max_len
, ndef
, 1);
1171 #endif /* CONFIG_P2P */
1177 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1181 struct wpabuf
*req
, *sel
;
1183 char *pos
, *role
, *type
, *pos2
;
1186 int forced_freq
= 0;
1188 freq
= strstr(cmd
, " freq=");
1192 forced_freq
= atoi(freq
);
1194 #endif /* CONFIG_P2P */
1197 pos
= os_strchr(role
, ' ');
1199 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1205 pos
= os_strchr(type
, ' ');
1207 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1212 pos2
= os_strchr(pos
, ' ');
1214 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1219 len
= os_strlen(pos
);
1221 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1226 req
= wpabuf_alloc(len
);
1228 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1231 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1232 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1237 len
= os_strlen(pos2
);
1239 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1245 sel
= wpabuf_alloc(len
);
1247 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1251 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1252 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1258 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1259 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1261 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1262 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1264 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1266 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1268 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1269 #endif /* CONFIG_AP */
1271 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1273 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1274 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1276 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1278 #endif /* CONFIG_P2P */
1280 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1281 "reported: role=%s type=%s", role
, type
);
1288 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1293 #endif /* CONFIG_WPS_NFC */
1296 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1305 struct wps_new_ap_settings ap
;
1307 pin
= os_strchr(cmd
, ' ');
1312 if (hwaddr_aton(cmd
, bssid
)) {
1313 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1318 new_ssid
= os_strchr(pin
, ' ');
1319 if (new_ssid
== NULL
)
1320 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1323 new_auth
= os_strchr(new_ssid
, ' ');
1324 if (new_auth
== NULL
)
1328 new_encr
= os_strchr(new_auth
, ' ');
1329 if (new_encr
== NULL
)
1333 new_key
= os_strchr(new_encr
, ' ');
1334 if (new_key
== NULL
)
1338 os_memset(&ap
, 0, sizeof(ap
));
1339 ap
.ssid_hex
= new_ssid
;
1342 ap
.key_hex
= new_key
;
1343 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1348 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1349 char *cmd
, char *buf
,
1354 const char *pin_txt
;
1356 if (!wpa_s
->ap_iface
)
1359 pos
= os_strchr(cmd
, ' ');
1363 if (os_strcmp(cmd
, "disable") == 0) {
1364 wpas_wps_ap_pin_disable(wpa_s
);
1365 return os_snprintf(buf
, buflen
, "OK\n");
1368 if (os_strcmp(cmd
, "random") == 0) {
1370 timeout
= atoi(pos
);
1371 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1372 if (pin_txt
== NULL
)
1374 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1377 if (os_strcmp(cmd
, "get") == 0) {
1378 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1379 if (pin_txt
== NULL
)
1381 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1384 if (os_strcmp(cmd
, "set") == 0) {
1389 pos
= os_strchr(pos
, ' ');
1392 timeout
= atoi(pos
);
1394 if (os_strlen(pin
) > buflen
)
1396 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1398 return os_snprintf(buf
, buflen
, "%s", pin
);
1403 #endif /* CONFIG_AP */
1406 #ifdef CONFIG_WPS_ER
1407 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1410 char *uuid
= cmd
, *pin
, *pos
;
1411 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1412 pin
= os_strchr(uuid
, ' ');
1416 pos
= os_strchr(pin
, ' ');
1419 if (hwaddr_aton(pos
, addr_buf
) == 0)
1422 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1426 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1429 char *uuid
= cmd
, *pin
;
1430 pin
= os_strchr(uuid
, ' ');
1434 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1438 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1439 struct wpa_supplicant
*wpa_s
, char *cmd
)
1441 char *uuid
= cmd
, *id
;
1442 id
= os_strchr(uuid
, ' ');
1446 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1450 static int wpa_supplicant_ctrl_iface_wps_er_config(
1451 struct wpa_supplicant
*wpa_s
, char *cmd
)
1458 struct wps_new_ap_settings ap
;
1460 pin
= os_strchr(cmd
, ' ');
1465 new_ssid
= os_strchr(pin
, ' ');
1466 if (new_ssid
== NULL
)
1470 new_auth
= os_strchr(new_ssid
, ' ');
1471 if (new_auth
== NULL
)
1475 new_encr
= os_strchr(new_auth
, ' ');
1476 if (new_encr
== NULL
)
1480 new_key
= os_strchr(new_encr
, ' ');
1481 if (new_key
== NULL
)
1485 os_memset(&ap
, 0, sizeof(ap
));
1486 ap
.ssid_hex
= new_ssid
;
1489 ap
.key_hex
= new_key
;
1490 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1494 #ifdef CONFIG_WPS_NFC
1495 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1496 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1503 uuid
= os_strchr(cmd
, ' ');
1508 if (os_strcmp(cmd
, "WPS") == 0)
1510 else if (os_strcmp(cmd
, "NDEF") == 0)
1515 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1519 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1521 reply
[res
++] = '\n';
1528 #endif /* CONFIG_WPS_NFC */
1529 #endif /* CONFIG_WPS_ER */
1531 #endif /* CONFIG_WPS */
1534 #ifdef CONFIG_IBSS_RSN
1535 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1536 struct wpa_supplicant
*wpa_s
, char *addr
)
1540 if (hwaddr_aton(addr
, peer
)) {
1541 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1542 "address '%s'", addr
);
1546 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1549 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1551 #endif /* CONFIG_IBSS_RSN */
1554 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1557 #ifdef IEEE8021X_EAPOL
1560 struct wpa_ssid
*ssid
;
1562 pos
= os_strchr(rsp
, '-');
1567 pos
= os_strchr(pos
, ':');
1572 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1573 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1574 (u8
*) pos
, os_strlen(pos
));
1576 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1578 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1583 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1585 #else /* IEEE8021X_EAPOL */
1586 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1588 #endif /* IEEE8021X_EAPOL */
1592 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1594 char *buf
, size_t buflen
)
1596 char *pos
, *end
, tmp
[30];
1597 int res
, verbose
, wps
, ret
;
1600 #endif /* CONFIG_HS20 */
1602 if (os_strcmp(params
, "-DRIVER") == 0)
1603 return wpa_drv_status(wpa_s
, buf
, buflen
);
1604 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1605 wps
= os_strcmp(params
, "-WPS") == 0;
1608 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1609 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1610 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1611 MAC2STR(wpa_s
->bssid
));
1612 if (os_snprintf_error(end
- pos
, ret
))
1615 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1617 if (os_snprintf_error(end
- pos
, ret
))
1621 u8
*_ssid
= ssid
->ssid
;
1622 size_t ssid_len
= ssid
->ssid_len
;
1623 u8 ssid_buf
[MAX_SSID_LEN
];
1624 if (ssid_len
== 0) {
1625 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1632 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1633 wpa_ssid_txt(_ssid
, ssid_len
),
1635 if (os_snprintf_error(end
- pos
, ret
))
1639 if (wps
&& ssid
->passphrase
&&
1640 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1641 (ssid
->mode
== WPAS_MODE_AP
||
1642 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1643 ret
= os_snprintf(pos
, end
- pos
,
1646 if (os_snprintf_error(end
- pos
, ret
))
1651 ret
= os_snprintf(pos
, end
- pos
,
1654 if (os_snprintf_error(end
- pos
, ret
))
1659 switch (ssid
->mode
) {
1660 case WPAS_MODE_INFRA
:
1661 ret
= os_snprintf(pos
, end
- pos
,
1664 case WPAS_MODE_IBSS
:
1665 ret
= os_snprintf(pos
, end
- pos
,
1669 ret
= os_snprintf(pos
, end
- pos
,
1672 case WPAS_MODE_P2P_GO
:
1673 ret
= os_snprintf(pos
, end
- pos
,
1676 case WPAS_MODE_P2P_GROUP_FORMATION
:
1677 ret
= os_snprintf(pos
, end
- pos
,
1678 "mode=P2P GO - group "
1685 if (os_snprintf_error(end
- pos
, ret
))
1691 if (wpa_s
->ap_iface
) {
1692 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1696 #endif /* CONFIG_AP */
1697 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1700 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1703 #endif /* CONFIG_AP */
1704 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1705 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1706 wpa_s
->sme
.sae
.group
);
1707 if (os_snprintf_error(end
- pos
, ret
))
1711 #endif /* CONFIG_SAE */
1712 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1713 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1714 if (os_snprintf_error(end
- pos
, ret
))
1719 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1720 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1721 if (os_snprintf_error(end
- pos
, ret
))
1727 if (wpa_s
->global
->p2p
) {
1728 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1729 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1730 if (os_snprintf_error(end
- pos
, ret
))
1734 #endif /* CONFIG_P2P */
1736 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1737 MAC2STR(wpa_s
->own_addr
));
1738 if (os_snprintf_error(end
- pos
, ret
))
1743 if (wpa_s
->current_bss
&&
1744 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1745 HS20_IE_VENDOR_TYPE
)) &&
1746 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1747 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1750 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
1751 release
= rel_num
+ 1;
1753 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
1754 if (os_snprintf_error(end
- pos
, ret
))
1759 if (wpa_s
->current_ssid
) {
1760 struct wpa_cred
*cred
;
1763 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1766 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1769 if (cred
->provisioning_sp
) {
1770 ret
= os_snprintf(pos
, end
- pos
,
1771 "provisioning_sp=%s\n",
1772 cred
->provisioning_sp
);
1773 if (os_snprintf_error(end
- pos
, ret
))
1782 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
1783 struct wpabuf
*names
=
1784 wpa_s
->current_bss
->anqp
->domain_name
;
1785 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
1787 if (domain_name_list_contains(
1788 names
, cred
->domain
[i
], 1))
1791 if (i
== cred
->num_domain
)
1792 i
= 0; /* show first entry by default */
1794 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
1796 if (os_snprintf_error(end
- pos
, ret
))
1801 if (wpa_s
->current_bss
== NULL
||
1802 wpa_s
->current_bss
->anqp
== NULL
)
1805 res
= interworking_home_sp_cred(
1807 wpa_s
->current_bss
->anqp
->domain_name
);
1815 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1816 if (os_snprintf_error(end
- pos
, ret
))
1823 #endif /* CONFIG_HS20 */
1825 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1826 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1827 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1833 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1840 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1841 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1842 if (os_snprintf_error(end
- pos
, ret
))
1846 #endif /* CONFIG_WPS */
1850 * Allow using the STATUS command with default behavior, say for debug,
1851 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1852 * events with STATUS-NO_EVENTS.
1854 if (os_strcmp(params
, "-NO_EVENTS")) {
1855 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1856 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1857 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1859 MAC2STR(wpa_s
->bssid
),
1860 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1861 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1862 wpa_s
->current_ssid
->ssid_len
) : "");
1863 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1864 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1865 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1866 "- connection to " MACSTR
1867 " completed %s [id=%d id_str=%s]",
1868 MAC2STR(wpa_s
->bssid
), "(auth)",
1869 ssid
? ssid
->id
: -1,
1870 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1873 #endif /* ANDROID */
1879 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1884 struct wpa_ssid
*ssid
;
1887 /* cmd: "<network id> <BSSID>" */
1888 pos
= os_strchr(cmd
, ' ');
1893 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1894 if (hwaddr_aton(pos
, bssid
)) {
1895 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1899 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1901 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1906 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1907 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1913 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1914 char *cmd
, char *buf
,
1918 struct wpa_blacklist
*e
;
1922 /* cmd: "BLACKLIST [<BSSID>]" */
1926 e
= wpa_s
->blacklist
;
1928 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1930 if (os_snprintf_error(end
- pos
, ret
))
1939 if (os_strncmp(cmd
, "clear", 5) == 0) {
1940 wpa_blacklist_clear(wpa_s
);
1941 os_memcpy(buf
, "OK\n", 3);
1945 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1946 if (hwaddr_aton(cmd
, bssid
)) {
1947 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1952 * Add the BSSID twice, so its count will be 2, causing it to be
1953 * skipped when processing scan results.
1955 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1958 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1961 os_memcpy(buf
, "OK\n", 3);
1966 static const char * debug_level_str(int level
)
1987 static int str_to_debug_level(const char *s
)
1989 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1990 return MSG_EXCESSIVE
;
1991 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1993 if (os_strcasecmp(s
, "DEBUG") == 0)
1995 if (os_strcasecmp(s
, "INFO") == 0)
1997 if (os_strcasecmp(s
, "WARNING") == 0)
1999 if (os_strcasecmp(s
, "ERROR") == 0)
2005 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2006 char *cmd
, char *buf
,
2009 char *pos
, *end
, *stamp
;
2012 /* cmd: "LOG_LEVEL [<level>]" */
2016 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2018 debug_level_str(wpa_debug_level
),
2019 wpa_debug_timestamp
);
2020 if (os_snprintf_error(end
- pos
, ret
))
2029 stamp
= os_strchr(cmd
, ' ');
2032 while (*stamp
== ' ') {
2037 if (cmd
&& os_strlen(cmd
)) {
2038 int level
= str_to_debug_level(cmd
);
2041 wpa_debug_level
= level
;
2044 if (stamp
&& os_strlen(stamp
))
2045 wpa_debug_timestamp
= atoi(stamp
);
2047 os_memcpy(buf
, "OK\n", 3);
2052 static int wpa_supplicant_ctrl_iface_list_networks(
2053 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2055 char *pos
, *end
, *prev
;
2056 struct wpa_ssid
*ssid
;
2061 ret
= os_snprintf(pos
, end
- pos
,
2062 "network id / ssid / bssid / flags\n");
2063 if (os_snprintf_error(end
- pos
, ret
))
2067 ssid
= wpa_s
->conf
->ssid
;
2069 /* skip over ssids until we find next one */
2070 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2071 int last_id
= atoi(cmd
+ 8);
2072 if (last_id
!= -1) {
2073 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2081 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2083 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2084 if (os_snprintf_error(end
- pos
, ret
))
2087 if (ssid
->bssid_set
) {
2088 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2089 MAC2STR(ssid
->bssid
));
2091 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2093 if (os_snprintf_error(end
- pos
, ret
))
2096 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2097 ssid
== wpa_s
->current_ssid
?
2099 ssid
->disabled
? "[DISABLED]" : "",
2100 ssid
->disabled_until
.sec
?
2101 "[TEMP-DISABLED]" : "",
2102 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2104 if (os_snprintf_error(end
- pos
, ret
))
2107 ret
= os_snprintf(pos
, end
- pos
, "\n");
2108 if (os_snprintf_error(end
- pos
, ret
))
2119 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2122 ret
= os_snprintf(pos
, end
- pos
, "-");
2123 if (os_snprintf_error(end
- pos
, ret
))
2126 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2134 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2135 const u8
*ie
, size_t ie_len
)
2137 struct wpa_ie_data data
;
2141 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2142 if (os_snprintf_error(end
- pos
, ret
))
2146 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2147 ret
= os_snprintf(pos
, end
- pos
, "?]");
2148 if (os_snprintf_error(end
- pos
, ret
))
2155 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2156 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2157 pos
== start
? "" : "+");
2158 if (os_snprintf_error(end
- pos
, ret
))
2162 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2163 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2164 pos
== start
? "" : "+");
2165 if (os_snprintf_error(end
- pos
, ret
))
2169 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2170 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2171 pos
== start
? "" : "+");
2172 if (os_snprintf_error(end
- pos
, ret
))
2176 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2177 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2178 pos
== start
? "" : "+");
2179 if (os_snprintf_error(end
- pos
, ret
))
2183 #ifdef CONFIG_IEEE80211R
2184 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2185 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2186 pos
== start
? "" : "+");
2187 if (os_snprintf_error(end
- pos
, ret
))
2191 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2192 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2193 pos
== start
? "" : "+");
2194 if (os_snprintf_error(end
- pos
, ret
))
2198 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2199 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2200 pos
== start
? "" : "+");
2201 if (os_snprintf_error(end
- pos
, ret
))
2205 #endif /* CONFIG_IEEE80211R */
2206 #ifdef CONFIG_IEEE80211W
2207 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2208 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2209 pos
== start
? "" : "+");
2210 if (os_snprintf_error(end
- pos
, ret
))
2214 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2215 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2216 pos
== start
? "" : "+");
2217 if (os_snprintf_error(end
- pos
, ret
))
2221 #endif /* CONFIG_IEEE80211W */
2223 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2224 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2225 pos
== start
? "" : "+");
2226 if (os_snprintf_error(end
- pos
, ret
))
2231 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2233 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2234 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2235 if (os_snprintf_error(end
- pos
, ret
))
2240 ret
= os_snprintf(pos
, end
- pos
, "]");
2241 if (os_snprintf_error(end
- pos
, ret
))
2250 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2251 char *pos
, char *end
,
2252 struct wpabuf
*wps_ie
)
2259 if (wps_is_selected_pbc_registrar(wps_ie
))
2261 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2263 else if (wps_is_selected_pin_registrar(wps_ie
))
2268 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2269 if (!os_snprintf_error(end
- pos
, ret
))
2271 wpabuf_free(wps_ie
);
2274 #endif /* CONFIG_WPS */
2277 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2278 char *pos
, char *end
,
2279 const struct wpa_bss
*bss
)
2282 struct wpabuf
*wps_ie
;
2283 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2284 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2285 #else /* CONFIG_WPS */
2287 #endif /* CONFIG_WPS */
2291 /* Format one result on one text line into a buffer. */
2292 static int wpa_supplicant_ctrl_iface_scan_result(
2293 struct wpa_supplicant
*wpa_s
,
2294 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2298 const u8
*ie
, *ie2
, *p2p
, *mesh
;
2300 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2301 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2303 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2304 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2305 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2307 return 0; /* Do not show P2P listen discovery results here */
2312 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2313 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2314 if (os_snprintf_error(end
- pos
, ret
))
2317 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2319 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2320 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2322 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2325 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2326 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2327 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2328 if (os_snprintf_error(end
- pos
, ret
))
2333 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2334 if (os_snprintf_error(end
- pos
, ret
))
2338 if (bss_is_dmg(bss
)) {
2340 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2341 if (os_snprintf_error(end
- pos
, ret
))
2344 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2345 case IEEE80211_CAP_DMG_IBSS
:
2348 case IEEE80211_CAP_DMG_AP
:
2351 case IEEE80211_CAP_DMG_PBSS
:
2358 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2359 if (os_snprintf_error(end
- pos
, ret
))
2363 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2364 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2365 if (os_snprintf_error(end
- pos
, ret
))
2369 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2370 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2371 if (os_snprintf_error(end
- pos
, ret
))
2377 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2378 if (os_snprintf_error(end
- pos
, ret
))
2383 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2384 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2385 if (os_snprintf_error(end
- pos
, ret
))
2389 #endif /* CONFIG_HS20 */
2391 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2392 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2393 if (os_snprintf_error(end
- pos
, ret
))
2397 ret
= os_snprintf(pos
, end
- pos
, "\n");
2398 if (os_snprintf_error(end
- pos
, ret
))
2406 static int wpa_supplicant_ctrl_iface_scan_results(
2407 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2410 struct wpa_bss
*bss
;
2415 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2417 if (os_snprintf_error(end
- pos
, ret
))
2421 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2422 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2424 if (ret
< 0 || ret
>= end
- pos
)
2435 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2436 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2438 char *pos
, ifname
[IFNAMSIZ
+ 1];
2442 pos
= os_strstr(cmd
, "ifname=");
2445 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2448 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2451 os_strlcpy(reply
, ifname
, max_len
);
2452 return os_strlen(ifname
);
2456 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2457 struct wpa_supplicant
*wpa_s
, char *cmd
)
2460 struct wpa_ssid
*ssid
;
2463 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2465 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2467 wpa_printf(MSG_DEBUG
,
2468 "CTRL_IFACE: Could not find network id=%d", id
);
2471 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2472 wpa_printf(MSG_DEBUG
,
2473 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2476 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2477 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2478 wpa_printf(MSG_ERROR
,
2479 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2484 * TODO: If necessary write our own group_add function,
2485 * for now we can reuse select_network
2487 wpa_supplicant_select_network(wpa_s
, ssid
);
2493 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2494 struct wpa_supplicant
*wpa_s
, char *cmd
)
2496 struct wpa_supplicant
*orig
;
2497 struct wpa_global
*global
;
2500 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2502 global
= wpa_s
->global
;
2505 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2506 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2512 wpa_printf(MSG_ERROR
,
2513 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2517 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2518 wpa_printf(MSG_ERROR
,
2519 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2523 wpa_s
->reassociate
= 0;
2524 wpa_s
->disconnected
= 1;
2525 wpa_supplicant_cancel_sched_scan(wpa_s
);
2526 wpa_supplicant_cancel_scan(wpa_s
);
2529 * TODO: If necessary write our own group_remove function,
2530 * for now we can reuse deauthenticate
2532 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2534 if (wpa_s
->mesh_if_created
)
2535 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
2540 #endif /* CONFIG_MESH */
2543 static int wpa_supplicant_ctrl_iface_select_network(
2544 struct wpa_supplicant
*wpa_s
, char *cmd
)
2547 struct wpa_ssid
*ssid
;
2550 /* cmd: "<network id>" or "any" */
2551 if (os_strncmp(cmd
, "any", 3) == 0) {
2552 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2556 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2558 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2560 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2561 "network id=%d", id
);
2564 if (ssid
->disabled
== 2) {
2565 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2566 "SELECT_NETWORK with persistent P2P group");
2571 pos
= os_strstr(cmd
, " freq=");
2573 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
2575 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2576 os_free(wpa_s
->manual_scan_freqs
);
2577 wpa_s
->manual_scan_freqs
= freqs
;
2581 wpa_supplicant_select_network(wpa_s
, ssid
);
2587 static int wpa_supplicant_ctrl_iface_enable_network(
2588 struct wpa_supplicant
*wpa_s
, char *cmd
)
2591 struct wpa_ssid
*ssid
;
2593 /* cmd: "<network id>" or "all" */
2594 if (os_strcmp(cmd
, "all") == 0) {
2595 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2599 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2601 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2603 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2604 "network id=%d", id
);
2607 if (ssid
->disabled
== 2) {
2608 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2609 "ENABLE_NETWORK with persistent P2P group");
2613 if (os_strstr(cmd
, " no-connect")) {
2618 wpa_supplicant_enable_network(wpa_s
, ssid
);
2624 static int wpa_supplicant_ctrl_iface_disable_network(
2625 struct wpa_supplicant
*wpa_s
, char *cmd
)
2628 struct wpa_ssid
*ssid
;
2630 /* cmd: "<network id>" or "all" */
2631 if (os_strcmp(cmd
, "all") == 0) {
2632 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2636 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2638 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2640 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2641 "network id=%d", id
);
2644 if (ssid
->disabled
== 2) {
2645 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2646 "DISABLE_NETWORK with persistent P2P "
2651 wpa_supplicant_disable_network(wpa_s
, ssid
);
2657 static int wpa_supplicant_ctrl_iface_add_network(
2658 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2660 struct wpa_ssid
*ssid
;
2663 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2665 ssid
= wpa_config_add_network(wpa_s
->conf
);
2669 wpas_notify_network_added(wpa_s
, ssid
);
2672 wpa_config_set_network_defaults(ssid
);
2674 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2675 if (os_snprintf_error(buflen
, ret
))
2681 static int wpa_supplicant_ctrl_iface_remove_network(
2682 struct wpa_supplicant
*wpa_s
, char *cmd
)
2685 struct wpa_ssid
*ssid
;
2688 /* cmd: "<network id>" or "all" */
2689 if (os_strcmp(cmd
, "all") == 0) {
2690 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2691 if (wpa_s
->sched_scanning
)
2692 wpa_supplicant_cancel_sched_scan(wpa_s
);
2694 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2695 if (wpa_s
->current_ssid
) {
2697 wpa_s
->sme
.prev_bssid_set
= 0;
2698 #endif /* CONFIG_SME */
2699 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2700 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2701 wpa_supplicant_deauthenticate(
2702 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2704 ssid
= wpa_s
->conf
->ssid
;
2706 struct wpa_ssid
*remove_ssid
= ssid
;
2709 if (wpa_s
->last_ssid
== remove_ssid
)
2710 wpa_s
->last_ssid
= NULL
;
2711 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2712 wpa_config_remove_network(wpa_s
->conf
, id
);
2718 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2720 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2722 wpas_notify_network_removed(wpa_s
, ssid
);
2724 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2729 if (wpa_s
->last_ssid
== ssid
)
2730 wpa_s
->last_ssid
= NULL
;
2732 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2734 wpa_s
->sme
.prev_bssid_set
= 0;
2735 #endif /* CONFIG_SME */
2737 * Invalidate the EAP session cache if the current or
2738 * previously used network is removed.
2740 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2743 if (ssid
== wpa_s
->current_ssid
) {
2744 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2745 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2747 wpa_supplicant_deauthenticate(wpa_s
,
2748 WLAN_REASON_DEAUTH_LEAVING
);
2751 was_disabled
= ssid
->disabled
;
2753 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2754 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2755 "network id=%d", id
);
2759 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2760 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2761 "network from filters");
2762 wpa_supplicant_cancel_sched_scan(wpa_s
);
2763 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2770 static int wpa_supplicant_ctrl_iface_update_network(
2771 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2772 char *name
, char *value
)
2774 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2775 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2776 "variable '%s'", name
);
2780 if (os_strcmp(name
, "bssid") != 0 &&
2781 os_strcmp(name
, "priority") != 0)
2782 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2784 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2786 * Invalidate the EAP session cache if anything in the current
2787 * or previously used configuration changes.
2789 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2792 if ((os_strcmp(name
, "psk") == 0 &&
2793 value
[0] == '"' && ssid
->ssid_len
) ||
2794 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2795 wpa_config_update_psk(ssid
);
2796 else if (os_strcmp(name
, "priority") == 0)
2797 wpa_config_update_prio_list(wpa_s
->conf
);
2798 else if (os_strcmp(name
, "no_auto_peer") == 0)
2799 ssid
->no_auto_peer
= atoi(value
);
2805 static int wpa_supplicant_ctrl_iface_set_network(
2806 struct wpa_supplicant
*wpa_s
, char *cmd
)
2808 int id
, ret
, prev_bssid_set
;
2809 struct wpa_ssid
*ssid
;
2811 u8 prev_bssid
[ETH_ALEN
];
2813 /* cmd: "<network id> <variable name> <value>" */
2814 name
= os_strchr(cmd
, ' ');
2819 value
= os_strchr(name
, ' ');
2825 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2827 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2828 (u8
*) value
, os_strlen(value
));
2830 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2832 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2837 prev_bssid_set
= ssid
->bssid_set
;
2838 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
2839 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
2842 (ssid
->bssid_set
!= prev_bssid_set
||
2843 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
2844 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
2849 static int wpa_supplicant_ctrl_iface_get_network(
2850 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2854 struct wpa_ssid
*ssid
;
2857 /* cmd: "<network id> <variable name>" */
2858 name
= os_strchr(cmd
, ' ');
2859 if (name
== NULL
|| buflen
== 0)
2864 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2867 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2869 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2874 value
= wpa_config_get_no_key(ssid
, name
);
2875 if (value
== NULL
) {
2876 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2877 "variable '%s'", name
);
2881 res
= os_strlcpy(buf
, value
, buflen
);
2882 if (res
>= buflen
) {
2893 static int wpa_supplicant_ctrl_iface_dup_network(
2894 struct wpa_supplicant
*wpa_s
, char *cmd
)
2896 struct wpa_ssid
*ssid_s
, *ssid_d
;
2897 char *name
, *id
, *value
;
2898 int id_s
, id_d
, ret
;
2900 /* cmd: "<src network id> <dst network id> <variable name>" */
2901 id
= os_strchr(cmd
, ' ');
2906 name
= os_strchr(id
, ' ');
2913 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2916 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
2917 if (ssid_s
== NULL
) {
2918 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2919 "network id=%d", id_s
);
2923 ssid_d
= wpa_config_get_network(wpa_s
->conf
, id_d
);
2924 if (ssid_d
== NULL
) {
2925 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2926 "network id=%d", id_d
);
2930 value
= wpa_config_get(ssid_s
, name
);
2931 if (value
== NULL
) {
2932 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2933 "variable '%s'", name
);
2937 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid_d
, name
,
2946 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2947 char *buf
, size_t buflen
)
2950 struct wpa_cred
*cred
;
2955 ret
= os_snprintf(pos
, end
- pos
,
2956 "cred id / realm / username / domain / imsi\n");
2957 if (os_snprintf_error(end
- pos
, ret
))
2961 cred
= wpa_s
->conf
->cred
;
2963 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2964 cred
->id
, cred
->realm
? cred
->realm
: "",
2965 cred
->username
? cred
->username
: "",
2966 cred
->domain
? cred
->domain
[0] : "",
2967 cred
->imsi
? cred
->imsi
: "");
2968 if (os_snprintf_error(end
- pos
, ret
))
2979 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2980 char *buf
, size_t buflen
)
2982 struct wpa_cred
*cred
;
2985 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2987 cred
= wpa_config_add_cred(wpa_s
->conf
);
2991 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
2993 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2994 if (os_snprintf_error(buflen
, ret
))
3000 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3001 struct wpa_cred
*cred
)
3003 struct wpa_ssid
*ssid
;
3008 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3013 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3014 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3018 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3020 /* Remove any network entry created based on the removed credential */
3021 ssid
= wpa_s
->conf
->ssid
;
3023 if (ssid
->parent_cred
== cred
) {
3026 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3027 "used the removed credential", ssid
->id
);
3028 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3029 if (os_snprintf_error(sizeof(str
), res
))
3030 str
[sizeof(str
) - 1] = '\0';
3032 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3041 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3045 struct wpa_cred
*cred
, *prev
;
3047 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3048 * "provisioning_sp=<FQDN> */
3049 if (os_strcmp(cmd
, "all") == 0) {
3050 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3051 cred
= wpa_s
->conf
->cred
;
3055 wpas_ctrl_remove_cred(wpa_s
, prev
);
3060 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3061 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3063 cred
= wpa_s
->conf
->cred
;
3069 for (i
= 0; i
< prev
->num_domain
; i
++) {
3070 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3073 wpas_ctrl_remove_cred(wpa_s
, prev
);
3081 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3082 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3084 cred
= wpa_s
->conf
->cred
;
3088 if (prev
->provisioning_sp
&&
3089 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3090 wpas_ctrl_remove_cred(wpa_s
, prev
);
3096 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3098 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3099 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3103 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3107 struct wpa_cred
*cred
;
3110 /* cmd: "<cred id> <variable name> <value>" */
3111 name
= os_strchr(cmd
, ' ');
3116 value
= os_strchr(name
, ' ');
3122 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3124 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3125 (u8
*) value
, os_strlen(value
));
3127 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3129 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3134 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3135 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3136 "variable '%s'", name
);
3140 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3146 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3147 char *cmd
, char *buf
,
3152 struct wpa_cred
*cred
;
3155 /* cmd: "<cred id> <variable name>" */
3156 name
= os_strchr(cmd
, ' ');
3162 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3165 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3167 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3172 value
= wpa_config_get_cred_no_key(cred
, name
);
3173 if (value
== NULL
) {
3174 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3179 res
= os_strlcpy(buf
, value
, buflen
);
3180 if (res
>= buflen
) {
3191 #ifndef CONFIG_NO_CONFIG_WRITE
3192 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3196 if (!wpa_s
->conf
->update_config
) {
3197 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3198 "to update configuration (update_config=0)");
3202 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3204 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3205 "update configuration");
3207 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3213 #endif /* CONFIG_NO_CONFIG_WRITE */
3216 struct cipher_info
{
3222 static const struct cipher_info ciphers
[] = {
3223 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3224 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3225 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3226 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3227 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3228 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3229 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3230 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3234 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3235 struct wpa_driver_capa
*capa
,
3236 char *buf
, size_t buflen
)
3249 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3255 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3256 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3257 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3258 pos
== buf
? "" : " ",
3260 if (os_snprintf_error(end
- pos
, ret
))
3270 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3271 struct wpa_driver_capa
*capa
,
3272 char *buf
, size_t buflen
)
3285 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3291 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3292 if (capa
->enc
& ciphers
[i
].capa
) {
3293 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3294 pos
== buf
? "" : " ",
3296 if (os_snprintf_error(end
- pos
, ret
))
3306 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3307 struct wpa_driver_capa
*capa
,
3308 char *buf
, size_t buflen
)
3320 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3327 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3328 if (os_snprintf_error(end
- pos
, ret
))
3332 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3333 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3334 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3335 if (os_snprintf_error(end
- pos
, ret
))
3340 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3341 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3342 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3343 if (os_snprintf_error(end
- pos
, ret
))
3348 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3349 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3350 if (os_snprintf_error(end
- pos
, ret
))
3359 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3360 struct wpa_driver_capa
*capa
,
3361 char *buf
, size_t buflen
)
3373 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3379 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3380 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3381 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3382 pos
== buf
? "" : " ");
3383 if (os_snprintf_error(end
- pos
, ret
))
3388 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3389 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3390 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3391 pos
== buf
? "" : " ");
3392 if (os_snprintf_error(end
- pos
, ret
))
3401 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
3402 struct wpa_driver_capa
*capa
,
3403 char *buf
, size_t buflen
)
3415 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3421 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3422 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3423 pos
== buf
? "" : " ");
3424 if (os_snprintf_error(end
- pos
, ret
))
3429 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3430 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3431 pos
== buf
? "" : " ");
3432 if (os_snprintf_error(end
- pos
, ret
))
3437 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3438 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3439 pos
== buf
? "" : " ");
3440 if (os_snprintf_error(end
- pos
, ret
))
3449 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3450 struct wpa_driver_capa
*capa
,
3451 char *buf
, size_t buflen
)
3463 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3469 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3470 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3471 pos
== buf
? "" : " ");
3472 if (os_snprintf_error(end
- pos
, ret
))
3477 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3478 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3479 pos
== buf
? "" : " ");
3480 if (os_snprintf_error(end
- pos
, ret
))
3489 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3490 char *buf
, size_t buflen
)
3492 struct hostapd_channel_data
*chnl
;
3494 char *pos
, *end
, *hmode
;
3499 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3500 switch (wpa_s
->hw
.modes
[j
].mode
) {
3501 case HOSTAPD_MODE_IEEE80211B
:
3504 case HOSTAPD_MODE_IEEE80211G
:
3507 case HOSTAPD_MODE_IEEE80211A
:
3510 case HOSTAPD_MODE_IEEE80211AD
:
3516 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3517 if (os_snprintf_error(end
- pos
, ret
))
3520 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3521 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3522 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3524 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3525 if (os_snprintf_error(end
- pos
, ret
))
3529 ret
= os_snprintf(pos
, end
- pos
, "\n");
3530 if (os_snprintf_error(end
- pos
, ret
))
3539 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3540 char *buf
, size_t buflen
)
3542 struct hostapd_channel_data
*chnl
;
3544 char *pos
, *end
, *hmode
;
3549 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3550 switch (wpa_s
->hw
.modes
[j
].mode
) {
3551 case HOSTAPD_MODE_IEEE80211B
:
3554 case HOSTAPD_MODE_IEEE80211G
:
3557 case HOSTAPD_MODE_IEEE80211A
:
3560 case HOSTAPD_MODE_IEEE80211AD
:
3566 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3568 if (os_snprintf_error(end
- pos
, ret
))
3571 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3572 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3573 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3575 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
3576 chnl
[i
].chan
, chnl
[i
].freq
,
3577 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
3579 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
3582 if (os_snprintf_error(end
- pos
, ret
))
3586 ret
= os_snprintf(pos
, end
- pos
, "\n");
3587 if (os_snprintf_error(end
- pos
, ret
))
3596 static int wpa_supplicant_ctrl_iface_get_capability(
3597 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3600 struct wpa_driver_capa capa
;
3606 /* Determine whether or not strict checking was requested */
3607 len
= os_strlcpy(field
, _field
, sizeof(field
));
3608 if (len
>= sizeof(field
))
3610 strict
= os_strchr(field
, ' ');
3611 if (strict
!= NULL
) {
3613 if (os_strcmp(strict
, "strict") != 0)
3617 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3618 field
, strict
? strict
: "");
3620 if (os_strcmp(field
, "eap") == 0) {
3621 return eap_get_names(buf
, buflen
);
3624 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3626 if (os_strcmp(field
, "pairwise") == 0)
3627 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3630 if (os_strcmp(field
, "group") == 0)
3631 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3634 if (os_strcmp(field
, "key_mgmt") == 0)
3635 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3638 if (os_strcmp(field
, "proto") == 0)
3639 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3642 if (os_strcmp(field
, "auth_alg") == 0)
3643 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3646 if (os_strcmp(field
, "modes") == 0)
3647 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3650 if (os_strcmp(field
, "channels") == 0)
3651 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3653 if (os_strcmp(field
, "freq") == 0)
3654 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3657 if (os_strcmp(field
, "tdls") == 0)
3658 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
3659 #endif /* CONFIG_TDLS */
3662 if (os_strcmp(field
, "erp") == 0) {
3663 res
= os_snprintf(buf
, buflen
, "ERP");
3664 if (os_snprintf_error(buflen
, res
))
3668 #endif /* CONFIG_EPR */
3670 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3677 #ifdef CONFIG_INTERWORKING
3678 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3679 struct wpabuf
*data
)
3689 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3690 if (os_snprintf_error(end
- pos
, ret
))
3694 d
= wpabuf_head_u8(data
);
3695 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3696 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3697 if (os_snprintf_error(end
- pos
, ret
))
3702 ret
= os_snprintf(pos
, end
- pos
, "\n");
3703 if (os_snprintf_error(end
- pos
, ret
))
3709 #endif /* CONFIG_INTERWORKING */
3712 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3713 unsigned long mask
, char *buf
, size_t buflen
)
3723 if (mask
& WPA_BSS_MASK_ID
) {
3724 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3725 if (os_snprintf_error(end
- pos
, ret
))
3730 if (mask
& WPA_BSS_MASK_BSSID
) {
3731 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3732 MAC2STR(bss
->bssid
));
3733 if (os_snprintf_error(end
- pos
, ret
))
3738 if (mask
& WPA_BSS_MASK_FREQ
) {
3739 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3740 if (os_snprintf_error(end
- pos
, ret
))
3745 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3746 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3748 if (os_snprintf_error(end
- pos
, ret
))
3753 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3754 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3756 if (os_snprintf_error(end
- pos
, ret
))
3761 if (mask
& WPA_BSS_MASK_QUAL
) {
3762 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3763 if (os_snprintf_error(end
- pos
, ret
))
3768 if (mask
& WPA_BSS_MASK_NOISE
) {
3769 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3770 if (os_snprintf_error(end
- pos
, ret
))
3775 if (mask
& WPA_BSS_MASK_LEVEL
) {
3776 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3777 if (os_snprintf_error(end
- pos
, ret
))
3782 if (mask
& WPA_BSS_MASK_TSF
) {
3783 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3784 (unsigned long long) bss
->tsf
);
3785 if (os_snprintf_error(end
- pos
, ret
))
3790 if (mask
& WPA_BSS_MASK_AGE
) {
3791 struct os_reltime now
;
3793 os_get_reltime(&now
);
3794 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3795 (int) (now
.sec
- bss
->last_update
.sec
));
3796 if (os_snprintf_error(end
- pos
, ret
))
3801 if (mask
& WPA_BSS_MASK_IE
) {
3802 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3803 if (os_snprintf_error(end
- pos
, ret
))
3807 ie
= (const u8
*) (bss
+ 1);
3808 for (i
= 0; i
< bss
->ie_len
; i
++) {
3809 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3810 if (os_snprintf_error(end
- pos
, ret
))
3815 ret
= os_snprintf(pos
, end
- pos
, "\n");
3816 if (os_snprintf_error(end
- pos
, ret
))
3821 if (mask
& WPA_BSS_MASK_FLAGS
) {
3822 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3823 if (os_snprintf_error(end
- pos
, ret
))
3827 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3829 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3831 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3833 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3835 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3836 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3837 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3838 if (os_snprintf_error(end
- pos
, ret
))
3842 if (bss_is_dmg(bss
)) {
3844 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
3845 if (os_snprintf_error(end
- pos
, ret
))
3848 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
3849 case IEEE80211_CAP_DMG_IBSS
:
3852 case IEEE80211_CAP_DMG_AP
:
3855 case IEEE80211_CAP_DMG_PBSS
:
3862 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
3863 if (os_snprintf_error(end
- pos
, ret
))
3867 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3868 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3869 if (os_snprintf_error(end
- pos
, ret
))
3873 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3874 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3875 if (os_snprintf_error(end
- pos
, ret
))
3880 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3881 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3882 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3883 if (os_snprintf_error(end
- pos
, ret
))
3888 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3889 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3890 if (os_snprintf_error(end
- pos
, ret
))
3894 #endif /* CONFIG_HS20 */
3896 ret
= os_snprintf(pos
, end
- pos
, "\n");
3897 if (os_snprintf_error(end
- pos
, ret
))
3902 if (mask
& WPA_BSS_MASK_SSID
) {
3903 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3904 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3905 if (os_snprintf_error(end
- pos
, ret
))
3911 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3912 ie
= (const u8
*) (bss
+ 1);
3913 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3914 if (ret
< 0 || ret
>= end
- pos
)
3918 #endif /* CONFIG_WPS */
3921 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3922 ie
= (const u8
*) (bss
+ 1);
3923 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3924 if (ret
< 0 || ret
>= end
- pos
)
3928 #endif /* CONFIG_P2P */
3930 #ifdef CONFIG_WIFI_DISPLAY
3931 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3933 ie
= (const u8
*) (bss
+ 1);
3934 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3935 WFD_IE_VENDOR_TYPE
);
3937 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3938 if (os_snprintf_error(end
- pos
, ret
)) {
3944 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3949 ret
= os_snprintf(pos
, end
- pos
, "\n");
3950 if (os_snprintf_error(end
- pos
, ret
))
3955 #endif /* CONFIG_WIFI_DISPLAY */
3957 #ifdef CONFIG_INTERWORKING
3958 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3959 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3960 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3962 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3963 anqp
->network_auth_type
);
3964 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3965 anqp
->roaming_consortium
);
3966 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3967 anqp
->ip_addr_type_availability
);
3968 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3970 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3971 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3974 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3975 anqp
->hs20_operator_friendly_name
);
3976 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3977 anqp
->hs20_wan_metrics
);
3978 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3979 anqp
->hs20_connection_capability
);
3980 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
3981 anqp
->hs20_operating_class
);
3982 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
3983 anqp
->hs20_osu_providers_list
);
3984 #endif /* CONFIG_HS20 */
3986 #endif /* CONFIG_INTERWORKING */
3989 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
3990 ie
= (const u8
*) (bss
+ 1);
3991 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3992 if (ret
< 0 || ret
>= end
- pos
)
3996 #endif /* CONFIG_MESH */
3998 if (mask
& WPA_BSS_MASK_DELIM
) {
3999 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4000 if (os_snprintf_error(end
- pos
, ret
))
4009 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4010 const char *cmd
, char *buf
,
4015 struct wpa_bss
*bss
;
4016 struct wpa_bss
*bsslast
= NULL
;
4017 struct dl_list
*next
;
4020 char *ctmp
, *end
= buf
+ buflen
;
4021 unsigned long mask
= WPA_BSS_MASK_ALL
;
4023 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4024 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4025 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4027 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4029 } else { /* N1-N2 */
4030 unsigned int id1
, id2
;
4032 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4033 wpa_printf(MSG_INFO
, "Wrong BSS range "
4038 if (*(cmd
+ 6) == '-')
4041 id1
= atoi(cmd
+ 6);
4043 if (*ctmp
>= '0' && *ctmp
<= '9')
4046 id2
= (unsigned int) -1;
4047 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4048 if (id2
== (unsigned int) -1)
4049 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4053 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4054 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4055 struct wpa_bss
*tmp
= bss
;
4057 next
= tmp
->list_id
.next
;
4058 if (next
== &wpa_s
->bss_id
)
4060 tmp
= dl_list_entry(
4061 next
, struct wpa_bss
,
4070 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4071 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4072 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4073 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4074 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4076 bss
= wpa_bss_get_id(wpa_s
, i
);
4077 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4079 bss
= wpa_bss_get_id(wpa_s
, i
);
4081 next
= bss
->list_id
.next
;
4082 if (next
== &wpa_s
->bss_id
)
4085 bss
= dl_list_entry(next
, struct wpa_bss
,
4089 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4090 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4091 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4094 #endif /* CONFIG_P2P */
4095 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4096 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4098 struct wpa_bss
*tmp
;
4101 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4110 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4111 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4113 mask
= WPA_BSS_MASK_ALL
;
4119 if (bsslast
== NULL
)
4122 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4126 if (bss
== bsslast
) {
4127 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4128 (bss
== dl_list_last(&wpa_s
->bss_id
,
4129 struct wpa_bss
, list_id
))) {
4132 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4134 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4135 wpa_printf(MSG_DEBUG
,
4136 "Could not add end delim");
4141 next
= bss
->list_id
.next
;
4142 if (next
== &wpa_s
->bss_id
)
4144 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4145 } while (bss
&& len
);
4151 static int wpa_supplicant_ctrl_iface_ap_scan(
4152 struct wpa_supplicant
*wpa_s
, char *cmd
)
4154 int ap_scan
= atoi(cmd
);
4155 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4159 static int wpa_supplicant_ctrl_iface_scan_interval(
4160 struct wpa_supplicant
*wpa_s
, char *cmd
)
4162 int scan_int
= atoi(cmd
);
4163 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4167 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4168 struct wpa_supplicant
*wpa_s
, char *cmd
)
4170 int expire_age
= atoi(cmd
);
4171 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4175 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4176 struct wpa_supplicant
*wpa_s
, char *cmd
)
4178 int expire_count
= atoi(cmd
);
4179 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4183 static void wpa_supplicant_ctrl_iface_bss_flush(
4184 struct wpa_supplicant
*wpa_s
, char *cmd
)
4186 int flush_age
= atoi(cmd
);
4189 wpa_bss_flush(wpa_s
);
4191 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4195 #ifdef CONFIG_TESTING_OPTIONS
4196 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4198 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4199 /* MLME-DELETEKEYS.request */
4200 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4201 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4202 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4203 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4204 #ifdef CONFIG_IEEE80211W
4205 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4206 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4207 #endif /* CONFIG_IEEE80211W */
4209 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4211 /* MLME-SETPROTECTION.request(None) */
4212 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4213 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4214 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4215 wpa_sm_drop_sa(wpa_s
->wpa
);
4217 #endif /* CONFIG_TESTING_OPTIONS */
4220 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4223 #ifdef CONFIG_NO_SCAN_PROCESSING
4225 #else /* CONFIG_NO_SCAN_PROCESSING */
4227 struct wpa_bss
*bss
;
4228 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4230 if (hwaddr_aton(addr
, bssid
)) {
4231 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4232 "address '%s'", addr
);
4236 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4239 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4240 "configuration known for the target AP");
4244 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4246 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4252 * TODO: Find best network configuration block from configuration to
4253 * allow roaming to other networks
4256 wpa_s
->reassociate
= 1;
4257 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4260 #endif /* CONFIG_NO_SCAN_PROCESSING */
4265 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
4267 unsigned int timeout
= atoi(cmd
);
4268 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
4269 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
4270 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
4272 unsigned int search_delay
;
4274 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4275 wpa_dbg(wpa_s
, MSG_INFO
,
4276 "Reject P2P_FIND since interface is disabled");
4279 if (os_strstr(cmd
, "type=social"))
4280 type
= P2P_FIND_ONLY_SOCIAL
;
4281 else if (os_strstr(cmd
, "type=progressive"))
4282 type
= P2P_FIND_PROGRESSIVE
;
4284 pos
= os_strstr(cmd
, "dev_id=");
4287 if (hwaddr_aton(pos
, dev_id
))
4292 pos
= os_strstr(cmd
, "dev_type=");
4295 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
4297 _dev_type
= dev_type
;
4300 pos
= os_strstr(cmd
, "delay=");
4303 search_delay
= atoi(pos
);
4305 search_delay
= wpas_p2p_search_delay(wpa_s
);
4307 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
4308 _dev_id
, search_delay
);
4312 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
4313 char *buf
, size_t buflen
)
4318 enum p2p_wps_method wps_method
;
4321 int persistent_group
, persistent_id
= -1;
4330 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4331 * [persistent|persistent=<network id>]
4332 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4335 if (hwaddr_aton(cmd
, addr
))
4343 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
4344 pos2
= os_strstr(pos
, " persistent=");
4346 struct wpa_ssid
*ssid
;
4347 persistent_id
= atoi(pos2
+ 12);
4348 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
4349 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
4350 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
4351 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
4352 "SSID id=%d for persistent P2P group (GO)",
4357 join
= os_strstr(pos
, " join") != NULL
;
4358 auth
= os_strstr(pos
, " auth") != NULL
;
4359 automatic
= os_strstr(pos
, " auto") != NULL
;
4360 pd
= os_strstr(pos
, " provdisc") != NULL
;
4361 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4362 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4365 pos2
= os_strstr(pos
, " go_intent=");
4368 go_intent
= atoi(pos2
);
4369 if (go_intent
< 0 || go_intent
> 15)
4373 pos2
= os_strstr(pos
, " freq=");
4381 if (os_strncmp(pos
, "pin", 3) == 0) {
4382 /* Request random PIN (to be displayed) and enable the PIN */
4383 wps_method
= WPS_PIN_DISPLAY
;
4384 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
4385 wps_method
= WPS_PBC
;
4388 pos
= os_strchr(pin
, ' ');
4389 wps_method
= WPS_PIN_KEYPAD
;
4392 if (os_strncmp(pos
, "display", 7) == 0)
4393 wps_method
= WPS_PIN_DISPLAY
;
4395 if (!wps_pin_str_valid(pin
)) {
4396 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
4401 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
4402 persistent_group
, automatic
, join
,
4403 auth
, go_intent
, freq
, persistent_id
, pd
,
4405 if (new_pin
== -2) {
4406 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4409 if (new_pin
== -3) {
4410 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4415 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
4416 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
4417 if (os_snprintf_error(buflen
, ret
))
4422 os_memcpy(buf
, "OK\n", 3);
4427 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4429 unsigned int timeout
= atoi(cmd
);
4430 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4431 wpa_dbg(wpa_s
, MSG_INFO
,
4432 "Reject P2P_LISTEN since interface is disabled");
4435 return wpas_p2p_listen(wpa_s
, timeout
);
4439 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
4443 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
4445 /* <addr> <config method> [join|auto] */
4447 if (hwaddr_aton(cmd
, addr
))
4455 if (os_strstr(pos
, " join") != NULL
)
4456 use
= WPAS_P2P_PD_FOR_JOIN
;
4457 else if (os_strstr(pos
, " auto") != NULL
)
4458 use
= WPAS_P2P_PD_AUTO
;
4460 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
4464 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
4467 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4469 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
4470 ssid
->passphrase
== NULL
)
4473 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
4474 return os_strlen(buf
);
4478 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
4479 char *buf
, size_t buflen
)
4483 u8 dst_buf
[ETH_ALEN
], *dst
;
4484 struct wpabuf
*tlvs
;
4488 if (hwaddr_aton(cmd
, dst_buf
))
4491 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
4492 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
4499 if (os_strncmp(pos
, "upnp ", 5) == 0) {
4502 if (hexstr2bin(pos
, &version
, 1) < 0)
4508 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
4509 #ifdef CONFIG_WIFI_DISPLAY
4510 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
4511 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
4512 #endif /* CONFIG_WIFI_DISPLAY */
4514 len
= os_strlen(pos
);
4518 tlvs
= wpabuf_alloc(len
);
4521 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
4526 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
4531 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
4532 if (os_snprintf_error(buflen
, res
))
4538 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
4541 long long unsigned val
;
4543 if (sscanf(cmd
, "%llx", &val
) != 1)
4546 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
4550 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4555 struct wpabuf
*resp_tlvs
;
4559 pos
= os_strchr(cmd
, ' ');
4567 if (hwaddr_aton(pos
, dst
))
4574 pos2
= os_strchr(pos
, ' ');
4578 dialog_token
= atoi(pos
);
4580 len
= os_strlen(pos2
);
4584 resp_tlvs
= wpabuf_alloc(len
);
4585 if (resp_tlvs
== NULL
)
4587 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
4588 wpabuf_free(resp_tlvs
);
4592 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
4593 wpabuf_free(resp_tlvs
);
4598 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
4601 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
4603 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
4608 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
4613 struct wpabuf
*query
, *resp
;
4615 pos
= os_strchr(cmd
, ' ');
4620 len
= os_strlen(cmd
);
4624 query
= wpabuf_alloc(len
);
4627 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4632 len
= os_strlen(pos
);
4638 resp
= wpabuf_alloc(len
);
4643 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4649 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4658 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4663 pos
= os_strchr(cmd
, ' ');
4668 if (hexstr2bin(cmd
, &version
, 1) < 0)
4671 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4675 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4679 pos
= os_strchr(cmd
, ' ');
4684 if (os_strcmp(cmd
, "bonjour") == 0)
4685 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4686 if (os_strcmp(cmd
, "upnp") == 0)
4687 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4688 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4693 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4697 struct wpabuf
*query
;
4700 len
= os_strlen(cmd
);
4704 query
= wpabuf_alloc(len
);
4707 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4712 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4718 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4723 pos
= os_strchr(cmd
, ' ');
4728 if (hexstr2bin(cmd
, &version
, 1) < 0)
4731 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4735 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4739 pos
= os_strchr(cmd
, ' ');
4744 if (os_strcmp(cmd
, "bonjour") == 0)
4745 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4746 if (os_strcmp(cmd
, "upnp") == 0)
4747 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4748 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4753 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4759 if (hwaddr_aton(cmd
, addr
))
4762 return wpas_p2p_reject(wpa_s
, addr
);
4766 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4770 struct wpa_ssid
*ssid
;
4771 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4772 int freq
= 0, pref_freq
= 0;
4776 pos
= os_strstr(cmd
, " peer=");
4779 if (hwaddr_aton(pos
, peer
))
4783 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4784 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4785 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4786 "for persistent P2P group",
4791 pos
= os_strstr(cmd
, " freq=");
4799 pos
= os_strstr(cmd
, " pref=");
4802 pref_freq
= atoi(pos
);
4807 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4808 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4811 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4816 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4819 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4821 pos
= os_strstr(cmd
, " peer=");
4827 if (hwaddr_aton(pos
, peer
)) {
4828 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4832 pos
= os_strstr(pos
, " go_dev_addr=");
4835 if (hwaddr_aton(pos
, go_dev_addr
)) {
4836 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4840 go_dev
= go_dev_addr
;
4843 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4847 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4849 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4850 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4851 if (os_strncmp(cmd
, "group=", 6) == 0)
4852 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4858 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4859 char *cmd
, int freq
, int ht40
,
4863 struct wpa_ssid
*ssid
;
4866 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4867 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4868 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4869 "for persistent P2P group",
4874 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, 0, ht40
, vht
,
4879 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4881 int freq
= 0, ht40
, vht
;
4884 pos
= os_strstr(cmd
, "freq=");
4886 freq
= atoi(pos
+ 5);
4888 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4889 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4892 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4893 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4895 if (os_strcmp(cmd
, "persistent") == 0 ||
4896 os_strncmp(cmd
, "persistent ", 11) == 0)
4897 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4898 if (os_strncmp(cmd
, "freq=", 5) == 0)
4899 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4901 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4903 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4909 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4910 char *buf
, size_t buflen
)
4912 u8 addr
[ETH_ALEN
], *addr_ptr
;
4914 const struct p2p_peer_info
*info
;
4916 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4917 struct wpa_ssid
*ssid
;
4920 if (!wpa_s
->global
->p2p
)
4923 if (os_strcmp(cmd
, "FIRST") == 0) {
4926 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4927 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4932 if (hwaddr_aton(cmd
, addr
) < 0)
4938 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4945 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4951 "serial_number=%s\n"
4952 "config_methods=0x%x\n"
4954 "group_capab=0x%x\n"
4956 MAC2STR(info
->p2p_device_addr
),
4957 wps_dev_type_bin2str(info
->pri_dev_type
,
4958 devtype
, sizeof(devtype
)),
4963 info
->serial_number
,
4964 info
->config_methods
,
4968 if (os_snprintf_error(end
- pos
, res
))
4972 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4975 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4976 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4977 wps_dev_type_bin2str(t
, devtype
,
4979 if (os_snprintf_error(end
- pos
, res
))
4984 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4986 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4987 if (os_snprintf_error(end
- pos
, res
))
4992 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4997 if (info
->vendor_elems
) {
4998 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
4999 if (os_snprintf_error(end
- pos
, res
))
5003 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
5004 wpabuf_head(info
->vendor_elems
),
5005 wpabuf_len(info
->vendor_elems
));
5007 res
= os_snprintf(pos
, end
- pos
, "\n");
5008 if (os_snprintf_error(end
- pos
, res
))
5017 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
5022 if (wpa_s
->global
->p2p
== NULL
)
5025 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
5028 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
5029 struct wpa_freq_range
*freq
;
5030 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
5031 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
5032 freq
->min
, freq
->max
);
5035 wpas_p2p_update_channel_list(wpa_s
);
5040 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
5044 if (wpa_s
->global
->p2p
== NULL
)
5047 param
= os_strchr(cmd
, ' ');
5052 if (os_strcmp(cmd
, "discoverability") == 0) {
5053 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
5058 if (os_strcmp(cmd
, "managed") == 0) {
5059 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
5063 if (os_strcmp(cmd
, "listen_channel") == 0) {
5064 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
5068 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
5069 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
5073 if (os_strcmp(cmd
, "noa") == 0) {
5075 int count
, start
, duration
;
5076 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
5077 count
= atoi(param
);
5078 pos
= os_strchr(param
, ',');
5083 pos
= os_strchr(pos
, ',');
5087 duration
= atoi(pos
);
5088 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
5090 if (count
== 0 && duration
> 0)
5092 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
5093 "start=%d duration=%d", count
, start
, duration
);
5094 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
5097 if (os_strcmp(cmd
, "ps") == 0)
5098 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
5100 if (os_strcmp(cmd
, "oppps") == 0)
5101 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
5103 if (os_strcmp(cmd
, "ctwindow") == 0)
5104 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
5106 if (os_strcmp(cmd
, "disabled") == 0) {
5107 wpa_s
->global
->p2p_disabled
= atoi(param
);
5108 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
5109 wpa_s
->global
->p2p_disabled
?
5110 "disabled" : "enabled");
5111 if (wpa_s
->global
->p2p_disabled
) {
5112 wpas_p2p_stop_find(wpa_s
);
5113 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5114 p2p_flush(wpa_s
->global
->p2p
);
5119 if (os_strcmp(cmd
, "conc_pref") == 0) {
5120 if (os_strcmp(param
, "sta") == 0)
5121 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
5122 else if (os_strcmp(param
, "p2p") == 0)
5123 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
5125 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
5128 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
5133 if (os_strcmp(cmd
, "force_long_sd") == 0) {
5134 wpa_s
->force_long_sd
= atoi(param
);
5138 if (os_strcmp(cmd
, "peer_filter") == 0) {
5140 if (hwaddr_aton(param
, addr
))
5142 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
5146 if (os_strcmp(cmd
, "cross_connect") == 0)
5147 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
5149 if (os_strcmp(cmd
, "go_apsd") == 0) {
5150 if (os_strcmp(param
, "disable") == 0)
5151 wpa_s
->set_ap_uapsd
= 0;
5153 wpa_s
->set_ap_uapsd
= 1;
5154 wpa_s
->ap_uapsd
= atoi(param
);
5159 if (os_strcmp(cmd
, "client_apsd") == 0) {
5160 if (os_strcmp(param
, "disable") == 0)
5161 wpa_s
->set_sta_uapsd
= 0;
5165 /* format: BE,BK,VI,VO;max SP Length */
5167 pos
= os_strchr(param
, ',');
5172 pos
= os_strchr(pos
, ',');
5177 pos
= os_strchr(pos
, ',');
5182 /* ignore max SP Length for now */
5184 wpa_s
->set_sta_uapsd
= 1;
5185 wpa_s
->sta_uapsd
= 0;
5187 wpa_s
->sta_uapsd
|= BIT(0);
5189 wpa_s
->sta_uapsd
|= BIT(1);
5191 wpa_s
->sta_uapsd
|= BIT(2);
5193 wpa_s
->sta_uapsd
|= BIT(3);
5198 if (os_strcmp(cmd
, "disallow_freq") == 0)
5199 return p2p_ctrl_disallow_freq(wpa_s
, param
);
5201 if (os_strcmp(cmd
, "disc_int") == 0) {
5202 int min_disc_int
, max_disc_int
, max_disc_tu
;
5207 min_disc_int
= atoi(pos
);
5208 pos
= os_strchr(pos
, ' ');
5213 max_disc_int
= atoi(pos
);
5214 pos
= os_strchr(pos
, ' ');
5219 max_disc_tu
= atoi(pos
);
5221 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
5222 max_disc_int
, max_disc_tu
);
5225 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
5226 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
5230 #ifdef CONFIG_WPS_NFC
5231 if (os_strcmp(cmd
, "nfc_tag") == 0)
5232 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
5233 #endif /* CONFIG_WPS_NFC */
5235 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
5236 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
5240 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5247 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
5249 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5250 wpa_s
->force_long_sd
= 0;
5251 wpas_p2p_stop_find(wpa_s
);
5252 if (wpa_s
->global
->p2p
)
5253 p2p_flush(wpa_s
->global
->p2p
);
5257 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
5260 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
5263 pos
= os_strchr(cmd
, ' ');
5269 pos2
= os_strchr(pos
, ' ');
5277 pos
= os_strchr(pos2
, ' ');
5285 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
5289 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5292 unsigned int period
= 0, interval
= 0;
5295 pos
= os_strchr(cmd
, ' ');
5300 interval
= atoi(pos
);
5303 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
5307 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
5314 if (os_strncmp(pos
, "iface=", 6) == 0) {
5318 if (hwaddr_aton(pos
, peer
))
5321 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
5325 #endif /* CONFIG_P2P */
5328 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
5330 struct wpa_freq_range_list ranges
;
5332 struct hostapd_hw_modes
*mode
;
5335 if (wpa_s
->hw
.modes
== NULL
)
5338 os_memset(&ranges
, 0, sizeof(ranges
));
5339 if (freq_range_list_parse(&ranges
, val
) < 0)
5342 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
5345 mode
= &wpa_s
->hw
.modes
[i
];
5346 for (j
= 0; j
< mode
->num_channels
; j
++) {
5349 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
5352 freq
= mode
->channels
[j
].freq
;
5353 if (!freq_range_list_includes(&ranges
, freq
))
5356 int_array_add_unique(&freqs
, freq
);
5360 os_free(ranges
.range
);
5365 #ifdef CONFIG_INTERWORKING
5367 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
5375 auto_sel
= os_strstr(param
, "auto") != NULL
;
5377 pos
= os_strstr(param
, "freq=");
5379 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
5386 return interworking_select(wpa_s
, auto_sel
, freqs
);
5390 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
5393 struct wpa_bss
*bss
;
5395 if (hwaddr_aton(dst
, bssid
)) {
5396 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
5400 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5402 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
5407 return interworking_connect(wpa_s
, bss
);
5411 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5413 u8 dst_addr
[ETH_ALEN
];
5416 #define MAX_ANQP_INFO_ID 100
5417 u16 id
[MAX_ANQP_INFO_ID
];
5421 used
= hwaddr_aton2(dst
, dst_addr
);
5427 while (num_id
< MAX_ANQP_INFO_ID
) {
5428 if (os_strncmp(pos
, "hs20:", 5) == 0) {
5430 int num
= atoi(pos
+ 5);
5431 if (num
<= 0 || num
> 31)
5433 subtypes
|= BIT(num
);
5434 #else /* CONFIG_HS20 */
5436 #endif /* CONFIG_HS20 */
5438 id
[num_id
] = atoi(pos
);
5442 pos
= os_strchr(pos
+ 1, ',');
5451 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
);
5455 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5457 u8 dst_addr
[ETH_ALEN
];
5458 struct wpabuf
*advproto
, *query
= NULL
;
5463 used
= hwaddr_aton2(cmd
, dst_addr
);
5471 /* Advertisement Protocol ID */
5472 end
= os_strchr(pos
, ' ');
5476 len
= os_strlen(pos
);
5482 advproto
= wpabuf_alloc(len
);
5483 if (advproto
== NULL
)
5485 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
5489 /* Optional Query Request */
5494 len
= os_strlen(pos
);
5501 query
= wpabuf_alloc(len
);
5504 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
5509 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
5512 wpabuf_free(advproto
);
5519 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
5526 size_t resp_len
, start
, requested_len
;
5527 struct wpabuf
*resp
;
5530 used
= hwaddr_aton2(cmd
, addr
);
5537 dialog_token
= atoi(pos
);
5539 if (wpa_s
->last_gas_resp
&&
5540 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
5541 dialog_token
== wpa_s
->last_gas_dialog_token
)
5542 resp
= wpa_s
->last_gas_resp
;
5543 else if (wpa_s
->prev_gas_resp
&&
5544 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
5545 dialog_token
== wpa_s
->prev_gas_dialog_token
)
5546 resp
= wpa_s
->prev_gas_resp
;
5550 resp_len
= wpabuf_len(resp
);
5552 requested_len
= resp_len
;
5554 pos
= os_strchr(pos
, ' ');
5557 if (start
> resp_len
)
5558 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5559 pos
= os_strchr(pos
, ',');
5563 requested_len
= atoi(pos
);
5564 if (start
+ requested_len
> resp_len
)
5565 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5568 if (requested_len
* 2 + 1 > buflen
)
5569 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
5571 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
5574 if (start
+ requested_len
== resp_len
) {
5576 * Free memory by dropping the response after it has been
5579 if (resp
== wpa_s
->prev_gas_resp
) {
5580 wpabuf_free(wpa_s
->prev_gas_resp
);
5581 wpa_s
->prev_gas_resp
= NULL
;
5583 wpabuf_free(wpa_s
->last_gas_resp
);
5584 wpa_s
->last_gas_resp
= NULL
;
5590 #endif /* CONFIG_INTERWORKING */
5595 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5597 u8 dst_addr
[ETH_ALEN
];
5602 used
= hwaddr_aton2(dst
, dst_addr
);
5609 int num
= atoi(pos
);
5610 if (num
<= 0 || num
> 31)
5612 subtypes
|= BIT(num
);
5613 pos
= os_strchr(pos
+ 1, ',');
5622 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
5626 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5627 const u8
*addr
, const char *realm
)
5633 rlen
= os_strlen(realm
);
5635 buf
= os_malloc(len
);
5638 buf
[0] = 1; /* NAI Home Realm Count */
5639 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
5641 os_memcpy(buf
+ 3, realm
, rlen
);
5643 ret
= hs20_anqp_send_req(wpa_s
, addr
,
5644 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5653 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5656 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
5657 u8 dst_addr
[ETH_ALEN
];
5663 used
= hwaddr_aton2(dst
, dst_addr
);
5667 while (dst
[used
] == ' ')
5669 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
5670 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
5673 len
= os_strlen(dst
+ used
);
5675 if (len
== 0 && cred
&& cred
->realm
)
5676 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
5681 buf
= os_malloc(len
);
5684 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
5689 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
5690 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5698 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5700 u8 dst_addr
[ETH_ALEN
];
5704 used
= hwaddr_aton2(cmd
, dst_addr
);
5708 while (cmd
[used
] == ' ')
5712 wpa_s
->fetch_osu_icon_in_progress
= 0;
5713 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
5714 (u8
*) icon
, os_strlen(icon
));
5717 #endif /* CONFIG_HS20 */
5720 #ifdef CONFIG_AUTOSCAN
5722 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
5725 enum wpa_states state
= wpa_s
->wpa_state
;
5726 char *new_params
= NULL
;
5728 if (os_strlen(cmd
) > 0) {
5729 new_params
= os_strdup(cmd
);
5730 if (new_params
== NULL
)
5734 os_free(wpa_s
->conf
->autoscan
);
5735 wpa_s
->conf
->autoscan
= new_params
;
5737 if (wpa_s
->conf
->autoscan
== NULL
)
5738 autoscan_deinit(wpa_s
);
5739 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
5740 autoscan_init(wpa_s
, 1);
5741 else if (state
== WPA_SCANNING
)
5742 wpa_supplicant_reinit_autoscan(wpa_s
);
5747 #endif /* CONFIG_AUTOSCAN */
5752 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
5758 struct wpabuf
*tfs_req
= NULL
;
5760 if (os_strncmp(cmd
, "enter", 5) == 0)
5762 else if (os_strncmp(cmd
, "exit", 4) == 0)
5767 pos
= os_strstr(cmd
, " interval=");
5769 intval
= atoi(pos
+ 10);
5771 pos
= os_strstr(cmd
, " tfs_req=");
5776 end
= os_strchr(pos
, ' ');
5780 len
= os_strlen(pos
);
5784 tfs_req
= wpabuf_alloc(len
);
5785 if (tfs_req
== NULL
)
5787 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5788 wpabuf_free(tfs_req
);
5793 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5794 WNM_SLEEP_MODE_EXIT
, intval
,
5796 wpabuf_free(tfs_req
);
5802 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5806 query_reason
= atoi(cmd
);
5808 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5811 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5814 #endif /* CONFIG_WNM */
5817 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5820 struct wpa_signal_info si
;
5824 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5831 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5832 "NOISE=%d\nFREQUENCY=%u\n",
5833 si
.current_signal
, si
.current_txrate
/ 1000,
5834 si
.current_noise
, si
.frequency
);
5835 if (os_snprintf_error(end
- pos
, ret
))
5839 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5840 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5841 channel_width_to_string(si
.chanwidth
));
5842 if (os_snprintf_error(end
- pos
, ret
))
5847 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5848 ret
= os_snprintf(pos
, end
- pos
,
5849 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5850 si
.center_frq1
, si
.center_frq2
);
5851 if (os_snprintf_error(end
- pos
, ret
))
5856 if (si
.avg_signal
) {
5857 ret
= os_snprintf(pos
, end
- pos
,
5858 "AVG_RSSI=%d\n", si
.avg_signal
);
5859 if (os_snprintf_error(end
- pos
, ret
))
5868 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5871 struct hostap_sta_driver_data sta
;
5874 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5878 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5879 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5880 if (os_snprintf_error(buflen
, ret
))
5887 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5888 char *buf
, size_t buflen
)
5892 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5894 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5895 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5898 country
[0] = cmd
[8];
5899 country
[1] = cmd
[9];
5901 p2p_set_country(p2p
, country
);
5904 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5905 if (os_snprintf_error(buflen
, ret
))
5910 #endif /* ANDROID */
5913 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5914 char *buf
, size_t buflen
)
5919 unsigned int vendor_id
, subcmd
;
5920 struct wpabuf
*reply
;
5921 size_t data_len
= 0;
5923 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5924 vendor_id
= strtoul(cmd
, &pos
, 16);
5928 subcmd
= strtoul(pos
, &pos
, 10);
5931 if (!isblank(*pos
++))
5933 data_len
= os_strlen(pos
);
5938 data
= os_malloc(data_len
);
5942 if (hexstr2bin(pos
, data
, data_len
)) {
5943 wpa_printf(MSG_DEBUG
,
5944 "Vendor command: wrong parameter format");
5950 reply
= wpabuf_alloc((buflen
- 1) / 2);
5956 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
5960 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
5970 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5972 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5975 wpas_p2p_cancel(wpa_s
);
5976 wpas_p2p_stop_find(wpa_s
);
5977 p2p_ctrl_flush(wpa_s
);
5978 wpas_p2p_group_remove(wpa_s
, "*");
5979 wpas_p2p_service_flush(wpa_s
);
5980 wpa_s
->global
->p2p_disabled
= 0;
5981 wpa_s
->global
->p2p_per_sta_psk
= 0;
5982 wpa_s
->conf
->num_sec_device_types
= 0;
5983 wpa_s
->p2p_disable_ip_addr_req
= 0;
5984 os_free(wpa_s
->global
->p2p_go_avoid_freq
.range
);
5985 wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
5986 #endif /* CONFIG_P2P */
5988 #ifdef CONFIG_WPS_TESTING
5989 wps_version_number
= 0x20;
5990 wps_testing_dummy_cred
= 0;
5991 wps_corrupt_pkhash
= 0;
5992 #endif /* CONFIG_WPS_TESTING */
5994 wpa_s
->wps_fragment_size
= 0;
5995 wpas_wps_cancel(wpa_s
);
5996 wps_registrar_flush(wpa_s
->wps
->registrar
);
5997 #endif /* CONFIG_WPS */
5998 wpa_s
->after_wps
= 0;
5999 wpa_s
->known_wps_freq
= 0;
6002 #ifdef CONFIG_TDLS_TESTING
6003 extern unsigned int tdls_testing
;
6005 #endif /* CONFIG_TDLS_TESTING */
6006 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
6007 wpa_tdls_enable(wpa_s
->wpa
, 1);
6008 #endif /* CONFIG_TDLS */
6010 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
6011 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
6013 wpa_s
->no_keep_alive
= 0;
6015 os_free(wpa_s
->disallow_aps_bssid
);
6016 wpa_s
->disallow_aps_bssid
= NULL
;
6017 wpa_s
->disallow_aps_bssid_count
= 0;
6018 os_free(wpa_s
->disallow_aps_ssid
);
6019 wpa_s
->disallow_aps_ssid
= NULL
;
6020 wpa_s
->disallow_aps_ssid_count
= 0;
6022 wpa_s
->set_sta_uapsd
= 0;
6023 wpa_s
->sta_uapsd
= 0;
6025 wpa_drv_radio_disable(wpa_s
, 0);
6027 wpa_bss_flush(wpa_s
);
6028 wpa_blacklist_clear(wpa_s
);
6029 wpa_s
->extra_blacklist_count
= 0;
6030 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
6031 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
6032 wpa_config_flush_blobs(wpa_s
->conf
);
6033 wpa_s
->conf
->auto_interworking
= 0;
6034 wpa_s
->conf
->okc
= 0;
6036 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
6037 rsn_preauth_deinit(wpa_s
->wpa
);
6039 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
6040 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
6041 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
6042 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
6044 radio_remove_works(wpa_s
, NULL
, 1);
6045 wpa_s
->ext_work_in_progress
= 0;
6047 wpa_s
->next_ssid
= NULL
;
6049 #ifdef CONFIG_INTERWORKING
6050 hs20_cancel_fetch_osu(wpa_s
);
6051 #endif /* CONFIG_INTERWORKING */
6053 wpa_s
->ext_mgmt_frame_handling
= 0;
6054 wpa_s
->ext_eapol_frame_io
= 0;
6055 #ifdef CONFIG_TESTING_OPTIONS
6056 wpa_s
->extra_roc_dur
= 0;
6057 #endif /* CONFIG_TESTING_OPTIONS */
6059 wpa_s
->disconnected
= 0;
6060 os_free(wpa_s
->next_scan_freqs
);
6061 wpa_s
->next_scan_freqs
= NULL
;
6065 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
6066 char *buf
, size_t buflen
)
6068 struct wpa_radio_work
*work
;
6070 struct os_reltime now
, diff
;
6075 os_get_reltime(&now
);
6077 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
6081 os_reltime_sub(&now
, &work
->time
, &diff
);
6082 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
6083 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
6084 work
->started
, diff
.sec
, diff
.usec
);
6085 if (os_snprintf_error(end
- pos
, ret
))
6094 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
6096 struct wpa_radio_work
*work
= eloop_ctx
;
6097 struct wpa_external_work
*ework
= work
->ctx
;
6099 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
6100 "Timing out external radio work %u (%s)",
6101 ework
->id
, work
->type
);
6102 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
6103 work
->wpa_s
->ext_work_in_progress
= 0;
6104 radio_work_done(work
);
6109 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
6111 struct wpa_external_work
*ework
= work
->ctx
;
6115 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
6122 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
6123 ework
->id
, ework
->type
);
6124 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
6125 work
->wpa_s
->ext_work_in_progress
= 1;
6126 if (!ework
->timeout
)
6127 ework
->timeout
= 10;
6128 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
6133 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
6134 char *buf
, size_t buflen
)
6136 struct wpa_external_work
*ework
;
6140 unsigned int freq
= 0;
6142 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
6144 ework
= os_zalloc(sizeof(*ework
));
6148 pos
= os_strchr(cmd
, ' ');
6150 type_len
= pos
- cmd
;
6153 pos2
= os_strstr(pos
, "freq=");
6155 freq
= atoi(pos2
+ 5);
6157 pos2
= os_strstr(pos
, "timeout=");
6159 ework
->timeout
= atoi(pos2
+ 8);
6161 type_len
= os_strlen(cmd
);
6163 if (4 + type_len
>= sizeof(ework
->type
))
6164 type_len
= sizeof(ework
->type
) - 4 - 1;
6165 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
6166 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
6167 ework
->type
[4 + type_len
] = '\0';
6169 wpa_s
->ext_work_id
++;
6170 if (wpa_s
->ext_work_id
== 0)
6171 wpa_s
->ext_work_id
++;
6172 ework
->id
= wpa_s
->ext_work_id
;
6174 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
6180 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
6181 if (os_snprintf_error(buflen
, ret
))
6187 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
6189 struct wpa_radio_work
*work
;
6190 unsigned int id
= atoi(cmd
);
6192 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
6194 struct wpa_external_work
*ework
;
6196 if (os_strncmp(work
->type
, "ext:", 4) != 0)
6199 if (id
&& ework
->id
!= id
)
6201 wpa_dbg(wpa_s
, MSG_DEBUG
,
6202 "Completed external radio work %u (%s)",
6203 ework
->id
, ework
->type
);
6204 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
6205 wpa_s
->ext_work_in_progress
= 0;
6206 radio_work_done(work
);
6208 return 3; /* "OK\n" */
6215 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
6216 char *buf
, size_t buflen
)
6218 if (os_strcmp(cmd
, "show") == 0)
6219 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
6220 if (os_strncmp(cmd
, "add ", 4) == 0)
6221 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
6222 if (os_strncmp(cmd
, "done ", 5) == 0)
6223 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
6228 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
6230 struct wpa_radio_work
*work
, *tmp
;
6232 if (!wpa_s
|| !wpa_s
->radio
)
6235 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
6236 struct wpa_radio_work
, list
) {
6237 struct wpa_external_work
*ework
;
6239 if (os_strncmp(work
->type
, "ext:", 4) != 0)
6242 wpa_dbg(wpa_s
, MSG_DEBUG
,
6243 "Flushing%s external radio work %u (%s)",
6244 work
->started
? " started" : "", ework
->id
,
6247 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
6249 radio_work_done(work
);
6255 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
6257 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
6258 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
6262 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
6263 unsigned int *scan_id_count
, int scan_id
[])
6265 const char *pos
= value
;
6268 if (*pos
== ' ' || *pos
== '\0')
6270 if (*scan_id_count
== MAX_SCAN_ID
)
6272 scan_id
[(*scan_id_count
)++] = atoi(pos
);
6273 pos
= os_strchr(pos
, ',');
6282 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
6283 char *reply
, int reply_size
, int *reply_len
)
6286 unsigned int manual_scan_passive
= 0;
6287 unsigned int manual_scan_use_id
= 0;
6288 unsigned int manual_scan_only_new
= 0;
6289 unsigned int scan_only
= 0;
6290 unsigned int scan_id_count
= 0;
6291 int scan_id
[MAX_SCAN_ID
];
6292 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
6293 struct wpa_scan_results
*scan_res
);
6294 int *manual_scan_freqs
= NULL
;
6296 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
6301 if (radio_work_pending(wpa_s
, "scan")) {
6302 wpa_printf(MSG_DEBUG
,
6303 "Pending scan scheduled - reject new request");
6304 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
6309 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
6312 pos
= os_strstr(params
, "freq=");
6314 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
6316 if (manual_scan_freqs
== NULL
) {
6322 pos
= os_strstr(params
, "passive=");
6324 manual_scan_passive
= !!atoi(pos
+ 8);
6326 pos
= os_strstr(params
, "use_id=");
6328 manual_scan_use_id
= atoi(pos
+ 7);
6330 pos
= os_strstr(params
, "only_new=1");
6332 manual_scan_only_new
= 1;
6334 pos
= os_strstr(params
, "scan_id=");
6335 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
6343 scan_res_handler
= scan_only_handler
;
6344 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
6345 scan_res_handler
= NULL
;
6347 scan_res_handler
= wpa_s
->scan_res_handler
;
6349 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
6350 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
6351 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
6352 wpa_s
->manual_scan_passive
= manual_scan_passive
;
6353 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
6354 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
6355 wpa_s
->scan_id_count
= scan_id_count
;
6356 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
6357 wpa_s
->scan_res_handler
= scan_res_handler
;
6358 os_free(wpa_s
->manual_scan_freqs
);
6359 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
6360 manual_scan_freqs
= NULL
;
6362 wpa_s
->normal_scans
= 0;
6363 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6364 wpa_s
->after_wps
= 0;
6365 wpa_s
->known_wps_freq
= 0;
6366 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6367 if (wpa_s
->manual_scan_use_id
) {
6368 wpa_s
->manual_scan_id
++;
6369 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6370 wpa_s
->manual_scan_id
);
6371 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6372 wpa_s
->manual_scan_id
);
6374 } else if (wpa_s
->sched_scanning
) {
6375 wpa_s
->manual_scan_passive
= manual_scan_passive
;
6376 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
6377 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
6378 wpa_s
->scan_id_count
= scan_id_count
;
6379 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
6380 wpa_s
->scan_res_handler
= scan_res_handler
;
6381 os_free(wpa_s
->manual_scan_freqs
);
6382 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
6383 manual_scan_freqs
= NULL
;
6385 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
6386 wpa_supplicant_cancel_sched_scan(wpa_s
);
6387 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6388 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6389 if (wpa_s
->manual_scan_use_id
) {
6390 wpa_s
->manual_scan_id
++;
6391 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6392 wpa_s
->manual_scan_id
);
6393 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6394 wpa_s
->manual_scan_id
);
6397 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
6398 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
6402 os_free(manual_scan_freqs
);
6406 #ifdef CONFIG_TESTING_OPTIONS
6408 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
6409 unsigned int freq
, const u8
*dst
,
6410 const u8
*src
, const u8
*bssid
,
6411 const u8
*data
, size_t data_len
,
6412 enum offchannel_send_action_result
6415 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6416 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
6417 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
6418 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
6419 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
6420 "NO_ACK" : "FAILED"));
6424 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6428 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
6430 int freq
= 0, no_cck
= 0, wait_time
= 0;
6432 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6433 * <action=Action frame payload> */
6435 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
6438 used
= hwaddr_aton2(pos
, da
);
6444 used
= hwaddr_aton2(pos
, bssid
);
6449 param
= os_strstr(pos
, " freq=");
6455 param
= os_strstr(pos
, " no_cck=");
6458 no_cck
= atoi(param
);
6461 param
= os_strstr(pos
, " wait_time=");
6464 wait_time
= atoi(param
);
6467 param
= os_strstr(pos
, " action=");
6472 len
= os_strlen(param
);
6477 buf
= os_malloc(len
);
6481 if (hexstr2bin(param
, buf
, len
) < 0) {
6486 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
6487 buf
, len
, wait_time
,
6488 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
6494 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
6496 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
6497 offchannel_send_action_done(wpa_s
);
6501 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
6504 union wpa_event_data event
;
6505 enum wpa_event_type ev
;
6507 /* <event name> [parameters..] */
6509 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
6512 param
= os_strchr(pos
, ' ');
6516 os_memset(&event
, 0, sizeof(event
));
6518 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
6519 ev
= EVENT_INTERFACE_ENABLED
;
6520 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
6521 ev
= EVENT_INTERFACE_DISABLED
;
6522 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
6523 ev
= EVENT_AVOID_FREQUENCIES
;
6526 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
6528 wpa_supplicant_event(wpa_s
, ev
, &event
);
6529 os_free(event
.freq_range
.range
);
6532 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
6537 wpa_supplicant_event(wpa_s
, ev
, &event
);
6543 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6546 u8 src
[ETH_ALEN
], *buf
;
6550 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
6553 used
= hwaddr_aton2(pos
, src
);
6560 len
= os_strlen(pos
);
6565 buf
= os_malloc(len
);
6569 if (hexstr2bin(pos
, buf
, len
) < 0) {
6574 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
6581 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
6585 const u16
*pos
= buf
;
6587 for (i
= 0; i
< len
/ 2; i
++)
6591 sum
= (sum
& 0xffff) + (sum
>> 16);
6593 return sum
^ 0xffff;
6597 #define HWSIM_PACKETLEN 1500
6598 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6600 void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
, size_t len
)
6602 struct wpa_supplicant
*wpa_s
= ctx
;
6603 const struct ether_header
*eth
;
6604 const struct iphdr
*ip
;
6608 if (len
!= HWSIM_PACKETLEN
)
6611 eth
= (const struct ether_header
*) buf
;
6612 ip
= (const struct iphdr
*) (eth
+ 1);
6613 pos
= (const u8
*) (ip
+ 1);
6615 if (ip
->ihl
!= 5 || ip
->version
!= 4 ||
6616 ntohs(ip
->tot_len
) != HWSIM_IP_LEN
)
6619 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++) {
6625 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
6626 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
6630 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
6633 int enabled
= atoi(cmd
);
6636 if (wpa_s
->l2_test
) {
6637 l2_packet_deinit(wpa_s
->l2_test
);
6638 wpa_s
->l2_test
= NULL
;
6639 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
6647 wpa_s
->l2_test
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
,
6648 ETHERTYPE_IP
, wpas_data_test_rx
,
6650 if (wpa_s
->l2_test
== NULL
)
6653 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
6659 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6661 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
6666 u8 buf
[HWSIM_PACKETLEN
];
6667 struct ether_header
*eth
;
6672 if (wpa_s
->l2_test
== NULL
)
6675 /* format: <dst> <src> <tos> */
6678 used
= hwaddr_aton2(pos
, dst
);
6684 used
= hwaddr_aton2(pos
, src
);
6689 val
= strtol(pos
, NULL
, 0);
6690 if (val
< 0 || val
> 0xff)
6694 eth
= (struct ether_header
*) buf
;
6695 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
6696 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
6697 eth
->ether_type
= htons(ETHERTYPE_IP
);
6698 ip
= (struct iphdr
*) (eth
+ 1);
6699 os_memset(ip
, 0, sizeof(*ip
));
6704 ip
->tot_len
= htons(HWSIM_IP_LEN
);
6706 ip
->saddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6707 ip
->daddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6708 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
6709 dpos
= (u8
*) (ip
+ 1);
6710 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
6713 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, buf
,
6714 HWSIM_PACKETLEN
) < 0)
6717 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
6718 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
6724 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
6728 struct ether_header
*eth
;
6729 struct l2_packet_data
*l2
= NULL
;
6734 len
= os_strlen(cmd
);
6735 if (len
& 1 || len
< ETH_HLEN
* 2)
6739 buf
= os_malloc(len
);
6743 if (hexstr2bin(cmd
, buf
, len
) < 0)
6746 eth
= (struct ether_header
*) buf
;
6747 ethertype
= ntohs(eth
->ether_type
);
6749 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
6750 wpas_data_test_rx
, wpa_s
, 1);
6754 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
6755 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
6758 l2_packet_deinit(l2
);
6761 return res
< 0 ? -1 : 0;
6764 #endif /* CONFIG_TESTING_OPTIONS */
6767 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant
*wpa_s
)
6772 wpa_printf(MSG_DEBUG
, "Update vendor elements");
6774 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
6775 if (wpa_s
->vendor_elem
[i
]) {
6778 res
= os_snprintf(buf
, sizeof(buf
), "frame[%u]", i
);
6779 if (!os_snprintf_error(sizeof(buf
), res
)) {
6780 wpa_hexdump_buf(MSG_DEBUG
, buf
,
6781 wpa_s
->vendor_elem
[i
]);
6787 if (wpa_s
->parent
== wpa_s
&&
6788 wpa_s
->global
->p2p
&&
6789 !wpa_s
->global
->p2p_disabled
)
6790 p2p_set_vendor_elems(wpa_s
->global
->p2p
, wpa_s
->vendor_elem
);
6791 #endif /* CONFIG_P2P */
6795 static struct wpa_supplicant
*
6796 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant
*wpa_s
,
6797 enum wpa_vendor_elem_frame frame
)
6801 case VENDOR_ELEM_PROBE_REQ_P2P
:
6802 case VENDOR_ELEM_PROBE_RESP_P2P
:
6803 case VENDOR_ELEM_PROBE_RESP_P2P_GO
:
6804 case VENDOR_ELEM_BEACON_P2P_GO
:
6805 case VENDOR_ELEM_P2P_PD_REQ
:
6806 case VENDOR_ELEM_P2P_PD_RESP
:
6807 case VENDOR_ELEM_P2P_GO_NEG_REQ
:
6808 case VENDOR_ELEM_P2P_GO_NEG_RESP
:
6809 case VENDOR_ELEM_P2P_GO_NEG_CONF
:
6810 case VENDOR_ELEM_P2P_INV_REQ
:
6811 case VENDOR_ELEM_P2P_INV_RESP
:
6812 case VENDOR_ELEM_P2P_ASSOC_REQ
:
6813 return wpa_s
->parent
;
6814 #endif /* CONFIG_P2P */
6821 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6827 struct ieee802_11_elems elems
;
6830 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6832 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6834 pos
= os_strchr(pos
, ' ');
6839 len
= os_strlen(pos
);
6846 buf
= wpabuf_alloc(len
);
6850 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
6855 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
6861 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
6862 wpa_s
->vendor_elem
[frame
] = buf
;
6863 wpas_ctrl_vendor_elem_update(wpa_s
);
6867 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
6872 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
6874 wpas_ctrl_vendor_elem_update(wpa_s
);
6880 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
6881 char *buf
, size_t buflen
)
6883 int frame
= atoi(cmd
);
6885 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6887 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6889 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6892 return wpa_snprintf_hex(buf
, buflen
,
6893 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
6894 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
6898 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
6904 struct ieee802_11_elems elems
;
6908 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6910 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6912 pos
= os_strchr(pos
, ' ');
6918 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6919 wpa_s
->vendor_elem
[frame
] = NULL
;
6920 wpas_ctrl_vendor_elem_update(wpa_s
);
6924 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6927 len
= os_strlen(pos
);
6934 buf
= os_malloc(len
);
6938 if (hexstr2bin(pos
, buf
, len
) < 0) {
6943 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
6948 ie
= wpabuf_mhead_u8(wpa_s
->vendor_elem
[frame
]);
6949 end
= ie
+ wpabuf_len(wpa_s
->vendor_elem
[frame
]);
6951 for (; ie
+ 1 < end
; ie
+= 2 + ie
[1]) {
6954 if (os_memcmp(ie
, buf
, len
) != 0)
6957 if (wpabuf_len(wpa_s
->vendor_elem
[frame
]) == len
) {
6958 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6959 wpa_s
->vendor_elem
[frame
] = NULL
;
6961 os_memmove(ie
, ie
+ len
,
6963 wpa_s
->vendor_elem
[frame
]->used
-= len
;
6966 wpas_ctrl_vendor_elem_update(wpa_s
);
6976 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
6978 struct wpa_supplicant
*wpa_s
= ctx
;
6981 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
6983 (unsigned int) wpabuf_len(neighbor_rep
));
6984 wpabuf_free(neighbor_rep
);
6986 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
6991 static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant
*wpa_s
,
6994 struct wpa_ssid ssid
;
6995 struct wpa_ssid
*ssid_p
= NULL
;
6998 if (os_strncmp(cmd
, " ssid=", 6) == 0) {
6999 ssid
.ssid_len
= os_strlen(cmd
+ 6);
7000 if (ssid
.ssid_len
> 32)
7002 ssid
.ssid
= (u8
*) (cmd
+ 6);
7006 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
,
7007 wpas_ctrl_neighbor_rep_cb
,
7014 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
7016 eapol_sm_erp_flush(wpa_s
->eapol
);
7021 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
7022 char *buf
, size_t *resp_len
)
7025 const int reply_size
= 4096;
7028 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
7029 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
7030 if (wpa_debug_show_keys
)
7031 wpa_dbg(wpa_s
, MSG_DEBUG
,
7032 "Control interface command '%s'", buf
);
7034 wpa_dbg(wpa_s
, MSG_DEBUG
,
7035 "Control interface command '%s [REMOVED]'",
7036 os_strncmp(buf
, WPA_CTRL_RSP
,
7037 os_strlen(WPA_CTRL_RSP
)) == 0 ?
7038 WPA_CTRL_RSP
: "SET_NETWORK");
7039 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
7040 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
7041 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
7042 (const u8
*) buf
, os_strlen(buf
));
7044 int level
= MSG_DEBUG
;
7045 if (os_strcmp(buf
, "PING") == 0)
7046 level
= MSG_EXCESSIVE
;
7047 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
7050 reply
= os_malloc(reply_size
);
7051 if (reply
== NULL
) {
7056 os_memcpy(reply
, "OK\n", 3);
7059 if (os_strcmp(buf
, "PING") == 0) {
7060 os_memcpy(reply
, "PONG\n", 5);
7062 } else if (os_strcmp(buf
, "IFNAME") == 0) {
7063 reply_len
= os_strlen(wpa_s
->ifname
);
7064 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
7065 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
7066 if (wpa_debug_reopen_file() < 0)
7068 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
7069 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
7070 } else if (os_strcmp(buf
, "MIB") == 0) {
7071 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
7072 if (reply_len
>= 0) {
7073 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
7075 reply_size
- reply_len
);
7077 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
7078 reply_len
= wpa_supplicant_ctrl_iface_status(
7079 wpa_s
, buf
+ 6, reply
, reply_size
);
7080 } else if (os_strcmp(buf
, "PMKSA") == 0) {
7081 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
7083 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
7084 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7085 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
7086 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
7088 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
7089 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
7091 } else if (os_strcmp(buf
, "LOGON") == 0) {
7092 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7093 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
7094 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
7095 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
7096 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
7099 wpas_request_connection(wpa_s
);
7100 } else if (os_strcmp(buf
, "REATTACH") == 0) {
7101 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
7102 !wpa_s
->current_ssid
)
7105 wpa_s
->reattach
= 1;
7106 wpas_request_connection(wpa_s
);
7108 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
7109 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
7111 else if (wpa_s
->disconnected
)
7112 wpas_request_connection(wpa_s
);
7113 #ifdef IEEE8021X_EAPOL
7114 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
7115 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
7117 #endif /* IEEE8021X_EAPOL */
7118 #ifdef CONFIG_PEERKEY
7119 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
7120 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
7122 #endif /* CONFIG_PEERKEY */
7123 #ifdef CONFIG_IEEE80211R
7124 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
7125 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
7127 #endif /* CONFIG_IEEE80211R */
7129 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
7130 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
7132 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7136 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
7137 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
7139 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7143 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
7144 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
7147 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
7148 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
7149 wpa_s
, buf
+ 14, reply
, reply_size
);
7150 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
7151 if (wpas_wps_cancel(wpa_s
))
7153 #ifdef CONFIG_WPS_NFC
7154 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
7155 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
7157 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
7158 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
7160 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
7161 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
7162 wpa_s
, buf
+ 21, reply
, reply_size
);
7163 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
7164 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
7165 wpa_s
, buf
+ 14, reply
, reply_size
);
7166 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
7167 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
7170 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
7171 reply_len
= wpas_ctrl_nfc_get_handover_req(
7172 wpa_s
, buf
+ 21, reply
, reply_size
);
7173 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
7174 reply_len
= wpas_ctrl_nfc_get_handover_sel(
7175 wpa_s
, buf
+ 21, reply
, reply_size
);
7176 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
7177 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
7179 #endif /* CONFIG_WPS_NFC */
7180 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
7181 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
7184 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
7185 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
7186 wpa_s
, buf
+ 11, reply
, reply_size
);
7187 #endif /* CONFIG_AP */
7188 #ifdef CONFIG_WPS_ER
7189 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
7190 if (wpas_wps_er_start(wpa_s
, NULL
))
7192 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
7193 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
7195 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
7196 wpas_wps_er_stop(wpa_s
);
7197 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
7198 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
7200 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
7201 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
7203 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7205 } else if (ret
== -3) {
7206 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
7208 } else if (ret
== -4) {
7209 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
7213 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
7214 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
7216 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
7217 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
7220 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
7221 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
7223 #ifdef CONFIG_WPS_NFC
7224 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
7225 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
7226 wpa_s
, buf
+ 24, reply
, reply_size
);
7227 #endif /* CONFIG_WPS_NFC */
7228 #endif /* CONFIG_WPS_ER */
7229 #endif /* CONFIG_WPS */
7230 #ifdef CONFIG_IBSS_RSN
7231 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
7232 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
7234 #endif /* CONFIG_IBSS_RSN */
7236 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
7237 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
7238 wpa_s
, buf
+ 19, reply
, reply_size
);
7239 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
7240 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
7241 wpa_s
, "", reply
, reply_size
);
7242 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
7243 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
7245 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
7246 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
7249 #endif /* CONFIG_MESH */
7251 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
7252 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
7254 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
7255 if (p2p_ctrl_find(wpa_s
, ""))
7257 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
7258 wpas_p2p_stop_find(wpa_s
);
7259 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
7260 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
7262 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
7263 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
7265 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
7266 if (p2p_ctrl_listen(wpa_s
, ""))
7268 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
7269 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
7271 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
7272 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
7274 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
7275 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
7277 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
7278 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
7280 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
7281 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
7282 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
7283 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
7285 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
7286 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
7288 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
7289 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
7291 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
7292 wpas_p2p_sd_service_update(wpa_s
);
7293 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
7294 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
7296 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
7297 wpas_p2p_service_flush(wpa_s
);
7298 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
7299 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
7301 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
7302 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
7304 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
7305 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
7307 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
7308 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
7310 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
7311 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
7313 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
7314 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
7316 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
7317 p2p_ctrl_flush(wpa_s
);
7318 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
7319 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
7321 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
7322 if (wpas_p2p_cancel(wpa_s
))
7324 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
7325 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
7327 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
7328 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
7330 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
7331 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
7333 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
7334 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
7336 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
7337 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
7339 #endif /* CONFIG_P2P */
7340 #ifdef CONFIG_WIFI_DISPLAY
7341 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
7342 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
7344 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
7345 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
7347 #endif /* CONFIG_WIFI_DISPLAY */
7348 #ifdef CONFIG_INTERWORKING
7349 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
7350 if (interworking_fetch_anqp(wpa_s
) < 0)
7352 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
7353 interworking_stop_fetch_anqp(wpa_s
);
7354 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
7355 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
7357 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
7358 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
7360 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
7361 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
7363 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
7364 if (get_anqp(wpa_s
, buf
+ 9) < 0)
7366 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
7367 if (gas_request(wpa_s
, buf
+ 12) < 0)
7369 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
7370 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
7372 #endif /* CONFIG_INTERWORKING */
7374 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
7375 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
7377 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7378 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
7380 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
7381 if (hs20_icon_request(wpa_s
, buf
+ 18) < 0)
7383 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
7384 if (hs20_fetch_osu(wpa_s
) < 0)
7386 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
7387 hs20_cancel_fetch_osu(wpa_s
);
7388 #endif /* CONFIG_HS20 */
7389 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
7391 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7392 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
7396 * Notify response from timeout to allow the control
7397 * interface response to be sent first.
7399 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
7402 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
7403 if (wpa_supplicant_reload_configuration(wpa_s
))
7405 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
7406 wpa_supplicant_terminate_proc(wpa_s
->global
);
7407 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
7408 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
7410 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
7411 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
7412 wpa_s
, buf
+ 9, reply
, reply_size
);
7413 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
7414 reply_len
= wpa_supplicant_ctrl_iface_log_level(
7415 wpa_s
, buf
+ 9, reply
, reply_size
);
7416 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
7417 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
7418 wpa_s
, buf
+ 14, reply
, reply_size
);
7419 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
7420 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
7421 wpa_s
, NULL
, reply
, reply_size
);
7422 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
7424 wpa_s
->sme
.prev_bssid_set
= 0;
7425 #endif /* CONFIG_SME */
7426 wpa_s
->reassociate
= 0;
7427 wpa_s
->disconnected
= 1;
7428 wpa_supplicant_cancel_sched_scan(wpa_s
);
7429 wpa_supplicant_cancel_scan(wpa_s
);
7430 wpa_supplicant_deauthenticate(wpa_s
,
7431 WLAN_REASON_DEAUTH_LEAVING
);
7432 } else if (os_strcmp(buf
, "SCAN") == 0) {
7433 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
7434 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
7435 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
7436 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
7437 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
7438 wpa_s
, reply
, reply_size
);
7439 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
7440 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
7442 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
7443 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
7445 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
7446 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
7448 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
7449 reply_len
= wpa_supplicant_ctrl_iface_add_network(
7450 wpa_s
, reply
, reply_size
);
7451 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
7452 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
7454 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
7455 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
7457 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
7458 reply_len
= wpa_supplicant_ctrl_iface_get_network(
7459 wpa_s
, buf
+ 12, reply
, reply_size
);
7460 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
7461 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12))
7463 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
7464 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
7465 wpa_s
, reply
, reply_size
);
7466 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
7467 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
7468 wpa_s
, reply
, reply_size
);
7469 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
7470 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
7472 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
7473 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
7475 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
7476 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
7479 #ifndef CONFIG_NO_CONFIG_WRITE
7480 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
7481 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
7483 #endif /* CONFIG_NO_CONFIG_WRITE */
7484 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
7485 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
7486 wpa_s
, buf
+ 15, reply
, reply_size
);
7487 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
7488 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
7490 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
7491 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
7493 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
7494 reply_len
= wpa_supplicant_global_iface_list(
7495 wpa_s
->global
, reply
, reply_size
);
7496 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
7497 reply_len
= wpa_supplicant_global_iface_interfaces(
7498 wpa_s
->global
, reply
, reply_size
);
7499 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
7500 reply_len
= wpa_supplicant_ctrl_iface_bss(
7501 wpa_s
, buf
+ 4, reply
, reply_size
);
7503 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
7504 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
7505 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
7506 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
7508 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
7509 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
7511 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
7512 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
7514 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
7515 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
7517 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
7518 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
7520 #endif /* CONFIG_AP */
7521 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
7522 wpas_notify_suspend(wpa_s
->global
);
7523 } else if (os_strcmp(buf
, "RESUME") == 0) {
7524 wpas_notify_resume(wpa_s
->global
);
7525 #ifdef CONFIG_TESTING_OPTIONS
7526 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
7527 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
7528 #endif /* CONFIG_TESTING_OPTIONS */
7529 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
7530 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
7532 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
7533 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
7534 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
7535 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
7537 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
7538 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
7541 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
7542 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
7544 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
7545 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
7547 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
7548 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
7550 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
7551 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
7553 #endif /* CONFIG_TDLS */
7554 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
7555 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
7556 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
7557 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
7559 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
7560 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
7562 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
7563 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
7565 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
7566 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
7568 #ifdef CONFIG_AUTOSCAN
7569 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
7570 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
7572 #endif /* CONFIG_AUTOSCAN */
7574 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
7575 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
7577 #endif /* ANDROID */
7578 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
7579 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
7581 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
7582 pmksa_cache_clear_current(wpa_s
->wpa
);
7583 eapol_sm_request_reauth(wpa_s
->eapol
);
7585 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
7586 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
7588 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
7589 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
7591 #endif /* CONFIG_WNM */
7592 } else if (os_strcmp(buf
, "FLUSH") == 0) {
7593 wpa_supplicant_ctrl_iface_flush(wpa_s
);
7594 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
7595 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
7597 #ifdef CONFIG_TESTING_OPTIONS
7598 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
7599 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
7601 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
7602 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
7603 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
7604 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
7606 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
7607 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
7609 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
7610 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
7612 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
7613 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
7615 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
7616 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
7618 #endif /* CONFIG_TESTING_OPTIONS */
7619 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
7620 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
7622 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
7623 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
7625 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7626 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
7628 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
7629 if (wpas_ctrl_iface_send_neigbor_rep(wpa_s
, buf
+ 20))
7631 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
7632 wpas_ctrl_iface_erp_flush(wpa_s
);
7634 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
7638 if (reply_len
< 0) {
7639 os_memcpy(reply
, "FAIL\n", 5);
7643 *resp_len
= reply_len
;
7648 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
7651 struct wpa_interface iface
;
7655 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7656 * TAB<bridge_ifname>
7658 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
7660 os_memset(&iface
, 0, sizeof(iface
));
7663 iface
.ifname
= pos
= cmd
;
7664 pos
= os_strchr(pos
, '\t');
7667 if (iface
.ifname
[0] == '\0')
7672 iface
.confname
= pos
;
7673 pos
= os_strchr(pos
, '\t');
7676 if (iface
.confname
[0] == '\0')
7677 iface
.confname
= NULL
;
7682 pos
= os_strchr(pos
, '\t');
7685 if (iface
.driver
[0] == '\0')
7686 iface
.driver
= NULL
;
7690 iface
.ctrl_interface
= pos
;
7691 pos
= os_strchr(pos
, '\t');
7694 if (iface
.ctrl_interface
[0] == '\0')
7695 iface
.ctrl_interface
= NULL
;
7699 iface
.driver_param
= pos
;
7700 pos
= os_strchr(pos
, '\t');
7703 if (iface
.driver_param
[0] == '\0')
7704 iface
.driver_param
= NULL
;
7708 iface
.bridge_ifname
= pos
;
7709 pos
= os_strchr(pos
, '\t');
7712 if (iface
.bridge_ifname
[0] == '\0')
7713 iface
.bridge_ifname
= NULL
;
7718 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
7721 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
7725 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
7728 struct wpa_supplicant
*wpa_s
;
7730 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
7732 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
7735 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
7739 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
7741 struct wpa_interface_info
*prev
;
7745 iface
= iface
->next
;
7747 os_free(prev
->ifname
);
7748 os_free(prev
->desc
);
7754 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
7758 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
7761 for (i
= 0; wpa_drivers
[i
]; i
++) {
7762 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
7763 if (drv
->get_interfaces
== NULL
)
7765 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
7779 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
7780 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
7781 tmp
->drv_name
, tmp
->ifname
,
7782 tmp
->desc
? tmp
->desc
: "");
7783 if (os_snprintf_error(end
- pos
, res
)) {
7790 wpa_free_iface_info(iface
);
7796 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
7801 struct wpa_supplicant
*wpa_s
;
7803 wpa_s
= global
->ifaces
;
7808 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
7809 if (os_snprintf_error(end
- pos
, res
)) {
7814 wpa_s
= wpa_s
->next
;
7820 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
7822 char *cmd
, size_t *resp_len
)
7824 struct wpa_supplicant
*wpa_s
;
7826 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7827 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
7831 if (wpa_s
== NULL
) {
7832 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
7834 *resp_len
= os_strlen(resp
);
7840 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
7844 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
7845 char *buf
, size_t *resp_len
)
7848 static const char * cmd
[] = {
7854 "P2P_GET_PASSPHRASE",
7855 "P2P_SERVICE_UPDATE",
7856 "P2P_SERVICE_FLUSH",
7863 static const char * prefix
[] = {
7866 #endif /* ANDROID */
7872 "P2P_GROUP_REMOVE ",
7875 "P2P_SERV_DISC_REQ ",
7876 "P2P_SERV_DISC_CANCEL_REQ ",
7877 "P2P_SERV_DISC_RESP ",
7878 "P2P_SERV_DISC_EXTERNAL ",
7886 "P2P_PRESENCE_REQ ",
7888 "P2P_REMOVE_CLIENT ",
7889 "NFC_GET_HANDOVER_SEL ",
7890 "NFC_GET_HANDOVER_REQ ",
7891 "NFC_REPORT_HANDOVER ",
7897 if (global
->p2p_init_wpa_s
== NULL
)
7900 for (i
= 0; !found
&& cmd
[i
]; i
++) {
7901 if (os_strcmp(buf
, cmd
[i
]) == 0)
7905 for (i
= 0; !found
&& prefix
[i
]; i
++) {
7906 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
7911 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7913 #endif /* CONFIG_P2P */
7918 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
7919 char *buf
, size_t *resp_len
)
7921 #ifdef CONFIG_WIFI_DISPLAY
7922 if (global
->p2p_init_wpa_s
== NULL
)
7924 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
7925 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
7926 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7928 #endif /* CONFIG_WIFI_DISPLAY */
7933 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
7934 char *buf
, size_t *resp_len
)
7938 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
7942 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
7950 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
7954 value
= os_strchr(cmd
, ' ');
7959 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
7961 #ifdef CONFIG_WIFI_DISPLAY
7962 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
7963 wifi_display_enable(global
, !!atoi(value
));
7966 #endif /* CONFIG_WIFI_DISPLAY */
7968 /* Restore cmd to its original value to allow redirection */
7975 #ifndef CONFIG_NO_CONFIG_WRITE
7976 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
7978 int ret
= 0, saved
= 0;
7979 struct wpa_supplicant
*wpa_s
;
7981 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7982 if (!wpa_s
->conf
->update_config
) {
7983 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7987 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
7988 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7991 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7996 if (!saved
&& !ret
) {
7997 wpa_dbg(wpa_s
, MSG_DEBUG
,
7998 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
8004 #endif /* CONFIG_NO_CONFIG_WRITE */
8007 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
8008 char *buf
, size_t buflen
)
8012 struct wpa_supplicant
*wpa_s
;
8018 if (global
->p2p
&& !global
->p2p_disabled
) {
8019 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
8022 MAC2STR(global
->p2p_dev_addr
),
8023 p2p_get_state_txt(global
->p2p
));
8024 if (os_snprintf_error(end
- pos
, ret
))
8027 } else if (global
->p2p
) {
8028 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
8029 if (os_snprintf_error(end
- pos
, ret
))
8033 #endif /* CONFIG_P2P */
8035 #ifdef CONFIG_WIFI_DISPLAY
8036 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
8037 !!global
->wifi_display
);
8038 if (os_snprintf_error(end
- pos
, ret
))
8041 #endif /* CONFIG_WIFI_DISPLAY */
8043 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
8044 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
8045 "address=" MACSTR
"\n",
8046 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
8047 if (os_snprintf_error(end
- pos
, ret
))
8056 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
8057 char *buf
, size_t *resp_len
)
8060 const int reply_size
= 2048;
8062 int level
= MSG_DEBUG
;
8064 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
8065 char *pos
= os_strchr(buf
+ 7, ' ');
8068 return wpas_global_ctrl_iface_ifname(global
,
8074 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
8078 if (os_strcmp(buf
, "PING") == 0)
8079 level
= MSG_EXCESSIVE
;
8080 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
8081 (const u8
*) buf
, os_strlen(buf
));
8083 reply
= os_malloc(reply_size
);
8084 if (reply
== NULL
) {
8089 os_memcpy(reply
, "OK\n", 3);
8092 if (os_strcmp(buf
, "PING") == 0) {
8093 os_memcpy(reply
, "PONG\n", 5);
8095 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
8096 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
8098 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
8099 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
8101 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
8102 reply_len
= wpa_supplicant_global_iface_list(
8103 global
, reply
, reply_size
);
8104 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
8105 reply_len
= wpa_supplicant_global_iface_interfaces(
8106 global
, reply
, reply_size
);
8107 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
8108 wpa_supplicant_terminate_proc(global
);
8109 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
8110 wpas_notify_suspend(global
);
8111 } else if (os_strcmp(buf
, "RESUME") == 0) {
8112 wpas_notify_resume(global
);
8113 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
8114 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
8116 if (global
->p2p_init_wpa_s
) {
8118 /* Check if P2P redirection would work for this
8120 return wpa_supplicant_ctrl_iface_process(
8121 global
->p2p_init_wpa_s
,
8124 #endif /* CONFIG_P2P */
8127 #ifndef CONFIG_NO_CONFIG_WRITE
8128 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
8129 if (wpas_global_ctrl_iface_save_config(global
))
8131 #endif /* CONFIG_NO_CONFIG_WRITE */
8132 } else if (os_strcmp(buf
, "STATUS") == 0) {
8133 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
8135 #ifdef CONFIG_MODULE_TESTS
8136 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
8137 int wpas_module_tests(void);
8138 if (wpas_module_tests() < 0)
8140 #endif /* CONFIG_MODULE_TESTS */
8141 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
8142 if (wpa_debug_reopen_file() < 0)
8145 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
8149 if (reply_len
< 0) {
8150 os_memcpy(reply
, "FAIL\n", 5);
8154 *resp_len
= reply_len
;