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
))
1298 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && hapd
->conf
->extended_key_id
) {
1299 ret
= os_snprintf(pos
, end
- pos
, "extended_key_id=%d\n",
1300 hapd
->conf
->extended_key_id
);
1301 if (os_snprintf_error(end
- pos
, ret
))
1310 static void hostapd_disassoc_accept_mac(struct hostapd_data
*hapd
)
1312 struct sta_info
*sta
;
1313 struct vlan_description vlan_id
;
1315 if (hapd
->conf
->macaddr_acl
!= DENY_UNLESS_ACCEPTED
)
1318 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1319 if (!hostapd_maclist_found(hapd
->conf
->accept_mac
,
1320 hapd
->conf
->num_accept_mac
,
1321 sta
->addr
, &vlan_id
) ||
1322 (vlan_id
.notempty
&&
1323 vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1324 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1325 WLAN_REASON_UNSPECIFIED
);
1330 static void hostapd_disassoc_deny_mac(struct hostapd_data
*hapd
)
1332 struct sta_info
*sta
;
1333 struct vlan_description vlan_id
;
1335 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1336 if (hostapd_maclist_found(hapd
->conf
->deny_mac
,
1337 hapd
->conf
->num_deny_mac
, sta
->addr
,
1339 (!vlan_id
.notempty
||
1340 !vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1341 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1342 WLAN_REASON_UNSPECIFIED
);
1347 static int hostapd_ctrl_iface_set_band(struct hostapd_data
*hapd
,
1350 union wpa_event_data event
;
1351 enum set_band setband
;
1353 if (os_strcmp(band
, "AUTO") == 0)
1354 setband
= WPA_SETBAND_AUTO
;
1355 else if (os_strcmp(band
, "5G") == 0)
1356 setband
= WPA_SETBAND_5G
;
1357 else if (os_strcmp(band
, "2G") == 0)
1358 setband
= WPA_SETBAND_2G
;
1362 if (hostapd_drv_set_band(hapd
, setband
) == 0) {
1363 os_memset(&event
, 0, sizeof(event
));
1364 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
1365 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
1366 wpa_supplicant_event(hapd
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
1373 static int hostapd_ctrl_iface_set(struct hostapd_data
*hapd
, char *cmd
)
1378 value
= os_strchr(cmd
, ' ');
1383 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
1385 #ifdef CONFIG_WPS_TESTING
1386 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
1388 val
= strtol(value
, NULL
, 0);
1389 if (val
< 0 || val
> 0xff) {
1391 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
1392 "wps_version_number %ld", val
);
1394 wps_version_number
= val
;
1395 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
1397 (wps_version_number
& 0xf0) >> 4,
1398 wps_version_number
& 0x0f);
1399 hostapd_wps_update_ie(hapd
);
1401 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
1402 wps_testing_dummy_cred
= atoi(value
);
1403 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
1404 wps_testing_dummy_cred
);
1405 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
1406 wps_corrupt_pkhash
= atoi(value
);
1407 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
1408 wps_corrupt_pkhash
);
1409 #endif /* CONFIG_WPS_TESTING */
1410 #ifdef CONFIG_TESTING_OPTIONS
1411 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
1412 hapd
->ext_mgmt_frame_handling
= atoi(value
);
1413 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
1414 hapd
->ext_eapol_frame_io
= atoi(value
);
1416 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
1417 os_free(hapd
->dpp_config_obj_override
);
1418 hapd
->dpp_config_obj_override
= os_strdup(value
);
1419 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
1420 os_free(hapd
->dpp_discovery_override
);
1421 hapd
->dpp_discovery_override
= os_strdup(value
);
1422 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
1423 os_free(hapd
->dpp_groups_override
);
1424 hapd
->dpp_groups_override
= os_strdup(value
);
1425 } else if (os_strcasecmp(cmd
,
1426 "dpp_ignore_netaccesskey_mismatch") == 0) {
1427 hapd
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
1428 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
1429 dpp_test
= atoi(value
);
1430 #endif /* CONFIG_DPP */
1431 #endif /* CONFIG_TESTING_OPTIONS */
1433 } else if (os_strcasecmp(cmd
, "mbo_assoc_disallow") == 0) {
1436 if (!hapd
->conf
->mbo_enabled
)
1440 if (val
< 0 || val
> 1)
1443 hapd
->mbo_assoc_disallow
= val
;
1444 ieee802_11_update_beacons(hapd
->iface
);
1447 * TODO: Need to configure drivers that do AP MLME offload with
1448 * disallowing station logic.
1450 #endif /* CONFIG_MBO */
1452 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
1453 os_free(hapd
->dpp_configurator_params
);
1454 hapd
->dpp_configurator_params
= os_strdup(value
);
1455 #endif /* CONFIG_DPP */
1456 } else if (os_strcasecmp(cmd
, "setband") == 0) {
1457 ret
= hostapd_ctrl_iface_set_band(hapd
, value
);
1459 ret
= hostapd_set_iface(hapd
->iconf
, hapd
->conf
, cmd
, value
);
1463 if (os_strcasecmp(cmd
, "deny_mac_file") == 0) {
1464 hostapd_disassoc_deny_mac(hapd
);
1465 } else if (os_strcasecmp(cmd
, "accept_mac_file") == 0) {
1466 hostapd_disassoc_accept_mac(hapd
);
1467 } else if (os_strncmp(cmd
, "wme_ac_", 7) == 0 ||
1468 os_strncmp(cmd
, "wmm_ac_", 7) == 0) {
1469 hapd
->parameter_set_count
++;
1470 if (ieee802_11_update_beacons(hapd
->iface
))
1471 wpa_printf(MSG_DEBUG
,
1472 "Failed to update beacons with WMM parameters");
1473 } else if (os_strcmp(cmd
, "wpa_passphrase") == 0 ||
1474 os_strcmp(cmd
, "sae_password") == 0 ||
1475 os_strcmp(cmd
, "sae_pwe") == 0) {
1477 hostapd_setup_sae_pt(hapd
->conf
);
1485 static int hostapd_ctrl_iface_get(struct hostapd_data
*hapd
, char *cmd
,
1486 char *buf
, size_t buflen
)
1490 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
1492 if (os_strcmp(cmd
, "version") == 0) {
1493 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
1494 if (os_snprintf_error(buflen
, res
))
1497 } else if (os_strcmp(cmd
, "tls_library") == 0) {
1498 res
= tls_get_library_version(buf
, buflen
);
1499 if (os_snprintf_error(buflen
, res
))
1508 static int hostapd_ctrl_iface_enable(struct hostapd_iface
*iface
)
1510 if (hostapd_enable_iface(iface
) < 0) {
1511 wpa_printf(MSG_ERROR
, "Enabling of interface failed");
1518 static int hostapd_ctrl_iface_reload(struct hostapd_iface
*iface
)
1520 if (hostapd_reload_iface(iface
) < 0) {
1521 wpa_printf(MSG_ERROR
, "Reloading of interface failed");
1528 static int hostapd_ctrl_iface_disable(struct hostapd_iface
*iface
)
1530 if (hostapd_disable_iface(iface
) < 0) {
1531 wpa_printf(MSG_ERROR
, "Disabling of interface failed");
1539 hostapd_ctrl_iface_kick_mismatch_psk_sta_iter(struct hostapd_data
*hapd
,
1540 struct sta_info
*sta
, void *ctx
)
1542 struct hostapd_wpa_psk
*psk
;
1550 pmk
= wpa_auth_get_pmk(sta
->wpa_sm
, &pmk_len
);
1552 for (psk
= hapd
->conf
->ssid
.wpa_psk
; pmk
&& psk
; psk
= psk
->next
) {
1553 pmk_match
= PMK_LEN
== pmk_len
&&
1554 os_memcmp(psk
->psk
, pmk
, pmk_len
) == 0;
1555 sta_match
= psk
->group
== 0 &&
1556 os_memcmp(sta
->addr
, psk
->addr
, ETH_ALEN
) == 0;
1557 bss_match
= psk
->group
== 1;
1559 if (pmk_match
&& (sta_match
|| bss_match
))
1563 wpa_printf(MSG_INFO
, "STA " MACSTR
1564 " PSK/passphrase no longer valid - disconnect",
1565 MAC2STR(sta
->addr
));
1566 reason
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
1567 hostapd_drv_sta_deauth(hapd
, sta
->addr
, reason
);
1568 ap_sta_deauthenticate(hapd
, sta
, reason
);
1574 static int hostapd_ctrl_iface_reload_wpa_psk(struct hostapd_data
*hapd
)
1576 struct hostapd_bss_config
*conf
= hapd
->conf
;
1579 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
1581 err
= hostapd_setup_wpa_psk(conf
);
1583 wpa_printf(MSG_ERROR
, "Reloading WPA-PSK passwords failed: %d",
1588 ap_for_each_sta(hapd
, hostapd_ctrl_iface_kick_mismatch_psk_sta_iter
,
1595 #ifdef CONFIG_TESTING_OPTIONS
1597 static int hostapd_ctrl_iface_radar(struct hostapd_data
*hapd
, char *cmd
)
1599 union wpa_event_data data
;
1601 enum wpa_event_type event
;
1603 wpa_printf(MSG_DEBUG
, "RADAR TEST: %s", cmd
);
1605 os_memset(&data
, 0, sizeof(data
));
1607 param
= os_strchr(cmd
, ' ');
1612 if (os_strcmp(cmd
, "DETECTED") == 0)
1613 event
= EVENT_DFS_RADAR_DETECTED
;
1614 else if (os_strcmp(cmd
, "CAC-FINISHED") == 0)
1615 event
= EVENT_DFS_CAC_FINISHED
;
1616 else if (os_strcmp(cmd
, "CAC-ABORTED") == 0)
1617 event
= EVENT_DFS_CAC_ABORTED
;
1618 else if (os_strcmp(cmd
, "NOP-FINISHED") == 0)
1619 event
= EVENT_DFS_NOP_FINISHED
;
1621 wpa_printf(MSG_DEBUG
, "Unsupported RADAR test command: %s",
1626 pos
= os_strstr(param
, "freq=");
1628 data
.dfs_event
.freq
= atoi(pos
+ 5);
1630 pos
= os_strstr(param
, "ht_enabled=1");
1632 data
.dfs_event
.ht_enabled
= 1;
1634 pos
= os_strstr(param
, "chan_offset=");
1636 data
.dfs_event
.chan_offset
= atoi(pos
+ 12);
1638 pos
= os_strstr(param
, "chan_width=");
1640 data
.dfs_event
.chan_width
= atoi(pos
+ 11);
1642 pos
= os_strstr(param
, "cf1=");
1644 data
.dfs_event
.cf1
= atoi(pos
+ 4);
1646 pos
= os_strstr(param
, "cf2=");
1648 data
.dfs_event
.cf2
= atoi(pos
+ 4);
1650 wpa_supplicant_event(hapd
, event
, &data
);
1656 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data
*hapd
, char *cmd
)
1662 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
1664 len
= os_strlen(cmd
);
1669 buf
= os_malloc(len
);
1673 if (hexstr2bin(cmd
, buf
, len
) < 0) {
1678 res
= hostapd_drv_send_mlme(hapd
, buf
, len
, 0, NULL
, 0, 0);
1684 static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data
*hapd
,
1690 int stype
= 0, ok
= 0;
1691 union wpa_event_data event
;
1693 if (!hapd
->ext_mgmt_frame_handling
)
1696 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1698 wpa_printf(MSG_DEBUG
, "External MGMT TX status process: %s", cmd
);
1701 param
= os_strstr(pos
, "stype=");
1704 stype
= atoi(param
);
1707 param
= os_strstr(pos
, " ok=");
1713 param
= os_strstr(pos
, " buf=");
1718 len
= os_strlen(param
);
1723 buf
= os_malloc(len
);
1724 if (!buf
|| hexstr2bin(param
, buf
, len
) < 0) {
1729 os_memset(&event
, 0, sizeof(event
));
1730 event
.tx_status
.type
= WLAN_FC_TYPE_MGMT
;
1731 event
.tx_status
.data
= buf
;
1732 event
.tx_status
.data_len
= len
;
1733 event
.tx_status
.stype
= stype
;
1734 event
.tx_status
.ack
= ok
;
1735 hapd
->ext_mgmt_frame_handling
= 0;
1736 wpa_supplicant_event(hapd
, EVENT_TX_STATUS
, &event
);
1737 hapd
->ext_mgmt_frame_handling
= 1;
1745 static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data
*hapd
,
1751 int freq
= 0, datarate
= 0, ssi_signal
= 0;
1752 union wpa_event_data event
;
1754 if (!hapd
->ext_mgmt_frame_handling
)
1757 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1759 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
1762 param
= os_strstr(pos
, "freq=");
1768 param
= os_strstr(pos
, " datarate=");
1771 datarate
= atoi(param
);
1774 param
= os_strstr(pos
, " ssi_signal=");
1777 ssi_signal
= atoi(param
);
1780 param
= os_strstr(pos
, " frame=");
1785 len
= os_strlen(param
);
1790 buf
= os_malloc(len
);
1794 if (hexstr2bin(param
, buf
, len
) < 0) {
1799 os_memset(&event
, 0, sizeof(event
));
1800 event
.rx_mgmt
.freq
= freq
;
1801 event
.rx_mgmt
.frame
= buf
;
1802 event
.rx_mgmt
.frame_len
= len
;
1803 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1804 event
.rx_mgmt
.datarate
= datarate
;
1805 hapd
->ext_mgmt_frame_handling
= 0;
1806 wpa_supplicant_event(hapd
, EVENT_RX_MGMT
, &event
);
1807 hapd
->ext_mgmt_frame_handling
= 1;
1815 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data
*hapd
, char *cmd
)
1818 u8 src
[ETH_ALEN
], *buf
;
1822 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
1825 used
= hwaddr_aton2(pos
, src
);
1832 len
= os_strlen(pos
);
1837 buf
= os_malloc(len
);
1841 if (hexstr2bin(pos
, buf
, len
) < 0) {
1846 ieee802_1x_receive(hapd
, src
, buf
, len
);
1853 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
1857 const u16
*pos
= buf
;
1859 for (i
= 0; i
< len
/ 2; i
++)
1863 sum
= (sum
& 0xffff) + (sum
>> 16);
1865 return sum
^ 0xffff;
1869 #define HWSIM_PACKETLEN 1500
1870 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1872 static void hostapd_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
1875 struct hostapd_data
*hapd
= ctx
;
1876 const struct ether_header
*eth
;
1882 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
1883 wpa_printf(MSG_DEBUG
,
1884 "test data: RX - ignore unexpected length %d",
1889 eth
= (const struct ether_header
*) buf
;
1890 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
1891 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
1893 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 ||
1894 ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
1895 wpa_printf(MSG_DEBUG
,
1896 "test data: RX - ignore unexpect IP header");
1900 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
1901 if (*pos
!= (u8
) i
) {
1902 wpa_printf(MSG_DEBUG
,
1903 "test data: RX - ignore mismatching payload");
1910 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
1911 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
1912 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
1913 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
1917 static int hostapd_ctrl_iface_data_test_config(struct hostapd_data
*hapd
,
1920 int enabled
= atoi(cmd
);
1925 if (hapd
->l2_test
) {
1926 l2_packet_deinit(hapd
->l2_test
);
1927 hapd
->l2_test
= NULL
;
1928 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1929 "test data: Disabled");
1937 pos
= os_strstr(cmd
, " ifname=");
1941 ifname
= hapd
->conf
->iface
;
1943 hapd
->l2_test
= l2_packet_init(ifname
, hapd
->own_addr
,
1944 ETHERTYPE_IP
, hostapd_data_test_rx
,
1946 if (hapd
->l2_test
== NULL
)
1949 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: Enabled");
1955 static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data
*hapd
, char *cmd
)
1957 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
1962 u8 buf
[2 + HWSIM_PACKETLEN
];
1963 struct ether_header
*eth
;
1967 size_t send_len
= HWSIM_IP_LEN
;
1969 if (hapd
->l2_test
== NULL
)
1972 /* format: <dst> <src> <tos> [len=<length>] */
1975 used
= hwaddr_aton2(pos
, dst
);
1981 used
= hwaddr_aton2(pos
, src
);
1986 val
= strtol(pos
, &pos2
, 0);
1987 if (val
< 0 || val
> 0xff)
1991 pos
= os_strstr(pos2
, " len=");
1994 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
1999 eth
= (struct ether_header
*) &buf
[2];
2000 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
2001 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
2002 eth
->ether_type
= htons(ETHERTYPE_IP
);
2003 ip
= (struct ip
*) (eth
+ 1);
2004 os_memset(ip
, 0, sizeof(*ip
));
2009 ip
->ip_len
= htons(send_len
);
2011 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
2012 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
2013 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
2014 dpos
= (u8
*) (ip
+ 1);
2015 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
2018 if (l2_packet_send(hapd
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
2019 sizeof(struct ether_header
) + send_len
) < 0)
2022 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX dst=" MACSTR
2023 " src=" MACSTR
" tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
2029 static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data
*hapd
,
2033 struct ether_header
*eth
;
2034 struct l2_packet_data
*l2
= NULL
;
2038 const char *ifname
= hapd
->conf
->iface
;
2040 if (os_strncmp(cmd
, "ifname=", 7) == 0) {
2043 cmd
= os_strchr(cmd
, ' ');
2049 len
= os_strlen(cmd
);
2050 if (len
& 1 || len
< ETH_HLEN
* 2)
2054 buf
= os_malloc(len
);
2058 if (hexstr2bin(cmd
, buf
, len
) < 0)
2061 eth
= (struct ether_header
*) buf
;
2062 ethertype
= ntohs(eth
->ether_type
);
2064 l2
= l2_packet_init(ifname
, hapd
->own_addr
, ethertype
,
2065 hostapd_data_test_rx
, hapd
, 1);
2069 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
2070 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
2073 l2_packet_deinit(l2
);
2076 return res
< 0 ? -1 : 0;
2080 static int hostapd_ctrl_test_alloc_fail(struct hostapd_data
*hapd
, char *cmd
)
2082 #ifdef WPA_TRACE_BFD
2085 wpa_trace_fail_after
= atoi(cmd
);
2086 pos
= os_strchr(cmd
, ':');
2089 os_strlcpy(wpa_trace_fail_func
, pos
,
2090 sizeof(wpa_trace_fail_func
));
2092 wpa_trace_fail_after
= 0;
2096 #else /* WPA_TRACE_BFD */
2098 #endif /* WPA_TRACE_BFD */
2102 static int hostapd_ctrl_get_alloc_fail(struct hostapd_data
*hapd
,
2103 char *buf
, size_t buflen
)
2105 #ifdef WPA_TRACE_BFD
2106 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
2107 wpa_trace_fail_func
);
2108 #else /* WPA_TRACE_BFD */
2110 #endif /* WPA_TRACE_BFD */
2114 static int hostapd_ctrl_test_fail(struct hostapd_data
*hapd
, char *cmd
)
2116 #ifdef WPA_TRACE_BFD
2119 wpa_trace_test_fail_after
= atoi(cmd
);
2120 pos
= os_strchr(cmd
, ':');
2123 os_strlcpy(wpa_trace_test_fail_func
, pos
,
2124 sizeof(wpa_trace_test_fail_func
));
2126 wpa_trace_test_fail_after
= 0;
2130 #else /* WPA_TRACE_BFD */
2132 #endif /* WPA_TRACE_BFD */
2136 static int hostapd_ctrl_get_fail(struct hostapd_data
*hapd
,
2137 char *buf
, size_t buflen
)
2139 #ifdef WPA_TRACE_BFD
2140 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
2141 wpa_trace_test_fail_func
);
2142 #else /* WPA_TRACE_BFD */
2144 #endif /* WPA_TRACE_BFD */
2148 static int hostapd_ctrl_reset_pn(struct hostapd_data
*hapd
, const char *cmd
)
2150 struct sta_info
*sta
;
2152 u8 zero
[WPA_TK_MAX_LEN
];
2154 os_memset(zero
, 0, sizeof(zero
));
2156 if (hwaddr_aton(cmd
, addr
))
2159 if (is_broadcast_ether_addr(addr
) && os_strstr(cmd
, "IGTK")) {
2160 if (hapd
->last_igtk_alg
== WPA_ALG_NONE
)
2163 wpa_printf(MSG_INFO
, "TESTING: Reset IPN for IGTK");
2165 /* First, use a zero key to avoid any possible duplicate key
2166 * avoidance in the driver. */
2167 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2168 hapd
->last_igtk_alg
,
2169 broadcast_ether_addr
,
2170 hapd
->last_igtk_key_idx
, 0, 1, NULL
, 0,
2171 zero
, hapd
->last_igtk_len
,
2172 KEY_FLAG_GROUP_TX_DEFAULT
) < 0)
2175 /* Set the previously configured key to reset its TSC */
2176 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2177 hapd
->last_igtk_alg
,
2178 broadcast_ether_addr
,
2179 hapd
->last_igtk_key_idx
, 0, 1, NULL
,
2181 hapd
->last_igtk_len
,
2182 KEY_FLAG_GROUP_TX_DEFAULT
);
2185 if (is_broadcast_ether_addr(addr
)) {
2186 if (hapd
->last_gtk_alg
== WPA_ALG_NONE
)
2189 wpa_printf(MSG_INFO
, "TESTING: Reset PN for GTK");
2191 /* First, use a zero key to avoid any possible duplicate key
2192 * avoidance in the driver. */
2193 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2195 broadcast_ether_addr
,
2196 hapd
->last_gtk_key_idx
, 0, 1, NULL
, 0,
2197 zero
, hapd
->last_gtk_len
,
2198 KEY_FLAG_GROUP_TX_DEFAULT
) < 0)
2201 /* Set the previously configured key to reset its TSC */
2202 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2204 broadcast_ether_addr
,
2205 hapd
->last_gtk_key_idx
, 0, 1, NULL
,
2208 KEY_FLAG_GROUP_TX_DEFAULT
);
2211 sta
= ap_get_sta(hapd
, addr
);
2215 if (sta
->last_tk_alg
== WPA_ALG_NONE
)
2218 wpa_printf(MSG_INFO
, "TESTING: Reset PN for " MACSTR
,
2219 MAC2STR(sta
->addr
));
2221 /* First, use a zero key to avoid any possible duplicate key avoidance
2223 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2224 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2225 zero
, sta
->last_tk_len
,
2226 KEY_FLAG_PAIRWISE_RX_TX
) < 0)
2229 /* Set the previously configured key to reset its TSC/RSC */
2230 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2231 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
,
2232 0, sta
->last_tk
, sta
->last_tk_len
,
2233 KEY_FLAG_PAIRWISE_RX_TX
);
2237 static int hostapd_ctrl_set_key(struct hostapd_data
*hapd
, const char *cmd
)
2240 const char *pos
= cmd
;
2242 enum key_flag key_flag
;
2244 u8 seq
[6], key
[WPA_TK_MAX_LEN
];
2247 /* parameters: alg addr idx set_tx seq key key_flag */
2250 pos
= os_strchr(pos
, ' ');
2254 if (hwaddr_aton(pos
, addr
))
2261 pos
= os_strchr(pos
, ' ');
2266 pos
= os_strchr(pos
, ' ');
2270 if (hexstr2bin(pos
, seq
, sizeof(seq
)) < 0)
2276 if (!os_strchr(pos
, ' '))
2278 key_len
= (os_strchr(pos
, ' ') - pos
) / 2;
2279 if (hexstr2bin(pos
, key
, key_len
) < 0)
2286 key_flag
= atoi(pos
);
2287 pos
= os_strchr(pos
, ' ');
2291 wpa_printf(MSG_INFO
, "TESTING: Set key");
2292 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, alg
, addr
, idx
, 0,
2293 set_tx
, seq
, 6, key
, key_len
, key_flag
);
2297 static void restore_tk(void *ctx1
, void *ctx2
)
2299 struct hostapd_data
*hapd
= ctx1
;
2300 struct sta_info
*sta
= ctx2
;
2302 wpa_printf(MSG_INFO
, "TESTING: Restore TK for " MACSTR
,
2303 MAC2STR(sta
->addr
));
2304 /* This does not really restore the TSC properly, so this will result
2305 * in replay protection issues for now since there is no clean way of
2306 * preventing encryption of a single EAPOL frame. */
2307 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2308 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2309 sta
->last_tk
, sta
->last_tk_len
,
2310 KEY_FLAG_PAIRWISE_RX_TX
);
2314 static int hostapd_ctrl_resend_m1(struct hostapd_data
*hapd
, const char *cmd
)
2316 struct sta_info
*sta
;
2318 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2320 if (hwaddr_aton(cmd
, addr
))
2323 sta
= ap_get_sta(hapd
, addr
);
2324 if (!sta
|| !sta
->wpa_sm
)
2327 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2328 plain
= 0; /* no need for special processing */
2330 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2331 MAC2STR(sta
->addr
));
2332 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2333 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2334 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2337 wpa_printf(MSG_INFO
, "TESTING: Send M1 to " MACSTR
, MAC2STR(sta
->addr
));
2338 return wpa_auth_resend_m1(sta
->wpa_sm
,
2339 os_strstr(cmd
, "change-anonce") != NULL
,
2340 plain
? restore_tk
: NULL
, hapd
, sta
);
2344 static int hostapd_ctrl_resend_m3(struct hostapd_data
*hapd
, const char *cmd
)
2346 struct sta_info
*sta
;
2348 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2350 if (hwaddr_aton(cmd
, addr
))
2353 sta
= ap_get_sta(hapd
, addr
);
2354 if (!sta
|| !sta
->wpa_sm
)
2357 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2358 plain
= 0; /* no need for special processing */
2360 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2361 MAC2STR(sta
->addr
));
2362 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2363 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2364 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2367 wpa_printf(MSG_INFO
, "TESTING: Send M3 to " MACSTR
, MAC2STR(sta
->addr
));
2368 return wpa_auth_resend_m3(sta
->wpa_sm
,
2369 plain
? restore_tk
: NULL
, hapd
, sta
);
2373 static int hostapd_ctrl_resend_group_m1(struct hostapd_data
*hapd
,
2376 struct sta_info
*sta
;
2378 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2380 if (hwaddr_aton(cmd
, addr
))
2383 sta
= ap_get_sta(hapd
, addr
);
2384 if (!sta
|| !sta
->wpa_sm
)
2387 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2388 plain
= 0; /* no need for special processing */
2390 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2391 MAC2STR(sta
->addr
));
2392 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2393 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2394 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2397 wpa_printf(MSG_INFO
,
2398 "TESTING: Send group M1 for the same GTK and zero RSC to "
2399 MACSTR
, MAC2STR(sta
->addr
));
2400 return wpa_auth_resend_group_m1(sta
->wpa_sm
,
2401 plain
? restore_tk
: NULL
, hapd
, sta
);
2405 static int hostapd_ctrl_get_pmk(struct hostapd_data
*hapd
, const char *cmd
,
2406 char *buf
, size_t buflen
)
2408 struct sta_info
*sta
;
2413 if (hwaddr_aton(cmd
, addr
))
2416 sta
= ap_get_sta(hapd
, addr
);
2417 if (!sta
|| !sta
->wpa_sm
) {
2418 wpa_printf(MSG_DEBUG
, "No STA WPA state machine for " MACSTR
,
2422 pmk
= wpa_auth_get_pmk(sta
->wpa_sm
, &pmk_len
);
2424 wpa_printf(MSG_DEBUG
, "No PMK stored for " MACSTR
,
2429 return wpa_snprintf_hex(buf
, buflen
, pmk
, pmk_len
);
2432 #endif /* CONFIG_TESTING_OPTIONS */
2435 static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface
*iface
,
2439 struct csa_settings settings
;
2443 ret
= hostapd_parse_csa_settings(pos
, &settings
);
2447 for (i
= 0; i
< iface
->num_bss
; i
++) {
2449 /* Save CHAN_SWITCH VHT config */
2450 hostapd_chan_switch_vht_config(
2451 iface
->bss
[i
], settings
.freq_params
.vht_enabled
);
2453 ret
= hostapd_switch_channel(iface
->bss
[i
], &settings
);
2455 /* FIX: What do we do if CSA fails in the middle of
2456 * submitting multi-BSS CSA requests? */
2462 #else /* NEED_AP_MLME */
2464 #endif /* NEED_AP_MLME */
2468 static int hostapd_ctrl_iface_mib(struct hostapd_data
*hapd
, char *reply
,
2469 int reply_size
, const char *param
)
2471 #ifdef RADIUS_SERVER
2472 if (os_strcmp(param
, "radius_server") == 0) {
2473 return radius_server_get_mib(hapd
->radius_srv
, reply
,
2476 #endif /* RADIUS_SERVER */
2481 static int hostapd_ctrl_iface_vendor(struct hostapd_data
*hapd
, char *cmd
,
2482 char *buf
, size_t buflen
)
2487 unsigned int vendor_id
, subcmd
;
2488 struct wpabuf
*reply
;
2489 size_t data_len
= 0;
2491 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2492 vendor_id
= strtoul(cmd
, &pos
, 16);
2493 if (!isblank((unsigned char) *pos
))
2496 subcmd
= strtoul(pos
, &pos
, 10);
2499 if (!isblank((unsigned char) *pos
++))
2501 data_len
= os_strlen(pos
);
2506 data
= os_malloc(data_len
);
2510 if (hexstr2bin(pos
, data
, data_len
)) {
2511 wpa_printf(MSG_DEBUG
,
2512 "Vendor command: wrong parameter format");
2518 reply
= wpabuf_alloc((buflen
- 1) / 2);
2524 ret
= hostapd_drv_vendor_cmd(hapd
, vendor_id
, subcmd
, data
, data_len
,
2528 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
2538 static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data
*hapd
,
2542 struct sta_info
*sta
;
2544 if (hwaddr_aton(cmd
, addr
))
2547 sta
= ap_get_sta(hapd
, addr
);
2548 if (!sta
|| !sta
->eapol_sm
)
2551 eapol_auth_reauthenticate(sta
->eapol_sm
);
2556 static int hostapd_ctrl_iface_eapol_set(struct hostapd_data
*hapd
, char *cmd
)
2559 struct sta_info
*sta
;
2560 char *pos
= cmd
, *param
;
2562 if (hwaddr_aton(pos
, addr
) || pos
[17] != ' ')
2566 pos
= os_strchr(pos
, ' ');
2571 sta
= ap_get_sta(hapd
, addr
);
2572 if (!sta
|| !sta
->eapol_sm
)
2575 return eapol_auth_set_conf(sta
->eapol_sm
, param
, pos
);
2579 static int hostapd_ctrl_iface_log_level(struct hostapd_data
*hapd
, char *cmd
,
2580 char *buf
, size_t buflen
)
2582 char *pos
, *end
, *stamp
;
2585 /* cmd: "LOG_LEVEL [<level>]" */
2589 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2591 debug_level_str(wpa_debug_level
),
2592 wpa_debug_timestamp
);
2593 if (os_snprintf_error(end
- pos
, ret
))
2602 stamp
= os_strchr(cmd
, ' ');
2605 while (*stamp
== ' ') {
2610 if (os_strlen(cmd
)) {
2611 int level
= str_to_debug_level(cmd
);
2614 wpa_debug_level
= level
;
2617 if (stamp
&& os_strlen(stamp
))
2618 wpa_debug_timestamp
= atoi(stamp
);
2620 os_memcpy(buf
, "OK\n", 3);
2626 static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data
*hapd
,
2627 char *buf
, size_t buflen
)
2629 struct hostapd_iface
*iface
= hapd
->iface
;
2631 struct hostapd_sta_info
*info
;
2632 struct os_reltime now
;
2634 if (!iface
->num_sta_seen
)
2637 sta_track_expire(iface
, 0);
2642 os_get_reltime(&now
);
2643 dl_list_for_each_reverse(info
, &iface
->sta_seen
,
2644 struct hostapd_sta_info
, list
) {
2645 struct os_reltime age
;
2648 os_reltime_sub(&now
, &info
->last_seen
, &age
);
2649 ret
= os_snprintf(pos
, end
- pos
, MACSTR
" %u %d\n",
2650 MAC2STR(info
->addr
), (unsigned int) age
.sec
,
2652 if (os_snprintf_error(end
- pos
, ret
))
2659 #endif /* NEED_AP_MLME */
2662 static int hostapd_ctrl_iface_req_lci(struct hostapd_data
*hapd
,
2667 if (hwaddr_aton(cmd
, addr
)) {
2668 wpa_printf(MSG_INFO
, "CTRL: REQ_LCI: Invalid MAC address");
2672 return hostapd_send_lci_req(hapd
, addr
);
2676 static int hostapd_ctrl_iface_req_range(struct hostapd_data
*hapd
, char *cmd
)
2679 char *token
, *context
= NULL
;
2680 int random_interval
, min_ap
;
2681 u8 responders
[ETH_ALEN
* RRM_RANGE_REQ_MAX_RESPONDERS
];
2682 unsigned int n_responders
;
2684 token
= str_token(cmd
, " ", &context
);
2685 if (!token
|| hwaddr_aton(token
, addr
)) {
2686 wpa_printf(MSG_INFO
,
2687 "CTRL: REQ_RANGE - Bad destination address");
2691 token
= str_token(cmd
, " ", &context
);
2695 random_interval
= atoi(token
);
2696 if (random_interval
< 0 || random_interval
> 0xffff)
2699 token
= str_token(cmd
, " ", &context
);
2703 min_ap
= atoi(token
);
2704 if (min_ap
<= 0 || min_ap
> WLAN_RRM_RANGE_REQ_MAX_MIN_AP
)
2708 while ((token
= str_token(cmd
, " ", &context
))) {
2709 if (n_responders
== RRM_RANGE_REQ_MAX_RESPONDERS
) {
2710 wpa_printf(MSG_INFO
,
2711 "CTRL: REQ_RANGE: Too many responders");
2715 if (hwaddr_aton(token
, responders
+ n_responders
* ETH_ALEN
)) {
2716 wpa_printf(MSG_INFO
,
2717 "CTRL: REQ_RANGE: Bad responder address");
2724 if (!n_responders
) {
2725 wpa_printf(MSG_INFO
,
2726 "CTRL: REQ_RANGE - No FTM responder address");
2730 return hostapd_send_range_req(hapd
, addr
, random_interval
, min_ap
,
2731 responders
, n_responders
);
2735 static int hostapd_ctrl_iface_req_beacon(struct hostapd_data
*hapd
,
2736 const char *cmd
, char *reply
,
2745 if (hwaddr_aton(cmd
, addr
))
2747 pos
= os_strchr(cmd
, ' ');
2751 if (os_strncmp(pos
, "req_mode=", 9) == 0) {
2752 int val
= hex2byte(pos
+ 9);
2758 pos
= os_strchr(pos
, ' ');
2763 req
= wpabuf_parse_bin(pos
);
2767 ret
= hostapd_send_beacon_req(hapd
, addr
, req_mode
, req
);
2770 ret
= os_snprintf(reply
, reply_size
, "%d", ret
);
2775 static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data
*hapd
,
2776 char *buf
, size_t buflen
)
2778 if (!(hapd
->conf
->radio_measurements
[0] &
2779 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2780 wpa_printf(MSG_ERROR
,
2781 "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled");
2785 return hostapd_neighbor_show(hapd
, buf
, buflen
);
2789 static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data
*hapd
, char *buf
)
2791 struct wpa_ssid_value ssid
;
2793 struct wpabuf
*nr
, *lci
= NULL
, *civic
= NULL
;
2798 if (!(hapd
->conf
->radio_measurements
[0] &
2799 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2800 wpa_printf(MSG_ERROR
,
2801 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
2805 if (hwaddr_aton(buf
, bssid
)) {
2806 wpa_printf(MSG_ERROR
, "CTRL: SET_NEIGHBOR: Bad BSSID");
2810 tmp
= os_strstr(buf
, "ssid=");
2811 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2812 wpa_printf(MSG_ERROR
,
2813 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
2816 buf
= os_strchr(tmp
+ 6, tmp
[5] == '"' ? '"' : ' ');
2820 tmp
= os_strstr(buf
, "nr=");
2822 wpa_printf(MSG_ERROR
,
2823 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
2827 buf
= os_strchr(tmp
, ' ');
2831 nr
= wpabuf_parse_bin(tmp
+ 3);
2833 wpa_printf(MSG_ERROR
,
2834 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
2841 tmp
= os_strstr(buf
, "lci=");
2843 buf
= os_strchr(tmp
, ' ');
2846 lci
= wpabuf_parse_bin(tmp
+ 4);
2848 wpa_printf(MSG_ERROR
,
2849 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
2858 tmp
= os_strstr(buf
, "civic=");
2860 buf
= os_strchr(tmp
, ' ');
2863 civic
= wpabuf_parse_bin(tmp
+ 6);
2865 wpa_printf(MSG_ERROR
,
2866 "CTRL: SET_NEIGHBOR: Bad civic subelement");
2876 if (os_strstr(buf
, "stat"))
2880 ret
= hostapd_neighbor_set(hapd
, bssid
, &ssid
, nr
, lci
, civic
,
2891 static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data
*hapd
,
2894 struct wpa_ssid_value ssid
;
2895 struct wpa_ssid_value
*ssidp
= NULL
;
2899 if (hwaddr_aton(buf
, bssid
)) {
2900 wpa_printf(MSG_ERROR
, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
2904 tmp
= os_strstr(buf
, "ssid=");
2907 if (ssid_parse(tmp
+ 5, &ssid
)) {
2908 wpa_printf(MSG_ERROR
,
2909 "CTRL: REMOVE_NEIGHBOR: Bad SSID");
2914 return hostapd_neighbor_remove(hapd
, bssid
, ssidp
);
2918 static int hostapd_ctrl_driver_flags(struct hostapd_iface
*iface
, char *buf
,
2924 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
2925 (long long unsigned) iface
->drv_flags
);
2926 if (os_snprintf_error(buflen
, ret
))
2932 for (i
= 0; i
< 64; i
++) {
2933 if (iface
->drv_flags
& (1LLU << i
)) {
2934 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
2935 driver_flag_to_string(1LLU << i
));
2936 if (os_snprintf_error(end
- pos
, ret
))
2946 static int hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry
**acl
, int *num
,
2947 const char *txtaddr
)
2950 struct vlan_description vlan_id
;
2955 if (hwaddr_aton(txtaddr
, addr
))
2958 if (hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
))
2959 hostapd_remove_acl_mac(acl
, num
, addr
);
2965 static void hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry
**acl
,
2969 hostapd_remove_acl_mac(acl
, num
, (*acl
)[0].addr
);
2973 static int hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry
*acl
, int num
,
2974 char *buf
, size_t buflen
)
2976 int i
= 0, len
= 0, ret
= 0;
2982 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2983 MACSTR
" VLAN_ID=%d\n",
2984 MAC2STR(acl
[i
].addr
),
2985 acl
[i
].vlan_id
.untagged
);
2986 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
2995 static int hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry
**acl
, int *num
,
2999 struct vlan_description vlan_id
;
3000 int ret
= 0, vlanid
= 0;
3003 if (hwaddr_aton(cmd
, addr
))
3006 pos
= os_strstr(cmd
, "VLAN_ID=");
3008 vlanid
= atoi(pos
+ 8);
3010 if (!hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
)) {
3011 ret
= hostapd_add_acl_maclist(acl
, num
, vlanid
, addr
);
3012 if (ret
!= -1 && *acl
)
3013 qsort(*acl
, *num
, sizeof(**acl
), hostapd_acl_comp
);
3016 return ret
< 0 ? -1 : 0;
3020 static int hostapd_ctrl_iface_get_capability(struct hostapd_data
*hapd
,
3021 const char *field
, char *buf
,
3024 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s'", field
);
3027 if (os_strcmp(field
, "dpp") == 0) {
3031 res
= os_snprintf(buf
, buflen
, "DPP=2");
3032 #else /* CONFIG_DPP2 */
3033 res
= os_snprintf(buf
, buflen
, "DPP=1");
3034 #endif /* CONFIG_DPP2 */
3035 if (os_snprintf_error(buflen
, res
))
3039 #endif /* CONFIG_DPP */
3041 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3048 static int hostapd_ctrl_iface_receive_process(struct hostapd_data
*hapd
,
3049 char *buf
, char *reply
,
3051 struct sockaddr_storage
*from
,
3056 os_memcpy(reply
, "OK\n", 3);
3059 if (os_strcmp(buf
, "PING") == 0) {
3060 os_memcpy(reply
, "PONG\n", 5);
3062 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3063 if (wpa_debug_reopen_file() < 0)
3065 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3066 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3067 } else if (os_strcmp(buf
, "STATUS") == 0) {
3068 reply_len
= hostapd_ctrl_iface_status(hapd
, reply
,
3070 } else if (os_strcmp(buf
, "STATUS-DRIVER") == 0) {
3071 reply_len
= hostapd_drv_status(hapd
, reply
, reply_size
);
3072 } else if (os_strcmp(buf
, "MIB") == 0) {
3073 reply_len
= ieee802_11_get_mib(hapd
, reply
, reply_size
);
3074 if (reply_len
>= 0) {
3075 res
= wpa_get_mib(hapd
->wpa_auth
, reply
+ reply_len
,
3076 reply_size
- reply_len
);
3082 if (reply_len
>= 0) {
3083 res
= ieee802_1x_get_mib(hapd
, reply
+ reply_len
,
3084 reply_size
- reply_len
);
3090 #ifndef CONFIG_NO_RADIUS
3091 if (reply_len
>= 0) {
3092 res
= radius_client_get_mib(hapd
->radius
,
3094 reply_size
- reply_len
);
3100 #endif /* CONFIG_NO_RADIUS */
3101 } else if (os_strncmp(buf
, "MIB ", 4) == 0) {
3102 reply_len
= hostapd_ctrl_iface_mib(hapd
, reply
, reply_size
,
3104 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
3105 reply_len
= hostapd_ctrl_iface_sta_first(hapd
, reply
,
3107 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
3108 reply_len
= hostapd_ctrl_iface_sta(hapd
, buf
+ 4, reply
,
3110 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
3111 reply_len
= hostapd_ctrl_iface_sta_next(hapd
, buf
+ 9, reply
,
3113 } else if (os_strcmp(buf
, "ATTACH") == 0) {
3114 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, NULL
))
3116 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
3117 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, buf
+ 7))
3119 } else if (os_strcmp(buf
, "DETACH") == 0) {
3120 if (hostapd_ctrl_iface_detach(hapd
, from
, fromlen
))
3122 } else if (os_strncmp(buf
, "LEVEL ", 6) == 0) {
3123 if (hostapd_ctrl_iface_level(hapd
, from
, fromlen
,
3126 } else if (os_strncmp(buf
, "NEW_STA ", 8) == 0) {
3127 if (hostapd_ctrl_iface_new_sta(hapd
, buf
+ 8))
3129 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
3130 if (hostapd_ctrl_iface_deauthenticate(hapd
, buf
+ 15))
3132 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
3133 if (hostapd_ctrl_iface_disassociate(hapd
, buf
+ 13))
3135 #ifdef CONFIG_TAXONOMY
3136 } else if (os_strncmp(buf
, "SIGNATURE ", 10) == 0) {
3137 reply_len
= hostapd_ctrl_iface_signature(hapd
, buf
+ 10,
3139 #endif /* CONFIG_TAXONOMY */
3140 } else if (os_strncmp(buf
, "POLL_STA ", 9) == 0) {
3141 if (hostapd_ctrl_iface_poll_sta(hapd
, buf
+ 9))
3143 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
3144 if (hostapd_ctrl_iface_stop_ap(hapd
))
3147 } else if (os_strncmp(buf
, "SA_QUERY ", 9) == 0) {
3148 if (hostapd_ctrl_iface_sa_query(hapd
, buf
+ 9))
3150 #endif /* NEED_AP_MLME */
3152 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
3153 if (hostapd_ctrl_iface_wps_pin(hapd
, buf
+ 8))
3155 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
3156 reply_len
= hostapd_ctrl_iface_wps_check_pin(
3157 hapd
, buf
+ 14, reply
, reply_size
);
3158 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
3159 if (hostapd_wps_button_pushed(hapd
, NULL
))
3161 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
3162 if (hostapd_wps_cancel(hapd
))
3164 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
3165 reply_len
= hostapd_ctrl_iface_wps_ap_pin(hapd
, buf
+ 11,
3167 } else if (os_strncmp(buf
, "WPS_CONFIG ", 11) == 0) {
3168 if (hostapd_ctrl_iface_wps_config(hapd
, buf
+ 11) < 0)
3170 } else if (os_strncmp(buf
, "WPS_GET_STATUS", 13) == 0) {
3171 reply_len
= hostapd_ctrl_iface_wps_get_status(hapd
, reply
,
3173 #ifdef CONFIG_WPS_NFC
3174 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
3175 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd
, buf
+ 17))
3177 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
3178 reply_len
= hostapd_ctrl_iface_wps_nfc_config_token(
3179 hapd
, buf
+ 21, reply
, reply_size
);
3180 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
3181 reply_len
= hostapd_ctrl_iface_wps_nfc_token(
3182 hapd
, buf
+ 14, reply
, reply_size
);
3183 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
3184 reply_len
= hostapd_ctrl_iface_nfc_get_handover_sel(
3185 hapd
, buf
+ 21, reply
, reply_size
);
3186 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
3187 if (hostapd_ctrl_iface_nfc_report_handover(hapd
, buf
+ 20))
3189 #endif /* CONFIG_WPS_NFC */
3190 #endif /* CONFIG_WPS */
3191 #ifdef CONFIG_INTERWORKING
3192 } else if (os_strncmp(buf
, "SET_QOS_MAP_SET ", 16) == 0) {
3193 if (hostapd_ctrl_iface_set_qos_map_set(hapd
, buf
+ 16))
3195 } else if (os_strncmp(buf
, "SEND_QOS_MAP_CONF ", 18) == 0) {
3196 if (hostapd_ctrl_iface_send_qos_map_conf(hapd
, buf
+ 18))
3198 #endif /* CONFIG_INTERWORKING */
3200 } else if (os_strncmp(buf
, "HS20_WNM_NOTIF ", 15) == 0) {
3201 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd
, buf
+ 15))
3203 } else if (os_strncmp(buf
, "HS20_DEAUTH_REQ ", 16) == 0) {
3204 if (hostapd_ctrl_iface_hs20_deauth_req(hapd
, buf
+ 16))
3206 #endif /* CONFIG_HS20 */
3207 #ifdef CONFIG_WNM_AP
3208 } else if (os_strncmp(buf
, "DISASSOC_IMMINENT ", 18) == 0) {
3209 if (hostapd_ctrl_iface_disassoc_imminent(hapd
, buf
+ 18))
3211 } else if (os_strncmp(buf
, "ESS_DISASSOC ", 13) == 0) {
3212 if (hostapd_ctrl_iface_ess_disassoc(hapd
, buf
+ 13))
3214 } else if (os_strncmp(buf
, "BSS_TM_REQ ", 11) == 0) {
3215 if (hostapd_ctrl_iface_bss_tm_req(hapd
, buf
+ 11))
3217 } else if (os_strncmp(buf
, "COLOC_INTF_REQ ", 15) == 0) {
3218 if (hostapd_ctrl_iface_coloc_intf_req(hapd
, buf
+ 15))
3220 #endif /* CONFIG_WNM_AP */
3221 } else if (os_strcmp(buf
, "GET_CONFIG") == 0) {
3222 reply_len
= hostapd_ctrl_iface_get_config(hapd
, reply
,
3224 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3225 if (hostapd_ctrl_iface_set(hapd
, buf
+ 4))
3227 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3228 reply_len
= hostapd_ctrl_iface_get(hapd
, buf
+ 4, reply
,
3230 } else if (os_strncmp(buf
, "ENABLE", 6) == 0) {
3231 if (hostapd_ctrl_iface_enable(hapd
->iface
))
3233 } else if (os_strcmp(buf
, "RELOAD_WPA_PSK") == 0) {
3234 if (hostapd_ctrl_iface_reload_wpa_psk(hapd
))
3236 } else if (os_strncmp(buf
, "RELOAD", 6) == 0) {
3237 if (hostapd_ctrl_iface_reload(hapd
->iface
))
3239 } else if (os_strncmp(buf
, "DISABLE", 7) == 0) {
3240 if (hostapd_ctrl_iface_disable(hapd
->iface
))
3242 } else if (os_strcmp(buf
, "UPDATE_BEACON") == 0) {
3243 if (ieee802_11_set_beacon(hapd
))
3245 #ifdef CONFIG_TESTING_OPTIONS
3246 } else if (os_strncmp(buf
, "RADAR ", 6) == 0) {
3247 if (hostapd_ctrl_iface_radar(hapd
, buf
+ 6))
3249 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
3250 if (hostapd_ctrl_iface_mgmt_tx(hapd
, buf
+ 8))
3252 } else if (os_strncmp(buf
, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
3253 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd
,
3256 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
3257 if (hostapd_ctrl_iface_mgmt_rx_process(hapd
, buf
+ 16) < 0)
3259 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
3260 if (hostapd_ctrl_iface_eapol_rx(hapd
, buf
+ 9) < 0)
3262 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
3263 if (hostapd_ctrl_iface_data_test_config(hapd
, buf
+ 17) < 0)
3265 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
3266 if (hostapd_ctrl_iface_data_test_tx(hapd
, buf
+ 13) < 0)
3268 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
3269 if (hostapd_ctrl_iface_data_test_frame(hapd
, buf
+ 16) < 0)
3271 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
3272 if (hostapd_ctrl_test_alloc_fail(hapd
, buf
+ 16) < 0)
3274 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
3275 reply_len
= hostapd_ctrl_get_alloc_fail(hapd
, reply
,
3277 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
3278 if (hostapd_ctrl_test_fail(hapd
, buf
+ 10) < 0)
3280 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
3281 reply_len
= hostapd_ctrl_get_fail(hapd
, reply
, reply_size
);
3282 } else if (os_strncmp(buf
, "RESET_PN ", 9) == 0) {
3283 if (hostapd_ctrl_reset_pn(hapd
, buf
+ 9) < 0)
3285 } else if (os_strncmp(buf
, "SET_KEY ", 8) == 0) {
3286 if (hostapd_ctrl_set_key(hapd
, buf
+ 8) < 0)
3288 } else if (os_strncmp(buf
, "RESEND_M1 ", 10) == 0) {
3289 if (hostapd_ctrl_resend_m1(hapd
, buf
+ 10) < 0)
3291 } else if (os_strncmp(buf
, "RESEND_M3 ", 10) == 0) {
3292 if (hostapd_ctrl_resend_m3(hapd
, buf
+ 10) < 0)
3294 } else if (os_strncmp(buf
, "RESEND_GROUP_M1 ", 16) == 0) {
3295 if (hostapd_ctrl_resend_group_m1(hapd
, buf
+ 16) < 0)
3297 } else if (os_strcmp(buf
, "REKEY_GTK") == 0) {
3298 if (wpa_auth_rekey_gtk(hapd
->wpa_auth
) < 0)
3300 } else if (os_strncmp(buf
, "GET_PMK ", 8) == 0) {
3301 reply_len
= hostapd_ctrl_get_pmk(hapd
, buf
+ 8, reply
,
3303 #endif /* CONFIG_TESTING_OPTIONS */
3304 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
3305 if (hostapd_ctrl_iface_chan_switch(hapd
->iface
, buf
+ 12))
3307 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
3308 reply_len
= hostapd_ctrl_iface_vendor(hapd
, buf
+ 7, reply
,
3310 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
3311 ieee802_1x_erp_flush(hapd
);
3312 #ifdef RADIUS_SERVER
3313 radius_server_erp_flush(hapd
->radius_srv
);
3314 #endif /* RADIUS_SERVER */
3315 } else if (os_strncmp(buf
, "EAPOL_REAUTH ", 13) == 0) {
3316 if (hostapd_ctrl_iface_eapol_reauth(hapd
, buf
+ 13))
3318 } else if (os_strncmp(buf
, "EAPOL_SET ", 10) == 0) {
3319 if (hostapd_ctrl_iface_eapol_set(hapd
, buf
+ 10))
3321 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
3322 reply_len
= hostapd_ctrl_iface_log_level(
3323 hapd
, buf
+ 9, reply
, reply_size
);
3325 } else if (os_strcmp(buf
, "TRACK_STA_LIST") == 0) {
3326 reply_len
= hostapd_ctrl_iface_track_sta_list(
3327 hapd
, reply
, reply_size
);
3328 #endif /* NEED_AP_MLME */
3329 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3330 reply_len
= hostapd_ctrl_iface_pmksa_list(hapd
, reply
,
3332 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
3333 hostapd_ctrl_iface_pmksa_flush(hapd
);
3334 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
3335 if (hostapd_ctrl_iface_pmksa_add(hapd
, buf
+ 10) < 0)
3337 } else if (os_strncmp(buf
, "SET_NEIGHBOR ", 13) == 0) {
3338 if (hostapd_ctrl_iface_set_neighbor(hapd
, buf
+ 13))
3340 } else if (os_strcmp(buf
, "SHOW_NEIGHBOR") == 0) {
3341 reply_len
= hostapd_ctrl_iface_show_neighbor(hapd
, reply
,
3343 } else if (os_strncmp(buf
, "REMOVE_NEIGHBOR ", 16) == 0) {
3344 if (hostapd_ctrl_iface_remove_neighbor(hapd
, buf
+ 16))
3346 } else if (os_strncmp(buf
, "REQ_LCI ", 8) == 0) {
3347 if (hostapd_ctrl_iface_req_lci(hapd
, buf
+ 8))
3349 } else if (os_strncmp(buf
, "REQ_RANGE ", 10) == 0) {
3350 if (hostapd_ctrl_iface_req_range(hapd
, buf
+ 10))
3352 } else if (os_strncmp(buf
, "REQ_BEACON ", 11) == 0) {
3353 reply_len
= hostapd_ctrl_iface_req_beacon(hapd
, buf
+ 11,
3355 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
3356 reply_len
= hostapd_ctrl_driver_flags(hapd
->iface
, reply
,
3358 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
3360 } else if (os_strncmp(buf
, "ACCEPT_ACL ", 11) == 0) {
3361 if (os_strncmp(buf
+ 11, "ADD_MAC ", 8) == 0) {
3362 if (!hostapd_ctrl_iface_acl_add_mac(
3363 &hapd
->conf
->accept_mac
,
3364 &hapd
->conf
->num_accept_mac
, buf
+ 19))
3365 hostapd_disassoc_accept_mac(hapd
);
3368 } else if (os_strncmp((buf
+ 11), "DEL_MAC ", 8) == 0) {
3369 hostapd_ctrl_iface_acl_del_mac(
3370 &hapd
->conf
->accept_mac
,
3371 &hapd
->conf
->num_accept_mac
, buf
+ 19);
3372 } else if (os_strcmp(buf
+ 11, "SHOW") == 0) {
3373 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3374 hapd
->conf
->accept_mac
,
3375 hapd
->conf
->num_accept_mac
, reply
, reply_size
);
3376 } else if (os_strcmp(buf
+ 11, "CLEAR") == 0) {
3377 hostapd_ctrl_iface_acl_clear_list(
3378 &hapd
->conf
->accept_mac
,
3379 &hapd
->conf
->num_accept_mac
);
3381 } else if (os_strncmp(buf
, "DENY_ACL ", 9) == 0) {
3382 if (os_strncmp(buf
+ 9, "ADD_MAC ", 8) == 0) {
3383 if (!hostapd_ctrl_iface_acl_add_mac(
3384 &hapd
->conf
->deny_mac
,
3385 &hapd
->conf
->num_deny_mac
, buf
+ 17))
3386 hostapd_disassoc_deny_mac(hapd
);
3387 } else if (os_strncmp(buf
+ 9, "DEL_MAC ", 8) == 0) {
3388 hostapd_ctrl_iface_acl_del_mac(
3389 &hapd
->conf
->deny_mac
,
3390 &hapd
->conf
->num_deny_mac
, buf
+ 17);
3391 } else if (os_strcmp(buf
+ 9, "SHOW") == 0) {
3392 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3393 hapd
->conf
->deny_mac
,
3394 hapd
->conf
->num_deny_mac
, reply
, reply_size
);
3395 } else if (os_strcmp(buf
+ 9, "CLEAR") == 0) {
3396 hostapd_ctrl_iface_acl_clear_list(
3397 &hapd
->conf
->deny_mac
,
3398 &hapd
->conf
->num_deny_mac
);
3401 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
3402 res
= hostapd_dpp_qr_code(hapd
, buf
+ 12);
3406 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3407 if (os_snprintf_error(reply_size
, reply_len
))
3410 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
3411 res
= hostapd_dpp_nfc_uri(hapd
, buf
+ 12);
3415 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3416 if (os_snprintf_error(reply_size
, reply_len
))
3419 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
3420 res
= hostapd_dpp_nfc_handover_req(hapd
, buf
+ 20);
3424 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3425 if (os_snprintf_error(reply_size
, reply_len
))
3428 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
3429 res
= hostapd_dpp_nfc_handover_sel(hapd
, buf
+ 20);
3433 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3434 if (os_snprintf_error(reply_size
, reply_len
))
3437 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
3438 res
= dpp_bootstrap_gen(hapd
->iface
->interfaces
->dpp
, buf
+ 18);
3442 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3443 if (os_snprintf_error(reply_size
, reply_len
))
3446 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
3447 if (dpp_bootstrap_remove(hapd
->iface
->interfaces
->dpp
,
3450 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
3453 uri
= dpp_bootstrap_get_uri(hapd
->iface
->interfaces
->dpp
,
3458 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
3459 if (os_snprintf_error(reply_size
, reply_len
))
3462 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
3463 reply_len
= dpp_bootstrap_info(hapd
->iface
->interfaces
->dpp
,
3466 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
3467 if (hostapd_dpp_auth_init(hapd
, buf
+ 13) < 0)
3469 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
3470 if (hostapd_dpp_listen(hapd
, buf
+ 11) < 0)
3472 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
3473 hostapd_dpp_stop(hapd
);
3474 hostapd_dpp_listen_stop(hapd
);
3475 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
3476 res
= dpp_configurator_add(hapd
->iface
->interfaces
->dpp
,
3481 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3482 if (os_snprintf_error(reply_size
, reply_len
))
3485 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
3486 if (dpp_configurator_remove(hapd
->iface
->interfaces
->dpp
,
3489 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
3490 if (hostapd_dpp_configurator_sign(hapd
, buf
+ 21) < 0)
3492 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
3493 reply_len
= dpp_configurator_get_key_id(
3494 hapd
->iface
->interfaces
->dpp
,
3497 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
3498 res
= hostapd_dpp_pkex_add(hapd
, buf
+ 12);
3502 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3503 if (os_snprintf_error(reply_size
, reply_len
))
3506 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
3507 if (hostapd_dpp_pkex_remove(hapd
, buf
+ 16) < 0)
3509 #endif /* CONFIG_DPP */
3510 #ifdef RADIUS_SERVER
3511 } else if (os_strncmp(buf
, "DAC_REQUEST ", 12) == 0) {
3512 if (radius_server_dac_request(hapd
->radius_srv
, buf
+ 12) < 0)
3514 #endif /* RADIUS_SERVER */
3515 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
3516 reply_len
= hostapd_ctrl_iface_get_capability(
3517 hapd
, buf
+ 15, reply
, reply_size
);
3519 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
3523 if (reply_len
< 0) {
3524 os_memcpy(reply
, "FAIL\n", 5);
3532 static void hostapd_ctrl_iface_receive(int sock
, void *eloop_ctx
,
3535 struct hostapd_data
*hapd
= eloop_ctx
;
3538 struct sockaddr_storage from
;
3539 socklen_t fromlen
= sizeof(from
);
3540 char *reply
, *pos
= buf
;
3541 const int reply_size
= 4096;
3543 int level
= MSG_DEBUG
;
3544 #ifdef CONFIG_CTRL_IFACE_UDP
3545 unsigned char lcookie
[CTRL_IFACE_COOKIE_LEN
];
3546 #endif /* CONFIG_CTRL_IFACE_UDP */
3548 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
3549 (struct sockaddr
*) &from
, &fromlen
);
3551 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
3557 reply
= os_malloc(reply_size
);
3558 if (reply
== NULL
) {
3559 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
3561 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3567 #ifdef CONFIG_CTRL_IFACE_UDP
3568 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
3569 os_memcpy(reply
, "COOKIE=", 7);
3570 wpa_snprintf_hex(reply
+ 7, 2 * CTRL_IFACE_COOKIE_LEN
+ 1,
3571 hapd
->ctrl_iface_cookie
,
3572 CTRL_IFACE_COOKIE_LEN
);
3573 reply_len
= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
3577 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
3578 hexstr2bin(buf
+ 7, lcookie
, CTRL_IFACE_COOKIE_LEN
) < 0) {
3579 wpa_printf(MSG_DEBUG
,
3580 "CTRL: No cookie in the request - drop request");
3585 if (os_memcmp(hapd
->ctrl_iface_cookie
, lcookie
,
3586 CTRL_IFACE_COOKIE_LEN
) != 0) {
3587 wpa_printf(MSG_DEBUG
,
3588 "CTRL: Invalid cookie in the request - drop request");
3593 pos
= buf
+ 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
3596 #endif /* CONFIG_CTRL_IFACE_UDP */
3598 if (os_strcmp(pos
, "PING") == 0)
3599 level
= MSG_EXCESSIVE
;
3600 wpa_hexdump_ascii(level
, "RX ctrl_iface", pos
, res
);
3602 reply_len
= hostapd_ctrl_iface_receive_process(hapd
, pos
,
3606 #ifdef CONFIG_CTRL_IFACE_UDP
3608 #endif /* CONFIG_CTRL_IFACE_UDP */
3609 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
3611 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3618 #ifndef CONFIG_CTRL_IFACE_UDP
3619 static char * hostapd_ctrl_iface_path(struct hostapd_data
*hapd
)
3624 if (hapd
->conf
->ctrl_interface
== NULL
)
3627 len
= os_strlen(hapd
->conf
->ctrl_interface
) +
3628 os_strlen(hapd
->conf
->iface
) + 2;
3629 buf
= os_malloc(len
);
3633 os_snprintf(buf
, len
, "%s/%s",
3634 hapd
->conf
->ctrl_interface
, hapd
->conf
->iface
);
3635 buf
[len
- 1] = '\0';
3638 #endif /* CONFIG_CTRL_IFACE_UDP */
3641 static void hostapd_ctrl_iface_msg_cb(void *ctx
, int level
,
3642 enum wpa_msg_type type
,
3643 const char *txt
, size_t len
)
3645 struct hostapd_data
*hapd
= ctx
;
3648 hostapd_ctrl_iface_send(hapd
, level
, type
, txt
, len
);
3652 int hostapd_ctrl_iface_init(struct hostapd_data
*hapd
)
3654 #ifdef CONFIG_CTRL_IFACE_UDP
3655 int port
= HOSTAPD_CTRL_IFACE_PORT
;
3657 char port_str
[40], *tmp
;
3659 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3662 if (hapd
->ctrl_sock
> -1) {
3663 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3667 if (hapd
->conf
->ctrl_interface
== NULL
)
3670 pos
= os_strstr(hapd
->conf
->ctrl_interface
, "udp:");
3675 wpa_printf(MSG_ERROR
, "Invalid ctrl_iface UDP port");
3680 dl_list_init(&hapd
->ctrl_dst
);
3681 hapd
->ctrl_sock
= -1;
3682 os_get_random(hapd
->ctrl_iface_cookie
, CTRL_IFACE_COOKIE_LEN
);
3684 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3685 hints
.ai_flags
= AI_PASSIVE
;
3686 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3688 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3689 hints
.ai_family
= AF_INET6
;
3690 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3691 hints
.ai_family
= AF_INET
;
3692 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3693 hints
.ai_socktype
= SOCK_DGRAM
;
3696 os_snprintf(p
, sizeof(p
), "%d", port
);
3697 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3699 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3704 hapd
->ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3706 if (hapd
->ctrl_sock
< 0) {
3707 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3711 if (bind(hapd
->ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) < 0) {
3713 if ((HOSTAPD_CTRL_IFACE_PORT
- port
) <
3714 HOSTAPD_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3716 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3720 freeaddrinfo(saveres
);
3722 os_snprintf(port_str
, sizeof(port_str
), "udp:%d", port
);
3723 tmp
= os_strdup(port_str
);
3725 os_free(hapd
->conf
->ctrl_interface
);
3726 hapd
->conf
->ctrl_interface
= tmp
;
3728 wpa_printf(MSG_DEBUG
, "ctrl_iface_init UDP port: %d", port
);
3730 if (eloop_register_read_sock(hapd
->ctrl_sock
,
3731 hostapd_ctrl_iface_receive
, hapd
, NULL
) <
3733 hostapd_ctrl_iface_deinit(hapd
);
3737 hapd
->msg_ctx
= hapd
;
3738 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3743 if (hapd
->ctrl_sock
>= 0)
3744 close(hapd
->ctrl_sock
);
3746 #else /* CONFIG_CTRL_IFACE_UDP */
3747 struct sockaddr_un addr
;
3751 if (hapd
->ctrl_sock
> -1) {
3752 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3756 dl_list_init(&hapd
->ctrl_dst
);
3758 if (hapd
->conf
->ctrl_interface
== NULL
)
3761 if (mkdir(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3762 if (errno
== EEXIST
) {
3763 wpa_printf(MSG_DEBUG
, "Using existing control "
3764 "interface directory.");
3766 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3772 if (hapd
->conf
->ctrl_interface_gid_set
&&
3773 lchown(hapd
->conf
->ctrl_interface
, -1,
3774 hapd
->conf
->ctrl_interface_gid
) < 0) {
3775 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3780 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3781 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3782 lchown(hapd
->conf
->ctrl_interface
, -1,
3783 hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3784 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3791 * Android is using umask 0077 which would leave the control interface
3792 * directory without group access. This breaks things since Wi-Fi
3793 * framework assumes that this directory can be accessed by other
3794 * applications in the wifi group. Fix this by adding group access even
3795 * if umask value would prevent this.
3797 if (chmod(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3798 wpa_printf(MSG_ERROR
, "CTRL: Could not chmod directory: %s",
3800 /* Try to continue anyway */
3802 #endif /* ANDROID */
3804 if (os_strlen(hapd
->conf
->ctrl_interface
) + 1 +
3805 os_strlen(hapd
->conf
->iface
) >= sizeof(addr
.sun_path
))
3808 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
3810 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
3814 os_memset(&addr
, 0, sizeof(addr
));
3816 addr
.sun_len
= sizeof(addr
);
3817 #endif /* __FreeBSD__ */
3818 addr
.sun_family
= AF_UNIX
;
3819 fname
= hostapd_ctrl_iface_path(hapd
);
3822 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
3823 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3824 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
3826 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3827 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
3828 " allow connections - assuming it was left"
3829 "over from forced program termination");
3830 if (unlink(fname
) < 0) {
3831 wpa_printf(MSG_ERROR
,
3832 "Could not unlink existing ctrl_iface socket '%s': %s",
3833 fname
, strerror(errno
));
3836 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
3838 wpa_printf(MSG_ERROR
,
3839 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
3843 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
3844 "ctrl_iface socket '%s'", fname
);
3846 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
3847 "be in use - cannot override it");
3848 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
3849 "not used anymore", fname
);
3856 if (hapd
->conf
->ctrl_interface_gid_set
&&
3857 lchown(fname
, -1, hapd
->conf
->ctrl_interface_gid
) < 0) {
3858 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
3863 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3864 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3865 lchown(fname
, -1, hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3866 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
3871 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
3872 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
3878 hapd
->ctrl_sock
= s
;
3879 if (eloop_register_read_sock(s
, hostapd_ctrl_iface_receive
, hapd
,
3881 hostapd_ctrl_iface_deinit(hapd
);
3884 hapd
->msg_ctx
= hapd
;
3885 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3897 #endif /* CONFIG_CTRL_IFACE_UDP */
3901 void hostapd_ctrl_iface_deinit(struct hostapd_data
*hapd
)
3903 struct wpa_ctrl_dst
*dst
, *prev
;
3905 if (hapd
->ctrl_sock
> -1) {
3906 #ifndef CONFIG_CTRL_IFACE_UDP
3908 #endif /* !CONFIG_CTRL_IFACE_UDP */
3910 eloop_unregister_read_sock(hapd
->ctrl_sock
);
3911 close(hapd
->ctrl_sock
);
3912 hapd
->ctrl_sock
= -1;
3913 #ifndef CONFIG_CTRL_IFACE_UDP
3914 fname
= hostapd_ctrl_iface_path(hapd
);
3919 if (hapd
->conf
->ctrl_interface
&&
3920 rmdir(hapd
->conf
->ctrl_interface
) < 0) {
3921 if (errno
== ENOTEMPTY
) {
3922 wpa_printf(MSG_DEBUG
, "Control interface "
3923 "directory not empty - leaving it "
3926 wpa_printf(MSG_ERROR
,
3927 "rmdir[ctrl_interface=%s]: %s",
3928 hapd
->conf
->ctrl_interface
,
3932 #endif /* !CONFIG_CTRL_IFACE_UDP */
3935 dl_list_for_each_safe(dst
, prev
, &hapd
->ctrl_dst
, struct wpa_ctrl_dst
,
3939 #ifdef CONFIG_TESTING_OPTIONS
3940 l2_packet_deinit(hapd
->l2_test
);
3941 hapd
->l2_test
= NULL
;
3942 #endif /* CONFIG_TESTING_OPTIONS */
3946 static int hostapd_ctrl_iface_add(struct hapd_interfaces
*interfaces
,
3949 if (hostapd_add_iface(interfaces
, buf
) < 0) {
3950 wpa_printf(MSG_ERROR
, "Adding interface %s failed", buf
);
3957 static int hostapd_ctrl_iface_remove(struct hapd_interfaces
*interfaces
,
3960 if (hostapd_remove_iface(interfaces
, buf
) < 0) {
3961 wpa_printf(MSG_ERROR
, "Removing interface %s failed", buf
);
3968 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces
*interfaces
,
3969 struct sockaddr_storage
*from
,
3970 socklen_t fromlen
, char *input
)
3972 return ctrl_iface_attach(&interfaces
->global_ctrl_dst
, from
, fromlen
,
3977 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces
*interfaces
,
3978 struct sockaddr_storage
*from
,
3981 return ctrl_iface_detach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
3985 static void hostapd_ctrl_iface_flush(struct hapd_interfaces
*interfaces
)
3987 #ifdef CONFIG_WPS_TESTING
3988 wps_version_number
= 0x20;
3989 wps_testing_dummy_cred
= 0;
3990 wps_corrupt_pkhash
= 0;
3991 #endif /* CONFIG_WPS_TESTING */
3993 #ifdef CONFIG_TESTING_OPTIONS
3995 dpp_test
= DPP_TEST_DISABLED
;
3996 #endif /* CONFIG_DPP */
3997 #endif /* CONFIG_TESTING_OPTIONS */
4000 dpp_global_clear(interfaces
->dpp
);
4001 #endif /* CONFIG_DPP */
4008 hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces
*interfaces
,
4011 char ifname
[IFNAMSIZ
+ 1];
4012 struct fst_iface_cfg cfg
;
4013 struct hostapd_data
*hapd
;
4014 struct fst_wpa_obj iface_obj
;
4016 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
4017 hapd
= hostapd_get_iface(interfaces
, ifname
);
4019 if (hapd
->iface
->fst
) {
4020 wpa_printf(MSG_INFO
, "FST: Already attached");
4023 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
4024 hapd
->iface
->fst
= fst_attach(ifname
, hapd
->own_addr
,
4026 if (hapd
->iface
->fst
)
4036 hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces
*interfaces
,
4039 char ifname
[IFNAMSIZ
+ 1];
4040 struct hostapd_data
* hapd
;
4042 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
4043 hapd
= hostapd_get_iface(interfaces
, ifname
);
4045 if (!fst_iface_detach(ifname
)) {
4046 hapd
->iface
->fst
= NULL
;
4047 hapd
->iface
->fst_ies
= NULL
;
4056 #endif /* CONFIG_FST */
4059 static struct hostapd_data
*
4060 hostapd_interfaces_get_hapd(struct hapd_interfaces
*interfaces
,
4065 for (i
= 0; i
< interfaces
->count
; i
++) {
4066 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
4068 for (j
= 0; j
< iface
->num_bss
; j
++) {
4069 struct hostapd_data
*hapd
;
4071 hapd
= iface
->bss
[j
];
4072 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
4081 static int hostapd_ctrl_iface_dup_param(struct hostapd_data
*src_hapd
,
4082 struct hostapd_data
*dst_hapd
,
4088 value
= os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4090 wpa_printf(MSG_ERROR
,
4091 "DUP: cannot allocate buffer to stringify %s",
4096 if (os_strcmp(param
, "wpa") == 0) {
4097 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%d",
4098 src_hapd
->conf
->wpa
);
4099 } else if (os_strcmp(param
, "wpa_key_mgmt") == 0 &&
4100 src_hapd
->conf
->wpa_key_mgmt
) {
4101 res
= hostapd_ctrl_iface_get_key_mgmt(
4102 src_hapd
, value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4103 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, res
))
4104 goto error_stringify
;
4105 } else if (os_strcmp(param
, "wpa_pairwise") == 0 &&
4106 src_hapd
->conf
->wpa_pairwise
) {
4107 res
= wpa_write_ciphers(value
,
4108 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4109 src_hapd
->conf
->wpa_pairwise
, " ");
4111 goto error_stringify
;
4112 } else if (os_strcmp(param
, "rsn_pairwise") == 0 &&
4113 src_hapd
->conf
->rsn_pairwise
) {
4114 res
= wpa_write_ciphers(value
,
4115 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4116 src_hapd
->conf
->rsn_pairwise
, " ");
4118 goto error_stringify
;
4119 } else if (os_strcmp(param
, "wpa_passphrase") == 0 &&
4120 src_hapd
->conf
->ssid
.wpa_passphrase
) {
4121 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%s",
4122 src_hapd
->conf
->ssid
.wpa_passphrase
);
4123 } else if (os_strcmp(param
, "wpa_psk") == 0 &&
4124 src_hapd
->conf
->ssid
.wpa_psk_set
) {
4125 wpa_snprintf_hex(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4126 src_hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
4128 wpa_printf(MSG_WARNING
, "DUP: %s cannot be duplicated", param
);
4132 res
= hostapd_set_iface(dst_hapd
->iconf
, dst_hapd
->conf
, param
, value
);
4137 wpa_printf(MSG_ERROR
, "DUP: cannot stringify %s", param
);
4145 hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces
*interfaces
,
4147 char *reply
, int reply_size
)
4152 struct hostapd_iface
*iface
;
4156 show_ctrl
= !!os_strstr(input
, "ctrl");
4159 end
= reply
+ reply_size
;
4161 for (i
= 0; i
< interfaces
->count
; i
++) {
4162 iface
= interfaces
->iface
[i
];
4164 for (j
= 0; j
< iface
->num_bss
; j
++) {
4165 struct hostapd_bss_config
*conf
;
4167 conf
= iface
->conf
->bss
[j
];
4169 res
= os_snprintf(pos
, end
- pos
,
4170 "%s ctrl_iface=%s\n",
4172 conf
->ctrl_interface
?
4173 conf
->ctrl_interface
: "N/A");
4175 res
= os_snprintf(pos
, end
- pos
, "%s\n",
4177 if (os_snprintf_error(end
- pos
, res
)) {
4190 hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces
*interfaces
,
4193 char *p_start
= cmd
, *p_end
;
4194 struct hostapd_data
*src_hapd
, *dst_hapd
;
4196 /* cmd: "<src ifname> <dst ifname> <variable name> */
4198 p_end
= os_strchr(p_start
, ' ');
4200 wpa_printf(MSG_ERROR
, "DUP: no src ifname found in cmd: '%s'",
4206 src_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4208 wpa_printf(MSG_ERROR
, "DUP: no src ifname found: '%s'",
4213 p_start
= p_end
+ 1;
4214 p_end
= os_strchr(p_start
, ' ');
4216 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found in cmd: '%s'",
4222 dst_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4224 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found: '%s'",
4229 p_start
= p_end
+ 1;
4230 return hostapd_ctrl_iface_dup_param(src_hapd
, dst_hapd
, p_start
);
4234 static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces
*interfaces
,
4236 char *buf
, char *reply
,
4238 struct sockaddr_storage
*from
,
4241 struct hostapd_data
*hapd
;
4243 hapd
= hostapd_interfaces_get_hapd(interfaces
, ifname
);
4247 res
= os_snprintf(reply
, reply_size
, "FAIL-NO-IFNAME-MATCH\n");
4248 if (os_snprintf_error(reply_size
, res
))
4253 return hostapd_ctrl_iface_receive_process(hapd
, buf
, reply
,reply_size
,
4258 static void hostapd_global_ctrl_iface_receive(int sock
, void *eloop_ctx
,
4261 struct hapd_interfaces
*interfaces
= eloop_ctx
;
4262 char buffer
[256], *buf
= buffer
;
4264 struct sockaddr_storage from
;
4265 socklen_t fromlen
= sizeof(from
);
4268 const int reply_size
= 4096;
4269 #ifdef CONFIG_CTRL_IFACE_UDP
4270 unsigned char lcookie
[CTRL_IFACE_COOKIE_LEN
];
4271 #endif /* CONFIG_CTRL_IFACE_UDP */
4273 res
= recvfrom(sock
, buffer
, sizeof(buffer
) - 1, 0,
4274 (struct sockaddr
*) &from
, &fromlen
);
4276 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
4281 wpa_printf(MSG_DEBUG
, "Global ctrl_iface command: %s", buf
);
4283 reply
= os_malloc(reply_size
);
4284 if (reply
== NULL
) {
4285 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
4287 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4293 os_memcpy(reply
, "OK\n", 3);
4296 #ifdef CONFIG_CTRL_IFACE_UDP
4297 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
4298 os_memcpy(reply
, "COOKIE=", 7);
4299 wpa_snprintf_hex(reply
+ 7, 2 * CTRL_IFACE_COOKIE_LEN
+ 1,
4300 interfaces
->ctrl_iface_cookie
,
4301 CTRL_IFACE_COOKIE_LEN
);
4302 reply_len
= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
4306 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
4307 hexstr2bin(buf
+ 7, lcookie
, CTRL_IFACE_COOKIE_LEN
) < 0) {
4308 wpa_printf(MSG_DEBUG
,
4309 "CTRL: No cookie in the request - drop request");
4314 if (os_memcmp(interfaces
->ctrl_iface_cookie
, lcookie
,
4315 CTRL_IFACE_COOKIE_LEN
) != 0) {
4316 wpa_printf(MSG_DEBUG
,
4317 "CTRL: Invalid cookie in the request - drop request");
4322 buf
+= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
4325 #endif /* CONFIG_CTRL_IFACE_UDP */
4327 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
4328 char *pos
= os_strchr(buf
+ 7, ' ');
4332 reply_len
= hostapd_global_ctrl_iface_ifname(
4333 interfaces
, buf
+ 7, pos
, reply
, reply_size
,
4339 if (os_strcmp(buf
, "PING") == 0) {
4340 os_memcpy(reply
, "PONG\n", 5);
4342 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
4343 if (wpa_debug_reopen_file() < 0)
4345 } else if (os_strcmp(buf
, "FLUSH") == 0) {
4346 hostapd_ctrl_iface_flush(interfaces
);
4347 } else if (os_strncmp(buf
, "ADD ", 4) == 0) {
4348 if (hostapd_ctrl_iface_add(interfaces
, buf
+ 4) < 0)
4350 } else if (os_strncmp(buf
, "REMOVE ", 7) == 0) {
4351 if (hostapd_ctrl_iface_remove(interfaces
, buf
+ 7) < 0)
4353 } else if (os_strcmp(buf
, "ATTACH") == 0) {
4354 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4357 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
4358 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4361 } else if (os_strcmp(buf
, "DETACH") == 0) {
4362 if (hostapd_global_ctrl_iface_detach(interfaces
, &from
,
4365 #ifdef CONFIG_MODULE_TESTS
4366 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
4367 if (hapd_module_tests() < 0)
4369 #endif /* CONFIG_MODULE_TESTS */
4371 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
4372 if (!hostapd_global_ctrl_iface_fst_attach(interfaces
, buf
+ 11))
4373 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4376 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
4377 if (!hostapd_global_ctrl_iface_fst_detach(interfaces
, buf
+ 11))
4378 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4381 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
4382 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
4383 #endif /* CONFIG_FST */
4384 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
4385 if (!hostapd_global_ctrl_iface_dup_network(interfaces
,
4387 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4390 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
4391 reply_len
= hostapd_global_ctrl_iface_interfaces(
4392 interfaces
, buf
+ 10, reply
, sizeof(buffer
));
4393 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4396 wpa_printf(MSG_DEBUG
, "Unrecognized global ctrl_iface command "
4402 if (reply_len
< 0) {
4403 os_memcpy(reply
, "FAIL\n", 5);
4407 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
4409 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4416 #ifndef CONFIG_CTRL_IFACE_UDP
4417 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces
*interface
)
4422 if (interface
->global_iface_path
== NULL
)
4425 len
= os_strlen(interface
->global_iface_path
) +
4426 os_strlen(interface
->global_iface_name
) + 2;
4427 buf
= os_malloc(len
);
4431 os_snprintf(buf
, len
, "%s/%s", interface
->global_iface_path
,
4432 interface
->global_iface_name
);
4433 buf
[len
- 1] = '\0';
4436 #endif /* CONFIG_CTRL_IFACE_UDP */
4439 int hostapd_global_ctrl_iface_init(struct hapd_interfaces
*interface
)
4441 #ifdef CONFIG_CTRL_IFACE_UDP
4442 int port
= HOSTAPD_GLOBAL_CTRL_IFACE_PORT
;
4445 struct addrinfo hints
= { 0 }, *res
, *saveres
;
4448 if (interface
->global_ctrl_sock
> -1) {
4449 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
4453 if (interface
->global_iface_path
== NULL
)
4456 pos
= os_strstr(interface
->global_iface_path
, "udp:");
4461 wpa_printf(MSG_ERROR
, "Invalid global ctrl UDP port");
4466 os_get_random(interface
->ctrl_iface_cookie
, CTRL_IFACE_COOKIE_LEN
);
4468 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4469 hints
.ai_flags
= AI_PASSIVE
;
4470 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4472 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
4473 hints
.ai_family
= AF_INET6
;
4474 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4475 hints
.ai_family
= AF_INET
;
4476 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4477 hints
.ai_socktype
= SOCK_DGRAM
;
4480 os_snprintf(p
, sizeof(p
), "%d", port
);
4481 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
4483 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
4488 interface
->global_ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
4490 if (interface
->global_ctrl_sock
< 0) {
4491 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
4495 if (bind(interface
->global_ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) <
4498 if ((port
- HOSTAPD_GLOBAL_CTRL_IFACE_PORT
) <
4499 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT
&& !pos
)
4501 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
4505 freeaddrinfo(saveres
);
4507 wpa_printf(MSG_DEBUG
, "global ctrl_iface_init UDP port: %d", port
);
4509 if (eloop_register_read_sock(interface
->global_ctrl_sock
,
4510 hostapd_global_ctrl_iface_receive
,
4511 interface
, NULL
) < 0) {
4512 hostapd_global_ctrl_iface_deinit(interface
);
4516 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4521 if (interface
->global_ctrl_sock
>= 0)
4522 close(interface
->global_ctrl_sock
);
4524 #else /* CONFIG_CTRL_IFACE_UDP */
4525 struct sockaddr_un addr
;
4529 if (interface
->global_iface_path
== NULL
) {
4530 wpa_printf(MSG_DEBUG
, "ctrl_iface not configured!");
4534 if (mkdir(interface
->global_iface_path
, S_IRWXU
| S_IRWXG
) < 0) {
4535 if (errno
== EEXIST
) {
4536 wpa_printf(MSG_DEBUG
, "Using existing control "
4537 "interface directory.");
4539 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
4543 } else if (interface
->ctrl_iface_group
&&
4544 lchown(interface
->global_iface_path
, -1,
4545 interface
->ctrl_iface_group
) < 0) {
4546 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4551 if (os_strlen(interface
->global_iface_path
) + 1 +
4552 os_strlen(interface
->global_iface_name
) >= sizeof(addr
.sun_path
))
4555 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
4557 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
4561 os_memset(&addr
, 0, sizeof(addr
));
4563 addr
.sun_len
= sizeof(addr
);
4564 #endif /* __FreeBSD__ */
4565 addr
.sun_family
= AF_UNIX
;
4566 fname
= hostapd_global_ctrl_iface_path(interface
);
4569 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
4570 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4571 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
4573 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4574 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
4575 " allow connections - assuming it was left"
4576 "over from forced program termination");
4577 if (unlink(fname
) < 0) {
4578 wpa_printf(MSG_ERROR
,
4579 "Could not unlink existing ctrl_iface socket '%s': %s",
4580 fname
, strerror(errno
));
4583 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
4585 wpa_printf(MSG_ERROR
, "bind(PF_UNIX): %s",
4589 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
4590 "ctrl_iface socket '%s'", fname
);
4592 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
4593 "be in use - cannot override it");
4594 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
4595 "not used anymore", fname
);
4602 if (interface
->ctrl_iface_group
&&
4603 lchown(fname
, -1, interface
->ctrl_iface_group
) < 0) {
4604 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4609 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
4610 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
4616 interface
->global_ctrl_sock
= s
;
4617 eloop_register_read_sock(s
, hostapd_global_ctrl_iface_receive
,
4620 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4632 #endif /* CONFIG_CTRL_IFACE_UDP */
4636 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces
*interfaces
)
4638 #ifndef CONFIG_CTRL_IFACE_UDP
4640 #endif /* CONFIG_CTRL_IFACE_UDP */
4641 struct wpa_ctrl_dst
*dst
, *prev
;
4643 if (interfaces
->global_ctrl_sock
> -1) {
4644 eloop_unregister_read_sock(interfaces
->global_ctrl_sock
);
4645 close(interfaces
->global_ctrl_sock
);
4646 interfaces
->global_ctrl_sock
= -1;
4647 #ifndef CONFIG_CTRL_IFACE_UDP
4648 fname
= hostapd_global_ctrl_iface_path(interfaces
);
4654 if (interfaces
->global_iface_path
&&
4655 rmdir(interfaces
->global_iface_path
) < 0) {
4656 if (errno
== ENOTEMPTY
) {
4657 wpa_printf(MSG_DEBUG
, "Control interface "
4658 "directory not empty - leaving it "
4661 wpa_printf(MSG_ERROR
,
4662 "rmdir[ctrl_interface=%s]: %s",
4663 interfaces
->global_iface_path
,
4667 #endif /* CONFIG_CTRL_IFACE_UDP */
4670 os_free(interfaces
->global_iface_path
);
4671 interfaces
->global_iface_path
= NULL
;
4673 dl_list_for_each_safe(dst
, prev
, &interfaces
->global_ctrl_dst
,
4674 struct wpa_ctrl_dst
, list
)
4679 static int hostapd_ctrl_check_event_enabled(struct wpa_ctrl_dst
*dst
,
4682 /* Enable Probe Request events based on explicit request.
4683 * Other events are enabled by default.
4685 if (str_starts(buf
, RX_PROBE_REQUEST
))
4686 return !!(dst
->events
& WPA_EVENT_RX_PROBE_REQUEST
);
4691 static void hostapd_ctrl_iface_send_internal(int sock
, struct dl_list
*ctrl_dst
,
4692 const char *ifname
, int level
,
4693 const char *buf
, size_t len
)
4695 struct wpa_ctrl_dst
*dst
, *next
;
4701 if (sock
< 0 || dl_list_empty(ctrl_dst
))
4704 res
= os_snprintf(levelstr
, sizeof(levelstr
), "<%d>", level
);
4705 if (os_snprintf_error(sizeof(levelstr
), res
))
4709 io
[idx
].iov_base
= "IFNAME=";
4710 io
[idx
].iov_len
= 7;
4712 io
[idx
].iov_base
= (char *) ifname
;
4713 io
[idx
].iov_len
= os_strlen(ifname
);
4715 io
[idx
].iov_base
= " ";
4716 io
[idx
].iov_len
= 1;
4719 io
[idx
].iov_base
= levelstr
;
4720 io
[idx
].iov_len
= os_strlen(levelstr
);
4722 io
[idx
].iov_base
= (char *) buf
;
4723 io
[idx
].iov_len
= len
;
4725 os_memset(&msg
, 0, sizeof(msg
));
4727 msg
.msg_iovlen
= idx
;
4730 dl_list_for_each_safe(dst
, next
, ctrl_dst
, struct wpa_ctrl_dst
, list
) {
4731 if ((level
>= dst
->debug_level
) &&
4732 hostapd_ctrl_check_event_enabled(dst
, buf
)) {
4733 sockaddr_print(MSG_DEBUG
, "CTRL_IFACE monitor send",
4734 &dst
->addr
, dst
->addrlen
);
4735 msg
.msg_name
= &dst
->addr
;
4736 msg
.msg_namelen
= dst
->addrlen
;
4737 if (sendmsg(sock
, &msg
, 0) < 0) {
4739 wpa_printf(MSG_INFO
, "CTRL_IFACE monitor[%d]: "
4741 idx
, errno
, strerror(errno
));
4743 if (dst
->errors
> 10 || _errno
== ENOENT
) {
4744 ctrl_iface_detach(ctrl_dst
,
4756 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
4757 enum wpa_msg_type type
,
4758 const char *buf
, size_t len
)
4760 if (type
!= WPA_MSG_NO_GLOBAL
) {
4761 hostapd_ctrl_iface_send_internal(
4762 hapd
->iface
->interfaces
->global_ctrl_sock
,
4763 &hapd
->iface
->interfaces
->global_ctrl_dst
,
4764 type
!= WPA_MSG_PER_INTERFACE
?
4765 NULL
: hapd
->conf
->iface
,
4769 if (type
!= WPA_MSG_ONLY_GLOBAL
) {
4770 hostapd_ctrl_iface_send_internal(
4771 hapd
->ctrl_sock
, &hapd
->ctrl_dst
,
4772 NULL
, level
, buf
, len
);
4776 #endif /* CONFIG_NATIVE_WINDOWS */