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 - sizeof(from->sun_family));
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,
179 fromlen - sizeof(from->sun_family)) == 0) {
181 wpa_s->ctrl_dst = dst->next;
183 prev->next = dst->next;
185 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached",
186 (u8 *) from->sun_path,
187 fromlen - sizeof(from->sun_family));
190 #endif /* CONFIG_CTRL_IFACE_UDP */
198 static int wpa_supplicant_ctrl_iface_level(struct wpa_supplicant *wpa_s,
199 CTRL_IFACE_SOCK *from,
203 struct wpa_ctrl_dst *dst;
205 wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
207 dst = wpa_s->ctrl_dst;
209 #ifdef CONFIG_CTRL_IFACE_UDP
210 if (from->sin_addr.s_addr == dst->addr.sin_addr.s_addr &&
211 from->sin_port == dst->addr.sin_port) {
212 wpa_printf(MSG_DEBUG, "CTRL_IFACE changed monitor "
213 "level %s:%d", inet_ntoa(from->sin_addr),
214 ntohs(from->sin_port));
215 dst->debug_level = atoi(level);
218 #else /* CONFIG_CTRL_IFACE_UDP */
219 if (fromlen == dst->addrlen &&
220 memcmp(from->sun_path, dst->addr.sun_path,
221 fromlen - sizeof(from->sun_family)) == 0) {
222 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE changed monitor "
223 "level", (u8 *) from->sun_path,
224 fromlen - sizeof(from->sun_family));
225 dst->debug_level = atoi(level);
228 #endif /* CONFIG_CTRL_IFACE_UDP */
236 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
241 struct wpa_ssid *ssid;
243 pos = strchr(rsp, '-');
248 pos = strchr(pos, ':');
253 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
254 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
255 (u8 *) pos, strlen(pos));
257 ssid = wpa_config_get_network(wpa_s->conf, id);
259 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
264 if (strcmp(rsp, "IDENTITY") == 0) {
265 free(ssid->identity);
266 ssid->identity = (u8 *) strdup(pos);
267 ssid->identity_len = strlen(pos);
268 ssid->pending_req_identity = 0;
269 if (ssid == wpa_s->current_ssid)
270 wpa_s->reassociate = 1;
271 } else if (strcmp(rsp, "PASSWORD") == 0) {
272 free(ssid->password);
273 ssid->password = (u8 *) strdup(pos);
274 ssid->password_len = strlen(pos);
275 ssid->pending_req_password = 0;
276 if (ssid == wpa_s->current_ssid)
277 wpa_s->reassociate = 1;
278 } else if (strcmp(rsp, "NEW_PASSWORD") == 0) {
279 free(ssid->new_password);
280 ssid->new_password = (u8 *) strdup(pos);
281 ssid->new_password_len = strlen(pos);
282 ssid->pending_req_new_password = 0;
283 if (ssid == wpa_s->current_ssid)
284 wpa_s->reassociate = 1;
285 } else if (strcmp(rsp, "PIN") == 0) {
287 ssid->pin = strdup(pos);
288 ssid->pending_req_pin = 0;
289 if (ssid == wpa_s->current_ssid)
290 wpa_s->reassociate = 1;
291 } else if (strcmp(rsp, "OTP") == 0) {
293 ssid->otp = (u8 *) strdup(pos);
294 ssid->otp_len = strlen(pos);
295 free(ssid->pending_req_otp);
296 ssid->pending_req_otp = NULL;
297 ssid->pending_req_otp_len = 0;
298 } else if (strcmp(rsp, "PASSPHRASE") == 0) {
299 free(ssid->private_key_passwd);
300 ssid->private_key_passwd = (u8 *) strdup(pos);
301 ssid->pending_req_passphrase = 0;
302 if (ssid == wpa_s->current_ssid)
303 wpa_s->reassociate = 1;
305 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
313 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
315 char *buf, size_t buflen)
317 char *pos, *end, tmp[30];
320 verbose = strcmp(params, "-VERBOSE") == 0;
323 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
324 pos += snprintf(pos, end - pos, "bssid=" MACSTR "\n",
325 MAC2STR(wpa_s->bssid));
326 if (wpa_s->current_ssid) {
327 pos += snprintf(pos, end - pos, "ssid=%s\n",
328 wpa_ssid_txt(wpa_s->current_ssid->ssid,
329 wpa_s->current_ssid->
333 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
335 pos += snprintf(pos, end - pos, "wpa_state=%s\n",
336 wpa_supplicant_state_txt(wpa_s->wpa_state));
339 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0)
340 pos += snprintf(pos, end - pos, "ip_address=%s\n", tmp);
342 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
343 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
344 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
350 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
358 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
363 struct wpa_ssid *ssid;
366 /* cmd: "<network id> <BSSID>" */
367 pos = strchr(cmd, ' ');
372 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
373 if (hwaddr_aton(pos, bssid)) {
374 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
378 ssid = wpa_config_get_network(wpa_s->conf, id);
380 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
385 memcpy(ssid->bssid, bssid, ETH_ALEN);
387 memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0;
394 static int wpa_supplicant_ctrl_iface_list_networks(
395 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
398 struct wpa_ssid *ssid;
402 pos += snprintf(pos, end - pos, "network id / ssid / bssid / flags\n");
404 ssid = wpa_s->conf->ssid;
406 pos += snprintf(pos, end - pos, "%d\t%s",
408 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
409 if (ssid->bssid_set) {
410 pos += snprintf(pos, end - pos, "\t" MACSTR,
411 MAC2STR(ssid->bssid));
413 pos += snprintf(pos, end - pos, "\tany");
415 pos += snprintf(pos, end - pos, "\t%s%s",
416 ssid == wpa_s->current_ssid ? "[CURRENT]" : "",
417 ssid->disabled ? "[DISABLED]" : "");
418 pos += snprintf(pos, end - pos, "\n");
427 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
430 pos += snprintf(pos, end - pos, "-");
431 if (cipher & WPA_CIPHER_NONE) {
432 pos += snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
435 if (cipher & WPA_CIPHER_WEP40) {
436 pos += snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
439 if (cipher & WPA_CIPHER_WEP104) {
440 pos += snprintf(pos, end - pos, "%sWEP104", first ? "" : "+");
443 if (cipher & WPA_CIPHER_TKIP) {
444 pos += snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
447 if (cipher & WPA_CIPHER_CCMP) {
448 pos += snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
455 static char * wpa_supplicant_ie_txt(struct wpa_supplicant *wpa_s,
456 char *pos, char *end, const char *proto,
457 const u8 *ie, size_t ie_len)
459 struct wpa_ie_data data;
462 pos += snprintf(pos, end - pos, "[%s-", proto);
464 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
465 pos += snprintf(pos, end - pos, "?]");
470 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
471 pos += snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
474 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
475 pos += snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
478 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
479 pos += snprintf(pos, end - pos, "%sNone", first ? "" : "+");
483 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
485 if (data.capabilities & WPA_CAPABILITY_PREAUTH)
486 pos += snprintf(pos, end - pos, "-preauth");
488 pos += snprintf(pos, end - pos, "]");
494 static int wpa_supplicant_ctrl_iface_scan_results(
495 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
498 struct wpa_scan_result *res;
501 if (wpa_s->scan_results == NULL &&
502 wpa_supplicant_get_scan_results(wpa_s) < 0)
507 pos += snprintf(pos, end - pos, "bssid / frequency / signal level / "
510 for (i = 0; i < wpa_s->num_scan_results; i++) {
511 res = &wpa_s->scan_results[i];
512 pos += snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
513 MAC2STR(res->bssid), res->freq, res->level);
514 if (res->wpa_ie_len) {
515 pos = wpa_supplicant_ie_txt(wpa_s, pos, end, "WPA",
519 if (res->rsn_ie_len) {
520 pos = wpa_supplicant_ie_txt(wpa_s, pos, end, "WPA2",
524 if (!res->wpa_ie_len && !res->rsn_ie_len &&
525 res->caps & IEEE80211_CAP_PRIVACY)
526 pos += snprintf(pos, end - pos, "[WEP]");
527 if (res->caps & IEEE80211_CAP_IBSS)
528 pos += snprintf(pos, end - pos, "[IBSS]");
530 pos += snprintf(pos, end - pos, "\t%s",
531 wpa_ssid_txt(res->ssid, res->ssid_len));
533 pos += snprintf(pos, end - pos, "\n");
540 static int wpa_supplicant_ctrl_iface_select_network(
541 struct wpa_supplicant *wpa_s, char *cmd)
544 struct wpa_ssid *ssid;
546 /* cmd: "<network id>" or "any" */
547 if (strcmp(cmd, "any") == 0) {
548 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
549 ssid = wpa_s->conf->ssid;
554 wpa_s->reassociate = 1;
555 wpa_supplicant_req_scan(wpa_s, 0, 0);
560 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
562 ssid = wpa_config_get_network(wpa_s->conf, id);
564 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
569 if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
570 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
572 /* Mark all other networks disabled and trigger reassociation */
573 ssid = wpa_s->conf->ssid;
575 ssid->disabled = id != ssid->id;
578 wpa_s->reassociate = 1;
579 wpa_supplicant_req_scan(wpa_s, 0, 0);
585 static int wpa_supplicant_ctrl_iface_enable_network(
586 struct wpa_supplicant *wpa_s, char *cmd)
589 struct wpa_ssid *ssid;
591 /* cmd: "<network id>" */
593 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
595 ssid = wpa_config_get_network(wpa_s->conf, id);
597 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
602 if (wpa_s->current_ssid == NULL && ssid->disabled) {
604 * Try to reassociate since there is no current configuration
605 * and a new network was made available. */
606 wpa_s->reassociate = 1;
607 wpa_supplicant_req_scan(wpa_s, 0, 0);
615 static int wpa_supplicant_ctrl_iface_disable_network(
616 struct wpa_supplicant *wpa_s, char *cmd)
619 struct wpa_ssid *ssid;
621 /* cmd: "<network id>" */
623 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
625 ssid = wpa_config_get_network(wpa_s->conf, id);
627 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
632 if (ssid == wpa_s->current_ssid)
633 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
640 static int wpa_supplicant_ctrl_iface_add_network(
641 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
643 struct wpa_ssid *ssid;
645 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
647 ssid = wpa_config_add_network(wpa_s->conf);
651 wpa_config_set_network_defaults(ssid);
653 return snprintf(buf, buflen, "%d\n", ssid->id);
657 static int wpa_supplicant_ctrl_iface_remove_network(
658 struct wpa_supplicant *wpa_s, char *cmd)
661 struct wpa_ssid *ssid;
663 /* cmd: "<network id>" */
665 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
667 ssid = wpa_config_get_network(wpa_s->conf, id);
669 wpa_config_remove_network(wpa_s->conf, id) < 0) {
670 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
675 if (ssid == wpa_s->current_ssid)
676 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
682 static int wpa_supplicant_ctrl_iface_set_network(
683 struct wpa_supplicant *wpa_s, char *cmd)
686 struct wpa_ssid *ssid;
689 /* cmd: "<network id> <variable name> <value>" */
690 name = strchr(cmd, ' ');
695 value = strchr(name, ' ');
701 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
703 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
704 (u8 *) value, strlen(value));
706 ssid = wpa_config_get_network(wpa_s->conf, id);
708 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
713 if (wpa_config_set(ssid, name, value, 0) < 0) {
714 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
715 "variable '%s'", name);
719 if ((strcmp(name, "psk") == 0 && value[0] == '"' && ssid->ssid_len) ||
720 (strcmp(name, "ssid") == 0 && ssid->passphrase))
721 wpa_config_update_psk(ssid);
727 static int wpa_supplicant_ctrl_iface_get_network(
728 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
731 struct wpa_ssid *ssid;
734 /* cmd: "<network id> <variable name>" */
735 name = strchr(cmd, ' ');
741 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
744 ssid = wpa_config_get_network(wpa_s->conf, id);
746 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
751 value = wpa_config_get(ssid, name);
753 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
754 "variable '%s'", name);
758 snprintf(buf, buflen, "%s", value);
766 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
770 if (!wpa_s->conf->update_config) {
771 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
772 "to update configuration (update_config=0)");
776 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
778 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
779 "update configuration");
781 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
789 static int wpa_supplicant_ctrl_iface_get_capability(
790 struct wpa_supplicant *wpa_s, const char *field, char *buf,
793 struct wpa_driver_capa capa;
797 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'", field);
799 if (strcmp(field, "eap") == 0) {
800 return eap_get_names(buf, buflen);
803 res = wpa_drv_get_capa(wpa_s, &capa);
808 if (strcmp(field, "pairwise") == 0) {
810 return snprintf(buf, buflen, "CCMP TKIP NONE");
812 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
813 pos += snprintf(pos, end - pos, "%sCCMP",
818 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
819 pos += snprintf(pos, end - pos, "%sTKIP",
824 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
825 pos += snprintf(pos, end - pos, "%sNONE",
833 if (strcmp(field, "group") == 0) {
835 return snprintf(buf, buflen, "CCMP TKIP WEP104 WEP40");
837 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
838 pos += snprintf(pos, end - pos, "%sCCMP",
843 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
844 pos += snprintf(pos, end - pos, "%sTKIP",
849 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
850 pos += snprintf(pos, end - pos, "%sWEP104",
855 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
856 pos += snprintf(pos, end - pos, "%sWEP40",
864 if (strcmp(field, "key_mgmt") == 0) {
866 return snprintf(buf, buflen, "WPA-PSK WPA-EAP "
867 "IEEE8021X WPA-NONE NONE");
870 pos += snprintf(pos, end - pos, "NONE IEEE8021X");
872 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
873 WPA_DRIVER_CAPA_KEY_MGMT_WPA2))
874 pos += snprintf(pos, end - pos, " WPA-EAP");
876 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
877 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK))
878 pos += snprintf(pos, end - pos, " WPA-PSK");
880 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE)
881 pos += snprintf(pos, end - pos, " WPA-NONE");
886 if (strcmp(field, "proto") == 0) {
888 return snprintf(buf, buflen, "RSN WPA");
890 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
891 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
892 pos += snprintf(pos, end - pos, "%sRSN",
897 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
898 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
899 pos += snprintf(pos, end - pos, "%sWPA",
907 if (strcmp(field, "auth_alg") == 0) {
909 return snprintf(buf, buflen, "OPEN SHARED LEAP");
911 if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
912 pos += snprintf(pos, end - pos, "%sOPEN",
917 if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
918 pos += snprintf(pos, end - pos, "%sSHARED",
923 if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
924 pos += snprintf(pos, end - pos, "%sLEAP",
932 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
939 static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
942 struct wpa_supplicant *wpa_s = eloop_ctx;
945 CTRL_IFACE_SOCK from;
946 socklen_t fromlen = sizeof(from);
948 const int reply_size = 2048;
950 int new_attached = 0, ctrl_rsp = 0;
952 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
953 (struct sockaddr *) &from, &fromlen);
955 perror("recvfrom(ctrl_iface)");
959 if (strncmp(buf, WPA_CTRL_RSP, strlen(WPA_CTRL_RSP)) == 0 ||
960 strncmp(buf, "SET_NETWORK ", 12) == 0) {
961 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
964 wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface", (u8 *) buf, res);
967 reply = malloc(reply_size);
969 sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
974 memcpy(reply, "OK\n", 3);
977 if (strcmp(buf, "PING") == 0) {
978 memcpy(reply, "PONG\n", 5);
980 } else if (strcmp(buf, "MIB") == 0) {
981 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
982 if (reply_len >= 0) {
983 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
984 reply_size - reply_len);
990 } else if (strncmp(buf, "STATUS", 6) == 0) {
991 reply_len = wpa_supplicant_ctrl_iface_status(
992 wpa_s, buf + 6, reply, reply_size);
993 } else if (strcmp(buf, "PMKSA") == 0) {
994 reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size);
995 } else if (strncmp(buf, "SET ", 4) == 0) {
996 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
998 } else if (strcmp(buf, "LOGON") == 0) {
999 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
1000 } else if (strcmp(buf, "LOGOFF") == 0) {
1001 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
1002 } else if (strcmp(buf, "REASSOCIATE") == 0) {
1003 wpa_s->disconnected = 0;
1004 wpa_s->reassociate = 1;
1005 wpa_supplicant_req_scan(wpa_s, 0, 0);
1006 } else if (strncmp(buf, "PREAUTH ", 8) == 0) {
1007 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
1009 } else if (strcmp(buf, "ATTACH") == 0) {
1010 if (wpa_supplicant_ctrl_iface_attach(wpa_s, &from, fromlen))
1014 } else if (strcmp(buf, "DETACH") == 0) {
1015 if (wpa_supplicant_ctrl_iface_detach(wpa_s, &from, fromlen))
1017 } else if (strncmp(buf, "LEVEL ", 6) == 0) {
1018 if (wpa_supplicant_ctrl_iface_level(wpa_s, &from, fromlen,
1021 } else if (strncmp(buf, WPA_CTRL_RSP, strlen(WPA_CTRL_RSP)) == 0) {
1022 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1023 wpa_s, buf + strlen(WPA_CTRL_RSP)))
1027 } else if (strcmp(buf, "RECONFIGURE") == 0) {
1028 if (wpa_supplicant_reload_configuration(wpa_s))
1030 } else if (strcmp(buf, "TERMINATE") == 0) {
1032 } else if (strncmp(buf, "BSSID ", 6) == 0) {
1033 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
1035 } else if (strcmp(buf, "LIST_NETWORKS") == 0) {
1036 reply_len = wpa_supplicant_ctrl_iface_list_networks(
1037 wpa_s, reply, reply_size);
1038 } else if (strcmp(buf, "DISCONNECT") == 0) {
1039 wpa_s->disconnected = 1;
1040 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
1041 } else if (strcmp(buf, "SCAN") == 0) {
1042 wpa_s->scan_req = 2;
1043 wpa_supplicant_req_scan(wpa_s, 0, 0);
1044 } else if (strcmp(buf, "SCAN_RESULTS") == 0) {
1045 reply_len = wpa_supplicant_ctrl_iface_scan_results(
1046 wpa_s, reply, reply_size);
1047 } else if (strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
1048 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
1050 } else if (strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
1051 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
1053 } else if (strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
1054 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
1056 } else if (strcmp(buf, "ADD_NETWORK") == 0) {
1057 reply_len = wpa_supplicant_ctrl_iface_add_network(
1058 wpa_s, reply, reply_size);
1059 } else if (strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
1060 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
1062 } else if (strncmp(buf, "SET_NETWORK ", 12) == 0) {
1063 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
1065 } else if (strncmp(buf, "GET_NETWORK ", 12) == 0) {
1066 reply_len = wpa_supplicant_ctrl_iface_get_network(
1067 wpa_s, buf + 12, reply, reply_size);
1068 } else if (strcmp(buf, "SAVE_CONFIG") == 0) {
1069 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
1071 } else if (strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
1072 reply_len = wpa_supplicant_ctrl_iface_get_capability(
1073 wpa_s, buf + 15, reply, reply_size);
1075 memcpy(reply, "UNKNOWN COMMAND\n", 16);
1079 if (reply_len < 0) {
1080 memcpy(reply, "FAIL\n", 5);
1083 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1087 eapol_sm_notify_ctrl_attached(wpa_s->eapol);
1089 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1093 #ifndef CONFIG_CTRL_IFACE_UDP
1094 static char * wpa_supplicant_ctrl_iface_path(struct wpa_supplicant *wpa_s)
1099 if (wpa_s->conf->ctrl_interface == NULL)
1102 len = strlen(wpa_s->conf->ctrl_interface) + strlen(wpa_s->ifname) + 2;
1107 snprintf(buf, len, "%s/%s",
1108 wpa_s->conf->ctrl_interface, wpa_s->ifname);
1111 /* Windows/WinPcap uses interface names that are not suitable
1112 * as a file name - convert invalid chars to underscores */
1120 #endif /* __CYGWIN__ */
1123 #endif /* CONFIG_CTRL_IFACE_UDP */
1127 * wpa_supplicant_ctrl_iface_init - Initialize control interface
1128 * @wpa_s: Pointer to wpa_supplicant data
1129 * Returns: 0 on success, -1 on failure
1131 * Initialize the control interface and start receiving commands from external
1134 int wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
1136 CTRL_IFACE_SOCK addr;
1138 #ifndef CONFIG_CTRL_IFACE_UDP
1140 #endif /* CONFIG_CTRL_IFACE_UDP */
1142 wpa_s->ctrl_sock = -1;
1144 if (wpa_s->conf->ctrl_interface == NULL)
1147 #ifdef CONFIG_CTRL_IFACE_UDP
1148 s = socket(PF_INET, SOCK_DGRAM, 0);
1150 perror("socket(PF_INET)");
1154 memset(&addr, 0, sizeof(addr));
1155 addr.sin_family = AF_INET;
1156 addr.sin_addr.s_addr = htonl((127 << 24) | 1);
1157 addr.sin_port = htons(WPA_CTRL_IFACE_PORT);
1158 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1159 perror("bind(AF_INET)");
1162 #else /* CONFIG_CTRL_IFACE_UDP */
1163 if (mkdir(wpa_s->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
1164 if (errno == EEXIST) {
1165 wpa_printf(MSG_DEBUG, "Using existing control "
1166 "interface directory.");
1168 perror("mkdir[ctrl_interface]");
1173 if (wpa_s->conf->ctrl_interface_gid_set &&
1174 chown(wpa_s->conf->ctrl_interface, 0,
1175 wpa_s->conf->ctrl_interface_gid) < 0) {
1176 perror("chown[ctrl_interface]");
1180 if (strlen(wpa_s->conf->ctrl_interface) + 1 + strlen(wpa_s->ifname) >=
1181 sizeof(addr.sun_path))
1184 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1186 perror("socket(PF_UNIX)");
1190 memset(&addr, 0, sizeof(addr));
1191 addr.sun_family = AF_UNIX;
1192 fname = wpa_supplicant_ctrl_iface_path(wpa_s);
1195 strncpy(addr.sun_path, fname, sizeof(addr.sun_path));
1196 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1197 perror("bind(PF_UNIX)");
1198 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1199 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1200 " allow connections - assuming it was left"
1201 "over from forced program termination");
1202 if (unlink(fname) < 0) {
1203 perror("unlink[ctrl_iface]");
1204 wpa_printf(MSG_ERROR, "Could not unlink "
1205 "existing ctrl_iface socket '%s'",
1209 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1211 perror("bind(PF_UNIX)");
1214 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1215 "ctrl_iface socket '%s'", fname);
1217 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1218 "be in use - cannot override it");
1219 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1220 "not used anymore", fname);
1227 if (wpa_s->conf->ctrl_interface_gid_set &&
1228 chown(fname, 0, wpa_s->conf->ctrl_interface_gid) < 0) {
1229 perror("chown[ctrl_interface/ifname]");
1233 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
1234 perror("chmod[ctrl_interface/ifname]");
1238 #endif /* CONFIG_CTRL_IFACE_UDP */
1240 wpa_s->ctrl_sock = s;
1241 eloop_register_read_sock(s, wpa_supplicant_ctrl_iface_receive, wpa_s,
1249 #ifndef CONFIG_CTRL_IFACE_UDP
1254 #endif /* CONFIG_CTRL_IFACE_UDP */
1260 * wpa_supplicant_ctrl_iface_deinit - Deinitialize control interface
1261 * @wpa_s: Pointer to wpa_supplicant data
1263 * Deinitialize the control interface that was initialized with
1264 * wpa_supplicant_ctrl_iface_init().
1266 void wpa_supplicant_ctrl_iface_deinit(struct wpa_supplicant *wpa_s)
1268 struct wpa_ctrl_dst *dst, *prev;
1270 if (wpa_s->ctrl_sock > -1) {
1271 #ifndef CONFIG_CTRL_IFACE_UDP
1273 #endif /* CONFIG_CTRL_IFACE_UDP */
1274 eloop_unregister_read_sock(wpa_s->ctrl_sock);
1275 if (wpa_s->ctrl_dst) {
1277 * Wait a second before closing the control socket if
1278 * there are any attached monitors in order to allow
1279 * them to receive any pending messages.
1281 wpa_printf(MSG_DEBUG, "CTRL_IFACE wait for attached "
1282 "monitors to receive messages");
1285 close(wpa_s->ctrl_sock);
1286 wpa_s->ctrl_sock = -1;
1287 #ifndef CONFIG_CTRL_IFACE_UDP
1288 fname = wpa_supplicant_ctrl_iface_path(wpa_s);
1293 if (rmdir(wpa_s->conf->ctrl_interface) < 0) {
1294 if (errno == ENOTEMPTY) {
1295 wpa_printf(MSG_DEBUG, "Control interface "
1296 "directory not empty - leaving it "
1299 perror("rmdir[ctrl_interface]");
1302 #endif /* CONFIG_CTRL_IFACE_UDP */
1305 dst = wpa_s->ctrl_dst;
1315 * wpa_supplicant_ctrl_iface_send - Send a control interface packet to monitors
1316 * @wpa_s: Pointer to wpa_supplicant data
1317 * @level: Priority level of the message
1318 * @buf: Message data
1319 * @len: Message length
1321 * Send a packet to all monitor programs attached to the control interface.
1323 void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant *wpa_s, int level,
1324 char *buf, size_t len)
1326 struct wpa_ctrl_dst *dst, *next;
1329 #ifdef CONFIG_CTRL_IFACE_UDP
1333 dst = wpa_s->ctrl_dst;
1334 if (wpa_s->ctrl_sock < 0 || dst == NULL)
1337 snprintf(levelstr, sizeof(levelstr), "<%d>", level);
1339 llen = strlen(levelstr);
1340 sbuf = malloc(llen + len);
1344 memcpy(sbuf, levelstr, llen);
1345 memcpy(sbuf + llen, buf, len);
1350 if (level >= dst->debug_level) {
1351 wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor send %s:%d",
1352 inet_ntoa(dst->addr.sin_addr),
1353 ntohs(dst->addr.sin_port));
1354 if (sendto(wpa_s->ctrl_sock, sbuf, llen + len, 0,
1355 (struct sockaddr *) &dst->addr,
1356 sizeof(dst->addr)) < 0) {
1357 perror("sendto(CTRL_IFACE monitor)");
1359 if (dst->errors > 10) {
1360 wpa_supplicant_ctrl_iface_detach(
1371 #else /* CONFIG_CTRL_IFACE_UDP */
1375 dst = wpa_s->ctrl_dst;
1376 if (wpa_s->ctrl_sock < 0 || dst == NULL)
1379 snprintf(levelstr, sizeof(levelstr), "<%d>", level);
1380 io[0].iov_base = levelstr;
1381 io[0].iov_len = strlen(levelstr);
1382 io[1].iov_base = buf;
1383 io[1].iov_len = len;
1384 memset(&msg, 0, sizeof(msg));
1391 if (level >= dst->debug_level) {
1392 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
1393 (u8 *) dst->addr.sun_path, dst->addrlen -
1394 sizeof(dst->addr.sun_family));
1395 msg.msg_name = &dst->addr;
1396 msg.msg_namelen = dst->addrlen;
1397 if (sendmsg(wpa_s->ctrl_sock, &msg, 0) < 0) {
1398 perror("sendmsg(CTRL_IFACE monitor)");
1400 if (dst->errors > 10) {
1401 wpa_supplicant_ctrl_iface_detach(
1411 #endif /* CONFIG_CTRL_IFACE_UDP */
1416 * wpa_supplicant_ctrl_iface_wait - Wait for ctrl_iface monitor
1417 * @wpa_s: Pointer to wpa_supplicant data
1419 * Wait until the first message from an external program using the control
1420 * interface is received. This function can be used to delay normal startup
1421 * processing to allow control interface programs to attach with
1422 * %wpa_supplicant before normal operations are started.
1424 void wpa_supplicant_ctrl_iface_wait(struct wpa_supplicant *wpa_s)
1428 if (wpa_s->ctrl_sock < 0)
1431 wpa_printf(MSG_DEBUG, "CTRL_IFACE - %s - wait for monitor",
1435 FD_SET(wpa_s->ctrl_sock, &rfds);
1436 select(wpa_s->ctrl_sock + 1, &rfds, NULL, NULL, NULL);
1440 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
1443 struct wpa_interface iface;
1447 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1449 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
1451 memset(&iface, 0, sizeof(iface));
1454 iface.ifname = pos = cmd;
1455 pos = strchr(pos, '\t');
1458 if (iface.ifname[0] == '\0')
1463 iface.confname = pos;
1464 pos = strchr(pos, '\t');
1467 if (iface.confname[0] == '\0')
1468 iface.confname = NULL;
1473 pos = strchr(pos, '\t');
1476 if (iface.driver[0] == '\0')
1477 iface.driver = NULL;
1481 iface.ctrl_interface = pos;
1482 pos = strchr(pos, '\t');
1485 if (iface.ctrl_interface[0] == '\0')
1486 iface.ctrl_interface = NULL;
1490 iface.driver_param = pos;
1491 pos = strchr(pos, '\t');
1494 if (iface.driver_param[0] == '\0')
1495 iface.driver_param = NULL;
1500 if (wpa_supplicant_get_iface(global, iface.ifname))
1503 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
1507 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
1510 struct wpa_supplicant *wpa_s;
1512 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
1514 wpa_s = wpa_supplicant_get_iface(global, cmd);
1517 return wpa_supplicant_remove_iface(global, wpa_s);
1521 static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
1524 struct wpa_global *global = eloop_ctx;
1527 CTRL_IFACE_SOCK from;
1528 socklen_t fromlen = sizeof(from);
1530 const int reply_size = 2048;
1533 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
1534 (struct sockaddr *) &from, &fromlen);
1536 perror("recvfrom(ctrl_iface)");
1540 wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface", (u8 *) buf, res);
1542 reply = malloc(reply_size);
1543 if (reply == NULL) {
1544 sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
1549 memcpy(reply, "OK\n", 3);
1552 if (strcmp(buf, "PING") == 0) {
1553 memcpy(reply, "PONG\n", 5);
1555 } else if (strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
1556 if (wpa_supplicant_global_iface_add(global, buf + 14))
1558 } else if (strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
1559 if (wpa_supplicant_global_iface_remove(global, buf + 17))
1562 memcpy(reply, "UNKNOWN COMMAND\n", 16);
1566 if (reply_len < 0) {
1567 memcpy(reply, "FAIL\n", 5);
1570 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1576 * wpa_supplicant_global_ctrl_iface_init - Initialize global control interface
1577 * @global: Pointer to global data from wpa_supplicant_init()
1578 * Returns: 0 on success, -1 on failure
1580 * Initialize the global control interface and start receiving commands from
1581 * external programs.
1583 int wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
1585 CTRL_IFACE_SOCK addr;
1588 global->ctrl_sock = -1;
1590 if (global->params.ctrl_interface == NULL)
1593 wpa_printf(MSG_DEBUG, "Global control interface '%s'",
1594 global->params.ctrl_interface);
1596 #ifdef CONFIG_CTRL_IFACE_UDP
1597 s = socket(PF_INET, SOCK_DGRAM, 0);
1599 perror("socket(PF_INET)");
1603 memset(&addr, 0, sizeof(addr));
1604 addr.sin_family = AF_INET;
1605 addr.sin_addr.s_addr = htonl((127 << 24) | 1);
1606 addr.sin_port = htons(WPA_GLOBAL_CTRL_IFACE_PORT);
1607 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1608 perror("bind(AF_INET)");
1611 #else /* CONFIG_CTRL_IFACE_UDP */
1612 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1614 perror("socket(PF_UNIX)");
1618 memset(&addr, 0, sizeof(addr));
1619 addr.sun_family = AF_UNIX;
1620 strncpy(addr.sun_path, global->params.ctrl_interface,
1621 sizeof(addr.sun_path));
1622 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1623 perror("bind(PF_UNIX)");
1624 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1625 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1626 " allow connections - assuming it was left"
1627 "over from forced program termination");
1628 if (unlink(global->params.ctrl_interface) < 0) {
1629 perror("unlink[ctrl_iface]");
1630 wpa_printf(MSG_ERROR, "Could not unlink "
1631 "existing ctrl_iface socket '%s'",
1632 global->params.ctrl_interface);
1635 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1637 perror("bind(PF_UNIX)");
1640 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1641 "ctrl_iface socket '%s'",
1642 global->params.ctrl_interface);
1644 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1645 "be in use - cannot override it");
1646 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1648 global->params.ctrl_interface);
1652 #endif /* CONFIG_CTRL_IFACE_UDP */
1654 global->ctrl_sock = s;
1655 eloop_register_read_sock(s, wpa_supplicant_global_ctrl_iface_receive,
1668 * wpa_supplicant_global_ctrl_iface_deinit - Deinitialize global ctrl interface
1669 * @global: Pointer to global data from wpa_supplicant_init()
1671 * Deinitialize the global control interface that was initialized with
1672 * wpa_supplicant_global_ctrl_iface_init().
1674 void wpa_supplicant_global_ctrl_iface_deinit(struct wpa_global *global)
1676 if (global->ctrl_sock < 0)
1679 eloop_unregister_read_sock(global->ctrl_sock);
1680 close(global->ctrl_sock);
1681 global->ctrl_sock = -1;
1683 #ifndef CONFIG_CTRL_IFACE_UDP
1684 if (global->params.ctrl_interface)
1685 unlink(global->params.ctrl_interface);
1686 #endif /* CONFIG_CTRL_IFACE_UDP */