2 * hostapd / UNIX domain socket -based control interface
3 * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #ifndef CONFIG_NATIVE_WINDOWS
13 #ifdef CONFIG_TESTING_OPTIONS
15 #include <net/if_ether.h>
17 #include <net/ethernet.h>
19 #include <netinet/ip.h>
20 #endif /* CONFIG_TESTING_OPTIONS */
26 #ifdef CONFIG_CTRL_IFACE_UDP
28 #endif /* CONFIG_CTRL_IFACE_UDP */
30 #include "utils/common.h"
31 #include "utils/eloop.h"
32 #include "utils/module_tests.h"
33 #include "common/version.h"
34 #include "common/ieee802_11_defs.h"
35 #include "common/ctrl_iface_common.h"
37 #include "common/dpp.h"
38 #endif /* CONFIG_DPP */
39 #include "common/wpa_ctrl.h"
40 #include "crypto/tls.h"
41 #include "drivers/driver.h"
42 #include "eapol_auth/eapol_auth_sm.h"
43 #include "radius/radius_client.h"
44 #include "radius/radius_server.h"
45 #include "l2_packet/l2_packet.h"
46 #include "ap/hostapd.h"
47 #include "ap/ap_config.h"
48 #include "ap/ieee802_1x.h"
49 #include "ap/wpa_auth.h"
50 #include "ap/ieee802_11.h"
51 #include "ap/sta_info.h"
52 #include "ap/wps_hostapd.h"
53 #include "ap/ctrl_iface_ap.h"
54 #include "ap/ap_drv_ops.h"
56 #include "ap/wnm_ap.h"
57 #include "ap/wpa_auth.h"
58 #include "ap/beacon.h"
59 #include "ap/neighbor_db.h"
61 #include "ap/dpp_hostapd.h"
62 #include "wps/wps_defs.h"
64 #include "fst/fst_ctrl_iface.h"
65 #include "config_file.h"
66 #include "ctrl_iface.h"
69 #define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
71 #ifdef CONFIG_CTRL_IFACE_UDP
73 static unsigned char cookie
[COOKIE_LEN
];
74 static unsigned char gcookie
[COOKIE_LEN
];
75 #define HOSTAPD_CTRL_IFACE_PORT 8877
76 #define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
77 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
78 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
79 #endif /* CONFIG_CTRL_IFACE_UDP */
81 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
82 enum wpa_msg_type type
,
83 const char *buf
, size_t len
);
86 static int hostapd_ctrl_iface_attach(struct hostapd_data
*hapd
,
87 struct sockaddr_storage
*from
,
88 socklen_t fromlen
, const char *input
)
90 return ctrl_iface_attach(&hapd
->ctrl_dst
, from
, fromlen
, input
);
94 static int hostapd_ctrl_iface_detach(struct hostapd_data
*hapd
,
95 struct sockaddr_storage
*from
,
98 return ctrl_iface_detach(&hapd
->ctrl_dst
, from
, fromlen
);
102 static int hostapd_ctrl_iface_level(struct hostapd_data
*hapd
,
103 struct sockaddr_storage
*from
,
107 return ctrl_iface_level(&hapd
->ctrl_dst
, from
, fromlen
, level
);
111 static int hostapd_ctrl_iface_new_sta(struct hostapd_data
*hapd
,
115 struct sta_info
*sta
;
117 wpa_printf(MSG_DEBUG
, "CTRL_IFACE NEW_STA %s", txtaddr
);
119 if (hwaddr_aton(txtaddr
, addr
))
122 sta
= ap_get_sta(hapd
, addr
);
126 wpa_printf(MSG_DEBUG
, "Add new STA " MACSTR
" based on ctrl_iface "
127 "notification", MAC2STR(addr
));
128 sta
= ap_sta_add(hapd
, addr
);
132 hostapd_new_assoc_sta(hapd
, sta
, 0);
138 static int hostapd_ctrl_iface_sa_query(struct hostapd_data
*hapd
,
142 u8 trans_id
[WLAN_SA_QUERY_TR_ID_LEN
];
144 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SA_QUERY %s", txtaddr
);
146 if (hwaddr_aton(txtaddr
, addr
) ||
147 os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0)
150 ieee802_11_send_sa_query_req(hapd
, addr
, trans_id
);
154 #endif /* NEED_AP_MLME */
158 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data
*hapd
, char *txt
)
160 char *pin
= os_strchr(txt
, ' ');
163 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
170 timeout_txt
= os_strchr(pin
, ' ');
172 *timeout_txt
++ = '\0';
173 timeout
= atoi(timeout_txt
);
174 pos
= os_strchr(timeout_txt
, ' ');
177 if (hwaddr_aton(pos
, addr_buf
) == 0)
183 return hostapd_wps_add_pin(hapd
, addr
, txt
, pin
, timeout
);
187 static int hostapd_ctrl_iface_wps_check_pin(
188 struct hostapd_data
*hapd
, char *cmd
, char *buf
, size_t buflen
)
195 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
196 (u8
*) cmd
, os_strlen(cmd
));
197 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
198 if (*pos
< '0' || *pos
> '9')
202 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
206 if (len
!= 4 && len
!= 8) {
207 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
213 unsigned int pin_val
;
215 if (!wps_pin_valid(pin_val
)) {
216 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
217 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
218 if (os_snprintf_error(buflen
, ret
))
224 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
225 if (os_snprintf_error(buflen
, ret
))
232 #ifdef CONFIG_WPS_NFC
233 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data
*hapd
,
240 len
= os_strlen(pos
);
245 buf
= wpabuf_alloc(len
);
248 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
253 ret
= hostapd_wps_nfc_tag_read(hapd
, buf
);
260 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data
*hapd
,
261 char *cmd
, char *reply
,
268 if (os_strcmp(cmd
, "WPS") == 0)
270 else if (os_strcmp(cmd
, "NDEF") == 0)
275 buf
= hostapd_wps_nfc_config_token(hapd
, ndef
);
279 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
290 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data
*hapd
,
291 char *reply
, size_t max_len
,
297 buf
= hostapd_wps_nfc_token_gen(hapd
, ndef
);
301 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
312 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data
*hapd
,
313 char *cmd
, char *reply
,
316 if (os_strcmp(cmd
, "WPS") == 0)
317 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
320 if (os_strcmp(cmd
, "NDEF") == 0)
321 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
324 if (os_strcmp(cmd
, "enable") == 0)
325 return hostapd_wps_nfc_token_enable(hapd
);
327 if (os_strcmp(cmd
, "disable") == 0) {
328 hostapd_wps_nfc_token_disable(hapd
);
336 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data
*hapd
,
337 char *cmd
, char *reply
,
345 pos
= os_strchr(cmd
, ' ');
350 if (os_strcmp(cmd
, "WPS") == 0)
352 else if (os_strcmp(cmd
, "NDEF") == 0)
357 if (os_strcmp(pos
, "WPS-CR") == 0)
358 buf
= hostapd_wps_nfc_hs_cr(hapd
, ndef
);
364 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
375 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data
*hapd
,
379 struct wpabuf
*req
, *sel
;
381 char *pos
, *role
, *type
, *pos2
;
384 pos
= os_strchr(role
, ' ');
390 pos
= os_strchr(type
, ' ');
395 pos2
= os_strchr(pos
, ' ');
400 len
= os_strlen(pos
);
405 req
= wpabuf_alloc(len
);
408 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
413 len
= os_strlen(pos2
);
420 sel
= wpabuf_alloc(len
);
425 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
431 if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0) {
432 ret
= hostapd_wps_nfc_report_handover(hapd
, req
, sel
);
434 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
435 "reported: role=%s type=%s", role
, type
);
444 #endif /* CONFIG_WPS_NFC */
447 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data
*hapd
, char *txt
,
448 char *buf
, size_t buflen
)
454 pos
= os_strchr(txt
, ' ');
458 if (os_strcmp(txt
, "disable") == 0) {
459 hostapd_wps_ap_pin_disable(hapd
);
460 return os_snprintf(buf
, buflen
, "OK\n");
463 if (os_strcmp(txt
, "random") == 0) {
466 pin_txt
= hostapd_wps_ap_pin_random(hapd
, timeout
);
469 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
472 if (os_strcmp(txt
, "get") == 0) {
473 pin_txt
= hostapd_wps_ap_pin_get(hapd
);
476 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
479 if (os_strcmp(txt
, "set") == 0) {
484 pos
= os_strchr(pos
, ' ');
489 if (os_strlen(pin
) > buflen
)
491 if (hostapd_wps_ap_pin_set(hapd
, pin
, timeout
) < 0)
493 return os_snprintf(buf
, buflen
, "%s", pin
);
500 static int hostapd_ctrl_iface_wps_config(struct hostapd_data
*hapd
, char *txt
)
503 char *ssid
, *auth
, *encr
= NULL
, *key
= NULL
;
506 pos
= os_strchr(txt
, ' ');
512 pos
= os_strchr(pos
, ' ');
516 pos
= os_strchr(pos
, ' ');
523 return hostapd_wps_config_ap(hapd
, ssid
, auth
, encr
, key
);
527 static const char * pbc_status_str(enum pbc_status status
)
530 case WPS_PBC_STATUS_DISABLE
:
532 case WPS_PBC_STATUS_ACTIVE
:
534 case WPS_PBC_STATUS_TIMEOUT
:
536 case WPS_PBC_STATUS_OVERLAP
:
544 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data
*hapd
,
545 char *buf
, size_t buflen
)
553 ret
= os_snprintf(pos
, end
- pos
, "PBC Status: %s\n",
554 pbc_status_str(hapd
->wps_stats
.pbc_status
));
556 if (os_snprintf_error(end
- pos
, ret
))
560 ret
= os_snprintf(pos
, end
- pos
, "Last WPS result: %s\n",
561 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
563 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
564 "Failed" : "None")));
566 if (os_snprintf_error(end
- pos
, ret
))
570 /* If status == Failure - Add possible Reasons */
571 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
572 hapd
->wps_stats
.failure_reason
> 0) {
573 ret
= os_snprintf(pos
, end
- pos
,
574 "Failure Reason: %s\n",
575 wps_ei_str(hapd
->wps_stats
.failure_reason
));
577 if (os_snprintf_error(end
- pos
, ret
))
582 if (hapd
->wps_stats
.status
) {
583 ret
= os_snprintf(pos
, end
- pos
, "Peer Address: " MACSTR
"\n",
584 MAC2STR(hapd
->wps_stats
.peer_addr
));
586 if (os_snprintf_error(end
- pos
, ret
))
594 #endif /* CONFIG_WPS */
598 static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data
*hapd
,
604 if (hwaddr_aton(cmd
, addr
))
617 return hs20_send_wnm_notification(hapd
, addr
, 1, url
);
621 static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data
*hapd
,
625 int code
, reauth_delay
, ret
;
630 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
631 if (hwaddr_aton(cmd
, addr
))
634 pos
= os_strchr(cmd
, ' ');
640 pos
= os_strchr(pos
, ' ');
644 reauth_delay
= atoi(pos
);
647 pos
= os_strchr(pos
, ' ');
650 url_len
= os_strlen(pos
);
653 req
= wpabuf_alloc(4 + url_len
);
656 wpabuf_put_u8(req
, code
);
657 wpabuf_put_le16(req
, reauth_delay
);
658 wpabuf_put_u8(req
, url_len
);
660 wpabuf_put_data(req
, pos
, url_len
);
662 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to " MACSTR
663 " to indicate imminent deauthentication (code=%d "
664 "reauth_delay=%d)", MAC2STR(addr
), code
, reauth_delay
);
665 ret
= hs20_send_wnm_notification_deauth_req(hapd
, addr
, req
);
670 #endif /* CONFIG_HS20 */
673 #ifdef CONFIG_INTERWORKING
675 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data
*hapd
,
678 u8 qos_map_set
[16 + 2 * 21], count
= 0;
679 const char *pos
= cmd
;
683 if (count
== sizeof(qos_map_set
)) {
684 wpa_printf(MSG_ERROR
, "Too many qos_map_set parameters");
689 if (val
< 0 || val
> 255) {
690 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
694 qos_map_set
[count
++] = val
;
695 pos
= os_strchr(pos
, ',');
701 if (count
< 16 || count
& 1) {
702 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
706 ret
= hostapd_drv_set_qos_map(hapd
, qos_map_set
, count
);
708 wpa_printf(MSG_INFO
, "Failed to set QoS Map Set");
712 os_memcpy(hapd
->conf
->qos_map_set
, qos_map_set
, count
);
713 hapd
->conf
->qos_map_set_len
= count
;
719 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data
*hapd
,
723 struct sta_info
*sta
;
725 u8
*qos_map_set
= hapd
->conf
->qos_map_set
;
726 u8 qos_map_set_len
= hapd
->conf
->qos_map_set_len
;
729 if (!qos_map_set_len
) {
730 wpa_printf(MSG_INFO
, "QoS Map Set is not set");
734 if (hwaddr_aton(cmd
, addr
))
737 sta
= ap_get_sta(hapd
, addr
);
739 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" not found "
740 "for QoS Map Configuration message",
745 if (!sta
->qos_map_enabled
) {
746 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" did not indicate "
747 "support for QoS Map", MAC2STR(addr
));
751 buf
= wpabuf_alloc(2 + 2 + qos_map_set_len
);
755 wpabuf_put_u8(buf
, WLAN_ACTION_QOS
);
756 wpabuf_put_u8(buf
, QOS_QOS_MAP_CONFIG
);
758 /* QoS Map Set Element */
759 wpabuf_put_u8(buf
, WLAN_EID_QOS_MAP_SET
);
760 wpabuf_put_u8(buf
, qos_map_set_len
);
761 wpabuf_put_data(buf
, qos_map_set
, qos_map_set_len
);
763 ret
= hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, addr
,
764 wpabuf_head(buf
), wpabuf_len(buf
));
770 #endif /* CONFIG_INTERWORKING */
775 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data
*hapd
,
780 struct sta_info
*sta
;
782 if (hwaddr_aton(cmd
, addr
))
786 disassoc_timer
= atoi(cmd
+ 17);
788 sta
= ap_get_sta(hapd
, addr
);
790 wpa_printf(MSG_DEBUG
, "Station " MACSTR
791 " not found for disassociation imminent message",
796 return wnm_send_disassoc_imminent(hapd
, sta
, disassoc_timer
);
800 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data
*hapd
,
804 const char *url
, *timerstr
;
806 struct sta_info
*sta
;
808 if (hwaddr_aton(cmd
, addr
))
811 sta
= ap_get_sta(hapd
, addr
);
813 wpa_printf(MSG_DEBUG
, "Station " MACSTR
814 " not found for ESS disassociation imminent message",
820 if (*timerstr
!= ' ')
823 disassoc_timer
= atoi(timerstr
);
824 if (disassoc_timer
< 0 || disassoc_timer
> 65535)
827 url
= os_strchr(timerstr
, ' ');
832 return wnm_send_ess_disassoc_imminent(hapd
, sta
, url
, disassoc_timer
);
836 static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data
*hapd
,
840 const char *pos
, *end
;
841 int disassoc_timer
= 0;
842 struct sta_info
*sta
;
843 u8 req_mode
= 0, valid_int
= 0x01;
852 if (hwaddr_aton(cmd
, addr
)) {
853 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
857 sta
= ap_get_sta(hapd
, addr
);
859 wpa_printf(MSG_DEBUG
, "Station " MACSTR
860 " not found for BSS TM Request message",
865 pos
= os_strstr(cmd
, " disassoc_timer=");
868 disassoc_timer
= atoi(pos
);
869 if (disassoc_timer
< 0 || disassoc_timer
> 65535) {
870 wpa_printf(MSG_DEBUG
, "Invalid disassoc_timer");
875 pos
= os_strstr(cmd
, " valid_int=");
878 valid_int
= atoi(pos
);
881 pos
= os_strstr(cmd
, " bss_term=");
884 req_mode
|= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED
;
885 /* TODO: TSF configurable/learnable */
886 bss_term_dur
[0] = 4; /* Subelement ID */
887 bss_term_dur
[1] = 10; /* Length */
888 os_memset(&bss_term_dur
[2], 0, 8);
889 end
= os_strchr(pos
, ',');
891 wpa_printf(MSG_DEBUG
, "Invalid bss_term data");
895 WPA_PUT_LE16(&bss_term_dur
[10], atoi(end
));
898 nei_len
= ieee802_11_parse_candidate_list(cmd
, nei_rep
,
903 pos
= os_strstr(cmd
, " url=");
907 end
= os_strchr(pos
, ' ');
911 len
= os_strlen(pos
);
912 url
= os_malloc(len
+ 1);
915 os_memcpy(url
, pos
, len
);
917 req_mode
|= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT
;
920 if (os_strstr(cmd
, " pref=1"))
921 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
922 if (os_strstr(cmd
, " abridged=1"))
923 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
924 if (os_strstr(cmd
, " disassoc_imminent=1"))
925 req_mode
|= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
928 pos
= os_strstr(cmd
, "mbo=");
930 unsigned int mbo_reason
, cell_pref
, reassoc_delay
;
933 ret
= sscanf(pos
, "mbo=%u:%u:%u", &mbo_reason
,
934 &reassoc_delay
, &cell_pref
);
936 wpa_printf(MSG_DEBUG
,
937 "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
942 if (mbo_reason
> MBO_TRANSITION_REASON_PREMIUM_AP
) {
943 wpa_printf(MSG_DEBUG
,
944 "Invalid MBO transition reason code %u",
950 /* Valid values for Cellular preference are: 0, 1, 255 */
951 if (cell_pref
!= 0 && cell_pref
!= 1 && cell_pref
!= 255) {
952 wpa_printf(MSG_DEBUG
,
953 "Invalid MBO cellular capability %u",
959 if (reassoc_delay
> 65535 ||
961 !(req_mode
& WNM_BSS_TM_REQ_DISASSOC_IMMINENT
))) {
962 wpa_printf(MSG_DEBUG
,
963 "MBO: Assoc retry delay is only valid in disassoc imminent mode");
968 *mbo_pos
++ = MBO_ATTR_ID_TRANSITION_REASON
;
970 *mbo_pos
++ = mbo_reason
;
971 *mbo_pos
++ = MBO_ATTR_ID_CELL_DATA_PREF
;
973 *mbo_pos
++ = cell_pref
;
976 *mbo_pos
++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY
;
978 WPA_PUT_LE16(mbo_pos
, reassoc_delay
);
982 mbo_len
= mbo_pos
- mbo
;
984 #endif /* CONFIG_MBO */
986 ret
= wnm_send_bss_tm_req(hapd
, sta
, req_mode
, disassoc_timer
,
987 valid_int
, bss_term_dur
, url
,
988 nei_len
? nei_rep
: NULL
, nei_len
,
989 mbo_len
? mbo
: NULL
, mbo_len
);
992 #endif /* CONFIG_MBO */
998 static int hostapd_ctrl_iface_coloc_intf_req(struct hostapd_data
*hapd
,
1002 struct sta_info
*sta
;
1004 unsigned int auto_report
, timeout
;
1006 if (hwaddr_aton(cmd
, addr
)) {
1007 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
1011 sta
= ap_get_sta(hapd
, addr
);
1013 wpa_printf(MSG_DEBUG
, "Station " MACSTR
1014 " not found for Collocated Interference Request",
1023 auto_report
= atoi(pos
);
1024 pos
= os_strchr(pos
, ' ');
1028 timeout
= atoi(pos
);
1030 return wnm_send_coloc_intf_req(hapd
, sta
, auto_report
, timeout
);
1033 #endif /* CONFIG_WNM_AP */
1036 static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data
*hapd
,
1037 char *buf
, size_t buflen
)
1045 WPA_ASSERT(hapd
->conf
->wpa_key_mgmt
);
1047 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) {
1048 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK ");
1049 if (os_snprintf_error(end
- pos
, ret
))
1053 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1054 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP ");
1055 if (os_snprintf_error(end
- pos
, ret
))
1059 #ifdef CONFIG_IEEE80211R_AP
1060 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1061 ret
= os_snprintf(pos
, end
- pos
, "FT-PSK ");
1062 if (os_snprintf_error(end
- pos
, ret
))
1066 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1067 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP ");
1068 if (os_snprintf_error(end
- pos
, ret
))
1072 #ifdef CONFIG_SHA384
1073 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X_SHA384
) {
1074 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP-SHA384 ");
1075 if (os_snprintf_error(end
- pos
, ret
))
1079 #endif /* CONFIG_SHA384 */
1081 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
1082 ret
= os_snprintf(pos
, end
- pos
, "FT-SAE ");
1083 if (os_snprintf_error(end
- pos
, ret
))
1087 #endif /* CONFIG_SAE */
1089 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1090 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA256 ");
1091 if (os_snprintf_error(end
- pos
, ret
))
1095 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1096 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA384 ");
1097 if (os_snprintf_error(end
- pos
, ret
))
1101 #endif /* CONFIG_FILS */
1102 #endif /* CONFIG_IEEE80211R_AP */
1103 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1104 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK-SHA256 ");
1105 if (os_snprintf_error(end
- pos
, ret
))
1109 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1110 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SHA256 ");
1111 if (os_snprintf_error(end
- pos
, ret
))
1116 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_SAE
) {
1117 ret
= os_snprintf(pos
, end
- pos
, "SAE ");
1118 if (os_snprintf_error(end
- pos
, ret
))
1122 #endif /* CONFIG_SAE */
1123 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1124 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SUITE-B ");
1125 if (os_snprintf_error(end
- pos
, ret
))
1129 if (hapd
->conf
->wpa_key_mgmt
&
1130 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
1131 ret
= os_snprintf(pos
, end
- pos
,
1132 "WPA-EAP-SUITE-B-192 ");
1133 if (os_snprintf_error(end
- pos
, ret
))
1138 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1139 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA256 ");
1140 if (os_snprintf_error(end
- pos
, ret
))
1144 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1145 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA384 ");
1146 if (os_snprintf_error(end
- pos
, ret
))
1150 #endif /* CONFIG_FILS */
1153 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) {
1154 ret
= os_snprintf(pos
, end
- pos
, "OWE ");
1155 if (os_snprintf_error(end
- pos
, ret
))
1159 #endif /* CONFIG_OWE */
1162 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) {
1163 ret
= os_snprintf(pos
, end
- pos
, "DPP ");
1164 if (os_snprintf_error(end
- pos
, ret
))
1168 #endif /* CONFIG_DPP */
1170 if (pos
> buf
&& *(pos
- 1) == ' ') {
1179 static int hostapd_ctrl_iface_get_config(struct hostapd_data
*hapd
,
1180 char *buf
, size_t buflen
)
1188 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n"
1190 MAC2STR(hapd
->own_addr
),
1191 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
1192 hapd
->conf
->ssid
.ssid_len
));
1193 if (os_snprintf_error(end
- pos
, ret
))
1198 ret
= os_snprintf(pos
, end
- pos
, "wps_state=%s\n",
1199 hapd
->conf
->wps_state
== 0 ? "disabled" :
1200 (hapd
->conf
->wps_state
== 1 ? "not configured" :
1202 if (os_snprintf_error(end
- pos
, ret
))
1206 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1207 hapd
->conf
->ssid
.wpa_passphrase
) {
1208 ret
= os_snprintf(pos
, end
- pos
, "passphrase=%s\n",
1209 hapd
->conf
->ssid
.wpa_passphrase
);
1210 if (os_snprintf_error(end
- pos
, ret
))
1215 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1216 hapd
->conf
->ssid
.wpa_psk
&&
1217 hapd
->conf
->ssid
.wpa_psk
->group
) {
1218 char hex
[PMK_LEN
* 2 + 1];
1219 wpa_snprintf_hex(hex
, sizeof(hex
),
1220 hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
1221 ret
= os_snprintf(pos
, end
- pos
, "psk=%s\n", hex
);
1222 if (os_snprintf_error(end
- pos
, ret
))
1226 #endif /* CONFIG_WPS */
1228 if (hapd
->conf
->wpa
) {
1229 ret
= os_snprintf(pos
, end
- pos
, "wpa=%d\n", hapd
->conf
->wpa
);
1230 if (os_snprintf_error(end
- pos
, ret
))
1235 if (hapd
->conf
->wpa
&& hapd
->conf
->wpa_key_mgmt
) {
1236 ret
= os_snprintf(pos
, end
- pos
, "key_mgmt=");
1237 if (os_snprintf_error(end
- pos
, ret
))
1241 pos
+= hostapd_ctrl_iface_get_key_mgmt(hapd
, pos
, end
- pos
);
1243 ret
= os_snprintf(pos
, end
- pos
, "\n");
1244 if (os_snprintf_error(end
- pos
, ret
))
1249 if (hapd
->conf
->wpa
) {
1250 ret
= os_snprintf(pos
, end
- pos
, "group_cipher=%s\n",
1251 wpa_cipher_txt(hapd
->conf
->wpa_group
));
1252 if (os_snprintf_error(end
- pos
, ret
))
1257 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && hapd
->conf
->rsn_pairwise
) {
1258 ret
= os_snprintf(pos
, end
- pos
, "rsn_pairwise_cipher=");
1259 if (os_snprintf_error(end
- pos
, ret
))
1263 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->rsn_pairwise
,
1269 ret
= os_snprintf(pos
, end
- pos
, "\n");
1270 if (os_snprintf_error(end
- pos
, ret
))
1275 if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) && hapd
->conf
->wpa_pairwise
) {
1276 ret
= os_snprintf(pos
, end
- pos
, "wpa_pairwise_cipher=");
1277 if (os_snprintf_error(end
- pos
, ret
))
1281 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->wpa_pairwise
,
1287 ret
= os_snprintf(pos
, end
- pos
, "\n");
1288 if (os_snprintf_error(end
- pos
, ret
))
1297 static void hostapd_disassoc_accept_mac(struct hostapd_data
*hapd
)
1299 struct sta_info
*sta
;
1300 struct vlan_description vlan_id
;
1302 if (hapd
->conf
->macaddr_acl
!= DENY_UNLESS_ACCEPTED
)
1305 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1306 if (!hostapd_maclist_found(hapd
->conf
->accept_mac
,
1307 hapd
->conf
->num_accept_mac
,
1308 sta
->addr
, &vlan_id
) ||
1309 (vlan_id
.notempty
&&
1310 vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1311 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1312 WLAN_REASON_UNSPECIFIED
);
1317 static void hostapd_disassoc_deny_mac(struct hostapd_data
*hapd
)
1319 struct sta_info
*sta
;
1320 struct vlan_description vlan_id
;
1322 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1323 if (hostapd_maclist_found(hapd
->conf
->deny_mac
,
1324 hapd
->conf
->num_deny_mac
, sta
->addr
,
1326 (!vlan_id
.notempty
||
1327 !vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1328 ap_sta_disconnect(hapd
, sta
, sta
->addr
,
1329 WLAN_REASON_UNSPECIFIED
);
1334 static int hostapd_ctrl_iface_set_band(struct hostapd_data
*hapd
,
1337 union wpa_event_data event
;
1338 enum set_band setband
;
1340 if (os_strcmp(band
, "AUTO") == 0)
1341 setband
= WPA_SETBAND_AUTO
;
1342 else if (os_strcmp(band
, "5G") == 0)
1343 setband
= WPA_SETBAND_5G
;
1344 else if (os_strcmp(band
, "2G") == 0)
1345 setband
= WPA_SETBAND_2G
;
1349 if (hostapd_drv_set_band(hapd
, setband
) == 0) {
1350 os_memset(&event
, 0, sizeof(event
));
1351 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
1352 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
1353 wpa_supplicant_event(hapd
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
1360 static int hostapd_ctrl_iface_set(struct hostapd_data
*hapd
, char *cmd
)
1365 value
= os_strchr(cmd
, ' ');
1370 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
1372 #ifdef CONFIG_WPS_TESTING
1373 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
1375 val
= strtol(value
, NULL
, 0);
1376 if (val
< 0 || val
> 0xff) {
1378 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
1379 "wps_version_number %ld", val
);
1381 wps_version_number
= val
;
1382 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
1384 (wps_version_number
& 0xf0) >> 4,
1385 wps_version_number
& 0x0f);
1386 hostapd_wps_update_ie(hapd
);
1388 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
1389 wps_testing_dummy_cred
= atoi(value
);
1390 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
1391 wps_testing_dummy_cred
);
1392 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
1393 wps_corrupt_pkhash
= atoi(value
);
1394 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
1395 wps_corrupt_pkhash
);
1396 #endif /* CONFIG_WPS_TESTING */
1397 #ifdef CONFIG_TESTING_OPTIONS
1398 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
1399 hapd
->ext_mgmt_frame_handling
= atoi(value
);
1400 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
1401 hapd
->ext_eapol_frame_io
= atoi(value
);
1403 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
1404 os_free(hapd
->dpp_config_obj_override
);
1405 hapd
->dpp_config_obj_override
= os_strdup(value
);
1406 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
1407 os_free(hapd
->dpp_discovery_override
);
1408 hapd
->dpp_discovery_override
= os_strdup(value
);
1409 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
1410 os_free(hapd
->dpp_groups_override
);
1411 hapd
->dpp_groups_override
= os_strdup(value
);
1412 } else if (os_strcasecmp(cmd
,
1413 "dpp_ignore_netaccesskey_mismatch") == 0) {
1414 hapd
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
1415 } else if (os_strcasecmp(cmd
, "dpp_test") == 0) {
1416 dpp_test
= atoi(value
);
1417 #endif /* CONFIG_DPP */
1418 #endif /* CONFIG_TESTING_OPTIONS */
1420 } else if (os_strcasecmp(cmd
, "mbo_assoc_disallow") == 0) {
1423 if (!hapd
->conf
->mbo_enabled
)
1427 if (val
< 0 || val
> 1)
1430 hapd
->mbo_assoc_disallow
= val
;
1431 ieee802_11_update_beacons(hapd
->iface
);
1434 * TODO: Need to configure drivers that do AP MLME offload with
1435 * disallowing station logic.
1437 #endif /* CONFIG_MBO */
1439 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
1440 os_free(hapd
->dpp_configurator_params
);
1441 hapd
->dpp_configurator_params
= os_strdup(value
);
1442 #endif /* CONFIG_DPP */
1443 } else if (os_strcasecmp(cmd
, "setband") == 0) {
1444 ret
= hostapd_ctrl_iface_set_band(hapd
, value
);
1446 ret
= hostapd_set_iface(hapd
->iconf
, hapd
->conf
, cmd
, value
);
1450 if (os_strcasecmp(cmd
, "deny_mac_file") == 0) {
1451 hostapd_disassoc_deny_mac(hapd
);
1452 } else if (os_strcasecmp(cmd
, "accept_mac_file") == 0) {
1453 hostapd_disassoc_accept_mac(hapd
);
1454 } else if (os_strncmp(cmd
, "wme_ac_", 7) == 0 ||
1455 os_strncmp(cmd
, "wmm_ac_", 7) == 0) {
1456 hapd
->parameter_set_count
++;
1457 if (ieee802_11_update_beacons(hapd
->iface
))
1458 wpa_printf(MSG_DEBUG
,
1459 "Failed to update beacons with WMM parameters");
1460 } else if (os_strcmp(cmd
, "wpa_passphrase") == 0 ||
1461 os_strcmp(cmd
, "sae_password") == 0 ||
1462 os_strcmp(cmd
, "sae_pwe") == 0) {
1464 hostapd_setup_sae_pt(hapd
->conf
);
1472 static int hostapd_ctrl_iface_get(struct hostapd_data
*hapd
, char *cmd
,
1473 char *buf
, size_t buflen
)
1477 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
1479 if (os_strcmp(cmd
, "version") == 0) {
1480 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
1481 if (os_snprintf_error(buflen
, res
))
1484 } else if (os_strcmp(cmd
, "tls_library") == 0) {
1485 res
= tls_get_library_version(buf
, buflen
);
1486 if (os_snprintf_error(buflen
, res
))
1495 static int hostapd_ctrl_iface_enable(struct hostapd_iface
*iface
)
1497 if (hostapd_enable_iface(iface
) < 0) {
1498 wpa_printf(MSG_ERROR
, "Enabling of interface failed");
1505 static int hostapd_ctrl_iface_reload(struct hostapd_iface
*iface
)
1507 if (hostapd_reload_iface(iface
) < 0) {
1508 wpa_printf(MSG_ERROR
, "Reloading of interface failed");
1515 static int hostapd_ctrl_iface_disable(struct hostapd_iface
*iface
)
1517 if (hostapd_disable_iface(iface
) < 0) {
1518 wpa_printf(MSG_ERROR
, "Disabling of interface failed");
1526 hostapd_ctrl_iface_kick_mismatch_psk_sta_iter(struct hostapd_data
*hapd
,
1527 struct sta_info
*sta
, void *ctx
)
1529 struct hostapd_wpa_psk
*psk
;
1537 pmk
= wpa_auth_get_pmk(sta
->wpa_sm
, &pmk_len
);
1539 for (psk
= hapd
->conf
->ssid
.wpa_psk
; pmk
&& psk
; psk
= psk
->next
) {
1540 pmk_match
= PMK_LEN
== pmk_len
&&
1541 os_memcmp(psk
->psk
, pmk
, pmk_len
) == 0;
1542 sta_match
= psk
->group
== 0 &&
1543 os_memcmp(sta
->addr
, psk
->addr
, ETH_ALEN
) == 0;
1544 bss_match
= psk
->group
== 1;
1546 if (pmk_match
&& (sta_match
|| bss_match
))
1550 wpa_printf(MSG_INFO
, "STA " MACSTR
1551 " PSK/passphrase no longer valid - disconnect",
1552 MAC2STR(sta
->addr
));
1553 reason
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
1554 hostapd_drv_sta_deauth(hapd
, sta
->addr
, reason
);
1555 ap_sta_deauthenticate(hapd
, sta
, reason
);
1561 static int hostapd_ctrl_iface_reload_wpa_psk(struct hostapd_data
*hapd
)
1563 struct hostapd_bss_config
*conf
= hapd
->conf
;
1566 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
1568 err
= hostapd_setup_wpa_psk(conf
);
1570 wpa_printf(MSG_ERROR
, "Reloading WPA-PSK passwords failed: %d",
1575 ap_for_each_sta(hapd
, hostapd_ctrl_iface_kick_mismatch_psk_sta_iter
,
1582 #ifdef CONFIG_TESTING_OPTIONS
1584 static int hostapd_ctrl_iface_radar(struct hostapd_data
*hapd
, char *cmd
)
1586 union wpa_event_data data
;
1588 enum wpa_event_type event
;
1590 wpa_printf(MSG_DEBUG
, "RADAR TEST: %s", cmd
);
1592 os_memset(&data
, 0, sizeof(data
));
1594 param
= os_strchr(cmd
, ' ');
1599 if (os_strcmp(cmd
, "DETECTED") == 0)
1600 event
= EVENT_DFS_RADAR_DETECTED
;
1601 else if (os_strcmp(cmd
, "CAC-FINISHED") == 0)
1602 event
= EVENT_DFS_CAC_FINISHED
;
1603 else if (os_strcmp(cmd
, "CAC-ABORTED") == 0)
1604 event
= EVENT_DFS_CAC_ABORTED
;
1605 else if (os_strcmp(cmd
, "NOP-FINISHED") == 0)
1606 event
= EVENT_DFS_NOP_FINISHED
;
1608 wpa_printf(MSG_DEBUG
, "Unsupported RADAR test command: %s",
1613 pos
= os_strstr(param
, "freq=");
1615 data
.dfs_event
.freq
= atoi(pos
+ 5);
1617 pos
= os_strstr(param
, "ht_enabled=1");
1619 data
.dfs_event
.ht_enabled
= 1;
1621 pos
= os_strstr(param
, "chan_offset=");
1623 data
.dfs_event
.chan_offset
= atoi(pos
+ 12);
1625 pos
= os_strstr(param
, "chan_width=");
1627 data
.dfs_event
.chan_width
= atoi(pos
+ 11);
1629 pos
= os_strstr(param
, "cf1=");
1631 data
.dfs_event
.cf1
= atoi(pos
+ 4);
1633 pos
= os_strstr(param
, "cf2=");
1635 data
.dfs_event
.cf2
= atoi(pos
+ 4);
1637 wpa_supplicant_event(hapd
, event
, &data
);
1643 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data
*hapd
, char *cmd
)
1649 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
1651 len
= os_strlen(cmd
);
1656 buf
= os_malloc(len
);
1660 if (hexstr2bin(cmd
, buf
, len
) < 0) {
1665 res
= hostapd_drv_send_mlme(hapd
, buf
, len
, 0, NULL
, 0, 0);
1671 static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data
*hapd
,
1677 int stype
= 0, ok
= 0;
1678 union wpa_event_data event
;
1680 if (!hapd
->ext_mgmt_frame_handling
)
1683 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1685 wpa_printf(MSG_DEBUG
, "External MGMT TX status process: %s", cmd
);
1688 param
= os_strstr(pos
, "stype=");
1691 stype
= atoi(param
);
1694 param
= os_strstr(pos
, " ok=");
1700 param
= os_strstr(pos
, " buf=");
1705 len
= os_strlen(param
);
1710 buf
= os_malloc(len
);
1711 if (!buf
|| hexstr2bin(param
, buf
, len
) < 0) {
1716 os_memset(&event
, 0, sizeof(event
));
1717 event
.tx_status
.type
= WLAN_FC_TYPE_MGMT
;
1718 event
.tx_status
.data
= buf
;
1719 event
.tx_status
.data_len
= len
;
1720 event
.tx_status
.stype
= stype
;
1721 event
.tx_status
.ack
= ok
;
1722 hapd
->ext_mgmt_frame_handling
= 0;
1723 wpa_supplicant_event(hapd
, EVENT_TX_STATUS
, &event
);
1724 hapd
->ext_mgmt_frame_handling
= 1;
1732 static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data
*hapd
,
1738 int freq
= 0, datarate
= 0, ssi_signal
= 0;
1739 union wpa_event_data event
;
1741 if (!hapd
->ext_mgmt_frame_handling
)
1744 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1746 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
1749 param
= os_strstr(pos
, "freq=");
1755 param
= os_strstr(pos
, " datarate=");
1758 datarate
= atoi(param
);
1761 param
= os_strstr(pos
, " ssi_signal=");
1764 ssi_signal
= atoi(param
);
1767 param
= os_strstr(pos
, " frame=");
1772 len
= os_strlen(param
);
1777 buf
= os_malloc(len
);
1781 if (hexstr2bin(param
, buf
, len
) < 0) {
1786 os_memset(&event
, 0, sizeof(event
));
1787 event
.rx_mgmt
.freq
= freq
;
1788 event
.rx_mgmt
.frame
= buf
;
1789 event
.rx_mgmt
.frame_len
= len
;
1790 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1791 event
.rx_mgmt
.datarate
= datarate
;
1792 hapd
->ext_mgmt_frame_handling
= 0;
1793 wpa_supplicant_event(hapd
, EVENT_RX_MGMT
, &event
);
1794 hapd
->ext_mgmt_frame_handling
= 1;
1802 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data
*hapd
, char *cmd
)
1805 u8 src
[ETH_ALEN
], *buf
;
1809 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
1812 used
= hwaddr_aton2(pos
, src
);
1819 len
= os_strlen(pos
);
1824 buf
= os_malloc(len
);
1828 if (hexstr2bin(pos
, buf
, len
) < 0) {
1833 ieee802_1x_receive(hapd
, src
, buf
, len
);
1840 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
1844 const u16
*pos
= buf
;
1846 for (i
= 0; i
< len
/ 2; i
++)
1850 sum
= (sum
& 0xffff) + (sum
>> 16);
1852 return sum
^ 0xffff;
1856 #define HWSIM_PACKETLEN 1500
1857 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1859 static void hostapd_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
1862 struct hostapd_data
*hapd
= ctx
;
1863 const struct ether_header
*eth
;
1869 if (len
< sizeof(*eth
) + sizeof(ip
) || len
> HWSIM_PACKETLEN
) {
1870 wpa_printf(MSG_DEBUG
,
1871 "test data: RX - ignore unexpected length %d",
1876 eth
= (const struct ether_header
*) buf
;
1877 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
1878 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
1880 if (ip
.ip_hl
!= 5 || ip
.ip_v
!= 4 ||
1881 ntohs(ip
.ip_len
) > HWSIM_IP_LEN
) {
1882 wpa_printf(MSG_DEBUG
,
1883 "test data: RX - ignore unexpect IP header");
1887 for (i
= 0; i
< ntohs(ip
.ip_len
) - sizeof(ip
); i
++) {
1888 if (*pos
!= (u8
) i
) {
1889 wpa_printf(MSG_DEBUG
,
1890 "test data: RX - ignore mismatching payload");
1897 if (ntohs(ip
.ip_len
) != HWSIM_IP_LEN
)
1898 os_snprintf(extra
, sizeof(extra
), " len=%d", ntohs(ip
.ip_len
));
1899 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
"%s",
1900 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
), extra
);
1904 static int hostapd_ctrl_iface_data_test_config(struct hostapd_data
*hapd
,
1907 int enabled
= atoi(cmd
);
1912 if (hapd
->l2_test
) {
1913 l2_packet_deinit(hapd
->l2_test
);
1914 hapd
->l2_test
= NULL
;
1915 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1916 "test data: Disabled");
1924 pos
= os_strstr(cmd
, " ifname=");
1928 ifname
= hapd
->conf
->iface
;
1930 hapd
->l2_test
= l2_packet_init(ifname
, hapd
->own_addr
,
1931 ETHERTYPE_IP
, hostapd_data_test_rx
,
1933 if (hapd
->l2_test
== NULL
)
1936 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: Enabled");
1942 static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data
*hapd
, char *cmd
)
1944 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
1949 u8 buf
[2 + HWSIM_PACKETLEN
];
1950 struct ether_header
*eth
;
1954 size_t send_len
= HWSIM_IP_LEN
;
1956 if (hapd
->l2_test
== NULL
)
1959 /* format: <dst> <src> <tos> [len=<length>] */
1962 used
= hwaddr_aton2(pos
, dst
);
1968 used
= hwaddr_aton2(pos
, src
);
1973 val
= strtol(pos
, &pos2
, 0);
1974 if (val
< 0 || val
> 0xff)
1978 pos
= os_strstr(pos2
, " len=");
1981 if (i
< sizeof(*ip
) || i
> HWSIM_IP_LEN
)
1986 eth
= (struct ether_header
*) &buf
[2];
1987 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
1988 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
1989 eth
->ether_type
= htons(ETHERTYPE_IP
);
1990 ip
= (struct ip
*) (eth
+ 1);
1991 os_memset(ip
, 0, sizeof(*ip
));
1996 ip
->ip_len
= htons(send_len
);
1998 ip
->ip_src
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
1999 ip
->ip_dst
.s_addr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
2000 ip
->ip_sum
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
2001 dpos
= (u8
*) (ip
+ 1);
2002 for (i
= 0; i
< send_len
- sizeof(*ip
); i
++)
2005 if (l2_packet_send(hapd
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
2006 sizeof(struct ether_header
) + send_len
) < 0)
2009 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX dst=" MACSTR
2010 " src=" MACSTR
" tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
2016 static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data
*hapd
,
2020 struct ether_header
*eth
;
2021 struct l2_packet_data
*l2
= NULL
;
2025 const char *ifname
= hapd
->conf
->iface
;
2027 if (os_strncmp(cmd
, "ifname=", 7) == 0) {
2030 cmd
= os_strchr(cmd
, ' ');
2036 len
= os_strlen(cmd
);
2037 if (len
& 1 || len
< ETH_HLEN
* 2)
2041 buf
= os_malloc(len
);
2045 if (hexstr2bin(cmd
, buf
, len
) < 0)
2048 eth
= (struct ether_header
*) buf
;
2049 ethertype
= ntohs(eth
->ether_type
);
2051 l2
= l2_packet_init(ifname
, hapd
->own_addr
, ethertype
,
2052 hostapd_data_test_rx
, hapd
, 1);
2056 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
2057 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
2060 l2_packet_deinit(l2
);
2063 return res
< 0 ? -1 : 0;
2067 static int hostapd_ctrl_test_alloc_fail(struct hostapd_data
*hapd
, char *cmd
)
2069 #ifdef WPA_TRACE_BFD
2072 wpa_trace_fail_after
= atoi(cmd
);
2073 pos
= os_strchr(cmd
, ':');
2076 os_strlcpy(wpa_trace_fail_func
, pos
,
2077 sizeof(wpa_trace_fail_func
));
2079 wpa_trace_fail_after
= 0;
2083 #else /* WPA_TRACE_BFD */
2085 #endif /* WPA_TRACE_BFD */
2089 static int hostapd_ctrl_get_alloc_fail(struct hostapd_data
*hapd
,
2090 char *buf
, size_t buflen
)
2092 #ifdef WPA_TRACE_BFD
2093 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
2094 wpa_trace_fail_func
);
2095 #else /* WPA_TRACE_BFD */
2097 #endif /* WPA_TRACE_BFD */
2101 static int hostapd_ctrl_test_fail(struct hostapd_data
*hapd
, char *cmd
)
2103 #ifdef WPA_TRACE_BFD
2106 wpa_trace_test_fail_after
= atoi(cmd
);
2107 pos
= os_strchr(cmd
, ':');
2110 os_strlcpy(wpa_trace_test_fail_func
, pos
,
2111 sizeof(wpa_trace_test_fail_func
));
2113 wpa_trace_test_fail_after
= 0;
2117 #else /* WPA_TRACE_BFD */
2119 #endif /* WPA_TRACE_BFD */
2123 static int hostapd_ctrl_get_fail(struct hostapd_data
*hapd
,
2124 char *buf
, size_t buflen
)
2126 #ifdef WPA_TRACE_BFD
2127 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
2128 wpa_trace_test_fail_func
);
2129 #else /* WPA_TRACE_BFD */
2131 #endif /* WPA_TRACE_BFD */
2135 static int hostapd_ctrl_reset_pn(struct hostapd_data
*hapd
, const char *cmd
)
2137 struct sta_info
*sta
;
2139 u8 zero
[WPA_TK_MAX_LEN
];
2141 os_memset(zero
, 0, sizeof(zero
));
2143 if (hwaddr_aton(cmd
, addr
))
2146 if (is_broadcast_ether_addr(addr
) && os_strstr(cmd
, "IGTK")) {
2147 if (hapd
->last_igtk_alg
== WPA_ALG_NONE
)
2150 wpa_printf(MSG_INFO
, "TESTING: Reset IPN for IGTK");
2152 /* First, use a zero key to avoid any possible duplicate key
2153 * avoidance in the driver. */
2154 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2155 hapd
->last_igtk_alg
,
2156 broadcast_ether_addr
,
2157 hapd
->last_igtk_key_idx
, 0, 1, NULL
, 0,
2158 zero
, hapd
->last_igtk_len
) < 0)
2161 /* Set the previously configured key to reset its TSC */
2162 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2163 hapd
->last_igtk_alg
,
2164 broadcast_ether_addr
,
2165 hapd
->last_igtk_key_idx
, 0, 1, NULL
,
2167 hapd
->last_igtk_len
);
2170 if (is_broadcast_ether_addr(addr
)) {
2171 if (hapd
->last_gtk_alg
== WPA_ALG_NONE
)
2174 wpa_printf(MSG_INFO
, "TESTING: Reset PN for GTK");
2176 /* First, use a zero key to avoid any possible duplicate key
2177 * avoidance in the driver. */
2178 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2180 broadcast_ether_addr
,
2181 hapd
->last_gtk_key_idx
, 0, 1, NULL
, 0,
2182 zero
, hapd
->last_gtk_len
) < 0)
2185 /* Set the previously configured key to reset its TSC */
2186 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2188 broadcast_ether_addr
,
2189 hapd
->last_gtk_key_idx
, 0, 1, NULL
,
2191 hapd
->last_gtk_len
);
2194 sta
= ap_get_sta(hapd
, addr
);
2198 if (sta
->last_tk_alg
== WPA_ALG_NONE
)
2201 wpa_printf(MSG_INFO
, "TESTING: Reset PN for " MACSTR
,
2202 MAC2STR(sta
->addr
));
2204 /* First, use a zero key to avoid any possible duplicate key avoidance
2206 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2207 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2208 zero
, sta
->last_tk_len
) < 0)
2211 /* Set the previously configured key to reset its TSC/RSC */
2212 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2213 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
,
2214 0, sta
->last_tk
, sta
->last_tk_len
);
2218 static int hostapd_ctrl_set_key(struct hostapd_data
*hapd
, const char *cmd
)
2221 const char *pos
= cmd
;
2224 u8 seq
[6], key
[WPA_TK_MAX_LEN
];
2227 /* parameters: alg addr idx set_tx seq key */
2230 pos
= os_strchr(pos
, ' ');
2234 if (hwaddr_aton(pos
, addr
))
2241 pos
= os_strchr(pos
, ' ');
2246 pos
= os_strchr(pos
, ' ');
2250 if (hexstr2bin(pos
, seq
, sizeof(seq
)) < 0)
2256 key_len
= os_strlen(pos
) / 2;
2257 if (hexstr2bin(pos
, key
, key_len
) < 0)
2260 wpa_printf(MSG_INFO
, "TESTING: Set key");
2261 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, alg
, addr
, idx
, 0,
2262 set_tx
, seq
, 6, key
, key_len
);
2266 static void restore_tk(void *ctx1
, void *ctx2
)
2268 struct hostapd_data
*hapd
= ctx1
;
2269 struct sta_info
*sta
= ctx2
;
2271 wpa_printf(MSG_INFO
, "TESTING: Restore TK for " MACSTR
,
2272 MAC2STR(sta
->addr
));
2273 /* This does not really restore the TSC properly, so this will result
2274 * in replay protection issues for now since there is no clean way of
2275 * preventing encryption of a single EAPOL frame. */
2276 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2277 sta
->addr
, sta
->last_tk_key_idx
, 0, 1, NULL
, 0,
2278 sta
->last_tk
, sta
->last_tk_len
);
2282 static int hostapd_ctrl_resend_m1(struct hostapd_data
*hapd
, const char *cmd
)
2284 struct sta_info
*sta
;
2286 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2288 if (hwaddr_aton(cmd
, addr
))
2291 sta
= ap_get_sta(hapd
, addr
);
2292 if (!sta
|| !sta
->wpa_sm
)
2295 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2296 plain
= 0; /* no need for special processing */
2298 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2299 MAC2STR(sta
->addr
));
2300 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2301 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2305 wpa_printf(MSG_INFO
, "TESTING: Send M1 to " MACSTR
, MAC2STR(sta
->addr
));
2306 return wpa_auth_resend_m1(sta
->wpa_sm
,
2307 os_strstr(cmd
, "change-anonce") != NULL
,
2308 plain
? restore_tk
: NULL
, hapd
, sta
);
2312 static int hostapd_ctrl_resend_m3(struct hostapd_data
*hapd
, const char *cmd
)
2314 struct sta_info
*sta
;
2316 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2318 if (hwaddr_aton(cmd
, addr
))
2321 sta
= ap_get_sta(hapd
, addr
);
2322 if (!sta
|| !sta
->wpa_sm
)
2325 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2326 plain
= 0; /* no need for special processing */
2328 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2329 MAC2STR(sta
->addr
));
2330 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2331 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2335 wpa_printf(MSG_INFO
, "TESTING: Send M3 to " MACSTR
, MAC2STR(sta
->addr
));
2336 return wpa_auth_resend_m3(sta
->wpa_sm
,
2337 plain
? restore_tk
: NULL
, hapd
, sta
);
2341 static int hostapd_ctrl_resend_group_m1(struct hostapd_data
*hapd
,
2344 struct sta_info
*sta
;
2346 int plain
= os_strstr(cmd
, "plaintext") != NULL
;
2348 if (hwaddr_aton(cmd
, addr
))
2351 sta
= ap_get_sta(hapd
, addr
);
2352 if (!sta
|| !sta
->wpa_sm
)
2355 if (plain
&& sta
->last_tk_alg
== WPA_ALG_NONE
)
2356 plain
= 0; /* no need for special processing */
2358 wpa_printf(MSG_INFO
, "TESTING: Clear TK for " MACSTR
,
2359 MAC2STR(sta
->addr
));
2360 hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, WPA_ALG_NONE
,
2361 sta
->addr
, sta
->last_tk_key_idx
, 0, 0, NULL
,
2365 wpa_printf(MSG_INFO
,
2366 "TESTING: Send group M1 for the same GTK and zero RSC to "
2367 MACSTR
, MAC2STR(sta
->addr
));
2368 return wpa_auth_resend_group_m1(sta
->wpa_sm
,
2369 plain
? restore_tk
: NULL
, hapd
, sta
);
2372 #endif /* CONFIG_TESTING_OPTIONS */
2375 static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface
*iface
,
2379 struct csa_settings settings
;
2383 ret
= hostapd_parse_csa_settings(pos
, &settings
);
2387 for (i
= 0; i
< iface
->num_bss
; i
++) {
2389 /* Save CHAN_SWITCH VHT config */
2390 hostapd_chan_switch_vht_config(
2391 iface
->bss
[i
], settings
.freq_params
.vht_enabled
);
2393 ret
= hostapd_switch_channel(iface
->bss
[i
], &settings
);
2395 /* FIX: What do we do if CSA fails in the middle of
2396 * submitting multi-BSS CSA requests? */
2402 #else /* NEED_AP_MLME */
2404 #endif /* NEED_AP_MLME */
2408 static int hostapd_ctrl_iface_mib(struct hostapd_data
*hapd
, char *reply
,
2409 int reply_size
, const char *param
)
2411 #ifdef RADIUS_SERVER
2412 if (os_strcmp(param
, "radius_server") == 0) {
2413 return radius_server_get_mib(hapd
->radius_srv
, reply
,
2416 #endif /* RADIUS_SERVER */
2421 static int hostapd_ctrl_iface_vendor(struct hostapd_data
*hapd
, char *cmd
,
2422 char *buf
, size_t buflen
)
2427 unsigned int vendor_id
, subcmd
;
2428 struct wpabuf
*reply
;
2429 size_t data_len
= 0;
2431 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2432 vendor_id
= strtoul(cmd
, &pos
, 16);
2433 if (!isblank((unsigned char) *pos
))
2436 subcmd
= strtoul(pos
, &pos
, 10);
2439 if (!isblank((unsigned char) *pos
++))
2441 data_len
= os_strlen(pos
);
2446 data
= os_malloc(data_len
);
2450 if (hexstr2bin(pos
, data
, data_len
)) {
2451 wpa_printf(MSG_DEBUG
,
2452 "Vendor command: wrong parameter format");
2458 reply
= wpabuf_alloc((buflen
- 1) / 2);
2464 ret
= hostapd_drv_vendor_cmd(hapd
, vendor_id
, subcmd
, data
, data_len
,
2468 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
2478 static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data
*hapd
,
2482 struct sta_info
*sta
;
2484 if (hwaddr_aton(cmd
, addr
))
2487 sta
= ap_get_sta(hapd
, addr
);
2488 if (!sta
|| !sta
->eapol_sm
)
2491 eapol_auth_reauthenticate(sta
->eapol_sm
);
2496 static int hostapd_ctrl_iface_eapol_set(struct hostapd_data
*hapd
, char *cmd
)
2499 struct sta_info
*sta
;
2500 char *pos
= cmd
, *param
;
2502 if (hwaddr_aton(pos
, addr
) || pos
[17] != ' ')
2506 pos
= os_strchr(pos
, ' ');
2511 sta
= ap_get_sta(hapd
, addr
);
2512 if (!sta
|| !sta
->eapol_sm
)
2515 return eapol_auth_set_conf(sta
->eapol_sm
, param
, pos
);
2519 static int hostapd_ctrl_iface_log_level(struct hostapd_data
*hapd
, char *cmd
,
2520 char *buf
, size_t buflen
)
2522 char *pos
, *end
, *stamp
;
2525 /* cmd: "LOG_LEVEL [<level>]" */
2529 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2531 debug_level_str(wpa_debug_level
),
2532 wpa_debug_timestamp
);
2533 if (os_snprintf_error(end
- pos
, ret
))
2542 stamp
= os_strchr(cmd
, ' ');
2545 while (*stamp
== ' ') {
2550 if (os_strlen(cmd
)) {
2551 int level
= str_to_debug_level(cmd
);
2554 wpa_debug_level
= level
;
2557 if (stamp
&& os_strlen(stamp
))
2558 wpa_debug_timestamp
= atoi(stamp
);
2560 os_memcpy(buf
, "OK\n", 3);
2566 static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data
*hapd
,
2567 char *buf
, size_t buflen
)
2569 struct hostapd_iface
*iface
= hapd
->iface
;
2571 struct hostapd_sta_info
*info
;
2572 struct os_reltime now
;
2574 if (!iface
->num_sta_seen
)
2577 sta_track_expire(iface
, 0);
2582 os_get_reltime(&now
);
2583 dl_list_for_each_reverse(info
, &iface
->sta_seen
,
2584 struct hostapd_sta_info
, list
) {
2585 struct os_reltime age
;
2588 os_reltime_sub(&now
, &info
->last_seen
, &age
);
2589 ret
= os_snprintf(pos
, end
- pos
, MACSTR
" %u %d\n",
2590 MAC2STR(info
->addr
), (unsigned int) age
.sec
,
2592 if (os_snprintf_error(end
- pos
, ret
))
2599 #endif /* NEED_AP_MLME */
2602 static int hostapd_ctrl_iface_req_lci(struct hostapd_data
*hapd
,
2607 if (hwaddr_aton(cmd
, addr
)) {
2608 wpa_printf(MSG_INFO
, "CTRL: REQ_LCI: Invalid MAC address");
2612 return hostapd_send_lci_req(hapd
, addr
);
2616 static int hostapd_ctrl_iface_req_range(struct hostapd_data
*hapd
, char *cmd
)
2619 char *token
, *context
= NULL
;
2620 int random_interval
, min_ap
;
2621 u8 responders
[ETH_ALEN
* RRM_RANGE_REQ_MAX_RESPONDERS
];
2622 unsigned int n_responders
;
2624 token
= str_token(cmd
, " ", &context
);
2625 if (!token
|| hwaddr_aton(token
, addr
)) {
2626 wpa_printf(MSG_INFO
,
2627 "CTRL: REQ_RANGE - Bad destination address");
2631 token
= str_token(cmd
, " ", &context
);
2635 random_interval
= atoi(token
);
2636 if (random_interval
< 0 || random_interval
> 0xffff)
2639 token
= str_token(cmd
, " ", &context
);
2643 min_ap
= atoi(token
);
2644 if (min_ap
<= 0 || min_ap
> WLAN_RRM_RANGE_REQ_MAX_MIN_AP
)
2648 while ((token
= str_token(cmd
, " ", &context
))) {
2649 if (n_responders
== RRM_RANGE_REQ_MAX_RESPONDERS
) {
2650 wpa_printf(MSG_INFO
,
2651 "CTRL: REQ_RANGE: Too many responders");
2655 if (hwaddr_aton(token
, responders
+ n_responders
* ETH_ALEN
)) {
2656 wpa_printf(MSG_INFO
,
2657 "CTRL: REQ_RANGE: Bad responder address");
2664 if (!n_responders
) {
2665 wpa_printf(MSG_INFO
,
2666 "CTRL: REQ_RANGE - No FTM responder address");
2670 return hostapd_send_range_req(hapd
, addr
, random_interval
, min_ap
,
2671 responders
, n_responders
);
2675 static int hostapd_ctrl_iface_req_beacon(struct hostapd_data
*hapd
,
2676 const char *cmd
, char *reply
,
2685 if (hwaddr_aton(cmd
, addr
))
2687 pos
= os_strchr(cmd
, ' ');
2691 if (os_strncmp(pos
, "req_mode=", 9) == 0) {
2692 int val
= hex2byte(pos
+ 9);
2698 pos
= os_strchr(pos
, ' ');
2703 req
= wpabuf_parse_bin(pos
);
2707 ret
= hostapd_send_beacon_req(hapd
, addr
, req_mode
, req
);
2710 ret
= os_snprintf(reply
, reply_size
, "%d", ret
);
2715 static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data
*hapd
,
2716 char *buf
, size_t buflen
)
2718 if (!(hapd
->conf
->radio_measurements
[0] &
2719 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2720 wpa_printf(MSG_ERROR
,
2721 "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled");
2725 return hostapd_neighbor_show(hapd
, buf
, buflen
);
2729 static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data
*hapd
, char *buf
)
2731 struct wpa_ssid_value ssid
;
2733 struct wpabuf
*nr
, *lci
= NULL
, *civic
= NULL
;
2738 if (!(hapd
->conf
->radio_measurements
[0] &
2739 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2740 wpa_printf(MSG_ERROR
,
2741 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
2745 if (hwaddr_aton(buf
, bssid
)) {
2746 wpa_printf(MSG_ERROR
, "CTRL: SET_NEIGHBOR: Bad BSSID");
2750 tmp
= os_strstr(buf
, "ssid=");
2751 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2752 wpa_printf(MSG_ERROR
,
2753 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
2756 buf
= os_strchr(tmp
+ 6, tmp
[5] == '"' ? '"' : ' ');
2760 tmp
= os_strstr(buf
, "nr=");
2762 wpa_printf(MSG_ERROR
,
2763 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
2767 buf
= os_strchr(tmp
, ' ');
2771 nr
= wpabuf_parse_bin(tmp
+ 3);
2773 wpa_printf(MSG_ERROR
,
2774 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
2781 tmp
= os_strstr(buf
, "lci=");
2783 buf
= os_strchr(tmp
, ' ');
2786 lci
= wpabuf_parse_bin(tmp
+ 4);
2788 wpa_printf(MSG_ERROR
,
2789 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
2798 tmp
= os_strstr(buf
, "civic=");
2800 buf
= os_strchr(tmp
, ' ');
2803 civic
= wpabuf_parse_bin(tmp
+ 6);
2805 wpa_printf(MSG_ERROR
,
2806 "CTRL: SET_NEIGHBOR: Bad civic subelement");
2816 if (os_strstr(buf
, "stat"))
2820 ret
= hostapd_neighbor_set(hapd
, bssid
, &ssid
, nr
, lci
, civic
,
2831 static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data
*hapd
,
2834 struct wpa_ssid_value ssid
;
2835 struct wpa_ssid_value
*ssidp
= NULL
;
2839 if (hwaddr_aton(buf
, bssid
)) {
2840 wpa_printf(MSG_ERROR
, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
2844 tmp
= os_strstr(buf
, "ssid=");
2847 if (ssid_parse(tmp
+ 5, &ssid
)) {
2848 wpa_printf(MSG_ERROR
,
2849 "CTRL: REMOVE_NEIGHBOR: Bad SSID");
2854 return hostapd_neighbor_remove(hapd
, bssid
, ssidp
);
2858 static int hostapd_ctrl_driver_flags(struct hostapd_iface
*iface
, char *buf
,
2864 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
2865 (long long unsigned) iface
->drv_flags
);
2866 if (os_snprintf_error(buflen
, ret
))
2872 for (i
= 0; i
< 64; i
++) {
2873 if (iface
->drv_flags
& (1LLU << i
)) {
2874 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
2875 driver_flag_to_string(1LLU << i
));
2876 if (os_snprintf_error(end
- pos
, ret
))
2886 static int hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry
**acl
, int *num
,
2887 const char *txtaddr
)
2890 struct vlan_description vlan_id
;
2895 if (hwaddr_aton(txtaddr
, addr
))
2898 if (hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
))
2899 hostapd_remove_acl_mac(acl
, num
, addr
);
2905 static void hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry
**acl
,
2909 hostapd_remove_acl_mac(acl
, num
, (*acl
)[0].addr
);
2913 static int hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry
*acl
, int num
,
2914 char *buf
, size_t buflen
)
2916 int i
= 0, len
= 0, ret
= 0;
2922 ret
= os_snprintf(buf
+ len
, buflen
- len
,
2923 MACSTR
" VLAN_ID=%d\n",
2924 MAC2STR(acl
[i
].addr
),
2925 acl
[i
].vlan_id
.untagged
);
2926 if (ret
< 0 || (size_t) ret
>= buflen
- len
)
2935 static int hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry
**acl
, int *num
,
2939 struct vlan_description vlan_id
;
2940 int ret
= 0, vlanid
= 0;
2943 if (hwaddr_aton(cmd
, addr
))
2946 pos
= os_strstr(cmd
, "VLAN_ID=");
2948 vlanid
= atoi(pos
+ 8);
2950 if (!hostapd_maclist_found(*acl
, *num
, addr
, &vlan_id
)) {
2951 ret
= hostapd_add_acl_maclist(acl
, num
, vlanid
, addr
);
2952 if (ret
!= -1 && *acl
)
2953 qsort(*acl
, *num
, sizeof(**acl
), hostapd_acl_comp
);
2956 return ret
< 0 ? -1 : 0;
2960 static int hostapd_ctrl_iface_get_capability(struct hostapd_data
*hapd
,
2961 const char *field
, char *buf
,
2964 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s'", field
);
2967 if (os_strcmp(field
, "dpp") == 0) {
2971 res
= os_snprintf(buf
, buflen
, "DPP=2");
2972 #else /* CONFIG_DPP2 */
2973 res
= os_snprintf(buf
, buflen
, "DPP=1");
2974 #endif /* CONFIG_DPP2 */
2975 if (os_snprintf_error(buflen
, res
))
2979 #endif /* CONFIG_DPP */
2981 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2988 static int hostapd_ctrl_iface_receive_process(struct hostapd_data
*hapd
,
2989 char *buf
, char *reply
,
2991 struct sockaddr_storage
*from
,
2996 os_memcpy(reply
, "OK\n", 3);
2999 if (os_strcmp(buf
, "PING") == 0) {
3000 os_memcpy(reply
, "PONG\n", 5);
3002 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3003 if (wpa_debug_reopen_file() < 0)
3005 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3006 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3007 } else if (os_strcmp(buf
, "STATUS") == 0) {
3008 reply_len
= hostapd_ctrl_iface_status(hapd
, reply
,
3010 } else if (os_strcmp(buf
, "STATUS-DRIVER") == 0) {
3011 reply_len
= hostapd_drv_status(hapd
, reply
, reply_size
);
3012 } else if (os_strcmp(buf
, "MIB") == 0) {
3013 reply_len
= ieee802_11_get_mib(hapd
, reply
, reply_size
);
3014 if (reply_len
>= 0) {
3015 res
= wpa_get_mib(hapd
->wpa_auth
, reply
+ reply_len
,
3016 reply_size
- reply_len
);
3022 if (reply_len
>= 0) {
3023 res
= ieee802_1x_get_mib(hapd
, reply
+ reply_len
,
3024 reply_size
- reply_len
);
3030 #ifndef CONFIG_NO_RADIUS
3031 if (reply_len
>= 0) {
3032 res
= radius_client_get_mib(hapd
->radius
,
3034 reply_size
- reply_len
);
3040 #endif /* CONFIG_NO_RADIUS */
3041 } else if (os_strncmp(buf
, "MIB ", 4) == 0) {
3042 reply_len
= hostapd_ctrl_iface_mib(hapd
, reply
, reply_size
,
3044 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
3045 reply_len
= hostapd_ctrl_iface_sta_first(hapd
, reply
,
3047 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
3048 reply_len
= hostapd_ctrl_iface_sta(hapd
, buf
+ 4, reply
,
3050 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
3051 reply_len
= hostapd_ctrl_iface_sta_next(hapd
, buf
+ 9, reply
,
3053 } else if (os_strcmp(buf
, "ATTACH") == 0) {
3054 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, NULL
))
3056 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
3057 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
, buf
+ 7))
3059 } else if (os_strcmp(buf
, "DETACH") == 0) {
3060 if (hostapd_ctrl_iface_detach(hapd
, from
, fromlen
))
3062 } else if (os_strncmp(buf
, "LEVEL ", 6) == 0) {
3063 if (hostapd_ctrl_iface_level(hapd
, from
, fromlen
,
3066 } else if (os_strncmp(buf
, "NEW_STA ", 8) == 0) {
3067 if (hostapd_ctrl_iface_new_sta(hapd
, buf
+ 8))
3069 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
3070 if (hostapd_ctrl_iface_deauthenticate(hapd
, buf
+ 15))
3072 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
3073 if (hostapd_ctrl_iface_disassociate(hapd
, buf
+ 13))
3075 #ifdef CONFIG_TAXONOMY
3076 } else if (os_strncmp(buf
, "SIGNATURE ", 10) == 0) {
3077 reply_len
= hostapd_ctrl_iface_signature(hapd
, buf
+ 10,
3079 #endif /* CONFIG_TAXONOMY */
3080 } else if (os_strncmp(buf
, "POLL_STA ", 9) == 0) {
3081 if (hostapd_ctrl_iface_poll_sta(hapd
, buf
+ 9))
3083 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
3084 if (hostapd_ctrl_iface_stop_ap(hapd
))
3087 } else if (os_strncmp(buf
, "SA_QUERY ", 9) == 0) {
3088 if (hostapd_ctrl_iface_sa_query(hapd
, buf
+ 9))
3090 #endif /* NEED_AP_MLME */
3092 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
3093 if (hostapd_ctrl_iface_wps_pin(hapd
, buf
+ 8))
3095 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
3096 reply_len
= hostapd_ctrl_iface_wps_check_pin(
3097 hapd
, buf
+ 14, reply
, reply_size
);
3098 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
3099 if (hostapd_wps_button_pushed(hapd
, NULL
))
3101 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
3102 if (hostapd_wps_cancel(hapd
))
3104 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
3105 reply_len
= hostapd_ctrl_iface_wps_ap_pin(hapd
, buf
+ 11,
3107 } else if (os_strncmp(buf
, "WPS_CONFIG ", 11) == 0) {
3108 if (hostapd_ctrl_iface_wps_config(hapd
, buf
+ 11) < 0)
3110 } else if (os_strncmp(buf
, "WPS_GET_STATUS", 13) == 0) {
3111 reply_len
= hostapd_ctrl_iface_wps_get_status(hapd
, reply
,
3113 #ifdef CONFIG_WPS_NFC
3114 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
3115 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd
, buf
+ 17))
3117 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
3118 reply_len
= hostapd_ctrl_iface_wps_nfc_config_token(
3119 hapd
, buf
+ 21, reply
, reply_size
);
3120 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
3121 reply_len
= hostapd_ctrl_iface_wps_nfc_token(
3122 hapd
, buf
+ 14, reply
, reply_size
);
3123 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
3124 reply_len
= hostapd_ctrl_iface_nfc_get_handover_sel(
3125 hapd
, buf
+ 21, reply
, reply_size
);
3126 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
3127 if (hostapd_ctrl_iface_nfc_report_handover(hapd
, buf
+ 20))
3129 #endif /* CONFIG_WPS_NFC */
3130 #endif /* CONFIG_WPS */
3131 #ifdef CONFIG_INTERWORKING
3132 } else if (os_strncmp(buf
, "SET_QOS_MAP_SET ", 16) == 0) {
3133 if (hostapd_ctrl_iface_set_qos_map_set(hapd
, buf
+ 16))
3135 } else if (os_strncmp(buf
, "SEND_QOS_MAP_CONF ", 18) == 0) {
3136 if (hostapd_ctrl_iface_send_qos_map_conf(hapd
, buf
+ 18))
3138 #endif /* CONFIG_INTERWORKING */
3140 } else if (os_strncmp(buf
, "HS20_WNM_NOTIF ", 15) == 0) {
3141 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd
, buf
+ 15))
3143 } else if (os_strncmp(buf
, "HS20_DEAUTH_REQ ", 16) == 0) {
3144 if (hostapd_ctrl_iface_hs20_deauth_req(hapd
, buf
+ 16))
3146 #endif /* CONFIG_HS20 */
3147 #ifdef CONFIG_WNM_AP
3148 } else if (os_strncmp(buf
, "DISASSOC_IMMINENT ", 18) == 0) {
3149 if (hostapd_ctrl_iface_disassoc_imminent(hapd
, buf
+ 18))
3151 } else if (os_strncmp(buf
, "ESS_DISASSOC ", 13) == 0) {
3152 if (hostapd_ctrl_iface_ess_disassoc(hapd
, buf
+ 13))
3154 } else if (os_strncmp(buf
, "BSS_TM_REQ ", 11) == 0) {
3155 if (hostapd_ctrl_iface_bss_tm_req(hapd
, buf
+ 11))
3157 } else if (os_strncmp(buf
, "COLOC_INTF_REQ ", 15) == 0) {
3158 if (hostapd_ctrl_iface_coloc_intf_req(hapd
, buf
+ 15))
3160 #endif /* CONFIG_WNM_AP */
3161 } else if (os_strcmp(buf
, "GET_CONFIG") == 0) {
3162 reply_len
= hostapd_ctrl_iface_get_config(hapd
, reply
,
3164 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3165 if (hostapd_ctrl_iface_set(hapd
, buf
+ 4))
3167 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3168 reply_len
= hostapd_ctrl_iface_get(hapd
, buf
+ 4, reply
,
3170 } else if (os_strncmp(buf
, "ENABLE", 6) == 0) {
3171 if (hostapd_ctrl_iface_enable(hapd
->iface
))
3173 } else if (os_strcmp(buf
, "RELOAD_WPA_PSK") == 0) {
3174 if (hostapd_ctrl_iface_reload_wpa_psk(hapd
))
3176 } else if (os_strncmp(buf
, "RELOAD", 6) == 0) {
3177 if (hostapd_ctrl_iface_reload(hapd
->iface
))
3179 } else if (os_strncmp(buf
, "DISABLE", 7) == 0) {
3180 if (hostapd_ctrl_iface_disable(hapd
->iface
))
3182 } else if (os_strcmp(buf
, "UPDATE_BEACON") == 0) {
3183 if (ieee802_11_set_beacon(hapd
))
3185 #ifdef CONFIG_TESTING_OPTIONS
3186 } else if (os_strncmp(buf
, "RADAR ", 6) == 0) {
3187 if (hostapd_ctrl_iface_radar(hapd
, buf
+ 6))
3189 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
3190 if (hostapd_ctrl_iface_mgmt_tx(hapd
, buf
+ 8))
3192 } else if (os_strncmp(buf
, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
3193 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd
,
3196 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
3197 if (hostapd_ctrl_iface_mgmt_rx_process(hapd
, buf
+ 16) < 0)
3199 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
3200 if (hostapd_ctrl_iface_eapol_rx(hapd
, buf
+ 9) < 0)
3202 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
3203 if (hostapd_ctrl_iface_data_test_config(hapd
, buf
+ 17) < 0)
3205 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
3206 if (hostapd_ctrl_iface_data_test_tx(hapd
, buf
+ 13) < 0)
3208 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
3209 if (hostapd_ctrl_iface_data_test_frame(hapd
, buf
+ 16) < 0)
3211 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
3212 if (hostapd_ctrl_test_alloc_fail(hapd
, buf
+ 16) < 0)
3214 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
3215 reply_len
= hostapd_ctrl_get_alloc_fail(hapd
, reply
,
3217 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
3218 if (hostapd_ctrl_test_fail(hapd
, buf
+ 10) < 0)
3220 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
3221 reply_len
= hostapd_ctrl_get_fail(hapd
, reply
, reply_size
);
3222 } else if (os_strncmp(buf
, "RESET_PN ", 9) == 0) {
3223 if (hostapd_ctrl_reset_pn(hapd
, buf
+ 9) < 0)
3225 } else if (os_strncmp(buf
, "SET_KEY ", 8) == 0) {
3226 if (hostapd_ctrl_set_key(hapd
, buf
+ 8) < 0)
3228 } else if (os_strncmp(buf
, "RESEND_M1 ", 10) == 0) {
3229 if (hostapd_ctrl_resend_m1(hapd
, buf
+ 10) < 0)
3231 } else if (os_strncmp(buf
, "RESEND_M3 ", 10) == 0) {
3232 if (hostapd_ctrl_resend_m3(hapd
, buf
+ 10) < 0)
3234 } else if (os_strncmp(buf
, "RESEND_GROUP_M1 ", 16) == 0) {
3235 if (hostapd_ctrl_resend_group_m1(hapd
, buf
+ 16) < 0)
3237 } else if (os_strcmp(buf
, "REKEY_GTK") == 0) {
3238 if (wpa_auth_rekey_gtk(hapd
->wpa_auth
) < 0)
3240 #endif /* CONFIG_TESTING_OPTIONS */
3241 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
3242 if (hostapd_ctrl_iface_chan_switch(hapd
->iface
, buf
+ 12))
3244 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
3245 reply_len
= hostapd_ctrl_iface_vendor(hapd
, buf
+ 7, reply
,
3247 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
3248 ieee802_1x_erp_flush(hapd
);
3249 #ifdef RADIUS_SERVER
3250 radius_server_erp_flush(hapd
->radius_srv
);
3251 #endif /* RADIUS_SERVER */
3252 } else if (os_strncmp(buf
, "EAPOL_REAUTH ", 13) == 0) {
3253 if (hostapd_ctrl_iface_eapol_reauth(hapd
, buf
+ 13))
3255 } else if (os_strncmp(buf
, "EAPOL_SET ", 10) == 0) {
3256 if (hostapd_ctrl_iface_eapol_set(hapd
, buf
+ 10))
3258 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
3259 reply_len
= hostapd_ctrl_iface_log_level(
3260 hapd
, buf
+ 9, reply
, reply_size
);
3262 } else if (os_strcmp(buf
, "TRACK_STA_LIST") == 0) {
3263 reply_len
= hostapd_ctrl_iface_track_sta_list(
3264 hapd
, reply
, reply_size
);
3265 #endif /* NEED_AP_MLME */
3266 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3267 reply_len
= hostapd_ctrl_iface_pmksa_list(hapd
, reply
,
3269 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
3270 hostapd_ctrl_iface_pmksa_flush(hapd
);
3271 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
3272 if (hostapd_ctrl_iface_pmksa_add(hapd
, buf
+ 10) < 0)
3274 } else if (os_strncmp(buf
, "SET_NEIGHBOR ", 13) == 0) {
3275 if (hostapd_ctrl_iface_set_neighbor(hapd
, buf
+ 13))
3277 } else if (os_strcmp(buf
, "SHOW_NEIGHBOR") == 0) {
3278 reply_len
= hostapd_ctrl_iface_show_neighbor(hapd
, reply
,
3280 } else if (os_strncmp(buf
, "REMOVE_NEIGHBOR ", 16) == 0) {
3281 if (hostapd_ctrl_iface_remove_neighbor(hapd
, buf
+ 16))
3283 } else if (os_strncmp(buf
, "REQ_LCI ", 8) == 0) {
3284 if (hostapd_ctrl_iface_req_lci(hapd
, buf
+ 8))
3286 } else if (os_strncmp(buf
, "REQ_RANGE ", 10) == 0) {
3287 if (hostapd_ctrl_iface_req_range(hapd
, buf
+ 10))
3289 } else if (os_strncmp(buf
, "REQ_BEACON ", 11) == 0) {
3290 reply_len
= hostapd_ctrl_iface_req_beacon(hapd
, buf
+ 11,
3292 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
3293 reply_len
= hostapd_ctrl_driver_flags(hapd
->iface
, reply
,
3295 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
3297 } else if (os_strncmp(buf
, "ACCEPT_ACL ", 11) == 0) {
3298 if (os_strncmp(buf
+ 11, "ADD_MAC ", 8) == 0) {
3299 if (!hostapd_ctrl_iface_acl_add_mac(
3300 &hapd
->conf
->accept_mac
,
3301 &hapd
->conf
->num_accept_mac
, buf
+ 19))
3302 hostapd_disassoc_accept_mac(hapd
);
3305 } else if (os_strncmp((buf
+ 11), "DEL_MAC ", 8) == 0) {
3306 hostapd_ctrl_iface_acl_del_mac(
3307 &hapd
->conf
->accept_mac
,
3308 &hapd
->conf
->num_accept_mac
, buf
+ 19);
3309 } else if (os_strcmp(buf
+ 11, "SHOW") == 0) {
3310 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3311 hapd
->conf
->accept_mac
,
3312 hapd
->conf
->num_accept_mac
, reply
, reply_size
);
3313 } else if (os_strcmp(buf
+ 11, "CLEAR") == 0) {
3314 hostapd_ctrl_iface_acl_clear_list(
3315 &hapd
->conf
->accept_mac
,
3316 &hapd
->conf
->num_accept_mac
);
3318 } else if (os_strncmp(buf
, "DENY_ACL ", 9) == 0) {
3319 if (os_strncmp(buf
+ 9, "ADD_MAC ", 8) == 0) {
3320 if (!hostapd_ctrl_iface_acl_add_mac(
3321 &hapd
->conf
->deny_mac
,
3322 &hapd
->conf
->num_deny_mac
, buf
+ 17))
3323 hostapd_disassoc_deny_mac(hapd
);
3324 } else if (os_strncmp(buf
+ 9, "DEL_MAC ", 8) == 0) {
3325 hostapd_ctrl_iface_acl_del_mac(
3326 &hapd
->conf
->deny_mac
,
3327 &hapd
->conf
->num_deny_mac
, buf
+ 17);
3328 } else if (os_strcmp(buf
+ 9, "SHOW") == 0) {
3329 reply_len
= hostapd_ctrl_iface_acl_show_mac(
3330 hapd
->conf
->deny_mac
,
3331 hapd
->conf
->num_deny_mac
, reply
, reply_size
);
3332 } else if (os_strcmp(buf
+ 9, "CLEAR") == 0) {
3333 hostapd_ctrl_iface_acl_clear_list(
3334 &hapd
->conf
->deny_mac
,
3335 &hapd
->conf
->num_deny_mac
);
3338 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
3339 res
= hostapd_dpp_qr_code(hapd
, buf
+ 12);
3343 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3344 if (os_snprintf_error(reply_size
, reply_len
))
3347 } else if (os_strncmp(buf
, "DPP_NFC_URI ", 12) == 0) {
3348 res
= hostapd_dpp_nfc_uri(hapd
, buf
+ 12);
3352 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3353 if (os_snprintf_error(reply_size
, reply_len
))
3356 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
3357 res
= dpp_bootstrap_gen(hapd
->iface
->interfaces
->dpp
, buf
+ 18);
3361 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3362 if (os_snprintf_error(reply_size
, reply_len
))
3365 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
3366 if (dpp_bootstrap_remove(hapd
->iface
->interfaces
->dpp
,
3369 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
3372 uri
= dpp_bootstrap_get_uri(hapd
->iface
->interfaces
->dpp
,
3377 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
3378 if (os_snprintf_error(reply_size
, reply_len
))
3381 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
3382 reply_len
= dpp_bootstrap_info(hapd
->iface
->interfaces
->dpp
,
3385 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
3386 if (hostapd_dpp_auth_init(hapd
, buf
+ 13) < 0)
3388 } else if (os_strncmp(buf
, "DPP_LISTEN ", 11) == 0) {
3389 if (hostapd_dpp_listen(hapd
, buf
+ 11) < 0)
3391 } else if (os_strcmp(buf
, "DPP_STOP_LISTEN") == 0) {
3392 hostapd_dpp_stop(hapd
);
3393 hostapd_dpp_listen_stop(hapd
);
3394 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
3395 res
= dpp_configurator_add(hapd
->iface
->interfaces
->dpp
,
3400 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3401 if (os_snprintf_error(reply_size
, reply_len
))
3404 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
3405 if (dpp_configurator_remove(hapd
->iface
->interfaces
->dpp
,
3408 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
3409 if (hostapd_dpp_configurator_sign(hapd
, buf
+ 21) < 0)
3411 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
3412 reply_len
= dpp_configurator_get_key_id(
3413 hapd
->iface
->interfaces
->dpp
,
3416 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
3417 res
= hostapd_dpp_pkex_add(hapd
, buf
+ 12);
3421 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
3422 if (os_snprintf_error(reply_size
, reply_len
))
3425 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
3426 if (hostapd_dpp_pkex_remove(hapd
, buf
+ 16) < 0)
3428 #endif /* CONFIG_DPP */
3429 #ifdef RADIUS_SERVER
3430 } else if (os_strncmp(buf
, "DAC_REQUEST ", 12) == 0) {
3431 if (radius_server_dac_request(hapd
->radius_srv
, buf
+ 12) < 0)
3433 #endif /* RADIUS_SERVER */
3434 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
3435 reply_len
= hostapd_ctrl_iface_get_capability(
3436 hapd
, buf
+ 15, reply
, reply_size
);
3438 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
3442 if (reply_len
< 0) {
3443 os_memcpy(reply
, "FAIL\n", 5);
3451 static void hostapd_ctrl_iface_receive(int sock
, void *eloop_ctx
,
3454 struct hostapd_data
*hapd
= eloop_ctx
;
3457 struct sockaddr_storage from
;
3458 socklen_t fromlen
= sizeof(from
);
3459 char *reply
, *pos
= buf
;
3460 const int reply_size
= 4096;
3462 int level
= MSG_DEBUG
;
3463 #ifdef CONFIG_CTRL_IFACE_UDP
3464 unsigned char lcookie
[COOKIE_LEN
];
3465 #endif /* CONFIG_CTRL_IFACE_UDP */
3467 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
3468 (struct sockaddr
*) &from
, &fromlen
);
3470 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
3476 reply
= os_malloc(reply_size
);
3477 if (reply
== NULL
) {
3478 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
3480 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3486 #ifdef CONFIG_CTRL_IFACE_UDP
3487 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
3488 os_memcpy(reply
, "COOKIE=", 7);
3489 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
3490 cookie
, COOKIE_LEN
);
3491 reply_len
= 7 + 2 * COOKIE_LEN
;
3495 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
3496 hexstr2bin(buf
+ 7, lcookie
, COOKIE_LEN
) < 0) {
3497 wpa_printf(MSG_DEBUG
,
3498 "CTRL: No cookie in the request - drop request");
3503 if (os_memcmp(cookie
, lcookie
, COOKIE_LEN
) != 0) {
3504 wpa_printf(MSG_DEBUG
,
3505 "CTRL: Invalid cookie in the request - drop request");
3510 pos
= buf
+ 7 + 2 * COOKIE_LEN
;
3513 #endif /* CONFIG_CTRL_IFACE_UDP */
3515 if (os_strcmp(pos
, "PING") == 0)
3516 level
= MSG_EXCESSIVE
;
3517 wpa_hexdump_ascii(level
, "RX ctrl_iface", pos
, res
);
3519 reply_len
= hostapd_ctrl_iface_receive_process(hapd
, pos
,
3523 #ifdef CONFIG_CTRL_IFACE_UDP
3525 #endif /* CONFIG_CTRL_IFACE_UDP */
3526 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
3528 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3535 #ifndef CONFIG_CTRL_IFACE_UDP
3536 static char * hostapd_ctrl_iface_path(struct hostapd_data
*hapd
)
3541 if (hapd
->conf
->ctrl_interface
== NULL
)
3544 len
= os_strlen(hapd
->conf
->ctrl_interface
) +
3545 os_strlen(hapd
->conf
->iface
) + 2;
3546 buf
= os_malloc(len
);
3550 os_snprintf(buf
, len
, "%s/%s",
3551 hapd
->conf
->ctrl_interface
, hapd
->conf
->iface
);
3552 buf
[len
- 1] = '\0';
3555 #endif /* CONFIG_CTRL_IFACE_UDP */
3558 static void hostapd_ctrl_iface_msg_cb(void *ctx
, int level
,
3559 enum wpa_msg_type type
,
3560 const char *txt
, size_t len
)
3562 struct hostapd_data
*hapd
= ctx
;
3565 hostapd_ctrl_iface_send(hapd
, level
, type
, txt
, len
);
3569 int hostapd_ctrl_iface_init(struct hostapd_data
*hapd
)
3571 #ifdef CONFIG_CTRL_IFACE_UDP
3572 int port
= HOSTAPD_CTRL_IFACE_PORT
;
3574 char port_str
[40], *tmp
;
3576 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3579 if (hapd
->ctrl_sock
> -1) {
3580 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3584 if (hapd
->conf
->ctrl_interface
== NULL
)
3587 pos
= os_strstr(hapd
->conf
->ctrl_interface
, "udp:");
3592 wpa_printf(MSG_ERROR
, "Invalid ctrl_iface UDP port");
3597 dl_list_init(&hapd
->ctrl_dst
);
3598 hapd
->ctrl_sock
= -1;
3599 os_get_random(cookie
, COOKIE_LEN
);
3601 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3602 hints
.ai_flags
= AI_PASSIVE
;
3603 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3605 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3606 hints
.ai_family
= AF_INET6
;
3607 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3608 hints
.ai_family
= AF_INET
;
3609 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3610 hints
.ai_socktype
= SOCK_DGRAM
;
3613 os_snprintf(p
, sizeof(p
), "%d", port
);
3614 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3616 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3621 hapd
->ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3623 if (hapd
->ctrl_sock
< 0) {
3624 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3628 if (bind(hapd
->ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) < 0) {
3630 if ((HOSTAPD_CTRL_IFACE_PORT
- port
) <
3631 HOSTAPD_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3633 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3637 freeaddrinfo(saveres
);
3639 os_snprintf(port_str
, sizeof(port_str
), "udp:%d", port
);
3640 tmp
= os_strdup(port_str
);
3642 os_free(hapd
->conf
->ctrl_interface
);
3643 hapd
->conf
->ctrl_interface
= tmp
;
3645 wpa_printf(MSG_DEBUG
, "ctrl_iface_init UDP port: %d", port
);
3647 if (eloop_register_read_sock(hapd
->ctrl_sock
,
3648 hostapd_ctrl_iface_receive
, hapd
, NULL
) <
3650 hostapd_ctrl_iface_deinit(hapd
);
3654 hapd
->msg_ctx
= hapd
;
3655 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3660 if (hapd
->ctrl_sock
>= 0)
3661 close(hapd
->ctrl_sock
);
3663 #else /* CONFIG_CTRL_IFACE_UDP */
3664 struct sockaddr_un addr
;
3668 if (hapd
->ctrl_sock
> -1) {
3669 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3673 dl_list_init(&hapd
->ctrl_dst
);
3675 if (hapd
->conf
->ctrl_interface
== NULL
)
3678 if (mkdir(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3679 if (errno
== EEXIST
) {
3680 wpa_printf(MSG_DEBUG
, "Using existing control "
3681 "interface directory.");
3683 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3689 if (hapd
->conf
->ctrl_interface_gid_set
&&
3690 lchown(hapd
->conf
->ctrl_interface
, -1,
3691 hapd
->conf
->ctrl_interface_gid
) < 0) {
3692 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3697 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3698 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3699 lchown(hapd
->conf
->ctrl_interface
, -1,
3700 hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3701 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
3708 * Android is using umask 0077 which would leave the control interface
3709 * directory without group access. This breaks things since Wi-Fi
3710 * framework assumes that this directory can be accessed by other
3711 * applications in the wifi group. Fix this by adding group access even
3712 * if umask value would prevent this.
3714 if (chmod(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3715 wpa_printf(MSG_ERROR
, "CTRL: Could not chmod directory: %s",
3717 /* Try to continue anyway */
3719 #endif /* ANDROID */
3721 if (os_strlen(hapd
->conf
->ctrl_interface
) + 1 +
3722 os_strlen(hapd
->conf
->iface
) >= sizeof(addr
.sun_path
))
3725 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
3727 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
3731 os_memset(&addr
, 0, sizeof(addr
));
3733 addr
.sun_len
= sizeof(addr
);
3734 #endif /* __FreeBSD__ */
3735 addr
.sun_family
= AF_UNIX
;
3736 fname
= hostapd_ctrl_iface_path(hapd
);
3739 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
3740 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3741 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
3743 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3744 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
3745 " allow connections - assuming it was left"
3746 "over from forced program termination");
3747 if (unlink(fname
) < 0) {
3748 wpa_printf(MSG_ERROR
,
3749 "Could not unlink existing ctrl_iface socket '%s': %s",
3750 fname
, strerror(errno
));
3753 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
3755 wpa_printf(MSG_ERROR
,
3756 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
3760 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
3761 "ctrl_iface socket '%s'", fname
);
3763 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
3764 "be in use - cannot override it");
3765 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
3766 "not used anymore", fname
);
3773 if (hapd
->conf
->ctrl_interface_gid_set
&&
3774 lchown(fname
, -1, hapd
->conf
->ctrl_interface_gid
) < 0) {
3775 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
3780 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3781 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3782 lchown(fname
, -1, hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3783 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface/ifname]: %s",
3788 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
3789 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
3795 hapd
->ctrl_sock
= s
;
3796 if (eloop_register_read_sock(s
, hostapd_ctrl_iface_receive
, hapd
,
3798 hostapd_ctrl_iface_deinit(hapd
);
3801 hapd
->msg_ctx
= hapd
;
3802 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3814 #endif /* CONFIG_CTRL_IFACE_UDP */
3818 void hostapd_ctrl_iface_deinit(struct hostapd_data
*hapd
)
3820 struct wpa_ctrl_dst
*dst
, *prev
;
3822 if (hapd
->ctrl_sock
> -1) {
3823 #ifndef CONFIG_CTRL_IFACE_UDP
3825 #endif /* !CONFIG_CTRL_IFACE_UDP */
3827 eloop_unregister_read_sock(hapd
->ctrl_sock
);
3828 close(hapd
->ctrl_sock
);
3829 hapd
->ctrl_sock
= -1;
3830 #ifndef CONFIG_CTRL_IFACE_UDP
3831 fname
= hostapd_ctrl_iface_path(hapd
);
3836 if (hapd
->conf
->ctrl_interface
&&
3837 rmdir(hapd
->conf
->ctrl_interface
) < 0) {
3838 if (errno
== ENOTEMPTY
) {
3839 wpa_printf(MSG_DEBUG
, "Control interface "
3840 "directory not empty - leaving it "
3843 wpa_printf(MSG_ERROR
,
3844 "rmdir[ctrl_interface=%s]: %s",
3845 hapd
->conf
->ctrl_interface
,
3849 #endif /* !CONFIG_CTRL_IFACE_UDP */
3852 dl_list_for_each_safe(dst
, prev
, &hapd
->ctrl_dst
, struct wpa_ctrl_dst
,
3856 #ifdef CONFIG_TESTING_OPTIONS
3857 l2_packet_deinit(hapd
->l2_test
);
3858 hapd
->l2_test
= NULL
;
3859 #endif /* CONFIG_TESTING_OPTIONS */
3863 static int hostapd_ctrl_iface_add(struct hapd_interfaces
*interfaces
,
3866 if (hostapd_add_iface(interfaces
, buf
) < 0) {
3867 wpa_printf(MSG_ERROR
, "Adding interface %s failed", buf
);
3874 static int hostapd_ctrl_iface_remove(struct hapd_interfaces
*interfaces
,
3877 if (hostapd_remove_iface(interfaces
, buf
) < 0) {
3878 wpa_printf(MSG_ERROR
, "Removing interface %s failed", buf
);
3885 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces
*interfaces
,
3886 struct sockaddr_storage
*from
,
3887 socklen_t fromlen
, char *input
)
3889 return ctrl_iface_attach(&interfaces
->global_ctrl_dst
, from
, fromlen
,
3894 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces
*interfaces
,
3895 struct sockaddr_storage
*from
,
3898 return ctrl_iface_detach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
3902 static void hostapd_ctrl_iface_flush(struct hapd_interfaces
*interfaces
)
3904 #ifdef CONFIG_WPS_TESTING
3905 wps_version_number
= 0x20;
3906 wps_testing_dummy_cred
= 0;
3907 wps_corrupt_pkhash
= 0;
3908 #endif /* CONFIG_WPS_TESTING */
3910 #ifdef CONFIG_TESTING_OPTIONS
3912 dpp_test
= DPP_TEST_DISABLED
;
3913 #endif /* CONFIG_DPP */
3914 #endif /* CONFIG_TESTING_OPTIONS */
3917 dpp_global_clear(interfaces
->dpp
);
3918 #endif /* CONFIG_DPP */
3925 hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces
*interfaces
,
3928 char ifname
[IFNAMSIZ
+ 1];
3929 struct fst_iface_cfg cfg
;
3930 struct hostapd_data
*hapd
;
3931 struct fst_wpa_obj iface_obj
;
3933 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
3934 hapd
= hostapd_get_iface(interfaces
, ifname
);
3936 if (hapd
->iface
->fst
) {
3937 wpa_printf(MSG_INFO
, "FST: Already attached");
3940 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
3941 hapd
->iface
->fst
= fst_attach(ifname
, hapd
->own_addr
,
3943 if (hapd
->iface
->fst
)
3953 hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces
*interfaces
,
3956 char ifname
[IFNAMSIZ
+ 1];
3957 struct hostapd_data
* hapd
;
3959 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
3960 hapd
= hostapd_get_iface(interfaces
, ifname
);
3962 if (!fst_iface_detach(ifname
)) {
3963 hapd
->iface
->fst
= NULL
;
3964 hapd
->iface
->fst_ies
= NULL
;
3973 #endif /* CONFIG_FST */
3976 static struct hostapd_data
*
3977 hostapd_interfaces_get_hapd(struct hapd_interfaces
*interfaces
,
3982 for (i
= 0; i
< interfaces
->count
; i
++) {
3983 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
3985 for (j
= 0; j
< iface
->num_bss
; j
++) {
3986 struct hostapd_data
*hapd
;
3988 hapd
= iface
->bss
[j
];
3989 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
3998 static int hostapd_ctrl_iface_dup_param(struct hostapd_data
*src_hapd
,
3999 struct hostapd_data
*dst_hapd
,
4005 value
= os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4007 wpa_printf(MSG_ERROR
,
4008 "DUP: cannot allocate buffer to stringify %s",
4013 if (os_strcmp(param
, "wpa") == 0) {
4014 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%d",
4015 src_hapd
->conf
->wpa
);
4016 } else if (os_strcmp(param
, "wpa_key_mgmt") == 0 &&
4017 src_hapd
->conf
->wpa_key_mgmt
) {
4018 res
= hostapd_ctrl_iface_get_key_mgmt(
4019 src_hapd
, value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
4020 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, res
))
4021 goto error_stringify
;
4022 } else if (os_strcmp(param
, "wpa_pairwise") == 0 &&
4023 src_hapd
->conf
->wpa_pairwise
) {
4024 res
= wpa_write_ciphers(value
,
4025 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4026 src_hapd
->conf
->wpa_pairwise
, " ");
4028 goto error_stringify
;
4029 } else if (os_strcmp(param
, "rsn_pairwise") == 0 &&
4030 src_hapd
->conf
->rsn_pairwise
) {
4031 res
= wpa_write_ciphers(value
,
4032 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4033 src_hapd
->conf
->rsn_pairwise
, " ");
4035 goto error_stringify
;
4036 } else if (os_strcmp(param
, "wpa_passphrase") == 0 &&
4037 src_hapd
->conf
->ssid
.wpa_passphrase
) {
4038 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%s",
4039 src_hapd
->conf
->ssid
.wpa_passphrase
);
4040 } else if (os_strcmp(param
, "wpa_psk") == 0 &&
4041 src_hapd
->conf
->ssid
.wpa_psk_set
) {
4042 wpa_snprintf_hex(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
4043 src_hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
4045 wpa_printf(MSG_WARNING
, "DUP: %s cannot be duplicated", param
);
4049 res
= hostapd_set_iface(dst_hapd
->iconf
, dst_hapd
->conf
, param
, value
);
4054 wpa_printf(MSG_ERROR
, "DUP: cannot stringify %s", param
);
4062 hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces
*interfaces
,
4064 char *reply
, int reply_size
)
4069 struct hostapd_iface
*iface
;
4073 show_ctrl
= !!os_strstr(input
, "ctrl");
4076 end
= reply
+ reply_size
;
4078 for (i
= 0; i
< interfaces
->count
; i
++) {
4079 iface
= interfaces
->iface
[i
];
4081 for (j
= 0; j
< iface
->num_bss
; j
++) {
4082 struct hostapd_bss_config
*conf
;
4084 conf
= iface
->conf
->bss
[j
];
4086 res
= os_snprintf(pos
, end
- pos
,
4087 "%s ctrl_iface=%s\n",
4089 conf
->ctrl_interface
?
4090 conf
->ctrl_interface
: "N/A");
4092 res
= os_snprintf(pos
, end
- pos
, "%s\n",
4094 if (os_snprintf_error(end
- pos
, res
)) {
4107 hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces
*interfaces
,
4110 char *p_start
= cmd
, *p_end
;
4111 struct hostapd_data
*src_hapd
, *dst_hapd
;
4113 /* cmd: "<src ifname> <dst ifname> <variable name> */
4115 p_end
= os_strchr(p_start
, ' ');
4117 wpa_printf(MSG_ERROR
, "DUP: no src ifname found in cmd: '%s'",
4123 src_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4125 wpa_printf(MSG_ERROR
, "DUP: no src ifname found: '%s'",
4130 p_start
= p_end
+ 1;
4131 p_end
= os_strchr(p_start
, ' ');
4133 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found in cmd: '%s'",
4139 dst_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
4141 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found: '%s'",
4146 p_start
= p_end
+ 1;
4147 return hostapd_ctrl_iface_dup_param(src_hapd
, dst_hapd
, p_start
);
4151 static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces
*interfaces
,
4153 char *buf
, char *reply
,
4155 struct sockaddr_storage
*from
,
4158 struct hostapd_data
*hapd
;
4160 hapd
= hostapd_interfaces_get_hapd(interfaces
, ifname
);
4164 res
= os_snprintf(reply
, reply_size
, "FAIL-NO-IFNAME-MATCH\n");
4165 if (os_snprintf_error(reply_size
, res
))
4170 return hostapd_ctrl_iface_receive_process(hapd
, buf
, reply
,reply_size
,
4175 static void hostapd_global_ctrl_iface_receive(int sock
, void *eloop_ctx
,
4178 void *interfaces
= eloop_ctx
;
4179 char buffer
[256], *buf
= buffer
;
4181 struct sockaddr_storage from
;
4182 socklen_t fromlen
= sizeof(from
);
4185 const int reply_size
= 4096;
4186 #ifdef CONFIG_CTRL_IFACE_UDP
4187 unsigned char lcookie
[COOKIE_LEN
];
4188 #endif /* CONFIG_CTRL_IFACE_UDP */
4190 res
= recvfrom(sock
, buffer
, sizeof(buffer
) - 1, 0,
4191 (struct sockaddr
*) &from
, &fromlen
);
4193 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
4198 wpa_printf(MSG_DEBUG
, "Global ctrl_iface command: %s", buf
);
4200 reply
= os_malloc(reply_size
);
4201 if (reply
== NULL
) {
4202 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
4204 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4210 os_memcpy(reply
, "OK\n", 3);
4213 #ifdef CONFIG_CTRL_IFACE_UDP
4214 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
4215 os_memcpy(reply
, "COOKIE=", 7);
4216 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
4217 gcookie
, COOKIE_LEN
);
4218 reply_len
= 7 + 2 * COOKIE_LEN
;
4222 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
4223 hexstr2bin(buf
+ 7, lcookie
, COOKIE_LEN
) < 0) {
4224 wpa_printf(MSG_DEBUG
,
4225 "CTRL: No cookie in the request - drop request");
4230 if (os_memcmp(gcookie
, lcookie
, COOKIE_LEN
) != 0) {
4231 wpa_printf(MSG_DEBUG
,
4232 "CTRL: Invalid cookie in the request - drop request");
4237 buf
+= 7 + 2 * COOKIE_LEN
;
4240 #endif /* CONFIG_CTRL_IFACE_UDP */
4242 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
4243 char *pos
= os_strchr(buf
+ 7, ' ');
4247 reply_len
= hostapd_global_ctrl_iface_ifname(
4248 interfaces
, buf
+ 7, pos
, reply
, reply_size
,
4254 if (os_strcmp(buf
, "PING") == 0) {
4255 os_memcpy(reply
, "PONG\n", 5);
4257 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
4258 if (wpa_debug_reopen_file() < 0)
4260 } else if (os_strcmp(buf
, "FLUSH") == 0) {
4261 hostapd_ctrl_iface_flush(interfaces
);
4262 } else if (os_strncmp(buf
, "ADD ", 4) == 0) {
4263 if (hostapd_ctrl_iface_add(interfaces
, buf
+ 4) < 0)
4265 } else if (os_strncmp(buf
, "REMOVE ", 7) == 0) {
4266 if (hostapd_ctrl_iface_remove(interfaces
, buf
+ 7) < 0)
4268 } else if (os_strcmp(buf
, "ATTACH") == 0) {
4269 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4272 } else if (os_strncmp(buf
, "ATTACH ", 7) == 0) {
4273 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
4276 } else if (os_strcmp(buf
, "DETACH") == 0) {
4277 if (hostapd_global_ctrl_iface_detach(interfaces
, &from
,
4280 #ifdef CONFIG_MODULE_TESTS
4281 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
4282 if (hapd_module_tests() < 0)
4284 #endif /* CONFIG_MODULE_TESTS */
4286 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
4287 if (!hostapd_global_ctrl_iface_fst_attach(interfaces
, buf
+ 11))
4288 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4291 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
4292 if (!hostapd_global_ctrl_iface_fst_detach(interfaces
, buf
+ 11))
4293 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4296 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
4297 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
4298 #endif /* CONFIG_FST */
4299 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
4300 if (!hostapd_global_ctrl_iface_dup_network(interfaces
,
4302 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
4305 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
4306 reply_len
= hostapd_global_ctrl_iface_interfaces(
4307 interfaces
, buf
+ 10, reply
, sizeof(buffer
));
4308 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4311 wpa_printf(MSG_DEBUG
, "Unrecognized global ctrl_iface command "
4317 if (reply_len
< 0) {
4318 os_memcpy(reply
, "FAIL\n", 5);
4322 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
4324 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
4331 #ifndef CONFIG_CTRL_IFACE_UDP
4332 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces
*interface
)
4337 if (interface
->global_iface_path
== NULL
)
4340 len
= os_strlen(interface
->global_iface_path
) +
4341 os_strlen(interface
->global_iface_name
) + 2;
4342 buf
= os_malloc(len
);
4346 os_snprintf(buf
, len
, "%s/%s", interface
->global_iface_path
,
4347 interface
->global_iface_name
);
4348 buf
[len
- 1] = '\0';
4351 #endif /* CONFIG_CTRL_IFACE_UDP */
4354 int hostapd_global_ctrl_iface_init(struct hapd_interfaces
*interface
)
4356 #ifdef CONFIG_CTRL_IFACE_UDP
4357 int port
= HOSTAPD_GLOBAL_CTRL_IFACE_PORT
;
4360 struct addrinfo hints
= { 0 }, *res
, *saveres
;
4363 if (interface
->global_ctrl_sock
> -1) {
4364 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
4368 if (interface
->global_iface_path
== NULL
)
4371 pos
= os_strstr(interface
->global_iface_path
, "udp:");
4376 wpa_printf(MSG_ERROR
, "Invalid global ctrl UDP port");
4381 os_get_random(gcookie
, COOKIE_LEN
);
4383 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4384 hints
.ai_flags
= AI_PASSIVE
;
4385 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4387 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
4388 hints
.ai_family
= AF_INET6
;
4389 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4390 hints
.ai_family
= AF_INET
;
4391 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4392 hints
.ai_socktype
= SOCK_DGRAM
;
4395 os_snprintf(p
, sizeof(p
), "%d", port
);
4396 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
4398 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
4403 interface
->global_ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
4405 if (interface
->global_ctrl_sock
< 0) {
4406 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
4410 if (bind(interface
->global_ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) <
4413 if ((port
- HOSTAPD_GLOBAL_CTRL_IFACE_PORT
) <
4414 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT
&& !pos
)
4416 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
4420 freeaddrinfo(saveres
);
4422 wpa_printf(MSG_DEBUG
, "global ctrl_iface_init UDP port: %d", port
);
4424 if (eloop_register_read_sock(interface
->global_ctrl_sock
,
4425 hostapd_global_ctrl_iface_receive
,
4426 interface
, NULL
) < 0) {
4427 hostapd_global_ctrl_iface_deinit(interface
);
4431 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4436 if (interface
->global_ctrl_sock
>= 0)
4437 close(interface
->global_ctrl_sock
);
4439 #else /* CONFIG_CTRL_IFACE_UDP */
4440 struct sockaddr_un addr
;
4444 if (interface
->global_iface_path
== NULL
) {
4445 wpa_printf(MSG_DEBUG
, "ctrl_iface not configured!");
4449 if (mkdir(interface
->global_iface_path
, S_IRWXU
| S_IRWXG
) < 0) {
4450 if (errno
== EEXIST
) {
4451 wpa_printf(MSG_DEBUG
, "Using existing control "
4452 "interface directory.");
4454 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
4458 } else if (interface
->ctrl_iface_group
&&
4459 lchown(interface
->global_iface_path
, -1,
4460 interface
->ctrl_iface_group
) < 0) {
4461 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4466 if (os_strlen(interface
->global_iface_path
) + 1 +
4467 os_strlen(interface
->global_iface_name
) >= sizeof(addr
.sun_path
))
4470 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
4472 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
4476 os_memset(&addr
, 0, sizeof(addr
));
4478 addr
.sun_len
= sizeof(addr
);
4479 #endif /* __FreeBSD__ */
4480 addr
.sun_family
= AF_UNIX
;
4481 fname
= hostapd_global_ctrl_iface_path(interface
);
4484 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
4485 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4486 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
4488 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4489 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
4490 " allow connections - assuming it was left"
4491 "over from forced program termination");
4492 if (unlink(fname
) < 0) {
4493 wpa_printf(MSG_ERROR
,
4494 "Could not unlink existing ctrl_iface socket '%s': %s",
4495 fname
, strerror(errno
));
4498 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
4500 wpa_printf(MSG_ERROR
, "bind(PF_UNIX): %s",
4504 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
4505 "ctrl_iface socket '%s'", fname
);
4507 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
4508 "be in use - cannot override it");
4509 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
4510 "not used anymore", fname
);
4517 if (interface
->ctrl_iface_group
&&
4518 lchown(fname
, -1, interface
->ctrl_iface_group
) < 0) {
4519 wpa_printf(MSG_ERROR
, "lchown[ctrl_interface]: %s",
4524 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
4525 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
4531 interface
->global_ctrl_sock
= s
;
4532 eloop_register_read_sock(s
, hostapd_global_ctrl_iface_receive
,
4535 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
4547 #endif /* CONFIG_CTRL_IFACE_UDP */
4551 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces
*interfaces
)
4553 #ifndef CONFIG_CTRL_IFACE_UDP
4555 #endif /* CONFIG_CTRL_IFACE_UDP */
4556 struct wpa_ctrl_dst
*dst
, *prev
;
4558 if (interfaces
->global_ctrl_sock
> -1) {
4559 eloop_unregister_read_sock(interfaces
->global_ctrl_sock
);
4560 close(interfaces
->global_ctrl_sock
);
4561 interfaces
->global_ctrl_sock
= -1;
4562 #ifndef CONFIG_CTRL_IFACE_UDP
4563 fname
= hostapd_global_ctrl_iface_path(interfaces
);
4569 if (interfaces
->global_iface_path
&&
4570 rmdir(interfaces
->global_iface_path
) < 0) {
4571 if (errno
== ENOTEMPTY
) {
4572 wpa_printf(MSG_DEBUG
, "Control interface "
4573 "directory not empty - leaving it "
4576 wpa_printf(MSG_ERROR
,
4577 "rmdir[ctrl_interface=%s]: %s",
4578 interfaces
->global_iface_path
,
4582 #endif /* CONFIG_CTRL_IFACE_UDP */
4585 os_free(interfaces
->global_iface_path
);
4586 interfaces
->global_iface_path
= NULL
;
4588 dl_list_for_each_safe(dst
, prev
, &interfaces
->global_ctrl_dst
,
4589 struct wpa_ctrl_dst
, list
)
4594 static int hostapd_ctrl_check_event_enabled(struct wpa_ctrl_dst
*dst
,
4597 /* Enable Probe Request events based on explicit request.
4598 * Other events are enabled by default.
4600 if (str_starts(buf
, RX_PROBE_REQUEST
))
4601 return !!(dst
->events
& WPA_EVENT_RX_PROBE_REQUEST
);
4606 static void hostapd_ctrl_iface_send_internal(int sock
, struct dl_list
*ctrl_dst
,
4607 const char *ifname
, int level
,
4608 const char *buf
, size_t len
)
4610 struct wpa_ctrl_dst
*dst
, *next
;
4616 if (sock
< 0 || dl_list_empty(ctrl_dst
))
4619 res
= os_snprintf(levelstr
, sizeof(levelstr
), "<%d>", level
);
4620 if (os_snprintf_error(sizeof(levelstr
), res
))
4624 #ifdef CONFIG_CTRL_IFACE_UDP
4625 io
[idx
].iov_base
= "IFACE=";
4626 io
[idx
].iov_len
= 6;
4627 #else /* CONFIG_CTRL_IFACE_UDP */
4628 io
[idx
].iov_base
= "IFNAME=";
4629 io
[idx
].iov_len
= 7;
4630 #endif /* CONFIG_CTRL_IFACE_UDP */
4632 io
[idx
].iov_base
= (char *) ifname
;
4633 io
[idx
].iov_len
= os_strlen(ifname
);
4635 io
[idx
].iov_base
= " ";
4636 io
[idx
].iov_len
= 1;
4639 io
[idx
].iov_base
= levelstr
;
4640 io
[idx
].iov_len
= os_strlen(levelstr
);
4642 io
[idx
].iov_base
= (char *) buf
;
4643 io
[idx
].iov_len
= len
;
4645 os_memset(&msg
, 0, sizeof(msg
));
4647 msg
.msg_iovlen
= idx
;
4650 dl_list_for_each_safe(dst
, next
, ctrl_dst
, struct wpa_ctrl_dst
, list
) {
4651 if ((level
>= dst
->debug_level
) &&
4652 hostapd_ctrl_check_event_enabled(dst
, buf
)) {
4653 sockaddr_print(MSG_DEBUG
, "CTRL_IFACE monitor send",
4654 &dst
->addr
, dst
->addrlen
);
4655 msg
.msg_name
= &dst
->addr
;
4656 msg
.msg_namelen
= dst
->addrlen
;
4657 if (sendmsg(sock
, &msg
, 0) < 0) {
4659 wpa_printf(MSG_INFO
, "CTRL_IFACE monitor[%d]: "
4661 idx
, errno
, strerror(errno
));
4663 if (dst
->errors
> 10 || _errno
== ENOENT
) {
4664 ctrl_iface_detach(ctrl_dst
,
4676 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
4677 enum wpa_msg_type type
,
4678 const char *buf
, size_t len
)
4680 if (type
!= WPA_MSG_NO_GLOBAL
) {
4681 hostapd_ctrl_iface_send_internal(
4682 hapd
->iface
->interfaces
->global_ctrl_sock
,
4683 &hapd
->iface
->interfaces
->global_ctrl_dst
,
4684 type
!= WPA_MSG_PER_INTERFACE
?
4685 NULL
: hapd
->conf
->iface
,
4689 if (type
!= WPA_MSG_ONLY_GLOBAL
) {
4690 hostapd_ctrl_iface_send_internal(
4691 hapd
->ctrl_sock
, &hapd
->ctrl_dst
,
4692 NULL
, level
, buf
, len
);
4696 #endif /* CONFIG_NATIVE_WINDOWS */