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"
63 #include "wps/wps_defs.h"
65 #include "fst/fst_ctrl_iface.h"
66 #include "config_file.h"
67 #include "ctrl_iface.h"
70 #define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
72 #ifdef CONFIG_CTRL_IFACE_UDP
73 #define HOSTAPD_CTRL_IFACE_PORT 8877
74 #define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
75 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
76 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
77 #endif /* CONFIG_CTRL_IFACE_UDP */
79 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
80 enum wpa_msg_type type
,
81 const char *buf
, size_t len
);
84 static int hostapd_ctrl_iface_attach(struct hostapd_data
*hapd
,
85 struct sockaddr_storage
*from
,
86 socklen_t fromlen
, const char *input
)
88 return ctrl_iface_attach(&hapd
->ctrl_dst
, from
, fromlen
, input
);
92 static int hostapd_ctrl_iface_detach(struct hostapd_data
*hapd
,
93 struct sockaddr_storage
*from
,
96 return ctrl_iface_detach(&hapd
->ctrl_dst
, from
, fromlen
);
100 static int hostapd_ctrl_iface_level(struct hostapd_data
*hapd
,
101 struct sockaddr_storage
*from
,
105 return ctrl_iface_level(&hapd
->ctrl_dst
, from
, fromlen
, level
);
109 static int hostapd_ctrl_iface_new_sta(struct hostapd_data
*hapd
,
113 struct sta_info
*sta
;
115 wpa_printf(MSG_DEBUG
, "CTRL_IFACE NEW_STA %s", txtaddr
);
117 if (hwaddr_aton(txtaddr
, addr
))
120 sta
= ap_get_sta(hapd
, addr
);
124 wpa_printf(MSG_DEBUG
, "Add new STA " MACSTR
" based on ctrl_iface "
125 "notification", MAC2STR(addr
));
126 sta
= ap_sta_add(hapd
, addr
);
130 hostapd_new_assoc_sta(hapd
, sta
, 0);
136 static int hostapd_ctrl_iface_sa_query(struct hostapd_data
*hapd
,
140 u8 trans_id
[WLAN_SA_QUERY_TR_ID_LEN
];
142 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SA_QUERY %s", txtaddr
);
144 if (hwaddr_aton(txtaddr
, addr
) ||
145 os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0)
148 ieee802_11_send_sa_query_req(hapd
, addr
, trans_id
);
152 #endif /* NEED_AP_MLME */
156 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data
*hapd
, char *txt
)
158 char *pin
= os_strchr(txt
, ' ');
161 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
168 timeout_txt
= os_strchr(pin
, ' ');
170 *timeout_txt
++ = '\0';
171 timeout
= atoi(timeout_txt
);
172 pos
= os_strchr(timeout_txt
, ' ');
175 if (hwaddr_aton(pos
, addr_buf
) == 0)
181 return hostapd_wps_add_pin(hapd
, addr
, txt
, pin
, timeout
);
185 static int hostapd_ctrl_iface_wps_check_pin(
186 struct hostapd_data
*hapd
, char *cmd
, char *buf
, size_t buflen
)
193 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
194 (u8
*) cmd
, os_strlen(cmd
));
195 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
196 if (*pos
< '0' || *pos
> '9')
200 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
204 if (len
!= 4 && len
!= 8) {
205 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
211 unsigned int pin_val
;
213 if (!wps_pin_valid(pin_val
)) {
214 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
215 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
216 if (os_snprintf_error(buflen
, ret
))
222 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
223 if (os_snprintf_error(buflen
, ret
))
230 #ifdef CONFIG_WPS_NFC
231 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data
*hapd
,
238 len
= os_strlen(pos
);
243 buf
= wpabuf_alloc(len
);
246 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
251 ret
= hostapd_wps_nfc_tag_read(hapd
, buf
);
258 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data
*hapd
,
259 char *cmd
, char *reply
,
266 if (os_strcmp(cmd
, "WPS") == 0)
268 else if (os_strcmp(cmd
, "NDEF") == 0)
273 buf
= hostapd_wps_nfc_config_token(hapd
, ndef
);
277 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
288 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data
*hapd
,
289 char *reply
, size_t max_len
,
295 buf
= hostapd_wps_nfc_token_gen(hapd
, ndef
);
299 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
310 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data
*hapd
,
311 char *cmd
, char *reply
,
314 if (os_strcmp(cmd
, "WPS") == 0)
315 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
318 if (os_strcmp(cmd
, "NDEF") == 0)
319 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
322 if (os_strcmp(cmd
, "enable") == 0)
323 return hostapd_wps_nfc_token_enable(hapd
);
325 if (os_strcmp(cmd
, "disable") == 0) {
326 hostapd_wps_nfc_token_disable(hapd
);
334 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data
*hapd
,
335 char *cmd
, char *reply
,
343 pos
= os_strchr(cmd
, ' ');
348 if (os_strcmp(cmd
, "WPS") == 0)
350 else if (os_strcmp(cmd
, "NDEF") == 0)
355 if (os_strcmp(pos
, "WPS-CR") == 0)
356 buf
= hostapd_wps_nfc_hs_cr(hapd
, ndef
);
362 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
373 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data
*hapd
,
377 struct wpabuf
*req
, *sel
;
379 char *pos
, *role
, *type
, *pos2
;
382 pos
= os_strchr(role
, ' ');
388 pos
= os_strchr(type
, ' ');
393 pos2
= os_strchr(pos
, ' ');
398 len
= os_strlen(pos
);
403 req
= wpabuf_alloc(len
);
406 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
411 len
= os_strlen(pos2
);
418 sel
= wpabuf_alloc(len
);
423 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
429 if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0) {
430 ret
= hostapd_wps_nfc_report_handover(hapd
, req
, sel
);
432 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
433 "reported: role=%s type=%s", role
, type
);
442 #endif /* CONFIG_WPS_NFC */
445 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data
*hapd
, char *txt
,
446 char *buf
, size_t buflen
)
452 pos
= os_strchr(txt
, ' ');
456 if (os_strcmp(txt
, "disable") == 0) {
457 hostapd_wps_ap_pin_disable(hapd
);
458 return os_snprintf(buf
, buflen
, "OK\n");
461 if (os_strcmp(txt
, "random") == 0) {
464 pin_txt
= hostapd_wps_ap_pin_random(hapd
, timeout
);
467 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
470 if (os_strcmp(txt
, "get") == 0) {
471 pin_txt
= hostapd_wps_ap_pin_get(hapd
);
474 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
477 if (os_strcmp(txt
, "set") == 0) {
482 pos
= os_strchr(pos
, ' ');
487 if (os_strlen(pin
) > buflen
)
489 if (hostapd_wps_ap_pin_set(hapd
, pin
, timeout
) < 0)
491 return os_snprintf(buf
, buflen
, "%s", pin
);
498 static int hostapd_ctrl_iface_wps_config(struct hostapd_data
*hapd
, char *txt
)
501 char *ssid
, *auth
, *encr
= NULL
, *key
= NULL
;
504 pos
= os_strchr(txt
, ' ');
510 pos
= os_strchr(pos
, ' ');
514 pos
= os_strchr(pos
, ' ');
521 return hostapd_wps_config_ap(hapd
, ssid
, auth
, encr
, key
);
525 static const char * pbc_status_str(enum pbc_status status
)
528 case WPS_PBC_STATUS_DISABLE
:
530 case WPS_PBC_STATUS_ACTIVE
:
532 case WPS_PBC_STATUS_TIMEOUT
:
534 case WPS_PBC_STATUS_OVERLAP
:
542 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data
*hapd
,
543 char *buf
, size_t buflen
)
551 ret
= os_snprintf(pos
, end
- pos
, "PBC Status: %s\n",
552 pbc_status_str(hapd
->wps_stats
.pbc_status
));
554 if (os_snprintf_error(end
- pos
, ret
))
558 ret
= os_snprintf(pos
, end
- pos
, "Last WPS result: %s\n",
559 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
561 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
562 "Failed" : "None")));
564 if (os_snprintf_error(end
- pos
, ret
))
568 /* If status == Failure - Add possible Reasons */
569 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
570 hapd
->wps_stats
.failure_reason
> 0) {
571 ret
= os_snprintf(pos
, end
- pos
,
572 "Failure Reason: %s\n",
573 wps_ei_str(hapd
->wps_stats
.failure_reason
));
575 if (os_snprintf_error(end
- pos
, ret
))
580 if (hapd
->wps_stats
.status
) {
581 ret
= os_snprintf(pos
, end
- pos
, "Peer Address: " MACSTR
"\n",
582 MAC2STR(hapd
->wps_stats
.peer_addr
));
584 if (os_snprintf_error(end
- pos
, ret
))
592 #endif /* CONFIG_WPS */
596 static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data
*hapd
,
602 if (hwaddr_aton(cmd
, addr
))
615 return hs20_send_wnm_notification(hapd
, addr
, 1, url
);
619 static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data
*hapd
,
623 int code
, reauth_delay
, ret
;
628 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
629 if (hwaddr_aton(cmd
, addr
))
632 pos
= os_strchr(cmd
, ' ');
638 pos
= os_strchr(pos
, ' ');
642 reauth_delay
= atoi(pos
);
645 pos
= os_strchr(pos
, ' ');
648 url_len
= os_strlen(pos
);
651 req
= wpabuf_alloc(4 + url_len
);
654 wpabuf_put_u8(req
, code
);
655 wpabuf_put_le16(req
, reauth_delay
);
656 wpabuf_put_u8(req
, url_len
);
658 wpabuf_put_data(req
, pos
, url_len
);
660 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to " MACSTR
661 " to indicate imminent deauthentication (code=%d "
662 "reauth_delay=%d)", MAC2STR(addr
), code
, reauth_delay
);
663 ret
= hs20_send_wnm_notification_deauth_req(hapd
, addr
, req
);
668 #endif /* CONFIG_HS20 */
671 #ifdef CONFIG_INTERWORKING
673 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data
*hapd
,
676 u8 qos_map_set
[16 + 2 * 21], count
= 0;
677 const char *pos
= cmd
;
681 if (count
== sizeof(qos_map_set
)) {
682 wpa_printf(MSG_ERROR
, "Too many qos_map_set parameters");
687 if (val
< 0 || val
> 255) {
688 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
692 qos_map_set
[count
++] = val
;
693 pos
= os_strchr(pos
, ',');
699 if (count
< 16 || count
& 1) {
700 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
704 ret
= hostapd_drv_set_qos_map(hapd
, qos_map_set
, count
);
706 wpa_printf(MSG_INFO
, "Failed to set QoS Map Set");
710 os_memcpy(hapd
->conf
->qos_map_set
, qos_map_set
, count
);
711 hapd
->conf
->qos_map_set_len
= count
;
717 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data
*hapd
,
721 struct sta_info
*sta
;
723 u8
*qos_map_set
= hapd
->conf
->qos_map_set
;
724 u8 qos_map_set_len
= hapd
->conf
->qos_map_set_len
;
727 if (!qos_map_set_len
) {
728 wpa_printf(MSG_INFO
, "QoS Map Set is not set");
732 if (hwaddr_aton(cmd
, addr
))
735 sta
= ap_get_sta(hapd
, addr
);
737 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" not found "
738 "for QoS Map Configuration message",
743 if (!sta
->qos_map_enabled
) {
744 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" did not indicate "
745 "support for QoS Map", MAC2STR(addr
));
749 buf
= wpabuf_alloc(2 + 2 + qos_map_set_len
);
753 wpabuf_put_u8(buf
, WLAN_ACTION_QOS
);
754 wpabuf_put_u8(buf
, QOS_QOS_MAP_CONFIG
);
756 /* QoS Map Set Element */
757 wpabuf_put_u8(buf
, WLAN_EID_QOS_MAP_SET
);
758 wpabuf_put_u8(buf
, qos_map_set_len
);
759 wpabuf_put_data(buf
, qos_map_set
, qos_map_set_len
);
761 ret
= hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, addr
,
762 wpabuf_head(buf
), wpabuf_len(buf
));
768 #endif /* CONFIG_INTERWORKING */
773 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data
*hapd
,
778 struct sta_info
*sta
;
780 if (hwaddr_aton(cmd
, addr
))
784 disassoc_timer
= atoi(cmd
+ 17);
786 sta
= ap_get_sta(hapd
, addr
);
788 wpa_printf(MSG_DEBUG
, "Station " MACSTR
789 " not found for disassociation imminent message",
794 return wnm_send_disassoc_imminent(hapd
, sta
, disassoc_timer
);
798 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data
*hapd
,
802 const char *url
, *timerstr
;
804 struct sta_info
*sta
;
806 if (hwaddr_aton(cmd
, addr
))
809 sta
= ap_get_sta(hapd
, addr
);
811 wpa_printf(MSG_DEBUG
, "Station " MACSTR
812 " not found for ESS disassociation imminent message",
818 if (*timerstr
!= ' ')
821 disassoc_timer
= atoi(timerstr
);
822 if (disassoc_timer
< 0 || disassoc_timer
> 65535)
825 url
= os_strchr(timerstr
, ' ');
830 return wnm_send_ess_disassoc_imminent(hapd
, sta
, url
, disassoc_timer
);
834 static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data
*hapd
,
838 const char *pos
, *end
;
839 int disassoc_timer
= 0;
840 struct sta_info
*sta
;
841 u8 req_mode
= 0, valid_int
= 0x01;
850 if (hwaddr_aton(cmd
, addr
)) {
851 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
855 sta
= ap_get_sta(hapd
, addr
);
857 wpa_printf(MSG_DEBUG
, "Station " MACSTR
858 " not found for BSS TM Request message",
863 pos
= os_strstr(cmd
, " disassoc_timer=");
866 disassoc_timer
= atoi(pos
);
867 if (disassoc_timer
< 0 || disassoc_timer
> 65535) {
868 wpa_printf(MSG_DEBUG
, "Invalid disassoc_timer");
873 pos
= os_strstr(cmd
, " valid_int=");
876 valid_int
= atoi(pos
);
879 pos
= os_strstr(cmd
, " bss_term=");
882 req_mode
|= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED
;
883 /* TODO: TSF configurable/learnable */
884 bss_term_dur
[0] = 4; /* Subelement ID */
885 bss_term_dur
[1] = 10; /* Length */
886 os_memset(&bss_term_dur
[2], 0, 8);
887 end
= os_strchr(pos
, ',');
889 wpa_printf(MSG_DEBUG
, "Invalid bss_term data");
893 WPA_PUT_LE16(&bss_term_dur
[10], atoi(end
));
896 nei_len
= ieee802_11_parse_candidate_list(cmd
, nei_rep
,
901 pos
= os_strstr(cmd
, " url=");
905 end
= os_strchr(pos
, ' ');
909 len
= os_strlen(pos
);
910 url
= os_malloc(len
+ 1);
913 os_memcpy(url
, pos
, len
);
915 req_mode
|= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT
;
918 if (os_strstr(cmd
, " pref=1"))
919 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
920 if (os_strstr(cmd
, " abridged=1"))
921 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
922 if (os_strstr(cmd
, " disassoc_imminent=1"))
923 req_mode
|= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
926 pos
= os_strstr(cmd
, "mbo=");
928 unsigned int mbo_reason
, cell_pref
, reassoc_delay
;
931 ret
= sscanf(pos
, "mbo=%u:%u:%u", &mbo_reason
,
932 &reassoc_delay
, &cell_pref
);
934 wpa_printf(MSG_DEBUG
,
935 "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
940 if (mbo_reason
> MBO_TRANSITION_REASON_PREMIUM_AP
) {
941 wpa_printf(MSG_DEBUG
,
942 "Invalid MBO transition reason code %u",
948 /* Valid values for Cellular preference are: 0, 1, 255 */
949 if (cell_pref
!= 0 && cell_pref
!= 1 && cell_pref
!= 255) {
950 wpa_printf(MSG_DEBUG
,
951 "Invalid MBO cellular capability %u",
957 if (reassoc_delay
> 65535 ||
959 !(req_mode
& WNM_BSS_TM_REQ_DISASSOC_IMMINENT
))) {
960 wpa_printf(MSG_DEBUG
,
961 "MBO: Assoc retry delay is only valid in disassoc imminent mode");
966 *mbo_pos
++ = MBO_ATTR_ID_TRANSITION_REASON
;
968 *mbo_pos
++ = mbo_reason
;
969 *mbo_pos
++ = MBO_ATTR_ID_CELL_DATA_PREF
;
971 *mbo_pos
++ = cell_pref
;
974 *mbo_pos
++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY
;
976 WPA_PUT_LE16(mbo_pos
, reassoc_delay
);
980 mbo_len
= mbo_pos
- mbo
;
982 #endif /* CONFIG_MBO */
984 ret
= wnm_send_bss_tm_req(hapd
, sta
, req_mode
, disassoc_timer
,
985 valid_int
, bss_term_dur
, url
,
986 nei_len
? nei_rep
: NULL
, nei_len
,
987 mbo_len
? mbo
: NULL
, mbo_len
);
990 #endif /* CONFIG_MBO */
996 static int hostapd_ctrl_iface_coloc_intf_req(struct hostapd_data
*hapd
,
1000 struct sta_info
*sta
;
1002 unsigned int auto_report
, timeout
;
1004 if (hwaddr_aton(cmd
, addr
)) {
1005 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
1009 sta
= ap_get_sta(hapd
, addr
);
1011 wpa_printf(MSG_DEBUG
, "Station " MACSTR
1012 " not found for Collocated Interference Request",
1021 auto_report
= atoi(pos
);
1022 pos
= os_strchr(pos
, ' ');
1026 timeout
= atoi(pos
);
1028 return wnm_send_coloc_intf_req(hapd
, sta
, auto_report
, timeout
);
1031 #endif /* CONFIG_WNM_AP */
1034 static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data
*hapd
,
1035 char *buf
, size_t buflen
)
1043 WPA_ASSERT(hapd
->conf
->wpa_key_mgmt
);
1045 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) {
1046 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK ");
1047 if (os_snprintf_error(end
- pos
, ret
))
1051 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1052 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP ");
1053 if (os_snprintf_error(end
- pos
, ret
))
1057 #ifdef CONFIG_IEEE80211R_AP
1058 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1059 ret
= os_snprintf(pos
, end
- pos
, "FT-PSK ");
1060 if (os_snprintf_error(end
- pos
, ret
))
1064 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1065 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP ");
1066 if (os_snprintf_error(end
- pos
, ret
))
1070 #ifdef CONFIG_SHA384
1071 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
1072 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP-SHA384 ");
1073 if (os_snprintf_error(end
- pos
, ret
))
1077 #endif /* CONFIG_SHA384 */
1079 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
1080 ret
= os_snprintf(pos
, end
- pos
, "FT-SAE ");
1081 if (os_snprintf_error(end
- pos
, ret
))
1085 #endif /* CONFIG_SAE */
1087 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1088 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA256 ");
1089 if (os_snprintf_error(end
- pos
, ret
))
1093 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1094 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA384 ");
1095 if (os_snprintf_error(end
- pos
, ret
))
1099 #endif /* CONFIG_FILS */
1100 #endif /* CONFIG_IEEE80211R_AP */
1101 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1102 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK-SHA256 ");
1103 if (os_snprintf_error(end
- pos
, ret
))
1107 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1108 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SHA256 ");
1109 if (os_snprintf_error(end
- pos
, ret
))
1114 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_SAE
) {
1115 ret
= os_snprintf(pos
, end
- pos
, "SAE ");
1116 if (os_snprintf_error(end
- pos
, ret
))
1120 #endif /* CONFIG_SAE */
1121 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1122 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SUITE-B ");
1123 if (os_snprintf_error(end
- pos
, ret
))
1127 if (hapd
->conf
->wpa_key_mgmt
&
1128 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
1129 ret
= os_snprintf(pos
, end
- pos
,
1130 "WPA-EAP-SUITE-B-192 ");
1131 if (os_snprintf_error(end
- pos
, ret
))
1136 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1137 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA256 ");
1138 if (os_snprintf_error(end
- pos
, ret
))
1142 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1143 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA384 ");
1144 if (os_snprintf_error(end
- pos
, ret
))
1148 #endif /* CONFIG_FILS */
1151 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) {
1152 ret
= os_snprintf(pos
, end
- pos
, "OWE ");
1153 if (os_snprintf_error(end
- pos
, ret
))
1157 #endif /* CONFIG_OWE */
1160 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) {
1161 ret
= os_snprintf(pos
, end
- pos
, "DPP ");
1162 if (os_snprintf_error(end
- pos
, ret
))
1166 #endif /* CONFIG_DPP */
1168 if (pos
> buf
&& *(pos
- 1) == ' ') {
1177 static int hostapd_ctrl_iface_get_config(struct hostapd_data
*hapd
,
1178 char *buf
, size_t buflen
)
1186 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n"
1188 MAC2STR(hapd
->own_addr
),
1189 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
1190 hapd
->conf
->ssid
.ssid_len
));
1191 if (os_snprintf_error(end
- pos
, ret
))
1196 ret
= os_snprintf(pos
, end
- pos
, "wps_state=%s\n",
1197 hapd
->conf
->wps_state
== 0 ? "disabled" :
1198 (hapd
->conf
->wps_state
== 1 ? "not configured" :
1200 if (os_snprintf_error(end
- pos
, ret
))
1204 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1205 hapd
->conf
->ssid
.wpa_passphrase
) {
1206 ret
= os_snprintf(pos
, end
- pos
, "passphrase=%s\n",
1207 hapd
->conf
->ssid
.wpa_passphrase
);
1208 if (os_snprintf_error(end
- pos
, ret
))
1213 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1214 hapd
->conf
->ssid
.wpa_psk
&&
1215 hapd
->conf
->ssid
.wpa_psk
->group
) {
1216 char hex
[PMK_LEN
* 2 + 1];
1217 wpa_snprintf_hex(hex
, sizeof(hex
),
1218 hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
1219 ret
= os_snprintf(pos
, end
- pos
, "psk=%s\n", hex
);
1220 if (os_snprintf_error(end
- pos
, ret
))
1224 #endif /* CONFIG_WPS */
1226 if (hapd
->conf
->wpa
) {
1227 ret
= os_snprintf(pos
, end
- pos
, "wpa=%d\n", hapd
->conf
->wpa
);
1228 if (os_snprintf_error(end
- pos
, ret
))
1233 if (hapd
->conf
->wpa
&& hapd
->conf
->wpa_key_mgmt
) {
1234 ret
= os_snprintf(pos
, end
- pos
, "key_mgmt=");
1235 if (os_snprintf_error(end
- pos
, ret
))
1239 pos
+= hostapd_ctrl_iface_get_key_mgmt(hapd
, pos
, end
- pos
);
1241 ret
= os_snprintf(pos
, end
- pos
, "\n");
1242 if (os_snprintf_error(end
- pos
, ret
))
1247 if (hapd
->conf
->wpa
) {
1248 ret
= os_snprintf(pos
, end
- pos
, "group_cipher=%s\n",
1249 wpa_cipher_txt(hapd
->conf
->wpa_group
));
1250 if (os_snprintf_error(end
- pos
, ret
))
1255 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && hapd
->conf
->rsn_pairwise
) {
1256 ret
= os_snprintf(pos
, end
- pos
, "rsn_pairwise_cipher=");
1257 if (os_snprintf_error(end
- pos
, ret
))
1261 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->rsn_pairwise
,
1267 ret
= os_snprintf(pos
, end
- pos
, "\n");
1268 if (os_snprintf_error(end
- pos
, ret
))
1273 if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) && hapd
->conf
->wpa_pairwise
) {
1274 ret
= os_snprintf(pos
, end
- pos
, "wpa_pairwise_cipher=");
1275 if (os_snprintf_error(end
- pos
, ret
))
1279 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->wpa_pairwise
,
1285 ret
= os_snprintf(pos
, end
- pos
, "\n");
1286 if (os_snprintf_error(end
- pos
, ret
))
1291 if (hapd
->conf
->wpa
&& hapd
->conf
->wpa_deny_ptk0_rekey
) {
1292 ret
= os_snprintf(pos
, end
- pos
, "wpa_deny_ptk0_rekey=%d\n",
1293 hapd
->conf
->wpa_deny_ptk0_rekey
);
1294 if (os_snprintf_error(end
- pos
, ret
))
1299 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && hapd
->conf
->extended_key_id
) {
1300 ret
= os_snprintf(pos
, end
- pos
, "extended_key_id=%d\n",
1301 hapd
->conf
->extended_key_id
);
1302 if (os_snprintf_error(end
- pos
, ret
))
1311 static void hostapd_disassoc_accept_mac(struct hostapd_data
*hapd
)
1313 struct sta_info
*sta
;
1314 struct vlan_description vlan_id
;
1316 if (hapd
->conf
->macaddr_acl
!= DENY_UNLESS_ACCEPTED
)
1319 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1320 if (!hostapd_maclist_found(hapd
->conf
->accept_mac
,
1321 hapd
->conf
->num_accept_mac
,
1322 sta
->addr
, &vlan_id
) ||
1323 (vlan_id
.notempty
&&
1324 vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1325 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1326 WLAN_REASON_UNSPECIFIED
);
1331 static void hostapd_disassoc_deny_mac(struct hostapd_data
*hapd
)
1333 struct sta_info
*sta
;
1334 struct vlan_description vlan_id
;
1336 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1337 if (hostapd_maclist_found(hapd
->conf
->deny_mac
,
1338 hapd
->conf
->num_deny_mac
, sta
->addr
,
1340 (!vlan_id
.notempty
||
1341 !vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1342 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1343 WLAN_REASON_UNSPECIFIED
);
1348 static int hostapd_ctrl_iface_set_band(struct hostapd_data
*hapd
,
1351 union wpa_event_data event
;
1352 enum set_band setband
;
1354 if (os_strcmp(band
, "AUTO") == 0)
1355 setband
= WPA_SETBAND_AUTO
;
1356 else if (os_strcmp(band
, "5G") == 0)
1357 setband
= WPA_SETBAND_5G
;
1358 else if (os_strcmp(band
, "2G") == 0)
1359 setband
= WPA_SETBAND_2G
;
1363 if (hostapd_drv_set_band(hapd
, setband
) == 0) {
1364 os_memset(&event
, 0, sizeof(event
));
1365 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
1366 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
1367 wpa_supplicant_event(hapd
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
1374 static int hostapd_ctrl_iface_set(struct hostapd_data
*hapd
, char *cmd
)
1379 value
= os_strchr(cmd
, ' ');
1384 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
1386 #ifdef CONFIG_WPS_TESTING
1387 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
1389 val
= strtol(value
, NULL
, 0);
1390 if (val
< 0 || val
> 0xff) {
1392 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
1393 "wps_version_number %ld", val
);
1395 wps_version_number
= val
;
1396 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
1398 (wps_version_number
& 0xf0) >> 4,
1399 wps_version_number
& 0x0f);
1400 hostapd_wps_update_ie(hapd
);
1402 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
1403 wps_testing_dummy_cred
= atoi(value
);
1404 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
1405 wps_testing_dummy_cred
);
1406 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
1407 wps_corrupt_pkhash
= atoi(value
);
1408 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
1409 wps_corrupt_pkhash
);
1410 #endif /* CONFIG_WPS_TESTING */
1411 #ifdef CONFIG_TESTING_OPTIONS
1412 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
1413 hapd
->ext_mgmt_frame_handling
= atoi(value
);
1414 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
1415 hapd
->ext_eapol_frame_io
= atoi(value
);
1417 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
1418 os_free(hapd
->dpp_config_obj_override
);
1419 hapd
->dpp_config_obj_override
= os_strdup(value
);
1420 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
1421 os_free(hapd
->dpp_discovery_override
);
1422 hapd
->dpp_discovery_override
= os_strdup(value
);
1423 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
1424 os_free(hapd
->dpp_groups_override
);
1425 hapd
->dpp_groups_override
= os_strdup(value
);
1426 } else if (os_strcasecmp(cmd
,
1427 "dpp_ignore_netaccesskey_mismatch") == 0) {
1428 hapd
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
1429 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
1430 dpp_test
= atoi(value
);
1431 #endif /* CONFIG_DPP */
1432 #endif /* CONFIG_TESTING_OPTIONS */
1434 } else if (os_strcasecmp(cmd
, "mbo_assoc_disallow") == 0) {
1437 if (!hapd
->conf
->mbo_enabled
)
1441 if (val
< 0 || val
> 1)
1444 hapd
->mbo_assoc_disallow
= val
;
1445 ieee802_11_update_beacons(hapd
->iface
);
1448 * TODO: Need to configure drivers that do AP MLME offload with
1449 * disallowing station logic.
1451 #endif /* CONFIG_MBO */
1453 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
1454 os_free(hapd
->dpp_configurator_params
);
1455 hapd
->dpp_configurator_params
= os_strdup(value
);
1456 #endif /* CONFIG_DPP */
1457 } else if (os_strcasecmp(cmd
, "setband") == 0) {
1458 ret
= hostapd_ctrl_iface_set_band(hapd
, value
);
1460 ret
= hostapd_set_iface(hapd
->iconf
, hapd
->conf
, cmd
, value
);
1464 if (os_strcasecmp(cmd
, "deny_mac_file") == 0) {
1465 hostapd_disassoc_deny_mac(hapd
);
1466 } else if (os_strcasecmp(cmd
, "accept_mac_file") == 0) {
1467 hostapd_disassoc_accept_mac(hapd
);
1468 } else if (os_strncmp(cmd
, "wme_ac_", 7) == 0 ||
1469 os_strncmp(cmd
, "wmm_ac_", 7) == 0) {
1470 hapd
->parameter_set_count
++;
1471 if (ieee802_11_update_beacons(hapd
->iface
))
1472 wpa_printf(MSG_DEBUG
,
1473 "Failed to update beacons with WMM parameters");
1474 } else if (os_strcmp(cmd
, "wpa_passphrase") == 0 ||
1475 os_strcmp(cmd
, "sae_password") == 0 ||
1476 os_strcmp(cmd
, "sae_pwe") == 0) {
1478 hostapd_setup_sae_pt(hapd
->conf
);
1486 static int hostapd_ctrl_iface_get(struct hostapd_data
*hapd
, char *cmd
,
1487 char *buf
, size_t buflen
)
1491 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
1493 if (os_strcmp(cmd
, "version") == 0) {
1494 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
1495 if (os_snprintf_error(buflen
, res
))
1498 } else if (os_strcmp(cmd
, "tls_library") == 0) {
1499 res
= tls_get_library_version(buf
, buflen
);
1500 if (os_snprintf_error(buflen
, res
))
1509 static int hostapd_ctrl_iface_enable(struct hostapd_iface
*iface
)
1511 if (hostapd_enable_iface(iface
) < 0) {
1512 wpa_printf(MSG_ERROR
, "Enabling of interface failed");
1519 static int hostapd_ctrl_iface_reload(struct hostapd_iface
*iface
)
1521 if (hostapd_reload_iface(iface
) < 0) {
1522 wpa_printf(MSG_ERROR
, "Reloading of interface failed");
1529 static int hostapd_ctrl_iface_disable(struct hostapd_iface
*iface
)
1531 if (hostapd_disable_iface(iface
) < 0) {
1532 wpa_printf(MSG_ERROR
, "Disabling of interface failed");
1540 hostapd_ctrl_iface_kick_mismatch_psk_sta_iter(struct hostapd_data
*hapd
,
1541 struct sta_info
*sta
, void *ctx
)
1543 struct hostapd_wpa_psk
*psk
;
1551 pmk
= wpa_auth_get_pmk(sta
->wpa_sm
, &pmk_len
);
1553 for (psk
= hapd
->conf
->ssid
.wpa_psk
; pmk
&& psk
; psk
= psk
->next
) {
1554 pmk_match
= PMK_LEN
== pmk_len
&&
1555 os_memcmp(psk
->psk
, pmk
, pmk_len
) == 0;
1556 sta_match
= psk
->group
== 0 &&
1557 os_memcmp(sta
->addr
, psk
->addr
, ETH_ALEN
) == 0;
1558 bss_match
= psk
->group
== 1;
1560 if (pmk_match
&& (sta_match
|| bss_match
))
1564 wpa_printf(MSG_INFO
, "STA " MACSTR
1565 " PSK/passphrase no longer valid - disconnect",
1566 MAC2STR(sta
->addr
));
1567 reason
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
1568 hostapd_drv_sta_deauth(hapd
, sta
->addr
, reason
);
1569 ap_sta_deauthenticate(hapd
, sta
, reason
);
1575 static int hostapd_ctrl_iface_reload_wpa_psk(struct hostapd_data
*hapd
)
1577 struct hostapd_bss_config
*conf
= hapd
->conf
;
1580 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
1582 err
= hostapd_setup_wpa_psk(conf
);
1584 wpa_printf(MSG_ERROR
, "Reloading WPA-PSK passwords failed: %d",
1589 ap_for_each_sta(hapd
, hostapd_ctrl_iface_kick_mismatch_psk_sta_iter
,
1596 #ifdef CONFIG_TESTING_OPTIONS
1598 static int hostapd_ctrl_iface_radar(struct hostapd_data
*hapd
, char *cmd
)
1600 union wpa_event_data data
;
1602 enum wpa_event_type event
;
1604 wpa_printf(MSG_DEBUG
, "RADAR TEST: %s", cmd
);
1606 os_memset(&data
, 0, sizeof(data
));
1608 param
= os_strchr(cmd
, ' ');
1613 if (os_strcmp(cmd
, "DETECTED") == 0)
1614 event
= EVENT_DFS_RADAR_DETECTED
;
1615 else if (os_strcmp(cmd
, "CAC-FINISHED") == 0)
1616 event
= EVENT_DFS_CAC_FINISHED
;
1617 else if (os_strcmp(cmd
, "CAC-ABORTED") == 0)
1618 event
= EVENT_DFS_CAC_ABORTED
;
1619 else if (os_strcmp(cmd
, "NOP-FINISHED") == 0)
1620 event
= EVENT_DFS_NOP_FINISHED
;
1622 wpa_printf(MSG_DEBUG
, "Unsupported RADAR test command: %s",
1627 pos
= os_strstr(param
, "freq=");
1629 data
.dfs_event
.freq
= atoi(pos
+ 5);
1631 pos
= os_strstr(param
, "ht_enabled=1");
1633 data
.dfs_event
.ht_enabled
= 1;
1635 pos
= os_strstr(param
, "chan_offset=");
1637 data
.dfs_event
.chan_offset
= atoi(pos
+ 12);
1639 pos
= os_strstr(param
, "chan_width=");
1641 data
.dfs_event
.chan_width
= atoi(pos
+ 11);
1643 pos
= os_strstr(param
, "cf1=");
1645 data
.dfs_event
.cf1
= atoi(pos
+ 4);
1647 pos
= os_strstr(param
, "cf2=");
1649 data
.dfs_event
.cf2
= atoi(pos
+ 4);
1651 wpa_supplicant_event(hapd
, event
, &data
);
1657 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data
*hapd
, char *cmd
)
1663 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
1665 len
= os_strlen(cmd
);
1670 buf
= os_malloc(len
);
1674 if (hexstr2bin(cmd
, buf
, len
) < 0) {
1679 res
= hostapd_drv_send_mlme(hapd
, buf
, len
, 0, NULL
, 0, 0);
1685 static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data
*hapd
,
1691 int stype
= 0, ok
= 0;
1692 union wpa_event_data event
;
1694 if (!hapd
->ext_mgmt_frame_handling
)
1697 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1699 wpa_printf(MSG_DEBUG
, "External MGMT TX status process: %s", cmd
);
1702 param
= os_strstr(pos
, "stype=");
1705 stype
= atoi(param
);
1708 param
= os_strstr(pos
, " ok=");
1714 param
= os_strstr(pos
, " buf=");
1719 len
= os_strlen(param
);
1724 buf
= os_malloc(len
);
1725 if (!buf
|| hexstr2bin(param
, buf
, len
) < 0) {
1730 os_memset(&event
, 0, sizeof(event
));
1731 event
.tx_status
.type
= WLAN_FC_TYPE_MGMT
;
1732 event
.tx_status
.data
= buf
;
1733 event
.tx_status
.data_len
= len
;
1734 event
.tx_status
.stype
= stype
;
1735 event
.tx_status
.ack
= ok
;
1736 hapd
->ext_mgmt_frame_handling
= 0;
1737 wpa_supplicant_event(hapd
, EVENT_TX_STATUS
, &event
);
1738 hapd
->ext_mgmt_frame_handling
= 1;
1746 static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data
*hapd
,
1752 int freq
= 0, datarate
= 0, ssi_signal
= 0;
1753 union wpa_event_data event
;
1755 if (!hapd
->ext_mgmt_frame_handling
)
1758 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1760 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
1763 param
= os_strstr(pos
, "freq=");
1769 param
= os_strstr(pos
, " datarate=");
1772 datarate
= atoi(param
);
1775 param
= os_strstr(pos
, " ssi_signal=");
1778 ssi_signal
= atoi(param
);
1781 param
= os_strstr(pos
, " frame=");
1786 len
= os_strlen(param
);
1791 buf
= os_malloc(len
);
1795 if (hexstr2bin(param
, buf
, len
) < 0) {
1800 os_memset(&event
, 0, sizeof(event
));
1801 event
.rx_mgmt
.freq
= freq
;
1802 event
.rx_mgmt
.frame
= buf
;
1803 event
.rx_mgmt
.frame_len
= len
;
1804 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1805 event
.rx_mgmt
.datarate
= datarate
;
1806 hapd
->ext_mgmt_frame_handling
= 0;
1807 wpa_supplicant_event(hapd
, EVENT_RX_MGMT
, &event
);
1808 hapd
->ext_mgmt_frame_handling
= 1;
1816 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data
*hapd
, char *cmd
)
1819 u8 src
[ETH_ALEN
], *buf
;
1823 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
1826 used
= hwaddr_aton2(pos
, src
);
1833 len
= os_strlen(pos
);
1838 buf
= os_malloc(len
);
1842 if (hexstr2bin(pos
, buf
, len
) < 0) {
1847 ieee802_1x_receive(hapd
, src
, buf
, len
);
1854 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
1858 const u16
*pos
= buf
;
1860 for (i
= 0; i
< len
/ 2; i
++)
1864 sum
= (sum
& 0xffff) + (sum
>> 16);
1866 return sum
^ 0xffff;
1870 #define HWSIM_PACKETLEN 1500
1871 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1873 static void hostapd_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
1876 struct hostapd_data
*hapd
= ctx
;
1877 const struct ether_header
*eth
;
1883 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
1884 wpa_printf(MSG_DEBUG
,
1885 "test data: RX - ignore unexpected length %d",
1890 eth
= (const struct ether_header
*) buf
;
1891 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
1892 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
1894 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 ||
1895 ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
1896 wpa_printf(MSG_DEBUG
,
1897 "test data: RX - ignore unexpect IP header");
1901 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
1902 if (*pos
!= (u8
) i
) {
1903 wpa_printf(MSG_DEBUG
,
1904 "test data: RX - ignore mismatching payload");
1911 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
1912 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
1913 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
1914 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
1918 static int hostapd_ctrl_iface_data_test_config(struct hostapd_data
*hapd
,
1921 int enabled
= atoi(cmd
);
1926 if (hapd
->l2_test
) {
1927 l2_packet_deinit(hapd
->l2_test
);
1928 hapd
->l2_test
= NULL
;
1929 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1930 "test data: Disabled");
1938 pos
= os_strstr(cmd
, " ifname=");
1942 ifname
= hapd
->conf
->iface
;
1944 hapd
->l2_test
= l2_packet_init(ifname
, hapd
->own_addr
,
1945 ETHERTYPE_IP
, hostapd_data_test_rx
,
1947 if (hapd
->l2_test
== NULL
)
1950 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: Enabled");
1956 static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data
*hapd
, char *cmd
)
1958 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
1963 u8 buf
[2 + HWSIM_PACKETLEN
];
1964 struct ether_header
*eth
;
1968 size_t send_len
= HWSIM_IP_LEN
;
1970 if (hapd
->l2_test
== NULL
)
1973 /* format: <dst> <src> <tos> [len=<length>] */
1976 used
= hwaddr_aton2(pos
, dst
);
1982 used
= hwaddr_aton2(pos
, src
);
1987 val
= strtol(pos
, &pos2
, 0);
1988 if (val
< 0 || val
> 0xff)
1992 pos
= os_strstr(pos2
, " len=");
1995 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
2000 eth
= (struct ether_header
*) &buf
[2];
2001 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
2002 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
2003 eth
->ether_type
= htons(ETHERTYPE_IP
);
2004 ip
= (struct ip
*) (eth
+ 1);
2005 os_memset(ip
, 0, sizeof(*ip
));
2010 ip
->ip_len
= htons(send_len
);
2012 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
2013 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
2014 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
2015 dpos
= (u8
*) (ip
+ 1);
2016 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
2019 if (l2_packet_send(hapd
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
2020 sizeof(struct ether_header
) + send_len
) < 0)
2023 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX dst=" MACSTR
2024 " src=" MACSTR
" tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
2030 static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data
*hapd
,
2034 struct ether_header
*eth
;
2035 struct l2_packet_data
*l2
= NULL
;
2039 const char *ifname
= hapd
->conf
->iface
;
2041 if (os_strncmp(cmd
, "ifname=", 7) == 0) {
2044 cmd
= os_strchr(cmd
, ' ');
2050 len
= os_strlen(cmd
);
2051 if (len
& 1 || len
< ETH_HLEN
* 2)
2055 buf
= os_malloc(len
);
2059 if (hexstr2bin(cmd
, buf
, len
) < 0)
2062 eth
= (struct ether_header
*) buf
;
2063 ethertype
= ntohs(eth
->ether_type
);
2065 l2
= l2_packet_init(ifname
, hapd
->own_addr
, ethertype
,
2066 hostapd_data_test_rx
, hapd
, 1);
2070 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
2071 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
2074 l2_packet_deinit(l2
);
2077 return res
< 0 ? -1 : 0;
2081 static int hostapd_ctrl_test_alloc_fail(struct hostapd_data
*hapd
, char *cmd
)
2083 #ifdef WPA_TRACE_BFD
2086 wpa_trace_fail_after
= atoi(cmd
);
2087 pos
= os_strchr(cmd
, ':');
2090 os_strlcpy(wpa_trace_fail_func
, pos
,
2091 sizeof(wpa_trace_fail_func
));
2093 wpa_trace_fail_after
= 0;
2097 #else /* WPA_TRACE_BFD */
2099 #endif /* WPA_TRACE_BFD */
2103 static int hostapd_ctrl_get_alloc_fail(struct hostapd_data
*hapd
,
2104 char *buf
, size_t buflen
)
2106 #ifdef WPA_TRACE_BFD
2107 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
2108 wpa_trace_fail_func
);
2109 #else /* WPA_TRACE_BFD */
2111 #endif /* WPA_TRACE_BFD */
2115 static int hostapd_ctrl_test_fail(struct hostapd_data
*hapd
, char *cmd
)
2117 #ifdef WPA_TRACE_BFD
2120 wpa_trace_test_fail_after
= atoi(cmd
);
2121 pos
= os_strchr(cmd
, ':');
2124 os_strlcpy(wpa_trace_test_fail_func
, pos
,
2125 sizeof(wpa_trace_test_fail_func
));
2127 wpa_trace_test_fail_after
= 0;
2131 #else /* WPA_TRACE_BFD */
2133 #endif /* WPA_TRACE_BFD */
2137 static int hostapd_ctrl_get_fail(struct hostapd_data
*hapd
,
2138 char *buf
, size_t buflen
)
2140 #ifdef WPA_TRACE_BFD
2141 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
2142 wpa_trace_test_fail_func
);
2143 #else /* WPA_TRACE_BFD */
2145 #endif /* WPA_TRACE_BFD */
2149 static int hostapd_ctrl_reset_pn(struct hostapd_data
*hapd
, const char *cmd
)
2151 struct sta_info
*sta
;
2153 u8 zero
[WPA_TK_MAX_LEN
];
2155 os_memset(zero
, 0, sizeof(zero
));
2157 if (hwaddr_aton(cmd
, addr
))
2160 if (is_broadcast_ether_addr(addr
) && os_strstr(cmd
, "IGTK")) {
2161 if (hapd
->last_igtk_alg
== WPA_ALG_NONE
)
2164 wpa_printf(MSG_INFO
, "TESTING: Reset IPN for IGTK");
2166 /* First, use a zero key to avoid any possible duplicate key
2167 * avoidance in the driver. */
2168 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2169 hapd
->last_igtk_alg
,
2170 broadcast_ether_addr
,
2171 hapd
->last_igtk_key_idx
, 0, 1, NULL
, 0,
2172 zero
, hapd
->last_igtk_len
,
2173 KEY_FLAG_GROUP_TX_DEFAULT
) < 0)
2176 /* Set the previously configured key to reset its TSC */
2177 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2178 hapd
->last_igtk_alg
,
2179 broadcast_ether_addr
,
2180 hapd
->last_igtk_key_idx
, 0, 1, NULL
,
2182 hapd
->last_igtk_len
,
2183 KEY_FLAG_GROUP_TX_DEFAULT
);
2186 if (is_broadcast_ether_addr(addr
)) {
2187 if (hapd
->last_gtk_alg
== WPA_ALG_NONE
)
2190 wpa_printf(MSG_INFO
, "TESTING: Reset PN for GTK");
2192 /* First, use a zero key to avoid any possible duplicate key
2193 * avoidance in the driver. */
2194 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2196 broadcast_ether_addr
,
2197 hapd
->last_gtk_key_idx
, 0, 1, NULL
, 0,
2198 zero
, hapd
->last_gtk_len
,
2199 KEY_FLAG_GROUP_TX_DEFAULT
) < 0)
2202 /* Set the previously configured key to reset its TSC */
2203 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2205 broadcast_ether_addr
,
2206 hapd
->last_gtk_key_idx
, 0, 1, NULL
,
2209 KEY_FLAG_GROUP_TX_DEFAULT
);
2212 sta
= ap_get_sta(hapd
, addr
);
2216 if (sta
->last_tk_alg
== WPA_ALG_NONE
)
2219 wpa_printf(MSG_INFO
, "TESTING: Reset PN for " MACSTR
,
2220 MAC2STR(sta
->addr
));
2222 /* First, use a zero key to avoid any possible duplicate key avoidance
2224 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2225 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2226 zero
, sta
->last_tk_len
,
2227 KEY_FLAG_PAIRWISE_RX_TX
) < 0)
2230 /* Set the previously configured key to reset its TSC/RSC */
2231 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2232 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
,
2233 0, sta
->last_tk
, sta
->last_tk_len
,
2234 KEY_FLAG_PAIRWISE_RX_TX
);
2238 static int hostapd_ctrl_set_key(struct hostapd_data
*hapd
, const char *cmd
)
2241 const char *pos
= cmd
;
2243 enum key_flag key_flag
;
2245 u8 seq
[6], key
[WPA_TK_MAX_LEN
];
2248 /* parameters: alg addr idx set_tx seq key key_flag */
2251 pos
= os_strchr(pos
, ' ');
2255 if (hwaddr_aton(pos
, addr
))
2262 pos
= os_strchr(pos
, ' ');
2267 pos
= os_strchr(pos
, ' ');
2271 if (hexstr2bin(pos
, seq
, sizeof(seq
)) < 0)
2277 if (!os_strchr(pos
, ' '))
2279 key_len
= (os_strchr(pos
, ' ') - pos
) / 2;
2280 if (hexstr2bin(pos
, key
, key_len
) < 0)
2287 key_flag
= atoi(pos
);
2288 pos
= os_strchr(pos
, ' ');
2292 wpa_printf(MSG_INFO
, "TESTING: Set key");
2293 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, alg
, addr
, idx
, 0,
2294 set_tx
, seq
, 6, key
, key_len
, key_flag
);
2298 static void restore_tk(void *ctx1
, void *ctx2
)
2300 struct hostapd_data
*hapd
= ctx1
;
2301 struct sta_info
*sta
= ctx2
;
2303 wpa_printf(MSG_INFO
, "TESTING: Restore TK for " MACSTR
,
2304 MAC2STR(sta
->addr
));
2305 /* This does not really restore the TSC properly, so this will result
2306 * in replay protection issues for now since there is no clean way of
2307 * preventing encryption of a single EAPOL frame. */
2308 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2309 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2310 sta
->last_tk
, sta
->last_tk_len
,
2311 KEY_FLAG_PAIRWISE_RX_TX
);
2315 static int hostapd_ctrl_resend_m1(struct hostapd_data
*hapd
, const char *cmd
)
2317 struct sta_info
*sta
;
2319 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2321 if (hwaddr_aton(cmd
, addr
))
2324 sta
= ap_get_sta(hapd
, addr
);
2325 if (!sta
|| !sta
->wpa_sm
)
2328 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2329 plain
= 0; /* no need for special processing */
2331 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2332 MAC2STR(sta
->addr
));
2333 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2334 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2335 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2338 wpa_printf(MSG_INFO
, "TESTING: Send M1 to " MACSTR
, MAC2STR(sta
->addr
));
2339 return wpa_auth_resend_m1(sta
->wpa_sm
,
2340 os_strstr(cmd
, "change-anonce") != NULL
,
2341 plain
? restore_tk
: NULL
, hapd
, sta
);
2345 static int hostapd_ctrl_resend_m3(struct hostapd_data
*hapd
, const char *cmd
)
2347 struct sta_info
*sta
;
2349 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2351 if (hwaddr_aton(cmd
, addr
))
2354 sta
= ap_get_sta(hapd
, addr
);
2355 if (!sta
|| !sta
->wpa_sm
)
2358 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2359 plain
= 0; /* no need for special processing */
2361 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2362 MAC2STR(sta
->addr
));
2363 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2364 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2365 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2368 wpa_printf(MSG_INFO
, "TESTING: Send M3 to " MACSTR
, MAC2STR(sta
->addr
));
2369 return wpa_auth_resend_m3(sta
->wpa_sm
,
2370 plain
? restore_tk
: NULL
, hapd
, sta
);
2374 static int hostapd_ctrl_resend_group_m1(struct hostapd_data
*hapd
,
2377 struct sta_info
*sta
;
2379 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2381 if (hwaddr_aton(cmd
, addr
))
2384 sta
= ap_get_sta(hapd
, addr
);
2385 if (!sta
|| !sta
->wpa_sm
)
2388 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2389 plain
= 0; /* no need for special processing */
2391 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2392 MAC2STR(sta
->addr
));
2393 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2394 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2395 0, NULL
, 0, KEY_FLAG_PAIRWISE
);
2398 wpa_printf(MSG_INFO
,
2399 "TESTING: Send group M1 for the same GTK and zero RSC to "
2400 MACSTR
, MAC2STR(sta
->addr
));
2401 return wpa_auth_resend_group_m1(sta
->wpa_sm
,
2402 plain
? restore_tk
: NULL
, hapd
, sta
);
2406 static int hostapd_ctrl_get_pmk(struct hostapd_data
*hapd
, const char *cmd
,
2407 char *buf
, size_t buflen
)
2409 struct sta_info
*sta
;
2414 if (hwaddr_aton(cmd
, addr
))
2417 sta
= ap_get_sta(hapd
, addr
);
2418 if (!sta
|| !sta
->wpa_sm
) {
2419 wpa_printf(MSG_DEBUG
, "No STA WPA state machine for " MACSTR
,
2423 pmk
= wpa_auth_get_pmk(sta
->wpa_sm
, &pmk_len
);
2425 wpa_printf(MSG_DEBUG
, "No PMK stored for " MACSTR
,
2430 return wpa_snprintf_hex(buf
, buflen
, pmk
, pmk_len
);
2433 #endif /* CONFIG_TESTING_OPTIONS */
2436 static int hostapd_ctrl_check_freq_params(struct hostapd_freq_params
*params
)
2438 switch (params
->bandwidth
) {
2440 /* bandwidth not specified: use 20 MHz by default */
2443 if (params
->center_freq1
&&
2444 params
->center_freq1
!= params
->freq
)
2447 if (params
->center_freq2
|| params
->sec_channel_offset
)
2451 if (params
->center_freq2
|| !params
->sec_channel_offset
)
2454 if (!params
->center_freq1
)
2456 switch (params
->sec_channel_offset
) {
2458 if (params
->freq
+ 10 != params
->center_freq1
)
2462 if (params
->freq
- 10 != params
->center_freq1
)
2470 if (!params
->center_freq1
|| !params
->sec_channel_offset
)
2473 switch (params
->sec_channel_offset
) {
2475 if (params
->freq
- 10 != params
->center_freq1
&&
2476 params
->freq
+ 30 != params
->center_freq1
)
2480 if (params
->freq
+ 10 != params
->center_freq1
&&
2481 params
->freq
- 30 != params
->center_freq1
)
2488 /* Adjacent and overlapped are not allowed for 80+80 */
2489 if (params
->center_freq2
&&
2490 params
->center_freq1
- params
->center_freq2
<= 80 &&
2491 params
->center_freq2
- params
->center_freq1
<= 80)
2495 if (!params
->center_freq1
|| params
->center_freq2
||
2496 !params
->sec_channel_offset
)
2499 switch (params
->sec_channel_offset
) {
2501 if (params
->freq
+ 70 != params
->center_freq1
&&
2502 params
->freq
+ 30 != params
->center_freq1
&&
2503 params
->freq
- 10 != params
->center_freq1
&&
2504 params
->freq
- 50 != params
->center_freq1
)
2508 if (params
->freq
+ 50 != params
->center_freq1
&&
2509 params
->freq
+ 10 != params
->center_freq1
&&
2510 params
->freq
- 30 != params
->center_freq1
&&
2511 params
->freq
- 70 != params
->center_freq1
)
2526 static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface
*iface
,
2530 struct csa_settings settings
;
2537 ret
= hostapd_parse_csa_settings(pos
, &settings
);
2541 ret
= hostapd_ctrl_check_freq_params(&settings
.freq_params
);
2543 wpa_printf(MSG_INFO
,
2544 "chanswitch: invalid frequency settings provided");
2548 switch (settings
.freq_params
.bandwidth
) {
2550 bandwidth
= CHAN_WIDTH_40
;
2553 if (settings
.freq_params
.center_freq2
)
2554 bandwidth
= CHAN_WIDTH_80P80
;
2556 bandwidth
= CHAN_WIDTH_80
;
2559 bandwidth
= CHAN_WIDTH_160
;
2562 bandwidth
= CHAN_WIDTH_20
;
2566 if (settings
.freq_params
.center_freq1
)
2567 dfs_range
+= hostapd_is_dfs_overlap(
2568 iface
, bandwidth
, settings
.freq_params
.center_freq1
);
2570 dfs_range
+= hostapd_is_dfs_overlap(
2571 iface
, bandwidth
, settings
.freq_params
.freq
);
2573 if (settings
.freq_params
.center_freq2
)
2574 dfs_range
+= hostapd_is_dfs_overlap(
2575 iface
, bandwidth
, settings
.freq_params
.center_freq2
);
2578 ret
= ieee80211_freq_to_chan(settings
.freq_params
.freq
, &chan
);
2579 if (ret
== NUM_HOSTAPD_MODES
) {
2580 wpa_printf(MSG_ERROR
,
2581 "Failed to get channel for (freq=%d, sec_channel_offset=%d, bw=%d)",
2582 settings
.freq_params
.freq
,
2583 settings
.freq_params
.sec_channel_offset
,
2584 settings
.freq_params
.bandwidth
);
2588 settings
.freq_params
.channel
= chan
;
2590 wpa_printf(MSG_DEBUG
,
2591 "DFS/CAC to (channel=%u, freq=%d, sec_channel_offset=%d, bw=%d, center_freq1=%d)",
2592 settings
.freq_params
.channel
,
2593 settings
.freq_params
.freq
,
2594 settings
.freq_params
.sec_channel_offset
,
2595 settings
.freq_params
.bandwidth
,
2596 settings
.freq_params
.center_freq1
);
2598 /* Perform CAC and switch channel */
2599 hostapd_switch_channel_fallback(iface
, &settings
.freq_params
);
2603 for (i
= 0; i
< iface
->num_bss
; i
++) {
2605 /* Save CHAN_SWITCH VHT config */
2606 hostapd_chan_switch_vht_config(
2607 iface
->bss
[i
], settings
.freq_params
.vht_enabled
);
2609 ret
= hostapd_switch_channel(iface
->bss
[i
], &settings
);
2611 /* FIX: What do we do if CSA fails in the middle of
2612 * submitting multi-BSS CSA requests? */
2618 #else /* NEED_AP_MLME */
2620 #endif /* NEED_AP_MLME */
2624 static int hostapd_ctrl_iface_mib(struct hostapd_data
*hapd
, char *reply
,
2625 int reply_size
, const char *param
)
2627 #ifdef RADIUS_SERVER
2628 if (os_strcmp(param
, "radius_server") == 0) {
2629 return radius_server_get_mib(hapd
->radius_srv
, reply
,
2632 #endif /* RADIUS_SERVER */
2637 static int hostapd_ctrl_iface_vendor(struct hostapd_data
*hapd
, char *cmd
,
2638 char *buf
, size_t buflen
)
2643 unsigned int vendor_id
, subcmd
;
2644 struct wpabuf
*reply
;
2645 size_t data_len
= 0;
2647 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2648 vendor_id
= strtoul(cmd
, &pos
, 16);
2649 if (!isblank((unsigned char) *pos
))
2652 subcmd
= strtoul(pos
, &pos
, 10);
2655 if (!isblank((unsigned char) *pos
++))
2657 data_len
= os_strlen(pos
);
2662 data
= os_malloc(data_len
);
2666 if (hexstr2bin(pos
, data
, data_len
)) {
2667 wpa_printf(MSG_DEBUG
,
2668 "Vendor command: wrong parameter format");
2674 reply
= wpabuf_alloc((buflen
- 1) / 2);
2680 ret
= hostapd_drv_vendor_cmd(hapd
, vendor_id
, subcmd
, data
, data_len
,
2684 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
2694 static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data
*hapd
,
2698 struct sta_info
*sta
;
2700 if (hwaddr_aton(cmd
, addr
))
2703 sta
= ap_get_sta(hapd
, addr
);
2704 if (!sta
|| !sta
->eapol_sm
)
2707 eapol_auth_reauthenticate(sta
->eapol_sm
);
2712 static int hostapd_ctrl_iface_eapol_set(struct hostapd_data
*hapd
, char *cmd
)
2715 struct sta_info
*sta
;
2716 char *pos
= cmd
, *param
;
2718 if (hwaddr_aton(pos
, addr
) || pos
[17] != ' ')
2722 pos
= os_strchr(pos
, ' ');
2727 sta
= ap_get_sta(hapd
, addr
);
2728 if (!sta
|| !sta
->eapol_sm
)
2731 return eapol_auth_set_conf(sta
->eapol_sm
, param
, pos
);
2735 static int hostapd_ctrl_iface_log_level(struct hostapd_data
*hapd
, char *cmd
,
2736 char *buf
, size_t buflen
)
2738 char *pos
, *end
, *stamp
;
2741 /* cmd: "LOG_LEVEL [<level>]" */
2745 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2747 debug_level_str(wpa_debug_level
),
2748 wpa_debug_timestamp
);
2749 if (os_snprintf_error(end
- pos
, ret
))
2758 stamp
= os_strchr(cmd
, ' ');
2761 while (*stamp
== ' ') {
2766 if (os_strlen(cmd
)) {
2767 int level
= str_to_debug_level(cmd
);
2770 wpa_debug_level
= level
;
2773 if (stamp
&& os_strlen(stamp
))
2774 wpa_debug_timestamp
= atoi(stamp
);
2776 os_memcpy(buf
, "OK\n", 3);
2782 static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data
*hapd
,
2783 char *buf
, size_t buflen
)
2785 struct hostapd_iface
*iface
= hapd
->iface
;
2787 struct hostapd_sta_info
*info
;
2788 struct os_reltime now
;
2790 if (!iface
->num_sta_seen
)
2793 sta_track_expire(iface
, 0);
2798 os_get_reltime(&now
);
2799 dl_list_for_each_reverse(info
, &iface
->sta_seen
,
2800 struct hostapd_sta_info
, list
) {
2801 struct os_reltime age
;
2804 os_reltime_sub(&now
, &info
->last_seen
, &age
);
2805 ret
= os_snprintf(pos
, end
- pos
, MACSTR
" %u %d\n",
2806 MAC2STR(info
->addr
), (unsigned int) age
.sec
,
2808 if (os_snprintf_error(end
- pos
, ret
))
2815 #endif /* NEED_AP_MLME */
2818 static int hostapd_ctrl_iface_req_lci(struct hostapd_data
*hapd
,
2823 if (hwaddr_aton(cmd
, addr
)) {
2824 wpa_printf(MSG_INFO
, "CTRL: REQ_LCI: Invalid MAC address");
2828 return hostapd_send_lci_req(hapd
, addr
);
2832 static int hostapd_ctrl_iface_req_range(struct hostapd_data
*hapd
, char *cmd
)
2835 char *token
, *context
= NULL
;
2836 int random_interval
, min_ap
;
2837 u8 responders
[ETH_ALEN
* RRM_RANGE_REQ_MAX_RESPONDERS
];
2838 unsigned int n_responders
;
2840 token
= str_token(cmd
, " ", &context
);
2841 if (!token
|| hwaddr_aton(token
, addr
)) {
2842 wpa_printf(MSG_INFO
,
2843 "CTRL: REQ_RANGE - Bad destination address");
2847 token
= str_token(cmd
, " ", &context
);
2851 random_interval
= atoi(token
);
2852 if (random_interval
< 0 || random_interval
> 0xffff)
2855 token
= str_token(cmd
, " ", &context
);
2859 min_ap
= atoi(token
);
2860 if (min_ap
<= 0 || min_ap
> WLAN_RRM_RANGE_REQ_MAX_MIN_AP
)
2864 while ((token
= str_token(cmd
, " ", &context
))) {
2865 if (n_responders
== RRM_RANGE_REQ_MAX_RESPONDERS
) {
2866 wpa_printf(MSG_INFO
,
2867 "CTRL: REQ_RANGE: Too many responders");
2871 if (hwaddr_aton(token
, responders
+ n_responders
* ETH_ALEN
)) {
2872 wpa_printf(MSG_INFO
,
2873 "CTRL: REQ_RANGE: Bad responder address");
2880 if (!n_responders
) {
2881 wpa_printf(MSG_INFO
,
2882 "CTRL: REQ_RANGE - No FTM responder address");
2886 return hostapd_send_range_req(hapd
, addr
, random_interval
, min_ap
,
2887 responders
, n_responders
);
2891 static int hostapd_ctrl_iface_req_beacon(struct hostapd_data
*hapd
,
2892 const char *cmd
, char *reply
,
2901 if (hwaddr_aton(cmd
, addr
))
2903 pos
= os_strchr(cmd
, ' ');
2907 if (os_strncmp(pos
, "req_mode=", 9) == 0) {
2908 int val
= hex2byte(pos
+ 9);
2914 pos
= os_strchr(pos
, ' ');
2919 req
= wpabuf_parse_bin(pos
);
2923 ret
= hostapd_send_beacon_req(hapd
, addr
, req_mode
, req
);
2926 ret
= os_snprintf(reply
, reply_size
, "%d", ret
);
2931 static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data
*hapd
,
2932 char *buf
, size_t buflen
)
2934 if (!(hapd
->conf
->radio_measurements
[0] &
2935 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2936 wpa_printf(MSG_ERROR
,
2937 "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled");
2941 return hostapd_neighbor_show(hapd
, buf
, buflen
);
2945 static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data
*hapd
, char *buf
)
2947 struct wpa_ssid_value ssid
;
2949 struct wpabuf
*nr
, *lci
= NULL
, *civic
= NULL
;
2954 if (!(hapd
->conf
->radio_measurements
[0] &
2955 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2956 wpa_printf(MSG_ERROR
,
2957 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
2961 if (hwaddr_aton(buf
, bssid
)) {
2962 wpa_printf(MSG_ERROR
, "CTRL: SET_NEIGHBOR: Bad BSSID");
2966 tmp
= os_strstr(buf
, "ssid=");
2967 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2968 wpa_printf(MSG_ERROR
,
2969 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
2972 buf
= os_strchr(tmp
+ 6, tmp
[5] == '"' ? '"' : ' ');
2976 tmp
= os_strstr(buf
, "nr=");
2978 wpa_printf(MSG_ERROR
,
2979 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
2983 buf
= os_strchr(tmp
, ' ');
2987 nr
= wpabuf_parse_bin(tmp
+ 3);
2989 wpa_printf(MSG_ERROR
,
2990 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
2997 tmp
= os_strstr(buf
, "lci=");
2999 buf
= os_strchr(tmp
, ' ');
3002 lci
= wpabuf_parse_bin(tmp
+ 4);
3004 wpa_printf(MSG_ERROR
,
3005 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
3014 tmp
= os_strstr(buf
, "civic=");
3016 buf
= os_strchr(tmp
, ' ');
3019 civic
= wpabuf_parse_bin(tmp
+ 6);
3021 wpa_printf(MSG_ERROR
,
3022 "CTRL: SET_NEIGHBOR: Bad civic subelement");
3032 if (os_strstr(buf
, "stat"))
3036 ret
= hostapd_neighbor_set(hapd
, bssid
, &ssid
, nr
, lci
, civic
,
3047 static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data
*hapd
,
3050 struct wpa_ssid_value ssid
;
3051 struct wpa_ssid_value
*ssidp
= NULL
;
3055 if (hwaddr_aton(buf
, bssid
)) {
3056 wpa_printf(MSG_ERROR
, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
3060 tmp
= os_strstr(buf
, "ssid=");
3063 if (ssid_parse(tmp
+ 5, &ssid
)) {
3064 wpa_printf(MSG_ERROR
,
3065 "CTRL: REMOVE_NEIGHBOR: Bad SSID");
3070 return hostapd_neighbor_remove(hapd
, bssid
, ssidp
);
3074 static int hostapd_ctrl_driver_flags(struct hostapd_iface
*iface
, char *buf
,
3080 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
3081 (long long unsigned) iface
->drv_flags
);
3082 if (os_snprintf_error(buflen
, ret
))
3088 for (i
= 0; i
< 64; i
++) {
3089 if (iface
->drv_flags
& (1LLU << i
)) {
3090 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
3091 driver_flag_to_string(1LLU << i
));
3092 if (os_snprintf_error(end
- pos
, ret
))
3102 static int hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry
**acl
, int *num
,
3103 const char *txtaddr
)
3106 struct vlan_description vlan_id
;
3111 if (hwaddr_aton(txtaddr
, addr
))
3114 if (hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
))
3115 hostapd_remove_acl_mac(acl
, num
, addr
);
3121 static void hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry
**acl
,
3125 hostapd_remove_acl_mac(acl
, num
, (*acl
)[0].addr
);
3129 static int hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry
*acl
, int num
,
3130 char *buf
, size_t buflen
)
3132 int i
= 0, len
= 0, ret
= 0;
3138 ret
= os_snprintf(buf
+ len
, buflen
- len
,
3139 MACSTR
" VLAN_ID=%d\n",
3140 MAC2STR(acl
[i
].addr
),
3141 acl
[i
].vlan_id
.untagged
);
3142 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
3151 static int hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry
**acl
, int *num
,
3155 struct vlan_description vlan_id
;
3156 int ret
= 0, vlanid
= 0;
3159 if (hwaddr_aton(cmd
, addr
))
3162 pos
= os_strstr(cmd
, "VLAN_ID=");
3164 vlanid
= atoi(pos
+ 8);
3166 if (!hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
)) {
3167 ret
= hostapd_add_acl_maclist(acl
, num
, vlanid
, addr
);
3168 if (ret
!= -1 && *acl
)
3169 qsort(*acl
, *num
, sizeof(**acl
), hostapd_acl_comp
);
3172 return ret
< 0 ? -1 : 0;
3176 static int hostapd_ctrl_iface_get_capability(struct hostapd_data
*hapd
,
3177 const char *field
, char *buf
,
3180 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s'", field
);
3183 if (os_strcmp(field
, "dpp") == 0) {
3187 res
= os_snprintf(buf
, buflen
, "DPP=2");
3188 #else /* CONFIG_DPP2 */
3189 res
= os_snprintf(buf
, buflen
, "DPP=1");
3190 #endif /* CONFIG_DPP2 */
3191 if (os_snprintf_error(buflen
, res
))
3195 #endif /* CONFIG_DPP */
3197 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3204 static int hostapd_ctrl_iface_receive_process(struct hostapd_data
*hapd
,
3205 char *buf
, char *reply
,
3207 struct sockaddr_storage
*from
,
3212 os_memcpy(reply
, "OK\n", 3);
3215 if (os_strcmp(buf
, "PING") == 0) {
3216 os_memcpy(reply
, "PONG\n", 5);
3218 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3219 if (wpa_debug_reopen_file() < 0)
3221 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3222 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3223 } else if (os_strcmp(buf
, "STATUS") == 0) {
3224 reply_len
= hostapd_ctrl_iface_status(hapd
, reply
,
3226 } else if (os_strcmp(buf
, "STATUS-DRIVER") == 0) {
3227 reply_len
= hostapd_drv_status(hapd
, reply
, reply_size
);
3228 } else if (os_strcmp(buf
, "MIB") == 0) {
3229 reply_len
= ieee802_11_get_mib(hapd
, reply
, reply_size
);
3230 if (reply_len
>= 0) {
3231 res
= wpa_get_mib(hapd
->wpa_auth
, reply
+ reply_len
,
3232 reply_size
- reply_len
);
3238 if (reply_len
>= 0) {
3239 res
= ieee802_1x_get_mib(hapd
, reply
+ reply_len
,
3240 reply_size
- reply_len
);
3246 #ifndef CONFIG_NO_RADIUS
3247 if (reply_len
>= 0) {
3248 res
= radius_client_get_mib(hapd
->radius
,
3250 reply_size
- reply_len
);
3256 #endif /* CONFIG_NO_RADIUS */
3257 } else if (os_strncmp(buf
, "MIB ", 4) == 0) {
3258 reply_len
= hostapd_ctrl_iface_mib(hapd
, reply
, reply_size
,
3260 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
3261 reply_len
= hostapd_ctrl_iface_sta_first(hapd
, reply
,
3263 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
3264 reply_len
= hostapd_ctrl_iface_sta(hapd
, buf
+ 4, reply
,
3266 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
3267 reply_len
= hostapd_ctrl_iface_sta_next(hapd
, buf
+ 9, reply
,
3269 } else if (os_strcmp(buf
, "ATTACH") == 0) {
3270 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, NULL
))
3272 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
3273 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, buf
+ 7))
3275 } else if (os_strcmp(buf
, "DETACH") == 0) {
3276 if (hostapd_ctrl_iface_detach(hapd
, from
, fromlen
))
3278 } else if (os_strncmp(buf
, "LEVEL ", 6) == 0) {
3279 if (hostapd_ctrl_iface_level(hapd
, from
, fromlen
,
3282 } else if (os_strncmp(buf
, "NEW_STA ", 8) == 0) {
3283 if (hostapd_ctrl_iface_new_sta(hapd
, buf
+ 8))
3285 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
3286 if (hostapd_ctrl_iface_deauthenticate(hapd
, buf
+ 15))
3288 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
3289 if (hostapd_ctrl_iface_disassociate(hapd
, buf
+ 13))
3291 #ifdef CONFIG_TAXONOMY
3292 } else if (os_strncmp(buf
, "SIGNATURE ", 10) == 0) {
3293 reply_len
= hostapd_ctrl_iface_signature(hapd
, buf
+ 10,
3295 #endif /* CONFIG_TAXONOMY */
3296 } else if (os_strncmp(buf
, "POLL_STA ", 9) == 0) {
3297 if (hostapd_ctrl_iface_poll_sta(hapd
, buf
+ 9))
3299 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
3300 if (hostapd_ctrl_iface_stop_ap(hapd
))
3303 } else if (os_strncmp(buf
, "SA_QUERY ", 9) == 0) {
3304 if (hostapd_ctrl_iface_sa_query(hapd
, buf
+ 9))
3306 #endif /* NEED_AP_MLME */
3308 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
3309 if (hostapd_ctrl_iface_wps_pin(hapd
, buf
+ 8))
3311 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
3312 reply_len
= hostapd_ctrl_iface_wps_check_pin(
3313 hapd
, buf
+ 14, reply
, reply_size
);
3314 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
3315 if (hostapd_wps_button_pushed(hapd
, NULL
))
3317 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
3318 if (hostapd_wps_cancel(hapd
))
3320 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
3321 reply_len
= hostapd_ctrl_iface_wps_ap_pin(hapd
, buf
+ 11,
3323 } else if (os_strncmp(buf
, "WPS_CONFIG ", 11) == 0) {
3324 if (hostapd_ctrl_iface_wps_config(hapd
, buf
+ 11) < 0)
3326 } else if (os_strncmp(buf
, "WPS_GET_STATUS", 13) == 0) {
3327 reply_len
= hostapd_ctrl_iface_wps_get_status(hapd
, reply
,
3329 #ifdef CONFIG_WPS_NFC
3330 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
3331 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd
, buf
+ 17))
3333 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
3334 reply_len
= hostapd_ctrl_iface_wps_nfc_config_token(
3335 hapd
, buf
+ 21, reply
, reply_size
);
3336 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
3337 reply_len
= hostapd_ctrl_iface_wps_nfc_token(
3338 hapd
, buf
+ 14, reply
, reply_size
);
3339 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
3340 reply_len
= hostapd_ctrl_iface_nfc_get_handover_sel(
3341 hapd
, buf
+ 21, reply
, reply_size
);
3342 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
3343 if (hostapd_ctrl_iface_nfc_report_handover(hapd
, buf
+ 20))
3345 #endif /* CONFIG_WPS_NFC */
3346 #endif /* CONFIG_WPS */
3347 #ifdef CONFIG_INTERWORKING
3348 } else if (os_strncmp(buf
, "SET_QOS_MAP_SET ", 16) == 0) {
3349 if (hostapd_ctrl_iface_set_qos_map_set(hapd
, buf
+ 16))
3351 } else if (os_strncmp(buf
, "SEND_QOS_MAP_CONF ", 18) == 0) {
3352 if (hostapd_ctrl_iface_send_qos_map_conf(hapd
, buf
+ 18))
3354 #endif /* CONFIG_INTERWORKING */
3356 } else if (os_strncmp(buf
, "HS20_WNM_NOTIF ", 15) == 0) {
3357 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd
, buf
+ 15))
3359 } else if (os_strncmp(buf
, "HS20_DEAUTH_REQ ", 16) == 0) {
3360 if (hostapd_ctrl_iface_hs20_deauth_req(hapd
, buf
+ 16))
3362 #endif /* CONFIG_HS20 */
3363 #ifdef CONFIG_WNM_AP
3364 } else if (os_strncmp(buf
, "DISASSOC_IMMINENT ", 18) == 0) {
3365 if (hostapd_ctrl_iface_disassoc_imminent(hapd
, buf
+ 18))
3367 } else if (os_strncmp(buf
, "ESS_DISASSOC ", 13) == 0) {
3368 if (hostapd_ctrl_iface_ess_disassoc(hapd
, buf
+ 13))
3370 } else if (os_strncmp(buf
, "BSS_TM_REQ ", 11) == 0) {
3371 if (hostapd_ctrl_iface_bss_tm_req(hapd
, buf
+ 11))
3373 } else if (os_strncmp(buf
, "COLOC_INTF_REQ ", 15) == 0) {
3374 if (hostapd_ctrl_iface_coloc_intf_req(hapd
, buf
+ 15))
3376 #endif /* CONFIG_WNM_AP */
3377 } else if (os_strcmp(buf
, "GET_CONFIG") == 0) {
3378 reply_len
= hostapd_ctrl_iface_get_config(hapd
, reply
,
3380 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3381 if (hostapd_ctrl_iface_set(hapd
, buf
+ 4))
3383 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3384 reply_len
= hostapd_ctrl_iface_get(hapd
, buf
+ 4, reply
,
3386 } else if (os_strncmp(buf
, "ENABLE", 6) == 0) {
3387 if (hostapd_ctrl_iface_enable(hapd
->iface
))
3389 } else if (os_strcmp(buf
, "RELOAD_WPA_PSK") == 0) {
3390 if (hostapd_ctrl_iface_reload_wpa_psk(hapd
))
3392 } else if (os_strncmp(buf
, "RELOAD", 6) == 0) {
3393 if (hostapd_ctrl_iface_reload(hapd
->iface
))
3395 } else if (os_strncmp(buf
, "DISABLE", 7) == 0) {
3396 if (hostapd_ctrl_iface_disable(hapd
->iface
))
3398 } else if (os_strcmp(buf
, "UPDATE_BEACON") == 0) {
3399 if (ieee802_11_set_beacon(hapd
))
3401 #ifdef CONFIG_TESTING_OPTIONS
3402 } else if (os_strncmp(buf
, "RADAR ", 6) == 0) {
3403 if (hostapd_ctrl_iface_radar(hapd
, buf
+ 6))
3405 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
3406 if (hostapd_ctrl_iface_mgmt_tx(hapd
, buf
+ 8))
3408 } else if (os_strncmp(buf
, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
3409 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd
,
3412 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
3413 if (hostapd_ctrl_iface_mgmt_rx_process(hapd
, buf
+ 16) < 0)
3415 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
3416 if (hostapd_ctrl_iface_eapol_rx(hapd
, buf
+ 9) < 0)
3418 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
3419 if (hostapd_ctrl_iface_data_test_config(hapd
, buf
+ 17) < 0)
3421 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
3422 if (hostapd_ctrl_iface_data_test_tx(hapd
, buf
+ 13) < 0)
3424 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
3425 if (hostapd_ctrl_iface_data_test_frame(hapd
, buf
+ 16) < 0)
3427 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
3428 if (hostapd_ctrl_test_alloc_fail(hapd
, buf
+ 16) < 0)
3430 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
3431 reply_len
= hostapd_ctrl_get_alloc_fail(hapd
, reply
,
3433 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
3434 if (hostapd_ctrl_test_fail(hapd
, buf
+ 10) < 0)
3436 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
3437 reply_len
= hostapd_ctrl_get_fail(hapd
, reply
, reply_size
);
3438 } else if (os_strncmp(buf
, "RESET_PN ", 9) == 0) {
3439 if (hostapd_ctrl_reset_pn(hapd
, buf
+ 9) < 0)
3441 } else if (os_strncmp(buf
, "SET_KEY ", 8) == 0) {
3442 if (hostapd_ctrl_set_key(hapd
, buf
+ 8) < 0)
3444 } else if (os_strncmp(buf
, "RESEND_M1 ", 10) == 0) {
3445 if (hostapd_ctrl_resend_m1(hapd
, buf
+ 10) < 0)
3447 } else if (os_strncmp(buf
, "RESEND_M3 ", 10) == 0) {
3448 if (hostapd_ctrl_resend_m3(hapd
, buf
+ 10) < 0)
3450 } else if (os_strncmp(buf
, "RESEND_GROUP_M1 ", 16) == 0) {
3451 if (hostapd_ctrl_resend_group_m1(hapd
, buf
+ 16) < 0)
3453 } else if (os_strcmp(buf
, "REKEY_GTK") == 0) {
3454 if (wpa_auth_rekey_gtk(hapd
->wpa_auth
) < 0)
3456 } else if (os_strncmp(buf
, "GET_PMK ", 8) == 0) {
3457 reply_len
= hostapd_ctrl_get_pmk(hapd
, buf
+ 8, reply
,
3459 #endif /* CONFIG_TESTING_OPTIONS */
3460 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
3461 if (hostapd_ctrl_iface_chan_switch(hapd
->iface
, buf
+ 12))
3463 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
3464 reply_len
= hostapd_ctrl_iface_vendor(hapd
, buf
+ 7, reply
,
3466 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
3467 ieee802_1x_erp_flush(hapd
);
3468 #ifdef RADIUS_SERVER
3469 radius_server_erp_flush(hapd
->radius_srv
);
3470 #endif /* RADIUS_SERVER */
3471 } else if (os_strncmp(buf
, "EAPOL_REAUTH ", 13) == 0) {
3472 if (hostapd_ctrl_iface_eapol_reauth(hapd
, buf
+ 13))
3474 } else if (os_strncmp(buf
, "EAPOL_SET ", 10) == 0) {
3475 if (hostapd_ctrl_iface_eapol_set(hapd
, buf
+ 10))
3477 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
3478 reply_len
= hostapd_ctrl_iface_log_level(
3479 hapd
, buf
+ 9, reply
, reply_size
);
3481 } else if (os_strcmp(buf
, "TRACK_STA_LIST") == 0) {
3482 reply_len
= hostapd_ctrl_iface_track_sta_list(
3483 hapd
, reply
, reply_size
);
3484 #endif /* NEED_AP_MLME */
3485 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3486 reply_len
= hostapd_ctrl_iface_pmksa_list(hapd
, reply
,
3488 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
3489 hostapd_ctrl_iface_pmksa_flush(hapd
);
3490 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
3491 if (hostapd_ctrl_iface_pmksa_add(hapd
, buf
+ 10) < 0)
3493 } else if (os_strncmp(buf
, "SET_NEIGHBOR ", 13) == 0) {
3494 if (hostapd_ctrl_iface_set_neighbor(hapd
, buf
+ 13))
3496 } else if (os_strcmp(buf
, "SHOW_NEIGHBOR") == 0) {
3497 reply_len
= hostapd_ctrl_iface_show_neighbor(hapd
, reply
,
3499 } else if (os_strncmp(buf
, "REMOVE_NEIGHBOR ", 16) == 0) {
3500 if (hostapd_ctrl_iface_remove_neighbor(hapd
, buf
+ 16))
3502 } else if (os_strncmp(buf
, "REQ_LCI ", 8) == 0) {
3503 if (hostapd_ctrl_iface_req_lci(hapd
, buf
+ 8))
3505 } else if (os_strncmp(buf
, "REQ_RANGE ", 10) == 0) {
3506 if (hostapd_ctrl_iface_req_range(hapd
, buf
+ 10))
3508 } else if (os_strncmp(buf
, "REQ_BEACON ", 11) == 0) {
3509 reply_len
= hostapd_ctrl_iface_req_beacon(hapd
, buf
+ 11,
3511 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
3512 reply_len
= hostapd_ctrl_driver_flags(hapd
->iface
, reply
,
3514 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
3516 } else if (os_strncmp(buf
, "ACCEPT_ACL ", 11) == 0) {
3517 if (os_strncmp(buf
+ 11, "ADD_MAC ", 8) == 0) {
3518 if (!hostapd_ctrl_iface_acl_add_mac(
3519 &hapd
->conf
->accept_mac
,
3520 &hapd
->conf
->num_accept_mac
, buf
+ 19))
3521 hostapd_disassoc_accept_mac(hapd
);
3524 } else if (os_strncmp((buf
+ 11), "DEL_MAC ", 8) == 0) {
3525 hostapd_ctrl_iface_acl_del_mac(
3526 &hapd
->conf
->accept_mac
,
3527 &hapd
->conf
->num_accept_mac
, buf
+ 19);
3528 } else if (os_strcmp(buf
+ 11, "SHOW") == 0) {
3529 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3530 hapd
->conf
->accept_mac
,
3531 hapd
->conf
->num_accept_mac
, reply
, reply_size
);
3532 } else if (os_strcmp(buf
+ 11, "CLEAR") == 0) {
3533 hostapd_ctrl_iface_acl_clear_list(
3534 &hapd
->conf
->accept_mac
,
3535 &hapd
->conf
->num_accept_mac
);
3537 } else if (os_strncmp(buf
, "DENY_ACL ", 9) == 0) {
3538 if (os_strncmp(buf
+ 9, "ADD_MAC ", 8) == 0) {
3539 if (!hostapd_ctrl_iface_acl_add_mac(
3540 &hapd
->conf
->deny_mac
,
3541 &hapd
->conf
->num_deny_mac
, buf
+ 17))
3542 hostapd_disassoc_deny_mac(hapd
);
3543 } else if (os_strncmp(buf
+ 9, "DEL_MAC ", 8) == 0) {
3544 hostapd_ctrl_iface_acl_del_mac(
3545 &hapd
->conf
->deny_mac
,
3546 &hapd
->conf
->num_deny_mac
, buf
+ 17);
3547 } else if (os_strcmp(buf
+ 9, "SHOW") == 0) {
3548 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3549 hapd
->conf
->deny_mac
,
3550 hapd
->conf
->num_deny_mac
, reply
, reply_size
);
3551 } else if (os_strcmp(buf
+ 9, "CLEAR") == 0) {
3552 hostapd_ctrl_iface_acl_clear_list(
3553 &hapd
->conf
->deny_mac
,
3554 &hapd
->conf
->num_deny_mac
);
3557 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
3558 res
= hostapd_dpp_qr_code(hapd
, buf
+ 12);
3562 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3563 if (os_snprintf_error(reply_size
, reply_len
))
3566 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
3567 res
= hostapd_dpp_nfc_uri(hapd
, buf
+ 12);
3571 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3572 if (os_snprintf_error(reply_size
, reply_len
))
3575 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
3576 res
= hostapd_dpp_nfc_handover_req(hapd
, buf
+ 20);
3580 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3581 if (os_snprintf_error(reply_size
, reply_len
))
3584 } else if (os_strncmp(buf
, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
3585 res
= hostapd_dpp_nfc_handover_sel(hapd
, buf
+ 20);
3589 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3590 if (os_snprintf_error(reply_size
, reply_len
))
3593 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
3594 res
= dpp_bootstrap_gen(hapd
->iface
->interfaces
->dpp
, buf
+ 18);
3598 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3599 if (os_snprintf_error(reply_size
, reply_len
))
3602 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
3603 if (dpp_bootstrap_remove(hapd
->iface
->interfaces
->dpp
,
3606 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
3609 uri
= dpp_bootstrap_get_uri(hapd
->iface
->interfaces
->dpp
,
3614 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
3615 if (os_snprintf_error(reply_size
, reply_len
))
3618 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
3619 reply_len
= dpp_bootstrap_info(hapd
->iface
->interfaces
->dpp
,
3622 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_SET ", 18) == 0) {
3623 if (dpp_bootstrap_set(hapd
->iface
->interfaces
->dpp
,
3625 os_strchr(buf
+ 18, ' ')) < 0)
3627 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
3628 if (hostapd_dpp_auth_init(hapd
, buf
+ 13) < 0)
3630 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
3631 if (hostapd_dpp_listen(hapd
, buf
+ 11) < 0)
3633 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
3634 hostapd_dpp_stop(hapd
);
3635 hostapd_dpp_listen_stop(hapd
);
3636 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
3637 res
= dpp_configurator_add(hapd
->iface
->interfaces
->dpp
,
3642 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3643 if (os_snprintf_error(reply_size
, reply_len
))
3646 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
3647 if (dpp_configurator_remove(hapd
->iface
->interfaces
->dpp
,
3650 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
3651 if (hostapd_dpp_configurator_sign(hapd
, buf
+ 21) < 0)
3653 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
3654 reply_len
= dpp_configurator_get_key_id(
3655 hapd
->iface
->interfaces
->dpp
,
3658 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
3659 res
= hostapd_dpp_pkex_add(hapd
, buf
+ 12);
3663 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3664 if (os_snprintf_error(reply_size
, reply_len
))
3667 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
3668 if (hostapd_dpp_pkex_remove(hapd
, buf
+ 16) < 0)
3670 #endif /* CONFIG_DPP */
3671 #ifdef RADIUS_SERVER
3672 } else if (os_strncmp(buf
, "DAC_REQUEST ", 12) == 0) {
3673 if (radius_server_dac_request(hapd
->radius_srv
, buf
+ 12) < 0)
3675 #endif /* RADIUS_SERVER */
3676 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
3677 reply_len
= hostapd_ctrl_iface_get_capability(
3678 hapd
, buf
+ 15, reply
, reply_size
);
3680 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
3684 if (reply_len
< 0) {
3685 os_memcpy(reply
, "FAIL\n", 5);
3693 static void hostapd_ctrl_iface_receive(int sock
, void *eloop_ctx
,
3696 struct hostapd_data
*hapd
= eloop_ctx
;
3699 struct sockaddr_storage from
;
3700 socklen_t fromlen
= sizeof(from
);
3701 char *reply
, *pos
= buf
;
3702 const int reply_size
= 4096;
3704 int level
= MSG_DEBUG
;
3705 #ifdef CONFIG_CTRL_IFACE_UDP
3706 unsigned char lcookie
[CTRL_IFACE_COOKIE_LEN
];
3707 #endif /* CONFIG_CTRL_IFACE_UDP */
3709 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
3710 (struct sockaddr
*) &from
, &fromlen
);
3712 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
3718 reply
= os_malloc(reply_size
);
3719 if (reply
== NULL
) {
3720 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
3722 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3728 #ifdef CONFIG_CTRL_IFACE_UDP
3729 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
3730 os_memcpy(reply
, "COOKIE=", 7);
3731 wpa_snprintf_hex(reply
+ 7, 2 * CTRL_IFACE_COOKIE_LEN
+ 1,
3732 hapd
->ctrl_iface_cookie
,
3733 CTRL_IFACE_COOKIE_LEN
);
3734 reply_len
= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
3738 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
3739 hexstr2bin(buf
+ 7, lcookie
, CTRL_IFACE_COOKIE_LEN
) < 0) {
3740 wpa_printf(MSG_DEBUG
,
3741 "CTRL: No cookie in the request - drop request");
3746 if (os_memcmp(hapd
->ctrl_iface_cookie
, lcookie
,
3747 CTRL_IFACE_COOKIE_LEN
) != 0) {
3748 wpa_printf(MSG_DEBUG
,
3749 "CTRL: Invalid cookie in the request - drop request");
3754 pos
= buf
+ 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
3757 #endif /* CONFIG_CTRL_IFACE_UDP */
3759 if (os_strcmp(pos
, "PING") == 0)
3760 level
= MSG_EXCESSIVE
;
3761 wpa_hexdump_ascii(level
, "RX ctrl_iface", pos
, res
);
3763 reply_len
= hostapd_ctrl_iface_receive_process(hapd
, pos
,
3767 #ifdef CONFIG_CTRL_IFACE_UDP
3769 #endif /* CONFIG_CTRL_IFACE_UDP */
3770 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
3772 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3779 #ifndef CONFIG_CTRL_IFACE_UDP
3780 static char * hostapd_ctrl_iface_path(struct hostapd_data
*hapd
)
3785 if (hapd
->conf
->ctrl_interface
== NULL
)
3788 len
= os_strlen(hapd
->conf
->ctrl_interface
) +
3789 os_strlen(hapd
->conf
->iface
) + 2;
3790 buf
= os_malloc(len
);
3794 os_snprintf(buf
, len
, "%s/%s",
3795 hapd
->conf
->ctrl_interface
, hapd
->conf
->iface
);
3796 buf
[len
- 1] = '\0';
3799 #endif /* CONFIG_CTRL_IFACE_UDP */
3802 static void hostapd_ctrl_iface_msg_cb(void *ctx
, int level
,
3803 enum wpa_msg_type type
,
3804 const char *txt
, size_t len
)
3806 struct hostapd_data
*hapd
= ctx
;
3809 hostapd_ctrl_iface_send(hapd
, level
, type
, txt
, len
);
3813 int hostapd_ctrl_iface_init(struct hostapd_data
*hapd
)
3815 #ifdef CONFIG_CTRL_IFACE_UDP
3816 int port
= HOSTAPD_CTRL_IFACE_PORT
;
3818 char port_str
[40], *tmp
;
3820 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3823 if (hapd
->ctrl_sock
> -1) {
3824 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3828 if (hapd
->conf
->ctrl_interface
== NULL
)
3831 pos
= os_strstr(hapd
->conf
->ctrl_interface
, "udp:");
3836 wpa_printf(MSG_ERROR
, "Invalid ctrl_iface UDP port");
3841 dl_list_init(&hapd
->ctrl_dst
);
3842 hapd
->ctrl_sock
= -1;
3843 os_get_random(hapd
->ctrl_iface_cookie
, CTRL_IFACE_COOKIE_LEN
);
3845 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3846 hints
.ai_flags
= AI_PASSIVE
;
3847 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3849 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3850 hints
.ai_family
= AF_INET6
;
3851 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3852 hints
.ai_family
= AF_INET
;
3853 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3854 hints
.ai_socktype
= SOCK_DGRAM
;
3857 os_snprintf(p
, sizeof(p
), "%d", port
);
3858 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3860 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3865 hapd
->ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3867 if (hapd
->ctrl_sock
< 0) {
3868 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3872 if (bind(hapd
->ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) < 0) {
3874 if ((HOSTAPD_CTRL_IFACE_PORT
- port
) <
3875 HOSTAPD_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3877 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3881 freeaddrinfo(saveres
);
3883 os_snprintf(port_str
, sizeof(port_str
), "udp:%d", port
);
3884 tmp
= os_strdup(port_str
);
3886 os_free(hapd
->conf
->ctrl_interface
);
3887 hapd
->conf
->ctrl_interface
= tmp
;
3889 wpa_printf(MSG_DEBUG
, "ctrl_iface_init UDP port: %d", port
);
3891 if (eloop_register_read_sock(hapd
->ctrl_sock
,
3892 hostapd_ctrl_iface_receive
, hapd
, NULL
) <
3894 hostapd_ctrl_iface_deinit(hapd
);
3898 hapd
->msg_ctx
= hapd
;
3899 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3904 if (hapd
->ctrl_sock
>= 0)
3905 close(hapd
->ctrl_sock
);
3907 #else /* CONFIG_CTRL_IFACE_UDP */
3908 struct sockaddr_un addr
;
3912 if (hapd
->ctrl_sock
> -1) {
3913 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3917 dl_list_init(&hapd
->ctrl_dst
);
3919 if (hapd
->conf
->ctrl_interface
== NULL
)
3922 if (mkdir(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3923 if (errno
== EEXIST
) {
3924 wpa_printf(MSG_DEBUG
, "Using existing control "
3925 "interface directory.");
3927 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3933 if (hapd
->conf
->ctrl_interface_gid_set
&&
3934 lchown(hapd
->conf
->ctrl_interface
, -1,
3935 hapd
->conf
->ctrl_interface_gid
) < 0) {
3936 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3941 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3942 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3943 lchown(hapd
->conf
->ctrl_interface
, -1,
3944 hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3945 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3952 * Android is using umask 0077 which would leave the control interface
3953 * directory without group access. This breaks things since Wi-Fi
3954 * framework assumes that this directory can be accessed by other
3955 * applications in the wifi group. Fix this by adding group access even
3956 * if umask value would prevent this.
3958 if (chmod(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3959 wpa_printf(MSG_ERROR
, "CTRL: Could not chmod directory: %s",
3961 /* Try to continue anyway */
3963 #endif /* ANDROID */
3965 if (os_strlen(hapd
->conf
->ctrl_interface
) + 1 +
3966 os_strlen(hapd
->conf
->iface
) >= sizeof(addr
.sun_path
))
3969 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
3971 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
3975 os_memset(&addr
, 0, sizeof(addr
));
3977 addr
.sun_len
= sizeof(addr
);
3978 #endif /* __FreeBSD__ */
3979 addr
.sun_family
= AF_UNIX
;
3980 fname
= hostapd_ctrl_iface_path(hapd
);
3983 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
3984 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3985 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
3987 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3988 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
3989 " allow connections - assuming it was left"
3990 "over from forced program termination");
3991 if (unlink(fname
) < 0) {
3992 wpa_printf(MSG_ERROR
,
3993 "Could not unlink existing ctrl_iface socket '%s': %s",
3994 fname
, strerror(errno
));
3997 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
3999 wpa_printf(MSG_ERROR
,
4000 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
4004 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
4005 "ctrl_iface socket '%s'", fname
);
4007 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
4008 "be in use - cannot override it");
4009 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
4010 "not used anymore", fname
);
4017 if (hapd
->conf
->ctrl_interface_gid_set
&&
4018 lchown(fname
, -1, hapd
->conf
->ctrl_interface_gid
) < 0) {
4019 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
4024 if (!hapd
->conf
->ctrl_interface_gid_set
&&
4025 hapd
->iface
->interfaces
->ctrl_iface_group
&&
4026 lchown(fname
, -1, hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
4027 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
4032 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
4033 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
4039 hapd
->ctrl_sock
= s
;
4040 if (eloop_register_read_sock(s
, hostapd_ctrl_iface_receive
, hapd
,
4042 hostapd_ctrl_iface_deinit(hapd
);
4045 hapd
->msg_ctx
= hapd
;
4046 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4058 #endif /* CONFIG_CTRL_IFACE_UDP */
4062 void hostapd_ctrl_iface_deinit(struct hostapd_data
*hapd
)
4064 struct wpa_ctrl_dst
*dst
, *prev
;
4066 if (hapd
->ctrl_sock
> -1) {
4067 #ifndef CONFIG_CTRL_IFACE_UDP
4069 #endif /* !CONFIG_CTRL_IFACE_UDP */
4071 eloop_unregister_read_sock(hapd
->ctrl_sock
);
4072 close(hapd
->ctrl_sock
);
4073 hapd
->ctrl_sock
= -1;
4074 #ifndef CONFIG_CTRL_IFACE_UDP
4075 fname
= hostapd_ctrl_iface_path(hapd
);
4080 if (hapd
->conf
->ctrl_interface
&&
4081 rmdir(hapd
->conf
->ctrl_interface
) < 0) {
4082 if (errno
== ENOTEMPTY
) {
4083 wpa_printf(MSG_DEBUG
, "Control interface "
4084 "directory not empty - leaving it "
4087 wpa_printf(MSG_ERROR
,
4088 "rmdir[ctrl_interface=%s]: %s",
4089 hapd
->conf
->ctrl_interface
,
4093 #endif /* !CONFIG_CTRL_IFACE_UDP */
4096 dl_list_for_each_safe(dst
, prev
, &hapd
->ctrl_dst
, struct wpa_ctrl_dst
,
4100 #ifdef CONFIG_TESTING_OPTIONS
4101 l2_packet_deinit(hapd
->l2_test
);
4102 hapd
->l2_test
= NULL
;
4103 #endif /* CONFIG_TESTING_OPTIONS */
4107 static int hostapd_ctrl_iface_add(struct hapd_interfaces
*interfaces
,
4110 if (hostapd_add_iface(interfaces
, buf
) < 0) {
4111 wpa_printf(MSG_ERROR
, "Adding interface %s failed", buf
);
4118 static int hostapd_ctrl_iface_remove(struct hapd_interfaces
*interfaces
,
4121 if (hostapd_remove_iface(interfaces
, buf
) < 0) {
4122 wpa_printf(MSG_ERROR
, "Removing interface %s failed", buf
);
4129 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces
*interfaces
,
4130 struct sockaddr_storage
*from
,
4131 socklen_t fromlen
, char *input
)
4133 return ctrl_iface_attach(&interfaces
->global_ctrl_dst
, from
, fromlen
,
4138 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces
*interfaces
,
4139 struct sockaddr_storage
*from
,
4142 return ctrl_iface_detach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
4146 static void hostapd_ctrl_iface_flush(struct hapd_interfaces
*interfaces
)
4148 #ifdef CONFIG_WPS_TESTING
4149 wps_version_number
= 0x20;
4150 wps_testing_dummy_cred
= 0;
4151 wps_corrupt_pkhash
= 0;
4152 #endif /* CONFIG_WPS_TESTING */
4154 #ifdef CONFIG_TESTING_OPTIONS
4156 dpp_test
= DPP_TEST_DISABLED
;
4157 #endif /* CONFIG_DPP */
4158 #endif /* CONFIG_TESTING_OPTIONS */
4161 dpp_global_clear(interfaces
->dpp
);
4162 #endif /* CONFIG_DPP */
4169 hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces
*interfaces
,
4172 char ifname
[IFNAMSIZ
+ 1];
4173 struct fst_iface_cfg cfg
;
4174 struct hostapd_data
*hapd
;
4175 struct fst_wpa_obj iface_obj
;
4177 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
4178 hapd
= hostapd_get_iface(interfaces
, ifname
);
4180 if (hapd
->iface
->fst
) {
4181 wpa_printf(MSG_INFO
, "FST: Already attached");
4184 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
4185 hapd
->iface
->fst
= fst_attach(ifname
, hapd
->own_addr
,
4187 if (hapd
->iface
->fst
)
4197 hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces
*interfaces
,
4200 char ifname
[IFNAMSIZ
+ 1];
4201 struct hostapd_data
* hapd
;
4203 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
4204 hapd
= hostapd_get_iface(interfaces
, ifname
);
4206 if (!fst_iface_detach(ifname
)) {
4207 hapd
->iface
->fst
= NULL
;
4208 hapd
->iface
->fst_ies
= NULL
;
4217 #endif /* CONFIG_FST */
4220 static struct hostapd_data
*
4221 hostapd_interfaces_get_hapd(struct hapd_interfaces
*interfaces
,
4226 for (i
= 0; i
< interfaces
->count
; i
++) {
4227 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
4229 for (j
= 0; j
< iface
->num_bss
; j
++) {
4230 struct hostapd_data
*hapd
;
4232 hapd
= iface
->bss
[j
];
4233 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
4242 static int hostapd_ctrl_iface_dup_param(struct hostapd_data
*src_hapd
,
4243 struct hostapd_data
*dst_hapd
,
4249 value
= os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4251 wpa_printf(MSG_ERROR
,
4252 "DUP: cannot allocate buffer to stringify %s",
4257 if (os_strcmp(param
, "wpa") == 0) {
4258 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%d",
4259 src_hapd
->conf
->wpa
);
4260 } else if (os_strcmp(param
, "wpa_key_mgmt") == 0 &&
4261 src_hapd
->conf
->wpa_key_mgmt
) {
4262 res
= hostapd_ctrl_iface_get_key_mgmt(
4263 src_hapd
, value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4264 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, res
))
4265 goto error_stringify
;
4266 } else if (os_strcmp(param
, "wpa_pairwise") == 0 &&
4267 src_hapd
->conf
->wpa_pairwise
) {
4268 res
= wpa_write_ciphers(value
,
4269 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4270 src_hapd
->conf
->wpa_pairwise
, " ");
4272 goto error_stringify
;
4273 } else if (os_strcmp(param
, "rsn_pairwise") == 0 &&
4274 src_hapd
->conf
->rsn_pairwise
) {
4275 res
= wpa_write_ciphers(value
,
4276 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4277 src_hapd
->conf
->rsn_pairwise
, " ");
4279 goto error_stringify
;
4280 } else if (os_strcmp(param
, "wpa_passphrase") == 0 &&
4281 src_hapd
->conf
->ssid
.wpa_passphrase
) {
4282 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%s",
4283 src_hapd
->conf
->ssid
.wpa_passphrase
);
4284 } else if (os_strcmp(param
, "wpa_psk") == 0 &&
4285 src_hapd
->conf
->ssid
.wpa_psk_set
) {
4286 wpa_snprintf_hex(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4287 src_hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
4289 wpa_printf(MSG_WARNING
, "DUP: %s cannot be duplicated", param
);
4293 res
= hostapd_set_iface(dst_hapd
->iconf
, dst_hapd
->conf
, param
, value
);
4298 wpa_printf(MSG_ERROR
, "DUP: cannot stringify %s", param
);
4306 hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces
*interfaces
,
4308 char *reply
, int reply_size
)
4313 struct hostapd_iface
*iface
;
4317 show_ctrl
= !!os_strstr(input
, "ctrl");
4320 end
= reply
+ reply_size
;
4322 for (i
= 0; i
< interfaces
->count
; i
++) {
4323 iface
= interfaces
->iface
[i
];
4325 for (j
= 0; j
< iface
->num_bss
; j
++) {
4326 struct hostapd_bss_config
*conf
;
4328 conf
= iface
->conf
->bss
[j
];
4330 res
= os_snprintf(pos
, end
- pos
,
4331 "%s ctrl_iface=%s\n",
4333 conf
->ctrl_interface
?
4334 conf
->ctrl_interface
: "N/A");
4336 res
= os_snprintf(pos
, end
- pos
, "%s\n",
4338 if (os_snprintf_error(end
- pos
, res
)) {
4351 hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces
*interfaces
,
4354 char *p_start
= cmd
, *p_end
;
4355 struct hostapd_data
*src_hapd
, *dst_hapd
;
4357 /* cmd: "<src ifname> <dst ifname> <variable name> */
4359 p_end
= os_strchr(p_start
, ' ');
4361 wpa_printf(MSG_ERROR
, "DUP: no src ifname found in cmd: '%s'",
4367 src_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4369 wpa_printf(MSG_ERROR
, "DUP: no src ifname found: '%s'",
4374 p_start
= p_end
+ 1;
4375 p_end
= os_strchr(p_start
, ' ');
4377 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found in cmd: '%s'",
4383 dst_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4385 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found: '%s'",
4390 p_start
= p_end
+ 1;
4391 return hostapd_ctrl_iface_dup_param(src_hapd
, dst_hapd
, p_start
);
4395 static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces
*interfaces
,
4397 char *buf
, char *reply
,
4399 struct sockaddr_storage
*from
,
4402 struct hostapd_data
*hapd
;
4404 hapd
= hostapd_interfaces_get_hapd(interfaces
, ifname
);
4408 res
= os_snprintf(reply
, reply_size
, "FAIL-NO-IFNAME-MATCH\n");
4409 if (os_snprintf_error(reply_size
, res
))
4414 return hostapd_ctrl_iface_receive_process(hapd
, buf
, reply
,reply_size
,
4419 static void hostapd_global_ctrl_iface_receive(int sock
, void *eloop_ctx
,
4422 struct hapd_interfaces
*interfaces
= eloop_ctx
;
4423 char buffer
[256], *buf
= buffer
;
4425 struct sockaddr_storage from
;
4426 socklen_t fromlen
= sizeof(from
);
4429 const int reply_size
= 4096;
4430 #ifdef CONFIG_CTRL_IFACE_UDP
4431 unsigned char lcookie
[CTRL_IFACE_COOKIE_LEN
];
4432 #endif /* CONFIG_CTRL_IFACE_UDP */
4434 res
= recvfrom(sock
, buffer
, sizeof(buffer
) - 1, 0,
4435 (struct sockaddr
*) &from
, &fromlen
);
4437 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
4442 wpa_printf(MSG_DEBUG
, "Global ctrl_iface command: %s", buf
);
4444 reply
= os_malloc(reply_size
);
4445 if (reply
== NULL
) {
4446 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
4448 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4454 os_memcpy(reply
, "OK\n", 3);
4457 #ifdef CONFIG_CTRL_IFACE_UDP
4458 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
4459 os_memcpy(reply
, "COOKIE=", 7);
4460 wpa_snprintf_hex(reply
+ 7, 2 * CTRL_IFACE_COOKIE_LEN
+ 1,
4461 interfaces
->ctrl_iface_cookie
,
4462 CTRL_IFACE_COOKIE_LEN
);
4463 reply_len
= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
4467 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
4468 hexstr2bin(buf
+ 7, lcookie
, CTRL_IFACE_COOKIE_LEN
) < 0) {
4469 wpa_printf(MSG_DEBUG
,
4470 "CTRL: No cookie in the request - drop request");
4475 if (os_memcmp(interfaces
->ctrl_iface_cookie
, lcookie
,
4476 CTRL_IFACE_COOKIE_LEN
) != 0) {
4477 wpa_printf(MSG_DEBUG
,
4478 "CTRL: Invalid cookie in the request - drop request");
4483 buf
+= 7 + 2 * CTRL_IFACE_COOKIE_LEN
;
4486 #endif /* CONFIG_CTRL_IFACE_UDP */
4488 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
4489 char *pos
= os_strchr(buf
+ 7, ' ');
4493 reply_len
= hostapd_global_ctrl_iface_ifname(
4494 interfaces
, buf
+ 7, pos
, reply
, reply_size
,
4500 if (os_strcmp(buf
, "PING") == 0) {
4501 os_memcpy(reply
, "PONG\n", 5);
4503 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
4504 if (wpa_debug_reopen_file() < 0)
4506 } else if (os_strcmp(buf
, "FLUSH") == 0) {
4507 hostapd_ctrl_iface_flush(interfaces
);
4508 } else if (os_strncmp(buf
, "ADD ", 4) == 0) {
4509 if (hostapd_ctrl_iface_add(interfaces
, buf
+ 4) < 0)
4511 } else if (os_strncmp(buf
, "REMOVE ", 7) == 0) {
4512 if (hostapd_ctrl_iface_remove(interfaces
, buf
+ 7) < 0)
4514 } else if (os_strcmp(buf
, "ATTACH") == 0) {
4515 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4518 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
4519 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4522 } else if (os_strcmp(buf
, "DETACH") == 0) {
4523 if (hostapd_global_ctrl_iface_detach(interfaces
, &from
,
4526 #ifdef CONFIG_MODULE_TESTS
4527 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
4528 if (hapd_module_tests() < 0)
4530 #endif /* CONFIG_MODULE_TESTS */
4532 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
4533 if (!hostapd_global_ctrl_iface_fst_attach(interfaces
, buf
+ 11))
4534 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4537 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
4538 if (!hostapd_global_ctrl_iface_fst_detach(interfaces
, buf
+ 11))
4539 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4542 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
4543 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
4544 #endif /* CONFIG_FST */
4545 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
4546 if (!hostapd_global_ctrl_iface_dup_network(interfaces
,
4548 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4551 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
4552 reply_len
= hostapd_global_ctrl_iface_interfaces(
4553 interfaces
, buf
+ 10, reply
, sizeof(buffer
));
4554 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4557 wpa_printf(MSG_DEBUG
, "Unrecognized global ctrl_iface command "
4563 if (reply_len
< 0) {
4564 os_memcpy(reply
, "FAIL\n", 5);
4568 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
4570 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4577 #ifndef CONFIG_CTRL_IFACE_UDP
4578 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces
*interface
)
4583 if (interface
->global_iface_path
== NULL
)
4586 len
= os_strlen(interface
->global_iface_path
) +
4587 os_strlen(interface
->global_iface_name
) + 2;
4588 buf
= os_malloc(len
);
4592 os_snprintf(buf
, len
, "%s/%s", interface
->global_iface_path
,
4593 interface
->global_iface_name
);
4594 buf
[len
- 1] = '\0';
4597 #endif /* CONFIG_CTRL_IFACE_UDP */
4600 int hostapd_global_ctrl_iface_init(struct hapd_interfaces
*interface
)
4602 #ifdef CONFIG_CTRL_IFACE_UDP
4603 int port
= HOSTAPD_GLOBAL_CTRL_IFACE_PORT
;
4606 struct addrinfo hints
= { 0 }, *res
, *saveres
;
4609 if (interface
->global_ctrl_sock
> -1) {
4610 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
4614 if (interface
->global_iface_path
== NULL
)
4617 pos
= os_strstr(interface
->global_iface_path
, "udp:");
4622 wpa_printf(MSG_ERROR
, "Invalid global ctrl UDP port");
4627 os_get_random(interface
->ctrl_iface_cookie
, CTRL_IFACE_COOKIE_LEN
);
4629 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4630 hints
.ai_flags
= AI_PASSIVE
;
4631 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4633 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
4634 hints
.ai_family
= AF_INET6
;
4635 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4636 hints
.ai_family
= AF_INET
;
4637 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4638 hints
.ai_socktype
= SOCK_DGRAM
;
4641 os_snprintf(p
, sizeof(p
), "%d", port
);
4642 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
4644 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
4649 interface
->global_ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
4651 if (interface
->global_ctrl_sock
< 0) {
4652 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
4656 if (bind(interface
->global_ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) <
4659 if ((port
- HOSTAPD_GLOBAL_CTRL_IFACE_PORT
) <
4660 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT
&& !pos
)
4662 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
4666 freeaddrinfo(saveres
);
4668 wpa_printf(MSG_DEBUG
, "global ctrl_iface_init UDP port: %d", port
);
4670 if (eloop_register_read_sock(interface
->global_ctrl_sock
,
4671 hostapd_global_ctrl_iface_receive
,
4672 interface
, NULL
) < 0) {
4673 hostapd_global_ctrl_iface_deinit(interface
);
4677 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4682 if (interface
->global_ctrl_sock
>= 0)
4683 close(interface
->global_ctrl_sock
);
4685 #else /* CONFIG_CTRL_IFACE_UDP */
4686 struct sockaddr_un addr
;
4690 if (interface
->global_iface_path
== NULL
) {
4691 wpa_printf(MSG_DEBUG
, "ctrl_iface not configured!");
4695 if (mkdir(interface
->global_iface_path
, S_IRWXU
| S_IRWXG
) < 0) {
4696 if (errno
== EEXIST
) {
4697 wpa_printf(MSG_DEBUG
, "Using existing control "
4698 "interface directory.");
4700 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
4704 } else if (interface
->ctrl_iface_group
&&
4705 lchown(interface
->global_iface_path
, -1,
4706 interface
->ctrl_iface_group
) < 0) {
4707 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4712 if (os_strlen(interface
->global_iface_path
) + 1 +
4713 os_strlen(interface
->global_iface_name
) >= sizeof(addr
.sun_path
))
4716 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
4718 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
4722 os_memset(&addr
, 0, sizeof(addr
));
4724 addr
.sun_len
= sizeof(addr
);
4725 #endif /* __FreeBSD__ */
4726 addr
.sun_family
= AF_UNIX
;
4727 fname
= hostapd_global_ctrl_iface_path(interface
);
4730 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
4731 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4732 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
4734 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4735 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
4736 " allow connections - assuming it was left"
4737 "over from forced program termination");
4738 if (unlink(fname
) < 0) {
4739 wpa_printf(MSG_ERROR
,
4740 "Could not unlink existing ctrl_iface socket '%s': %s",
4741 fname
, strerror(errno
));
4744 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
4746 wpa_printf(MSG_ERROR
, "bind(PF_UNIX): %s",
4750 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
4751 "ctrl_iface socket '%s'", fname
);
4753 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
4754 "be in use - cannot override it");
4755 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
4756 "not used anymore", fname
);
4763 if (interface
->ctrl_iface_group
&&
4764 lchown(fname
, -1, interface
->ctrl_iface_group
) < 0) {
4765 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4770 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
4771 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
4777 interface
->global_ctrl_sock
= s
;
4778 eloop_register_read_sock(s
, hostapd_global_ctrl_iface_receive
,
4781 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4793 #endif /* CONFIG_CTRL_IFACE_UDP */
4797 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces
*interfaces
)
4799 #ifndef CONFIG_CTRL_IFACE_UDP
4801 #endif /* CONFIG_CTRL_IFACE_UDP */
4802 struct wpa_ctrl_dst
*dst
, *prev
;
4804 if (interfaces
->global_ctrl_sock
> -1) {
4805 eloop_unregister_read_sock(interfaces
->global_ctrl_sock
);
4806 close(interfaces
->global_ctrl_sock
);
4807 interfaces
->global_ctrl_sock
= -1;
4808 #ifndef CONFIG_CTRL_IFACE_UDP
4809 fname
= hostapd_global_ctrl_iface_path(interfaces
);
4815 if (interfaces
->global_iface_path
&&
4816 rmdir(interfaces
->global_iface_path
) < 0) {
4817 if (errno
== ENOTEMPTY
) {
4818 wpa_printf(MSG_DEBUG
, "Control interface "
4819 "directory not empty - leaving it "
4822 wpa_printf(MSG_ERROR
,
4823 "rmdir[ctrl_interface=%s]: %s",
4824 interfaces
->global_iface_path
,
4828 #endif /* CONFIG_CTRL_IFACE_UDP */
4831 os_free(interfaces
->global_iface_path
);
4832 interfaces
->global_iface_path
= NULL
;
4834 dl_list_for_each_safe(dst
, prev
, &interfaces
->global_ctrl_dst
,
4835 struct wpa_ctrl_dst
, list
)
4840 static int hostapd_ctrl_check_event_enabled(struct wpa_ctrl_dst
*dst
,
4843 /* Enable Probe Request events based on explicit request.
4844 * Other events are enabled by default.
4846 if (str_starts(buf
, RX_PROBE_REQUEST
))
4847 return !!(dst
->events
& WPA_EVENT_RX_PROBE_REQUEST
);
4852 static void hostapd_ctrl_iface_send_internal(int sock
, struct dl_list
*ctrl_dst
,
4853 const char *ifname
, int level
,
4854 const char *buf
, size_t len
)
4856 struct wpa_ctrl_dst
*dst
, *next
;
4862 if (sock
< 0 || dl_list_empty(ctrl_dst
))
4865 res
= os_snprintf(levelstr
, sizeof(levelstr
), "<%d>", level
);
4866 if (os_snprintf_error(sizeof(levelstr
), res
))
4870 io
[idx
].iov_base
= "IFNAME=";
4871 io
[idx
].iov_len
= 7;
4873 io
[idx
].iov_base
= (char *) ifname
;
4874 io
[idx
].iov_len
= os_strlen(ifname
);
4876 io
[idx
].iov_base
= " ";
4877 io
[idx
].iov_len
= 1;
4880 io
[idx
].iov_base
= levelstr
;
4881 io
[idx
].iov_len
= os_strlen(levelstr
);
4883 io
[idx
].iov_base
= (char *) buf
;
4884 io
[idx
].iov_len
= len
;
4886 os_memset(&msg
, 0, sizeof(msg
));
4888 msg
.msg_iovlen
= idx
;
4891 dl_list_for_each_safe(dst
, next
, ctrl_dst
, struct wpa_ctrl_dst
, list
) {
4892 if ((level
>= dst
->debug_level
) &&
4893 hostapd_ctrl_check_event_enabled(dst
, buf
)) {
4894 sockaddr_print(MSG_DEBUG
, "CTRL_IFACE monitor send",
4895 &dst
->addr
, dst
->addrlen
);
4896 msg
.msg_name
= &dst
->addr
;
4897 msg
.msg_namelen
= dst
->addrlen
;
4898 if (sendmsg(sock
, &msg
, 0) < 0) {
4900 wpa_printf(MSG_INFO
, "CTRL_IFACE monitor[%d]: "
4902 idx
, errno
, strerror(errno
));
4904 if (dst
->errors
> 10 || _errno
== ENOENT
) {
4905 ctrl_iface_detach(ctrl_dst
,
4917 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
4918 enum wpa_msg_type type
,
4919 const char *buf
, size_t len
)
4921 if (type
!= WPA_MSG_NO_GLOBAL
) {
4922 hostapd_ctrl_iface_send_internal(
4923 hapd
->iface
->interfaces
->global_ctrl_sock
,
4924 &hapd
->iface
->interfaces
->global_ctrl_dst
,
4925 type
!= WPA_MSG_PER_INTERFACE
?
4926 NULL
: hapd
->conf
->iface
,
4930 if (type
!= WPA_MSG_ONLY_GLOBAL
) {
4931 hostapd_ctrl_iface_send_internal(
4932 hapd
->ctrl_sock
, &hapd
->ctrl_dst
,
4933 NULL
, level
, buf
, len
);
4937 #endif /* CONFIG_NATIVE_WINDOWS */