2 * hostapd / UNIX domain socket -based control interface
3 * Copyright (c) 2004-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #ifndef CONFIG_NATIVE_WINDOWS
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "common/version.h"
20 #include "common/ieee802_11_defs.h"
21 #include "drivers/driver.h"
22 #include "radius/radius_client.h"
23 #include "ap/hostapd.h"
24 #include "ap/ap_config.h"
25 #include "ap/ieee802_1x.h"
26 #include "ap/wpa_auth.h"
27 #include "ap/ieee802_11.h"
28 #include "ap/sta_info.h"
29 #include "ap/wps_hostapd.h"
30 #include "ap/ctrl_iface_ap.h"
31 #include "ap/ap_drv_ops.h"
32 #include "ap/wpa_auth.h"
33 #include "wps/wps_defs.h"
35 #include "config_file.h"
36 #include "ctrl_iface.h"
40 struct wpa_ctrl_dst *next;
41 struct sockaddr_un addr;
48 static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
49 const char *buf, size_t len);
52 static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
53 struct sockaddr_un *from,
56 struct wpa_ctrl_dst *dst;
58 dst = os_zalloc(sizeof(*dst));
61 os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
62 dst->addrlen = fromlen;
63 dst->debug_level = MSG_INFO;
64 dst->next = hapd->ctrl_dst;
66 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached",
67 (u8 *) from->sun_path,
68 fromlen - offsetof(struct sockaddr_un, sun_path));
73 static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
74 struct sockaddr_un *from,
77 struct wpa_ctrl_dst *dst, *prev = NULL;
81 if (fromlen == dst->addrlen &&
82 os_memcmp(from->sun_path, dst->addr.sun_path,
83 fromlen - offsetof(struct sockaddr_un, sun_path))
85 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached",
86 (u8 *) from->sun_path,
88 offsetof(struct sockaddr_un, sun_path));
90 hapd->ctrl_dst = dst->next;
92 prev->next = dst->next;
103 static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
104 struct sockaddr_un *from,
108 struct wpa_ctrl_dst *dst;
110 wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
112 dst = hapd->ctrl_dst;
114 if (fromlen == dst->addrlen &&
115 os_memcmp(from->sun_path, dst->addr.sun_path,
116 fromlen - offsetof(struct sockaddr_un, sun_path))
118 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE changed monitor "
119 "level", (u8 *) from->sun_path, fromlen -
120 offsetof(struct sockaddr_un, sun_path));
121 dst->debug_level = atoi(level);
131 static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
135 struct sta_info *sta;
137 wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
139 if (hwaddr_aton(txtaddr, addr))
142 sta = ap_get_sta(hapd, addr);
146 wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
147 "notification", MAC2STR(addr));
148 sta = ap_sta_add(hapd, addr);
152 hostapd_new_assoc_sta(hapd, sta, 0);
157 #ifdef CONFIG_IEEE80211W
159 static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
163 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
165 wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
167 if (hwaddr_aton(txtaddr, addr) ||
168 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
171 ieee802_11_send_sa_query_req(hapd, addr, trans_id);
175 #endif /* NEED_AP_MLME */
176 #endif /* CONFIG_IEEE80211W */
180 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
182 char *pin = os_strchr(txt, ' ');
185 u8 addr_buf[ETH_ALEN], *addr = NULL;
192 timeout_txt = os_strchr(pin, ' ');
194 *timeout_txt++ = '\0';
195 timeout = atoi(timeout_txt);
196 pos = os_strchr(timeout_txt, ' ');
199 if (hwaddr_aton(pos, addr_buf) == 0)
205 return hostapd_wps_add_pin(hapd, addr, txt, pin, timeout);
209 static int hostapd_ctrl_iface_wps_check_pin(
210 struct hostapd_data *hapd, char *cmd, char *buf, size_t buflen)
217 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
218 (u8 *) cmd, os_strlen(cmd));
219 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
220 if (*pos < '0' || *pos > '9')
224 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
228 if (len != 4 && len != 8) {
229 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
235 unsigned int pin_val;
237 if (!wps_pin_valid(pin_val)) {
238 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
239 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
240 if (ret < 0 || (size_t) ret >= buflen)
246 ret = os_snprintf(buf, buflen, "%s", pin);
247 if (ret < 0 || (size_t) ret >= buflen)
254 #ifdef CONFIG_WPS_NFC
255 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
262 len = os_strlen(pos);
267 buf = wpabuf_alloc(len);
270 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
275 ret = hostapd_wps_nfc_tag_read(hapd, buf);
282 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
283 char *cmd, char *reply,
290 if (os_strcmp(cmd, "WPS") == 0)
292 else if (os_strcmp(cmd, "NDEF") == 0)
297 buf = hostapd_wps_nfc_config_token(hapd, ndef);
301 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
312 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data *hapd,
313 char *reply, size_t max_len,
319 buf = hostapd_wps_nfc_token_gen(hapd, ndef);
323 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
334 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data *hapd,
335 char *cmd, char *reply,
338 if (os_strcmp(cmd, "WPS") == 0)
339 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
342 if (os_strcmp(cmd, "NDEF") == 0)
343 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
346 if (os_strcmp(cmd, "enable") == 0)
347 return hostapd_wps_nfc_token_enable(hapd);
349 if (os_strcmp(cmd, "disable") == 0) {
350 hostapd_wps_nfc_token_disable(hapd);
358 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data *hapd,
359 char *cmd, char *reply,
367 pos = os_strchr(cmd, ' ');
372 if (os_strcmp(cmd, "WPS") == 0)
374 else if (os_strcmp(cmd, "NDEF") == 0)
379 if (os_strcmp(pos, "WPS-CR") == 0)
380 buf = hostapd_wps_nfc_hs_cr(hapd, ndef);
386 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
397 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data *hapd,
401 * Since NFC connection handover provided full WPS Credential, there is
402 * no need for additional operations within hostapd. Just report this in
405 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported: %s", cmd);
409 #endif /* CONFIG_WPS_NFC */
412 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
413 char *buf, size_t buflen)
419 pos = os_strchr(txt, ' ');
423 if (os_strcmp(txt, "disable") == 0) {
424 hostapd_wps_ap_pin_disable(hapd);
425 return os_snprintf(buf, buflen, "OK\n");
428 if (os_strcmp(txt, "random") == 0) {
431 pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
434 return os_snprintf(buf, buflen, "%s", pin_txt);
437 if (os_strcmp(txt, "get") == 0) {
438 pin_txt = hostapd_wps_ap_pin_get(hapd);
441 return os_snprintf(buf, buflen, "%s", pin_txt);
444 if (os_strcmp(txt, "set") == 0) {
449 pos = os_strchr(pos, ' ');
454 if (os_strlen(pin) > buflen)
456 if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
458 return os_snprintf(buf, buflen, "%s", pin);
465 static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
468 char *ssid, *auth, *encr = NULL, *key = NULL;
471 pos = os_strchr(txt, ' ');
477 pos = os_strchr(pos, ' ');
481 pos = os_strchr(pos, ' ');
488 return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
492 static const char * pbc_status_str(enum pbc_status status)
495 case WPS_PBC_STATUS_DISABLE:
497 case WPS_PBC_STATUS_ACTIVE:
499 case WPS_PBC_STATUS_TIMEOUT:
501 case WPS_PBC_STATUS_OVERLAP:
509 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
510 char *buf, size_t buflen)
518 ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
519 pbc_status_str(hapd->wps_stats.pbc_status));
521 if (ret < 0 || ret >= end - pos)
525 ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
526 (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
528 (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
529 "Failed" : "None")));
531 if (ret < 0 || ret >= end - pos)
535 /* If status == Failure - Add possible Reasons */
536 if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
537 hapd->wps_stats.failure_reason > 0) {
538 ret = os_snprintf(pos, end - pos,
539 "Failure Reason: %s\n",
540 wps_ei_str(hapd->wps_stats.failure_reason));
542 if (ret < 0 || ret >= end - pos)
547 if (hapd->wps_stats.status) {
548 ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
549 MAC2STR(hapd->wps_stats.peer_addr));
551 if (ret < 0 || ret >= end - pos)
559 #endif /* CONFIG_WPS */
562 #ifdef CONFIG_INTERWORKING
564 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data *hapd,
567 u8 qos_map_set[16 + 2 * 21], count = 0;
568 const char *pos = cmd;
572 if (count == sizeof(qos_map_set)) {
573 wpa_printf(MSG_ERROR, "Too many qos_map_set parameters");
578 if (val < 0 || val > 255) {
579 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
583 qos_map_set[count++] = val;
584 pos = os_strchr(pos, ',');
590 if (count < 16 || count & 1) {
591 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
595 ret = hostapd_drv_set_qos_map(hapd, qos_map_set, count);
597 wpa_printf(MSG_INFO, "Failed to set QoS Map Set");
601 os_memcpy(hapd->conf->qos_map_set, qos_map_set, count);
602 hapd->conf->qos_map_set_len = count;
608 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
612 struct sta_info *sta;
614 u8 *qos_map_set = hapd->conf->qos_map_set;
615 u8 qos_map_set_len = hapd->conf->qos_map_set_len;
618 if (!qos_map_set_len) {
619 wpa_printf(MSG_INFO, "QoS Map Set is not set");
623 if (hwaddr_aton(cmd, addr))
626 sta = ap_get_sta(hapd, addr);
628 wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
629 "for QoS Map Configuration message",
634 if (!sta->qos_map_enabled) {
635 wpa_printf(MSG_DEBUG, "Station " MACSTR " did not indicate "
636 "support for QoS Map", MAC2STR(addr));
640 buf = wpabuf_alloc(2 + 2 + qos_map_set_len);
644 wpabuf_put_u8(buf, WLAN_ACTION_QOS);
645 wpabuf_put_u8(buf, QOS_QOS_MAP_CONFIG);
647 /* QoS Map Set Element */
648 wpabuf_put_u8(buf, WLAN_EID_QOS_MAP_SET);
649 wpabuf_put_u8(buf, qos_map_set_len);
650 wpabuf_put_data(buf, qos_map_set, qos_map_set_len);
652 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
653 wpabuf_head(buf), wpabuf_len(buf));
659 #endif /* CONFIG_INTERWORKING */
664 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data *hapd,
669 struct ieee80211_mgmt *mgmt;
672 if (hwaddr_aton(cmd, addr))
676 disassoc_timer = atoi(cmd + 17);
678 os_memset(buf, 0, sizeof(buf));
679 mgmt = (struct ieee80211_mgmt *) buf;
680 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
681 WLAN_FC_STYPE_ACTION);
682 os_memcpy(mgmt->da, addr, ETH_ALEN);
683 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
684 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
685 mgmt->u.action.category = WLAN_ACTION_WNM;
686 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
687 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
688 mgmt->u.action.u.bss_tm_req.req_mode =
689 WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
690 mgmt->u.action.u.bss_tm_req.disassoc_timer =
691 host_to_le16(disassoc_timer);
692 mgmt->u.action.u.bss_tm_req.validity_interval = 0;
694 pos = mgmt->u.action.u.bss_tm_req.variable;
696 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
697 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
698 "Management Request frame");
706 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
710 const char *url, *timerstr;
712 struct ieee80211_mgmt *mgmt;
716 if (hwaddr_aton(cmd, addr))
720 if (*timerstr != ' ')
723 disassoc_timer = atoi(timerstr);
724 if (disassoc_timer < 0 || disassoc_timer > 65535)
727 url = os_strchr(timerstr, ' ');
731 url_len = os_strlen(url);
735 os_memset(buf, 0, sizeof(buf));
736 mgmt = (struct ieee80211_mgmt *) buf;
737 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
738 WLAN_FC_STYPE_ACTION);
739 os_memcpy(mgmt->da, addr, ETH_ALEN);
740 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
741 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
742 mgmt->u.action.category = WLAN_ACTION_WNM;
743 mgmt->u.action.u.bss_tm_req.action = WNM_BSS_TRANS_MGMT_REQ;
744 mgmt->u.action.u.bss_tm_req.dialog_token = 1;
745 mgmt->u.action.u.bss_tm_req.req_mode =
746 WNM_BSS_TM_REQ_DISASSOC_IMMINENT |
747 WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
748 mgmt->u.action.u.bss_tm_req.disassoc_timer =
749 host_to_le16(disassoc_timer);
750 mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
752 pos = mgmt->u.action.u.bss_tm_req.variable;
754 /* Session Information URL */
756 os_memcpy(pos, url, url_len);
759 if (hostapd_drv_send_mlme(hapd, buf, pos - buf, 0) < 0) {
760 wpa_printf(MSG_DEBUG, "Failed to send BSS Transition "
761 "Management Request frame");
765 /* send disassociation frame after time-out */
766 if (disassoc_timer) {
767 struct sta_info *sta;
768 int timeout, beacon_int;
771 * Prevent STA from reconnecting using cached PMKSA to force
772 * full authentication with the authentication server (which may
773 * decide to reject the connection),
775 wpa_auth_pmksa_remove(hapd->wpa_auth, addr);
777 sta = ap_get_sta(hapd, addr);
779 wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
780 "for ESS disassociation imminent message",
785 beacon_int = hapd->iconf->beacon_int;
787 beacon_int = 100; /* best guess */
788 /* Calculate timeout in ms based on beacon_int in TU */
789 timeout = disassoc_timer * beacon_int * 128 / 125;
790 wpa_printf(MSG_DEBUG, "Disassociation timer for " MACSTR
791 " set to %d ms", MAC2STR(addr), timeout);
793 sta->timeout_next = STA_DISASSOC_FROM_CLI;
794 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
795 eloop_register_timeout(timeout / 1000,
796 timeout % 1000 * 1000,
797 ap_handle_timer, hapd, sta);
803 #endif /* CONFIG_WNM */
806 static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
807 char *buf, size_t buflen)
815 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
817 MAC2STR(hapd->own_addr),
818 wpa_ssid_txt(hapd->conf->ssid.ssid,
819 hapd->conf->ssid.ssid_len));
820 if (ret < 0 || ret >= end - pos)
825 ret = os_snprintf(pos, end - pos, "wps_state=%s\n",
826 hapd->conf->wps_state == 0 ? "disabled" :
827 (hapd->conf->wps_state == 1 ? "not configured" :
829 if (ret < 0 || ret >= end - pos)
833 if (hapd->conf->wps_state && hapd->conf->wpa &&
834 hapd->conf->ssid.wpa_passphrase) {
835 ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
836 hapd->conf->ssid.wpa_passphrase);
837 if (ret < 0 || ret >= end - pos)
842 if (hapd->conf->wps_state && hapd->conf->wpa &&
843 hapd->conf->ssid.wpa_psk &&
844 hapd->conf->ssid.wpa_psk->group) {
845 char hex[PMK_LEN * 2 + 1];
846 wpa_snprintf_hex(hex, sizeof(hex),
847 hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
848 ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
849 if (ret < 0 || ret >= end - pos)
853 #endif /* CONFIG_WPS */
855 if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
856 ret = os_snprintf(pos, end - pos, "key_mgmt=");
857 if (ret < 0 || ret >= end - pos)
861 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
862 ret = os_snprintf(pos, end - pos, "WPA-PSK ");
863 if (ret < 0 || ret >= end - pos)
867 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
868 ret = os_snprintf(pos, end - pos, "WPA-EAP ");
869 if (ret < 0 || ret >= end - pos)
873 #ifdef CONFIG_IEEE80211R
874 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
875 ret = os_snprintf(pos, end - pos, "FT-PSK ");
876 if (ret < 0 || ret >= end - pos)
880 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
881 ret = os_snprintf(pos, end - pos, "FT-EAP ");
882 if (ret < 0 || ret >= end - pos)
886 #endif /* CONFIG_IEEE80211R */
887 #ifdef CONFIG_IEEE80211W
888 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
889 ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
890 if (ret < 0 || ret >= end - pos)
894 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
895 ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
896 if (ret < 0 || ret >= end - pos)
900 #endif /* CONFIG_IEEE80211W */
902 ret = os_snprintf(pos, end - pos, "\n");
903 if (ret < 0 || ret >= end - pos)
908 if (hapd->conf->wpa) {
909 ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
910 wpa_cipher_txt(hapd->conf->wpa_group));
911 if (ret < 0 || ret >= end - pos)
916 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
917 ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
918 if (ret < 0 || ret >= end - pos)
922 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
928 ret = os_snprintf(pos, end - pos, "\n");
929 if (ret < 0 || ret >= end - pos)
934 if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
935 ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
936 if (ret < 0 || ret >= end - pos)
940 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
946 ret = os_snprintf(pos, end - pos, "\n");
947 if (ret < 0 || ret >= end - pos)
956 static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
961 value = os_strchr(cmd, ' ');
966 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
968 #ifdef CONFIG_WPS_TESTING
969 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
971 val = strtol(value, NULL, 0);
972 if (val < 0 || val > 0xff) {
974 wpa_printf(MSG_DEBUG, "WPS: Invalid "
975 "wps_version_number %ld", val);
977 wps_version_number = val;
978 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
980 (wps_version_number & 0xf0) >> 4,
981 wps_version_number & 0x0f);
982 hostapd_wps_update_ie(hapd);
984 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
985 wps_testing_dummy_cred = atoi(value);
986 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
987 wps_testing_dummy_cred);
988 #endif /* CONFIG_WPS_TESTING */
989 #ifdef CONFIG_INTERWORKING
990 } else if (os_strcasecmp(cmd, "gas_frag_limit") == 0) {
991 int val = atoi(value);
995 hapd->gas_frag_limit = val;
996 #endif /* CONFIG_INTERWORKING */
998 ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value);
1005 static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
1006 char *buf, size_t buflen)
1010 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
1012 if (os_strcmp(cmd, "version") == 0) {
1013 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
1014 if (res < 0 || (unsigned int) res >= buflen)
1023 static int hostapd_ctrl_iface_enable(struct hostapd_iface *iface)
1025 if (hostapd_enable_iface(iface) < 0) {
1026 wpa_printf(MSG_ERROR, "Enabling of interface failed");
1033 static int hostapd_ctrl_iface_reload(struct hostapd_iface *iface)
1035 if (hostapd_reload_iface(iface) < 0) {
1036 wpa_printf(MSG_ERROR, "Reloading of interface failed");
1043 static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
1045 if (hostapd_disable_iface(iface) < 0) {
1046 wpa_printf(MSG_ERROR, "Disabling of interface failed");
1053 #ifdef CONFIG_TESTING_OPTIONS
1054 static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
1056 union wpa_event_data data;
1058 enum wpa_event_type event;
1060 wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
1062 os_memset(&data, 0, sizeof(data));
1064 param = os_strchr(cmd, ' ');
1069 if (os_strcmp(cmd, "DETECTED") == 0)
1070 event = EVENT_DFS_RADAR_DETECTED;
1071 else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
1072 event = EVENT_DFS_CAC_FINISHED;
1073 else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
1074 event = EVENT_DFS_CAC_ABORTED;
1075 else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
1076 event = EVENT_DFS_NOP_FINISHED;
1078 wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
1083 pos = os_strstr(param, "freq=");
1085 data.dfs_event.freq = atoi(pos + 5);
1087 pos = os_strstr(param, "ht_enabled=1");
1089 data.dfs_event.ht_enabled = 1;
1091 pos = os_strstr(param, "chan_offset=");
1093 data.dfs_event.chan_offset = atoi(pos + 12);
1095 pos = os_strstr(param, "chan_width=");
1097 data.dfs_event.chan_width = atoi(pos + 11);
1099 pos = os_strstr(param, "cf1=");
1101 data.dfs_event.cf1 = atoi(pos + 4);
1103 pos = os_strstr(param, "cf2=");
1105 data.dfs_event.cf2 = atoi(pos + 4);
1107 wpa_supplicant_event(hapd, event, &data);
1111 #endif /* CONFIG_TESTING_OPTIONS */
1114 static int hostapd_ctrl_iface_chan_switch(struct hostapd_data *hapd, char *pos)
1117 struct csa_settings settings;
1118 int ret = hostapd_parse_csa_settings(pos, &settings);
1123 return hostapd_switch_channel(hapd, &settings);
1124 #else /* NEED_AP_MLME */
1126 #endif /* NEED_AP_MLME */
1130 static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
1133 struct hostapd_data *hapd = eloop_ctx;
1136 struct sockaddr_un from;
1137 socklen_t fromlen = sizeof(from);
1139 const int reply_size = 4096;
1141 int level = MSG_DEBUG;
1143 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
1144 (struct sockaddr *) &from, &fromlen);
1146 perror("recvfrom(ctrl_iface)");
1150 if (os_strcmp(buf, "PING") == 0)
1151 level = MSG_EXCESSIVE;
1152 wpa_hexdump_ascii(level, "RX ctrl_iface", (u8 *) buf, res);
1154 reply = os_malloc(reply_size);
1155 if (reply == NULL) {
1156 sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
1161 os_memcpy(reply, "OK\n", 3);
1164 if (os_strcmp(buf, "PING") == 0) {
1165 os_memcpy(reply, "PONG\n", 5);
1167 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
1168 if (wpa_debug_reopen_file() < 0)
1170 } else if (os_strcmp(buf, "STATUS") == 0) {
1171 reply_len = hostapd_ctrl_iface_status(hapd, reply,
1173 } else if (os_strcmp(buf, "MIB") == 0) {
1174 reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
1175 if (reply_len >= 0) {
1176 res = wpa_get_mib(hapd->wpa_auth, reply + reply_len,
1177 reply_size - reply_len);
1183 if (reply_len >= 0) {
1184 res = ieee802_1x_get_mib(hapd, reply + reply_len,
1185 reply_size - reply_len);
1191 #ifndef CONFIG_NO_RADIUS
1192 if (reply_len >= 0) {
1193 res = radius_client_get_mib(hapd->radius,
1195 reply_size - reply_len);
1201 #endif /* CONFIG_NO_RADIUS */
1202 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
1203 reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
1205 } else if (os_strncmp(buf, "STA ", 4) == 0) {
1206 reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply,
1208 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
1209 reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
1211 } else if (os_strcmp(buf, "ATTACH") == 0) {
1212 if (hostapd_ctrl_iface_attach(hapd, &from, fromlen))
1214 } else if (os_strcmp(buf, "DETACH") == 0) {
1215 if (hostapd_ctrl_iface_detach(hapd, &from, fromlen))
1217 } else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
1218 if (hostapd_ctrl_iface_level(hapd, &from, fromlen,
1221 } else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
1222 if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
1224 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
1225 if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
1227 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
1228 if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
1230 #ifdef CONFIG_IEEE80211W
1232 } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
1233 if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
1235 #endif /* NEED_AP_MLME */
1236 #endif /* CONFIG_IEEE80211W */
1238 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
1239 if (hostapd_ctrl_iface_wps_pin(hapd, buf + 8))
1241 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
1242 reply_len = hostapd_ctrl_iface_wps_check_pin(
1243 hapd, buf + 14, reply, reply_size);
1244 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
1245 if (hostapd_wps_button_pushed(hapd, NULL))
1247 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
1248 if (hostapd_wps_cancel(hapd))
1250 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
1251 reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
1253 } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
1254 if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
1256 } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
1257 reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
1259 #ifdef CONFIG_WPS_NFC
1260 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
1261 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
1263 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
1264 reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
1265 hapd, buf + 21, reply, reply_size);
1266 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
1267 reply_len = hostapd_ctrl_iface_wps_nfc_token(
1268 hapd, buf + 14, reply, reply_size);
1269 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
1270 reply_len = hostapd_ctrl_iface_nfc_get_handover_sel(
1271 hapd, buf + 21, reply, reply_size);
1272 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
1273 if (hostapd_ctrl_iface_nfc_report_handover(hapd, buf + 20))
1275 #endif /* CONFIG_WPS_NFC */
1276 #endif /* CONFIG_WPS */
1277 #ifdef CONFIG_INTERWORKING
1278 } else if (os_strncmp(buf, "SET_QOS_MAP_SET ", 16) == 0) {
1279 if (hostapd_ctrl_iface_set_qos_map_set(hapd, buf + 16))
1281 } else if (os_strncmp(buf, "SEND_QOS_MAP_CONF ", 18) == 0) {
1282 if (hostapd_ctrl_iface_send_qos_map_conf(hapd, buf + 18))
1284 #endif /* CONFIG_INTERWORKING */
1286 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
1287 if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
1289 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
1290 if (hostapd_ctrl_iface_ess_disassoc(hapd, buf + 13))
1292 #endif /* CONFIG_WNM */
1293 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
1294 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
1296 } else if (os_strncmp(buf, "SET ", 4) == 0) {
1297 if (hostapd_ctrl_iface_set(hapd, buf + 4))
1299 } else if (os_strncmp(buf, "GET ", 4) == 0) {
1300 reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
1302 } else if (os_strncmp(buf, "ENABLE", 6) == 0) {
1303 if (hostapd_ctrl_iface_enable(hapd->iface))
1305 } else if (os_strncmp(buf, "RELOAD", 6) == 0) {
1306 if (hostapd_ctrl_iface_reload(hapd->iface))
1308 } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
1309 if (hostapd_ctrl_iface_disable(hapd->iface))
1311 #ifdef CONFIG_TESTING_OPTIONS
1312 } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
1313 if (hostapd_ctrl_iface_radar(hapd, buf + 6))
1315 #endif /* CONFIG_TESTING_OPTIONS */
1316 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
1317 if (hostapd_ctrl_iface_chan_switch(hapd, buf + 12))
1320 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
1324 if (reply_len < 0) {
1325 os_memcpy(reply, "FAIL\n", 5);
1328 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1333 static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
1338 if (hapd->conf->ctrl_interface == NULL)
1341 len = os_strlen(hapd->conf->ctrl_interface) +
1342 os_strlen(hapd->conf->iface) + 2;
1343 buf = os_malloc(len);
1347 os_snprintf(buf, len, "%s/%s",
1348 hapd->conf->ctrl_interface, hapd->conf->iface);
1349 buf[len - 1] = '\0';
1354 static void hostapd_ctrl_iface_msg_cb(void *ctx, int level, int global,
1355 const char *txt, size_t len)
1357 struct hostapd_data *hapd = ctx;
1360 hostapd_ctrl_iface_send(hapd, level, txt, len);
1364 int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
1366 struct sockaddr_un addr;
1370 if (hapd->ctrl_sock > -1) {
1371 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
1375 if (hapd->conf->ctrl_interface == NULL)
1378 if (mkdir(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
1379 if (errno == EEXIST) {
1380 wpa_printf(MSG_DEBUG, "Using existing control "
1381 "interface directory.");
1383 perror("mkdir[ctrl_interface]");
1388 if (hapd->conf->ctrl_interface_gid_set &&
1389 chown(hapd->conf->ctrl_interface, -1,
1390 hapd->conf->ctrl_interface_gid) < 0) {
1391 perror("chown[ctrl_interface]");
1395 if (!hapd->conf->ctrl_interface_gid_set &&
1396 hapd->iface->interfaces->ctrl_iface_group &&
1397 chown(hapd->conf->ctrl_interface, -1,
1398 hapd->iface->interfaces->ctrl_iface_group) < 0) {
1399 perror("chown[ctrl_interface]");
1405 * Android is using umask 0077 which would leave the control interface
1406 * directory without group access. This breaks things since Wi-Fi
1407 * framework assumes that this directory can be accessed by other
1408 * applications in the wifi group. Fix this by adding group access even
1409 * if umask value would prevent this.
1411 if (chmod(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
1412 wpa_printf(MSG_ERROR, "CTRL: Could not chmod directory: %s",
1414 /* Try to continue anyway */
1416 #endif /* ANDROID */
1418 if (os_strlen(hapd->conf->ctrl_interface) + 1 +
1419 os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path))
1422 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1424 perror("socket(PF_UNIX)");
1428 os_memset(&addr, 0, sizeof(addr));
1430 addr.sun_len = sizeof(addr);
1431 #endif /* __FreeBSD__ */
1432 addr.sun_family = AF_UNIX;
1433 fname = hostapd_ctrl_iface_path(hapd);
1436 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
1437 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1438 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
1440 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1441 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1442 " allow connections - assuming it was left"
1443 "over from forced program termination");
1444 if (unlink(fname) < 0) {
1445 perror("unlink[ctrl_iface]");
1446 wpa_printf(MSG_ERROR, "Could not unlink "
1447 "existing ctrl_iface socket '%s'",
1451 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1453 perror("hostapd-ctrl-iface: bind(PF_UNIX)");
1456 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1457 "ctrl_iface socket '%s'", fname);
1459 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1460 "be in use - cannot override it");
1461 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1462 "not used anymore", fname);
1469 if (hapd->conf->ctrl_interface_gid_set &&
1470 chown(fname, -1, hapd->conf->ctrl_interface_gid) < 0) {
1471 perror("chown[ctrl_interface/ifname]");
1475 if (!hapd->conf->ctrl_interface_gid_set &&
1476 hapd->iface->interfaces->ctrl_iface_group &&
1477 chown(fname, -1, hapd->iface->interfaces->ctrl_iface_group) < 0) {
1478 perror("chown[ctrl_interface/ifname]");
1482 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
1483 perror("chmod[ctrl_interface/ifname]");
1488 hapd->ctrl_sock = s;
1489 eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
1491 hapd->msg_ctx = hapd;
1492 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
1507 void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
1509 struct wpa_ctrl_dst *dst, *prev;
1511 if (hapd->ctrl_sock > -1) {
1513 eloop_unregister_read_sock(hapd->ctrl_sock);
1514 close(hapd->ctrl_sock);
1515 hapd->ctrl_sock = -1;
1516 fname = hostapd_ctrl_iface_path(hapd);
1521 if (hapd->conf->ctrl_interface &&
1522 rmdir(hapd->conf->ctrl_interface) < 0) {
1523 if (errno == ENOTEMPTY) {
1524 wpa_printf(MSG_DEBUG, "Control interface "
1525 "directory not empty - leaving it "
1528 wpa_printf(MSG_ERROR,
1529 "rmdir[ctrl_interface=%s]: %s",
1530 hapd->conf->ctrl_interface,
1536 dst = hapd->ctrl_dst;
1545 static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces,
1548 if (hostapd_add_iface(interfaces, buf) < 0) {
1549 wpa_printf(MSG_ERROR, "Adding interface %s failed", buf);
1556 static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
1559 if (hostapd_remove_iface(interfaces, buf) < 0) {
1560 wpa_printf(MSG_ERROR, "Removing interface %s failed", buf);
1567 static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
1570 void *interfaces = eloop_ctx;
1573 struct sockaddr_un from;
1574 socklen_t fromlen = sizeof(from);
1578 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
1579 (struct sockaddr *) &from, &fromlen);
1581 perror("recvfrom(ctrl_iface)");
1585 wpa_printf(MSG_DEBUG, "Global ctrl_iface command: %s", buf);
1587 os_memcpy(reply, "OK\n", 3);
1590 if (os_strcmp(buf, "PING") == 0) {
1591 os_memcpy(reply, "PONG\n", 5);
1593 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
1594 if (wpa_debug_reopen_file() < 0)
1596 } else if (os_strncmp(buf, "ADD ", 4) == 0) {
1597 if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0)
1599 } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
1600 if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
1603 wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
1608 if (reply_len < 0) {
1609 os_memcpy(reply, "FAIL\n", 5);
1613 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1617 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces *interface)
1622 if (interface->global_iface_path == NULL)
1625 len = os_strlen(interface->global_iface_path) +
1626 os_strlen(interface->global_iface_name) + 2;
1627 buf = os_malloc(len);
1631 os_snprintf(buf, len, "%s/%s", interface->global_iface_path,
1632 interface->global_iface_name);
1633 buf[len - 1] = '\0';
1638 int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
1640 struct sockaddr_un addr;
1644 if (interface->global_iface_path == NULL) {
1645 wpa_printf(MSG_DEBUG, "ctrl_iface not configured!");
1649 if (mkdir(interface->global_iface_path, S_IRWXU | S_IRWXG) < 0) {
1650 if (errno == EEXIST) {
1651 wpa_printf(MSG_DEBUG, "Using existing control "
1652 "interface directory.");
1654 perror("mkdir[ctrl_interface]");
1657 } else if (interface->ctrl_iface_group &&
1658 chown(interface->global_iface_path, -1,
1659 interface->ctrl_iface_group) < 0) {
1660 perror("chown[ctrl_interface]");
1664 if (os_strlen(interface->global_iface_path) + 1 +
1665 os_strlen(interface->global_iface_name) >= sizeof(addr.sun_path))
1668 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1670 perror("socket(PF_UNIX)");
1674 os_memset(&addr, 0, sizeof(addr));
1676 addr.sun_len = sizeof(addr);
1677 #endif /* __FreeBSD__ */
1678 addr.sun_family = AF_UNIX;
1679 fname = hostapd_global_ctrl_iface_path(interface);
1682 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
1683 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1684 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
1686 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1687 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1688 " allow connections - assuming it was left"
1689 "over from forced program termination");
1690 if (unlink(fname) < 0) {
1691 perror("unlink[ctrl_iface]");
1692 wpa_printf(MSG_ERROR, "Could not unlink "
1693 "existing ctrl_iface socket '%s'",
1697 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1699 perror("bind(PF_UNIX)");
1702 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1703 "ctrl_iface socket '%s'", fname);
1705 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1706 "be in use - cannot override it");
1707 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1708 "not used anymore", fname);
1715 if (interface->ctrl_iface_group &&
1716 chown(fname, -1, interface->ctrl_iface_group) < 0) {
1717 perror("chown[ctrl_interface]");
1721 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
1722 perror("chmod[ctrl_interface/ifname]");
1727 interface->global_ctrl_sock = s;
1728 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
1744 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
1748 if (interfaces->global_ctrl_sock > -1) {
1749 eloop_unregister_read_sock(interfaces->global_ctrl_sock);
1750 close(interfaces->global_ctrl_sock);
1751 interfaces->global_ctrl_sock = -1;
1752 fname = hostapd_global_ctrl_iface_path(interfaces);
1758 if (interfaces->global_iface_path &&
1759 rmdir(interfaces->global_iface_path) < 0) {
1760 if (errno == ENOTEMPTY) {
1761 wpa_printf(MSG_DEBUG, "Control interface "
1762 "directory not empty - leaving it "
1765 wpa_printf(MSG_ERROR,
1766 "rmdir[ctrl_interface=%s]: %s",
1767 interfaces->global_iface_path,
1771 os_free(interfaces->global_iface_path);
1772 interfaces->global_iface_path = NULL;
1777 static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
1778 const char *buf, size_t len)
1780 struct wpa_ctrl_dst *dst, *next;
1786 dst = hapd->ctrl_dst;
1787 if (hapd->ctrl_sock < 0 || dst == NULL)
1790 os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
1791 io[0].iov_base = levelstr;
1792 io[0].iov_len = os_strlen(levelstr);
1793 io[1].iov_base = (char *) buf;
1794 io[1].iov_len = len;
1795 os_memset(&msg, 0, sizeof(msg));
1802 if (level >= dst->debug_level) {
1803 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
1804 (u8 *) dst->addr.sun_path, dst->addrlen -
1805 offsetof(struct sockaddr_un, sun_path));
1806 msg.msg_name = &dst->addr;
1807 msg.msg_namelen = dst->addrlen;
1808 if (sendmsg(hapd->ctrl_sock, &msg, 0) < 0) {
1810 wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
1812 idx, errno, strerror(errno));
1814 if (dst->errors > 10 || _errno == ENOENT) {
1815 hostapd_ctrl_iface_detach(
1827 #endif /* CONFIG_NATIVE_WINDOWS */