2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2007, 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"
23 #include "ctrl_iface.h"
24 #include "l2_packet/l2_packet.h"
26 #include "pmksa_cache.h"
28 #include "eap_peer/eap.h"
29 #include "ieee802_11_defs.h"
32 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
36 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
42 value
= os_strchr(cmd
, ' ');
47 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
48 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
49 eapol_sm_configure(wpa_s
->eapol
,
50 atoi(value
), -1, -1, -1);
51 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
52 eapol_sm_configure(wpa_s
->eapol
,
53 -1, atoi(value
), -1, -1);
54 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
55 eapol_sm_configure(wpa_s
->eapol
,
56 -1, -1, atoi(value
), -1);
57 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
58 eapol_sm_configure(wpa_s
->eapol
,
59 -1, -1, -1, atoi(value
));
60 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
61 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
64 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
66 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
69 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
70 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
79 #ifdef IEEE8021X_EAPOL
80 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
84 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
86 if (hwaddr_aton(addr
, bssid
)) {
87 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
92 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
93 rsn_preauth_deinit(wpa_s
->wpa
);
94 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
99 #endif /* IEEE8021X_EAPOL */
102 #ifdef CONFIG_PEERKEY
103 /* MLME-STKSTART.request(peer) */
104 static int wpa_supplicant_ctrl_iface_stkstart(
105 struct wpa_supplicant
*wpa_s
, char *addr
)
109 if (hwaddr_aton(addr
, peer
)) {
110 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
111 "address '%s'", peer
);
115 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
118 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
120 #endif /* CONFIG_PEERKEY */
123 #ifdef CONFIG_IEEE80211R
124 static int wpa_supplicant_ctrl_iface_ft_ds(
125 struct wpa_supplicant
*wpa_s
, char *addr
)
127 u8 target_ap
[ETH_ALEN
];
129 if (hwaddr_aton(addr
, target_ap
)) {
130 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
131 "address '%s'", target_ap
);
135 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
137 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
);
139 #endif /* CONFIG_IEEE80211R */
142 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
145 #ifdef IEEE8021X_EAPOL
148 struct wpa_ssid
*ssid
;
149 struct eap_peer_config
*eap
;
151 pos
= os_strchr(rsp
, '-');
156 pos
= os_strchr(pos
, ':');
161 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
162 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
163 (u8
*) pos
, os_strlen(pos
));
165 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
167 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
173 if (os_strcmp(rsp
, "IDENTITY") == 0) {
174 os_free(eap
->identity
);
175 eap
->identity
= (u8
*) os_strdup(pos
);
176 eap
->identity_len
= os_strlen(pos
);
177 eap
->pending_req_identity
= 0;
178 if (ssid
== wpa_s
->current_ssid
)
179 wpa_s
->reassociate
= 1;
180 } else if (os_strcmp(rsp
, "PASSWORD") == 0) {
181 os_free(eap
->password
);
182 eap
->password
= (u8
*) os_strdup(pos
);
183 eap
->password_len
= os_strlen(pos
);
184 eap
->pending_req_password
= 0;
185 if (ssid
== wpa_s
->current_ssid
)
186 wpa_s
->reassociate
= 1;
187 } else if (os_strcmp(rsp
, "NEW_PASSWORD") == 0) {
188 os_free(eap
->new_password
);
189 eap
->new_password
= (u8
*) os_strdup(pos
);
190 eap
->new_password_len
= os_strlen(pos
);
191 eap
->pending_req_new_password
= 0;
192 if (ssid
== wpa_s
->current_ssid
)
193 wpa_s
->reassociate
= 1;
194 } else if (os_strcmp(rsp
, "PIN") == 0) {
196 eap
->pin
= os_strdup(pos
);
197 eap
->pending_req_pin
= 0;
198 if (ssid
== wpa_s
->current_ssid
)
199 wpa_s
->reassociate
= 1;
200 } else if (os_strcmp(rsp
, "OTP") == 0) {
202 eap
->otp
= (u8
*) os_strdup(pos
);
203 eap
->otp_len
= os_strlen(pos
);
204 os_free(eap
->pending_req_otp
);
205 eap
->pending_req_otp
= NULL
;
206 eap
->pending_req_otp_len
= 0;
207 } else if (os_strcmp(rsp
, "PASSPHRASE") == 0) {
208 os_free(eap
->private_key_passwd
);
209 eap
->private_key_passwd
= (u8
*) os_strdup(pos
);
210 eap
->pending_req_passphrase
= 0;
211 if (ssid
== wpa_s
->current_ssid
)
212 wpa_s
->reassociate
= 1;
214 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown field '%s'", rsp
);
219 #else /* IEEE8021X_EAPOL */
220 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
222 #endif /* IEEE8021X_EAPOL */
226 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
228 char *buf
, size_t buflen
)
230 char *pos
, *end
, tmp
[30];
231 int res
, verbose
, ret
;
233 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
236 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
237 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
238 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
239 MAC2STR(wpa_s
->bssid
));
240 if (ret
< 0 || ret
>= end
- pos
)
244 u8
*_ssid
= ssid
->ssid
;
245 size_t ssid_len
= ssid
->ssid_len
;
246 u8 ssid_buf
[MAX_SSID_LEN
];
248 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
255 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
256 wpa_ssid_txt(_ssid
, ssid_len
),
258 if (ret
< 0 || ret
>= end
- pos
)
263 ret
= os_snprintf(pos
, end
- pos
,
266 if (ret
< 0 || ret
>= end
- pos
)
272 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
274 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
275 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
276 if (ret
< 0 || ret
>= end
- pos
)
281 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
282 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
283 if (ret
< 0 || ret
>= end
- pos
)
288 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X
||
289 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
||
290 wpa_s
->key_mgmt
== WPA_KEY_MGMT_FT_IEEE8021X
) {
291 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
297 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
305 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
310 struct wpa_ssid
*ssid
;
313 /* cmd: "<network id> <BSSID>" */
314 pos
= os_strchr(cmd
, ' ');
319 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
320 if (hwaddr_aton(pos
, bssid
)) {
321 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
325 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
327 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
332 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
333 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
339 static int wpa_supplicant_ctrl_iface_list_networks(
340 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
343 struct wpa_ssid
*ssid
;
348 ret
= os_snprintf(pos
, end
- pos
,
349 "network id / ssid / bssid / flags\n");
350 if (ret
< 0 || ret
>= end
- pos
)
354 ssid
= wpa_s
->conf
->ssid
;
356 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
358 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
359 if (ret
< 0 || ret
>= end
- pos
)
362 if (ssid
->bssid_set
) {
363 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
364 MAC2STR(ssid
->bssid
));
366 ret
= os_snprintf(pos
, end
- pos
, "\tany");
368 if (ret
< 0 || ret
>= end
- pos
)
371 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s",
372 ssid
== wpa_s
->current_ssid
?
374 ssid
->disabled
? "[DISABLED]" : "");
375 if (ret
< 0 || ret
>= end
- pos
)
378 ret
= os_snprintf(pos
, end
- pos
, "\n");
379 if (ret
< 0 || ret
>= end
- pos
)
390 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
393 ret
= os_snprintf(pos
, end
- pos
, "-");
394 if (ret
< 0 || ret
>= end
- pos
)
397 if (cipher
& WPA_CIPHER_NONE
) {
398 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : "+");
399 if (ret
< 0 || ret
>= end
- pos
)
404 if (cipher
& WPA_CIPHER_WEP40
) {
405 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : "+");
406 if (ret
< 0 || ret
>= end
- pos
)
411 if (cipher
& WPA_CIPHER_WEP104
) {
412 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
414 if (ret
< 0 || ret
>= end
- pos
)
419 if (cipher
& WPA_CIPHER_TKIP
) {
420 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : "+");
421 if (ret
< 0 || ret
>= end
- pos
)
426 if (cipher
& WPA_CIPHER_CCMP
) {
427 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : "+");
428 if (ret
< 0 || ret
>= end
- pos
)
437 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
438 const u8
*ie
, size_t ie_len
)
440 struct wpa_ie_data data
;
443 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
444 if (ret
< 0 || ret
>= end
- pos
)
448 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
449 ret
= os_snprintf(pos
, end
- pos
, "?]");
450 if (ret
< 0 || ret
>= end
- pos
)
457 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
458 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
459 if (ret
< 0 || ret
>= end
- pos
)
464 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
465 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
466 if (ret
< 0 || ret
>= end
- pos
)
471 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
472 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
473 if (ret
< 0 || ret
>= end
- pos
)
478 #ifdef CONFIG_IEEE80211R
479 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
480 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
482 if (ret
< 0 || ret
>= end
- pos
)
487 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
488 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
490 if (ret
< 0 || ret
>= end
- pos
)
495 #endif /* CONFIG_IEEE80211R */
497 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
499 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
500 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
501 if (ret
< 0 || ret
>= end
- pos
)
506 ret
= os_snprintf(pos
, end
- pos
, "]");
507 if (ret
< 0 || ret
>= end
- pos
)
515 /* Format one result on one text line into a buffer. */
516 static int wpa_supplicant_ctrl_iface_scan_result(
517 const struct wpa_scan_res
*res
, char *buf
, size_t buflen
)
526 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
527 MAC2STR(res
->bssid
), res
->freq
, res
->level
);
528 if (ret
< 0 || ret
>= end
- pos
)
531 ie
= wpa_scan_get_vendor_ie(res
, WPA_IE_VENDOR_TYPE
);
533 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
534 ie2
= wpa_scan_get_ie(res
, WLAN_EID_RSN
);
536 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
537 if (!ie
&& !ie2
&& res
->caps
& IEEE80211_CAP_PRIVACY
) {
538 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
539 if (ret
< 0 || ret
>= end
- pos
)
543 if (res
->caps
& IEEE80211_CAP_IBSS
) {
544 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
545 if (ret
< 0 || ret
>= end
- pos
)
550 ie
= wpa_scan_get_ie(res
, WLAN_EID_SSID
);
551 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
552 ie
? wpa_ssid_txt(ie
+ 2, ie
[1]) : "");
553 if (ret
< 0 || ret
>= end
- pos
)
557 ret
= os_snprintf(pos
, end
- pos
, "\n");
558 if (ret
< 0 || ret
>= end
- pos
)
566 static int wpa_supplicant_ctrl_iface_scan_results(
567 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
570 struct wpa_scan_res
*res
;
574 if (wpa_s
->scan_res
== NULL
&&
575 wpa_supplicant_get_scan_results(wpa_s
) < 0)
580 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
582 if (ret
< 0 || ret
>= end
- pos
)
586 for (i
= 0; i
< wpa_s
->scan_res
->num
; i
++) {
587 res
= wpa_s
->scan_res
->res
[i
];
588 ret
= wpa_supplicant_ctrl_iface_scan_result(res
, pos
,
590 if (ret
< 0 || ret
>= end
- pos
)
599 static int wpa_supplicant_ctrl_iface_select_network(
600 struct wpa_supplicant
*wpa_s
, char *cmd
)
603 struct wpa_ssid
*ssid
;
605 /* cmd: "<network id>" or "any" */
606 if (os_strcmp(cmd
, "any") == 0) {
607 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
608 ssid
= wpa_s
->conf
->ssid
;
613 wpa_s
->reassociate
= 1;
614 wpa_supplicant_req_scan(wpa_s
, 0, 0);
619 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
621 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
623 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
628 if (ssid
!= wpa_s
->current_ssid
&& wpa_s
->current_ssid
)
629 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
631 /* Mark all other networks disabled and trigger reassociation */
632 ssid
= wpa_s
->conf
->ssid
;
634 ssid
->disabled
= id
!= ssid
->id
;
637 wpa_s
->reassociate
= 1;
638 wpa_supplicant_req_scan(wpa_s
, 0, 0);
644 static int wpa_supplicant_ctrl_iface_enable_network(
645 struct wpa_supplicant
*wpa_s
, char *cmd
)
648 struct wpa_ssid
*ssid
;
650 /* cmd: "<network id>" or "all" */
651 if (os_strcmp(cmd
, "all") == 0) {
652 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
653 ssid
= wpa_s
->conf
->ssid
;
655 if (ssid
== wpa_s
->current_ssid
&& ssid
->disabled
)
656 wpa_s
->reassociate
= 1;
660 if (wpa_s
->reassociate
)
661 wpa_supplicant_req_scan(wpa_s
, 0, 0);
666 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
668 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
670 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
675 if (wpa_s
->current_ssid
== NULL
&& ssid
->disabled
) {
677 * Try to reassociate since there is no current configuration
678 * and a new network was made available. */
679 wpa_s
->reassociate
= 1;
680 wpa_supplicant_req_scan(wpa_s
, 0, 0);
688 static int wpa_supplicant_ctrl_iface_disable_network(
689 struct wpa_supplicant
*wpa_s
, char *cmd
)
692 struct wpa_ssid
*ssid
;
694 /* cmd: "<network id>" or "all" */
695 if (os_strcmp(cmd
, "all") == 0) {
696 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
697 ssid
= wpa_s
->conf
->ssid
;
702 if (wpa_s
->current_ssid
)
703 wpa_supplicant_disassociate(wpa_s
,
704 WLAN_REASON_DEAUTH_LEAVING
);
709 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
711 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
713 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
718 if (ssid
== wpa_s
->current_ssid
)
719 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
726 static int wpa_supplicant_ctrl_iface_add_network(
727 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
729 struct wpa_ssid
*ssid
;
732 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
734 ssid
= wpa_config_add_network(wpa_s
->conf
);
738 wpa_config_set_network_defaults(ssid
);
740 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
741 if (ret
< 0 || (size_t) ret
>= buflen
)
747 static int wpa_supplicant_ctrl_iface_remove_network(
748 struct wpa_supplicant
*wpa_s
, char *cmd
)
751 struct wpa_ssid
*ssid
;
753 /* cmd: "<network id>" or "all" */
754 if (os_strcmp(cmd
, "all") == 0) {
755 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
756 ssid
= wpa_s
->conf
->ssid
;
760 wpa_config_remove_network(wpa_s
->conf
, id
);
762 if (wpa_s
->current_ssid
) {
763 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
764 wpa_supplicant_disassociate(wpa_s
,
765 WLAN_REASON_DEAUTH_LEAVING
);
771 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
773 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
775 wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
776 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
781 if (ssid
== wpa_s
->current_ssid
) {
783 * Invalidate the EAP session cache if the current network is
786 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
788 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
795 static int wpa_supplicant_ctrl_iface_set_network(
796 struct wpa_supplicant
*wpa_s
, char *cmd
)
799 struct wpa_ssid
*ssid
;
802 /* cmd: "<network id> <variable name> <value>" */
803 name
= os_strchr(cmd
, ' ');
808 value
= os_strchr(name
, ' ');
814 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
816 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
817 (u8
*) value
, os_strlen(value
));
819 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
821 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
826 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
827 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
828 "variable '%s'", name
);
832 if (wpa_s
->current_ssid
== ssid
) {
834 * Invalidate the EAP session cache if anything in the current
835 * configuration changes.
837 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
840 if ((os_strcmp(name
, "psk") == 0 &&
841 value
[0] == '"' && ssid
->ssid_len
) ||
842 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
843 wpa_config_update_psk(ssid
);
849 static int wpa_supplicant_ctrl_iface_get_network(
850 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
854 struct wpa_ssid
*ssid
;
857 /* cmd: "<network id> <variable name>" */
858 name
= os_strchr(cmd
, ' ');
859 if (name
== NULL
|| buflen
== 0)
864 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
867 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
869 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
874 value
= wpa_config_get_no_key(ssid
, name
);
876 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
877 "variable '%s'", name
);
881 res
= os_strlcpy(buf
, value
, buflen
);
893 #ifndef CONFIG_NO_CONFIG_WRITE
894 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
898 if (!wpa_s
->conf
->update_config
) {
899 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
900 "to update configuration (update_config=0)");
904 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
906 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
907 "update configuration");
909 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
915 #endif /* CONFIG_NO_CONFIG_WRITE */
918 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
919 struct wpa_driver_capa
*capa
,
920 char *buf
, size_t buflen
)
932 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
938 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
939 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
940 if (ret
< 0 || ret
>= end
- pos
)
946 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
947 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
948 if (ret
< 0 || ret
>= end
- pos
)
954 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
955 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : " ");
956 if (ret
< 0 || ret
>= end
- pos
)
966 static int ctrl_iface_get_capability_group(int res
, char *strict
,
967 struct wpa_driver_capa
*capa
,
968 char *buf
, size_t buflen
)
980 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
986 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
987 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
988 if (ret
< 0 || ret
>= end
- pos
)
994 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
995 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
996 if (ret
< 0 || ret
>= end
- pos
)
1002 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP104
) {
1003 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
1005 if (ret
< 0 || ret
>= end
- pos
)
1011 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP40
) {
1012 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : " ");
1013 if (ret
< 0 || ret
>= end
- pos
)
1023 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
1024 struct wpa_driver_capa
*capa
,
1025 char *buf
, size_t buflen
)
1037 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
1044 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
1045 if (ret
< 0 || ret
>= end
- pos
)
1049 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1050 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
1051 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
1052 if (ret
< 0 || ret
>= end
- pos
)
1057 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
1058 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
1059 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
1060 if (ret
< 0 || ret
>= end
- pos
)
1065 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
1066 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
1067 if (ret
< 0 || ret
>= end
- pos
)
1076 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
1077 struct wpa_driver_capa
*capa
,
1078 char *buf
, size_t buflen
)
1090 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
1096 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
1097 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
1098 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
1099 if (ret
< 0 || ret
>= end
- pos
)
1105 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
1106 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
1107 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
1108 if (ret
< 0 || ret
>= end
- pos
)
1118 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
1119 struct wpa_driver_capa
*capa
,
1120 char *buf
, size_t buflen
)
1132 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
1138 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
1139 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
1140 if (ret
< 0 || ret
>= end
- pos
)
1146 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
1147 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
1149 if (ret
< 0 || ret
>= end
- pos
)
1155 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
1156 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
1157 if (ret
< 0 || ret
>= end
- pos
)
1167 static int wpa_supplicant_ctrl_iface_get_capability(
1168 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
1171 struct wpa_driver_capa capa
;
1177 /* Determine whether or not strict checking was requested */
1178 len
= os_strlcpy(field
, _field
, sizeof(field
));
1179 if (len
>= sizeof(field
))
1181 strict
= os_strchr(field
, ' ');
1182 if (strict
!= NULL
) {
1184 if (os_strcmp(strict
, "strict") != 0)
1188 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
1189 field
, strict
? strict
: "");
1191 if (os_strcmp(field
, "eap") == 0) {
1192 return eap_get_names(buf
, buflen
);
1195 res
= wpa_drv_get_capa(wpa_s
, &capa
);
1197 if (os_strcmp(field
, "pairwise") == 0)
1198 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
1201 if (os_strcmp(field
, "group") == 0)
1202 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
1205 if (os_strcmp(field
, "key_mgmt") == 0)
1206 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
1209 if (os_strcmp(field
, "proto") == 0)
1210 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
1213 if (os_strcmp(field
, "auth_alg") == 0)
1214 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
1217 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
1224 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
1225 const char *cmd
, char *buf
,
1230 struct wpa_scan_results
*results
;
1231 struct wpa_scan_res
*bss
;
1236 results
= wpa_s
->scan_res
;
1237 if (results
== NULL
)
1240 if (hwaddr_aton(cmd
, bssid
) == 0) {
1241 for (i
= 0; i
< results
->num
; i
++) {
1242 if (os_memcmp(bssid
, results
->res
[i
]->bssid
, ETH_ALEN
)
1249 if (i
>= results
->num
|| results
->res
[i
] == NULL
)
1250 return 0; /* no match found */
1252 bss
= results
->res
[i
];
1255 ret
= snprintf(pos
, end
- pos
,
1256 "bssid=" MACSTR
"\n"
1259 "capabilities=0x%04x\n"
1265 MAC2STR(bss
->bssid
), bss
->freq
, bss
->beacon_int
,
1266 bss
->caps
, bss
->qual
, bss
->noise
, bss
->level
,
1267 (unsigned long long) bss
->tsf
);
1268 if (ret
< 0 || ret
>= end
- pos
)
1272 ie
= (const u8
*) (bss
+ 1);
1273 for (i
= 0; i
< bss
->ie_len
; i
++) {
1274 ret
= snprintf(pos
, end
- pos
, "%02x", *ie
++);
1275 if (ret
< 0 || ret
>= end
- pos
)
1280 ret
= snprintf(pos
, end
- pos
, "\n");
1281 if (ret
< 0 || ret
>= end
- pos
)
1285 ret
= os_snprintf(pos
, end
- pos
, "flags=");
1286 if (ret
< 0 || ret
>= end
- pos
)
1290 ie
= wpa_scan_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1292 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
1293 ie2
= wpa_scan_get_ie(bss
, WLAN_EID_RSN
);
1295 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
1296 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
1297 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
1298 if (ret
< 0 || ret
>= end
- pos
)
1302 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
1303 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
1304 if (ret
< 0 || ret
>= end
- pos
)
1309 ret
= snprintf(pos
, end
- pos
, "\n");
1310 if (ret
< 0 || ret
>= end
- pos
)
1314 ie
= wpa_scan_get_ie(bss
, WLAN_EID_SSID
);
1315 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
1316 ie
? wpa_ssid_txt(ie
+ 2, ie
[1]) : "");
1317 if (ret
< 0 || ret
>= end
- pos
)
1325 static int wpa_supplicant_ctrl_iface_ap_scan(
1326 struct wpa_supplicant
*wpa_s
, char *cmd
)
1328 int ap_scan
= atoi(cmd
);
1330 if (ap_scan
< 0 || ap_scan
> 2)
1332 wpa_s
->conf
->ap_scan
= ap_scan
;
1337 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
1338 char *buf
, size_t *resp_len
)
1341 const int reply_size
= 2048;
1345 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
1346 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
1347 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
1348 (const u8
*) buf
, os_strlen(buf
));
1350 wpa_hexdump_ascii(MSG_DEBUG
, "RX ctrl_iface",
1351 (const u8
*) buf
, os_strlen(buf
));
1354 reply
= os_malloc(reply_size
);
1355 if (reply
== NULL
) {
1360 os_memcpy(reply
, "OK\n", 3);
1363 if (os_strcmp(buf
, "PING") == 0) {
1364 os_memcpy(reply
, "PONG\n", 5);
1366 } else if (os_strcmp(buf
, "MIB") == 0) {
1367 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
1368 if (reply_len
>= 0) {
1370 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
1371 reply_size
- reply_len
);
1377 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
1378 reply_len
= wpa_supplicant_ctrl_iface_status(
1379 wpa_s
, buf
+ 6, reply
, reply_size
);
1380 } else if (os_strcmp(buf
, "PMKSA") == 0) {
1381 reply_len
= pmksa_cache_list(wpa_s
->wpa
, reply
, reply_size
);
1382 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
1383 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
1385 } else if (os_strcmp(buf
, "LOGON") == 0) {
1386 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
1387 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
1388 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
1389 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
1390 wpa_s
->disconnected
= 0;
1391 wpa_s
->reassociate
= 1;
1392 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1393 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
1394 if (wpa_s
->disconnected
) {
1395 wpa_s
->disconnected
= 0;
1396 wpa_s
->reassociate
= 1;
1397 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1399 #ifdef IEEE8021X_EAPOL
1400 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
1401 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
1403 #endif /* IEEE8021X_EAPOL */
1404 #ifdef CONFIG_PEERKEY
1405 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
1406 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
1408 #endif /* CONFIG_PEERKEY */
1409 #ifdef CONFIG_IEEE80211R
1410 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
1411 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
1413 #endif /* CONFIG_IEEE80211R */
1414 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
1416 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1417 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
1421 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
1422 if (wpa_supplicant_reload_configuration(wpa_s
))
1424 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
1426 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
1427 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
1429 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
1430 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
1431 wpa_s
, reply
, reply_size
);
1432 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
1433 wpa_s
->reassociate
= 0;
1434 wpa_s
->disconnected
= 1;
1435 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1436 } else if (os_strcmp(buf
, "SCAN") == 0) {
1437 wpa_s
->scan_req
= 2;
1438 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1439 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
1440 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
1441 wpa_s
, reply
, reply_size
);
1442 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
1443 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
1445 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
1446 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
1448 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
1449 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
1451 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
1452 reply_len
= wpa_supplicant_ctrl_iface_add_network(
1453 wpa_s
, reply
, reply_size
);
1454 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
1455 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
1457 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
1458 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
1460 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
1461 reply_len
= wpa_supplicant_ctrl_iface_get_network(
1462 wpa_s
, buf
+ 12, reply
, reply_size
);
1463 #ifndef CONFIG_NO_CONFIG_WRITE
1464 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
1465 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
1467 #endif /* CONFIG_NO_CONFIG_WRITE */
1468 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
1469 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
1470 wpa_s
, buf
+ 15, reply
, reply_size
);
1471 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
1472 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
1474 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
1475 reply_len
= wpa_supplicant_global_iface_interfaces(
1476 wpa_s
->global
, reply
, reply_size
);
1477 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
1478 reply_len
= wpa_supplicant_ctrl_iface_bss(
1479 wpa_s
, buf
+ 4, reply
, reply_size
);
1481 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
1485 if (reply_len
< 0) {
1486 os_memcpy(reply
, "FAIL\n", 5);
1491 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
1493 *resp_len
= reply_len
;
1498 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
1501 struct wpa_interface iface
;
1505 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1506 * TAB<bridge_ifname>
1508 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
1510 os_memset(&iface
, 0, sizeof(iface
));
1513 iface
.ifname
= pos
= cmd
;
1514 pos
= os_strchr(pos
, '\t');
1517 if (iface
.ifname
[0] == '\0')
1522 iface
.confname
= pos
;
1523 pos
= os_strchr(pos
, '\t');
1526 if (iface
.confname
[0] == '\0')
1527 iface
.confname
= NULL
;
1532 pos
= os_strchr(pos
, '\t');
1535 if (iface
.driver
[0] == '\0')
1536 iface
.driver
= NULL
;
1540 iface
.ctrl_interface
= pos
;
1541 pos
= os_strchr(pos
, '\t');
1544 if (iface
.ctrl_interface
[0] == '\0')
1545 iface
.ctrl_interface
= NULL
;
1549 iface
.driver_param
= pos
;
1550 pos
= os_strchr(pos
, '\t');
1553 if (iface
.driver_param
[0] == '\0')
1554 iface
.driver_param
= NULL
;
1558 iface
.bridge_ifname
= pos
;
1559 pos
= os_strchr(pos
, '\t');
1562 if (iface
.bridge_ifname
[0] == '\0')
1563 iface
.bridge_ifname
= NULL
;
1568 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
1571 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
1575 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
1578 struct wpa_supplicant
*wpa_s
;
1580 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
1582 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
1585 return wpa_supplicant_remove_iface(global
, wpa_s
);
1589 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
1594 struct wpa_supplicant
*wpa_s
;
1596 wpa_s
= global
->ifaces
;
1601 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
1602 if (res
< 0 || res
>= end
- pos
) {
1607 wpa_s
= wpa_s
->next
;
1613 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
1614 char *buf
, size_t *resp_len
)
1617 const int reply_size
= 2048;
1620 wpa_hexdump_ascii(MSG_DEBUG
, "RX global ctrl_iface",
1621 (const u8
*) buf
, os_strlen(buf
));
1623 reply
= os_malloc(reply_size
);
1624 if (reply
== NULL
) {
1629 os_memcpy(reply
, "OK\n", 3);
1632 if (os_strcmp(buf
, "PING") == 0) {
1633 os_memcpy(reply
, "PONG\n", 5);
1635 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
1636 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
1638 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
1639 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
1641 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
1642 reply_len
= wpa_supplicant_global_iface_interfaces(
1643 global
, reply
, reply_size
);
1644 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
1647 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
1651 if (reply_len
< 0) {
1652 os_memcpy(reply
, "FAIL\n", 5);
1656 *resp_len
= reply_len
;