2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2008, 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"
30 #include "wps_supplicant.h"
33 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
35 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
39 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
45 value = os_strchr(cmd, ' ');
50 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
51 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
52 eapol_sm_configure(wpa_s->eapol,
53 atoi(value), -1, -1, -1);
54 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
55 eapol_sm_configure(wpa_s->eapol,
56 -1, atoi(value), -1, -1);
57 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
58 eapol_sm_configure(wpa_s->eapol,
59 -1, -1, atoi(value), -1);
60 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
61 eapol_sm_configure(wpa_s->eapol,
62 -1, -1, -1, atoi(value));
63 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
64 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
67 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
69 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
72 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
73 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
82 #ifdef IEEE8021X_EAPOL
83 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
87 struct wpa_ssid *ssid = wpa_s->current_ssid;
89 if (hwaddr_aton(addr, bssid)) {
90 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
95 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
96 rsn_preauth_deinit(wpa_s->wpa);
97 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
102 #endif /* IEEE8021X_EAPOL */
105 #ifdef CONFIG_PEERKEY
106 /* MLME-STKSTART.request(peer) */
107 static int wpa_supplicant_ctrl_iface_stkstart(
108 struct wpa_supplicant *wpa_s, char *addr)
112 if (hwaddr_aton(addr, peer)) {
113 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
114 "address '%s'", peer);
118 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
121 return wpa_sm_stkstart(wpa_s->wpa, peer);
123 #endif /* CONFIG_PEERKEY */
126 #ifdef CONFIG_IEEE80211R
127 static int wpa_supplicant_ctrl_iface_ft_ds(
128 struct wpa_supplicant *wpa_s, char *addr)
130 u8 target_ap[ETH_ALEN];
132 if (hwaddr_aton(addr, target_ap)) {
133 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
134 "address '%s'", target_ap);
138 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
140 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap);
142 #endif /* CONFIG_IEEE80211R */
146 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
151 if (cmd == NULL || os_strcmp(cmd, "any") == 0)
152 return wpas_wps_start_pbc(wpa_s, NULL);
154 if (hwaddr_aton(cmd, bssid)) {
155 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
160 return wpas_wps_start_pbc(wpa_s, bssid);
164 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
165 char *cmd, char *buf,
168 u8 bssid[ETH_ALEN], *_bssid = bssid;
172 pin = os_strchr(cmd, ' ');
176 if (os_strcmp(cmd, "any") == 0)
178 else if (hwaddr_aton(cmd, bssid)) {
179 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
185 ret = wpas_wps_start_pin(wpa_s, _bssid, pin);
188 ret = os_snprintf(buf, buflen, "%s", pin);
189 if (ret < 0 || (size_t) ret >= buflen)
194 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
198 /* Return the generated PIN */
199 ret = os_snprintf(buf, buflen, "%08d", ret);
200 if (ret < 0 || (size_t) ret >= buflen)
206 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
209 u8 bssid[ETH_ALEN], *_bssid = bssid;
212 pin = os_strchr(cmd, ' ');
217 if (os_strcmp(cmd, "any") == 0)
219 else if (hwaddr_aton(cmd, bssid)) {
220 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
225 return wpas_wps_start_reg(wpa_s, _bssid, pin);
227 #endif /* CONFIG_WPS */
230 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
233 #ifdef IEEE8021X_EAPOL
236 struct wpa_ssid *ssid;
237 struct eap_peer_config *eap;
239 pos = os_strchr(rsp, '-');
244 pos = os_strchr(pos, ':');
249 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
250 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
251 (u8 *) pos, os_strlen(pos));
253 ssid = wpa_config_get_network(wpa_s->conf, id);
255 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
261 if (os_strcmp(rsp, "IDENTITY") == 0) {
262 os_free(eap->identity);
263 eap->identity = (u8 *) os_strdup(pos);
264 eap->identity_len = os_strlen(pos);
265 eap->pending_req_identity = 0;
266 if (ssid == wpa_s->current_ssid)
267 wpa_s->reassociate = 1;
268 } else if (os_strcmp(rsp, "PASSWORD") == 0) {
269 os_free(eap->password);
270 eap->password = (u8 *) os_strdup(pos);
271 eap->password_len = os_strlen(pos);
272 eap->pending_req_password = 0;
273 if (ssid == wpa_s->current_ssid)
274 wpa_s->reassociate = 1;
275 } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) {
276 os_free(eap->new_password);
277 eap->new_password = (u8 *) os_strdup(pos);
278 eap->new_password_len = os_strlen(pos);
279 eap->pending_req_new_password = 0;
280 if (ssid == wpa_s->current_ssid)
281 wpa_s->reassociate = 1;
282 } else if (os_strcmp(rsp, "PIN") == 0) {
284 eap->pin = os_strdup(pos);
285 eap->pending_req_pin = 0;
286 if (ssid == wpa_s->current_ssid)
287 wpa_s->reassociate = 1;
288 } else if (os_strcmp(rsp, "OTP") == 0) {
290 eap->otp = (u8 *) os_strdup(pos);
291 eap->otp_len = os_strlen(pos);
292 os_free(eap->pending_req_otp);
293 eap->pending_req_otp = NULL;
294 eap->pending_req_otp_len = 0;
295 } else if (os_strcmp(rsp, "PASSPHRASE") == 0) {
296 os_free(eap->private_key_passwd);
297 eap->private_key_passwd = (u8 *) os_strdup(pos);
298 eap->pending_req_passphrase = 0;
299 if (ssid == wpa_s->current_ssid)
300 wpa_s->reassociate = 1;
302 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
307 #else /* IEEE8021X_EAPOL */
308 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
310 #endif /* IEEE8021X_EAPOL */
314 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
316 char *buf, size_t buflen)
318 char *pos, *end, tmp[30];
319 int res, verbose, ret;
321 verbose = os_strcmp(params, "-VERBOSE") == 0;
324 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
325 struct wpa_ssid *ssid = wpa_s->current_ssid;
326 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
327 MAC2STR(wpa_s->bssid));
328 if (ret < 0 || ret >= end - pos)
332 u8 *_ssid = ssid->ssid;
333 size_t ssid_len = ssid->ssid_len;
334 u8 ssid_buf[MAX_SSID_LEN];
336 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
343 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
344 wpa_ssid_txt(_ssid, ssid_len),
346 if (ret < 0 || ret >= end - pos)
351 ret = os_snprintf(pos, end - pos,
354 if (ret < 0 || ret >= end - pos)
360 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
362 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
363 wpa_supplicant_state_txt(wpa_s->wpa_state));
364 if (ret < 0 || ret >= end - pos)
369 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
370 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
371 if (ret < 0 || ret >= end - pos)
376 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
377 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
378 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
384 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
392 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
397 struct wpa_ssid *ssid;
400 /* cmd: "<network id> <BSSID>" */
401 pos = os_strchr(cmd, ' ');
406 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
407 if (hwaddr_aton(pos, bssid)) {
408 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
412 ssid = wpa_config_get_network(wpa_s->conf, id);
414 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
419 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
420 ssid->bssid_set = !is_zero_ether_addr(bssid);
426 static int wpa_supplicant_ctrl_iface_list_networks(
427 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
430 struct wpa_ssid *ssid;
435 ret = os_snprintf(pos, end - pos,
436 "network id / ssid / bssid / flags\n");
437 if (ret < 0 || ret >= end - pos)
441 ssid = wpa_s->conf->ssid;
443 ret = os_snprintf(pos, end - pos, "%d\t%s",
445 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
446 if (ret < 0 || ret >= end - pos)
449 if (ssid->bssid_set) {
450 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
451 MAC2STR(ssid->bssid));
453 ret = os_snprintf(pos, end - pos, "\tany");
455 if (ret < 0 || ret >= end - pos)
458 ret = os_snprintf(pos, end - pos, "\t%s%s",
459 ssid == wpa_s->current_ssid ?
461 ssid->disabled ? "[DISABLED]" : "");
462 if (ret < 0 || ret >= end - pos)
465 ret = os_snprintf(pos, end - pos, "\n");
466 if (ret < 0 || ret >= end - pos)
477 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
480 ret = os_snprintf(pos, end - pos, "-");
481 if (ret < 0 || ret >= end - pos)
484 if (cipher & WPA_CIPHER_NONE) {
485 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
486 if (ret < 0 || ret >= end - pos)
491 if (cipher & WPA_CIPHER_WEP40) {
492 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
493 if (ret < 0 || ret >= end - pos)
498 if (cipher & WPA_CIPHER_WEP104) {
499 ret = os_snprintf(pos, end - pos, "%sWEP104",
501 if (ret < 0 || ret >= end - pos)
506 if (cipher & WPA_CIPHER_TKIP) {
507 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
508 if (ret < 0 || ret >= end - pos)
513 if (cipher & WPA_CIPHER_CCMP) {
514 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
515 if (ret < 0 || ret >= end - pos)
524 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
525 const u8 *ie, size_t ie_len)
527 struct wpa_ie_data data;
530 ret = os_snprintf(pos, end - pos, "[%s-", proto);
531 if (ret < 0 || ret >= end - pos)
535 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
536 ret = os_snprintf(pos, end - pos, "?]");
537 if (ret < 0 || ret >= end - pos)
544 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
545 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
546 if (ret < 0 || ret >= end - pos)
551 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
552 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
553 if (ret < 0 || ret >= end - pos)
558 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
559 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
560 if (ret < 0 || ret >= end - pos)
565 #ifdef CONFIG_IEEE80211R
566 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
567 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
569 if (ret < 0 || ret >= end - pos)
574 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
575 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
577 if (ret < 0 || ret >= end - pos)
582 #endif /* CONFIG_IEEE80211R */
583 #ifdef CONFIG_IEEE80211W
584 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
585 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
587 if (ret < 0 || ret >= end - pos)
592 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
593 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
595 if (ret < 0 || ret >= end - pos)
600 #endif /* CONFIG_IEEE80211W */
602 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
604 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
605 ret = os_snprintf(pos, end - pos, "-preauth");
606 if (ret < 0 || ret >= end - pos)
611 ret = os_snprintf(pos, end - pos, "]");
612 if (ret < 0 || ret >= end - pos)
619 static char * wpa_supplicant_wps_ie_txt(char *pos, char *end,
620 const struct wpa_scan_res *res)
623 struct wpabuf *wps_ie;
627 wps_ie = wpa_scan_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
631 if (wps_is_selected_pbc_registrar(wps_ie))
633 else if (wps_is_selected_pin_registrar(wps_ie))
638 ret = os_snprintf(pos, end - pos, "%s", txt);
639 if (ret >= 0 && ret < end - pos)
642 #endif /* CONFIG_WPS */
648 /* Format one result on one text line into a buffer. */
649 static int wpa_supplicant_ctrl_iface_scan_result(
650 const struct wpa_scan_res *res, char *buf, size_t buflen)
659 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
660 MAC2STR(res->bssid), res->freq, res->level);
661 if (ret < 0 || ret >= end - pos)
664 ie = wpa_scan_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
666 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
667 ie2 = wpa_scan_get_ie(res, WLAN_EID_RSN);
669 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
670 pos = wpa_supplicant_wps_ie_txt(pos, end, res);
671 if (!ie && !ie2 && res->caps & IEEE80211_CAP_PRIVACY) {
672 ret = os_snprintf(pos, end - pos, "[WEP]");
673 if (ret < 0 || ret >= end - pos)
677 if (res->caps & IEEE80211_CAP_IBSS) {
678 ret = os_snprintf(pos, end - pos, "[IBSS]");
679 if (ret < 0 || ret >= end - pos)
684 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
685 ret = os_snprintf(pos, end - pos, "\t%s",
686 ie ? wpa_ssid_txt(ie + 2, ie[1]) : "");
687 if (ret < 0 || ret >= end - pos)
691 ret = os_snprintf(pos, end - pos, "\n");
692 if (ret < 0 || ret >= end - pos)
700 static int wpa_supplicant_ctrl_iface_scan_results(
701 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
704 struct wpa_scan_res *res;
708 if (wpa_s->scan_res == NULL &&
709 wpa_supplicant_get_scan_results(wpa_s) < 0)
714 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
716 if (ret < 0 || ret >= end - pos)
720 for (i = 0; i < wpa_s->scan_res->num; i++) {
721 res = wpa_s->scan_res->res[i];
722 ret = wpa_supplicant_ctrl_iface_scan_result(res, pos,
724 if (ret < 0 || ret >= end - pos)
733 static int wpa_supplicant_ctrl_iface_select_network(
734 struct wpa_supplicant *wpa_s, char *cmd)
737 struct wpa_ssid *ssid;
739 /* cmd: "<network id>" or "any" */
740 if (os_strcmp(cmd, "any") == 0) {
741 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
742 ssid = wpa_s->conf->ssid;
747 wpa_s->reassociate = 1;
748 wpa_supplicant_req_scan(wpa_s, 0, 0);
753 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
755 ssid = wpa_config_get_network(wpa_s->conf, id);
757 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
762 if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
763 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
765 /* Mark all other networks disabled and trigger reassociation */
766 ssid = wpa_s->conf->ssid;
768 ssid->disabled = id != ssid->id;
771 wpa_s->reassociate = 1;
772 wpa_supplicant_req_scan(wpa_s, 0, 0);
778 static int wpa_supplicant_ctrl_iface_enable_network(
779 struct wpa_supplicant *wpa_s, char *cmd)
782 struct wpa_ssid *ssid;
784 /* cmd: "<network id>" or "all" */
785 if (os_strcmp(cmd, "all") == 0) {
786 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
787 ssid = wpa_s->conf->ssid;
789 if (ssid == wpa_s->current_ssid && ssid->disabled)
790 wpa_s->reassociate = 1;
794 if (wpa_s->reassociate)
795 wpa_supplicant_req_scan(wpa_s, 0, 0);
800 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
802 ssid = wpa_config_get_network(wpa_s->conf, id);
804 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
809 if (wpa_s->current_ssid == NULL && ssid->disabled) {
811 * Try to reassociate since there is no current configuration
812 * and a new network was made available. */
813 wpa_s->reassociate = 1;
814 wpa_supplicant_req_scan(wpa_s, 0, 0);
822 static int wpa_supplicant_ctrl_iface_disable_network(
823 struct wpa_supplicant *wpa_s, char *cmd)
826 struct wpa_ssid *ssid;
828 /* cmd: "<network id>" or "all" */
829 if (os_strcmp(cmd, "all") == 0) {
830 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
831 ssid = wpa_s->conf->ssid;
836 if (wpa_s->current_ssid)
837 wpa_supplicant_disassociate(wpa_s,
838 WLAN_REASON_DEAUTH_LEAVING);
843 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
845 ssid = wpa_config_get_network(wpa_s->conf, id);
847 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
852 if (ssid == wpa_s->current_ssid)
853 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
860 static int wpa_supplicant_ctrl_iface_add_network(
861 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
863 struct wpa_ssid *ssid;
866 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
868 ssid = wpa_config_add_network(wpa_s->conf);
872 wpa_config_set_network_defaults(ssid);
874 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
875 if (ret < 0 || (size_t) ret >= buflen)
881 static int wpa_supplicant_ctrl_iface_remove_network(
882 struct wpa_supplicant *wpa_s, char *cmd)
885 struct wpa_ssid *ssid;
887 /* cmd: "<network id>" or "all" */
888 if (os_strcmp(cmd, "all") == 0) {
889 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
890 ssid = wpa_s->conf->ssid;
894 wpa_config_remove_network(wpa_s->conf, id);
896 if (wpa_s->current_ssid) {
897 eapol_sm_invalidate_cached_session(wpa_s->eapol);
898 wpa_supplicant_disassociate(wpa_s,
899 WLAN_REASON_DEAUTH_LEAVING);
905 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
907 ssid = wpa_config_get_network(wpa_s->conf, id);
909 wpa_config_remove_network(wpa_s->conf, id) < 0) {
910 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
915 if (ssid == wpa_s->current_ssid) {
917 * Invalidate the EAP session cache if the current network is
920 eapol_sm_invalidate_cached_session(wpa_s->eapol);
922 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
929 static int wpa_supplicant_ctrl_iface_set_network(
930 struct wpa_supplicant *wpa_s, char *cmd)
933 struct wpa_ssid *ssid;
936 /* cmd: "<network id> <variable name> <value>" */
937 name = os_strchr(cmd, ' ');
942 value = os_strchr(name, ' ');
948 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
950 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
951 (u8 *) value, os_strlen(value));
953 ssid = wpa_config_get_network(wpa_s->conf, id);
955 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
960 if (wpa_config_set(ssid, name, value, 0) < 0) {
961 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
962 "variable '%s'", name);
966 if (wpa_s->current_ssid == ssid) {
968 * Invalidate the EAP session cache if anything in the current
969 * configuration changes.
971 eapol_sm_invalidate_cached_session(wpa_s->eapol);
974 if ((os_strcmp(name, "psk") == 0 &&
975 value[0] == '"' && ssid->ssid_len) ||
976 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
977 wpa_config_update_psk(ssid);
983 static int wpa_supplicant_ctrl_iface_get_network(
984 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
988 struct wpa_ssid *ssid;
991 /* cmd: "<network id> <variable name>" */
992 name = os_strchr(cmd, ' ');
993 if (name == NULL || buflen == 0)
998 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1001 ssid = wpa_config_get_network(wpa_s->conf, id);
1003 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1008 value = wpa_config_get_no_key(ssid, name);
1009 if (value == NULL) {
1010 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
1011 "variable '%s'", name);
1015 res = os_strlcpy(buf, value, buflen);
1016 if (res >= buflen) {
1027 #ifndef CONFIG_NO_CONFIG_WRITE
1028 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
1032 if (!wpa_s->conf->update_config) {
1033 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
1034 "to update configuration (update_config=0)");
1038 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
1040 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
1041 "update configuration");
1043 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
1049 #endif /* CONFIG_NO_CONFIG_WRITE */
1052 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
1053 struct wpa_driver_capa *capa,
1054 char *buf, size_t buflen)
1066 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
1072 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1073 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
1074 if (ret < 0 || ret >= end - pos)
1080 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1081 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
1082 if (ret < 0 || ret >= end - pos)
1088 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1089 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
1090 if (ret < 0 || ret >= end - pos)
1100 static int ctrl_iface_get_capability_group(int res, char *strict,
1101 struct wpa_driver_capa *capa,
1102 char *buf, size_t buflen)
1114 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
1120 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1121 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
1122 if (ret < 0 || ret >= end - pos)
1128 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1129 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
1130 if (ret < 0 || ret >= end - pos)
1136 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
1137 ret = os_snprintf(pos, end - pos, "%sWEP104",
1139 if (ret < 0 || ret >= end - pos)
1145 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
1146 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
1147 if (ret < 0 || ret >= end - pos)
1157 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
1158 struct wpa_driver_capa *capa,
1159 char *buf, size_t buflen)
1171 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
1178 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
1179 if (ret < 0 || ret >= end - pos)
1183 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1184 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
1185 ret = os_snprintf(pos, end - pos, " WPA-EAP");
1186 if (ret < 0 || ret >= end - pos)
1191 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1192 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1193 ret = os_snprintf(pos, end - pos, " WPA-PSK");
1194 if (ret < 0 || ret >= end - pos)
1199 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1200 ret = os_snprintf(pos, end - pos, " WPA-NONE");
1201 if (ret < 0 || ret >= end - pos)
1210 static int ctrl_iface_get_capability_proto(int res, char *strict,
1211 struct wpa_driver_capa *capa,
1212 char *buf, size_t buflen)
1224 len = os_strlcpy(buf, "RSN WPA", buflen);
1230 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1231 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1232 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
1233 if (ret < 0 || ret >= end - pos)
1239 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1240 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
1241 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
1242 if (ret < 0 || ret >= end - pos)
1252 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
1253 struct wpa_driver_capa *capa,
1254 char *buf, size_t buflen)
1266 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
1272 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
1273 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
1274 if (ret < 0 || ret >= end - pos)
1280 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
1281 ret = os_snprintf(pos, end - pos, "%sSHARED",
1283 if (ret < 0 || ret >= end - pos)
1289 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
1290 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
1291 if (ret < 0 || ret >= end - pos)
1301 static int wpa_supplicant_ctrl_iface_get_capability(
1302 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
1305 struct wpa_driver_capa capa;
1311 /* Determine whether or not strict checking was requested */
1312 len = os_strlcpy(field, _field, sizeof(field));
1313 if (len >= sizeof(field))
1315 strict = os_strchr(field, ' ');
1316 if (strict != NULL) {
1318 if (os_strcmp(strict, "strict") != 0)
1322 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
1323 field, strict ? strict : "");
1325 if (os_strcmp(field, "eap") == 0) {
1326 return eap_get_names(buf, buflen);
1329 res = wpa_drv_get_capa(wpa_s, &capa);
1331 if (os_strcmp(field, "pairwise") == 0)
1332 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
1335 if (os_strcmp(field, "group") == 0)
1336 return ctrl_iface_get_capability_group(res, strict, &capa,
1339 if (os_strcmp(field, "key_mgmt") == 0)
1340 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
1343 if (os_strcmp(field, "proto") == 0)
1344 return ctrl_iface_get_capability_proto(res, strict, &capa,
1347 if (os_strcmp(field, "auth_alg") == 0)
1348 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
1351 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
1358 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
1359 const char *cmd, char *buf,
1364 struct wpa_scan_results *results;
1365 struct wpa_scan_res *bss;
1370 if (wpa_s->scan_res == NULL &&
1371 wpa_supplicant_get_scan_results(wpa_s) < 0)
1374 results = wpa_s->scan_res;
1375 if (results == NULL)
1378 if (hwaddr_aton(cmd, bssid) == 0) {
1379 for (i = 0; i < results->num; i++) {
1380 if (os_memcmp(bssid, results->res[i]->bssid, ETH_ALEN)
1387 if (i >= results->num || results->res[i] == NULL)
1388 return 0; /* no match found */
1390 bss = results->res[i];
1393 ret = os_snprintf(pos, end - pos,
1394 "bssid=" MACSTR "\n"
1397 "capabilities=0x%04x\n"
1403 MAC2STR(bss->bssid), bss->freq, bss->beacon_int,
1404 bss->caps, bss->qual, bss->noise, bss->level,
1405 (unsigned long long) bss->tsf);
1406 if (ret < 0 || ret >= end - pos)
1410 ie = (const u8 *) (bss + 1);
1411 for (i = 0; i < bss->ie_len; i++) {
1412 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
1413 if (ret < 0 || ret >= end - pos)
1418 ret = os_snprintf(pos, end - pos, "\n");
1419 if (ret < 0 || ret >= end - pos)
1423 ret = os_snprintf(pos, end - pos, "flags=");
1424 if (ret < 0 || ret >= end - pos)
1428 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1430 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1431 ie2 = wpa_scan_get_ie(bss, WLAN_EID_RSN);
1433 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1434 pos = wpa_supplicant_wps_ie_txt(pos, end, bss);
1435 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1436 ret = os_snprintf(pos, end - pos, "[WEP]");
1437 if (ret < 0 || ret >= end - pos)
1441 if (bss->caps & IEEE80211_CAP_IBSS) {
1442 ret = os_snprintf(pos, end - pos, "[IBSS]");
1443 if (ret < 0 || ret >= end - pos)
1448 ret = os_snprintf(pos, end - pos, "\n");
1449 if (ret < 0 || ret >= end - pos)
1453 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
1454 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
1455 ie ? wpa_ssid_txt(ie + 2, ie[1]) : "");
1456 if (ret < 0 || ret >= end - pos)
1464 static int wpa_supplicant_ctrl_iface_ap_scan(
1465 struct wpa_supplicant *wpa_s, char *cmd)
1467 int ap_scan = atoi(cmd);
1469 if (ap_scan < 0 || ap_scan > 2)
1471 wpa_s->conf->ap_scan = ap_scan;
1476 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
1477 char *buf, size_t *resp_len)
1480 const int reply_size = 2048;
1484 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
1485 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
1486 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
1487 (const u8 *) buf, os_strlen(buf));
1489 wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface",
1490 (const u8 *) buf, os_strlen(buf));
1493 reply = os_malloc(reply_size);
1494 if (reply == NULL) {
1499 os_memcpy(reply, "OK\n", 3);
1502 if (os_strcmp(buf, "PING") == 0) {
1503 os_memcpy(reply, "PONG\n", 5);
1505 } else if (os_strcmp(buf, "MIB") == 0) {
1506 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
1507 if (reply_len >= 0) {
1509 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
1510 reply_size - reply_len);
1516 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
1517 reply_len = wpa_supplicant_ctrl_iface_status(
1518 wpa_s, buf + 6, reply, reply_size);
1519 } else if (os_strcmp(buf, "PMKSA") == 0) {
1520 reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size);
1521 } else if (os_strncmp(buf, "SET ", 4) == 0) {
1522 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
1524 } else if (os_strcmp(buf, "LOGON") == 0) {
1525 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
1526 } else if (os_strcmp(buf, "LOGOFF") == 0) {
1527 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
1528 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
1529 wpa_s->disconnected = 0;
1530 wpa_s->reassociate = 1;
1531 wpa_supplicant_req_scan(wpa_s, 0, 0);
1532 } else if (os_strcmp(buf, "RECONNECT") == 0) {
1533 if (wpa_s->disconnected) {
1534 wpa_s->disconnected = 0;
1535 wpa_s->reassociate = 1;
1536 wpa_supplicant_req_scan(wpa_s, 0, 0);
1538 #ifdef IEEE8021X_EAPOL
1539 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
1540 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
1542 #endif /* IEEE8021X_EAPOL */
1543 #ifdef CONFIG_PEERKEY
1544 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
1545 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
1547 #endif /* CONFIG_PEERKEY */
1548 #ifdef CONFIG_IEEE80211R
1549 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
1550 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
1552 #endif /* CONFIG_IEEE80211R */
1554 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
1555 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL))
1557 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
1558 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8))
1560 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
1561 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
1564 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
1565 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
1567 #endif /* CONFIG_WPS */
1568 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
1570 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1571 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
1575 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
1576 if (wpa_supplicant_reload_configuration(wpa_s))
1578 } else if (os_strcmp(buf, "TERMINATE") == 0) {
1580 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
1581 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
1583 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
1584 reply_len = wpa_supplicant_ctrl_iface_list_networks(
1585 wpa_s, reply, reply_size);
1586 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
1587 wpa_s->reassociate = 0;
1588 wpa_s->disconnected = 1;
1589 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1590 } else if (os_strcmp(buf, "SCAN") == 0) {
1591 wpa_s->scan_req = 2;
1592 wpa_supplicant_req_scan(wpa_s, 0, 0);
1593 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
1594 reply_len = wpa_supplicant_ctrl_iface_scan_results(
1595 wpa_s, reply, reply_size);
1596 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
1597 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
1599 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
1600 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
1602 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
1603 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
1605 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
1606 reply_len = wpa_supplicant_ctrl_iface_add_network(
1607 wpa_s, reply, reply_size);
1608 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
1609 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
1611 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
1612 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
1614 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
1615 reply_len = wpa_supplicant_ctrl_iface_get_network(
1616 wpa_s, buf + 12, reply, reply_size);
1617 #ifndef CONFIG_NO_CONFIG_WRITE
1618 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
1619 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
1621 #endif /* CONFIG_NO_CONFIG_WRITE */
1622 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
1623 reply_len = wpa_supplicant_ctrl_iface_get_capability(
1624 wpa_s, buf + 15, reply, reply_size);
1625 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
1626 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
1628 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
1629 reply_len = wpa_supplicant_global_iface_list(
1630 wpa_s->global, reply, reply_size);
1631 } else if (os_strcmp(buf, "INTERFACES") == 0) {
1632 reply_len = wpa_supplicant_global_iface_interfaces(
1633 wpa_s->global, reply, reply_size);
1634 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
1635 reply_len = wpa_supplicant_ctrl_iface_bss(
1636 wpa_s, buf + 4, reply, reply_size);
1638 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
1642 if (reply_len < 0) {
1643 os_memcpy(reply, "FAIL\n", 5);
1648 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1650 *resp_len = reply_len;
1655 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
1658 struct wpa_interface iface;
1662 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1663 * TAB<bridge_ifname>
1665 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
1667 os_memset(&iface, 0, sizeof(iface));
1670 iface.ifname = pos = cmd;
1671 pos = os_strchr(pos, '\t');
1674 if (iface.ifname[0] == '\0')
1679 iface.confname = pos;
1680 pos = os_strchr(pos, '\t');
1683 if (iface.confname[0] == '\0')
1684 iface.confname = NULL;
1689 pos = os_strchr(pos, '\t');
1692 if (iface.driver[0] == '\0')
1693 iface.driver = NULL;
1697 iface.ctrl_interface = pos;
1698 pos = os_strchr(pos, '\t');
1701 if (iface.ctrl_interface[0] == '\0')
1702 iface.ctrl_interface = NULL;
1706 iface.driver_param = pos;
1707 pos = os_strchr(pos, '\t');
1710 if (iface.driver_param[0] == '\0')
1711 iface.driver_param = NULL;
1715 iface.bridge_ifname = pos;
1716 pos = os_strchr(pos, '\t');
1719 if (iface.bridge_ifname[0] == '\0')
1720 iface.bridge_ifname = NULL;
1725 if (wpa_supplicant_get_iface(global, iface.ifname))
1728 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
1732 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
1735 struct wpa_supplicant *wpa_s;
1737 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
1739 wpa_s = wpa_supplicant_get_iface(global, cmd);
1742 return wpa_supplicant_remove_iface(global, wpa_s);
1746 static void wpa_free_iface_info(struct wpa_interface_info *iface)
1748 struct wpa_interface_info *prev;
1752 iface = iface->next;
1754 os_free(prev->ifname);
1755 os_free(prev->desc);
1761 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
1765 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
1768 for (i = 0; wpa_supplicant_drivers[i]; i++) {
1769 struct wpa_driver_ops *drv = wpa_supplicant_drivers[i];
1770 if (drv->get_interfaces == NULL)
1772 tmp = drv->get_interfaces(global->drv_priv);
1786 for (tmp = iface; tmp; tmp = tmp->next) {
1787 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
1788 tmp->drv_name, tmp->ifname,
1789 tmp->desc ? tmp->desc : "");
1790 if (res < 0 || res >= end - pos) {
1797 wpa_free_iface_info(iface);
1803 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
1808 struct wpa_supplicant *wpa_s;
1810 wpa_s = global->ifaces;
1815 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
1816 if (res < 0 || res >= end - pos) {
1821 wpa_s = wpa_s->next;
1827 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
1828 char *buf, size_t *resp_len)
1831 const int reply_size = 2048;
1834 wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface",
1835 (const u8 *) buf, os_strlen(buf));
1837 reply = os_malloc(reply_size);
1838 if (reply == NULL) {
1843 os_memcpy(reply, "OK\n", 3);
1846 if (os_strcmp(buf, "PING") == 0) {
1847 os_memcpy(reply, "PONG\n", 5);
1849 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
1850 if (wpa_supplicant_global_iface_add(global, buf + 14))
1852 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
1853 if (wpa_supplicant_global_iface_remove(global, buf + 17))
1855 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
1856 reply_len = wpa_supplicant_global_iface_list(
1857 global, reply, reply_size);
1858 } else if (os_strcmp(buf, "INTERFACES") == 0) {
1859 reply_len = wpa_supplicant_global_iface_interfaces(
1860 global, reply, reply_size);
1861 } else if (os_strcmp(buf, "TERMINATE") == 0) {
1864 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
1868 if (reply_len < 0) {
1869 os_memcpy(reply, "FAIL\n", 5);
1873 *resp_len = reply_len;