2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/wpa_ctrl.h"
21 #include "eap_peer/eap.h"
22 #include "eapol_supp/eapol_supp_sm.h"
23 #include "rsn_supp/wpa.h"
24 #include "rsn_supp/preauth.h"
25 #include "rsn_supp/pmksa_cache.h"
26 #include "l2_packet/l2_packet.h"
29 #include "wpa_supplicant_i.h"
31 #include "wps_supplicant.h"
37 #include "ctrl_iface.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 wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
53 value
= os_strchr(cmd
, ' ');
58 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
59 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
60 eapol_sm_configure(wpa_s
->eapol
,
61 atoi(value
), -1, -1, -1);
62 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
63 eapol_sm_configure(wpa_s
->eapol
,
64 -1, atoi(value
), -1, -1);
65 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
66 eapol_sm_configure(wpa_s
->eapol
,
67 -1, -1, atoi(value
), -1);
68 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
69 eapol_sm_configure(wpa_s
->eapol
,
70 -1, -1, -1, atoi(value
));
71 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
72 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
75 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
77 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
80 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
81 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
90 #ifdef IEEE8021X_EAPOL
91 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
95 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
97 if (hwaddr_aton(addr
, bssid
)) {
98 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
103 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
104 rsn_preauth_deinit(wpa_s
->wpa
);
105 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
110 #endif /* IEEE8021X_EAPOL */
113 #ifdef CONFIG_PEERKEY
114 /* MLME-STKSTART.request(peer) */
115 static int wpa_supplicant_ctrl_iface_stkstart(
116 struct wpa_supplicant
*wpa_s
, char *addr
)
120 if (hwaddr_aton(addr
, peer
)) {
121 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
122 "address '%s'", peer
);
126 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
129 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
131 #endif /* CONFIG_PEERKEY */
134 #ifdef CONFIG_IEEE80211R
135 static int wpa_supplicant_ctrl_iface_ft_ds(
136 struct wpa_supplicant
*wpa_s
, char *addr
)
138 u8 target_ap
[ETH_ALEN
];
140 if (hwaddr_aton(addr
, target_ap
)) {
141 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
142 "address '%s'", target_ap
);
146 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
148 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
);
150 #endif /* CONFIG_IEEE80211R */
154 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
157 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
159 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0)
161 else if (hwaddr_aton(cmd
, bssid
)) {
162 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
169 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
);
170 #endif /* CONFIG_AP */
172 return wpas_wps_start_pbc(wpa_s
, _bssid
);
176 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
177 char *cmd
, char *buf
,
180 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
184 pin
= os_strchr(cmd
, ' ');
188 if (os_strcmp(cmd
, "any") == 0)
190 else if (hwaddr_aton(cmd
, bssid
)) {
191 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
198 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
200 #endif /* CONFIG_AP */
203 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
);
206 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
207 if (ret
< 0 || (size_t) ret
>= buflen
)
212 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
);
216 /* Return the generated PIN */
217 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
218 if (ret
< 0 || (size_t) ret
>= buflen
)
224 #ifdef CONFIG_WPS_OOB
225 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant
*wpa_s
,
228 char *path
, *method
, *name
;
230 path
= os_strchr(cmd
, ' ');
235 method
= os_strchr(path
, ' ');
240 name
= os_strchr(method
, ' ');
244 return wpas_wps_start_oob(wpa_s
, cmd
, path
, method
, name
);
246 #endif /* CONFIG_WPS_OOB */
249 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
252 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
258 struct wps_new_ap_settings ap
;
260 pin
= os_strchr(cmd
, ' ');
265 if (os_strcmp(cmd
, "any") == 0)
267 else if (hwaddr_aton(cmd
, bssid
)) {
268 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
273 new_ssid
= os_strchr(pin
, ' ');
274 if (new_ssid
== NULL
)
275 return wpas_wps_start_reg(wpa_s
, _bssid
, pin
, NULL
);
278 new_auth
= os_strchr(new_ssid
, ' ');
279 if (new_auth
== NULL
)
283 new_encr
= os_strchr(new_auth
, ' ');
284 if (new_encr
== NULL
)
288 new_key
= os_strchr(new_encr
, ' ');
293 os_memset(&ap
, 0, sizeof(ap
));
294 ap
.ssid_hex
= new_ssid
;
297 ap
.key_hex
= new_key
;
298 return wpas_wps_start_reg(wpa_s
, _bssid
, pin
, &ap
);
303 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
306 char *uuid
= cmd
, *pin
;
307 pin
= os_strchr(uuid
, ' ');
311 return wpas_wps_er_add_pin(wpa_s
, uuid
, pin
);
315 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
318 char *uuid
= cmd
, *pin
;
319 pin
= os_strchr(uuid
, ' ');
323 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
325 #endif /* CONFIG_WPS_ER */
327 #endif /* CONFIG_WPS */
330 #ifdef CONFIG_IBSS_RSN
331 static int wpa_supplicant_ctrl_iface_ibss_rsn(
332 struct wpa_supplicant
*wpa_s
, char *addr
)
336 if (hwaddr_aton(addr
, peer
)) {
337 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
338 "address '%s'", peer
);
342 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
345 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
347 #endif /* CONFIG_IBSS_RSN */
350 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
353 #ifdef IEEE8021X_EAPOL
356 struct wpa_ssid
*ssid
;
357 struct eap_peer_config
*eap
;
359 pos
= os_strchr(rsp
, '-');
364 pos
= os_strchr(pos
, ':');
369 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
370 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
371 (u8
*) pos
, os_strlen(pos
));
373 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
375 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
381 if (os_strcmp(rsp
, "IDENTITY") == 0) {
382 os_free(eap
->identity
);
383 eap
->identity
= (u8
*) os_strdup(pos
);
384 eap
->identity_len
= os_strlen(pos
);
385 eap
->pending_req_identity
= 0;
386 if (ssid
== wpa_s
->current_ssid
)
387 wpa_s
->reassociate
= 1;
388 } else if (os_strcmp(rsp
, "PASSWORD") == 0) {
389 os_free(eap
->password
);
390 eap
->password
= (u8
*) os_strdup(pos
);
391 eap
->password_len
= os_strlen(pos
);
392 eap
->pending_req_password
= 0;
393 if (ssid
== wpa_s
->current_ssid
)
394 wpa_s
->reassociate
= 1;
395 } else if (os_strcmp(rsp
, "NEW_PASSWORD") == 0) {
396 os_free(eap
->new_password
);
397 eap
->new_password
= (u8
*) os_strdup(pos
);
398 eap
->new_password_len
= os_strlen(pos
);
399 eap
->pending_req_new_password
= 0;
400 if (ssid
== wpa_s
->current_ssid
)
401 wpa_s
->reassociate
= 1;
402 } else if (os_strcmp(rsp
, "PIN") == 0) {
404 eap
->pin
= os_strdup(pos
);
405 eap
->pending_req_pin
= 0;
406 if (ssid
== wpa_s
->current_ssid
)
407 wpa_s
->reassociate
= 1;
408 } else if (os_strcmp(rsp
, "OTP") == 0) {
410 eap
->otp
= (u8
*) os_strdup(pos
);
411 eap
->otp_len
= os_strlen(pos
);
412 os_free(eap
->pending_req_otp
);
413 eap
->pending_req_otp
= NULL
;
414 eap
->pending_req_otp_len
= 0;
415 } else if (os_strcmp(rsp
, "PASSPHRASE") == 0) {
416 os_free(eap
->private_key_passwd
);
417 eap
->private_key_passwd
= (u8
*) os_strdup(pos
);
418 eap
->pending_req_passphrase
= 0;
419 if (ssid
== wpa_s
->current_ssid
)
420 wpa_s
->reassociate
= 1;
422 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", rsp
);
427 #else /* IEEE8021X_EAPOL */
428 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
430 #endif /* IEEE8021X_EAPOL */
434 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
436 char *buf
, size_t buflen
)
438 char *pos
, *end
, tmp
[30];
439 int res
, verbose
, ret
;
441 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
444 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
445 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
446 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
447 MAC2STR(wpa_s
->bssid
));
448 if (ret
< 0 || ret
>= end
- pos
)
452 u8
*_ssid
= ssid
->ssid
;
453 size_t ssid_len
= ssid
->ssid_len
;
454 u8 ssid_buf
[MAX_SSID_LEN
];
456 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
463 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
464 wpa_ssid_txt(_ssid
, ssid_len
),
466 if (ret
< 0 || ret
>= end
- pos
)
471 ret
= os_snprintf(pos
, end
- pos
,
474 if (ret
< 0 || ret
>= end
- pos
)
479 switch (ssid
->mode
) {
480 case WPAS_MODE_INFRA
:
481 ret
= os_snprintf(pos
, end
- pos
,
485 ret
= os_snprintf(pos
, end
- pos
,
489 ret
= os_snprintf(pos
, end
- pos
,
496 if (ret
< 0 || ret
>= end
- pos
)
502 if (wpa_s
->ap_iface
) {
503 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
507 #endif /* CONFIG_AP */
508 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
510 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
511 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
512 if (ret
< 0 || ret
>= end
- pos
)
517 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
518 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
519 if (ret
< 0 || ret
>= end
- pos
)
524 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
525 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
526 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
532 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
540 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
545 struct wpa_ssid
*ssid
;
548 /* cmd: "<network id> <BSSID>" */
549 pos
= os_strchr(cmd
, ' ');
554 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
555 if (hwaddr_aton(pos
, bssid
)) {
556 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
560 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
562 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
567 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
568 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
574 static int wpa_supplicant_ctrl_iface_list_networks(
575 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
578 struct wpa_ssid
*ssid
;
583 ret
= os_snprintf(pos
, end
- pos
,
584 "network id / ssid / bssid / flags\n");
585 if (ret
< 0 || ret
>= end
- pos
)
589 ssid
= wpa_s
->conf
->ssid
;
591 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
593 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
594 if (ret
< 0 || ret
>= end
- pos
)
597 if (ssid
->bssid_set
) {
598 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
599 MAC2STR(ssid
->bssid
));
601 ret
= os_snprintf(pos
, end
- pos
, "\tany");
603 if (ret
< 0 || ret
>= end
- pos
)
606 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s",
607 ssid
== wpa_s
->current_ssid
?
609 ssid
->disabled
? "[DISABLED]" : "");
610 if (ret
< 0 || ret
>= end
- pos
)
613 ret
= os_snprintf(pos
, end
- pos
, "\n");
614 if (ret
< 0 || ret
>= end
- pos
)
625 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
628 ret
= os_snprintf(pos
, end
- pos
, "-");
629 if (ret
< 0 || ret
>= end
- pos
)
632 if (cipher
& WPA_CIPHER_NONE
) {
633 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : "+");
634 if (ret
< 0 || ret
>= end
- pos
)
639 if (cipher
& WPA_CIPHER_WEP40
) {
640 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : "+");
641 if (ret
< 0 || ret
>= end
- pos
)
646 if (cipher
& WPA_CIPHER_WEP104
) {
647 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
649 if (ret
< 0 || ret
>= end
- pos
)
654 if (cipher
& WPA_CIPHER_TKIP
) {
655 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : "+");
656 if (ret
< 0 || ret
>= end
- pos
)
661 if (cipher
& WPA_CIPHER_CCMP
) {
662 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : "+");
663 if (ret
< 0 || ret
>= end
- pos
)
672 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
673 const u8
*ie
, size_t ie_len
)
675 struct wpa_ie_data data
;
678 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
679 if (ret
< 0 || ret
>= end
- pos
)
683 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
684 ret
= os_snprintf(pos
, end
- pos
, "?]");
685 if (ret
< 0 || ret
>= end
- pos
)
692 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
693 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
694 if (ret
< 0 || ret
>= end
- pos
)
699 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
700 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
701 if (ret
< 0 || ret
>= end
- pos
)
706 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
707 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
708 if (ret
< 0 || ret
>= end
- pos
)
713 #ifdef CONFIG_IEEE80211R
714 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
715 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
717 if (ret
< 0 || ret
>= end
- pos
)
722 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
723 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
725 if (ret
< 0 || ret
>= end
- pos
)
730 #endif /* CONFIG_IEEE80211R */
731 #ifdef CONFIG_IEEE80211W
732 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
733 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
735 if (ret
< 0 || ret
>= end
- pos
)
740 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
741 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
743 if (ret
< 0 || ret
>= end
- pos
)
748 #endif /* CONFIG_IEEE80211W */
750 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
752 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
753 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
754 if (ret
< 0 || ret
>= end
- pos
)
759 ret
= os_snprintf(pos
, end
- pos
, "]");
760 if (ret
< 0 || ret
>= end
- pos
)
769 static char * wpa_supplicant_wps_ie_txt_buf(char *pos
, char *end
,
770 struct wpabuf
*wps_ie
)
777 if (wps_is_selected_pbc_registrar(wps_ie
))
779 else if (wps_is_selected_pin_registrar(wps_ie
))
784 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
785 if (ret
>= 0 && ret
< end
- pos
)
790 #endif /* CONFIG_WPS */
793 static char * wpa_supplicant_wps_ie_txt(char *pos
, char *end
,
794 const struct wpa_bss
*bss
)
797 struct wpabuf
*wps_ie
;
798 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
799 return wpa_supplicant_wps_ie_txt_buf(pos
, end
, wps_ie
);
800 #else /* CONFIG_WPS */
802 #endif /* CONFIG_WPS */
806 /* Format one result on one text line into a buffer. */
807 static int wpa_supplicant_ctrl_iface_scan_result(
808 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
817 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
818 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
819 if (ret
< 0 || ret
>= end
- pos
)
822 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
824 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
825 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
827 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
828 pos
= wpa_supplicant_wps_ie_txt(pos
, end
, bss
);
829 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
830 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
831 if (ret
< 0 || ret
>= end
- pos
)
835 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
836 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
837 if (ret
< 0 || ret
>= end
- pos
)
841 if (bss
->caps
& IEEE80211_CAP_ESS
) {
842 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
843 if (ret
< 0 || ret
>= end
- pos
)
848 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
849 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
850 if (ret
< 0 || ret
>= end
- pos
)
854 ret
= os_snprintf(pos
, end
- pos
, "\n");
855 if (ret
< 0 || ret
>= end
- pos
)
863 static int wpa_supplicant_ctrl_iface_scan_results(
864 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
872 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
874 if (ret
< 0 || ret
>= end
- pos
)
878 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
879 ret
= wpa_supplicant_ctrl_iface_scan_result(bss
, pos
,
881 if (ret
< 0 || ret
>= end
- pos
)
890 static int wpa_supplicant_ctrl_iface_select_network(
891 struct wpa_supplicant
*wpa_s
, char *cmd
)
894 struct wpa_ssid
*ssid
;
896 /* cmd: "<network id>" or "any" */
897 if (os_strcmp(cmd
, "any") == 0) {
898 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
902 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
904 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
906 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
907 "network id=%d", id
);
912 wpa_supplicant_select_network(wpa_s
, ssid
);
918 static int wpa_supplicant_ctrl_iface_enable_network(
919 struct wpa_supplicant
*wpa_s
, char *cmd
)
922 struct wpa_ssid
*ssid
;
924 /* cmd: "<network id>" or "all" */
925 if (os_strcmp(cmd
, "all") == 0) {
926 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
930 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
932 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
934 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
935 "network id=%d", id
);
939 wpa_supplicant_enable_network(wpa_s
, ssid
);
945 static int wpa_supplicant_ctrl_iface_disable_network(
946 struct wpa_supplicant
*wpa_s
, char *cmd
)
949 struct wpa_ssid
*ssid
;
951 /* cmd: "<network id>" or "all" */
952 if (os_strcmp(cmd
, "all") == 0) {
953 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
957 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
959 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
961 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
962 "network id=%d", id
);
966 wpa_supplicant_disable_network(wpa_s
, ssid
);
972 static int wpa_supplicant_ctrl_iface_add_network(
973 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
975 struct wpa_ssid
*ssid
;
978 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
980 ssid
= wpa_config_add_network(wpa_s
->conf
);
984 wpas_notify_network_added(wpa_s
, ssid
);
987 wpa_config_set_network_defaults(ssid
);
989 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
990 if (ret
< 0 || (size_t) ret
>= buflen
)
996 static int wpa_supplicant_ctrl_iface_remove_network(
997 struct wpa_supplicant
*wpa_s
, char *cmd
)
1000 struct wpa_ssid
*ssid
;
1002 /* cmd: "<network id>" or "all" */
1003 if (os_strcmp(cmd
, "all") == 0) {
1004 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
1005 ssid
= wpa_s
->conf
->ssid
;
1007 struct wpa_ssid
*remove_ssid
= ssid
;
1010 wpas_notify_network_removed(wpa_s
, remove_ssid
);
1011 wpa_config_remove_network(wpa_s
->conf
, id
);
1013 if (wpa_s
->current_ssid
) {
1014 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1015 wpa_supplicant_disassociate(wpa_s
,
1016 WLAN_REASON_DEAUTH_LEAVING
);
1022 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
1024 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1026 wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
1027 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1032 if (ssid
== wpa_s
->current_ssid
) {
1034 * Invalidate the EAP session cache if the current network is
1037 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1039 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1046 static int wpa_supplicant_ctrl_iface_set_network(
1047 struct wpa_supplicant
*wpa_s
, char *cmd
)
1050 struct wpa_ssid
*ssid
;
1053 /* cmd: "<network id> <variable name> <value>" */
1054 name
= os_strchr(cmd
, ' ');
1059 value
= os_strchr(name
, ' ');
1065 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1067 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1068 (u8
*) value
, os_strlen(value
));
1070 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1072 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1077 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
1078 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
1079 "variable '%s'", name
);
1083 if (wpa_s
->current_ssid
== ssid
) {
1085 * Invalidate the EAP session cache if anything in the current
1086 * configuration changes.
1088 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1091 if ((os_strcmp(name
, "psk") == 0 &&
1092 value
[0] == '"' && ssid
->ssid_len
) ||
1093 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
1094 wpa_config_update_psk(ssid
);
1100 static int wpa_supplicant_ctrl_iface_get_network(
1101 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1105 struct wpa_ssid
*ssid
;
1108 /* cmd: "<network id> <variable name>" */
1109 name
= os_strchr(cmd
, ' ');
1110 if (name
== NULL
|| buflen
== 0)
1115 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1118 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1120 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1125 value
= wpa_config_get_no_key(ssid
, name
);
1126 if (value
== NULL
) {
1127 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
1128 "variable '%s'", name
);
1132 res
= os_strlcpy(buf
, value
, buflen
);
1133 if (res
>= buflen
) {
1144 #ifndef CONFIG_NO_CONFIG_WRITE
1145 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
1149 if (!wpa_s
->conf
->update_config
) {
1150 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
1151 "to update configuration (update_config=0)");
1155 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
1157 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
1158 "update configuration");
1160 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
1166 #endif /* CONFIG_NO_CONFIG_WRITE */
1169 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
1170 struct wpa_driver_capa
*capa
,
1171 char *buf
, size_t buflen
)
1183 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
1189 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
1190 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
1191 if (ret
< 0 || ret
>= end
- pos
)
1197 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
1198 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
1199 if (ret
< 0 || ret
>= end
- pos
)
1205 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
1206 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : " ");
1207 if (ret
< 0 || ret
>= end
- pos
)
1217 static int ctrl_iface_get_capability_group(int res
, char *strict
,
1218 struct wpa_driver_capa
*capa
,
1219 char *buf
, size_t buflen
)
1231 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
1237 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
1238 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
1239 if (ret
< 0 || ret
>= end
- pos
)
1245 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
1246 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
1247 if (ret
< 0 || ret
>= end
- pos
)
1253 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP104
) {
1254 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
1256 if (ret
< 0 || ret
>= end
- pos
)
1262 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP40
) {
1263 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : " ");
1264 if (ret
< 0 || ret
>= end
- pos
)
1274 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
1275 struct wpa_driver_capa
*capa
,
1276 char *buf
, size_t buflen
)
1288 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
1295 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
1296 if (ret
< 0 || ret
>= end
- pos
)
1300 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1301 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
1302 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
1303 if (ret
< 0 || ret
>= end
- pos
)
1308 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
1309 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
1310 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
1311 if (ret
< 0 || ret
>= end
- pos
)
1316 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
1317 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
1318 if (ret
< 0 || ret
>= end
- pos
)
1327 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
1328 struct wpa_driver_capa
*capa
,
1329 char *buf
, size_t buflen
)
1341 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
1347 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
1348 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
1349 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
1350 if (ret
< 0 || ret
>= end
- pos
)
1356 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1357 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
1358 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
1359 if (ret
< 0 || ret
>= end
- pos
)
1369 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
1370 struct wpa_driver_capa
*capa
,
1371 char *buf
, size_t buflen
)
1383 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
1389 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
1390 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
1391 if (ret
< 0 || ret
>= end
- pos
)
1397 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
1398 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1400 if (ret
< 0 || ret
>= end
- pos
)
1406 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
1407 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
1408 if (ret
< 0 || ret
>= end
- pos
)
1418 static int wpa_supplicant_ctrl_iface_get_capability(
1419 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
1422 struct wpa_driver_capa capa
;
1428 /* Determine whether or not strict checking was requested */
1429 len
= os_strlcpy(field
, _field
, sizeof(field
));
1430 if (len
>= sizeof(field
))
1432 strict
= os_strchr(field
, ' ');
1433 if (strict
!= NULL
) {
1435 if (os_strcmp(strict
, "strict") != 0)
1439 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
1440 field
, strict
? strict
: "");
1442 if (os_strcmp(field
, "eap") == 0) {
1443 return eap_get_names(buf
, buflen
);
1446 res
= wpa_drv_get_capa(wpa_s
, &capa
);
1448 if (os_strcmp(field
, "pairwise") == 0)
1449 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
1452 if (os_strcmp(field
, "group") == 0)
1453 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
1456 if (os_strcmp(field
, "key_mgmt") == 0)
1457 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
1460 if (os_strcmp(field
, "proto") == 0)
1461 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
1464 if (os_strcmp(field
, "auth_alg") == 0)
1465 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
1468 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
1475 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
1476 const char *cmd
, char *buf
,
1481 struct wpa_bss
*bss
;
1486 if (os_strcmp(cmd
, "FIRST") == 0)
1487 bss
= dl_list_first(&wpa_s
->bss
, struct wpa_bss
, list
);
1488 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
1490 bss
= wpa_bss_get_id(wpa_s
, i
);
1491 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
1493 bss
= wpa_bss_get_id(wpa_s
, i
);
1495 struct dl_list
*next
= bss
->list_id
.next
;
1496 if (next
== &wpa_s
->bss_id
)
1499 bss
= dl_list_entry(next
, struct wpa_bss
,
1502 } else if (hwaddr_aton(cmd
, bssid
) == 0)
1503 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
1505 struct wpa_bss
*tmp
;
1508 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
1522 ret
= os_snprintf(pos
, end
- pos
,
1524 "bssid=" MACSTR
"\n"
1527 "capabilities=0x%04x\n"
1534 MAC2STR(bss
->bssid
), bss
->freq
, bss
->beacon_int
,
1535 bss
->caps
, bss
->qual
, bss
->noise
, bss
->level
,
1536 (unsigned long long) bss
->tsf
);
1537 if (ret
< 0 || ret
>= end
- pos
)
1541 ie
= (const u8
*) (bss
+ 1);
1542 for (i
= 0; i
< bss
->ie_len
; i
++) {
1543 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
1544 if (ret
< 0 || ret
>= end
- pos
)
1549 ret
= os_snprintf(pos
, end
- pos
, "\n");
1550 if (ret
< 0 || ret
>= end
- pos
)
1554 ret
= os_snprintf(pos
, end
- pos
, "flags=");
1555 if (ret
< 0 || ret
>= end
- pos
)
1559 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1561 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
1562 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1564 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
1565 pos
= wpa_supplicant_wps_ie_txt(pos
, end
, bss
);
1566 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
1567 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
1568 if (ret
< 0 || ret
>= end
- pos
)
1572 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
1573 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
1574 if (ret
< 0 || ret
>= end
- pos
)
1578 if (bss
->caps
& IEEE80211_CAP_ESS
) {
1579 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
1580 if (ret
< 0 || ret
>= end
- pos
)
1585 ret
= os_snprintf(pos
, end
- pos
, "\n");
1586 if (ret
< 0 || ret
>= end
- pos
)
1590 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
1591 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1592 if (ret
< 0 || ret
>= end
- pos
)
1597 ie
= (const u8
*) (bss
+ 1);
1598 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
1599 if (ret
< 0 || ret
>= end
- pos
)
1602 #endif /* CONFIG_WPS */
1608 static int wpa_supplicant_ctrl_iface_ap_scan(
1609 struct wpa_supplicant
*wpa_s
, char *cmd
)
1611 int ap_scan
= atoi(cmd
);
1612 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
1616 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
1617 char *buf
, size_t *resp_len
)
1620 const int reply_size
= 2048;
1624 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
1625 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
1626 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
1627 (const u8
*) buf
, os_strlen(buf
));
1629 wpa_hexdump_ascii(MSG_DEBUG
, "RX ctrl_iface",
1630 (const u8
*) buf
, os_strlen(buf
));
1633 reply
= os_malloc(reply_size
);
1634 if (reply
== NULL
) {
1639 os_memcpy(reply
, "OK\n", 3);
1642 if (os_strcmp(buf
, "PING") == 0) {
1643 os_memcpy(reply
, "PONG\n", 5);
1645 } else if (os_strcmp(buf
, "MIB") == 0) {
1646 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
1647 if (reply_len
>= 0) {
1649 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
1650 reply_size
- reply_len
);
1656 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
1657 reply_len
= wpa_supplicant_ctrl_iface_status(
1658 wpa_s
, buf
+ 6, reply
, reply_size
);
1659 } else if (os_strcmp(buf
, "PMKSA") == 0) {
1660 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
1662 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
1663 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
1665 } else if (os_strcmp(buf
, "LOGON") == 0) {
1666 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
1667 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
1668 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
1669 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
1670 wpa_s
->disconnected
= 0;
1671 wpa_s
->reassociate
= 1;
1672 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1673 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
1674 if (wpa_s
->disconnected
) {
1675 wpa_s
->disconnected
= 0;
1676 wpa_s
->reassociate
= 1;
1677 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1679 #ifdef IEEE8021X_EAPOL
1680 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
1681 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
1683 #endif /* IEEE8021X_EAPOL */
1684 #ifdef CONFIG_PEERKEY
1685 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
1686 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
1688 #endif /* CONFIG_PEERKEY */
1689 #ifdef CONFIG_IEEE80211R
1690 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
1691 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
1693 #endif /* CONFIG_IEEE80211R */
1695 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
1696 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
))
1698 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
1699 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8))
1701 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
1702 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
1705 #ifdef CONFIG_WPS_OOB
1706 } else if (os_strncmp(buf
, "WPS_OOB ", 8) == 0) {
1707 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s
, buf
+ 8))
1709 #endif /* CONFIG_WPS_OOB */
1710 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
1711 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
1713 #ifdef CONFIG_WPS_ER
1714 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
1715 if (wpas_wps_er_start(wpa_s
))
1717 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
1718 if (wpas_wps_er_stop(wpa_s
))
1720 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
1721 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
1723 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
1724 if (wpas_wps_er_pbc(wpa_s
, buf
+ 11))
1726 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
1727 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
1729 #endif /* CONFIG_WPS_ER */
1730 #endif /* CONFIG_WPS */
1731 #ifdef CONFIG_IBSS_RSN
1732 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
1733 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
1735 #endif /* CONFIG_IBSS_RSN */
1736 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
1738 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1739 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
1743 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
1744 if (wpa_supplicant_reload_configuration(wpa_s
))
1746 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
1747 wpa_supplicant_terminate_proc(wpa_s
->global
);
1748 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
1749 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
1751 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
1752 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
1753 wpa_s
, reply
, reply_size
);
1754 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
1755 wpa_s
->reassociate
= 0;
1756 wpa_s
->disconnected
= 1;
1757 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1758 } else if (os_strcmp(buf
, "SCAN") == 0) {
1759 wpa_s
->scan_req
= 2;
1760 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1761 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
1762 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
1763 wpa_s
, reply
, reply_size
);
1764 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
1765 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
1767 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
1768 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
1770 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
1771 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
1773 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
1774 reply_len
= wpa_supplicant_ctrl_iface_add_network(
1775 wpa_s
, reply
, reply_size
);
1776 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
1777 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
1779 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
1780 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
1782 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
1783 reply_len
= wpa_supplicant_ctrl_iface_get_network(
1784 wpa_s
, buf
+ 12, reply
, reply_size
);
1785 #ifndef CONFIG_NO_CONFIG_WRITE
1786 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
1787 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
1789 #endif /* CONFIG_NO_CONFIG_WRITE */
1790 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
1791 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
1792 wpa_s
, buf
+ 15, reply
, reply_size
);
1793 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
1794 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
1796 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
1797 reply_len
= wpa_supplicant_global_iface_list(
1798 wpa_s
->global
, reply
, reply_size
);
1799 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
1800 reply_len
= wpa_supplicant_global_iface_interfaces(
1801 wpa_s
->global
, reply
, reply_size
);
1802 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
1803 reply_len
= wpa_supplicant_ctrl_iface_bss(
1804 wpa_s
, buf
+ 4, reply
, reply_size
);
1806 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
1807 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
1808 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
1809 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
1811 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
1812 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
1814 #endif /* CONFIG_AP */
1816 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
1820 if (reply_len
< 0) {
1821 os_memcpy(reply
, "FAIL\n", 5);
1826 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
1828 *resp_len
= reply_len
;
1833 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
1836 struct wpa_interface iface
;
1840 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1841 * TAB<bridge_ifname>
1843 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
1845 os_memset(&iface
, 0, sizeof(iface
));
1848 iface
.ifname
= pos
= cmd
;
1849 pos
= os_strchr(pos
, '\t');
1852 if (iface
.ifname
[0] == '\0')
1857 iface
.confname
= pos
;
1858 pos
= os_strchr(pos
, '\t');
1861 if (iface
.confname
[0] == '\0')
1862 iface
.confname
= NULL
;
1867 pos
= os_strchr(pos
, '\t');
1870 if (iface
.driver
[0] == '\0')
1871 iface
.driver
= NULL
;
1875 iface
.ctrl_interface
= pos
;
1876 pos
= os_strchr(pos
, '\t');
1879 if (iface
.ctrl_interface
[0] == '\0')
1880 iface
.ctrl_interface
= NULL
;
1884 iface
.driver_param
= pos
;
1885 pos
= os_strchr(pos
, '\t');
1888 if (iface
.driver_param
[0] == '\0')
1889 iface
.driver_param
= NULL
;
1893 iface
.bridge_ifname
= pos
;
1894 pos
= os_strchr(pos
, '\t');
1897 if (iface
.bridge_ifname
[0] == '\0')
1898 iface
.bridge_ifname
= NULL
;
1903 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
1906 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
1910 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
1913 struct wpa_supplicant
*wpa_s
;
1915 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
1917 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
1920 return wpa_supplicant_remove_iface(global
, wpa_s
);
1924 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
1926 struct wpa_interface_info
*prev
;
1930 iface
= iface
->next
;
1932 os_free(prev
->ifname
);
1933 os_free(prev
->desc
);
1939 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
1943 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
1946 for (i
= 0; wpa_drivers
[i
]; i
++) {
1947 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
1948 if (drv
->get_interfaces
== NULL
)
1950 tmp
= drv
->get_interfaces(global
->drv_priv
);
1964 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
1965 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
1966 tmp
->drv_name
, tmp
->ifname
,
1967 tmp
->desc
? tmp
->desc
: "");
1968 if (res
< 0 || res
>= end
- pos
) {
1975 wpa_free_iface_info(iface
);
1981 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
1986 struct wpa_supplicant
*wpa_s
;
1988 wpa_s
= global
->ifaces
;
1993 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
1994 if (res
< 0 || res
>= end
- pos
) {
1999 wpa_s
= wpa_s
->next
;
2005 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
2006 char *buf
, size_t *resp_len
)
2009 const int reply_size
= 2048;
2012 wpa_hexdump_ascii(MSG_DEBUG
, "RX global ctrl_iface",
2013 (const u8
*) buf
, os_strlen(buf
));
2015 reply
= os_malloc(reply_size
);
2016 if (reply
== NULL
) {
2021 os_memcpy(reply
, "OK\n", 3);
2024 if (os_strcmp(buf
, "PING") == 0) {
2025 os_memcpy(reply
, "PONG\n", 5);
2027 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
2028 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
2030 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
2031 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
2033 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
2034 reply_len
= wpa_supplicant_global_iface_list(
2035 global
, reply
, reply_size
);
2036 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
2037 reply_len
= wpa_supplicant_global_iface_interfaces(
2038 global
, reply
, reply_size
);
2039 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
2040 wpa_supplicant_terminate_proc(global
);
2042 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
2046 if (reply_len
< 0) {
2047 os_memcpy(reply
, "FAIL\n", 5);
2051 *resp_len
= reply_len
;