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 #ifdef CONFIG_CTRL_IFACE_UDP
24 #endif /* CONFIG_CTRL_IFACE_UDP */
26 #include "utils/common.h"
27 #include "utils/eloop.h"
28 #include "utils/module_tests.h"
29 #include "common/version.h"
30 #include "common/ieee802_11_defs.h"
31 #include "common/ctrl_iface_common.h"
32 #include "crypto/tls.h"
33 #include "drivers/driver.h"
34 #include "eapol_auth/eapol_auth_sm.h"
35 #include "radius/radius_client.h"
36 #include "radius/radius_server.h"
37 #include "l2_packet/l2_packet.h"
38 #include "ap/hostapd.h"
39 #include "ap/ap_config.h"
40 #include "ap/ieee802_1x.h"
41 #include "ap/wpa_auth.h"
42 #include "ap/ieee802_11.h"
43 #include "ap/sta_info.h"
44 #include "ap/wps_hostapd.h"
45 #include "ap/ctrl_iface_ap.h"
46 #include "ap/ap_drv_ops.h"
48 #include "ap/wnm_ap.h"
49 #include "ap/wpa_auth.h"
50 #include "ap/beacon.h"
51 #include "ap/neighbor_db.h"
53 #include "ap/dpp_hostapd.h"
54 #include "wps/wps_defs.h"
56 #include "fst/fst_ctrl_iface.h"
57 #include "config_file.h"
58 #include "ctrl_iface.h"
61 #define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
63 #ifdef CONFIG_CTRL_IFACE_UDP
65 static unsigned char cookie
[COOKIE_LEN
];
66 static unsigned char gcookie
[COOKIE_LEN
];
67 #define HOSTAPD_CTRL_IFACE_PORT 8877
68 #define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
69 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
70 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
71 #endif /* CONFIG_CTRL_IFACE_UDP */
73 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
74 enum wpa_msg_type type
,
75 const char *buf
, size_t len
);
78 static int hostapd_ctrl_iface_attach(struct hostapd_data
*hapd
,
79 struct sockaddr_storage
*from
,
82 return ctrl_iface_attach(&hapd
->ctrl_dst
, from
, fromlen
);
86 static int hostapd_ctrl_iface_detach(struct hostapd_data
*hapd
,
87 struct sockaddr_storage
*from
,
90 return ctrl_iface_detach(&hapd
->ctrl_dst
, from
, fromlen
);
94 static int hostapd_ctrl_iface_level(struct hostapd_data
*hapd
,
95 struct sockaddr_storage
*from
,
99 return ctrl_iface_level(&hapd
->ctrl_dst
, from
, fromlen
, level
);
103 static int hostapd_ctrl_iface_new_sta(struct hostapd_data
*hapd
,
107 struct sta_info
*sta
;
109 wpa_printf(MSG_DEBUG
, "CTRL_IFACE NEW_STA %s", txtaddr
);
111 if (hwaddr_aton(txtaddr
, addr
))
114 sta
= ap_get_sta(hapd
, addr
);
118 wpa_printf(MSG_DEBUG
, "Add new STA " MACSTR
" based on ctrl_iface "
119 "notification", MAC2STR(addr
));
120 sta
= ap_sta_add(hapd
, addr
);
124 hostapd_new_assoc_sta(hapd
, sta
, 0);
129 #ifdef CONFIG_IEEE80211W
131 static int hostapd_ctrl_iface_sa_query(struct hostapd_data
*hapd
,
135 u8 trans_id
[WLAN_SA_QUERY_TR_ID_LEN
];
137 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SA_QUERY %s", txtaddr
);
139 if (hwaddr_aton(txtaddr
, addr
) ||
140 os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0)
143 ieee802_11_send_sa_query_req(hapd
, addr
, trans_id
);
147 #endif /* NEED_AP_MLME */
148 #endif /* CONFIG_IEEE80211W */
152 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data
*hapd
, char *txt
)
154 char *pin
= os_strchr(txt
, ' ');
157 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
164 timeout_txt
= os_strchr(pin
, ' ');
166 *timeout_txt
++ = '\0';
167 timeout
= atoi(timeout_txt
);
168 pos
= os_strchr(timeout_txt
, ' ');
171 if (hwaddr_aton(pos
, addr_buf
) == 0)
177 return hostapd_wps_add_pin(hapd
, addr
, txt
, pin
, timeout
);
181 static int hostapd_ctrl_iface_wps_check_pin(
182 struct hostapd_data
*hapd
, char *cmd
, char *buf
, size_t buflen
)
189 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
190 (u8
*) cmd
, os_strlen(cmd
));
191 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
192 if (*pos
< '0' || *pos
> '9')
196 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
200 if (len
!= 4 && len
!= 8) {
201 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
207 unsigned int pin_val
;
209 if (!wps_pin_valid(pin_val
)) {
210 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
211 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
212 if (os_snprintf_error(buflen
, ret
))
218 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
219 if (os_snprintf_error(buflen
, ret
))
226 #ifdef CONFIG_WPS_NFC
227 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data
*hapd
,
234 len
= os_strlen(pos
);
239 buf
= wpabuf_alloc(len
);
242 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
247 ret
= hostapd_wps_nfc_tag_read(hapd
, buf
);
254 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data
*hapd
,
255 char *cmd
, char *reply
,
262 if (os_strcmp(cmd
, "WPS") == 0)
264 else if (os_strcmp(cmd
, "NDEF") == 0)
269 buf
= hostapd_wps_nfc_config_token(hapd
, ndef
);
273 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
284 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data
*hapd
,
285 char *reply
, size_t max_len
,
291 buf
= hostapd_wps_nfc_token_gen(hapd
, ndef
);
295 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
306 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data
*hapd
,
307 char *cmd
, char *reply
,
310 if (os_strcmp(cmd
, "WPS") == 0)
311 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
314 if (os_strcmp(cmd
, "NDEF") == 0)
315 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
318 if (os_strcmp(cmd
, "enable") == 0)
319 return hostapd_wps_nfc_token_enable(hapd
);
321 if (os_strcmp(cmd
, "disable") == 0) {
322 hostapd_wps_nfc_token_disable(hapd
);
330 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data
*hapd
,
331 char *cmd
, char *reply
,
339 pos
= os_strchr(cmd
, ' ');
344 if (os_strcmp(cmd
, "WPS") == 0)
346 else if (os_strcmp(cmd
, "NDEF") == 0)
351 if (os_strcmp(pos
, "WPS-CR") == 0)
352 buf
= hostapd_wps_nfc_hs_cr(hapd
, ndef
);
358 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
369 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data
*hapd
,
373 struct wpabuf
*req
, *sel
;
375 char *pos
, *role
, *type
, *pos2
;
378 pos
= os_strchr(role
, ' ');
384 pos
= os_strchr(type
, ' ');
389 pos2
= os_strchr(pos
, ' ');
394 len
= os_strlen(pos
);
399 req
= wpabuf_alloc(len
);
402 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
407 len
= os_strlen(pos2
);
414 sel
= wpabuf_alloc(len
);
419 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
425 if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0) {
426 ret
= hostapd_wps_nfc_report_handover(hapd
, req
, sel
);
428 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
429 "reported: role=%s type=%s", role
, type
);
438 #endif /* CONFIG_WPS_NFC */
441 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data
*hapd
, char *txt
,
442 char *buf
, size_t buflen
)
448 pos
= os_strchr(txt
, ' ');
452 if (os_strcmp(txt
, "disable") == 0) {
453 hostapd_wps_ap_pin_disable(hapd
);
454 return os_snprintf(buf
, buflen
, "OK\n");
457 if (os_strcmp(txt
, "random") == 0) {
460 pin_txt
= hostapd_wps_ap_pin_random(hapd
, timeout
);
463 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
466 if (os_strcmp(txt
, "get") == 0) {
467 pin_txt
= hostapd_wps_ap_pin_get(hapd
);
470 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
473 if (os_strcmp(txt
, "set") == 0) {
478 pos
= os_strchr(pos
, ' ');
483 if (os_strlen(pin
) > buflen
)
485 if (hostapd_wps_ap_pin_set(hapd
, pin
, timeout
) < 0)
487 return os_snprintf(buf
, buflen
, "%s", pin
);
494 static int hostapd_ctrl_iface_wps_config(struct hostapd_data
*hapd
, char *txt
)
497 char *ssid
, *auth
, *encr
= NULL
, *key
= NULL
;
500 pos
= os_strchr(txt
, ' ');
506 pos
= os_strchr(pos
, ' ');
510 pos
= os_strchr(pos
, ' ');
517 return hostapd_wps_config_ap(hapd
, ssid
, auth
, encr
, key
);
521 static const char * pbc_status_str(enum pbc_status status
)
524 case WPS_PBC_STATUS_DISABLE
:
526 case WPS_PBC_STATUS_ACTIVE
:
528 case WPS_PBC_STATUS_TIMEOUT
:
530 case WPS_PBC_STATUS_OVERLAP
:
538 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data
*hapd
,
539 char *buf
, size_t buflen
)
547 ret
= os_snprintf(pos
, end
- pos
, "PBC Status: %s\n",
548 pbc_status_str(hapd
->wps_stats
.pbc_status
));
550 if (os_snprintf_error(end
- pos
, ret
))
554 ret
= os_snprintf(pos
, end
- pos
, "Last WPS result: %s\n",
555 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
557 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
558 "Failed" : "None")));
560 if (os_snprintf_error(end
- pos
, ret
))
564 /* If status == Failure - Add possible Reasons */
565 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
566 hapd
->wps_stats
.failure_reason
> 0) {
567 ret
= os_snprintf(pos
, end
- pos
,
568 "Failure Reason: %s\n",
569 wps_ei_str(hapd
->wps_stats
.failure_reason
));
571 if (os_snprintf_error(end
- pos
, ret
))
576 if (hapd
->wps_stats
.status
) {
577 ret
= os_snprintf(pos
, end
- pos
, "Peer Address: " MACSTR
"\n",
578 MAC2STR(hapd
->wps_stats
.peer_addr
));
580 if (os_snprintf_error(end
- pos
, ret
))
588 #endif /* CONFIG_WPS */
592 static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data
*hapd
,
598 if (hwaddr_aton(cmd
, addr
))
611 return hs20_send_wnm_notification(hapd
, addr
, 1, url
);
615 static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data
*hapd
,
619 int code
, reauth_delay
, ret
;
624 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
625 if (hwaddr_aton(cmd
, addr
))
628 pos
= os_strchr(cmd
, ' ');
634 pos
= os_strchr(pos
, ' ');
638 reauth_delay
= atoi(pos
);
641 pos
= os_strchr(pos
, ' ');
644 url_len
= os_strlen(pos
);
647 req
= wpabuf_alloc(4 + url_len
);
650 wpabuf_put_u8(req
, code
);
651 wpabuf_put_le16(req
, reauth_delay
);
652 wpabuf_put_u8(req
, url_len
);
654 wpabuf_put_data(req
, pos
, url_len
);
656 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to " MACSTR
657 " to indicate imminent deauthentication (code=%d "
658 "reauth_delay=%d)", MAC2STR(addr
), code
, reauth_delay
);
659 ret
= hs20_send_wnm_notification_deauth_req(hapd
, addr
, req
);
664 #endif /* CONFIG_HS20 */
667 #ifdef CONFIG_INTERWORKING
669 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data
*hapd
,
672 u8 qos_map_set
[16 + 2 * 21], count
= 0;
673 const char *pos
= cmd
;
677 if (count
== sizeof(qos_map_set
)) {
678 wpa_printf(MSG_ERROR
, "Too many qos_map_set parameters");
683 if (val
< 0 || val
> 255) {
684 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
688 qos_map_set
[count
++] = val
;
689 pos
= os_strchr(pos
, ',');
695 if (count
< 16 || count
& 1) {
696 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
700 ret
= hostapd_drv_set_qos_map(hapd
, qos_map_set
, count
);
702 wpa_printf(MSG_INFO
, "Failed to set QoS Map Set");
706 os_memcpy(hapd
->conf
->qos_map_set
, qos_map_set
, count
);
707 hapd
->conf
->qos_map_set_len
= count
;
713 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data
*hapd
,
717 struct sta_info
*sta
;
719 u8
*qos_map_set
= hapd
->conf
->qos_map_set
;
720 u8 qos_map_set_len
= hapd
->conf
->qos_map_set_len
;
723 if (!qos_map_set_len
) {
724 wpa_printf(MSG_INFO
, "QoS Map Set is not set");
728 if (hwaddr_aton(cmd
, addr
))
731 sta
= ap_get_sta(hapd
, addr
);
733 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" not found "
734 "for QoS Map Configuration message",
739 if (!sta
->qos_map_enabled
) {
740 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" did not indicate "
741 "support for QoS Map", MAC2STR(addr
));
745 buf
= wpabuf_alloc(2 + 2 + qos_map_set_len
);
749 wpabuf_put_u8(buf
, WLAN_ACTION_QOS
);
750 wpabuf_put_u8(buf
, QOS_QOS_MAP_CONFIG
);
752 /* QoS Map Set Element */
753 wpabuf_put_u8(buf
, WLAN_EID_QOS_MAP_SET
);
754 wpabuf_put_u8(buf
, qos_map_set_len
);
755 wpabuf_put_data(buf
, qos_map_set
, qos_map_set_len
);
757 ret
= hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, addr
,
758 wpabuf_head(buf
), wpabuf_len(buf
));
764 #endif /* CONFIG_INTERWORKING */
769 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data
*hapd
,
774 struct sta_info
*sta
;
776 if (hwaddr_aton(cmd
, addr
))
780 disassoc_timer
= atoi(cmd
+ 17);
782 sta
= ap_get_sta(hapd
, addr
);
784 wpa_printf(MSG_DEBUG
, "Station " MACSTR
785 " not found for disassociation imminent message",
790 return wnm_send_disassoc_imminent(hapd
, sta
, disassoc_timer
);
794 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data
*hapd
,
798 const char *url
, *timerstr
;
800 struct sta_info
*sta
;
802 if (hwaddr_aton(cmd
, addr
))
805 sta
= ap_get_sta(hapd
, addr
);
807 wpa_printf(MSG_DEBUG
, "Station " MACSTR
808 " not found for ESS disassociation imminent message",
814 if (*timerstr
!= ' ')
817 disassoc_timer
= atoi(timerstr
);
818 if (disassoc_timer
< 0 || disassoc_timer
> 65535)
821 url
= os_strchr(timerstr
, ' ');
826 return wnm_send_ess_disassoc_imminent(hapd
, sta
, url
, disassoc_timer
);
830 static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data
*hapd
,
834 const char *pos
, *end
;
835 int disassoc_timer
= 0;
836 struct sta_info
*sta
;
837 u8 req_mode
= 0, valid_int
= 0x01;
846 if (hwaddr_aton(cmd
, addr
)) {
847 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
851 sta
= ap_get_sta(hapd
, addr
);
853 wpa_printf(MSG_DEBUG
, "Station " MACSTR
854 " not found for BSS TM Request message",
859 pos
= os_strstr(cmd
, " disassoc_timer=");
862 disassoc_timer
= atoi(pos
);
863 if (disassoc_timer
< 0 || disassoc_timer
> 65535) {
864 wpa_printf(MSG_DEBUG
, "Invalid disassoc_timer");
869 pos
= os_strstr(cmd
, " valid_int=");
872 valid_int
= atoi(pos
);
875 pos
= os_strstr(cmd
, " bss_term=");
878 req_mode
|= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED
;
879 /* TODO: TSF configurable/learnable */
880 bss_term_dur
[0] = 4; /* Subelement ID */
881 bss_term_dur
[1] = 10; /* Length */
882 os_memset(bss_term_dur
, 2, 8);
883 end
= os_strchr(pos
, ',');
885 wpa_printf(MSG_DEBUG
, "Invalid bss_term data");
889 WPA_PUT_LE16(&bss_term_dur
[10], atoi(end
));
892 nei_len
= ieee802_11_parse_candidate_list(cmd
, nei_rep
,
897 pos
= os_strstr(cmd
, " url=");
901 end
= os_strchr(pos
, ' ');
905 len
= os_strlen(pos
);
906 url
= os_malloc(len
+ 1);
909 os_memcpy(url
, pos
, len
);
911 req_mode
|= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT
;
914 if (os_strstr(cmd
, " pref=1"))
915 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
916 if (os_strstr(cmd
, " abridged=1"))
917 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
918 if (os_strstr(cmd
, " disassoc_imminent=1"))
919 req_mode
|= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
922 pos
= os_strstr(cmd
, "mbo=");
924 unsigned int mbo_reason
, cell_pref
, reassoc_delay
;
927 ret
= sscanf(pos
, "mbo=%u:%u:%u", &mbo_reason
,
928 &reassoc_delay
, &cell_pref
);
930 wpa_printf(MSG_DEBUG
,
931 "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
936 if (mbo_reason
> MBO_TRANSITION_REASON_PREMIUM_AP
) {
937 wpa_printf(MSG_DEBUG
,
938 "Invalid MBO transition reason code %u",
944 /* Valid values for Cellular preference are: 0, 1, 255 */
945 if (cell_pref
!= 0 && cell_pref
!= 1 && cell_pref
!= 255) {
946 wpa_printf(MSG_DEBUG
,
947 "Invalid MBO cellular capability %u",
953 if (reassoc_delay
> 65535 ||
955 !(req_mode
& WNM_BSS_TM_REQ_DISASSOC_IMMINENT
))) {
956 wpa_printf(MSG_DEBUG
,
957 "MBO: Assoc retry delay is only valid in disassoc imminent mode");
962 *mbo_pos
++ = MBO_ATTR_ID_TRANSITION_REASON
;
964 *mbo_pos
++ = mbo_reason
;
965 *mbo_pos
++ = MBO_ATTR_ID_CELL_DATA_PREF
;
967 *mbo_pos
++ = cell_pref
;
970 *mbo_pos
++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY
;
972 WPA_PUT_LE16(mbo_pos
, reassoc_delay
);
976 mbo_len
= mbo_pos
- mbo
;
978 #endif /* CONFIG_MBO */
980 ret
= wnm_send_bss_tm_req(hapd
, sta
, req_mode
, disassoc_timer
,
981 valid_int
, bss_term_dur
, url
,
982 nei_len
? nei_rep
: NULL
, nei_len
,
983 mbo_len
? mbo
: NULL
, mbo_len
);
986 #endif /* CONFIG_MBO */
991 #endif /* CONFIG_WNM_AP */
994 static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data
*hapd
,
995 char *buf
, size_t buflen
)
1003 WPA_ASSERT(hapd
->conf
->wpa_key_mgmt
);
1005 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) {
1006 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK ");
1007 if (os_snprintf_error(end
- pos
, ret
))
1011 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1012 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP ");
1013 if (os_snprintf_error(end
- pos
, ret
))
1017 #ifdef CONFIG_IEEE80211R_AP
1018 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1019 ret
= os_snprintf(pos
, end
- pos
, "FT-PSK ");
1020 if (os_snprintf_error(end
- pos
, ret
))
1024 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1025 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP ");
1026 if (os_snprintf_error(end
- pos
, ret
))
1031 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
1032 ret
= os_snprintf(pos
, end
- pos
, "FT-SAE ");
1033 if (os_snprintf_error(end
- pos
, ret
))
1037 #endif /* CONFIG_SAE */
1039 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1040 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA256 ");
1041 if (os_snprintf_error(end
- pos
, ret
))
1045 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1046 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA384 ");
1047 if (os_snprintf_error(end
- pos
, ret
))
1051 #endif /* CONFIG_FILS */
1052 #endif /* CONFIG_IEEE80211R_AP */
1053 #ifdef CONFIG_IEEE80211W
1054 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1055 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK-SHA256 ");
1056 if (os_snprintf_error(end
- pos
, ret
))
1060 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1061 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SHA256 ");
1062 if (os_snprintf_error(end
- pos
, ret
))
1066 #endif /* CONFIG_IEEE80211W */
1068 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_SAE
) {
1069 ret
= os_snprintf(pos
, end
- pos
, "SAE ");
1070 if (os_snprintf_error(end
- pos
, ret
))
1074 #endif /* CONFIG_SAE */
1075 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1076 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SUITE-B ");
1077 if (os_snprintf_error(end
- pos
, ret
))
1081 if (hapd
->conf
->wpa_key_mgmt
&
1082 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
1083 ret
= os_snprintf(pos
, end
- pos
,
1084 "WPA-EAP-SUITE-B-192 ");
1085 if (os_snprintf_error(end
- pos
, ret
))
1090 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1091 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA256 ");
1092 if (os_snprintf_error(end
- pos
, ret
))
1096 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1097 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA384 ");
1098 if (os_snprintf_error(end
- pos
, ret
))
1102 #endif /* CONFIG_FILS */
1105 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) {
1106 ret
= os_snprintf(pos
, end
- pos
, "OWE ");
1107 if (os_snprintf_error(end
- pos
, ret
))
1111 #endif /* CONFIG_OWE */
1114 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) {
1115 ret
= os_snprintf(pos
, end
- pos
, "DPP ");
1116 if (os_snprintf_error(end
- pos
, ret
))
1120 #endif /* CONFIG_DPP */
1122 if (pos
> buf
&& *(pos
- 1) == ' ') {
1131 static int hostapd_ctrl_iface_get_config(struct hostapd_data
*hapd
,
1132 char *buf
, size_t buflen
)
1140 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n"
1142 MAC2STR(hapd
->own_addr
),
1143 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
1144 hapd
->conf
->ssid
.ssid_len
));
1145 if (os_snprintf_error(end
- pos
, ret
))
1150 ret
= os_snprintf(pos
, end
- pos
, "wps_state=%s\n",
1151 hapd
->conf
->wps_state
== 0 ? "disabled" :
1152 (hapd
->conf
->wps_state
== 1 ? "not configured" :
1154 if (os_snprintf_error(end
- pos
, ret
))
1158 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1159 hapd
->conf
->ssid
.wpa_passphrase
) {
1160 ret
= os_snprintf(pos
, end
- pos
, "passphrase=%s\n",
1161 hapd
->conf
->ssid
.wpa_passphrase
);
1162 if (os_snprintf_error(end
- pos
, ret
))
1167 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1168 hapd
->conf
->ssid
.wpa_psk
&&
1169 hapd
->conf
->ssid
.wpa_psk
->group
) {
1170 char hex
[PMK_LEN
* 2 + 1];
1171 wpa_snprintf_hex(hex
, sizeof(hex
),
1172 hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
1173 ret
= os_snprintf(pos
, end
- pos
, "psk=%s\n", hex
);
1174 if (os_snprintf_error(end
- pos
, ret
))
1178 #endif /* CONFIG_WPS */
1180 if (hapd
->conf
->wpa
) {
1181 ret
= os_snprintf(pos
, end
- pos
, "wpa=%d\n", hapd
->conf
->wpa
);
1182 if (os_snprintf_error(end
- pos
, ret
))
1187 if (hapd
->conf
->wpa
&& hapd
->conf
->wpa_key_mgmt
) {
1188 ret
= os_snprintf(pos
, end
- pos
, "key_mgmt=");
1189 if (os_snprintf_error(end
- pos
, ret
))
1193 pos
+= hostapd_ctrl_iface_get_key_mgmt(hapd
, pos
, end
- pos
);
1195 ret
= os_snprintf(pos
, end
- pos
, "\n");
1196 if (os_snprintf_error(end
- pos
, ret
))
1201 if (hapd
->conf
->wpa
) {
1202 ret
= os_snprintf(pos
, end
- pos
, "group_cipher=%s\n",
1203 wpa_cipher_txt(hapd
->conf
->wpa_group
));
1204 if (os_snprintf_error(end
- pos
, ret
))
1209 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && hapd
->conf
->rsn_pairwise
) {
1210 ret
= os_snprintf(pos
, end
- pos
, "rsn_pairwise_cipher=");
1211 if (os_snprintf_error(end
- pos
, ret
))
1215 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->rsn_pairwise
,
1221 ret
= os_snprintf(pos
, end
- pos
, "\n");
1222 if (os_snprintf_error(end
- pos
, ret
))
1227 if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) && hapd
->conf
->wpa_pairwise
) {
1228 ret
= os_snprintf(pos
, end
- pos
, "wpa_pairwise_cipher=");
1229 if (os_snprintf_error(end
- pos
, ret
))
1233 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->wpa_pairwise
,
1239 ret
= os_snprintf(pos
, end
- pos
, "\n");
1240 if (os_snprintf_error(end
- pos
, ret
))
1249 static int hostapd_ctrl_iface_set(struct hostapd_data
*hapd
, char *cmd
)
1254 value
= os_strchr(cmd
, ' ');
1259 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
1261 #ifdef CONFIG_WPS_TESTING
1262 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
1264 val
= strtol(value
, NULL
, 0);
1265 if (val
< 0 || val
> 0xff) {
1267 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
1268 "wps_version_number %ld", val
);
1270 wps_version_number
= val
;
1271 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
1273 (wps_version_number
& 0xf0) >> 4,
1274 wps_version_number
& 0x0f);
1275 hostapd_wps_update_ie(hapd
);
1277 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
1278 wps_testing_dummy_cred
= atoi(value
);
1279 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
1280 wps_testing_dummy_cred
);
1281 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
1282 wps_corrupt_pkhash
= atoi(value
);
1283 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
1284 wps_corrupt_pkhash
);
1285 #endif /* CONFIG_WPS_TESTING */
1286 #ifdef CONFIG_TESTING_OPTIONS
1287 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
1288 hapd
->ext_mgmt_frame_handling
= atoi(value
);
1289 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
1290 hapd
->ext_eapol_frame_io
= atoi(value
);
1292 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
1293 os_free(hapd
->dpp_config_obj_override
);
1294 hapd
->dpp_config_obj_override
= os_strdup(value
);
1295 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
1296 os_free(hapd
->dpp_discovery_override
);
1297 hapd
->dpp_discovery_override
= os_strdup(value
);
1298 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
1299 os_free(hapd
->dpp_groups_override
);
1300 hapd
->dpp_groups_override
= os_strdup(value
);
1301 } else if (os_strcasecmp(cmd
,
1302 "dpp_ignore_netaccesskey_mismatch") == 0) {
1303 hapd
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
1304 #endif /* CONFIG_DPP */
1305 #endif /* CONFIG_TESTING_OPTIONS */
1307 } else if (os_strcasecmp(cmd
, "mbo_assoc_disallow") == 0) {
1310 if (!hapd
->conf
->mbo_enabled
)
1314 if (val
< 0 || val
> 1)
1317 hapd
->mbo_assoc_disallow
= val
;
1318 ieee802_11_update_beacons(hapd
->iface
);
1321 * TODO: Need to configure drivers that do AP MLME offload with
1322 * disallowing station logic.
1324 #endif /* CONFIG_MBO */
1326 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
1327 os_free(hapd
->dpp_configurator_params
);
1328 hapd
->dpp_configurator_params
= os_strdup(value
);
1329 #endif /* CONFIG_DPP */
1331 struct sta_info
*sta
;
1332 struct vlan_description vlan_id
;
1334 ret
= hostapd_set_iface(hapd
->iconf
, hapd
->conf
, cmd
, value
);
1338 if (os_strcasecmp(cmd
, "deny_mac_file") == 0) {
1339 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1340 if (hostapd_maclist_found(
1341 hapd
->conf
->deny_mac
,
1342 hapd
->conf
->num_deny_mac
, sta
->addr
,
1344 (!vlan_id
.notempty
||
1345 !vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1347 hapd
, sta
, sta
->addr
,
1348 WLAN_REASON_UNSPECIFIED
);
1350 } else if (hapd
->conf
->macaddr_acl
== DENY_UNLESS_ACCEPTED
&&
1351 os_strcasecmp(cmd
, "accept_mac_file") == 0) {
1352 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1353 if (!hostapd_maclist_found(
1354 hapd
->conf
->accept_mac
,
1355 hapd
->conf
->num_accept_mac
,
1356 sta
->addr
, &vlan_id
) ||
1357 (vlan_id
.notempty
&&
1358 vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1360 hapd
, sta
, sta
->addr
,
1361 WLAN_REASON_UNSPECIFIED
);
1370 static int hostapd_ctrl_iface_get(struct hostapd_data
*hapd
, char *cmd
,
1371 char *buf
, size_t buflen
)
1375 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
1377 if (os_strcmp(cmd
, "version") == 0) {
1378 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
1379 if (os_snprintf_error(buflen
, res
))
1382 } else if (os_strcmp(cmd
, "tls_library") == 0) {
1383 res
= tls_get_library_version(buf
, buflen
);
1384 if (os_snprintf_error(buflen
, res
))
1393 static int hostapd_ctrl_iface_enable(struct hostapd_iface
*iface
)
1395 if (hostapd_enable_iface(iface
) < 0) {
1396 wpa_printf(MSG_ERROR
, "Enabling of interface failed");
1403 static int hostapd_ctrl_iface_reload(struct hostapd_iface
*iface
)
1405 if (hostapd_reload_iface(iface
) < 0) {
1406 wpa_printf(MSG_ERROR
, "Reloading of interface failed");
1413 static int hostapd_ctrl_iface_disable(struct hostapd_iface
*iface
)
1415 if (hostapd_disable_iface(iface
) < 0) {
1416 wpa_printf(MSG_ERROR
, "Disabling of interface failed");
1423 #ifdef CONFIG_TESTING_OPTIONS
1425 static int hostapd_ctrl_iface_radar(struct hostapd_data
*hapd
, char *cmd
)
1427 union wpa_event_data data
;
1429 enum wpa_event_type event
;
1431 wpa_printf(MSG_DEBUG
, "RADAR TEST: %s", cmd
);
1433 os_memset(&data
, 0, sizeof(data
));
1435 param
= os_strchr(cmd
, ' ');
1440 if (os_strcmp(cmd
, "DETECTED") == 0)
1441 event
= EVENT_DFS_RADAR_DETECTED
;
1442 else if (os_strcmp(cmd
, "CAC-FINISHED") == 0)
1443 event
= EVENT_DFS_CAC_FINISHED
;
1444 else if (os_strcmp(cmd
, "CAC-ABORTED") == 0)
1445 event
= EVENT_DFS_CAC_ABORTED
;
1446 else if (os_strcmp(cmd
, "NOP-FINISHED") == 0)
1447 event
= EVENT_DFS_NOP_FINISHED
;
1449 wpa_printf(MSG_DEBUG
, "Unsupported RADAR test command: %s",
1454 pos
= os_strstr(param
, "freq=");
1456 data
.dfs_event
.freq
= atoi(pos
+ 5);
1458 pos
= os_strstr(param
, "ht_enabled=1");
1460 data
.dfs_event
.ht_enabled
= 1;
1462 pos
= os_strstr(param
, "chan_offset=");
1464 data
.dfs_event
.chan_offset
= atoi(pos
+ 12);
1466 pos
= os_strstr(param
, "chan_width=");
1468 data
.dfs_event
.chan_width
= atoi(pos
+ 11);
1470 pos
= os_strstr(param
, "cf1=");
1472 data
.dfs_event
.cf1
= atoi(pos
+ 4);
1474 pos
= os_strstr(param
, "cf2=");
1476 data
.dfs_event
.cf2
= atoi(pos
+ 4);
1478 wpa_supplicant_event(hapd
, event
, &data
);
1484 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data
*hapd
, char *cmd
)
1490 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
1492 len
= os_strlen(cmd
);
1497 buf
= os_malloc(len
);
1501 if (hexstr2bin(cmd
, buf
, len
) < 0) {
1506 res
= hostapd_drv_send_mlme(hapd
, buf
, len
, 0);
1512 static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data
*hapd
,
1518 int stype
= 0, ok
= 0;
1519 union wpa_event_data event
;
1521 if (!hapd
->ext_mgmt_frame_handling
)
1524 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1526 wpa_printf(MSG_DEBUG
, "External MGMT TX status process: %s", cmd
);
1529 param
= os_strstr(pos
, "stype=");
1532 stype
= atoi(param
);
1535 param
= os_strstr(pos
, " ok=");
1541 param
= os_strstr(pos
, " buf=");
1546 len
= os_strlen(param
);
1551 buf
= os_malloc(len
);
1552 if (!buf
|| hexstr2bin(param
, buf
, len
) < 0) {
1557 os_memset(&event
, 0, sizeof(event
));
1558 event
.tx_status
.type
= WLAN_FC_TYPE_MGMT
;
1559 event
.tx_status
.data
= buf
;
1560 event
.tx_status
.data_len
= len
;
1561 event
.tx_status
.stype
= stype
;
1562 event
.tx_status
.ack
= ok
;
1563 hapd
->ext_mgmt_frame_handling
= 0;
1564 wpa_supplicant_event(hapd
, EVENT_TX_STATUS
, &event
);
1565 hapd
->ext_mgmt_frame_handling
= 1;
1573 static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data
*hapd
,
1579 int freq
= 0, datarate
= 0, ssi_signal
= 0;
1580 union wpa_event_data event
;
1582 if (!hapd
->ext_mgmt_frame_handling
)
1585 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1587 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
1590 param
= os_strstr(pos
, "freq=");
1596 param
= os_strstr(pos
, " datarate=");
1599 datarate
= atoi(param
);
1602 param
= os_strstr(pos
, " ssi_signal=");
1605 ssi_signal
= atoi(param
);
1608 param
= os_strstr(pos
, " frame=");
1613 len
= os_strlen(param
);
1618 buf
= os_malloc(len
);
1622 if (hexstr2bin(param
, buf
, len
) < 0) {
1627 os_memset(&event
, 0, sizeof(event
));
1628 event
.rx_mgmt
.freq
= freq
;
1629 event
.rx_mgmt
.frame
= buf
;
1630 event
.rx_mgmt
.frame_len
= len
;
1631 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1632 event
.rx_mgmt
.datarate
= datarate
;
1633 hapd
->ext_mgmt_frame_handling
= 0;
1634 wpa_supplicant_event(hapd
, EVENT_RX_MGMT
, &event
);
1635 hapd
->ext_mgmt_frame_handling
= 1;
1643 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data
*hapd
, char *cmd
)
1646 u8 src
[ETH_ALEN
], *buf
;
1650 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
1653 used
= hwaddr_aton2(pos
, src
);
1660 len
= os_strlen(pos
);
1665 buf
= os_malloc(len
);
1669 if (hexstr2bin(pos
, buf
, len
) < 0) {
1674 ieee802_1x_receive(hapd
, src
, buf
, len
);
1681 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
1685 const u16
*pos
= buf
;
1687 for (i
= 0; i
< len
/ 2; i
++)
1691 sum
= (sum
& 0xffff) + (sum
>> 16);
1693 return sum
^ 0xffff;
1697 #define HWSIM_PACKETLEN 1500
1698 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1700 static void hostapd_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
1703 struct hostapd_data
*hapd
= ctx
;
1704 const struct ether_header
*eth
;
1709 if (len
!= HWSIM_PACKETLEN
)
1712 eth
= (const struct ether_header
*) buf
;
1713 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
1714 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
1716 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
1717 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
1720 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
1726 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
1727 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
1731 static int hostapd_ctrl_iface_data_test_config(struct hostapd_data
*hapd
,
1734 int enabled
= atoi(cmd
);
1739 if (hapd
->l2_test
) {
1740 l2_packet_deinit(hapd
->l2_test
);
1741 hapd
->l2_test
= NULL
;
1742 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1743 "test data: Disabled");
1751 pos
= os_strstr(cmd
, " ifname=");
1755 ifname
= hapd
->conf
->iface
;
1757 hapd
->l2_test
= l2_packet_init(ifname
, hapd
->own_addr
,
1758 ETHERTYPE_IP
, hostapd_data_test_rx
,
1760 if (hapd
->l2_test
== NULL
)
1763 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: Enabled");
1769 static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data
*hapd
, char *cmd
)
1771 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
1776 u8 buf
[2 + HWSIM_PACKETLEN
];
1777 struct ether_header
*eth
;
1782 if (hapd
->l2_test
== NULL
)
1785 /* format: <dst> <src> <tos> */
1788 used
= hwaddr_aton2(pos
, dst
);
1794 used
= hwaddr_aton2(pos
, src
);
1799 val
= strtol(pos
, NULL
, 0);
1800 if (val
< 0 || val
> 0xff)
1804 eth
= (struct ether_header
*) &buf
[2];
1805 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
1806 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
1807 eth
->ether_type
= htons(ETHERTYPE_IP
);
1808 ip
= (struct iphdr
*) (eth
+ 1);
1809 os_memset(ip
, 0, sizeof(*ip
));
1814 ip
->tot_len
= htons(HWSIM_IP_LEN
);
1816 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
1817 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
1818 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
1819 dpos
= (u8
*) (ip
+ 1);
1820 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
1823 if (l2_packet_send(hapd
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
1824 HWSIM_PACKETLEN
) < 0)
1827 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX dst=" MACSTR
1828 " src=" MACSTR
" tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
1834 static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data
*hapd
,
1838 struct ether_header
*eth
;
1839 struct l2_packet_data
*l2
= NULL
;
1843 const char *ifname
= hapd
->conf
->iface
;
1845 if (os_strncmp(cmd
, "ifname=", 7) == 0) {
1848 cmd
= os_strchr(cmd
, ' ');
1854 len
= os_strlen(cmd
);
1855 if (len
& 1 || len
< ETH_HLEN
* 2)
1859 buf
= os_malloc(len
);
1863 if (hexstr2bin(cmd
, buf
, len
) < 0)
1866 eth
= (struct ether_header
*) buf
;
1867 ethertype
= ntohs(eth
->ether_type
);
1869 l2
= l2_packet_init(ifname
, hapd
->own_addr
, ethertype
,
1870 hostapd_data_test_rx
, hapd
, 1);
1874 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
1875 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
1878 l2_packet_deinit(l2
);
1881 return res
< 0 ? -1 : 0;
1885 static int hostapd_ctrl_test_alloc_fail(struct hostapd_data
*hapd
, char *cmd
)
1887 #ifdef WPA_TRACE_BFD
1890 wpa_trace_fail_after
= atoi(cmd
);
1891 pos
= os_strchr(cmd
, ':');
1894 os_strlcpy(wpa_trace_fail_func
, pos
,
1895 sizeof(wpa_trace_fail_func
));
1897 wpa_trace_fail_after
= 0;
1901 #else /* WPA_TRACE_BFD */
1903 #endif /* WPA_TRACE_BFD */
1907 static int hostapd_ctrl_get_alloc_fail(struct hostapd_data
*hapd
,
1908 char *buf
, size_t buflen
)
1910 #ifdef WPA_TRACE_BFD
1911 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
1912 wpa_trace_fail_func
);
1913 #else /* WPA_TRACE_BFD */
1915 #endif /* WPA_TRACE_BFD */
1919 static int hostapd_ctrl_test_fail(struct hostapd_data
*hapd
, char *cmd
)
1921 #ifdef WPA_TRACE_BFD
1924 wpa_trace_test_fail_after
= atoi(cmd
);
1925 pos
= os_strchr(cmd
, ':');
1928 os_strlcpy(wpa_trace_test_fail_func
, pos
,
1929 sizeof(wpa_trace_test_fail_func
));
1931 wpa_trace_test_fail_after
= 0;
1935 #else /* WPA_TRACE_BFD */
1937 #endif /* WPA_TRACE_BFD */
1941 static int hostapd_ctrl_get_fail(struct hostapd_data
*hapd
,
1942 char *buf
, size_t buflen
)
1944 #ifdef WPA_TRACE_BFD
1945 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
1946 wpa_trace_test_fail_func
);
1947 #else /* WPA_TRACE_BFD */
1949 #endif /* WPA_TRACE_BFD */
1953 static int hostapd_ctrl_reset_pn(struct hostapd_data
*hapd
, const char *cmd
)
1955 struct sta_info
*sta
;
1957 u8 zero
[WPA_TK_MAX_LEN
];
1959 os_memset(zero
, 0, sizeof(zero
));
1961 if (hwaddr_aton(cmd
, addr
))
1964 #ifdef CONFIG_IEEE80211W
1965 if (is_broadcast_ether_addr(addr
) && os_strstr(cmd
, "IGTK")) {
1966 if (hapd
->last_igtk_alg
== WPA_ALG_NONE
)
1969 wpa_printf(MSG_INFO
, "TESTING: Reset IPN for IGTK");
1971 /* First, use a zero key to avoid any possible duplicate key
1972 * avoidance in the driver. */
1973 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
1974 hapd
->last_igtk_alg
,
1975 broadcast_ether_addr
,
1976 hapd
->last_igtk_key_idx
, 1, NULL
, 0,
1977 zero
, hapd
->last_igtk_len
) < 0)
1980 /* Set the previously configured key to reset its TSC */
1981 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
1982 hapd
->last_igtk_alg
,
1983 broadcast_ether_addr
,
1984 hapd
->last_igtk_key_idx
, 1, NULL
, 0,
1986 hapd
->last_igtk_len
);
1988 #endif /* CONFIG_IEEE80211W */
1990 if (is_broadcast_ether_addr(addr
)) {
1991 if (hapd
->last_gtk_alg
== WPA_ALG_NONE
)
1994 wpa_printf(MSG_INFO
, "TESTING: Reset PN for GTK");
1996 /* First, use a zero key to avoid any possible duplicate key
1997 * avoidance in the driver. */
1998 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2000 broadcast_ether_addr
,
2001 hapd
->last_gtk_key_idx
, 1, NULL
, 0,
2002 zero
, hapd
->last_gtk_len
) < 0)
2005 /* Set the previously configured key to reset its TSC */
2006 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2008 broadcast_ether_addr
,
2009 hapd
->last_gtk_key_idx
, 1, NULL
, 0,
2010 hapd
->last_gtk
, hapd
->last_gtk_len
);
2013 sta
= ap_get_sta(hapd
, addr
);
2017 if (sta
->last_tk_alg
== WPA_ALG_NONE
)
2020 wpa_printf(MSG_INFO
, "TESTING: Reset PN for " MACSTR
,
2021 MAC2STR(sta
->addr
));
2023 /* First, use a zero key to avoid any possible duplicate key avoidance
2025 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2026 sta
->addr
, sta
->last_tk_key_idx
, 1, NULL
, 0,
2027 zero
, sta
->last_tk_len
) < 0)
2030 /* Set the previously configured key to reset its TSC/RSC */
2031 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2032 sta
->addr
, sta
->last_tk_key_idx
, 1, NULL
, 0,
2033 sta
->last_tk
, sta
->last_tk_len
);
2036 #endif /* CONFIG_TESTING_OPTIONS */
2039 static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface
*iface
,
2043 struct csa_settings settings
;
2047 ret
= hostapd_parse_csa_settings(pos
, &settings
);
2051 for (i
= 0; i
< iface
->num_bss
; i
++) {
2052 ret
= hostapd_switch_channel(iface
->bss
[i
], &settings
);
2054 /* FIX: What do we do if CSA fails in the middle of
2055 * submitting multi-BSS CSA requests? */
2061 #else /* NEED_AP_MLME */
2063 #endif /* NEED_AP_MLME */
2067 static int hostapd_ctrl_iface_mib(struct hostapd_data
*hapd
, char *reply
,
2068 int reply_size
, const char *param
)
2070 #ifdef RADIUS_SERVER
2071 if (os_strcmp(param
, "radius_server") == 0) {
2072 return radius_server_get_mib(hapd
->radius_srv
, reply
,
2075 #endif /* RADIUS_SERVER */
2080 static int hostapd_ctrl_iface_vendor(struct hostapd_data
*hapd
, char *cmd
,
2081 char *buf
, size_t buflen
)
2086 unsigned int vendor_id
, subcmd
;
2087 struct wpabuf
*reply
;
2088 size_t data_len
= 0;
2090 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2091 vendor_id
= strtoul(cmd
, &pos
, 16);
2092 if (!isblank((unsigned char) *pos
))
2095 subcmd
= strtoul(pos
, &pos
, 10);
2098 if (!isblank((unsigned char) *pos
++))
2100 data_len
= os_strlen(pos
);
2105 data
= os_malloc(data_len
);
2109 if (hexstr2bin(pos
, data
, data_len
)) {
2110 wpa_printf(MSG_DEBUG
,
2111 "Vendor command: wrong parameter format");
2117 reply
= wpabuf_alloc((buflen
- 1) / 2);
2123 ret
= hostapd_drv_vendor_cmd(hapd
, vendor_id
, subcmd
, data
, data_len
,
2127 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
2137 static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data
*hapd
,
2141 struct sta_info
*sta
;
2143 if (hwaddr_aton(cmd
, addr
))
2146 sta
= ap_get_sta(hapd
, addr
);
2147 if (!sta
|| !sta
->eapol_sm
)
2150 eapol_auth_reauthenticate(sta
->eapol_sm
);
2155 static int hostapd_ctrl_iface_eapol_set(struct hostapd_data
*hapd
, char *cmd
)
2158 struct sta_info
*sta
;
2159 char *pos
= cmd
, *param
;
2161 if (hwaddr_aton(pos
, addr
) || pos
[17] != ' ')
2165 pos
= os_strchr(pos
, ' ');
2170 sta
= ap_get_sta(hapd
, addr
);
2171 if (!sta
|| !sta
->eapol_sm
)
2174 return eapol_auth_set_conf(sta
->eapol_sm
, param
, pos
);
2178 static int hostapd_ctrl_iface_log_level(struct hostapd_data
*hapd
, char *cmd
,
2179 char *buf
, size_t buflen
)
2181 char *pos
, *end
, *stamp
;
2184 /* cmd: "LOG_LEVEL [<level>]" */
2188 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2190 debug_level_str(wpa_debug_level
),
2191 wpa_debug_timestamp
);
2192 if (os_snprintf_error(end
- pos
, ret
))
2201 stamp
= os_strchr(cmd
, ' ');
2204 while (*stamp
== ' ') {
2209 if (os_strlen(cmd
)) {
2210 int level
= str_to_debug_level(cmd
);
2213 wpa_debug_level
= level
;
2216 if (stamp
&& os_strlen(stamp
))
2217 wpa_debug_timestamp
= atoi(stamp
);
2219 os_memcpy(buf
, "OK\n", 3);
2225 static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data
*hapd
,
2226 char *buf
, size_t buflen
)
2228 struct hostapd_iface
*iface
= hapd
->iface
;
2230 struct hostapd_sta_info
*info
;
2231 struct os_reltime now
;
2233 if (!iface
->num_sta_seen
)
2236 sta_track_expire(iface
, 0);
2241 os_get_reltime(&now
);
2242 dl_list_for_each_reverse(info
, &iface
->sta_seen
,
2243 struct hostapd_sta_info
, list
) {
2244 struct os_reltime age
;
2247 os_reltime_sub(&now
, &info
->last_seen
, &age
);
2248 ret
= os_snprintf(pos
, end
- pos
, MACSTR
" %u %d\n",
2249 MAC2STR(info
->addr
), (unsigned int) age
.sec
,
2251 if (os_snprintf_error(end
- pos
, ret
))
2258 #endif /* NEED_AP_MLME */
2261 static int hostapd_ctrl_iface_req_lci(struct hostapd_data
*hapd
,
2266 if (hwaddr_aton(cmd
, addr
)) {
2267 wpa_printf(MSG_INFO
, "CTRL: REQ_LCI: Invalid MAC address");
2271 return hostapd_send_lci_req(hapd
, addr
);
2275 static int hostapd_ctrl_iface_req_range(struct hostapd_data
*hapd
, char *cmd
)
2278 char *token
, *context
= NULL
;
2279 int random_interval
, min_ap
;
2280 u8 responders
[ETH_ALEN
* RRM_RANGE_REQ_MAX_RESPONDERS
];
2281 unsigned int n_responders
;
2283 token
= str_token(cmd
, " ", &context
);
2284 if (!token
|| hwaddr_aton(token
, addr
)) {
2285 wpa_printf(MSG_INFO
,
2286 "CTRL: REQ_RANGE - Bad destination address");
2290 token
= str_token(cmd
, " ", &context
);
2294 random_interval
= atoi(token
);
2295 if (random_interval
< 0 || random_interval
> 0xffff)
2298 token
= str_token(cmd
, " ", &context
);
2302 min_ap
= atoi(token
);
2303 if (min_ap
<= 0 || min_ap
> WLAN_RRM_RANGE_REQ_MAX_MIN_AP
)
2307 while ((token
= str_token(cmd
, " ", &context
))) {
2308 if (n_responders
== RRM_RANGE_REQ_MAX_RESPONDERS
) {
2309 wpa_printf(MSG_INFO
,
2310 "CTRL: REQ_RANGE: Too many responders");
2314 if (hwaddr_aton(token
, responders
+ n_responders
* ETH_ALEN
)) {
2315 wpa_printf(MSG_INFO
,
2316 "CTRL: REQ_RANGE: Bad responder address");
2323 if (!n_responders
) {
2324 wpa_printf(MSG_INFO
,
2325 "CTRL: REQ_RANGE - No FTM responder address");
2329 return hostapd_send_range_req(hapd
, addr
, random_interval
, min_ap
,
2330 responders
, n_responders
);
2334 static int hostapd_ctrl_iface_req_beacon(struct hostapd_data
*hapd
,
2335 const char *cmd
, char *reply
,
2344 if (hwaddr_aton(cmd
, addr
))
2346 pos
= os_strchr(cmd
, ' ');
2350 if (os_strncmp(pos
, "req_mode=", 9) == 0) {
2351 int val
= hex2byte(pos
+ 9);
2357 pos
= os_strchr(pos
, ' ');
2362 req
= wpabuf_parse_bin(pos
);
2366 ret
= hostapd_send_beacon_req(hapd
, addr
, req_mode
, req
);
2369 ret
= os_snprintf(reply
, reply_size
, "%d", ret
);
2374 static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data
*hapd
, char *buf
)
2376 struct wpa_ssid_value ssid
;
2378 struct wpabuf
*nr
, *lci
= NULL
, *civic
= NULL
;
2383 if (!(hapd
->conf
->radio_measurements
[0] &
2384 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2385 wpa_printf(MSG_ERROR
,
2386 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
2390 if (hwaddr_aton(buf
, bssid
)) {
2391 wpa_printf(MSG_ERROR
, "CTRL: SET_NEIGHBOR: Bad BSSID");
2395 tmp
= os_strstr(buf
, "ssid=");
2396 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2397 wpa_printf(MSG_ERROR
,
2398 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
2401 buf
= os_strchr(tmp
+ 6, tmp
[5] == '"' ? '"' : ' ');
2405 tmp
= os_strstr(buf
, "nr=");
2407 wpa_printf(MSG_ERROR
,
2408 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
2412 buf
= os_strchr(tmp
, ' ');
2416 nr
= wpabuf_parse_bin(tmp
+ 3);
2418 wpa_printf(MSG_ERROR
,
2419 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
2426 tmp
= os_strstr(buf
, "lci=");
2428 buf
= os_strchr(tmp
, ' ');
2431 lci
= wpabuf_parse_bin(tmp
+ 4);
2433 wpa_printf(MSG_ERROR
,
2434 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
2443 tmp
= os_strstr(buf
, "civic=");
2445 buf
= os_strchr(tmp
, ' ');
2448 civic
= wpabuf_parse_bin(tmp
+ 6);
2450 wpa_printf(MSG_ERROR
,
2451 "CTRL: SET_NEIGHBOR: Bad civic subelement");
2461 if (os_strstr(buf
, "stat"))
2465 ret
= hostapd_neighbor_set(hapd
, bssid
, &ssid
, nr
, lci
, civic
,
2476 static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data
*hapd
,
2479 struct wpa_ssid_value ssid
;
2483 if (hwaddr_aton(buf
, bssid
)) {
2484 wpa_printf(MSG_ERROR
, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
2488 tmp
= os_strstr(buf
, "ssid=");
2489 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2490 wpa_printf(MSG_ERROR
,
2491 "CTRL: REMOVE_NEIGHBORr: Bad or missing SSID");
2495 return hostapd_neighbor_remove(hapd
, bssid
, &ssid
);
2499 static int hostapd_ctrl_driver_flags(struct hostapd_iface
*iface
, char *buf
,
2505 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
2506 (long long unsigned) iface
->drv_flags
);
2507 if (os_snprintf_error(buflen
, ret
))
2513 for (i
= 0; i
< 64; i
++) {
2514 if (iface
->drv_flags
& (1LLU << i
)) {
2515 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
2516 driver_flag_to_string(1LLU << i
));
2517 if (os_snprintf_error(end
- pos
, ret
))
2527 static int hostapd_ctrl_iface_receive_process(struct hostapd_data
*hapd
,
2528 char *buf
, char *reply
,
2530 struct sockaddr_storage
*from
,
2535 os_memcpy(reply
, "OK\n", 3);
2538 if (os_strcmp(buf
, "PING") == 0) {
2539 os_memcpy(reply
, "PONG\n", 5);
2541 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
2542 if (wpa_debug_reopen_file() < 0)
2544 } else if (os_strcmp(buf
, "STATUS") == 0) {
2545 reply_len
= hostapd_ctrl_iface_status(hapd
, reply
,
2547 } else if (os_strcmp(buf
, "STATUS-DRIVER") == 0) {
2548 reply_len
= hostapd_drv_status(hapd
, reply
, reply_size
);
2549 } else if (os_strcmp(buf
, "MIB") == 0) {
2550 reply_len
= ieee802_11_get_mib(hapd
, reply
, reply_size
);
2551 if (reply_len
>= 0) {
2552 res
= wpa_get_mib(hapd
->wpa_auth
, reply
+ reply_len
,
2553 reply_size
- reply_len
);
2559 if (reply_len
>= 0) {
2560 res
= ieee802_1x_get_mib(hapd
, reply
+ reply_len
,
2561 reply_size
- reply_len
);
2567 #ifndef CONFIG_NO_RADIUS
2568 if (reply_len
>= 0) {
2569 res
= radius_client_get_mib(hapd
->radius
,
2571 reply_size
- reply_len
);
2577 #endif /* CONFIG_NO_RADIUS */
2578 } else if (os_strncmp(buf
, "MIB ", 4) == 0) {
2579 reply_len
= hostapd_ctrl_iface_mib(hapd
, reply
, reply_size
,
2581 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
2582 reply_len
= hostapd_ctrl_iface_sta_first(hapd
, reply
,
2584 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
2585 reply_len
= hostapd_ctrl_iface_sta(hapd
, buf
+ 4, reply
,
2587 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
2588 reply_len
= hostapd_ctrl_iface_sta_next(hapd
, buf
+ 9, reply
,
2590 } else if (os_strcmp(buf
, "ATTACH") == 0) {
2591 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
))
2593 } else if (os_strcmp(buf
, "DETACH") == 0) {
2594 if (hostapd_ctrl_iface_detach(hapd
, from
, fromlen
))
2596 } else if (os_strncmp(buf
, "LEVEL ", 6) == 0) {
2597 if (hostapd_ctrl_iface_level(hapd
, from
, fromlen
,
2600 } else if (os_strncmp(buf
, "NEW_STA ", 8) == 0) {
2601 if (hostapd_ctrl_iface_new_sta(hapd
, buf
+ 8))
2603 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
2604 if (hostapd_ctrl_iface_deauthenticate(hapd
, buf
+ 15))
2606 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
2607 if (hostapd_ctrl_iface_disassociate(hapd
, buf
+ 13))
2609 #ifdef CONFIG_TAXONOMY
2610 } else if (os_strncmp(buf
, "SIGNATURE ", 10) == 0) {
2611 reply_len
= hostapd_ctrl_iface_signature(hapd
, buf
+ 10,
2613 #endif /* CONFIG_TAXONOMY */
2614 } else if (os_strncmp(buf
, "POLL_STA ", 9) == 0) {
2615 if (hostapd_ctrl_iface_poll_sta(hapd
, buf
+ 9))
2617 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
2618 if (hostapd_ctrl_iface_stop_ap(hapd
))
2620 #ifdef CONFIG_IEEE80211W
2622 } else if (os_strncmp(buf
, "SA_QUERY ", 9) == 0) {
2623 if (hostapd_ctrl_iface_sa_query(hapd
, buf
+ 9))
2625 #endif /* NEED_AP_MLME */
2626 #endif /* CONFIG_IEEE80211W */
2628 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
2629 if (hostapd_ctrl_iface_wps_pin(hapd
, buf
+ 8))
2631 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
2632 reply_len
= hostapd_ctrl_iface_wps_check_pin(
2633 hapd
, buf
+ 14, reply
, reply_size
);
2634 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
2635 if (hostapd_wps_button_pushed(hapd
, NULL
))
2637 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
2638 if (hostapd_wps_cancel(hapd
))
2640 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
2641 reply_len
= hostapd_ctrl_iface_wps_ap_pin(hapd
, buf
+ 11,
2643 } else if (os_strncmp(buf
, "WPS_CONFIG ", 11) == 0) {
2644 if (hostapd_ctrl_iface_wps_config(hapd
, buf
+ 11) < 0)
2646 } else if (os_strncmp(buf
, "WPS_GET_STATUS", 13) == 0) {
2647 reply_len
= hostapd_ctrl_iface_wps_get_status(hapd
, reply
,
2649 #ifdef CONFIG_WPS_NFC
2650 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
2651 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd
, buf
+ 17))
2653 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
2654 reply_len
= hostapd_ctrl_iface_wps_nfc_config_token(
2655 hapd
, buf
+ 21, reply
, reply_size
);
2656 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
2657 reply_len
= hostapd_ctrl_iface_wps_nfc_token(
2658 hapd
, buf
+ 14, reply
, reply_size
);
2659 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
2660 reply_len
= hostapd_ctrl_iface_nfc_get_handover_sel(
2661 hapd
, buf
+ 21, reply
, reply_size
);
2662 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
2663 if (hostapd_ctrl_iface_nfc_report_handover(hapd
, buf
+ 20))
2665 #endif /* CONFIG_WPS_NFC */
2666 #endif /* CONFIG_WPS */
2667 #ifdef CONFIG_INTERWORKING
2668 } else if (os_strncmp(buf
, "SET_QOS_MAP_SET ", 16) == 0) {
2669 if (hostapd_ctrl_iface_set_qos_map_set(hapd
, buf
+ 16))
2671 } else if (os_strncmp(buf
, "SEND_QOS_MAP_CONF ", 18) == 0) {
2672 if (hostapd_ctrl_iface_send_qos_map_conf(hapd
, buf
+ 18))
2674 #endif /* CONFIG_INTERWORKING */
2676 } else if (os_strncmp(buf
, "HS20_WNM_NOTIF ", 15) == 0) {
2677 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd
, buf
+ 15))
2679 } else if (os_strncmp(buf
, "HS20_DEAUTH_REQ ", 16) == 0) {
2680 if (hostapd_ctrl_iface_hs20_deauth_req(hapd
, buf
+ 16))
2682 #endif /* CONFIG_HS20 */
2683 #ifdef CONFIG_WNM_AP
2684 } else if (os_strncmp(buf
, "DISASSOC_IMMINENT ", 18) == 0) {
2685 if (hostapd_ctrl_iface_disassoc_imminent(hapd
, buf
+ 18))
2687 } else if (os_strncmp(buf
, "ESS_DISASSOC ", 13) == 0) {
2688 if (hostapd_ctrl_iface_ess_disassoc(hapd
, buf
+ 13))
2690 } else if (os_strncmp(buf
, "BSS_TM_REQ ", 11) == 0) {
2691 if (hostapd_ctrl_iface_bss_tm_req(hapd
, buf
+ 11))
2693 #endif /* CONFIG_WNM_AP */
2694 } else if (os_strcmp(buf
, "GET_CONFIG") == 0) {
2695 reply_len
= hostapd_ctrl_iface_get_config(hapd
, reply
,
2697 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
2698 if (hostapd_ctrl_iface_set(hapd
, buf
+ 4))
2700 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
2701 reply_len
= hostapd_ctrl_iface_get(hapd
, buf
+ 4, reply
,
2703 } else if (os_strncmp(buf
, "ENABLE", 6) == 0) {
2704 if (hostapd_ctrl_iface_enable(hapd
->iface
))
2706 } else if (os_strncmp(buf
, "RELOAD", 6) == 0) {
2707 if (hostapd_ctrl_iface_reload(hapd
->iface
))
2709 } else if (os_strncmp(buf
, "DISABLE", 7) == 0) {
2710 if (hostapd_ctrl_iface_disable(hapd
->iface
))
2712 } else if (os_strcmp(buf
, "UPDATE_BEACON") == 0) {
2713 if (ieee802_11_set_beacon(hapd
))
2715 #ifdef CONFIG_TESTING_OPTIONS
2716 } else if (os_strncmp(buf
, "RADAR ", 6) == 0) {
2717 if (hostapd_ctrl_iface_radar(hapd
, buf
+ 6))
2719 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
2720 if (hostapd_ctrl_iface_mgmt_tx(hapd
, buf
+ 8))
2722 } else if (os_strncmp(buf
, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
2723 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd
,
2726 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
2727 if (hostapd_ctrl_iface_mgmt_rx_process(hapd
, buf
+ 16) < 0)
2729 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
2730 if (hostapd_ctrl_iface_eapol_rx(hapd
, buf
+ 9) < 0)
2732 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
2733 if (hostapd_ctrl_iface_data_test_config(hapd
, buf
+ 17) < 0)
2735 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
2736 if (hostapd_ctrl_iface_data_test_tx(hapd
, buf
+ 13) < 0)
2738 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
2739 if (hostapd_ctrl_iface_data_test_frame(hapd
, buf
+ 16) < 0)
2741 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
2742 if (hostapd_ctrl_test_alloc_fail(hapd
, buf
+ 16) < 0)
2744 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
2745 reply_len
= hostapd_ctrl_get_alloc_fail(hapd
, reply
,
2747 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
2748 if (hostapd_ctrl_test_fail(hapd
, buf
+ 10) < 0)
2750 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
2751 reply_len
= hostapd_ctrl_get_fail(hapd
, reply
, reply_size
);
2752 } else if (os_strncmp(buf
, "RESET_PN ", 9) == 0) {
2753 if (hostapd_ctrl_reset_pn(hapd
, buf
+ 9) < 0)
2755 #endif /* CONFIG_TESTING_OPTIONS */
2756 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
2757 if (hostapd_ctrl_iface_chan_switch(hapd
->iface
, buf
+ 12))
2759 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
2760 reply_len
= hostapd_ctrl_iface_vendor(hapd
, buf
+ 7, reply
,
2762 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
2763 ieee802_1x_erp_flush(hapd
);
2764 #ifdef RADIUS_SERVER
2765 radius_server_erp_flush(hapd
->radius_srv
);
2766 #endif /* RADIUS_SERVER */
2767 } else if (os_strncmp(buf
, "EAPOL_REAUTH ", 13) == 0) {
2768 if (hostapd_ctrl_iface_eapol_reauth(hapd
, buf
+ 13))
2770 } else if (os_strncmp(buf
, "EAPOL_SET ", 10) == 0) {
2771 if (hostapd_ctrl_iface_eapol_set(hapd
, buf
+ 10))
2773 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
2774 reply_len
= hostapd_ctrl_iface_log_level(
2775 hapd
, buf
+ 9, reply
, reply_size
);
2777 } else if (os_strcmp(buf
, "TRACK_STA_LIST") == 0) {
2778 reply_len
= hostapd_ctrl_iface_track_sta_list(
2779 hapd
, reply
, reply_size
);
2780 #endif /* NEED_AP_MLME */
2781 } else if (os_strcmp(buf
, "PMKSA") == 0) {
2782 reply_len
= hostapd_ctrl_iface_pmksa_list(hapd
, reply
,
2784 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
2785 hostapd_ctrl_iface_pmksa_flush(hapd
);
2786 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
2787 if (hostapd_ctrl_iface_pmksa_add(hapd
, buf
+ 10) < 0)
2789 } else if (os_strncmp(buf
, "SET_NEIGHBOR ", 13) == 0) {
2790 if (hostapd_ctrl_iface_set_neighbor(hapd
, buf
+ 13))
2792 } else if (os_strncmp(buf
, "REMOVE_NEIGHBOR ", 16) == 0) {
2793 if (hostapd_ctrl_iface_remove_neighbor(hapd
, buf
+ 16))
2795 } else if (os_strncmp(buf
, "REQ_LCI ", 8) == 0) {
2796 if (hostapd_ctrl_iface_req_lci(hapd
, buf
+ 8))
2798 } else if (os_strncmp(buf
, "REQ_RANGE ", 10) == 0) {
2799 if (hostapd_ctrl_iface_req_range(hapd
, buf
+ 10))
2801 } else if (os_strncmp(buf
, "REQ_BEACON ", 11) == 0) {
2802 reply_len
= hostapd_ctrl_iface_req_beacon(hapd
, buf
+ 11,
2804 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
2805 reply_len
= hostapd_ctrl_driver_flags(hapd
->iface
, reply
,
2807 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
2810 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
2811 res
= hostapd_dpp_qr_code(hapd
, buf
+ 12);
2815 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2816 if (os_snprintf_error(reply_size
, reply_len
))
2819 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
2820 res
= hostapd_dpp_bootstrap_gen(hapd
, buf
+ 18);
2824 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2825 if (os_snprintf_error(reply_size
, reply_len
))
2828 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
2829 if (hostapd_dpp_bootstrap_remove(hapd
, buf
+ 21) < 0)
2831 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
2834 uri
= hostapd_dpp_bootstrap_get_uri(hapd
, atoi(buf
+ 22));
2838 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
2839 if (os_snprintf_error(reply_size
, reply_len
))
2842 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
2843 reply_len
= hostapd_dpp_bootstrap_info(hapd
, atoi(buf
+ 19),
2845 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
2846 if (hostapd_dpp_auth_init(hapd
, buf
+ 13) < 0)
2848 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
2849 res
= hostapd_dpp_configurator_add(hapd
, buf
+ 20);
2853 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2854 if (os_snprintf_error(reply_size
, reply_len
))
2857 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
2858 if (hostapd_dpp_configurator_remove(hapd
, buf
+ 24) < 0)
2860 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
2861 res
= hostapd_dpp_pkex_add(hapd
, buf
+ 12);
2865 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2866 if (os_snprintf_error(reply_size
, reply_len
))
2869 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
2870 if (hostapd_dpp_pkex_remove(hapd
, buf
+ 16) < 0)
2872 #endif /* CONFIG_DPP */
2874 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
2878 if (reply_len
< 0) {
2879 os_memcpy(reply
, "FAIL\n", 5);
2887 static void hostapd_ctrl_iface_receive(int sock
, void *eloop_ctx
,
2890 struct hostapd_data
*hapd
= eloop_ctx
;
2893 struct sockaddr_storage from
;
2894 socklen_t fromlen
= sizeof(from
);
2895 char *reply
, *pos
= buf
;
2896 const int reply_size
= 4096;
2898 int level
= MSG_DEBUG
;
2899 #ifdef CONFIG_CTRL_IFACE_UDP
2900 unsigned char lcookie
[COOKIE_LEN
];
2901 #endif /* CONFIG_CTRL_IFACE_UDP */
2903 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
2904 (struct sockaddr
*) &from
, &fromlen
);
2906 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
2912 reply
= os_malloc(reply_size
);
2913 if (reply
== NULL
) {
2914 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
2916 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
2922 #ifdef CONFIG_CTRL_IFACE_UDP
2923 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
2924 os_memcpy(reply
, "COOKIE=", 7);
2925 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
2926 cookie
, COOKIE_LEN
);
2927 reply_len
= 7 + 2 * COOKIE_LEN
;
2931 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
2932 hexstr2bin(buf
+ 7, lcookie
, COOKIE_LEN
) < 0) {
2933 wpa_printf(MSG_DEBUG
,
2934 "CTRL: No cookie in the request - drop request");
2939 if (os_memcmp(cookie
, lcookie
, COOKIE_LEN
) != 0) {
2940 wpa_printf(MSG_DEBUG
,
2941 "CTRL: Invalid cookie in the request - drop request");
2946 pos
= buf
+ 7 + 2 * COOKIE_LEN
;
2949 #endif /* CONFIG_CTRL_IFACE_UDP */
2951 if (os_strcmp(pos
, "PING") == 0)
2952 level
= MSG_EXCESSIVE
;
2953 wpa_hexdump_ascii(level
, "RX ctrl_iface", pos
, res
);
2955 reply_len
= hostapd_ctrl_iface_receive_process(hapd
, pos
,
2959 #ifdef CONFIG_CTRL_IFACE_UDP
2961 #endif /* CONFIG_CTRL_IFACE_UDP */
2962 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
2964 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
2971 #ifndef CONFIG_CTRL_IFACE_UDP
2972 static char * hostapd_ctrl_iface_path(struct hostapd_data
*hapd
)
2977 if (hapd
->conf
->ctrl_interface
== NULL
)
2980 len
= os_strlen(hapd
->conf
->ctrl_interface
) +
2981 os_strlen(hapd
->conf
->iface
) + 2;
2982 buf
= os_malloc(len
);
2986 os_snprintf(buf
, len
, "%s/%s",
2987 hapd
->conf
->ctrl_interface
, hapd
->conf
->iface
);
2988 buf
[len
- 1] = '\0';
2991 #endif /* CONFIG_CTRL_IFACE_UDP */
2994 static void hostapd_ctrl_iface_msg_cb(void *ctx
, int level
,
2995 enum wpa_msg_type type
,
2996 const char *txt
, size_t len
)
2998 struct hostapd_data
*hapd
= ctx
;
3001 hostapd_ctrl_iface_send(hapd
, level
, type
, txt
, len
);
3005 int hostapd_ctrl_iface_init(struct hostapd_data
*hapd
)
3007 #ifdef CONFIG_CTRL_IFACE_UDP
3008 int port
= HOSTAPD_CTRL_IFACE_PORT
;
3010 char port_str
[40], *tmp
;
3012 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3015 if (hapd
->ctrl_sock
> -1) {
3016 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3020 if (hapd
->conf
->ctrl_interface
== NULL
)
3023 pos
= os_strstr(hapd
->conf
->ctrl_interface
, "udp:");
3028 wpa_printf(MSG_ERROR
, "Invalid ctrl_iface UDP port");
3033 dl_list_init(&hapd
->ctrl_dst
);
3034 hapd
->ctrl_sock
= -1;
3035 os_get_random(cookie
, COOKIE_LEN
);
3037 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3038 hints
.ai_flags
= AI_PASSIVE
;
3039 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3041 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3042 hints
.ai_family
= AF_INET6
;
3043 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3044 hints
.ai_family
= AF_INET
;
3045 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3046 hints
.ai_socktype
= SOCK_DGRAM
;
3049 os_snprintf(p
, sizeof(p
), "%d", port
);
3050 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3052 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3057 hapd
->ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3059 if (hapd
->ctrl_sock
< 0) {
3060 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3064 if (bind(hapd
->ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) < 0) {
3066 if ((HOSTAPD_CTRL_IFACE_PORT
- port
) <
3067 HOSTAPD_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3069 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3073 freeaddrinfo(saveres
);
3075 os_snprintf(port_str
, sizeof(port_str
), "udp:%d", port
);
3076 tmp
= os_strdup(port_str
);
3078 os_free(hapd
->conf
->ctrl_interface
);
3079 hapd
->conf
->ctrl_interface
= tmp
;
3081 wpa_printf(MSG_DEBUG
, "ctrl_iface_init UDP port: %d", port
);
3083 if (eloop_register_read_sock(hapd
->ctrl_sock
,
3084 hostapd_ctrl_iface_receive
, hapd
, NULL
) <
3086 hostapd_ctrl_iface_deinit(hapd
);
3090 hapd
->msg_ctx
= hapd
;
3091 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3096 if (hapd
->ctrl_sock
>= 0)
3097 close(hapd
->ctrl_sock
);
3099 #else /* CONFIG_CTRL_IFACE_UDP */
3100 struct sockaddr_un addr
;
3104 if (hapd
->ctrl_sock
> -1) {
3105 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3109 dl_list_init(&hapd
->ctrl_dst
);
3111 if (hapd
->conf
->ctrl_interface
== NULL
)
3114 if (mkdir(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3115 if (errno
== EEXIST
) {
3116 wpa_printf(MSG_DEBUG
, "Using existing control "
3117 "interface directory.");
3119 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3125 if (hapd
->conf
->ctrl_interface_gid_set
&&
3126 chown(hapd
->conf
->ctrl_interface
, -1,
3127 hapd
->conf
->ctrl_interface_gid
) < 0) {
3128 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
3133 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3134 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3135 chown(hapd
->conf
->ctrl_interface
, -1,
3136 hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3137 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
3144 * Android is using umask 0077 which would leave the control interface
3145 * directory without group access. This breaks things since Wi-Fi
3146 * framework assumes that this directory can be accessed by other
3147 * applications in the wifi group. Fix this by adding group access even
3148 * if umask value would prevent this.
3150 if (chmod(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3151 wpa_printf(MSG_ERROR
, "CTRL: Could not chmod directory: %s",
3153 /* Try to continue anyway */
3155 #endif /* ANDROID */
3157 if (os_strlen(hapd
->conf
->ctrl_interface
) + 1 +
3158 os_strlen(hapd
->conf
->iface
) >= sizeof(addr
.sun_path
))
3161 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
3163 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
3167 os_memset(&addr
, 0, sizeof(addr
));
3169 addr
.sun_len
= sizeof(addr
);
3170 #endif /* __FreeBSD__ */
3171 addr
.sun_family
= AF_UNIX
;
3172 fname
= hostapd_ctrl_iface_path(hapd
);
3175 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
3176 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3177 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
3179 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3180 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
3181 " allow connections - assuming it was left"
3182 "over from forced program termination");
3183 if (unlink(fname
) < 0) {
3184 wpa_printf(MSG_ERROR
,
3185 "Could not unlink existing ctrl_iface socket '%s': %s",
3186 fname
, strerror(errno
));
3189 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
3191 wpa_printf(MSG_ERROR
,
3192 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
3196 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
3197 "ctrl_iface socket '%s'", fname
);
3199 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
3200 "be in use - cannot override it");
3201 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
3202 "not used anymore", fname
);
3209 if (hapd
->conf
->ctrl_interface_gid_set
&&
3210 chown(fname
, -1, hapd
->conf
->ctrl_interface_gid
) < 0) {
3211 wpa_printf(MSG_ERROR
, "chown[ctrl_interface/ifname]: %s",
3216 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3217 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3218 chown(fname
, -1, hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3219 wpa_printf(MSG_ERROR
, "chown[ctrl_interface/ifname]: %s",
3224 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
3225 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
3231 hapd
->ctrl_sock
= s
;
3232 if (eloop_register_read_sock(s
, hostapd_ctrl_iface_receive
, hapd
,
3234 hostapd_ctrl_iface_deinit(hapd
);
3237 hapd
->msg_ctx
= hapd
;
3238 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3250 #endif /* CONFIG_CTRL_IFACE_UDP */
3254 void hostapd_ctrl_iface_deinit(struct hostapd_data
*hapd
)
3256 struct wpa_ctrl_dst
*dst
, *prev
;
3258 if (hapd
->ctrl_sock
> -1) {
3259 #ifndef CONFIG_CTRL_IFACE_UDP
3261 #endif /* !CONFIG_CTRL_IFACE_UDP */
3263 eloop_unregister_read_sock(hapd
->ctrl_sock
);
3264 close(hapd
->ctrl_sock
);
3265 hapd
->ctrl_sock
= -1;
3266 #ifndef CONFIG_CTRL_IFACE_UDP
3267 fname
= hostapd_ctrl_iface_path(hapd
);
3272 if (hapd
->conf
->ctrl_interface
&&
3273 rmdir(hapd
->conf
->ctrl_interface
) < 0) {
3274 if (errno
== ENOTEMPTY
) {
3275 wpa_printf(MSG_DEBUG
, "Control interface "
3276 "directory not empty - leaving it "
3279 wpa_printf(MSG_ERROR
,
3280 "rmdir[ctrl_interface=%s]: %s",
3281 hapd
->conf
->ctrl_interface
,
3285 #endif /* !CONFIG_CTRL_IFACE_UDP */
3288 dl_list_for_each_safe(dst
, prev
, &hapd
->ctrl_dst
, struct wpa_ctrl_dst
,
3292 #ifdef CONFIG_TESTING_OPTIONS
3293 l2_packet_deinit(hapd
->l2_test
);
3294 hapd
->l2_test
= NULL
;
3295 #endif /* CONFIG_TESTING_OPTIONS */
3299 static int hostapd_ctrl_iface_add(struct hapd_interfaces
*interfaces
,
3302 if (hostapd_add_iface(interfaces
, buf
) < 0) {
3303 wpa_printf(MSG_ERROR
, "Adding interface %s failed", buf
);
3310 static int hostapd_ctrl_iface_remove(struct hapd_interfaces
*interfaces
,
3313 if (hostapd_remove_iface(interfaces
, buf
) < 0) {
3314 wpa_printf(MSG_ERROR
, "Removing interface %s failed", buf
);
3321 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces
*interfaces
,
3322 struct sockaddr_storage
*from
,
3325 return ctrl_iface_attach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
3329 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces
*interfaces
,
3330 struct sockaddr_storage
*from
,
3333 return ctrl_iface_detach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
3337 static void hostapd_ctrl_iface_flush(struct hapd_interfaces
*interfaces
)
3339 #ifdef CONFIG_WPS_TESTING
3340 wps_version_number
= 0x20;
3341 wps_testing_dummy_cred
= 0;
3342 wps_corrupt_pkhash
= 0;
3343 #endif /* CONFIG_WPS_TESTING */
3350 hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces
*interfaces
,
3353 char ifname
[IFNAMSIZ
+ 1];
3354 struct fst_iface_cfg cfg
;
3355 struct hostapd_data
*hapd
;
3356 struct fst_wpa_obj iface_obj
;
3358 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
3359 hapd
= hostapd_get_iface(interfaces
, ifname
);
3361 if (hapd
->iface
->fst
) {
3362 wpa_printf(MSG_INFO
, "FST: Already attached");
3365 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
3366 hapd
->iface
->fst
= fst_attach(ifname
, hapd
->own_addr
,
3368 if (hapd
->iface
->fst
)
3378 hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces
*interfaces
,
3381 char ifname
[IFNAMSIZ
+ 1];
3382 struct hostapd_data
* hapd
;
3384 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
3385 hapd
= hostapd_get_iface(interfaces
, ifname
);
3387 if (!fst_iface_detach(ifname
)) {
3388 hapd
->iface
->fst
= NULL
;
3389 hapd
->iface
->fst_ies
= NULL
;
3398 #endif /* CONFIG_FST */
3401 static struct hostapd_data
*
3402 hostapd_interfaces_get_hapd(struct hapd_interfaces
*interfaces
,
3407 for (i
= 0; i
< interfaces
->count
; i
++) {
3408 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
3410 for (j
= 0; j
< iface
->num_bss
; j
++) {
3411 struct hostapd_data
*hapd
;
3413 hapd
= iface
->bss
[j
];
3414 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
3423 static int hostapd_ctrl_iface_dup_param(struct hostapd_data
*src_hapd
,
3424 struct hostapd_data
*dst_hapd
,
3430 value
= os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
3432 wpa_printf(MSG_ERROR
,
3433 "DUP: cannot allocate buffer to stringify %s",
3438 if (os_strcmp(param
, "wpa") == 0) {
3439 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%d",
3440 src_hapd
->conf
->wpa
);
3441 } else if (os_strcmp(param
, "wpa_key_mgmt") == 0 &&
3442 src_hapd
->conf
->wpa_key_mgmt
) {
3443 res
= hostapd_ctrl_iface_get_key_mgmt(
3444 src_hapd
, value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
3445 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, res
))
3446 goto error_stringify
;
3447 } else if (os_strcmp(param
, "wpa_pairwise") == 0 &&
3448 src_hapd
->conf
->wpa_pairwise
) {
3449 res
= wpa_write_ciphers(value
,
3450 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
3451 src_hapd
->conf
->wpa_pairwise
, " ");
3453 goto error_stringify
;
3454 } else if (os_strcmp(param
, "rsn_pairwise") == 0 &&
3455 src_hapd
->conf
->rsn_pairwise
) {
3456 res
= wpa_write_ciphers(value
,
3457 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
3458 src_hapd
->conf
->rsn_pairwise
, " ");
3460 goto error_stringify
;
3461 } else if (os_strcmp(param
, "wpa_passphrase") == 0 &&
3462 src_hapd
->conf
->ssid
.wpa_passphrase
) {
3463 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%s",
3464 src_hapd
->conf
->ssid
.wpa_passphrase
);
3465 } else if (os_strcmp(param
, "wpa_psk") == 0 &&
3466 src_hapd
->conf
->ssid
.wpa_psk_set
) {
3467 wpa_snprintf_hex(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
3468 src_hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
3470 wpa_printf(MSG_WARNING
, "DUP: %s cannot be duplicated", param
);
3474 res
= hostapd_set_iface(dst_hapd
->iconf
, dst_hapd
->conf
, param
, value
);
3479 wpa_printf(MSG_ERROR
, "DUP: cannot stringify %s", param
);
3487 hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces
*interfaces
,
3489 char *reply
, int reply_size
)
3494 struct hostapd_iface
*iface
;
3498 show_ctrl
= !!os_strstr(input
, "ctrl");
3501 end
= reply
+ reply_size
;
3503 for (i
= 0; i
< interfaces
->count
; i
++) {
3504 iface
= interfaces
->iface
[i
];
3506 for (j
= 0; j
< iface
->num_bss
; j
++) {
3507 struct hostapd_bss_config
*conf
;
3509 conf
= iface
->conf
->bss
[j
];
3511 res
= os_snprintf(pos
, end
- pos
,
3512 "%s ctrl_iface=%s\n",
3514 conf
->ctrl_interface
?
3515 conf
->ctrl_interface
: "N/A");
3517 res
= os_snprintf(pos
, end
- pos
, "%s\n",
3519 if (os_snprintf_error(end
- pos
, res
)) {
3532 hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces
*interfaces
,
3535 char *p_start
= cmd
, *p_end
;
3536 struct hostapd_data
*src_hapd
, *dst_hapd
;
3538 /* cmd: "<src ifname> <dst ifname> <variable name> */
3540 p_end
= os_strchr(p_start
, ' ');
3542 wpa_printf(MSG_ERROR
, "DUP: no src ifname found in cmd: '%s'",
3548 src_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
3550 wpa_printf(MSG_ERROR
, "DUP: no src ifname found: '%s'",
3555 p_start
= p_end
+ 1;
3556 p_end
= os_strchr(p_start
, ' ');
3558 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found in cmd: '%s'",
3564 dst_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
3566 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found: '%s'",
3571 p_start
= p_end
+ 1;
3572 return hostapd_ctrl_iface_dup_param(src_hapd
, dst_hapd
, p_start
);
3576 static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces
*interfaces
,
3578 char *buf
, char *reply
,
3580 struct sockaddr_storage
*from
,
3583 struct hostapd_data
*hapd
;
3585 hapd
= hostapd_interfaces_get_hapd(interfaces
, ifname
);
3589 res
= os_snprintf(reply
, reply_size
, "FAIL-NO-IFNAME-MATCH\n");
3590 if (os_snprintf_error(reply_size
, res
))
3595 return hostapd_ctrl_iface_receive_process(hapd
, buf
, reply
,reply_size
,
3600 static void hostapd_global_ctrl_iface_receive(int sock
, void *eloop_ctx
,
3603 void *interfaces
= eloop_ctx
;
3604 char buffer
[256], *buf
= buffer
;
3606 struct sockaddr_storage from
;
3607 socklen_t fromlen
= sizeof(from
);
3610 const int reply_size
= 4096;
3611 #ifdef CONFIG_CTRL_IFACE_UDP
3612 unsigned char lcookie
[COOKIE_LEN
];
3613 #endif /* CONFIG_CTRL_IFACE_UDP */
3615 res
= recvfrom(sock
, buffer
, sizeof(buffer
) - 1, 0,
3616 (struct sockaddr
*) &from
, &fromlen
);
3618 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
3623 wpa_printf(MSG_DEBUG
, "Global ctrl_iface command: %s", buf
);
3625 reply
= os_malloc(reply_size
);
3626 if (reply
== NULL
) {
3627 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
3629 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3635 os_memcpy(reply
, "OK\n", 3);
3638 #ifdef CONFIG_CTRL_IFACE_UDP
3639 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
3640 os_memcpy(reply
, "COOKIE=", 7);
3641 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
3642 gcookie
, COOKIE_LEN
);
3643 reply_len
= 7 + 2 * COOKIE_LEN
;
3647 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
3648 hexstr2bin(buf
+ 7, lcookie
, COOKIE_LEN
) < 0) {
3649 wpa_printf(MSG_DEBUG
,
3650 "CTRL: No cookie in the request - drop request");
3655 if (os_memcmp(gcookie
, lcookie
, COOKIE_LEN
) != 0) {
3656 wpa_printf(MSG_DEBUG
,
3657 "CTRL: Invalid cookie in the request - drop request");
3662 buf
+= 7 + 2 * COOKIE_LEN
;
3665 #endif /* CONFIG_CTRL_IFACE_UDP */
3667 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
3668 char *pos
= os_strchr(buf
+ 7, ' ');
3672 reply_len
= hostapd_global_ctrl_iface_ifname(
3673 interfaces
, buf
+ 7, pos
, reply
, reply_size
,
3679 if (os_strcmp(buf
, "PING") == 0) {
3680 os_memcpy(reply
, "PONG\n", 5);
3682 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3683 if (wpa_debug_reopen_file() < 0)
3685 } else if (os_strcmp(buf
, "FLUSH") == 0) {
3686 hostapd_ctrl_iface_flush(interfaces
);
3687 } else if (os_strncmp(buf
, "ADD ", 4) == 0) {
3688 if (hostapd_ctrl_iface_add(interfaces
, buf
+ 4) < 0)
3690 } else if (os_strncmp(buf
, "REMOVE ", 7) == 0) {
3691 if (hostapd_ctrl_iface_remove(interfaces
, buf
+ 7) < 0)
3693 } else if (os_strcmp(buf
, "ATTACH") == 0) {
3694 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
3697 } else if (os_strcmp(buf
, "DETACH") == 0) {
3698 if (hostapd_global_ctrl_iface_detach(interfaces
, &from
,
3701 #ifdef CONFIG_MODULE_TESTS
3702 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
3703 if (hapd_module_tests() < 0)
3705 #endif /* CONFIG_MODULE_TESTS */
3707 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
3708 if (!hostapd_global_ctrl_iface_fst_attach(interfaces
, buf
+ 11))
3709 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
3712 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
3713 if (!hostapd_global_ctrl_iface_fst_detach(interfaces
, buf
+ 11))
3714 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
3717 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
3718 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
3719 #endif /* CONFIG_FST */
3720 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
3721 if (!hostapd_global_ctrl_iface_dup_network(interfaces
,
3723 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
3726 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
3727 reply_len
= hostapd_global_ctrl_iface_interfaces(
3728 interfaces
, buf
+ 10, reply
, sizeof(buffer
));
3729 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
3732 wpa_printf(MSG_DEBUG
, "Unrecognized global ctrl_iface command "
3738 if (reply_len
< 0) {
3739 os_memcpy(reply
, "FAIL\n", 5);
3743 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
3745 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3752 #ifndef CONFIG_CTRL_IFACE_UDP
3753 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces
*interface
)
3758 if (interface
->global_iface_path
== NULL
)
3761 len
= os_strlen(interface
->global_iface_path
) +
3762 os_strlen(interface
->global_iface_name
) + 2;
3763 buf
= os_malloc(len
);
3767 os_snprintf(buf
, len
, "%s/%s", interface
->global_iface_path
,
3768 interface
->global_iface_name
);
3769 buf
[len
- 1] = '\0';
3772 #endif /* CONFIG_CTRL_IFACE_UDP */
3775 int hostapd_global_ctrl_iface_init(struct hapd_interfaces
*interface
)
3777 #ifdef CONFIG_CTRL_IFACE_UDP
3778 int port
= HOSTAPD_GLOBAL_CTRL_IFACE_PORT
;
3781 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3784 if (interface
->global_ctrl_sock
> -1) {
3785 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3789 if (interface
->global_iface_path
== NULL
)
3792 pos
= os_strstr(interface
->global_iface_path
, "udp:");
3797 wpa_printf(MSG_ERROR
, "Invalid global ctrl UDP port");
3802 os_get_random(gcookie
, COOKIE_LEN
);
3804 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3805 hints
.ai_flags
= AI_PASSIVE
;
3806 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3808 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3809 hints
.ai_family
= AF_INET6
;
3810 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3811 hints
.ai_family
= AF_INET
;
3812 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3813 hints
.ai_socktype
= SOCK_DGRAM
;
3816 os_snprintf(p
, sizeof(p
), "%d", port
);
3817 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3819 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3824 interface
->global_ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3826 if (interface
->global_ctrl_sock
< 0) {
3827 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3831 if (bind(interface
->global_ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) <
3834 if ((port
- HOSTAPD_GLOBAL_CTRL_IFACE_PORT
) <
3835 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3837 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3841 freeaddrinfo(saveres
);
3843 wpa_printf(MSG_DEBUG
, "global ctrl_iface_init UDP port: %d", port
);
3845 if (eloop_register_read_sock(interface
->global_ctrl_sock
,
3846 hostapd_global_ctrl_iface_receive
,
3847 interface
, NULL
) < 0) {
3848 hostapd_global_ctrl_iface_deinit(interface
);
3855 if (interface
->global_ctrl_sock
>= 0)
3856 close(interface
->global_ctrl_sock
);
3858 #else /* CONFIG_CTRL_IFACE_UDP */
3859 struct sockaddr_un addr
;
3863 if (interface
->global_iface_path
== NULL
) {
3864 wpa_printf(MSG_DEBUG
, "ctrl_iface not configured!");
3868 if (mkdir(interface
->global_iface_path
, S_IRWXU
| S_IRWXG
) < 0) {
3869 if (errno
== EEXIST
) {
3870 wpa_printf(MSG_DEBUG
, "Using existing control "
3871 "interface directory.");
3873 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3877 } else if (interface
->ctrl_iface_group
&&
3878 chown(interface
->global_iface_path
, -1,
3879 interface
->ctrl_iface_group
) < 0) {
3880 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
3885 if (os_strlen(interface
->global_iface_path
) + 1 +
3886 os_strlen(interface
->global_iface_name
) >= sizeof(addr
.sun_path
))
3889 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
3891 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
3895 os_memset(&addr
, 0, sizeof(addr
));
3897 addr
.sun_len
= sizeof(addr
);
3898 #endif /* __FreeBSD__ */
3899 addr
.sun_family
= AF_UNIX
;
3900 fname
= hostapd_global_ctrl_iface_path(interface
);
3903 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
3904 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3905 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
3907 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3908 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
3909 " allow connections - assuming it was left"
3910 "over from forced program termination");
3911 if (unlink(fname
) < 0) {
3912 wpa_printf(MSG_ERROR
,
3913 "Could not unlink existing ctrl_iface socket '%s': %s",
3914 fname
, strerror(errno
));
3917 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
3919 wpa_printf(MSG_ERROR
, "bind(PF_UNIX): %s",
3923 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
3924 "ctrl_iface socket '%s'", fname
);
3926 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
3927 "be in use - cannot override it");
3928 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
3929 "not used anymore", fname
);
3936 if (interface
->ctrl_iface_group
&&
3937 chown(fname
, -1, interface
->ctrl_iface_group
) < 0) {
3938 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
3943 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
3944 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
3950 interface
->global_ctrl_sock
= s
;
3951 eloop_register_read_sock(s
, hostapd_global_ctrl_iface_receive
,
3964 #endif /* CONFIG_CTRL_IFACE_UDP */
3968 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces
*interfaces
)
3970 #ifndef CONFIG_CTRL_IFACE_UDP
3972 #endif /* CONFIG_CTRL_IFACE_UDP */
3973 struct wpa_ctrl_dst
*dst
, *prev
;
3975 if (interfaces
->global_ctrl_sock
> -1) {
3976 eloop_unregister_read_sock(interfaces
->global_ctrl_sock
);
3977 close(interfaces
->global_ctrl_sock
);
3978 interfaces
->global_ctrl_sock
= -1;
3979 #ifndef CONFIG_CTRL_IFACE_UDP
3980 fname
= hostapd_global_ctrl_iface_path(interfaces
);
3986 if (interfaces
->global_iface_path
&&
3987 rmdir(interfaces
->global_iface_path
) < 0) {
3988 if (errno
== ENOTEMPTY
) {
3989 wpa_printf(MSG_DEBUG
, "Control interface "
3990 "directory not empty - leaving it "
3993 wpa_printf(MSG_ERROR
,
3994 "rmdir[ctrl_interface=%s]: %s",
3995 interfaces
->global_iface_path
,
3999 #endif /* CONFIG_CTRL_IFACE_UDP */
4002 os_free(interfaces
->global_iface_path
);
4003 interfaces
->global_iface_path
= NULL
;
4005 dl_list_for_each_safe(dst
, prev
, &interfaces
->global_ctrl_dst
,
4006 struct wpa_ctrl_dst
, list
)
4011 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
4012 enum wpa_msg_type type
,
4013 const char *buf
, size_t len
)
4015 struct wpa_ctrl_dst
*dst
, *next
;
4016 struct dl_list
*ctrl_dst
;
4023 if (type
!= WPA_MSG_ONLY_GLOBAL
) {
4024 s
= hapd
->ctrl_sock
;
4025 ctrl_dst
= &hapd
->ctrl_dst
;
4027 s
= hapd
->iface
->interfaces
->global_ctrl_sock
;
4028 ctrl_dst
= &hapd
->iface
->interfaces
->global_ctrl_dst
;
4031 if (s
< 0 || dl_list_empty(ctrl_dst
))
4034 os_snprintf(levelstr
, sizeof(levelstr
), "<%d>", level
);
4035 io
[0].iov_base
= levelstr
;
4036 io
[0].iov_len
= os_strlen(levelstr
);
4037 io
[1].iov_base
= (char *) buf
;
4038 io
[1].iov_len
= len
;
4039 os_memset(&msg
, 0, sizeof(msg
));
4044 dl_list_for_each_safe(dst
, next
, ctrl_dst
, struct wpa_ctrl_dst
, list
) {
4045 if (level
>= dst
->debug_level
) {
4046 sockaddr_print(MSG_DEBUG
, "CTRL_IFACE monitor send",
4047 &dst
->addr
, dst
->addrlen
);
4048 msg
.msg_name
= &dst
->addr
;
4049 msg
.msg_namelen
= dst
->addrlen
;
4050 if (sendmsg(s
, &msg
, 0) < 0) {
4052 wpa_printf(MSG_INFO
, "CTRL_IFACE monitor[%d]: "
4054 idx
, errno
, strerror(errno
));
4056 if (dst
->errors
> 10 || _errno
== ENOENT
) {
4057 if (type
!= WPA_MSG_ONLY_GLOBAL
)
4058 hostapd_ctrl_iface_detach(
4062 hostapd_global_ctrl_iface_detach(
4063 hapd
->iface
->interfaces
,
4074 #endif /* CONFIG_NATIVE_WINDOWS */