2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2010, 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"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/version.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/wpa_ctrl.h"
16 #include "eap_peer/eap.h"
17 #include "eapol_supp/eapol_supp_sm.h"
18 #include "rsn_supp/wpa.h"
19 #include "rsn_supp/preauth.h"
20 #include "rsn_supp/pmksa_cache.h"
21 #include "l2_packet/l2_packet.h"
24 #include "wpa_supplicant_i.h"
26 #include "wps_supplicant.h"
29 #include "p2p_supplicant.h"
34 #include "ctrl_iface.h"
35 #include "interworking.h"
36 #include "blacklist.h"
37 #include "wpas_glue.h"
39 extern struct wpa_driver_ops
*wpa_drivers
[];
41 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
43 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
47 static int pno_start(struct wpa_supplicant
*wpa_s
)
51 struct wpa_ssid
*ssid
;
52 struct wpa_driver_scan_params params
;
57 os_memset(¶ms
, 0, sizeof(params
));
60 ssid
= wpa_s
->conf
->ssid
;
66 if (num_ssid
> WPAS_MAX_SCAN_SSIDS
) {
67 wpa_printf(MSG_DEBUG
, "PNO: Use only the first %u SSIDs from "
68 "%u", WPAS_MAX_SCAN_SSIDS
, (unsigned int) num_ssid
);
69 num_ssid
= WPAS_MAX_SCAN_SSIDS
;
73 wpa_printf(MSG_DEBUG
, "PNO: No configured SSIDs");
77 params
.filter_ssids
= os_malloc(sizeof(struct wpa_driver_scan_filter
) *
79 if (params
.filter_ssids
== NULL
)
82 ssid
= wpa_s
->conf
->ssid
;
84 if (!ssid
->disabled
) {
85 params
.ssids
[i
].ssid
= ssid
->ssid
;
86 params
.ssids
[i
].ssid_len
= ssid
->ssid_len
;
88 os_memcpy(params
.filter_ssids
[i
].ssid
, ssid
->ssid
,
90 params
.filter_ssids
[i
].ssid_len
= ssid
->ssid_len
;
91 params
.num_filter_ssids
++;
99 ret
= wpa_drv_sched_scan(wpa_s
, ¶ms
, 10 * 1000);
100 os_free(params
.filter_ssids
);
107 static int pno_stop(struct wpa_supplicant
*wpa_s
)
111 return wpa_drv_stop_sched_scan(wpa_s
);
117 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
120 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
127 if (hwaddr_aton(pos
, addr
)) {
131 n
= os_realloc(filter
, (count
+ 1) * ETH_ALEN
);
137 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
140 pos
= os_strchr(pos
, ' ');
145 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
146 os_free(wpa_s
->bssid_filter
);
147 wpa_s
->bssid_filter
= filter
;
148 wpa_s
->bssid_filter_count
= count
;
154 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
160 value
= os_strchr(cmd
, ' ');
165 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
166 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
167 eapol_sm_configure(wpa_s
->eapol
,
168 atoi(value
), -1, -1, -1);
169 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
170 eapol_sm_configure(wpa_s
->eapol
,
171 -1, atoi(value
), -1, -1);
172 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
173 eapol_sm_configure(wpa_s
->eapol
,
174 -1, -1, atoi(value
), -1);
175 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
176 eapol_sm_configure(wpa_s
->eapol
,
177 -1, -1, -1, atoi(value
));
178 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
179 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
182 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
184 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
187 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
188 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
190 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
191 wpa_s
->wps_fragment_size
= atoi(value
);
192 #ifdef CONFIG_WPS_TESTING
193 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
195 val
= strtol(value
, NULL
, 0);
196 if (val
< 0 || val
> 0xff) {
198 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
199 "wps_version_number %ld", val
);
201 wps_version_number
= val
;
202 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
204 (wps_version_number
& 0xf0) >> 4,
205 wps_version_number
& 0x0f);
207 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
208 wps_testing_dummy_cred
= atoi(value
);
209 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
210 wps_testing_dummy_cred
);
211 #endif /* CONFIG_WPS_TESTING */
212 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
213 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
215 #ifdef CONFIG_TDLS_TESTING
216 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
217 extern unsigned int tdls_testing
;
218 tdls_testing
= strtol(value
, NULL
, 0);
219 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
220 #endif /* CONFIG_TDLS_TESTING */
222 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
223 int disabled
= atoi(value
);
224 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
226 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
228 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
230 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
231 #endif /* CONFIG_TDLS */
232 } else if (os_strcasecmp(cmd
, "pno") == 0) {
234 ret
= pno_start(wpa_s
);
236 ret
= pno_stop(wpa_s
);
237 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
238 int disabled
= atoi(value
);
239 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
242 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
243 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
244 if (os_strcmp(value
, "disable") == 0)
245 wpa_s
->set_sta_uapsd
= 0;
249 /* format: BE,BK,VI,VO;max SP Length */
251 pos
= os_strchr(value
, ',');
256 pos
= os_strchr(pos
, ',');
261 pos
= os_strchr(pos
, ',');
266 /* ignore max SP Length for now */
268 wpa_s
->set_sta_uapsd
= 1;
269 wpa_s
->sta_uapsd
= 0;
271 wpa_s
->sta_uapsd
|= BIT(0);
273 wpa_s
->sta_uapsd
|= BIT(1);
275 wpa_s
->sta_uapsd
|= BIT(2);
277 wpa_s
->sta_uapsd
|= BIT(3);
279 } else if (os_strcasecmp(cmd
, "ps") == 0) {
280 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
281 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
282 ret
= set_bssid_filter(wpa_s
, value
);
285 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
287 wpa_supplicant_update_config(wpa_s
);
294 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
295 char *cmd
, char *buf
, size_t buflen
)
299 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
301 if (os_strcmp(cmd
, "version") == 0) {
302 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
303 } else if (os_strcasecmp(cmd
, "country") == 0) {
304 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
305 res
= os_snprintf(buf
, buflen
, "%c%c",
306 wpa_s
->conf
->country
[0],
307 wpa_s
->conf
->country
[1]);
310 if (res
< 0 || (unsigned int) res
>= buflen
)
316 #ifdef IEEE8021X_EAPOL
317 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
321 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
323 if (hwaddr_aton(addr
, bssid
)) {
324 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
329 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
330 rsn_preauth_deinit(wpa_s
->wpa
);
331 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
336 #endif /* IEEE8021X_EAPOL */
339 #ifdef CONFIG_PEERKEY
340 /* MLME-STKSTART.request(peer) */
341 static int wpa_supplicant_ctrl_iface_stkstart(
342 struct wpa_supplicant
*wpa_s
, char *addr
)
346 if (hwaddr_aton(addr
, peer
)) {
347 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
348 "address '%s'", addr
);
352 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
355 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
357 #endif /* CONFIG_PEERKEY */
362 static int wpa_supplicant_ctrl_iface_tdls_discover(
363 struct wpa_supplicant
*wpa_s
, char *addr
)
368 if (hwaddr_aton(addr
, peer
)) {
369 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
370 "address '%s'", addr
);
374 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
377 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
378 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
380 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
386 static int wpa_supplicant_ctrl_iface_tdls_setup(
387 struct wpa_supplicant
*wpa_s
, char *addr
)
392 if (hwaddr_aton(addr
, peer
)) {
393 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
394 "address '%s'", addr
);
398 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
401 ret
= wpa_tdls_reneg(wpa_s
->wpa
, peer
);
403 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
404 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
406 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
413 static int wpa_supplicant_ctrl_iface_tdls_teardown(
414 struct wpa_supplicant
*wpa_s
, char *addr
)
418 if (hwaddr_aton(addr
, peer
)) {
419 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
420 "address '%s'", addr
);
424 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
427 return wpa_tdls_teardown_link(wpa_s
->wpa
, peer
,
428 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
431 #endif /* CONFIG_TDLS */
434 #ifdef CONFIG_IEEE80211R
435 static int wpa_supplicant_ctrl_iface_ft_ds(
436 struct wpa_supplicant
*wpa_s
, char *addr
)
438 u8 target_ap
[ETH_ALEN
];
442 if (hwaddr_aton(addr
, target_ap
)) {
443 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
444 "address '%s'", addr
);
448 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
450 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
452 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
456 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
458 #endif /* CONFIG_IEEE80211R */
462 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
465 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
467 u8 p2p_dev_addr
[ETH_ALEN
];
468 #endif /* CONFIG_P2P */
470 u8
*_p2p_dev_addr
= NULL
;
471 #endif /* CONFIG_AP */
473 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
476 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
477 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
478 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
479 "P2P Device Address '%s'",
483 _p2p_dev_addr
= p2p_dev_addr
;
484 #endif /* CONFIG_P2P */
485 } else if (hwaddr_aton(cmd
, bssid
)) {
486 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
493 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
494 #endif /* CONFIG_AP */
496 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
500 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
501 char *cmd
, char *buf
,
504 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
508 pin
= os_strchr(cmd
, ' ');
512 if (os_strcmp(cmd
, "any") == 0)
514 else if (os_strcmp(cmd
, "get") == 0) {
515 ret
= wps_generate_pin();
517 } else if (hwaddr_aton(cmd
, bssid
)) {
518 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
525 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
527 #endif /* CONFIG_AP */
530 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
534 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
535 if (ret
< 0 || (size_t) ret
>= buflen
)
540 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
545 /* Return the generated PIN */
546 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
547 if (ret
< 0 || (size_t) ret
>= buflen
)
553 static int wpa_supplicant_ctrl_iface_wps_check_pin(
554 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
561 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
562 (u8
*) cmd
, os_strlen(cmd
));
563 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
564 if (*pos
< '0' || *pos
> '9')
568 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
572 if (len
!= 4 && len
!= 8) {
573 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
579 unsigned int pin_val
;
581 if (!wps_pin_valid(pin_val
)) {
582 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
583 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
584 if (ret
< 0 || (size_t) ret
>= buflen
)
590 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
591 if (ret
< 0 || (size_t) ret
>= buflen
)
598 #ifdef CONFIG_WPS_OOB
599 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant
*wpa_s
,
602 char *path
, *method
, *name
;
604 path
= os_strchr(cmd
, ' ');
609 method
= os_strchr(path
, ' ');
614 name
= os_strchr(method
, ' ');
618 return wpas_wps_start_oob(wpa_s
, cmd
, path
, method
, name
);
620 #endif /* CONFIG_WPS_OOB */
623 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
632 struct wps_new_ap_settings ap
;
634 pin
= os_strchr(cmd
, ' ');
639 if (hwaddr_aton(cmd
, bssid
)) {
640 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
645 new_ssid
= os_strchr(pin
, ' ');
646 if (new_ssid
== NULL
)
647 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
650 new_auth
= os_strchr(new_ssid
, ' ');
651 if (new_auth
== NULL
)
655 new_encr
= os_strchr(new_auth
, ' ');
656 if (new_encr
== NULL
)
660 new_key
= os_strchr(new_encr
, ' ');
665 os_memset(&ap
, 0, sizeof(ap
));
666 ap
.ssid_hex
= new_ssid
;
669 ap
.key_hex
= new_key
;
670 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
675 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
676 char *cmd
, char *buf
,
683 if (!wpa_s
->ap_iface
)
686 pos
= os_strchr(cmd
, ' ');
690 if (os_strcmp(cmd
, "disable") == 0) {
691 wpas_wps_ap_pin_disable(wpa_s
);
692 return os_snprintf(buf
, buflen
, "OK\n");
695 if (os_strcmp(cmd
, "random") == 0) {
698 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
701 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
704 if (os_strcmp(cmd
, "get") == 0) {
705 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
708 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
711 if (os_strcmp(cmd
, "set") == 0) {
716 pos
= os_strchr(pos
, ' ');
721 if (os_strlen(pin
) > buflen
)
723 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
725 return os_snprintf(buf
, buflen
, "%s", pin
);
730 #endif /* CONFIG_AP */
734 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
737 char *uuid
= cmd
, *pin
, *pos
;
738 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
739 pin
= os_strchr(uuid
, ' ');
743 pos
= os_strchr(pin
, ' ');
746 if (hwaddr_aton(pos
, addr_buf
) == 0)
749 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
753 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
756 char *uuid
= cmd
, *pin
;
757 pin
= os_strchr(uuid
, ' ');
761 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
765 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
766 struct wpa_supplicant
*wpa_s
, char *cmd
)
768 char *uuid
= cmd
, *id
;
769 id
= os_strchr(uuid
, ' ');
773 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
777 static int wpa_supplicant_ctrl_iface_wps_er_config(
778 struct wpa_supplicant
*wpa_s
, char *cmd
)
785 struct wps_new_ap_settings ap
;
787 pin
= os_strchr(cmd
, ' ');
792 new_ssid
= os_strchr(pin
, ' ');
793 if (new_ssid
== NULL
)
797 new_auth
= os_strchr(new_ssid
, ' ');
798 if (new_auth
== NULL
)
802 new_encr
= os_strchr(new_auth
, ' ');
803 if (new_encr
== NULL
)
807 new_key
= os_strchr(new_encr
, ' ');
812 os_memset(&ap
, 0, sizeof(ap
));
813 ap
.ssid_hex
= new_ssid
;
816 ap
.key_hex
= new_key
;
817 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
819 #endif /* CONFIG_WPS_ER */
821 #endif /* CONFIG_WPS */
824 #ifdef CONFIG_IBSS_RSN
825 static int wpa_supplicant_ctrl_iface_ibss_rsn(
826 struct wpa_supplicant
*wpa_s
, char *addr
)
830 if (hwaddr_aton(addr
, peer
)) {
831 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
832 "address '%s'", addr
);
836 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
839 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
841 #endif /* CONFIG_IBSS_RSN */
844 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant
*wpa_s
,
845 struct wpa_ssid
*ssid
,
849 #ifdef IEEE8021X_EAPOL
850 struct eap_peer_config
*eap
= &ssid
->eap
;
852 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: response handle field=%s", field
);
853 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: response value",
854 (const u8
*) value
, os_strlen(value
));
856 switch (wpa_supplicant_ctrl_req_from_string(field
)) {
857 case WPA_CTRL_REQ_EAP_IDENTITY
:
858 os_free(eap
->identity
);
859 eap
->identity
= (u8
*) os_strdup(value
);
860 eap
->identity_len
= os_strlen(value
);
861 eap
->pending_req_identity
= 0;
862 if (ssid
== wpa_s
->current_ssid
)
863 wpa_s
->reassociate
= 1;
865 case WPA_CTRL_REQ_EAP_PASSWORD
:
866 os_free(eap
->password
);
867 eap
->password
= (u8
*) os_strdup(value
);
868 eap
->password_len
= os_strlen(value
);
869 eap
->pending_req_password
= 0;
870 if (ssid
== wpa_s
->current_ssid
)
871 wpa_s
->reassociate
= 1;
873 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
874 os_free(eap
->new_password
);
875 eap
->new_password
= (u8
*) os_strdup(value
);
876 eap
->new_password_len
= os_strlen(value
);
877 eap
->pending_req_new_password
= 0;
878 if (ssid
== wpa_s
->current_ssid
)
879 wpa_s
->reassociate
= 1;
881 case WPA_CTRL_REQ_EAP_PIN
:
883 eap
->pin
= os_strdup(value
);
884 eap
->pending_req_pin
= 0;
885 if (ssid
== wpa_s
->current_ssid
)
886 wpa_s
->reassociate
= 1;
888 case WPA_CTRL_REQ_EAP_OTP
:
890 eap
->otp
= (u8
*) os_strdup(value
);
891 eap
->otp_len
= os_strlen(value
);
892 os_free(eap
->pending_req_otp
);
893 eap
->pending_req_otp
= NULL
;
894 eap
->pending_req_otp_len
= 0;
896 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
897 os_free(eap
->private_key_passwd
);
898 eap
->private_key_passwd
= (u8
*) os_strdup(value
);
899 eap
->pending_req_passphrase
= 0;
900 if (ssid
== wpa_s
->current_ssid
)
901 wpa_s
->reassociate
= 1;
904 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", field
);
909 #else /* IEEE8021X_EAPOL */
910 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: IEEE 802.1X not included");
912 #endif /* IEEE8021X_EAPOL */
916 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
919 #ifdef IEEE8021X_EAPOL
922 struct wpa_ssid
*ssid
;
924 pos
= os_strchr(rsp
, '-');
929 pos
= os_strchr(pos
, ':');
934 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
935 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
936 (u8
*) pos
, os_strlen(pos
));
938 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
940 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
945 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
947 #else /* IEEE8021X_EAPOL */
948 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
950 #endif /* IEEE8021X_EAPOL */
954 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
956 char *buf
, size_t buflen
)
958 char *pos
, *end
, tmp
[30];
959 int res
, verbose
, wps
, ret
;
961 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
962 wps
= os_strcmp(params
, "-WPS") == 0;
965 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
966 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
967 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
968 MAC2STR(wpa_s
->bssid
));
969 if (ret
< 0 || ret
>= end
- pos
)
973 u8
*_ssid
= ssid
->ssid
;
974 size_t ssid_len
= ssid
->ssid_len
;
975 u8 ssid_buf
[MAX_SSID_LEN
];
977 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
984 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
985 wpa_ssid_txt(_ssid
, ssid_len
),
987 if (ret
< 0 || ret
>= end
- pos
)
991 if (wps
&& ssid
->passphrase
&&
992 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
993 (ssid
->mode
== WPAS_MODE_AP
||
994 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
995 ret
= os_snprintf(pos
, end
- pos
,
998 if (ret
< 0 || ret
>= end
- pos
)
1003 ret
= os_snprintf(pos
, end
- pos
,
1006 if (ret
< 0 || ret
>= end
- pos
)
1011 switch (ssid
->mode
) {
1012 case WPAS_MODE_INFRA
:
1013 ret
= os_snprintf(pos
, end
- pos
,
1016 case WPAS_MODE_IBSS
:
1017 ret
= os_snprintf(pos
, end
- pos
,
1021 ret
= os_snprintf(pos
, end
- pos
,
1024 case WPAS_MODE_P2P_GO
:
1025 ret
= os_snprintf(pos
, end
- pos
,
1028 case WPAS_MODE_P2P_GROUP_FORMATION
:
1029 ret
= os_snprintf(pos
, end
- pos
,
1030 "mode=P2P GO - group "
1037 if (ret
< 0 || ret
>= end
- pos
)
1043 if (wpa_s
->ap_iface
) {
1044 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1048 #endif /* CONFIG_AP */
1049 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1051 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1052 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1053 if (ret
< 0 || ret
>= end
- pos
)
1058 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1059 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1060 if (ret
< 0 || ret
>= end
- pos
)
1066 if (wpa_s
->global
->p2p
) {
1067 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1068 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1069 if (ret
< 0 || ret
>= end
- pos
)
1073 #endif /* CONFIG_P2P */
1075 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1076 MAC2STR(wpa_s
->own_addr
));
1077 if (ret
< 0 || ret
>= end
- pos
)
1081 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1082 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1083 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1089 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1097 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1102 struct wpa_ssid
*ssid
;
1105 /* cmd: "<network id> <BSSID>" */
1106 pos
= os_strchr(cmd
, ' ');
1111 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1112 if (hwaddr_aton(pos
, bssid
)) {
1113 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1117 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1119 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1124 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1125 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1131 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1132 char *cmd
, char *buf
,
1136 struct wpa_blacklist
*e
;
1140 /* cmd: "BLACKLIST [<BSSID>]" */
1144 e
= wpa_s
->blacklist
;
1146 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1148 if (ret
< 0 || ret
>= end
- pos
)
1157 if (os_strncmp(cmd
, "clear", 5) == 0) {
1158 wpa_blacklist_clear(wpa_s
);
1159 os_memcpy(buf
, "OK\n", 3);
1163 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1164 if (hwaddr_aton(cmd
, bssid
)) {
1165 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1170 * Add the BSSID twice, so its count will be 2, causing it to be
1171 * skipped when processing scan results.
1173 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1176 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1179 os_memcpy(buf
, "OK\n", 3);
1184 extern int wpa_debug_level
;
1185 extern int wpa_debug_timestamp
;
1187 static const char * debug_level_str(int level
)
1208 static int str_to_debug_level(const char *s
)
1210 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1211 return MSG_EXCESSIVE
;
1212 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1214 if (os_strcasecmp(s
, "DEBUG") == 0)
1216 if (os_strcasecmp(s
, "INFO") == 0)
1218 if (os_strcasecmp(s
, "WARNING") == 0)
1220 if (os_strcasecmp(s
, "ERROR") == 0)
1226 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1227 char *cmd
, char *buf
,
1230 char *pos
, *end
, *stamp
;
1237 /* cmd: "LOG_LEVEL [<level>]" */
1241 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1243 debug_level_str(wpa_debug_level
),
1244 wpa_debug_timestamp
);
1245 if (ret
< 0 || ret
>= end
- pos
)
1254 stamp
= os_strchr(cmd
, ' ');
1257 while (*stamp
== ' ') {
1262 if (cmd
&& os_strlen(cmd
)) {
1263 int level
= str_to_debug_level(cmd
);
1266 wpa_debug_level
= level
;
1269 if (stamp
&& os_strlen(stamp
))
1270 wpa_debug_timestamp
= atoi(stamp
);
1272 os_memcpy(buf
, "OK\n", 3);
1277 static int wpa_supplicant_ctrl_iface_list_networks(
1278 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1281 struct wpa_ssid
*ssid
;
1286 ret
= os_snprintf(pos
, end
- pos
,
1287 "network id / ssid / bssid / flags\n");
1288 if (ret
< 0 || ret
>= end
- pos
)
1292 ssid
= wpa_s
->conf
->ssid
;
1294 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
1296 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1297 if (ret
< 0 || ret
>= end
- pos
)
1300 if (ssid
->bssid_set
) {
1301 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
1302 MAC2STR(ssid
->bssid
));
1304 ret
= os_snprintf(pos
, end
- pos
, "\tany");
1306 if (ret
< 0 || ret
>= end
- pos
)
1309 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s",
1310 ssid
== wpa_s
->current_ssid
?
1312 ssid
->disabled
? "[DISABLED]" : "",
1313 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
1315 if (ret
< 0 || ret
>= end
- pos
)
1318 ret
= os_snprintf(pos
, end
- pos
, "\n");
1319 if (ret
< 0 || ret
>= end
- pos
)
1330 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
1333 ret
= os_snprintf(pos
, end
- pos
, "-");
1334 if (ret
< 0 || ret
>= end
- pos
)
1337 if (cipher
& WPA_CIPHER_NONE
) {
1338 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : "+");
1339 if (ret
< 0 || ret
>= end
- pos
)
1344 if (cipher
& WPA_CIPHER_WEP40
) {
1345 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : "+");
1346 if (ret
< 0 || ret
>= end
- pos
)
1351 if (cipher
& WPA_CIPHER_WEP104
) {
1352 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
1354 if (ret
< 0 || ret
>= end
- pos
)
1359 if (cipher
& WPA_CIPHER_TKIP
) {
1360 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : "+");
1361 if (ret
< 0 || ret
>= end
- pos
)
1366 if (cipher
& WPA_CIPHER_CCMP
) {
1367 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : "+");
1368 if (ret
< 0 || ret
>= end
- pos
)
1377 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
1378 const u8
*ie
, size_t ie_len
)
1380 struct wpa_ie_data data
;
1383 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
1384 if (ret
< 0 || ret
>= end
- pos
)
1388 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
1389 ret
= os_snprintf(pos
, end
- pos
, "?]");
1390 if (ret
< 0 || ret
>= end
- pos
)
1397 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1398 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
1399 if (ret
< 0 || ret
>= end
- pos
)
1404 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
1405 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
1406 if (ret
< 0 || ret
>= end
- pos
)
1411 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
1412 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
1413 if (ret
< 0 || ret
>= end
- pos
)
1418 #ifdef CONFIG_IEEE80211R
1419 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1420 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
1422 if (ret
< 0 || ret
>= end
- pos
)
1427 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1428 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
1430 if (ret
< 0 || ret
>= end
- pos
)
1435 #endif /* CONFIG_IEEE80211R */
1436 #ifdef CONFIG_IEEE80211W
1437 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1438 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
1440 if (ret
< 0 || ret
>= end
- pos
)
1445 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1446 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
1448 if (ret
< 0 || ret
>= end
- pos
)
1453 #endif /* CONFIG_IEEE80211W */
1455 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
1457 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
1458 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
1459 if (ret
< 0 || ret
>= end
- pos
)
1464 ret
= os_snprintf(pos
, end
- pos
, "]");
1465 if (ret
< 0 || ret
>= end
- pos
)
1474 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
1475 char *pos
, char *end
,
1476 struct wpabuf
*wps_ie
)
1483 if (wps_is_selected_pbc_registrar(wps_ie
))
1486 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
1488 #endif /* CONFIG_WPS2 */
1489 else if (wps_is_selected_pin_registrar(wps_ie
))
1494 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
1495 if (ret
>= 0 && ret
< end
- pos
)
1497 wpabuf_free(wps_ie
);
1500 #endif /* CONFIG_WPS */
1503 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
1504 char *pos
, char *end
,
1505 const struct wpa_bss
*bss
)
1508 struct wpabuf
*wps_ie
;
1509 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
1510 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
1511 #else /* CONFIG_WPS */
1513 #endif /* CONFIG_WPS */
1517 /* Format one result on one text line into a buffer. */
1518 static int wpa_supplicant_ctrl_iface_scan_result(
1519 struct wpa_supplicant
*wpa_s
,
1520 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
1524 const u8
*ie
, *ie2
, *p2p
;
1526 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1527 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
1528 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
1530 return 0; /* Do not show P2P listen discovery results here */
1535 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
1536 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
1537 if (ret
< 0 || ret
>= end
- pos
)
1540 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1542 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
1543 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1545 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
1546 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
1547 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
1548 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
1549 if (ret
< 0 || ret
>= end
- pos
)
1553 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
1554 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
1555 if (ret
< 0 || ret
>= end
- pos
)
1559 if (bss
->caps
& IEEE80211_CAP_ESS
) {
1560 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
1561 if (ret
< 0 || ret
>= end
- pos
)
1566 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
1567 if (ret
< 0 || ret
>= end
- pos
)
1572 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
1573 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1574 if (ret
< 0 || ret
>= end
- pos
)
1578 ret
= os_snprintf(pos
, end
- pos
, "\n");
1579 if (ret
< 0 || ret
>= end
- pos
)
1587 static int wpa_supplicant_ctrl_iface_scan_results(
1588 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1591 struct wpa_bss
*bss
;
1596 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
1598 if (ret
< 0 || ret
>= end
- pos
)
1602 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
1603 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
1605 if (ret
< 0 || ret
>= end
- pos
)
1614 static int wpa_supplicant_ctrl_iface_select_network(
1615 struct wpa_supplicant
*wpa_s
, char *cmd
)
1618 struct wpa_ssid
*ssid
;
1620 /* cmd: "<network id>" or "any" */
1621 if (os_strcmp(cmd
, "any") == 0) {
1622 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
1626 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
1628 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1630 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1631 "network id=%d", id
);
1634 if (ssid
->disabled
== 2) {
1635 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1636 "SELECT_NETWORK with persistent P2P group");
1641 wpa_supplicant_select_network(wpa_s
, ssid
);
1647 static int wpa_supplicant_ctrl_iface_enable_network(
1648 struct wpa_supplicant
*wpa_s
, char *cmd
)
1651 struct wpa_ssid
*ssid
;
1653 /* cmd: "<network id>" or "all" */
1654 if (os_strcmp(cmd
, "all") == 0) {
1655 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
1659 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
1661 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1663 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1664 "network id=%d", id
);
1667 if (ssid
->disabled
== 2) {
1668 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1669 "ENABLE_NETWORK with persistent P2P group");
1673 if (os_strstr(cmd
, " no-connect")) {
1678 wpa_supplicant_enable_network(wpa_s
, ssid
);
1684 static int wpa_supplicant_ctrl_iface_disable_network(
1685 struct wpa_supplicant
*wpa_s
, char *cmd
)
1688 struct wpa_ssid
*ssid
;
1690 /* cmd: "<network id>" or "all" */
1691 if (os_strcmp(cmd
, "all") == 0) {
1692 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
1696 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
1698 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1700 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1701 "network id=%d", id
);
1704 if (ssid
->disabled
== 2) {
1705 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1706 "DISABLE_NETWORK with persistent P2P "
1711 wpa_supplicant_disable_network(wpa_s
, ssid
);
1717 static int wpa_supplicant_ctrl_iface_add_network(
1718 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1720 struct wpa_ssid
*ssid
;
1723 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
1725 ssid
= wpa_config_add_network(wpa_s
->conf
);
1729 wpas_notify_network_added(wpa_s
, ssid
);
1732 wpa_config_set_network_defaults(ssid
);
1734 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
1735 if (ret
< 0 || (size_t) ret
>= buflen
)
1741 static int wpa_supplicant_ctrl_iface_remove_network(
1742 struct wpa_supplicant
*wpa_s
, char *cmd
)
1745 struct wpa_ssid
*ssid
;
1747 /* cmd: "<network id>" or "all" */
1748 if (os_strcmp(cmd
, "all") == 0) {
1749 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
1750 ssid
= wpa_s
->conf
->ssid
;
1752 struct wpa_ssid
*remove_ssid
= ssid
;
1755 wpas_notify_network_removed(wpa_s
, remove_ssid
);
1756 wpa_config_remove_network(wpa_s
->conf
, id
);
1758 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1759 if (wpa_s
->current_ssid
) {
1761 wpa_s
->sme
.prev_bssid_set
= 0;
1762 #endif /* CONFIG_SME */
1763 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1764 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1765 wpa_supplicant_disassociate(wpa_s
,
1766 WLAN_REASON_DEAUTH_LEAVING
);
1772 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
1774 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1776 wpas_notify_network_removed(wpa_s
, ssid
);
1778 wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
1779 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1784 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
1786 wpa_s
->sme
.prev_bssid_set
= 0;
1787 #endif /* CONFIG_SME */
1789 * Invalidate the EAP session cache if the current or
1790 * previously used network is removed.
1792 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1795 if (ssid
== wpa_s
->current_ssid
) {
1796 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1797 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1799 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1806 static int wpa_supplicant_ctrl_iface_set_network(
1807 struct wpa_supplicant
*wpa_s
, char *cmd
)
1810 struct wpa_ssid
*ssid
;
1813 /* cmd: "<network id> <variable name> <value>" */
1814 name
= os_strchr(cmd
, ' ');
1819 value
= os_strchr(name
, ' ');
1825 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1827 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1828 (u8
*) value
, os_strlen(value
));
1830 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1832 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1837 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
1838 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
1839 "variable '%s'", name
);
1843 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
1845 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
1847 * Invalidate the EAP session cache if anything in the current
1848 * or previously used configuration changes.
1850 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1853 if ((os_strcmp(name
, "psk") == 0 &&
1854 value
[0] == '"' && ssid
->ssid_len
) ||
1855 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
1856 wpa_config_update_psk(ssid
);
1857 else if (os_strcmp(name
, "priority") == 0)
1858 wpa_config_update_prio_list(wpa_s
->conf
);
1864 static int wpa_supplicant_ctrl_iface_get_network(
1865 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1869 struct wpa_ssid
*ssid
;
1872 /* cmd: "<network id> <variable name>" */
1873 name
= os_strchr(cmd
, ' ');
1874 if (name
== NULL
|| buflen
== 0)
1879 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1882 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1884 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1889 value
= wpa_config_get_no_key(ssid
, name
);
1890 if (value
== NULL
) {
1891 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
1892 "variable '%s'", name
);
1896 res
= os_strlcpy(buf
, value
, buflen
);
1897 if (res
>= buflen
) {
1908 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
1909 char *buf
, size_t buflen
)
1912 struct wpa_cred
*cred
;
1917 ret
= os_snprintf(pos
, end
- pos
,
1918 "cred id / realm / username / domain / imsi\n");
1919 if (ret
< 0 || ret
>= end
- pos
)
1923 cred
= wpa_s
->conf
->cred
;
1925 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
1926 cred
->id
, cred
->realm
? cred
->realm
: "",
1927 cred
->username
? cred
->username
: "",
1928 cred
->domain
? cred
->domain
: "",
1929 cred
->imsi
? cred
->imsi
: "");
1930 if (ret
< 0 || ret
>= end
- pos
)
1941 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
1942 char *buf
, size_t buflen
)
1944 struct wpa_cred
*cred
;
1947 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
1949 cred
= wpa_config_add_cred(wpa_s
->conf
);
1953 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
1954 if (ret
< 0 || (size_t) ret
>= buflen
)
1960 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
1964 struct wpa_cred
*cred
;
1966 /* cmd: "<cred id>" or "all" */
1967 if (os_strcmp(cmd
, "all") == 0) {
1968 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
1969 cred
= wpa_s
->conf
->cred
;
1973 wpa_config_remove_cred(wpa_s
->conf
, id
);
1979 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
1981 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
1983 wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
1984 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
1993 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
1997 struct wpa_cred
*cred
;
2000 /* cmd: "<cred id> <variable name> <value>" */
2001 name
= os_strchr(cmd
, ' ');
2006 value
= os_strchr(name
, ' ');
2012 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2014 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2015 (u8
*) value
, os_strlen(value
));
2017 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2019 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2024 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
2025 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
2026 "variable '%s'", name
);
2034 #ifndef CONFIG_NO_CONFIG_WRITE
2035 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
2039 if (!wpa_s
->conf
->update_config
) {
2040 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2041 "to update configuration (update_config=0)");
2045 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
2047 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2048 "update configuration");
2050 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2056 #endif /* CONFIG_NO_CONFIG_WRITE */
2059 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2060 struct wpa_driver_capa
*capa
,
2061 char *buf
, size_t buflen
)
2073 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2079 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2080 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2081 if (ret
< 0 || ret
>= end
- pos
)
2087 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2088 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2089 if (ret
< 0 || ret
>= end
- pos
)
2095 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2096 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : " ");
2097 if (ret
< 0 || ret
>= end
- pos
)
2107 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2108 struct wpa_driver_capa
*capa
,
2109 char *buf
, size_t buflen
)
2121 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2127 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2128 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2129 if (ret
< 0 || ret
>= end
- pos
)
2135 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2136 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2137 if (ret
< 0 || ret
>= end
- pos
)
2143 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP104
) {
2144 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
2146 if (ret
< 0 || ret
>= end
- pos
)
2152 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP40
) {
2153 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : " ");
2154 if (ret
< 0 || ret
>= end
- pos
)
2164 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2165 struct wpa_driver_capa
*capa
,
2166 char *buf
, size_t buflen
)
2178 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2185 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2186 if (ret
< 0 || ret
>= end
- pos
)
2190 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2191 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2192 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2193 if (ret
< 0 || ret
>= end
- pos
)
2198 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2199 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2200 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2201 if (ret
< 0 || ret
>= end
- pos
)
2206 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2207 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2208 if (ret
< 0 || ret
>= end
- pos
)
2217 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2218 struct wpa_driver_capa
*capa
,
2219 char *buf
, size_t buflen
)
2231 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2237 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2238 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2239 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
2240 if (ret
< 0 || ret
>= end
- pos
)
2246 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2247 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
2248 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
2249 if (ret
< 0 || ret
>= end
- pos
)
2259 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
2260 struct wpa_driver_capa
*capa
,
2261 char *buf
, size_t buflen
)
2273 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
2279 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
2280 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
2281 if (ret
< 0 || ret
>= end
- pos
)
2287 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
2288 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
2290 if (ret
< 0 || ret
>= end
- pos
)
2296 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
2297 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
2298 if (ret
< 0 || ret
>= end
- pos
)
2308 static int wpa_supplicant_ctrl_iface_get_capability(
2309 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
2312 struct wpa_driver_capa capa
;
2318 /* Determine whether or not strict checking was requested */
2319 len
= os_strlcpy(field
, _field
, sizeof(field
));
2320 if (len
>= sizeof(field
))
2322 strict
= os_strchr(field
, ' ');
2323 if (strict
!= NULL
) {
2325 if (os_strcmp(strict
, "strict") != 0)
2329 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2330 field
, strict
? strict
: "");
2332 if (os_strcmp(field
, "eap") == 0) {
2333 return eap_get_names(buf
, buflen
);
2336 res
= wpa_drv_get_capa(wpa_s
, &capa
);
2338 if (os_strcmp(field
, "pairwise") == 0)
2339 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
2342 if (os_strcmp(field
, "group") == 0)
2343 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
2346 if (os_strcmp(field
, "key_mgmt") == 0)
2347 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
2350 if (os_strcmp(field
, "proto") == 0)
2351 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
2354 if (os_strcmp(field
, "auth_alg") == 0)
2355 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
2358 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2365 #ifdef CONFIG_INTERWORKING
2366 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
2367 struct wpabuf
*data
)
2377 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
2378 if (ret
< 0 || ret
>= end
- pos
)
2382 d
= wpabuf_head_u8(data
);
2383 for (i
= 0; i
< wpabuf_len(data
); i
++) {
2384 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
2385 if (ret
< 0 || ret
>= end
- pos
)
2390 ret
= os_snprintf(pos
, end
- pos
, "\n");
2391 if (ret
< 0 || ret
>= end
- pos
)
2397 #endif /* CONFIG_INTERWORKING */
2400 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
2401 unsigned long mask
, char *buf
, size_t buflen
)
2411 if (mask
& WPA_BSS_MASK_ID
) {
2412 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
2413 if (ret
< 0 || ret
>= end
- pos
)
2418 if (mask
& WPA_BSS_MASK_BSSID
) {
2419 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2420 MAC2STR(bss
->bssid
));
2421 if (ret
< 0 || ret
>= end
- pos
)
2426 if (mask
& WPA_BSS_MASK_FREQ
) {
2427 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
2428 if (ret
< 0 || ret
>= end
- pos
)
2433 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
2434 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
2436 if (ret
< 0 || ret
>= end
- pos
)
2441 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
2442 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
2444 if (ret
< 0 || ret
>= end
- pos
)
2449 if (mask
& WPA_BSS_MASK_QUAL
) {
2450 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
2451 if (ret
< 0 || ret
>= end
- pos
)
2456 if (mask
& WPA_BSS_MASK_NOISE
) {
2457 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
2458 if (ret
< 0 || ret
>= end
- pos
)
2463 if (mask
& WPA_BSS_MASK_LEVEL
) {
2464 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
2465 if (ret
< 0 || ret
>= end
- pos
)
2470 if (mask
& WPA_BSS_MASK_TSF
) {
2471 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
2472 (unsigned long long) bss
->tsf
);
2473 if (ret
< 0 || ret
>= end
- pos
)
2478 if (mask
& WPA_BSS_MASK_AGE
) {
2482 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
2483 (int) (now
.sec
- bss
->last_update
.sec
));
2484 if (ret
< 0 || ret
>= end
- pos
)
2489 if (mask
& WPA_BSS_MASK_IE
) {
2490 ret
= os_snprintf(pos
, end
- pos
, "ie=");
2491 if (ret
< 0 || ret
>= end
- pos
)
2495 ie
= (const u8
*) (bss
+ 1);
2496 for (i
= 0; i
< bss
->ie_len
; i
++) {
2497 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
2498 if (ret
< 0 || ret
>= end
- pos
)
2503 ret
= os_snprintf(pos
, end
- pos
, "\n");
2504 if (ret
< 0 || ret
>= end
- pos
)
2509 if (mask
& WPA_BSS_MASK_FLAGS
) {
2510 ret
= os_snprintf(pos
, end
- pos
, "flags=");
2511 if (ret
< 0 || ret
>= end
- pos
)
2515 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2517 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
2519 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2521 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
2523 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2524 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2525 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2526 if (ret
< 0 || ret
>= end
- pos
)
2530 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2531 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2532 if (ret
< 0 || ret
>= end
- pos
)
2536 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2537 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2538 if (ret
< 0 || ret
>= end
- pos
)
2542 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
)) {
2543 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2544 if (ret
< 0 || ret
>= end
- pos
)
2549 ret
= os_snprintf(pos
, end
- pos
, "\n");
2550 if (ret
< 0 || ret
>= end
- pos
)
2555 if (mask
& WPA_BSS_MASK_SSID
) {
2556 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
2557 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2558 if (ret
< 0 || ret
>= end
- pos
)
2564 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
2565 ie
= (const u8
*) (bss
+ 1);
2566 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2567 if (ret
< 0 || ret
>= end
- pos
)
2571 #endif /* CONFIG_WPS */
2574 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
2575 ie
= (const u8
*) (bss
+ 1);
2576 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2577 if (ret
< 0 || ret
>= end
- pos
)
2581 #endif /* CONFIG_P2P */
2583 #ifdef CONFIG_INTERWORKING
2584 if (mask
& WPA_BSS_MASK_INTERNETW
) {
2585 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
2586 bss
->anqp_venue_name
);
2587 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
2588 bss
->anqp_network_auth_type
);
2589 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
2590 bss
->anqp_roaming_consortium
);
2591 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
2592 bss
->anqp_ip_addr_type_availability
);
2593 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
2594 bss
->anqp_nai_realm
);
2595 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", bss
->anqp_3gpp
);
2596 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
2597 bss
->anqp_domain_name
);
2599 #endif /* CONFIG_INTERWORKING */
2605 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
2606 const char *cmd
, char *buf
,
2611 struct wpa_bss
*bss
;
2612 struct wpa_bss
*bsslast
= NULL
;
2613 struct dl_list
*next
;
2617 unsigned long mask
= WPA_BSS_MASK_ALL
;
2619 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
2620 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
2621 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
2623 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
2625 } else { /* N1-N2 */
2626 unsigned int id1
, id2
;
2628 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
2629 wpa_printf(MSG_INFO
, "Wrong BSS range "
2634 id1
= atoi(cmd
+ 6);
2635 bss
= wpa_bss_get_id(wpa_s
, id1
);
2636 id2
= atoi(ctmp
+ 1);
2638 bsslast
= dl_list_last(&wpa_s
->bss_id
,
2642 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
2643 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
2644 struct wpa_bss
*tmp
= bss
;
2646 next
= tmp
->list_id
.next
;
2647 if (next
== &wpa_s
->bss_id
)
2649 tmp
= dl_list_entry(
2650 next
, struct wpa_bss
,
2659 } else if (os_strcmp(cmd
, "FIRST") == 0)
2660 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
2661 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
2663 bss
= wpa_bss_get_id(wpa_s
, i
);
2664 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
2666 bss
= wpa_bss_get_id(wpa_s
, i
);
2668 next
= bss
->list_id
.next
;
2669 if (next
== &wpa_s
->bss_id
)
2672 bss
= dl_list_entry(next
, struct wpa_bss
,
2676 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
2677 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
2678 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
2681 #endif /* CONFIG_P2P */
2682 } else if (hwaddr_aton(cmd
, bssid
) == 0)
2683 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2685 struct wpa_bss
*tmp
;
2688 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
2697 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
2698 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
2700 mask
= WPA_BSS_MASK_ALL
;
2706 if (bsslast
== NULL
)
2709 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
2715 next
= bss
->list_id
.next
;
2716 if (next
== &wpa_s
->bss_id
)
2718 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
2719 } while (bss
&& len
);
2725 static int wpa_supplicant_ctrl_iface_ap_scan(
2726 struct wpa_supplicant
*wpa_s
, char *cmd
)
2728 int ap_scan
= atoi(cmd
);
2729 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
2733 static int wpa_supplicant_ctrl_iface_scan_interval(
2734 struct wpa_supplicant
*wpa_s
, char *cmd
)
2736 int scan_int
= atoi(cmd
);
2737 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
2741 static int wpa_supplicant_ctrl_iface_bss_expire_age(
2742 struct wpa_supplicant
*wpa_s
, char *cmd
)
2744 int expire_age
= atoi(cmd
);
2745 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
2749 static int wpa_supplicant_ctrl_iface_bss_expire_count(
2750 struct wpa_supplicant
*wpa_s
, char *cmd
)
2752 int expire_count
= atoi(cmd
);
2753 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
2757 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
2759 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
2760 /* MLME-DELETEKEYS.request */
2761 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
2762 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
2763 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
2764 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
2765 #ifdef CONFIG_IEEE80211W
2766 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
2767 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
2768 #endif /* CONFIG_IEEE80211W */
2770 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
2772 /* MLME-SETPROTECTION.request(None) */
2773 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
2774 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
2775 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
2776 wpa_sm_drop_sa(wpa_s
->wpa
);
2780 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
2783 #ifdef CONFIG_NO_SCAN_PROCESSING
2785 #else /* CONFIG_NO_SCAN_PROCESSING */
2787 struct wpa_bss
*bss
;
2788 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2790 if (hwaddr_aton(addr
, bssid
)) {
2791 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
2792 "address '%s'", addr
);
2796 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
2798 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2800 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
2806 * TODO: Find best network configuration block from configuration to
2807 * allow roaming to other networks
2811 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
2812 "configuration known for the target AP");
2816 wpa_s
->reassociate
= 1;
2817 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
2820 #endif /* CONFIG_NO_SCAN_PROCESSING */
2825 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
2827 unsigned int timeout
= atoi(cmd
);
2828 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
2829 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
2832 if (os_strstr(cmd
, "type=social"))
2833 type
= P2P_FIND_ONLY_SOCIAL
;
2834 else if (os_strstr(cmd
, "type=progressive"))
2835 type
= P2P_FIND_PROGRESSIVE
;
2837 pos
= os_strstr(cmd
, "dev_id=");
2840 if (hwaddr_aton(pos
, dev_id
))
2845 return wpas_p2p_find(wpa_s
, timeout
, type
, 0, NULL
, _dev_id
);
2849 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
2850 char *buf
, size_t buflen
)
2855 enum p2p_wps_method wps_method
;
2858 int persistent_group
, persistent_id
= -1;
2865 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
2866 * [persistent|persistent=<network id>]
2867 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */
2869 if (hwaddr_aton(cmd
, addr
))
2877 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
2878 pos2
= os_strstr(pos
, " persistent=");
2880 struct wpa_ssid
*ssid
;
2881 persistent_id
= atoi(pos2
+ 12);
2882 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
2883 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
2884 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
2885 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2886 "SSID id=%d for persistent P2P group (GO)",
2891 join
= os_strstr(pos
, " join") != NULL
;
2892 auth
= os_strstr(pos
, " auth") != NULL
;
2893 automatic
= os_strstr(pos
, " auto") != NULL
;
2895 pos2
= os_strstr(pos
, " go_intent=");
2898 go_intent
= atoi(pos2
);
2899 if (go_intent
< 0 || go_intent
> 15)
2903 pos2
= os_strstr(pos
, " freq=");
2911 if (os_strncmp(pos
, "pin", 3) == 0) {
2912 /* Request random PIN (to be displayed) and enable the PIN */
2913 wps_method
= WPS_PIN_DISPLAY
;
2914 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
2915 wps_method
= WPS_PBC
;
2918 pos
= os_strchr(pin
, ' ');
2919 wps_method
= WPS_PIN_KEYPAD
;
2922 if (os_strncmp(pos
, "display", 7) == 0)
2923 wps_method
= WPS_PIN_DISPLAY
;
2927 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
2928 persistent_group
, automatic
, join
,
2929 auth
, go_intent
, freq
, persistent_id
);
2930 if (new_pin
== -2) {
2931 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
2934 if (new_pin
== -3) {
2935 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
2940 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
2941 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
2942 if (ret
< 0 || (size_t) ret
>= buflen
)
2947 os_memcpy(buf
, "OK\n", 3);
2952 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
2954 unsigned int timeout
= atoi(cmd
);
2955 return wpas_p2p_listen(wpa_s
, timeout
);
2959 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
2963 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
2965 /* <addr> <config method> [join|auto] */
2967 if (hwaddr_aton(cmd
, addr
))
2975 if (os_strstr(pos
, " join") != NULL
)
2976 use
= WPAS_P2P_PD_FOR_JOIN
;
2977 else if (os_strstr(pos
, " auto") != NULL
)
2978 use
= WPAS_P2P_PD_AUTO
;
2980 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
2984 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
2987 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2989 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
2990 ssid
->passphrase
== NULL
)
2993 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
2994 return os_strlen(buf
);
2998 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
2999 char *buf
, size_t buflen
)
3003 u8 dst_buf
[ETH_ALEN
], *dst
;
3004 struct wpabuf
*tlvs
;
3008 if (hwaddr_aton(cmd
, dst_buf
))
3011 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
3012 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
3019 if (os_strncmp(pos
, "upnp ", 5) == 0) {
3022 if (hexstr2bin(pos
, &version
, 1) < 0)
3028 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
3030 len
= os_strlen(pos
);
3034 tlvs
= wpabuf_alloc(len
);
3037 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
3042 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
3047 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
3048 if (res
< 0 || (unsigned) res
>= buflen
)
3054 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
3057 long long unsigned val
;
3059 if (sscanf(cmd
, "%llx", &val
) != 1)
3062 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
3066 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3071 struct wpabuf
*resp_tlvs
;
3075 pos
= os_strchr(cmd
, ' ');
3083 if (hwaddr_aton(pos
, dst
))
3090 pos2
= os_strchr(pos
, ' ');
3094 dialog_token
= atoi(pos
);
3096 len
= os_strlen(pos2
);
3100 resp_tlvs
= wpabuf_alloc(len
);
3101 if (resp_tlvs
== NULL
)
3103 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
3104 wpabuf_free(resp_tlvs
);
3108 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
3109 wpabuf_free(resp_tlvs
);
3114 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
3117 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
3119 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
3124 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
3129 struct wpabuf
*query
, *resp
;
3131 pos
= os_strchr(cmd
, ' ');
3136 len
= os_strlen(cmd
);
3140 query
= wpabuf_alloc(len
);
3143 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3148 len
= os_strlen(pos
);
3154 resp
= wpabuf_alloc(len
);
3159 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
3165 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
3174 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3179 pos
= os_strchr(cmd
, ' ');
3184 if (hexstr2bin(cmd
, &version
, 1) < 0)
3187 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
3191 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3195 pos
= os_strchr(cmd
, ' ');
3200 if (os_strcmp(cmd
, "bonjour") == 0)
3201 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
3202 if (os_strcmp(cmd
, "upnp") == 0)
3203 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
3204 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3209 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
3213 struct wpabuf
*query
;
3216 len
= os_strlen(cmd
);
3220 query
= wpabuf_alloc(len
);
3223 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3228 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
3234 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3239 pos
= os_strchr(cmd
, ' ');
3244 if (hexstr2bin(cmd
, &version
, 1) < 0)
3247 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
3251 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
3255 pos
= os_strchr(cmd
, ' ');
3260 if (os_strcmp(cmd
, "bonjour") == 0)
3261 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
3262 if (os_strcmp(cmd
, "upnp") == 0)
3263 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
3264 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3269 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
3275 if (hwaddr_aton(cmd
, addr
))
3278 return wpas_p2p_reject(wpa_s
, addr
);
3282 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
3286 struct wpa_ssid
*ssid
;
3290 pos
= os_strstr(cmd
, " peer=");
3293 if (hwaddr_aton(pos
, peer
))
3296 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3297 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3298 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3299 "for persistent P2P group",
3304 return wpas_p2p_invite(wpa_s
, pos
? peer
: NULL
, ssid
, NULL
);
3308 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
3311 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
3313 pos
= os_strstr(cmd
, " peer=");
3319 if (hwaddr_aton(pos
, peer
)) {
3320 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
3324 pos
= os_strstr(pos
, " go_dev_addr=");
3327 if (hwaddr_aton(pos
, go_dev_addr
)) {
3328 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
3332 go_dev
= go_dev_addr
;
3335 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
3339 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
3341 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3342 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
3343 if (os_strncmp(cmd
, "group=", 6) == 0)
3344 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
3350 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
3351 char *cmd
, int freq
)
3354 struct wpa_ssid
*ssid
;
3357 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3358 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3359 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3360 "for persistent P2P group",
3365 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
);
3369 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3374 pos
= os_strstr(cmd
, "freq=");
3376 freq
= atoi(pos
+ 5);
3378 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3379 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
);
3380 if (os_strcmp(cmd
, "persistent") == 0 ||
3381 os_strncmp(cmd
, "persistent ", 11) == 0)
3382 return wpas_p2p_group_add(wpa_s
, 1, freq
);
3383 if (os_strncmp(cmd
, "freq=", 5) == 0)
3384 return wpas_p2p_group_add(wpa_s
, 0, freq
);
3386 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3392 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
3393 char *buf
, size_t buflen
)
3395 u8 addr
[ETH_ALEN
], *addr_ptr
;
3397 const struct p2p_peer_info
*info
;
3399 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
3400 struct wpa_ssid
*ssid
;
3402 if (!wpa_s
->global
->p2p
)
3405 if (os_strcmp(cmd
, "FIRST") == 0) {
3408 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3409 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
3414 if (hwaddr_aton(cmd
, addr
) < 0)
3420 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
3427 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
3433 "serial_number=%s\n"
3434 "config_methods=0x%x\n"
3436 "group_capab=0x%x\n"
3438 MAC2STR(info
->p2p_device_addr
),
3439 wps_dev_type_bin2str(info
->pri_dev_type
,
3440 devtype
, sizeof(devtype
)),
3445 info
->serial_number
,
3446 info
->config_methods
,
3450 if (res
< 0 || res
>= end
- pos
)
3454 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
3456 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
3457 if (res
< 0 || res
>= end
- pos
)
3462 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
3471 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
3474 struct wpa_freq_range
*freq
= NULL
, *n
;
3475 unsigned int count
= 0, i
;
3476 const char *pos
, *pos2
, *pos3
;
3478 if (wpa_s
->global
->p2p
== NULL
)
3482 * param includes comma separated frequency range.
3483 * For example: 2412-2432,2462,5000-6000
3486 while (pos
&& pos
[0]) {
3487 n
= os_realloc(freq
,
3488 (count
+ 1) * sizeof(struct wpa_freq_range
));
3494 freq
[count
].min
= atoi(pos
);
3495 pos2
= os_strchr(pos
, '-');
3496 pos3
= os_strchr(pos
, ',');
3497 if (pos2
&& (!pos3
|| pos2
< pos3
)) {
3499 freq
[count
].max
= atoi(pos2
);
3501 freq
[count
].max
= freq
[count
].min
;
3508 for (i
= 0; i
< count
; i
++) {
3509 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
3510 freq
[i
].min
, freq
[i
].max
);
3513 os_free(wpa_s
->global
->p2p_disallow_freq
);
3514 wpa_s
->global
->p2p_disallow_freq
= freq
;
3515 wpa_s
->global
->num_p2p_disallow_freq
= count
;
3516 wpas_p2p_update_channel_list(wpa_s
);
3521 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
3525 if (wpa_s
->global
->p2p
== NULL
)
3528 param
= os_strchr(cmd
, ' ');
3533 if (os_strcmp(cmd
, "discoverability") == 0) {
3534 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
3539 if (os_strcmp(cmd
, "managed") == 0) {
3540 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
3544 if (os_strcmp(cmd
, "listen_channel") == 0) {
3545 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
3549 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
3550 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
3554 if (os_strcmp(cmd
, "noa") == 0) {
3556 int count
, start
, duration
;
3557 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
3558 count
= atoi(param
);
3559 pos
= os_strchr(param
, ',');
3564 pos
= os_strchr(pos
, ',');
3568 duration
= atoi(pos
);
3569 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
3571 if (count
== 0 && duration
> 0)
3573 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
3574 "start=%d duration=%d", count
, start
, duration
);
3575 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
3578 if (os_strcmp(cmd
, "ps") == 0)
3579 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
3581 if (os_strcmp(cmd
, "oppps") == 0)
3582 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
3584 if (os_strcmp(cmd
, "ctwindow") == 0)
3585 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
3587 if (os_strcmp(cmd
, "disabled") == 0) {
3588 wpa_s
->global
->p2p_disabled
= atoi(param
);
3589 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
3590 wpa_s
->global
->p2p_disabled
?
3591 "disabled" : "enabled");
3592 if (wpa_s
->global
->p2p_disabled
) {
3593 wpas_p2p_stop_find(wpa_s
);
3594 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
3595 p2p_flush(wpa_s
->global
->p2p
);
3600 if (os_strcmp(cmd
, "force_long_sd") == 0) {
3601 wpa_s
->force_long_sd
= atoi(param
);
3605 if (os_strcmp(cmd
, "peer_filter") == 0) {
3607 if (hwaddr_aton(param
, addr
))
3609 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
3613 if (os_strcmp(cmd
, "cross_connect") == 0)
3614 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
3616 if (os_strcmp(cmd
, "go_apsd") == 0) {
3617 if (os_strcmp(param
, "disable") == 0)
3618 wpa_s
->set_ap_uapsd
= 0;
3620 wpa_s
->set_ap_uapsd
= 1;
3621 wpa_s
->ap_uapsd
= atoi(param
);
3626 if (os_strcmp(cmd
, "client_apsd") == 0) {
3627 if (os_strcmp(param
, "disable") == 0)
3628 wpa_s
->set_sta_uapsd
= 0;
3632 /* format: BE,BK,VI,VO;max SP Length */
3634 pos
= os_strchr(param
, ',');
3639 pos
= os_strchr(pos
, ',');
3644 pos
= os_strchr(pos
, ',');
3649 /* ignore max SP Length for now */
3651 wpa_s
->set_sta_uapsd
= 1;
3652 wpa_s
->sta_uapsd
= 0;
3654 wpa_s
->sta_uapsd
|= BIT(0);
3656 wpa_s
->sta_uapsd
|= BIT(1);
3658 wpa_s
->sta_uapsd
|= BIT(2);
3660 wpa_s
->sta_uapsd
|= BIT(3);
3665 if (os_strcmp(cmd
, "disallow_freq") == 0)
3666 return p2p_ctrl_disallow_freq(wpa_s
, param
);
3668 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
3675 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
3678 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
3681 pos
= os_strchr(cmd
, ' ');
3687 pos2
= os_strchr(pos
, ' ');
3695 pos
= os_strchr(pos2
, ' ');
3703 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
3707 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3710 unsigned int period
= 0, interval
= 0;
3713 pos
= os_strchr(cmd
, ' ');
3718 interval
= atoi(pos
);
3721 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
3724 #endif /* CONFIG_P2P */
3727 #ifdef CONFIG_INTERWORKING
3728 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
3731 struct wpa_bss
*bss
;
3733 if (hwaddr_aton(dst
, bssid
)) {
3734 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
3738 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3740 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
3745 return interworking_connect(wpa_s
, bss
);
3749 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
3751 u8 dst_addr
[ETH_ALEN
];
3754 #define MAX_ANQP_INFO_ID 100
3755 u16 id
[MAX_ANQP_INFO_ID
];
3758 used
= hwaddr_aton2(dst
, dst_addr
);
3762 while (num_id
< MAX_ANQP_INFO_ID
) {
3763 id
[num_id
] = atoi(pos
);
3766 pos
= os_strchr(pos
+ 1, ',');
3775 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
);
3777 #endif /* CONFIG_INTERWORKING */
3780 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
3781 struct wpa_supplicant
*wpa_s
, char *cmd
)
3783 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
3788 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
3791 struct wpa_signal_info si
;
3794 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
3798 ret
= os_snprintf(buf
, buflen
, "RSSI=%d\nLINKSPEED=%d\n"
3799 "NOISE=%d\nFREQUENCY=%u\n",
3800 si
.current_signal
, si
.current_txrate
/ 1000,
3801 si
.current_noise
, si
.frequency
);
3802 if (ret
< 0 || (unsigned int) ret
> buflen
)
3808 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
3809 char *buf
, size_t *resp_len
)
3812 const int reply_size
= 4096;
3816 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
3817 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
3818 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
3819 (const u8
*) buf
, os_strlen(buf
));
3821 int level
= MSG_DEBUG
;
3822 if (os_strcmp(buf
, "PING") == 0)
3823 level
= MSG_EXCESSIVE
;
3824 wpa_hexdump_ascii(level
, "RX ctrl_iface",
3825 (const u8
*) buf
, os_strlen(buf
));
3828 reply
= os_malloc(reply_size
);
3829 if (reply
== NULL
) {
3834 os_memcpy(reply
, "OK\n", 3);
3837 if (os_strcmp(buf
, "PING") == 0) {
3838 os_memcpy(reply
, "PONG\n", 5);
3840 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3841 if (wpa_debug_reopen_file() < 0)
3843 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3844 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3845 } else if (os_strcmp(buf
, "MIB") == 0) {
3846 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
3847 if (reply_len
>= 0) {
3849 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
3850 reply_size
- reply_len
);
3856 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
3857 reply_len
= wpa_supplicant_ctrl_iface_status(
3858 wpa_s
, buf
+ 6, reply
, reply_size
);
3859 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3860 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
3862 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3863 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
3865 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3866 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
3868 } else if (os_strcmp(buf
, "LOGON") == 0) {
3869 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
3870 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
3871 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
3872 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
3873 wpa_s
->normal_scans
= 0;
3874 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3877 wpa_s
->disconnected
= 0;
3878 wpa_s
->reassociate
= 1;
3879 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3881 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
3882 wpa_s
->normal_scans
= 0;
3883 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3885 else if (wpa_s
->disconnected
) {
3886 wpa_s
->disconnected
= 0;
3887 wpa_s
->reassociate
= 1;
3888 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3890 #ifdef IEEE8021X_EAPOL
3891 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
3892 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
3894 #endif /* IEEE8021X_EAPOL */
3895 #ifdef CONFIG_PEERKEY
3896 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
3897 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
3899 #endif /* CONFIG_PEERKEY */
3900 #ifdef CONFIG_IEEE80211R
3901 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
3902 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
3904 #endif /* CONFIG_IEEE80211R */
3906 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
3907 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
3909 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3913 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
3914 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
3916 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3920 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
3921 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
3924 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
3925 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
3926 wpa_s
, buf
+ 14, reply
, reply_size
);
3927 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
3928 if (wpas_wps_cancel(wpa_s
))
3930 #ifdef CONFIG_WPS_OOB
3931 } else if (os_strncmp(buf
, "WPS_OOB ", 8) == 0) {
3932 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s
, buf
+ 8))
3934 #endif /* CONFIG_WPS_OOB */
3935 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
3936 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
3939 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
3940 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
3941 wpa_s
, buf
+ 11, reply
, reply_size
);
3942 #endif /* CONFIG_AP */
3943 #ifdef CONFIG_WPS_ER
3944 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
3945 if (wpas_wps_er_start(wpa_s
, NULL
))
3947 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
3948 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
3950 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
3951 if (wpas_wps_er_stop(wpa_s
))
3953 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
3954 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
3956 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
3957 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
3959 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3961 } else if (ret
== -3) {
3962 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
3964 } else if (ret
== -4) {
3965 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
3969 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
3970 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
3972 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
3973 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
3976 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
3977 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
3979 #endif /* CONFIG_WPS_ER */
3980 #endif /* CONFIG_WPS */
3981 #ifdef CONFIG_IBSS_RSN
3982 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
3983 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
3985 #endif /* CONFIG_IBSS_RSN */
3987 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
3988 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
3990 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
3991 if (p2p_ctrl_find(wpa_s
, ""))
3993 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
3994 wpas_p2p_stop_find(wpa_s
);
3995 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
3996 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
3998 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
3999 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
4001 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
4002 if (p2p_ctrl_listen(wpa_s
, ""))
4004 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
4005 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
4007 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
4008 if (wpas_p2p_group_add(wpa_s
, 0, 0))
4010 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
4011 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
4013 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
4014 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
4016 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
4017 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
4018 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
4019 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
4021 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
4022 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
4024 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
4025 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
4027 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
4028 wpas_p2p_sd_service_update(wpa_s
);
4029 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
4030 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
4032 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
4033 wpas_p2p_service_flush(wpa_s
);
4034 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
4035 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
4037 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
4038 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
4040 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
4041 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
4043 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
4044 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
4046 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
4047 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
4049 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
4050 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
4052 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
4053 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4054 wpa_s
->force_long_sd
= 0;
4055 if (wpa_s
->global
->p2p
)
4056 p2p_flush(wpa_s
->global
->p2p
);
4057 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
4058 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
4060 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
4061 if (wpas_p2p_cancel(wpa_s
))
4063 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
4064 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
4066 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
4067 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
4069 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
4070 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
4072 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
4073 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
4075 #endif /* CONFIG_P2P */
4076 #ifdef CONFIG_INTERWORKING
4077 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
4078 if (interworking_fetch_anqp(wpa_s
) < 0)
4080 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
4081 interworking_stop_fetch_anqp(wpa_s
);
4082 } else if (os_strncmp(buf
, "INTERWORKING_SELECT", 19) == 0) {
4083 if (interworking_select(wpa_s
, os_strstr(buf
+ 19, "auto") !=
4086 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
4087 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
4089 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
4090 if (get_anqp(wpa_s
, buf
+ 9) < 0)
4092 #endif /* CONFIG_INTERWORKING */
4093 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
4095 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
4096 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
4100 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
4101 if (wpa_supplicant_reload_configuration(wpa_s
))
4103 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4104 wpa_supplicant_terminate_proc(wpa_s
->global
);
4105 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
4106 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
4108 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
4109 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
4110 wpa_s
, buf
+ 9, reply
, reply_size
);
4111 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
4112 reply_len
= wpa_supplicant_ctrl_iface_log_level(
4113 wpa_s
, buf
+ 9, reply
, reply_size
);
4114 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
4115 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
4116 wpa_s
, reply
, reply_size
);
4117 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
4119 wpa_s
->sme
.prev_bssid_set
= 0;
4120 #endif /* CONFIG_SME */
4121 wpa_s
->reassociate
= 0;
4122 wpa_s
->disconnected
= 1;
4123 wpa_supplicant_cancel_sched_scan(wpa_s
);
4124 wpa_supplicant_deauthenticate(wpa_s
,
4125 WLAN_REASON_DEAUTH_LEAVING
);
4126 } else if (os_strcmp(buf
, "SCAN") == 0) {
4127 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4130 if (!wpa_s
->scanning
&&
4131 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
4132 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
4133 wpa_s
->normal_scans
= 0;
4134 wpa_s
->scan_req
= 2;
4135 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4136 } else if (wpa_s
->sched_scanning
) {
4137 wpa_printf(MSG_DEBUG
, "Stop ongoing "
4138 "sched_scan to allow requested "
4139 "full scan to proceed");
4140 wpa_supplicant_cancel_sched_scan(wpa_s
);
4141 wpa_s
->scan_req
= 2;
4142 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4144 wpa_printf(MSG_DEBUG
, "Ongoing scan action - "
4145 "reject new request");
4146 reply_len
= os_snprintf(reply
, reply_size
,
4150 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
4151 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
4152 wpa_s
, reply
, reply_size
);
4153 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
4154 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
4156 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
4157 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
4159 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
4160 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
4162 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
4163 reply_len
= wpa_supplicant_ctrl_iface_add_network(
4164 wpa_s
, reply
, reply_size
);
4165 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
4166 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
4168 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
4169 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
4171 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
4172 reply_len
= wpa_supplicant_ctrl_iface_get_network(
4173 wpa_s
, buf
+ 12, reply
, reply_size
);
4174 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
4175 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
4176 wpa_s
, reply
, reply_size
);
4177 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
4178 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
4179 wpa_s
, reply
, reply_size
);
4180 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
4181 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
4183 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
4184 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
4186 #ifndef CONFIG_NO_CONFIG_WRITE
4187 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
4188 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
4190 #endif /* CONFIG_NO_CONFIG_WRITE */
4191 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
4192 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
4193 wpa_s
, buf
+ 15, reply
, reply_size
);
4194 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
4195 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
4197 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
4198 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
4200 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
4201 reply_len
= wpa_supplicant_global_iface_list(
4202 wpa_s
->global
, reply
, reply_size
);
4203 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
4204 reply_len
= wpa_supplicant_global_iface_interfaces(
4205 wpa_s
->global
, reply
, reply_size
);
4206 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
4207 reply_len
= wpa_supplicant_ctrl_iface_bss(
4208 wpa_s
, buf
+ 4, reply
, reply_size
);
4210 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
4211 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
4212 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
4213 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
4215 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
4216 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
4218 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
4219 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
4221 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
4222 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
4224 #endif /* CONFIG_AP */
4225 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
4226 wpas_notify_suspend(wpa_s
->global
);
4227 } else if (os_strcmp(buf
, "RESUME") == 0) {
4228 wpas_notify_resume(wpa_s
->global
);
4229 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
4230 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
4231 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
4232 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
4234 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
4235 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
4237 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
4238 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
4240 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
4241 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
4245 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
4246 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
4248 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
4249 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
4251 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
4252 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
4254 #endif /* CONFIG_TDLS */
4255 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
4256 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
4258 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
4259 eapol_sm_request_reauth(wpa_s
->eapol
);
4261 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4265 if (reply_len
< 0) {
4266 os_memcpy(reply
, "FAIL\n", 5);
4271 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
4273 *resp_len
= reply_len
;
4278 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
4281 struct wpa_interface iface
;
4285 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
4286 * TAB<bridge_ifname>
4288 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
4290 os_memset(&iface
, 0, sizeof(iface
));
4293 iface
.ifname
= pos
= cmd
;
4294 pos
= os_strchr(pos
, '\t');
4297 if (iface
.ifname
[0] == '\0')
4302 iface
.confname
= pos
;
4303 pos
= os_strchr(pos
, '\t');
4306 if (iface
.confname
[0] == '\0')
4307 iface
.confname
= NULL
;
4312 pos
= os_strchr(pos
, '\t');
4315 if (iface
.driver
[0] == '\0')
4316 iface
.driver
= NULL
;
4320 iface
.ctrl_interface
= pos
;
4321 pos
= os_strchr(pos
, '\t');
4324 if (iface
.ctrl_interface
[0] == '\0')
4325 iface
.ctrl_interface
= NULL
;
4329 iface
.driver_param
= pos
;
4330 pos
= os_strchr(pos
, '\t');
4333 if (iface
.driver_param
[0] == '\0')
4334 iface
.driver_param
= NULL
;
4338 iface
.bridge_ifname
= pos
;
4339 pos
= os_strchr(pos
, '\t');
4342 if (iface
.bridge_ifname
[0] == '\0')
4343 iface
.bridge_ifname
= NULL
;
4348 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
4351 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
4355 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
4358 struct wpa_supplicant
*wpa_s
;
4360 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
4362 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
4365 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
4369 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
4371 struct wpa_interface_info
*prev
;
4375 iface
= iface
->next
;
4377 os_free(prev
->ifname
);
4378 os_free(prev
->desc
);
4384 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
4388 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
4391 for (i
= 0; wpa_drivers
[i
]; i
++) {
4392 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
4393 if (drv
->get_interfaces
== NULL
)
4395 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
4409 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
4410 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
4411 tmp
->drv_name
, tmp
->ifname
,
4412 tmp
->desc
? tmp
->desc
: "");
4413 if (res
< 0 || res
>= end
- pos
) {
4420 wpa_free_iface_info(iface
);
4426 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
4431 struct wpa_supplicant
*wpa_s
;
4433 wpa_s
= global
->ifaces
;
4438 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
4439 if (res
< 0 || res
>= end
- pos
) {
4444 wpa_s
= wpa_s
->next
;
4450 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
4451 char *buf
, size_t *resp_len
)
4454 const int reply_size
= 2048;
4456 int level
= MSG_DEBUG
;
4458 if (os_strcmp(buf
, "PING") == 0)
4459 level
= MSG_EXCESSIVE
;
4460 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
4461 (const u8
*) buf
, os_strlen(buf
));
4463 reply
= os_malloc(reply_size
);
4464 if (reply
== NULL
) {
4469 os_memcpy(reply
, "OK\n", 3);
4472 if (os_strcmp(buf
, "PING") == 0) {
4473 os_memcpy(reply
, "PONG\n", 5);
4475 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
4476 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
4478 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
4479 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
4481 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
4482 reply_len
= wpa_supplicant_global_iface_list(
4483 global
, reply
, reply_size
);
4484 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
4485 reply_len
= wpa_supplicant_global_iface_interfaces(
4486 global
, reply
, reply_size
);
4487 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4488 wpa_supplicant_terminate_proc(global
);
4489 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
4490 wpas_notify_suspend(global
);
4491 } else if (os_strcmp(buf
, "RESUME") == 0) {
4492 wpas_notify_resume(global
);
4494 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4498 if (reply_len
< 0) {
4499 os_memcpy(reply
, "FAIL\n", 5);
4503 *resp_len
= reply_len
;