2 * hostapd / UNIX domain socket -based control interface
3 * Copyright (c) 2004-2015, 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
13 #ifdef CONFIG_TESTING_OPTIONS
14 #include <net/ethernet.h>
15 #include <netinet/ip.h>
16 #endif /* CONFIG_TESTING_OPTIONS */
22 #include "utils/common.h"
23 #include "utils/eloop.h"
24 #include "common/version.h"
25 #include "common/ieee802_11_defs.h"
26 #include "crypto/tls.h"
27 #include "drivers/driver.h"
28 #include "eapol_auth/eapol_auth_sm.h"
29 #include "radius/radius_client.h"
30 #include "radius/radius_server.h"
31 #include "l2_packet/l2_packet.h"
32 #include "ap/hostapd.h"
33 #include "ap/ap_config.h"
34 #include "ap/ieee802_1x.h"
35 #include "ap/wpa_auth.h"
36 #include "ap/ieee802_11.h"
37 #include "ap/sta_info.h"
38 #include "ap/wps_hostapd.h"
39 #include "ap/ctrl_iface_ap.h"
40 #include "ap/ap_drv_ops.h"
42 #include "ap/wnm_ap.h"
43 #include "ap/wpa_auth.h"
44 #include "ap/beacon.h"
45 #include "wps/wps_defs.h"
47 #include "config_file.h"
48 #include "ctrl_iface.h"
52 struct wpa_ctrl_dst *next;
53 struct sockaddr_un addr;
60 static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
61 enum wpa_msg_type type,
62 const char *buf, size_t len);
65 static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
66 struct sockaddr_un *from,
69 struct wpa_ctrl_dst *dst;
71 dst = os_zalloc(sizeof(*dst));
74 os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
75 dst->addrlen = fromlen;
76 dst->debug_level = MSG_INFO;
77 dst->next = hapd->ctrl_dst;
79 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached",
80 (u8 *) from->sun_path,
81 fromlen - offsetof(struct sockaddr_un, sun_path));
86 static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
87 struct sockaddr_un *from,
90 struct wpa_ctrl_dst *dst, *prev = NULL;
94 if (fromlen == dst->addrlen &&
95 os_memcmp(from->sun_path, dst->addr.sun_path,
96 fromlen - offsetof(struct sockaddr_un, sun_path))
98 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached",
99 (u8 *) from->sun_path,
101 offsetof(struct sockaddr_un, sun_path));
103 hapd->ctrl_dst = dst->next;
105 prev->next = dst->next;
116 static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
117 struct sockaddr_un *from,
121 struct wpa_ctrl_dst *dst;
123 wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
125 dst = hapd->ctrl_dst;
127 if (fromlen == dst->addrlen &&
128 os_memcmp(from->sun_path, dst->addr.sun_path,
129 fromlen - offsetof(struct sockaddr_un, sun_path))
131 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE changed monitor "
132 "level", (u8 *) from->sun_path, fromlen -
133 offsetof(struct sockaddr_un, sun_path));
134 dst->debug_level = atoi(level);
144 static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
148 struct sta_info *sta;
150 wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
152 if (hwaddr_aton(txtaddr, addr))
155 sta = ap_get_sta(hapd, addr);
159 wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
160 "notification", MAC2STR(addr));
161 sta = ap_sta_add(hapd, addr);
165 hostapd_new_assoc_sta(hapd, sta, 0);
170 #ifdef CONFIG_IEEE80211W
172 static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
176 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
178 wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
180 if (hwaddr_aton(txtaddr, addr) ||
181 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
184 ieee802_11_send_sa_query_req(hapd, addr, trans_id);
188 #endif /* NEED_AP_MLME */
189 #endif /* CONFIG_IEEE80211W */
193 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
195 char *pin = os_strchr(txt, ' ');
198 u8 addr_buf[ETH_ALEN], *addr = NULL;
205 timeout_txt = os_strchr(pin, ' ');
207 *timeout_txt++ = '\0';
208 timeout = atoi(timeout_txt);
209 pos = os_strchr(timeout_txt, ' ');
212 if (hwaddr_aton(pos, addr_buf) == 0)
218 return hostapd_wps_add_pin(hapd, addr, txt, pin, timeout);
222 static int hostapd_ctrl_iface_wps_check_pin(
223 struct hostapd_data *hapd, char *cmd, char *buf, size_t buflen)
230 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
231 (u8 *) cmd, os_strlen(cmd));
232 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
233 if (*pos < '0' || *pos > '9')
237 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
241 if (len != 4 && len != 8) {
242 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
248 unsigned int pin_val;
250 if (!wps_pin_valid(pin_val)) {
251 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
252 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
253 if (os_snprintf_error(buflen, ret))
259 ret = os_snprintf(buf, buflen, "%s", pin);
260 if (os_snprintf_error(buflen, ret))
267 #ifdef CONFIG_WPS_NFC
268 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
275 len = os_strlen(pos);
280 buf = wpabuf_alloc(len);
283 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
288 ret = hostapd_wps_nfc_tag_read(hapd, buf);
295 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
296 char *cmd, char *reply,
303 if (os_strcmp(cmd, "WPS") == 0)
305 else if (os_strcmp(cmd, "NDEF") == 0)
310 buf = hostapd_wps_nfc_config_token(hapd, ndef);
314 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
325 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data *hapd,
326 char *reply, size_t max_len,
332 buf = hostapd_wps_nfc_token_gen(hapd, ndef);
336 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
347 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data *hapd,
348 char *cmd, char *reply,
351 if (os_strcmp(cmd, "WPS") == 0)
352 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
355 if (os_strcmp(cmd, "NDEF") == 0)
356 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
359 if (os_strcmp(cmd, "enable") == 0)
360 return hostapd_wps_nfc_token_enable(hapd);
362 if (os_strcmp(cmd, "disable") == 0) {
363 hostapd_wps_nfc_token_disable(hapd);
371 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data *hapd,
372 char *cmd, char *reply,
380 pos = os_strchr(cmd, ' ');
385 if (os_strcmp(cmd, "WPS") == 0)
387 else if (os_strcmp(cmd, "NDEF") == 0)
392 if (os_strcmp(pos, "WPS-CR") == 0)
393 buf = hostapd_wps_nfc_hs_cr(hapd, ndef);
399 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
410 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data *hapd,
414 struct wpabuf *req, *sel;
416 char *pos, *role, *type, *pos2;
419 pos = os_strchr(role, ' ');
425 pos = os_strchr(type, ' ');
430 pos2 = os_strchr(pos, ' ');
435 len = os_strlen(pos);
440 req = wpabuf_alloc(len);
443 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
448 len = os_strlen(pos2);
455 sel = wpabuf_alloc(len);
460 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
466 if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) {
467 ret = hostapd_wps_nfc_report_handover(hapd, req, sel);
469 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
470 "reported: role=%s type=%s", role, type);
479 #endif /* CONFIG_WPS_NFC */
482 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
483 char *buf, size_t buflen)
489 pos = os_strchr(txt, ' ');
493 if (os_strcmp(txt, "disable") == 0) {
494 hostapd_wps_ap_pin_disable(hapd);
495 return os_snprintf(buf, buflen, "OK\n");
498 if (os_strcmp(txt, "random") == 0) {
501 pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
504 return os_snprintf(buf, buflen, "%s", pin_txt);
507 if (os_strcmp(txt, "get") == 0) {
508 pin_txt = hostapd_wps_ap_pin_get(hapd);
511 return os_snprintf(buf, buflen, "%s", pin_txt);
514 if (os_strcmp(txt, "set") == 0) {
519 pos = os_strchr(pos, ' ');
524 if (os_strlen(pin) > buflen)
526 if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
528 return os_snprintf(buf, buflen, "%s", pin);
535 static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
538 char *ssid, *auth, *encr = NULL, *key = NULL;
541 pos = os_strchr(txt, ' ');
547 pos = os_strchr(pos, ' ');
551 pos = os_strchr(pos, ' ');
558 return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
562 static const char * pbc_status_str(enum pbc_status status)
565 case WPS_PBC_STATUS_DISABLE:
567 case WPS_PBC_STATUS_ACTIVE:
569 case WPS_PBC_STATUS_TIMEOUT:
571 case WPS_PBC_STATUS_OVERLAP:
579 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
580 char *buf, size_t buflen)
588 ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
589 pbc_status_str(hapd->wps_stats.pbc_status));
591 if (os_snprintf_error(end - pos, ret))
595 ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
596 (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
598 (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
599 "Failed" : "None")));
601 if (os_snprintf_error(end - pos, ret))
605 /* If status == Failure - Add possible Reasons */
606 if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
607 hapd->wps_stats.failure_reason > 0) {
608 ret = os_snprintf(pos, end - pos,
609 "Failure Reason: %s\n",
610 wps_ei_str(hapd->wps_stats.failure_reason));
612 if (os_snprintf_error(end - pos, ret))
617 if (hapd->wps_stats.status) {
618 ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
619 MAC2STR(hapd->wps_stats.peer_addr));
621 if (os_snprintf_error(end - pos, ret))
629 #endif /* CONFIG_WPS */
633 static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data *hapd,
639 if (hwaddr_aton(cmd, addr))
652 return hs20_send_wnm_notification(hapd, addr, 1, url);
656 static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data *hapd,
660 int code, reauth_delay, ret;
665 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
666 if (hwaddr_aton(cmd, addr))
669 pos = os_strchr(cmd, ' ');
675 pos = os_strchr(pos, ' ');
679 reauth_delay = atoi(pos);
682 pos = os_strchr(pos, ' ');
685 url_len = os_strlen(pos);
688 req = wpabuf_alloc(4 + url_len);
691 wpabuf_put_u8(req, code);
692 wpabuf_put_le16(req, reauth_delay);
693 wpabuf_put_u8(req, url_len);
695 wpabuf_put_data(req, pos, url_len);
697 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to " MACSTR
698 " to indicate imminent deauthentication (code=%d "
699 "reauth_delay=%d)", MAC2STR(addr), code, reauth_delay);
700 ret = hs20_send_wnm_notification_deauth_req(hapd, addr, req);
705 #endif /* CONFIG_HS20 */
708 #ifdef CONFIG_INTERWORKING
710 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data *hapd,
713 u8 qos_map_set[16 + 2 * 21], count = 0;
714 const char *pos = cmd;
718 if (count == sizeof(qos_map_set)) {
719 wpa_printf(MSG_ERROR, "Too many qos_map_set parameters");
724 if (val < 0 || val > 255) {
725 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
729 qos_map_set[count++] = val;
730 pos = os_strchr(pos, ',');
736 if (count < 16 || count & 1) {
737 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
741 ret = hostapd_drv_set_qos_map(hapd, qos_map_set, count);
743 wpa_printf(MSG_INFO, "Failed to set QoS Map Set");
747 os_memcpy(hapd->conf->qos_map_set, qos_map_set, count);
748 hapd->conf->qos_map_set_len = count;
754 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
758 struct sta_info *sta;
760 u8 *qos_map_set = hapd->conf->qos_map_set;
761 u8 qos_map_set_len = hapd->conf->qos_map_set_len;
764 if (!qos_map_set_len) {
765 wpa_printf(MSG_INFO, "QoS Map Set is not set");
769 if (hwaddr_aton(cmd, addr))
772 sta = ap_get_sta(hapd, addr);
774 wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
775 "for QoS Map Configuration message",
780 if (!sta->qos_map_enabled) {
781 wpa_printf(MSG_DEBUG, "Station " MACSTR " did not indicate "
782 "support for QoS Map", MAC2STR(addr));
786 buf = wpabuf_alloc(2 + 2 + qos_map_set_len);
790 wpabuf_put_u8(buf, WLAN_ACTION_QOS);
791 wpabuf_put_u8(buf, QOS_QOS_MAP_CONFIG);
793 /* QoS Map Set Element */
794 wpabuf_put_u8(buf, WLAN_EID_QOS_MAP_SET);
795 wpabuf_put_u8(buf, qos_map_set_len);
796 wpabuf_put_data(buf, qos_map_set, qos_map_set_len);
798 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
799 wpabuf_head(buf), wpabuf_len(buf));
805 #endif /* CONFIG_INTERWORKING */
810 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data *hapd,
815 struct sta_info *sta;
817 if (hwaddr_aton(cmd, addr))
821 disassoc_timer = atoi(cmd + 17);
823 sta = ap_get_sta(hapd, addr);
825 wpa_printf(MSG_DEBUG, "Station " MACSTR
826 " not found for disassociation imminent message",
831 return wnm_send_disassoc_imminent(hapd, sta, disassoc_timer);
835 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
839 const char *url, *timerstr;
841 struct sta_info *sta;
843 if (hwaddr_aton(cmd, addr))
846 sta = ap_get_sta(hapd, addr);
848 wpa_printf(MSG_DEBUG, "Station " MACSTR
849 " not found for ESS disassociation imminent message",
855 if (*timerstr != ' ')
858 disassoc_timer = atoi(timerstr);
859 if (disassoc_timer < 0 || disassoc_timer > 65535)
862 url = os_strchr(timerstr, ' ');
867 return wnm_send_ess_disassoc_imminent(hapd, sta, url, disassoc_timer);
871 static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data *hapd,
875 const char *pos, *end;
876 int disassoc_timer = 0;
877 struct sta_info *sta;
878 u8 req_mode = 0, valid_int = 0x01;
883 u8 *nei_pos = nei_rep;
885 if (hwaddr_aton(cmd, addr)) {
886 wpa_printf(MSG_DEBUG, "Invalid STA MAC address");
890 sta = ap_get_sta(hapd, addr);
892 wpa_printf(MSG_DEBUG, "Station " MACSTR
893 " not found for BSS TM Request message",
898 pos = os_strstr(cmd, " disassoc_timer=");
901 disassoc_timer = atoi(pos);
902 if (disassoc_timer < 0 || disassoc_timer > 65535) {
903 wpa_printf(MSG_DEBUG, "Invalid disassoc_timer");
908 pos = os_strstr(cmd, " valid_int=");
911 valid_int = atoi(pos);
914 pos = os_strstr(cmd, " bss_term=");
917 req_mode |= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED;
918 /* TODO: TSF configurable/learnable */
919 bss_term_dur[0] = 4; /* Subelement ID */
920 bss_term_dur[1] = 10; /* Length */
921 os_memset(bss_term_dur, 2, 8);
922 end = os_strchr(pos, ',');
924 wpa_printf(MSG_DEBUG, "Invalid bss_term data");
928 WPA_PUT_LE16(&bss_term_dur[10], atoi(end));
933 * BSS Transition Candidate List Entries - Neighbor Report elements
934 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
935 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
943 pos = os_strstr(pos, " neighbor=");
946 if (nei_pos + 15 > nei_rep + sizeof(nei_rep)) {
947 wpa_printf(MSG_DEBUG,
948 "Not enough room for additional neighbor");
954 *nei_pos++ = WLAN_EID_NEIGHBOR_REPORT;
955 nei_pos++; /* length to be filled in */
957 if (hwaddr_aton(pos, nei_pos)) {
958 wpa_printf(MSG_DEBUG, "Invalid BSSID");
964 wpa_printf(MSG_DEBUG, "Missing BSSID Information");
969 val = strtol(pos, &endptr, 0);
970 WPA_PUT_LE32(nei_pos, val);
972 if (*endptr != ',') {
973 wpa_printf(MSG_DEBUG, "Missing Operating Class");
978 *nei_pos++ = atoi(pos); /* Operating Class */
979 pos = os_strchr(pos, ',');
981 wpa_printf(MSG_DEBUG, "Missing Channel Number");
986 *nei_pos++ = atoi(pos); /* Channel Number */
987 pos = os_strchr(pos, ',');
989 wpa_printf(MSG_DEBUG, "Missing PHY Type");
994 *nei_pos++ = atoi(pos); /* PHY Type */
995 end = os_strchr(pos, ' ');
996 tmp = os_strchr(pos, ',');
997 if (tmp && (!end || tmp < end)) {
998 /* Optional Subelements (hexdump) */
1002 end = os_strchr(pos, ' ');
1006 len = os_strlen(pos);
1007 if (nei_pos + len / 2 > nei_rep + sizeof(nei_rep)) {
1008 wpa_printf(MSG_DEBUG,
1009 "Not enough room for neighbor subelements");
1013 hexstr2bin(pos, nei_pos, len / 2) < 0) {
1014 wpa_printf(MSG_DEBUG,
1015 "Invalid neighbor subelement info");
1022 nei_start[1] = nei_pos - nei_start - 2;
1025 pos = os_strstr(cmd, " url=");
1029 end = os_strchr(pos, ' ');
1033 len = os_strlen(pos);
1034 url = os_malloc(len + 1);
1037 os_memcpy(url, pos, len);
1039 req_mode |= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
1042 if (os_strstr(cmd, " pref=1"))
1043 req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED;
1044 if (os_strstr(cmd, " abridged=1"))
1045 req_mode |= WNM_BSS_TM_REQ_ABRIDGED;
1046 if (os_strstr(cmd, " disassoc_imminent=1"))
1047 req_mode |= WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
1049 ret = wnm_send_bss_tm_req(hapd, sta, req_mode, disassoc_timer,
1050 valid_int, bss_term_dur, url,
1051 nei_pos > nei_rep ? nei_rep : NULL,
1057 #endif /* CONFIG_WNM */
1060 static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
1061 char *buf, size_t buflen)
1069 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
1071 MAC2STR(hapd->own_addr),
1072 wpa_ssid_txt(hapd->conf->ssid.ssid,
1073 hapd->conf->ssid.ssid_len));
1074 if (os_snprintf_error(end - pos, ret))
1079 ret = os_snprintf(pos, end - pos, "wps_state=%s\n",
1080 hapd->conf->wps_state == 0 ? "disabled" :
1081 (hapd->conf->wps_state == 1 ? "not configured" :
1083 if (os_snprintf_error(end - pos, ret))
1087 if (hapd->conf->wps_state && hapd->conf->wpa &&
1088 hapd->conf->ssid.wpa_passphrase) {
1089 ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
1090 hapd->conf->ssid.wpa_passphrase);
1091 if (os_snprintf_error(end - pos, ret))
1096 if (hapd->conf->wps_state && hapd->conf->wpa &&
1097 hapd->conf->ssid.wpa_psk &&
1098 hapd->conf->ssid.wpa_psk->group) {
1099 char hex[PMK_LEN * 2 + 1];
1100 wpa_snprintf_hex(hex, sizeof(hex),
1101 hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
1102 ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
1103 if (os_snprintf_error(end - pos, ret))
1107 #endif /* CONFIG_WPS */
1109 if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
1110 ret = os_snprintf(pos, end - pos, "key_mgmt=");
1111 if (os_snprintf_error(end - pos, ret))
1115 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
1116 ret = os_snprintf(pos, end - pos, "WPA-PSK ");
1117 if (os_snprintf_error(end - pos, ret))
1121 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1122 ret = os_snprintf(pos, end - pos, "WPA-EAP ");
1123 if (os_snprintf_error(end - pos, ret))
1127 #ifdef CONFIG_IEEE80211R
1128 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1129 ret = os_snprintf(pos, end - pos, "FT-PSK ");
1130 if (os_snprintf_error(end - pos, ret))
1134 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1135 ret = os_snprintf(pos, end - pos, "FT-EAP ");
1136 if (os_snprintf_error(end - pos, ret))
1141 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_SAE) {
1142 ret = os_snprintf(pos, end - pos, "FT-SAE ");
1143 if (os_snprintf_error(end - pos, ret))
1147 #endif /* CONFIG_SAE */
1148 #endif /* CONFIG_IEEE80211R */
1149 #ifdef CONFIG_IEEE80211W
1150 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1151 ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
1152 if (os_snprintf_error(end - pos, ret))
1156 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1157 ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
1158 if (os_snprintf_error(end - pos, ret))
1162 #endif /* CONFIG_IEEE80211W */
1164 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_SAE) {
1165 ret = os_snprintf(pos, end - pos, "SAE ");
1166 if (os_snprintf_error(end - pos, ret))
1170 #endif /* CONFIG_SAE */
1171 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
1172 ret = os_snprintf(pos, end - pos, "WPA-EAP-SUITE-B ");
1173 if (os_snprintf_error(end - pos, ret))
1177 if (hapd->conf->wpa_key_mgmt &
1178 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
1179 ret = os_snprintf(pos, end - pos,
1180 "WPA-EAP-SUITE-B-192 ");
1181 if (os_snprintf_error(end - pos, ret))
1186 ret = os_snprintf(pos, end - pos, "\n");
1187 if (os_snprintf_error(end - pos, ret))
1192 if (hapd->conf->wpa) {
1193 ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
1194 wpa_cipher_txt(hapd->conf->wpa_group));
1195 if (os_snprintf_error(end - pos, ret))
1200 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
1201 ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
1202 if (os_snprintf_error(end - pos, ret))
1206 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
1212 ret = os_snprintf(pos, end - pos, "\n");
1213 if (os_snprintf_error(end - pos, ret))
1218 if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
1219 ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
1220 if (os_snprintf_error(end - pos, ret))
1224 ret = wpa_write_ciphers(pos, end, hapd->conf->wpa_pairwise,
1230 ret = os_snprintf(pos, end - pos, "\n");
1231 if (os_snprintf_error(end - pos, ret))
1240 static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
1245 value = os_strchr(cmd, ' ');
1250 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
1252 #ifdef CONFIG_WPS_TESTING
1253 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
1255 val = strtol(value, NULL, 0);
1256 if (val < 0 || val > 0xff) {
1258 wpa_printf(MSG_DEBUG, "WPS: Invalid "
1259 "wps_version_number %ld", val);
1261 wps_version_number = val;
1262 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
1264 (wps_version_number & 0xf0) >> 4,
1265 wps_version_number & 0x0f);
1266 hostapd_wps_update_ie(hapd);
1268 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
1269 wps_testing_dummy_cred = atoi(value);
1270 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
1271 wps_testing_dummy_cred);
1272 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
1273 wps_corrupt_pkhash = atoi(value);
1274 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
1275 wps_corrupt_pkhash);
1276 #endif /* CONFIG_WPS_TESTING */
1277 #ifdef CONFIG_INTERWORKING
1278 } else if (os_strcasecmp(cmd, "gas_frag_limit") == 0) {
1279 int val = atoi(value);
1283 hapd->gas_frag_limit = val;
1284 #endif /* CONFIG_INTERWORKING */
1285 #ifdef CONFIG_TESTING_OPTIONS
1286 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
1287 hapd->ext_mgmt_frame_handling = atoi(value);
1288 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
1289 hapd->ext_eapol_frame_io = atoi(value);
1290 #endif /* CONFIG_TESTING_OPTIONS */
1292 struct sta_info *sta;
1295 ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value);
1299 if (os_strcasecmp(cmd, "deny_mac_file") == 0) {
1300 for (sta = hapd->sta_list; sta; sta = sta->next) {
1301 if (hostapd_maclist_found(
1302 hapd->conf->deny_mac,
1303 hapd->conf->num_deny_mac, sta->addr,
1305 (!vlan_id || vlan_id == sta->vlan_id))
1307 hapd, sta, sta->addr,
1308 WLAN_REASON_UNSPECIFIED);
1310 } else if (hapd->conf->macaddr_acl == DENY_UNLESS_ACCEPTED &&
1311 os_strcasecmp(cmd, "accept_mac_file") == 0) {
1312 for (sta = hapd->sta_list; sta; sta = sta->next) {
1313 if (!hostapd_maclist_found(
1314 hapd->conf->accept_mac,
1315 hapd->conf->num_accept_mac,
1316 sta->addr, &vlan_id) ||
1317 (vlan_id && vlan_id != sta->vlan_id))
1319 hapd, sta, sta->addr,
1320 WLAN_REASON_UNSPECIFIED);
1329 static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
1330 char *buf, size_t buflen)
1334 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
1336 if (os_strcmp(cmd, "version") == 0) {
1337 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
1338 if (os_snprintf_error(buflen, res))
1341 } else if (os_strcmp(cmd, "tls_library") == 0) {
1342 res = tls_get_library_version(buf, buflen);
1343 if (os_snprintf_error(buflen, res))
1352 static int hostapd_ctrl_iface_enable(struct hostapd_iface *iface)
1354 if (hostapd_enable_iface(iface) < 0) {
1355 wpa_printf(MSG_ERROR, "Enabling of interface failed");
1362 static int hostapd_ctrl_iface_reload(struct hostapd_iface *iface)
1364 if (hostapd_reload_iface(iface) < 0) {
1365 wpa_printf(MSG_ERROR, "Reloading of interface failed");
1372 static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
1374 if (hostapd_disable_iface(iface) < 0) {
1375 wpa_printf(MSG_ERROR, "Disabling of interface failed");
1382 #ifdef CONFIG_TESTING_OPTIONS
1384 static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
1386 union wpa_event_data data;
1388 enum wpa_event_type event;
1390 wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
1392 os_memset(&data, 0, sizeof(data));
1394 param = os_strchr(cmd, ' ');
1399 if (os_strcmp(cmd, "DETECTED") == 0)
1400 event = EVENT_DFS_RADAR_DETECTED;
1401 else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
1402 event = EVENT_DFS_CAC_FINISHED;
1403 else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
1404 event = EVENT_DFS_CAC_ABORTED;
1405 else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
1406 event = EVENT_DFS_NOP_FINISHED;
1408 wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
1413 pos = os_strstr(param, "freq=");
1415 data.dfs_event.freq = atoi(pos + 5);
1417 pos = os_strstr(param, "ht_enabled=1");
1419 data.dfs_event.ht_enabled = 1;
1421 pos = os_strstr(param, "chan_offset=");
1423 data.dfs_event.chan_offset = atoi(pos + 12);
1425 pos = os_strstr(param, "chan_width=");
1427 data.dfs_event.chan_width = atoi(pos + 11);
1429 pos = os_strstr(param, "cf1=");
1431 data.dfs_event.cf1 = atoi(pos + 4);
1433 pos = os_strstr(param, "cf2=");
1435 data.dfs_event.cf2 = atoi(pos + 4);
1437 wpa_supplicant_event(hapd, event, &data);
1443 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data *hapd, char *cmd)
1449 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
1451 len = os_strlen(cmd);
1456 buf = os_malloc(len);
1460 if (hexstr2bin(cmd, buf, len) < 0) {
1465 res = hostapd_drv_send_mlme(hapd, buf, len, 0);
1471 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data *hapd, char *cmd)
1474 u8 src[ETH_ALEN], *buf;
1478 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
1481 used = hwaddr_aton2(pos, src);
1488 len = os_strlen(pos);
1493 buf = os_malloc(len);
1497 if (hexstr2bin(pos, buf, len) < 0) {
1502 ieee802_1x_receive(hapd, src, buf, len);
1509 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
1513 const u16 *pos = buf;
1515 for (i = 0; i < len / 2; i++)
1519 sum = (sum & 0xffff) + (sum >> 16);
1521 return sum ^ 0xffff;
1525 #define HWSIM_PACKETLEN 1500
1526 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1528 void hostapd_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
1531 struct hostapd_data *hapd = ctx;
1532 const struct ether_header *eth;
1537 if (len != HWSIM_PACKETLEN)
1540 eth = (const struct ether_header *) buf;
1541 os_memcpy(&ip, eth + 1, sizeof(ip));
1542 pos = &buf[sizeof(*eth) + sizeof(ip)];
1544 if (ip.ihl != 5 || ip.version != 4 ||
1545 ntohs(ip.tot_len) != HWSIM_IP_LEN)
1548 for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) {
1554 wpa_msg(hapd->msg_ctx, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
1555 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
1559 static int hostapd_ctrl_iface_data_test_config(struct hostapd_data *hapd,
1562 int enabled = atoi(cmd);
1567 if (hapd->l2_test) {
1568 l2_packet_deinit(hapd->l2_test);
1569 hapd->l2_test = NULL;
1570 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1571 "test data: Disabled");
1579 pos = os_strstr(cmd, " ifname=");
1583 ifname = hapd->conf->iface;
1585 hapd->l2_test = l2_packet_init(ifname, hapd->own_addr,
1586 ETHERTYPE_IP, hostapd_data_test_rx,
1588 if (hapd->l2_test == NULL)
1591 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: Enabled");
1597 static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data *hapd, char *cmd)
1599 u8 dst[ETH_ALEN], src[ETH_ALEN];
1604 u8 buf[2 + HWSIM_PACKETLEN];
1605 struct ether_header *eth;
1610 if (hapd->l2_test == NULL)
1613 /* format: <dst> <src> <tos> */
1616 used = hwaddr_aton2(pos, dst);
1622 used = hwaddr_aton2(pos, src);
1627 val = strtol(pos, NULL, 0);
1628 if (val < 0 || val > 0xff)
1632 eth = (struct ether_header *) &buf[2];
1633 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
1634 os_memcpy(eth->ether_shost, src, ETH_ALEN);
1635 eth->ether_type = htons(ETHERTYPE_IP);
1636 ip = (struct iphdr *) (eth + 1);
1637 os_memset(ip, 0, sizeof(*ip));
1642 ip->tot_len = htons(HWSIM_IP_LEN);
1644 ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
1645 ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
1646 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
1647 dpos = (u8 *) (ip + 1);
1648 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
1651 if (l2_packet_send(hapd->l2_test, dst, ETHERTYPE_IP, &buf[2],
1652 HWSIM_PACKETLEN) < 0)
1655 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX dst=" MACSTR
1656 " src=" MACSTR " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
1662 static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data *hapd,
1666 struct ether_header *eth;
1667 struct l2_packet_data *l2 = NULL;
1671 const char *ifname = hapd->conf->iface;
1673 if (os_strncmp(cmd, "ifname=", 7) == 0) {
1676 cmd = os_strchr(cmd, ' ');
1682 len = os_strlen(cmd);
1683 if (len & 1 || len < ETH_HLEN * 2)
1687 buf = os_malloc(len);
1691 if (hexstr2bin(cmd, buf, len) < 0)
1694 eth = (struct ether_header *) buf;
1695 ethertype = ntohs(eth->ether_type);
1697 l2 = l2_packet_init(ifname, hapd->own_addr, ethertype,
1698 hostapd_data_test_rx, hapd, 1);
1702 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
1703 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX frame res=%d", res);
1706 l2_packet_deinit(l2);
1709 return res < 0 ? -1 : 0;
1713 static int hostapd_ctrl_test_alloc_fail(struct hostapd_data *hapd, char *cmd)
1715 #ifdef WPA_TRACE_BFD
1716 extern char wpa_trace_fail_func[256];
1717 extern unsigned int wpa_trace_fail_after;
1720 wpa_trace_fail_after = atoi(cmd);
1721 pos = os_strchr(cmd, ':');
1724 os_strlcpy(wpa_trace_fail_func, pos,
1725 sizeof(wpa_trace_fail_func));
1727 wpa_trace_fail_after = 0;
1731 #else /* WPA_TRACE_BFD */
1733 #endif /* WPA_TRACE_BFD */
1737 static int hostapd_ctrl_get_alloc_fail(struct hostapd_data *hapd,
1738 char *buf, size_t buflen)
1740 #ifdef WPA_TRACE_BFD
1741 extern char wpa_trace_fail_func[256];
1742 extern unsigned int wpa_trace_fail_after;
1744 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
1745 wpa_trace_fail_func);
1746 #else /* WPA_TRACE_BFD */
1748 #endif /* WPA_TRACE_BFD */
1752 static int hostapd_ctrl_test_fail(struct hostapd_data *hapd, char *cmd)
1754 #ifdef WPA_TRACE_BFD
1755 extern char wpa_trace_test_fail_func[256];
1756 extern unsigned int wpa_trace_test_fail_after;
1759 wpa_trace_test_fail_after = atoi(cmd);
1760 pos = os_strchr(cmd, ':');
1763 os_strlcpy(wpa_trace_test_fail_func, pos,
1764 sizeof(wpa_trace_test_fail_func));
1766 wpa_trace_test_fail_after = 0;
1770 #else /* WPA_TRACE_BFD */
1772 #endif /* WPA_TRACE_BFD */
1776 static int hostapd_ctrl_get_fail(struct hostapd_data *hapd,
1777 char *buf, size_t buflen)
1779 #ifdef WPA_TRACE_BFD
1780 extern char wpa_trace_test_fail_func[256];
1781 extern unsigned int wpa_trace_test_fail_after;
1783 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
1784 wpa_trace_test_fail_func);
1785 #else /* WPA_TRACE_BFD */
1787 #endif /* WPA_TRACE_BFD */
1790 #endif /* CONFIG_TESTING_OPTIONS */
1793 static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface,
1797 struct csa_settings settings;
1801 ret = hostapd_parse_csa_settings(pos, &settings);
1805 for (i = 0; i < iface->num_bss; i++) {
1806 ret = hostapd_switch_channel(iface->bss[i], &settings);
1808 /* FIX: What do we do if CSA fails in the middle of
1809 * submitting multi-BSS CSA requests? */
1815 #else /* NEED_AP_MLME */
1817 #endif /* NEED_AP_MLME */
1821 static int hostapd_ctrl_iface_mib(struct hostapd_data *hapd, char *reply,
1822 int reply_size, const char *param)
1824 #ifdef RADIUS_SERVER
1825 if (os_strcmp(param, "radius_server") == 0) {
1826 return radius_server_get_mib(hapd->radius_srv, reply,
1829 #endif /* RADIUS_SERVER */
1834 static int hostapd_ctrl_iface_vendor(struct hostapd_data *hapd, char *cmd,
1835 char *buf, size_t buflen)
1840 unsigned int vendor_id, subcmd;
1841 struct wpabuf *reply;
1842 size_t data_len = 0;
1844 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
1845 vendor_id = strtoul(cmd, &pos, 16);
1849 subcmd = strtoul(pos, &pos, 10);
1852 if (!isblank(*pos++))
1854 data_len = os_strlen(pos);
1859 data = os_malloc(data_len);
1863 if (hexstr2bin(pos, data, data_len)) {
1864 wpa_printf(MSG_DEBUG,
1865 "Vendor command: wrong parameter format");
1871 reply = wpabuf_alloc((buflen - 1) / 2);
1877 ret = hostapd_drv_vendor_cmd(hapd, vendor_id, subcmd, data, data_len,
1881 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
1891 static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data *hapd,
1895 struct sta_info *sta;
1897 if (hwaddr_aton(cmd, addr))
1900 sta = ap_get_sta(hapd, addr);
1901 if (!sta || !sta->eapol_sm)
1904 eapol_auth_reauthenticate(sta->eapol_sm);
1909 static int hostapd_ctrl_iface_eapol_set(struct hostapd_data *hapd, char *cmd)
1912 struct sta_info *sta;
1913 char *pos = cmd, *param;
1915 if (hwaddr_aton(pos, addr) || pos[17] != ' ')
1919 pos = os_strchr(pos, ' ');
1924 sta = ap_get_sta(hapd, addr);
1925 if (!sta || !sta->eapol_sm)
1928 return eapol_auth_set_conf(sta->eapol_sm, param, pos);
1932 static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
1935 struct hostapd_data *hapd = eloop_ctx;
1938 struct sockaddr_un from;
1939 socklen_t fromlen = sizeof(from);
1941 const int reply_size = 4096;
1943 int level = MSG_DEBUG;
1945 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
1946 (struct sockaddr *) &from, &fromlen);
1948 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
1953 if (os_strcmp(buf, "PING") == 0)
1954 level = MSG_EXCESSIVE;
1955 wpa_hexdump_ascii(level, "RX ctrl_iface", (u8 *) buf, res);
1957 reply = os_malloc(reply_size);
1958 if (reply == NULL) {
1959 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
1961 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
1967 os_memcpy(reply, "OK\n", 3);
1970 if (os_strcmp(buf, "PING") == 0) {
1971 os_memcpy(reply, "PONG\n", 5);
1973 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
1974 if (wpa_debug_reopen_file() < 0)
1976 } else if (os_strcmp(buf, "STATUS") == 0) {
1977 reply_len = hostapd_ctrl_iface_status(hapd, reply,
1979 } else if (os_strcmp(buf, "STATUS-DRIVER") == 0) {
1980 reply_len = hostapd_drv_status(hapd, reply, reply_size);
1981 } else if (os_strcmp(buf, "MIB") == 0) {
1982 reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
1983 if (reply_len >= 0) {
1984 res = wpa_get_mib(hapd->wpa_auth, reply + reply_len,
1985 reply_size - reply_len);
1991 if (reply_len >= 0) {
1992 res = ieee802_1x_get_mib(hapd, reply + reply_len,
1993 reply_size - reply_len);
1999 #ifndef CONFIG_NO_RADIUS
2000 if (reply_len >= 0) {
2001 res = radius_client_get_mib(hapd->radius,
2003 reply_size - reply_len);
2009 #endif /* CONFIG_NO_RADIUS */
2010 } else if (os_strncmp(buf, "MIB ", 4) == 0) {
2011 reply_len = hostapd_ctrl_iface_mib(hapd, reply, reply_size,
2013 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
2014 reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
2016 } else if (os_strncmp(buf, "STA ", 4) == 0) {
2017 reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply,
2019 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
2020 reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
2022 } else if (os_strcmp(buf, "ATTACH") == 0) {
2023 if (hostapd_ctrl_iface_attach(hapd, &from, fromlen))
2025 } else if (os_strcmp(buf, "DETACH") == 0) {
2026 if (hostapd_ctrl_iface_detach(hapd, &from, fromlen))
2028 } else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
2029 if (hostapd_ctrl_iface_level(hapd, &from, fromlen,
2032 } else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
2033 if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
2035 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
2036 if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
2038 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
2039 if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
2041 } else if (os_strcmp(buf, "STOP_AP") == 0) {
2042 if (hostapd_ctrl_iface_stop_ap(hapd))
2044 #ifdef CONFIG_IEEE80211W
2046 } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
2047 if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
2049 #endif /* NEED_AP_MLME */
2050 #endif /* CONFIG_IEEE80211W */
2052 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
2053 if (hostapd_ctrl_iface_wps_pin(hapd, buf + 8))
2055 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
2056 reply_len = hostapd_ctrl_iface_wps_check_pin(
2057 hapd, buf + 14, reply, reply_size);
2058 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
2059 if (hostapd_wps_button_pushed(hapd, NULL))
2061 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
2062 if (hostapd_wps_cancel(hapd))
2064 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
2065 reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
2067 } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
2068 if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
2070 } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
2071 reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
2073 #ifdef CONFIG_WPS_NFC
2074 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
2075 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
2077 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
2078 reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
2079 hapd, buf + 21, reply, reply_size);
2080 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
2081 reply_len = hostapd_ctrl_iface_wps_nfc_token(
2082 hapd, buf + 14, reply, reply_size);
2083 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
2084 reply_len = hostapd_ctrl_iface_nfc_get_handover_sel(
2085 hapd, buf + 21, reply, reply_size);
2086 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
2087 if (hostapd_ctrl_iface_nfc_report_handover(hapd, buf + 20))
2089 #endif /* CONFIG_WPS_NFC */
2090 #endif /* CONFIG_WPS */
2091 #ifdef CONFIG_INTERWORKING
2092 } else if (os_strncmp(buf, "SET_QOS_MAP_SET ", 16) == 0) {
2093 if (hostapd_ctrl_iface_set_qos_map_set(hapd, buf + 16))
2095 } else if (os_strncmp(buf, "SEND_QOS_MAP_CONF ", 18) == 0) {
2096 if (hostapd_ctrl_iface_send_qos_map_conf(hapd, buf + 18))
2098 #endif /* CONFIG_INTERWORKING */
2100 } else if (os_strncmp(buf, "HS20_WNM_NOTIF ", 15) == 0) {
2101 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd, buf + 15))
2103 } else if (os_strncmp(buf, "HS20_DEAUTH_REQ ", 16) == 0) {
2104 if (hostapd_ctrl_iface_hs20_deauth_req(hapd, buf + 16))
2106 #endif /* CONFIG_HS20 */
2108 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
2109 if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
2111 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
2112 if (hostapd_ctrl_iface_ess_disassoc(hapd, buf + 13))
2114 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
2115 if (hostapd_ctrl_iface_bss_tm_req(hapd, buf + 11))
2117 #endif /* CONFIG_WNM */
2118 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
2119 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
2121 } else if (os_strncmp(buf, "SET ", 4) == 0) {
2122 if (hostapd_ctrl_iface_set(hapd, buf + 4))
2124 } else if (os_strncmp(buf, "GET ", 4) == 0) {
2125 reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
2127 } else if (os_strncmp(buf, "ENABLE", 6) == 0) {
2128 if (hostapd_ctrl_iface_enable(hapd->iface))
2130 } else if (os_strncmp(buf, "RELOAD", 6) == 0) {
2131 if (hostapd_ctrl_iface_reload(hapd->iface))
2133 } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
2134 if (hostapd_ctrl_iface_disable(hapd->iface))
2136 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
2137 if (ieee802_11_set_beacon(hapd))
2139 #ifdef CONFIG_TESTING_OPTIONS
2140 } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
2141 if (hostapd_ctrl_iface_radar(hapd, buf + 6))
2143 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
2144 if (hostapd_ctrl_iface_mgmt_tx(hapd, buf + 8))
2146 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
2147 if (hostapd_ctrl_iface_eapol_rx(hapd, buf + 9) < 0)
2149 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
2150 if (hostapd_ctrl_iface_data_test_config(hapd, buf + 17) < 0)
2152 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
2153 if (hostapd_ctrl_iface_data_test_tx(hapd, buf + 13) < 0)
2155 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
2156 if (hostapd_ctrl_iface_data_test_frame(hapd, buf + 16) < 0)
2158 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
2159 if (hostapd_ctrl_test_alloc_fail(hapd, buf + 16) < 0)
2161 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
2162 reply_len = hostapd_ctrl_get_alloc_fail(hapd, reply,
2164 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
2165 if (hostapd_ctrl_test_fail(hapd, buf + 10) < 0)
2167 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
2168 reply_len = hostapd_ctrl_get_fail(hapd, reply, reply_size);
2169 #endif /* CONFIG_TESTING_OPTIONS */
2170 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
2171 if (hostapd_ctrl_iface_chan_switch(hapd->iface, buf + 12))
2173 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
2174 reply_len = hostapd_ctrl_iface_vendor(hapd, buf + 7, reply,
2176 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
2177 ieee802_1x_erp_flush(hapd);
2178 #ifdef RADIUS_SERVER
2179 radius_server_erp_flush(hapd->radius_srv);
2180 #endif /* RADIUS_SERVER */
2181 } else if (os_strncmp(buf, "EAPOL_REAUTH ", 13) == 0) {
2182 if (hostapd_ctrl_iface_eapol_reauth(hapd, buf + 13))
2184 } else if (os_strncmp(buf, "EAPOL_SET ", 10) == 0) {
2185 if (hostapd_ctrl_iface_eapol_set(hapd, buf + 10))
2188 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
2192 if (reply_len < 0) {
2193 os_memcpy(reply, "FAIL\n", 5);
2196 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
2198 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
2205 static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
2210 if (hapd->conf->ctrl_interface == NULL)
2213 len = os_strlen(hapd->conf->ctrl_interface) +
2214 os_strlen(hapd->conf->iface) + 2;
2215 buf = os_malloc(len);
2219 os_snprintf(buf, len, "%s/%s",
2220 hapd->conf->ctrl_interface, hapd->conf->iface);
2221 buf[len - 1] = '\0';
2226 static void hostapd_ctrl_iface_msg_cb(void *ctx, int level,
2227 enum wpa_msg_type type,
2228 const char *txt, size_t len)
2230 struct hostapd_data *hapd = ctx;
2233 hostapd_ctrl_iface_send(hapd, level, type, txt, len);
2237 int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
2239 struct sockaddr_un addr;
2243 if (hapd->ctrl_sock > -1) {
2244 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
2248 if (hapd->conf->ctrl_interface == NULL)
2251 if (mkdir(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
2252 if (errno == EEXIST) {
2253 wpa_printf(MSG_DEBUG, "Using existing control "
2254 "interface directory.");
2256 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
2262 if (hapd->conf->ctrl_interface_gid_set &&
2263 chown(hapd->conf->ctrl_interface, -1,
2264 hapd->conf->ctrl_interface_gid) < 0) {
2265 wpa_printf(MSG_ERROR, "chown[ctrl_interface]: %s",
2270 if (!hapd->conf->ctrl_interface_gid_set &&
2271 hapd->iface->interfaces->ctrl_iface_group &&
2272 chown(hapd->conf->ctrl_interface, -1,
2273 hapd->iface->interfaces->ctrl_iface_group) < 0) {
2274 wpa_printf(MSG_ERROR, "chown[ctrl_interface]: %s",
2281 * Android is using umask 0077 which would leave the control interface
2282 * directory without group access. This breaks things since Wi-Fi
2283 * framework assumes that this directory can be accessed by other
2284 * applications in the wifi group. Fix this by adding group access even
2285 * if umask value would prevent this.
2287 if (chmod(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
2288 wpa_printf(MSG_ERROR, "CTRL: Could not chmod directory: %s",
2290 /* Try to continue anyway */
2292 #endif /* ANDROID */
2294 if (os_strlen(hapd->conf->ctrl_interface) + 1 +
2295 os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path))
2298 s = socket(PF_UNIX, SOCK_DGRAM, 0);
2300 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
2304 os_memset(&addr, 0, sizeof(addr));
2306 addr.sun_len = sizeof(addr);
2307 #endif /* __FreeBSD__ */
2308 addr.sun_family = AF_UNIX;
2309 fname = hostapd_ctrl_iface_path(hapd);
2312 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
2313 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2314 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
2316 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2317 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
2318 " allow connections - assuming it was left"
2319 "over from forced program termination");
2320 if (unlink(fname) < 0) {
2321 wpa_printf(MSG_ERROR,
2322 "Could not unlink existing ctrl_iface socket '%s': %s",
2323 fname, strerror(errno));
2326 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
2328 wpa_printf(MSG_ERROR,
2329 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
2333 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
2334 "ctrl_iface socket '%s'", fname);
2336 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
2337 "be in use - cannot override it");
2338 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
2339 "not used anymore", fname);
2346 if (hapd->conf->ctrl_interface_gid_set &&
2347 chown(fname, -1, hapd->conf->ctrl_interface_gid) < 0) {
2348 wpa_printf(MSG_ERROR, "chown[ctrl_interface/ifname]: %s",
2353 if (!hapd->conf->ctrl_interface_gid_set &&
2354 hapd->iface->interfaces->ctrl_iface_group &&
2355 chown(fname, -1, hapd->iface->interfaces->ctrl_iface_group) < 0) {
2356 wpa_printf(MSG_ERROR, "chown[ctrl_interface/ifname]: %s",
2361 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
2362 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
2368 hapd->ctrl_sock = s;
2369 if (eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
2371 hostapd_ctrl_iface_deinit(hapd);
2374 hapd->msg_ctx = hapd;
2375 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
2390 void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
2392 struct wpa_ctrl_dst *dst, *prev;
2394 if (hapd->ctrl_sock > -1) {
2396 eloop_unregister_read_sock(hapd->ctrl_sock);
2397 close(hapd->ctrl_sock);
2398 hapd->ctrl_sock = -1;
2399 fname = hostapd_ctrl_iface_path(hapd);
2404 if (hapd->conf->ctrl_interface &&
2405 rmdir(hapd->conf->ctrl_interface) < 0) {
2406 if (errno == ENOTEMPTY) {
2407 wpa_printf(MSG_DEBUG, "Control interface "
2408 "directory not empty - leaving it "
2411 wpa_printf(MSG_ERROR,
2412 "rmdir[ctrl_interface=%s]: %s",
2413 hapd->conf->ctrl_interface,
2419 dst = hapd->ctrl_dst;
2420 hapd->ctrl_dst = NULL;
2427 #ifdef CONFIG_TESTING_OPTIONS
2428 l2_packet_deinit(hapd->l2_test);
2429 hapd->l2_test = NULL;
2430 #endif /* CONFIG_TESTING_OPTIONS */
2434 static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces,
2437 if (hostapd_add_iface(interfaces, buf) < 0) {
2438 wpa_printf(MSG_ERROR, "Adding interface %s failed", buf);
2445 static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
2448 if (hostapd_remove_iface(interfaces, buf) < 0) {
2449 wpa_printf(MSG_ERROR, "Removing interface %s failed", buf);
2456 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
2457 struct sockaddr_un *from,
2460 struct wpa_ctrl_dst *dst;
2462 dst = os_zalloc(sizeof(*dst));
2465 os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
2466 dst->addrlen = fromlen;
2467 dst->debug_level = MSG_INFO;
2468 dst->next = interfaces->global_ctrl_dst;
2469 interfaces->global_ctrl_dst = dst;
2470 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached (global)",
2472 fromlen - offsetof(struct sockaddr_un, sun_path));
2477 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces,
2478 struct sockaddr_un *from,
2481 struct wpa_ctrl_dst *dst, *prev = NULL;
2483 dst = interfaces->global_ctrl_dst;
2485 if (fromlen == dst->addrlen &&
2486 os_memcmp(from->sun_path, dst->addr.sun_path,
2487 fromlen - offsetof(struct sockaddr_un, sun_path))
2489 wpa_hexdump(MSG_DEBUG,
2490 "CTRL_IFACE monitor detached (global)",
2493 offsetof(struct sockaddr_un, sun_path));
2495 interfaces->global_ctrl_dst = dst->next;
2497 prev->next = dst->next;
2508 static void hostapd_ctrl_iface_flush(struct hapd_interfaces *interfaces)
2510 #ifdef CONFIG_WPS_TESTING
2511 wps_version_number = 0x20;
2512 wps_testing_dummy_cred = 0;
2513 wps_corrupt_pkhash = 0;
2514 #endif /* CONFIG_WPS_TESTING */
2518 static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
2521 void *interfaces = eloop_ctx;
2524 struct sockaddr_un from;
2525 socklen_t fromlen = sizeof(from);
2528 const int reply_size = 4096;
2530 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
2531 (struct sockaddr *) &from, &fromlen);
2533 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
2538 wpa_printf(MSG_DEBUG, "Global ctrl_iface command: %s", buf);
2540 reply = os_malloc(reply_size);
2541 if (reply == NULL) {
2542 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
2544 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
2550 os_memcpy(reply, "OK\n", 3);
2553 if (os_strcmp(buf, "PING") == 0) {
2554 os_memcpy(reply, "PONG\n", 5);
2556 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
2557 if (wpa_debug_reopen_file() < 0)
2559 } else if (os_strcmp(buf, "FLUSH") == 0) {
2560 hostapd_ctrl_iface_flush(interfaces);
2561 } else if (os_strncmp(buf, "ADD ", 4) == 0) {
2562 if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0)
2564 } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
2565 if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
2567 } else if (os_strcmp(buf, "ATTACH") == 0) {
2568 if (hostapd_global_ctrl_iface_attach(interfaces, &from,
2571 } else if (os_strcmp(buf, "DETACH") == 0) {
2572 if (hostapd_global_ctrl_iface_detach(interfaces, &from,
2575 #ifdef CONFIG_MODULE_TESTS
2576 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
2577 int hapd_module_tests(void);
2578 if (hapd_module_tests() < 0)
2580 #endif /* CONFIG_MODULE_TESTS */
2582 wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
2587 if (reply_len < 0) {
2588 os_memcpy(reply, "FAIL\n", 5);
2592 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
2594 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
2601 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces *interface)
2606 if (interface->global_iface_path == NULL)
2609 len = os_strlen(interface->global_iface_path) +
2610 os_strlen(interface->global_iface_name) + 2;
2611 buf = os_malloc(len);
2615 os_snprintf(buf, len, "%s/%s", interface->global_iface_path,
2616 interface->global_iface_name);
2617 buf[len - 1] = '\0';
2622 int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
2624 struct sockaddr_un addr;
2628 if (interface->global_iface_path == NULL) {
2629 wpa_printf(MSG_DEBUG, "ctrl_iface not configured!");
2633 if (mkdir(interface->global_iface_path, S_IRWXU | S_IRWXG) < 0) {
2634 if (errno == EEXIST) {
2635 wpa_printf(MSG_DEBUG, "Using existing control "
2636 "interface directory.");
2638 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
2642 } else if (interface->ctrl_iface_group &&
2643 chown(interface->global_iface_path, -1,
2644 interface->ctrl_iface_group) < 0) {
2645 wpa_printf(MSG_ERROR, "chown[ctrl_interface]: %s",
2650 if (os_strlen(interface->global_iface_path) + 1 +
2651 os_strlen(interface->global_iface_name) >= sizeof(addr.sun_path))
2654 s = socket(PF_UNIX, SOCK_DGRAM, 0);
2656 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
2660 os_memset(&addr, 0, sizeof(addr));
2662 addr.sun_len = sizeof(addr);
2663 #endif /* __FreeBSD__ */
2664 addr.sun_family = AF_UNIX;
2665 fname = hostapd_global_ctrl_iface_path(interface);
2668 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
2669 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2670 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
2672 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
2673 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
2674 " allow connections - assuming it was left"
2675 "over from forced program termination");
2676 if (unlink(fname) < 0) {
2677 wpa_printf(MSG_ERROR,
2678 "Could not unlink existing ctrl_iface socket '%s': %s",
2679 fname, strerror(errno));
2682 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
2684 wpa_printf(MSG_ERROR, "bind(PF_UNIX): %s",
2688 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
2689 "ctrl_iface socket '%s'", fname);
2691 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
2692 "be in use - cannot override it");
2693 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
2694 "not used anymore", fname);
2701 if (interface->ctrl_iface_group &&
2702 chown(fname, -1, interface->ctrl_iface_group) < 0) {
2703 wpa_printf(MSG_ERROR, "chown[ctrl_interface]: %s",
2708 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
2709 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
2715 interface->global_ctrl_sock = s;
2716 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
2732 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
2735 struct wpa_ctrl_dst *dst, *prev;
2737 if (interfaces->global_ctrl_sock > -1) {
2738 eloop_unregister_read_sock(interfaces->global_ctrl_sock);
2739 close(interfaces->global_ctrl_sock);
2740 interfaces->global_ctrl_sock = -1;
2741 fname = hostapd_global_ctrl_iface_path(interfaces);
2747 if (interfaces->global_iface_path &&
2748 rmdir(interfaces->global_iface_path) < 0) {
2749 if (errno == ENOTEMPTY) {
2750 wpa_printf(MSG_DEBUG, "Control interface "
2751 "directory not empty - leaving it "
2754 wpa_printf(MSG_ERROR,
2755 "rmdir[ctrl_interface=%s]: %s",
2756 interfaces->global_iface_path,
2762 os_free(interfaces->global_iface_path);
2763 interfaces->global_iface_path = NULL;
2765 dst = interfaces->global_ctrl_dst;
2766 interfaces->global_ctrl_dst = NULL;
2775 static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
2776 enum wpa_msg_type type,
2777 const char *buf, size_t len)
2779 struct wpa_ctrl_dst *dst, *next;
2786 if (type != WPA_MSG_ONLY_GLOBAL) {
2787 s = hapd->ctrl_sock;
2788 dst = hapd->ctrl_dst;
2790 s = hapd->iface->interfaces->global_ctrl_sock;
2791 dst = hapd->iface->interfaces->global_ctrl_dst;
2794 if (s < 0 || dst == NULL)
2797 os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
2798 io[0].iov_base = levelstr;
2799 io[0].iov_len = os_strlen(levelstr);
2800 io[1].iov_base = (char *) buf;
2801 io[1].iov_len = len;
2802 os_memset(&msg, 0, sizeof(msg));
2809 if (level >= dst->debug_level) {
2810 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
2811 (u8 *) dst->addr.sun_path, dst->addrlen -
2812 offsetof(struct sockaddr_un, sun_path));
2813 msg.msg_name = &dst->addr;
2814 msg.msg_namelen = dst->addrlen;
2815 if (sendmsg(s, &msg, 0) < 0) {
2817 wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
2819 idx, errno, strerror(errno));
2821 if (dst->errors > 10 || _errno == ENOENT) {
2822 if (type != WPA_MSG_ONLY_GLOBAL)
2823 hostapd_ctrl_iface_detach(
2827 hostapd_global_ctrl_iface_detach(
2828 hapd->iface->interfaces,
2840 #endif /* CONFIG_NATIVE_WINDOWS */