2 * WPA Supplicant / UNIX domain and UDP socket -based control interface
3 * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.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.
19 #include <sys/types.h>
22 #ifndef CONFIG_NATIVE_WINDOWS
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
28 #endif /* CONFIG_NATIVE_WINDOWS */
33 #include "wpa_supplicant.h"
36 #include "wpa_supplicant_i.h"
37 #include "ctrl_iface.h"
38 #include "l2_packet.h"
44 #ifdef CONFIG_CTRL_IFACE_UDP
45 #define CTRL_IFACE_SOCK struct sockaddr_in
46 #else /* CONFIG_CTRL_IFACE_UDP */
47 #define CTRL_IFACE_SOCK struct sockaddr_un
48 #endif /* CONFIG_CTRL_IFACE_UDP */
52 * struct wpa_ctrl_dst - Internal data structure of control interface monitors
54 * This structure is used to store information about registered control
55 * interface monitors into struct wpa_supplicant. This data is private to
56 * ctrl_iface.c and should not be touched directly from other files.
59 struct wpa_ctrl_dst *next;
67 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
73 value = strchr(cmd, ' ');
78 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
79 if (strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
80 eapol_sm_configure(wpa_s->eapol,
81 atoi(value), -1, -1, -1);
82 } else if (strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
83 eapol_sm_configure(wpa_s->eapol,
84 -1, atoi(value), -1, -1);
85 } else if (strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
86 eapol_sm_configure(wpa_s->eapol,
87 -1, -1, atoi(value), -1);
88 } else if (strcasecmp(cmd, "EAPOL::maxStart") == 0) {
89 eapol_sm_configure(wpa_s->eapol,
90 -1, -1, -1, atoi(value));
91 } else if (strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
92 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
95 } else if (strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == 0) {
96 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
99 } else if (strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
100 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
109 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
114 if (hwaddr_aton(addr, bssid)) {
115 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
120 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
121 rsn_preauth_deinit(wpa_s->wpa);
122 if (rsn_preauth_init(wpa_s->wpa, bssid, wpa_s->current_ssid))
129 static int wpa_supplicant_ctrl_iface_attach(struct wpa_supplicant *wpa_s,
130 CTRL_IFACE_SOCK *from,
133 struct wpa_ctrl_dst *dst;
135 dst = malloc(sizeof(*dst));
138 memset(dst, 0, sizeof(*dst));
139 memcpy(&dst->addr, from, sizeof(CTRL_IFACE_SOCK));
140 dst->addrlen = fromlen;
141 dst->debug_level = MSG_INFO;
142 dst->next = wpa_s->ctrl_dst;
143 wpa_s->ctrl_dst = dst;
144 #ifdef CONFIG_CTRL_IFACE_UDP
145 wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor attached %s:%d",
146 inet_ntoa(from->sin_addr), ntohs(from->sin_port));
147 #else /* CONFIG_CTRL_IFACE_UDP */
148 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached",
149 (u8 *) from->sun_path, fromlen);
150 #endif /* CONFIG_CTRL_IFACE_UDP */
155 static int wpa_supplicant_ctrl_iface_detach(struct wpa_supplicant *wpa_s,
156 CTRL_IFACE_SOCK *from,
159 struct wpa_ctrl_dst *dst, *prev = NULL;
161 dst = wpa_s->ctrl_dst;
163 #ifdef CONFIG_CTRL_IFACE_UDP
164 if (from->sin_addr.s_addr == dst->addr.sin_addr.s_addr &&
165 from->sin_port == dst->addr.sin_port) {
167 wpa_s->ctrl_dst = dst->next;
169 prev->next = dst->next;
171 wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor detached "
172 "%s:%d", inet_ntoa(from->sin_addr),
173 ntohs(from->sin_port));
176 #else /* CONFIG_CTRL_IFACE_UDP */
177 if (fromlen == dst->addrlen &&
178 memcmp(from->sun_path, dst->addr.sun_path, fromlen) == 0) {
180 wpa_s->ctrl_dst = dst->next;
182 prev->next = dst->next;
184 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached",
185 (u8 *) from->sun_path, fromlen);
188 #endif /* CONFIG_CTRL_IFACE_UDP */
196 static int wpa_supplicant_ctrl_iface_level(struct wpa_supplicant *wpa_s,
197 CTRL_IFACE_SOCK *from,
201 struct wpa_ctrl_dst *dst;
203 wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
205 dst = wpa_s->ctrl_dst;
207 #ifdef CONFIG_CTRL_IFACE_UDP
208 if (from->sin_addr.s_addr == dst->addr.sin_addr.s_addr &&
209 from->sin_port == dst->addr.sin_port) {
210 wpa_printf(MSG_DEBUG, "CTRL_IFACE changed monitor "
211 "level %s:%d", inet_ntoa(from->sin_addr),
212 ntohs(from->sin_port));
213 dst->debug_level = atoi(level);
216 #else /* CONFIG_CTRL_IFACE_UDP */
217 if (fromlen == dst->addrlen &&
218 memcmp(from->sun_path, dst->addr.sun_path, fromlen) == 0) {
219 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE changed monitor "
220 "level", (u8 *) from->sun_path, fromlen);
221 dst->debug_level = atoi(level);
224 #endif /* CONFIG_CTRL_IFACE_UDP */
232 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
237 struct wpa_ssid *ssid;
239 pos = strchr(rsp, '-');
244 pos = 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, 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 "
260 if (strcmp(rsp, "IDENTITY") == 0) {
261 free(ssid->identity);
262 ssid->identity = (u8 *) strdup(pos);
263 ssid->identity_len = strlen(pos);
264 ssid->pending_req_identity = 0;
265 if (ssid == wpa_s->current_ssid)
266 wpa_s->reassociate = 1;
267 } else if (strcmp(rsp, "PASSWORD") == 0) {
268 free(ssid->password);
269 ssid->password = (u8 *) strdup(pos);
270 ssid->password_len = strlen(pos);
271 ssid->pending_req_password = 0;
272 if (ssid == wpa_s->current_ssid)
273 wpa_s->reassociate = 1;
274 } else if (strcmp(rsp, "NEW_PASSWORD") == 0) {
275 free(ssid->new_password);
276 ssid->new_password = (u8 *) strdup(pos);
277 ssid->new_password_len = strlen(pos);
278 ssid->pending_req_new_password = 0;
279 if (ssid == wpa_s->current_ssid)
280 wpa_s->reassociate = 1;
281 } else if (strcmp(rsp, "PIN") == 0) {
283 ssid->pin = strdup(pos);
284 ssid->pending_req_pin = 0;
285 if (ssid == wpa_s->current_ssid)
286 wpa_s->reassociate = 1;
287 } else if (strcmp(rsp, "OTP") == 0) {
289 ssid->otp = (u8 *) strdup(pos);
290 ssid->otp_len = strlen(pos);
291 free(ssid->pending_req_otp);
292 ssid->pending_req_otp = NULL;
293 ssid->pending_req_otp_len = 0;
294 } else if (strcmp(rsp, "PASSPHRASE") == 0) {
295 free(ssid->private_key_passwd);
296 ssid->private_key_passwd = (u8 *) strdup(pos);
297 ssid->pending_req_passphrase = 0;
298 if (ssid == wpa_s->current_ssid)
299 wpa_s->reassociate = 1;
301 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
309 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
311 char *buf, size_t buflen)
313 char *pos, *end, tmp[30];
316 verbose = strcmp(params, "-VERBOSE") == 0;
319 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
320 pos += snprintf(pos, end - pos, "bssid=" MACSTR "\n",
321 MAC2STR(wpa_s->bssid));
322 if (wpa_s->current_ssid) {
323 pos += snprintf(pos, end - pos, "ssid=%s\n",
324 wpa_ssid_txt(wpa_s->current_ssid->ssid,
325 wpa_s->current_ssid->
329 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
331 pos += snprintf(pos, end - pos, "wpa_state=%s\n",
332 wpa_supplicant_state_txt(wpa_s->wpa_state));
335 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0)
336 pos += snprintf(pos, end - pos, "ip_address=%s\n", tmp);
338 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
339 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
340 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
346 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
354 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
359 struct wpa_ssid *ssid;
362 /* cmd: "<network id> <BSSID>" */
363 pos = strchr(cmd, ' ');
368 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
369 if (hwaddr_aton(pos, bssid)) {
370 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
374 ssid = wpa_config_get_network(wpa_s->conf, id);
376 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
381 memcpy(ssid->bssid, bssid, ETH_ALEN);
383 memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0;
390 static int wpa_supplicant_ctrl_iface_list_networks(
391 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
394 struct wpa_ssid *ssid;
398 pos += snprintf(pos, end - pos, "network id / ssid / bssid / flags\n");
400 ssid = wpa_s->conf->ssid;
402 pos += snprintf(pos, end - pos, "%d\t%s",
404 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
405 if (ssid->bssid_set) {
406 pos += snprintf(pos, end - pos, "\t" MACSTR,
407 MAC2STR(ssid->bssid));
409 pos += snprintf(pos, end - pos, "\tany");
411 pos += snprintf(pos, end - pos, "\t%s%s",
412 ssid == wpa_s->current_ssid ? "[CURRENT]" : "",
413 ssid->disabled ? "[DISABLED]" : "");
414 pos += snprintf(pos, end - pos, "\n");
423 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
426 pos += snprintf(pos, end - pos, "-");
427 if (cipher & WPA_CIPHER_NONE) {
428 pos += snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
431 if (cipher & WPA_CIPHER_WEP40) {
432 pos += snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
435 if (cipher & WPA_CIPHER_WEP104) {
436 pos += snprintf(pos, end - pos, "%sWEP104", first ? "" : "+");
439 if (cipher & WPA_CIPHER_TKIP) {
440 pos += snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
443 if (cipher & WPA_CIPHER_CCMP) {
444 pos += snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
451 static char * wpa_supplicant_ie_txt(struct wpa_supplicant *wpa_s,
452 char *pos, char *end, const char *proto,
453 const u8 *ie, size_t ie_len)
455 struct wpa_ie_data data;
458 pos += snprintf(pos, end - pos, "[%s-", proto);
460 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
461 pos += snprintf(pos, end - pos, "?]");
466 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
467 pos += snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
470 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
471 pos += snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
474 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
475 pos += snprintf(pos, end - pos, "%sNone", first ? "" : "+");
479 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
481 if (data.capabilities & WPA_CAPABILITY_PREAUTH)
482 pos += snprintf(pos, end - pos, "-preauth");
484 pos += snprintf(pos, end - pos, "]");
490 static int wpa_supplicant_ctrl_iface_scan_results(
491 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
494 struct wpa_scan_result *res;
497 if (wpa_s->scan_results == NULL &&
498 wpa_supplicant_get_scan_results(wpa_s) < 0)
503 pos += snprintf(pos, end - pos, "bssid / frequency / signal level / "
506 for (i = 0; i < wpa_s->num_scan_results; i++) {
507 res = &wpa_s->scan_results[i];
508 pos += snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
509 MAC2STR(res->bssid), res->freq, res->level);
510 if (res->wpa_ie_len) {
511 pos = wpa_supplicant_ie_txt(wpa_s, pos, end, "WPA",
515 if (res->rsn_ie_len) {
516 pos = wpa_supplicant_ie_txt(wpa_s, pos, end, "WPA2",
520 if (!res->wpa_ie_len && !res->rsn_ie_len &&
521 res->caps & IEEE80211_CAP_PRIVACY)
522 pos += snprintf(pos, end - pos, "[WEP]");
523 if (res->caps & IEEE80211_CAP_IBSS)
524 pos += snprintf(pos, end - pos, "[IBSS]");
526 pos += snprintf(pos, end - pos, "\t%s",
527 wpa_ssid_txt(res->ssid, res->ssid_len));
529 pos += snprintf(pos, end - pos, "\n");
536 static int wpa_supplicant_ctrl_iface_select_network(
537 struct wpa_supplicant *wpa_s, char *cmd)
540 struct wpa_ssid *ssid;
542 /* cmd: "<network id>" or "any" */
543 if (strcmp(cmd, "any") == 0) {
544 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
545 ssid = wpa_s->conf->ssid;
550 wpa_s->reassociate = 1;
551 wpa_supplicant_req_scan(wpa_s, 0, 0);
556 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
558 ssid = wpa_config_get_network(wpa_s->conf, id);
560 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
565 if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
566 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
568 /* Mark all other networks disabled and trigger reassociation */
569 ssid = wpa_s->conf->ssid;
571 ssid->disabled = id != ssid->id;
574 wpa_s->reassociate = 1;
575 wpa_supplicant_req_scan(wpa_s, 0, 0);
581 static int wpa_supplicant_ctrl_iface_enable_network(
582 struct wpa_supplicant *wpa_s, char *cmd)
585 struct wpa_ssid *ssid;
587 /* cmd: "<network id>" */
589 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
591 ssid = wpa_config_get_network(wpa_s->conf, id);
593 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
598 if (wpa_s->current_ssid == NULL && ssid->disabled) {
600 * Try to reassociate since there is no current configuration
601 * and a new network was made available. */
602 wpa_s->reassociate = 1;
603 wpa_supplicant_req_scan(wpa_s, 0, 0);
611 static int wpa_supplicant_ctrl_iface_disable_network(
612 struct wpa_supplicant *wpa_s, char *cmd)
615 struct wpa_ssid *ssid;
617 /* cmd: "<network id>" */
619 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_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)
629 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
636 static int wpa_supplicant_ctrl_iface_add_network(
637 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
639 struct wpa_ssid *ssid;
641 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
643 ssid = wpa_config_add_network(wpa_s->conf);
647 wpa_config_set_network_defaults(ssid);
649 return snprintf(buf, buflen, "%d\n", ssid->id);
653 static int wpa_supplicant_ctrl_iface_remove_network(
654 struct wpa_supplicant *wpa_s, char *cmd)
657 struct wpa_ssid *ssid;
659 /* cmd: "<network id>" */
661 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
663 ssid = wpa_config_get_network(wpa_s->conf, id);
665 wpa_config_remove_network(wpa_s->conf, id) < 0) {
666 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
671 if (ssid == wpa_s->current_ssid)
672 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
678 static int wpa_supplicant_ctrl_iface_set_network(
679 struct wpa_supplicant *wpa_s, char *cmd)
682 struct wpa_ssid *ssid;
685 /* cmd: "<network id> <variable name> <value>" */
686 name = strchr(cmd, ' ');
691 value = strchr(name, ' ');
697 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s' "
698 "value='%s'", id, name, value);
700 ssid = wpa_config_get_network(wpa_s->conf, id);
702 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
707 if (wpa_config_set(ssid, name, value, 0) < 0) {
708 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
709 "variable '%s' to '%s'", name, value);
713 if ((strcmp(name, "psk") == 0 && value[0] == '"' && ssid->ssid_len) ||
714 (strcmp(name, "ssid") == 0 && ssid->passphrase))
715 wpa_config_update_psk(ssid);
721 static int wpa_supplicant_ctrl_iface_get_network(
722 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
725 struct wpa_ssid *ssid;
728 /* cmd: "<network id> <variable name>" */
729 name = strchr(cmd, ' ');
735 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
738 ssid = wpa_config_get_network(wpa_s->conf, id);
740 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
745 value = wpa_config_get(ssid, name);
747 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
748 "variable '%s'", name);
752 snprintf(buf, buflen, "%s", value);
760 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
764 if (!wpa_s->conf->update_config) {
765 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
766 "to update configuration (update_config=0)");
770 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
772 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
773 "update configuration");
775 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
783 static int wpa_supplicant_ctrl_iface_get_capability(
784 struct wpa_supplicant *wpa_s, const char *field, char *buf,
787 struct wpa_driver_capa capa;
791 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'", field);
793 if (strcmp(field, "eap") == 0) {
794 return eap_get_names(buf, buflen);
797 res = wpa_drv_get_capa(wpa_s, &capa);
802 if (strcmp(field, "pairwise") == 0) {
804 return snprintf(buf, buflen, "CCMP TKIP NONE");
806 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
807 pos += snprintf(pos, end - pos, "%sCCMP",
812 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
813 pos += snprintf(pos, end - pos, "%sTKIP",
818 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
819 pos += snprintf(pos, end - pos, "%sNONE",
827 if (strcmp(field, "group") == 0) {
829 return snprintf(buf, buflen, "CCMP TKIP WEP104 WEP40");
831 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
832 pos += snprintf(pos, end - pos, "%sCCMP",
837 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
838 pos += snprintf(pos, end - pos, "%sTKIP",
843 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
844 pos += snprintf(pos, end - pos, "%sWEP104",
849 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
850 pos += snprintf(pos, end - pos, "%sWEP40",
858 if (strcmp(field, "key_mgmt") == 0) {
860 return snprintf(buf, buflen, "WPA-PSK WPA-EAP "
861 "IEEE8021X WPA-NONE NONE");
864 pos += snprintf(pos, end - pos, "NONE IEEE8021X");
866 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
867 WPA_DRIVER_CAPA_KEY_MGMT_WPA2))
868 pos += snprintf(pos, end - pos, " WPA-EAP");
870 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
871 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK))
872 pos += snprintf(pos, end - pos, " WPA-PSK");
874 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE)
875 pos += snprintf(pos, end - pos, " WPA-NONE");
880 if (strcmp(field, "proto") == 0) {
882 return snprintf(buf, buflen, "RSN WPA");
884 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
885 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
886 pos += snprintf(pos, end - pos, "%sRSN",
891 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
892 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
893 pos += snprintf(pos, end - pos, "%sWPA",
901 if (strcmp(field, "auth_alg") == 0) {
903 return snprintf(buf, buflen, "OPEN SHARED LEAP");
905 if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
906 pos += snprintf(pos, end - pos, "%sOPEN",
911 if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
912 pos += snprintf(pos, end - pos, "%sSHARED",
917 if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
918 pos += snprintf(pos, end - pos, "%sLEAP",
926 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
933 static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
936 struct wpa_supplicant *wpa_s = eloop_ctx;
939 CTRL_IFACE_SOCK from;
940 socklen_t fromlen = sizeof(from);
942 const int reply_size = 2048;
944 int new_attached = 0, ctrl_rsp = 0;
946 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
947 (struct sockaddr *) &from, &fromlen);
949 perror("recvfrom(ctrl_iface)");
953 if (strncmp(buf, WPA_CTRL_RSP, strlen(WPA_CTRL_RSP)) == 0) {
954 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
957 wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface", (u8 *) buf, res);
960 reply = malloc(reply_size);
962 sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
967 memcpy(reply, "OK\n", 3);
970 if (strcmp(buf, "PING") == 0) {
971 memcpy(reply, "PONG\n", 5);
973 } else if (strcmp(buf, "MIB") == 0) {
974 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
975 if (reply_len >= 0) {
976 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
977 reply_size - reply_len);
983 } else if (strncmp(buf, "STATUS", 6) == 0) {
984 reply_len = wpa_supplicant_ctrl_iface_status(
985 wpa_s, buf + 6, reply, reply_size);
986 } else if (strcmp(buf, "PMKSA") == 0) {
987 reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size);
988 } else if (strncmp(buf, "SET ", 4) == 0) {
989 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
991 } else if (strcmp(buf, "LOGON") == 0) {
992 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
993 } else if (strcmp(buf, "LOGOFF") == 0) {
994 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
995 } else if (strcmp(buf, "REASSOCIATE") == 0) {
996 wpa_s->disconnected = 0;
997 wpa_s->reassociate = 1;
998 wpa_supplicant_req_scan(wpa_s, 0, 0);
999 } else if (strncmp(buf, "PREAUTH ", 8) == 0) {
1000 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
1002 } else if (strcmp(buf, "ATTACH") == 0) {
1003 if (wpa_supplicant_ctrl_iface_attach(wpa_s, &from, fromlen))
1007 } else if (strcmp(buf, "DETACH") == 0) {
1008 if (wpa_supplicant_ctrl_iface_detach(wpa_s, &from, fromlen))
1010 } else if (strncmp(buf, "LEVEL ", 6) == 0) {
1011 if (wpa_supplicant_ctrl_iface_level(wpa_s, &from, fromlen,
1014 } else if (strncmp(buf, WPA_CTRL_RSP, strlen(WPA_CTRL_RSP)) == 0) {
1015 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1016 wpa_s, buf + strlen(WPA_CTRL_RSP)))
1020 } else if (strcmp(buf, "RECONFIGURE") == 0) {
1021 if (wpa_supplicant_reload_configuration(wpa_s))
1023 } else if (strcmp(buf, "TERMINATE") == 0) {
1025 } else if (strncmp(buf, "BSSID ", 6) == 0) {
1026 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
1028 } else if (strcmp(buf, "LIST_NETWORKS") == 0) {
1029 reply_len = wpa_supplicant_ctrl_iface_list_networks(
1030 wpa_s, reply, reply_size);
1031 } else if (strcmp(buf, "DISCONNECT") == 0) {
1032 wpa_s->disconnected = 1;
1033 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
1034 } else if (strcmp(buf, "SCAN") == 0) {
1035 wpa_s->scan_req = 2;
1036 wpa_supplicant_req_scan(wpa_s, 0, 0);
1037 } else if (strcmp(buf, "SCAN_RESULTS") == 0) {
1038 reply_len = wpa_supplicant_ctrl_iface_scan_results(
1039 wpa_s, reply, reply_size);
1040 } else if (strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
1041 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
1043 } else if (strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
1044 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
1046 } else if (strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
1047 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
1049 } else if (strcmp(buf, "ADD_NETWORK") == 0) {
1050 reply_len = wpa_supplicant_ctrl_iface_add_network(
1051 wpa_s, reply, reply_size);
1052 } else if (strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
1053 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
1055 } else if (strncmp(buf, "SET_NETWORK ", 12) == 0) {
1056 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
1058 } else if (strncmp(buf, "GET_NETWORK ", 12) == 0) {
1059 reply_len = wpa_supplicant_ctrl_iface_get_network(
1060 wpa_s, buf + 12, reply, reply_size);
1061 } else if (strcmp(buf, "SAVE_CONFIG") == 0) {
1062 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
1064 } else if (strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
1065 reply_len = wpa_supplicant_ctrl_iface_get_capability(
1066 wpa_s, buf + 15, reply, reply_size);
1068 memcpy(reply, "UNKNOWN COMMAND\n", 16);
1072 if (reply_len < 0) {
1073 memcpy(reply, "FAIL\n", 5);
1076 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1080 eapol_sm_notify_ctrl_attached(wpa_s->eapol);
1082 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1086 #ifndef CONFIG_CTRL_IFACE_UDP
1087 static char * wpa_supplicant_ctrl_iface_path(struct wpa_supplicant *wpa_s)
1092 if (wpa_s->conf->ctrl_interface == NULL)
1095 len = strlen(wpa_s->conf->ctrl_interface) + strlen(wpa_s->ifname) + 2;
1100 snprintf(buf, len, "%s/%s",
1101 wpa_s->conf->ctrl_interface, wpa_s->ifname);
1104 /* Windows/WinPcap uses interface names that are not suitable
1105 * as a file name - convert invalid chars to underscores */
1113 #endif /* __CYGWIN__ */
1116 #endif /* CONFIG_CTRL_IFACE_UDP */
1120 * wpa_supplicant_ctrl_iface_init - Initialize control interface
1121 * @wpa_s: Pointer to wpa_supplicant data
1122 * Returns: 0 on success, -1 on failure
1124 * Initialize the control interface and start receiving commands from external
1127 int wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
1129 CTRL_IFACE_SOCK addr;
1131 #ifndef CONFIG_CTRL_IFACE_UDP
1133 #endif /* CONFIG_CTRL_IFACE_UDP */
1135 wpa_s->ctrl_sock = -1;
1137 if (wpa_s->conf->ctrl_interface == NULL)
1140 #ifdef CONFIG_CTRL_IFACE_UDP
1141 s = socket(PF_INET, SOCK_DGRAM, 0);
1143 perror("socket(PF_INET)");
1147 memset(&addr, 0, sizeof(addr));
1148 addr.sin_family = AF_INET;
1149 addr.sin_addr.s_addr = htonl((127 << 24) | 1);
1150 addr.sin_port = htons(WPA_CTRL_IFACE_PORT);
1151 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1152 perror("bind(AF_INET)");
1155 #else /* CONFIG_CTRL_IFACE_UDP */
1156 if (mkdir(wpa_s->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
1157 if (errno == EEXIST) {
1158 wpa_printf(MSG_DEBUG, "Using existing control "
1159 "interface directory.");
1161 perror("mkdir[ctrl_interface]");
1166 if (wpa_s->conf->ctrl_interface_gid_set &&
1167 chown(wpa_s->conf->ctrl_interface, 0,
1168 wpa_s->conf->ctrl_interface_gid) < 0) {
1169 perror("chown[ctrl_interface]");
1173 if (strlen(wpa_s->conf->ctrl_interface) + 1 + strlen(wpa_s->ifname) >=
1174 sizeof(addr.sun_path))
1177 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1179 perror("socket(PF_UNIX)");
1183 memset(&addr, 0, sizeof(addr));
1184 addr.sun_family = AF_UNIX;
1185 fname = wpa_supplicant_ctrl_iface_path(wpa_s);
1188 strncpy(addr.sun_path, fname, sizeof(addr.sun_path));
1189 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1190 perror("bind(PF_UNIX)");
1191 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1192 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1193 " allow connections - assuming it was left"
1194 "over from forced program termination");
1195 if (unlink(fname) < 0) {
1196 perror("unlink[ctrl_iface]");
1197 wpa_printf(MSG_ERROR, "Could not unlink "
1198 "existing ctrl_iface socket '%s'",
1202 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1204 perror("bind(PF_UNIX)");
1207 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1208 "ctrl_iface socket '%s'", fname);
1210 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1211 "be in use - cannot override it");
1212 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1213 "not used anymore", fname);
1220 if (wpa_s->conf->ctrl_interface_gid_set &&
1221 chown(fname, 0, wpa_s->conf->ctrl_interface_gid) < 0) {
1222 perror("chown[ctrl_interface/ifname]");
1226 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
1227 perror("chmod[ctrl_interface/ifname]");
1231 #endif /* CONFIG_CTRL_IFACE_UDP */
1233 wpa_s->ctrl_sock = s;
1234 eloop_register_read_sock(s, wpa_supplicant_ctrl_iface_receive, wpa_s,
1242 #ifndef CONFIG_CTRL_IFACE_UDP
1247 #endif /* CONFIG_CTRL_IFACE_UDP */
1253 * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface
1254 * @wpa_s: Pointer to wpa_supplicant data
1256 * Deinitialize the control interface that was initialized with
1257 * wpa_supplicant_ctrl_iface_init().
1259 void wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant *wpa_s)
1261 struct wpa_ctrl_dst *dst, *prev;
1263 if (wpa_s->ctrl_sock > -1) {
1264 #ifndef CONFIG_CTRL_IFACE_UDP
1266 #endif /* CONFIG_CTRL_IFACE_UDP */
1267 eloop_unregister_read_sock(wpa_s->ctrl_sock);
1268 if (wpa_s->ctrl_dst) {
1270 * Wait a second before closing the control socket if
1271 * there are any attached monitors in order to allow
1272 * them to receive any pending messages.
1274 wpa_printf(MSG_DEBUG, "CTRL_IFACE wait for attached "
1275 "monitors to receive messages");
1278 close(wpa_s->ctrl_sock);
1279 wpa_s->ctrl_sock = -1;
1280 #ifndef CONFIG_CTRL_IFACE_UDP
1281 fname = wpa_supplicant_ctrl_iface_path(wpa_s);
1286 if (rmdir(wpa_s->conf->ctrl_interface) < 0) {
1287 if (errno == ENOTEMPTY) {
1288 wpa_printf(MSG_DEBUG, "Control interface "
1289 "directory not empty - leaving it "
1292 perror("rmdir[ctrl_interface]");
1295 #endif /* CONFIG_CTRL_IFACE_UDP */
1298 dst = wpa_s->ctrl_dst;
1308 * wpa_supplicant_ctrl_iface_send - Send a control interface packet to monitors
1309 * @wpa_s: Pointer to wpa_supplicant data
1310 * @level: Priority level of the message
1311 * @buf: Message data
1312 * @len: Message length
1314 * Send a packet to all monitor programs attached to the control interface.
1316 void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant *wpa_s, int level,
1317 char *buf, size_t len)
1319 struct wpa_ctrl_dst *dst, *next;
1322 #ifdef CONFIG_CTRL_IFACE_UDP
1326 dst = wpa_s->ctrl_dst;
1327 if (wpa_s->ctrl_sock < 0 || dst == NULL)
1330 snprintf(levelstr, sizeof(levelstr), "<%d>", level);
1332 llen = strlen(levelstr);
1333 sbuf = malloc(llen + len);
1337 memcpy(sbuf, levelstr, llen);
1338 memcpy(sbuf + llen, buf, len);
1343 if (level >= dst->debug_level) {
1344 wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor send %s:%d",
1345 inet_ntoa(dst->addr.sin_addr),
1346 ntohs(dst->addr.sin_port));
1347 if (sendto(wpa_s->ctrl_sock, sbuf, llen + len, 0,
1348 (struct sockaddr *) &dst->addr,
1349 sizeof(dst->addr)) < 0) {
1350 perror("sendto(CTRL_IFACE monitor)");
1352 if (dst->errors > 10) {
1353 wpa_supplicant_ctrl_iface_detach(
1364 #else /* CONFIG_CTRL_IFACE_UDP */
1368 dst = wpa_s->ctrl_dst;
1369 if (wpa_s->ctrl_sock < 0 || dst == NULL)
1372 snprintf(levelstr, sizeof(levelstr), "<%d>", level);
1373 io[0].iov_base = levelstr;
1374 io[0].iov_len = strlen(levelstr);
1375 io[1].iov_base = buf;
1376 io[1].iov_len = len;
1377 memset(&msg, 0, sizeof(msg));
1384 if (level >= dst->debug_level) {
1385 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
1386 (u8 *) dst->addr.sun_path, dst->addrlen);
1387 msg.msg_name = &dst->addr;
1388 msg.msg_namelen = dst->addrlen;
1389 if (sendmsg(wpa_s->ctrl_sock, &msg, 0) < 0) {
1390 perror("sendmsg(CTRL_IFACE monitor)");
1392 if (dst->errors > 10) {
1393 wpa_supplicant_ctrl_iface_detach(
1403 #endif /* CONFIG_CTRL_IFACE_UDP */
1408 * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor
1409 * @wpa_s: Pointer to wpa_supplicant data
1411 * Wait until the first message from an external program using the control
1412 * interface is received. This function can be used to delay normal startup
1413 * processing to allow control interface programs to attach with
1414 * %wpa_supplicant before normal operations are started.
1416 void wpa_supplicant_ctrl_iface_wait(struct wpa_supplicant *wpa_s)
1420 if (wpa_s->ctrl_sock < 0)
1423 wpa_printf(MSG_DEBUG, "CTRL_IFACE - %s - wait for monitor",
1427 FD_SET(wpa_s->ctrl_sock, &rfds);
1428 select(wpa_s->ctrl_sock + 1, &rfds, NULL, NULL, NULL);
1432 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
1435 struct wpa_interface iface;
1439 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1441 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
1443 memset(&iface, 0, sizeof(iface));
1446 iface.ifname = pos = cmd;
1447 pos = strchr(pos, '\t');
1450 if (iface.ifname[0] == '\0')
1455 iface.confname = pos;
1456 pos = strchr(pos, '\t');
1459 if (iface.confname[0] == '\0')
1460 iface.confname = NULL;
1465 pos = strchr(pos, '\t');
1468 if (iface.driver[0] == '\0')
1469 iface.driver = NULL;
1473 iface.ctrl_interface = pos;
1474 pos = strchr(pos, '\t');
1477 if (iface.ctrl_interface[0] == '\0')
1478 iface.ctrl_interface = NULL;
1482 iface.driver_param = pos;
1483 pos = strchr(pos, '\t');
1486 if (iface.driver_param[0] == '\0')
1487 iface.driver_param = NULL;
1492 if (wpa_supplicant_get_iface(global, iface.ifname))
1495 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
1499 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
1502 struct wpa_supplicant *wpa_s;
1504 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
1506 wpa_s = wpa_supplicant_get_iface(global, cmd);
1509 return wpa_supplicant_remove_iface(global, wpa_s);
1513 static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
1516 struct wpa_global *global = eloop_ctx;
1519 CTRL_IFACE_SOCK from;
1520 socklen_t fromlen = sizeof(from);
1522 const int reply_size = 2048;
1525 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
1526 (struct sockaddr *) &from, &fromlen);
1528 perror("recvfrom(ctrl_iface)");
1532 wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface", (u8 *) buf, res);
1534 reply = malloc(reply_size);
1535 if (reply == NULL) {
1536 sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
1541 memcpy(reply, "OK\n", 3);
1544 if (strcmp(buf, "PING") == 0) {
1545 memcpy(reply, "PONG\n", 5);
1547 } else if (strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
1548 if (wpa_supplicant_global_iface_add(global, buf + 14))
1550 } else if (strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
1551 if (wpa_supplicant_global_iface_remove(global, buf + 17))
1554 memcpy(reply, "UNKNOWN COMMAND\n", 16);
1558 if (reply_len < 0) {
1559 memcpy(reply, "FAIL\n", 5);
1562 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1568 * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface
1569 * @global: Pointer to global data from wpa_supplicant_init()
1570 * Returns: 0 on success, -1 on failure
1572 * Initialize the global control interface and start receiving commands from
1573 * external programs.
1575 int wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
1577 CTRL_IFACE_SOCK addr;
1579 #ifndef CONFIG_CTRL_IFACE_UDP
1581 #endif /* CONFIG_CTRL_IFACE_UDP */
1583 global->ctrl_sock = -1;
1585 if (global->params.ctrl_interface == NULL)
1588 wpa_printf(MSG_DEBUG, "Global control interface '%s'",
1589 global->params.ctrl_interface);
1591 #ifdef CONFIG_CTRL_IFACE_UDP
1592 s = socket(PF_INET, SOCK_DGRAM, 0);
1594 perror("socket(PF_INET)");
1598 memset(&addr, 0, sizeof(addr));
1599 addr.sin_family = AF_INET;
1600 addr.sin_addr.s_addr = htonl((127 << 24) | 1);
1601 addr.sin_port = htons(WPA_GLOBAL_CTRL_IFACE_PORT);
1602 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1603 perror("bind(AF_INET)");
1606 #else /* CONFIG_CTRL_IFACE_UDP */
1607 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1609 perror("socket(PF_UNIX)");
1613 memset(&addr, 0, sizeof(addr));
1614 addr.sun_family = AF_UNIX;
1615 strncpy(addr.sun_path, global->params.ctrl_interface,
1616 sizeof(addr.sun_path));
1617 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1618 perror("bind(PF_UNIX)");
1619 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1620 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1621 " allow connections - assuming it was left"
1622 "over from forced program termination");
1623 if (unlink(global->params.ctrl_interface) < 0) {
1624 perror("unlink[ctrl_iface]");
1625 wpa_printf(MSG_ERROR, "Could not unlink "
1626 "existing ctrl_iface socket '%s'",
1627 global->params.ctrl_interface);
1630 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1632 perror("bind(PF_UNIX)");
1635 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1636 "ctrl_iface socket '%s'",
1637 global->params.ctrl_interface);
1639 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1640 "be in use - cannot override it");
1641 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1643 global->params.ctrl_interface);
1647 #endif /* CONFIG_CTRL_IFACE_UDP */
1649 global->ctrl_sock = s;
1650 eloop_register_read_sock(s, wpa_supplicant_global_ctrl_iface_receive,
1658 #ifndef CONFIG_CTRL_IFACE_UDP
1663 #endif /* CONFIG_CTRL_IFACE_UDP */
1669 * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface
1670 * @global: Pointer to global data from wpa_supplicant_init()
1672 * Deinitialize the global control interface that was initialized with
1673 * wpa_supplicant_global_ctrl_iface_init().
1675 void wpa_supplicant_global_ctrl_iface_deinit(struct wpa_global *global)
1677 if (global->ctrl_sock < 0)
1680 eloop_unregister_read_sock(global->ctrl_sock);
1681 close(global->ctrl_sock);
1682 global->ctrl_sock = -1;
1684 #ifndef CONFIG_CTRL_IFACE_UDP
1685 if (global->params.ctrl_interface)
1686 unlink(global->params.ctrl_interface);
1687 #endif /* CONFIG_CTRL_IFACE_UDP */