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"
51 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
53 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
55 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
58 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
61 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
68 if (hwaddr_aton(pos
, addr
)) {
72 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
78 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
81 pos
= os_strchr(pos
, ' ');
86 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
87 os_free(wpa_s
->bssid_filter
);
88 wpa_s
->bssid_filter
= filter
;
89 wpa_s
->bssid_filter_count
= count
;
95 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
98 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
99 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
100 size_t count
= 0, ssid_count
= 0;
104 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
105 * SSID_SPEC ::= ssid <SSID_HEX>
106 * BSSID_SPEC ::= bssid <BSSID_HEX>
113 if (os_strncmp(pos
, "bssid ", 6) == 0) {
116 res
= hwaddr_aton2(pos
, addr
);
120 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
121 "BSSID value '%s'", pos
);
125 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
132 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
134 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
140 if (*end
== '\0' || *end
== ' ')
145 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
146 sizeof(struct wpa_ssid_value
));
154 if ((end
- pos
) & 0x01 || end
- pos
> 2 * 32 ||
155 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
156 (end
- pos
) / 2) < 0) {
159 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
160 "SSID value '%s'", pos
);
163 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
164 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
165 ssid
[ssid_count
].ssid
,
166 ssid
[ssid_count
].ssid_len
);
170 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
177 pos
= os_strchr(pos
, ' ');
182 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
183 os_free(wpa_s
->disallow_aps_bssid
);
184 wpa_s
->disallow_aps_bssid
= bssid
;
185 wpa_s
->disallow_aps_bssid_count
= count
;
187 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
188 os_free(wpa_s
->disallow_aps_ssid
);
189 wpa_s
->disallow_aps_ssid
= ssid
;
190 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
192 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
195 c
= wpa_s
->current_ssid
;
196 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
199 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
200 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
203 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
204 "because current AP was marked disallowed");
207 wpa_s
->sme
.prev_bssid_set
= 0;
208 #endif /* CONFIG_SME */
209 wpa_s
->reassociate
= 1;
210 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
211 wpa_supplicant_req_scan(wpa_s
, 0, 0);
217 #ifndef CONFIG_NO_CONFIG_BLOBS
218 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
221 struct wpa_config_blob
*blob
;
224 pos
= os_strchr(pos
, ' ');
228 len
= os_strlen(pos
);
232 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
233 blob
= os_zalloc(sizeof(*blob
));
236 blob
->name
= os_strdup(name
);
237 blob
->data
= os_malloc(len
/ 2);
238 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
239 wpa_config_free_blob(blob
);
243 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
244 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
245 wpa_config_free_blob(blob
);
250 wpa_config_set_blob(wpa_s
->conf
, blob
);
254 #endif /* CONFIG_NO_CONFIG_BLOBS */
257 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
265 params
= os_strchr(cmd
, ' ');
266 os_free(wpa_s
->manual_sched_scan_freqs
);
269 pos
= os_strstr(params
, "freq=");
271 freqs
= freq_range_to_channel_list(wpa_s
,
274 wpa_s
->manual_sched_scan_freqs
= freqs
;
275 ret
= wpas_start_pno(wpa_s
);
277 ret
= wpas_stop_pno(wpa_s
);
283 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
289 value
= os_strchr(cmd
, ' ');
294 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
295 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
296 eapol_sm_configure(wpa_s
->eapol
,
297 atoi(value
), -1, -1, -1);
298 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
299 eapol_sm_configure(wpa_s
->eapol
,
300 -1, atoi(value
), -1, -1);
301 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
302 eapol_sm_configure(wpa_s
->eapol
,
303 -1, -1, atoi(value
), -1);
304 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
305 eapol_sm_configure(wpa_s
->eapol
,
306 -1, -1, -1, atoi(value
));
307 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
308 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
311 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
313 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
316 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
317 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
319 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
320 wpa_s
->wps_fragment_size
= atoi(value
);
321 #ifdef CONFIG_WPS_TESTING
322 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
324 val
= strtol(value
, NULL
, 0);
325 if (val
< 0 || val
> 0xff) {
327 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
328 "wps_version_number %ld", val
);
330 wps_version_number
= val
;
331 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
333 (wps_version_number
& 0xf0) >> 4,
334 wps_version_number
& 0x0f);
336 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
337 wps_testing_dummy_cred
= atoi(value
);
338 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
339 wps_testing_dummy_cred
);
340 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
341 wps_corrupt_pkhash
= atoi(value
);
342 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
344 #endif /* CONFIG_WPS_TESTING */
345 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
346 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
349 #ifdef CONFIG_TDLS_TESTING
350 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
351 extern unsigned int tdls_testing
;
352 tdls_testing
= strtol(value
, NULL
, 0);
353 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
354 #endif /* CONFIG_TDLS_TESTING */
355 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
356 int disabled
= atoi(value
);
357 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
359 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
361 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
363 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
364 #endif /* CONFIG_TDLS */
365 } else if (os_strcasecmp(cmd
, "pno") == 0) {
366 ret
= wpas_ctrl_pno(wpa_s
, value
);
367 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
368 int disabled
= atoi(value
);
369 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
372 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
373 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
374 if (os_strcmp(value
, "disable") == 0)
375 wpa_s
->set_sta_uapsd
= 0;
379 /* format: BE,BK,VI,VO;max SP Length */
381 pos
= os_strchr(value
, ',');
386 pos
= os_strchr(pos
, ',');
391 pos
= os_strchr(pos
, ',');
396 /* ignore max SP Length for now */
398 wpa_s
->set_sta_uapsd
= 1;
399 wpa_s
->sta_uapsd
= 0;
401 wpa_s
->sta_uapsd
|= BIT(0);
403 wpa_s
->sta_uapsd
|= BIT(1);
405 wpa_s
->sta_uapsd
|= BIT(2);
407 wpa_s
->sta_uapsd
|= BIT(3);
409 } else if (os_strcasecmp(cmd
, "ps") == 0) {
410 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
411 #ifdef CONFIG_WIFI_DISPLAY
412 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
413 int enabled
= !!atoi(value
);
414 if (enabled
&& !wpa_s
->global
->p2p
)
417 wifi_display_enable(wpa_s
->global
, enabled
);
418 #endif /* CONFIG_WIFI_DISPLAY */
419 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
420 ret
= set_bssid_filter(wpa_s
, value
);
421 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
422 ret
= set_disallow_aps(wpa_s
, value
);
423 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
424 wpa_s
->no_keep_alive
= !!atoi(value
);
425 #ifdef CONFIG_TESTING_OPTIONS
426 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
427 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
428 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
429 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
431 if (wpa_s
->ap_iface
) {
432 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
433 wpa_s
->ext_eapol_frame_io
;
435 #endif /* CONFIG_AP */
436 #endif /* CONFIG_TESTING_OPTIONS */
437 #ifndef CONFIG_NO_CONFIG_BLOBS
438 } else if (os_strcmp(cmd
, "blob") == 0) {
439 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
440 #endif /* CONFIG_NO_CONFIG_BLOBS */
443 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
445 wpa_supplicant_update_config(wpa_s
);
452 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
453 char *cmd
, char *buf
, size_t buflen
)
457 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
459 if (os_strcmp(cmd
, "version") == 0) {
460 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
461 } else if (os_strcasecmp(cmd
, "country") == 0) {
462 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
463 res
= os_snprintf(buf
, buflen
, "%c%c",
464 wpa_s
->conf
->country
[0],
465 wpa_s
->conf
->country
[1]);
466 #ifdef CONFIG_WIFI_DISPLAY
467 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
469 if (wpa_s
->global
->p2p
== NULL
||
470 wpa_s
->global
->p2p_disabled
)
473 enabled
= wpa_s
->global
->wifi_display
;
474 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
475 if (res
< 0 || (unsigned int) res
>= buflen
)
478 #endif /* CONFIG_WIFI_DISPLAY */
479 #ifdef CONFIG_TESTING_GET_GTK
480 } else if (os_strcmp(cmd
, "gtk") == 0) {
481 if (wpa_s
->last_gtk_len
== 0)
483 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
484 wpa_s
->last_gtk_len
);
486 #endif /* CONFIG_TESTING_GET_GTK */
489 if (res
< 0 || (unsigned int) res
>= buflen
)
495 #ifdef IEEE8021X_EAPOL
496 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
500 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
502 if (hwaddr_aton(addr
, bssid
)) {
503 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
508 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
509 rsn_preauth_deinit(wpa_s
->wpa
);
510 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
515 #endif /* IEEE8021X_EAPOL */
518 #ifdef CONFIG_PEERKEY
519 /* MLME-STKSTART.request(peer) */
520 static int wpa_supplicant_ctrl_iface_stkstart(
521 struct wpa_supplicant
*wpa_s
, char *addr
)
525 if (hwaddr_aton(addr
, peer
)) {
526 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
527 "address '%s'", addr
);
531 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
534 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
536 #endif /* CONFIG_PEERKEY */
541 static int wpa_supplicant_ctrl_iface_tdls_discover(
542 struct wpa_supplicant
*wpa_s
, char *addr
)
547 if (hwaddr_aton(addr
, peer
)) {
548 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
549 "address '%s'", addr
);
553 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
556 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
557 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
559 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
565 static int wpa_supplicant_ctrl_iface_tdls_setup(
566 struct wpa_supplicant
*wpa_s
, char *addr
)
571 if (hwaddr_aton(addr
, peer
)) {
572 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
573 "address '%s'", addr
);
577 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
580 if ((wpa_s
->conf
->tdls_external_control
) &&
581 wpa_tdls_is_external_setup(wpa_s
->wpa
))
582 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
584 wpa_tdls_remove(wpa_s
->wpa
, peer
);
586 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
587 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
589 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
595 static int wpa_supplicant_ctrl_iface_tdls_teardown(
596 struct wpa_supplicant
*wpa_s
, char *addr
)
601 if (os_strcmp(addr
, "*") == 0) {
602 /* remove everyone */
603 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
604 wpa_tdls_teardown_peers(wpa_s
->wpa
);
608 if (hwaddr_aton(addr
, peer
)) {
609 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
610 "address '%s'", addr
);
614 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
617 if ((wpa_s
->conf
->tdls_external_control
) &&
618 wpa_tdls_is_external_setup(wpa_s
->wpa
))
619 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
621 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
622 ret
= wpa_tdls_teardown_link(
624 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
626 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
632 static int ctrl_iface_get_capability_tdls(
633 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
637 ret
= os_snprintf(buf
, buflen
, "%s\n",
638 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
640 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
641 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
642 if (ret
< 0 || (size_t) ret
> buflen
)
647 #endif /* CONFIG_TDLS */
650 #ifdef CONFIG_IEEE80211R
651 static int wpa_supplicant_ctrl_iface_ft_ds(
652 struct wpa_supplicant
*wpa_s
, char *addr
)
654 u8 target_ap
[ETH_ALEN
];
658 if (hwaddr_aton(addr
, target_ap
)) {
659 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
660 "address '%s'", addr
);
664 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
666 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
668 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
672 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
674 #endif /* CONFIG_IEEE80211R */
678 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
681 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
683 u8 p2p_dev_addr
[ETH_ALEN
];
684 #endif /* CONFIG_P2P */
686 u8
*_p2p_dev_addr
= NULL
;
687 #endif /* CONFIG_AP */
689 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
692 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
693 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
694 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
695 "P2P Device Address '%s'",
699 _p2p_dev_addr
= p2p_dev_addr
;
700 #endif /* CONFIG_P2P */
701 } else if (hwaddr_aton(cmd
, bssid
)) {
702 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
709 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
710 #endif /* CONFIG_AP */
712 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
716 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
717 char *cmd
, char *buf
,
720 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
724 pin
= os_strchr(cmd
, ' ');
728 if (os_strcmp(cmd
, "any") == 0)
730 else if (os_strcmp(cmd
, "get") == 0) {
731 ret
= wps_generate_pin();
733 } else if (hwaddr_aton(cmd
, bssid
)) {
734 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
740 if (wpa_s
->ap_iface
) {
745 pos
= os_strchr(pin
, ' ');
752 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
753 buf
, buflen
, timeout
);
755 #endif /* CONFIG_AP */
758 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
762 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
763 if (ret
< 0 || (size_t) ret
>= buflen
)
768 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
773 /* Return the generated PIN */
774 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
775 if (ret
< 0 || (size_t) ret
>= buflen
)
781 static int wpa_supplicant_ctrl_iface_wps_check_pin(
782 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
789 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
790 (u8
*) cmd
, os_strlen(cmd
));
791 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
792 if (*pos
< '0' || *pos
> '9')
796 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
800 if (len
!= 4 && len
!= 8) {
801 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
807 unsigned int pin_val
;
809 if (!wps_pin_valid(pin_val
)) {
810 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
811 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
812 if (ret
< 0 || (size_t) ret
>= buflen
)
818 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
819 if (ret
< 0 || (size_t) ret
>= buflen
)
826 #ifdef CONFIG_WPS_NFC
828 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
831 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
833 if (cmd
== NULL
|| cmd
[0] == '\0')
835 else if (hwaddr_aton(cmd
, bssid
))
838 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
843 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
844 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
851 pos
= os_strchr(cmd
, ' ');
854 if (os_strcmp(cmd
, "WPS") == 0)
856 else if (os_strcmp(cmd
, "NDEF") == 0)
861 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
865 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
876 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
877 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
883 if (os_strcmp(cmd
, "WPS") == 0)
885 else if (os_strcmp(cmd
, "NDEF") == 0)
890 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
894 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
905 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
906 struct wpa_supplicant
*wpa_s
, char *pos
)
914 freq
= strstr(pos
, " freq=");
918 forced_freq
= atoi(freq
);
921 len
= os_strlen(pos
);
926 buf
= wpabuf_alloc(len
);
929 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
934 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
941 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
942 char *reply
, size_t max_len
,
948 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
952 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
964 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
965 char *reply
, size_t max_len
,
971 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
973 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
977 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
986 #endif /* CONFIG_P2P */
989 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
990 char *cmd
, char *reply
,
996 pos
= os_strchr(cmd
, ' ');
1001 if (os_strcmp(cmd
, "WPS") == 0)
1003 else if (os_strcmp(cmd
, "NDEF") == 0)
1008 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1011 return wpas_ctrl_nfc_get_handover_req_wps(
1012 wpa_s
, reply
, max_len
, ndef
);
1016 if (os_strcmp(pos
, "P2P-CR") == 0) {
1017 return wpas_ctrl_nfc_get_handover_req_p2p(
1018 wpa_s
, reply
, max_len
, ndef
);
1020 #endif /* CONFIG_P2P */
1026 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1027 char *reply
, size_t max_len
,
1028 int ndef
, int cr
, char *uuid
)
1033 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1037 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1039 reply
[res
++] = '\n';
1049 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1050 char *reply
, size_t max_len
,
1056 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1060 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1062 reply
[res
++] = '\n';
1069 #endif /* CONFIG_P2P */
1072 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1073 char *cmd
, char *reply
,
1079 pos
= os_strchr(cmd
, ' ');
1084 if (os_strcmp(cmd
, "WPS") == 0)
1086 else if (os_strcmp(cmd
, "NDEF") == 0)
1091 pos2
= os_strchr(pos
, ' ');
1094 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1097 return wpas_ctrl_nfc_get_handover_sel_wps(
1098 wpa_s
, reply
, max_len
, ndef
,
1099 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1103 if (os_strcmp(pos
, "P2P-CR") == 0) {
1104 return wpas_ctrl_nfc_get_handover_sel_p2p(
1105 wpa_s
, reply
, max_len
, ndef
, 0);
1108 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1109 return wpas_ctrl_nfc_get_handover_sel_p2p(
1110 wpa_s
, reply
, max_len
, ndef
, 1);
1112 #endif /* CONFIG_P2P */
1118 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1122 struct wpabuf
*req
, *sel
;
1124 char *pos
, *role
, *type
, *pos2
;
1127 int forced_freq
= 0;
1129 freq
= strstr(cmd
, " freq=");
1133 forced_freq
= atoi(freq
);
1135 #endif /* CONFIG_P2P */
1138 pos
= os_strchr(role
, ' ');
1140 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1146 pos
= os_strchr(type
, ' ');
1148 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1153 pos2
= os_strchr(pos
, ' ');
1155 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1160 len
= os_strlen(pos
);
1162 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1167 req
= wpabuf_alloc(len
);
1169 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1172 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1173 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1178 len
= os_strlen(pos2
);
1180 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1186 sel
= wpabuf_alloc(len
);
1188 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1192 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1193 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1199 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1200 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1202 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1203 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1205 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1207 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1209 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1210 #endif /* CONFIG_AP */
1212 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1214 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1215 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1217 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1219 #endif /* CONFIG_P2P */
1221 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1222 "reported: role=%s type=%s", role
, type
);
1229 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1234 #endif /* CONFIG_WPS_NFC */
1237 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1246 struct wps_new_ap_settings ap
;
1248 pin
= os_strchr(cmd
, ' ');
1253 if (hwaddr_aton(cmd
, bssid
)) {
1254 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1259 new_ssid
= os_strchr(pin
, ' ');
1260 if (new_ssid
== NULL
)
1261 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1264 new_auth
= os_strchr(new_ssid
, ' ');
1265 if (new_auth
== NULL
)
1269 new_encr
= os_strchr(new_auth
, ' ');
1270 if (new_encr
== NULL
)
1274 new_key
= os_strchr(new_encr
, ' ');
1275 if (new_key
== NULL
)
1279 os_memset(&ap
, 0, sizeof(ap
));
1280 ap
.ssid_hex
= new_ssid
;
1283 ap
.key_hex
= new_key
;
1284 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1289 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1290 char *cmd
, char *buf
,
1295 const char *pin_txt
;
1297 if (!wpa_s
->ap_iface
)
1300 pos
= os_strchr(cmd
, ' ');
1304 if (os_strcmp(cmd
, "disable") == 0) {
1305 wpas_wps_ap_pin_disable(wpa_s
);
1306 return os_snprintf(buf
, buflen
, "OK\n");
1309 if (os_strcmp(cmd
, "random") == 0) {
1311 timeout
= atoi(pos
);
1312 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1313 if (pin_txt
== NULL
)
1315 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1318 if (os_strcmp(cmd
, "get") == 0) {
1319 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1320 if (pin_txt
== NULL
)
1322 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1325 if (os_strcmp(cmd
, "set") == 0) {
1330 pos
= os_strchr(pos
, ' ');
1333 timeout
= atoi(pos
);
1335 if (os_strlen(pin
) > buflen
)
1337 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1339 return os_snprintf(buf
, buflen
, "%s", pin
);
1344 #endif /* CONFIG_AP */
1347 #ifdef CONFIG_WPS_ER
1348 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1351 char *uuid
= cmd
, *pin
, *pos
;
1352 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1353 pin
= os_strchr(uuid
, ' ');
1357 pos
= os_strchr(pin
, ' ');
1360 if (hwaddr_aton(pos
, addr_buf
) == 0)
1363 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1367 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1370 char *uuid
= cmd
, *pin
;
1371 pin
= os_strchr(uuid
, ' ');
1375 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1379 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1380 struct wpa_supplicant
*wpa_s
, char *cmd
)
1382 char *uuid
= cmd
, *id
;
1383 id
= os_strchr(uuid
, ' ');
1387 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1391 static int wpa_supplicant_ctrl_iface_wps_er_config(
1392 struct wpa_supplicant
*wpa_s
, char *cmd
)
1399 struct wps_new_ap_settings ap
;
1401 pin
= os_strchr(cmd
, ' ');
1406 new_ssid
= os_strchr(pin
, ' ');
1407 if (new_ssid
== NULL
)
1411 new_auth
= os_strchr(new_ssid
, ' ');
1412 if (new_auth
== NULL
)
1416 new_encr
= os_strchr(new_auth
, ' ');
1417 if (new_encr
== NULL
)
1421 new_key
= os_strchr(new_encr
, ' ');
1422 if (new_key
== NULL
)
1426 os_memset(&ap
, 0, sizeof(ap
));
1427 ap
.ssid_hex
= new_ssid
;
1430 ap
.key_hex
= new_key
;
1431 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1435 #ifdef CONFIG_WPS_NFC
1436 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1437 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1444 uuid
= os_strchr(cmd
, ' ');
1449 if (os_strcmp(cmd
, "WPS") == 0)
1451 else if (os_strcmp(cmd
, "NDEF") == 0)
1456 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1460 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1462 reply
[res
++] = '\n';
1469 #endif /* CONFIG_WPS_NFC */
1470 #endif /* CONFIG_WPS_ER */
1472 #endif /* CONFIG_WPS */
1475 #ifdef CONFIG_IBSS_RSN
1476 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1477 struct wpa_supplicant
*wpa_s
, char *addr
)
1481 if (hwaddr_aton(addr
, peer
)) {
1482 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1483 "address '%s'", addr
);
1487 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1490 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1492 #endif /* CONFIG_IBSS_RSN */
1495 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1498 #ifdef IEEE8021X_EAPOL
1501 struct wpa_ssid
*ssid
;
1503 pos
= os_strchr(rsp
, '-');
1508 pos
= os_strchr(pos
, ':');
1513 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1514 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1515 (u8
*) pos
, os_strlen(pos
));
1517 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1519 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1524 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1526 #else /* IEEE8021X_EAPOL */
1527 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1529 #endif /* IEEE8021X_EAPOL */
1533 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1535 char *buf
, size_t buflen
)
1537 char *pos
, *end
, tmp
[30];
1538 int res
, verbose
, wps
, ret
;
1541 #endif /* CONFIG_HS20 */
1543 if (os_strcmp(params
, "-DRIVER") == 0)
1544 return wpa_drv_status(wpa_s
, buf
, buflen
);
1545 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1546 wps
= os_strcmp(params
, "-WPS") == 0;
1549 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1550 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1551 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1552 MAC2STR(wpa_s
->bssid
));
1553 if (ret
< 0 || ret
>= end
- pos
)
1556 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1558 if (ret
< 0 || ret
>= end
- pos
)
1562 u8
*_ssid
= ssid
->ssid
;
1563 size_t ssid_len
= ssid
->ssid_len
;
1564 u8 ssid_buf
[MAX_SSID_LEN
];
1565 if (ssid_len
== 0) {
1566 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1573 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1574 wpa_ssid_txt(_ssid
, ssid_len
),
1576 if (ret
< 0 || ret
>= end
- pos
)
1580 if (wps
&& ssid
->passphrase
&&
1581 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1582 (ssid
->mode
== WPAS_MODE_AP
||
1583 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1584 ret
= os_snprintf(pos
, end
- pos
,
1587 if (ret
< 0 || ret
>= end
- pos
)
1592 ret
= os_snprintf(pos
, end
- pos
,
1595 if (ret
< 0 || ret
>= end
- pos
)
1600 switch (ssid
->mode
) {
1601 case WPAS_MODE_INFRA
:
1602 ret
= os_snprintf(pos
, end
- pos
,
1605 case WPAS_MODE_IBSS
:
1606 ret
= os_snprintf(pos
, end
- pos
,
1610 ret
= os_snprintf(pos
, end
- pos
,
1613 case WPAS_MODE_P2P_GO
:
1614 ret
= os_snprintf(pos
, end
- pos
,
1617 case WPAS_MODE_P2P_GROUP_FORMATION
:
1618 ret
= os_snprintf(pos
, end
- pos
,
1619 "mode=P2P GO - group "
1626 if (ret
< 0 || ret
>= end
- pos
)
1632 if (wpa_s
->ap_iface
) {
1633 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1637 #endif /* CONFIG_AP */
1638 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1641 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1644 #endif /* CONFIG_AP */
1645 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1646 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1647 wpa_s
->sme
.sae
.group
);
1648 if (ret
< 0 || ret
>= end
- pos
)
1652 #endif /* CONFIG_SAE */
1653 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1654 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1655 if (ret
< 0 || ret
>= end
- pos
)
1660 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1661 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1662 if (ret
< 0 || ret
>= end
- pos
)
1668 if (wpa_s
->global
->p2p
) {
1669 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1670 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1671 if (ret
< 0 || ret
>= end
- pos
)
1675 #endif /* CONFIG_P2P */
1677 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1678 MAC2STR(wpa_s
->own_addr
));
1679 if (ret
< 0 || ret
>= end
- pos
)
1684 if (wpa_s
->current_bss
&&
1685 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1686 HS20_IE_VENDOR_TYPE
)) &&
1687 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1688 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1691 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
1692 release
= rel_num
+ 1;
1694 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
1695 if (ret
< 0 || ret
>= end
- pos
)
1700 if (wpa_s
->current_ssid
) {
1701 struct wpa_cred
*cred
;
1704 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1707 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1710 if (cred
->provisioning_sp
) {
1711 ret
= os_snprintf(pos
, end
- pos
,
1712 "provisioning_sp=%s\n",
1713 cred
->provisioning_sp
);
1714 if (ret
< 0 || ret
>= end
- pos
)
1723 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
1724 struct wpabuf
*names
=
1725 wpa_s
->current_bss
->anqp
->domain_name
;
1726 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
1728 if (domain_name_list_contains(
1729 names
, cred
->domain
[i
], 1))
1732 if (i
== cred
->num_domain
)
1733 i
= 0; /* show first entry by default */
1735 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
1737 if (ret
< 0 || ret
>= end
- pos
)
1742 if (wpa_s
->current_bss
== NULL
||
1743 wpa_s
->current_bss
->anqp
== NULL
)
1746 res
= interworking_home_sp_cred(
1748 wpa_s
->current_bss
->anqp
->domain_name
);
1756 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1757 if (ret
< 0 || ret
>= end
- pos
)
1764 #endif /* CONFIG_HS20 */
1766 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1767 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1768 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1774 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1781 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1782 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1783 if (ret
< 0 || ret
>= end
- pos
)
1787 #endif /* CONFIG_WPS */
1791 * Allow using the STATUS command with default behavior, say for debug,
1792 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1793 * events with STATUS-NO_EVENTS.
1795 if (os_strcmp(params
, "-NO_EVENTS")) {
1796 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1797 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1798 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1800 MAC2STR(wpa_s
->bssid
),
1801 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1802 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1803 wpa_s
->current_ssid
->ssid_len
) : "");
1804 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1805 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1806 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1807 "- connection to " MACSTR
1808 " completed %s [id=%d id_str=%s]",
1809 MAC2STR(wpa_s
->bssid
), "(auth)",
1810 ssid
? ssid
->id
: -1,
1811 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1814 #endif /* ANDROID */
1820 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1825 struct wpa_ssid
*ssid
;
1828 /* cmd: "<network id> <BSSID>" */
1829 pos
= os_strchr(cmd
, ' ');
1834 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1835 if (hwaddr_aton(pos
, bssid
)) {
1836 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1840 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1842 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1847 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1848 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1854 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1855 char *cmd
, char *buf
,
1859 struct wpa_blacklist
*e
;
1863 /* cmd: "BLACKLIST [<BSSID>]" */
1867 e
= wpa_s
->blacklist
;
1869 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1871 if (ret
< 0 || ret
>= end
- pos
)
1880 if (os_strncmp(cmd
, "clear", 5) == 0) {
1881 wpa_blacklist_clear(wpa_s
);
1882 os_memcpy(buf
, "OK\n", 3);
1886 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1887 if (hwaddr_aton(cmd
, bssid
)) {
1888 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1893 * Add the BSSID twice, so its count will be 2, causing it to be
1894 * skipped when processing scan results.
1896 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1899 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1902 os_memcpy(buf
, "OK\n", 3);
1907 static const char * debug_level_str(int level
)
1928 static int str_to_debug_level(const char *s
)
1930 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1931 return MSG_EXCESSIVE
;
1932 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1934 if (os_strcasecmp(s
, "DEBUG") == 0)
1936 if (os_strcasecmp(s
, "INFO") == 0)
1938 if (os_strcasecmp(s
, "WARNING") == 0)
1940 if (os_strcasecmp(s
, "ERROR") == 0)
1946 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1947 char *cmd
, char *buf
,
1950 char *pos
, *end
, *stamp
;
1957 /* cmd: "LOG_LEVEL [<level>]" */
1961 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1963 debug_level_str(wpa_debug_level
),
1964 wpa_debug_timestamp
);
1965 if (ret
< 0 || ret
>= end
- pos
)
1974 stamp
= os_strchr(cmd
, ' ');
1977 while (*stamp
== ' ') {
1982 if (cmd
&& os_strlen(cmd
)) {
1983 int level
= str_to_debug_level(cmd
);
1986 wpa_debug_level
= level
;
1989 if (stamp
&& os_strlen(stamp
))
1990 wpa_debug_timestamp
= atoi(stamp
);
1992 os_memcpy(buf
, "OK\n", 3);
1997 static int wpa_supplicant_ctrl_iface_list_networks(
1998 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2001 struct wpa_ssid
*ssid
;
2006 ret
= os_snprintf(pos
, end
- pos
,
2007 "network id / ssid / bssid / flags\n");
2008 if (ret
< 0 || ret
>= end
- pos
)
2012 ssid
= wpa_s
->conf
->ssid
;
2014 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2016 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2017 if (ret
< 0 || ret
>= end
- pos
)
2020 if (ssid
->bssid_set
) {
2021 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2022 MAC2STR(ssid
->bssid
));
2024 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2026 if (ret
< 0 || ret
>= end
- pos
)
2029 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2030 ssid
== wpa_s
->current_ssid
?
2032 ssid
->disabled
? "[DISABLED]" : "",
2033 ssid
->disabled_until
.sec
?
2034 "[TEMP-DISABLED]" : "",
2035 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2037 if (ret
< 0 || ret
>= end
- pos
)
2040 ret
= os_snprintf(pos
, end
- pos
, "\n");
2041 if (ret
< 0 || ret
>= end
- pos
)
2052 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2055 ret
= os_snprintf(pos
, end
- pos
, "-");
2056 if (ret
< 0 || ret
>= end
- pos
)
2059 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2067 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2068 const u8
*ie
, size_t ie_len
)
2070 struct wpa_ie_data data
;
2074 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2075 if (ret
< 0 || ret
>= end
- pos
)
2079 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2080 ret
= os_snprintf(pos
, end
- pos
, "?]");
2081 if (ret
< 0 || ret
>= end
- pos
)
2088 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2089 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2090 pos
== start
? "" : "+");
2091 if (ret
< 0 || ret
>= end
- pos
)
2095 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2096 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2097 pos
== start
? "" : "+");
2098 if (ret
< 0 || ret
>= end
- pos
)
2102 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2103 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2104 pos
== start
? "" : "+");
2105 if (ret
< 0 || ret
>= end
- pos
)
2109 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2110 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2111 pos
== start
? "" : "+");
2112 if (ret
< 0 || ret
>= end
- pos
)
2116 #ifdef CONFIG_IEEE80211R
2117 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2118 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2119 pos
== start
? "" : "+");
2120 if (ret
< 0 || ret
>= end
- pos
)
2124 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2125 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2126 pos
== start
? "" : "+");
2127 if (ret
< 0 || ret
>= end
- pos
)
2131 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2132 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2133 pos
== start
? "" : "+");
2134 if (ret
< 0 || ret
>= end
- pos
)
2138 #endif /* CONFIG_IEEE80211R */
2139 #ifdef CONFIG_IEEE80211W
2140 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2141 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2142 pos
== start
? "" : "+");
2143 if (ret
< 0 || ret
>= end
- pos
)
2147 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2148 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2149 pos
== start
? "" : "+");
2150 if (ret
< 0 || ret
>= end
- pos
)
2154 #endif /* CONFIG_IEEE80211W */
2156 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2158 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2159 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2160 if (ret
< 0 || ret
>= end
- pos
)
2165 ret
= os_snprintf(pos
, end
- pos
, "]");
2166 if (ret
< 0 || ret
>= end
- pos
)
2175 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2176 char *pos
, char *end
,
2177 struct wpabuf
*wps_ie
)
2184 if (wps_is_selected_pbc_registrar(wps_ie
))
2186 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2188 else if (wps_is_selected_pin_registrar(wps_ie
))
2193 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2194 if (ret
>= 0 && ret
< end
- pos
)
2196 wpabuf_free(wps_ie
);
2199 #endif /* CONFIG_WPS */
2202 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2203 char *pos
, char *end
,
2204 const struct wpa_bss
*bss
)
2207 struct wpabuf
*wps_ie
;
2208 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2209 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2210 #else /* CONFIG_WPS */
2212 #endif /* CONFIG_WPS */
2216 /* Format one result on one text line into a buffer. */
2217 static int wpa_supplicant_ctrl_iface_scan_result(
2218 struct wpa_supplicant
*wpa_s
,
2219 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2223 const u8
*ie
, *ie2
, *p2p
;
2225 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2227 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2228 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2229 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2231 return 0; /* Do not show P2P listen discovery results here */
2236 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2237 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2238 if (ret
< 0 || ret
>= end
- pos
)
2241 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2243 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2244 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2246 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
2247 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2248 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2249 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2250 if (ret
< 0 || ret
>= end
- pos
)
2254 if (bss_is_dmg(bss
)) {
2256 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2257 if (ret
< 0 || ret
>= end
- pos
)
2260 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2261 case IEEE80211_CAP_DMG_IBSS
:
2264 case IEEE80211_CAP_DMG_AP
:
2267 case IEEE80211_CAP_DMG_PBSS
:
2274 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2275 if (ret
< 0 || ret
>= end
- pos
)
2279 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2280 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2281 if (ret
< 0 || ret
>= end
- pos
)
2285 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2286 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2287 if (ret
< 0 || ret
>= end
- pos
)
2293 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2294 if (ret
< 0 || ret
>= end
- pos
)
2299 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2300 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2301 if (ret
< 0 || ret
>= end
- pos
)
2305 #endif /* CONFIG_HS20 */
2307 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2308 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2309 if (ret
< 0 || ret
>= end
- pos
)
2313 ret
= os_snprintf(pos
, end
- pos
, "\n");
2314 if (ret
< 0 || ret
>= end
- pos
)
2322 static int wpa_supplicant_ctrl_iface_scan_results(
2323 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2326 struct wpa_bss
*bss
;
2331 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2333 if (ret
< 0 || ret
>= end
- pos
)
2337 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2338 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2340 if (ret
< 0 || ret
>= end
- pos
)
2349 static int wpa_supplicant_ctrl_iface_select_network(
2350 struct wpa_supplicant
*wpa_s
, char *cmd
)
2353 struct wpa_ssid
*ssid
;
2356 /* cmd: "<network id>" or "any" */
2357 if (os_strncmp(cmd
, "any", 3) == 0) {
2358 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2362 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2364 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2366 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2367 "network id=%d", id
);
2370 if (ssid
->disabled
== 2) {
2371 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2372 "SELECT_NETWORK with persistent P2P group");
2377 pos
= os_strstr(cmd
, " freq=");
2379 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
2381 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2382 os_free(wpa_s
->manual_scan_freqs
);
2383 wpa_s
->manual_scan_freqs
= freqs
;
2387 wpa_supplicant_select_network(wpa_s
, ssid
);
2393 static int wpa_supplicant_ctrl_iface_enable_network(
2394 struct wpa_supplicant
*wpa_s
, char *cmd
)
2397 struct wpa_ssid
*ssid
;
2399 /* cmd: "<network id>" or "all" */
2400 if (os_strcmp(cmd
, "all") == 0) {
2401 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2405 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2407 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2409 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2410 "network id=%d", id
);
2413 if (ssid
->disabled
== 2) {
2414 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2415 "ENABLE_NETWORK with persistent P2P group");
2419 if (os_strstr(cmd
, " no-connect")) {
2424 wpa_supplicant_enable_network(wpa_s
, ssid
);
2430 static int wpa_supplicant_ctrl_iface_disable_network(
2431 struct wpa_supplicant
*wpa_s
, char *cmd
)
2434 struct wpa_ssid
*ssid
;
2436 /* cmd: "<network id>" or "all" */
2437 if (os_strcmp(cmd
, "all") == 0) {
2438 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2442 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2444 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2446 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2447 "network id=%d", id
);
2450 if (ssid
->disabled
== 2) {
2451 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2452 "DISABLE_NETWORK with persistent P2P "
2457 wpa_supplicant_disable_network(wpa_s
, ssid
);
2463 static int wpa_supplicant_ctrl_iface_add_network(
2464 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2466 struct wpa_ssid
*ssid
;
2469 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2471 ssid
= wpa_config_add_network(wpa_s
->conf
);
2475 wpas_notify_network_added(wpa_s
, ssid
);
2478 wpa_config_set_network_defaults(ssid
);
2480 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2481 if (ret
< 0 || (size_t) ret
>= buflen
)
2487 static int wpa_supplicant_ctrl_iface_remove_network(
2488 struct wpa_supplicant
*wpa_s
, char *cmd
)
2491 struct wpa_ssid
*ssid
;
2494 /* cmd: "<network id>" or "all" */
2495 if (os_strcmp(cmd
, "all") == 0) {
2496 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2497 if (wpa_s
->sched_scanning
)
2498 wpa_supplicant_cancel_sched_scan(wpa_s
);
2500 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2501 if (wpa_s
->current_ssid
) {
2503 wpa_s
->sme
.prev_bssid_set
= 0;
2504 #endif /* CONFIG_SME */
2505 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2506 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2507 wpa_supplicant_deauthenticate(
2508 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2510 ssid
= wpa_s
->conf
->ssid
;
2512 struct wpa_ssid
*remove_ssid
= ssid
;
2515 if (wpa_s
->last_ssid
== remove_ssid
)
2516 wpa_s
->last_ssid
= NULL
;
2517 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2518 wpa_config_remove_network(wpa_s
->conf
, id
);
2524 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2526 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2528 wpas_notify_network_removed(wpa_s
, ssid
);
2530 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2535 if (wpa_s
->last_ssid
== ssid
)
2536 wpa_s
->last_ssid
= NULL
;
2538 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2540 wpa_s
->sme
.prev_bssid_set
= 0;
2541 #endif /* CONFIG_SME */
2543 * Invalidate the EAP session cache if the current or
2544 * previously used network is removed.
2546 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2549 if (ssid
== wpa_s
->current_ssid
) {
2550 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2551 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2553 wpa_supplicant_deauthenticate(wpa_s
,
2554 WLAN_REASON_DEAUTH_LEAVING
);
2557 was_disabled
= ssid
->disabled
;
2559 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2560 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2561 "network id=%d", id
);
2565 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2566 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2567 "network from filters");
2568 wpa_supplicant_cancel_sched_scan(wpa_s
);
2569 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2576 static int wpa_supplicant_ctrl_iface_update_network(
2577 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
2578 char *name
, char *value
)
2580 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2581 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2582 "variable '%s'", name
);
2586 if (os_strcmp(name
, "bssid") != 0 &&
2587 os_strcmp(name
, "priority") != 0)
2588 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2590 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2592 * Invalidate the EAP session cache if anything in the current
2593 * or previously used configuration changes.
2595 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2598 if ((os_strcmp(name
, "psk") == 0 &&
2599 value
[0] == '"' && ssid
->ssid_len
) ||
2600 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2601 wpa_config_update_psk(ssid
);
2602 else if (os_strcmp(name
, "priority") == 0)
2603 wpa_config_update_prio_list(wpa_s
->conf
);
2609 static int wpa_supplicant_ctrl_iface_set_network(
2610 struct wpa_supplicant
*wpa_s
, char *cmd
)
2612 int id
, ret
, prev_bssid_set
;
2613 struct wpa_ssid
*ssid
;
2615 u8 prev_bssid
[ETH_ALEN
];
2617 /* cmd: "<network id> <variable name> <value>" */
2618 name
= os_strchr(cmd
, ' ');
2623 value
= os_strchr(name
, ' ');
2629 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2631 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2632 (u8
*) value
, os_strlen(value
));
2634 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2636 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2641 prev_bssid_set
= ssid
->bssid_set
;
2642 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
2643 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
2646 (ssid
->bssid_set
!= prev_bssid_set
||
2647 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
2648 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
2653 static int wpa_supplicant_ctrl_iface_get_network(
2654 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2658 struct wpa_ssid
*ssid
;
2661 /* cmd: "<network id> <variable name>" */
2662 name
= os_strchr(cmd
, ' ');
2663 if (name
== NULL
|| buflen
== 0)
2668 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2671 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2673 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2678 value
= wpa_config_get_no_key(ssid
, name
);
2679 if (value
== NULL
) {
2680 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2681 "variable '%s'", name
);
2685 res
= os_strlcpy(buf
, value
, buflen
);
2686 if (res
>= buflen
) {
2697 static int wpa_supplicant_ctrl_iface_dup_network(
2698 struct wpa_supplicant
*wpa_s
, char *cmd
)
2700 struct wpa_ssid
*ssid_s
, *ssid_d
;
2701 char *name
, *id
, *value
;
2702 int id_s
, id_d
, ret
;
2704 /* cmd: "<src network id> <dst network id> <variable name>" */
2705 id
= os_strchr(cmd
, ' ');
2710 name
= os_strchr(id
, ' ');
2717 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2720 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
2721 if (ssid_s
== NULL
) {
2722 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2723 "network id=%d", id_s
);
2727 ssid_d
= wpa_config_get_network(wpa_s
->conf
, id_d
);
2728 if (ssid_d
== NULL
) {
2729 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2730 "network id=%d", id_s
);
2734 value
= wpa_config_get(ssid_s
, name
);
2735 if (value
== NULL
) {
2736 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2737 "variable '%s'", name
);
2741 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid_d
, name
,
2750 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2751 char *buf
, size_t buflen
)
2754 struct wpa_cred
*cred
;
2759 ret
= os_snprintf(pos
, end
- pos
,
2760 "cred id / realm / username / domain / imsi\n");
2761 if (ret
< 0 || ret
>= end
- pos
)
2765 cred
= wpa_s
->conf
->cred
;
2767 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2768 cred
->id
, cred
->realm
? cred
->realm
: "",
2769 cred
->username
? cred
->username
: "",
2770 cred
->domain
? cred
->domain
[0] : "",
2771 cred
->imsi
? cred
->imsi
: "");
2772 if (ret
< 0 || ret
>= end
- pos
)
2783 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2784 char *buf
, size_t buflen
)
2786 struct wpa_cred
*cred
;
2789 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2791 cred
= wpa_config_add_cred(wpa_s
->conf
);
2795 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
2797 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2798 if (ret
< 0 || (size_t) ret
>= buflen
)
2804 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
2805 struct wpa_cred
*cred
)
2807 struct wpa_ssid
*ssid
;
2812 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2817 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
2818 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2822 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
2824 /* Remove any network entry created based on the removed credential */
2825 ssid
= wpa_s
->conf
->ssid
;
2827 if (ssid
->parent_cred
== cred
) {
2828 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
2829 "used the removed credential", ssid
->id
);
2830 os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
2832 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
2841 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
2845 struct wpa_cred
*cred
, *prev
;
2847 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2848 * "provisioning_sp=<FQDN> */
2849 if (os_strcmp(cmd
, "all") == 0) {
2850 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
2851 cred
= wpa_s
->conf
->cred
;
2855 wpas_ctrl_remove_cred(wpa_s
, prev
);
2860 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
2861 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2863 cred
= wpa_s
->conf
->cred
;
2869 for (i
= 0; i
< prev
->num_domain
; i
++) {
2870 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
2873 wpas_ctrl_remove_cred(wpa_s
, prev
);
2881 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
2882 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2884 cred
= wpa_s
->conf
->cred
;
2888 if (prev
->provisioning_sp
&&
2889 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
2890 wpas_ctrl_remove_cred(wpa_s
, prev
);
2896 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
2898 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2899 return wpas_ctrl_remove_cred(wpa_s
, cred
);
2903 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
2907 struct wpa_cred
*cred
;
2910 /* cmd: "<cred id> <variable name> <value>" */
2911 name
= os_strchr(cmd
, ' ');
2916 value
= os_strchr(name
, ' ');
2922 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2924 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2925 (u8
*) value
, os_strlen(value
));
2927 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2929 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2934 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
2935 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
2936 "variable '%s'", name
);
2940 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
2946 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
2947 char *cmd
, char *buf
,
2952 struct wpa_cred
*cred
;
2955 /* cmd: "<cred id> <variable name>" */
2956 name
= os_strchr(cmd
, ' ');
2962 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2965 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2967 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2972 value
= wpa_config_get_cred_no_key(cred
, name
);
2973 if (value
== NULL
) {
2974 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
2979 res
= os_strlcpy(buf
, value
, buflen
);
2980 if (res
>= buflen
) {
2991 #ifndef CONFIG_NO_CONFIG_WRITE
2992 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
2996 if (!wpa_s
->conf
->update_config
) {
2997 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2998 "to update configuration (update_config=0)");
3002 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3004 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3005 "update configuration");
3007 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3013 #endif /* CONFIG_NO_CONFIG_WRITE */
3016 struct cipher_info
{
3022 static const struct cipher_info ciphers
[] = {
3023 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3024 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3025 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3026 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3027 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3028 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3029 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3030 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3034 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3035 struct wpa_driver_capa
*capa
,
3036 char *buf
, size_t buflen
)
3049 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3055 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3056 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3057 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3058 pos
== buf
? "" : " ",
3060 if (ret
< 0 || ret
>= end
- pos
)
3070 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3071 struct wpa_driver_capa
*capa
,
3072 char *buf
, size_t buflen
)
3085 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3091 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3092 if (capa
->enc
& ciphers
[i
].capa
) {
3093 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3094 pos
== buf
? "" : " ",
3096 if (ret
< 0 || ret
>= end
- pos
)
3106 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3107 struct wpa_driver_capa
*capa
,
3108 char *buf
, size_t buflen
)
3120 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3127 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3128 if (ret
< 0 || ret
>= end
- pos
)
3132 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3133 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3134 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3135 if (ret
< 0 || ret
>= end
- pos
)
3140 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3141 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3142 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3143 if (ret
< 0 || ret
>= end
- pos
)
3148 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3149 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3150 if (ret
< 0 || ret
>= end
- pos
)
3159 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3160 struct wpa_driver_capa
*capa
,
3161 char *buf
, size_t buflen
)
3173 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3179 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3180 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3181 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3182 pos
== buf
? "" : " ");
3183 if (ret
< 0 || ret
>= end
- pos
)
3188 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3189 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3190 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3191 pos
== buf
? "" : " ");
3192 if (ret
< 0 || ret
>= end
- pos
)
3201 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
3202 struct wpa_driver_capa
*capa
,
3203 char *buf
, size_t buflen
)
3215 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3221 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3222 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3223 pos
== buf
? "" : " ");
3224 if (ret
< 0 || ret
>= end
- pos
)
3229 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3230 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3231 pos
== buf
? "" : " ");
3232 if (ret
< 0 || ret
>= end
- pos
)
3237 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3238 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3239 pos
== buf
? "" : " ");
3240 if (ret
< 0 || ret
>= end
- pos
)
3249 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3250 struct wpa_driver_capa
*capa
,
3251 char *buf
, size_t buflen
)
3263 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3269 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3270 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3271 pos
== buf
? "" : " ");
3272 if (ret
< 0 || ret
>= end
- pos
)
3277 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3278 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3279 pos
== buf
? "" : " ");
3280 if (ret
< 0 || ret
>= end
- pos
)
3289 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3290 char *buf
, size_t buflen
)
3292 struct hostapd_channel_data
*chnl
;
3294 char *pos
, *end
, *hmode
;
3299 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3300 switch (wpa_s
->hw
.modes
[j
].mode
) {
3301 case HOSTAPD_MODE_IEEE80211B
:
3304 case HOSTAPD_MODE_IEEE80211G
:
3307 case HOSTAPD_MODE_IEEE80211A
:
3310 case HOSTAPD_MODE_IEEE80211AD
:
3316 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3317 if (ret
< 0 || ret
>= end
- pos
)
3320 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3321 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3322 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3324 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3325 if (ret
< 0 || ret
>= end
- pos
)
3329 ret
= os_snprintf(pos
, end
- pos
, "\n");
3330 if (ret
< 0 || ret
>= end
- pos
)
3339 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3340 char *buf
, size_t buflen
)
3342 struct hostapd_channel_data
*chnl
;
3344 char *pos
, *end
, *hmode
;
3349 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3350 switch (wpa_s
->hw
.modes
[j
].mode
) {
3351 case HOSTAPD_MODE_IEEE80211B
:
3354 case HOSTAPD_MODE_IEEE80211G
:
3357 case HOSTAPD_MODE_IEEE80211A
:
3360 case HOSTAPD_MODE_IEEE80211AD
:
3366 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3368 if (ret
< 0 || ret
>= end
- pos
)
3371 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3372 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3373 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3375 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
3376 chnl
[i
].chan
, chnl
[i
].freq
,
3377 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IBSS
?
3379 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
3382 if (ret
< 0 || ret
>= end
- pos
)
3386 ret
= os_snprintf(pos
, end
- pos
, "\n");
3387 if (ret
< 0 || ret
>= end
- pos
)
3396 static int wpa_supplicant_ctrl_iface_get_capability(
3397 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3400 struct wpa_driver_capa capa
;
3406 /* Determine whether or not strict checking was requested */
3407 len
= os_strlcpy(field
, _field
, sizeof(field
));
3408 if (len
>= sizeof(field
))
3410 strict
= os_strchr(field
, ' ');
3411 if (strict
!= NULL
) {
3413 if (os_strcmp(strict
, "strict") != 0)
3417 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3418 field
, strict
? strict
: "");
3420 if (os_strcmp(field
, "eap") == 0) {
3421 return eap_get_names(buf
, buflen
);
3424 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3426 if (os_strcmp(field
, "pairwise") == 0)
3427 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3430 if (os_strcmp(field
, "group") == 0)
3431 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3434 if (os_strcmp(field
, "key_mgmt") == 0)
3435 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3438 if (os_strcmp(field
, "proto") == 0)
3439 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3442 if (os_strcmp(field
, "auth_alg") == 0)
3443 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3446 if (os_strcmp(field
, "modes") == 0)
3447 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3450 if (os_strcmp(field
, "channels") == 0)
3451 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3453 if (os_strcmp(field
, "freq") == 0)
3454 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3457 if (os_strcmp(field
, "tdls") == 0)
3458 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
3459 #endif /* CONFIG_TDLS */
3461 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3468 #ifdef CONFIG_INTERWORKING
3469 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3470 struct wpabuf
*data
)
3480 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3481 if (ret
< 0 || ret
>= end
- pos
)
3485 d
= wpabuf_head_u8(data
);
3486 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3487 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3488 if (ret
< 0 || ret
>= end
- pos
)
3493 ret
= os_snprintf(pos
, end
- pos
, "\n");
3494 if (ret
< 0 || ret
>= end
- pos
)
3500 #endif /* CONFIG_INTERWORKING */
3503 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3504 unsigned long mask
, char *buf
, size_t buflen
)
3514 if (mask
& WPA_BSS_MASK_ID
) {
3515 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3516 if (ret
< 0 || ret
>= end
- pos
)
3521 if (mask
& WPA_BSS_MASK_BSSID
) {
3522 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3523 MAC2STR(bss
->bssid
));
3524 if (ret
< 0 || ret
>= end
- pos
)
3529 if (mask
& WPA_BSS_MASK_FREQ
) {
3530 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3531 if (ret
< 0 || ret
>= end
- pos
)
3536 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3537 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3539 if (ret
< 0 || ret
>= end
- pos
)
3544 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3545 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3547 if (ret
< 0 || ret
>= end
- pos
)
3552 if (mask
& WPA_BSS_MASK_QUAL
) {
3553 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3554 if (ret
< 0 || ret
>= end
- pos
)
3559 if (mask
& WPA_BSS_MASK_NOISE
) {
3560 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3561 if (ret
< 0 || ret
>= end
- pos
)
3566 if (mask
& WPA_BSS_MASK_LEVEL
) {
3567 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3568 if (ret
< 0 || ret
>= end
- pos
)
3573 if (mask
& WPA_BSS_MASK_TSF
) {
3574 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3575 (unsigned long long) bss
->tsf
);
3576 if (ret
< 0 || ret
>= end
- pos
)
3581 if (mask
& WPA_BSS_MASK_AGE
) {
3582 struct os_reltime now
;
3584 os_get_reltime(&now
);
3585 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3586 (int) (now
.sec
- bss
->last_update
.sec
));
3587 if (ret
< 0 || ret
>= end
- pos
)
3592 if (mask
& WPA_BSS_MASK_IE
) {
3593 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3594 if (ret
< 0 || ret
>= end
- pos
)
3598 ie
= (const u8
*) (bss
+ 1);
3599 for (i
= 0; i
< bss
->ie_len
; i
++) {
3600 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3601 if (ret
< 0 || ret
>= end
- pos
)
3606 ret
= os_snprintf(pos
, end
- pos
, "\n");
3607 if (ret
< 0 || ret
>= end
- pos
)
3612 if (mask
& WPA_BSS_MASK_FLAGS
) {
3613 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3614 if (ret
< 0 || ret
>= end
- pos
)
3618 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3620 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3622 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3624 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3626 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3627 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3628 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3629 if (ret
< 0 || ret
>= end
- pos
)
3633 if (bss_is_dmg(bss
)) {
3635 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
3636 if (ret
< 0 || ret
>= end
- pos
)
3639 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
3640 case IEEE80211_CAP_DMG_IBSS
:
3643 case IEEE80211_CAP_DMG_AP
:
3646 case IEEE80211_CAP_DMG_PBSS
:
3653 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
3654 if (ret
< 0 || ret
>= end
- pos
)
3658 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3659 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3660 if (ret
< 0 || ret
>= end
- pos
)
3664 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3665 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3666 if (ret
< 0 || ret
>= end
- pos
)
3671 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3672 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3673 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3674 if (ret
< 0 || ret
>= end
- pos
)
3679 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3680 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3681 if (ret
< 0 || ret
>= end
- pos
)
3685 #endif /* CONFIG_HS20 */
3687 ret
= os_snprintf(pos
, end
- pos
, "\n");
3688 if (ret
< 0 || ret
>= end
- pos
)
3693 if (mask
& WPA_BSS_MASK_SSID
) {
3694 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3695 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3696 if (ret
< 0 || ret
>= end
- pos
)
3702 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3703 ie
= (const u8
*) (bss
+ 1);
3704 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3705 if (ret
< 0 || ret
>= end
- pos
)
3709 #endif /* CONFIG_WPS */
3712 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3713 ie
= (const u8
*) (bss
+ 1);
3714 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3715 if (ret
< 0 || ret
>= end
- pos
)
3719 #endif /* CONFIG_P2P */
3721 #ifdef CONFIG_WIFI_DISPLAY
3722 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3724 ie
= (const u8
*) (bss
+ 1);
3725 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3726 WFD_IE_VENDOR_TYPE
);
3728 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3729 if (ret
< 0 || ret
>= end
- pos
) {
3735 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3740 ret
= os_snprintf(pos
, end
- pos
, "\n");
3741 if (ret
< 0 || ret
>= end
- pos
)
3746 #endif /* CONFIG_WIFI_DISPLAY */
3748 #ifdef CONFIG_INTERWORKING
3749 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3750 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3751 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3753 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3754 anqp
->network_auth_type
);
3755 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3756 anqp
->roaming_consortium
);
3757 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3758 anqp
->ip_addr_type_availability
);
3759 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3761 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3762 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3765 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3766 anqp
->hs20_operator_friendly_name
);
3767 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3768 anqp
->hs20_wan_metrics
);
3769 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3770 anqp
->hs20_connection_capability
);
3771 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
3772 anqp
->hs20_operating_class
);
3773 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
3774 anqp
->hs20_osu_providers_list
);
3775 #endif /* CONFIG_HS20 */
3777 #endif /* CONFIG_INTERWORKING */
3779 if (mask
& WPA_BSS_MASK_DELIM
) {
3780 ret
= os_snprintf(pos
, end
- pos
, "====\n");
3781 if (ret
< 0 || ret
>= end
- pos
)
3790 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
3791 const char *cmd
, char *buf
,
3796 struct wpa_bss
*bss
;
3797 struct wpa_bss
*bsslast
= NULL
;
3798 struct dl_list
*next
;
3802 unsigned long mask
= WPA_BSS_MASK_ALL
;
3804 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
3805 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
3806 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
3808 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
3810 } else { /* N1-N2 */
3811 unsigned int id1
, id2
;
3813 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
3814 wpa_printf(MSG_INFO
, "Wrong BSS range "
3819 if (*(cmd
+ 6) == '-')
3822 id1
= atoi(cmd
+ 6);
3824 if (*ctmp
>= '0' && *ctmp
<= '9')
3827 id2
= (unsigned int) -1;
3828 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
3829 if (id2
== (unsigned int) -1)
3830 bsslast
= dl_list_last(&wpa_s
->bss_id
,
3834 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
3835 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
3836 struct wpa_bss
*tmp
= bss
;
3838 next
= tmp
->list_id
.next
;
3839 if (next
== &wpa_s
->bss_id
)
3841 tmp
= dl_list_entry(
3842 next
, struct wpa_bss
,
3851 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
3852 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3853 else if (os_strncmp(cmd
, "LAST", 4) == 0)
3854 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3855 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
3857 bss
= wpa_bss_get_id(wpa_s
, i
);
3858 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3860 bss
= wpa_bss_get_id(wpa_s
, i
);
3862 next
= bss
->list_id
.next
;
3863 if (next
== &wpa_s
->bss_id
)
3866 bss
= dl_list_entry(next
, struct wpa_bss
,
3870 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
3871 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
3872 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
3875 #endif /* CONFIG_P2P */
3876 } else if (hwaddr_aton(cmd
, bssid
) == 0)
3877 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3879 struct wpa_bss
*tmp
;
3882 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
3891 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
3892 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
3894 mask
= WPA_BSS_MASK_ALL
;
3900 if (bsslast
== NULL
)
3903 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
3907 if (bss
== bsslast
) {
3908 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
3909 (bss
== dl_list_last(&wpa_s
->bss_id
,
3910 struct wpa_bss
, list_id
)))
3911 os_snprintf(buf
- 5, 5, "####\n");
3914 next
= bss
->list_id
.next
;
3915 if (next
== &wpa_s
->bss_id
)
3917 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
3918 } while (bss
&& len
);
3924 static int wpa_supplicant_ctrl_iface_ap_scan(
3925 struct wpa_supplicant
*wpa_s
, char *cmd
)
3927 int ap_scan
= atoi(cmd
);
3928 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
3932 static int wpa_supplicant_ctrl_iface_scan_interval(
3933 struct wpa_supplicant
*wpa_s
, char *cmd
)
3935 int scan_int
= atoi(cmd
);
3936 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
3940 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3941 struct wpa_supplicant
*wpa_s
, char *cmd
)
3943 int expire_age
= atoi(cmd
);
3944 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
3948 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3949 struct wpa_supplicant
*wpa_s
, char *cmd
)
3951 int expire_count
= atoi(cmd
);
3952 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
3956 static int wpa_supplicant_ctrl_iface_bss_flush(
3957 struct wpa_supplicant
*wpa_s
, char *cmd
)
3959 int flush_age
= atoi(cmd
);
3962 wpa_bss_flush(wpa_s
);
3964 wpa_bss_flush_by_age(wpa_s
, flush_age
);
3969 #ifdef CONFIG_TESTING_OPTIONS
3970 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
3972 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
3973 /* MLME-DELETEKEYS.request */
3974 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
3975 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
3976 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
3977 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
3978 #ifdef CONFIG_IEEE80211W
3979 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
3980 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
3981 #endif /* CONFIG_IEEE80211W */
3983 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
3985 /* MLME-SETPROTECTION.request(None) */
3986 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
3987 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
3988 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
3989 wpa_sm_drop_sa(wpa_s
->wpa
);
3991 #endif /* CONFIG_TESTING_OPTIONS */
3994 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
3997 #ifdef CONFIG_NO_SCAN_PROCESSING
3999 #else /* CONFIG_NO_SCAN_PROCESSING */
4001 struct wpa_bss
*bss
;
4002 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4004 if (hwaddr_aton(addr
, bssid
)) {
4005 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4006 "address '%s'", addr
);
4010 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4013 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4014 "configuration known for the target AP");
4018 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4020 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4026 * TODO: Find best network configuration block from configuration to
4027 * allow roaming to other networks
4030 wpa_s
->reassociate
= 1;
4031 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4034 #endif /* CONFIG_NO_SCAN_PROCESSING */
4039 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
4041 unsigned int timeout
= atoi(cmd
);
4042 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
4043 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
4044 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
4046 unsigned int search_delay
;
4048 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4049 wpa_dbg(wpa_s
, MSG_INFO
,
4050 "Reject P2P_FIND since interface is disabled");
4053 if (os_strstr(cmd
, "type=social"))
4054 type
= P2P_FIND_ONLY_SOCIAL
;
4055 else if (os_strstr(cmd
, "type=progressive"))
4056 type
= P2P_FIND_PROGRESSIVE
;
4058 pos
= os_strstr(cmd
, "dev_id=");
4061 if (hwaddr_aton(pos
, dev_id
))
4066 pos
= os_strstr(cmd
, "dev_type=");
4069 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
4071 _dev_type
= dev_type
;
4074 pos
= os_strstr(cmd
, "delay=");
4077 search_delay
= atoi(pos
);
4079 search_delay
= wpas_p2p_search_delay(wpa_s
);
4081 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
4082 _dev_id
, search_delay
);
4086 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
4087 char *buf
, size_t buflen
)
4092 enum p2p_wps_method wps_method
;
4095 int persistent_group
, persistent_id
= -1;
4104 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4105 * [persistent|persistent=<network id>]
4106 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4109 if (hwaddr_aton(cmd
, addr
))
4117 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
4118 pos2
= os_strstr(pos
, " persistent=");
4120 struct wpa_ssid
*ssid
;
4121 persistent_id
= atoi(pos2
+ 12);
4122 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
4123 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
4124 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
4125 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
4126 "SSID id=%d for persistent P2P group (GO)",
4131 join
= os_strstr(pos
, " join") != NULL
;
4132 auth
= os_strstr(pos
, " auth") != NULL
;
4133 automatic
= os_strstr(pos
, " auto") != NULL
;
4134 pd
= os_strstr(pos
, " provdisc") != NULL
;
4135 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4136 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4139 pos2
= os_strstr(pos
, " go_intent=");
4142 go_intent
= atoi(pos2
);
4143 if (go_intent
< 0 || go_intent
> 15)
4147 pos2
= os_strstr(pos
, " freq=");
4155 if (os_strncmp(pos
, "pin", 3) == 0) {
4156 /* Request random PIN (to be displayed) and enable the PIN */
4157 wps_method
= WPS_PIN_DISPLAY
;
4158 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
4159 wps_method
= WPS_PBC
;
4162 pos
= os_strchr(pin
, ' ');
4163 wps_method
= WPS_PIN_KEYPAD
;
4166 if (os_strncmp(pos
, "display", 7) == 0)
4167 wps_method
= WPS_PIN_DISPLAY
;
4169 if (!wps_pin_str_valid(pin
)) {
4170 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
4175 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
4176 persistent_group
, automatic
, join
,
4177 auth
, go_intent
, freq
, persistent_id
, pd
,
4179 if (new_pin
== -2) {
4180 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4183 if (new_pin
== -3) {
4184 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4189 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
4190 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
4191 if (ret
< 0 || (size_t) ret
>= buflen
)
4196 os_memcpy(buf
, "OK\n", 3);
4201 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4203 unsigned int timeout
= atoi(cmd
);
4204 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4205 wpa_dbg(wpa_s
, MSG_INFO
,
4206 "Reject P2P_LISTEN since interface is disabled");
4209 return wpas_p2p_listen(wpa_s
, timeout
);
4213 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
4217 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
4219 /* <addr> <config method> [join|auto] */
4221 if (hwaddr_aton(cmd
, addr
))
4229 if (os_strstr(pos
, " join") != NULL
)
4230 use
= WPAS_P2P_PD_FOR_JOIN
;
4231 else if (os_strstr(pos
, " auto") != NULL
)
4232 use
= WPAS_P2P_PD_AUTO
;
4234 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
4238 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
4241 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4243 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
4244 ssid
->passphrase
== NULL
)
4247 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
4248 return os_strlen(buf
);
4252 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
4253 char *buf
, size_t buflen
)
4257 u8 dst_buf
[ETH_ALEN
], *dst
;
4258 struct wpabuf
*tlvs
;
4262 if (hwaddr_aton(cmd
, dst_buf
))
4265 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
4266 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
4273 if (os_strncmp(pos
, "upnp ", 5) == 0) {
4276 if (hexstr2bin(pos
, &version
, 1) < 0)
4282 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
4283 #ifdef CONFIG_WIFI_DISPLAY
4284 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
4285 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
4286 #endif /* CONFIG_WIFI_DISPLAY */
4288 len
= os_strlen(pos
);
4292 tlvs
= wpabuf_alloc(len
);
4295 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
4300 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
4305 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
4306 if (res
< 0 || (unsigned) res
>= buflen
)
4312 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
4315 long long unsigned val
;
4317 if (sscanf(cmd
, "%llx", &val
) != 1)
4320 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
4324 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4329 struct wpabuf
*resp_tlvs
;
4333 pos
= os_strchr(cmd
, ' ');
4341 if (hwaddr_aton(pos
, dst
))
4348 pos2
= os_strchr(pos
, ' ');
4352 dialog_token
= atoi(pos
);
4354 len
= os_strlen(pos2
);
4358 resp_tlvs
= wpabuf_alloc(len
);
4359 if (resp_tlvs
== NULL
)
4361 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
4362 wpabuf_free(resp_tlvs
);
4366 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
4367 wpabuf_free(resp_tlvs
);
4372 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
4375 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
4377 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
4382 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
4387 struct wpabuf
*query
, *resp
;
4389 pos
= os_strchr(cmd
, ' ');
4394 len
= os_strlen(cmd
);
4398 query
= wpabuf_alloc(len
);
4401 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4406 len
= os_strlen(pos
);
4412 resp
= wpabuf_alloc(len
);
4417 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4423 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4432 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4437 pos
= os_strchr(cmd
, ' ');
4442 if (hexstr2bin(cmd
, &version
, 1) < 0)
4445 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4449 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4453 pos
= os_strchr(cmd
, ' ');
4458 if (os_strcmp(cmd
, "bonjour") == 0)
4459 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4460 if (os_strcmp(cmd
, "upnp") == 0)
4461 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4462 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4467 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4471 struct wpabuf
*query
;
4474 len
= os_strlen(cmd
);
4478 query
= wpabuf_alloc(len
);
4481 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4486 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4492 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4497 pos
= os_strchr(cmd
, ' ');
4502 if (hexstr2bin(cmd
, &version
, 1) < 0)
4505 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4509 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4513 pos
= os_strchr(cmd
, ' ');
4518 if (os_strcmp(cmd
, "bonjour") == 0)
4519 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4520 if (os_strcmp(cmd
, "upnp") == 0)
4521 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4522 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4527 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4533 if (hwaddr_aton(cmd
, addr
))
4536 return wpas_p2p_reject(wpa_s
, addr
);
4540 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4544 struct wpa_ssid
*ssid
;
4545 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4546 int freq
= 0, pref_freq
= 0;
4550 pos
= os_strstr(cmd
, " peer=");
4553 if (hwaddr_aton(pos
, peer
))
4557 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4558 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4559 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4560 "for persistent P2P group",
4565 pos
= os_strstr(cmd
, " freq=");
4573 pos
= os_strstr(cmd
, " pref=");
4576 pref_freq
= atoi(pos
);
4581 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4582 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4585 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4590 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4593 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4595 pos
= os_strstr(cmd
, " peer=");
4601 if (hwaddr_aton(pos
, peer
)) {
4602 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4606 pos
= os_strstr(pos
, " go_dev_addr=");
4609 if (hwaddr_aton(pos
, go_dev_addr
)) {
4610 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4614 go_dev
= go_dev_addr
;
4617 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4621 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4623 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4624 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4625 if (os_strncmp(cmd
, "group=", 6) == 0)
4626 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4632 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4633 char *cmd
, int freq
, int ht40
,
4637 struct wpa_ssid
*ssid
;
4640 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4641 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4642 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4643 "for persistent P2P group",
4648 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, 0, ht40
, vht
,
4653 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4655 int freq
= 0, ht40
, vht
;
4658 pos
= os_strstr(cmd
, "freq=");
4660 freq
= atoi(pos
+ 5);
4662 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4663 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4666 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4667 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4669 if (os_strcmp(cmd
, "persistent") == 0 ||
4670 os_strncmp(cmd
, "persistent ", 11) == 0)
4671 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4672 if (os_strncmp(cmd
, "freq=", 5) == 0)
4673 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4675 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4677 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4683 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4684 char *buf
, size_t buflen
)
4686 u8 addr
[ETH_ALEN
], *addr_ptr
;
4688 const struct p2p_peer_info
*info
;
4690 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4691 struct wpa_ssid
*ssid
;
4694 if (!wpa_s
->global
->p2p
)
4697 if (os_strcmp(cmd
, "FIRST") == 0) {
4700 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4701 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4706 if (hwaddr_aton(cmd
, addr
) < 0)
4712 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4719 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4725 "serial_number=%s\n"
4726 "config_methods=0x%x\n"
4728 "group_capab=0x%x\n"
4730 MAC2STR(info
->p2p_device_addr
),
4731 wps_dev_type_bin2str(info
->pri_dev_type
,
4732 devtype
, sizeof(devtype
)),
4737 info
->serial_number
,
4738 info
->config_methods
,
4742 if (res
< 0 || res
>= end
- pos
)
4746 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4749 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4750 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4751 wps_dev_type_bin2str(t
, devtype
,
4753 if (res
< 0 || res
>= end
- pos
)
4758 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4760 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4761 if (res
< 0 || res
>= end
- pos
)
4766 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4771 if (info
->vendor_elems
) {
4772 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
4773 if (res
< 0 || res
>= end
- pos
)
4777 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4778 wpabuf_head(info
->vendor_elems
),
4779 wpabuf_len(info
->vendor_elems
));
4781 res
= os_snprintf(pos
, end
- pos
, "\n");
4782 if (res
< 0 || res
>= end
- pos
)
4791 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
4796 if (wpa_s
->global
->p2p
== NULL
)
4799 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
4802 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
4803 struct wpa_freq_range
*freq
;
4804 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
4805 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
4806 freq
->min
, freq
->max
);
4809 wpas_p2p_update_channel_list(wpa_s
);
4814 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
4818 if (wpa_s
->global
->p2p
== NULL
)
4821 param
= os_strchr(cmd
, ' ');
4826 if (os_strcmp(cmd
, "discoverability") == 0) {
4827 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
4832 if (os_strcmp(cmd
, "managed") == 0) {
4833 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
4837 if (os_strcmp(cmd
, "listen_channel") == 0) {
4838 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
4842 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
4843 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
4847 if (os_strcmp(cmd
, "noa") == 0) {
4849 int count
, start
, duration
;
4850 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4851 count
= atoi(param
);
4852 pos
= os_strchr(param
, ',');
4857 pos
= os_strchr(pos
, ',');
4861 duration
= atoi(pos
);
4862 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
4864 if (count
== 0 && duration
> 0)
4866 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4867 "start=%d duration=%d", count
, start
, duration
);
4868 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
4871 if (os_strcmp(cmd
, "ps") == 0)
4872 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
4874 if (os_strcmp(cmd
, "oppps") == 0)
4875 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
4877 if (os_strcmp(cmd
, "ctwindow") == 0)
4878 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
4880 if (os_strcmp(cmd
, "disabled") == 0) {
4881 wpa_s
->global
->p2p_disabled
= atoi(param
);
4882 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
4883 wpa_s
->global
->p2p_disabled
?
4884 "disabled" : "enabled");
4885 if (wpa_s
->global
->p2p_disabled
) {
4886 wpas_p2p_stop_find(wpa_s
);
4887 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4888 p2p_flush(wpa_s
->global
->p2p
);
4893 if (os_strcmp(cmd
, "conc_pref") == 0) {
4894 if (os_strcmp(param
, "sta") == 0)
4895 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
4896 else if (os_strcmp(param
, "p2p") == 0)
4897 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
4899 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
4902 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
4907 if (os_strcmp(cmd
, "force_long_sd") == 0) {
4908 wpa_s
->force_long_sd
= atoi(param
);
4912 if (os_strcmp(cmd
, "peer_filter") == 0) {
4914 if (hwaddr_aton(param
, addr
))
4916 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
4920 if (os_strcmp(cmd
, "cross_connect") == 0)
4921 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
4923 if (os_strcmp(cmd
, "go_apsd") == 0) {
4924 if (os_strcmp(param
, "disable") == 0)
4925 wpa_s
->set_ap_uapsd
= 0;
4927 wpa_s
->set_ap_uapsd
= 1;
4928 wpa_s
->ap_uapsd
= atoi(param
);
4933 if (os_strcmp(cmd
, "client_apsd") == 0) {
4934 if (os_strcmp(param
, "disable") == 0)
4935 wpa_s
->set_sta_uapsd
= 0;
4939 /* format: BE,BK,VI,VO;max SP Length */
4941 pos
= os_strchr(param
, ',');
4946 pos
= os_strchr(pos
, ',');
4951 pos
= os_strchr(pos
, ',');
4956 /* ignore max SP Length for now */
4958 wpa_s
->set_sta_uapsd
= 1;
4959 wpa_s
->sta_uapsd
= 0;
4961 wpa_s
->sta_uapsd
|= BIT(0);
4963 wpa_s
->sta_uapsd
|= BIT(1);
4965 wpa_s
->sta_uapsd
|= BIT(2);
4967 wpa_s
->sta_uapsd
|= BIT(3);
4972 if (os_strcmp(cmd
, "disallow_freq") == 0)
4973 return p2p_ctrl_disallow_freq(wpa_s
, param
);
4975 if (os_strcmp(cmd
, "disc_int") == 0) {
4976 int min_disc_int
, max_disc_int
, max_disc_tu
;
4981 min_disc_int
= atoi(pos
);
4982 pos
= os_strchr(pos
, ' ');
4987 max_disc_int
= atoi(pos
);
4988 pos
= os_strchr(pos
, ' ');
4993 max_disc_tu
= atoi(pos
);
4995 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
4996 max_disc_int
, max_disc_tu
);
4999 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
5000 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
5004 #ifdef CONFIG_WPS_NFC
5005 if (os_strcmp(cmd
, "nfc_tag") == 0)
5006 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
5007 #endif /* CONFIG_WPS_NFC */
5009 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
5010 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
5014 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5021 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
5023 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5024 wpa_s
->force_long_sd
= 0;
5025 if (wpa_s
->global
->p2p
)
5026 p2p_flush(wpa_s
->global
->p2p
);
5030 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
5033 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
5036 pos
= os_strchr(cmd
, ' ');
5042 pos2
= os_strchr(pos
, ' ');
5050 pos
= os_strchr(pos2
, ' ');
5058 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
5062 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5065 unsigned int period
= 0, interval
= 0;
5068 pos
= os_strchr(cmd
, ' ');
5073 interval
= atoi(pos
);
5076 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
5080 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
5087 if (os_strncmp(pos
, "iface=", 6) == 0) {
5091 if (hwaddr_aton(pos
, peer
))
5094 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
5098 #endif /* CONFIG_P2P */
5101 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
5103 struct wpa_freq_range_list ranges
;
5105 struct hostapd_hw_modes
*mode
;
5108 if (wpa_s
->hw
.modes
== NULL
)
5111 os_memset(&ranges
, 0, sizeof(ranges
));
5112 if (freq_range_list_parse(&ranges
, val
) < 0)
5115 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
5118 mode
= &wpa_s
->hw
.modes
[i
];
5119 for (j
= 0; j
< mode
->num_channels
; j
++) {
5122 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
5125 freq
= mode
->channels
[j
].freq
;
5126 if (!freq_range_list_includes(&ranges
, freq
))
5129 int_array_add_unique(&freqs
, freq
);
5133 os_free(ranges
.range
);
5138 #ifdef CONFIG_INTERWORKING
5140 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
5148 auto_sel
= os_strstr(param
, "auto") != NULL
;
5150 pos
= os_strstr(param
, "freq=");
5152 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
5159 return interworking_select(wpa_s
, auto_sel
, freqs
);
5163 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
5166 struct wpa_bss
*bss
;
5168 if (hwaddr_aton(dst
, bssid
)) {
5169 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
5173 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
5175 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
5180 return interworking_connect(wpa_s
, bss
);
5184 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5186 u8 dst_addr
[ETH_ALEN
];
5189 #define MAX_ANQP_INFO_ID 100
5190 u16 id
[MAX_ANQP_INFO_ID
];
5194 used
= hwaddr_aton2(dst
, dst_addr
);
5198 while (num_id
< MAX_ANQP_INFO_ID
) {
5199 if (os_strncmp(pos
, "hs20:", 5) == 0) {
5201 int num
= atoi(pos
+ 5);
5202 if (num
<= 0 || num
> 31)
5204 subtypes
|= BIT(num
);
5205 #else /* CONFIG_HS20 */
5207 #endif /* CONFIG_HS20 */
5209 id
[num_id
] = atoi(pos
);
5213 pos
= os_strchr(pos
+ 1, ',');
5222 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
);
5226 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5228 u8 dst_addr
[ETH_ALEN
];
5229 struct wpabuf
*advproto
, *query
= NULL
;
5234 used
= hwaddr_aton2(cmd
, dst_addr
);
5242 /* Advertisement Protocol ID */
5243 end
= os_strchr(pos
, ' ');
5247 len
= os_strlen(pos
);
5253 advproto
= wpabuf_alloc(len
);
5254 if (advproto
== NULL
)
5256 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
5260 /* Optional Query Request */
5265 len
= os_strlen(pos
);
5272 query
= wpabuf_alloc(len
);
5275 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
5280 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
5283 wpabuf_free(advproto
);
5290 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
5297 size_t resp_len
, start
, requested_len
;
5298 struct wpabuf
*resp
;
5301 used
= hwaddr_aton2(cmd
, addr
);
5308 dialog_token
= atoi(pos
);
5310 if (wpa_s
->last_gas_resp
&&
5311 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
5312 dialog_token
== wpa_s
->last_gas_dialog_token
)
5313 resp
= wpa_s
->last_gas_resp
;
5314 else if (wpa_s
->prev_gas_resp
&&
5315 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
5316 dialog_token
== wpa_s
->prev_gas_dialog_token
)
5317 resp
= wpa_s
->prev_gas_resp
;
5321 resp_len
= wpabuf_len(resp
);
5323 requested_len
= resp_len
;
5325 pos
= os_strchr(pos
, ' ');
5328 if (start
> resp_len
)
5329 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5330 pos
= os_strchr(pos
, ',');
5334 requested_len
= atoi(pos
);
5335 if (start
+ requested_len
> resp_len
)
5336 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5339 if (requested_len
* 2 + 1 > buflen
)
5340 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
5342 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
5345 if (start
+ requested_len
== resp_len
) {
5347 * Free memory by dropping the response after it has been
5350 if (resp
== wpa_s
->prev_gas_resp
) {
5351 wpabuf_free(wpa_s
->prev_gas_resp
);
5352 wpa_s
->prev_gas_resp
= NULL
;
5354 wpabuf_free(wpa_s
->last_gas_resp
);
5355 wpa_s
->last_gas_resp
= NULL
;
5361 #endif /* CONFIG_INTERWORKING */
5366 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5368 u8 dst_addr
[ETH_ALEN
];
5373 used
= hwaddr_aton2(dst
, dst_addr
);
5378 int num
= atoi(pos
);
5379 if (num
<= 0 || num
> 31)
5381 subtypes
|= BIT(num
);
5382 pos
= os_strchr(pos
+ 1, ',');
5391 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
5395 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5396 const u8
*addr
, const char *realm
)
5402 rlen
= os_strlen(realm
);
5404 buf
= os_malloc(len
);
5407 buf
[0] = 1; /* NAI Home Realm Count */
5408 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
5410 os_memcpy(buf
+ 3, realm
, rlen
);
5412 ret
= hs20_anqp_send_req(wpa_s
, addr
,
5413 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5422 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5425 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
5426 u8 dst_addr
[ETH_ALEN
];
5432 used
= hwaddr_aton2(dst
, dst_addr
);
5436 while (dst
[used
] == ' ')
5438 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
5439 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
5442 len
= os_strlen(dst
+ used
);
5444 if (len
== 0 && cred
&& cred
->realm
)
5445 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
5450 buf
= os_malloc(len
);
5453 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
5458 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
5459 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5467 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5469 u8 dst_addr
[ETH_ALEN
];
5473 used
= hwaddr_aton2(cmd
, dst_addr
);
5477 while (cmd
[used
] == ' ')
5481 wpa_s
->fetch_osu_icon_in_progress
= 0;
5482 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
5483 (u8
*) icon
, os_strlen(icon
));
5486 #endif /* CONFIG_HS20 */
5489 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5490 struct wpa_supplicant
*wpa_s
, char *cmd
)
5492 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
5497 #ifdef CONFIG_AUTOSCAN
5499 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
5502 enum wpa_states state
= wpa_s
->wpa_state
;
5503 char *new_params
= NULL
;
5505 if (os_strlen(cmd
) > 0) {
5506 new_params
= os_strdup(cmd
);
5507 if (new_params
== NULL
)
5511 os_free(wpa_s
->conf
->autoscan
);
5512 wpa_s
->conf
->autoscan
= new_params
;
5514 if (wpa_s
->conf
->autoscan
== NULL
)
5515 autoscan_deinit(wpa_s
);
5516 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
5517 autoscan_init(wpa_s
, 1);
5518 else if (state
== WPA_SCANNING
)
5519 wpa_supplicant_reinit_autoscan(wpa_s
);
5524 #endif /* CONFIG_AUTOSCAN */
5529 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
5535 struct wpabuf
*tfs_req
= NULL
;
5537 if (os_strncmp(cmd
, "enter", 5) == 0)
5539 else if (os_strncmp(cmd
, "exit", 4) == 0)
5544 pos
= os_strstr(cmd
, " interval=");
5546 intval
= atoi(pos
+ 10);
5548 pos
= os_strstr(cmd
, " tfs_req=");
5553 end
= os_strchr(pos
, ' ');
5557 len
= os_strlen(pos
);
5561 tfs_req
= wpabuf_alloc(len
);
5562 if (tfs_req
== NULL
)
5564 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5565 wpabuf_free(tfs_req
);
5570 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5571 WNM_SLEEP_MODE_EXIT
, intval
,
5573 wpabuf_free(tfs_req
);
5579 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5583 query_reason
= atoi(cmd
);
5585 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5588 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5591 #endif /* CONFIG_WNM */
5594 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5597 struct wpa_signal_info si
;
5601 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5608 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5609 "NOISE=%d\nFREQUENCY=%u\n",
5610 si
.current_signal
, si
.current_txrate
/ 1000,
5611 si
.current_noise
, si
.frequency
);
5612 if (ret
< 0 || ret
> end
- pos
)
5616 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5617 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5618 channel_width_to_string(si
.chanwidth
));
5619 if (ret
< 0 || ret
> end
- pos
)
5624 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5625 ret
= os_snprintf(pos
, end
- pos
,
5626 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5627 si
.center_frq1
, si
.center_frq2
);
5628 if (ret
< 0 || ret
> end
- pos
)
5633 if (si
.avg_signal
) {
5634 ret
= os_snprintf(pos
, end
- pos
,
5635 "AVG_RSSI=%d\n", si
.avg_signal
);
5636 if (ret
< 0 || ret
>= end
- pos
)
5645 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5648 struct hostap_sta_driver_data sta
;
5651 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5655 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5656 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5657 if (ret
< 0 || (size_t) ret
> buflen
)
5664 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5665 char *buf
, size_t buflen
)
5669 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5671 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5672 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5675 country
[0] = cmd
[8];
5676 country
[1] = cmd
[9];
5678 p2p_set_country(p2p
, country
);
5681 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5685 #endif /* ANDROID */
5688 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5689 char *buf
, size_t buflen
)
5694 unsigned int vendor_id
, subcmd
;
5695 struct wpabuf
*reply
;
5696 size_t data_len
= 0;
5698 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5699 vendor_id
= strtoul(cmd
, &pos
, 16);
5703 subcmd
= strtoul(pos
, &pos
, 10);
5706 if (!isblank(*pos
++))
5708 data_len
= os_strlen(pos
);
5713 data
= os_malloc(data_len
);
5717 if (hexstr2bin(pos
, data
, data_len
)) {
5718 wpa_printf(MSG_DEBUG
,
5719 "Vendor command: wrong parameter format");
5725 reply
= wpabuf_alloc((buflen
- 1) / 2);
5731 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
5735 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
5745 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5747 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5750 wpas_p2p_cancel(wpa_s
);
5751 wpas_p2p_stop_find(wpa_s
);
5752 p2p_ctrl_flush(wpa_s
);
5753 wpas_p2p_group_remove(wpa_s
, "*");
5754 wpas_p2p_service_flush(wpa_s
);
5755 wpa_s
->global
->p2p_disabled
= 0;
5756 wpa_s
->global
->p2p_per_sta_psk
= 0;
5757 wpa_s
->conf
->num_sec_device_types
= 0;
5758 wpa_s
->p2p_disable_ip_addr_req
= 0;
5759 os_free(wpa_s
->global
->p2p_go_avoid_freq
.range
);
5760 wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
5761 #endif /* CONFIG_P2P */
5763 #ifdef CONFIG_WPS_TESTING
5764 wps_version_number
= 0x20;
5765 wps_testing_dummy_cred
= 0;
5766 wps_corrupt_pkhash
= 0;
5767 #endif /* CONFIG_WPS_TESTING */
5769 wpa_s
->wps_fragment_size
= 0;
5770 wpas_wps_cancel(wpa_s
);
5771 #endif /* CONFIG_WPS */
5772 wpa_s
->after_wps
= 0;
5773 wpa_s
->known_wps_freq
= 0;
5776 #ifdef CONFIG_TDLS_TESTING
5777 extern unsigned int tdls_testing
;
5779 #endif /* CONFIG_TDLS_TESTING */
5780 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
5781 wpa_tdls_enable(wpa_s
->wpa
, 1);
5782 #endif /* CONFIG_TDLS */
5784 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
5785 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
5787 wpa_s
->no_keep_alive
= 0;
5789 os_free(wpa_s
->disallow_aps_bssid
);
5790 wpa_s
->disallow_aps_bssid
= NULL
;
5791 wpa_s
->disallow_aps_bssid_count
= 0;
5792 os_free(wpa_s
->disallow_aps_ssid
);
5793 wpa_s
->disallow_aps_ssid
= NULL
;
5794 wpa_s
->disallow_aps_ssid_count
= 0;
5796 wpa_s
->set_sta_uapsd
= 0;
5797 wpa_s
->sta_uapsd
= 0;
5799 wpa_drv_radio_disable(wpa_s
, 0);
5801 wpa_bss_flush(wpa_s
);
5802 wpa_blacklist_clear(wpa_s
);
5803 wpa_s
->extra_blacklist_count
= 0;
5804 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
5805 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
5806 wpa_config_flush_blobs(wpa_s
->conf
);
5807 wpa_s
->conf
->auto_interworking
= 0;
5808 wpa_s
->conf
->okc
= 0;
5810 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
5811 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
5812 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
5813 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5815 radio_remove_works(wpa_s
, NULL
, 1);
5817 wpa_s
->next_ssid
= NULL
;
5819 #ifdef CONFIG_INTERWORKING
5820 hs20_cancel_fetch_osu(wpa_s
);
5821 #endif /* CONFIG_INTERWORKING */
5823 wpa_s
->ext_mgmt_frame_handling
= 0;
5824 wpa_s
->ext_eapol_frame_io
= 0;
5828 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
5829 char *buf
, size_t buflen
)
5831 struct wpa_radio_work
*work
;
5833 struct os_reltime now
, diff
;
5838 os_get_reltime(&now
);
5840 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5844 os_reltime_sub(&now
, &work
->time
, &diff
);
5845 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
5846 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
5847 work
->started
, diff
.sec
, diff
.usec
);
5848 if (ret
< 0 || ret
>= end
- pos
)
5857 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
5859 struct wpa_radio_work
*work
= eloop_ctx
;
5860 struct wpa_external_work
*ework
= work
->ctx
;
5862 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
5863 "Timing out external radio work %u (%s)",
5864 ework
->id
, work
->type
);
5865 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
5866 radio_work_done(work
);
5871 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
5873 struct wpa_external_work
*ework
= work
->ctx
;
5877 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
5884 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
5885 ework
->id
, ework
->type
);
5886 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
5887 if (!ework
->timeout
)
5888 ework
->timeout
= 10;
5889 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
5894 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
5895 char *buf
, size_t buflen
)
5897 struct wpa_external_work
*ework
;
5901 unsigned int freq
= 0;
5903 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5905 ework
= os_zalloc(sizeof(*ework
));
5909 pos
= os_strchr(cmd
, ' ');
5911 type_len
= pos
- cmd
;
5914 pos2
= os_strstr(pos
, "freq=");
5916 freq
= atoi(pos2
+ 5);
5918 pos2
= os_strstr(pos
, "timeout=");
5920 ework
->timeout
= atoi(pos2
+ 8);
5922 type_len
= os_strlen(cmd
);
5924 if (4 + type_len
>= sizeof(ework
->type
))
5925 type_len
= sizeof(ework
->type
) - 4 - 1;
5926 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
5927 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
5928 ework
->type
[4 + type_len
] = '\0';
5930 wpa_s
->ext_work_id
++;
5931 if (wpa_s
->ext_work_id
== 0)
5932 wpa_s
->ext_work_id
++;
5933 ework
->id
= wpa_s
->ext_work_id
;
5935 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
5941 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
5942 if (ret
< 0 || (size_t) ret
>= buflen
)
5948 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
5950 struct wpa_radio_work
*work
;
5951 unsigned int id
= atoi(cmd
);
5953 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5955 struct wpa_external_work
*ework
;
5957 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5960 if (id
&& ework
->id
!= id
)
5962 wpa_dbg(wpa_s
, MSG_DEBUG
,
5963 "Completed external radio work %u (%s)",
5964 ework
->id
, ework
->type
);
5965 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
5966 radio_work_done(work
);
5968 return 3; /* "OK\n" */
5975 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
5976 char *buf
, size_t buflen
)
5978 if (os_strcmp(cmd
, "show") == 0)
5979 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
5980 if (os_strncmp(cmd
, "add ", 4) == 0)
5981 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
5982 if (os_strncmp(cmd
, "done ", 5) == 0)
5983 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
5988 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
5990 struct wpa_radio_work
*work
, *tmp
;
5992 if (!wpa_s
|| !wpa_s
->radio
)
5995 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
5996 struct wpa_radio_work
, list
) {
5997 struct wpa_external_work
*ework
;
5999 if (os_strncmp(work
->type
, "ext:", 4) != 0)
6002 wpa_dbg(wpa_s
, MSG_DEBUG
,
6003 "Flushing%s external radio work %u (%s)",
6004 work
->started
? " started" : "", ework
->id
,
6007 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
6009 radio_work_done(work
);
6015 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
6017 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
6018 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
6022 static int set_scan_freqs(struct wpa_supplicant
*wpa_s
, char *val
)
6026 freqs
= freq_range_to_channel_list(wpa_s
, val
);
6030 os_free(wpa_s
->manual_scan_freqs
);
6031 wpa_s
->manual_scan_freqs
= freqs
;
6037 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
)
6039 const char *pos
= value
;
6042 if (*pos
== ' ' || *pos
== '\0')
6044 if (wpa_s
->scan_id_count
== MAX_SCAN_ID
)
6046 wpa_s
->scan_id
[wpa_s
->scan_id_count
++] = atoi(pos
);
6047 pos
= os_strchr(pos
, ',');
6056 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
6057 char *reply
, int reply_size
, int *reply_len
)
6061 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
6066 wpa_s
->manual_scan_passive
= 0;
6067 wpa_s
->manual_scan_use_id
= 0;
6068 wpa_s
->manual_scan_only_new
= 0;
6069 wpa_s
->scan_id_count
= 0;
6072 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
6073 wpa_s
->scan_res_handler
= scan_only_handler
;
6075 pos
= os_strstr(params
, "freq=");
6076 if (pos
&& set_scan_freqs(wpa_s
, pos
+ 5) < 0) {
6081 pos
= os_strstr(params
, "passive=");
6083 wpa_s
->manual_scan_passive
= !!atoi(pos
+ 8);
6085 pos
= os_strstr(params
, "use_id=");
6087 wpa_s
->manual_scan_use_id
= atoi(pos
+ 7);
6089 pos
= os_strstr(params
, "only_new=1");
6091 wpa_s
->manual_scan_only_new
= 1;
6093 pos
= os_strstr(params
, "scan_id=");
6094 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8) < 0) {
6099 os_free(wpa_s
->manual_scan_freqs
);
6100 wpa_s
->manual_scan_freqs
= NULL
;
6101 if (wpa_s
->scan_res_handler
== scan_only_handler
)
6102 wpa_s
->scan_res_handler
= NULL
;
6105 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
6106 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
6107 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
6108 wpa_s
->normal_scans
= 0;
6109 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6110 wpa_s
->after_wps
= 0;
6111 wpa_s
->known_wps_freq
= 0;
6112 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6113 if (wpa_s
->manual_scan_use_id
) {
6114 wpa_s
->manual_scan_id
++;
6115 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6116 wpa_s
->manual_scan_id
);
6117 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6118 wpa_s
->manual_scan_id
);
6120 } else if (wpa_s
->sched_scanning
) {
6121 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
6122 wpa_supplicant_cancel_sched_scan(wpa_s
);
6123 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
6124 wpa_supplicant_req_scan(wpa_s
, 0, 0);
6125 if (wpa_s
->manual_scan_use_id
) {
6126 wpa_s
->manual_scan_id
++;
6127 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
6128 wpa_s
->manual_scan_id
);
6129 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
6130 wpa_s
->manual_scan_id
);
6133 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
6134 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
6139 #ifdef CONFIG_TESTING_OPTIONS
6141 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
6142 unsigned int freq
, const u8
*dst
,
6143 const u8
*src
, const u8
*bssid
,
6144 const u8
*data
, size_t data_len
,
6145 enum offchannel_send_action_result
6148 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6149 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
6150 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
6151 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
6152 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
6153 "NO_ACK" : "FAILED"));
6157 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6161 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
6163 int freq
= 0, no_cck
= 0, wait_time
= 0;
6165 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6166 * <action=Action frame payload> */
6168 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
6171 used
= hwaddr_aton2(pos
, da
);
6177 used
= hwaddr_aton2(pos
, bssid
);
6182 param
= os_strstr(pos
, " freq=");
6188 param
= os_strstr(pos
, " no_cck=");
6191 no_cck
= atoi(param
);
6194 param
= os_strstr(pos
, " wait_time=");
6197 wait_time
= atoi(param
);
6200 param
= os_strstr(pos
, " action=");
6205 len
= os_strlen(param
);
6210 buf
= os_malloc(len
);
6214 if (hexstr2bin(param
, buf
, len
) < 0) {
6219 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
6220 buf
, len
, wait_time
,
6221 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
6227 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
6229 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
6230 offchannel_send_action_done(wpa_s
);
6234 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
6237 union wpa_event_data event
;
6238 enum wpa_event_type ev
;
6240 /* <event name> [parameters..] */
6242 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
6245 param
= os_strchr(pos
, ' ');
6249 os_memset(&event
, 0, sizeof(event
));
6251 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
6252 ev
= EVENT_INTERFACE_ENABLED
;
6253 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
6254 ev
= EVENT_INTERFACE_DISABLED
;
6255 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
6256 ev
= EVENT_AVOID_FREQUENCIES
;
6259 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
6261 wpa_supplicant_event(wpa_s
, ev
, &event
);
6262 os_free(event
.freq_range
.range
);
6265 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
6270 wpa_supplicant_event(wpa_s
, ev
, &event
);
6276 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6279 u8 src
[ETH_ALEN
], *buf
;
6283 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
6286 used
= hwaddr_aton2(pos
, src
);
6293 len
= os_strlen(pos
);
6298 buf
= os_malloc(len
);
6302 if (hexstr2bin(pos
, buf
, len
) < 0) {
6307 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
6314 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
6318 const u16
*pos
= buf
;
6320 for (i
= 0; i
< len
/ 2; i
++)
6324 sum
= (sum
& 0xffff) + (sum
>> 16);
6326 return sum
^ 0xffff;
6330 #define HWSIM_PACKETLEN 1500
6331 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6333 void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
, size_t len
)
6335 struct wpa_supplicant
*wpa_s
= ctx
;
6336 const struct ether_header
*eth
;
6337 const struct iphdr
*ip
;
6341 if (len
!= HWSIM_PACKETLEN
)
6344 eth
= (const struct ether_header
*) buf
;
6345 ip
= (const struct iphdr
*) (eth
+ 1);
6346 pos
= (const u8
*) (ip
+ 1);
6348 if (ip
->ihl
!= 5 || ip
->version
!= 4 ||
6349 ntohs(ip
->tot_len
) != HWSIM_IP_LEN
)
6352 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++) {
6358 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
6359 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
6363 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
6366 int enabled
= atoi(cmd
);
6369 if (wpa_s
->l2_test
) {
6370 l2_packet_deinit(wpa_s
->l2_test
);
6371 wpa_s
->l2_test
= NULL
;
6372 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
6380 wpa_s
->l2_test
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
,
6381 ETHERTYPE_IP
, wpas_data_test_rx
,
6383 if (wpa_s
->l2_test
== NULL
)
6386 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
6392 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
6394 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
6399 u8 buf
[HWSIM_PACKETLEN
];
6400 struct ether_header
*eth
;
6405 if (wpa_s
->l2_test
== NULL
)
6408 /* format: <dst> <src> <tos> */
6411 used
= hwaddr_aton2(pos
, dst
);
6417 used
= hwaddr_aton2(pos
, src
);
6422 val
= strtol(pos
, NULL
, 0);
6423 if (val
< 0 || val
> 0xff)
6427 eth
= (struct ether_header
*) buf
;
6428 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
6429 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
6430 eth
->ether_type
= htons(ETHERTYPE_IP
);
6431 ip
= (struct iphdr
*) (eth
+ 1);
6432 os_memset(ip
, 0, sizeof(*ip
));
6437 ip
->tot_len
= htons(HWSIM_IP_LEN
);
6439 ip
->saddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6440 ip
->daddr
= htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6441 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
6442 dpos
= (u8
*) (ip
+ 1);
6443 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
6446 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, buf
,
6447 HWSIM_PACKETLEN
) < 0)
6450 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
6451 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
6456 #endif /* CONFIG_TESTING_OPTIONS */
6459 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant
*wpa_s
)
6464 wpa_printf(MSG_DEBUG
, "Update vendor elements");
6466 for (i
= 0; i
< NUM_VENDOR_ELEM_FRAMES
; i
++) {
6467 if (wpa_s
->vendor_elem
[i
]) {
6468 os_snprintf(buf
, sizeof(buf
), "frame[%u]", i
);
6469 wpa_hexdump_buf(MSG_DEBUG
, buf
, wpa_s
->vendor_elem
[i
]);
6474 if (wpa_s
->parent
== wpa_s
&&
6475 wpa_s
->global
->p2p
&&
6476 !wpa_s
->global
->p2p_disabled
)
6477 p2p_set_vendor_elems(wpa_s
->global
->p2p
, wpa_s
->vendor_elem
);
6478 #endif /* CONFIG_P2P */
6482 static struct wpa_supplicant
*
6483 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant
*wpa_s
,
6484 enum wpa_vendor_elem_frame frame
)
6488 case VENDOR_ELEM_PROBE_REQ_P2P
:
6489 case VENDOR_ELEM_PROBE_RESP_P2P
:
6490 case VENDOR_ELEM_PROBE_RESP_P2P_GO
:
6491 case VENDOR_ELEM_BEACON_P2P_GO
:
6492 case VENDOR_ELEM_P2P_PD_REQ
:
6493 case VENDOR_ELEM_P2P_PD_RESP
:
6494 case VENDOR_ELEM_P2P_GO_NEG_REQ
:
6495 case VENDOR_ELEM_P2P_GO_NEG_RESP
:
6496 case VENDOR_ELEM_P2P_GO_NEG_CONF
:
6497 case VENDOR_ELEM_P2P_INV_REQ
:
6498 case VENDOR_ELEM_P2P_INV_RESP
:
6499 case VENDOR_ELEM_P2P_ASSOC_REQ
:
6500 return wpa_s
->parent
;
6501 #endif /* CONFIG_P2P */
6508 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
6514 struct ieee802_11_elems elems
;
6517 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6519 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6521 pos
= os_strchr(pos
, ' ');
6526 len
= os_strlen(pos
);
6533 buf
= wpabuf_alloc(len
);
6537 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
6542 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
6548 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
6549 wpa_s
->vendor_elem
[frame
] = buf
;
6550 wpas_ctrl_vendor_elem_update(wpa_s
);
6554 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
6559 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
6561 wpas_ctrl_vendor_elem_update(wpa_s
);
6567 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
6568 char *buf
, size_t buflen
)
6570 int frame
= atoi(cmd
);
6572 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6574 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6576 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6579 return wpa_snprintf_hex(buf
, buflen
,
6580 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
6581 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
6585 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
6591 struct ieee802_11_elems elems
;
6595 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
6597 wpa_s
= wpas_ctrl_vendor_elem_iface(wpa_s
, frame
);
6599 pos
= os_strchr(pos
, ' ');
6605 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6606 wpa_s
->vendor_elem
[frame
] = NULL
;
6607 wpas_ctrl_vendor_elem_update(wpa_s
);
6611 if (wpa_s
->vendor_elem
[frame
] == NULL
)
6614 len
= os_strlen(pos
);
6621 buf
= os_malloc(len
);
6625 if (hexstr2bin(pos
, buf
, len
) < 0) {
6630 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
6635 ie
= wpabuf_mhead_u8(wpa_s
->vendor_elem
[frame
]);
6636 end
= ie
+ wpabuf_len(wpa_s
->vendor_elem
[frame
]);
6638 for (; ie
+ 1 < end
; ie
+= 2 + ie
[1]) {
6641 if (os_memcmp(ie
, buf
, len
) != 0)
6644 if (wpabuf_len(wpa_s
->vendor_elem
[frame
]) == len
) {
6645 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
6646 wpa_s
->vendor_elem
[frame
] = NULL
;
6648 os_memmove(ie
, ie
+ len
,
6650 wpa_s
->vendor_elem
[frame
]->used
-= len
;
6653 wpas_ctrl_vendor_elem_update(wpa_s
);
6663 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
6664 char *buf
, size_t *resp_len
)
6667 const int reply_size
= 4096;
6670 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
6671 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
6672 if (wpa_debug_show_keys
)
6673 wpa_dbg(wpa_s
, MSG_DEBUG
,
6674 "Control interface command '%s'", buf
);
6676 wpa_dbg(wpa_s
, MSG_DEBUG
,
6677 "Control interface command '%s [REMOVED]'",
6678 os_strncmp(buf
, WPA_CTRL_RSP
,
6679 os_strlen(WPA_CTRL_RSP
)) == 0 ?
6680 WPA_CTRL_RSP
: "SET_NETWORK");
6681 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
6682 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
6683 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
6684 (const u8
*) buf
, os_strlen(buf
));
6686 int level
= MSG_DEBUG
;
6687 if (os_strcmp(buf
, "PING") == 0)
6688 level
= MSG_EXCESSIVE
;
6689 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
6692 reply
= os_malloc(reply_size
);
6693 if (reply
== NULL
) {
6698 os_memcpy(reply
, "OK\n", 3);
6701 if (os_strcmp(buf
, "PING") == 0) {
6702 os_memcpy(reply
, "PONG\n", 5);
6704 } else if (os_strcmp(buf
, "IFNAME") == 0) {
6705 reply_len
= os_strlen(wpa_s
->ifname
);
6706 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
6707 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
6708 if (wpa_debug_reopen_file() < 0)
6710 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
6711 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
6712 } else if (os_strcmp(buf
, "MIB") == 0) {
6713 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
6714 if (reply_len
>= 0) {
6716 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
6717 reply_size
- reply_len
);
6723 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
6724 reply_len
= wpa_supplicant_ctrl_iface_status(
6725 wpa_s
, buf
+ 6, reply
, reply_size
);
6726 } else if (os_strcmp(buf
, "PMKSA") == 0) {
6727 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
6729 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
6730 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
6731 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
6732 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
6734 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
6735 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
6737 } else if (os_strcmp(buf
, "LOGON") == 0) {
6738 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
6739 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
6740 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
6741 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
6742 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
6745 wpas_request_connection(wpa_s
);
6746 } else if (os_strcmp(buf
, "REATTACH") == 0) {
6747 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
6748 !wpa_s
->current_ssid
)
6751 wpa_s
->reattach
= 1;
6752 wpas_request_connection(wpa_s
);
6754 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
6755 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
6757 else if (wpa_s
->disconnected
)
6758 wpas_request_connection(wpa_s
);
6759 #ifdef IEEE8021X_EAPOL
6760 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
6761 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
6763 #endif /* IEEE8021X_EAPOL */
6764 #ifdef CONFIG_PEERKEY
6765 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
6766 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
6768 #endif /* CONFIG_PEERKEY */
6769 #ifdef CONFIG_IEEE80211R
6770 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
6771 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
6773 #endif /* CONFIG_IEEE80211R */
6775 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
6776 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
6778 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
6782 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
6783 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
6785 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
6789 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
6790 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
6793 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
6794 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
6795 wpa_s
, buf
+ 14, reply
, reply_size
);
6796 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
6797 if (wpas_wps_cancel(wpa_s
))
6799 #ifdef CONFIG_WPS_NFC
6800 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
6801 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
6803 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
6804 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
6806 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6807 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6808 wpa_s
, buf
+ 21, reply
, reply_size
);
6809 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
6810 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
6811 wpa_s
, buf
+ 14, reply
, reply_size
);
6812 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
6813 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
6816 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6817 reply_len
= wpas_ctrl_nfc_get_handover_req(
6818 wpa_s
, buf
+ 21, reply
, reply_size
);
6819 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6820 reply_len
= wpas_ctrl_nfc_get_handover_sel(
6821 wpa_s
, buf
+ 21, reply
, reply_size
);
6822 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
6823 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
6825 #endif /* CONFIG_WPS_NFC */
6826 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
6827 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
6830 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
6831 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
6832 wpa_s
, buf
+ 11, reply
, reply_size
);
6833 #endif /* CONFIG_AP */
6834 #ifdef CONFIG_WPS_ER
6835 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
6836 if (wpas_wps_er_start(wpa_s
, NULL
))
6838 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
6839 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
6841 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
6842 if (wpas_wps_er_stop(wpa_s
))
6844 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
6845 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
6847 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
6848 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
6850 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
6852 } else if (ret
== -3) {
6853 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
6855 } else if (ret
== -4) {
6856 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
6860 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
6861 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
6863 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
6864 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
6867 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
6868 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
6870 #ifdef CONFIG_WPS_NFC
6871 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6872 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6873 wpa_s
, buf
+ 24, reply
, reply_size
);
6874 #endif /* CONFIG_WPS_NFC */
6875 #endif /* CONFIG_WPS_ER */
6876 #endif /* CONFIG_WPS */
6877 #ifdef CONFIG_IBSS_RSN
6878 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
6879 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
6881 #endif /* CONFIG_IBSS_RSN */
6883 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
6884 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
6886 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
6887 if (p2p_ctrl_find(wpa_s
, ""))
6889 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
6890 wpas_p2p_stop_find(wpa_s
);
6891 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
6892 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
6894 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
6895 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
6897 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
6898 if (p2p_ctrl_listen(wpa_s
, ""))
6900 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
6901 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
6903 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
6904 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
6906 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
6907 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
6909 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
6910 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
6912 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
6913 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
6914 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
6915 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
6917 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6918 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
6920 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
6921 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
6923 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
6924 wpas_p2p_sd_service_update(wpa_s
);
6925 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6926 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
6928 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
6929 wpas_p2p_service_flush(wpa_s
);
6930 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
6931 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
6933 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
6934 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
6936 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
6937 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
6939 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
6940 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
6942 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
6943 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
6945 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
6946 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
6948 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
6949 p2p_ctrl_flush(wpa_s
);
6950 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
6951 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
6953 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
6954 if (wpas_p2p_cancel(wpa_s
))
6956 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
6957 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
6959 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
6960 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
6962 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
6963 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
6965 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
6966 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
6968 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
6969 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
6971 #endif /* CONFIG_P2P */
6972 #ifdef CONFIG_WIFI_DISPLAY
6973 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
6974 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
6976 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
6977 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
6979 #endif /* CONFIG_WIFI_DISPLAY */
6980 #ifdef CONFIG_INTERWORKING
6981 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
6982 if (interworking_fetch_anqp(wpa_s
) < 0)
6984 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
6985 interworking_stop_fetch_anqp(wpa_s
);
6986 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
6987 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
6989 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
6990 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
6992 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
6993 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
6995 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
6996 if (get_anqp(wpa_s
, buf
+ 9) < 0)
6998 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
6999 if (gas_request(wpa_s
, buf
+ 12) < 0)
7001 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
7002 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
7004 #endif /* CONFIG_INTERWORKING */
7006 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
7007 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
7009 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7010 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
7012 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
7013 if (hs20_icon_request(wpa_s
, buf
+ 18) < 0)
7015 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
7016 if (hs20_fetch_osu(wpa_s
) < 0)
7018 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
7019 hs20_cancel_fetch_osu(wpa_s
);
7020 #endif /* CONFIG_HS20 */
7021 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
7023 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7024 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
7028 * Notify response from timeout to allow the control
7029 * interface response to be sent first.
7031 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
7034 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
7035 if (wpa_supplicant_reload_configuration(wpa_s
))
7037 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
7038 wpa_supplicant_terminate_proc(wpa_s
->global
);
7039 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
7040 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
7042 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
7043 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
7044 wpa_s
, buf
+ 9, reply
, reply_size
);
7045 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
7046 reply_len
= wpa_supplicant_ctrl_iface_log_level(
7047 wpa_s
, buf
+ 9, reply
, reply_size
);
7048 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
7049 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
7050 wpa_s
, reply
, reply_size
);
7051 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
7053 wpa_s
->sme
.prev_bssid_set
= 0;
7054 #endif /* CONFIG_SME */
7055 wpa_s
->reassociate
= 0;
7056 wpa_s
->disconnected
= 1;
7057 wpa_supplicant_cancel_sched_scan(wpa_s
);
7058 wpa_supplicant_cancel_scan(wpa_s
);
7059 wpa_supplicant_deauthenticate(wpa_s
,
7060 WLAN_REASON_DEAUTH_LEAVING
);
7061 } else if (os_strcmp(buf
, "SCAN") == 0) {
7062 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
7063 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
7064 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
7065 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
7066 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
7067 wpa_s
, reply
, reply_size
);
7068 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
7069 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
7071 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
7072 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
7074 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
7075 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
7077 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
7078 reply_len
= wpa_supplicant_ctrl_iface_add_network(
7079 wpa_s
, reply
, reply_size
);
7080 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
7081 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
7083 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
7084 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
7086 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
7087 reply_len
= wpa_supplicant_ctrl_iface_get_network(
7088 wpa_s
, buf
+ 12, reply
, reply_size
);
7089 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
7090 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12))
7092 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
7093 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
7094 wpa_s
, reply
, reply_size
);
7095 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
7096 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
7097 wpa_s
, reply
, reply_size
);
7098 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
7099 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
7101 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
7102 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
7104 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
7105 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
7108 #ifndef CONFIG_NO_CONFIG_WRITE
7109 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
7110 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
7112 #endif /* CONFIG_NO_CONFIG_WRITE */
7113 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
7114 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
7115 wpa_s
, buf
+ 15, reply
, reply_size
);
7116 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
7117 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
7119 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
7120 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
7122 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
7123 reply_len
= wpa_supplicant_global_iface_list(
7124 wpa_s
->global
, reply
, reply_size
);
7125 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
7126 reply_len
= wpa_supplicant_global_iface_interfaces(
7127 wpa_s
->global
, reply
, reply_size
);
7128 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
7129 reply_len
= wpa_supplicant_ctrl_iface_bss(
7130 wpa_s
, buf
+ 4, reply
, reply_size
);
7132 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
7133 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
7134 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
7135 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
7137 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
7138 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
7140 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
7141 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
7143 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
7144 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
7146 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
7147 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
7149 #endif /* CONFIG_AP */
7150 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
7151 wpas_notify_suspend(wpa_s
->global
);
7152 } else if (os_strcmp(buf
, "RESUME") == 0) {
7153 wpas_notify_resume(wpa_s
->global
);
7154 #ifdef CONFIG_TESTING_OPTIONS
7155 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
7156 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
7157 #endif /* CONFIG_TESTING_OPTIONS */
7158 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
7159 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
7161 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
7162 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
7164 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
7165 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
7167 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
7168 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
7171 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
7172 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10))
7175 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
7176 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
7178 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
7179 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
7181 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
7182 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
7184 #endif /* CONFIG_TDLS */
7185 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
7186 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
7188 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
7189 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
7191 #ifdef CONFIG_AUTOSCAN
7192 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
7193 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
7195 #endif /* CONFIG_AUTOSCAN */
7197 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
7198 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
7200 #endif /* ANDROID */
7201 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
7202 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
7204 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
7205 pmksa_cache_clear_current(wpa_s
->wpa
);
7206 eapol_sm_request_reauth(wpa_s
->eapol
);
7208 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
7209 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
7211 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
7212 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
7214 #endif /* CONFIG_WNM */
7215 } else if (os_strcmp(buf
, "FLUSH") == 0) {
7216 wpa_supplicant_ctrl_iface_flush(wpa_s
);
7217 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
7218 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
7220 #ifdef CONFIG_TESTING_OPTIONS
7221 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
7222 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
7224 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
7225 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
7226 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
7227 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
7229 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
7230 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
7232 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
7233 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
7235 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
7236 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
7238 #endif /* CONFIG_TESTING_OPTIONS */
7239 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
7240 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
7242 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
7243 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
7245 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7246 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
7249 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
7253 if (reply_len
< 0) {
7254 os_memcpy(reply
, "FAIL\n", 5);
7258 *resp_len
= reply_len
;
7263 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
7266 struct wpa_interface iface
;
7270 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7271 * TAB<bridge_ifname>
7273 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
7275 os_memset(&iface
, 0, sizeof(iface
));
7278 iface
.ifname
= pos
= cmd
;
7279 pos
= os_strchr(pos
, '\t');
7282 if (iface
.ifname
[0] == '\0')
7287 iface
.confname
= pos
;
7288 pos
= os_strchr(pos
, '\t');
7291 if (iface
.confname
[0] == '\0')
7292 iface
.confname
= NULL
;
7297 pos
= os_strchr(pos
, '\t');
7300 if (iface
.driver
[0] == '\0')
7301 iface
.driver
= NULL
;
7305 iface
.ctrl_interface
= pos
;
7306 pos
= os_strchr(pos
, '\t');
7309 if (iface
.ctrl_interface
[0] == '\0')
7310 iface
.ctrl_interface
= NULL
;
7314 iface
.driver_param
= pos
;
7315 pos
= os_strchr(pos
, '\t');
7318 if (iface
.driver_param
[0] == '\0')
7319 iface
.driver_param
= NULL
;
7323 iface
.bridge_ifname
= pos
;
7324 pos
= os_strchr(pos
, '\t');
7327 if (iface
.bridge_ifname
[0] == '\0')
7328 iface
.bridge_ifname
= NULL
;
7333 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
7336 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
7340 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
7343 struct wpa_supplicant
*wpa_s
;
7345 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
7347 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
7350 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
7354 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
7356 struct wpa_interface_info
*prev
;
7360 iface
= iface
->next
;
7362 os_free(prev
->ifname
);
7363 os_free(prev
->desc
);
7369 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
7373 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
7376 for (i
= 0; wpa_drivers
[i
]; i
++) {
7377 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
7378 if (drv
->get_interfaces
== NULL
)
7380 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
7394 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
7395 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
7396 tmp
->drv_name
, tmp
->ifname
,
7397 tmp
->desc
? tmp
->desc
: "");
7398 if (res
< 0 || res
>= end
- pos
) {
7405 wpa_free_iface_info(iface
);
7411 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
7416 struct wpa_supplicant
*wpa_s
;
7418 wpa_s
= global
->ifaces
;
7423 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
7424 if (res
< 0 || res
>= end
- pos
) {
7429 wpa_s
= wpa_s
->next
;
7435 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
7437 char *cmd
, size_t *resp_len
)
7439 struct wpa_supplicant
*wpa_s
;
7441 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7442 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
7446 if (wpa_s
== NULL
) {
7447 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
7449 *resp_len
= os_strlen(resp
);
7455 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
7459 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
7460 char *buf
, size_t *resp_len
)
7463 static const char * cmd
[] = {
7469 "P2P_GET_PASSPHRASE",
7470 "P2P_SERVICE_UPDATE",
7471 "P2P_SERVICE_FLUSH",
7478 static const char * prefix
[] = {
7481 #endif /* ANDROID */
7487 "P2P_GROUP_REMOVE ",
7490 "P2P_SERV_DISC_REQ ",
7491 "P2P_SERV_DISC_CANCEL_REQ ",
7492 "P2P_SERV_DISC_RESP ",
7493 "P2P_SERV_DISC_EXTERNAL ",
7501 "P2P_PRESENCE_REQ ",
7503 "P2P_REMOVE_CLIENT ",
7504 "NFC_GET_HANDOVER_SEL ",
7505 "NFC_GET_HANDOVER_REQ ",
7506 "NFC_REPORT_HANDOVER ",
7512 if (global
->p2p_init_wpa_s
== NULL
)
7515 for (i
= 0; !found
&& cmd
[i
]; i
++) {
7516 if (os_strcmp(buf
, cmd
[i
]) == 0)
7520 for (i
= 0; !found
&& prefix
[i
]; i
++) {
7521 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
7526 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7528 #endif /* CONFIG_P2P */
7533 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
7534 char *buf
, size_t *resp_len
)
7536 #ifdef CONFIG_WIFI_DISPLAY
7537 if (global
->p2p_init_wpa_s
== NULL
)
7539 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
7540 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
7541 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
7543 #endif /* CONFIG_WIFI_DISPLAY */
7548 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
7549 char *buf
, size_t *resp_len
)
7553 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
7557 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
7565 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
7569 value
= os_strchr(cmd
, ' ');
7574 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
7576 #ifdef CONFIG_WIFI_DISPLAY
7577 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
7578 wifi_display_enable(global
, !!atoi(value
));
7581 #endif /* CONFIG_WIFI_DISPLAY */
7583 /* Restore cmd to its original value to allow redirection */
7590 #ifndef CONFIG_NO_CONFIG_WRITE
7591 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
7593 int ret
= 0, saved
= 0;
7594 struct wpa_supplicant
*wpa_s
;
7596 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7597 if (!wpa_s
->conf
->update_config
) {
7598 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7602 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
7603 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7606 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7611 if (!saved
&& !ret
) {
7612 wpa_dbg(wpa_s
, MSG_DEBUG
,
7613 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7619 #endif /* CONFIG_NO_CONFIG_WRITE */
7622 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
7623 char *buf
, size_t buflen
)
7627 struct wpa_supplicant
*wpa_s
;
7633 if (global
->p2p
&& !global
->p2p_disabled
) {
7634 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
7637 MAC2STR(global
->p2p_dev_addr
),
7638 p2p_get_state_txt(global
->p2p
));
7639 if (ret
< 0 || ret
>= end
- pos
)
7642 } else if (global
->p2p
) {
7643 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
7644 if (ret
< 0 || ret
>= end
- pos
)
7648 #endif /* CONFIG_P2P */
7650 #ifdef CONFIG_WIFI_DISPLAY
7651 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
7652 !!global
->wifi_display
);
7653 if (ret
< 0 || ret
>= end
- pos
)
7656 #endif /* CONFIG_WIFI_DISPLAY */
7658 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7659 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
7660 "address=" MACSTR
"\n",
7661 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
7662 if (ret
< 0 || ret
>= end
- pos
)
7671 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
7672 char *buf
, size_t *resp_len
)
7675 const int reply_size
= 2048;
7677 int level
= MSG_DEBUG
;
7679 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
7680 char *pos
= os_strchr(buf
+ 7, ' ');
7683 return wpas_global_ctrl_iface_ifname(global
,
7689 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
7693 if (os_strcmp(buf
, "PING") == 0)
7694 level
= MSG_EXCESSIVE
;
7695 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
7696 (const u8
*) buf
, os_strlen(buf
));
7698 reply
= os_malloc(reply_size
);
7699 if (reply
== NULL
) {
7704 os_memcpy(reply
, "OK\n", 3);
7707 if (os_strcmp(buf
, "PING") == 0) {
7708 os_memcpy(reply
, "PONG\n", 5);
7710 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
7711 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
7713 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
7714 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
7716 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
7717 reply_len
= wpa_supplicant_global_iface_list(
7718 global
, reply
, reply_size
);
7719 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
7720 reply_len
= wpa_supplicant_global_iface_interfaces(
7721 global
, reply
, reply_size
);
7722 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
7723 wpa_supplicant_terminate_proc(global
);
7724 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
7725 wpas_notify_suspend(global
);
7726 } else if (os_strcmp(buf
, "RESUME") == 0) {
7727 wpas_notify_resume(global
);
7728 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
7729 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
7731 if (global
->p2p_init_wpa_s
) {
7733 /* Check if P2P redirection would work for this
7735 return wpa_supplicant_ctrl_iface_process(
7736 global
->p2p_init_wpa_s
,
7739 #endif /* CONFIG_P2P */
7742 #ifndef CONFIG_NO_CONFIG_WRITE
7743 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
7744 if (wpas_global_ctrl_iface_save_config(global
))
7746 #endif /* CONFIG_NO_CONFIG_WRITE */
7747 } else if (os_strcmp(buf
, "STATUS") == 0) {
7748 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
7750 #ifdef CONFIG_MODULE_TESTS
7751 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
7752 int wpas_module_tests(void);
7753 if (wpas_module_tests() < 0)
7755 #endif /* CONFIG_MODULE_TESTS */
7756 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
7757 if (wpa_debug_reopen_file() < 0)
7760 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
7764 if (reply_len
< 0) {
7765 os_memcpy(reply
, "FAIL\n", 5);
7769 *resp_len
= reply_len
;