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 */
446 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
448 wpa_supplicant_update_config(wpa_s
);
455 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
456 char *cmd
, char *buf
, size_t buflen
)
460 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
462 if (os_strcmp(cmd
, "version") == 0) {
463 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
464 } else if (os_strcasecmp(cmd
, "country") == 0) {
465 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
466 res
= os_snprintf(buf
, buflen
, "%c%c",
467 wpa_s
->conf
->country
[0],
468 wpa_s
->conf
->country
[1]);
469 #ifdef CONFIG_WIFI_DISPLAY
470 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
472 if (wpa_s
->global
->p2p
== NULL
||
473 wpa_s
->global
->p2p_disabled
)
476 enabled
= wpa_s
->global
->wifi_display
;
477 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
478 #endif /* CONFIG_WIFI_DISPLAY */
479 #ifdef CONFIG_TESTING_GET_GTK
480 } else if (os_strcmp(cmd
, "gtk") == 0) {
481 if (wpa_s
->last_gtk_len
== 0)
483 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
484 wpa_s
->last_gtk_len
);
486 #endif /* CONFIG_TESTING_GET_GTK */
489 if (os_snprintf_error(buflen
, res
))
495 #ifdef IEEE8021X_EAPOL
496 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
500 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
502 if (hwaddr_aton(addr
, bssid
)) {
503 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
508 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
509 rsn_preauth_deinit(wpa_s
->wpa
);
510 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
515 #endif /* IEEE8021X_EAPOL */
518 #ifdef CONFIG_PEERKEY
519 /* MLME-STKSTART.request(peer) */
520 static int wpa_supplicant_ctrl_iface_stkstart(
521 struct wpa_supplicant
*wpa_s
, char *addr
)
525 if (hwaddr_aton(addr
, peer
)) {
526 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
527 "address '%s'", addr
);
531 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
534 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
536 #endif /* CONFIG_PEERKEY */
541 static int wpa_supplicant_ctrl_iface_tdls_discover(
542 struct wpa_supplicant
*wpa_s
, char *addr
)
547 if (hwaddr_aton(addr
, peer
)) {
548 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
549 "address '%s'", addr
);
553 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
556 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
557 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
559 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
565 static int wpa_supplicant_ctrl_iface_tdls_setup(
566 struct wpa_supplicant
*wpa_s
, char *addr
)
571 if (hwaddr_aton(addr
, peer
)) {
572 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
573 "address '%s'", addr
);
577 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
580 if ((wpa_s
->conf
->tdls_external_control
) &&
581 wpa_tdls_is_external_setup(wpa_s
->wpa
))
582 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
584 wpa_tdls_remove(wpa_s
->wpa
, peer
);
586 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
587 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
589 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
595 static int wpa_supplicant_ctrl_iface_tdls_teardown(
596 struct wpa_supplicant
*wpa_s
, char *addr
)
601 if (os_strcmp(addr
, "*") == 0) {
602 /* remove everyone */
603 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
604 wpa_tdls_teardown_peers(wpa_s
->wpa
);
608 if (hwaddr_aton(addr
, peer
)) {
609 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
610 "address '%s'", addr
);
614 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
617 if ((wpa_s
->conf
->tdls_external_control
) &&
618 wpa_tdls_is_external_setup(wpa_s
->wpa
))
619 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
621 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
622 ret
= wpa_tdls_teardown_link(
624 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
626 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
632 static int ctrl_iface_get_capability_tdls(
633 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
637 ret
= os_snprintf(buf
, buflen
, "%s\n",
638 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
640 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
641 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
642 if (os_snprintf_error(buflen
, ret
))
647 #endif /* CONFIG_TDLS */
650 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
652 char *token
, *context
= NULL
;
653 struct wmm_ac_ts_setup_params params
= {
658 while ((token
= str_token(cmd
, " ", &context
))) {
659 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
660 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
661 sscanf(token
, "nominal_msdu_size=%i",
662 ¶ms
.nominal_msdu_size
) == 1 ||
663 sscanf(token
, "mean_data_rate=%i",
664 ¶ms
.mean_data_rate
) == 1 ||
665 sscanf(token
, "min_phy_rate=%i",
666 ¶ms
.minimum_phy_rate
) == 1 ||
667 sscanf(token
, "sba=%i",
668 ¶ms
.surplus_bandwidth_allowance
) == 1)
671 if (os_strcasecmp(token
, "downlink") == 0) {
672 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
673 } else if (os_strcasecmp(token
, "uplink") == 0) {
674 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
675 } else if (os_strcasecmp(token
, "bidi") == 0) {
676 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
677 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
678 params
.fixed_nominal_msdu
= 1;
680 wpa_printf(MSG_DEBUG
,
681 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
688 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
692 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
696 return wpas_wmm_ac_delts(wpa_s
, tsid
);
700 #ifdef CONFIG_IEEE80211R
701 static int wpa_supplicant_ctrl_iface_ft_ds(
702 struct wpa_supplicant
*wpa_s
, char *addr
)
704 u8 target_ap
[ETH_ALEN
];
708 if (hwaddr_aton(addr
, target_ap
)) {
709 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
710 "address '%s'", addr
);
714 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
716 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
718 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
722 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
724 #endif /* CONFIG_IEEE80211R */
728 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
731 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
733 u8 p2p_dev_addr
[ETH_ALEN
];
734 #endif /* CONFIG_P2P */
736 u8
*_p2p_dev_addr
= NULL
;
737 #endif /* CONFIG_AP */
739 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
742 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
743 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
744 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
745 "P2P Device Address '%s'",
749 _p2p_dev_addr
= p2p_dev_addr
;
750 #endif /* CONFIG_P2P */
751 } else if (hwaddr_aton(cmd
, bssid
)) {
752 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
759 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
760 #endif /* CONFIG_AP */
762 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
766 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
767 char *cmd
, char *buf
,
770 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
774 pin
= os_strchr(cmd
, ' ');
778 if (os_strcmp(cmd
, "any") == 0)
780 else if (os_strcmp(cmd
, "get") == 0) {
781 ret
= wps_generate_pin();
783 } else if (hwaddr_aton(cmd
, bssid
)) {
784 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
790 if (wpa_s
->ap_iface
) {
795 pos
= os_strchr(pin
, ' ');
802 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
803 buf
, buflen
, timeout
);
805 #endif /* CONFIG_AP */
808 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
812 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
813 if (os_snprintf_error(buflen
, ret
))
818 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
823 /* Return the generated PIN */
824 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
825 if (os_snprintf_error(buflen
, ret
))
831 static int wpa_supplicant_ctrl_iface_wps_check_pin(
832 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
839 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
840 (u8
*) cmd
, os_strlen(cmd
));
841 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
842 if (*pos
< '0' || *pos
> '9')
846 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
850 if (len
!= 4 && len
!= 8) {
851 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
857 unsigned int pin_val
;
859 if (!wps_pin_valid(pin_val
)) {
860 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
861 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
862 if (os_snprintf_error(buflen
, ret
))
868 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
869 if (os_snprintf_error(buflen
, ret
))
876 #ifdef CONFIG_WPS_NFC
878 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
881 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
883 if (cmd
== NULL
|| cmd
[0] == '\0')
885 else if (hwaddr_aton(cmd
, bssid
))
888 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
893 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
894 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
901 pos
= os_strchr(cmd
, ' ');
904 if (os_strcmp(cmd
, "WPS") == 0)
906 else if (os_strcmp(cmd
, "NDEF") == 0)
911 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
915 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
926 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
927 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
933 if (os_strcmp(cmd
, "WPS") == 0)
935 else if (os_strcmp(cmd
, "NDEF") == 0)
940 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
944 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
955 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
956 struct wpa_supplicant
*wpa_s
, char *pos
)
964 freq
= strstr(pos
, " freq=");
968 forced_freq
= atoi(freq
);
971 len
= os_strlen(pos
);
976 buf
= wpabuf_alloc(len
);
979 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
984 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
991 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
992 char *reply
, size_t max_len
,
998 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1002 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1004 reply
[res
++] = '\n';
1014 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1015 char *reply
, size_t max_len
,
1021 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1023 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1027 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1029 reply
[res
++] = '\n';
1036 #endif /* CONFIG_P2P */
1039 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1040 char *cmd
, char *reply
,
1046 pos
= os_strchr(cmd
, ' ');
1051 if (os_strcmp(cmd
, "WPS") == 0)
1053 else if (os_strcmp(cmd
, "NDEF") == 0)
1058 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1061 return wpas_ctrl_nfc_get_handover_req_wps(
1062 wpa_s
, reply
, max_len
, ndef
);
1066 if (os_strcmp(pos
, "P2P-CR") == 0) {
1067 return wpas_ctrl_nfc_get_handover_req_p2p(
1068 wpa_s
, reply
, max_len
, ndef
);
1070 #endif /* CONFIG_P2P */
1076 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1077 char *reply
, size_t max_len
,
1078 int ndef
, int cr
, char *uuid
)
1083 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1087 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1089 reply
[res
++] = '\n';
1099 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1100 char *reply
, size_t max_len
,
1106 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1110 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1112 reply
[res
++] = '\n';
1119 #endif /* CONFIG_P2P */
1122 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1123 char *cmd
, char *reply
,
1129 pos
= os_strchr(cmd
, ' ');
1134 if (os_strcmp(cmd
, "WPS") == 0)
1136 else if (os_strcmp(cmd
, "NDEF") == 0)
1141 pos2
= os_strchr(pos
, ' ');
1144 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1147 return wpas_ctrl_nfc_get_handover_sel_wps(
1148 wpa_s
, reply
, max_len
, ndef
,
1149 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1153 if (os_strcmp(pos
, "P2P-CR") == 0) {
1154 return wpas_ctrl_nfc_get_handover_sel_p2p(
1155 wpa_s
, reply
, max_len
, ndef
, 0);
1158 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1159 return wpas_ctrl_nfc_get_handover_sel_p2p(
1160 wpa_s
, reply
, max_len
, ndef
, 1);
1162 #endif /* CONFIG_P2P */
1168 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1172 struct wpabuf
*req
, *sel
;
1174 char *pos
, *role
, *type
, *pos2
;
1177 int forced_freq
= 0;
1179 freq
= strstr(cmd
, " freq=");
1183 forced_freq
= atoi(freq
);
1185 #endif /* CONFIG_P2P */
1188 pos
= os_strchr(role
, ' ');
1190 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1196 pos
= os_strchr(type
, ' ');
1198 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1203 pos2
= os_strchr(pos
, ' ');
1205 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1210 len
= os_strlen(pos
);
1212 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1217 req
= wpabuf_alloc(len
);
1219 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1222 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1223 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1228 len
= os_strlen(pos2
);
1230 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1236 sel
= wpabuf_alloc(len
);
1238 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1242 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1243 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1249 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1250 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1252 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1253 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1255 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1257 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1259 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1260 #endif /* CONFIG_AP */
1262 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1264 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1265 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1267 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1269 #endif /* CONFIG_P2P */
1271 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1272 "reported: role=%s type=%s", role
, type
);
1279 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1284 #endif /* CONFIG_WPS_NFC */
1287 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1296 struct wps_new_ap_settings ap
;
1298 pin
= os_strchr(cmd
, ' ');
1303 if (hwaddr_aton(cmd
, bssid
)) {
1304 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1309 new_ssid
= os_strchr(pin
, ' ');
1310 if (new_ssid
== NULL
)
1311 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1314 new_auth
= os_strchr(new_ssid
, ' ');
1315 if (new_auth
== NULL
)
1319 new_encr
= os_strchr(new_auth
, ' ');
1320 if (new_encr
== NULL
)
1324 new_key
= os_strchr(new_encr
, ' ');
1325 if (new_key
== NULL
)
1329 os_memset(&ap
, 0, sizeof(ap
));
1330 ap
.ssid_hex
= new_ssid
;
1333 ap
.key_hex
= new_key
;
1334 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1339 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1340 char *cmd
, char *buf
,
1345 const char *pin_txt
;
1347 if (!wpa_s
->ap_iface
)
1350 pos
= os_strchr(cmd
, ' ');
1354 if (os_strcmp(cmd
, "disable") == 0) {
1355 wpas_wps_ap_pin_disable(wpa_s
);
1356 return os_snprintf(buf
, buflen
, "OK\n");
1359 if (os_strcmp(cmd
, "random") == 0) {
1361 timeout
= atoi(pos
);
1362 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1363 if (pin_txt
== NULL
)
1365 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1368 if (os_strcmp(cmd
, "get") == 0) {
1369 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1370 if (pin_txt
== NULL
)
1372 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1375 if (os_strcmp(cmd
, "set") == 0) {
1380 pos
= os_strchr(pos
, ' ');
1383 timeout
= atoi(pos
);
1385 if (os_strlen(pin
) > buflen
)
1387 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1389 return os_snprintf(buf
, buflen
, "%s", pin
);
1394 #endif /* CONFIG_AP */
1397 #ifdef CONFIG_WPS_ER
1398 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1401 char *uuid
= cmd
, *pin
, *pos
;
1402 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1403 pin
= os_strchr(uuid
, ' ');
1407 pos
= os_strchr(pin
, ' ');
1410 if (hwaddr_aton(pos
, addr_buf
) == 0)
1413 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1417 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1420 char *uuid
= cmd
, *pin
;
1421 pin
= os_strchr(uuid
, ' ');
1425 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1429 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1430 struct wpa_supplicant
*wpa_s
, char *cmd
)
1432 char *uuid
= cmd
, *id
;
1433 id
= os_strchr(uuid
, ' ');
1437 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1441 static int wpa_supplicant_ctrl_iface_wps_er_config(
1442 struct wpa_supplicant
*wpa_s
, char *cmd
)
1449 struct wps_new_ap_settings ap
;
1451 pin
= os_strchr(cmd
, ' ');
1456 new_ssid
= os_strchr(pin
, ' ');
1457 if (new_ssid
== NULL
)
1461 new_auth
= os_strchr(new_ssid
, ' ');
1462 if (new_auth
== NULL
)
1466 new_encr
= os_strchr(new_auth
, ' ');
1467 if (new_encr
== NULL
)
1471 new_key
= os_strchr(new_encr
, ' ');
1472 if (new_key
== NULL
)
1476 os_memset(&ap
, 0, sizeof(ap
));
1477 ap
.ssid_hex
= new_ssid
;
1480 ap
.key_hex
= new_key
;
1481 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1485 #ifdef CONFIG_WPS_NFC
1486 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1487 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1494 uuid
= os_strchr(cmd
, ' ');
1499 if (os_strcmp(cmd
, "WPS") == 0)
1501 else if (os_strcmp(cmd
, "NDEF") == 0)
1506 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1510 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1512 reply
[res
++] = '\n';
1519 #endif /* CONFIG_WPS_NFC */
1520 #endif /* CONFIG_WPS_ER */
1522 #endif /* CONFIG_WPS */
1525 #ifdef CONFIG_IBSS_RSN
1526 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1527 struct wpa_supplicant
*wpa_s
, char *addr
)
1531 if (hwaddr_aton(addr
, peer
)) {
1532 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1533 "address '%s'", addr
);
1537 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1540 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1542 #endif /* CONFIG_IBSS_RSN */
1545 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1548 #ifdef IEEE8021X_EAPOL
1551 struct wpa_ssid
*ssid
;
1553 pos
= os_strchr(rsp
, '-');
1558 pos
= os_strchr(pos
, ':');
1563 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1564 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1565 (u8
*) pos
, os_strlen(pos
));
1567 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1569 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1574 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1576 #else /* IEEE8021X_EAPOL */
1577 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1579 #endif /* IEEE8021X_EAPOL */
1583 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1585 char *buf
, size_t buflen
)
1587 char *pos
, *end
, tmp
[30];
1588 int res
, verbose
, wps
, ret
;
1591 #endif /* CONFIG_HS20 */
1593 if (os_strcmp(params
, "-DRIVER") == 0)
1594 return wpa_drv_status(wpa_s
, buf
, buflen
);
1595 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1596 wps
= os_strcmp(params
, "-WPS") == 0;
1599 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1600 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1601 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1602 MAC2STR(wpa_s
->bssid
));
1603 if (os_snprintf_error(end
- pos
, ret
))
1606 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1608 if (os_snprintf_error(end
- pos
, ret
))
1612 u8
*_ssid
= ssid
->ssid
;
1613 size_t ssid_len
= ssid
->ssid_len
;
1614 u8 ssid_buf
[MAX_SSID_LEN
];
1615 if (ssid_len
== 0) {
1616 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1623 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1624 wpa_ssid_txt(_ssid
, ssid_len
),
1626 if (os_snprintf_error(end
- pos
, ret
))
1630 if (wps
&& ssid
->passphrase
&&
1631 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1632 (ssid
->mode
== WPAS_MODE_AP
||
1633 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1634 ret
= os_snprintf(pos
, end
- pos
,
1637 if (os_snprintf_error(end
- pos
, ret
))
1642 ret
= os_snprintf(pos
, end
- pos
,
1645 if (os_snprintf_error(end
- pos
, ret
))
1650 switch (ssid
->mode
) {
1651 case WPAS_MODE_INFRA
:
1652 ret
= os_snprintf(pos
, end
- pos
,
1655 case WPAS_MODE_IBSS
:
1656 ret
= os_snprintf(pos
, end
- pos
,
1660 ret
= os_snprintf(pos
, end
- pos
,
1663 case WPAS_MODE_P2P_GO
:
1664 ret
= os_snprintf(pos
, end
- pos
,
1667 case WPAS_MODE_P2P_GROUP_FORMATION
:
1668 ret
= os_snprintf(pos
, end
- pos
,
1669 "mode=P2P GO - group "
1676 if (os_snprintf_error(end
- pos
, ret
))
1682 if (wpa_s
->ap_iface
) {
1683 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1687 #endif /* CONFIG_AP */
1688 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1691 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1694 #endif /* CONFIG_AP */
1695 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1696 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1697 wpa_s
->sme
.sae
.group
);
1698 if (os_snprintf_error(end
- pos
, ret
))
1702 #endif /* CONFIG_SAE */
1703 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1704 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1705 if (os_snprintf_error(end
- pos
, ret
))
1710 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1711 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1712 if (os_snprintf_error(end
- pos
, ret
))
1718 if (wpa_s
->global
->p2p
) {
1719 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1720 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1721 if (os_snprintf_error(end
- pos
, ret
))
1725 #endif /* CONFIG_P2P */
1727 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1728 MAC2STR(wpa_s
->own_addr
));
1729 if (os_snprintf_error(end
- pos
, ret
))
1734 if (wpa_s
->current_bss
&&
1735 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1736 HS20_IE_VENDOR_TYPE
)) &&
1737 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1738 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1741 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
1742 release
= rel_num
+ 1;
1744 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
1745 if (os_snprintf_error(end
- pos
, ret
))
1750 if (wpa_s
->current_ssid
) {
1751 struct wpa_cred
*cred
;
1754 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1757 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1760 if (cred
->provisioning_sp
) {
1761 ret
= os_snprintf(pos
, end
- pos
,
1762 "provisioning_sp=%s\n",
1763 cred
->provisioning_sp
);
1764 if (os_snprintf_error(end
- pos
, ret
))
1773 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
1774 struct wpabuf
*names
=
1775 wpa_s
->current_bss
->anqp
->domain_name
;
1776 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
1778 if (domain_name_list_contains(
1779 names
, cred
->domain
[i
], 1))
1782 if (i
== cred
->num_domain
)
1783 i
= 0; /* show first entry by default */
1785 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
1787 if (os_snprintf_error(end
- pos
, ret
))
1792 if (wpa_s
->current_bss
== NULL
||
1793 wpa_s
->current_bss
->anqp
== NULL
)
1796 res
= interworking_home_sp_cred(
1798 wpa_s
->current_bss
->anqp
->domain_name
);
1806 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1807 if (os_snprintf_error(end
- pos
, ret
))
1814 #endif /* CONFIG_HS20 */
1816 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1817 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1818 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1824 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1831 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1832 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1833 if (os_snprintf_error(end
- pos
, ret
))
1837 #endif /* CONFIG_WPS */
1841 * Allow using the STATUS command with default behavior, say for debug,
1842 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1843 * events with STATUS-NO_EVENTS.
1845 if (os_strcmp(params
, "-NO_EVENTS")) {
1846 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1847 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1848 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1850 MAC2STR(wpa_s
->bssid
),
1851 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1852 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1853 wpa_s
->current_ssid
->ssid_len
) : "");
1854 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1855 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1856 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1857 "- connection to " MACSTR
1858 " completed %s [id=%d id_str=%s]",
1859 MAC2STR(wpa_s
->bssid
), "(auth)",
1860 ssid
? ssid
->id
: -1,
1861 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1864 #endif /* ANDROID */
1870 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1875 struct wpa_ssid
*ssid
;
1878 /* cmd: "<network id> <BSSID>" */
1879 pos
= os_strchr(cmd
, ' ');
1884 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1885 if (hwaddr_aton(pos
, bssid
)) {
1886 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1890 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1892 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1897 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1898 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1904 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1905 char *cmd
, char *buf
,
1909 struct wpa_blacklist
*e
;
1913 /* cmd: "BLACKLIST [<BSSID>]" */
1917 e
= wpa_s
->blacklist
;
1919 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1921 if (os_snprintf_error(end
- pos
, ret
))
1930 if (os_strncmp(cmd
, "clear", 5) == 0) {
1931 wpa_blacklist_clear(wpa_s
);
1932 os_memcpy(buf
, "OK\n", 3);
1936 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1937 if (hwaddr_aton(cmd
, bssid
)) {
1938 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1943 * Add the BSSID twice, so its count will be 2, causing it to be
1944 * skipped when processing scan results.
1946 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1949 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1952 os_memcpy(buf
, "OK\n", 3);
1957 static const char * debug_level_str(int level
)
1978 static int str_to_debug_level(const char *s
)
1980 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1981 return MSG_EXCESSIVE
;
1982 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1984 if (os_strcasecmp(s
, "DEBUG") == 0)
1986 if (os_strcasecmp(s
, "INFO") == 0)
1988 if (os_strcasecmp(s
, "WARNING") == 0)
1990 if (os_strcasecmp(s
, "ERROR") == 0)
1996 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1997 char *cmd
, char *buf
,
2000 char *pos
, *end
, *stamp
;
2003 /* cmd: "LOG_LEVEL [<level>]" */
2007 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2009 debug_level_str(wpa_debug_level
),
2010 wpa_debug_timestamp
);
2011 if (os_snprintf_error(end
- pos
, ret
))
2020 stamp
= os_strchr(cmd
, ' ');
2023 while (*stamp
== ' ') {
2028 if (cmd
&& os_strlen(cmd
)) {
2029 int level
= str_to_debug_level(cmd
);
2032 wpa_debug_level
= level
;
2035 if (stamp
&& os_strlen(stamp
))
2036 wpa_debug_timestamp
= atoi(stamp
);
2038 os_memcpy(buf
, "OK\n", 3);
2043 static int wpa_supplicant_ctrl_iface_list_networks(
2044 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2046 char *pos
, *end
, *prev
;
2047 struct wpa_ssid
*ssid
;
2052 ret
= os_snprintf(pos
, end
- pos
,
2053 "network id / ssid / bssid / flags\n");
2054 if (os_snprintf_error(end
- pos
, ret
))
2058 ssid
= wpa_s
->conf
->ssid
;
2060 /* skip over ssids until we find next one */
2061 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2062 int last_id
= atoi(cmd
+ 8);
2063 if (last_id
!= -1) {
2064 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2072 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2074 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2075 if (os_snprintf_error(end
- pos
, ret
))
2078 if (ssid
->bssid_set
) {
2079 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2080 MAC2STR(ssid
->bssid
));
2082 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2084 if (os_snprintf_error(end
- pos
, ret
))
2087 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2088 ssid
== wpa_s
->current_ssid
?
2090 ssid
->disabled
? "[DISABLED]" : "",
2091 ssid
->disabled_until
.sec
?
2092 "[TEMP-DISABLED]" : "",
2093 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2095 if (os_snprintf_error(end
- pos
, ret
))
2098 ret
= os_snprintf(pos
, end
- pos
, "\n");
2099 if (os_snprintf_error(end
- pos
, ret
))
2110 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2113 ret
= os_snprintf(pos
, end
- pos
, "-");
2114 if (os_snprintf_error(end
- pos
, ret
))
2117 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2125 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2126 const u8
*ie
, size_t ie_len
)
2128 struct wpa_ie_data data
;
2132 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2133 if (os_snprintf_error(end
- pos
, ret
))
2137 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2138 ret
= os_snprintf(pos
, end
- pos
, "?]");
2139 if (os_snprintf_error(end
- pos
, ret
))
2146 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2147 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2148 pos
== start
? "" : "+");
2149 if (os_snprintf_error(end
- pos
, ret
))
2153 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2154 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2155 pos
== start
? "" : "+");
2156 if (os_snprintf_error(end
- pos
, ret
))
2160 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2161 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2162 pos
== start
? "" : "+");
2163 if (os_snprintf_error(end
- pos
, ret
))
2167 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2168 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2169 pos
== start
? "" : "+");
2170 if (os_snprintf_error(end
- pos
, ret
))
2174 #ifdef CONFIG_IEEE80211R
2175 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2176 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2177 pos
== start
? "" : "+");
2178 if (os_snprintf_error(end
- pos
, ret
))
2182 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2183 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2184 pos
== start
? "" : "+");
2185 if (os_snprintf_error(end
- pos
, ret
))
2189 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2190 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2191 pos
== start
? "" : "+");
2192 if (os_snprintf_error(end
- pos
, ret
))
2196 #endif /* CONFIG_IEEE80211R */
2197 #ifdef CONFIG_IEEE80211W
2198 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2199 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2200 pos
== start
? "" : "+");
2201 if (os_snprintf_error(end
- pos
, ret
))
2205 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2206 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2207 pos
== start
? "" : "+");
2208 if (os_snprintf_error(end
- pos
, ret
))
2212 #endif /* CONFIG_IEEE80211W */
2214 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2215 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2216 pos
== start
? "" : "+");
2217 if (os_snprintf_error(end
- pos
, ret
))
2222 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2224 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2225 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2226 if (os_snprintf_error(end
- pos
, ret
))
2231 ret
= os_snprintf(pos
, end
- pos
, "]");
2232 if (os_snprintf_error(end
- pos
, ret
))
2241 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2242 char *pos
, char *end
,
2243 struct wpabuf
*wps_ie
)
2250 if (wps_is_selected_pbc_registrar(wps_ie
))
2252 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2254 else if (wps_is_selected_pin_registrar(wps_ie
))
2259 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2260 if (!os_snprintf_error(end
- pos
, ret
))
2262 wpabuf_free(wps_ie
);
2265 #endif /* CONFIG_WPS */
2268 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2269 char *pos
, char *end
,
2270 const struct wpa_bss
*bss
)
2273 struct wpabuf
*wps_ie
;
2274 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2275 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2276 #else /* CONFIG_WPS */
2278 #endif /* CONFIG_WPS */
2282 /* Format one result on one text line into a buffer. */
2283 static int wpa_supplicant_ctrl_iface_scan_result(
2284 struct wpa_supplicant
*wpa_s
,
2285 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2289 const u8
*ie
, *ie2
, *p2p
, *mesh
;
2291 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2292 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2294 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2295 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2296 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2298 return 0; /* Do not show P2P listen discovery results here */
2303 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2304 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2305 if (os_snprintf_error(end
- pos
, ret
))
2308 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2310 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2311 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2313 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2316 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2317 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2318 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2319 if (os_snprintf_error(end
- pos
, ret
))
2324 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2325 if (os_snprintf_error(end
- pos
, ret
))
2329 if (bss_is_dmg(bss
)) {
2331 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2332 if (os_snprintf_error(end
- pos
, ret
))
2335 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2336 case IEEE80211_CAP_DMG_IBSS
:
2339 case IEEE80211_CAP_DMG_AP
:
2342 case IEEE80211_CAP_DMG_PBSS
:
2349 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2350 if (os_snprintf_error(end
- pos
, ret
))
2354 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2355 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2356 if (os_snprintf_error(end
- pos
, ret
))
2360 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2361 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2362 if (os_snprintf_error(end
- pos
, ret
))
2368 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2369 if (os_snprintf_error(end
- pos
, ret
))
2374 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2375 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2376 if (os_snprintf_error(end
- pos
, ret
))
2380 #endif /* CONFIG_HS20 */
2382 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2383 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2384 if (os_snprintf_error(end
- pos
, ret
))
2388 ret
= os_snprintf(pos
, end
- pos
, "\n");
2389 if (os_snprintf_error(end
- pos
, ret
))
2397 static int wpa_supplicant_ctrl_iface_scan_results(
2398 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2401 struct wpa_bss
*bss
;
2406 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2408 if (os_snprintf_error(end
- pos
, ret
))
2412 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2413 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2415 if (ret
< 0 || ret
>= end
- pos
)
2426 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2427 struct wpa_supplicant
*wpa_s
, char *cmd
)
2430 struct wpa_ssid
*ssid
;
2433 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2435 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2437 wpa_printf(MSG_DEBUG
,
2438 "CTRL_IFACE: Could not find network id=%d", id
);
2441 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2442 wpa_printf(MSG_DEBUG
,
2443 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2446 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2447 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2448 wpa_printf(MSG_ERROR
,
2449 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2454 * TODO: If necessary write our own group_add function,
2455 * for now we can reuse select_network
2457 wpa_supplicant_select_network(wpa_s
, ssid
);
2463 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2464 struct wpa_supplicant
*wpa_s
, char *cmd
)
2467 * TODO: Support a multiple mesh and other iface type combinations
2469 if (os_strcmp(cmd
, wpa_s
->ifname
) != 0) {
2470 wpa_printf(MSG_DEBUG
,
2471 "CTRL_IFACE: MESH_GROUP_REMOVE unknown interface name: %s",
2476 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2478 wpa_s
->reassociate
= 0;
2479 wpa_s
->disconnected
= 1;
2480 wpa_supplicant_cancel_sched_scan(wpa_s
);
2481 wpa_supplicant_cancel_scan(wpa_s
);
2484 * TODO: If necessary write our own group_remove function,
2485 * for now we can reuse deauthenticate
2487 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2492 #endif /* CONFIG_MESH */
2495 static int wpa_supplicant_ctrl_iface_select_network(
2496 struct wpa_supplicant
*wpa_s
, char *cmd
)
2499 struct wpa_ssid
*ssid
;
2502 /* cmd: "<network id>" or "any" */
2503 if (os_strncmp(cmd
, "any", 3) == 0) {
2504 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2508 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2510 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2512 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2513 "network id=%d", id
);
2516 if (ssid
->disabled
== 2) {
2517 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2518 "SELECT_NETWORK with persistent P2P group");
2523 pos
= os_strstr(cmd
, " freq=");
2525 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
2527 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2528 os_free(wpa_s
->manual_scan_freqs
);
2529 wpa_s
->manual_scan_freqs
= freqs
;
2533 wpa_supplicant_select_network(wpa_s
, ssid
);
2539 static int wpa_supplicant_ctrl_iface_enable_network(
2540 struct wpa_supplicant
*wpa_s
, char *cmd
)
2543 struct wpa_ssid
*ssid
;
2545 /* cmd: "<network id>" or "all" */
2546 if (os_strcmp(cmd
, "all") == 0) {
2547 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2551 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2553 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2555 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2556 "network id=%d", id
);
2559 if (ssid
->disabled
== 2) {
2560 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2561 "ENABLE_NETWORK with persistent P2P group");
2565 if (os_strstr(cmd
, " no-connect")) {
2570 wpa_supplicant_enable_network(wpa_s
, ssid
);
2576 static int wpa_supplicant_ctrl_iface_disable_network(
2577 struct wpa_supplicant
*wpa_s
, char *cmd
)
2580 struct wpa_ssid
*ssid
;
2582 /* cmd: "<network id>" or "all" */
2583 if (os_strcmp(cmd
, "all") == 0) {
2584 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2588 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2590 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2592 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2593 "network id=%d", id
);
2596 if (ssid
->disabled
== 2) {
2597 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2598 "DISABLE_NETWORK with persistent P2P "
2603 wpa_supplicant_disable_network(wpa_s
, ssid
);
2609 static int wpa_supplicant_ctrl_iface_add_network(
2610 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2612 struct wpa_ssid
*ssid
;
2615 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2617 ssid
= wpa_config_add_network(wpa_s
->conf
);
2621 wpas_notify_network_added(wpa_s
, ssid
);
2624 wpa_config_set_network_defaults(ssid
);
2626 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2627 if (os_snprintf_error(buflen
, ret
))
2633 static int wpa_supplicant_ctrl_iface_remove_network(
2634 struct wpa_supplicant
*wpa_s
, char *cmd
)
2637 struct wpa_ssid
*ssid
;
2640 /* cmd: "<network id>" or "all" */
2641 if (os_strcmp(cmd
, "all") == 0) {
2642 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2643 if (wpa_s
->sched_scanning
)
2644 wpa_supplicant_cancel_sched_scan(wpa_s
);
2646 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2647 if (wpa_s
->current_ssid
) {
2649 wpa_s
->sme
.prev_bssid_set
= 0;
2650 #endif /* CONFIG_SME */
2651 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2652 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2653 wpa_supplicant_deauthenticate(
2654 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2656 ssid
= wpa_s
->conf
->ssid
;
2658 struct wpa_ssid
*remove_ssid
= ssid
;
2661 if (wpa_s
->last_ssid
== remove_ssid
)
2662 wpa_s
->last_ssid
= NULL
;
2663 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2664 wpa_config_remove_network(wpa_s
->conf
, id
);
2670 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2672 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2674 wpas_notify_network_removed(wpa_s
, ssid
);
2676 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2681 if (wpa_s
->last_ssid
== ssid
)
2682 wpa_s
->last_ssid
= NULL
;
2684 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2686 wpa_s
->sme
.prev_bssid_set
= 0;
2687 #endif /* CONFIG_SME */
2689 * Invalidate the EAP session cache if the current or
2690 * previously used network is removed.
2692 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2695 if (ssid
== wpa_s
->current_ssid
) {
2696 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2697 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2699 wpa_supplicant_deauthenticate(wpa_s
,
2700 WLAN_REASON_DEAUTH_LEAVING
);
2703 was_disabled
= ssid
->disabled
;
2705 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2706 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2707 "network id=%d", id
);
2711 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2712 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2713 "network from filters");
2714 wpa_supplicant_cancel_sched_scan(wpa_s
);
2715 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2722 static int wpa_supplicant_ctrl_iface_update_network(
2723 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2724 char *name
, char *value
)
2726 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2727 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2728 "variable '%s'", name
);
2732 if (os_strcmp(name
, "bssid") != 0 &&
2733 os_strcmp(name
, "priority") != 0)
2734 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2736 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2738 * Invalidate the EAP session cache if anything in the current
2739 * or previously used configuration changes.
2741 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2744 if ((os_strcmp(name
, "psk") == 0 &&
2745 value
[0] == '"' && ssid
->ssid_len
) ||
2746 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2747 wpa_config_update_psk(ssid
);
2748 else if (os_strcmp(name
, "priority") == 0)
2749 wpa_config_update_prio_list(wpa_s
->conf
);
2750 else if (os_strcmp(name
, "no_auto_peer") == 0)
2751 ssid
->no_auto_peer
= atoi(value
);
2757 static int wpa_supplicant_ctrl_iface_set_network(
2758 struct wpa_supplicant
*wpa_s
, char *cmd
)
2760 int id
, ret
, prev_bssid_set
;
2761 struct wpa_ssid
*ssid
;
2763 u8 prev_bssid
[ETH_ALEN
];
2765 /* cmd: "<network id> <variable name> <value>" */
2766 name
= os_strchr(cmd
, ' ');
2771 value
= os_strchr(name
, ' ');
2777 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2779 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2780 (u8
*) value
, os_strlen(value
));
2782 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2784 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2789 prev_bssid_set
= ssid
->bssid_set
;
2790 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
2791 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
2794 (ssid
->bssid_set
!= prev_bssid_set
||
2795 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
2796 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
2801 static int wpa_supplicant_ctrl_iface_get_network(
2802 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2806 struct wpa_ssid
*ssid
;
2809 /* cmd: "<network id> <variable name>" */
2810 name
= os_strchr(cmd
, ' ');
2811 if (name
== NULL
|| buflen
== 0)
2816 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2819 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2821 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2826 value
= wpa_config_get_no_key(ssid
, name
);
2827 if (value
== NULL
) {
2828 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2829 "variable '%s'", name
);
2833 res
= os_strlcpy(buf
, value
, buflen
);
2834 if (res
>= buflen
) {
2845 static int wpa_supplicant_ctrl_iface_dup_network(
2846 struct wpa_supplicant
*wpa_s
, char *cmd
)
2848 struct wpa_ssid
*ssid_s
, *ssid_d
;
2849 char *name
, *id
, *value
;
2850 int id_s
, id_d
, ret
;
2852 /* cmd: "<src network id> <dst network id> <variable name>" */
2853 id
= os_strchr(cmd
, ' ');
2858 name
= os_strchr(id
, ' ');
2865 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2868 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
2869 if (ssid_s
== NULL
) {
2870 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2871 "network id=%d", id_s
);
2875 ssid_d
= wpa_config_get_network(wpa_s
->conf
, id_d
);
2876 if (ssid_d
== NULL
) {
2877 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2878 "network id=%d", id_d
);
2882 value
= wpa_config_get(ssid_s
, name
);
2883 if (value
== NULL
) {
2884 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2885 "variable '%s'", name
);
2889 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid_d
, name
,
2898 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2899 char *buf
, size_t buflen
)
2902 struct wpa_cred
*cred
;
2907 ret
= os_snprintf(pos
, end
- pos
,
2908 "cred id / realm / username / domain / imsi\n");
2909 if (os_snprintf_error(end
- pos
, ret
))
2913 cred
= wpa_s
->conf
->cred
;
2915 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2916 cred
->id
, cred
->realm
? cred
->realm
: "",
2917 cred
->username
? cred
->username
: "",
2918 cred
->domain
? cred
->domain
[0] : "",
2919 cred
->imsi
? cred
->imsi
: "");
2920 if (os_snprintf_error(end
- pos
, ret
))
2931 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2932 char *buf
, size_t buflen
)
2934 struct wpa_cred
*cred
;
2937 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2939 cred
= wpa_config_add_cred(wpa_s
->conf
);
2943 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
2945 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2946 if (os_snprintf_error(buflen
, ret
))
2952 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
2953 struct wpa_cred
*cred
)
2955 struct wpa_ssid
*ssid
;
2960 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2965 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
2966 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2970 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
2972 /* Remove any network entry created based on the removed credential */
2973 ssid
= wpa_s
->conf
->ssid
;
2975 if (ssid
->parent_cred
== cred
) {
2978 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
2979 "used the removed credential", ssid
->id
);
2980 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
2981 if (os_snprintf_error(sizeof(str
), res
))
2982 str
[sizeof(str
) - 1] = '\0';
2984 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
2993 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
2997 struct wpa_cred
*cred
, *prev
;
2999 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3000 * "provisioning_sp=<FQDN> */
3001 if (os_strcmp(cmd
, "all") == 0) {
3002 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3003 cred
= wpa_s
->conf
->cred
;
3007 wpas_ctrl_remove_cred(wpa_s
, prev
);
3012 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3013 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3015 cred
= wpa_s
->conf
->cred
;
3021 for (i
= 0; i
< prev
->num_domain
; i
++) {
3022 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3025 wpas_ctrl_remove_cred(wpa_s
, prev
);
3033 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3034 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3036 cred
= wpa_s
->conf
->cred
;
3040 if (prev
->provisioning_sp
&&
3041 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3042 wpas_ctrl_remove_cred(wpa_s
, prev
);
3048 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3050 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3051 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3055 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3059 struct wpa_cred
*cred
;
3062 /* cmd: "<cred id> <variable name> <value>" */
3063 name
= os_strchr(cmd
, ' ');
3068 value
= os_strchr(name
, ' ');
3074 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3076 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3077 (u8
*) value
, os_strlen(value
));
3079 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3081 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3086 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3087 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3088 "variable '%s'", name
);
3092 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3098 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3099 char *cmd
, char *buf
,
3104 struct wpa_cred
*cred
;
3107 /* cmd: "<cred id> <variable name>" */
3108 name
= os_strchr(cmd
, ' ');
3114 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3117 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3119 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3124 value
= wpa_config_get_cred_no_key(cred
, name
);
3125 if (value
== NULL
) {
3126 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3131 res
= os_strlcpy(buf
, value
, buflen
);
3132 if (res
>= buflen
) {
3143 #ifndef CONFIG_NO_CONFIG_WRITE
3144 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3148 if (!wpa_s
->conf
->update_config
) {
3149 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3150 "to update configuration (update_config=0)");
3154 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3156 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3157 "update configuration");
3159 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3165 #endif /* CONFIG_NO_CONFIG_WRITE */
3168 struct cipher_info
{
3174 static const struct cipher_info ciphers
[] = {
3175 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3176 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3177 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3178 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3179 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3180 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3181 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3182 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3186 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3187 struct wpa_driver_capa
*capa
,
3188 char *buf
, size_t buflen
)
3201 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3207 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3208 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3209 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3210 pos
== buf
? "" : " ",
3212 if (os_snprintf_error(end
- pos
, ret
))
3222 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3223 struct wpa_driver_capa
*capa
,
3224 char *buf
, size_t buflen
)
3237 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3243 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3244 if (capa
->enc
& ciphers
[i
].capa
) {
3245 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3246 pos
== buf
? "" : " ",
3248 if (os_snprintf_error(end
- pos
, ret
))
3258 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3259 struct wpa_driver_capa
*capa
,
3260 char *buf
, size_t buflen
)
3272 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3279 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3280 if (os_snprintf_error(end
- pos
, ret
))
3284 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3285 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3286 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3287 if (os_snprintf_error(end
- pos
, ret
))
3292 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3293 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3294 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3295 if (os_snprintf_error(end
- pos
, ret
))
3300 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3301 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3302 if (os_snprintf_error(end
- pos
, ret
))
3311 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3312 struct wpa_driver_capa
*capa
,
3313 char *buf
, size_t buflen
)
3325 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3331 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3332 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3333 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3334 pos
== buf
? "" : " ");
3335 if (os_snprintf_error(end
- pos
, ret
))
3340 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3341 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3342 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3343 pos
== buf
? "" : " ");
3344 if (os_snprintf_error(end
- pos
, ret
))
3353 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
3354 struct wpa_driver_capa
*capa
,
3355 char *buf
, size_t buflen
)
3367 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3373 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3374 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3375 pos
== buf
? "" : " ");
3376 if (os_snprintf_error(end
- pos
, ret
))
3381 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3382 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3383 pos
== buf
? "" : " ");
3384 if (os_snprintf_error(end
- pos
, ret
))
3389 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3390 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3391 pos
== buf
? "" : " ");
3392 if (os_snprintf_error(end
- pos
, ret
))
3401 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3402 struct wpa_driver_capa
*capa
,
3403 char *buf
, size_t buflen
)
3415 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3421 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3422 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3423 pos
== buf
? "" : " ");
3424 if (os_snprintf_error(end
- pos
, ret
))
3429 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3430 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3431 pos
== buf
? "" : " ");
3432 if (os_snprintf_error(end
- pos
, ret
))
3441 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3442 char *buf
, size_t buflen
)
3444 struct hostapd_channel_data
*chnl
;
3446 char *pos
, *end
, *hmode
;
3451 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3452 switch (wpa_s
->hw
.modes
[j
].mode
) {
3453 case HOSTAPD_MODE_IEEE80211B
:
3456 case HOSTAPD_MODE_IEEE80211G
:
3459 case HOSTAPD_MODE_IEEE80211A
:
3462 case HOSTAPD_MODE_IEEE80211AD
:
3468 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3469 if (os_snprintf_error(end
- pos
, ret
))
3472 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3473 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3474 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3476 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3477 if (os_snprintf_error(end
- pos
, ret
))
3481 ret
= os_snprintf(pos
, end
- pos
, "\n");
3482 if (os_snprintf_error(end
- pos
, ret
))
3491 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3492 char *buf
, size_t buflen
)
3494 struct hostapd_channel_data
*chnl
;
3496 char *pos
, *end
, *hmode
;
3501 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3502 switch (wpa_s
->hw
.modes
[j
].mode
) {
3503 case HOSTAPD_MODE_IEEE80211B
:
3506 case HOSTAPD_MODE_IEEE80211G
:
3509 case HOSTAPD_MODE_IEEE80211A
:
3512 case HOSTAPD_MODE_IEEE80211AD
:
3518 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3520 if (os_snprintf_error(end
- pos
, ret
))
3523 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3524 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3525 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3527 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
3528 chnl
[i
].chan
, chnl
[i
].freq
,
3529 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
3531 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
3534 if (os_snprintf_error(end
- pos
, ret
))
3538 ret
= os_snprintf(pos
, end
- pos
, "\n");
3539 if (os_snprintf_error(end
- pos
, ret
))
3548 static int wpa_supplicant_ctrl_iface_get_capability(
3549 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3552 struct wpa_driver_capa capa
;
3558 /* Determine whether or not strict checking was requested */
3559 len
= os_strlcpy(field
, _field
, sizeof(field
));
3560 if (len
>= sizeof(field
))
3562 strict
= os_strchr(field
, ' ');
3563 if (strict
!= NULL
) {
3565 if (os_strcmp(strict
, "strict") != 0)
3569 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3570 field
, strict
? strict
: "");
3572 if (os_strcmp(field
, "eap") == 0) {
3573 return eap_get_names(buf
, buflen
);
3576 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3578 if (os_strcmp(field
, "pairwise") == 0)
3579 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3582 if (os_strcmp(field
, "group") == 0)
3583 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3586 if (os_strcmp(field
, "key_mgmt") == 0)
3587 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3590 if (os_strcmp(field
, "proto") == 0)
3591 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3594 if (os_strcmp(field
, "auth_alg") == 0)
3595 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3598 if (os_strcmp(field
, "modes") == 0)
3599 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3602 if (os_strcmp(field
, "channels") == 0)
3603 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3605 if (os_strcmp(field
, "freq") == 0)
3606 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3609 if (os_strcmp(field
, "tdls") == 0)
3610 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
3611 #endif /* CONFIG_TDLS */
3614 if (os_strcmp(field
, "erp") == 0) {
3615 res
= os_snprintf(buf
, buflen
, "ERP");
3616 if (os_snprintf_error(buflen
, res
))
3620 #endif /* CONFIG_EPR */
3622 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3629 #ifdef CONFIG_INTERWORKING
3630 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3631 struct wpabuf
*data
)
3641 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3642 if (os_snprintf_error(end
- pos
, ret
))
3646 d
= wpabuf_head_u8(data
);
3647 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3648 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3649 if (os_snprintf_error(end
- pos
, ret
))
3654 ret
= os_snprintf(pos
, end
- pos
, "\n");
3655 if (os_snprintf_error(end
- pos
, ret
))
3661 #endif /* CONFIG_INTERWORKING */
3664 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3665 unsigned long mask
, char *buf
, size_t buflen
)
3675 if (mask
& WPA_BSS_MASK_ID
) {
3676 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3677 if (os_snprintf_error(end
- pos
, ret
))
3682 if (mask
& WPA_BSS_MASK_BSSID
) {
3683 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3684 MAC2STR(bss
->bssid
));
3685 if (os_snprintf_error(end
- pos
, ret
))
3690 if (mask
& WPA_BSS_MASK_FREQ
) {
3691 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3692 if (os_snprintf_error(end
- pos
, ret
))
3697 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3698 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3700 if (os_snprintf_error(end
- pos
, ret
))
3705 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3706 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3708 if (os_snprintf_error(end
- pos
, ret
))
3713 if (mask
& WPA_BSS_MASK_QUAL
) {
3714 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3715 if (os_snprintf_error(end
- pos
, ret
))
3720 if (mask
& WPA_BSS_MASK_NOISE
) {
3721 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3722 if (os_snprintf_error(end
- pos
, ret
))
3727 if (mask
& WPA_BSS_MASK_LEVEL
) {
3728 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3729 if (os_snprintf_error(end
- pos
, ret
))
3734 if (mask
& WPA_BSS_MASK_TSF
) {
3735 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3736 (unsigned long long) bss
->tsf
);
3737 if (os_snprintf_error(end
- pos
, ret
))
3742 if (mask
& WPA_BSS_MASK_AGE
) {
3743 struct os_reltime now
;
3745 os_get_reltime(&now
);
3746 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3747 (int) (now
.sec
- bss
->last_update
.sec
));
3748 if (os_snprintf_error(end
- pos
, ret
))
3753 if (mask
& WPA_BSS_MASK_IE
) {
3754 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3755 if (os_snprintf_error(end
- pos
, ret
))
3759 ie
= (const u8
*) (bss
+ 1);
3760 for (i
= 0; i
< bss
->ie_len
; i
++) {
3761 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3762 if (os_snprintf_error(end
- pos
, ret
))
3767 ret
= os_snprintf(pos
, end
- pos
, "\n");
3768 if (os_snprintf_error(end
- pos
, ret
))
3773 if (mask
& WPA_BSS_MASK_FLAGS
) {
3774 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3775 if (os_snprintf_error(end
- pos
, ret
))
3779 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3781 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3783 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3785 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3787 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3788 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3789 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3790 if (os_snprintf_error(end
- pos
, ret
))
3794 if (bss_is_dmg(bss
)) {
3796 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
3797 if (os_snprintf_error(end
- pos
, ret
))
3800 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
3801 case IEEE80211_CAP_DMG_IBSS
:
3804 case IEEE80211_CAP_DMG_AP
:
3807 case IEEE80211_CAP_DMG_PBSS
:
3814 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
3815 if (os_snprintf_error(end
- pos
, ret
))
3819 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3820 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3821 if (os_snprintf_error(end
- pos
, ret
))
3825 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3826 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3827 if (os_snprintf_error(end
- pos
, ret
))
3832 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3833 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3834 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3835 if (os_snprintf_error(end
- pos
, ret
))
3840 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3841 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3842 if (os_snprintf_error(end
- pos
, ret
))
3846 #endif /* CONFIG_HS20 */
3848 ret
= os_snprintf(pos
, end
- pos
, "\n");
3849 if (os_snprintf_error(end
- pos
, ret
))
3854 if (mask
& WPA_BSS_MASK_SSID
) {
3855 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3856 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3857 if (os_snprintf_error(end
- pos
, ret
))
3863 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3864 ie
= (const u8
*) (bss
+ 1);
3865 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3866 if (ret
< 0 || ret
>= end
- pos
)
3870 #endif /* CONFIG_WPS */
3873 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3874 ie
= (const u8
*) (bss
+ 1);
3875 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3876 if (ret
< 0 || ret
>= end
- pos
)
3880 #endif /* CONFIG_P2P */
3882 #ifdef CONFIG_WIFI_DISPLAY
3883 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3885 ie
= (const u8
*) (bss
+ 1);
3886 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3887 WFD_IE_VENDOR_TYPE
);
3889 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3890 if (os_snprintf_error(end
- pos
, ret
)) {
3896 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3901 ret
= os_snprintf(pos
, end
- pos
, "\n");
3902 if (os_snprintf_error(end
- pos
, ret
))
3907 #endif /* CONFIG_WIFI_DISPLAY */
3909 #ifdef CONFIG_INTERWORKING
3910 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3911 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3912 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3914 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3915 anqp
->network_auth_type
);
3916 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3917 anqp
->roaming_consortium
);
3918 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3919 anqp
->ip_addr_type_availability
);
3920 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3922 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3923 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3926 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3927 anqp
->hs20_operator_friendly_name
);
3928 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3929 anqp
->hs20_wan_metrics
);
3930 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3931 anqp
->hs20_connection_capability
);
3932 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
3933 anqp
->hs20_operating_class
);
3934 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
3935 anqp
->hs20_osu_providers_list
);
3936 #endif /* CONFIG_HS20 */
3938 #endif /* CONFIG_INTERWORKING */
3941 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
3942 ie
= (const u8
*) (bss
+ 1);
3943 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3944 if (ret
< 0 || ret
>= end
- pos
)
3948 #endif /* CONFIG_MESH */
3950 if (mask
& WPA_BSS_MASK_DELIM
) {
3951 ret
= os_snprintf(pos
, end
- pos
, "====\n");
3952 if (os_snprintf_error(end
- pos
, ret
))
3961 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
3962 const char *cmd
, char *buf
,
3967 struct wpa_bss
*bss
;
3968 struct wpa_bss
*bsslast
= NULL
;
3969 struct dl_list
*next
;
3972 char *ctmp
, *end
= buf
+ buflen
;
3973 unsigned long mask
= WPA_BSS_MASK_ALL
;
3975 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
3976 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
3977 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
3979 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
3981 } else { /* N1-N2 */
3982 unsigned int id1
, id2
;
3984 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
3985 wpa_printf(MSG_INFO
, "Wrong BSS range "
3990 if (*(cmd
+ 6) == '-')
3993 id1
= atoi(cmd
+ 6);
3995 if (*ctmp
>= '0' && *ctmp
<= '9')
3998 id2
= (unsigned int) -1;
3999 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4000 if (id2
== (unsigned int) -1)
4001 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4005 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4006 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4007 struct wpa_bss
*tmp
= bss
;
4009 next
= tmp
->list_id
.next
;
4010 if (next
== &wpa_s
->bss_id
)
4012 tmp
= dl_list_entry(
4013 next
, struct wpa_bss
,
4022 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4023 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4024 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4025 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4026 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4028 bss
= wpa_bss_get_id(wpa_s
, i
);
4029 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4031 bss
= wpa_bss_get_id(wpa_s
, i
);
4033 next
= bss
->list_id
.next
;
4034 if (next
== &wpa_s
->bss_id
)
4037 bss
= dl_list_entry(next
, struct wpa_bss
,
4041 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4042 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4043 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4046 #endif /* CONFIG_P2P */
4047 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4048 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4050 struct wpa_bss
*tmp
;
4053 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4062 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4063 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4065 mask
= WPA_BSS_MASK_ALL
;
4071 if (bsslast
== NULL
)
4074 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4078 if (bss
== bsslast
) {
4079 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4080 (bss
== dl_list_last(&wpa_s
->bss_id
,
4081 struct wpa_bss
, list_id
))) {
4084 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4086 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4087 wpa_printf(MSG_DEBUG
,
4088 "Could not add end delim");
4093 next
= bss
->list_id
.next
;
4094 if (next
== &wpa_s
->bss_id
)
4096 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4097 } while (bss
&& len
);
4103 static int wpa_supplicant_ctrl_iface_ap_scan(
4104 struct wpa_supplicant
*wpa_s
, char *cmd
)
4106 int ap_scan
= atoi(cmd
);
4107 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4111 static int wpa_supplicant_ctrl_iface_scan_interval(
4112 struct wpa_supplicant
*wpa_s
, char *cmd
)
4114 int scan_int
= atoi(cmd
);
4115 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4119 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4120 struct wpa_supplicant
*wpa_s
, char *cmd
)
4122 int expire_age
= atoi(cmd
);
4123 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4127 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4128 struct wpa_supplicant
*wpa_s
, char *cmd
)
4130 int expire_count
= atoi(cmd
);
4131 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4135 static void wpa_supplicant_ctrl_iface_bss_flush(
4136 struct wpa_supplicant
*wpa_s
, char *cmd
)
4138 int flush_age
= atoi(cmd
);
4141 wpa_bss_flush(wpa_s
);
4143 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4147 #ifdef CONFIG_TESTING_OPTIONS
4148 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4150 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4151 /* MLME-DELETEKEYS.request */
4152 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4153 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4154 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4155 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4156 #ifdef CONFIG_IEEE80211W
4157 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4158 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4159 #endif /* CONFIG_IEEE80211W */
4161 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4163 /* MLME-SETPROTECTION.request(None) */
4164 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4165 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4166 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4167 wpa_sm_drop_sa(wpa_s
->wpa
);
4169 #endif /* CONFIG_TESTING_OPTIONS */
4172 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4175 #ifdef CONFIG_NO_SCAN_PROCESSING
4177 #else /* CONFIG_NO_SCAN_PROCESSING */
4179 struct wpa_bss
*bss
;
4180 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4182 if (hwaddr_aton(addr
, bssid
)) {
4183 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4184 "address '%s'", addr
);
4188 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4191 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4192 "configuration known for the target AP");
4196 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4198 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4204 * TODO: Find best network configuration block from configuration to
4205 * allow roaming to other networks
4208 wpa_s
->reassociate
= 1;
4209 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4212 #endif /* CONFIG_NO_SCAN_PROCESSING */
4217 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
4219 unsigned int timeout
= atoi(cmd
);
4220 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
4221 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
4222 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
4224 unsigned int search_delay
;
4226 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4227 wpa_dbg(wpa_s
, MSG_INFO
,
4228 "Reject P2P_FIND since interface is disabled");
4231 if (os_strstr(cmd
, "type=social"))
4232 type
= P2P_FIND_ONLY_SOCIAL
;
4233 else if (os_strstr(cmd
, "type=progressive"))
4234 type
= P2P_FIND_PROGRESSIVE
;
4236 pos
= os_strstr(cmd
, "dev_id=");
4239 if (hwaddr_aton(pos
, dev_id
))
4244 pos
= os_strstr(cmd
, "dev_type=");
4247 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
4249 _dev_type
= dev_type
;
4252 pos
= os_strstr(cmd
, "delay=");
4255 search_delay
= atoi(pos
);
4257 search_delay
= wpas_p2p_search_delay(wpa_s
);
4259 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
4260 _dev_id
, search_delay
);
4264 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
4265 char *buf
, size_t buflen
)
4270 enum p2p_wps_method wps_method
;
4273 int persistent_group
, persistent_id
= -1;
4282 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4283 * [persistent|persistent=<network id>]
4284 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4287 if (hwaddr_aton(cmd
, addr
))
4295 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
4296 pos2
= os_strstr(pos
, " persistent=");
4298 struct wpa_ssid
*ssid
;
4299 persistent_id
= atoi(pos2
+ 12);
4300 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
4301 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
4302 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
4303 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
4304 "SSID id=%d for persistent P2P group (GO)",
4309 join
= os_strstr(pos
, " join") != NULL
;
4310 auth
= os_strstr(pos
, " auth") != NULL
;
4311 automatic
= os_strstr(pos
, " auto") != NULL
;
4312 pd
= os_strstr(pos
, " provdisc") != NULL
;
4313 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4314 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4317 pos2
= os_strstr(pos
, " go_intent=");
4320 go_intent
= atoi(pos2
);
4321 if (go_intent
< 0 || go_intent
> 15)
4325 pos2
= os_strstr(pos
, " freq=");
4333 if (os_strncmp(pos
, "pin", 3) == 0) {
4334 /* Request random PIN (to be displayed) and enable the PIN */
4335 wps_method
= WPS_PIN_DISPLAY
;
4336 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
4337 wps_method
= WPS_PBC
;
4340 pos
= os_strchr(pin
, ' ');
4341 wps_method
= WPS_PIN_KEYPAD
;
4344 if (os_strncmp(pos
, "display", 7) == 0)
4345 wps_method
= WPS_PIN_DISPLAY
;
4347 if (!wps_pin_str_valid(pin
)) {
4348 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
4353 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
4354 persistent_group
, automatic
, join
,
4355 auth
, go_intent
, freq
, persistent_id
, pd
,
4357 if (new_pin
== -2) {
4358 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4361 if (new_pin
== -3) {
4362 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4367 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
4368 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
4369 if (os_snprintf_error(buflen
, ret
))
4374 os_memcpy(buf
, "OK\n", 3);
4379 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4381 unsigned int timeout
= atoi(cmd
);
4382 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4383 wpa_dbg(wpa_s
, MSG_INFO
,
4384 "Reject P2P_LISTEN since interface is disabled");
4387 return wpas_p2p_listen(wpa_s
, timeout
);
4391 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
4395 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
4397 /* <addr> <config method> [join|auto] */
4399 if (hwaddr_aton(cmd
, addr
))
4407 if (os_strstr(pos
, " join") != NULL
)
4408 use
= WPAS_P2P_PD_FOR_JOIN
;
4409 else if (os_strstr(pos
, " auto") != NULL
)
4410 use
= WPAS_P2P_PD_AUTO
;
4412 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
4416 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
4419 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4421 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
4422 ssid
->passphrase
== NULL
)
4425 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
4426 return os_strlen(buf
);
4430 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
4431 char *buf
, size_t buflen
)
4435 u8 dst_buf
[ETH_ALEN
], *dst
;
4436 struct wpabuf
*tlvs
;
4440 if (hwaddr_aton(cmd
, dst_buf
))
4443 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
4444 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
4451 if (os_strncmp(pos
, "upnp ", 5) == 0) {
4454 if (hexstr2bin(pos
, &version
, 1) < 0)
4460 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
4461 #ifdef CONFIG_WIFI_DISPLAY
4462 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
4463 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
4464 #endif /* CONFIG_WIFI_DISPLAY */
4466 len
= os_strlen(pos
);
4470 tlvs
= wpabuf_alloc(len
);
4473 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
4478 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
4483 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
4484 if (os_snprintf_error(buflen
, res
))
4490 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
4493 long long unsigned val
;
4495 if (sscanf(cmd
, "%llx", &val
) != 1)
4498 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
4502 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4507 struct wpabuf
*resp_tlvs
;
4511 pos
= os_strchr(cmd
, ' ');
4519 if (hwaddr_aton(pos
, dst
))
4526 pos2
= os_strchr(pos
, ' ');
4530 dialog_token
= atoi(pos
);
4532 len
= os_strlen(pos2
);
4536 resp_tlvs
= wpabuf_alloc(len
);
4537 if (resp_tlvs
== NULL
)
4539 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
4540 wpabuf_free(resp_tlvs
);
4544 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
4545 wpabuf_free(resp_tlvs
);
4550 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
4553 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
4555 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
4560 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
4565 struct wpabuf
*query
, *resp
;
4567 pos
= os_strchr(cmd
, ' ');
4572 len
= os_strlen(cmd
);
4576 query
= wpabuf_alloc(len
);
4579 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4584 len
= os_strlen(pos
);
4590 resp
= wpabuf_alloc(len
);
4595 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4601 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4610 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4615 pos
= os_strchr(cmd
, ' ');
4620 if (hexstr2bin(cmd
, &version
, 1) < 0)
4623 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4627 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4631 pos
= os_strchr(cmd
, ' ');
4636 if (os_strcmp(cmd
, "bonjour") == 0)
4637 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4638 if (os_strcmp(cmd
, "upnp") == 0)
4639 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4640 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4645 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4649 struct wpabuf
*query
;
4652 len
= os_strlen(cmd
);
4656 query
= wpabuf_alloc(len
);
4659 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4664 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4670 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4675 pos
= os_strchr(cmd
, ' ');
4680 if (hexstr2bin(cmd
, &version
, 1) < 0)
4683 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4687 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4691 pos
= os_strchr(cmd
, ' ');
4696 if (os_strcmp(cmd
, "bonjour") == 0)
4697 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4698 if (os_strcmp(cmd
, "upnp") == 0)
4699 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4700 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4705 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4711 if (hwaddr_aton(cmd
, addr
))
4714 return wpas_p2p_reject(wpa_s
, addr
);
4718 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4722 struct wpa_ssid
*ssid
;
4723 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4724 int freq
= 0, pref_freq
= 0;
4728 pos
= os_strstr(cmd
, " peer=");
4731 if (hwaddr_aton(pos
, peer
))
4735 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4736 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4737 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4738 "for persistent P2P group",
4743 pos
= os_strstr(cmd
, " freq=");
4751 pos
= os_strstr(cmd
, " pref=");
4754 pref_freq
= atoi(pos
);
4759 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4760 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4763 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4768 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4771 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4773 pos
= os_strstr(cmd
, " peer=");
4779 if (hwaddr_aton(pos
, peer
)) {
4780 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4784 pos
= os_strstr(pos
, " go_dev_addr=");
4787 if (hwaddr_aton(pos
, go_dev_addr
)) {
4788 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4792 go_dev
= go_dev_addr
;
4795 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4799 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4801 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4802 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4803 if (os_strncmp(cmd
, "group=", 6) == 0)
4804 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4810 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4811 char *cmd
, int freq
, int ht40
,
4815 struct wpa_ssid
*ssid
;
4818 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4819 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4820 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4821 "for persistent P2P group",
4826 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, 0, ht40
, vht
,
4831 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4833 int freq
= 0, ht40
, vht
;
4836 pos
= os_strstr(cmd
, "freq=");
4838 freq
= atoi(pos
+ 5);
4840 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4841 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4844 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4845 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4847 if (os_strcmp(cmd
, "persistent") == 0 ||
4848 os_strncmp(cmd
, "persistent ", 11) == 0)
4849 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4850 if (os_strncmp(cmd
, "freq=", 5) == 0)
4851 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4853 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4855 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4861 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4862 char *buf
, size_t buflen
)
4864 u8 addr
[ETH_ALEN
], *addr_ptr
;
4866 const struct p2p_peer_info
*info
;
4868 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4869 struct wpa_ssid
*ssid
;
4872 if (!wpa_s
->global
->p2p
)
4875 if (os_strcmp(cmd
, "FIRST") == 0) {
4878 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4879 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4884 if (hwaddr_aton(cmd
, addr
) < 0)
4890 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4897 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4903 "serial_number=%s\n"
4904 "config_methods=0x%x\n"
4906 "group_capab=0x%x\n"
4908 MAC2STR(info
->p2p_device_addr
),
4909 wps_dev_type_bin2str(info
->pri_dev_type
,
4910 devtype
, sizeof(devtype
)),
4915 info
->serial_number
,
4916 info
->config_methods
,
4920 if (os_snprintf_error(end
- pos
, res
))
4924 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4927 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4928 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4929 wps_dev_type_bin2str(t
, devtype
,
4931 if (os_snprintf_error(end
- pos
, res
))
4936 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4938 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4939 if (os_snprintf_error(end
- pos
, res
))
4944 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4949 if (info
->vendor_elems
) {
4950 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
4951 if (os_snprintf_error(end
- pos
, res
))
4955 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4956 wpabuf_head(info
->vendor_elems
),
4957 wpabuf_len(info
->vendor_elems
));
4959 res
= os_snprintf(pos
, end
- pos
, "\n");
4960 if (os_snprintf_error(end
- pos
, res
))
4969 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
4974 if (wpa_s
->global
->p2p
== NULL
)
4977 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
4980 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
4981 struct wpa_freq_range
*freq
;
4982 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
4983 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
4984 freq
->min
, freq
->max
);
4987 wpas_p2p_update_channel_list(wpa_s
);
4992 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
4996 if (wpa_s
->global
->p2p
== NULL
)
4999 param
= os_strchr(cmd
, ' ');
5004 if (os_strcmp(cmd
, "discoverability") == 0) {
5005 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
5010 if (os_strcmp(cmd
, "managed") == 0) {
5011 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
5015 if (os_strcmp(cmd
, "listen_channel") == 0) {
5016 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
5020 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
5021 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
5025 if (os_strcmp(cmd
, "noa") == 0) {
5027 int count
, start
, duration
;
5028 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
5029 count
= atoi(param
);
5030 pos
= os_strchr(param
, ',');
5035 pos
= os_strchr(pos
, ',');
5039 duration
= atoi(pos
);
5040 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
5042 if (count
== 0 && duration
> 0)
5044 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
5045 "start=%d duration=%d", count
, start
, duration
);
5046 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
5049 if (os_strcmp(cmd
, "ps") == 0)
5050 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
5052 if (os_strcmp(cmd
, "oppps") == 0)
5053 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
5055 if (os_strcmp(cmd
, "ctwindow") == 0)
5056 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
5058 if (os_strcmp(cmd
, "disabled") == 0) {
5059 wpa_s
->global
->p2p_disabled
= atoi(param
);
5060 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
5061 wpa_s
->global
->p2p_disabled
?
5062 "disabled" : "enabled");
5063 if (wpa_s
->global
->p2p_disabled
) {
5064 wpas_p2p_stop_find(wpa_s
);
5065 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5066 p2p_flush(wpa_s
->global
->p2p
);
5071 if (os_strcmp(cmd
, "conc_pref") == 0) {
5072 if (os_strcmp(param
, "sta") == 0)
5073 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
5074 else if (os_strcmp(param
, "p2p") == 0)
5075 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
5077 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
5080 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
5085 if (os_strcmp(cmd
, "force_long_sd") == 0) {
5086 wpa_s
->force_long_sd
= atoi(param
);
5090 if (os_strcmp(cmd
, "peer_filter") == 0) {
5092 if (hwaddr_aton(param
, addr
))
5094 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
5098 if (os_strcmp(cmd
, "cross_connect") == 0)
5099 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
5101 if (os_strcmp(cmd
, "go_apsd") == 0) {
5102 if (os_strcmp(param
, "disable") == 0)
5103 wpa_s
->set_ap_uapsd
= 0;
5105 wpa_s
->set_ap_uapsd
= 1;
5106 wpa_s
->ap_uapsd
= atoi(param
);
5111 if (os_strcmp(cmd
, "client_apsd") == 0) {
5112 if (os_strcmp(param
, "disable") == 0)
5113 wpa_s
->set_sta_uapsd
= 0;
5117 /* format: BE,BK,VI,VO;max SP Length */
5119 pos
= os_strchr(param
, ',');
5124 pos
= os_strchr(pos
, ',');
5129 pos
= os_strchr(pos
, ',');
5134 /* ignore max SP Length for now */
5136 wpa_s
->set_sta_uapsd
= 1;
5137 wpa_s
->sta_uapsd
= 0;
5139 wpa_s
->sta_uapsd
|= BIT(0);
5141 wpa_s
->sta_uapsd
|= BIT(1);
5143 wpa_s
->sta_uapsd
|= BIT(2);
5145 wpa_s
->sta_uapsd
|= BIT(3);
5150 if (os_strcmp(cmd
, "disallow_freq") == 0)
5151 return p2p_ctrl_disallow_freq(wpa_s
, param
);
5153 if (os_strcmp(cmd
, "disc_int") == 0) {
5154 int min_disc_int
, max_disc_int
, max_disc_tu
;
5159 min_disc_int
= atoi(pos
);
5160 pos
= os_strchr(pos
, ' ');
5165 max_disc_int
= atoi(pos
);
5166 pos
= os_strchr(pos
, ' ');
5171 max_disc_tu
= atoi(pos
);
5173 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
5174 max_disc_int
, max_disc_tu
);
5177 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
5178 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
5182 #ifdef CONFIG_WPS_NFC
5183 if (os_strcmp(cmd
, "nfc_tag") == 0)
5184 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
5185 #endif /* CONFIG_WPS_NFC */
5187 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
5188 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
5192 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5199 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
5201 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5202 wpa_s
->force_long_sd
= 0;
5203 wpas_p2p_stop_find(wpa_s
);
5204 if (wpa_s
->global
->p2p
)
5205 p2p_flush(wpa_s
->global
->p2p
);
5209 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
5212 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
5215 pos
= os_strchr(cmd
, ' ');
5221 pos2
= os_strchr(pos
, ' ');
5229 pos
= os_strchr(pos2
, ' ');
5237 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
5241 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5244 unsigned int period
= 0, interval
= 0;
5247 pos
= os_strchr(cmd
, ' ');
5252 interval
= atoi(pos
);
5255 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
5259 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
5266 if (os_strncmp(pos
, "iface=", 6) == 0) {
5270 if (hwaddr_aton(pos
, peer
))
5273 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
5277 #endif /* CONFIG_P2P */
5280 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
5282 struct wpa_freq_range_list ranges
;
5284 struct hostapd_hw_modes
*mode
;
5287 if (wpa_s
->hw
.modes
== NULL
)
5290 os_memset(&ranges
, 0, sizeof(ranges
));
5291 if (freq_range_list_parse(&ranges
, val
) < 0)
5294 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
5297 mode
= &wpa_s
->hw
.modes
[i
];
5298 for (j
= 0; j
< mode
->num_channels
; j
++) {
5301 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
5304 freq
= mode
->channels
[j
].freq
;
5305 if (!freq_range_list_includes(&ranges
, freq
))
5308 int_array_add_unique(&freqs
, freq
);
5312 os_free(ranges
.range
);
5317 #ifdef CONFIG_INTERWORKING
5319 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
5327 auto_sel
= os_strstr(param
, "auto") != NULL
;
5329 pos
= os_strstr(param
, "freq=");
5331 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
5338 return interworking_select(wpa_s
, auto_sel
, freqs
);
5342 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
5345 struct wpa_bss
*bss
;
5347 if (hwaddr_aton(dst
, bssid
)) {
5348 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
5352 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5354 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
5359 return interworking_connect(wpa_s
, bss
);
5363 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5365 u8 dst_addr
[ETH_ALEN
];
5368 #define MAX_ANQP_INFO_ID 100
5369 u16 id
[MAX_ANQP_INFO_ID
];
5373 used
= hwaddr_aton2(dst
, dst_addr
);
5379 while (num_id
< MAX_ANQP_INFO_ID
) {
5380 if (os_strncmp(pos
, "hs20:", 5) == 0) {
5382 int num
= atoi(pos
+ 5);
5383 if (num
<= 0 || num
> 31)
5385 subtypes
|= BIT(num
);
5386 #else /* CONFIG_HS20 */
5388 #endif /* CONFIG_HS20 */
5390 id
[num_id
] = atoi(pos
);
5394 pos
= os_strchr(pos
+ 1, ',');
5403 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
);
5407 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5409 u8 dst_addr
[ETH_ALEN
];
5410 struct wpabuf
*advproto
, *query
= NULL
;
5415 used
= hwaddr_aton2(cmd
, dst_addr
);
5423 /* Advertisement Protocol ID */
5424 end
= os_strchr(pos
, ' ');
5428 len
= os_strlen(pos
);
5434 advproto
= wpabuf_alloc(len
);
5435 if (advproto
== NULL
)
5437 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
5441 /* Optional Query Request */
5446 len
= os_strlen(pos
);
5453 query
= wpabuf_alloc(len
);
5456 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
5461 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
5464 wpabuf_free(advproto
);
5471 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
5478 size_t resp_len
, start
, requested_len
;
5479 struct wpabuf
*resp
;
5482 used
= hwaddr_aton2(cmd
, addr
);
5489 dialog_token
= atoi(pos
);
5491 if (wpa_s
->last_gas_resp
&&
5492 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
5493 dialog_token
== wpa_s
->last_gas_dialog_token
)
5494 resp
= wpa_s
->last_gas_resp
;
5495 else if (wpa_s
->prev_gas_resp
&&
5496 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
5497 dialog_token
== wpa_s
->prev_gas_dialog_token
)
5498 resp
= wpa_s
->prev_gas_resp
;
5502 resp_len
= wpabuf_len(resp
);
5504 requested_len
= resp_len
;
5506 pos
= os_strchr(pos
, ' ');
5509 if (start
> resp_len
)
5510 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5511 pos
= os_strchr(pos
, ',');
5515 requested_len
= atoi(pos
);
5516 if (start
+ requested_len
> resp_len
)
5517 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5520 if (requested_len
* 2 + 1 > buflen
)
5521 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
5523 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
5526 if (start
+ requested_len
== resp_len
) {
5528 * Free memory by dropping the response after it has been
5531 if (resp
== wpa_s
->prev_gas_resp
) {
5532 wpabuf_free(wpa_s
->prev_gas_resp
);
5533 wpa_s
->prev_gas_resp
= NULL
;
5535 wpabuf_free(wpa_s
->last_gas_resp
);
5536 wpa_s
->last_gas_resp
= NULL
;
5542 #endif /* CONFIG_INTERWORKING */
5547 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5549 u8 dst_addr
[ETH_ALEN
];
5554 used
= hwaddr_aton2(dst
, dst_addr
);
5561 int num
= atoi(pos
);
5562 if (num
<= 0 || num
> 31)
5564 subtypes
|= BIT(num
);
5565 pos
= os_strchr(pos
+ 1, ',');
5574 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
5578 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5579 const u8
*addr
, const char *realm
)
5585 rlen
= os_strlen(realm
);
5587 buf
= os_malloc(len
);
5590 buf
[0] = 1; /* NAI Home Realm Count */
5591 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
5593 os_memcpy(buf
+ 3, realm
, rlen
);
5595 ret
= hs20_anqp_send_req(wpa_s
, addr
,
5596 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5605 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5608 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
5609 u8 dst_addr
[ETH_ALEN
];
5615 used
= hwaddr_aton2(dst
, dst_addr
);
5619 while (dst
[used
] == ' ')
5621 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
5622 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
5625 len
= os_strlen(dst
+ used
);
5627 if (len
== 0 && cred
&& cred
->realm
)
5628 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
5633 buf
= os_malloc(len
);
5636 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
5641 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
5642 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5650 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5652 u8 dst_addr
[ETH_ALEN
];
5656 used
= hwaddr_aton2(cmd
, dst_addr
);
5660 while (cmd
[used
] == ' ')
5664 wpa_s
->fetch_osu_icon_in_progress
= 0;
5665 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
5666 (u8
*) icon
, os_strlen(icon
));
5669 #endif /* CONFIG_HS20 */
5672 #ifdef CONFIG_AUTOSCAN
5674 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
5677 enum wpa_states state
= wpa_s
->wpa_state
;
5678 char *new_params
= NULL
;
5680 if (os_strlen(cmd
) > 0) {
5681 new_params
= os_strdup(cmd
);
5682 if (new_params
== NULL
)
5686 os_free(wpa_s
->conf
->autoscan
);
5687 wpa_s
->conf
->autoscan
= new_params
;
5689 if (wpa_s
->conf
->autoscan
== NULL
)
5690 autoscan_deinit(wpa_s
);
5691 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
5692 autoscan_init(wpa_s
, 1);
5693 else if (state
== WPA_SCANNING
)
5694 wpa_supplicant_reinit_autoscan(wpa_s
);
5699 #endif /* CONFIG_AUTOSCAN */
5704 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
5710 struct wpabuf
*tfs_req
= NULL
;
5712 if (os_strncmp(cmd
, "enter", 5) == 0)
5714 else if (os_strncmp(cmd
, "exit", 4) == 0)
5719 pos
= os_strstr(cmd
, " interval=");
5721 intval
= atoi(pos
+ 10);
5723 pos
= os_strstr(cmd
, " tfs_req=");
5728 end
= os_strchr(pos
, ' ');
5732 len
= os_strlen(pos
);
5736 tfs_req
= wpabuf_alloc(len
);
5737 if (tfs_req
== NULL
)
5739 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5740 wpabuf_free(tfs_req
);
5745 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5746 WNM_SLEEP_MODE_EXIT
, intval
,
5748 wpabuf_free(tfs_req
);
5754 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5758 query_reason
= atoi(cmd
);
5760 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5763 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5766 #endif /* CONFIG_WNM */
5769 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5772 struct wpa_signal_info si
;
5776 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5783 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5784 "NOISE=%d\nFREQUENCY=%u\n",
5785 si
.current_signal
, si
.current_txrate
/ 1000,
5786 si
.current_noise
, si
.frequency
);
5787 if (os_snprintf_error(end
- pos
, ret
))
5791 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5792 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5793 channel_width_to_string(si
.chanwidth
));
5794 if (os_snprintf_error(end
- pos
, ret
))
5799 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5800 ret
= os_snprintf(pos
, end
- pos
,
5801 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5802 si
.center_frq1
, si
.center_frq2
);
5803 if (os_snprintf_error(end
- pos
, ret
))
5808 if (si
.avg_signal
) {
5809 ret
= os_snprintf(pos
, end
- pos
,
5810 "AVG_RSSI=%d\n", si
.avg_signal
);
5811 if (os_snprintf_error(end
- pos
, ret
))
5820 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5823 struct hostap_sta_driver_data sta
;
5826 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5830 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5831 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5832 if (os_snprintf_error(buflen
, ret
))
5839 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5840 char *buf
, size_t buflen
)
5844 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5846 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5847 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5850 country
[0] = cmd
[8];
5851 country
[1] = cmd
[9];
5853 p2p_set_country(p2p
, country
);
5856 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5857 if (os_snprintf_error(buflen
, ret
))
5862 #endif /* ANDROID */
5865 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5866 char *buf
, size_t buflen
)
5871 unsigned int vendor_id
, subcmd
;
5872 struct wpabuf
*reply
;
5873 size_t data_len
= 0;
5875 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5876 vendor_id
= strtoul(cmd
, &pos
, 16);
5880 subcmd
= strtoul(pos
, &pos
, 10);
5883 if (!isblank(*pos
++))
5885 data_len
= os_strlen(pos
);
5890 data
= os_malloc(data_len
);
5894 if (hexstr2bin(pos
, data
, data_len
)) {
5895 wpa_printf(MSG_DEBUG
,
5896 "Vendor command: wrong parameter format");
5902 reply
= wpabuf_alloc((buflen
- 1) / 2);
5908 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
5912 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
5922 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5924 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5927 wpas_p2p_cancel(wpa_s
);
5928 wpas_p2p_stop_find(wpa_s
);
5929 p2p_ctrl_flush(wpa_s
);
5930 wpas_p2p_group_remove(wpa_s
, "*");
5931 wpas_p2p_service_flush(wpa_s
);
5932 wpa_s
->global
->p2p_disabled
= 0;
5933 wpa_s
->global
->p2p_per_sta_psk
= 0;
5934 wpa_s
->conf
->num_sec_device_types
= 0;
5935 wpa_s
->p2p_disable_ip_addr_req
= 0;
5936 os_free(wpa_s
->global
->p2p_go_avoid_freq
.range
);
5937 wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
5938 #endif /* CONFIG_P2P */
5940 #ifdef CONFIG_WPS_TESTING
5941 wps_version_number
= 0x20;
5942 wps_testing_dummy_cred
= 0;
5943 wps_corrupt_pkhash
= 0;
5944 #endif /* CONFIG_WPS_TESTING */
5946 wpa_s
->wps_fragment_size
= 0;
5947 wpas_wps_cancel(wpa_s
);
5948 #endif /* CONFIG_WPS */
5949 wpa_s
->after_wps
= 0;
5950 wpa_s
->known_wps_freq
= 0;
5953 #ifdef CONFIG_TDLS_TESTING
5954 extern unsigned int tdls_testing
;
5956 #endif /* CONFIG_TDLS_TESTING */
5957 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
5958 wpa_tdls_enable(wpa_s
->wpa
, 1);
5959 #endif /* CONFIG_TDLS */
5961 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
5962 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
5964 wpa_s
->no_keep_alive
= 0;
5966 os_free(wpa_s
->disallow_aps_bssid
);
5967 wpa_s
->disallow_aps_bssid
= NULL
;
5968 wpa_s
->disallow_aps_bssid_count
= 0;
5969 os_free(wpa_s
->disallow_aps_ssid
);
5970 wpa_s
->disallow_aps_ssid
= NULL
;
5971 wpa_s
->disallow_aps_ssid_count
= 0;
5973 wpa_s
->set_sta_uapsd
= 0;
5974 wpa_s
->sta_uapsd
= 0;
5976 wpa_drv_radio_disable(wpa_s
, 0);
5978 wpa_bss_flush(wpa_s
);
5979 wpa_blacklist_clear(wpa_s
);
5980 wpa_s
->extra_blacklist_count
= 0;
5981 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
5982 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
5983 wpa_config_flush_blobs(wpa_s
->conf
);
5984 wpa_s
->conf
->auto_interworking
= 0;
5985 wpa_s
->conf
->okc
= 0;
5987 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
5988 rsn_preauth_deinit(wpa_s
->wpa
);
5990 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
5991 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
5992 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
5993 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5995 radio_remove_works(wpa_s
, NULL
, 1);
5996 wpa_s
->ext_work_in_progress
= 0;
5998 wpa_s
->next_ssid
= NULL
;
6000 #ifdef CONFIG_INTERWORKING
6001 hs20_cancel_fetch_osu(wpa_s
);
6002 #endif /* CONFIG_INTERWORKING */
6004 wpa_s
->ext_mgmt_frame_handling
= 0;
6005 wpa_s
->ext_eapol_frame_io
= 0;
6006 #ifdef CONFIG_TESTING_OPTIONS
6007 wpa_s
->extra_roc_dur
= 0;
6008 #endif /* CONFIG_TESTING_OPTIONS */
6010 wpa_s
->disconnected
= 0;
6014 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
6015 char *buf
, size_t buflen
)
6017 struct wpa_radio_work
*work
;
6019 struct os_reltime now
, diff
;
6024 os_get_reltime(&now
);
6026 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
6030 os_reltime_sub(&now
, &work
->time
, &diff
);
6031 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
6032 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
6033 work
->started
, diff
.sec
, diff
.usec
);
6034 if (os_snprintf_error(end
- pos
, ret
))
6043 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
6045 struct wpa_radio_work
*work
= eloop_ctx
;
6046 struct wpa_external_work
*ework
= work
->ctx
;
6048 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
6049 "Timing out external radio work %u (%s)",
6050 ework
->id
, work
->type
);
6051 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
6052 work
->wpa_s
->ext_work_in_progress
= 0;
6053 radio_work_done(work
);
6058 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
6060 struct wpa_external_work
*ework
= work
->ctx
;
6064 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
6071 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
6072 ework
->id
, ework
->type
);
6073 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
6074 work
->wpa_s
->ext_work_in_progress
= 1;
6075 if (!ework
->timeout
)
6076 ework
->timeout
= 10;
6077 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
6082 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
6083 char *buf
, size_t buflen
)
6085 struct wpa_external_work
*ework
;
6089 unsigned int freq
= 0;
6091 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
6093 ework
= os_zalloc(sizeof(*ework
));
6097 pos
= os_strchr(cmd
, ' ');
6099 type_len
= pos
- cmd
;
6102 pos2
= os_strstr(pos
, "freq=");
6104 freq
= atoi(pos2
+ 5);
6106 pos2
= os_strstr(pos
, "timeout=");
6108 ework
->timeout
= atoi(pos2
+ 8);
6110 type_len
= os_strlen(cmd
);
6112 if (4 + type_len
>= sizeof(ework
->type
))
6113 type_len
= sizeof(ework
->type
) - 4 - 1;
6114 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
6115 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
6116 ework
->type
[4 + type_len
] = '\0';
6118 wpa_s
->ext_work_id
++;
6119 if (wpa_s
->ext_work_id
== 0)
6120 wpa_s
->ext_work_id
++;
6121 ework
->id
= wpa_s
->ext_work_id
;
6123 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
6129 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
6130 if (os_snprintf_error(buflen
, ret
))
6136 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
6138 struct wpa_radio_work
*work
;
6139 unsigned int id
= atoi(cmd
);
6141 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
6143 struct wpa_external_work
*ework
;
6145 if (os_strncmp(work
->type
, "ext:", 4) != 0)
6148 if (id
&& ework
->id
!= id
)
6150 wpa_dbg(wpa_s
, MSG_DEBUG
,
6151 "Completed external radio work %u (%s)",
6152 ework
->id
, ework
->type
);
6153 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
6154 wpa_s
->ext_work_in_progress
= 0;
6155 radio_work_done(work
);
6157 return 3; /* "OK\n" */
6164 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
6165 char *buf
, size_t buflen
)
6167 if (os_strcmp(cmd
, "show") == 0)
6168 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
6169 if (os_strncmp(cmd
, "add ", 4) == 0)
6170 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
6171 if (os_strncmp(cmd
, "done ", 5) == 0)
6172 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
6177 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
6179 struct wpa_radio_work
*work
, *tmp
;
6181 if (!wpa_s
|| !wpa_s
->radio
)
6184 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
6185 struct wpa_radio_work
, list
) {
6186 struct wpa_external_work
*ework
;
6188 if (os_strncmp(work
->type
, "ext:", 4) != 0)
6191 wpa_dbg(wpa_s
, MSG_DEBUG
,
6192 "Flushing%s external radio work %u (%s)",
6193 work
->started
? " started" : "", ework
->id
,
6196 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
6198 radio_work_done(work
);
6204 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
6206 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
6207 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
6211 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
6212 unsigned int *scan_id_count
, int scan_id
[])
6214 const char *pos
= value
;
6217 if (*pos
== ' ' || *pos
== '\0')
6219 if (*scan_id_count
== MAX_SCAN_ID
)
6221 scan_id
[(*scan_id_count
)++] = atoi(pos
);
6222 pos
= os_strchr(pos
, ',');
6231 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
6232 char *reply
, int reply_size
, int *reply_len
)
6235 unsigned int manual_scan_passive
= 0;
6236 unsigned int manual_scan_use_id
= 0;
6237 unsigned int manual_scan_only_new
= 0;
6238 unsigned int scan_only
= 0;
6239 unsigned int scan_id_count
= 0;
6240 int scan_id
[MAX_SCAN_ID
];
6241 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
6242 struct wpa_scan_results
*scan_res
);
6243 int *manual_scan_freqs
= NULL
;
6245 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
6251 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
6254 pos
= os_strstr(params
, "freq=");
6256 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
6258 if (manual_scan_freqs
== NULL
) {
6264 pos
= os_strstr(params
, "passive=");
6266 manual_scan_passive
= !!atoi(pos
+ 8);
6268 pos
= os_strstr(params
, "use_id=");
6270 manual_scan_use_id
= atoi(pos
+ 7);
6272 pos
= os_strstr(params
, "only_new=1");
6274 manual_scan_only_new
= 1;
6276 pos
= os_strstr(params
, "scan_id=");
6277 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
6285 scan_res_handler
= scan_only_handler
;
6286 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
6287 scan_res_handler
= NULL
;
6289 scan_res_handler
= wpa_s
->scan_res_handler
;
6291 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
6292 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
6293 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
6294 wpa_s
->manual_scan_passive
= manual_scan_passive
;
6295 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
6296 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
6297 wpa_s
->scan_id_count
= scan_id_count
;
6298 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
6299 wpa_s
->scan_res_handler
= scan_res_handler
;
6300 os_free(wpa_s
->manual_scan_freqs
);
6301 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
6302 manual_scan_freqs
= NULL
;
6304 wpa_s
->normal_scans
= 0;
6305 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6306 wpa_s
->after_wps
= 0;
6307 wpa_s
->known_wps_freq
= 0;
6308 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6309 if (wpa_s
->manual_scan_use_id
) {
6310 wpa_s
->manual_scan_id
++;
6311 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6312 wpa_s
->manual_scan_id
);
6313 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6314 wpa_s
->manual_scan_id
);
6316 } else if (wpa_s
->sched_scanning
) {
6317 wpa_s
->manual_scan_passive
= manual_scan_passive
;
6318 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
6319 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
6320 wpa_s
->scan_id_count
= scan_id_count
;
6321 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
6322 wpa_s
->scan_res_handler
= scan_res_handler
;
6323 os_free(wpa_s
->manual_scan_freqs
);
6324 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
6325 manual_scan_freqs
= NULL
;
6327 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
6328 wpa_supplicant_cancel_sched_scan(wpa_s
);
6329 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6330 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6331 if (wpa_s
->manual_scan_use_id
) {
6332 wpa_s
->manual_scan_id
++;
6333 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6334 wpa_s
->manual_scan_id
);
6335 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6336 wpa_s
->manual_scan_id
);
6339 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
6340 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
6344 os_free(manual_scan_freqs
);
6348 #ifdef CONFIG_TESTING_OPTIONS
6350 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
6351 unsigned int freq
, const u8
*dst
,
6352 const u8
*src
, const u8
*bssid
,
6353 const u8
*data
, size_t data_len
,
6354 enum offchannel_send_action_result
6357 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6358 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
6359 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
6360 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
6361 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
6362 "NO_ACK" : "FAILED"));
6366 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6370 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
6372 int freq
= 0, no_cck
= 0, wait_time
= 0;
6374 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6375 * <action=Action frame payload> */
6377 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
6380 used
= hwaddr_aton2(pos
, da
);
6386 used
= hwaddr_aton2(pos
, bssid
);
6391 param
= os_strstr(pos
, " freq=");
6397 param
= os_strstr(pos
, " no_cck=");
6400 no_cck
= atoi(param
);
6403 param
= os_strstr(pos
, " wait_time=");
6406 wait_time
= atoi(param
);
6409 param
= os_strstr(pos
, " action=");
6414 len
= os_strlen(param
);
6419 buf
= os_malloc(len
);
6423 if (hexstr2bin(param
, buf
, len
) < 0) {
6428 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
6429 buf
, len
, wait_time
,
6430 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
6436 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
6438 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
6439 offchannel_send_action_done(wpa_s
);
6443 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
6446 union wpa_event_data event
;
6447 enum wpa_event_type ev
;
6449 /* <event name> [parameters..] */
6451 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
6454 param
= os_strchr(pos
, ' ');
6458 os_memset(&event
, 0, sizeof(event
));
6460 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
6461 ev
= EVENT_INTERFACE_ENABLED
;
6462 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
6463 ev
= EVENT_INTERFACE_DISABLED
;
6464 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
6465 ev
= EVENT_AVOID_FREQUENCIES
;
6468 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
6470 wpa_supplicant_event(wpa_s
, ev
, &event
);
6471 os_free(event
.freq_range
.range
);
6474 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
6479 wpa_supplicant_event(wpa_s
, ev
, &event
);
6485 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6488 u8 src
[ETH_ALEN
], *buf
;
6492 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
6495 used
= hwaddr_aton2(pos
, src
);
6502 len
= os_strlen(pos
);
6507 buf
= os_malloc(len
);
6511 if (hexstr2bin(pos
, buf
, len
) < 0) {
6516 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
6523 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
6527 const u16
*pos
= buf
;
6529 for (i
= 0; i
< len
/ 2; i
++)
6533 sum
= (sum
& 0xffff) + (sum
>> 16);
6535 return sum
^ 0xffff;
6539 #define HWSIM_PACKETLEN 1500
6540 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6542 void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
, size_t len
)
6544 struct wpa_supplicant
*wpa_s
= ctx
;
6545 const struct ether_header
*eth
;
6546 const struct iphdr
*ip
;
6550 if (len
!= HWSIM_PACKETLEN
)
6553 eth
= (const struct ether_header
*) buf
;
6554 ip
= (const struct iphdr
*) (eth
+ 1);
6555 pos
= (const u8
*) (ip
+ 1);
6557 if (ip
->ihl
!= 5 || ip
->version
!= 4 ||
6558 ntohs(ip
->tot_len
) != HWSIM_IP_LEN
)
6561 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++) {
6567 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
6568 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
6572 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
6575 int enabled
= atoi(cmd
);
6578 if (wpa_s
->l2_test
) {
6579 l2_packet_deinit(wpa_s
->l2_test
);
6580 wpa_s
->l2_test
= NULL
;
6581 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
6589 wpa_s
->l2_test
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
,
6590 ETHERTYPE_IP
, wpas_data_test_rx
,
6592 if (wpa_s
->l2_test
== NULL
)
6595 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
6601 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6603 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
6608 u8 buf
[HWSIM_PACKETLEN
];
6609 struct ether_header
*eth
;
6614 if (wpa_s
->l2_test
== NULL
)
6617 /* format: <dst> <src> <tos> */
6620 used
= hwaddr_aton2(pos
, dst
);
6626 used
= hwaddr_aton2(pos
, src
);
6631 val
= strtol(pos
, NULL
, 0);
6632 if (val
< 0 || val
> 0xff)
6636 eth
= (struct ether_header
*) buf
;
6637 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
6638 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
6639 eth
->ether_type
= htons(ETHERTYPE_IP
);
6640 ip
= (struct iphdr
*) (eth
+ 1);
6641 os_memset(ip
, 0, sizeof(*ip
));
6646 ip
->tot_len
= htons(HWSIM_IP_LEN
);
6648 ip
->saddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6649 ip
->daddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6650 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
6651 dpos
= (u8
*) (ip
+ 1);
6652 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
6655 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, buf
,
6656 HWSIM_PACKETLEN
) < 0)
6659 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
6660 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
6666 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
6670 struct ether_header
*eth
;
6671 struct l2_packet_data
*l2
= NULL
;
6676 len
= os_strlen(cmd
);
6677 if (len
& 1 || len
< ETH_HLEN
* 2)
6681 buf
= os_malloc(len
);
6685 if (hexstr2bin(cmd
, buf
, len
) < 0)
6688 eth
= (struct ether_header
*) buf
;
6689 ethertype
= ntohs(eth
->ether_type
);
6691 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
6692 wpas_data_test_rx
, wpa_s
, 1);
6696 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
6697 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
6700 l2_packet_deinit(l2
);
6703 return res
< 0 ? -1 : 0;
6706 #endif /* CONFIG_TESTING_OPTIONS */
6709 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant
*wpa_s
)
6714 wpa_printf(MSG_DEBUG
, "Update vendor elements");
6716 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
6717 if (wpa_s
->vendor_elem
[i
]) {
6720 res
= os_snprintf(buf
, sizeof(buf
), "frame[%u]", i
);
6721 if (!os_snprintf_error(sizeof(buf
), res
)) {
6722 wpa_hexdump_buf(MSG_DEBUG
, buf
,
6723 wpa_s
->vendor_elem
[i
]);
6729 if (wpa_s
->parent
== wpa_s
&&
6730 wpa_s
->global
->p2p
&&
6731 !wpa_s
->global
->p2p_disabled
)
6732 p2p_set_vendor_elems(wpa_s
->global
->p2p
, wpa_s
->vendor_elem
);
6733 #endif /* CONFIG_P2P */
6737 static struct wpa_supplicant
*
6738 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant
*wpa_s
,
6739 enum wpa_vendor_elem_frame frame
)
6743 case VENDOR_ELEM_PROBE_REQ_P2P
:
6744 case VENDOR_ELEM_PROBE_RESP_P2P
:
6745 case VENDOR_ELEM_PROBE_RESP_P2P_GO
:
6746 case VENDOR_ELEM_BEACON_P2P_GO
:
6747 case VENDOR_ELEM_P2P_PD_REQ
:
6748 case VENDOR_ELEM_P2P_PD_RESP
:
6749 case VENDOR_ELEM_P2P_GO_NEG_REQ
:
6750 case VENDOR_ELEM_P2P_GO_NEG_RESP
:
6751 case VENDOR_ELEM_P2P_GO_NEG_CONF
:
6752 case VENDOR_ELEM_P2P_INV_REQ
:
6753 case VENDOR_ELEM_P2P_INV_RESP
:
6754 case VENDOR_ELEM_P2P_ASSOC_REQ
:
6755 return wpa_s
->parent
;
6756 #endif /* CONFIG_P2P */
6763 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6769 struct ieee802_11_elems elems
;
6772 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6774 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6776 pos
= os_strchr(pos
, ' ');
6781 len
= os_strlen(pos
);
6788 buf
= wpabuf_alloc(len
);
6792 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
6797 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
6803 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
6804 wpa_s
->vendor_elem
[frame
] = buf
;
6805 wpas_ctrl_vendor_elem_update(wpa_s
);
6809 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
6814 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
6816 wpas_ctrl_vendor_elem_update(wpa_s
);
6822 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
6823 char *buf
, size_t buflen
)
6825 int frame
= atoi(cmd
);
6827 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6829 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6831 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6834 return wpa_snprintf_hex(buf
, buflen
,
6835 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
6836 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
6840 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
6846 struct ieee802_11_elems elems
;
6850 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6852 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6854 pos
= os_strchr(pos
, ' ');
6860 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6861 wpa_s
->vendor_elem
[frame
] = NULL
;
6862 wpas_ctrl_vendor_elem_update(wpa_s
);
6866 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6869 len
= os_strlen(pos
);
6876 buf
= os_malloc(len
);
6880 if (hexstr2bin(pos
, buf
, len
) < 0) {
6885 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
6890 ie
= wpabuf_mhead_u8(wpa_s
->vendor_elem
[frame
]);
6891 end
= ie
+ wpabuf_len(wpa_s
->vendor_elem
[frame
]);
6893 for (; ie
+ 1 < end
; ie
+= 2 + ie
[1]) {
6896 if (os_memcmp(ie
, buf
, len
) != 0)
6899 if (wpabuf_len(wpa_s
->vendor_elem
[frame
]) == len
) {
6900 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6901 wpa_s
->vendor_elem
[frame
] = NULL
;
6903 os_memmove(ie
, ie
+ len
,
6905 wpa_s
->vendor_elem
[frame
]->used
-= len
;
6908 wpas_ctrl_vendor_elem_update(wpa_s
);
6918 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
6920 struct wpa_supplicant
*wpa_s
= ctx
;
6923 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
6925 (unsigned int) wpabuf_len(neighbor_rep
));
6926 wpabuf_free(neighbor_rep
);
6928 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
6933 static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant
*wpa_s
,
6936 struct wpa_ssid ssid
;
6937 struct wpa_ssid
*ssid_p
= NULL
;
6940 if (os_strncmp(cmd
, " ssid=", 6) == 0) {
6941 ssid
.ssid_len
= os_strlen(cmd
+ 6);
6942 if (ssid
.ssid_len
> 32)
6944 ssid
.ssid
= (u8
*) (cmd
+ 6);
6948 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
,
6949 wpas_ctrl_neighbor_rep_cb
,
6956 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
6958 eapol_sm_erp_flush(wpa_s
->eapol
);
6963 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
6964 char *buf
, size_t *resp_len
)
6967 const int reply_size
= 4096;
6970 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
6971 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
6972 if (wpa_debug_show_keys
)
6973 wpa_dbg(wpa_s
, MSG_DEBUG
,
6974 "Control interface command '%s'", buf
);
6976 wpa_dbg(wpa_s
, MSG_DEBUG
,
6977 "Control interface command '%s [REMOVED]'",
6978 os_strncmp(buf
, WPA_CTRL_RSP
,
6979 os_strlen(WPA_CTRL_RSP
)) == 0 ?
6980 WPA_CTRL_RSP
: "SET_NETWORK");
6981 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
6982 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
6983 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
6984 (const u8
*) buf
, os_strlen(buf
));
6986 int level
= MSG_DEBUG
;
6987 if (os_strcmp(buf
, "PING") == 0)
6988 level
= MSG_EXCESSIVE
;
6989 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
6992 reply
= os_malloc(reply_size
);
6993 if (reply
== NULL
) {
6998 os_memcpy(reply
, "OK\n", 3);
7001 if (os_strcmp(buf
, "PING") == 0) {
7002 os_memcpy(reply
, "PONG\n", 5);
7004 } else if (os_strcmp(buf
, "IFNAME") == 0) {
7005 reply_len
= os_strlen(wpa_s
->ifname
);
7006 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
7007 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
7008 if (wpa_debug_reopen_file() < 0)
7010 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
7011 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
7012 } else if (os_strcmp(buf
, "MIB") == 0) {
7013 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
7014 if (reply_len
>= 0) {
7015 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
7017 reply_size
- reply_len
);
7019 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
7020 reply_len
= wpa_supplicant_ctrl_iface_status(
7021 wpa_s
, buf
+ 6, reply
, reply_size
);
7022 } else if (os_strcmp(buf
, "PMKSA") == 0) {
7023 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
7025 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
7026 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7027 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
7028 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
7030 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
7031 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
7033 } else if (os_strcmp(buf
, "LOGON") == 0) {
7034 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7035 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
7036 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
7037 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
7038 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
7041 wpas_request_connection(wpa_s
);
7042 } else if (os_strcmp(buf
, "REATTACH") == 0) {
7043 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
7044 !wpa_s
->current_ssid
)
7047 wpa_s
->reattach
= 1;
7048 wpas_request_connection(wpa_s
);
7050 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
7051 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
7053 else if (wpa_s
->disconnected
)
7054 wpas_request_connection(wpa_s
);
7055 #ifdef IEEE8021X_EAPOL
7056 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
7057 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
7059 #endif /* IEEE8021X_EAPOL */
7060 #ifdef CONFIG_PEERKEY
7061 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
7062 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
7064 #endif /* CONFIG_PEERKEY */
7065 #ifdef CONFIG_IEEE80211R
7066 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
7067 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
7069 #endif /* CONFIG_IEEE80211R */
7071 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
7072 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
7074 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7078 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
7079 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
7081 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7085 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
7086 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
7089 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
7090 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
7091 wpa_s
, buf
+ 14, reply
, reply_size
);
7092 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
7093 if (wpas_wps_cancel(wpa_s
))
7095 #ifdef CONFIG_WPS_NFC
7096 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
7097 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
7099 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
7100 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
7102 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
7103 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
7104 wpa_s
, buf
+ 21, reply
, reply_size
);
7105 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
7106 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
7107 wpa_s
, buf
+ 14, reply
, reply_size
);
7108 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
7109 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
7112 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
7113 reply_len
= wpas_ctrl_nfc_get_handover_req(
7114 wpa_s
, buf
+ 21, reply
, reply_size
);
7115 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
7116 reply_len
= wpas_ctrl_nfc_get_handover_sel(
7117 wpa_s
, buf
+ 21, reply
, reply_size
);
7118 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
7119 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
7121 #endif /* CONFIG_WPS_NFC */
7122 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
7123 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
7126 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
7127 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
7128 wpa_s
, buf
+ 11, reply
, reply_size
);
7129 #endif /* CONFIG_AP */
7130 #ifdef CONFIG_WPS_ER
7131 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
7132 if (wpas_wps_er_start(wpa_s
, NULL
))
7134 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
7135 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
7137 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
7138 wpas_wps_er_stop(wpa_s
);
7139 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
7140 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
7142 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
7143 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
7145 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7147 } else if (ret
== -3) {
7148 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
7150 } else if (ret
== -4) {
7151 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
7155 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
7156 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
7158 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
7159 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
7162 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
7163 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
7165 #ifdef CONFIG_WPS_NFC
7166 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
7167 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
7168 wpa_s
, buf
+ 24, reply
, reply_size
);
7169 #endif /* CONFIG_WPS_NFC */
7170 #endif /* CONFIG_WPS_ER */
7171 #endif /* CONFIG_WPS */
7172 #ifdef CONFIG_IBSS_RSN
7173 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
7174 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
7176 #endif /* CONFIG_IBSS_RSN */
7178 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
7179 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
7181 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
7182 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
7185 #endif /* CONFIG_MESH */
7187 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
7188 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
7190 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
7191 if (p2p_ctrl_find(wpa_s
, ""))
7193 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
7194 wpas_p2p_stop_find(wpa_s
);
7195 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
7196 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
7198 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
7199 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
7201 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
7202 if (p2p_ctrl_listen(wpa_s
, ""))
7204 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
7205 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
7207 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
7208 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
7210 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
7211 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
7213 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
7214 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
7216 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
7217 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
7218 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
7219 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
7221 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
7222 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
7224 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
7225 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
7227 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
7228 wpas_p2p_sd_service_update(wpa_s
);
7229 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
7230 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
7232 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
7233 wpas_p2p_service_flush(wpa_s
);
7234 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
7235 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
7237 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
7238 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
7240 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
7241 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
7243 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
7244 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
7246 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
7247 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
7249 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
7250 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
7252 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
7253 p2p_ctrl_flush(wpa_s
);
7254 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
7255 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
7257 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
7258 if (wpas_p2p_cancel(wpa_s
))
7260 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
7261 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
7263 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
7264 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
7266 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
7267 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
7269 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
7270 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
7272 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
7273 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
7275 #endif /* CONFIG_P2P */
7276 #ifdef CONFIG_WIFI_DISPLAY
7277 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
7278 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
7280 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
7281 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
7283 #endif /* CONFIG_WIFI_DISPLAY */
7284 #ifdef CONFIG_INTERWORKING
7285 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
7286 if (interworking_fetch_anqp(wpa_s
) < 0)
7288 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
7289 interworking_stop_fetch_anqp(wpa_s
);
7290 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
7291 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
7293 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
7294 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
7296 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
7297 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
7299 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
7300 if (get_anqp(wpa_s
, buf
+ 9) < 0)
7302 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
7303 if (gas_request(wpa_s
, buf
+ 12) < 0)
7305 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
7306 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
7308 #endif /* CONFIG_INTERWORKING */
7310 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
7311 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
7313 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7314 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
7316 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
7317 if (hs20_icon_request(wpa_s
, buf
+ 18) < 0)
7319 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
7320 if (hs20_fetch_osu(wpa_s
) < 0)
7322 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
7323 hs20_cancel_fetch_osu(wpa_s
);
7324 #endif /* CONFIG_HS20 */
7325 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
7327 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7328 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
7332 * Notify response from timeout to allow the control
7333 * interface response to be sent first.
7335 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
7338 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
7339 if (wpa_supplicant_reload_configuration(wpa_s
))
7341 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
7342 wpa_supplicant_terminate_proc(wpa_s
->global
);
7343 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
7344 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
7346 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
7347 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
7348 wpa_s
, buf
+ 9, reply
, reply_size
);
7349 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
7350 reply_len
= wpa_supplicant_ctrl_iface_log_level(
7351 wpa_s
, buf
+ 9, reply
, reply_size
);
7352 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
7353 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
7354 wpa_s
, buf
+ 14, reply
, reply_size
);
7355 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
7356 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
7357 wpa_s
, NULL
, reply
, reply_size
);
7358 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
7360 wpa_s
->sme
.prev_bssid_set
= 0;
7361 #endif /* CONFIG_SME */
7362 wpa_s
->reassociate
= 0;
7363 wpa_s
->disconnected
= 1;
7364 wpa_supplicant_cancel_sched_scan(wpa_s
);
7365 wpa_supplicant_cancel_scan(wpa_s
);
7366 wpa_supplicant_deauthenticate(wpa_s
,
7367 WLAN_REASON_DEAUTH_LEAVING
);
7368 } else if (os_strcmp(buf
, "SCAN") == 0) {
7369 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
7370 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
7371 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
7372 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
7373 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
7374 wpa_s
, reply
, reply_size
);
7375 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
7376 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
7378 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
7379 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
7381 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
7382 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
7384 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
7385 reply_len
= wpa_supplicant_ctrl_iface_add_network(
7386 wpa_s
, reply
, reply_size
);
7387 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
7388 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
7390 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
7391 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
7393 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
7394 reply_len
= wpa_supplicant_ctrl_iface_get_network(
7395 wpa_s
, buf
+ 12, reply
, reply_size
);
7396 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
7397 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12))
7399 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
7400 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
7401 wpa_s
, reply
, reply_size
);
7402 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
7403 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
7404 wpa_s
, reply
, reply_size
);
7405 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
7406 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
7408 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
7409 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
7411 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
7412 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
7415 #ifndef CONFIG_NO_CONFIG_WRITE
7416 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
7417 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
7419 #endif /* CONFIG_NO_CONFIG_WRITE */
7420 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
7421 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
7422 wpa_s
, buf
+ 15, reply
, reply_size
);
7423 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
7424 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
7426 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
7427 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
7429 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
7430 reply_len
= wpa_supplicant_global_iface_list(
7431 wpa_s
->global
, reply
, reply_size
);
7432 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
7433 reply_len
= wpa_supplicant_global_iface_interfaces(
7434 wpa_s
->global
, reply
, reply_size
);
7435 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
7436 reply_len
= wpa_supplicant_ctrl_iface_bss(
7437 wpa_s
, buf
+ 4, reply
, reply_size
);
7439 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
7440 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
7441 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
7442 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
7444 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
7445 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
7447 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
7448 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
7450 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
7451 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
7453 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
7454 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
7456 #endif /* CONFIG_AP */
7457 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
7458 wpas_notify_suspend(wpa_s
->global
);
7459 } else if (os_strcmp(buf
, "RESUME") == 0) {
7460 wpas_notify_resume(wpa_s
->global
);
7461 #ifdef CONFIG_TESTING_OPTIONS
7462 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
7463 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
7464 #endif /* CONFIG_TESTING_OPTIONS */
7465 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
7466 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
7468 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
7469 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
7470 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
7471 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
7473 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
7474 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
7477 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
7478 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
7480 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
7481 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
7483 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
7484 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
7486 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
7487 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
7489 #endif /* CONFIG_TDLS */
7490 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
7491 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
7492 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
7493 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
7495 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
7496 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
7498 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
7499 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
7501 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
7502 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
7504 #ifdef CONFIG_AUTOSCAN
7505 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
7506 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
7508 #endif /* CONFIG_AUTOSCAN */
7510 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
7511 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
7513 #endif /* ANDROID */
7514 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
7515 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
7517 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
7518 pmksa_cache_clear_current(wpa_s
->wpa
);
7519 eapol_sm_request_reauth(wpa_s
->eapol
);
7521 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
7522 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
7524 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
7525 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
7527 #endif /* CONFIG_WNM */
7528 } else if (os_strcmp(buf
, "FLUSH") == 0) {
7529 wpa_supplicant_ctrl_iface_flush(wpa_s
);
7530 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
7531 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
7533 #ifdef CONFIG_TESTING_OPTIONS
7534 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
7535 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
7537 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
7538 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
7539 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
7540 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
7542 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
7543 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
7545 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
7546 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
7548 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
7549 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
7551 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
7552 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
7554 #endif /* CONFIG_TESTING_OPTIONS */
7555 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
7556 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
7558 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
7559 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
7561 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7562 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
7564 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
7565 if (wpas_ctrl_iface_send_neigbor_rep(wpa_s
, buf
+ 20))
7567 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
7568 wpas_ctrl_iface_erp_flush(wpa_s
);
7570 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
7574 if (reply_len
< 0) {
7575 os_memcpy(reply
, "FAIL\n", 5);
7579 *resp_len
= reply_len
;
7584 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
7587 struct wpa_interface iface
;
7591 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7592 * TAB<bridge_ifname>
7594 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
7596 os_memset(&iface
, 0, sizeof(iface
));
7599 iface
.ifname
= pos
= cmd
;
7600 pos
= os_strchr(pos
, '\t');
7603 if (iface
.ifname
[0] == '\0')
7608 iface
.confname
= pos
;
7609 pos
= os_strchr(pos
, '\t');
7612 if (iface
.confname
[0] == '\0')
7613 iface
.confname
= NULL
;
7618 pos
= os_strchr(pos
, '\t');
7621 if (iface
.driver
[0] == '\0')
7622 iface
.driver
= NULL
;
7626 iface
.ctrl_interface
= pos
;
7627 pos
= os_strchr(pos
, '\t');
7630 if (iface
.ctrl_interface
[0] == '\0')
7631 iface
.ctrl_interface
= NULL
;
7635 iface
.driver_param
= pos
;
7636 pos
= os_strchr(pos
, '\t');
7639 if (iface
.driver_param
[0] == '\0')
7640 iface
.driver_param
= NULL
;
7644 iface
.bridge_ifname
= pos
;
7645 pos
= os_strchr(pos
, '\t');
7648 if (iface
.bridge_ifname
[0] == '\0')
7649 iface
.bridge_ifname
= NULL
;
7654 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
7657 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
7661 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
7664 struct wpa_supplicant
*wpa_s
;
7666 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
7668 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
7671 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
7675 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
7677 struct wpa_interface_info
*prev
;
7681 iface
= iface
->next
;
7683 os_free(prev
->ifname
);
7684 os_free(prev
->desc
);
7690 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
7694 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
7697 for (i
= 0; wpa_drivers
[i
]; i
++) {
7698 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
7699 if (drv
->get_interfaces
== NULL
)
7701 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
7715 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
7716 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
7717 tmp
->drv_name
, tmp
->ifname
,
7718 tmp
->desc
? tmp
->desc
: "");
7719 if (os_snprintf_error(end
- pos
, res
)) {
7726 wpa_free_iface_info(iface
);
7732 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
7737 struct wpa_supplicant
*wpa_s
;
7739 wpa_s
= global
->ifaces
;
7744 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
7745 if (os_snprintf_error(end
- pos
, res
)) {
7750 wpa_s
= wpa_s
->next
;
7756 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
7758 char *cmd
, size_t *resp_len
)
7760 struct wpa_supplicant
*wpa_s
;
7762 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7763 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
7767 if (wpa_s
== NULL
) {
7768 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
7770 *resp_len
= os_strlen(resp
);
7776 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
7780 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
7781 char *buf
, size_t *resp_len
)
7784 static const char * cmd
[] = {
7790 "P2P_GET_PASSPHRASE",
7791 "P2P_SERVICE_UPDATE",
7792 "P2P_SERVICE_FLUSH",
7799 static const char * prefix
[] = {
7802 #endif /* ANDROID */
7808 "P2P_GROUP_REMOVE ",
7811 "P2P_SERV_DISC_REQ ",
7812 "P2P_SERV_DISC_CANCEL_REQ ",
7813 "P2P_SERV_DISC_RESP ",
7814 "P2P_SERV_DISC_EXTERNAL ",
7822 "P2P_PRESENCE_REQ ",
7824 "P2P_REMOVE_CLIENT ",
7825 "NFC_GET_HANDOVER_SEL ",
7826 "NFC_GET_HANDOVER_REQ ",
7827 "NFC_REPORT_HANDOVER ",
7833 if (global
->p2p_init_wpa_s
== NULL
)
7836 for (i
= 0; !found
&& cmd
[i
]; i
++) {
7837 if (os_strcmp(buf
, cmd
[i
]) == 0)
7841 for (i
= 0; !found
&& prefix
[i
]; i
++) {
7842 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
7847 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7849 #endif /* CONFIG_P2P */
7854 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
7855 char *buf
, size_t *resp_len
)
7857 #ifdef CONFIG_WIFI_DISPLAY
7858 if (global
->p2p_init_wpa_s
== NULL
)
7860 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
7861 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
7862 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7864 #endif /* CONFIG_WIFI_DISPLAY */
7869 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
7870 char *buf
, size_t *resp_len
)
7874 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
7878 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
7886 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
7890 value
= os_strchr(cmd
, ' ');
7895 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
7897 #ifdef CONFIG_WIFI_DISPLAY
7898 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
7899 wifi_display_enable(global
, !!atoi(value
));
7902 #endif /* CONFIG_WIFI_DISPLAY */
7904 /* Restore cmd to its original value to allow redirection */
7911 #ifndef CONFIG_NO_CONFIG_WRITE
7912 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
7914 int ret
= 0, saved
= 0;
7915 struct wpa_supplicant
*wpa_s
;
7917 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7918 if (!wpa_s
->conf
->update_config
) {
7919 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7923 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
7924 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7927 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7932 if (!saved
&& !ret
) {
7933 wpa_dbg(wpa_s
, MSG_DEBUG
,
7934 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7940 #endif /* CONFIG_NO_CONFIG_WRITE */
7943 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
7944 char *buf
, size_t buflen
)
7948 struct wpa_supplicant
*wpa_s
;
7954 if (global
->p2p
&& !global
->p2p_disabled
) {
7955 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
7958 MAC2STR(global
->p2p_dev_addr
),
7959 p2p_get_state_txt(global
->p2p
));
7960 if (os_snprintf_error(end
- pos
, ret
))
7963 } else if (global
->p2p
) {
7964 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
7965 if (os_snprintf_error(end
- pos
, ret
))
7969 #endif /* CONFIG_P2P */
7971 #ifdef CONFIG_WIFI_DISPLAY
7972 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
7973 !!global
->wifi_display
);
7974 if (os_snprintf_error(end
- pos
, ret
))
7977 #endif /* CONFIG_WIFI_DISPLAY */
7979 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7980 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
7981 "address=" MACSTR
"\n",
7982 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
7983 if (os_snprintf_error(end
- pos
, ret
))
7992 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
7993 char *buf
, size_t *resp_len
)
7996 const int reply_size
= 2048;
7998 int level
= MSG_DEBUG
;
8000 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
8001 char *pos
= os_strchr(buf
+ 7, ' ');
8004 return wpas_global_ctrl_iface_ifname(global
,
8010 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
8014 if (os_strcmp(buf
, "PING") == 0)
8015 level
= MSG_EXCESSIVE
;
8016 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
8017 (const u8
*) buf
, os_strlen(buf
));
8019 reply
= os_malloc(reply_size
);
8020 if (reply
== NULL
) {
8025 os_memcpy(reply
, "OK\n", 3);
8028 if (os_strcmp(buf
, "PING") == 0) {
8029 os_memcpy(reply
, "PONG\n", 5);
8031 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
8032 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
8034 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
8035 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
8037 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
8038 reply_len
= wpa_supplicant_global_iface_list(
8039 global
, reply
, reply_size
);
8040 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
8041 reply_len
= wpa_supplicant_global_iface_interfaces(
8042 global
, reply
, reply_size
);
8043 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
8044 wpa_supplicant_terminate_proc(global
);
8045 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
8046 wpas_notify_suspend(global
);
8047 } else if (os_strcmp(buf
, "RESUME") == 0) {
8048 wpas_notify_resume(global
);
8049 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
8050 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
8052 if (global
->p2p_init_wpa_s
) {
8054 /* Check if P2P redirection would work for this
8056 return wpa_supplicant_ctrl_iface_process(
8057 global
->p2p_init_wpa_s
,
8060 #endif /* CONFIG_P2P */
8063 #ifndef CONFIG_NO_CONFIG_WRITE
8064 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
8065 if (wpas_global_ctrl_iface_save_config(global
))
8067 #endif /* CONFIG_NO_CONFIG_WRITE */
8068 } else if (os_strcmp(buf
, "STATUS") == 0) {
8069 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
8071 #ifdef CONFIG_MODULE_TESTS
8072 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
8073 int wpas_module_tests(void);
8074 if (wpas_module_tests() < 0)
8076 #endif /* CONFIG_MODULE_TESTS */
8077 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
8078 if (wpa_debug_reopen_file() < 0)
8081 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
8085 if (reply_len
< 0) {
8086 os_memcpy(reply
, "FAIL\n", 5);
8090 *resp_len
= reply_len
;