2 * hostapd / UNIX domain socket -based control interface
3 * Copyright (c) 2004-2018, 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
15 #include <net/if_ether.h>
17 #include <net/ethernet.h>
19 #include <netinet/ip.h>
20 #endif /* CONFIG_TESTING_OPTIONS */
26 #ifdef CONFIG_CTRL_IFACE_UDP
28 #endif /* CONFIG_CTRL_IFACE_UDP */
30 #include "utils/common.h"
31 #include "utils/eloop.h"
32 #include "utils/module_tests.h"
33 #include "common/version.h"
34 #include "common/ieee802_11_defs.h"
35 #include "common/ctrl_iface_common.h"
37 #include "common/dpp.h"
38 #endif /* CONFIG_DPP */
39 #include "common/wpa_ctrl.h"
40 #include "crypto/tls.h"
41 #include "drivers/driver.h"
42 #include "eapol_auth/eapol_auth_sm.h"
43 #include "radius/radius_client.h"
44 #include "radius/radius_server.h"
45 #include "l2_packet/l2_packet.h"
46 #include "ap/hostapd.h"
47 #include "ap/ap_config.h"
48 #include "ap/ieee802_1x.h"
49 #include "ap/wpa_auth.h"
50 #include "ap/ieee802_11.h"
51 #include "ap/sta_info.h"
52 #include "ap/wps_hostapd.h"
53 #include "ap/ctrl_iface_ap.h"
54 #include "ap/ap_drv_ops.h"
56 #include "ap/wnm_ap.h"
57 #include "ap/wpa_auth.h"
58 #include "ap/beacon.h"
59 #include "ap/neighbor_db.h"
61 #include "ap/dpp_hostapd.h"
62 #include "wps/wps_defs.h"
64 #include "fst/fst_ctrl_iface.h"
65 #include "config_file.h"
66 #include "ctrl_iface.h"
69 #define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
71 #ifdef CONFIG_CTRL_IFACE_UDP
72 #define HOSTAPD_CTRL_IFACE_PORT 8877
73 #define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
74 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
75 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
76 #endif /* CONFIG_CTRL_IFACE_UDP */
78 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
79 enum wpa_msg_type type
,
80 const char *buf
, size_t len
);
83 static int hostapd_ctrl_iface_attach(struct hostapd_data
*hapd
,
84 struct sockaddr_storage
*from
,
85 socklen_t fromlen
, const char *input
)
87 return ctrl_iface_attach(&hapd
->ctrl_dst
, from
, fromlen
, input
);
91 static int hostapd_ctrl_iface_detach(struct hostapd_data
*hapd
,
92 struct sockaddr_storage
*from
,
95 return ctrl_iface_detach(&hapd
->ctrl_dst
, from
, fromlen
);
99 static int hostapd_ctrl_iface_level(struct hostapd_data
*hapd
,
100 struct sockaddr_storage
*from
,
104 return ctrl_iface_level(&hapd
->ctrl_dst
, from
, fromlen
, level
);
108 static int hostapd_ctrl_iface_new_sta(struct hostapd_data
*hapd
,
112 struct sta_info
*sta
;
114 wpa_printf(MSG_DEBUG
, "CTRL_IFACE NEW_STA %s", txtaddr
);
116 if (hwaddr_aton(txtaddr
, addr
))
119 sta
= ap_get_sta(hapd
, addr
);
123 wpa_printf(MSG_DEBUG
, "Add new STA " MACSTR
" based on ctrl_iface "
124 "notification", MAC2STR(addr
));
125 sta
= ap_sta_add(hapd
, addr
);
129 hostapd_new_assoc_sta(hapd
, sta
, 0);
135 static int hostapd_ctrl_iface_sa_query(struct hostapd_data
*hapd
,
139 u8 trans_id
[WLAN_SA_QUERY_TR_ID_LEN
];
141 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SA_QUERY %s", txtaddr
);
143 if (hwaddr_aton(txtaddr
, addr
) ||
144 os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0)
147 ieee802_11_send_sa_query_req(hapd
, addr
, trans_id
);
151 #endif /* NEED_AP_MLME */
155 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data
*hapd
, char *txt
)
157 char *pin
= os_strchr(txt
, ' ');
160 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
167 timeout_txt
= os_strchr(pin
, ' ');
169 *timeout_txt
++ = '\0';
170 timeout
= atoi(timeout_txt
);
171 pos
= os_strchr(timeout_txt
, ' ');
174 if (hwaddr_aton(pos
, addr_buf
) == 0)
180 return hostapd_wps_add_pin(hapd
, addr
, txt
, pin
, timeout
);
184 static int hostapd_ctrl_iface_wps_check_pin(
185 struct hostapd_data
*hapd
, char *cmd
, char *buf
, size_t buflen
)
192 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
193 (u8
*) cmd
, os_strlen(cmd
));
194 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
195 if (*pos
< '0' || *pos
> '9')
199 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
203 if (len
!= 4 && len
!= 8) {
204 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
210 unsigned int pin_val
;
212 if (!wps_pin_valid(pin_val
)) {
213 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
214 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
215 if (os_snprintf_error(buflen
, ret
))
221 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
222 if (os_snprintf_error(buflen
, ret
))
229 #ifdef CONFIG_WPS_NFC
230 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data
*hapd
,
237 len
= os_strlen(pos
);
242 buf
= wpabuf_alloc(len
);
245 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
250 ret
= hostapd_wps_nfc_tag_read(hapd
, buf
);
257 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data
*hapd
,
258 char *cmd
, char *reply
,
265 if (os_strcmp(cmd
, "WPS") == 0)
267 else if (os_strcmp(cmd
, "NDEF") == 0)
272 buf
= hostapd_wps_nfc_config_token(hapd
, ndef
);
276 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
287 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data
*hapd
,
288 char *reply
, size_t max_len
,
294 buf
= hostapd_wps_nfc_token_gen(hapd
, ndef
);
298 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
309 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data
*hapd
,
310 char *cmd
, char *reply
,
313 if (os_strcmp(cmd
, "WPS") == 0)
314 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
317 if (os_strcmp(cmd
, "NDEF") == 0)
318 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
321 if (os_strcmp(cmd
, "enable") == 0)
322 return hostapd_wps_nfc_token_enable(hapd
);
324 if (os_strcmp(cmd
, "disable") == 0) {
325 hostapd_wps_nfc_token_disable(hapd
);
333 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data
*hapd
,
334 char *cmd
, char *reply
,
342 pos
= os_strchr(cmd
, ' ');
347 if (os_strcmp(cmd
, "WPS") == 0)
349 else if (os_strcmp(cmd
, "NDEF") == 0)
354 if (os_strcmp(pos
, "WPS-CR") == 0)
355 buf
= hostapd_wps_nfc_hs_cr(hapd
, ndef
);
361 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
372 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data
*hapd
,
376 struct wpabuf
*req
, *sel
;
378 char *pos
, *role
, *type
, *pos2
;
381 pos
= os_strchr(role
, ' ');
387 pos
= os_strchr(type
, ' ');
392 pos2
= os_strchr(pos
, ' ');
397 len
= os_strlen(pos
);
402 req
= wpabuf_alloc(len
);
405 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
410 len
= os_strlen(pos2
);
417 sel
= wpabuf_alloc(len
);
422 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
428 if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0) {
429 ret
= hostapd_wps_nfc_report_handover(hapd
, req
, sel
);
431 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
432 "reported: role=%s type=%s", role
, type
);
441 #endif /* CONFIG_WPS_NFC */
444 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data
*hapd
, char *txt
,
445 char *buf
, size_t buflen
)
451 pos
= os_strchr(txt
, ' ');
455 if (os_strcmp(txt
, "disable") == 0) {
456 hostapd_wps_ap_pin_disable(hapd
);
457 return os_snprintf(buf
, buflen
, "OK\n");
460 if (os_strcmp(txt
, "random") == 0) {
463 pin_txt
= hostapd_wps_ap_pin_random(hapd
, timeout
);
466 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
469 if (os_strcmp(txt
, "get") == 0) {
470 pin_txt
= hostapd_wps_ap_pin_get(hapd
);
473 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
476 if (os_strcmp(txt
, "set") == 0) {
481 pos
= os_strchr(pos
, ' ');
486 if (os_strlen(pin
) > buflen
)
488 if (hostapd_wps_ap_pin_set(hapd
, pin
, timeout
) < 0)
490 return os_snprintf(buf
, buflen
, "%s", pin
);
497 static int hostapd_ctrl_iface_wps_config(struct hostapd_data
*hapd
, char *txt
)
500 char *ssid
, *auth
, *encr
= NULL
, *key
= NULL
;
503 pos
= os_strchr(txt
, ' ');
509 pos
= os_strchr(pos
, ' ');
513 pos
= os_strchr(pos
, ' ');
520 return hostapd_wps_config_ap(hapd
, ssid
, auth
, encr
, key
);
524 static const char * pbc_status_str(enum pbc_status status
)
527 case WPS_PBC_STATUS_DISABLE
:
529 case WPS_PBC_STATUS_ACTIVE
:
531 case WPS_PBC_STATUS_TIMEOUT
:
533 case WPS_PBC_STATUS_OVERLAP
:
541 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data
*hapd
,
542 char *buf
, size_t buflen
)
550 ret
= os_snprintf(pos
, end
- pos
, "PBC Status: %s\n",
551 pbc_status_str(hapd
->wps_stats
.pbc_status
));
553 if (os_snprintf_error(end
- pos
, ret
))
557 ret
= os_snprintf(pos
, end
- pos
, "Last WPS result: %s\n",
558 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
560 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
561 "Failed" : "None")));
563 if (os_snprintf_error(end
- pos
, ret
))
567 /* If status == Failure - Add possible Reasons */
568 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
569 hapd
->wps_stats
.failure_reason
> 0) {
570 ret
= os_snprintf(pos
, end
- pos
,
571 "Failure Reason: %s\n",
572 wps_ei_str(hapd
->wps_stats
.failure_reason
));
574 if (os_snprintf_error(end
- pos
, ret
))
579 if (hapd
->wps_stats
.status
) {
580 ret
= os_snprintf(pos
, end
- pos
, "Peer Address: " MACSTR
"\n",
581 MAC2STR(hapd
->wps_stats
.peer_addr
));
583 if (os_snprintf_error(end
- pos
, ret
))
591 #endif /* CONFIG_WPS */
595 static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data
*hapd
,
601 if (hwaddr_aton(cmd
, addr
))
614 return hs20_send_wnm_notification(hapd
, addr
, 1, url
);
618 static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data
*hapd
,
622 int code
, reauth_delay
, ret
;
627 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
628 if (hwaddr_aton(cmd
, addr
))
631 pos
= os_strchr(cmd
, ' ');
637 pos
= os_strchr(pos
, ' ');
641 reauth_delay
= atoi(pos
);
644 pos
= os_strchr(pos
, ' ');
647 url_len
= os_strlen(pos
);
650 req
= wpabuf_alloc(4 + url_len
);
653 wpabuf_put_u8(req
, code
);
654 wpabuf_put_le16(req
, reauth_delay
);
655 wpabuf_put_u8(req
, url_len
);
657 wpabuf_put_data(req
, pos
, url_len
);
659 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to " MACSTR
660 " to indicate imminent deauthentication (code=%d "
661 "reauth_delay=%d)", MAC2STR(addr
), code
, reauth_delay
);
662 ret
= hs20_send_wnm_notification_deauth_req(hapd
, addr
, req
);
667 #endif /* CONFIG_HS20 */
670 #ifdef CONFIG_INTERWORKING
672 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data
*hapd
,
675 u8 qos_map_set
[16 + 2 * 21], count
= 0;
676 const char *pos
= cmd
;
680 if (count
== sizeof(qos_map_set
)) {
681 wpa_printf(MSG_ERROR
, "Too many qos_map_set parameters");
686 if (val
< 0 || val
> 255) {
687 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
691 qos_map_set
[count
++] = val
;
692 pos
= os_strchr(pos
, ',');
698 if (count
< 16 || count
& 1) {
699 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
703 ret
= hostapd_drv_set_qos_map(hapd
, qos_map_set
, count
);
705 wpa_printf(MSG_INFO
, "Failed to set QoS Map Set");
709 os_memcpy(hapd
->conf
->qos_map_set
, qos_map_set
, count
);
710 hapd
->conf
->qos_map_set_len
= count
;
716 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data
*hapd
,
720 struct sta_info
*sta
;
722 u8
*qos_map_set
= hapd
->conf
->qos_map_set
;
723 u8 qos_map_set_len
= hapd
->conf
->qos_map_set_len
;
726 if (!qos_map_set_len
) {
727 wpa_printf(MSG_INFO
, "QoS Map Set is not set");
731 if (hwaddr_aton(cmd
, addr
))
734 sta
= ap_get_sta(hapd
, addr
);
736 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" not found "
737 "for QoS Map Configuration message",
742 if (!sta
->qos_map_enabled
) {
743 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" did not indicate "
744 "support for QoS Map", MAC2STR(addr
));
748 buf
= wpabuf_alloc(2 + 2 + qos_map_set_len
);
752 wpabuf_put_u8(buf
, WLAN_ACTION_QOS
);
753 wpabuf_put_u8(buf
, QOS_QOS_MAP_CONFIG
);
755 /* QoS Map Set Element */
756 wpabuf_put_u8(buf
, WLAN_EID_QOS_MAP_SET
);
757 wpabuf_put_u8(buf
, qos_map_set_len
);
758 wpabuf_put_data(buf
, qos_map_set
, qos_map_set_len
);
760 ret
= hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, addr
,
761 wpabuf_head(buf
), wpabuf_len(buf
));
767 #endif /* CONFIG_INTERWORKING */
772 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data
*hapd
,
777 struct sta_info
*sta
;
779 if (hwaddr_aton(cmd
, addr
))
783 disassoc_timer
= atoi(cmd
+ 17);
785 sta
= ap_get_sta(hapd
, addr
);
787 wpa_printf(MSG_DEBUG
, "Station " MACSTR
788 " not found for disassociation imminent message",
793 return wnm_send_disassoc_imminent(hapd
, sta
, disassoc_timer
);
797 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data
*hapd
,
801 const char *url
, *timerstr
;
803 struct sta_info
*sta
;
805 if (hwaddr_aton(cmd
, addr
))
808 sta
= ap_get_sta(hapd
, addr
);
810 wpa_printf(MSG_DEBUG
, "Station " MACSTR
811 " not found for ESS disassociation imminent message",
817 if (*timerstr
!= ' ')
820 disassoc_timer
= atoi(timerstr
);
821 if (disassoc_timer
< 0 || disassoc_timer
> 65535)
824 url
= os_strchr(timerstr
, ' ');
829 return wnm_send_ess_disassoc_imminent(hapd
, sta
, url
, disassoc_timer
);
833 static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data
*hapd
,
837 const char *pos
, *end
;
838 int disassoc_timer
= 0;
839 struct sta_info
*sta
;
840 u8 req_mode
= 0, valid_int
= 0x01;
849 if (hwaddr_aton(cmd
, addr
)) {
850 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
854 sta
= ap_get_sta(hapd
, addr
);
856 wpa_printf(MSG_DEBUG
, "Station " MACSTR
857 " not found for BSS TM Request message",
862 pos
= os_strstr(cmd
, " disassoc_timer=");
865 disassoc_timer
= atoi(pos
);
866 if (disassoc_timer
< 0 || disassoc_timer
> 65535) {
867 wpa_printf(MSG_DEBUG
, "Invalid disassoc_timer");
872 pos
= os_strstr(cmd
, " valid_int=");
875 valid_int
= atoi(pos
);
878 pos
= os_strstr(cmd
, " bss_term=");
881 req_mode
|= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED
;
882 /* TODO: TSF configurable/learnable */
883 bss_term_dur
[0] = 4; /* Subelement ID */
884 bss_term_dur
[1] = 10; /* Length */
885 os_memset(&bss_term_dur
[2], 0, 8);
886 end
= os_strchr(pos
, ',');
888 wpa_printf(MSG_DEBUG
, "Invalid bss_term data");
892 WPA_PUT_LE16(&bss_term_dur
[10], atoi(end
));
895 nei_len
= ieee802_11_parse_candidate_list(cmd
, nei_rep
,
900 pos
= os_strstr(cmd
, " url=");
904 end
= os_strchr(pos
, ' ');
908 len
= os_strlen(pos
);
909 url
= os_malloc(len
+ 1);
912 os_memcpy(url
, pos
, len
);
914 req_mode
|= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT
;
917 if (os_strstr(cmd
, " pref=1"))
918 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
919 if (os_strstr(cmd
, " abridged=1"))
920 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
921 if (os_strstr(cmd
, " disassoc_imminent=1"))
922 req_mode
|= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
925 pos
= os_strstr(cmd
, "mbo=");
927 unsigned int mbo_reason
, cell_pref
, reassoc_delay
;
930 ret
= sscanf(pos
, "mbo=%u:%u:%u", &mbo_reason
,
931 &reassoc_delay
, &cell_pref
);
933 wpa_printf(MSG_DEBUG
,
934 "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
939 if (mbo_reason
> MBO_TRANSITION_REASON_PREMIUM_AP
) {
940 wpa_printf(MSG_DEBUG
,
941 "Invalid MBO transition reason code %u",
947 /* Valid values for Cellular preference are: 0, 1, 255 */
948 if (cell_pref
!= 0 && cell_pref
!= 1 && cell_pref
!= 255) {
949 wpa_printf(MSG_DEBUG
,
950 "Invalid MBO cellular capability %u",
956 if (reassoc_delay
> 65535 ||
958 !(req_mode
& WNM_BSS_TM_REQ_DISASSOC_IMMINENT
))) {
959 wpa_printf(MSG_DEBUG
,
960 "MBO: Assoc retry delay is only valid in disassoc imminent mode");
965 *mbo_pos
++ = MBO_ATTR_ID_TRANSITION_REASON
;
967 *mbo_pos
++ = mbo_reason
;
968 *mbo_pos
++ = MBO_ATTR_ID_CELL_DATA_PREF
;
970 *mbo_pos
++ = cell_pref
;
973 *mbo_pos
++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY
;
975 WPA_PUT_LE16(mbo_pos
, reassoc_delay
);
979 mbo_len
= mbo_pos
- mbo
;
981 #endif /* CONFIG_MBO */
983 ret
= wnm_send_bss_tm_req(hapd
, sta
, req_mode
, disassoc_timer
,
984 valid_int
, bss_term_dur
, url
,
985 nei_len
? nei_rep
: NULL
, nei_len
,
986 mbo_len
? mbo
: NULL
, mbo_len
);
989 #endif /* CONFIG_MBO */
995 static int hostapd_ctrl_iface_coloc_intf_req(struct hostapd_data
*hapd
,
999 struct sta_info
*sta
;
1001 unsigned int auto_report
, timeout
;
1003 if (hwaddr_aton(cmd
, addr
)) {
1004 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
1008 sta
= ap_get_sta(hapd
, addr
);
1010 wpa_printf(MSG_DEBUG
, "Station " MACSTR
1011 " not found for Collocated Interference Request",
1020 auto_report
= atoi(pos
);
1021 pos
= os_strchr(pos
, ' ');
1025 timeout
= atoi(pos
);
1027 return wnm_send_coloc_intf_req(hapd
, sta
, auto_report
, timeout
);
1030 #endif /* CONFIG_WNM_AP */
1033 static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data
*hapd
,
1034 char *buf
, size_t buflen
)
1042 WPA_ASSERT(hapd
->conf
->wpa_key_mgmt
);
1044 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) {
1045 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK ");
1046 if (os_snprintf_error(end
- pos
, ret
))
1050 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1051 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP ");
1052 if (os_snprintf_error(end
- pos
, ret
))
1056 #ifdef CONFIG_IEEE80211R_AP
1057 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1058 ret
= os_snprintf(pos
, end
- pos
, "FT-PSK ");
1059 if (os_snprintf_error(end
- pos
, ret
))
1063 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1064 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP ");
1065 if (os_snprintf_error(end
- pos
, ret
))
1069 #ifdef CONFIG_SHA384
1070 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
1071 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP-SHA384 ");
1072 if (os_snprintf_error(end
- pos
, ret
))
1076 #endif /* CONFIG_SHA384 */
1078 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
1079 ret
= os_snprintf(pos
, end
- pos
, "FT-SAE ");
1080 if (os_snprintf_error(end
- pos
, ret
))
1084 #endif /* CONFIG_SAE */
1086 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1087 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA256 ");
1088 if (os_snprintf_error(end
- pos
, ret
))
1092 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1093 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA384 ");
1094 if (os_snprintf_error(end
- pos
, ret
))
1098 #endif /* CONFIG_FILS */
1099 #endif /* CONFIG_IEEE80211R_AP */
1100 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1101 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK-SHA256 ");
1102 if (os_snprintf_error(end
- pos
, ret
))
1106 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1107 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SHA256 ");
1108 if (os_snprintf_error(end
- pos
, ret
))
1113 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_SAE
) {
1114 ret
= os_snprintf(pos
, end
- pos
, "SAE ");
1115 if (os_snprintf_error(end
- pos
, ret
))
1119 #endif /* CONFIG_SAE */
1120 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1121 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SUITE-B ");
1122 if (os_snprintf_error(end
- pos
, ret
))
1126 if (hapd
->conf
->wpa_key_mgmt
&
1127 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
1128 ret
= os_snprintf(pos
, end
- pos
,
1129 "WPA-EAP-SUITE-B-192 ");
1130 if (os_snprintf_error(end
- pos
, ret
))
1135 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1136 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA256 ");
1137 if (os_snprintf_error(end
- pos
, ret
))
1141 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1142 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA384 ");
1143 if (os_snprintf_error(end
- pos
, ret
))
1147 #endif /* CONFIG_FILS */
1150 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) {
1151 ret
= os_snprintf(pos
, end
- pos
, "OWE ");
1152 if (os_snprintf_error(end
- pos
, ret
))
1156 #endif /* CONFIG_OWE */
1159 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) {
1160 ret
= os_snprintf(pos
, end
- pos
, "DPP ");
1161 if (os_snprintf_error(end
- pos
, ret
))
1165 #endif /* CONFIG_DPP */
1167 if (pos
> buf
&& *(pos
- 1) == ' ') {
1176 static int hostapd_ctrl_iface_get_config(struct hostapd_data
*hapd
,
1177 char *buf
, size_t buflen
)
1185 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n"
1187 MAC2STR(hapd
->own_addr
),
1188 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
1189 hapd
->conf
->ssid
.ssid_len
));
1190 if (os_snprintf_error(end
- pos
, ret
))
1195 ret
= os_snprintf(pos
, end
- pos
, "wps_state=%s\n",
1196 hapd
->conf
->wps_state
== 0 ? "disabled" :
1197 (hapd
->conf
->wps_state
== 1 ? "not configured" :
1199 if (os_snprintf_error(end
- pos
, ret
))
1203 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1204 hapd
->conf
->ssid
.wpa_passphrase
) {
1205 ret
= os_snprintf(pos
, end
- pos
, "passphrase=%s\n",
1206 hapd
->conf
->ssid
.wpa_passphrase
);
1207 if (os_snprintf_error(end
- pos
, ret
))
1212 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1213 hapd
->conf
->ssid
.wpa_psk
&&
1214 hapd
->conf
->ssid
.wpa_psk
->group
) {
1215 char hex
[PMK_LEN
* 2 + 1];
1216 wpa_snprintf_hex(hex
, sizeof(hex
),
1217 hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
1218 ret
= os_snprintf(pos
, end
- pos
, "psk=%s\n", hex
);
1219 if (os_snprintf_error(end
- pos
, ret
))
1223 #endif /* CONFIG_WPS */
1225 if (hapd
->conf
->wpa
) {
1226 ret
= os_snprintf(pos
, end
- pos
, "wpa=%d\n", hapd
->conf
->wpa
);
1227 if (os_snprintf_error(end
- pos
, ret
))
1232 if (hapd
->conf
->wpa
&& hapd
->conf
->wpa_key_mgmt
) {
1233 ret
= os_snprintf(pos
, end
- pos
, "key_mgmt=");
1234 if (os_snprintf_error(end
- pos
, ret
))
1238 pos
+= hostapd_ctrl_iface_get_key_mgmt(hapd
, pos
, end
- pos
);
1240 ret
= os_snprintf(pos
, end
- pos
, "\n");
1241 if (os_snprintf_error(end
- pos
, ret
))
1246 if (hapd
->conf
->wpa
) {
1247 ret
= os_snprintf(pos
, end
- pos
, "group_cipher=%s\n",
1248 wpa_cipher_txt(hapd
->conf
->wpa_group
));
1249 if (os_snprintf_error(end
- pos
, ret
))
1254 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && hapd
->conf
->rsn_pairwise
) {
1255 ret
= os_snprintf(pos
, end
- pos
, "rsn_pairwise_cipher=");
1256 if (os_snprintf_error(end
- pos
, ret
))
1260 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->rsn_pairwise
,
1266 ret
= os_snprintf(pos
, end
- pos
, "\n");
1267 if (os_snprintf_error(end
- pos
, ret
))
1272 if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) && hapd
->conf
->wpa_pairwise
) {
1273 ret
= os_snprintf(pos
, end
- pos
, "wpa_pairwise_cipher=");
1274 if (os_snprintf_error(end
- pos
, ret
))
1278 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->wpa_pairwise
,
1284 ret
= os_snprintf(pos
, end
- pos
, "\n");
1285 if (os_snprintf_error(end
- pos
, ret
))
1290 if (hapd
->conf
->wpa
&& hapd
->conf
->wpa_deny_ptk0_rekey
) {
1291 ret
= os_snprintf(pos
, end
- pos
, "wpa_deny_ptk0_rekey=%d\n",
1292 hapd
->conf
->wpa_deny_ptk0_rekey
);
1293 if (os_snprintf_error(end
- pos
, ret
))
1302 static void hostapd_disassoc_accept_mac(struct hostapd_data
*hapd
)
1304 struct sta_info
*sta
;
1305 struct vlan_description vlan_id
;
1307 if (hapd
->conf
->macaddr_acl
!= DENY_UNLESS_ACCEPTED
)
1310 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1311 if (!hostapd_maclist_found(hapd
->conf
->accept_mac
,
1312 hapd
->conf
->num_accept_mac
,
1313 sta
->addr
, &vlan_id
) ||
1314 (vlan_id
.notempty
&&
1315 vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1316 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1317 WLAN_REASON_UNSPECIFIED
);
1322 static void hostapd_disassoc_deny_mac(struct hostapd_data
*hapd
)
1324 struct sta_info
*sta
;
1325 struct vlan_description vlan_id
;
1327 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1328 if (hostapd_maclist_found(hapd
->conf
->deny_mac
,
1329 hapd
->conf
->num_deny_mac
, sta
->addr
,
1331 (!vlan_id
.notempty
||
1332 !vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1333 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1334 WLAN_REASON_UNSPECIFIED
);
1339 static int hostapd_ctrl_iface_set_band(struct hostapd_data
*hapd
,
1342 union wpa_event_data event
;
1343 enum set_band setband
;
1345 if (os_strcmp(band
, "AUTO") == 0)
1346 setband
= WPA_SETBAND_AUTO
;
1347 else if (os_strcmp(band
, "5G") == 0)
1348 setband
= WPA_SETBAND_5G
;
1349 else if (os_strcmp(band
, "2G") == 0)
1350 setband
= WPA_SETBAND_2G
;
1354 if (hostapd_drv_set_band(hapd
, setband
) == 0) {
1355 os_memset(&event
, 0, sizeof(event
));
1356 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
1357 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
1358 wpa_supplicant_event(hapd
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
1365 static int hostapd_ctrl_iface_set(struct hostapd_data
*hapd
, char *cmd
)
1370 value
= os_strchr(cmd
, ' ');
1375 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
1377 #ifdef CONFIG_WPS_TESTING
1378 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
1380 val
= strtol(value
, NULL
, 0);
1381 if (val
< 0 || val
> 0xff) {
1383 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
1384 "wps_version_number %ld", val
);
1386 wps_version_number
= val
;
1387 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
1389 (wps_version_number
& 0xf0) >> 4,
1390 wps_version_number
& 0x0f);
1391 hostapd_wps_update_ie(hapd
);
1393 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
1394 wps_testing_dummy_cred
= atoi(value
);
1395 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
1396 wps_testing_dummy_cred
);
1397 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
1398 wps_corrupt_pkhash
= atoi(value
);
1399 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
1400 wps_corrupt_pkhash
);
1401 #endif /* CONFIG_WPS_TESTING */
1402 #ifdef CONFIG_TESTING_OPTIONS
1403 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
1404 hapd
->ext_mgmt_frame_handling
= atoi(value
);
1405 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
1406 hapd
->ext_eapol_frame_io
= atoi(value
);
1408 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
1409 os_free(hapd
->dpp_config_obj_override
);
1410 hapd
->dpp_config_obj_override
= os_strdup(value
);
1411 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
1412 os_free(hapd
->dpp_discovery_override
);
1413 hapd
->dpp_discovery_override
= os_strdup(value
);
1414 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
1415 os_free(hapd
->dpp_groups_override
);
1416 hapd
->dpp_groups_override
= os_strdup(value
);
1417 } else if (os_strcasecmp(cmd
,
1418 "dpp_ignore_netaccesskey_mismatch") == 0) {
1419 hapd
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
1420 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
1421 dpp_test
= atoi(value
);
1422 #endif /* CONFIG_DPP */
1423 #endif /* CONFIG_TESTING_OPTIONS */
1425 } else if (os_strcasecmp(cmd
, "mbo_assoc_disallow") == 0) {
1428 if (!hapd
->conf
->mbo_enabled
)
1432 if (val
< 0 || val
> 1)
1435 hapd
->mbo_assoc_disallow
= val
;
1436 ieee802_11_update_beacons(hapd
->iface
);
1439 * TODO: Need to configure drivers that do AP MLME offload with
1440 * disallowing station logic.
1442 #endif /* CONFIG_MBO */
1444 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
1445 os_free(hapd
->dpp_configurator_params
);
1446 hapd
->dpp_configurator_params
= os_strdup(value
);
1447 #endif /* CONFIG_DPP */
1448 } else if (os_strcasecmp(cmd
, "setband") == 0) {
1449 ret
= hostapd_ctrl_iface_set_band(hapd
, value
);
1451 ret
= hostapd_set_iface(hapd
->iconf
, hapd
->conf
, cmd
, value
);
1455 if (os_strcasecmp(cmd
, "deny_mac_file") == 0) {
1456 hostapd_disassoc_deny_mac(hapd
);
1457 } else if (os_strcasecmp(cmd
, "accept_mac_file") == 0) {
1458 hostapd_disassoc_accept_mac(hapd
);
1459 } else if (os_strncmp(cmd
, "wme_ac_", 7) == 0 ||
1460 os_strncmp(cmd
, "wmm_ac_", 7) == 0) {
1461 hapd
->parameter_set_count
++;
1462 if (ieee802_11_update_beacons(hapd
->iface
))
1463 wpa_printf(MSG_DEBUG
,
1464 "Failed to update beacons with WMM parameters");
1465 } else if (os_strcmp(cmd
, "wpa_passphrase") == 0 ||
1466 os_strcmp(cmd
, "sae_password") == 0 ||
1467 os_strcmp(cmd
, "sae_pwe") == 0) {
1469 hostapd_setup_sae_pt(hapd
->conf
);
1477 static int hostapd_ctrl_iface_get(struct hostapd_data
*hapd
, char *cmd
,
1478 char *buf
, size_t buflen
)
1482 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
1484 if (os_strcmp(cmd
, "version") == 0) {
1485 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
1486 if (os_snprintf_error(buflen
, res
))
1489 } else if (os_strcmp(cmd
, "tls_library") == 0) {
1490 res
= tls_get_library_version(buf
, buflen
);
1491 if (os_snprintf_error(buflen
, res
))
1500 static int hostapd_ctrl_iface_enable(struct hostapd_iface
*iface
)
1502 if (hostapd_enable_iface(iface
) < 0) {
1503 wpa_printf(MSG_ERROR
, "Enabling of interface failed");
1510 static int hostapd_ctrl_iface_reload(struct hostapd_iface
*iface
)
1512 if (hostapd_reload_iface(iface
) < 0) {
1513 wpa_printf(MSG_ERROR
, "Reloading of interface failed");
1520 static int hostapd_ctrl_iface_disable(struct hostapd_iface
*iface
)
1522 if (hostapd_disable_iface(iface
) < 0) {
1523 wpa_printf(MSG_ERROR
, "Disabling of interface failed");
1531 hostapd_ctrl_iface_kick_mismatch_psk_sta_iter(struct hostapd_data
*hapd
,
1532 struct sta_info
*sta
, void *ctx
)
1534 struct hostapd_wpa_psk
*psk
;
1542 pmk
= wpa_auth_get_pmk(sta
->wpa_sm
, &pmk_len
);
1544 for (psk
= hapd
->conf
->ssid
.wpa_psk
; pmk
&& psk
; psk
= psk
->next
) {
1545 pmk_match
= PMK_LEN
== pmk_len
&&
1546 os_memcmp(psk
->psk
, pmk
, pmk_len
) == 0;
1547 sta_match
= psk
->group
== 0 &&
1548 os_memcmp(sta
->addr
, psk
->addr
, ETH_ALEN
) == 0;
1549 bss_match
= psk
->group
== 1;
1551 if (pmk_match
&& (sta_match
|| bss_match
))
1555 wpa_printf(MSG_INFO
, "STA " MACSTR
1556 " PSK/passphrase no longer valid - disconnect",
1557 MAC2STR(sta
->addr
));
1558 reason
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
1559 hostapd_drv_sta_deauth(hapd
, sta
->addr
, reason
);
1560 ap_sta_deauthenticate(hapd
, sta
, reason
);
1566 static int hostapd_ctrl_iface_reload_wpa_psk(struct hostapd_data
*hapd
)
1568 struct hostapd_bss_config
*conf
= hapd
->conf
;
1571 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
1573 err
= hostapd_setup_wpa_psk(conf
);
1575 wpa_printf(MSG_ERROR
, "Reloading WPA-PSK passwords failed: %d",
1580 ap_for_each_sta(hapd
, hostapd_ctrl_iface_kick_mismatch_psk_sta_iter
,
1587 #ifdef CONFIG_TESTING_OPTIONS
1589 static int hostapd_ctrl_iface_radar(struct hostapd_data
*hapd
, char *cmd
)
1591 union wpa_event_data data
;
1593 enum wpa_event_type event
;
1595 wpa_printf(MSG_DEBUG
, "RADAR TEST: %s", cmd
);
1597 os_memset(&data
, 0, sizeof(data
));
1599 param
= os_strchr(cmd
, ' ');
1604 if (os_strcmp(cmd
, "DETECTED") == 0)
1605 event
= EVENT_DFS_RADAR_DETECTED
;
1606 else if (os_strcmp(cmd
, "CAC-FINISHED") == 0)
1607 event
= EVENT_DFS_CAC_FINISHED
;
1608 else if (os_strcmp(cmd
, "CAC-ABORTED") == 0)
1609 event
= EVENT_DFS_CAC_ABORTED
;
1610 else if (os_strcmp(cmd
, "NOP-FINISHED") == 0)
1611 event
= EVENT_DFS_NOP_FINISHED
;
1613 wpa_printf(MSG_DEBUG
, "Unsupported RADAR test command: %s",
1618 pos
= os_strstr(param
, "freq=");
1620 data
.dfs_event
.freq
= atoi(pos
+ 5);
1622 pos
= os_strstr(param
, "ht_enabled=1");
1624 data
.dfs_event
.ht_enabled
= 1;
1626 pos
= os_strstr(param
, "chan_offset=");
1628 data
.dfs_event
.chan_offset
= atoi(pos
+ 12);
1630 pos
= os_strstr(param
, "chan_width=");
1632 data
.dfs_event
.chan_width
= atoi(pos
+ 11);
1634 pos
= os_strstr(param
, "cf1=");
1636 data
.dfs_event
.cf1
= atoi(pos
+ 4);
1638 pos
= os_strstr(param
, "cf2=");
1640 data
.dfs_event
.cf2
= atoi(pos
+ 4);
1642 wpa_supplicant_event(hapd
, event
, &data
);
1648 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data
*hapd
, char *cmd
)
1654 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
1656 len
= os_strlen(cmd
);
1661 buf
= os_malloc(len
);
1665 if (hexstr2bin(cmd
, buf
, len
) < 0) {
1670 res
= hostapd_drv_send_mlme(hapd
, buf
, len
, 0, NULL
, 0, 0);
1676 static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data
*hapd
,
1682 int stype
= 0, ok
= 0;
1683 union wpa_event_data event
;
1685 if (!hapd
->ext_mgmt_frame_handling
)
1688 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1690 wpa_printf(MSG_DEBUG
, "External MGMT TX status process: %s", cmd
);
1693 param
= os_strstr(pos
, "stype=");
1696 stype
= atoi(param
);
1699 param
= os_strstr(pos
, " ok=");
1705 param
= os_strstr(pos
, " buf=");
1710 len
= os_strlen(param
);
1715 buf
= os_malloc(len
);
1716 if (!buf
|| hexstr2bin(param
, buf
, len
) < 0) {
1721 os_memset(&event
, 0, sizeof(event
));
1722 event
.tx_status
.type
= WLAN_FC_TYPE_MGMT
;
1723 event
.tx_status
.data
= buf
;
1724 event
.tx_status
.data_len
= len
;
1725 event
.tx_status
.stype
= stype
;
1726 event
.tx_status
.ack
= ok
;
1727 hapd
->ext_mgmt_frame_handling
= 0;
1728 wpa_supplicant_event(hapd
, EVENT_TX_STATUS
, &event
);
1729 hapd
->ext_mgmt_frame_handling
= 1;
1737 static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data
*hapd
,
1743 int freq
= 0, datarate
= 0, ssi_signal
= 0;
1744 union wpa_event_data event
;
1746 if (!hapd
->ext_mgmt_frame_handling
)
1749 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1751 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
1754 param
= os_strstr(pos
, "freq=");
1760 param
= os_strstr(pos
, " datarate=");
1763 datarate
= atoi(param
);
1766 param
= os_strstr(pos
, " ssi_signal=");
1769 ssi_signal
= atoi(param
);
1772 param
= os_strstr(pos
, " frame=");
1777 len
= os_strlen(param
);
1782 buf
= os_malloc(len
);
1786 if (hexstr2bin(param
, buf
, len
) < 0) {
1791 os_memset(&event
, 0, sizeof(event
));
1792 event
.rx_mgmt
.freq
= freq
;
1793 event
.rx_mgmt
.frame
= buf
;
1794 event
.rx_mgmt
.frame_len
= len
;
1795 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1796 event
.rx_mgmt
.datarate
= datarate
;
1797 hapd
->ext_mgmt_frame_handling
= 0;
1798 wpa_supplicant_event(hapd
, EVENT_RX_MGMT
, &event
);
1799 hapd
->ext_mgmt_frame_handling
= 1;
1807 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data
*hapd
, char *cmd
)
1810 u8 src
[ETH_ALEN
], *buf
;
1814 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
1817 used
= hwaddr_aton2(pos
, src
);
1824 len
= os_strlen(pos
);
1829 buf
= os_malloc(len
);
1833 if (hexstr2bin(pos
, buf
, len
) < 0) {
1838 ieee802_1x_receive(hapd
, src
, buf
, len
);
1845 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
1849 const u16
*pos
= buf
;
1851 for (i
= 0; i
< len
/ 2; i
++)
1855 sum
= (sum
& 0xffff) + (sum
>> 16);
1857 return sum
^ 0xffff;
1861 #define HWSIM_PACKETLEN 1500
1862 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1864 static void hostapd_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
1867 struct hostapd_data
*hapd
= ctx
;
1868 const struct ether_header
*eth
;
1874 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
1875 wpa_printf(MSG_DEBUG
,
1876 "test data: RX - ignore unexpected length %d",
1881 eth
= (const struct ether_header
*) buf
;
1882 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
1883 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
1885 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 ||
1886 ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
1887 wpa_printf(MSG_DEBUG
,
1888 "test data: RX - ignore unexpect IP header");
1892 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
1893 if (*pos
!= (u8
) i
) {
1894 wpa_printf(MSG_DEBUG
,
1895 "test data: RX - ignore mismatching payload");
1902 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
1903 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
1904 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
1905 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
1909 static int hostapd_ctrl_iface_data_test_config(struct hostapd_data
*hapd
,
1912 int enabled
= atoi(cmd
);
1917 if (hapd
->l2_test
) {
1918 l2_packet_deinit(hapd
->l2_test
);
1919 hapd
->l2_test
= NULL
;
1920 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1921 "test data: Disabled");
1929 pos
= os_strstr(cmd
, " ifname=");
1933 ifname
= hapd
->conf
->iface
;
1935 hapd
->l2_test
= l2_packet_init(ifname
, hapd
->own_addr
,
1936 ETHERTYPE_IP
, hostapd_data_test_rx
,
1938 if (hapd
->l2_test
== NULL
)
1941 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: Enabled");
1947 static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data
*hapd
, char *cmd
)
1949 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
1954 u8 buf
[2 + HWSIM_PACKETLEN
];
1955 struct ether_header
*eth
;
1959 size_t send_len
= HWSIM_IP_LEN
;
1961 if (hapd
->l2_test
== NULL
)
1964 /* format: <dst> <src> <tos> [len=<length>] */
1967 used
= hwaddr_aton2(pos
, dst
);
1973 used
= hwaddr_aton2(pos
, src
);
1978 val
= strtol(pos
, &pos2
, 0);
1979 if (val
< 0 || val
> 0xff)
1983 pos
= os_strstr(pos2
, " len=");
1986 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
1991 eth
= (struct ether_header
*) &buf
[2];
1992 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
1993 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
1994 eth
->ether_type
= htons(ETHERTYPE_IP
);
1995 ip
= (struct ip
*) (eth
+ 1);
1996 os_memset(ip
, 0, sizeof(*ip
));
2001 ip
->ip_len
= htons(send_len
);
2003 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
2004 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
2005 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
2006 dpos
= (u8
*) (ip
+ 1);
2007 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
2010 if (l2_packet_send(hapd
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
2011 sizeof(struct ether_header
) + send_len
) < 0)
2014 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX dst=" MACSTR
2015 " src=" MACSTR
" tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
2021 static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data
*hapd
,
2025 struct ether_header
*eth
;
2026 struct l2_packet_data
*l2
= NULL
;
2030 const char *ifname
= hapd
->conf
->iface
;
2032 if (os_strncmp(cmd
, "ifname=", 7) == 0) {
2035 cmd
= os_strchr(cmd
, ' ');
2041 len
= os_strlen(cmd
);
2042 if (len
& 1 || len
< ETH_HLEN
* 2)
2046 buf
= os_malloc(len
);
2050 if (hexstr2bin(cmd
, buf
, len
) < 0)
2053 eth
= (struct ether_header
*) buf
;
2054 ethertype
= ntohs(eth
->ether_type
);
2056 l2
= l2_packet_init(ifname
, hapd
->own_addr
, ethertype
,
2057 hostapd_data_test_rx
, hapd
, 1);
2061 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
2062 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
2065 l2_packet_deinit(l2
);
2068 return res
< 0 ? -1 : 0;
2072 static int hostapd_ctrl_test_alloc_fail(struct hostapd_data
*hapd
, char *cmd
)
2074 #ifdef WPA_TRACE_BFD
2077 wpa_trace_fail_after
= atoi(cmd
);
2078 pos
= os_strchr(cmd
, ':');
2081 os_strlcpy(wpa_trace_fail_func
, pos
,
2082 sizeof(wpa_trace_fail_func
));
2084 wpa_trace_fail_after
= 0;
2088 #else /* WPA_TRACE_BFD */
2090 #endif /* WPA_TRACE_BFD */
2094 static int hostapd_ctrl_get_alloc_fail(struct hostapd_data
*hapd
,
2095 char *buf
, size_t buflen
)
2097 #ifdef WPA_TRACE_BFD
2098 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
2099 wpa_trace_fail_func
);
2100 #else /* WPA_TRACE_BFD */
2102 #endif /* WPA_TRACE_BFD */
2106 static int hostapd_ctrl_test_fail(struct hostapd_data
*hapd
, char *cmd
)
2108 #ifdef WPA_TRACE_BFD
2111 wpa_trace_test_fail_after
= atoi(cmd
);
2112 pos
= os_strchr(cmd
, ':');
2115 os_strlcpy(wpa_trace_test_fail_func
, pos
,
2116 sizeof(wpa_trace_test_fail_func
));
2118 wpa_trace_test_fail_after
= 0;
2122 #else /* WPA_TRACE_BFD */
2124 #endif /* WPA_TRACE_BFD */
2128 static int hostapd_ctrl_get_fail(struct hostapd_data
*hapd
,
2129 char *buf
, size_t buflen
)
2131 #ifdef WPA_TRACE_BFD
2132 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
2133 wpa_trace_test_fail_func
);
2134 #else /* WPA_TRACE_BFD */
2136 #endif /* WPA_TRACE_BFD */
2140 static int hostapd_ctrl_reset_pn(struct hostapd_data
*hapd
, const char *cmd
)
2142 struct sta_info
*sta
;
2144 u8 zero
[WPA_TK_MAX_LEN
];
2146 os_memset(zero
, 0, sizeof(zero
));
2148 if (hwaddr_aton(cmd
, addr
))
2151 if (is_broadcast_ether_addr(addr
) && os_strstr(cmd
, "IGTK")) {
2152 if (hapd
->last_igtk_alg
== WPA_ALG_NONE
)
2155 wpa_printf(MSG_INFO
, "TESTING: Reset IPN for IGTK");
2157 /* First, use a zero key to avoid any possible duplicate key
2158 * avoidance in the driver. */
2159 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2160 hapd
->last_igtk_alg
,
2161 broadcast_ether_addr
,
2162 hapd
->last_igtk_key_idx
, 0, 1, NULL
, 0,
2163 zero
, hapd
->last_igtk_len
,
2164 KEY_FLAG_GROUP_TX_DEFAULT
) < 0)
2167 /* Set the previously configured key to reset its TSC */
2168 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2169 hapd
->last_igtk_alg
,
2170 broadcast_ether_addr
,
2171 hapd
->last_igtk_key_idx
, 0, 1, NULL
,
2173 hapd
->last_igtk_len
,
2174 KEY_FLAG_GROUP_TX_DEFAULT
);
2177 if (is_broadcast_ether_addr(addr
)) {
2178 if (hapd
->last_gtk_alg
== WPA_ALG_NONE
)
2181 wpa_printf(MSG_INFO
, "TESTING: Reset PN for GTK");
2183 /* First, use a zero key to avoid any possible duplicate key
2184 * avoidance in the driver. */
2185 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2187 broadcast_ether_addr
,
2188 hapd
->last_gtk_key_idx
, 0, 1, NULL
, 0,
2189 zero
, hapd
->last_gtk_len
,
2190 KEY_FLAG_GROUP_TX_DEFAULT
) < 0)
2193 /* Set the previously configured key to reset its TSC */
2194 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2196 broadcast_ether_addr
,
2197 hapd
->last_gtk_key_idx
, 0, 1, NULL
,
2200 KEY_FLAG_GROUP_TX_DEFAULT
);
2203 sta
= ap_get_sta(hapd
, addr
);
2207 if (sta
->last_tk_alg
== WPA_ALG_NONE
)
2210 wpa_printf(MSG_INFO
, "TESTING: Reset PN for " MACSTR
,
2211 MAC2STR(sta
->addr
));
2213 /* First, use a zero key to avoid any possible duplicate key avoidance
2215 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2216 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2217 zero
, sta
->last_tk_len
,
2218 KEY_FLAG_PAIRWISE_RX_TX
) < 0)
2221 /* Set the previously configured key to reset its TSC/RSC */
2222 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2223 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
,
2224 0, sta
->last_tk
, sta
->last_tk_len
,
2225 KEY_FLAG_PAIRWISE_RX_TX
);
2229 static int hostapd_ctrl_set_key(struct hostapd_data
*hapd
, const char *cmd
)
2232 const char *pos
= cmd
;
2234 enum key_flag key_flag
;
2236 u8 seq
[6], key
[WPA_TK_MAX_LEN
];
2239 /* parameters: alg addr idx set_tx seq key key_flag */
2242 pos
= os_strchr(pos
, ' ');
2246 if (hwaddr_aton(pos
, addr
))
2253 pos
= os_strchr(pos
, ' ');
2258 pos
= os_strchr(pos
, ' ');
2262 if (hexstr2bin(pos
, seq
, sizeof(seq
)) < 0)
2268 if (!os_strchr(pos
, ' '))
2270 key_len
= (os_strchr(pos
, ' ') - pos
) / 2;
2271 if (hexstr2bin(pos
, key
, key_len
) < 0)
2278 key_flag
= atoi(pos
);
2279 pos
= os_strchr(pos
, ' ');
2283 wpa_printf(MSG_INFO
, "TESTING: Set key");
2284 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, alg
, addr
, idx
, 0,
2285 set_tx
, seq
, 6, key
, key_len
, key_flag
);
2289 static void restore_tk(void *ctx1
, void *ctx2
)
2291 struct hostapd_data
*hapd
= ctx1
;
2292 struct sta_info
*sta
= ctx2
;
2294 wpa_printf(MSG_INFO
, "TESTING: Restore TK for " MACSTR
,
2295 MAC2STR(sta
->addr
));
2296 /* This does not really restore the TSC properly, so this will result
2297 * in replay protection issues for now since there is no clean way of
2298 * preventing encryption of a single EAPOL frame. */
2299 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2300 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2301 sta
->last_tk
, sta
->last_tk_len
,
2302 KEY_FLAG_PAIRWISE_RX_TX
);
2306 static int hostapd_ctrl_resend_m1(struct hostapd_data
*hapd
, const char *cmd
)
2308 struct sta_info
*sta
;
2310 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2312 if (hwaddr_aton(cmd
, addr
))
2315 sta
= ap_get_sta(hapd
, addr
);
2316 if (!sta
|| !sta
->wpa_sm
)
2319 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2320 plain
= 0; /* no need for special processing */
2322 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2323 MAC2STR(sta
->addr
));
2324 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2325 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2326 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2329 wpa_printf(MSG_INFO
, "TESTING: Send M1 to " MACSTR
, MAC2STR(sta
->addr
));
2330 return wpa_auth_resend_m1(sta
->wpa_sm
,
2331 os_strstr(cmd
, "change-anonce") != NULL
,
2332 plain
? restore_tk
: NULL
, hapd
, sta
);
2336 static int hostapd_ctrl_resend_m3(struct hostapd_data
*hapd
, const char *cmd
)
2338 struct sta_info
*sta
;
2340 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2342 if (hwaddr_aton(cmd
, addr
))
2345 sta
= ap_get_sta(hapd
, addr
);
2346 if (!sta
|| !sta
->wpa_sm
)
2349 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2350 plain
= 0; /* no need for special processing */
2352 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2353 MAC2STR(sta
->addr
));
2354 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2355 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2356 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2359 wpa_printf(MSG_INFO
, "TESTING: Send M3 to " MACSTR
, MAC2STR(sta
->addr
));
2360 return wpa_auth_resend_m3(sta
->wpa_sm
,
2361 plain
? restore_tk
: NULL
, hapd
, sta
);
2365 static int hostapd_ctrl_resend_group_m1(struct hostapd_data
*hapd
,
2368 struct sta_info
*sta
;
2370 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2372 if (hwaddr_aton(cmd
, addr
))
2375 sta
= ap_get_sta(hapd
, addr
);
2376 if (!sta
|| !sta
->wpa_sm
)
2379 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2380 plain
= 0; /* no need for special processing */
2382 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2383 MAC2STR(sta
->addr
));
2384 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2385 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2386 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2389 wpa_printf(MSG_INFO
,
2390 "TESTING: Send group M1 for the same GTK and zero RSC to "
2391 MACSTR
, MAC2STR(sta
->addr
));
2392 return wpa_auth_resend_group_m1(sta
->wpa_sm
,
2393 plain
? restore_tk
: NULL
, hapd
, sta
);
2397 static int hostapd_ctrl_get_pmk(struct hostapd_data
*hapd
, const char *cmd
,
2398 char *buf
, size_t buflen
)
2400 struct sta_info
*sta
;
2405 if (hwaddr_aton(cmd
, addr
))
2408 sta
= ap_get_sta(hapd
, addr
);
2409 if (!sta
|| !sta
->wpa_sm
) {
2410 wpa_printf(MSG_DEBUG
, "No STA WPA state machine for " MACSTR
,
2414 pmk
= wpa_auth_get_pmk(sta
->wpa_sm
, &pmk_len
);
2416 wpa_printf(MSG_DEBUG
, "No PMK stored for " MACSTR
,
2421 return wpa_snprintf_hex(buf
, buflen
, pmk
, pmk_len
);
2424 #endif /* CONFIG_TESTING_OPTIONS */
2427 static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface
*iface
,
2431 struct csa_settings settings
;
2435 ret
= hostapd_parse_csa_settings(pos
, &settings
);
2439 for (i
= 0; i
< iface
->num_bss
; i
++) {
2441 /* Save CHAN_SWITCH VHT config */
2442 hostapd_chan_switch_vht_config(
2443 iface
->bss
[i
], settings
.freq_params
.vht_enabled
);
2445 ret
= hostapd_switch_channel(iface
->bss
[i
], &settings
);
2447 /* FIX: What do we do if CSA fails in the middle of
2448 * submitting multi-BSS CSA requests? */
2454 #else /* NEED_AP_MLME */
2456 #endif /* NEED_AP_MLME */
2460 static int hostapd_ctrl_iface_mib(struct hostapd_data
*hapd
, char *reply
,
2461 int reply_size
, const char *param
)
2463 #ifdef RADIUS_SERVER
2464 if (os_strcmp(param
, "radius_server") == 0) {
2465 return radius_server_get_mib(hapd
->radius_srv
, reply
,
2468 #endif /* RADIUS_SERVER */
2473 static int hostapd_ctrl_iface_vendor(struct hostapd_data
*hapd
, char *cmd
,
2474 char *buf
, size_t buflen
)
2479 unsigned int vendor_id
, subcmd
;
2480 struct wpabuf
*reply
;
2481 size_t data_len
= 0;
2483 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2484 vendor_id
= strtoul(cmd
, &pos
, 16);
2485 if (!isblank((unsigned char) *pos
))
2488 subcmd
= strtoul(pos
, &pos
, 10);
2491 if (!isblank((unsigned char) *pos
++))
2493 data_len
= os_strlen(pos
);
2498 data
= os_malloc(data_len
);
2502 if (hexstr2bin(pos
, data
, data_len
)) {
2503 wpa_printf(MSG_DEBUG
,
2504 "Vendor command: wrong parameter format");
2510 reply
= wpabuf_alloc((buflen
- 1) / 2);
2516 ret
= hostapd_drv_vendor_cmd(hapd
, vendor_id
, subcmd
, data
, data_len
,
2520 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
2530 static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data
*hapd
,
2534 struct sta_info
*sta
;
2536 if (hwaddr_aton(cmd
, addr
))
2539 sta
= ap_get_sta(hapd
, addr
);
2540 if (!sta
|| !sta
->eapol_sm
)
2543 eapol_auth_reauthenticate(sta
->eapol_sm
);
2548 static int hostapd_ctrl_iface_eapol_set(struct hostapd_data
*hapd
, char *cmd
)
2551 struct sta_info
*sta
;
2552 char *pos
= cmd
, *param
;
2554 if (hwaddr_aton(pos
, addr
) || pos
[17] != ' ')
2558 pos
= os_strchr(pos
, ' ');
2563 sta
= ap_get_sta(hapd
, addr
);
2564 if (!sta
|| !sta
->eapol_sm
)
2567 return eapol_auth_set_conf(sta
->eapol_sm
, param
, pos
);
2571 static int hostapd_ctrl_iface_log_level(struct hostapd_data
*hapd
, char *cmd
,
2572 char *buf
, size_t buflen
)
2574 char *pos
, *end
, *stamp
;
2577 /* cmd: "LOG_LEVEL [<level>]" */
2581 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2583 debug_level_str(wpa_debug_level
),
2584 wpa_debug_timestamp
);
2585 if (os_snprintf_error(end
- pos
, ret
))
2594 stamp
= os_strchr(cmd
, ' ');
2597 while (*stamp
== ' ') {
2602 if (os_strlen(cmd
)) {
2603 int level
= str_to_debug_level(cmd
);
2606 wpa_debug_level
= level
;
2609 if (stamp
&& os_strlen(stamp
))
2610 wpa_debug_timestamp
= atoi(stamp
);
2612 os_memcpy(buf
, "OK\n", 3);
2618 static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data
*hapd
,
2619 char *buf
, size_t buflen
)
2621 struct hostapd_iface
*iface
= hapd
->iface
;
2623 struct hostapd_sta_info
*info
;
2624 struct os_reltime now
;
2626 if (!iface
->num_sta_seen
)
2629 sta_track_expire(iface
, 0);
2634 os_get_reltime(&now
);
2635 dl_list_for_each_reverse(info
, &iface
->sta_seen
,
2636 struct hostapd_sta_info
, list
) {
2637 struct os_reltime age
;
2640 os_reltime_sub(&now
, &info
->last_seen
, &age
);
2641 ret
= os_snprintf(pos
, end
- pos
, MACSTR
" %u %d\n",
2642 MAC2STR(info
->addr
), (unsigned int) age
.sec
,
2644 if (os_snprintf_error(end
- pos
, ret
))
2651 #endif /* NEED_AP_MLME */
2654 static int hostapd_ctrl_iface_req_lci(struct hostapd_data
*hapd
,
2659 if (hwaddr_aton(cmd
, addr
)) {
2660 wpa_printf(MSG_INFO
, "CTRL: REQ_LCI: Invalid MAC address");
2664 return hostapd_send_lci_req(hapd
, addr
);
2668 static int hostapd_ctrl_iface_req_range(struct hostapd_data
*hapd
, char *cmd
)
2671 char *token
, *context
= NULL
;
2672 int random_interval
, min_ap
;
2673 u8 responders
[ETH_ALEN
* RRM_RANGE_REQ_MAX_RESPONDERS
];
2674 unsigned int n_responders
;
2676 token
= str_token(cmd
, " ", &context
);
2677 if (!token
|| hwaddr_aton(token
, addr
)) {
2678 wpa_printf(MSG_INFO
,
2679 "CTRL: REQ_RANGE - Bad destination address");
2683 token
= str_token(cmd
, " ", &context
);
2687 random_interval
= atoi(token
);
2688 if (random_interval
< 0 || random_interval
> 0xffff)
2691 token
= str_token(cmd
, " ", &context
);
2695 min_ap
= atoi(token
);
2696 if (min_ap
<= 0 || min_ap
> WLAN_RRM_RANGE_REQ_MAX_MIN_AP
)
2700 while ((token
= str_token(cmd
, " ", &context
))) {
2701 if (n_responders
== RRM_RANGE_REQ_MAX_RESPONDERS
) {
2702 wpa_printf(MSG_INFO
,
2703 "CTRL: REQ_RANGE: Too many responders");
2707 if (hwaddr_aton(token
, responders
+ n_responders
* ETH_ALEN
)) {
2708 wpa_printf(MSG_INFO
,
2709 "CTRL: REQ_RANGE: Bad responder address");
2716 if (!n_responders
) {
2717 wpa_printf(MSG_INFO
,
2718 "CTRL: REQ_RANGE - No FTM responder address");
2722 return hostapd_send_range_req(hapd
, addr
, random_interval
, min_ap
,
2723 responders
, n_responders
);
2727 static int hostapd_ctrl_iface_req_beacon(struct hostapd_data
*hapd
,
2728 const char *cmd
, char *reply
,
2737 if (hwaddr_aton(cmd
, addr
))
2739 pos
= os_strchr(cmd
, ' ');
2743 if (os_strncmp(pos
, "req_mode=", 9) == 0) {
2744 int val
= hex2byte(pos
+ 9);
2750 pos
= os_strchr(pos
, ' ');
2755 req
= wpabuf_parse_bin(pos
);
2759 ret
= hostapd_send_beacon_req(hapd
, addr
, req_mode
, req
);
2762 ret
= os_snprintf(reply
, reply_size
, "%d", ret
);
2767 static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data
*hapd
,
2768 char *buf
, size_t buflen
)
2770 if (!(hapd
->conf
->radio_measurements
[0] &
2771 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2772 wpa_printf(MSG_ERROR
,
2773 "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled");
2777 return hostapd_neighbor_show(hapd
, buf
, buflen
);
2781 static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data
*hapd
, char *buf
)
2783 struct wpa_ssid_value ssid
;
2785 struct wpabuf
*nr
, *lci
= NULL
, *civic
= NULL
;
2790 if (!(hapd
->conf
->radio_measurements
[0] &
2791 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2792 wpa_printf(MSG_ERROR
,
2793 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
2797 if (hwaddr_aton(buf
, bssid
)) {
2798 wpa_printf(MSG_ERROR
, "CTRL: SET_NEIGHBOR: Bad BSSID");
2802 tmp
= os_strstr(buf
, "ssid=");
2803 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2804 wpa_printf(MSG_ERROR
,
2805 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
2808 buf
= os_strchr(tmp
+ 6, tmp
[5] == '"' ? '"' : ' ');
2812 tmp
= os_strstr(buf
, "nr=");
2814 wpa_printf(MSG_ERROR
,
2815 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
2819 buf
= os_strchr(tmp
, ' ');
2823 nr
= wpabuf_parse_bin(tmp
+ 3);
2825 wpa_printf(MSG_ERROR
,
2826 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
2833 tmp
= os_strstr(buf
, "lci=");
2835 buf
= os_strchr(tmp
, ' ');
2838 lci
= wpabuf_parse_bin(tmp
+ 4);
2840 wpa_printf(MSG_ERROR
,
2841 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
2850 tmp
= os_strstr(buf
, "civic=");
2852 buf
= os_strchr(tmp
, ' ');
2855 civic
= wpabuf_parse_bin(tmp
+ 6);
2857 wpa_printf(MSG_ERROR
,
2858 "CTRL: SET_NEIGHBOR: Bad civic subelement");
2868 if (os_strstr(buf
, "stat"))
2872 ret
= hostapd_neighbor_set(hapd
, bssid
, &ssid
, nr
, lci
, civic
,
2883 static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data
*hapd
,
2886 struct wpa_ssid_value ssid
;
2887 struct wpa_ssid_value
*ssidp
= NULL
;
2891 if (hwaddr_aton(buf
, bssid
)) {
2892 wpa_printf(MSG_ERROR
, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
2896 tmp
= os_strstr(buf
, "ssid=");
2899 if (ssid_parse(tmp
+ 5, &ssid
)) {
2900 wpa_printf(MSG_ERROR
,
2901 "CTRL: REMOVE_NEIGHBOR: Bad SSID");
2906 return hostapd_neighbor_remove(hapd
, bssid
, ssidp
);
2910 static int hostapd_ctrl_driver_flags(struct hostapd_iface
*iface
, char *buf
,
2916 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
2917 (long long unsigned) iface
->drv_flags
);
2918 if (os_snprintf_error(buflen
, ret
))
2924 for (i
= 0; i
< 64; i
++) {
2925 if (iface
->drv_flags
& (1LLU << i
)) {
2926 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
2927 driver_flag_to_string(1LLU << i
));
2928 if (os_snprintf_error(end
- pos
, ret
))
2938 static int hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry
**acl
, int *num
,
2939 const char *txtaddr
)
2942 struct vlan_description vlan_id
;
2947 if (hwaddr_aton(txtaddr
, addr
))
2950 if (hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
))
2951 hostapd_remove_acl_mac(acl
, num
, addr
);
2957 static void hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry
**acl
,
2961 hostapd_remove_acl_mac(acl
, num
, (*acl
)[0].addr
);
2965 static int hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry
*acl
, int num
,
2966 char *buf
, size_t buflen
)
2968 int i
= 0, len
= 0, ret
= 0;
2974 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2975 MACSTR
" VLAN_ID=%d\n",
2976 MAC2STR(acl
[i
].addr
),
2977 acl
[i
].vlan_id
.untagged
);
2978 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
2987 static int hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry
**acl
, int *num
,
2991 struct vlan_description vlan_id
;
2992 int ret
= 0, vlanid
= 0;
2995 if (hwaddr_aton(cmd
, addr
))
2998 pos
= os_strstr(cmd
, "VLAN_ID=");
3000 vlanid
= atoi(pos
+ 8);
3002 if (!hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
)) {
3003 ret
= hostapd_add_acl_maclist(acl
, num
, vlanid
, addr
);
3004 if (ret
!= -1 && *acl
)
3005 qsort(*acl
, *num
, sizeof(**acl
), hostapd_acl_comp
);
3008 return ret
< 0 ? -1 : 0;
3012 static int hostapd_ctrl_iface_get_capability(struct hostapd_data
*hapd
,
3013 const char *field
, char *buf
,
3016 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s'", field
);
3019 if (os_strcmp(field
, "dpp") == 0) {
3023 res
= os_snprintf(buf
, buflen
, "DPP=2");
3024 #else /* CONFIG_DPP2 */
3025 res
= os_snprintf(buf
, buflen
, "DPP=1");
3026 #endif /* CONFIG_DPP2 */
3027 if (os_snprintf_error(buflen
, res
))
3031 #endif /* CONFIG_DPP */
3033 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3040 static int hostapd_ctrl_iface_receive_process(struct hostapd_data
*hapd
,
3041 char *buf
, char *reply
,
3043 struct sockaddr_storage
*from
,
3048 os_memcpy(reply
, "OK\n", 3);
3051 if (os_strcmp(buf
, "PING") == 0) {
3052 os_memcpy(reply
, "PONG\n", 5);
3054 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3055 if (wpa_debug_reopen_file() < 0)
3057 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3058 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3059 } else if (os_strcmp(buf
, "STATUS") == 0) {
3060 reply_len
= hostapd_ctrl_iface_status(hapd
, reply
,
3062 } else if (os_strcmp(buf
, "STATUS-DRIVER") == 0) {
3063 reply_len
= hostapd_drv_status(hapd
, reply
, reply_size
);
3064 } else if (os_strcmp(buf
, "MIB") == 0) {
3065 reply_len
= ieee802_11_get_mib(hapd
, reply
, reply_size
);
3066 if (reply_len
>= 0) {
3067 res
= wpa_get_mib(hapd
->wpa_auth
, reply
+ reply_len
,
3068 reply_size
- reply_len
);
3074 if (reply_len
>= 0) {
3075 res
= ieee802_1x_get_mib(hapd
, reply
+ reply_len
,
3076 reply_size
- reply_len
);
3082 #ifndef CONFIG_NO_RADIUS
3083 if (reply_len
>= 0) {
3084 res
= radius_client_get_mib(hapd
->radius
,
3086 reply_size
- reply_len
);
3092 #endif /* CONFIG_NO_RADIUS */
3093 } else if (os_strncmp(buf
, "MIB ", 4) == 0) {
3094 reply_len
= hostapd_ctrl_iface_mib(hapd
, reply
, reply_size
,
3096 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
3097 reply_len
= hostapd_ctrl_iface_sta_first(hapd
, reply
,
3099 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
3100 reply_len
= hostapd_ctrl_iface_sta(hapd
, buf
+ 4, reply
,
3102 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
3103 reply_len
= hostapd_ctrl_iface_sta_next(hapd
, buf
+ 9, reply
,
3105 } else if (os_strcmp(buf
, "ATTACH") == 0) {
3106 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, NULL
))
3108 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
3109 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, buf
+ 7))
3111 } else if (os_strcmp(buf
, "DETACH") == 0) {
3112 if (hostapd_ctrl_iface_detach(hapd
, from
, fromlen
))
3114 } else if (os_strncmp(buf
, "LEVEL ", 6) == 0) {
3115 if (hostapd_ctrl_iface_level(hapd
, from
, fromlen
,
3118 } else if (os_strncmp(buf
, "NEW_STA ", 8) == 0) {
3119 if (hostapd_ctrl_iface_new_sta(hapd
, buf
+ 8))
3121 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
3122 if (hostapd_ctrl_iface_deauthenticate(hapd
, buf
+ 15))
3124 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
3125 if (hostapd_ctrl_iface_disassociate(hapd
, buf
+ 13))
3127 #ifdef CONFIG_TAXONOMY
3128 } else if (os_strncmp(buf
, "SIGNATURE ", 10) == 0) {
3129 reply_len
= hostapd_ctrl_iface_signature(hapd
, buf
+ 10,
3131 #endif /* CONFIG_TAXONOMY */
3132 } else if (os_strncmp(buf
, "POLL_STA ", 9) == 0) {
3133 if (hostapd_ctrl_iface_poll_sta(hapd
, buf
+ 9))
3135 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
3136 if (hostapd_ctrl_iface_stop_ap(hapd
))
3139 } else if (os_strncmp(buf
, "SA_QUERY ", 9) == 0) {
3140 if (hostapd_ctrl_iface_sa_query(hapd
, buf
+ 9))
3142 #endif /* NEED_AP_MLME */
3144 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
3145 if (hostapd_ctrl_iface_wps_pin(hapd
, buf
+ 8))
3147 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
3148 reply_len
= hostapd_ctrl_iface_wps_check_pin(
3149 hapd
, buf
+ 14, reply
, reply_size
);
3150 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
3151 if (hostapd_wps_button_pushed(hapd
, NULL
))
3153 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
3154 if (hostapd_wps_cancel(hapd
))
3156 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
3157 reply_len
= hostapd_ctrl_iface_wps_ap_pin(hapd
, buf
+ 11,
3159 } else if (os_strncmp(buf
, "WPS_CONFIG ", 11) == 0) {
3160 if (hostapd_ctrl_iface_wps_config(hapd
, buf
+ 11) < 0)
3162 } else if (os_strncmp(buf
, "WPS_GET_STATUS", 13) == 0) {
3163 reply_len
= hostapd_ctrl_iface_wps_get_status(hapd
, reply
,
3165 #ifdef CONFIG_WPS_NFC
3166 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
3167 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd
, buf
+ 17))
3169 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
3170 reply_len
= hostapd_ctrl_iface_wps_nfc_config_token(
3171 hapd
, buf
+ 21, reply
, reply_size
);
3172 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
3173 reply_len
= hostapd_ctrl_iface_wps_nfc_token(
3174 hapd
, buf
+ 14, reply
, reply_size
);
3175 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
3176 reply_len
= hostapd_ctrl_iface_nfc_get_handover_sel(
3177 hapd
, buf
+ 21, reply
, reply_size
);
3178 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
3179 if (hostapd_ctrl_iface_nfc_report_handover(hapd
, buf
+ 20))
3181 #endif /* CONFIG_WPS_NFC */
3182 #endif /* CONFIG_WPS */
3183 #ifdef CONFIG_INTERWORKING
3184 } else if (os_strncmp(buf
, "SET_QOS_MAP_SET ", 16) == 0) {
3185 if (hostapd_ctrl_iface_set_qos_map_set(hapd
, buf
+ 16))
3187 } else if (os_strncmp(buf
, "SEND_QOS_MAP_CONF ", 18) == 0) {
3188 if (hostapd_ctrl_iface_send_qos_map_conf(hapd
, buf
+ 18))
3190 #endif /* CONFIG_INTERWORKING */
3192 } else if (os_strncmp(buf
, "HS20_WNM_NOTIF ", 15) == 0) {
3193 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd
, buf
+ 15))
3195 } else if (os_strncmp(buf
, "HS20_DEAUTH_REQ ", 16) == 0) {
3196 if (hostapd_ctrl_iface_hs20_deauth_req(hapd
, buf
+ 16))
3198 #endif /* CONFIG_HS20 */
3199 #ifdef CONFIG_WNM_AP
3200 } else if (os_strncmp(buf
, "DISASSOC_IMMINENT ", 18) == 0) {
3201 if (hostapd_ctrl_iface_disassoc_imminent(hapd
, buf
+ 18))
3203 } else if (os_strncmp(buf
, "ESS_DISASSOC ", 13) == 0) {
3204 if (hostapd_ctrl_iface_ess_disassoc(hapd
, buf
+ 13))
3206 } else if (os_strncmp(buf
, "BSS_TM_REQ ", 11) == 0) {
3207 if (hostapd_ctrl_iface_bss_tm_req(hapd
, buf
+ 11))
3209 } else if (os_strncmp(buf
, "COLOC_INTF_REQ ", 15) == 0) {
3210 if (hostapd_ctrl_iface_coloc_intf_req(hapd
, buf
+ 15))
3212 #endif /* CONFIG_WNM_AP */
3213 } else if (os_strcmp(buf
, "GET_CONFIG") == 0) {
3214 reply_len
= hostapd_ctrl_iface_get_config(hapd
, reply
,
3216 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3217 if (hostapd_ctrl_iface_set(hapd
, buf
+ 4))
3219 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3220 reply_len
= hostapd_ctrl_iface_get(hapd
, buf
+ 4, reply
,
3222 } else if (os_strncmp(buf
, "ENABLE", 6) == 0) {
3223 if (hostapd_ctrl_iface_enable(hapd
->iface
))
3225 } else if (os_strcmp(buf
, "RELOAD_WPA_PSK") == 0) {
3226 if (hostapd_ctrl_iface_reload_wpa_psk(hapd
))
3228 } else if (os_strncmp(buf
, "RELOAD", 6) == 0) {
3229 if (hostapd_ctrl_iface_reload(hapd
->iface
))
3231 } else if (os_strncmp(buf
, "DISABLE", 7) == 0) {
3232 if (hostapd_ctrl_iface_disable(hapd
->iface
))
3234 } else if (os_strcmp(buf
, "UPDATE_BEACON") == 0) {
3235 if (ieee802_11_set_beacon(hapd
))
3237 #ifdef CONFIG_TESTING_OPTIONS
3238 } else if (os_strncmp(buf
, "RADAR ", 6) == 0) {
3239 if (hostapd_ctrl_iface_radar(hapd
, buf
+ 6))
3241 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
3242 if (hostapd_ctrl_iface_mgmt_tx(hapd
, buf
+ 8))
3244 } else if (os_strncmp(buf
, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
3245 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd
,
3248 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
3249 if (hostapd_ctrl_iface_mgmt_rx_process(hapd
, buf
+ 16) < 0)
3251 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
3252 if (hostapd_ctrl_iface_eapol_rx(hapd
, buf
+ 9) < 0)
3254 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
3255 if (hostapd_ctrl_iface_data_test_config(hapd
, buf
+ 17) < 0)
3257 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
3258 if (hostapd_ctrl_iface_data_test_tx(hapd
, buf
+ 13) < 0)
3260 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
3261 if (hostapd_ctrl_iface_data_test_frame(hapd
, buf
+ 16) < 0)
3263 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
3264 if (hostapd_ctrl_test_alloc_fail(hapd
, buf
+ 16) < 0)
3266 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
3267 reply_len
= hostapd_ctrl_get_alloc_fail(hapd
, reply
,
3269 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
3270 if (hostapd_ctrl_test_fail(hapd
, buf
+ 10) < 0)
3272 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
3273 reply_len
= hostapd_ctrl_get_fail(hapd
, reply
, reply_size
);
3274 } else if (os_strncmp(buf
, "RESET_PN ", 9) == 0) {
3275 if (hostapd_ctrl_reset_pn(hapd
, buf
+ 9) < 0)
3277 } else if (os_strncmp(buf
, "SET_KEY ", 8) == 0) {
3278 if (hostapd_ctrl_set_key(hapd
, buf
+ 8) < 0)
3280 } else if (os_strncmp(buf
, "RESEND_M1 ", 10) == 0) {
3281 if (hostapd_ctrl_resend_m1(hapd
, buf
+ 10) < 0)
3283 } else if (os_strncmp(buf
, "RESEND_M3 ", 10) == 0) {
3284 if (hostapd_ctrl_resend_m3(hapd
, buf
+ 10) < 0)
3286 } else if (os_strncmp(buf
, "RESEND_GROUP_M1 ", 16) == 0) {
3287 if (hostapd_ctrl_resend_group_m1(hapd
, buf
+ 16) < 0)
3289 } else if (os_strcmp(buf
, "REKEY_GTK") == 0) {
3290 if (wpa_auth_rekey_gtk(hapd
->wpa_auth
) < 0)
3292 } else if (os_strncmp(buf
, "GET_PMK ", 8) == 0) {
3293 reply_len
= hostapd_ctrl_get_pmk(hapd
, buf
+ 8, reply
,
3295 #endif /* CONFIG_TESTING_OPTIONS */
3296 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
3297 if (hostapd_ctrl_iface_chan_switch(hapd
->iface
, buf
+ 12))
3299 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
3300 reply_len
= hostapd_ctrl_iface_vendor(hapd
, buf
+ 7, reply
,
3302 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
3303 ieee802_1x_erp_flush(hapd
);
3304 #ifdef RADIUS_SERVER
3305 radius_server_erp_flush(hapd
->radius_srv
);
3306 #endif /* RADIUS_SERVER */
3307 } else if (os_strncmp(buf
, "EAPOL_REAUTH ", 13) == 0) {
3308 if (hostapd_ctrl_iface_eapol_reauth(hapd
, buf
+ 13))
3310 } else if (os_strncmp(buf
, "EAPOL_SET ", 10) == 0) {
3311 if (hostapd_ctrl_iface_eapol_set(hapd
, buf
+ 10))
3313 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
3314 reply_len
= hostapd_ctrl_iface_log_level(
3315 hapd
, buf
+ 9, reply
, reply_size
);
3317 } else if (os_strcmp(buf
, "TRACK_STA_LIST") == 0) {
3318 reply_len
= hostapd_ctrl_iface_track_sta_list(
3319 hapd
, reply
, reply_size
);
3320 #endif /* NEED_AP_MLME */
3321 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3322 reply_len
= hostapd_ctrl_iface_pmksa_list(hapd
, reply
,
3324 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
3325 hostapd_ctrl_iface_pmksa_flush(hapd
);
3326 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
3327 if (hostapd_ctrl_iface_pmksa_add(hapd
, buf
+ 10) < 0)
3329 } else if (os_strncmp(buf
, "SET_NEIGHBOR ", 13) == 0) {
3330 if (hostapd_ctrl_iface_set_neighbor(hapd
, buf
+ 13))
3332 } else if (os_strcmp(buf
, "SHOW_NEIGHBOR") == 0) {
3333 reply_len
= hostapd_ctrl_iface_show_neighbor(hapd
, reply
,
3335 } else if (os_strncmp(buf
, "REMOVE_NEIGHBOR ", 16) == 0) {
3336 if (hostapd_ctrl_iface_remove_neighbor(hapd
, buf
+ 16))
3338 } else if (os_strncmp(buf
, "REQ_LCI ", 8) == 0) {
3339 if (hostapd_ctrl_iface_req_lci(hapd
, buf
+ 8))
3341 } else if (os_strncmp(buf
, "REQ_RANGE ", 10) == 0) {
3342 if (hostapd_ctrl_iface_req_range(hapd
, buf
+ 10))
3344 } else if (os_strncmp(buf
, "REQ_BEACON ", 11) == 0) {
3345 reply_len
= hostapd_ctrl_iface_req_beacon(hapd
, buf
+ 11,
3347 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
3348 reply_len
= hostapd_ctrl_driver_flags(hapd
->iface
, reply
,
3350 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
3352 } else if (os_strncmp(buf
, "ACCEPT_ACL ", 11) == 0) {
3353 if (os_strncmp(buf
+ 11, "ADD_MAC ", 8) == 0) {
3354 if (!hostapd_ctrl_iface_acl_add_mac(
3355 &hapd
->conf
->accept_mac
,
3356 &hapd
->conf
->num_accept_mac
, buf
+ 19))
3357 hostapd_disassoc_accept_mac(hapd
);
3360 } else if (os_strncmp((buf
+ 11), "DEL_MAC ", 8) == 0) {
3361 hostapd_ctrl_iface_acl_del_mac(
3362 &hapd
->conf
->accept_mac
,
3363 &hapd
->conf
->num_accept_mac
, buf
+ 19);
3364 } else if (os_strcmp(buf
+ 11, "SHOW") == 0) {
3365 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3366 hapd
->conf
->accept_mac
,
3367 hapd
->conf
->num_accept_mac
, reply
, reply_size
);
3368 } else if (os_strcmp(buf
+ 11, "CLEAR") == 0) {
3369 hostapd_ctrl_iface_acl_clear_list(
3370 &hapd
->conf
->accept_mac
,
3371 &hapd
->conf
->num_accept_mac
);
3373 } else if (os_strncmp(buf
, "DENY_ACL ", 9) == 0) {
3374 if (os_strncmp(buf
+ 9, "ADD_MAC ", 8) == 0) {
3375 if (!hostapd_ctrl_iface_acl_add_mac(
3376 &hapd
->conf
->deny_mac
,
3377 &hapd
->conf
->num_deny_mac
, buf
+ 17))
3378 hostapd_disassoc_deny_mac(hapd
);
3379 } else if (os_strncmp(buf
+ 9, "DEL_MAC ", 8) == 0) {
3380 hostapd_ctrl_iface_acl_del_mac(
3381 &hapd
->conf
->deny_mac
,
3382 &hapd
->conf
->num_deny_mac
, buf
+ 17);
3383 } else if (os_strcmp(buf
+ 9, "SHOW") == 0) {
3384 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3385 hapd
->conf
->deny_mac
,
3386 hapd
->conf
->num_deny_mac
, reply
, reply_size
);
3387 } else if (os_strcmp(buf
+ 9, "CLEAR") == 0) {
3388 hostapd_ctrl_iface_acl_clear_list(
3389 &hapd
->conf
->deny_mac
,
3390 &hapd
->conf
->num_deny_mac
);
3393 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
3394 res
= hostapd_dpp_qr_code(hapd
, buf
+ 12);
3398 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3399 if (os_snprintf_error(reply_size
, reply_len
))
3402 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
3403 res
= hostapd_dpp_nfc_uri(hapd
, buf
+ 12);
3407 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3408 if (os_snprintf_error(reply_size
, reply_len
))
3411 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
3412 res
= hostapd_dpp_nfc_handover_req(hapd
, buf
+ 20);
3416 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3417 if (os_snprintf_error(reply_size
, reply_len
))
3420 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
3421 res
= hostapd_dpp_nfc_handover_sel(hapd
, buf
+ 20);
3425 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3426 if (os_snprintf_error(reply_size
, reply_len
))
3429 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
3430 res
= dpp_bootstrap_gen(hapd
->iface
->interfaces
->dpp
, buf
+ 18);
3434 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3435 if (os_snprintf_error(reply_size
, reply_len
))
3438 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
3439 if (dpp_bootstrap_remove(hapd
->iface
->interfaces
->dpp
,
3442 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
3445 uri
= dpp_bootstrap_get_uri(hapd
->iface
->interfaces
->dpp
,
3450 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
3451 if (os_snprintf_error(reply_size
, reply_len
))
3454 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
3455 reply_len
= dpp_bootstrap_info(hapd
->iface
->interfaces
->dpp
,
3458 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
3459 if (hostapd_dpp_auth_init(hapd
, buf
+ 13) < 0)
3461 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
3462 if (hostapd_dpp_listen(hapd
, buf
+ 11) < 0)
3464 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
3465 hostapd_dpp_stop(hapd
);
3466 hostapd_dpp_listen_stop(hapd
);
3467 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
3468 res
= dpp_configurator_add(hapd
->iface
->interfaces
->dpp
,
3473 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3474 if (os_snprintf_error(reply_size
, reply_len
))
3477 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
3478 if (dpp_configurator_remove(hapd
->iface
->interfaces
->dpp
,
3481 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
3482 if (hostapd_dpp_configurator_sign(hapd
, buf
+ 21) < 0)
3484 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
3485 reply_len
= dpp_configurator_get_key_id(
3486 hapd
->iface
->interfaces
->dpp
,
3489 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
3490 res
= hostapd_dpp_pkex_add(hapd
, buf
+ 12);
3494 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3495 if (os_snprintf_error(reply_size
, reply_len
))
3498 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
3499 if (hostapd_dpp_pkex_remove(hapd
, buf
+ 16) < 0)
3501 #endif /* CONFIG_DPP */
3502 #ifdef RADIUS_SERVER
3503 } else if (os_strncmp(buf
, "DAC_REQUEST ", 12) == 0) {
3504 if (radius_server_dac_request(hapd
->radius_srv
, buf
+ 12) < 0)
3506 #endif /* RADIUS_SERVER */
3507 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
3508 reply_len
= hostapd_ctrl_iface_get_capability(
3509 hapd
, buf
+ 15, reply
, reply_size
);
3511 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
3515 if (reply_len
< 0) {
3516 os_memcpy(reply
, "FAIL\n", 5);
3524 static void hostapd_ctrl_iface_receive(int sock
, void *eloop_ctx
,
3527 struct hostapd_data
*hapd
= eloop_ctx
;
3530 struct sockaddr_storage from
;
3531 socklen_t fromlen
= sizeof(from
);
3532 char *reply
, *pos
= buf
;
3533 const int reply_size
= 4096;
3535 int level
= MSG_DEBUG
;
3536 #ifdef CONFIG_CTRL_IFACE_UDP
3537 unsigned char lcookie
[CTRL_IFACE_COOKIE_LEN
];
3538 #endif /* CONFIG_CTRL_IFACE_UDP */
3540 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
3541 (struct sockaddr
*) &from
, &fromlen
);
3543 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
3549 reply
= os_malloc(reply_size
);
3550 if (reply
== NULL
) {
3551 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
3553 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3559 #ifdef CONFIG_CTRL_IFACE_UDP
3560 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
3561 os_memcpy(reply
, "COOKIE=", 7);
3562 wpa_snprintf_hex(reply
+ 7, 2 * CTRL_IFACE_COOKIE_LEN
+ 1,
3563 hapd
->ctrl_iface_cookie
,
3564 CTRL_IFACE_COOKIE_LEN
);
3565 reply_len
= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
3569 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
3570 hexstr2bin(buf
+ 7, lcookie
, CTRL_IFACE_COOKIE_LEN
) < 0) {
3571 wpa_printf(MSG_DEBUG
,
3572 "CTRL: No cookie in the request - drop request");
3577 if (os_memcmp(hapd
->ctrl_iface_cookie
, lcookie
,
3578 CTRL_IFACE_COOKIE_LEN
) != 0) {
3579 wpa_printf(MSG_DEBUG
,
3580 "CTRL: Invalid cookie in the request - drop request");
3585 pos
= buf
+ 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
3588 #endif /* CONFIG_CTRL_IFACE_UDP */
3590 if (os_strcmp(pos
, "PING") == 0)
3591 level
= MSG_EXCESSIVE
;
3592 wpa_hexdump_ascii(level
, "RX ctrl_iface", pos
, res
);
3594 reply_len
= hostapd_ctrl_iface_receive_process(hapd
, pos
,
3598 #ifdef CONFIG_CTRL_IFACE_UDP
3600 #endif /* CONFIG_CTRL_IFACE_UDP */
3601 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
3603 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3610 #ifndef CONFIG_CTRL_IFACE_UDP
3611 static char * hostapd_ctrl_iface_path(struct hostapd_data
*hapd
)
3616 if (hapd
->conf
->ctrl_interface
== NULL
)
3619 len
= os_strlen(hapd
->conf
->ctrl_interface
) +
3620 os_strlen(hapd
->conf
->iface
) + 2;
3621 buf
= os_malloc(len
);
3625 os_snprintf(buf
, len
, "%s/%s",
3626 hapd
->conf
->ctrl_interface
, hapd
->conf
->iface
);
3627 buf
[len
- 1] = '\0';
3630 #endif /* CONFIG_CTRL_IFACE_UDP */
3633 static void hostapd_ctrl_iface_msg_cb(void *ctx
, int level
,
3634 enum wpa_msg_type type
,
3635 const char *txt
, size_t len
)
3637 struct hostapd_data
*hapd
= ctx
;
3640 hostapd_ctrl_iface_send(hapd
, level
, type
, txt
, len
);
3644 int hostapd_ctrl_iface_init(struct hostapd_data
*hapd
)
3646 #ifdef CONFIG_CTRL_IFACE_UDP
3647 int port
= HOSTAPD_CTRL_IFACE_PORT
;
3649 char port_str
[40], *tmp
;
3651 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3654 if (hapd
->ctrl_sock
> -1) {
3655 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3659 if (hapd
->conf
->ctrl_interface
== NULL
)
3662 pos
= os_strstr(hapd
->conf
->ctrl_interface
, "udp:");
3667 wpa_printf(MSG_ERROR
, "Invalid ctrl_iface UDP port");
3672 dl_list_init(&hapd
->ctrl_dst
);
3673 hapd
->ctrl_sock
= -1;
3674 os_get_random(hapd
->ctrl_iface_cookie
, CTRL_IFACE_COOKIE_LEN
);
3676 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3677 hints
.ai_flags
= AI_PASSIVE
;
3678 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3680 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3681 hints
.ai_family
= AF_INET6
;
3682 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3683 hints
.ai_family
= AF_INET
;
3684 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3685 hints
.ai_socktype
= SOCK_DGRAM
;
3688 os_snprintf(p
, sizeof(p
), "%d", port
);
3689 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3691 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3696 hapd
->ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3698 if (hapd
->ctrl_sock
< 0) {
3699 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3703 if (bind(hapd
->ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) < 0) {
3705 if ((HOSTAPD_CTRL_IFACE_PORT
- port
) <
3706 HOSTAPD_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3708 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3712 freeaddrinfo(saveres
);
3714 os_snprintf(port_str
, sizeof(port_str
), "udp:%d", port
);
3715 tmp
= os_strdup(port_str
);
3717 os_free(hapd
->conf
->ctrl_interface
);
3718 hapd
->conf
->ctrl_interface
= tmp
;
3720 wpa_printf(MSG_DEBUG
, "ctrl_iface_init UDP port: %d", port
);
3722 if (eloop_register_read_sock(hapd
->ctrl_sock
,
3723 hostapd_ctrl_iface_receive
, hapd
, NULL
) <
3725 hostapd_ctrl_iface_deinit(hapd
);
3729 hapd
->msg_ctx
= hapd
;
3730 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3735 if (hapd
->ctrl_sock
>= 0)
3736 close(hapd
->ctrl_sock
);
3738 #else /* CONFIG_CTRL_IFACE_UDP */
3739 struct sockaddr_un addr
;
3743 if (hapd
->ctrl_sock
> -1) {
3744 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3748 dl_list_init(&hapd
->ctrl_dst
);
3750 if (hapd
->conf
->ctrl_interface
== NULL
)
3753 if (mkdir(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3754 if (errno
== EEXIST
) {
3755 wpa_printf(MSG_DEBUG
, "Using existing control "
3756 "interface directory.");
3758 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3764 if (hapd
->conf
->ctrl_interface_gid_set
&&
3765 lchown(hapd
->conf
->ctrl_interface
, -1,
3766 hapd
->conf
->ctrl_interface_gid
) < 0) {
3767 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3772 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3773 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3774 lchown(hapd
->conf
->ctrl_interface
, -1,
3775 hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3776 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3783 * Android is using umask 0077 which would leave the control interface
3784 * directory without group access. This breaks things since Wi-Fi
3785 * framework assumes that this directory can be accessed by other
3786 * applications in the wifi group. Fix this by adding group access even
3787 * if umask value would prevent this.
3789 if (chmod(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3790 wpa_printf(MSG_ERROR
, "CTRL: Could not chmod directory: %s",
3792 /* Try to continue anyway */
3794 #endif /* ANDROID */
3796 if (os_strlen(hapd
->conf
->ctrl_interface
) + 1 +
3797 os_strlen(hapd
->conf
->iface
) >= sizeof(addr
.sun_path
))
3800 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
3802 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
3806 os_memset(&addr
, 0, sizeof(addr
));
3808 addr
.sun_len
= sizeof(addr
);
3809 #endif /* __FreeBSD__ */
3810 addr
.sun_family
= AF_UNIX
;
3811 fname
= hostapd_ctrl_iface_path(hapd
);
3814 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
3815 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3816 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
3818 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3819 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
3820 " allow connections - assuming it was left"
3821 "over from forced program termination");
3822 if (unlink(fname
) < 0) {
3823 wpa_printf(MSG_ERROR
,
3824 "Could not unlink existing ctrl_iface socket '%s': %s",
3825 fname
, strerror(errno
));
3828 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
3830 wpa_printf(MSG_ERROR
,
3831 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
3835 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
3836 "ctrl_iface socket '%s'", fname
);
3838 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
3839 "be in use - cannot override it");
3840 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
3841 "not used anymore", fname
);
3848 if (hapd
->conf
->ctrl_interface_gid_set
&&
3849 lchown(fname
, -1, hapd
->conf
->ctrl_interface_gid
) < 0) {
3850 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
3855 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3856 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3857 lchown(fname
, -1, hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3858 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
3863 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
3864 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
3870 hapd
->ctrl_sock
= s
;
3871 if (eloop_register_read_sock(s
, hostapd_ctrl_iface_receive
, hapd
,
3873 hostapd_ctrl_iface_deinit(hapd
);
3876 hapd
->msg_ctx
= hapd
;
3877 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3889 #endif /* CONFIG_CTRL_IFACE_UDP */
3893 void hostapd_ctrl_iface_deinit(struct hostapd_data
*hapd
)
3895 struct wpa_ctrl_dst
*dst
, *prev
;
3897 if (hapd
->ctrl_sock
> -1) {
3898 #ifndef CONFIG_CTRL_IFACE_UDP
3900 #endif /* !CONFIG_CTRL_IFACE_UDP */
3902 eloop_unregister_read_sock(hapd
->ctrl_sock
);
3903 close(hapd
->ctrl_sock
);
3904 hapd
->ctrl_sock
= -1;
3905 #ifndef CONFIG_CTRL_IFACE_UDP
3906 fname
= hostapd_ctrl_iface_path(hapd
);
3911 if (hapd
->conf
->ctrl_interface
&&
3912 rmdir(hapd
->conf
->ctrl_interface
) < 0) {
3913 if (errno
== ENOTEMPTY
) {
3914 wpa_printf(MSG_DEBUG
, "Control interface "
3915 "directory not empty - leaving it "
3918 wpa_printf(MSG_ERROR
,
3919 "rmdir[ctrl_interface=%s]: %s",
3920 hapd
->conf
->ctrl_interface
,
3924 #endif /* !CONFIG_CTRL_IFACE_UDP */
3927 dl_list_for_each_safe(dst
, prev
, &hapd
->ctrl_dst
, struct wpa_ctrl_dst
,
3931 #ifdef CONFIG_TESTING_OPTIONS
3932 l2_packet_deinit(hapd
->l2_test
);
3933 hapd
->l2_test
= NULL
;
3934 #endif /* CONFIG_TESTING_OPTIONS */
3938 static int hostapd_ctrl_iface_add(struct hapd_interfaces
*interfaces
,
3941 if (hostapd_add_iface(interfaces
, buf
) < 0) {
3942 wpa_printf(MSG_ERROR
, "Adding interface %s failed", buf
);
3949 static int hostapd_ctrl_iface_remove(struct hapd_interfaces
*interfaces
,
3952 if (hostapd_remove_iface(interfaces
, buf
) < 0) {
3953 wpa_printf(MSG_ERROR
, "Removing interface %s failed", buf
);
3960 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces
*interfaces
,
3961 struct sockaddr_storage
*from
,
3962 socklen_t fromlen
, char *input
)
3964 return ctrl_iface_attach(&interfaces
->global_ctrl_dst
, from
, fromlen
,
3969 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces
*interfaces
,
3970 struct sockaddr_storage
*from
,
3973 return ctrl_iface_detach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
3977 static void hostapd_ctrl_iface_flush(struct hapd_interfaces
*interfaces
)
3979 #ifdef CONFIG_WPS_TESTING
3980 wps_version_number
= 0x20;
3981 wps_testing_dummy_cred
= 0;
3982 wps_corrupt_pkhash
= 0;
3983 #endif /* CONFIG_WPS_TESTING */
3985 #ifdef CONFIG_TESTING_OPTIONS
3987 dpp_test
= DPP_TEST_DISABLED
;
3988 #endif /* CONFIG_DPP */
3989 #endif /* CONFIG_TESTING_OPTIONS */
3992 dpp_global_clear(interfaces
->dpp
);
3993 #endif /* CONFIG_DPP */
4000 hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces
*interfaces
,
4003 char ifname
[IFNAMSIZ
+ 1];
4004 struct fst_iface_cfg cfg
;
4005 struct hostapd_data
*hapd
;
4006 struct fst_wpa_obj iface_obj
;
4008 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
4009 hapd
= hostapd_get_iface(interfaces
, ifname
);
4011 if (hapd
->iface
->fst
) {
4012 wpa_printf(MSG_INFO
, "FST: Already attached");
4015 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
4016 hapd
->iface
->fst
= fst_attach(ifname
, hapd
->own_addr
,
4018 if (hapd
->iface
->fst
)
4028 hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces
*interfaces
,
4031 char ifname
[IFNAMSIZ
+ 1];
4032 struct hostapd_data
* hapd
;
4034 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
4035 hapd
= hostapd_get_iface(interfaces
, ifname
);
4037 if (!fst_iface_detach(ifname
)) {
4038 hapd
->iface
->fst
= NULL
;
4039 hapd
->iface
->fst_ies
= NULL
;
4048 #endif /* CONFIG_FST */
4051 static struct hostapd_data
*
4052 hostapd_interfaces_get_hapd(struct hapd_interfaces
*interfaces
,
4057 for (i
= 0; i
< interfaces
->count
; i
++) {
4058 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
4060 for (j
= 0; j
< iface
->num_bss
; j
++) {
4061 struct hostapd_data
*hapd
;
4063 hapd
= iface
->bss
[j
];
4064 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
4073 static int hostapd_ctrl_iface_dup_param(struct hostapd_data
*src_hapd
,
4074 struct hostapd_data
*dst_hapd
,
4080 value
= os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4082 wpa_printf(MSG_ERROR
,
4083 "DUP: cannot allocate buffer to stringify %s",
4088 if (os_strcmp(param
, "wpa") == 0) {
4089 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%d",
4090 src_hapd
->conf
->wpa
);
4091 } else if (os_strcmp(param
, "wpa_key_mgmt") == 0 &&
4092 src_hapd
->conf
->wpa_key_mgmt
) {
4093 res
= hostapd_ctrl_iface_get_key_mgmt(
4094 src_hapd
, value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4095 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, res
))
4096 goto error_stringify
;
4097 } else if (os_strcmp(param
, "wpa_pairwise") == 0 &&
4098 src_hapd
->conf
->wpa_pairwise
) {
4099 res
= wpa_write_ciphers(value
,
4100 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4101 src_hapd
->conf
->wpa_pairwise
, " ");
4103 goto error_stringify
;
4104 } else if (os_strcmp(param
, "rsn_pairwise") == 0 &&
4105 src_hapd
->conf
->rsn_pairwise
) {
4106 res
= wpa_write_ciphers(value
,
4107 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4108 src_hapd
->conf
->rsn_pairwise
, " ");
4110 goto error_stringify
;
4111 } else if (os_strcmp(param
, "wpa_passphrase") == 0 &&
4112 src_hapd
->conf
->ssid
.wpa_passphrase
) {
4113 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%s",
4114 src_hapd
->conf
->ssid
.wpa_passphrase
);
4115 } else if (os_strcmp(param
, "wpa_psk") == 0 &&
4116 src_hapd
->conf
->ssid
.wpa_psk_set
) {
4117 wpa_snprintf_hex(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4118 src_hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
4120 wpa_printf(MSG_WARNING
, "DUP: %s cannot be duplicated", param
);
4124 res
= hostapd_set_iface(dst_hapd
->iconf
, dst_hapd
->conf
, param
, value
);
4129 wpa_printf(MSG_ERROR
, "DUP: cannot stringify %s", param
);
4137 hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces
*interfaces
,
4139 char *reply
, int reply_size
)
4144 struct hostapd_iface
*iface
;
4148 show_ctrl
= !!os_strstr(input
, "ctrl");
4151 end
= reply
+ reply_size
;
4153 for (i
= 0; i
< interfaces
->count
; i
++) {
4154 iface
= interfaces
->iface
[i
];
4156 for (j
= 0; j
< iface
->num_bss
; j
++) {
4157 struct hostapd_bss_config
*conf
;
4159 conf
= iface
->conf
->bss
[j
];
4161 res
= os_snprintf(pos
, end
- pos
,
4162 "%s ctrl_iface=%s\n",
4164 conf
->ctrl_interface
?
4165 conf
->ctrl_interface
: "N/A");
4167 res
= os_snprintf(pos
, end
- pos
, "%s\n",
4169 if (os_snprintf_error(end
- pos
, res
)) {
4182 hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces
*interfaces
,
4185 char *p_start
= cmd
, *p_end
;
4186 struct hostapd_data
*src_hapd
, *dst_hapd
;
4188 /* cmd: "<src ifname> <dst ifname> <variable name> */
4190 p_end
= os_strchr(p_start
, ' ');
4192 wpa_printf(MSG_ERROR
, "DUP: no src ifname found in cmd: '%s'",
4198 src_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4200 wpa_printf(MSG_ERROR
, "DUP: no src ifname found: '%s'",
4205 p_start
= p_end
+ 1;
4206 p_end
= os_strchr(p_start
, ' ');
4208 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found in cmd: '%s'",
4214 dst_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4216 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found: '%s'",
4221 p_start
= p_end
+ 1;
4222 return hostapd_ctrl_iface_dup_param(src_hapd
, dst_hapd
, p_start
);
4226 static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces
*interfaces
,
4228 char *buf
, char *reply
,
4230 struct sockaddr_storage
*from
,
4233 struct hostapd_data
*hapd
;
4235 hapd
= hostapd_interfaces_get_hapd(interfaces
, ifname
);
4239 res
= os_snprintf(reply
, reply_size
, "FAIL-NO-IFNAME-MATCH\n");
4240 if (os_snprintf_error(reply_size
, res
))
4245 return hostapd_ctrl_iface_receive_process(hapd
, buf
, reply
,reply_size
,
4250 static void hostapd_global_ctrl_iface_receive(int sock
, void *eloop_ctx
,
4253 struct hapd_interfaces
*interfaces
= eloop_ctx
;
4254 char buffer
[256], *buf
= buffer
;
4256 struct sockaddr_storage from
;
4257 socklen_t fromlen
= sizeof(from
);
4260 const int reply_size
= 4096;
4261 #ifdef CONFIG_CTRL_IFACE_UDP
4262 unsigned char lcookie
[CTRL_IFACE_COOKIE_LEN
];
4263 #endif /* CONFIG_CTRL_IFACE_UDP */
4265 res
= recvfrom(sock
, buffer
, sizeof(buffer
) - 1, 0,
4266 (struct sockaddr
*) &from
, &fromlen
);
4268 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
4273 wpa_printf(MSG_DEBUG
, "Global ctrl_iface command: %s", buf
);
4275 reply
= os_malloc(reply_size
);
4276 if (reply
== NULL
) {
4277 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
4279 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4285 os_memcpy(reply
, "OK\n", 3);
4288 #ifdef CONFIG_CTRL_IFACE_UDP
4289 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
4290 os_memcpy(reply
, "COOKIE=", 7);
4291 wpa_snprintf_hex(reply
+ 7, 2 * CTRL_IFACE_COOKIE_LEN
+ 1,
4292 interfaces
->ctrl_iface_cookie
,
4293 CTRL_IFACE_COOKIE_LEN
);
4294 reply_len
= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
4298 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
4299 hexstr2bin(buf
+ 7, lcookie
, CTRL_IFACE_COOKIE_LEN
) < 0) {
4300 wpa_printf(MSG_DEBUG
,
4301 "CTRL: No cookie in the request - drop request");
4306 if (os_memcmp(interfaces
->ctrl_iface_cookie
, lcookie
,
4307 CTRL_IFACE_COOKIE_LEN
) != 0) {
4308 wpa_printf(MSG_DEBUG
,
4309 "CTRL: Invalid cookie in the request - drop request");
4314 buf
+= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
4317 #endif /* CONFIG_CTRL_IFACE_UDP */
4319 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
4320 char *pos
= os_strchr(buf
+ 7, ' ');
4324 reply_len
= hostapd_global_ctrl_iface_ifname(
4325 interfaces
, buf
+ 7, pos
, reply
, reply_size
,
4331 if (os_strcmp(buf
, "PING") == 0) {
4332 os_memcpy(reply
, "PONG\n", 5);
4334 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
4335 if (wpa_debug_reopen_file() < 0)
4337 } else if (os_strcmp(buf
, "FLUSH") == 0) {
4338 hostapd_ctrl_iface_flush(interfaces
);
4339 } else if (os_strncmp(buf
, "ADD ", 4) == 0) {
4340 if (hostapd_ctrl_iface_add(interfaces
, buf
+ 4) < 0)
4342 } else if (os_strncmp(buf
, "REMOVE ", 7) == 0) {
4343 if (hostapd_ctrl_iface_remove(interfaces
, buf
+ 7) < 0)
4345 } else if (os_strcmp(buf
, "ATTACH") == 0) {
4346 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4349 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
4350 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4353 } else if (os_strcmp(buf
, "DETACH") == 0) {
4354 if (hostapd_global_ctrl_iface_detach(interfaces
, &from
,
4357 #ifdef CONFIG_MODULE_TESTS
4358 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
4359 if (hapd_module_tests() < 0)
4361 #endif /* CONFIG_MODULE_TESTS */
4363 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
4364 if (!hostapd_global_ctrl_iface_fst_attach(interfaces
, buf
+ 11))
4365 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4368 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
4369 if (!hostapd_global_ctrl_iface_fst_detach(interfaces
, buf
+ 11))
4370 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4373 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
4374 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
4375 #endif /* CONFIG_FST */
4376 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
4377 if (!hostapd_global_ctrl_iface_dup_network(interfaces
,
4379 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4382 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
4383 reply_len
= hostapd_global_ctrl_iface_interfaces(
4384 interfaces
, buf
+ 10, reply
, sizeof(buffer
));
4385 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4388 wpa_printf(MSG_DEBUG
, "Unrecognized global ctrl_iface command "
4394 if (reply_len
< 0) {
4395 os_memcpy(reply
, "FAIL\n", 5);
4399 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
4401 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4408 #ifndef CONFIG_CTRL_IFACE_UDP
4409 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces
*interface
)
4414 if (interface
->global_iface_path
== NULL
)
4417 len
= os_strlen(interface
->global_iface_path
) +
4418 os_strlen(interface
->global_iface_name
) + 2;
4419 buf
= os_malloc(len
);
4423 os_snprintf(buf
, len
, "%s/%s", interface
->global_iface_path
,
4424 interface
->global_iface_name
);
4425 buf
[len
- 1] = '\0';
4428 #endif /* CONFIG_CTRL_IFACE_UDP */
4431 int hostapd_global_ctrl_iface_init(struct hapd_interfaces
*interface
)
4433 #ifdef CONFIG_CTRL_IFACE_UDP
4434 int port
= HOSTAPD_GLOBAL_CTRL_IFACE_PORT
;
4437 struct addrinfo hints
= { 0 }, *res
, *saveres
;
4440 if (interface
->global_ctrl_sock
> -1) {
4441 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
4445 if (interface
->global_iface_path
== NULL
)
4448 pos
= os_strstr(interface
->global_iface_path
, "udp:");
4453 wpa_printf(MSG_ERROR
, "Invalid global ctrl UDP port");
4458 os_get_random(interface
->ctrl_iface_cookie
, CTRL_IFACE_COOKIE_LEN
);
4460 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4461 hints
.ai_flags
= AI_PASSIVE
;
4462 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4464 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
4465 hints
.ai_family
= AF_INET6
;
4466 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4467 hints
.ai_family
= AF_INET
;
4468 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4469 hints
.ai_socktype
= SOCK_DGRAM
;
4472 os_snprintf(p
, sizeof(p
), "%d", port
);
4473 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
4475 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
4480 interface
->global_ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
4482 if (interface
->global_ctrl_sock
< 0) {
4483 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
4487 if (bind(interface
->global_ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) <
4490 if ((port
- HOSTAPD_GLOBAL_CTRL_IFACE_PORT
) <
4491 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT
&& !pos
)
4493 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
4497 freeaddrinfo(saveres
);
4499 wpa_printf(MSG_DEBUG
, "global ctrl_iface_init UDP port: %d", port
);
4501 if (eloop_register_read_sock(interface
->global_ctrl_sock
,
4502 hostapd_global_ctrl_iface_receive
,
4503 interface
, NULL
) < 0) {
4504 hostapd_global_ctrl_iface_deinit(interface
);
4508 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4513 if (interface
->global_ctrl_sock
>= 0)
4514 close(interface
->global_ctrl_sock
);
4516 #else /* CONFIG_CTRL_IFACE_UDP */
4517 struct sockaddr_un addr
;
4521 if (interface
->global_iface_path
== NULL
) {
4522 wpa_printf(MSG_DEBUG
, "ctrl_iface not configured!");
4526 if (mkdir(interface
->global_iface_path
, S_IRWXU
| S_IRWXG
) < 0) {
4527 if (errno
== EEXIST
) {
4528 wpa_printf(MSG_DEBUG
, "Using existing control "
4529 "interface directory.");
4531 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
4535 } else if (interface
->ctrl_iface_group
&&
4536 lchown(interface
->global_iface_path
, -1,
4537 interface
->ctrl_iface_group
) < 0) {
4538 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4543 if (os_strlen(interface
->global_iface_path
) + 1 +
4544 os_strlen(interface
->global_iface_name
) >= sizeof(addr
.sun_path
))
4547 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
4549 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
4553 os_memset(&addr
, 0, sizeof(addr
));
4555 addr
.sun_len
= sizeof(addr
);
4556 #endif /* __FreeBSD__ */
4557 addr
.sun_family
= AF_UNIX
;
4558 fname
= hostapd_global_ctrl_iface_path(interface
);
4561 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
4562 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4563 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
4565 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4566 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
4567 " allow connections - assuming it was left"
4568 "over from forced program termination");
4569 if (unlink(fname
) < 0) {
4570 wpa_printf(MSG_ERROR
,
4571 "Could not unlink existing ctrl_iface socket '%s': %s",
4572 fname
, strerror(errno
));
4575 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
4577 wpa_printf(MSG_ERROR
, "bind(PF_UNIX): %s",
4581 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
4582 "ctrl_iface socket '%s'", fname
);
4584 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
4585 "be in use - cannot override it");
4586 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
4587 "not used anymore", fname
);
4594 if (interface
->ctrl_iface_group
&&
4595 lchown(fname
, -1, interface
->ctrl_iface_group
) < 0) {
4596 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4601 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
4602 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
4608 interface
->global_ctrl_sock
= s
;
4609 eloop_register_read_sock(s
, hostapd_global_ctrl_iface_receive
,
4612 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4624 #endif /* CONFIG_CTRL_IFACE_UDP */
4628 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces
*interfaces
)
4630 #ifndef CONFIG_CTRL_IFACE_UDP
4632 #endif /* CONFIG_CTRL_IFACE_UDP */
4633 struct wpa_ctrl_dst
*dst
, *prev
;
4635 if (interfaces
->global_ctrl_sock
> -1) {
4636 eloop_unregister_read_sock(interfaces
->global_ctrl_sock
);
4637 close(interfaces
->global_ctrl_sock
);
4638 interfaces
->global_ctrl_sock
= -1;
4639 #ifndef CONFIG_CTRL_IFACE_UDP
4640 fname
= hostapd_global_ctrl_iface_path(interfaces
);
4646 if (interfaces
->global_iface_path
&&
4647 rmdir(interfaces
->global_iface_path
) < 0) {
4648 if (errno
== ENOTEMPTY
) {
4649 wpa_printf(MSG_DEBUG
, "Control interface "
4650 "directory not empty - leaving it "
4653 wpa_printf(MSG_ERROR
,
4654 "rmdir[ctrl_interface=%s]: %s",
4655 interfaces
->global_iface_path
,
4659 #endif /* CONFIG_CTRL_IFACE_UDP */
4662 os_free(interfaces
->global_iface_path
);
4663 interfaces
->global_iface_path
= NULL
;
4665 dl_list_for_each_safe(dst
, prev
, &interfaces
->global_ctrl_dst
,
4666 struct wpa_ctrl_dst
, list
)
4671 static int hostapd_ctrl_check_event_enabled(struct wpa_ctrl_dst
*dst
,
4674 /* Enable Probe Request events based on explicit request.
4675 * Other events are enabled by default.
4677 if (str_starts(buf
, RX_PROBE_REQUEST
))
4678 return !!(dst
->events
& WPA_EVENT_RX_PROBE_REQUEST
);
4683 static void hostapd_ctrl_iface_send_internal(int sock
, struct dl_list
*ctrl_dst
,
4684 const char *ifname
, int level
,
4685 const char *buf
, size_t len
)
4687 struct wpa_ctrl_dst
*dst
, *next
;
4693 if (sock
< 0 || dl_list_empty(ctrl_dst
))
4696 res
= os_snprintf(levelstr
, sizeof(levelstr
), "<%d>", level
);
4697 if (os_snprintf_error(sizeof(levelstr
), res
))
4701 io
[idx
].iov_base
= "IFNAME=";
4702 io
[idx
].iov_len
= 7;
4704 io
[idx
].iov_base
= (char *) ifname
;
4705 io
[idx
].iov_len
= os_strlen(ifname
);
4707 io
[idx
].iov_base
= " ";
4708 io
[idx
].iov_len
= 1;
4711 io
[idx
].iov_base
= levelstr
;
4712 io
[idx
].iov_len
= os_strlen(levelstr
);
4714 io
[idx
].iov_base
= (char *) buf
;
4715 io
[idx
].iov_len
= len
;
4717 os_memset(&msg
, 0, sizeof(msg
));
4719 msg
.msg_iovlen
= idx
;
4722 dl_list_for_each_safe(dst
, next
, ctrl_dst
, struct wpa_ctrl_dst
, list
) {
4723 if ((level
>= dst
->debug_level
) &&
4724 hostapd_ctrl_check_event_enabled(dst
, buf
)) {
4725 sockaddr_print(MSG_DEBUG
, "CTRL_IFACE monitor send",
4726 &dst
->addr
, dst
->addrlen
);
4727 msg
.msg_name
= &dst
->addr
;
4728 msg
.msg_namelen
= dst
->addrlen
;
4729 if (sendmsg(sock
, &msg
, 0) < 0) {
4731 wpa_printf(MSG_INFO
, "CTRL_IFACE monitor[%d]: "
4733 idx
, errno
, strerror(errno
));
4735 if (dst
->errors
> 10 || _errno
== ENOENT
) {
4736 ctrl_iface_detach(ctrl_dst
,
4748 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
4749 enum wpa_msg_type type
,
4750 const char *buf
, size_t len
)
4752 if (type
!= WPA_MSG_NO_GLOBAL
) {
4753 hostapd_ctrl_iface_send_internal(
4754 hapd
->iface
->interfaces
->global_ctrl_sock
,
4755 &hapd
->iface
->interfaces
->global_ctrl_dst
,
4756 type
!= WPA_MSG_PER_INTERFACE
?
4757 NULL
: hapd
->conf
->iface
,
4761 if (type
!= WPA_MSG_ONLY_GLOBAL
) {
4762 hostapd_ctrl_iface_send_internal(
4763 hapd
->ctrl_sock
, &hapd
->ctrl_dst
,
4764 NULL
, level
, buf
, len
);
4768 #endif /* CONFIG_NATIVE_WINDOWS */