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.
21 #include "eapol_supp/eapol_supp_sm.h"
22 #include "wpa_supplicant_i.h"
24 #include "ctrl_iface.h"
25 #include "l2_packet/l2_packet.h"
27 #include "pmksa_cache.h"
28 #include "common/wpa_ctrl.h"
29 #include "eap_peer/eap.h"
30 #include "common/ieee802_11_defs.h"
31 #include "wps_supplicant.h"
37 extern struct wpa_driver_ops
*wpa_drivers
[];
39 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
41 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
45 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
51 value
= os_strchr(cmd
, ' ');
56 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
57 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
58 eapol_sm_configure(wpa_s
->eapol
,
59 atoi(value
), -1, -1, -1);
60 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
61 eapol_sm_configure(wpa_s
->eapol
,
62 -1, atoi(value
), -1, -1);
63 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
64 eapol_sm_configure(wpa_s
->eapol
,
65 -1, -1, atoi(value
), -1);
66 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
67 eapol_sm_configure(wpa_s
->eapol
,
68 -1, -1, -1, atoi(value
));
69 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
70 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
73 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
75 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
78 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
79 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
88 #ifdef IEEE8021X_EAPOL
89 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
93 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
95 if (hwaddr_aton(addr
, bssid
)) {
96 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
101 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
102 rsn_preauth_deinit(wpa_s
->wpa
);
103 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
108 #endif /* IEEE8021X_EAPOL */
111 #ifdef CONFIG_PEERKEY
112 /* MLME-STKSTART.request(peer) */
113 static int wpa_supplicant_ctrl_iface_stkstart(
114 struct wpa_supplicant
*wpa_s
, char *addr
)
118 if (hwaddr_aton(addr
, peer
)) {
119 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
120 "address '%s'", peer
);
124 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
127 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
129 #endif /* CONFIG_PEERKEY */
132 #ifdef CONFIG_IEEE80211R
133 static int wpa_supplicant_ctrl_iface_ft_ds(
134 struct wpa_supplicant
*wpa_s
, char *addr
)
136 u8 target_ap
[ETH_ALEN
];
138 if (hwaddr_aton(addr
, target_ap
)) {
139 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
140 "address '%s'", target_ap
);
144 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
146 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
);
148 #endif /* CONFIG_IEEE80211R */
152 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
155 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
157 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0)
159 else if (hwaddr_aton(cmd
, bssid
)) {
160 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
167 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
);
168 #endif /* CONFIG_AP */
170 return wpas_wps_start_pbc(wpa_s
, _bssid
);
174 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
175 char *cmd
, char *buf
,
178 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
182 pin
= os_strchr(cmd
, ' ');
186 if (os_strcmp(cmd
, "any") == 0)
188 else if (hwaddr_aton(cmd
, bssid
)) {
189 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
196 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
198 #endif /* CONFIG_AP */
201 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
);
204 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
205 if (ret
< 0 || (size_t) ret
>= buflen
)
210 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
);
214 /* Return the generated PIN */
215 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
216 if (ret
< 0 || (size_t) ret
>= buflen
)
222 #ifdef CONFIG_WPS_OOB
223 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant
*wpa_s
,
226 char *path
, *method
, *name
;
228 path
= os_strchr(cmd
, ' ');
233 method
= os_strchr(path
, ' ');
238 name
= os_strchr(method
, ' ');
242 return wpas_wps_start_oob(wpa_s
, cmd
, path
, method
, name
);
244 #endif /* CONFIG_WPS_OOB */
247 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
250 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
256 struct wps_new_ap_settings ap
;
258 pin
= os_strchr(cmd
, ' ');
263 if (os_strcmp(cmd
, "any") == 0)
265 else if (hwaddr_aton(cmd
, bssid
)) {
266 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
271 new_ssid
= os_strchr(pin
, ' ');
272 if (new_ssid
== NULL
)
273 return wpas_wps_start_reg(wpa_s
, _bssid
, pin
, NULL
);
276 new_auth
= os_strchr(new_ssid
, ' ');
277 if (new_auth
== NULL
)
281 new_encr
= os_strchr(new_auth
, ' ');
282 if (new_encr
== NULL
)
286 new_key
= os_strchr(new_encr
, ' ');
291 os_memset(&ap
, 0, sizeof(ap
));
292 ap
.ssid_hex
= new_ssid
;
295 ap
.key_hex
= new_key
;
296 return wpas_wps_start_reg(wpa_s
, _bssid
, pin
, &ap
);
301 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
304 char *uuid
= cmd
, *pin
;
305 pin
= os_strchr(uuid
, ' ');
309 return wpas_wps_er_add_pin(wpa_s
, uuid
, pin
);
313 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
316 char *uuid
= cmd
, *pin
;
317 pin
= os_strchr(uuid
, ' ');
321 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
323 #endif /* CONFIG_WPS_ER */
325 #endif /* CONFIG_WPS */
328 #ifdef CONFIG_IBSS_RSN
329 static int wpa_supplicant_ctrl_iface_ibss_rsn(
330 struct wpa_supplicant
*wpa_s
, char *addr
)
334 if (hwaddr_aton(addr
, peer
)) {
335 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
336 "address '%s'", peer
);
340 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
343 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
345 #endif /* CONFIG_IBSS_RSN */
348 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
351 #ifdef IEEE8021X_EAPOL
354 struct wpa_ssid
*ssid
;
355 struct eap_peer_config
*eap
;
357 pos
= os_strchr(rsp
, '-');
362 pos
= os_strchr(pos
, ':');
367 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
368 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
369 (u8
*) pos
, os_strlen(pos
));
371 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
373 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
379 if (os_strcmp(rsp
, "IDENTITY") == 0) {
380 os_free(eap
->identity
);
381 eap
->identity
= (u8
*) os_strdup(pos
);
382 eap
->identity_len
= os_strlen(pos
);
383 eap
->pending_req_identity
= 0;
384 if (ssid
== wpa_s
->current_ssid
)
385 wpa_s
->reassociate
= 1;
386 } else if (os_strcmp(rsp
, "PASSWORD") == 0) {
387 os_free(eap
->password
);
388 eap
->password
= (u8
*) os_strdup(pos
);
389 eap
->password_len
= os_strlen(pos
);
390 eap
->pending_req_password
= 0;
391 if (ssid
== wpa_s
->current_ssid
)
392 wpa_s
->reassociate
= 1;
393 } else if (os_strcmp(rsp
, "NEW_PASSWORD") == 0) {
394 os_free(eap
->new_password
);
395 eap
->new_password
= (u8
*) os_strdup(pos
);
396 eap
->new_password_len
= os_strlen(pos
);
397 eap
->pending_req_new_password
= 0;
398 if (ssid
== wpa_s
->current_ssid
)
399 wpa_s
->reassociate
= 1;
400 } else if (os_strcmp(rsp
, "PIN") == 0) {
402 eap
->pin
= os_strdup(pos
);
403 eap
->pending_req_pin
= 0;
404 if (ssid
== wpa_s
->current_ssid
)
405 wpa_s
->reassociate
= 1;
406 } else if (os_strcmp(rsp
, "OTP") == 0) {
408 eap
->otp
= (u8
*) os_strdup(pos
);
409 eap
->otp_len
= os_strlen(pos
);
410 os_free(eap
->pending_req_otp
);
411 eap
->pending_req_otp
= NULL
;
412 eap
->pending_req_otp_len
= 0;
413 } else if (os_strcmp(rsp
, "PASSPHRASE") == 0) {
414 os_free(eap
->private_key_passwd
);
415 eap
->private_key_passwd
= (u8
*) os_strdup(pos
);
416 eap
->pending_req_passphrase
= 0;
417 if (ssid
== wpa_s
->current_ssid
)
418 wpa_s
->reassociate
= 1;
420 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", rsp
);
425 #else /* IEEE8021X_EAPOL */
426 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
428 #endif /* IEEE8021X_EAPOL */
432 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
434 char *buf
, size_t buflen
)
436 char *pos
, *end
, tmp
[30];
437 int res
, verbose
, ret
;
439 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
442 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
443 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
444 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
445 MAC2STR(wpa_s
->bssid
));
446 if (ret
< 0 || ret
>= end
- pos
)
450 u8
*_ssid
= ssid
->ssid
;
451 size_t ssid_len
= ssid
->ssid_len
;
452 u8 ssid_buf
[MAX_SSID_LEN
];
454 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
461 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
462 wpa_ssid_txt(_ssid
, ssid_len
),
464 if (ret
< 0 || ret
>= end
- pos
)
469 ret
= os_snprintf(pos
, end
- pos
,
472 if (ret
< 0 || ret
>= end
- pos
)
479 if (wpa_s
->ap_iface
) {
480 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
484 #endif /* CONFIG_AP */
485 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
487 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
488 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
489 if (ret
< 0 || ret
>= end
- pos
)
494 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
495 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
496 if (ret
< 0 || ret
>= end
- pos
)
501 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
502 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
503 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
509 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
517 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
522 struct wpa_ssid
*ssid
;
525 /* cmd: "<network id> <BSSID>" */
526 pos
= os_strchr(cmd
, ' ');
531 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
532 if (hwaddr_aton(pos
, bssid
)) {
533 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
537 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
539 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
544 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
545 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
551 static int wpa_supplicant_ctrl_iface_list_networks(
552 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
555 struct wpa_ssid
*ssid
;
560 ret
= os_snprintf(pos
, end
- pos
,
561 "network id / ssid / bssid / flags\n");
562 if (ret
< 0 || ret
>= end
- pos
)
566 ssid
= wpa_s
->conf
->ssid
;
568 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
570 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
571 if (ret
< 0 || ret
>= end
- pos
)
574 if (ssid
->bssid_set
) {
575 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
576 MAC2STR(ssid
->bssid
));
578 ret
= os_snprintf(pos
, end
- pos
, "\tany");
580 if (ret
< 0 || ret
>= end
- pos
)
583 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s",
584 ssid
== wpa_s
->current_ssid
?
586 ssid
->disabled
? "[DISABLED]" : "");
587 if (ret
< 0 || ret
>= end
- pos
)
590 ret
= os_snprintf(pos
, end
- pos
, "\n");
591 if (ret
< 0 || ret
>= end
- pos
)
602 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
605 ret
= os_snprintf(pos
, end
- pos
, "-");
606 if (ret
< 0 || ret
>= end
- pos
)
609 if (cipher
& WPA_CIPHER_NONE
) {
610 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : "+");
611 if (ret
< 0 || ret
>= end
- pos
)
616 if (cipher
& WPA_CIPHER_WEP40
) {
617 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : "+");
618 if (ret
< 0 || ret
>= end
- pos
)
623 if (cipher
& WPA_CIPHER_WEP104
) {
624 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
626 if (ret
< 0 || ret
>= end
- pos
)
631 if (cipher
& WPA_CIPHER_TKIP
) {
632 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : "+");
633 if (ret
< 0 || ret
>= end
- pos
)
638 if (cipher
& WPA_CIPHER_CCMP
) {
639 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : "+");
640 if (ret
< 0 || ret
>= end
- pos
)
649 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
650 const u8
*ie
, size_t ie_len
)
652 struct wpa_ie_data data
;
655 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
656 if (ret
< 0 || ret
>= end
- pos
)
660 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
661 ret
= os_snprintf(pos
, end
- pos
, "?]");
662 if (ret
< 0 || ret
>= end
- pos
)
669 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
670 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
671 if (ret
< 0 || ret
>= end
- pos
)
676 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
677 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
678 if (ret
< 0 || ret
>= end
- pos
)
683 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
684 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
685 if (ret
< 0 || ret
>= end
- pos
)
690 #ifdef CONFIG_IEEE80211R
691 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
692 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
694 if (ret
< 0 || ret
>= end
- pos
)
699 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
700 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
702 if (ret
< 0 || ret
>= end
- pos
)
707 #endif /* CONFIG_IEEE80211R */
708 #ifdef CONFIG_IEEE80211W
709 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
710 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
712 if (ret
< 0 || ret
>= end
- pos
)
717 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
718 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
720 if (ret
< 0 || ret
>= end
- pos
)
725 #endif /* CONFIG_IEEE80211W */
727 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
729 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
730 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
731 if (ret
< 0 || ret
>= end
- pos
)
736 ret
= os_snprintf(pos
, end
- pos
, "]");
737 if (ret
< 0 || ret
>= end
- pos
)
744 static char * wpa_supplicant_wps_ie_txt(char *pos
, char *end
,
745 const struct wpa_scan_res
*res
)
748 struct wpabuf
*wps_ie
;
752 wps_ie
= wpa_scan_get_vendor_ie_multi(res
, WPS_IE_VENDOR_TYPE
);
756 if (wps_is_selected_pbc_registrar(wps_ie
))
758 else if (wps_is_selected_pin_registrar(wps_ie
))
763 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
764 if (ret
>= 0 && ret
< end
- pos
)
767 #endif /* CONFIG_WPS */
773 /* Format one result on one text line into a buffer. */
774 static int wpa_supplicant_ctrl_iface_scan_result(
775 const struct wpa_scan_res
*res
, char *buf
, size_t buflen
)
784 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
785 MAC2STR(res
->bssid
), res
->freq
, res
->level
);
786 if (ret
< 0 || ret
>= end
- pos
)
789 ie
= wpa_scan_get_vendor_ie(res
, WPA_IE_VENDOR_TYPE
);
791 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
792 ie2
= wpa_scan_get_ie(res
, WLAN_EID_RSN
);
794 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
795 pos
= wpa_supplicant_wps_ie_txt(pos
, end
, res
);
796 if (!ie
&& !ie2
&& res
->caps
& IEEE80211_CAP_PRIVACY
) {
797 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
798 if (ret
< 0 || ret
>= end
- pos
)
802 if (res
->caps
& IEEE80211_CAP_IBSS
) {
803 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
804 if (ret
< 0 || ret
>= end
- pos
)
809 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
810 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
811 ie
? wpa_ssid_txt(ie
+ 2, ie
[1]) : "");
812 if (ret
< 0 || ret
>= end
- pos
)
816 ret
= os_snprintf(pos
, end
- pos
, "\n");
817 if (ret
< 0 || ret
>= end
- pos
)
825 static int wpa_supplicant_ctrl_iface_scan_results(
826 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
829 struct wpa_scan_res
*res
;
833 if (wpa_s
->scan_res
== NULL
&&
834 wpa_supplicant_get_scan_results(wpa_s
) < 0)
839 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
841 if (ret
< 0 || ret
>= end
- pos
)
845 for (i
= 0; i
< wpa_s
->scan_res
->num
; i
++) {
846 res
= wpa_s
->scan_res
->res
[i
];
847 ret
= wpa_supplicant_ctrl_iface_scan_result(res
, pos
,
849 if (ret
< 0 || ret
>= end
- pos
)
858 static int wpa_supplicant_ctrl_iface_select_network(
859 struct wpa_supplicant
*wpa_s
, char *cmd
)
862 struct wpa_ssid
*ssid
;
864 /* cmd: "<network id>" or "any" */
865 if (os_strcmp(cmd
, "any") == 0) {
866 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
870 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
872 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
874 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
875 "network id=%d", id
);
880 wpa_supplicant_select_network(wpa_s
, ssid
);
886 static int wpa_supplicant_ctrl_iface_enable_network(
887 struct wpa_supplicant
*wpa_s
, char *cmd
)
890 struct wpa_ssid
*ssid
;
892 /* cmd: "<network id>" or "all" */
893 if (os_strcmp(cmd
, "all") == 0) {
894 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
898 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
900 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
902 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
903 "network id=%d", id
);
907 wpa_supplicant_enable_network(wpa_s
, ssid
);
913 static int wpa_supplicant_ctrl_iface_disable_network(
914 struct wpa_supplicant
*wpa_s
, char *cmd
)
917 struct wpa_ssid
*ssid
;
919 /* cmd: "<network id>" or "all" */
920 if (os_strcmp(cmd
, "all") == 0) {
921 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
925 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
927 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
929 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
930 "network id=%d", id
);
934 wpa_supplicant_disable_network(wpa_s
, ssid
);
940 static int wpa_supplicant_ctrl_iface_add_network(
941 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
943 struct wpa_ssid
*ssid
;
946 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
948 ssid
= wpa_config_add_network(wpa_s
->conf
);
952 wpas_notify_network_added(wpa_s
, ssid
);
955 wpa_config_set_network_defaults(ssid
);
957 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
958 if (ret
< 0 || (size_t) ret
>= buflen
)
964 static int wpa_supplicant_ctrl_iface_remove_network(
965 struct wpa_supplicant
*wpa_s
, char *cmd
)
968 struct wpa_ssid
*ssid
;
970 /* cmd: "<network id>" or "all" */
971 if (os_strcmp(cmd
, "all") == 0) {
972 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
973 ssid
= wpa_s
->conf
->ssid
;
975 struct wpa_ssid
*remove_ssid
= ssid
;
978 wpas_notify_network_removed(wpa_s
, remove_ssid
);
979 wpa_config_remove_network(wpa_s
->conf
, id
);
981 if (wpa_s
->current_ssid
) {
982 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
983 wpa_supplicant_disassociate(wpa_s
,
984 WLAN_REASON_DEAUTH_LEAVING
);
990 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
992 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
994 wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
995 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1000 if (ssid
== wpa_s
->current_ssid
) {
1002 * Invalidate the EAP session cache if the current network is
1005 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1007 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1014 static int wpa_supplicant_ctrl_iface_set_network(
1015 struct wpa_supplicant
*wpa_s
, char *cmd
)
1018 struct wpa_ssid
*ssid
;
1021 /* cmd: "<network id> <variable name> <value>" */
1022 name
= os_strchr(cmd
, ' ');
1027 value
= os_strchr(name
, ' ');
1033 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1035 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1036 (u8
*) value
, os_strlen(value
));
1038 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1040 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1045 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
1046 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
1047 "variable '%s'", name
);
1051 if (wpa_s
->current_ssid
== ssid
) {
1053 * Invalidate the EAP session cache if anything in the current
1054 * configuration changes.
1056 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1059 if ((os_strcmp(name
, "psk") == 0 &&
1060 value
[0] == '"' && ssid
->ssid_len
) ||
1061 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
1062 wpa_config_update_psk(ssid
);
1068 static int wpa_supplicant_ctrl_iface_get_network(
1069 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1073 struct wpa_ssid
*ssid
;
1076 /* cmd: "<network id> <variable name>" */
1077 name
= os_strchr(cmd
, ' ');
1078 if (name
== NULL
|| buflen
== 0)
1083 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1086 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1088 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1093 value
= wpa_config_get_no_key(ssid
, name
);
1094 if (value
== NULL
) {
1095 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
1096 "variable '%s'", name
);
1100 res
= os_strlcpy(buf
, value
, buflen
);
1101 if (res
>= buflen
) {
1112 #ifndef CONFIG_NO_CONFIG_WRITE
1113 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
1117 if (!wpa_s
->conf
->update_config
) {
1118 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
1119 "to update configuration (update_config=0)");
1123 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
1125 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
1126 "update configuration");
1128 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
1134 #endif /* CONFIG_NO_CONFIG_WRITE */
1137 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
1138 struct wpa_driver_capa
*capa
,
1139 char *buf
, size_t buflen
)
1151 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
1157 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
1158 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
1159 if (ret
< 0 || ret
>= end
- pos
)
1165 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
1166 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
1167 if (ret
< 0 || ret
>= end
- pos
)
1173 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
1174 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : " ");
1175 if (ret
< 0 || ret
>= end
- pos
)
1185 static int ctrl_iface_get_capability_group(int res
, char *strict
,
1186 struct wpa_driver_capa
*capa
,
1187 char *buf
, size_t buflen
)
1199 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
1205 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
1206 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
1207 if (ret
< 0 || ret
>= end
- pos
)
1213 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
1214 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
1215 if (ret
< 0 || ret
>= end
- pos
)
1221 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP104
) {
1222 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
1224 if (ret
< 0 || ret
>= end
- pos
)
1230 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP40
) {
1231 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : " ");
1232 if (ret
< 0 || ret
>= end
- pos
)
1242 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
1243 struct wpa_driver_capa
*capa
,
1244 char *buf
, size_t buflen
)
1256 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
1263 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
1264 if (ret
< 0 || ret
>= end
- pos
)
1268 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1269 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
1270 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
1271 if (ret
< 0 || ret
>= end
- pos
)
1276 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
1277 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
1278 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
1279 if (ret
< 0 || ret
>= end
- pos
)
1284 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
1285 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
1286 if (ret
< 0 || ret
>= end
- pos
)
1295 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
1296 struct wpa_driver_capa
*capa
,
1297 char *buf
, size_t buflen
)
1309 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
1315 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
1316 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
1317 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
1318 if (ret
< 0 || ret
>= end
- pos
)
1324 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1325 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
1326 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
1327 if (ret
< 0 || ret
>= end
- pos
)
1337 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
1338 struct wpa_driver_capa
*capa
,
1339 char *buf
, size_t buflen
)
1351 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
1357 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
1358 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
1359 if (ret
< 0 || ret
>= end
- pos
)
1365 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
1366 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1368 if (ret
< 0 || ret
>= end
- pos
)
1374 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
1375 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
1376 if (ret
< 0 || ret
>= end
- pos
)
1386 static int wpa_supplicant_ctrl_iface_get_capability(
1387 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
1390 struct wpa_driver_capa capa
;
1396 /* Determine whether or not strict checking was requested */
1397 len
= os_strlcpy(field
, _field
, sizeof(field
));
1398 if (len
>= sizeof(field
))
1400 strict
= os_strchr(field
, ' ');
1401 if (strict
!= NULL
) {
1403 if (os_strcmp(strict
, "strict") != 0)
1407 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
1408 field
, strict
? strict
: "");
1410 if (os_strcmp(field
, "eap") == 0) {
1411 return eap_get_names(buf
, buflen
);
1414 res
= wpa_drv_get_capa(wpa_s
, &capa
);
1416 if (os_strcmp(field
, "pairwise") == 0)
1417 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
1420 if (os_strcmp(field
, "group") == 0)
1421 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
1424 if (os_strcmp(field
, "key_mgmt") == 0)
1425 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
1428 if (os_strcmp(field
, "proto") == 0)
1429 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
1432 if (os_strcmp(field
, "auth_alg") == 0)
1433 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
1436 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
1443 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
1444 const char *cmd
, char *buf
,
1449 struct wpa_scan_results
*results
;
1450 struct wpa_scan_res
*bss
;
1455 if (wpa_s
->scan_res
== NULL
&&
1456 wpa_supplicant_get_scan_results(wpa_s
) < 0)
1459 results
= wpa_s
->scan_res
;
1460 if (results
== NULL
)
1463 if (hwaddr_aton(cmd
, bssid
) == 0) {
1464 for (i
= 0; i
< results
->num
; i
++) {
1465 if (os_memcmp(bssid
, results
->res
[i
]->bssid
, ETH_ALEN
)
1472 if (i
>= results
->num
|| results
->res
[i
] == NULL
)
1473 return 0; /* no match found */
1475 bss
= results
->res
[i
];
1478 ret
= os_snprintf(pos
, end
- pos
,
1479 "bssid=" MACSTR
"\n"
1482 "capabilities=0x%04x\n"
1488 MAC2STR(bss
->bssid
), bss
->freq
, bss
->beacon_int
,
1489 bss
->caps
, bss
->qual
, bss
->noise
, bss
->level
,
1490 (unsigned long long) bss
->tsf
);
1491 if (ret
< 0 || ret
>= end
- pos
)
1495 ie
= (const u8
*) (bss
+ 1);
1496 for (i
= 0; i
< bss
->ie_len
; i
++) {
1497 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
1498 if (ret
< 0 || ret
>= end
- pos
)
1503 ret
= os_snprintf(pos
, end
- pos
, "\n");
1504 if (ret
< 0 || ret
>= end
- pos
)
1508 ret
= os_snprintf(pos
, end
- pos
, "flags=");
1509 if (ret
< 0 || ret
>= end
- pos
)
1513 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1515 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
1516 ie2
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
1518 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
1519 pos
= wpa_supplicant_wps_ie_txt(pos
, end
, bss
);
1520 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
1521 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
1522 if (ret
< 0 || ret
>= end
- pos
)
1526 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
1527 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
1528 if (ret
< 0 || ret
>= end
- pos
)
1533 ret
= os_snprintf(pos
, end
- pos
, "\n");
1534 if (ret
< 0 || ret
>= end
- pos
)
1538 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
1539 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
1540 ie
? wpa_ssid_txt(ie
+ 2, ie
[1]) : "");
1541 if (ret
< 0 || ret
>= end
- pos
)
1546 ie
= (const u8
*) (bss
+ 1);
1547 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
1548 if (ret
< 0 || ret
>= end
- pos
)
1551 #endif /* CONFIG_WPS */
1557 static int wpa_supplicant_ctrl_iface_ap_scan(
1558 struct wpa_supplicant
*wpa_s
, char *cmd
)
1560 int ap_scan
= atoi(cmd
);
1561 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
1565 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
1566 char *buf
, size_t *resp_len
)
1569 const int reply_size
= 2048;
1573 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
1574 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
1575 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
1576 (const u8
*) buf
, os_strlen(buf
));
1578 wpa_hexdump_ascii(MSG_DEBUG
, "RX ctrl_iface",
1579 (const u8
*) buf
, os_strlen(buf
));
1582 reply
= os_malloc(reply_size
);
1583 if (reply
== NULL
) {
1588 os_memcpy(reply
, "OK\n", 3);
1591 if (os_strcmp(buf
, "PING") == 0) {
1592 os_memcpy(reply
, "PONG\n", 5);
1594 } else if (os_strcmp(buf
, "MIB") == 0) {
1595 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
1596 if (reply_len
>= 0) {
1598 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
1599 reply_size
- reply_len
);
1605 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
1606 reply_len
= wpa_supplicant_ctrl_iface_status(
1607 wpa_s
, buf
+ 6, reply
, reply_size
);
1608 } else if (os_strcmp(buf
, "PMKSA") == 0) {
1609 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
1611 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
1612 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
1614 } else if (os_strcmp(buf
, "LOGON") == 0) {
1615 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
1616 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
1617 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
1618 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
1619 wpa_s
->disconnected
= 0;
1620 wpa_s
->reassociate
= 1;
1621 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1622 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
1623 if (wpa_s
->disconnected
) {
1624 wpa_s
->disconnected
= 0;
1625 wpa_s
->reassociate
= 1;
1626 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1628 #ifdef IEEE8021X_EAPOL
1629 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
1630 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
1632 #endif /* IEEE8021X_EAPOL */
1633 #ifdef CONFIG_PEERKEY
1634 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
1635 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
1637 #endif /* CONFIG_PEERKEY */
1638 #ifdef CONFIG_IEEE80211R
1639 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
1640 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
1642 #endif /* CONFIG_IEEE80211R */
1644 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
1645 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
))
1647 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
1648 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8))
1650 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
1651 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
1654 #ifdef CONFIG_WPS_OOB
1655 } else if (os_strncmp(buf
, "WPS_OOB ", 8) == 0) {
1656 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s
, buf
+ 8))
1658 #endif /* CONFIG_WPS_OOB */
1659 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
1660 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
1662 #ifdef CONFIG_WPS_ER
1663 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
1664 if (wpas_wps_er_start(wpa_s
))
1666 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
1667 if (wpas_wps_er_stop(wpa_s
))
1669 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
1670 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
1672 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
1673 if (wpas_wps_er_pbc(wpa_s
, buf
+ 11))
1675 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
1676 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
1678 #endif /* CONFIG_WPS_ER */
1679 #endif /* CONFIG_WPS */
1680 #ifdef CONFIG_IBSS_RSN
1681 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
1682 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
1684 #endif /* CONFIG_IBSS_RSN */
1685 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
1687 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1688 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
1692 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
1693 if (wpa_supplicant_reload_configuration(wpa_s
))
1695 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
1697 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
1698 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
1700 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
1701 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
1702 wpa_s
, reply
, reply_size
);
1703 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
1704 wpa_s
->reassociate
= 0;
1705 wpa_s
->disconnected
= 1;
1706 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1707 } else if (os_strcmp(buf
, "SCAN") == 0) {
1708 wpa_s
->scan_req
= 2;
1709 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1710 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
1711 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
1712 wpa_s
, reply
, reply_size
);
1713 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
1714 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
1716 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
1717 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
1719 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
1720 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
1722 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
1723 reply_len
= wpa_supplicant_ctrl_iface_add_network(
1724 wpa_s
, reply
, reply_size
);
1725 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
1726 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
1728 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
1729 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
1731 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
1732 reply_len
= wpa_supplicant_ctrl_iface_get_network(
1733 wpa_s
, buf
+ 12, reply
, reply_size
);
1734 #ifndef CONFIG_NO_CONFIG_WRITE
1735 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
1736 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
1738 #endif /* CONFIG_NO_CONFIG_WRITE */
1739 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
1740 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
1741 wpa_s
, buf
+ 15, reply
, reply_size
);
1742 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
1743 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
1745 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
1746 reply_len
= wpa_supplicant_global_iface_list(
1747 wpa_s
->global
, reply
, reply_size
);
1748 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
1749 reply_len
= wpa_supplicant_global_iface_interfaces(
1750 wpa_s
->global
, reply
, reply_size
);
1751 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
1752 reply_len
= wpa_supplicant_ctrl_iface_bss(
1753 wpa_s
, buf
+ 4, reply
, reply_size
);
1755 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
1756 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
1757 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
1758 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
1760 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
1761 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
1763 #endif /* CONFIG_AP */
1765 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
1769 if (reply_len
< 0) {
1770 os_memcpy(reply
, "FAIL\n", 5);
1775 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
1777 *resp_len
= reply_len
;
1782 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
1785 struct wpa_interface iface
;
1789 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1790 * TAB<bridge_ifname>
1792 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
1794 os_memset(&iface
, 0, sizeof(iface
));
1797 iface
.ifname
= pos
= cmd
;
1798 pos
= os_strchr(pos
, '\t');
1801 if (iface
.ifname
[0] == '\0')
1806 iface
.confname
= pos
;
1807 pos
= os_strchr(pos
, '\t');
1810 if (iface
.confname
[0] == '\0')
1811 iface
.confname
= NULL
;
1816 pos
= os_strchr(pos
, '\t');
1819 if (iface
.driver
[0] == '\0')
1820 iface
.driver
= NULL
;
1824 iface
.ctrl_interface
= pos
;
1825 pos
= os_strchr(pos
, '\t');
1828 if (iface
.ctrl_interface
[0] == '\0')
1829 iface
.ctrl_interface
= NULL
;
1833 iface
.driver_param
= pos
;
1834 pos
= os_strchr(pos
, '\t');
1837 if (iface
.driver_param
[0] == '\0')
1838 iface
.driver_param
= NULL
;
1842 iface
.bridge_ifname
= pos
;
1843 pos
= os_strchr(pos
, '\t');
1846 if (iface
.bridge_ifname
[0] == '\0')
1847 iface
.bridge_ifname
= NULL
;
1852 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
1855 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
1859 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
1862 struct wpa_supplicant
*wpa_s
;
1864 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
1866 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
1869 return wpa_supplicant_remove_iface(global
, wpa_s
);
1873 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
1875 struct wpa_interface_info
*prev
;
1879 iface
= iface
->next
;
1881 os_free(prev
->ifname
);
1882 os_free(prev
->desc
);
1888 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
1892 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
1895 for (i
= 0; wpa_drivers
[i
]; i
++) {
1896 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
1897 if (drv
->get_interfaces
== NULL
)
1899 tmp
= drv
->get_interfaces(global
->drv_priv
);
1913 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
1914 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
1915 tmp
->drv_name
, tmp
->ifname
,
1916 tmp
->desc
? tmp
->desc
: "");
1917 if (res
< 0 || res
>= end
- pos
) {
1924 wpa_free_iface_info(iface
);
1930 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
1935 struct wpa_supplicant
*wpa_s
;
1937 wpa_s
= global
->ifaces
;
1942 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
1943 if (res
< 0 || res
>= end
- pos
) {
1948 wpa_s
= wpa_s
->next
;
1954 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
1955 char *buf
, size_t *resp_len
)
1958 const int reply_size
= 2048;
1961 wpa_hexdump_ascii(MSG_DEBUG
, "RX global ctrl_iface",
1962 (const u8
*) buf
, os_strlen(buf
));
1964 reply
= os_malloc(reply_size
);
1965 if (reply
== NULL
) {
1970 os_memcpy(reply
, "OK\n", 3);
1973 if (os_strcmp(buf
, "PING") == 0) {
1974 os_memcpy(reply
, "PONG\n", 5);
1976 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
1977 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
1979 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
1980 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
1982 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
1983 reply_len
= wpa_supplicant_global_iface_list(
1984 global
, reply
, reply_size
);
1985 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
1986 reply_len
= wpa_supplicant_global_iface_interfaces(
1987 global
, reply
, reply_size
);
1988 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
1991 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
1995 if (reply_len
< 0) {
1996 os_memcpy(reply
, "FAIL\n", 5);
2000 *resp_len
= reply_len
;