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 if (os_snprintf_error(buflen
, res
))
481 #endif /* CONFIG_WIFI_DISPLAY */
482 #ifdef CONFIG_TESTING_GET_GTK
483 } else if (os_strcmp(cmd
, "gtk") == 0) {
484 if (wpa_s
->last_gtk_len
== 0)
486 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
487 wpa_s
->last_gtk_len
);
489 #endif /* CONFIG_TESTING_GET_GTK */
492 if (res
< 0 || (unsigned int) res
>= buflen
)
498 #ifdef IEEE8021X_EAPOL
499 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
503 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
505 if (hwaddr_aton(addr
, bssid
)) {
506 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
511 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
512 rsn_preauth_deinit(wpa_s
->wpa
);
513 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
518 #endif /* IEEE8021X_EAPOL */
521 #ifdef CONFIG_PEERKEY
522 /* MLME-STKSTART.request(peer) */
523 static int wpa_supplicant_ctrl_iface_stkstart(
524 struct wpa_supplicant
*wpa_s
, char *addr
)
528 if (hwaddr_aton(addr
, peer
)) {
529 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
530 "address '%s'", addr
);
534 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
537 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
539 #endif /* CONFIG_PEERKEY */
544 static int wpa_supplicant_ctrl_iface_tdls_discover(
545 struct wpa_supplicant
*wpa_s
, char *addr
)
550 if (hwaddr_aton(addr
, peer
)) {
551 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
552 "address '%s'", addr
);
556 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
559 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
560 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
562 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
568 static int wpa_supplicant_ctrl_iface_tdls_setup(
569 struct wpa_supplicant
*wpa_s
, char *addr
)
574 if (hwaddr_aton(addr
, peer
)) {
575 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
576 "address '%s'", addr
);
580 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
583 if ((wpa_s
->conf
->tdls_external_control
) &&
584 wpa_tdls_is_external_setup(wpa_s
->wpa
))
585 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
587 wpa_tdls_remove(wpa_s
->wpa
, peer
);
589 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
590 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
592 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
598 static int wpa_supplicant_ctrl_iface_tdls_teardown(
599 struct wpa_supplicant
*wpa_s
, char *addr
)
604 if (os_strcmp(addr
, "*") == 0) {
605 /* remove everyone */
606 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
607 wpa_tdls_teardown_peers(wpa_s
->wpa
);
611 if (hwaddr_aton(addr
, peer
)) {
612 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
613 "address '%s'", addr
);
617 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
620 if ((wpa_s
->conf
->tdls_external_control
) &&
621 wpa_tdls_is_external_setup(wpa_s
->wpa
))
622 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
624 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
625 ret
= wpa_tdls_teardown_link(
627 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
629 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
635 static int ctrl_iface_get_capability_tdls(
636 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
640 ret
= os_snprintf(buf
, buflen
, "%s\n",
641 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
643 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
644 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
645 if (ret
< 0 || (size_t) ret
> buflen
)
650 #endif /* CONFIG_TDLS */
653 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
655 char *token
, *context
= NULL
;
656 struct wmm_ac_ts_setup_params params
= {
661 while ((token
= str_token(cmd
, " ", &context
))) {
662 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
663 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
664 sscanf(token
, "nominal_msdu_size=%i",
665 ¶ms
.nominal_msdu_size
) == 1 ||
666 sscanf(token
, "mean_data_rate=%i",
667 ¶ms
.mean_data_rate
) == 1 ||
668 sscanf(token
, "min_phy_rate=%i",
669 ¶ms
.minimum_phy_rate
) == 1 ||
670 sscanf(token
, "sba=%i",
671 ¶ms
.surplus_bandwidth_allowance
) == 1)
674 if (os_strcasecmp(token
, "downlink") == 0) {
675 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
676 } else if (os_strcasecmp(token
, "uplink") == 0) {
677 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
678 } else if (os_strcasecmp(token
, "bidi") == 0) {
679 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
680 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
681 params
.fixed_nominal_msdu
= 1;
683 wpa_printf(MSG_DEBUG
,
684 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
691 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
695 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
699 return wpas_wmm_ac_delts(wpa_s
, tsid
);
703 #ifdef CONFIG_IEEE80211R
704 static int wpa_supplicant_ctrl_iface_ft_ds(
705 struct wpa_supplicant
*wpa_s
, char *addr
)
707 u8 target_ap
[ETH_ALEN
];
711 if (hwaddr_aton(addr
, target_ap
)) {
712 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
713 "address '%s'", addr
);
717 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
719 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
721 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
725 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
727 #endif /* CONFIG_IEEE80211R */
731 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
734 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
736 u8 p2p_dev_addr
[ETH_ALEN
];
737 #endif /* CONFIG_P2P */
739 u8
*_p2p_dev_addr
= NULL
;
740 #endif /* CONFIG_AP */
742 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
745 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
746 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
747 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
748 "P2P Device Address '%s'",
752 _p2p_dev_addr
= p2p_dev_addr
;
753 #endif /* CONFIG_P2P */
754 } else if (hwaddr_aton(cmd
, bssid
)) {
755 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
762 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
763 #endif /* CONFIG_AP */
765 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
769 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
770 char *cmd
, char *buf
,
773 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
777 pin
= os_strchr(cmd
, ' ');
781 if (os_strcmp(cmd
, "any") == 0)
783 else if (os_strcmp(cmd
, "get") == 0) {
784 ret
= wps_generate_pin();
786 } else if (hwaddr_aton(cmd
, bssid
)) {
787 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
793 if (wpa_s
->ap_iface
) {
798 pos
= os_strchr(pin
, ' ');
805 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
806 buf
, buflen
, timeout
);
808 #endif /* CONFIG_AP */
811 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
815 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
816 if (os_snprintf_error(buflen
, ret
))
821 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
826 /* Return the generated PIN */
827 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
828 if (os_snprintf_error(buflen
, ret
))
834 static int wpa_supplicant_ctrl_iface_wps_check_pin(
835 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
842 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
843 (u8
*) cmd
, os_strlen(cmd
));
844 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
845 if (*pos
< '0' || *pos
> '9')
849 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
853 if (len
!= 4 && len
!= 8) {
854 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
860 unsigned int pin_val
;
862 if (!wps_pin_valid(pin_val
)) {
863 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
864 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
865 if (os_snprintf_error(buflen
, ret
))
871 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
872 if (os_snprintf_error(buflen
, ret
))
879 #ifdef CONFIG_WPS_NFC
881 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
884 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
886 if (cmd
== NULL
|| cmd
[0] == '\0')
888 else if (hwaddr_aton(cmd
, bssid
))
891 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
896 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
897 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
904 pos
= os_strchr(cmd
, ' ');
907 if (os_strcmp(cmd
, "WPS") == 0)
909 else if (os_strcmp(cmd
, "NDEF") == 0)
914 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
918 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
929 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
930 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
936 if (os_strcmp(cmd
, "WPS") == 0)
938 else if (os_strcmp(cmd
, "NDEF") == 0)
943 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
947 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
958 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
959 struct wpa_supplicant
*wpa_s
, char *pos
)
967 freq
= strstr(pos
, " freq=");
971 forced_freq
= atoi(freq
);
974 len
= os_strlen(pos
);
979 buf
= wpabuf_alloc(len
);
982 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
987 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
994 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
995 char *reply
, size_t max_len
,
1001 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1005 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1007 reply
[res
++] = '\n';
1017 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1018 char *reply
, size_t max_len
,
1024 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1026 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1030 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1032 reply
[res
++] = '\n';
1039 #endif /* CONFIG_P2P */
1042 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1043 char *cmd
, char *reply
,
1049 pos
= os_strchr(cmd
, ' ');
1054 if (os_strcmp(cmd
, "WPS") == 0)
1056 else if (os_strcmp(cmd
, "NDEF") == 0)
1061 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1064 return wpas_ctrl_nfc_get_handover_req_wps(
1065 wpa_s
, reply
, max_len
, ndef
);
1069 if (os_strcmp(pos
, "P2P-CR") == 0) {
1070 return wpas_ctrl_nfc_get_handover_req_p2p(
1071 wpa_s
, reply
, max_len
, ndef
);
1073 #endif /* CONFIG_P2P */
1079 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1080 char *reply
, size_t max_len
,
1081 int ndef
, int cr
, char *uuid
)
1086 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1090 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1092 reply
[res
++] = '\n';
1102 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1103 char *reply
, size_t max_len
,
1109 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1113 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1115 reply
[res
++] = '\n';
1122 #endif /* CONFIG_P2P */
1125 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1126 char *cmd
, char *reply
,
1132 pos
= os_strchr(cmd
, ' ');
1137 if (os_strcmp(cmd
, "WPS") == 0)
1139 else if (os_strcmp(cmd
, "NDEF") == 0)
1144 pos2
= os_strchr(pos
, ' ');
1147 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1150 return wpas_ctrl_nfc_get_handover_sel_wps(
1151 wpa_s
, reply
, max_len
, ndef
,
1152 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1156 if (os_strcmp(pos
, "P2P-CR") == 0) {
1157 return wpas_ctrl_nfc_get_handover_sel_p2p(
1158 wpa_s
, reply
, max_len
, ndef
, 0);
1161 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1162 return wpas_ctrl_nfc_get_handover_sel_p2p(
1163 wpa_s
, reply
, max_len
, ndef
, 1);
1165 #endif /* CONFIG_P2P */
1171 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1175 struct wpabuf
*req
, *sel
;
1177 char *pos
, *role
, *type
, *pos2
;
1180 int forced_freq
= 0;
1182 freq
= strstr(cmd
, " freq=");
1186 forced_freq
= atoi(freq
);
1188 #endif /* CONFIG_P2P */
1191 pos
= os_strchr(role
, ' ');
1193 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1199 pos
= os_strchr(type
, ' ');
1201 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1206 pos2
= os_strchr(pos
, ' ');
1208 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1213 len
= os_strlen(pos
);
1215 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1220 req
= wpabuf_alloc(len
);
1222 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1225 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1226 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1231 len
= os_strlen(pos2
);
1233 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1239 sel
= wpabuf_alloc(len
);
1241 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1245 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1246 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1252 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1253 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1255 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1256 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1258 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1260 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1262 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1263 #endif /* CONFIG_AP */
1265 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1267 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1268 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1270 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1272 #endif /* CONFIG_P2P */
1274 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1275 "reported: role=%s type=%s", role
, type
);
1282 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1287 #endif /* CONFIG_WPS_NFC */
1290 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1299 struct wps_new_ap_settings ap
;
1301 pin
= os_strchr(cmd
, ' ');
1306 if (hwaddr_aton(cmd
, bssid
)) {
1307 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1312 new_ssid
= os_strchr(pin
, ' ');
1313 if (new_ssid
== NULL
)
1314 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1317 new_auth
= os_strchr(new_ssid
, ' ');
1318 if (new_auth
== NULL
)
1322 new_encr
= os_strchr(new_auth
, ' ');
1323 if (new_encr
== NULL
)
1327 new_key
= os_strchr(new_encr
, ' ');
1328 if (new_key
== NULL
)
1332 os_memset(&ap
, 0, sizeof(ap
));
1333 ap
.ssid_hex
= new_ssid
;
1336 ap
.key_hex
= new_key
;
1337 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1342 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1343 char *cmd
, char *buf
,
1348 const char *pin_txt
;
1350 if (!wpa_s
->ap_iface
)
1353 pos
= os_strchr(cmd
, ' ');
1357 if (os_strcmp(cmd
, "disable") == 0) {
1358 wpas_wps_ap_pin_disable(wpa_s
);
1359 return os_snprintf(buf
, buflen
, "OK\n");
1362 if (os_strcmp(cmd
, "random") == 0) {
1364 timeout
= atoi(pos
);
1365 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1366 if (pin_txt
== NULL
)
1368 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1371 if (os_strcmp(cmd
, "get") == 0) {
1372 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1373 if (pin_txt
== NULL
)
1375 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1378 if (os_strcmp(cmd
, "set") == 0) {
1383 pos
= os_strchr(pos
, ' ');
1386 timeout
= atoi(pos
);
1388 if (os_strlen(pin
) > buflen
)
1390 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1392 return os_snprintf(buf
, buflen
, "%s", pin
);
1397 #endif /* CONFIG_AP */
1400 #ifdef CONFIG_WPS_ER
1401 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1404 char *uuid
= cmd
, *pin
, *pos
;
1405 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1406 pin
= os_strchr(uuid
, ' ');
1410 pos
= os_strchr(pin
, ' ');
1413 if (hwaddr_aton(pos
, addr_buf
) == 0)
1416 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1420 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1423 char *uuid
= cmd
, *pin
;
1424 pin
= os_strchr(uuid
, ' ');
1428 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1432 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1433 struct wpa_supplicant
*wpa_s
, char *cmd
)
1435 char *uuid
= cmd
, *id
;
1436 id
= os_strchr(uuid
, ' ');
1440 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1444 static int wpa_supplicant_ctrl_iface_wps_er_config(
1445 struct wpa_supplicant
*wpa_s
, char *cmd
)
1452 struct wps_new_ap_settings ap
;
1454 pin
= os_strchr(cmd
, ' ');
1459 new_ssid
= os_strchr(pin
, ' ');
1460 if (new_ssid
== NULL
)
1464 new_auth
= os_strchr(new_ssid
, ' ');
1465 if (new_auth
== NULL
)
1469 new_encr
= os_strchr(new_auth
, ' ');
1470 if (new_encr
== NULL
)
1474 new_key
= os_strchr(new_encr
, ' ');
1475 if (new_key
== NULL
)
1479 os_memset(&ap
, 0, sizeof(ap
));
1480 ap
.ssid_hex
= new_ssid
;
1483 ap
.key_hex
= new_key
;
1484 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1488 #ifdef CONFIG_WPS_NFC
1489 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1490 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1497 uuid
= os_strchr(cmd
, ' ');
1502 if (os_strcmp(cmd
, "WPS") == 0)
1504 else if (os_strcmp(cmd
, "NDEF") == 0)
1509 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1513 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1515 reply
[res
++] = '\n';
1522 #endif /* CONFIG_WPS_NFC */
1523 #endif /* CONFIG_WPS_ER */
1525 #endif /* CONFIG_WPS */
1528 #ifdef CONFIG_IBSS_RSN
1529 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1530 struct wpa_supplicant
*wpa_s
, char *addr
)
1534 if (hwaddr_aton(addr
, peer
)) {
1535 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1536 "address '%s'", addr
);
1540 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1543 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1545 #endif /* CONFIG_IBSS_RSN */
1548 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1551 #ifdef IEEE8021X_EAPOL
1554 struct wpa_ssid
*ssid
;
1556 pos
= os_strchr(rsp
, '-');
1561 pos
= os_strchr(pos
, ':');
1566 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1567 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1568 (u8
*) pos
, os_strlen(pos
));
1570 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1572 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1577 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1579 #else /* IEEE8021X_EAPOL */
1580 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1582 #endif /* IEEE8021X_EAPOL */
1586 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1588 char *buf
, size_t buflen
)
1590 char *pos
, *end
, tmp
[30];
1591 int res
, verbose
, wps
, ret
;
1594 #endif /* CONFIG_HS20 */
1596 if (os_strcmp(params
, "-DRIVER") == 0)
1597 return wpa_drv_status(wpa_s
, buf
, buflen
);
1598 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1599 wps
= os_strcmp(params
, "-WPS") == 0;
1602 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1603 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1604 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1605 MAC2STR(wpa_s
->bssid
));
1606 if (os_snprintf_error(end
- pos
, ret
))
1609 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1611 if (os_snprintf_error(end
- pos
, ret
))
1615 u8
*_ssid
= ssid
->ssid
;
1616 size_t ssid_len
= ssid
->ssid_len
;
1617 u8 ssid_buf
[MAX_SSID_LEN
];
1618 if (ssid_len
== 0) {
1619 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1626 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1627 wpa_ssid_txt(_ssid
, ssid_len
),
1629 if (os_snprintf_error(end
- pos
, ret
))
1633 if (wps
&& ssid
->passphrase
&&
1634 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1635 (ssid
->mode
== WPAS_MODE_AP
||
1636 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1637 ret
= os_snprintf(pos
, end
- pos
,
1640 if (os_snprintf_error(end
- pos
, ret
))
1645 ret
= os_snprintf(pos
, end
- pos
,
1648 if (os_snprintf_error(end
- pos
, ret
))
1653 switch (ssid
->mode
) {
1654 case WPAS_MODE_INFRA
:
1655 ret
= os_snprintf(pos
, end
- pos
,
1658 case WPAS_MODE_IBSS
:
1659 ret
= os_snprintf(pos
, end
- pos
,
1663 ret
= os_snprintf(pos
, end
- pos
,
1666 case WPAS_MODE_P2P_GO
:
1667 ret
= os_snprintf(pos
, end
- pos
,
1670 case WPAS_MODE_P2P_GROUP_FORMATION
:
1671 ret
= os_snprintf(pos
, end
- pos
,
1672 "mode=P2P GO - group "
1679 if (ret
< 0 || ret
>= end
- pos
)
1685 if (wpa_s
->ap_iface
) {
1686 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1690 #endif /* CONFIG_AP */
1691 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1694 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1697 #endif /* CONFIG_AP */
1698 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1699 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1700 wpa_s
->sme
.sae
.group
);
1701 if (os_snprintf_error(end
- pos
, ret
))
1705 #endif /* CONFIG_SAE */
1706 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1707 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1708 if (os_snprintf_error(end
- pos
, ret
))
1713 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1714 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1715 if (os_snprintf_error(end
- pos
, ret
))
1721 if (wpa_s
->global
->p2p
) {
1722 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1723 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1724 if (os_snprintf_error(end
- pos
, ret
))
1728 #endif /* CONFIG_P2P */
1730 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1731 MAC2STR(wpa_s
->own_addr
));
1732 if (os_snprintf_error(end
- pos
, ret
))
1737 if (wpa_s
->current_bss
&&
1738 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1739 HS20_IE_VENDOR_TYPE
)) &&
1740 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1741 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1744 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
1745 release
= rel_num
+ 1;
1747 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
1748 if (os_snprintf_error(end
- pos
, ret
))
1753 if (wpa_s
->current_ssid
) {
1754 struct wpa_cred
*cred
;
1757 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1760 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1763 if (cred
->provisioning_sp
) {
1764 ret
= os_snprintf(pos
, end
- pos
,
1765 "provisioning_sp=%s\n",
1766 cred
->provisioning_sp
);
1767 if (os_snprintf_error(end
- pos
, ret
))
1776 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
1777 struct wpabuf
*names
=
1778 wpa_s
->current_bss
->anqp
->domain_name
;
1779 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
1781 if (domain_name_list_contains(
1782 names
, cred
->domain
[i
], 1))
1785 if (i
== cred
->num_domain
)
1786 i
= 0; /* show first entry by default */
1788 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
1790 if (os_snprintf_error(end
- pos
, ret
))
1795 if (wpa_s
->current_bss
== NULL
||
1796 wpa_s
->current_bss
->anqp
== NULL
)
1799 res
= interworking_home_sp_cred(
1801 wpa_s
->current_bss
->anqp
->domain_name
);
1809 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1810 if (os_snprintf_error(end
- pos
, ret
))
1817 #endif /* CONFIG_HS20 */
1819 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1820 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1821 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1827 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1834 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1835 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1836 if (os_snprintf_error(end
- pos
, ret
))
1840 #endif /* CONFIG_WPS */
1844 * Allow using the STATUS command with default behavior, say for debug,
1845 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1846 * events with STATUS-NO_EVENTS.
1848 if (os_strcmp(params
, "-NO_EVENTS")) {
1849 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1850 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1851 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1853 MAC2STR(wpa_s
->bssid
),
1854 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1855 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1856 wpa_s
->current_ssid
->ssid_len
) : "");
1857 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1858 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1859 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1860 "- connection to " MACSTR
1861 " completed %s [id=%d id_str=%s]",
1862 MAC2STR(wpa_s
->bssid
), "(auth)",
1863 ssid
? ssid
->id
: -1,
1864 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1867 #endif /* ANDROID */
1873 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1878 struct wpa_ssid
*ssid
;
1881 /* cmd: "<network id> <BSSID>" */
1882 pos
= os_strchr(cmd
, ' ');
1887 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1888 if (hwaddr_aton(pos
, bssid
)) {
1889 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1893 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1895 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1900 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1901 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1907 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1908 char *cmd
, char *buf
,
1912 struct wpa_blacklist
*e
;
1916 /* cmd: "BLACKLIST [<BSSID>]" */
1920 e
= wpa_s
->blacklist
;
1922 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1924 if (os_snprintf_error(end
- pos
, ret
))
1933 if (os_strncmp(cmd
, "clear", 5) == 0) {
1934 wpa_blacklist_clear(wpa_s
);
1935 os_memcpy(buf
, "OK\n", 3);
1939 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1940 if (hwaddr_aton(cmd
, bssid
)) {
1941 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1946 * Add the BSSID twice, so its count will be 2, causing it to be
1947 * skipped when processing scan results.
1949 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1952 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1955 os_memcpy(buf
, "OK\n", 3);
1960 static const char * debug_level_str(int level
)
1981 static int str_to_debug_level(const char *s
)
1983 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1984 return MSG_EXCESSIVE
;
1985 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1987 if (os_strcasecmp(s
, "DEBUG") == 0)
1989 if (os_strcasecmp(s
, "INFO") == 0)
1991 if (os_strcasecmp(s
, "WARNING") == 0)
1993 if (os_strcasecmp(s
, "ERROR") == 0)
1999 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2000 char *cmd
, char *buf
,
2003 char *pos
, *end
, *stamp
;
2006 /* cmd: "LOG_LEVEL [<level>]" */
2010 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2012 debug_level_str(wpa_debug_level
),
2013 wpa_debug_timestamp
);
2014 if (os_snprintf_error(end
- pos
, ret
))
2023 stamp
= os_strchr(cmd
, ' ');
2026 while (*stamp
== ' ') {
2031 if (cmd
&& os_strlen(cmd
)) {
2032 int level
= str_to_debug_level(cmd
);
2035 wpa_debug_level
= level
;
2038 if (stamp
&& os_strlen(stamp
))
2039 wpa_debug_timestamp
= atoi(stamp
);
2041 os_memcpy(buf
, "OK\n", 3);
2046 static int wpa_supplicant_ctrl_iface_list_networks(
2047 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2049 char *pos
, *end
, *prev
;
2050 struct wpa_ssid
*ssid
;
2055 ret
= os_snprintf(pos
, end
- pos
,
2056 "network id / ssid / bssid / flags\n");
2057 if (os_snprintf_error(end
- pos
, ret
))
2061 ssid
= wpa_s
->conf
->ssid
;
2063 /* skip over ssids until we find next one */
2064 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2065 int last_id
= atoi(cmd
+ 8);
2066 if (last_id
!= -1) {
2067 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2075 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2077 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2078 if (os_snprintf_error(end
- pos
, ret
))
2081 if (ssid
->bssid_set
) {
2082 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2083 MAC2STR(ssid
->bssid
));
2085 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2087 if (os_snprintf_error(end
- pos
, ret
))
2090 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2091 ssid
== wpa_s
->current_ssid
?
2093 ssid
->disabled
? "[DISABLED]" : "",
2094 ssid
->disabled_until
.sec
?
2095 "[TEMP-DISABLED]" : "",
2096 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2098 if (os_snprintf_error(end
- pos
, ret
))
2101 ret
= os_snprintf(pos
, end
- pos
, "\n");
2102 if (os_snprintf_error(end
- pos
, ret
))
2113 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2116 ret
= os_snprintf(pos
, end
- pos
, "-");
2117 if (os_snprintf_error(end
- pos
, ret
))
2120 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2128 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2129 const u8
*ie
, size_t ie_len
)
2131 struct wpa_ie_data data
;
2135 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2136 if (os_snprintf_error(end
- pos
, ret
))
2140 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2141 ret
= os_snprintf(pos
, end
- pos
, "?]");
2142 if (os_snprintf_error(end
- pos
, ret
))
2149 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2150 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2151 pos
== start
? "" : "+");
2152 if (os_snprintf_error(end
- pos
, ret
))
2156 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2157 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2158 pos
== start
? "" : "+");
2159 if (os_snprintf_error(end
- pos
, ret
))
2163 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2164 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2165 pos
== start
? "" : "+");
2166 if (os_snprintf_error(end
- pos
, ret
))
2170 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2171 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2172 pos
== start
? "" : "+");
2173 if (os_snprintf_error(end
- pos
, ret
))
2177 #ifdef CONFIG_IEEE80211R
2178 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2179 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2180 pos
== start
? "" : "+");
2181 if (os_snprintf_error(end
- pos
, ret
))
2185 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2186 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2187 pos
== start
? "" : "+");
2188 if (os_snprintf_error(end
- pos
, ret
))
2192 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2193 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2194 pos
== start
? "" : "+");
2195 if (os_snprintf_error(end
- pos
, ret
))
2199 #endif /* CONFIG_IEEE80211R */
2200 #ifdef CONFIG_IEEE80211W
2201 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2202 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2203 pos
== start
? "" : "+");
2204 if (os_snprintf_error(end
- pos
, ret
))
2208 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2209 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2210 pos
== start
? "" : "+");
2211 if (os_snprintf_error(end
- pos
, ret
))
2215 #endif /* CONFIG_IEEE80211W */
2217 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2218 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2219 pos
== start
? "" : "+");
2220 if (os_snprintf_error(end
- pos
, ret
))
2225 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2227 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2228 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2229 if (os_snprintf_error(end
- pos
, ret
))
2234 ret
= os_snprintf(pos
, end
- pos
, "]");
2235 if (os_snprintf_error(end
- pos
, ret
))
2244 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2245 char *pos
, char *end
,
2246 struct wpabuf
*wps_ie
)
2253 if (wps_is_selected_pbc_registrar(wps_ie
))
2255 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2257 else if (wps_is_selected_pin_registrar(wps_ie
))
2262 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2263 if (!os_snprintf_error(end
- pos
, ret
))
2265 wpabuf_free(wps_ie
);
2268 #endif /* CONFIG_WPS */
2271 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2272 char *pos
, char *end
,
2273 const struct wpa_bss
*bss
)
2276 struct wpabuf
*wps_ie
;
2277 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2278 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2279 #else /* CONFIG_WPS */
2281 #endif /* CONFIG_WPS */
2285 /* Format one result on one text line into a buffer. */
2286 static int wpa_supplicant_ctrl_iface_scan_result(
2287 struct wpa_supplicant
*wpa_s
,
2288 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2292 const u8
*ie
, *ie2
, *p2p
, *mesh
;
2294 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2295 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2297 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2298 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2299 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2301 return 0; /* Do not show P2P listen discovery results here */
2306 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2307 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2308 if (os_snprintf_error(end
- pos
, ret
))
2311 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2313 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2314 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2316 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2319 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2320 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2321 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2322 if (os_snprintf_error(end
- pos
, ret
))
2327 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2328 if (os_snprintf_error(end
- pos
, ret
))
2332 if (bss_is_dmg(bss
)) {
2334 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2335 if (os_snprintf_error(end
- pos
, ret
))
2338 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2339 case IEEE80211_CAP_DMG_IBSS
:
2342 case IEEE80211_CAP_DMG_AP
:
2345 case IEEE80211_CAP_DMG_PBSS
:
2352 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2353 if (os_snprintf_error(end
- pos
, ret
))
2357 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2358 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2359 if (os_snprintf_error(end
- pos
, ret
))
2363 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2364 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2365 if (os_snprintf_error(end
- pos
, ret
))
2371 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2372 if (os_snprintf_error(end
- pos
, ret
))
2377 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2378 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2379 if (os_snprintf_error(end
- pos
, ret
))
2383 #endif /* CONFIG_HS20 */
2385 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2386 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2387 if (os_snprintf_error(end
- pos
, ret
))
2391 ret
= os_snprintf(pos
, end
- pos
, "\n");
2392 if (os_snprintf_error(end
- pos
, ret
))
2400 static int wpa_supplicant_ctrl_iface_scan_results(
2401 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2404 struct wpa_bss
*bss
;
2409 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2411 if (os_snprintf_error(end
- pos
, ret
))
2415 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2416 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2418 if (ret
< 0 || ret
>= end
- pos
)
2429 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2430 struct wpa_supplicant
*wpa_s
, char *cmd
)
2433 struct wpa_ssid
*ssid
;
2436 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2438 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2440 wpa_printf(MSG_DEBUG
,
2441 "CTRL_IFACE: Could not find network id=%d", id
);
2444 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2445 wpa_printf(MSG_DEBUG
,
2446 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2449 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2450 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2451 wpa_printf(MSG_ERROR
,
2452 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2457 * TODO: If necessary write our own group_add function,
2458 * for now we can reuse select_network
2460 wpa_supplicant_select_network(wpa_s
, ssid
);
2466 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2467 struct wpa_supplicant
*wpa_s
, char *cmd
)
2470 * TODO: Support a multiple mesh and other iface type combinations
2472 if (os_strcmp(cmd
, wpa_s
->ifname
) != 0) {
2473 wpa_printf(MSG_DEBUG
,
2474 "CTRL_IFACE: MESH_GROUP_REMOVE unknown interface name: %s",
2479 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2481 wpa_s
->reassociate
= 0;
2482 wpa_s
->disconnected
= 1;
2483 wpa_supplicant_cancel_sched_scan(wpa_s
);
2484 wpa_supplicant_cancel_scan(wpa_s
);
2487 * TODO: If necessary write our own group_remove function,
2488 * for now we can reuse deauthenticate
2490 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2495 #endif /* CONFIG_MESH */
2498 static int wpa_supplicant_ctrl_iface_select_network(
2499 struct wpa_supplicant
*wpa_s
, char *cmd
)
2502 struct wpa_ssid
*ssid
;
2505 /* cmd: "<network id>" or "any" */
2506 if (os_strncmp(cmd
, "any", 3) == 0) {
2507 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2511 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2513 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2515 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2516 "network id=%d", id
);
2519 if (ssid
->disabled
== 2) {
2520 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2521 "SELECT_NETWORK with persistent P2P group");
2526 pos
= os_strstr(cmd
, " freq=");
2528 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
2530 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2531 os_free(wpa_s
->manual_scan_freqs
);
2532 wpa_s
->manual_scan_freqs
= freqs
;
2536 wpa_supplicant_select_network(wpa_s
, ssid
);
2542 static int wpa_supplicant_ctrl_iface_enable_network(
2543 struct wpa_supplicant
*wpa_s
, char *cmd
)
2546 struct wpa_ssid
*ssid
;
2548 /* cmd: "<network id>" or "all" */
2549 if (os_strcmp(cmd
, "all") == 0) {
2550 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2554 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2556 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2558 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2559 "network id=%d", id
);
2562 if (ssid
->disabled
== 2) {
2563 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2564 "ENABLE_NETWORK with persistent P2P group");
2568 if (os_strstr(cmd
, " no-connect")) {
2573 wpa_supplicant_enable_network(wpa_s
, ssid
);
2579 static int wpa_supplicant_ctrl_iface_disable_network(
2580 struct wpa_supplicant
*wpa_s
, char *cmd
)
2583 struct wpa_ssid
*ssid
;
2585 /* cmd: "<network id>" or "all" */
2586 if (os_strcmp(cmd
, "all") == 0) {
2587 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2591 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2593 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2595 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2596 "network id=%d", id
);
2599 if (ssid
->disabled
== 2) {
2600 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2601 "DISABLE_NETWORK with persistent P2P "
2606 wpa_supplicant_disable_network(wpa_s
, ssid
);
2612 static int wpa_supplicant_ctrl_iface_add_network(
2613 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2615 struct wpa_ssid
*ssid
;
2618 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2620 ssid
= wpa_config_add_network(wpa_s
->conf
);
2624 wpas_notify_network_added(wpa_s
, ssid
);
2627 wpa_config_set_network_defaults(ssid
);
2629 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2630 if (os_snprintf_error(buflen
, ret
))
2636 static int wpa_supplicant_ctrl_iface_remove_network(
2637 struct wpa_supplicant
*wpa_s
, char *cmd
)
2640 struct wpa_ssid
*ssid
;
2643 /* cmd: "<network id>" or "all" */
2644 if (os_strcmp(cmd
, "all") == 0) {
2645 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2646 if (wpa_s
->sched_scanning
)
2647 wpa_supplicant_cancel_sched_scan(wpa_s
);
2649 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2650 if (wpa_s
->current_ssid
) {
2652 wpa_s
->sme
.prev_bssid_set
= 0;
2653 #endif /* CONFIG_SME */
2654 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2655 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2656 wpa_supplicant_deauthenticate(
2657 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2659 ssid
= wpa_s
->conf
->ssid
;
2661 struct wpa_ssid
*remove_ssid
= ssid
;
2664 if (wpa_s
->last_ssid
== remove_ssid
)
2665 wpa_s
->last_ssid
= NULL
;
2666 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2667 wpa_config_remove_network(wpa_s
->conf
, id
);
2673 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2675 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2677 wpas_notify_network_removed(wpa_s
, ssid
);
2679 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2684 if (wpa_s
->last_ssid
== ssid
)
2685 wpa_s
->last_ssid
= NULL
;
2687 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2689 wpa_s
->sme
.prev_bssid_set
= 0;
2690 #endif /* CONFIG_SME */
2692 * Invalidate the EAP session cache if the current or
2693 * previously used network is removed.
2695 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2698 if (ssid
== wpa_s
->current_ssid
) {
2699 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2700 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2702 wpa_supplicant_deauthenticate(wpa_s
,
2703 WLAN_REASON_DEAUTH_LEAVING
);
2706 was_disabled
= ssid
->disabled
;
2708 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2709 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2710 "network id=%d", id
);
2714 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2715 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2716 "network from filters");
2717 wpa_supplicant_cancel_sched_scan(wpa_s
);
2718 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2725 static int wpa_supplicant_ctrl_iface_update_network(
2726 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2727 char *name
, char *value
)
2729 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2730 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2731 "variable '%s'", name
);
2735 if (os_strcmp(name
, "bssid") != 0 &&
2736 os_strcmp(name
, "priority") != 0)
2737 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2739 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2741 * Invalidate the EAP session cache if anything in the current
2742 * or previously used configuration changes.
2744 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2747 if ((os_strcmp(name
, "psk") == 0 &&
2748 value
[0] == '"' && ssid
->ssid_len
) ||
2749 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2750 wpa_config_update_psk(ssid
);
2751 else if (os_strcmp(name
, "priority") == 0)
2752 wpa_config_update_prio_list(wpa_s
->conf
);
2753 else if (os_strcmp(name
, "no_auto_peer") == 0)
2754 ssid
->no_auto_peer
= atoi(value
);
2760 static int wpa_supplicant_ctrl_iface_set_network(
2761 struct wpa_supplicant
*wpa_s
, char *cmd
)
2763 int id
, ret
, prev_bssid_set
;
2764 struct wpa_ssid
*ssid
;
2766 u8 prev_bssid
[ETH_ALEN
];
2768 /* cmd: "<network id> <variable name> <value>" */
2769 name
= os_strchr(cmd
, ' ');
2774 value
= os_strchr(name
, ' ');
2780 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2782 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2783 (u8
*) value
, os_strlen(value
));
2785 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2787 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2792 prev_bssid_set
= ssid
->bssid_set
;
2793 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
2794 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
2797 (ssid
->bssid_set
!= prev_bssid_set
||
2798 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
2799 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
2804 static int wpa_supplicant_ctrl_iface_get_network(
2805 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2809 struct wpa_ssid
*ssid
;
2812 /* cmd: "<network id> <variable name>" */
2813 name
= os_strchr(cmd
, ' ');
2814 if (name
== NULL
|| buflen
== 0)
2819 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2822 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2824 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2829 value
= wpa_config_get_no_key(ssid
, name
);
2830 if (value
== NULL
) {
2831 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2832 "variable '%s'", name
);
2836 res
= os_strlcpy(buf
, value
, buflen
);
2837 if (res
>= buflen
) {
2848 static int wpa_supplicant_ctrl_iface_dup_network(
2849 struct wpa_supplicant
*wpa_s
, char *cmd
)
2851 struct wpa_ssid
*ssid_s
, *ssid_d
;
2852 char *name
, *id
, *value
;
2853 int id_s
, id_d
, ret
;
2855 /* cmd: "<src network id> <dst network id> <variable name>" */
2856 id
= os_strchr(cmd
, ' ');
2861 name
= os_strchr(id
, ' ');
2868 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2871 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
2872 if (ssid_s
== NULL
) {
2873 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2874 "network id=%d", id_s
);
2878 ssid_d
= wpa_config_get_network(wpa_s
->conf
, id_d
);
2879 if (ssid_d
== NULL
) {
2880 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2881 "network id=%d", id_d
);
2885 value
= wpa_config_get(ssid_s
, name
);
2886 if (value
== NULL
) {
2887 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2888 "variable '%s'", name
);
2892 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid_d
, name
,
2901 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2902 char *buf
, size_t buflen
)
2905 struct wpa_cred
*cred
;
2910 ret
= os_snprintf(pos
, end
- pos
,
2911 "cred id / realm / username / domain / imsi\n");
2912 if (os_snprintf_error(end
- pos
, ret
))
2916 cred
= wpa_s
->conf
->cred
;
2918 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2919 cred
->id
, cred
->realm
? cred
->realm
: "",
2920 cred
->username
? cred
->username
: "",
2921 cred
->domain
? cred
->domain
[0] : "",
2922 cred
->imsi
? cred
->imsi
: "");
2923 if (os_snprintf_error(end
- pos
, ret
))
2934 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2935 char *buf
, size_t buflen
)
2937 struct wpa_cred
*cred
;
2940 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2942 cred
= wpa_config_add_cred(wpa_s
->conf
);
2946 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
2948 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2949 if (os_snprintf_error(buflen
, ret
))
2955 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
2956 struct wpa_cred
*cred
)
2958 struct wpa_ssid
*ssid
;
2963 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2968 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
2969 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2973 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
2975 /* Remove any network entry created based on the removed credential */
2976 ssid
= wpa_s
->conf
->ssid
;
2978 if (ssid
->parent_cred
== cred
) {
2979 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
2980 "used the removed credential", ssid
->id
);
2981 os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
2983 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
2992 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
2996 struct wpa_cred
*cred
, *prev
;
2998 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2999 * "provisioning_sp=<FQDN> */
3000 if (os_strcmp(cmd
, "all") == 0) {
3001 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3002 cred
= wpa_s
->conf
->cred
;
3006 wpas_ctrl_remove_cred(wpa_s
, prev
);
3011 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3012 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3014 cred
= wpa_s
->conf
->cred
;
3020 for (i
= 0; i
< prev
->num_domain
; i
++) {
3021 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3024 wpas_ctrl_remove_cred(wpa_s
, prev
);
3032 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3033 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3035 cred
= wpa_s
->conf
->cred
;
3039 if (prev
->provisioning_sp
&&
3040 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3041 wpas_ctrl_remove_cred(wpa_s
, prev
);
3047 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3049 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3050 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3054 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3058 struct wpa_cred
*cred
;
3061 /* cmd: "<cred id> <variable name> <value>" */
3062 name
= os_strchr(cmd
, ' ');
3067 value
= os_strchr(name
, ' ');
3073 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3075 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3076 (u8
*) value
, os_strlen(value
));
3078 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3080 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3085 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3086 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3087 "variable '%s'", name
);
3091 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3097 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3098 char *cmd
, char *buf
,
3103 struct wpa_cred
*cred
;
3106 /* cmd: "<cred id> <variable name>" */
3107 name
= os_strchr(cmd
, ' ');
3113 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3116 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3118 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3123 value
= wpa_config_get_cred_no_key(cred
, name
);
3124 if (value
== NULL
) {
3125 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3130 res
= os_strlcpy(buf
, value
, buflen
);
3131 if (res
>= buflen
) {
3142 #ifndef CONFIG_NO_CONFIG_WRITE
3143 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3147 if (!wpa_s
->conf
->update_config
) {
3148 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3149 "to update configuration (update_config=0)");
3153 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3155 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3156 "update configuration");
3158 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3164 #endif /* CONFIG_NO_CONFIG_WRITE */
3167 struct cipher_info
{
3173 static const struct cipher_info ciphers
[] = {
3174 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3175 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3176 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3177 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3178 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3179 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3180 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3181 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3185 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3186 struct wpa_driver_capa
*capa
,
3187 char *buf
, size_t buflen
)
3200 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3206 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3207 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3208 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3209 pos
== buf
? "" : " ",
3211 if (os_snprintf_error(end
- pos
, ret
))
3221 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3222 struct wpa_driver_capa
*capa
,
3223 char *buf
, size_t buflen
)
3236 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3242 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3243 if (capa
->enc
& ciphers
[i
].capa
) {
3244 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3245 pos
== buf
? "" : " ",
3247 if (os_snprintf_error(end
- pos
, ret
))
3257 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3258 struct wpa_driver_capa
*capa
,
3259 char *buf
, size_t buflen
)
3271 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3278 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3279 if (os_snprintf_error(end
- pos
, ret
))
3283 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3284 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3285 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3286 if (os_snprintf_error(end
- pos
, ret
))
3291 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3292 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3293 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3294 if (os_snprintf_error(end
- pos
, ret
))
3299 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3300 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3301 if (os_snprintf_error(end
- pos
, ret
))
3310 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3311 struct wpa_driver_capa
*capa
,
3312 char *buf
, size_t buflen
)
3324 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3330 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3331 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3332 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3333 pos
== buf
? "" : " ");
3334 if (os_snprintf_error(end
- pos
, ret
))
3339 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3340 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3341 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3342 pos
== buf
? "" : " ");
3343 if (os_snprintf_error(end
- pos
, ret
))
3352 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
3353 struct wpa_driver_capa
*capa
,
3354 char *buf
, size_t buflen
)
3366 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3372 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3373 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3374 pos
== buf
? "" : " ");
3375 if (os_snprintf_error(end
- pos
, ret
))
3380 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3381 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3382 pos
== buf
? "" : " ");
3383 if (os_snprintf_error(end
- pos
, ret
))
3388 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3389 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3390 pos
== buf
? "" : " ");
3391 if (os_snprintf_error(end
- pos
, ret
))
3400 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3401 struct wpa_driver_capa
*capa
,
3402 char *buf
, size_t buflen
)
3414 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3420 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3421 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3422 pos
== buf
? "" : " ");
3423 if (os_snprintf_error(end
- pos
, ret
))
3428 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3429 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3430 pos
== buf
? "" : " ");
3431 if (os_snprintf_error(end
- pos
, ret
))
3440 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3441 char *buf
, size_t buflen
)
3443 struct hostapd_channel_data
*chnl
;
3445 char *pos
, *end
, *hmode
;
3450 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3451 switch (wpa_s
->hw
.modes
[j
].mode
) {
3452 case HOSTAPD_MODE_IEEE80211B
:
3455 case HOSTAPD_MODE_IEEE80211G
:
3458 case HOSTAPD_MODE_IEEE80211A
:
3461 case HOSTAPD_MODE_IEEE80211AD
:
3467 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3468 if (os_snprintf_error(end
- pos
, ret
))
3471 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3472 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3473 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3475 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3476 if (os_snprintf_error(end
- pos
, ret
))
3480 ret
= os_snprintf(pos
, end
- pos
, "\n");
3481 if (os_snprintf_error(end
- pos
, ret
))
3490 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3491 char *buf
, size_t buflen
)
3493 struct hostapd_channel_data
*chnl
;
3495 char *pos
, *end
, *hmode
;
3500 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3501 switch (wpa_s
->hw
.modes
[j
].mode
) {
3502 case HOSTAPD_MODE_IEEE80211B
:
3505 case HOSTAPD_MODE_IEEE80211G
:
3508 case HOSTAPD_MODE_IEEE80211A
:
3511 case HOSTAPD_MODE_IEEE80211AD
:
3517 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3519 if (os_snprintf_error(end
- pos
, ret
))
3522 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3523 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3524 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3526 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
3527 chnl
[i
].chan
, chnl
[i
].freq
,
3528 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
3530 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
3533 if (os_snprintf_error(end
- pos
, ret
))
3537 ret
= os_snprintf(pos
, end
- pos
, "\n");
3538 if (os_snprintf_error(end
- pos
, ret
))
3547 static int wpa_supplicant_ctrl_iface_get_capability(
3548 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3551 struct wpa_driver_capa capa
;
3557 /* Determine whether or not strict checking was requested */
3558 len
= os_strlcpy(field
, _field
, sizeof(field
));
3559 if (len
>= sizeof(field
))
3561 strict
= os_strchr(field
, ' ');
3562 if (strict
!= NULL
) {
3564 if (os_strcmp(strict
, "strict") != 0)
3568 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3569 field
, strict
? strict
: "");
3571 if (os_strcmp(field
, "eap") == 0) {
3572 return eap_get_names(buf
, buflen
);
3575 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3577 if (os_strcmp(field
, "pairwise") == 0)
3578 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3581 if (os_strcmp(field
, "group") == 0)
3582 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3585 if (os_strcmp(field
, "key_mgmt") == 0)
3586 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3589 if (os_strcmp(field
, "proto") == 0)
3590 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3593 if (os_strcmp(field
, "auth_alg") == 0)
3594 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3597 if (os_strcmp(field
, "modes") == 0)
3598 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3601 if (os_strcmp(field
, "channels") == 0)
3602 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3604 if (os_strcmp(field
, "freq") == 0)
3605 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3608 if (os_strcmp(field
, "tdls") == 0)
3609 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
3610 #endif /* CONFIG_TDLS */
3613 if (os_strcmp(field
, "erp") == 0) {
3614 res
= os_snprintf(buf
, buflen
, "ERP");
3615 if (os_snprintf_error(buflen
, res
))
3619 #endif /* CONFIG_EPR */
3621 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3628 #ifdef CONFIG_INTERWORKING
3629 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3630 struct wpabuf
*data
)
3640 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3641 if (os_snprintf_error(end
- pos
, ret
))
3645 d
= wpabuf_head_u8(data
);
3646 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3647 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3648 if (os_snprintf_error(end
- pos
, ret
))
3653 ret
= os_snprintf(pos
, end
- pos
, "\n");
3654 if (os_snprintf_error(end
- pos
, ret
))
3660 #endif /* CONFIG_INTERWORKING */
3663 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3664 unsigned long mask
, char *buf
, size_t buflen
)
3674 if (mask
& WPA_BSS_MASK_ID
) {
3675 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3676 if (os_snprintf_error(end
- pos
, ret
))
3681 if (mask
& WPA_BSS_MASK_BSSID
) {
3682 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3683 MAC2STR(bss
->bssid
));
3684 if (os_snprintf_error(end
- pos
, ret
))
3689 if (mask
& WPA_BSS_MASK_FREQ
) {
3690 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3691 if (os_snprintf_error(end
- pos
, ret
))
3696 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3697 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3699 if (os_snprintf_error(end
- pos
, ret
))
3704 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3705 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3707 if (os_snprintf_error(end
- pos
, ret
))
3712 if (mask
& WPA_BSS_MASK_QUAL
) {
3713 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3714 if (os_snprintf_error(end
- pos
, ret
))
3719 if (mask
& WPA_BSS_MASK_NOISE
) {
3720 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3721 if (os_snprintf_error(end
- pos
, ret
))
3726 if (mask
& WPA_BSS_MASK_LEVEL
) {
3727 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3728 if (os_snprintf_error(end
- pos
, ret
))
3733 if (mask
& WPA_BSS_MASK_TSF
) {
3734 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3735 (unsigned long long) bss
->tsf
);
3736 if (os_snprintf_error(end
- pos
, ret
))
3741 if (mask
& WPA_BSS_MASK_AGE
) {
3742 struct os_reltime now
;
3744 os_get_reltime(&now
);
3745 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3746 (int) (now
.sec
- bss
->last_update
.sec
));
3747 if (os_snprintf_error(end
- pos
, ret
))
3752 if (mask
& WPA_BSS_MASK_IE
) {
3753 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3754 if (os_snprintf_error(end
- pos
, ret
))
3758 ie
= (const u8
*) (bss
+ 1);
3759 for (i
= 0; i
< bss
->ie_len
; i
++) {
3760 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3761 if (os_snprintf_error(end
- pos
, ret
))
3766 ret
= os_snprintf(pos
, end
- pos
, "\n");
3767 if (os_snprintf_error(end
- pos
, ret
))
3772 if (mask
& WPA_BSS_MASK_FLAGS
) {
3773 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3774 if (os_snprintf_error(end
- pos
, ret
))
3778 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3780 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3782 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3784 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3786 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3787 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3788 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3789 if (os_snprintf_error(end
- pos
, ret
))
3793 if (bss_is_dmg(bss
)) {
3795 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
3796 if (os_snprintf_error(end
- pos
, ret
))
3799 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
3800 case IEEE80211_CAP_DMG_IBSS
:
3803 case IEEE80211_CAP_DMG_AP
:
3806 case IEEE80211_CAP_DMG_PBSS
:
3813 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
3814 if (os_snprintf_error(end
- pos
, ret
))
3818 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3819 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3820 if (os_snprintf_error(end
- pos
, ret
))
3824 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3825 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3826 if (os_snprintf_error(end
- pos
, ret
))
3831 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3832 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3833 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3834 if (os_snprintf_error(end
- pos
, ret
))
3839 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3840 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3841 if (os_snprintf_error(end
- pos
, ret
))
3845 #endif /* CONFIG_HS20 */
3847 ret
= os_snprintf(pos
, end
- pos
, "\n");
3848 if (os_snprintf_error(end
- pos
, ret
))
3853 if (mask
& WPA_BSS_MASK_SSID
) {
3854 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3855 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3856 if (os_snprintf_error(end
- pos
, ret
))
3862 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3863 ie
= (const u8
*) (bss
+ 1);
3864 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3865 if (ret
< 0 || ret
>= end
- pos
)
3869 #endif /* CONFIG_WPS */
3872 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3873 ie
= (const u8
*) (bss
+ 1);
3874 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3875 if (ret
< 0 || ret
>= end
- pos
)
3879 #endif /* CONFIG_P2P */
3881 #ifdef CONFIG_WIFI_DISPLAY
3882 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3884 ie
= (const u8
*) (bss
+ 1);
3885 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3886 WFD_IE_VENDOR_TYPE
);
3888 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3889 if (os_snprintf_error(end
- pos
, ret
)) {
3895 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3900 ret
= os_snprintf(pos
, end
- pos
, "\n");
3901 if (os_snprintf_error(end
- pos
, ret
))
3906 #endif /* CONFIG_WIFI_DISPLAY */
3908 #ifdef CONFIG_INTERWORKING
3909 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3910 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3911 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3913 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3914 anqp
->network_auth_type
);
3915 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3916 anqp
->roaming_consortium
);
3917 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3918 anqp
->ip_addr_type_availability
);
3919 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3921 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3922 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3925 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3926 anqp
->hs20_operator_friendly_name
);
3927 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3928 anqp
->hs20_wan_metrics
);
3929 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3930 anqp
->hs20_connection_capability
);
3931 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
3932 anqp
->hs20_operating_class
);
3933 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
3934 anqp
->hs20_osu_providers_list
);
3935 #endif /* CONFIG_HS20 */
3937 #endif /* CONFIG_INTERWORKING */
3940 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
3941 ie
= (const u8
*) (bss
+ 1);
3942 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3943 if (ret
< 0 || ret
>= end
- pos
)
3947 #endif /* CONFIG_MESH */
3949 if (mask
& WPA_BSS_MASK_DELIM
) {
3950 ret
= os_snprintf(pos
, end
- pos
, "====\n");
3951 if (os_snprintf_error(end
- pos
, ret
))
3960 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
3961 const char *cmd
, char *buf
,
3966 struct wpa_bss
*bss
;
3967 struct wpa_bss
*bsslast
= NULL
;
3968 struct dl_list
*next
;
3972 unsigned long mask
= WPA_BSS_MASK_ALL
;
3974 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
3975 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
3976 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
3978 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
3980 } else { /* N1-N2 */
3981 unsigned int id1
, id2
;
3983 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
3984 wpa_printf(MSG_INFO
, "Wrong BSS range "
3989 if (*(cmd
+ 6) == '-')
3992 id1
= atoi(cmd
+ 6);
3994 if (*ctmp
>= '0' && *ctmp
<= '9')
3997 id2
= (unsigned int) -1;
3998 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
3999 if (id2
== (unsigned int) -1)
4000 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4004 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4005 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4006 struct wpa_bss
*tmp
= bss
;
4008 next
= tmp
->list_id
.next
;
4009 if (next
== &wpa_s
->bss_id
)
4011 tmp
= dl_list_entry(
4012 next
, struct wpa_bss
,
4021 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4022 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4023 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4024 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4025 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4027 bss
= wpa_bss_get_id(wpa_s
, i
);
4028 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4030 bss
= wpa_bss_get_id(wpa_s
, i
);
4032 next
= bss
->list_id
.next
;
4033 if (next
== &wpa_s
->bss_id
)
4036 bss
= dl_list_entry(next
, struct wpa_bss
,
4040 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4041 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4042 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4045 #endif /* CONFIG_P2P */
4046 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4047 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4049 struct wpa_bss
*tmp
;
4052 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4061 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4062 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4064 mask
= WPA_BSS_MASK_ALL
;
4070 if (bsslast
== NULL
)
4073 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4077 if (bss
== bsslast
) {
4078 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4079 (bss
== dl_list_last(&wpa_s
->bss_id
,
4080 struct wpa_bss
, list_id
)))
4081 os_snprintf(buf
- 5, 5, "####\n");
4084 next
= bss
->list_id
.next
;
4085 if (next
== &wpa_s
->bss_id
)
4087 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4088 } while (bss
&& len
);
4094 static int wpa_supplicant_ctrl_iface_ap_scan(
4095 struct wpa_supplicant
*wpa_s
, char *cmd
)
4097 int ap_scan
= atoi(cmd
);
4098 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4102 static int wpa_supplicant_ctrl_iface_scan_interval(
4103 struct wpa_supplicant
*wpa_s
, char *cmd
)
4105 int scan_int
= atoi(cmd
);
4106 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4110 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4111 struct wpa_supplicant
*wpa_s
, char *cmd
)
4113 int expire_age
= atoi(cmd
);
4114 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4118 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4119 struct wpa_supplicant
*wpa_s
, char *cmd
)
4121 int expire_count
= atoi(cmd
);
4122 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4126 static int wpa_supplicant_ctrl_iface_bss_flush(
4127 struct wpa_supplicant
*wpa_s
, char *cmd
)
4129 int flush_age
= atoi(cmd
);
4132 wpa_bss_flush(wpa_s
);
4134 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4139 #ifdef CONFIG_TESTING_OPTIONS
4140 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4142 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4143 /* MLME-DELETEKEYS.request */
4144 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4145 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4146 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4147 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4148 #ifdef CONFIG_IEEE80211W
4149 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4150 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4151 #endif /* CONFIG_IEEE80211W */
4153 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4155 /* MLME-SETPROTECTION.request(None) */
4156 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4157 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4158 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4159 wpa_sm_drop_sa(wpa_s
->wpa
);
4161 #endif /* CONFIG_TESTING_OPTIONS */
4164 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4167 #ifdef CONFIG_NO_SCAN_PROCESSING
4169 #else /* CONFIG_NO_SCAN_PROCESSING */
4171 struct wpa_bss
*bss
;
4172 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4174 if (hwaddr_aton(addr
, bssid
)) {
4175 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4176 "address '%s'", addr
);
4180 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4183 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4184 "configuration known for the target AP");
4188 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4190 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4196 * TODO: Find best network configuration block from configuration to
4197 * allow roaming to other networks
4200 wpa_s
->reassociate
= 1;
4201 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4204 #endif /* CONFIG_NO_SCAN_PROCESSING */
4209 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
4211 unsigned int timeout
= atoi(cmd
);
4212 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
4213 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
4214 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
4216 unsigned int search_delay
;
4218 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4219 wpa_dbg(wpa_s
, MSG_INFO
,
4220 "Reject P2P_FIND since interface is disabled");
4223 if (os_strstr(cmd
, "type=social"))
4224 type
= P2P_FIND_ONLY_SOCIAL
;
4225 else if (os_strstr(cmd
, "type=progressive"))
4226 type
= P2P_FIND_PROGRESSIVE
;
4228 pos
= os_strstr(cmd
, "dev_id=");
4231 if (hwaddr_aton(pos
, dev_id
))
4236 pos
= os_strstr(cmd
, "dev_type=");
4239 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
4241 _dev_type
= dev_type
;
4244 pos
= os_strstr(cmd
, "delay=");
4247 search_delay
= atoi(pos
);
4249 search_delay
= wpas_p2p_search_delay(wpa_s
);
4251 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
4252 _dev_id
, search_delay
);
4256 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
4257 char *buf
, size_t buflen
)
4262 enum p2p_wps_method wps_method
;
4265 int persistent_group
, persistent_id
= -1;
4274 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4275 * [persistent|persistent=<network id>]
4276 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4279 if (hwaddr_aton(cmd
, addr
))
4287 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
4288 pos2
= os_strstr(pos
, " persistent=");
4290 struct wpa_ssid
*ssid
;
4291 persistent_id
= atoi(pos2
+ 12);
4292 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
4293 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
4294 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
4295 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
4296 "SSID id=%d for persistent P2P group (GO)",
4301 join
= os_strstr(pos
, " join") != NULL
;
4302 auth
= os_strstr(pos
, " auth") != NULL
;
4303 automatic
= os_strstr(pos
, " auto") != NULL
;
4304 pd
= os_strstr(pos
, " provdisc") != NULL
;
4305 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4306 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4309 pos2
= os_strstr(pos
, " go_intent=");
4312 go_intent
= atoi(pos2
);
4313 if (go_intent
< 0 || go_intent
> 15)
4317 pos2
= os_strstr(pos
, " freq=");
4325 if (os_strncmp(pos
, "pin", 3) == 0) {
4326 /* Request random PIN (to be displayed) and enable the PIN */
4327 wps_method
= WPS_PIN_DISPLAY
;
4328 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
4329 wps_method
= WPS_PBC
;
4332 pos
= os_strchr(pin
, ' ');
4333 wps_method
= WPS_PIN_KEYPAD
;
4336 if (os_strncmp(pos
, "display", 7) == 0)
4337 wps_method
= WPS_PIN_DISPLAY
;
4339 if (!wps_pin_str_valid(pin
)) {
4340 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
4345 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
4346 persistent_group
, automatic
, join
,
4347 auth
, go_intent
, freq
, persistent_id
, pd
,
4349 if (new_pin
== -2) {
4350 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4353 if (new_pin
== -3) {
4354 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4359 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
4360 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
4361 if (os_snprintf_error(buflen
, ret
))
4366 os_memcpy(buf
, "OK\n", 3);
4371 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4373 unsigned int timeout
= atoi(cmd
);
4374 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4375 wpa_dbg(wpa_s
, MSG_INFO
,
4376 "Reject P2P_LISTEN since interface is disabled");
4379 return wpas_p2p_listen(wpa_s
, timeout
);
4383 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
4387 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
4389 /* <addr> <config method> [join|auto] */
4391 if (hwaddr_aton(cmd
, addr
))
4399 if (os_strstr(pos
, " join") != NULL
)
4400 use
= WPAS_P2P_PD_FOR_JOIN
;
4401 else if (os_strstr(pos
, " auto") != NULL
)
4402 use
= WPAS_P2P_PD_AUTO
;
4404 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
4408 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
4411 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4413 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
4414 ssid
->passphrase
== NULL
)
4417 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
4418 return os_strlen(buf
);
4422 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
4423 char *buf
, size_t buflen
)
4427 u8 dst_buf
[ETH_ALEN
], *dst
;
4428 struct wpabuf
*tlvs
;
4432 if (hwaddr_aton(cmd
, dst_buf
))
4435 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
4436 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
4443 if (os_strncmp(pos
, "upnp ", 5) == 0) {
4446 if (hexstr2bin(pos
, &version
, 1) < 0)
4452 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
4453 #ifdef CONFIG_WIFI_DISPLAY
4454 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
4455 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
4456 #endif /* CONFIG_WIFI_DISPLAY */
4458 len
= os_strlen(pos
);
4462 tlvs
= wpabuf_alloc(len
);
4465 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
4470 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
4475 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
4476 if (os_snprintf_error(buflen
, res
))
4482 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
4485 long long unsigned val
;
4487 if (sscanf(cmd
, "%llx", &val
) != 1)
4490 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
4494 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4499 struct wpabuf
*resp_tlvs
;
4503 pos
= os_strchr(cmd
, ' ');
4511 if (hwaddr_aton(pos
, dst
))
4518 pos2
= os_strchr(pos
, ' ');
4522 dialog_token
= atoi(pos
);
4524 len
= os_strlen(pos2
);
4528 resp_tlvs
= wpabuf_alloc(len
);
4529 if (resp_tlvs
== NULL
)
4531 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
4532 wpabuf_free(resp_tlvs
);
4536 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
4537 wpabuf_free(resp_tlvs
);
4542 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
4545 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
4547 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
4552 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
4557 struct wpabuf
*query
, *resp
;
4559 pos
= os_strchr(cmd
, ' ');
4564 len
= os_strlen(cmd
);
4568 query
= wpabuf_alloc(len
);
4571 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4576 len
= os_strlen(pos
);
4582 resp
= wpabuf_alloc(len
);
4587 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4593 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4602 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4607 pos
= os_strchr(cmd
, ' ');
4612 if (hexstr2bin(cmd
, &version
, 1) < 0)
4615 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4619 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4623 pos
= os_strchr(cmd
, ' ');
4628 if (os_strcmp(cmd
, "bonjour") == 0)
4629 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4630 if (os_strcmp(cmd
, "upnp") == 0)
4631 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4632 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4637 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4641 struct wpabuf
*query
;
4644 len
= os_strlen(cmd
);
4648 query
= wpabuf_alloc(len
);
4651 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4656 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4662 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4667 pos
= os_strchr(cmd
, ' ');
4672 if (hexstr2bin(cmd
, &version
, 1) < 0)
4675 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4679 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4683 pos
= os_strchr(cmd
, ' ');
4688 if (os_strcmp(cmd
, "bonjour") == 0)
4689 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4690 if (os_strcmp(cmd
, "upnp") == 0)
4691 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4692 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4697 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4703 if (hwaddr_aton(cmd
, addr
))
4706 return wpas_p2p_reject(wpa_s
, addr
);
4710 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4714 struct wpa_ssid
*ssid
;
4715 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4716 int freq
= 0, pref_freq
= 0;
4720 pos
= os_strstr(cmd
, " peer=");
4723 if (hwaddr_aton(pos
, peer
))
4727 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4728 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4729 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4730 "for persistent P2P group",
4735 pos
= os_strstr(cmd
, " freq=");
4743 pos
= os_strstr(cmd
, " pref=");
4746 pref_freq
= atoi(pos
);
4751 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4752 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4755 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4760 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4763 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4765 pos
= os_strstr(cmd
, " peer=");
4771 if (hwaddr_aton(pos
, peer
)) {
4772 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4776 pos
= os_strstr(pos
, " go_dev_addr=");
4779 if (hwaddr_aton(pos
, go_dev_addr
)) {
4780 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4784 go_dev
= go_dev_addr
;
4787 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4791 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4793 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4794 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4795 if (os_strncmp(cmd
, "group=", 6) == 0)
4796 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4802 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4803 char *cmd
, int freq
, int ht40
,
4807 struct wpa_ssid
*ssid
;
4810 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4811 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4812 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4813 "for persistent P2P group",
4818 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, 0, ht40
, vht
,
4823 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4825 int freq
= 0, ht40
, vht
;
4828 pos
= os_strstr(cmd
, "freq=");
4830 freq
= atoi(pos
+ 5);
4832 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4833 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4836 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4837 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4839 if (os_strcmp(cmd
, "persistent") == 0 ||
4840 os_strncmp(cmd
, "persistent ", 11) == 0)
4841 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4842 if (os_strncmp(cmd
, "freq=", 5) == 0)
4843 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4845 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4847 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4853 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4854 char *buf
, size_t buflen
)
4856 u8 addr
[ETH_ALEN
], *addr_ptr
;
4858 const struct p2p_peer_info
*info
;
4860 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4861 struct wpa_ssid
*ssid
;
4864 if (!wpa_s
->global
->p2p
)
4867 if (os_strcmp(cmd
, "FIRST") == 0) {
4870 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4871 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4876 if (hwaddr_aton(cmd
, addr
) < 0)
4882 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4889 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4895 "serial_number=%s\n"
4896 "config_methods=0x%x\n"
4898 "group_capab=0x%x\n"
4900 MAC2STR(info
->p2p_device_addr
),
4901 wps_dev_type_bin2str(info
->pri_dev_type
,
4902 devtype
, sizeof(devtype
)),
4907 info
->serial_number
,
4908 info
->config_methods
,
4912 if (os_snprintf_error(end
- pos
, res
))
4916 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4919 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4920 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4921 wps_dev_type_bin2str(t
, devtype
,
4923 if (os_snprintf_error(end
- pos
, res
))
4928 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4930 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4931 if (os_snprintf_error(end
- pos
, res
))
4936 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4941 if (info
->vendor_elems
) {
4942 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
4943 if (os_snprintf_error(end
- pos
, res
))
4947 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4948 wpabuf_head(info
->vendor_elems
),
4949 wpabuf_len(info
->vendor_elems
));
4951 res
= os_snprintf(pos
, end
- pos
, "\n");
4952 if (os_snprintf_error(end
- pos
, res
))
4961 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
4966 if (wpa_s
->global
->p2p
== NULL
)
4969 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
4972 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
4973 struct wpa_freq_range
*freq
;
4974 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
4975 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
4976 freq
->min
, freq
->max
);
4979 wpas_p2p_update_channel_list(wpa_s
);
4984 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
4988 if (wpa_s
->global
->p2p
== NULL
)
4991 param
= os_strchr(cmd
, ' ');
4996 if (os_strcmp(cmd
, "discoverability") == 0) {
4997 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
5002 if (os_strcmp(cmd
, "managed") == 0) {
5003 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
5007 if (os_strcmp(cmd
, "listen_channel") == 0) {
5008 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
5012 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
5013 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
5017 if (os_strcmp(cmd
, "noa") == 0) {
5019 int count
, start
, duration
;
5020 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
5021 count
= atoi(param
);
5022 pos
= os_strchr(param
, ',');
5027 pos
= os_strchr(pos
, ',');
5031 duration
= atoi(pos
);
5032 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
5034 if (count
== 0 && duration
> 0)
5036 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
5037 "start=%d duration=%d", count
, start
, duration
);
5038 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
5041 if (os_strcmp(cmd
, "ps") == 0)
5042 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
5044 if (os_strcmp(cmd
, "oppps") == 0)
5045 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
5047 if (os_strcmp(cmd
, "ctwindow") == 0)
5048 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
5050 if (os_strcmp(cmd
, "disabled") == 0) {
5051 wpa_s
->global
->p2p_disabled
= atoi(param
);
5052 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
5053 wpa_s
->global
->p2p_disabled
?
5054 "disabled" : "enabled");
5055 if (wpa_s
->global
->p2p_disabled
) {
5056 wpas_p2p_stop_find(wpa_s
);
5057 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5058 p2p_flush(wpa_s
->global
->p2p
);
5063 if (os_strcmp(cmd
, "conc_pref") == 0) {
5064 if (os_strcmp(param
, "sta") == 0)
5065 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
5066 else if (os_strcmp(param
, "p2p") == 0)
5067 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
5069 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
5072 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
5077 if (os_strcmp(cmd
, "force_long_sd") == 0) {
5078 wpa_s
->force_long_sd
= atoi(param
);
5082 if (os_strcmp(cmd
, "peer_filter") == 0) {
5084 if (hwaddr_aton(param
, addr
))
5086 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
5090 if (os_strcmp(cmd
, "cross_connect") == 0)
5091 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
5093 if (os_strcmp(cmd
, "go_apsd") == 0) {
5094 if (os_strcmp(param
, "disable") == 0)
5095 wpa_s
->set_ap_uapsd
= 0;
5097 wpa_s
->set_ap_uapsd
= 1;
5098 wpa_s
->ap_uapsd
= atoi(param
);
5103 if (os_strcmp(cmd
, "client_apsd") == 0) {
5104 if (os_strcmp(param
, "disable") == 0)
5105 wpa_s
->set_sta_uapsd
= 0;
5109 /* format: BE,BK,VI,VO;max SP Length */
5111 pos
= os_strchr(param
, ',');
5116 pos
= os_strchr(pos
, ',');
5121 pos
= os_strchr(pos
, ',');
5126 /* ignore max SP Length for now */
5128 wpa_s
->set_sta_uapsd
= 1;
5129 wpa_s
->sta_uapsd
= 0;
5131 wpa_s
->sta_uapsd
|= BIT(0);
5133 wpa_s
->sta_uapsd
|= BIT(1);
5135 wpa_s
->sta_uapsd
|= BIT(2);
5137 wpa_s
->sta_uapsd
|= BIT(3);
5142 if (os_strcmp(cmd
, "disallow_freq") == 0)
5143 return p2p_ctrl_disallow_freq(wpa_s
, param
);
5145 if (os_strcmp(cmd
, "disc_int") == 0) {
5146 int min_disc_int
, max_disc_int
, max_disc_tu
;
5151 min_disc_int
= atoi(pos
);
5152 pos
= os_strchr(pos
, ' ');
5157 max_disc_int
= atoi(pos
);
5158 pos
= os_strchr(pos
, ' ');
5163 max_disc_tu
= atoi(pos
);
5165 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
5166 max_disc_int
, max_disc_tu
);
5169 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
5170 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
5174 #ifdef CONFIG_WPS_NFC
5175 if (os_strcmp(cmd
, "nfc_tag") == 0)
5176 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
5177 #endif /* CONFIG_WPS_NFC */
5179 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
5180 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
5184 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5191 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
5193 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5194 wpa_s
->force_long_sd
= 0;
5195 wpas_p2p_stop_find(wpa_s
);
5196 if (wpa_s
->global
->p2p
)
5197 p2p_flush(wpa_s
->global
->p2p
);
5201 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
5204 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
5207 pos
= os_strchr(cmd
, ' ');
5213 pos2
= os_strchr(pos
, ' ');
5221 pos
= os_strchr(pos2
, ' ');
5229 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
5233 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5236 unsigned int period
= 0, interval
= 0;
5239 pos
= os_strchr(cmd
, ' ');
5244 interval
= atoi(pos
);
5247 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
5251 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
5258 if (os_strncmp(pos
, "iface=", 6) == 0) {
5262 if (hwaddr_aton(pos
, peer
))
5265 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
5269 #endif /* CONFIG_P2P */
5272 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
5274 struct wpa_freq_range_list ranges
;
5276 struct hostapd_hw_modes
*mode
;
5279 if (wpa_s
->hw
.modes
== NULL
)
5282 os_memset(&ranges
, 0, sizeof(ranges
));
5283 if (freq_range_list_parse(&ranges
, val
) < 0)
5286 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
5289 mode
= &wpa_s
->hw
.modes
[i
];
5290 for (j
= 0; j
< mode
->num_channels
; j
++) {
5293 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
5296 freq
= mode
->channels
[j
].freq
;
5297 if (!freq_range_list_includes(&ranges
, freq
))
5300 int_array_add_unique(&freqs
, freq
);
5304 os_free(ranges
.range
);
5309 #ifdef CONFIG_INTERWORKING
5311 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
5319 auto_sel
= os_strstr(param
, "auto") != NULL
;
5321 pos
= os_strstr(param
, "freq=");
5323 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
5330 return interworking_select(wpa_s
, auto_sel
, freqs
);
5334 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
5337 struct wpa_bss
*bss
;
5339 if (hwaddr_aton(dst
, bssid
)) {
5340 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
5344 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5346 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
5351 return interworking_connect(wpa_s
, bss
);
5355 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5357 u8 dst_addr
[ETH_ALEN
];
5360 #define MAX_ANQP_INFO_ID 100
5361 u16 id
[MAX_ANQP_INFO_ID
];
5365 used
= hwaddr_aton2(dst
, dst_addr
);
5369 while (num_id
< MAX_ANQP_INFO_ID
) {
5370 if (os_strncmp(pos
, "hs20:", 5) == 0) {
5372 int num
= atoi(pos
+ 5);
5373 if (num
<= 0 || num
> 31)
5375 subtypes
|= BIT(num
);
5376 #else /* CONFIG_HS20 */
5378 #endif /* CONFIG_HS20 */
5380 id
[num_id
] = atoi(pos
);
5384 pos
= os_strchr(pos
+ 1, ',');
5393 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
);
5397 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5399 u8 dst_addr
[ETH_ALEN
];
5400 struct wpabuf
*advproto
, *query
= NULL
;
5405 used
= hwaddr_aton2(cmd
, dst_addr
);
5413 /* Advertisement Protocol ID */
5414 end
= os_strchr(pos
, ' ');
5418 len
= os_strlen(pos
);
5424 advproto
= wpabuf_alloc(len
);
5425 if (advproto
== NULL
)
5427 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
5431 /* Optional Query Request */
5436 len
= os_strlen(pos
);
5443 query
= wpabuf_alloc(len
);
5446 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
5451 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
5454 wpabuf_free(advproto
);
5461 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
5468 size_t resp_len
, start
, requested_len
;
5469 struct wpabuf
*resp
;
5472 used
= hwaddr_aton2(cmd
, addr
);
5479 dialog_token
= atoi(pos
);
5481 if (wpa_s
->last_gas_resp
&&
5482 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
5483 dialog_token
== wpa_s
->last_gas_dialog_token
)
5484 resp
= wpa_s
->last_gas_resp
;
5485 else if (wpa_s
->prev_gas_resp
&&
5486 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
5487 dialog_token
== wpa_s
->prev_gas_dialog_token
)
5488 resp
= wpa_s
->prev_gas_resp
;
5492 resp_len
= wpabuf_len(resp
);
5494 requested_len
= resp_len
;
5496 pos
= os_strchr(pos
, ' ');
5499 if (start
> resp_len
)
5500 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5501 pos
= os_strchr(pos
, ',');
5505 requested_len
= atoi(pos
);
5506 if (start
+ requested_len
> resp_len
)
5507 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5510 if (requested_len
* 2 + 1 > buflen
)
5511 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
5513 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
5516 if (start
+ requested_len
== resp_len
) {
5518 * Free memory by dropping the response after it has been
5521 if (resp
== wpa_s
->prev_gas_resp
) {
5522 wpabuf_free(wpa_s
->prev_gas_resp
);
5523 wpa_s
->prev_gas_resp
= NULL
;
5525 wpabuf_free(wpa_s
->last_gas_resp
);
5526 wpa_s
->last_gas_resp
= NULL
;
5532 #endif /* CONFIG_INTERWORKING */
5537 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5539 u8 dst_addr
[ETH_ALEN
];
5544 used
= hwaddr_aton2(dst
, dst_addr
);
5549 int num
= atoi(pos
);
5550 if (num
<= 0 || num
> 31)
5552 subtypes
|= BIT(num
);
5553 pos
= os_strchr(pos
+ 1, ',');
5562 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
5566 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5567 const u8
*addr
, const char *realm
)
5573 rlen
= os_strlen(realm
);
5575 buf
= os_malloc(len
);
5578 buf
[0] = 1; /* NAI Home Realm Count */
5579 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
5581 os_memcpy(buf
+ 3, realm
, rlen
);
5583 ret
= hs20_anqp_send_req(wpa_s
, addr
,
5584 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5593 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5596 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
5597 u8 dst_addr
[ETH_ALEN
];
5603 used
= hwaddr_aton2(dst
, dst_addr
);
5607 while (dst
[used
] == ' ')
5609 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
5610 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
5613 len
= os_strlen(dst
+ used
);
5615 if (len
== 0 && cred
&& cred
->realm
)
5616 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
5621 buf
= os_malloc(len
);
5624 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
5629 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
5630 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5638 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5640 u8 dst_addr
[ETH_ALEN
];
5644 used
= hwaddr_aton2(cmd
, dst_addr
);
5648 while (cmd
[used
] == ' ')
5652 wpa_s
->fetch_osu_icon_in_progress
= 0;
5653 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
5654 (u8
*) icon
, os_strlen(icon
));
5657 #endif /* CONFIG_HS20 */
5660 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5661 struct wpa_supplicant
*wpa_s
, char *cmd
)
5663 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
5668 #ifdef CONFIG_AUTOSCAN
5670 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
5673 enum wpa_states state
= wpa_s
->wpa_state
;
5674 char *new_params
= NULL
;
5676 if (os_strlen(cmd
) > 0) {
5677 new_params
= os_strdup(cmd
);
5678 if (new_params
== NULL
)
5682 os_free(wpa_s
->conf
->autoscan
);
5683 wpa_s
->conf
->autoscan
= new_params
;
5685 if (wpa_s
->conf
->autoscan
== NULL
)
5686 autoscan_deinit(wpa_s
);
5687 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
5688 autoscan_init(wpa_s
, 1);
5689 else if (state
== WPA_SCANNING
)
5690 wpa_supplicant_reinit_autoscan(wpa_s
);
5695 #endif /* CONFIG_AUTOSCAN */
5700 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
5706 struct wpabuf
*tfs_req
= NULL
;
5708 if (os_strncmp(cmd
, "enter", 5) == 0)
5710 else if (os_strncmp(cmd
, "exit", 4) == 0)
5715 pos
= os_strstr(cmd
, " interval=");
5717 intval
= atoi(pos
+ 10);
5719 pos
= os_strstr(cmd
, " tfs_req=");
5724 end
= os_strchr(pos
, ' ');
5728 len
= os_strlen(pos
);
5732 tfs_req
= wpabuf_alloc(len
);
5733 if (tfs_req
== NULL
)
5735 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5736 wpabuf_free(tfs_req
);
5741 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5742 WNM_SLEEP_MODE_EXIT
, intval
,
5744 wpabuf_free(tfs_req
);
5750 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5754 query_reason
= atoi(cmd
);
5756 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5759 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5762 #endif /* CONFIG_WNM */
5765 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5768 struct wpa_signal_info si
;
5772 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5779 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5780 "NOISE=%d\nFREQUENCY=%u\n",
5781 si
.current_signal
, si
.current_txrate
/ 1000,
5782 si
.current_noise
, si
.frequency
);
5783 if (ret
< 0 || ret
> end
- pos
)
5787 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5788 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5789 channel_width_to_string(si
.chanwidth
));
5790 if (ret
< 0 || ret
> end
- pos
)
5795 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5796 ret
= os_snprintf(pos
, end
- pos
,
5797 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5798 si
.center_frq1
, si
.center_frq2
);
5799 if (ret
< 0 || ret
> end
- pos
)
5804 if (si
.avg_signal
) {
5805 ret
= os_snprintf(pos
, end
- pos
,
5806 "AVG_RSSI=%d\n", si
.avg_signal
);
5807 if (os_snprintf_error(end
- pos
, ret
))
5816 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5819 struct hostap_sta_driver_data sta
;
5822 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5826 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5827 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5828 if (ret
< 0 || (size_t) ret
> buflen
)
5835 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5836 char *buf
, size_t buflen
)
5840 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5842 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5843 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5846 country
[0] = cmd
[8];
5847 country
[1] = cmd
[9];
5849 p2p_set_country(p2p
, country
);
5852 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5856 #endif /* ANDROID */
5859 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5860 char *buf
, size_t buflen
)
5865 unsigned int vendor_id
, subcmd
;
5866 struct wpabuf
*reply
;
5867 size_t data_len
= 0;
5869 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5870 vendor_id
= strtoul(cmd
, &pos
, 16);
5874 subcmd
= strtoul(pos
, &pos
, 10);
5877 if (!isblank(*pos
++))
5879 data_len
= os_strlen(pos
);
5884 data
= os_malloc(data_len
);
5888 if (hexstr2bin(pos
, data
, data_len
)) {
5889 wpa_printf(MSG_DEBUG
,
5890 "Vendor command: wrong parameter format");
5896 reply
= wpabuf_alloc((buflen
- 1) / 2);
5902 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
5906 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
5916 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5918 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5921 wpas_p2p_cancel(wpa_s
);
5922 wpas_p2p_stop_find(wpa_s
);
5923 p2p_ctrl_flush(wpa_s
);
5924 wpas_p2p_group_remove(wpa_s
, "*");
5925 wpas_p2p_service_flush(wpa_s
);
5926 wpa_s
->global
->p2p_disabled
= 0;
5927 wpa_s
->global
->p2p_per_sta_psk
= 0;
5928 wpa_s
->conf
->num_sec_device_types
= 0;
5929 wpa_s
->p2p_disable_ip_addr_req
= 0;
5930 os_free(wpa_s
->global
->p2p_go_avoid_freq
.range
);
5931 wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
5932 #endif /* CONFIG_P2P */
5934 #ifdef CONFIG_WPS_TESTING
5935 wps_version_number
= 0x20;
5936 wps_testing_dummy_cred
= 0;
5937 wps_corrupt_pkhash
= 0;
5938 #endif /* CONFIG_WPS_TESTING */
5940 wpa_s
->wps_fragment_size
= 0;
5941 wpas_wps_cancel(wpa_s
);
5942 #endif /* CONFIG_WPS */
5943 wpa_s
->after_wps
= 0;
5944 wpa_s
->known_wps_freq
= 0;
5947 #ifdef CONFIG_TDLS_TESTING
5948 extern unsigned int tdls_testing
;
5950 #endif /* CONFIG_TDLS_TESTING */
5951 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
5952 wpa_tdls_enable(wpa_s
->wpa
, 1);
5953 #endif /* CONFIG_TDLS */
5955 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
5956 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
5958 wpa_s
->no_keep_alive
= 0;
5960 os_free(wpa_s
->disallow_aps_bssid
);
5961 wpa_s
->disallow_aps_bssid
= NULL
;
5962 wpa_s
->disallow_aps_bssid_count
= 0;
5963 os_free(wpa_s
->disallow_aps_ssid
);
5964 wpa_s
->disallow_aps_ssid
= NULL
;
5965 wpa_s
->disallow_aps_ssid_count
= 0;
5967 wpa_s
->set_sta_uapsd
= 0;
5968 wpa_s
->sta_uapsd
= 0;
5970 wpa_drv_radio_disable(wpa_s
, 0);
5972 wpa_bss_flush(wpa_s
);
5973 wpa_blacklist_clear(wpa_s
);
5974 wpa_s
->extra_blacklist_count
= 0;
5975 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
5976 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
5977 wpa_config_flush_blobs(wpa_s
->conf
);
5978 wpa_s
->conf
->auto_interworking
= 0;
5979 wpa_s
->conf
->okc
= 0;
5981 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
5982 rsn_preauth_deinit(wpa_s
->wpa
);
5984 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
5985 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
5986 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
5987 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5989 radio_remove_works(wpa_s
, NULL
, 1);
5990 wpa_s
->ext_work_in_progress
= 0;
5992 wpa_s
->next_ssid
= NULL
;
5994 #ifdef CONFIG_INTERWORKING
5995 hs20_cancel_fetch_osu(wpa_s
);
5996 #endif /* CONFIG_INTERWORKING */
5998 wpa_s
->ext_mgmt_frame_handling
= 0;
5999 wpa_s
->ext_eapol_frame_io
= 0;
6000 #ifdef CONFIG_TESTING_OPTIONS
6001 wpa_s
->extra_roc_dur
= 0;
6002 #endif /* CONFIG_TESTING_OPTIONS */
6006 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
6007 char *buf
, size_t buflen
)
6009 struct wpa_radio_work
*work
;
6011 struct os_reltime now
, diff
;
6016 os_get_reltime(&now
);
6018 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
6022 os_reltime_sub(&now
, &work
->time
, &diff
);
6023 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
6024 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
6025 work
->started
, diff
.sec
, diff
.usec
);
6026 if (os_snprintf_error(end
- pos
, ret
))
6035 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
6037 struct wpa_radio_work
*work
= eloop_ctx
;
6038 struct wpa_external_work
*ework
= work
->ctx
;
6040 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
6041 "Timing out external radio work %u (%s)",
6042 ework
->id
, work
->type
);
6043 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
6044 work
->wpa_s
->ext_work_in_progress
= 0;
6045 radio_work_done(work
);
6050 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
6052 struct wpa_external_work
*ework
= work
->ctx
;
6056 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
6063 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
6064 ework
->id
, ework
->type
);
6065 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
6066 work
->wpa_s
->ext_work_in_progress
= 1;
6067 if (!ework
->timeout
)
6068 ework
->timeout
= 10;
6069 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
6074 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
6075 char *buf
, size_t buflen
)
6077 struct wpa_external_work
*ework
;
6081 unsigned int freq
= 0;
6083 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
6085 ework
= os_zalloc(sizeof(*ework
));
6089 pos
= os_strchr(cmd
, ' ');
6091 type_len
= pos
- cmd
;
6094 pos2
= os_strstr(pos
, "freq=");
6096 freq
= atoi(pos2
+ 5);
6098 pos2
= os_strstr(pos
, "timeout=");
6100 ework
->timeout
= atoi(pos2
+ 8);
6102 type_len
= os_strlen(cmd
);
6104 if (4 + type_len
>= sizeof(ework
->type
))
6105 type_len
= sizeof(ework
->type
) - 4 - 1;
6106 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
6107 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
6108 ework
->type
[4 + type_len
] = '\0';
6110 wpa_s
->ext_work_id
++;
6111 if (wpa_s
->ext_work_id
== 0)
6112 wpa_s
->ext_work_id
++;
6113 ework
->id
= wpa_s
->ext_work_id
;
6115 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
6121 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
6122 if (os_snprintf_error(buflen
, ret
))
6128 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
6130 struct wpa_radio_work
*work
;
6131 unsigned int id
= atoi(cmd
);
6133 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
6135 struct wpa_external_work
*ework
;
6137 if (os_strncmp(work
->type
, "ext:", 4) != 0)
6140 if (id
&& ework
->id
!= id
)
6142 wpa_dbg(wpa_s
, MSG_DEBUG
,
6143 "Completed external radio work %u (%s)",
6144 ework
->id
, ework
->type
);
6145 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
6146 wpa_s
->ext_work_in_progress
= 0;
6147 radio_work_done(work
);
6149 return 3; /* "OK\n" */
6156 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
6157 char *buf
, size_t buflen
)
6159 if (os_strcmp(cmd
, "show") == 0)
6160 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
6161 if (os_strncmp(cmd
, "add ", 4) == 0)
6162 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
6163 if (os_strncmp(cmd
, "done ", 5) == 0)
6164 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
6169 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
6171 struct wpa_radio_work
*work
, *tmp
;
6173 if (!wpa_s
|| !wpa_s
->radio
)
6176 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
6177 struct wpa_radio_work
, list
) {
6178 struct wpa_external_work
*ework
;
6180 if (os_strncmp(work
->type
, "ext:", 4) != 0)
6183 wpa_dbg(wpa_s
, MSG_DEBUG
,
6184 "Flushing%s external radio work %u (%s)",
6185 work
->started
? " started" : "", ework
->id
,
6188 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
6190 radio_work_done(work
);
6196 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
6198 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
6199 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
6203 static int set_scan_freqs(struct wpa_supplicant
*wpa_s
, char *val
)
6207 freqs
= freq_range_to_channel_list(wpa_s
, val
);
6211 os_free(wpa_s
->manual_scan_freqs
);
6212 wpa_s
->manual_scan_freqs
= freqs
;
6218 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
)
6220 const char *pos
= value
;
6223 if (*pos
== ' ' || *pos
== '\0')
6225 if (wpa_s
->scan_id_count
== MAX_SCAN_ID
)
6227 wpa_s
->scan_id
[wpa_s
->scan_id_count
++] = atoi(pos
);
6228 pos
= os_strchr(pos
, ',');
6237 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
6238 char *reply
, int reply_size
, int *reply_len
)
6242 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
6247 wpa_s
->manual_scan_passive
= 0;
6248 wpa_s
->manual_scan_use_id
= 0;
6249 wpa_s
->manual_scan_only_new
= 0;
6250 wpa_s
->scan_id_count
= 0;
6253 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
6254 wpa_s
->scan_res_handler
= scan_only_handler
;
6256 pos
= os_strstr(params
, "freq=");
6257 if (pos
&& set_scan_freqs(wpa_s
, pos
+ 5) < 0) {
6262 pos
= os_strstr(params
, "passive=");
6264 wpa_s
->manual_scan_passive
= !!atoi(pos
+ 8);
6266 pos
= os_strstr(params
, "use_id=");
6268 wpa_s
->manual_scan_use_id
= atoi(pos
+ 7);
6270 pos
= os_strstr(params
, "only_new=1");
6272 wpa_s
->manual_scan_only_new
= 1;
6274 pos
= os_strstr(params
, "scan_id=");
6275 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8) < 0) {
6280 os_free(wpa_s
->manual_scan_freqs
);
6281 wpa_s
->manual_scan_freqs
= NULL
;
6282 if (wpa_s
->scan_res_handler
== scan_only_handler
)
6283 wpa_s
->scan_res_handler
= NULL
;
6286 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
6287 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
6288 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
6289 wpa_s
->normal_scans
= 0;
6290 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6291 wpa_s
->after_wps
= 0;
6292 wpa_s
->known_wps_freq
= 0;
6293 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6294 if (wpa_s
->manual_scan_use_id
) {
6295 wpa_s
->manual_scan_id
++;
6296 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6297 wpa_s
->manual_scan_id
);
6298 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6299 wpa_s
->manual_scan_id
);
6301 } else if (wpa_s
->sched_scanning
) {
6302 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
6303 wpa_supplicant_cancel_sched_scan(wpa_s
);
6304 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6305 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6306 if (wpa_s
->manual_scan_use_id
) {
6307 wpa_s
->manual_scan_id
++;
6308 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6309 wpa_s
->manual_scan_id
);
6310 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6311 wpa_s
->manual_scan_id
);
6314 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
6315 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
6320 #ifdef CONFIG_TESTING_OPTIONS
6322 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
6323 unsigned int freq
, const u8
*dst
,
6324 const u8
*src
, const u8
*bssid
,
6325 const u8
*data
, size_t data_len
,
6326 enum offchannel_send_action_result
6329 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6330 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
6331 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
6332 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
6333 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
6334 "NO_ACK" : "FAILED"));
6338 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6342 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
6344 int freq
= 0, no_cck
= 0, wait_time
= 0;
6346 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6347 * <action=Action frame payload> */
6349 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
6352 used
= hwaddr_aton2(pos
, da
);
6358 used
= hwaddr_aton2(pos
, bssid
);
6363 param
= os_strstr(pos
, " freq=");
6369 param
= os_strstr(pos
, " no_cck=");
6372 no_cck
= atoi(param
);
6375 param
= os_strstr(pos
, " wait_time=");
6378 wait_time
= atoi(param
);
6381 param
= os_strstr(pos
, " action=");
6386 len
= os_strlen(param
);
6391 buf
= os_malloc(len
);
6395 if (hexstr2bin(param
, buf
, len
) < 0) {
6400 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
6401 buf
, len
, wait_time
,
6402 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
6408 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
6410 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
6411 offchannel_send_action_done(wpa_s
);
6415 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
6418 union wpa_event_data event
;
6419 enum wpa_event_type ev
;
6421 /* <event name> [parameters..] */
6423 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
6426 param
= os_strchr(pos
, ' ');
6430 os_memset(&event
, 0, sizeof(event
));
6432 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
6433 ev
= EVENT_INTERFACE_ENABLED
;
6434 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
6435 ev
= EVENT_INTERFACE_DISABLED
;
6436 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
6437 ev
= EVENT_AVOID_FREQUENCIES
;
6440 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
6442 wpa_supplicant_event(wpa_s
, ev
, &event
);
6443 os_free(event
.freq_range
.range
);
6446 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
6451 wpa_supplicant_event(wpa_s
, ev
, &event
);
6457 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6460 u8 src
[ETH_ALEN
], *buf
;
6464 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
6467 used
= hwaddr_aton2(pos
, src
);
6474 len
= os_strlen(pos
);
6479 buf
= os_malloc(len
);
6483 if (hexstr2bin(pos
, buf
, len
) < 0) {
6488 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
6495 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
6499 const u16
*pos
= buf
;
6501 for (i
= 0; i
< len
/ 2; i
++)
6505 sum
= (sum
& 0xffff) + (sum
>> 16);
6507 return sum
^ 0xffff;
6511 #define HWSIM_PACKETLEN 1500
6512 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6514 void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
, size_t len
)
6516 struct wpa_supplicant
*wpa_s
= ctx
;
6517 const struct ether_header
*eth
;
6518 const struct iphdr
*ip
;
6522 if (len
!= HWSIM_PACKETLEN
)
6525 eth
= (const struct ether_header
*) buf
;
6526 ip
= (const struct iphdr
*) (eth
+ 1);
6527 pos
= (const u8
*) (ip
+ 1);
6529 if (ip
->ihl
!= 5 || ip
->version
!= 4 ||
6530 ntohs(ip
->tot_len
) != HWSIM_IP_LEN
)
6533 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++) {
6539 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
6540 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
6544 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
6547 int enabled
= atoi(cmd
);
6550 if (wpa_s
->l2_test
) {
6551 l2_packet_deinit(wpa_s
->l2_test
);
6552 wpa_s
->l2_test
= NULL
;
6553 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
6561 wpa_s
->l2_test
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
,
6562 ETHERTYPE_IP
, wpas_data_test_rx
,
6564 if (wpa_s
->l2_test
== NULL
)
6567 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
6573 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6575 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
6580 u8 buf
[HWSIM_PACKETLEN
];
6581 struct ether_header
*eth
;
6586 if (wpa_s
->l2_test
== NULL
)
6589 /* format: <dst> <src> <tos> */
6592 used
= hwaddr_aton2(pos
, dst
);
6598 used
= hwaddr_aton2(pos
, src
);
6603 val
= strtol(pos
, NULL
, 0);
6604 if (val
< 0 || val
> 0xff)
6608 eth
= (struct ether_header
*) buf
;
6609 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
6610 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
6611 eth
->ether_type
= htons(ETHERTYPE_IP
);
6612 ip
= (struct iphdr
*) (eth
+ 1);
6613 os_memset(ip
, 0, sizeof(*ip
));
6618 ip
->tot_len
= htons(HWSIM_IP_LEN
);
6620 ip
->saddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6621 ip
->daddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6622 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
6623 dpos
= (u8
*) (ip
+ 1);
6624 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
6627 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, buf
,
6628 HWSIM_PACKETLEN
) < 0)
6631 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
6632 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
6638 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
6642 struct ether_header
*eth
;
6643 struct l2_packet_data
*l2
= NULL
;
6648 len
= os_strlen(cmd
);
6649 if (len
& 1 || len
< ETH_HLEN
* 2)
6653 buf
= os_malloc(len
);
6657 if (hexstr2bin(cmd
, buf
, len
) < 0)
6660 eth
= (struct ether_header
*) buf
;
6661 ethertype
= ntohs(eth
->ether_type
);
6663 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
6664 wpas_data_test_rx
, wpa_s
, 1);
6668 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
6669 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
6672 l2_packet_deinit(l2
);
6675 return res
< 0 ? -1 : 0;
6678 #endif /* CONFIG_TESTING_OPTIONS */
6681 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant
*wpa_s
)
6686 wpa_printf(MSG_DEBUG
, "Update vendor elements");
6688 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
6689 if (wpa_s
->vendor_elem
[i
]) {
6690 os_snprintf(buf
, sizeof(buf
), "frame[%u]", i
);
6691 wpa_hexdump_buf(MSG_DEBUG
, buf
, wpa_s
->vendor_elem
[i
]);
6696 if (wpa_s
->parent
== wpa_s
&&
6697 wpa_s
->global
->p2p
&&
6698 !wpa_s
->global
->p2p_disabled
)
6699 p2p_set_vendor_elems(wpa_s
->global
->p2p
, wpa_s
->vendor_elem
);
6700 #endif /* CONFIG_P2P */
6704 static struct wpa_supplicant
*
6705 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant
*wpa_s
,
6706 enum wpa_vendor_elem_frame frame
)
6710 case VENDOR_ELEM_PROBE_REQ_P2P
:
6711 case VENDOR_ELEM_PROBE_RESP_P2P
:
6712 case VENDOR_ELEM_PROBE_RESP_P2P_GO
:
6713 case VENDOR_ELEM_BEACON_P2P_GO
:
6714 case VENDOR_ELEM_P2P_PD_REQ
:
6715 case VENDOR_ELEM_P2P_PD_RESP
:
6716 case VENDOR_ELEM_P2P_GO_NEG_REQ
:
6717 case VENDOR_ELEM_P2P_GO_NEG_RESP
:
6718 case VENDOR_ELEM_P2P_GO_NEG_CONF
:
6719 case VENDOR_ELEM_P2P_INV_REQ
:
6720 case VENDOR_ELEM_P2P_INV_RESP
:
6721 case VENDOR_ELEM_P2P_ASSOC_REQ
:
6722 return wpa_s
->parent
;
6723 #endif /* CONFIG_P2P */
6730 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6736 struct ieee802_11_elems elems
;
6739 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6741 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6743 pos
= os_strchr(pos
, ' ');
6748 len
= os_strlen(pos
);
6755 buf
= wpabuf_alloc(len
);
6759 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
6764 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
6770 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
6771 wpa_s
->vendor_elem
[frame
] = buf
;
6772 wpas_ctrl_vendor_elem_update(wpa_s
);
6776 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
6781 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
6783 wpas_ctrl_vendor_elem_update(wpa_s
);
6789 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
6790 char *buf
, size_t buflen
)
6792 int frame
= atoi(cmd
);
6794 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6796 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6798 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6801 return wpa_snprintf_hex(buf
, buflen
,
6802 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
6803 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
6807 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
6813 struct ieee802_11_elems elems
;
6817 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6819 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6821 pos
= os_strchr(pos
, ' ');
6827 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6828 wpa_s
->vendor_elem
[frame
] = NULL
;
6829 wpas_ctrl_vendor_elem_update(wpa_s
);
6833 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6836 len
= os_strlen(pos
);
6843 buf
= os_malloc(len
);
6847 if (hexstr2bin(pos
, buf
, len
) < 0) {
6852 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
6857 ie
= wpabuf_mhead_u8(wpa_s
->vendor_elem
[frame
]);
6858 end
= ie
+ wpabuf_len(wpa_s
->vendor_elem
[frame
]);
6860 for (; ie
+ 1 < end
; ie
+= 2 + ie
[1]) {
6863 if (os_memcmp(ie
, buf
, len
) != 0)
6866 if (wpabuf_len(wpa_s
->vendor_elem
[frame
]) == len
) {
6867 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6868 wpa_s
->vendor_elem
[frame
] = NULL
;
6870 os_memmove(ie
, ie
+ len
,
6872 wpa_s
->vendor_elem
[frame
]->used
-= len
;
6875 wpas_ctrl_vendor_elem_update(wpa_s
);
6885 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
6887 struct wpa_supplicant
*wpa_s
= ctx
;
6890 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
6892 (unsigned int) wpabuf_len(neighbor_rep
));
6893 wpabuf_free(neighbor_rep
);
6895 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
6900 static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant
*wpa_s
,
6903 struct wpa_ssid ssid
;
6904 struct wpa_ssid
*ssid_p
= NULL
;
6907 if (os_strncmp(cmd
, " ssid=", 6) == 0) {
6908 ssid
.ssid_len
= os_strlen(cmd
+ 6);
6909 if (ssid
.ssid_len
> 32)
6911 ssid
.ssid
= (u8
*) (cmd
+ 6);
6915 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
,
6916 wpas_ctrl_neighbor_rep_cb
,
6923 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
6925 eapol_sm_erp_flush(wpa_s
->eapol
);
6930 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
6931 char *buf
, size_t *resp_len
)
6934 const int reply_size
= 4096;
6937 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
6938 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
6939 if (wpa_debug_show_keys
)
6940 wpa_dbg(wpa_s
, MSG_DEBUG
,
6941 "Control interface command '%s'", buf
);
6943 wpa_dbg(wpa_s
, MSG_DEBUG
,
6944 "Control interface command '%s [REMOVED]'",
6945 os_strncmp(buf
, WPA_CTRL_RSP
,
6946 os_strlen(WPA_CTRL_RSP
)) == 0 ?
6947 WPA_CTRL_RSP
: "SET_NETWORK");
6948 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
6949 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
6950 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
6951 (const u8
*) buf
, os_strlen(buf
));
6953 int level
= MSG_DEBUG
;
6954 if (os_strcmp(buf
, "PING") == 0)
6955 level
= MSG_EXCESSIVE
;
6956 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
6959 reply
= os_malloc(reply_size
);
6960 if (reply
== NULL
) {
6965 os_memcpy(reply
, "OK\n", 3);
6968 if (os_strcmp(buf
, "PING") == 0) {
6969 os_memcpy(reply
, "PONG\n", 5);
6971 } else if (os_strcmp(buf
, "IFNAME") == 0) {
6972 reply_len
= os_strlen(wpa_s
->ifname
);
6973 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
6974 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
6975 if (wpa_debug_reopen_file() < 0)
6977 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
6978 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
6979 } else if (os_strcmp(buf
, "MIB") == 0) {
6980 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
6981 if (reply_len
>= 0) {
6983 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
6984 reply_size
- reply_len
);
6990 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
6991 reply_len
= wpa_supplicant_ctrl_iface_status(
6992 wpa_s
, buf
+ 6, reply
, reply_size
);
6993 } else if (os_strcmp(buf
, "PMKSA") == 0) {
6994 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
6996 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
6997 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
6998 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
6999 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
7001 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
7002 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
7004 } else if (os_strcmp(buf
, "LOGON") == 0) {
7005 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7006 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
7007 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
7008 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
7009 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
7012 wpas_request_connection(wpa_s
);
7013 } else if (os_strcmp(buf
, "REATTACH") == 0) {
7014 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
7015 !wpa_s
->current_ssid
)
7018 wpa_s
->reattach
= 1;
7019 wpas_request_connection(wpa_s
);
7021 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
7022 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
7024 else if (wpa_s
->disconnected
)
7025 wpas_request_connection(wpa_s
);
7026 #ifdef IEEE8021X_EAPOL
7027 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
7028 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
7030 #endif /* IEEE8021X_EAPOL */
7031 #ifdef CONFIG_PEERKEY
7032 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
7033 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
7035 #endif /* CONFIG_PEERKEY */
7036 #ifdef CONFIG_IEEE80211R
7037 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
7038 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
7040 #endif /* CONFIG_IEEE80211R */
7042 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
7043 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
7045 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7049 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
7050 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
7052 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7056 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
7057 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
7060 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
7061 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
7062 wpa_s
, buf
+ 14, reply
, reply_size
);
7063 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
7064 if (wpas_wps_cancel(wpa_s
))
7066 #ifdef CONFIG_WPS_NFC
7067 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
7068 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
7070 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
7071 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
7073 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
7074 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
7075 wpa_s
, buf
+ 21, reply
, reply_size
);
7076 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
7077 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
7078 wpa_s
, buf
+ 14, reply
, reply_size
);
7079 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
7080 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
7083 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
7084 reply_len
= wpas_ctrl_nfc_get_handover_req(
7085 wpa_s
, buf
+ 21, reply
, reply_size
);
7086 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
7087 reply_len
= wpas_ctrl_nfc_get_handover_sel(
7088 wpa_s
, buf
+ 21, reply
, reply_size
);
7089 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
7090 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
7092 #endif /* CONFIG_WPS_NFC */
7093 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
7094 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
7097 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
7098 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
7099 wpa_s
, buf
+ 11, reply
, reply_size
);
7100 #endif /* CONFIG_AP */
7101 #ifdef CONFIG_WPS_ER
7102 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
7103 if (wpas_wps_er_start(wpa_s
, NULL
))
7105 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
7106 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
7108 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
7109 if (wpas_wps_er_stop(wpa_s
))
7111 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
7112 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
7114 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
7115 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
7117 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
7119 } else if (ret
== -3) {
7120 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
7122 } else if (ret
== -4) {
7123 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
7127 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
7128 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
7130 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
7131 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
7134 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
7135 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
7137 #ifdef CONFIG_WPS_NFC
7138 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
7139 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
7140 wpa_s
, buf
+ 24, reply
, reply_size
);
7141 #endif /* CONFIG_WPS_NFC */
7142 #endif /* CONFIG_WPS_ER */
7143 #endif /* CONFIG_WPS */
7144 #ifdef CONFIG_IBSS_RSN
7145 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
7146 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
7148 #endif /* CONFIG_IBSS_RSN */
7150 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
7151 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
7153 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
7154 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
7157 #endif /* CONFIG_MESH */
7159 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
7160 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
7162 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
7163 if (p2p_ctrl_find(wpa_s
, ""))
7165 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
7166 wpas_p2p_stop_find(wpa_s
);
7167 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
7168 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
7170 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
7171 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
7173 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
7174 if (p2p_ctrl_listen(wpa_s
, ""))
7176 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
7177 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
7179 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
7180 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
7182 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
7183 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
7185 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
7186 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
7188 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
7189 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
7190 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
7191 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
7193 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
7194 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
7196 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
7197 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
7199 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
7200 wpas_p2p_sd_service_update(wpa_s
);
7201 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
7202 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
7204 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
7205 wpas_p2p_service_flush(wpa_s
);
7206 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
7207 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
7209 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
7210 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
7212 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
7213 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
7215 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
7216 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
7218 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
7219 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
7221 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
7222 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
7224 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
7225 p2p_ctrl_flush(wpa_s
);
7226 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
7227 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
7229 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
7230 if (wpas_p2p_cancel(wpa_s
))
7232 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
7233 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
7235 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
7236 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
7238 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
7239 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
7241 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
7242 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
7244 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
7245 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
7247 #endif /* CONFIG_P2P */
7248 #ifdef CONFIG_WIFI_DISPLAY
7249 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
7250 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
7252 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
7253 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
7255 #endif /* CONFIG_WIFI_DISPLAY */
7256 #ifdef CONFIG_INTERWORKING
7257 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
7258 if (interworking_fetch_anqp(wpa_s
) < 0)
7260 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
7261 interworking_stop_fetch_anqp(wpa_s
);
7262 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
7263 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
7265 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
7266 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
7268 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
7269 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
7271 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
7272 if (get_anqp(wpa_s
, buf
+ 9) < 0)
7274 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
7275 if (gas_request(wpa_s
, buf
+ 12) < 0)
7277 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
7278 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
7280 #endif /* CONFIG_INTERWORKING */
7282 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
7283 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
7285 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7286 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
7288 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
7289 if (hs20_icon_request(wpa_s
, buf
+ 18) < 0)
7291 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
7292 if (hs20_fetch_osu(wpa_s
) < 0)
7294 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
7295 hs20_cancel_fetch_osu(wpa_s
);
7296 #endif /* CONFIG_HS20 */
7297 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
7299 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7300 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
7304 * Notify response from timeout to allow the control
7305 * interface response to be sent first.
7307 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
7310 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
7311 if (wpa_supplicant_reload_configuration(wpa_s
))
7313 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
7314 wpa_supplicant_terminate_proc(wpa_s
->global
);
7315 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
7316 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
7318 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
7319 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
7320 wpa_s
, buf
+ 9, reply
, reply_size
);
7321 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
7322 reply_len
= wpa_supplicant_ctrl_iface_log_level(
7323 wpa_s
, buf
+ 9, reply
, reply_size
);
7324 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
7325 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
7326 wpa_s
, buf
+ 14, reply
, reply_size
);
7327 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
7328 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
7329 wpa_s
, NULL
, reply
, reply_size
);
7330 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
7332 wpa_s
->sme
.prev_bssid_set
= 0;
7333 #endif /* CONFIG_SME */
7334 wpa_s
->reassociate
= 0;
7335 wpa_s
->disconnected
= 1;
7336 wpa_supplicant_cancel_sched_scan(wpa_s
);
7337 wpa_supplicant_cancel_scan(wpa_s
);
7338 wpa_supplicant_deauthenticate(wpa_s
,
7339 WLAN_REASON_DEAUTH_LEAVING
);
7340 } else if (os_strcmp(buf
, "SCAN") == 0) {
7341 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
7342 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
7343 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
7344 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
7345 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
7346 wpa_s
, reply
, reply_size
);
7347 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
7348 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
7350 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
7351 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
7353 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
7354 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
7356 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
7357 reply_len
= wpa_supplicant_ctrl_iface_add_network(
7358 wpa_s
, reply
, reply_size
);
7359 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
7360 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
7362 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
7363 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
7365 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
7366 reply_len
= wpa_supplicant_ctrl_iface_get_network(
7367 wpa_s
, buf
+ 12, reply
, reply_size
);
7368 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
7369 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12))
7371 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
7372 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
7373 wpa_s
, reply
, reply_size
);
7374 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
7375 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
7376 wpa_s
, reply
, reply_size
);
7377 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
7378 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
7380 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
7381 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
7383 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
7384 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
7387 #ifndef CONFIG_NO_CONFIG_WRITE
7388 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
7389 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
7391 #endif /* CONFIG_NO_CONFIG_WRITE */
7392 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
7393 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
7394 wpa_s
, buf
+ 15, reply
, reply_size
);
7395 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
7396 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
7398 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
7399 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
7401 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
7402 reply_len
= wpa_supplicant_global_iface_list(
7403 wpa_s
->global
, reply
, reply_size
);
7404 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
7405 reply_len
= wpa_supplicant_global_iface_interfaces(
7406 wpa_s
->global
, reply
, reply_size
);
7407 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
7408 reply_len
= wpa_supplicant_ctrl_iface_bss(
7409 wpa_s
, buf
+ 4, reply
, reply_size
);
7411 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
7412 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
7413 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
7414 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
7416 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
7417 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
7419 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
7420 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
7422 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
7423 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
7425 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
7426 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
7428 #endif /* CONFIG_AP */
7429 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
7430 wpas_notify_suspend(wpa_s
->global
);
7431 } else if (os_strcmp(buf
, "RESUME") == 0) {
7432 wpas_notify_resume(wpa_s
->global
);
7433 #ifdef CONFIG_TESTING_OPTIONS
7434 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
7435 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
7436 #endif /* CONFIG_TESTING_OPTIONS */
7437 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
7438 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
7440 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
7441 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
7443 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
7444 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
7446 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
7447 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
7450 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
7451 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10))
7454 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
7455 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
7457 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
7458 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
7460 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
7461 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
7463 #endif /* CONFIG_TDLS */
7464 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
7465 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
7466 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
7467 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
7469 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
7470 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
7472 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
7473 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
7475 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
7476 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
7478 #ifdef CONFIG_AUTOSCAN
7479 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
7480 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
7482 #endif /* CONFIG_AUTOSCAN */
7484 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
7485 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
7487 #endif /* ANDROID */
7488 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
7489 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
7491 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
7492 pmksa_cache_clear_current(wpa_s
->wpa
);
7493 eapol_sm_request_reauth(wpa_s
->eapol
);
7495 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
7496 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
7498 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
7499 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
7501 #endif /* CONFIG_WNM */
7502 } else if (os_strcmp(buf
, "FLUSH") == 0) {
7503 wpa_supplicant_ctrl_iface_flush(wpa_s
);
7504 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
7505 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
7507 #ifdef CONFIG_TESTING_OPTIONS
7508 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
7509 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
7511 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
7512 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
7513 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
7514 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
7516 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
7517 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
7519 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
7520 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
7522 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
7523 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
7525 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
7526 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
7528 #endif /* CONFIG_TESTING_OPTIONS */
7529 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
7530 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
7532 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
7533 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
7535 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7536 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
7538 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
7539 if (wpas_ctrl_iface_send_neigbor_rep(wpa_s
, buf
+ 20))
7541 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
7542 wpas_ctrl_iface_erp_flush(wpa_s
);
7544 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
7548 if (reply_len
< 0) {
7549 os_memcpy(reply
, "FAIL\n", 5);
7553 *resp_len
= reply_len
;
7558 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
7561 struct wpa_interface iface
;
7565 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7566 * TAB<bridge_ifname>
7568 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
7570 os_memset(&iface
, 0, sizeof(iface
));
7573 iface
.ifname
= pos
= cmd
;
7574 pos
= os_strchr(pos
, '\t');
7577 if (iface
.ifname
[0] == '\0')
7582 iface
.confname
= pos
;
7583 pos
= os_strchr(pos
, '\t');
7586 if (iface
.confname
[0] == '\0')
7587 iface
.confname
= NULL
;
7592 pos
= os_strchr(pos
, '\t');
7595 if (iface
.driver
[0] == '\0')
7596 iface
.driver
= NULL
;
7600 iface
.ctrl_interface
= pos
;
7601 pos
= os_strchr(pos
, '\t');
7604 if (iface
.ctrl_interface
[0] == '\0')
7605 iface
.ctrl_interface
= NULL
;
7609 iface
.driver_param
= pos
;
7610 pos
= os_strchr(pos
, '\t');
7613 if (iface
.driver_param
[0] == '\0')
7614 iface
.driver_param
= NULL
;
7618 iface
.bridge_ifname
= pos
;
7619 pos
= os_strchr(pos
, '\t');
7622 if (iface
.bridge_ifname
[0] == '\0')
7623 iface
.bridge_ifname
= NULL
;
7628 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
7631 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
7635 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
7638 struct wpa_supplicant
*wpa_s
;
7640 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
7642 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
7645 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
7649 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
7651 struct wpa_interface_info
*prev
;
7655 iface
= iface
->next
;
7657 os_free(prev
->ifname
);
7658 os_free(prev
->desc
);
7664 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
7668 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
7671 for (i
= 0; wpa_drivers
[i
]; i
++) {
7672 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
7673 if (drv
->get_interfaces
== NULL
)
7675 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
7689 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
7690 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
7691 tmp
->drv_name
, tmp
->ifname
,
7692 tmp
->desc
? tmp
->desc
: "");
7693 if (os_snprintf_error(end
- pos
, res
)) {
7700 wpa_free_iface_info(iface
);
7706 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
7711 struct wpa_supplicant
*wpa_s
;
7713 wpa_s
= global
->ifaces
;
7718 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
7719 if (os_snprintf_error(end
- pos
, res
)) {
7724 wpa_s
= wpa_s
->next
;
7730 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
7732 char *cmd
, size_t *resp_len
)
7734 struct wpa_supplicant
*wpa_s
;
7736 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7737 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
7741 if (wpa_s
== NULL
) {
7742 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
7744 *resp_len
= os_strlen(resp
);
7750 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
7754 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
7755 char *buf
, size_t *resp_len
)
7758 static const char * cmd
[] = {
7764 "P2P_GET_PASSPHRASE",
7765 "P2P_SERVICE_UPDATE",
7766 "P2P_SERVICE_FLUSH",
7773 static const char * prefix
[] = {
7776 #endif /* ANDROID */
7782 "P2P_GROUP_REMOVE ",
7785 "P2P_SERV_DISC_REQ ",
7786 "P2P_SERV_DISC_CANCEL_REQ ",
7787 "P2P_SERV_DISC_RESP ",
7788 "P2P_SERV_DISC_EXTERNAL ",
7796 "P2P_PRESENCE_REQ ",
7798 "P2P_REMOVE_CLIENT ",
7799 "NFC_GET_HANDOVER_SEL ",
7800 "NFC_GET_HANDOVER_REQ ",
7801 "NFC_REPORT_HANDOVER ",
7807 if (global
->p2p_init_wpa_s
== NULL
)
7810 for (i
= 0; !found
&& cmd
[i
]; i
++) {
7811 if (os_strcmp(buf
, cmd
[i
]) == 0)
7815 for (i
= 0; !found
&& prefix
[i
]; i
++) {
7816 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
7821 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7823 #endif /* CONFIG_P2P */
7828 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
7829 char *buf
, size_t *resp_len
)
7831 #ifdef CONFIG_WIFI_DISPLAY
7832 if (global
->p2p_init_wpa_s
== NULL
)
7834 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
7835 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
7836 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7838 #endif /* CONFIG_WIFI_DISPLAY */
7843 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
7844 char *buf
, size_t *resp_len
)
7848 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
7852 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
7860 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
7864 value
= os_strchr(cmd
, ' ');
7869 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
7871 #ifdef CONFIG_WIFI_DISPLAY
7872 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
7873 wifi_display_enable(global
, !!atoi(value
));
7876 #endif /* CONFIG_WIFI_DISPLAY */
7878 /* Restore cmd to its original value to allow redirection */
7885 #ifndef CONFIG_NO_CONFIG_WRITE
7886 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
7888 int ret
= 0, saved
= 0;
7889 struct wpa_supplicant
*wpa_s
;
7891 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7892 if (!wpa_s
->conf
->update_config
) {
7893 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7897 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
7898 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7901 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7906 if (!saved
&& !ret
) {
7907 wpa_dbg(wpa_s
, MSG_DEBUG
,
7908 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7914 #endif /* CONFIG_NO_CONFIG_WRITE */
7917 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
7918 char *buf
, size_t buflen
)
7922 struct wpa_supplicant
*wpa_s
;
7928 if (global
->p2p
&& !global
->p2p_disabled
) {
7929 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
7932 MAC2STR(global
->p2p_dev_addr
),
7933 p2p_get_state_txt(global
->p2p
));
7934 if (os_snprintf_error(end
- pos
, ret
))
7937 } else if (global
->p2p
) {
7938 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
7939 if (os_snprintf_error(end
- pos
, ret
))
7943 #endif /* CONFIG_P2P */
7945 #ifdef CONFIG_WIFI_DISPLAY
7946 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
7947 !!global
->wifi_display
);
7948 if (os_snprintf_error(end
- pos
, ret
))
7951 #endif /* CONFIG_WIFI_DISPLAY */
7953 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7954 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
7955 "address=" MACSTR
"\n",
7956 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
7957 if (os_snprintf_error(end
- pos
, ret
))
7966 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
7967 char *buf
, size_t *resp_len
)
7970 const int reply_size
= 2048;
7972 int level
= MSG_DEBUG
;
7974 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
7975 char *pos
= os_strchr(buf
+ 7, ' ');
7978 return wpas_global_ctrl_iface_ifname(global
,
7984 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
7988 if (os_strcmp(buf
, "PING") == 0)
7989 level
= MSG_EXCESSIVE
;
7990 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
7991 (const u8
*) buf
, os_strlen(buf
));
7993 reply
= os_malloc(reply_size
);
7994 if (reply
== NULL
) {
7999 os_memcpy(reply
, "OK\n", 3);
8002 if (os_strcmp(buf
, "PING") == 0) {
8003 os_memcpy(reply
, "PONG\n", 5);
8005 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
8006 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
8008 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
8009 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
8011 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
8012 reply_len
= wpa_supplicant_global_iface_list(
8013 global
, reply
, reply_size
);
8014 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
8015 reply_len
= wpa_supplicant_global_iface_interfaces(
8016 global
, reply
, reply_size
);
8017 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
8018 wpa_supplicant_terminate_proc(global
);
8019 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
8020 wpas_notify_suspend(global
);
8021 } else if (os_strcmp(buf
, "RESUME") == 0) {
8022 wpas_notify_resume(global
);
8023 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
8024 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
8026 if (global
->p2p_init_wpa_s
) {
8028 /* Check if P2P redirection would work for this
8030 return wpa_supplicant_ctrl_iface_process(
8031 global
->p2p_init_wpa_s
,
8034 #endif /* CONFIG_P2P */
8037 #ifndef CONFIG_NO_CONFIG_WRITE
8038 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
8039 if (wpas_global_ctrl_iface_save_config(global
))
8041 #endif /* CONFIG_NO_CONFIG_WRITE */
8042 } else if (os_strcmp(buf
, "STATUS") == 0) {
8043 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
8045 #ifdef CONFIG_MODULE_TESTS
8046 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
8047 int wpas_module_tests(void);
8048 if (wpas_module_tests() < 0)
8050 #endif /* CONFIG_MODULE_TESTS */
8051 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
8052 if (wpa_debug_reopen_file() < 0)
8055 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
8059 if (reply_len
< 0) {
8060 os_memcpy(reply
, "FAIL\n", 5);
8064 *resp_len
= reply_len
;