2 * hostapd / UNIX domain socket -based control interface
3 * Copyright (c) 2004-2014, 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 "radius/radius_server.h"
24 #include "ap/hostapd.h"
25 #include "ap/ap_config.h"
26 #include "ap/ieee802_1x.h"
27 #include "ap/wpa_auth.h"
28 #include "ap/ieee802_11.h"
29 #include "ap/sta_info.h"
30 #include "ap/wps_hostapd.h"
31 #include "ap/ctrl_iface_ap.h"
32 #include "ap/ap_drv_ops.h"
33 #include "ap/wnm_ap.h"
34 #include "ap/wpa_auth.h"
35 #include "wps/wps_defs.h"
37 #include "config_file.h"
38 #include "ctrl_iface.h"
42 struct wpa_ctrl_dst *next;
43 struct sockaddr_un addr;
50 static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
51 const char *buf, size_t len);
54 static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
55 struct sockaddr_un *from,
58 struct wpa_ctrl_dst *dst;
60 dst = os_zalloc(sizeof(*dst));
63 os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
64 dst->addrlen = fromlen;
65 dst->debug_level = MSG_INFO;
66 dst->next = hapd->ctrl_dst;
68 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached",
69 (u8 *) from->sun_path,
70 fromlen - offsetof(struct sockaddr_un, sun_path));
75 static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
76 struct sockaddr_un *from,
79 struct wpa_ctrl_dst *dst, *prev = NULL;
83 if (fromlen == dst->addrlen &&
84 os_memcmp(from->sun_path, dst->addr.sun_path,
85 fromlen - offsetof(struct sockaddr_un, sun_path))
87 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor detached",
88 (u8 *) from->sun_path,
90 offsetof(struct sockaddr_un, sun_path));
92 hapd->ctrl_dst = dst->next;
94 prev->next = dst->next;
105 static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
106 struct sockaddr_un *from,
110 struct wpa_ctrl_dst *dst;
112 wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", level);
114 dst = hapd->ctrl_dst;
116 if (fromlen == dst->addrlen &&
117 os_memcmp(from->sun_path, dst->addr.sun_path,
118 fromlen - offsetof(struct sockaddr_un, sun_path))
120 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE changed monitor "
121 "level", (u8 *) from->sun_path, fromlen -
122 offsetof(struct sockaddr_un, sun_path));
123 dst->debug_level = atoi(level);
133 static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
137 struct sta_info *sta;
139 wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
141 if (hwaddr_aton(txtaddr, addr))
144 sta = ap_get_sta(hapd, addr);
148 wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
149 "notification", MAC2STR(addr));
150 sta = ap_sta_add(hapd, addr);
154 hostapd_new_assoc_sta(hapd, sta, 0);
159 #ifdef CONFIG_IEEE80211W
161 static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
165 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
167 wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
169 if (hwaddr_aton(txtaddr, addr) ||
170 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
173 ieee802_11_send_sa_query_req(hapd, addr, trans_id);
177 #endif /* NEED_AP_MLME */
178 #endif /* CONFIG_IEEE80211W */
182 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
184 char *pin = os_strchr(txt, ' ');
187 u8 addr_buf[ETH_ALEN], *addr = NULL;
194 timeout_txt = os_strchr(pin, ' ');
196 *timeout_txt++ = '\0';
197 timeout = atoi(timeout_txt);
198 pos = os_strchr(timeout_txt, ' ');
201 if (hwaddr_aton(pos, addr_buf) == 0)
207 return hostapd_wps_add_pin(hapd, addr, txt, pin, timeout);
211 static int hostapd_ctrl_iface_wps_check_pin(
212 struct hostapd_data *hapd, char *cmd, char *buf, size_t buflen)
219 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
220 (u8 *) cmd, os_strlen(cmd));
221 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
222 if (*pos < '0' || *pos > '9')
226 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
230 if (len != 4 && len != 8) {
231 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
237 unsigned int pin_val;
239 if (!wps_pin_valid(pin_val)) {
240 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
241 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
242 if (ret < 0 || (size_t) ret >= buflen)
248 ret = os_snprintf(buf, buflen, "%s", pin);
249 if (ret < 0 || (size_t) ret >= buflen)
256 #ifdef CONFIG_WPS_NFC
257 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
264 len = os_strlen(pos);
269 buf = wpabuf_alloc(len);
272 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
277 ret = hostapd_wps_nfc_tag_read(hapd, buf);
284 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
285 char *cmd, char *reply,
292 if (os_strcmp(cmd, "WPS") == 0)
294 else if (os_strcmp(cmd, "NDEF") == 0)
299 buf = hostapd_wps_nfc_config_token(hapd, ndef);
303 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
314 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data *hapd,
315 char *reply, size_t max_len,
321 buf = hostapd_wps_nfc_token_gen(hapd, ndef);
325 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
336 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data *hapd,
337 char *cmd, char *reply,
340 if (os_strcmp(cmd, "WPS") == 0)
341 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
344 if (os_strcmp(cmd, "NDEF") == 0)
345 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
348 if (os_strcmp(cmd, "enable") == 0)
349 return hostapd_wps_nfc_token_enable(hapd);
351 if (os_strcmp(cmd, "disable") == 0) {
352 hostapd_wps_nfc_token_disable(hapd);
360 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data *hapd,
361 char *cmd, char *reply,
369 pos = os_strchr(cmd, ' ');
374 if (os_strcmp(cmd, "WPS") == 0)
376 else if (os_strcmp(cmd, "NDEF") == 0)
381 if (os_strcmp(pos, "WPS-CR") == 0)
382 buf = hostapd_wps_nfc_hs_cr(hapd, ndef);
388 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
399 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data *hapd,
403 struct wpabuf *req, *sel;
405 char *pos, *role, *type, *pos2;
408 pos = os_strchr(role, ' ');
414 pos = os_strchr(type, ' ');
419 pos2 = os_strchr(pos, ' ');
424 len = os_strlen(pos);
429 req = wpabuf_alloc(len);
432 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
437 len = os_strlen(pos2);
444 sel = wpabuf_alloc(len);
449 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
455 if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) {
456 ret = hostapd_wps_nfc_report_handover(hapd, req, sel);
458 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
459 "reported: role=%s type=%s", role, type);
468 #endif /* CONFIG_WPS_NFC */
471 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
472 char *buf, size_t buflen)
478 pos = os_strchr(txt, ' ');
482 if (os_strcmp(txt, "disable") == 0) {
483 hostapd_wps_ap_pin_disable(hapd);
484 return os_snprintf(buf, buflen, "OK\n");
487 if (os_strcmp(txt, "random") == 0) {
490 pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
493 return os_snprintf(buf, buflen, "%s", pin_txt);
496 if (os_strcmp(txt, "get") == 0) {
497 pin_txt = hostapd_wps_ap_pin_get(hapd);
500 return os_snprintf(buf, buflen, "%s", pin_txt);
503 if (os_strcmp(txt, "set") == 0) {
508 pos = os_strchr(pos, ' ');
513 if (os_strlen(pin) > buflen)
515 if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
517 return os_snprintf(buf, buflen, "%s", pin);
524 static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
527 char *ssid, *auth, *encr = NULL, *key = NULL;
530 pos = os_strchr(txt, ' ');
536 pos = os_strchr(pos, ' ');
540 pos = os_strchr(pos, ' ');
547 return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
551 static const char * pbc_status_str(enum pbc_status status)
554 case WPS_PBC_STATUS_DISABLE:
556 case WPS_PBC_STATUS_ACTIVE:
558 case WPS_PBC_STATUS_TIMEOUT:
560 case WPS_PBC_STATUS_OVERLAP:
568 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
569 char *buf, size_t buflen)
577 ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
578 pbc_status_str(hapd->wps_stats.pbc_status));
580 if (ret < 0 || ret >= end - pos)
584 ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
585 (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
587 (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
588 "Failed" : "None")));
590 if (ret < 0 || ret >= end - pos)
594 /* If status == Failure - Add possible Reasons */
595 if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
596 hapd->wps_stats.failure_reason > 0) {
597 ret = os_snprintf(pos, end - pos,
598 "Failure Reason: %s\n",
599 wps_ei_str(hapd->wps_stats.failure_reason));
601 if (ret < 0 || ret >= end - pos)
606 if (hapd->wps_stats.status) {
607 ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
608 MAC2STR(hapd->wps_stats.peer_addr));
610 if (ret < 0 || ret >= end - pos)
618 #endif /* CONFIG_WPS */
621 #ifdef CONFIG_INTERWORKING
623 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data *hapd,
626 u8 qos_map_set[16 + 2 * 21], count = 0;
627 const char *pos = cmd;
631 if (count == sizeof(qos_map_set)) {
632 wpa_printf(MSG_ERROR, "Too many qos_map_set parameters");
637 if (val < 0 || val > 255) {
638 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
642 qos_map_set[count++] = val;
643 pos = os_strchr(pos, ',');
649 if (count < 16 || count & 1) {
650 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
654 ret = hostapd_drv_set_qos_map(hapd, qos_map_set, count);
656 wpa_printf(MSG_INFO, "Failed to set QoS Map Set");
660 os_memcpy(hapd->conf->qos_map_set, qos_map_set, count);
661 hapd->conf->qos_map_set_len = count;
667 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
671 struct sta_info *sta;
673 u8 *qos_map_set = hapd->conf->qos_map_set;
674 u8 qos_map_set_len = hapd->conf->qos_map_set_len;
677 if (!qos_map_set_len) {
678 wpa_printf(MSG_INFO, "QoS Map Set is not set");
682 if (hwaddr_aton(cmd, addr))
685 sta = ap_get_sta(hapd, addr);
687 wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
688 "for QoS Map Configuration message",
693 if (!sta->qos_map_enabled) {
694 wpa_printf(MSG_DEBUG, "Station " MACSTR " did not indicate "
695 "support for QoS Map", MAC2STR(addr));
699 buf = wpabuf_alloc(2 + 2 + qos_map_set_len);
703 wpabuf_put_u8(buf, WLAN_ACTION_QOS);
704 wpabuf_put_u8(buf, QOS_QOS_MAP_CONFIG);
706 /* QoS Map Set Element */
707 wpabuf_put_u8(buf, WLAN_EID_QOS_MAP_SET);
708 wpabuf_put_u8(buf, qos_map_set_len);
709 wpabuf_put_data(buf, qos_map_set, qos_map_set_len);
711 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
712 wpabuf_head(buf), wpabuf_len(buf));
718 #endif /* CONFIG_INTERWORKING */
723 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data *hapd,
728 struct sta_info *sta;
730 if (hwaddr_aton(cmd, addr))
734 disassoc_timer = atoi(cmd + 17);
736 sta = ap_get_sta(hapd, addr);
738 wpa_printf(MSG_DEBUG, "Station " MACSTR
739 " not found for disassociation imminent message",
744 return wnm_send_disassoc_imminent(hapd, sta, disassoc_timer);
748 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
752 const char *url, *timerstr;
754 struct sta_info *sta;
756 if (hwaddr_aton(cmd, addr))
759 sta = ap_get_sta(hapd, addr);
761 wpa_printf(MSG_DEBUG, "Station " MACSTR
762 " not found for ESS disassociation imminent message",
768 if (*timerstr != ' ')
771 disassoc_timer = atoi(timerstr);
772 if (disassoc_timer < 0 || disassoc_timer > 65535)
775 url = os_strchr(timerstr, ' ');
780 return wnm_send_ess_disassoc_imminent(hapd, sta, url, disassoc_timer);
783 #endif /* CONFIG_WNM */
786 static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
787 char *buf, size_t buflen)
795 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
797 MAC2STR(hapd->own_addr),
798 wpa_ssid_txt(hapd->conf->ssid.ssid,
799 hapd->conf->ssid.ssid_len));
800 if (ret < 0 || ret >= end - pos)
805 ret = os_snprintf(pos, end - pos, "wps_state=%s\n",
806 hapd->conf->wps_state == 0 ? "disabled" :
807 (hapd->conf->wps_state == 1 ? "not configured" :
809 if (ret < 0 || ret >= end - pos)
813 if (hapd->conf->wps_state && hapd->conf->wpa &&
814 hapd->conf->ssid.wpa_passphrase) {
815 ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
816 hapd->conf->ssid.wpa_passphrase);
817 if (ret < 0 || ret >= end - pos)
822 if (hapd->conf->wps_state && hapd->conf->wpa &&
823 hapd->conf->ssid.wpa_psk &&
824 hapd->conf->ssid.wpa_psk->group) {
825 char hex[PMK_LEN * 2 + 1];
826 wpa_snprintf_hex(hex, sizeof(hex),
827 hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
828 ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
829 if (ret < 0 || ret >= end - pos)
833 #endif /* CONFIG_WPS */
835 if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
836 ret = os_snprintf(pos, end - pos, "key_mgmt=");
837 if (ret < 0 || ret >= end - pos)
841 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
842 ret = os_snprintf(pos, end - pos, "WPA-PSK ");
843 if (ret < 0 || ret >= end - pos)
847 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
848 ret = os_snprintf(pos, end - pos, "WPA-EAP ");
849 if (ret < 0 || ret >= end - pos)
853 #ifdef CONFIG_IEEE80211R
854 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
855 ret = os_snprintf(pos, end - pos, "FT-PSK ");
856 if (ret < 0 || ret >= end - pos)
860 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
861 ret = os_snprintf(pos, end - pos, "FT-EAP ");
862 if (ret < 0 || ret >= end - pos)
866 #endif /* CONFIG_IEEE80211R */
867 #ifdef CONFIG_IEEE80211W
868 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
869 ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
870 if (ret < 0 || ret >= end - pos)
874 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
875 ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
876 if (ret < 0 || ret >= end - pos)
880 #endif /* CONFIG_IEEE80211W */
882 ret = os_snprintf(pos, end - pos, "\n");
883 if (ret < 0 || ret >= end - pos)
888 if (hapd->conf->wpa) {
889 ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
890 wpa_cipher_txt(hapd->conf->wpa_group));
891 if (ret < 0 || ret >= end - pos)
896 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
897 ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
898 if (ret < 0 || ret >= end - pos)
902 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
908 ret = os_snprintf(pos, end - pos, "\n");
909 if (ret < 0 || ret >= end - pos)
914 if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
915 ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
916 if (ret < 0 || ret >= end - pos)
920 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
926 ret = os_snprintf(pos, end - pos, "\n");
927 if (ret < 0 || ret >= end - pos)
936 static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
941 value = os_strchr(cmd, ' ');
946 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
948 #ifdef CONFIG_WPS_TESTING
949 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
951 val = strtol(value, NULL, 0);
952 if (val < 0 || val > 0xff) {
954 wpa_printf(MSG_DEBUG, "WPS: Invalid "
955 "wps_version_number %ld", val);
957 wps_version_number = val;
958 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
960 (wps_version_number & 0xf0) >> 4,
961 wps_version_number & 0x0f);
962 hostapd_wps_update_ie(hapd);
964 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
965 wps_testing_dummy_cred = atoi(value);
966 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
967 wps_testing_dummy_cred);
968 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
969 wps_corrupt_pkhash = atoi(value);
970 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
972 #endif /* CONFIG_WPS_TESTING */
973 #ifdef CONFIG_INTERWORKING
974 } else if (os_strcasecmp(cmd, "gas_frag_limit") == 0) {
975 int val = atoi(value);
979 hapd->gas_frag_limit = val;
980 #endif /* CONFIG_INTERWORKING */
981 #ifdef CONFIG_TESTING_OPTIONS
982 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
983 hapd->ext_mgmt_frame_handling = atoi(value);
984 #endif /* CONFIG_TESTING_OPTIONS */
986 ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value);
993 static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
994 char *buf, size_t buflen)
998 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
1000 if (os_strcmp(cmd, "version") == 0) {
1001 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
1002 if (res < 0 || (unsigned int) res >= buflen)
1011 static int hostapd_ctrl_iface_enable(struct hostapd_iface *iface)
1013 if (hostapd_enable_iface(iface) < 0) {
1014 wpa_printf(MSG_ERROR, "Enabling of interface failed");
1021 static int hostapd_ctrl_iface_reload(struct hostapd_iface *iface)
1023 if (hostapd_reload_iface(iface) < 0) {
1024 wpa_printf(MSG_ERROR, "Reloading of interface failed");
1031 static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
1033 if (hostapd_disable_iface(iface) < 0) {
1034 wpa_printf(MSG_ERROR, "Disabling of interface failed");
1041 #ifdef CONFIG_TESTING_OPTIONS
1043 static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
1045 union wpa_event_data data;
1047 enum wpa_event_type event;
1049 wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
1051 os_memset(&data, 0, sizeof(data));
1053 param = os_strchr(cmd, ' ');
1058 if (os_strcmp(cmd, "DETECTED") == 0)
1059 event = EVENT_DFS_RADAR_DETECTED;
1060 else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
1061 event = EVENT_DFS_CAC_FINISHED;
1062 else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
1063 event = EVENT_DFS_CAC_ABORTED;
1064 else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
1065 event = EVENT_DFS_NOP_FINISHED;
1067 wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
1072 pos = os_strstr(param, "freq=");
1074 data.dfs_event.freq = atoi(pos + 5);
1076 pos = os_strstr(param, "ht_enabled=1");
1078 data.dfs_event.ht_enabled = 1;
1080 pos = os_strstr(param, "chan_offset=");
1082 data.dfs_event.chan_offset = atoi(pos + 12);
1084 pos = os_strstr(param, "chan_width=");
1086 data.dfs_event.chan_width = atoi(pos + 11);
1088 pos = os_strstr(param, "cf1=");
1090 data.dfs_event.cf1 = atoi(pos + 4);
1092 pos = os_strstr(param, "cf2=");
1094 data.dfs_event.cf2 = atoi(pos + 4);
1096 wpa_supplicant_event(hapd, event, &data);
1102 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data *hapd, char *cmd)
1108 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
1110 len = os_strlen(cmd);
1115 buf = os_malloc(len);
1119 if (hexstr2bin(cmd, buf, len) < 0) {
1124 res = hostapd_drv_send_mlme(hapd, buf, len, 0);
1129 #endif /* CONFIG_TESTING_OPTIONS */
1132 static int hostapd_ctrl_iface_chan_switch(struct hostapd_data *hapd, char *pos)
1135 struct csa_settings settings;
1136 int ret = hostapd_parse_csa_settings(pos, &settings);
1141 return hostapd_switch_channel(hapd, &settings);
1142 #else /* NEED_AP_MLME */
1144 #endif /* NEED_AP_MLME */
1148 static int hostapd_ctrl_iface_mib(struct hostapd_data *hapd, char *reply,
1149 int reply_size, const char *param)
1151 #ifdef RADIUS_SERVER
1152 if (os_strcmp(param, "radius_server") == 0) {
1153 return radius_server_get_mib(hapd->radius_srv, reply,
1156 #endif /* RADIUS_SERVER */
1161 static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
1164 struct hostapd_data *hapd = eloop_ctx;
1167 struct sockaddr_un from;
1168 socklen_t fromlen = sizeof(from);
1170 const int reply_size = 4096;
1172 int level = MSG_DEBUG;
1174 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
1175 (struct sockaddr *) &from, &fromlen);
1177 perror("recvfrom(ctrl_iface)");
1181 if (os_strcmp(buf, "PING") == 0)
1182 level = MSG_EXCESSIVE;
1183 wpa_hexdump_ascii(level, "RX ctrl_iface", (u8 *) buf, res);
1185 reply = os_malloc(reply_size);
1186 if (reply == NULL) {
1187 sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
1192 os_memcpy(reply, "OK\n", 3);
1195 if (os_strcmp(buf, "PING") == 0) {
1196 os_memcpy(reply, "PONG\n", 5);
1198 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
1199 if (wpa_debug_reopen_file() < 0)
1201 } else if (os_strcmp(buf, "STATUS") == 0) {
1202 reply_len = hostapd_ctrl_iface_status(hapd, reply,
1204 } else if (os_strcmp(buf, "STATUS-DRIVER") == 0) {
1205 reply_len = hostapd_drv_status(hapd, reply, reply_size);
1206 } else if (os_strcmp(buf, "MIB") == 0) {
1207 reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
1208 if (reply_len >= 0) {
1209 res = wpa_get_mib(hapd->wpa_auth, reply + reply_len,
1210 reply_size - reply_len);
1216 if (reply_len >= 0) {
1217 res = ieee802_1x_get_mib(hapd, reply + reply_len,
1218 reply_size - reply_len);
1224 #ifndef CONFIG_NO_RADIUS
1225 if (reply_len >= 0) {
1226 res = radius_client_get_mib(hapd->radius,
1228 reply_size - reply_len);
1234 #endif /* CONFIG_NO_RADIUS */
1235 } else if (os_strncmp(buf, "MIB ", 4) == 0) {
1236 reply_len = hostapd_ctrl_iface_mib(hapd, reply, reply_size,
1238 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
1239 reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
1241 } else if (os_strncmp(buf, "STA ", 4) == 0) {
1242 reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply,
1244 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
1245 reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
1247 } else if (os_strcmp(buf, "ATTACH") == 0) {
1248 if (hostapd_ctrl_iface_attach(hapd, &from, fromlen))
1250 } else if (os_strcmp(buf, "DETACH") == 0) {
1251 if (hostapd_ctrl_iface_detach(hapd, &from, fromlen))
1253 } else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
1254 if (hostapd_ctrl_iface_level(hapd, &from, fromlen,
1257 } else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
1258 if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
1260 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
1261 if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
1263 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
1264 if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
1266 #ifdef CONFIG_IEEE80211W
1268 } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
1269 if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
1271 #endif /* NEED_AP_MLME */
1272 #endif /* CONFIG_IEEE80211W */
1274 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
1275 if (hostapd_ctrl_iface_wps_pin(hapd, buf + 8))
1277 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
1278 reply_len = hostapd_ctrl_iface_wps_check_pin(
1279 hapd, buf + 14, reply, reply_size);
1280 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
1281 if (hostapd_wps_button_pushed(hapd, NULL))
1283 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
1284 if (hostapd_wps_cancel(hapd))
1286 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
1287 reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
1289 } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
1290 if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
1292 } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
1293 reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
1295 #ifdef CONFIG_WPS_NFC
1296 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
1297 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
1299 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
1300 reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
1301 hapd, buf + 21, reply, reply_size);
1302 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
1303 reply_len = hostapd_ctrl_iface_wps_nfc_token(
1304 hapd, buf + 14, reply, reply_size);
1305 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
1306 reply_len = hostapd_ctrl_iface_nfc_get_handover_sel(
1307 hapd, buf + 21, reply, reply_size);
1308 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
1309 if (hostapd_ctrl_iface_nfc_report_handover(hapd, buf + 20))
1311 #endif /* CONFIG_WPS_NFC */
1312 #endif /* CONFIG_WPS */
1313 #ifdef CONFIG_INTERWORKING
1314 } else if (os_strncmp(buf, "SET_QOS_MAP_SET ", 16) == 0) {
1315 if (hostapd_ctrl_iface_set_qos_map_set(hapd, buf + 16))
1317 } else if (os_strncmp(buf, "SEND_QOS_MAP_CONF ", 18) == 0) {
1318 if (hostapd_ctrl_iface_send_qos_map_conf(hapd, buf + 18))
1320 #endif /* CONFIG_INTERWORKING */
1322 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
1323 if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
1325 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
1326 if (hostapd_ctrl_iface_ess_disassoc(hapd, buf + 13))
1328 #endif /* CONFIG_WNM */
1329 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
1330 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
1332 } else if (os_strncmp(buf, "SET ", 4) == 0) {
1333 if (hostapd_ctrl_iface_set(hapd, buf + 4))
1335 } else if (os_strncmp(buf, "GET ", 4) == 0) {
1336 reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
1338 } else if (os_strncmp(buf, "ENABLE", 6) == 0) {
1339 if (hostapd_ctrl_iface_enable(hapd->iface))
1341 } else if (os_strncmp(buf, "RELOAD", 6) == 0) {
1342 if (hostapd_ctrl_iface_reload(hapd->iface))
1344 } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
1345 if (hostapd_ctrl_iface_disable(hapd->iface))
1347 #ifdef CONFIG_TESTING_OPTIONS
1348 } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
1349 if (hostapd_ctrl_iface_radar(hapd, buf + 6))
1351 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
1352 if (hostapd_ctrl_iface_mgmt_tx(hapd, buf + 8))
1354 #endif /* CONFIG_TESTING_OPTIONS */
1355 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
1356 if (hostapd_ctrl_iface_chan_switch(hapd, buf + 12))
1359 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
1363 if (reply_len < 0) {
1364 os_memcpy(reply, "FAIL\n", 5);
1367 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1372 static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
1377 if (hapd->conf->ctrl_interface == NULL)
1380 len = os_strlen(hapd->conf->ctrl_interface) +
1381 os_strlen(hapd->conf->iface) + 2;
1382 buf = os_malloc(len);
1386 os_snprintf(buf, len, "%s/%s",
1387 hapd->conf->ctrl_interface, hapd->conf->iface);
1388 buf[len - 1] = '\0';
1393 static void hostapd_ctrl_iface_msg_cb(void *ctx, int level, int global,
1394 const char *txt, size_t len)
1396 struct hostapd_data *hapd = ctx;
1399 hostapd_ctrl_iface_send(hapd, level, txt, len);
1403 int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
1405 struct sockaddr_un addr;
1409 if (hapd->ctrl_sock > -1) {
1410 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
1414 if (hapd->conf->ctrl_interface == NULL)
1417 if (mkdir(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
1418 if (errno == EEXIST) {
1419 wpa_printf(MSG_DEBUG, "Using existing control "
1420 "interface directory.");
1422 perror("mkdir[ctrl_interface]");
1427 if (hapd->conf->ctrl_interface_gid_set &&
1428 chown(hapd->conf->ctrl_interface, -1,
1429 hapd->conf->ctrl_interface_gid) < 0) {
1430 perror("chown[ctrl_interface]");
1434 if (!hapd->conf->ctrl_interface_gid_set &&
1435 hapd->iface->interfaces->ctrl_iface_group &&
1436 chown(hapd->conf->ctrl_interface, -1,
1437 hapd->iface->interfaces->ctrl_iface_group) < 0) {
1438 perror("chown[ctrl_interface]");
1444 * Android is using umask 0077 which would leave the control interface
1445 * directory without group access. This breaks things since Wi-Fi
1446 * framework assumes that this directory can be accessed by other
1447 * applications in the wifi group. Fix this by adding group access even
1448 * if umask value would prevent this.
1450 if (chmod(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
1451 wpa_printf(MSG_ERROR, "CTRL: Could not chmod directory: %s",
1453 /* Try to continue anyway */
1455 #endif /* ANDROID */
1457 if (os_strlen(hapd->conf->ctrl_interface) + 1 +
1458 os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path))
1461 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1463 perror("socket(PF_UNIX)");
1467 os_memset(&addr, 0, sizeof(addr));
1469 addr.sun_len = sizeof(addr);
1470 #endif /* __FreeBSD__ */
1471 addr.sun_family = AF_UNIX;
1472 fname = hostapd_ctrl_iface_path(hapd);
1475 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
1476 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1477 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
1479 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1480 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1481 " allow connections - assuming it was left"
1482 "over from forced program termination");
1483 if (unlink(fname) < 0) {
1484 perror("unlink[ctrl_iface]");
1485 wpa_printf(MSG_ERROR, "Could not unlink "
1486 "existing ctrl_iface socket '%s'",
1490 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1492 perror("hostapd-ctrl-iface: bind(PF_UNIX)");
1495 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1496 "ctrl_iface socket '%s'", fname);
1498 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1499 "be in use - cannot override it");
1500 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1501 "not used anymore", fname);
1508 if (hapd->conf->ctrl_interface_gid_set &&
1509 chown(fname, -1, hapd->conf->ctrl_interface_gid) < 0) {
1510 perror("chown[ctrl_interface/ifname]");
1514 if (!hapd->conf->ctrl_interface_gid_set &&
1515 hapd->iface->interfaces->ctrl_iface_group &&
1516 chown(fname, -1, hapd->iface->interfaces->ctrl_iface_group) < 0) {
1517 perror("chown[ctrl_interface/ifname]");
1521 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
1522 perror("chmod[ctrl_interface/ifname]");
1527 hapd->ctrl_sock = s;
1528 eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
1530 hapd->msg_ctx = hapd;
1531 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
1546 void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
1548 struct wpa_ctrl_dst *dst, *prev;
1550 if (hapd->ctrl_sock > -1) {
1552 eloop_unregister_read_sock(hapd->ctrl_sock);
1553 close(hapd->ctrl_sock);
1554 hapd->ctrl_sock = -1;
1555 fname = hostapd_ctrl_iface_path(hapd);
1560 if (hapd->conf->ctrl_interface &&
1561 rmdir(hapd->conf->ctrl_interface) < 0) {
1562 if (errno == ENOTEMPTY) {
1563 wpa_printf(MSG_DEBUG, "Control interface "
1564 "directory not empty - leaving it "
1567 wpa_printf(MSG_ERROR,
1568 "rmdir[ctrl_interface=%s]: %s",
1569 hapd->conf->ctrl_interface,
1575 dst = hapd->ctrl_dst;
1584 static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces,
1587 if (hostapd_add_iface(interfaces, buf) < 0) {
1588 wpa_printf(MSG_ERROR, "Adding interface %s failed", buf);
1595 static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
1598 if (hostapd_remove_iface(interfaces, buf) < 0) {
1599 wpa_printf(MSG_ERROR, "Removing interface %s failed", buf);
1606 static void hostapd_ctrl_iface_flush(struct hapd_interfaces *interfaces)
1608 #ifdef CONFIG_WPS_TESTING
1609 wps_version_number = 0x20;
1610 wps_testing_dummy_cred = 0;
1611 wps_corrupt_pkhash = 0;
1612 #endif /* CONFIG_WPS_TESTING */
1616 static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
1619 void *interfaces = eloop_ctx;
1622 struct sockaddr_un from;
1623 socklen_t fromlen = sizeof(from);
1627 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
1628 (struct sockaddr *) &from, &fromlen);
1630 perror("recvfrom(ctrl_iface)");
1634 wpa_printf(MSG_DEBUG, "Global ctrl_iface command: %s", buf);
1636 os_memcpy(reply, "OK\n", 3);
1639 if (os_strcmp(buf, "PING") == 0) {
1640 os_memcpy(reply, "PONG\n", 5);
1642 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
1643 if (wpa_debug_reopen_file() < 0)
1645 } else if (os_strcmp(buf, "FLUSH") == 0) {
1646 hostapd_ctrl_iface_flush(interfaces);
1647 } else if (os_strncmp(buf, "ADD ", 4) == 0) {
1648 if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0)
1650 } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
1651 if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
1654 wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
1659 if (reply_len < 0) {
1660 os_memcpy(reply, "FAIL\n", 5);
1664 sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen);
1668 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces *interface)
1673 if (interface->global_iface_path == NULL)
1676 len = os_strlen(interface->global_iface_path) +
1677 os_strlen(interface->global_iface_name) + 2;
1678 buf = os_malloc(len);
1682 os_snprintf(buf, len, "%s/%s", interface->global_iface_path,
1683 interface->global_iface_name);
1684 buf[len - 1] = '\0';
1689 int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
1691 struct sockaddr_un addr;
1695 if (interface->global_iface_path == NULL) {
1696 wpa_printf(MSG_DEBUG, "ctrl_iface not configured!");
1700 if (mkdir(interface->global_iface_path, S_IRWXU | S_IRWXG) < 0) {
1701 if (errno == EEXIST) {
1702 wpa_printf(MSG_DEBUG, "Using existing control "
1703 "interface directory.");
1705 perror("mkdir[ctrl_interface]");
1708 } else if (interface->ctrl_iface_group &&
1709 chown(interface->global_iface_path, -1,
1710 interface->ctrl_iface_group) < 0) {
1711 perror("chown[ctrl_interface]");
1715 if (os_strlen(interface->global_iface_path) + 1 +
1716 os_strlen(interface->global_iface_name) >= sizeof(addr.sun_path))
1719 s = socket(PF_UNIX, SOCK_DGRAM, 0);
1721 perror("socket(PF_UNIX)");
1725 os_memset(&addr, 0, sizeof(addr));
1727 addr.sun_len = sizeof(addr);
1728 #endif /* __FreeBSD__ */
1729 addr.sun_family = AF_UNIX;
1730 fname = hostapd_global_ctrl_iface_path(interface);
1733 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
1734 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1735 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
1737 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
1738 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
1739 " allow connections - assuming it was left"
1740 "over from forced program termination");
1741 if (unlink(fname) < 0) {
1742 perror("unlink[ctrl_iface]");
1743 wpa_printf(MSG_ERROR, "Could not unlink "
1744 "existing ctrl_iface socket '%s'",
1748 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
1750 perror("bind(PF_UNIX)");
1753 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
1754 "ctrl_iface socket '%s'", fname);
1756 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
1757 "be in use - cannot override it");
1758 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
1759 "not used anymore", fname);
1766 if (interface->ctrl_iface_group &&
1767 chown(fname, -1, interface->ctrl_iface_group) < 0) {
1768 perror("chown[ctrl_interface]");
1772 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
1773 perror("chmod[ctrl_interface/ifname]");
1778 interface->global_ctrl_sock = s;
1779 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
1795 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
1799 if (interfaces->global_ctrl_sock > -1) {
1800 eloop_unregister_read_sock(interfaces->global_ctrl_sock);
1801 close(interfaces->global_ctrl_sock);
1802 interfaces->global_ctrl_sock = -1;
1803 fname = hostapd_global_ctrl_iface_path(interfaces);
1809 if (interfaces->global_iface_path &&
1810 rmdir(interfaces->global_iface_path) < 0) {
1811 if (errno == ENOTEMPTY) {
1812 wpa_printf(MSG_DEBUG, "Control interface "
1813 "directory not empty - leaving it "
1816 wpa_printf(MSG_ERROR,
1817 "rmdir[ctrl_interface=%s]: %s",
1818 interfaces->global_iface_path,
1822 os_free(interfaces->global_iface_path);
1823 interfaces->global_iface_path = NULL;
1828 static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
1829 const char *buf, size_t len)
1831 struct wpa_ctrl_dst *dst, *next;
1837 dst = hapd->ctrl_dst;
1838 if (hapd->ctrl_sock < 0 || dst == NULL)
1841 os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
1842 io[0].iov_base = levelstr;
1843 io[0].iov_len = os_strlen(levelstr);
1844 io[1].iov_base = (char *) buf;
1845 io[1].iov_len = len;
1846 os_memset(&msg, 0, sizeof(msg));
1853 if (level >= dst->debug_level) {
1854 wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
1855 (u8 *) dst->addr.sun_path, dst->addrlen -
1856 offsetof(struct sockaddr_un, sun_path));
1857 msg.msg_name = &dst->addr;
1858 msg.msg_namelen = dst->addrlen;
1859 if (sendmsg(hapd->ctrl_sock, &msg, 0) < 0) {
1861 wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
1863 idx, errno, strerror(errno));
1865 if (dst->errors > 10 || _errno == ENOENT) {
1866 hostapd_ctrl_iface_detach(
1878 #endif /* CONFIG_NATIVE_WINDOWS */