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
))
129 n
= os_realloc(filter
, (count
+ 1) * ETH_ALEN
);
135 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
138 pos
= os_strchr(pos
, ' ');
143 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
144 os_free(wpa_s
->bssid_filter
);
145 wpa_s
->bssid_filter
= filter
;
146 wpa_s
->bssid_filter_count
= count
;
152 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
158 value
= os_strchr(cmd
, ' ');
163 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
164 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
165 eapol_sm_configure(wpa_s
->eapol
,
166 atoi(value
), -1, -1, -1);
167 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
168 eapol_sm_configure(wpa_s
->eapol
,
169 -1, atoi(value
), -1, -1);
170 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
171 eapol_sm_configure(wpa_s
->eapol
,
172 -1, -1, atoi(value
), -1);
173 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
174 eapol_sm_configure(wpa_s
->eapol
,
175 -1, -1, -1, atoi(value
));
176 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
177 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
180 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
182 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
185 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
186 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
188 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
189 wpa_s
->wps_fragment_size
= atoi(value
);
190 #ifdef CONFIG_WPS_TESTING
191 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
193 val
= strtol(value
, NULL
, 0);
194 if (val
< 0 || val
> 0xff) {
196 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
197 "wps_version_number %ld", val
);
199 wps_version_number
= val
;
200 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
202 (wps_version_number
& 0xf0) >> 4,
203 wps_version_number
& 0x0f);
205 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
206 wps_testing_dummy_cred
= atoi(value
);
207 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
208 wps_testing_dummy_cred
);
209 #endif /* CONFIG_WPS_TESTING */
210 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
211 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
213 #ifdef CONFIG_TDLS_TESTING
214 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
215 extern unsigned int tdls_testing
;
216 tdls_testing
= strtol(value
, NULL
, 0);
217 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
218 #endif /* CONFIG_TDLS_TESTING */
220 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
221 int disabled
= atoi(value
);
222 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
224 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
226 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
228 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
229 #endif /* CONFIG_TDLS */
230 } else if (os_strcasecmp(cmd
, "pno") == 0) {
232 ret
= pno_start(wpa_s
);
234 ret
= pno_stop(wpa_s
);
235 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
236 int disabled
= atoi(value
);
237 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
240 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
241 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
242 if (os_strcmp(value
, "disable") == 0)
243 wpa_s
->set_sta_uapsd
= 0;
247 /* format: BE,BK,VI,VO;max SP Length */
249 pos
= os_strchr(value
, ',');
254 pos
= os_strchr(pos
, ',');
259 pos
= os_strchr(pos
, ',');
264 /* ignore max SP Length for now */
266 wpa_s
->set_sta_uapsd
= 1;
267 wpa_s
->sta_uapsd
= 0;
269 wpa_s
->sta_uapsd
|= BIT(0);
271 wpa_s
->sta_uapsd
|= BIT(1);
273 wpa_s
->sta_uapsd
|= BIT(2);
275 wpa_s
->sta_uapsd
|= BIT(3);
277 } else if (os_strcasecmp(cmd
, "ps") == 0) {
278 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
279 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
280 ret
= set_bssid_filter(wpa_s
, value
);
283 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
285 wpa_supplicant_update_config(wpa_s
);
292 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
293 char *cmd
, char *buf
, size_t buflen
)
297 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
299 if (os_strcmp(cmd
, "version") == 0) {
300 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
301 } else if (os_strcasecmp(cmd
, "country") == 0) {
302 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
303 res
= os_snprintf(buf
, buflen
, "%c%c",
304 wpa_s
->conf
->country
[0],
305 wpa_s
->conf
->country
[1]);
308 if (res
< 0 || (unsigned int) res
>= buflen
)
314 #ifdef IEEE8021X_EAPOL
315 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
319 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
321 if (hwaddr_aton(addr
, bssid
)) {
322 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
327 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
328 rsn_preauth_deinit(wpa_s
->wpa
);
329 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
334 #endif /* IEEE8021X_EAPOL */
337 #ifdef CONFIG_PEERKEY
338 /* MLME-STKSTART.request(peer) */
339 static int wpa_supplicant_ctrl_iface_stkstart(
340 struct wpa_supplicant
*wpa_s
, char *addr
)
344 if (hwaddr_aton(addr
, peer
)) {
345 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
346 "address '%s'", addr
);
350 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
353 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
355 #endif /* CONFIG_PEERKEY */
360 static int wpa_supplicant_ctrl_iface_tdls_discover(
361 struct wpa_supplicant
*wpa_s
, char *addr
)
366 if (hwaddr_aton(addr
, peer
)) {
367 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
368 "address '%s'", addr
);
372 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
375 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
376 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
378 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
384 static int wpa_supplicant_ctrl_iface_tdls_setup(
385 struct wpa_supplicant
*wpa_s
, char *addr
)
390 if (hwaddr_aton(addr
, peer
)) {
391 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
392 "address '%s'", addr
);
396 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
399 ret
= wpa_tdls_reneg(wpa_s
->wpa
, peer
);
401 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
402 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
404 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
411 static int wpa_supplicant_ctrl_iface_tdls_teardown(
412 struct wpa_supplicant
*wpa_s
, char *addr
)
416 if (hwaddr_aton(addr
, peer
)) {
417 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
418 "address '%s'", addr
);
422 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
425 return wpa_tdls_teardown_link(wpa_s
->wpa
, peer
,
426 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
429 #endif /* CONFIG_TDLS */
432 #ifdef CONFIG_IEEE80211R
433 static int wpa_supplicant_ctrl_iface_ft_ds(
434 struct wpa_supplicant
*wpa_s
, char *addr
)
436 u8 target_ap
[ETH_ALEN
];
440 if (hwaddr_aton(addr
, target_ap
)) {
441 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
442 "address '%s'", addr
);
446 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
448 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
450 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
454 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
456 #endif /* CONFIG_IEEE80211R */
460 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
463 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
465 u8 p2p_dev_addr
[ETH_ALEN
];
466 #endif /* CONFIG_P2P */
468 u8
*_p2p_dev_addr
= NULL
;
469 #endif /* CONFIG_AP */
471 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
474 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
475 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
476 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
477 "P2P Device Address '%s'",
481 _p2p_dev_addr
= p2p_dev_addr
;
482 #endif /* CONFIG_P2P */
483 } else if (hwaddr_aton(cmd
, bssid
)) {
484 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
491 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
492 #endif /* CONFIG_AP */
494 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
498 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
499 char *cmd
, char *buf
,
502 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
506 pin
= os_strchr(cmd
, ' ');
510 if (os_strcmp(cmd
, "any") == 0)
512 else if (os_strcmp(cmd
, "get") == 0) {
513 ret
= wps_generate_pin();
515 } else if (hwaddr_aton(cmd
, bssid
)) {
516 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
523 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
525 #endif /* CONFIG_AP */
528 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
532 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
533 if (ret
< 0 || (size_t) ret
>= buflen
)
538 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
543 /* Return the generated PIN */
544 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
545 if (ret
< 0 || (size_t) ret
>= buflen
)
551 static int wpa_supplicant_ctrl_iface_wps_check_pin(
552 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
559 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
560 (u8
*) cmd
, os_strlen(cmd
));
561 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
562 if (*pos
< '0' || *pos
> '9')
566 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
570 if (len
!= 4 && len
!= 8) {
571 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
577 unsigned int pin_val
;
579 if (!wps_pin_valid(pin_val
)) {
580 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
581 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
582 if (ret
< 0 || (size_t) ret
>= buflen
)
588 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
589 if (ret
< 0 || (size_t) ret
>= buflen
)
596 #ifdef CONFIG_WPS_OOB
597 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant
*wpa_s
,
600 char *path
, *method
, *name
;
602 path
= os_strchr(cmd
, ' ');
607 method
= os_strchr(path
, ' ');
612 name
= os_strchr(method
, ' ');
616 return wpas_wps_start_oob(wpa_s
, cmd
, path
, method
, name
);
618 #endif /* CONFIG_WPS_OOB */
621 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
630 struct wps_new_ap_settings ap
;
632 pin
= os_strchr(cmd
, ' ');
637 if (hwaddr_aton(cmd
, bssid
)) {
638 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
643 new_ssid
= os_strchr(pin
, ' ');
644 if (new_ssid
== NULL
)
645 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
648 new_auth
= os_strchr(new_ssid
, ' ');
649 if (new_auth
== NULL
)
653 new_encr
= os_strchr(new_auth
, ' ');
654 if (new_encr
== NULL
)
658 new_key
= os_strchr(new_encr
, ' ');
663 os_memset(&ap
, 0, sizeof(ap
));
664 ap
.ssid_hex
= new_ssid
;
667 ap
.key_hex
= new_key
;
668 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
673 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
674 char *cmd
, char *buf
,
681 if (!wpa_s
->ap_iface
)
684 pos
= os_strchr(cmd
, ' ');
688 if (os_strcmp(cmd
, "disable") == 0) {
689 wpas_wps_ap_pin_disable(wpa_s
);
690 return os_snprintf(buf
, buflen
, "OK\n");
693 if (os_strcmp(cmd
, "random") == 0) {
696 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
699 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
702 if (os_strcmp(cmd
, "get") == 0) {
703 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
706 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
709 if (os_strcmp(cmd
, "set") == 0) {
714 pos
= os_strchr(pos
, ' ');
719 if (os_strlen(pin
) > buflen
)
721 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
723 return os_snprintf(buf
, buflen
, "%s", pin
);
728 #endif /* CONFIG_AP */
732 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
735 char *uuid
= cmd
, *pin
, *pos
;
736 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
737 pin
= os_strchr(uuid
, ' ');
741 pos
= os_strchr(pin
, ' ');
744 if (hwaddr_aton(pos
, addr_buf
) == 0)
747 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
751 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
754 char *uuid
= cmd
, *pin
;
755 pin
= os_strchr(uuid
, ' ');
759 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
763 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
764 struct wpa_supplicant
*wpa_s
, char *cmd
)
766 char *uuid
= cmd
, *id
;
767 id
= os_strchr(uuid
, ' ');
771 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
775 static int wpa_supplicant_ctrl_iface_wps_er_config(
776 struct wpa_supplicant
*wpa_s
, char *cmd
)
783 struct wps_new_ap_settings ap
;
785 pin
= os_strchr(cmd
, ' ');
790 new_ssid
= os_strchr(pin
, ' ');
791 if (new_ssid
== NULL
)
795 new_auth
= os_strchr(new_ssid
, ' ');
796 if (new_auth
== NULL
)
800 new_encr
= os_strchr(new_auth
, ' ');
801 if (new_encr
== NULL
)
805 new_key
= os_strchr(new_encr
, ' ');
810 os_memset(&ap
, 0, sizeof(ap
));
811 ap
.ssid_hex
= new_ssid
;
814 ap
.key_hex
= new_key
;
815 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
817 #endif /* CONFIG_WPS_ER */
819 #endif /* CONFIG_WPS */
822 #ifdef CONFIG_IBSS_RSN
823 static int wpa_supplicant_ctrl_iface_ibss_rsn(
824 struct wpa_supplicant
*wpa_s
, char *addr
)
828 if (hwaddr_aton(addr
, peer
)) {
829 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
830 "address '%s'", addr
);
834 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
837 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
839 #endif /* CONFIG_IBSS_RSN */
842 int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant
*wpa_s
,
843 struct wpa_ssid
*ssid
,
847 #ifdef IEEE8021X_EAPOL
848 struct eap_peer_config
*eap
= &ssid
->eap
;
850 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: response handle field=%s", field
);
851 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: response value",
852 (const u8
*) value
, os_strlen(value
));
854 switch (wpa_supplicant_ctrl_req_from_string(field
)) {
855 case WPA_CTRL_REQ_EAP_IDENTITY
:
856 os_free(eap
->identity
);
857 eap
->identity
= (u8
*) os_strdup(value
);
858 eap
->identity_len
= os_strlen(value
);
859 eap
->pending_req_identity
= 0;
860 if (ssid
== wpa_s
->current_ssid
)
861 wpa_s
->reassociate
= 1;
863 case WPA_CTRL_REQ_EAP_PASSWORD
:
864 os_free(eap
->password
);
865 eap
->password
= (u8
*) os_strdup(value
);
866 eap
->password_len
= os_strlen(value
);
867 eap
->pending_req_password
= 0;
868 if (ssid
== wpa_s
->current_ssid
)
869 wpa_s
->reassociate
= 1;
871 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
872 os_free(eap
->new_password
);
873 eap
->new_password
= (u8
*) os_strdup(value
);
874 eap
->new_password_len
= os_strlen(value
);
875 eap
->pending_req_new_password
= 0;
876 if (ssid
== wpa_s
->current_ssid
)
877 wpa_s
->reassociate
= 1;
879 case WPA_CTRL_REQ_EAP_PIN
:
881 eap
->pin
= os_strdup(value
);
882 eap
->pending_req_pin
= 0;
883 if (ssid
== wpa_s
->current_ssid
)
884 wpa_s
->reassociate
= 1;
886 case WPA_CTRL_REQ_EAP_OTP
:
888 eap
->otp
= (u8
*) os_strdup(value
);
889 eap
->otp_len
= os_strlen(value
);
890 os_free(eap
->pending_req_otp
);
891 eap
->pending_req_otp
= NULL
;
892 eap
->pending_req_otp_len
= 0;
894 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
895 os_free(eap
->private_key_passwd
);
896 eap
->private_key_passwd
= (u8
*) os_strdup(value
);
897 eap
->pending_req_passphrase
= 0;
898 if (ssid
== wpa_s
->current_ssid
)
899 wpa_s
->reassociate
= 1;
902 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", field
);
907 #else /* IEEE8021X_EAPOL */
908 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: IEEE 802.1X not included");
910 #endif /* IEEE8021X_EAPOL */
914 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
917 #ifdef IEEE8021X_EAPOL
920 struct wpa_ssid
*ssid
;
922 pos
= os_strchr(rsp
, '-');
927 pos
= os_strchr(pos
, ':');
932 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
933 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
934 (u8
*) pos
, os_strlen(pos
));
936 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
938 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
943 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
945 #else /* IEEE8021X_EAPOL */
946 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
948 #endif /* IEEE8021X_EAPOL */
952 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
954 char *buf
, size_t buflen
)
956 char *pos
, *end
, tmp
[30];
957 int res
, verbose
, wps
, ret
;
959 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
960 wps
= os_strcmp(params
, "-WPS") == 0;
963 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
964 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
965 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
966 MAC2STR(wpa_s
->bssid
));
967 if (ret
< 0 || ret
>= end
- pos
)
971 u8
*_ssid
= ssid
->ssid
;
972 size_t ssid_len
= ssid
->ssid_len
;
973 u8 ssid_buf
[MAX_SSID_LEN
];
975 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
982 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
983 wpa_ssid_txt(_ssid
, ssid_len
),
985 if (ret
< 0 || ret
>= end
- pos
)
989 if (wps
&& ssid
->passphrase
&&
990 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
991 (ssid
->mode
== WPAS_MODE_AP
||
992 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
993 ret
= os_snprintf(pos
, end
- pos
,
996 if (ret
< 0 || ret
>= end
- pos
)
1001 ret
= os_snprintf(pos
, end
- pos
,
1004 if (ret
< 0 || ret
>= end
- pos
)
1009 switch (ssid
->mode
) {
1010 case WPAS_MODE_INFRA
:
1011 ret
= os_snprintf(pos
, end
- pos
,
1014 case WPAS_MODE_IBSS
:
1015 ret
= os_snprintf(pos
, end
- pos
,
1019 ret
= os_snprintf(pos
, end
- pos
,
1022 case WPAS_MODE_P2P_GO
:
1023 ret
= os_snprintf(pos
, end
- pos
,
1026 case WPAS_MODE_P2P_GROUP_FORMATION
:
1027 ret
= os_snprintf(pos
, end
- pos
,
1028 "mode=P2P GO - group "
1035 if (ret
< 0 || ret
>= end
- pos
)
1041 if (wpa_s
->ap_iface
) {
1042 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1046 #endif /* CONFIG_AP */
1047 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1049 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1050 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1051 if (ret
< 0 || ret
>= end
- pos
)
1056 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1057 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1058 if (ret
< 0 || ret
>= end
- pos
)
1064 if (wpa_s
->global
->p2p
) {
1065 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1066 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1067 if (ret
< 0 || ret
>= end
- pos
)
1071 #endif /* CONFIG_P2P */
1073 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1074 MAC2STR(wpa_s
->own_addr
));
1075 if (ret
< 0 || ret
>= end
- pos
)
1079 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1080 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1081 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1087 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1095 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1100 struct wpa_ssid
*ssid
;
1103 /* cmd: "<network id> <BSSID>" */
1104 pos
= os_strchr(cmd
, ' ');
1109 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1110 if (hwaddr_aton(pos
, bssid
)) {
1111 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1115 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1117 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1122 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1123 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1129 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1130 char *cmd
, char *buf
,
1134 struct wpa_blacklist
*e
;
1138 /* cmd: "BLACKLIST [<BSSID>]" */
1142 e
= wpa_s
->blacklist
;
1144 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1146 if (ret
< 0 || ret
>= end
- pos
)
1155 if (os_strncmp(cmd
, "clear", 5) == 0) {
1156 wpa_blacklist_clear(wpa_s
);
1157 os_memcpy(buf
, "OK\n", 3);
1161 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1162 if (hwaddr_aton(cmd
, bssid
)) {
1163 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1168 * Add the BSSID twice, so its count will be 2, causing it to be
1169 * skipped when processing scan results.
1171 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1174 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1177 os_memcpy(buf
, "OK\n", 3);
1182 extern int wpa_debug_level
;
1183 extern int wpa_debug_timestamp
;
1185 static const char * debug_level_str(int level
)
1206 static int str_to_debug_level(const char *s
)
1208 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1209 return MSG_EXCESSIVE
;
1210 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1212 if (os_strcasecmp(s
, "DEBUG") == 0)
1214 if (os_strcasecmp(s
, "INFO") == 0)
1216 if (os_strcasecmp(s
, "WARNING") == 0)
1218 if (os_strcasecmp(s
, "ERROR") == 0)
1224 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1225 char *cmd
, char *buf
,
1228 char *pos
, *end
, *stamp
;
1235 /* cmd: "LOG_LEVEL [<level>]" */
1239 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1241 debug_level_str(wpa_debug_level
),
1242 wpa_debug_timestamp
);
1243 if (ret
< 0 || ret
>= end
- pos
)
1252 stamp
= os_strchr(cmd
, ' ');
1255 while (*stamp
== ' ') {
1260 if (cmd
&& os_strlen(cmd
)) {
1261 int level
= str_to_debug_level(cmd
);
1264 wpa_debug_level
= level
;
1267 if (stamp
&& os_strlen(stamp
))
1268 wpa_debug_timestamp
= atoi(stamp
);
1270 os_memcpy(buf
, "OK\n", 3);
1275 static int wpa_supplicant_ctrl_iface_list_networks(
1276 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1279 struct wpa_ssid
*ssid
;
1284 ret
= os_snprintf(pos
, end
- pos
,
1285 "network id / ssid / bssid / flags\n");
1286 if (ret
< 0 || ret
>= end
- pos
)
1290 ssid
= wpa_s
->conf
->ssid
;
1292 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
1294 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1295 if (ret
< 0 || ret
>= end
- pos
)
1298 if (ssid
->bssid_set
) {
1299 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
1300 MAC2STR(ssid
->bssid
));
1302 ret
= os_snprintf(pos
, end
- pos
, "\tany");
1304 if (ret
< 0 || ret
>= end
- pos
)
1307 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s",
1308 ssid
== wpa_s
->current_ssid
?
1310 ssid
->disabled
? "[DISABLED]" : "",
1311 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
1313 if (ret
< 0 || ret
>= end
- pos
)
1316 ret
= os_snprintf(pos
, end
- pos
, "\n");
1317 if (ret
< 0 || ret
>= end
- pos
)
1328 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
1331 ret
= os_snprintf(pos
, end
- pos
, "-");
1332 if (ret
< 0 || ret
>= end
- pos
)
1335 if (cipher
& WPA_CIPHER_NONE
) {
1336 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : "+");
1337 if (ret
< 0 || ret
>= end
- pos
)
1342 if (cipher
& WPA_CIPHER_WEP40
) {
1343 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : "+");
1344 if (ret
< 0 || ret
>= end
- pos
)
1349 if (cipher
& WPA_CIPHER_WEP104
) {
1350 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
1352 if (ret
< 0 || ret
>= end
- pos
)
1357 if (cipher
& WPA_CIPHER_TKIP
) {
1358 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : "+");
1359 if (ret
< 0 || ret
>= end
- pos
)
1364 if (cipher
& WPA_CIPHER_CCMP
) {
1365 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : "+");
1366 if (ret
< 0 || ret
>= end
- pos
)
1375 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
1376 const u8
*ie
, size_t ie_len
)
1378 struct wpa_ie_data data
;
1381 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
1382 if (ret
< 0 || ret
>= end
- pos
)
1386 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
1387 ret
= os_snprintf(pos
, end
- pos
, "?]");
1388 if (ret
< 0 || ret
>= end
- pos
)
1395 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1396 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
1397 if (ret
< 0 || ret
>= end
- pos
)
1402 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
1403 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
1404 if (ret
< 0 || ret
>= end
- pos
)
1409 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
1410 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
1411 if (ret
< 0 || ret
>= end
- pos
)
1416 #ifdef CONFIG_IEEE80211R
1417 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1418 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
1420 if (ret
< 0 || ret
>= end
- pos
)
1425 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1426 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
1428 if (ret
< 0 || ret
>= end
- pos
)
1433 #endif /* CONFIG_IEEE80211R */
1434 #ifdef CONFIG_IEEE80211W
1435 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1436 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
1438 if (ret
< 0 || ret
>= end
- pos
)
1443 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1444 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
1446 if (ret
< 0 || ret
>= end
- pos
)
1451 #endif /* CONFIG_IEEE80211W */
1453 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
1455 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
1456 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
1457 if (ret
< 0 || ret
>= end
- pos
)
1462 ret
= os_snprintf(pos
, end
- pos
, "]");
1463 if (ret
< 0 || ret
>= end
- pos
)
1472 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
1473 char *pos
, char *end
,
1474 struct wpabuf
*wps_ie
)
1481 if (wps_is_selected_pbc_registrar(wps_ie
))
1484 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
1486 #endif /* CONFIG_WPS2 */
1487 else if (wps_is_selected_pin_registrar(wps_ie
))
1492 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
1493 if (ret
>= 0 && ret
< end
- pos
)
1495 wpabuf_free(wps_ie
);
1498 #endif /* CONFIG_WPS */
1501 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
1502 char *pos
, char *end
,
1503 const struct wpa_bss
*bss
)
1506 struct wpabuf
*wps_ie
;
1507 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
1508 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
1509 #else /* CONFIG_WPS */
1511 #endif /* CONFIG_WPS */
1515 /* Format one result on one text line into a buffer. */
1516 static int wpa_supplicant_ctrl_iface_scan_result(
1517 struct wpa_supplicant
*wpa_s
,
1518 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
1522 const u8
*ie
, *ie2
, *p2p
;
1524 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1525 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
1526 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
1528 return 0; /* Do not show P2P listen discovery results here */
1533 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
1534 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
1535 if (ret
< 0 || ret
>= end
- pos
)
1538 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1540 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
1541 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1543 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
1544 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
1545 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
1546 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
1547 if (ret
< 0 || ret
>= end
- pos
)
1551 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
1552 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
1553 if (ret
< 0 || ret
>= end
- pos
)
1557 if (bss
->caps
& IEEE80211_CAP_ESS
) {
1558 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
1559 if (ret
< 0 || ret
>= end
- pos
)
1564 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
1565 if (ret
< 0 || ret
>= end
- pos
)
1570 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
1571 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1572 if (ret
< 0 || ret
>= end
- pos
)
1576 ret
= os_snprintf(pos
, end
- pos
, "\n");
1577 if (ret
< 0 || ret
>= end
- pos
)
1585 static int wpa_supplicant_ctrl_iface_scan_results(
1586 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1589 struct wpa_bss
*bss
;
1594 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
1596 if (ret
< 0 || ret
>= end
- pos
)
1600 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
1601 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
1603 if (ret
< 0 || ret
>= end
- pos
)
1612 static int wpa_supplicant_ctrl_iface_select_network(
1613 struct wpa_supplicant
*wpa_s
, char *cmd
)
1616 struct wpa_ssid
*ssid
;
1618 /* cmd: "<network id>" or "any" */
1619 if (os_strcmp(cmd
, "any") == 0) {
1620 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
1624 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
1626 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1628 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1629 "network id=%d", id
);
1632 if (ssid
->disabled
== 2) {
1633 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1634 "SELECT_NETWORK with persistent P2P group");
1639 wpa_supplicant_select_network(wpa_s
, ssid
);
1645 static int wpa_supplicant_ctrl_iface_enable_network(
1646 struct wpa_supplicant
*wpa_s
, char *cmd
)
1649 struct wpa_ssid
*ssid
;
1651 /* cmd: "<network id>" or "all" */
1652 if (os_strcmp(cmd
, "all") == 0) {
1653 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
1657 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
1659 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1661 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1662 "network id=%d", id
);
1665 if (ssid
->disabled
== 2) {
1666 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1667 "ENABLE_NETWORK with persistent P2P group");
1671 if (os_strstr(cmd
, " no-connect")) {
1676 wpa_supplicant_enable_network(wpa_s
, ssid
);
1682 static int wpa_supplicant_ctrl_iface_disable_network(
1683 struct wpa_supplicant
*wpa_s
, char *cmd
)
1686 struct wpa_ssid
*ssid
;
1688 /* cmd: "<network id>" or "all" */
1689 if (os_strcmp(cmd
, "all") == 0) {
1690 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
1694 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
1696 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1698 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1699 "network id=%d", id
);
1702 if (ssid
->disabled
== 2) {
1703 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1704 "DISABLE_NETWORK with persistent P2P "
1709 wpa_supplicant_disable_network(wpa_s
, ssid
);
1715 static int wpa_supplicant_ctrl_iface_add_network(
1716 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1718 struct wpa_ssid
*ssid
;
1721 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
1723 ssid
= wpa_config_add_network(wpa_s
->conf
);
1727 wpas_notify_network_added(wpa_s
, ssid
);
1730 wpa_config_set_network_defaults(ssid
);
1732 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
1733 if (ret
< 0 || (size_t) ret
>= buflen
)
1739 static int wpa_supplicant_ctrl_iface_remove_network(
1740 struct wpa_supplicant
*wpa_s
, char *cmd
)
1743 struct wpa_ssid
*ssid
;
1745 /* cmd: "<network id>" or "all" */
1746 if (os_strcmp(cmd
, "all") == 0) {
1747 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
1748 ssid
= wpa_s
->conf
->ssid
;
1750 struct wpa_ssid
*remove_ssid
= ssid
;
1753 wpas_notify_network_removed(wpa_s
, remove_ssid
);
1754 wpa_config_remove_network(wpa_s
->conf
, id
);
1756 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1757 if (wpa_s
->current_ssid
) {
1758 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1759 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1760 wpa_supplicant_disassociate(wpa_s
,
1761 WLAN_REASON_DEAUTH_LEAVING
);
1767 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
1769 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1771 wpas_notify_network_removed(wpa_s
, ssid
);
1773 wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
1774 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1779 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
1781 * Invalidate the EAP session cache if the current or
1782 * previously used network is removed.
1784 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1787 if (ssid
== wpa_s
->current_ssid
) {
1788 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1789 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1791 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1798 static int wpa_supplicant_ctrl_iface_set_network(
1799 struct wpa_supplicant
*wpa_s
, char *cmd
)
1802 struct wpa_ssid
*ssid
;
1805 /* cmd: "<network id> <variable name> <value>" */
1806 name
= os_strchr(cmd
, ' ');
1811 value
= os_strchr(name
, ' ');
1817 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1819 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1820 (u8
*) value
, os_strlen(value
));
1822 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1824 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1829 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
1830 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
1831 "variable '%s'", name
);
1835 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
1837 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
1839 * Invalidate the EAP session cache if anything in the current
1840 * or previously used configuration changes.
1842 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1845 if ((os_strcmp(name
, "psk") == 0 &&
1846 value
[0] == '"' && ssid
->ssid_len
) ||
1847 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
1848 wpa_config_update_psk(ssid
);
1849 else if (os_strcmp(name
, "priority") == 0)
1850 wpa_config_update_prio_list(wpa_s
->conf
);
1856 static int wpa_supplicant_ctrl_iface_get_network(
1857 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1861 struct wpa_ssid
*ssid
;
1864 /* cmd: "<network id> <variable name>" */
1865 name
= os_strchr(cmd
, ' ');
1866 if (name
== NULL
|| buflen
== 0)
1871 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1874 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1876 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1881 value
= wpa_config_get_no_key(ssid
, name
);
1882 if (value
== NULL
) {
1883 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
1884 "variable '%s'", name
);
1888 res
= os_strlcpy(buf
, value
, buflen
);
1889 if (res
>= buflen
) {
1900 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
1901 char *buf
, size_t buflen
)
1904 struct wpa_cred
*cred
;
1909 ret
= os_snprintf(pos
, end
- pos
,
1910 "cred id / realm / username / domain / imsi\n");
1911 if (ret
< 0 || ret
>= end
- pos
)
1915 cred
= wpa_s
->conf
->cred
;
1917 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
1918 cred
->id
, cred
->realm
? cred
->realm
: "",
1919 cred
->username
? cred
->username
: "",
1920 cred
->domain
? cred
->domain
: "",
1921 cred
->imsi
? cred
->imsi
: "");
1922 if (ret
< 0 || ret
>= end
- pos
)
1933 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
1934 char *buf
, size_t buflen
)
1936 struct wpa_cred
*cred
;
1939 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
1941 cred
= wpa_config_add_cred(wpa_s
->conf
);
1945 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
1946 if (ret
< 0 || (size_t) ret
>= buflen
)
1952 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
1956 struct wpa_cred
*cred
;
1958 /* cmd: "<cred id>" or "all" */
1959 if (os_strcmp(cmd
, "all") == 0) {
1960 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
1961 cred
= wpa_s
->conf
->cred
;
1965 wpa_config_remove_cred(wpa_s
->conf
, id
);
1971 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
1973 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
1975 wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
1976 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
1985 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
1989 struct wpa_cred
*cred
;
1992 /* cmd: "<cred id> <variable name> <value>" */
1993 name
= os_strchr(cmd
, ' ');
1998 value
= os_strchr(name
, ' ');
2004 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2006 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2007 (u8
*) value
, os_strlen(value
));
2009 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2011 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2016 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
2017 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
2018 "variable '%s'", name
);
2026 #ifndef CONFIG_NO_CONFIG_WRITE
2027 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
2031 if (!wpa_s
->conf
->update_config
) {
2032 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2033 "to update configuration (update_config=0)");
2037 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
2039 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2040 "update configuration");
2042 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2048 #endif /* CONFIG_NO_CONFIG_WRITE */
2051 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2052 struct wpa_driver_capa
*capa
,
2053 char *buf
, size_t buflen
)
2065 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2071 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2072 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2073 if (ret
< 0 || ret
>= end
- pos
)
2079 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2080 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2081 if (ret
< 0 || ret
>= end
- pos
)
2087 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2088 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : " ");
2089 if (ret
< 0 || ret
>= end
- pos
)
2099 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2100 struct wpa_driver_capa
*capa
,
2101 char *buf
, size_t buflen
)
2113 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2119 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2120 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2121 if (ret
< 0 || ret
>= end
- pos
)
2127 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2128 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2129 if (ret
< 0 || ret
>= end
- pos
)
2135 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP104
) {
2136 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
2138 if (ret
< 0 || ret
>= end
- pos
)
2144 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP40
) {
2145 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : " ");
2146 if (ret
< 0 || ret
>= end
- pos
)
2156 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2157 struct wpa_driver_capa
*capa
,
2158 char *buf
, size_t buflen
)
2170 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2177 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2178 if (ret
< 0 || ret
>= end
- pos
)
2182 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2183 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2184 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2185 if (ret
< 0 || ret
>= end
- pos
)
2190 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2191 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2192 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2193 if (ret
< 0 || ret
>= end
- pos
)
2198 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2199 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2200 if (ret
< 0 || ret
>= end
- pos
)
2209 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2210 struct wpa_driver_capa
*capa
,
2211 char *buf
, size_t buflen
)
2223 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2229 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2230 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2231 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
2232 if (ret
< 0 || ret
>= end
- pos
)
2238 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2239 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
2240 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
2241 if (ret
< 0 || ret
>= end
- pos
)
2251 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
2252 struct wpa_driver_capa
*capa
,
2253 char *buf
, size_t buflen
)
2265 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
2271 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
2272 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
2273 if (ret
< 0 || ret
>= end
- pos
)
2279 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
2280 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
2282 if (ret
< 0 || ret
>= end
- pos
)
2288 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
2289 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
2290 if (ret
< 0 || ret
>= end
- pos
)
2300 static int wpa_supplicant_ctrl_iface_get_capability(
2301 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
2304 struct wpa_driver_capa capa
;
2310 /* Determine whether or not strict checking was requested */
2311 len
= os_strlcpy(field
, _field
, sizeof(field
));
2312 if (len
>= sizeof(field
))
2314 strict
= os_strchr(field
, ' ');
2315 if (strict
!= NULL
) {
2317 if (os_strcmp(strict
, "strict") != 0)
2321 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2322 field
, strict
? strict
: "");
2324 if (os_strcmp(field
, "eap") == 0) {
2325 return eap_get_names(buf
, buflen
);
2328 res
= wpa_drv_get_capa(wpa_s
, &capa
);
2330 if (os_strcmp(field
, "pairwise") == 0)
2331 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
2334 if (os_strcmp(field
, "group") == 0)
2335 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
2338 if (os_strcmp(field
, "key_mgmt") == 0)
2339 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
2342 if (os_strcmp(field
, "proto") == 0)
2343 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
2346 if (os_strcmp(field
, "auth_alg") == 0)
2347 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
2350 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2357 #ifdef CONFIG_INTERWORKING
2358 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
2359 struct wpabuf
*data
)
2369 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
2370 if (ret
< 0 || ret
>= end
- pos
)
2374 d
= wpabuf_head_u8(data
);
2375 for (i
= 0; i
< wpabuf_len(data
); i
++) {
2376 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
2377 if (ret
< 0 || ret
>= end
- pos
)
2382 ret
= os_snprintf(pos
, end
- pos
, "\n");
2383 if (ret
< 0 || ret
>= end
- pos
)
2389 #endif /* CONFIG_INTERWORKING */
2392 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
2393 const char *cmd
, char *buf
,
2398 struct wpa_bss
*bss
;
2404 if (os_strcmp(cmd
, "FIRST") == 0)
2405 bss
= dl_list_first(&wpa_s
->bss
, struct wpa_bss
, list
);
2406 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
2408 bss
= wpa_bss_get_id(wpa_s
, i
);
2409 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
2411 bss
= wpa_bss_get_id(wpa_s
, i
);
2413 struct dl_list
*next
= bss
->list_id
.next
;
2414 if (next
== &wpa_s
->bss_id
)
2417 bss
= dl_list_entry(next
, struct wpa_bss
,
2421 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
2422 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
2423 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
2426 #endif /* CONFIG_P2P */
2427 } else if (hwaddr_aton(cmd
, bssid
) == 0)
2428 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2430 struct wpa_bss
*tmp
;
2433 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
2448 ret
= os_snprintf(pos
, end
- pos
,
2450 "bssid=" MACSTR
"\n"
2453 "capabilities=0x%04x\n"
2461 MAC2STR(bss
->bssid
), bss
->freq
, bss
->beacon_int
,
2462 bss
->caps
, bss
->qual
, bss
->noise
, bss
->level
,
2463 (unsigned long long) bss
->tsf
,
2464 (int) (now
.sec
- bss
->last_update
.sec
));
2465 if (ret
< 0 || ret
>= end
- pos
)
2469 ie
= (const u8
*) (bss
+ 1);
2470 for (i
= 0; i
< bss
->ie_len
; i
++) {
2471 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
2472 if (ret
< 0 || ret
>= end
- pos
)
2477 ret
= os_snprintf(pos
, end
- pos
, "\n");
2478 if (ret
< 0 || ret
>= end
- pos
)
2482 ret
= os_snprintf(pos
, end
- pos
, "flags=");
2483 if (ret
< 0 || ret
>= end
- pos
)
2487 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2489 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2490 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2492 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
2493 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2494 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2495 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2496 if (ret
< 0 || ret
>= end
- pos
)
2500 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2501 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2502 if (ret
< 0 || ret
>= end
- pos
)
2506 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2507 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2508 if (ret
< 0 || ret
>= end
- pos
)
2512 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
)) {
2513 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2514 if (ret
< 0 || ret
>= end
- pos
)
2519 ret
= os_snprintf(pos
, end
- pos
, "\n");
2520 if (ret
< 0 || ret
>= end
- pos
)
2524 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
2525 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2526 if (ret
< 0 || ret
>= end
- pos
)
2531 ie
= (const u8
*) (bss
+ 1);
2532 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2533 if (ret
< 0 || ret
>= end
- pos
)
2536 #endif /* CONFIG_WPS */
2539 ie
= (const u8
*) (bss
+ 1);
2540 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2541 if (ret
< 0 || ret
>= end
- pos
)
2544 #endif /* CONFIG_P2P */
2546 #ifdef CONFIG_INTERWORKING
2547 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name", bss
->anqp_venue_name
);
2548 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
2549 bss
->anqp_network_auth_type
);
2550 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
2551 bss
->anqp_roaming_consortium
);
2552 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
2553 bss
->anqp_ip_addr_type_availability
);
2554 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm", bss
->anqp_nai_realm
);
2555 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", bss
->anqp_3gpp
);
2556 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
2557 bss
->anqp_domain_name
);
2558 #endif /* CONFIG_INTERWORKING */
2564 static int wpa_supplicant_ctrl_iface_ap_scan(
2565 struct wpa_supplicant
*wpa_s
, char *cmd
)
2567 int ap_scan
= atoi(cmd
);
2568 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
2572 static int wpa_supplicant_ctrl_iface_scan_interval(
2573 struct wpa_supplicant
*wpa_s
, char *cmd
)
2575 int scan_int
= atoi(cmd
);
2578 wpa_s
->scan_interval
= scan_int
;
2583 static int wpa_supplicant_ctrl_iface_bss_expire_age(
2584 struct wpa_supplicant
*wpa_s
, char *cmd
)
2586 int expire_age
= atoi(cmd
);
2587 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
2591 static int wpa_supplicant_ctrl_iface_bss_expire_count(
2592 struct wpa_supplicant
*wpa_s
, char *cmd
)
2594 int expire_count
= atoi(cmd
);
2595 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
2599 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
2601 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
2602 /* MLME-DELETEKEYS.request */
2603 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
2604 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
2605 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
2606 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
2607 #ifdef CONFIG_IEEE80211W
2608 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
2609 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
2610 #endif /* CONFIG_IEEE80211W */
2612 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
2614 /* MLME-SETPROTECTION.request(None) */
2615 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
2616 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
2617 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
2618 wpa_sm_drop_sa(wpa_s
->wpa
);
2622 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
2625 #ifdef CONFIG_NO_SCAN_PROCESSING
2627 #else /* CONFIG_NO_SCAN_PROCESSING */
2629 struct wpa_bss
*bss
;
2630 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2632 if (hwaddr_aton(addr
, bssid
)) {
2633 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
2634 "address '%s'", addr
);
2638 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
2640 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2642 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
2648 * TODO: Find best network configuration block from configuration to
2649 * allow roaming to other networks
2653 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
2654 "configuration known for the target AP");
2658 wpa_s
->reassociate
= 1;
2659 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
2662 #endif /* CONFIG_NO_SCAN_PROCESSING */
2667 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
2669 unsigned int timeout
= atoi(cmd
);
2670 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
2671 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
2674 if (os_strstr(cmd
, "type=social"))
2675 type
= P2P_FIND_ONLY_SOCIAL
;
2676 else if (os_strstr(cmd
, "type=progressive"))
2677 type
= P2P_FIND_PROGRESSIVE
;
2679 pos
= os_strstr(cmd
, "dev_id=");
2682 if (hwaddr_aton(pos
, dev_id
))
2687 return wpas_p2p_find(wpa_s
, timeout
, type
, 0, NULL
, _dev_id
);
2691 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
2692 char *buf
, size_t buflen
)
2697 enum p2p_wps_method wps_method
;
2700 int persistent_group
;
2706 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] [persistent]
2707 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */
2709 if (hwaddr_aton(cmd
, addr
))
2717 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
2718 join
= os_strstr(pos
, " join") != NULL
;
2719 auth
= os_strstr(pos
, " auth") != NULL
;
2721 pos2
= os_strstr(pos
, " go_intent=");
2724 go_intent
= atoi(pos2
);
2725 if (go_intent
< 0 || go_intent
> 15)
2729 pos2
= os_strstr(pos
, " freq=");
2737 if (os_strncmp(pos
, "pin", 3) == 0) {
2738 /* Request random PIN (to be displayed) and enable the PIN */
2739 wps_method
= WPS_PIN_DISPLAY
;
2740 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
2741 wps_method
= WPS_PBC
;
2744 pos
= os_strchr(pin
, ' ');
2745 wps_method
= WPS_PIN_KEYPAD
;
2748 if (os_strncmp(pos
, "display", 7) == 0)
2749 wps_method
= WPS_PIN_DISPLAY
;
2753 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
2754 persistent_group
, join
, auth
, go_intent
,
2756 if (new_pin
== -2) {
2757 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
2760 if (new_pin
== -3) {
2761 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
2766 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
2767 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
2768 if (ret
< 0 || (size_t) ret
>= buflen
)
2773 os_memcpy(buf
, "OK\n", 3);
2778 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
2780 unsigned int timeout
= atoi(cmd
);
2781 return wpas_p2p_listen(wpa_s
, timeout
);
2785 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
2790 /* <addr> <config method> [join] */
2792 if (hwaddr_aton(cmd
, addr
))
2800 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
,
2801 os_strstr(pos
, "join") != NULL
);
2805 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
2808 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2810 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
2811 ssid
->passphrase
== NULL
)
2814 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
2815 return os_strlen(buf
);
2819 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
2820 char *buf
, size_t buflen
)
2824 u8 dst_buf
[ETH_ALEN
], *dst
;
2825 struct wpabuf
*tlvs
;
2829 if (hwaddr_aton(cmd
, dst_buf
))
2832 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
2833 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
2840 if (os_strncmp(pos
, "upnp ", 5) == 0) {
2843 if (hexstr2bin(pos
, &version
, 1) < 0)
2849 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
2851 len
= os_strlen(pos
);
2855 tlvs
= wpabuf_alloc(len
);
2858 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
2863 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
2868 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
2869 if (res
< 0 || (unsigned) res
>= buflen
)
2875 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
2878 long long unsigned val
;
2880 if (sscanf(cmd
, "%llx", &val
) != 1)
2883 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
2887 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
2892 struct wpabuf
*resp_tlvs
;
2896 pos
= os_strchr(cmd
, ' ');
2904 if (hwaddr_aton(pos
, dst
))
2911 pos2
= os_strchr(pos
, ' ');
2915 dialog_token
= atoi(pos
);
2917 len
= os_strlen(pos2
);
2921 resp_tlvs
= wpabuf_alloc(len
);
2922 if (resp_tlvs
== NULL
)
2924 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
2925 wpabuf_free(resp_tlvs
);
2929 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
2930 wpabuf_free(resp_tlvs
);
2935 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
2938 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
2943 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
2948 struct wpabuf
*query
, *resp
;
2950 pos
= os_strchr(cmd
, ' ');
2955 len
= os_strlen(cmd
);
2959 query
= wpabuf_alloc(len
);
2962 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
2967 len
= os_strlen(pos
);
2973 resp
= wpabuf_alloc(len
);
2978 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
2984 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
2993 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
2998 pos
= os_strchr(cmd
, ' ');
3003 if (hexstr2bin(cmd
, &version
, 1) < 0)
3006 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
3010 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3014 pos
= os_strchr(cmd
, ' ');
3019 if (os_strcmp(cmd
, "bonjour") == 0)
3020 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
3021 if (os_strcmp(cmd
, "upnp") == 0)
3022 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
3023 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3028 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
3032 struct wpabuf
*query
;
3035 len
= os_strlen(cmd
);
3039 query
= wpabuf_alloc(len
);
3042 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3047 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
3053 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3058 pos
= os_strchr(cmd
, ' ');
3063 if (hexstr2bin(cmd
, &version
, 1) < 0)
3066 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
3070 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
3074 pos
= os_strchr(cmd
, ' ');
3079 if (os_strcmp(cmd
, "bonjour") == 0)
3080 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
3081 if (os_strcmp(cmd
, "upnp") == 0)
3082 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
3083 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3088 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
3094 if (hwaddr_aton(cmd
, addr
))
3097 return wpas_p2p_reject(wpa_s
, addr
);
3101 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
3105 struct wpa_ssid
*ssid
;
3109 pos
= os_strstr(cmd
, " peer=");
3112 if (hwaddr_aton(pos
, peer
))
3115 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3116 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3117 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3118 "for persistent P2P group",
3123 return wpas_p2p_invite(wpa_s
, pos
? peer
: NULL
, ssid
, NULL
);
3127 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
3130 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
3132 pos
= os_strstr(cmd
, " peer=");
3138 if (hwaddr_aton(pos
, peer
)) {
3139 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
3143 pos
= os_strstr(pos
, " go_dev_addr=");
3146 if (hwaddr_aton(pos
, go_dev_addr
)) {
3147 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
3151 go_dev
= go_dev_addr
;
3154 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
3158 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
3160 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3161 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
3162 if (os_strncmp(cmd
, "group=", 6) == 0)
3163 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
3169 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
3170 char *cmd
, int freq
)
3173 struct wpa_ssid
*ssid
;
3176 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3177 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3178 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3179 "for persistent P2P group",
3184 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
);
3188 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3193 pos
= os_strstr(cmd
, "freq=");
3195 freq
= atoi(pos
+ 5);
3197 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3198 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
);
3199 if (os_strcmp(cmd
, "persistent") == 0 ||
3200 os_strncmp(cmd
, "persistent ", 11) == 0)
3201 return wpas_p2p_group_add(wpa_s
, 1, freq
);
3202 if (os_strncmp(cmd
, "freq=", 5) == 0)
3203 return wpas_p2p_group_add(wpa_s
, 0, freq
);
3205 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3211 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
3212 char *buf
, size_t buflen
)
3214 u8 addr
[ETH_ALEN
], *addr_ptr
;
3216 const struct p2p_peer_info
*info
;
3218 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
3219 struct wpa_ssid
*ssid
;
3221 if (!wpa_s
->global
->p2p
)
3224 if (os_strcmp(cmd
, "FIRST") == 0) {
3227 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3228 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
3233 if (hwaddr_aton(cmd
, addr
) < 0)
3239 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
3246 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
3252 "serial_number=%s\n"
3253 "config_methods=0x%x\n"
3255 "group_capab=0x%x\n"
3257 MAC2STR(info
->p2p_device_addr
),
3258 wps_dev_type_bin2str(info
->pri_dev_type
,
3259 devtype
, sizeof(devtype
)),
3264 info
->serial_number
,
3265 info
->config_methods
,
3269 if (res
< 0 || res
>= end
- pos
)
3273 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
3275 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
3276 if (res
< 0 || res
>= end
- pos
)
3281 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
3290 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
3294 if (wpa_s
->global
->p2p
== NULL
)
3297 param
= os_strchr(cmd
, ' ');
3302 if (os_strcmp(cmd
, "discoverability") == 0) {
3303 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
3308 if (os_strcmp(cmd
, "managed") == 0) {
3309 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
3313 if (os_strcmp(cmd
, "listen_channel") == 0) {
3314 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
3318 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
3319 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
3323 if (os_strcmp(cmd
, "noa") == 0) {
3325 int count
, start
, duration
;
3326 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
3327 count
= atoi(param
);
3328 pos
= os_strchr(param
, ',');
3333 pos
= os_strchr(pos
, ',');
3337 duration
= atoi(pos
);
3338 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
3340 if (count
== 0 && duration
> 0)
3342 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
3343 "start=%d duration=%d", count
, start
, duration
);
3344 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
3347 if (os_strcmp(cmd
, "ps") == 0)
3348 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
3350 if (os_strcmp(cmd
, "oppps") == 0)
3351 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
3353 if (os_strcmp(cmd
, "ctwindow") == 0)
3354 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
3356 if (os_strcmp(cmd
, "disabled") == 0) {
3357 wpa_s
->global
->p2p_disabled
= atoi(param
);
3358 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
3359 wpa_s
->global
->p2p_disabled
?
3360 "disabled" : "enabled");
3361 if (wpa_s
->global
->p2p_disabled
) {
3362 wpas_p2p_stop_find(wpa_s
);
3363 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
3364 p2p_flush(wpa_s
->global
->p2p
);
3369 if (os_strcmp(cmd
, "force_long_sd") == 0) {
3370 wpa_s
->force_long_sd
= atoi(param
);
3374 if (os_strcmp(cmd
, "peer_filter") == 0) {
3376 if (hwaddr_aton(param
, addr
))
3378 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
3382 if (os_strcmp(cmd
, "cross_connect") == 0)
3383 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
3385 if (os_strcmp(cmd
, "go_apsd") == 0) {
3386 if (os_strcmp(param
, "disable") == 0)
3387 wpa_s
->set_ap_uapsd
= 0;
3389 wpa_s
->set_ap_uapsd
= 1;
3390 wpa_s
->ap_uapsd
= atoi(param
);
3395 if (os_strcmp(cmd
, "client_apsd") == 0) {
3396 if (os_strcmp(param
, "disable") == 0)
3397 wpa_s
->set_sta_uapsd
= 0;
3401 /* format: BE,BK,VI,VO;max SP Length */
3403 pos
= os_strchr(param
, ',');
3408 pos
= os_strchr(pos
, ',');
3413 pos
= os_strchr(pos
, ',');
3418 /* ignore max SP Length for now */
3420 wpa_s
->set_sta_uapsd
= 1;
3421 wpa_s
->sta_uapsd
= 0;
3423 wpa_s
->sta_uapsd
|= BIT(0);
3425 wpa_s
->sta_uapsd
|= BIT(1);
3427 wpa_s
->sta_uapsd
|= BIT(2);
3429 wpa_s
->sta_uapsd
|= BIT(3);
3434 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
3441 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
3444 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
3447 pos
= os_strchr(cmd
, ' ');
3453 pos2
= os_strchr(pos
, ' ');
3461 pos
= os_strchr(pos2
, ' ');
3469 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
3473 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3476 unsigned int period
= 0, interval
= 0;
3479 pos
= os_strchr(cmd
, ' ');
3484 interval
= atoi(pos
);
3487 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
3490 #endif /* CONFIG_P2P */
3493 #ifdef CONFIG_INTERWORKING
3494 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
3497 struct wpa_bss
*bss
;
3499 if (hwaddr_aton(dst
, bssid
)) {
3500 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
3504 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3506 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
3511 return interworking_connect(wpa_s
, bss
);
3515 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
3517 u8 dst_addr
[ETH_ALEN
];
3520 #define MAX_ANQP_INFO_ID 100
3521 u16 id
[MAX_ANQP_INFO_ID
];
3524 used
= hwaddr_aton2(dst
, dst_addr
);
3528 while (num_id
< MAX_ANQP_INFO_ID
) {
3529 id
[num_id
] = atoi(pos
);
3532 pos
= os_strchr(pos
+ 1, ',');
3541 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
);
3543 #endif /* CONFIG_INTERWORKING */
3546 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
3547 struct wpa_supplicant
*wpa_s
, char *cmd
)
3549 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
3554 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
3557 struct wpa_signal_info si
;
3560 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
3564 ret
= os_snprintf(buf
, buflen
, "RSSI=%d\nLINKSPEED=%d\n"
3565 "NOISE=%d\nFREQUENCY=%u\n",
3566 si
.current_signal
, si
.current_txrate
/ 1000,
3567 si
.current_noise
, si
.frequency
);
3568 if (ret
< 0 || (unsigned int) ret
> buflen
)
3574 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
3575 char *buf
, size_t *resp_len
)
3578 const int reply_size
= 4096;
3582 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
3583 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
3584 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
3585 (const u8
*) buf
, os_strlen(buf
));
3587 int level
= MSG_DEBUG
;
3588 if (os_strcmp(buf
, "PING") == 0)
3589 level
= MSG_EXCESSIVE
;
3590 wpa_hexdump_ascii(level
, "RX ctrl_iface",
3591 (const u8
*) buf
, os_strlen(buf
));
3594 reply
= os_malloc(reply_size
);
3595 if (reply
== NULL
) {
3600 os_memcpy(reply
, "OK\n", 3);
3603 if (os_strcmp(buf
, "PING") == 0) {
3604 os_memcpy(reply
, "PONG\n", 5);
3606 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3607 if (wpa_debug_reopen_file() < 0)
3609 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3610 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3611 } else if (os_strcmp(buf
, "MIB") == 0) {
3612 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
3613 if (reply_len
>= 0) {
3615 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
3616 reply_size
- reply_len
);
3622 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
3623 reply_len
= wpa_supplicant_ctrl_iface_status(
3624 wpa_s
, buf
+ 6, reply
, reply_size
);
3625 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3626 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
3628 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3629 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
3631 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3632 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
3634 } else if (os_strcmp(buf
, "LOGON") == 0) {
3635 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
3636 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
3637 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
3638 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
3639 wpa_s
->normal_scans
= 0;
3640 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3643 wpa_s
->disconnected
= 0;
3644 wpa_s
->reassociate
= 1;
3645 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3647 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
3648 wpa_s
->normal_scans
= 0;
3649 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3651 else if (wpa_s
->disconnected
) {
3652 wpa_s
->disconnected
= 0;
3653 wpa_s
->reassociate
= 1;
3654 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3656 #ifdef IEEE8021X_EAPOL
3657 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
3658 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
3660 #endif /* IEEE8021X_EAPOL */
3661 #ifdef CONFIG_PEERKEY
3662 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
3663 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
3665 #endif /* CONFIG_PEERKEY */
3666 #ifdef CONFIG_IEEE80211R
3667 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
3668 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
3670 #endif /* CONFIG_IEEE80211R */
3672 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
3673 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
3675 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3679 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
3680 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
3682 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3686 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
3687 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
3690 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
3691 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
3692 wpa_s
, buf
+ 14, reply
, reply_size
);
3693 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
3694 if (wpas_wps_cancel(wpa_s
))
3696 #ifdef CONFIG_WPS_OOB
3697 } else if (os_strncmp(buf
, "WPS_OOB ", 8) == 0) {
3698 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s
, buf
+ 8))
3700 #endif /* CONFIG_WPS_OOB */
3701 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
3702 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
3705 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
3706 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
3707 wpa_s
, buf
+ 11, reply
, reply_size
);
3708 #endif /* CONFIG_AP */
3709 #ifdef CONFIG_WPS_ER
3710 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
3711 if (wpas_wps_er_start(wpa_s
, NULL
))
3713 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
3714 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
3716 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
3717 if (wpas_wps_er_stop(wpa_s
))
3719 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
3720 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
3722 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
3723 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
3725 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3727 } else if (ret
== -3) {
3728 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
3730 } else if (ret
== -4) {
3731 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
3735 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
3736 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
3738 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
3739 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
3742 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
3743 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
3745 #endif /* CONFIG_WPS_ER */
3746 #endif /* CONFIG_WPS */
3747 #ifdef CONFIG_IBSS_RSN
3748 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
3749 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
3751 #endif /* CONFIG_IBSS_RSN */
3753 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
3754 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
3756 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
3757 if (p2p_ctrl_find(wpa_s
, ""))
3759 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
3760 wpas_p2p_stop_find(wpa_s
);
3761 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
3762 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
3764 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
3765 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
3767 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
3768 if (p2p_ctrl_listen(wpa_s
, ""))
3770 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
3771 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
3773 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
3774 if (wpas_p2p_group_add(wpa_s
, 0, 0))
3776 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
3777 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
3779 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
3780 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
3782 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
3783 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
3784 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
3785 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
3787 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
3788 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
3790 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
3791 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
3793 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
3794 wpas_p2p_sd_service_update(wpa_s
);
3795 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
3796 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
3798 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
3799 wpas_p2p_service_flush(wpa_s
);
3800 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
3801 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
3803 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
3804 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
3806 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
3807 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
3809 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
3810 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
3812 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
3813 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
3815 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
3816 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
3818 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
3819 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
3820 wpa_s
->force_long_sd
= 0;
3821 if (wpa_s
->global
->p2p
)
3822 p2p_flush(wpa_s
->global
->p2p
);
3823 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
3824 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
3826 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
3827 if (wpas_p2p_cancel(wpa_s
))
3829 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
3830 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
3832 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
3833 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
3835 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
3836 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
3838 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
3839 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
3841 #endif /* CONFIG_P2P */
3842 #ifdef CONFIG_INTERWORKING
3843 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
3844 if (interworking_fetch_anqp(wpa_s
) < 0)
3846 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
3847 interworking_stop_fetch_anqp(wpa_s
);
3848 } else if (os_strncmp(buf
, "INTERWORKING_SELECT", 19) == 0) {
3849 if (interworking_select(wpa_s
, os_strstr(buf
+ 19, "auto") !=
3852 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
3853 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
3855 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
3856 if (get_anqp(wpa_s
, buf
+ 9) < 0)
3858 #endif /* CONFIG_INTERWORKING */
3859 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
3861 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
3862 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
3866 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
3867 if (wpa_supplicant_reload_configuration(wpa_s
))
3869 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
3870 wpa_supplicant_terminate_proc(wpa_s
->global
);
3871 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
3872 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
3874 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
3875 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
3876 wpa_s
, buf
+ 9, reply
, reply_size
);
3877 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
3878 reply_len
= wpa_supplicant_ctrl_iface_log_level(
3879 wpa_s
, buf
+ 9, reply
, reply_size
);
3880 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
3881 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
3882 wpa_s
, reply
, reply_size
);
3883 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
3884 wpa_s
->reassociate
= 0;
3885 wpa_s
->disconnected
= 1;
3886 wpa_supplicant_cancel_sched_scan(wpa_s
);
3887 wpa_supplicant_deauthenticate(wpa_s
,
3888 WLAN_REASON_DEAUTH_LEAVING
);
3889 } else if (os_strcmp(buf
, "SCAN") == 0) {
3890 wpa_s
->normal_scans
= 0;
3891 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3894 if (!wpa_s
->scanning
&&
3895 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
3896 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
3897 wpa_s
->scan_req
= 2;
3898 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3900 wpa_printf(MSG_DEBUG
, "Ongoing scan action - "
3901 "reject new request");
3902 reply_len
= os_snprintf(reply
, reply_size
,
3906 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
3907 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
3908 wpa_s
, reply
, reply_size
);
3909 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
3910 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
3912 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
3913 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
3915 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
3916 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
3918 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
3919 reply_len
= wpa_supplicant_ctrl_iface_add_network(
3920 wpa_s
, reply
, reply_size
);
3921 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
3922 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
3924 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
3925 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
3927 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
3928 reply_len
= wpa_supplicant_ctrl_iface_get_network(
3929 wpa_s
, buf
+ 12, reply
, reply_size
);
3930 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
3931 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
3932 wpa_s
, reply
, reply_size
);
3933 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
3934 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
3935 wpa_s
, reply
, reply_size
);
3936 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
3937 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
3939 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
3940 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
3942 #ifndef CONFIG_NO_CONFIG_WRITE
3943 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
3944 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
3946 #endif /* CONFIG_NO_CONFIG_WRITE */
3947 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
3948 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
3949 wpa_s
, buf
+ 15, reply
, reply_size
);
3950 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
3951 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
3953 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
3954 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
3956 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
3957 reply_len
= wpa_supplicant_global_iface_list(
3958 wpa_s
->global
, reply
, reply_size
);
3959 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
3960 reply_len
= wpa_supplicant_global_iface_interfaces(
3961 wpa_s
->global
, reply
, reply_size
);
3962 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
3963 reply_len
= wpa_supplicant_ctrl_iface_bss(
3964 wpa_s
, buf
+ 4, reply
, reply_size
);
3966 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
3967 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
3968 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
3969 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
3971 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
3972 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
3974 #endif /* CONFIG_AP */
3975 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
3976 wpas_notify_suspend(wpa_s
->global
);
3977 } else if (os_strcmp(buf
, "RESUME") == 0) {
3978 wpas_notify_resume(wpa_s
->global
);
3979 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
3980 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
3981 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
3982 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
3984 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
3985 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
3987 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
3988 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
3990 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
3991 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
3995 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
3996 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
3998 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
3999 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
4001 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
4002 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
4004 #endif /* CONFIG_TDLS */
4005 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
4006 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
4008 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
4009 eapol_sm_request_reauth(wpa_s
->eapol
);
4011 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4015 if (reply_len
< 0) {
4016 os_memcpy(reply
, "FAIL\n", 5);
4021 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
4023 *resp_len
= reply_len
;
4028 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
4031 struct wpa_interface iface
;
4035 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
4036 * TAB<bridge_ifname>
4038 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
4040 os_memset(&iface
, 0, sizeof(iface
));
4043 iface
.ifname
= pos
= cmd
;
4044 pos
= os_strchr(pos
, '\t');
4047 if (iface
.ifname
[0] == '\0')
4052 iface
.confname
= pos
;
4053 pos
= os_strchr(pos
, '\t');
4056 if (iface
.confname
[0] == '\0')
4057 iface
.confname
= NULL
;
4062 pos
= os_strchr(pos
, '\t');
4065 if (iface
.driver
[0] == '\0')
4066 iface
.driver
= NULL
;
4070 iface
.ctrl_interface
= pos
;
4071 pos
= os_strchr(pos
, '\t');
4074 if (iface
.ctrl_interface
[0] == '\0')
4075 iface
.ctrl_interface
= NULL
;
4079 iface
.driver_param
= pos
;
4080 pos
= os_strchr(pos
, '\t');
4083 if (iface
.driver_param
[0] == '\0')
4084 iface
.driver_param
= NULL
;
4088 iface
.bridge_ifname
= pos
;
4089 pos
= os_strchr(pos
, '\t');
4092 if (iface
.bridge_ifname
[0] == '\0')
4093 iface
.bridge_ifname
= NULL
;
4098 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
4101 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
4105 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
4108 struct wpa_supplicant
*wpa_s
;
4110 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
4112 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
4115 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
4119 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
4121 struct wpa_interface_info
*prev
;
4125 iface
= iface
->next
;
4127 os_free(prev
->ifname
);
4128 os_free(prev
->desc
);
4134 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
4138 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
4141 for (i
= 0; wpa_drivers
[i
]; i
++) {
4142 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
4143 if (drv
->get_interfaces
== NULL
)
4145 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
4159 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
4160 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
4161 tmp
->drv_name
, tmp
->ifname
,
4162 tmp
->desc
? tmp
->desc
: "");
4163 if (res
< 0 || res
>= end
- pos
) {
4170 wpa_free_iface_info(iface
);
4176 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
4181 struct wpa_supplicant
*wpa_s
;
4183 wpa_s
= global
->ifaces
;
4188 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
4189 if (res
< 0 || res
>= end
- pos
) {
4194 wpa_s
= wpa_s
->next
;
4200 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
4201 char *buf
, size_t *resp_len
)
4204 const int reply_size
= 2048;
4206 int level
= MSG_DEBUG
;
4208 if (os_strcmp(buf
, "PING") == 0)
4209 level
= MSG_EXCESSIVE
;
4210 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
4211 (const u8
*) buf
, os_strlen(buf
));
4213 reply
= os_malloc(reply_size
);
4214 if (reply
== NULL
) {
4219 os_memcpy(reply
, "OK\n", 3);
4222 if (os_strcmp(buf
, "PING") == 0) {
4223 os_memcpy(reply
, "PONG\n", 5);
4225 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
4226 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
4228 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
4229 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
4231 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
4232 reply_len
= wpa_supplicant_global_iface_list(
4233 global
, reply
, reply_size
);
4234 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
4235 reply_len
= wpa_supplicant_global_iface_interfaces(
4236 global
, reply
, reply_size
);
4237 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4238 wpa_supplicant_terminate_proc(global
);
4239 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
4240 wpas_notify_suspend(global
);
4241 } else if (os_strcmp(buf
, "RESUME") == 0) {
4242 wpas_notify_resume(global
);
4244 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4248 if (reply_len
< 0) {
4249 os_memcpy(reply
, "FAIL\n", 5);
4253 *resp_len
= reply_len
;