2 * hostapd / UNIX domain socket -based control interface
3 * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #ifndef CONFIG_NATIVE_WINDOWS
13 #ifdef CONFIG_TESTING_OPTIONS
14 #include <net/ethernet.h>
15 #include <netinet/ip.h>
16 #endif /* CONFIG_TESTING_OPTIONS */
22 #ifdef CONFIG_CTRL_IFACE_UDP
24 #endif /* CONFIG_CTRL_IFACE_UDP */
26 #include "utils/common.h"
27 #include "utils/eloop.h"
28 #include "utils/module_tests.h"
29 #include "common/version.h"
30 #include "common/ieee802_11_defs.h"
31 #include "common/ctrl_iface_common.h"
32 #include "crypto/tls.h"
33 #include "drivers/driver.h"
34 #include "eapol_auth/eapol_auth_sm.h"
35 #include "radius/radius_client.h"
36 #include "radius/radius_server.h"
37 #include "l2_packet/l2_packet.h"
38 #include "ap/hostapd.h"
39 #include "ap/ap_config.h"
40 #include "ap/ieee802_1x.h"
41 #include "ap/wpa_auth.h"
42 #include "ap/ieee802_11.h"
43 #include "ap/sta_info.h"
44 #include "ap/wps_hostapd.h"
45 #include "ap/ctrl_iface_ap.h"
46 #include "ap/ap_drv_ops.h"
48 #include "ap/wnm_ap.h"
49 #include "ap/wpa_auth.h"
50 #include "ap/beacon.h"
51 #include "ap/neighbor_db.h"
53 #include "ap/dpp_hostapd.h"
54 #include "wps/wps_defs.h"
56 #include "fst/fst_ctrl_iface.h"
57 #include "config_file.h"
58 #include "ctrl_iface.h"
61 #define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
63 #ifdef CONFIG_CTRL_IFACE_UDP
65 static unsigned char cookie
[COOKIE_LEN
];
66 static unsigned char gcookie
[COOKIE_LEN
];
67 #define HOSTAPD_CTRL_IFACE_PORT 8877
68 #define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
69 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
70 #define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
71 #endif /* CONFIG_CTRL_IFACE_UDP */
73 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
74 enum wpa_msg_type type
,
75 const char *buf
, size_t len
);
78 static int hostapd_ctrl_iface_attach(struct hostapd_data
*hapd
,
79 struct sockaddr_storage
*from
,
82 return ctrl_iface_attach(&hapd
->ctrl_dst
, from
, fromlen
);
86 static int hostapd_ctrl_iface_detach(struct hostapd_data
*hapd
,
87 struct sockaddr_storage
*from
,
90 return ctrl_iface_detach(&hapd
->ctrl_dst
, from
, fromlen
);
94 static int hostapd_ctrl_iface_level(struct hostapd_data
*hapd
,
95 struct sockaddr_storage
*from
,
99 return ctrl_iface_level(&hapd
->ctrl_dst
, from
, fromlen
, level
);
103 static int hostapd_ctrl_iface_new_sta(struct hostapd_data
*hapd
,
107 struct sta_info
*sta
;
109 wpa_printf(MSG_DEBUG
, "CTRL_IFACE NEW_STA %s", txtaddr
);
111 if (hwaddr_aton(txtaddr
, addr
))
114 sta
= ap_get_sta(hapd
, addr
);
118 wpa_printf(MSG_DEBUG
, "Add new STA " MACSTR
" based on ctrl_iface "
119 "notification", MAC2STR(addr
));
120 sta
= ap_sta_add(hapd
, addr
);
124 hostapd_new_assoc_sta(hapd
, sta
, 0);
129 #ifdef CONFIG_IEEE80211W
131 static int hostapd_ctrl_iface_sa_query(struct hostapd_data
*hapd
,
135 u8 trans_id
[WLAN_SA_QUERY_TR_ID_LEN
];
137 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SA_QUERY %s", txtaddr
);
139 if (hwaddr_aton(txtaddr
, addr
) ||
140 os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0)
143 ieee802_11_send_sa_query_req(hapd
, addr
, trans_id
);
147 #endif /* NEED_AP_MLME */
148 #endif /* CONFIG_IEEE80211W */
152 static int hostapd_ctrl_iface_wps_pin(struct hostapd_data
*hapd
, char *txt
)
154 char *pin
= os_strchr(txt
, ' ');
157 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
164 timeout_txt
= os_strchr(pin
, ' ');
166 *timeout_txt
++ = '\0';
167 timeout
= atoi(timeout_txt
);
168 pos
= os_strchr(timeout_txt
, ' ');
171 if (hwaddr_aton(pos
, addr_buf
) == 0)
177 return hostapd_wps_add_pin(hapd
, addr
, txt
, pin
, timeout
);
181 static int hostapd_ctrl_iface_wps_check_pin(
182 struct hostapd_data
*hapd
, char *cmd
, char *buf
, size_t buflen
)
189 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
190 (u8
*) cmd
, os_strlen(cmd
));
191 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
192 if (*pos
< '0' || *pos
> '9')
196 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
200 if (len
!= 4 && len
!= 8) {
201 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
207 unsigned int pin_val
;
209 if (!wps_pin_valid(pin_val
)) {
210 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
211 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
212 if (os_snprintf_error(buflen
, ret
))
218 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
219 if (os_snprintf_error(buflen
, ret
))
226 #ifdef CONFIG_WPS_NFC
227 static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data
*hapd
,
234 len
= os_strlen(pos
);
239 buf
= wpabuf_alloc(len
);
242 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
247 ret
= hostapd_wps_nfc_tag_read(hapd
, buf
);
254 static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data
*hapd
,
255 char *cmd
, char *reply
,
262 if (os_strcmp(cmd
, "WPS") == 0)
264 else if (os_strcmp(cmd
, "NDEF") == 0)
269 buf
= hostapd_wps_nfc_config_token(hapd
, ndef
);
273 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
284 static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data
*hapd
,
285 char *reply
, size_t max_len
,
291 buf
= hostapd_wps_nfc_token_gen(hapd
, ndef
);
295 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
306 static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data
*hapd
,
307 char *cmd
, char *reply
,
310 if (os_strcmp(cmd
, "WPS") == 0)
311 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
314 if (os_strcmp(cmd
, "NDEF") == 0)
315 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd
, reply
,
318 if (os_strcmp(cmd
, "enable") == 0)
319 return hostapd_wps_nfc_token_enable(hapd
);
321 if (os_strcmp(cmd
, "disable") == 0) {
322 hostapd_wps_nfc_token_disable(hapd
);
330 static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data
*hapd
,
331 char *cmd
, char *reply
,
339 pos
= os_strchr(cmd
, ' ');
344 if (os_strcmp(cmd
, "WPS") == 0)
346 else if (os_strcmp(cmd
, "NDEF") == 0)
351 if (os_strcmp(pos
, "WPS-CR") == 0)
352 buf
= hostapd_wps_nfc_hs_cr(hapd
, ndef
);
358 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
369 static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data
*hapd
,
373 struct wpabuf
*req
, *sel
;
375 char *pos
, *role
, *type
, *pos2
;
378 pos
= os_strchr(role
, ' ');
384 pos
= os_strchr(type
, ' ');
389 pos2
= os_strchr(pos
, ' ');
394 len
= os_strlen(pos
);
399 req
= wpabuf_alloc(len
);
402 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
407 len
= os_strlen(pos2
);
414 sel
= wpabuf_alloc(len
);
419 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
425 if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0) {
426 ret
= hostapd_wps_nfc_report_handover(hapd
, req
, sel
);
428 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
429 "reported: role=%s type=%s", role
, type
);
438 #endif /* CONFIG_WPS_NFC */
441 static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data
*hapd
, char *txt
,
442 char *buf
, size_t buflen
)
448 pos
= os_strchr(txt
, ' ');
452 if (os_strcmp(txt
, "disable") == 0) {
453 hostapd_wps_ap_pin_disable(hapd
);
454 return os_snprintf(buf
, buflen
, "OK\n");
457 if (os_strcmp(txt
, "random") == 0) {
460 pin_txt
= hostapd_wps_ap_pin_random(hapd
, timeout
);
463 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
466 if (os_strcmp(txt
, "get") == 0) {
467 pin_txt
= hostapd_wps_ap_pin_get(hapd
);
470 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
473 if (os_strcmp(txt
, "set") == 0) {
478 pos
= os_strchr(pos
, ' ');
483 if (os_strlen(pin
) > buflen
)
485 if (hostapd_wps_ap_pin_set(hapd
, pin
, timeout
) < 0)
487 return os_snprintf(buf
, buflen
, "%s", pin
);
494 static int hostapd_ctrl_iface_wps_config(struct hostapd_data
*hapd
, char *txt
)
497 char *ssid
, *auth
, *encr
= NULL
, *key
= NULL
;
500 pos
= os_strchr(txt
, ' ');
506 pos
= os_strchr(pos
, ' ');
510 pos
= os_strchr(pos
, ' ');
517 return hostapd_wps_config_ap(hapd
, ssid
, auth
, encr
, key
);
521 static const char * pbc_status_str(enum pbc_status status
)
524 case WPS_PBC_STATUS_DISABLE
:
526 case WPS_PBC_STATUS_ACTIVE
:
528 case WPS_PBC_STATUS_TIMEOUT
:
530 case WPS_PBC_STATUS_OVERLAP
:
538 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data
*hapd
,
539 char *buf
, size_t buflen
)
547 ret
= os_snprintf(pos
, end
- pos
, "PBC Status: %s\n",
548 pbc_status_str(hapd
->wps_stats
.pbc_status
));
550 if (os_snprintf_error(end
- pos
, ret
))
554 ret
= os_snprintf(pos
, end
- pos
, "Last WPS result: %s\n",
555 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
557 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
558 "Failed" : "None")));
560 if (os_snprintf_error(end
- pos
, ret
))
564 /* If status == Failure - Add possible Reasons */
565 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
566 hapd
->wps_stats
.failure_reason
> 0) {
567 ret
= os_snprintf(pos
, end
- pos
,
568 "Failure Reason: %s\n",
569 wps_ei_str(hapd
->wps_stats
.failure_reason
));
571 if (os_snprintf_error(end
- pos
, ret
))
576 if (hapd
->wps_stats
.status
) {
577 ret
= os_snprintf(pos
, end
- pos
, "Peer Address: " MACSTR
"\n",
578 MAC2STR(hapd
->wps_stats
.peer_addr
));
580 if (os_snprintf_error(end
- pos
, ret
))
588 #endif /* CONFIG_WPS */
592 static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data
*hapd
,
598 if (hwaddr_aton(cmd
, addr
))
611 return hs20_send_wnm_notification(hapd
, addr
, 1, url
);
615 static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data
*hapd
,
619 int code
, reauth_delay
, ret
;
624 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
625 if (hwaddr_aton(cmd
, addr
))
628 pos
= os_strchr(cmd
, ' ');
634 pos
= os_strchr(pos
, ' ');
638 reauth_delay
= atoi(pos
);
641 pos
= os_strchr(pos
, ' ');
644 url_len
= os_strlen(pos
);
647 req
= wpabuf_alloc(4 + url_len
);
650 wpabuf_put_u8(req
, code
);
651 wpabuf_put_le16(req
, reauth_delay
);
652 wpabuf_put_u8(req
, url_len
);
654 wpabuf_put_data(req
, pos
, url_len
);
656 wpa_printf(MSG_DEBUG
, "HS 2.0: Send WNM-Notification to " MACSTR
657 " to indicate imminent deauthentication (code=%d "
658 "reauth_delay=%d)", MAC2STR(addr
), code
, reauth_delay
);
659 ret
= hs20_send_wnm_notification_deauth_req(hapd
, addr
, req
);
664 #endif /* CONFIG_HS20 */
667 #ifdef CONFIG_INTERWORKING
669 static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data
*hapd
,
672 u8 qos_map_set
[16 + 2 * 21], count
= 0;
673 const char *pos
= cmd
;
677 if (count
== sizeof(qos_map_set
)) {
678 wpa_printf(MSG_ERROR
, "Too many qos_map_set parameters");
683 if (val
< 0 || val
> 255) {
684 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
688 qos_map_set
[count
++] = val
;
689 pos
= os_strchr(pos
, ',');
695 if (count
< 16 || count
& 1) {
696 wpa_printf(MSG_INFO
, "Invalid QoS Map Set");
700 ret
= hostapd_drv_set_qos_map(hapd
, qos_map_set
, count
);
702 wpa_printf(MSG_INFO
, "Failed to set QoS Map Set");
706 os_memcpy(hapd
->conf
->qos_map_set
, qos_map_set
, count
);
707 hapd
->conf
->qos_map_set_len
= count
;
713 static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data
*hapd
,
717 struct sta_info
*sta
;
719 u8
*qos_map_set
= hapd
->conf
->qos_map_set
;
720 u8 qos_map_set_len
= hapd
->conf
->qos_map_set_len
;
723 if (!qos_map_set_len
) {
724 wpa_printf(MSG_INFO
, "QoS Map Set is not set");
728 if (hwaddr_aton(cmd
, addr
))
731 sta
= ap_get_sta(hapd
, addr
);
733 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" not found "
734 "for QoS Map Configuration message",
739 if (!sta
->qos_map_enabled
) {
740 wpa_printf(MSG_DEBUG
, "Station " MACSTR
" did not indicate "
741 "support for QoS Map", MAC2STR(addr
));
745 buf
= wpabuf_alloc(2 + 2 + qos_map_set_len
);
749 wpabuf_put_u8(buf
, WLAN_ACTION_QOS
);
750 wpabuf_put_u8(buf
, QOS_QOS_MAP_CONFIG
);
752 /* QoS Map Set Element */
753 wpabuf_put_u8(buf
, WLAN_EID_QOS_MAP_SET
);
754 wpabuf_put_u8(buf
, qos_map_set_len
);
755 wpabuf_put_data(buf
, qos_map_set
, qos_map_set_len
);
757 ret
= hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, addr
,
758 wpabuf_head(buf
), wpabuf_len(buf
));
764 #endif /* CONFIG_INTERWORKING */
769 static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data
*hapd
,
774 struct sta_info
*sta
;
776 if (hwaddr_aton(cmd
, addr
))
780 disassoc_timer
= atoi(cmd
+ 17);
782 sta
= ap_get_sta(hapd
, addr
);
784 wpa_printf(MSG_DEBUG
, "Station " MACSTR
785 " not found for disassociation imminent message",
790 return wnm_send_disassoc_imminent(hapd
, sta
, disassoc_timer
);
794 static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data
*hapd
,
798 const char *url
, *timerstr
;
800 struct sta_info
*sta
;
802 if (hwaddr_aton(cmd
, addr
))
805 sta
= ap_get_sta(hapd
, addr
);
807 wpa_printf(MSG_DEBUG
, "Station " MACSTR
808 " not found for ESS disassociation imminent message",
814 if (*timerstr
!= ' ')
817 disassoc_timer
= atoi(timerstr
);
818 if (disassoc_timer
< 0 || disassoc_timer
> 65535)
821 url
= os_strchr(timerstr
, ' ');
826 return wnm_send_ess_disassoc_imminent(hapd
, sta
, url
, disassoc_timer
);
830 static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data
*hapd
,
834 const char *pos
, *end
;
835 int disassoc_timer
= 0;
836 struct sta_info
*sta
;
837 u8 req_mode
= 0, valid_int
= 0x01;
846 if (hwaddr_aton(cmd
, addr
)) {
847 wpa_printf(MSG_DEBUG
, "Invalid STA MAC address");
851 sta
= ap_get_sta(hapd
, addr
);
853 wpa_printf(MSG_DEBUG
, "Station " MACSTR
854 " not found for BSS TM Request message",
859 pos
= os_strstr(cmd
, " disassoc_timer=");
862 disassoc_timer
= atoi(pos
);
863 if (disassoc_timer
< 0 || disassoc_timer
> 65535) {
864 wpa_printf(MSG_DEBUG
, "Invalid disassoc_timer");
869 pos
= os_strstr(cmd
, " valid_int=");
872 valid_int
= atoi(pos
);
875 pos
= os_strstr(cmd
, " bss_term=");
878 req_mode
|= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED
;
879 /* TODO: TSF configurable/learnable */
880 bss_term_dur
[0] = 4; /* Subelement ID */
881 bss_term_dur
[1] = 10; /* Length */
882 os_memset(bss_term_dur
, 2, 8);
883 end
= os_strchr(pos
, ',');
885 wpa_printf(MSG_DEBUG
, "Invalid bss_term data");
889 WPA_PUT_LE16(&bss_term_dur
[10], atoi(end
));
892 nei_len
= ieee802_11_parse_candidate_list(cmd
, nei_rep
,
897 pos
= os_strstr(cmd
, " url=");
901 end
= os_strchr(pos
, ' ');
905 len
= os_strlen(pos
);
906 url
= os_malloc(len
+ 1);
909 os_memcpy(url
, pos
, len
);
911 req_mode
|= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT
;
914 if (os_strstr(cmd
, " pref=1"))
915 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
916 if (os_strstr(cmd
, " abridged=1"))
917 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
918 if (os_strstr(cmd
, " disassoc_imminent=1"))
919 req_mode
|= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
922 pos
= os_strstr(cmd
, "mbo=");
924 unsigned int mbo_reason
, cell_pref
, reassoc_delay
;
927 ret
= sscanf(pos
, "mbo=%u:%u:%u", &mbo_reason
,
928 &reassoc_delay
, &cell_pref
);
930 wpa_printf(MSG_DEBUG
,
931 "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
936 if (mbo_reason
> MBO_TRANSITION_REASON_PREMIUM_AP
) {
937 wpa_printf(MSG_DEBUG
,
938 "Invalid MBO transition reason code %u",
944 /* Valid values for Cellular preference are: 0, 1, 255 */
945 if (cell_pref
!= 0 && cell_pref
!= 1 && cell_pref
!= 255) {
946 wpa_printf(MSG_DEBUG
,
947 "Invalid MBO cellular capability %u",
953 if (reassoc_delay
> 65535 ||
955 !(req_mode
& WNM_BSS_TM_REQ_DISASSOC_IMMINENT
))) {
956 wpa_printf(MSG_DEBUG
,
957 "MBO: Assoc retry delay is only valid in disassoc imminent mode");
962 *mbo_pos
++ = MBO_ATTR_ID_TRANSITION_REASON
;
964 *mbo_pos
++ = mbo_reason
;
965 *mbo_pos
++ = MBO_ATTR_ID_CELL_DATA_PREF
;
967 *mbo_pos
++ = cell_pref
;
970 *mbo_pos
++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY
;
972 WPA_PUT_LE16(mbo_pos
, reassoc_delay
);
976 mbo_len
= mbo_pos
- mbo
;
978 #endif /* CONFIG_MBO */
980 ret
= wnm_send_bss_tm_req(hapd
, sta
, req_mode
, disassoc_timer
,
981 valid_int
, bss_term_dur
, url
,
982 nei_len
? nei_rep
: NULL
, nei_len
,
983 mbo_len
? mbo
: NULL
, mbo_len
);
986 #endif /* CONFIG_MBO */
991 #endif /* CONFIG_WNM_AP */
994 static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data
*hapd
,
995 char *buf
, size_t buflen
)
1003 WPA_ASSERT(hapd
->conf
->wpa_key_mgmt
);
1005 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) {
1006 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK ");
1007 if (os_snprintf_error(end
- pos
, ret
))
1011 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1012 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP ");
1013 if (os_snprintf_error(end
- pos
, ret
))
1017 #ifdef CONFIG_IEEE80211R_AP
1018 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1019 ret
= os_snprintf(pos
, end
- pos
, "FT-PSK ");
1020 if (os_snprintf_error(end
- pos
, ret
))
1024 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1025 ret
= os_snprintf(pos
, end
- pos
, "FT-EAP ");
1026 if (os_snprintf_error(end
- pos
, ret
))
1031 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
1032 ret
= os_snprintf(pos
, end
- pos
, "FT-SAE ");
1033 if (os_snprintf_error(end
- pos
, ret
))
1037 #endif /* CONFIG_SAE */
1039 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
1040 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA256 ");
1041 if (os_snprintf_error(end
- pos
, ret
))
1045 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
1046 ret
= os_snprintf(pos
, end
- pos
, "FT-FILS-SHA384 ");
1047 if (os_snprintf_error(end
- pos
, ret
))
1051 #endif /* CONFIG_FILS */
1052 #endif /* CONFIG_IEEE80211R_AP */
1053 #ifdef CONFIG_IEEE80211W
1054 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1055 ret
= os_snprintf(pos
, end
- pos
, "WPA-PSK-SHA256 ");
1056 if (os_snprintf_error(end
- pos
, ret
))
1060 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1061 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SHA256 ");
1062 if (os_snprintf_error(end
- pos
, ret
))
1066 #endif /* CONFIG_IEEE80211W */
1068 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_SAE
) {
1069 ret
= os_snprintf(pos
, end
- pos
, "SAE ");
1070 if (os_snprintf_error(end
- pos
, ret
))
1074 #endif /* CONFIG_SAE */
1075 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
1076 ret
= os_snprintf(pos
, end
- pos
, "WPA-EAP-SUITE-B ");
1077 if (os_snprintf_error(end
- pos
, ret
))
1081 if (hapd
->conf
->wpa_key_mgmt
&
1082 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
1083 ret
= os_snprintf(pos
, end
- pos
,
1084 "WPA-EAP-SUITE-B-192 ");
1085 if (os_snprintf_error(end
- pos
, ret
))
1090 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
1091 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA256 ");
1092 if (os_snprintf_error(end
- pos
, ret
))
1096 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
1097 ret
= os_snprintf(pos
, end
- pos
, "FILS-SHA384 ");
1098 if (os_snprintf_error(end
- pos
, ret
))
1102 #endif /* CONFIG_FILS */
1105 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) {
1106 ret
= os_snprintf(pos
, end
- pos
, "OWE ");
1107 if (os_snprintf_error(end
- pos
, ret
))
1111 #endif /* CONFIG_OWE */
1114 if (hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) {
1115 ret
= os_snprintf(pos
, end
- pos
, "DPP ");
1116 if (os_snprintf_error(end
- pos
, ret
))
1120 #endif /* CONFIG_DPP */
1122 if (pos
> buf
&& *(pos
- 1) == ' ') {
1131 static int hostapd_ctrl_iface_get_config(struct hostapd_data
*hapd
,
1132 char *buf
, size_t buflen
)
1140 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n"
1142 MAC2STR(hapd
->own_addr
),
1143 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
1144 hapd
->conf
->ssid
.ssid_len
));
1145 if (os_snprintf_error(end
- pos
, ret
))
1150 ret
= os_snprintf(pos
, end
- pos
, "wps_state=%s\n",
1151 hapd
->conf
->wps_state
== 0 ? "disabled" :
1152 (hapd
->conf
->wps_state
== 1 ? "not configured" :
1154 if (os_snprintf_error(end
- pos
, ret
))
1158 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1159 hapd
->conf
->ssid
.wpa_passphrase
) {
1160 ret
= os_snprintf(pos
, end
- pos
, "passphrase=%s\n",
1161 hapd
->conf
->ssid
.wpa_passphrase
);
1162 if (os_snprintf_error(end
- pos
, ret
))
1167 if (hapd
->conf
->wps_state
&& hapd
->conf
->wpa
&&
1168 hapd
->conf
->ssid
.wpa_psk
&&
1169 hapd
->conf
->ssid
.wpa_psk
->group
) {
1170 char hex
[PMK_LEN
* 2 + 1];
1171 wpa_snprintf_hex(hex
, sizeof(hex
),
1172 hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
1173 ret
= os_snprintf(pos
, end
- pos
, "psk=%s\n", hex
);
1174 if (os_snprintf_error(end
- pos
, ret
))
1178 #endif /* CONFIG_WPS */
1180 if (hapd
->conf
->wpa
) {
1181 ret
= os_snprintf(pos
, end
- pos
, "wpa=%d\n", hapd
->conf
->wpa
);
1182 if (os_snprintf_error(end
- pos
, ret
))
1187 if (hapd
->conf
->wpa
&& hapd
->conf
->wpa_key_mgmt
) {
1188 ret
= os_snprintf(pos
, end
- pos
, "key_mgmt=");
1189 if (os_snprintf_error(end
- pos
, ret
))
1193 pos
+= hostapd_ctrl_iface_get_key_mgmt(hapd
, pos
, end
- pos
);
1195 ret
= os_snprintf(pos
, end
- pos
, "\n");
1196 if (os_snprintf_error(end
- pos
, ret
))
1201 if (hapd
->conf
->wpa
) {
1202 ret
= os_snprintf(pos
, end
- pos
, "group_cipher=%s\n",
1203 wpa_cipher_txt(hapd
->conf
->wpa_group
));
1204 if (os_snprintf_error(end
- pos
, ret
))
1209 if ((hapd
->conf
->wpa
& WPA_PROTO_RSN
) && hapd
->conf
->rsn_pairwise
) {
1210 ret
= os_snprintf(pos
, end
- pos
, "rsn_pairwise_cipher=");
1211 if (os_snprintf_error(end
- pos
, ret
))
1215 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->rsn_pairwise
,
1221 ret
= os_snprintf(pos
, end
- pos
, "\n");
1222 if (os_snprintf_error(end
- pos
, ret
))
1227 if ((hapd
->conf
->wpa
& WPA_PROTO_WPA
) && hapd
->conf
->wpa_pairwise
) {
1228 ret
= os_snprintf(pos
, end
- pos
, "wpa_pairwise_cipher=");
1229 if (os_snprintf_error(end
- pos
, ret
))
1233 ret
= wpa_write_ciphers(pos
, end
, hapd
->conf
->wpa_pairwise
,
1239 ret
= os_snprintf(pos
, end
- pos
, "\n");
1240 if (os_snprintf_error(end
- pos
, ret
))
1249 static int hostapd_ctrl_iface_set(struct hostapd_data
*hapd
, char *cmd
)
1254 value
= os_strchr(cmd
, ' ');
1259 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
1261 #ifdef CONFIG_WPS_TESTING
1262 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
1264 val
= strtol(value
, NULL
, 0);
1265 if (val
< 0 || val
> 0xff) {
1267 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
1268 "wps_version_number %ld", val
);
1270 wps_version_number
= val
;
1271 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
1273 (wps_version_number
& 0xf0) >> 4,
1274 wps_version_number
& 0x0f);
1275 hostapd_wps_update_ie(hapd
);
1277 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
1278 wps_testing_dummy_cred
= atoi(value
);
1279 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
1280 wps_testing_dummy_cred
);
1281 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
1282 wps_corrupt_pkhash
= atoi(value
);
1283 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
1284 wps_corrupt_pkhash
);
1285 #endif /* CONFIG_WPS_TESTING */
1286 #ifdef CONFIG_TESTING_OPTIONS
1287 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
1288 hapd
->ext_mgmt_frame_handling
= atoi(value
);
1289 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
1290 hapd
->ext_eapol_frame_io
= atoi(value
);
1292 } else if (os_strcasecmp(cmd
, "dpp_config_obj_override") == 0) {
1293 os_free(hapd
->dpp_config_obj_override
);
1294 hapd
->dpp_config_obj_override
= os_strdup(value
);
1295 } else if (os_strcasecmp(cmd
, "dpp_discovery_override") == 0) {
1296 os_free(hapd
->dpp_discovery_override
);
1297 hapd
->dpp_discovery_override
= os_strdup(value
);
1298 } else if (os_strcasecmp(cmd
, "dpp_groups_override") == 0) {
1299 os_free(hapd
->dpp_groups_override
);
1300 hapd
->dpp_groups_override
= os_strdup(value
);
1301 } else if (os_strcasecmp(cmd
,
1302 "dpp_ignore_netaccesskey_mismatch") == 0) {
1303 hapd
->dpp_ignore_netaccesskey_mismatch
= atoi(value
);
1304 #endif /* CONFIG_DPP */
1305 #endif /* CONFIG_TESTING_OPTIONS */
1307 } else if (os_strcasecmp(cmd
, "mbo_assoc_disallow") == 0) {
1310 if (!hapd
->conf
->mbo_enabled
)
1314 if (val
< 0 || val
> 1)
1317 hapd
->mbo_assoc_disallow
= val
;
1318 ieee802_11_update_beacons(hapd
->iface
);
1321 * TODO: Need to configure drivers that do AP MLME offload with
1322 * disallowing station logic.
1324 #endif /* CONFIG_MBO */
1326 } else if (os_strcasecmp(cmd
, "dpp_configurator_params") == 0) {
1327 os_free(hapd
->dpp_configurator_params
);
1328 hapd
->dpp_configurator_params
= os_strdup(value
);
1329 #endif /* CONFIG_DPP */
1331 struct sta_info
*sta
;
1332 struct vlan_description vlan_id
;
1334 ret
= hostapd_set_iface(hapd
->iconf
, hapd
->conf
, cmd
, value
);
1338 if (os_strcasecmp(cmd
, "deny_mac_file") == 0) {
1339 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1340 if (hostapd_maclist_found(
1341 hapd
->conf
->deny_mac
,
1342 hapd
->conf
->num_deny_mac
, sta
->addr
,
1344 (!vlan_id
.notempty
||
1345 !vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1347 hapd
, sta
, sta
->addr
,
1348 WLAN_REASON_UNSPECIFIED
);
1350 } else if (hapd
->conf
->macaddr_acl
== DENY_UNLESS_ACCEPTED
&&
1351 os_strcasecmp(cmd
, "accept_mac_file") == 0) {
1352 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
1353 if (!hostapd_maclist_found(
1354 hapd
->conf
->accept_mac
,
1355 hapd
->conf
->num_accept_mac
,
1356 sta
->addr
, &vlan_id
) ||
1357 (vlan_id
.notempty
&&
1358 vlan_compare(&vlan_id
, sta
->vlan_desc
)))
1360 hapd
, sta
, sta
->addr
,
1361 WLAN_REASON_UNSPECIFIED
);
1370 static int hostapd_ctrl_iface_get(struct hostapd_data
*hapd
, char *cmd
,
1371 char *buf
, size_t buflen
)
1375 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
1377 if (os_strcmp(cmd
, "version") == 0) {
1378 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
1379 if (os_snprintf_error(buflen
, res
))
1382 } else if (os_strcmp(cmd
, "tls_library") == 0) {
1383 res
= tls_get_library_version(buf
, buflen
);
1384 if (os_snprintf_error(buflen
, res
))
1393 static int hostapd_ctrl_iface_enable(struct hostapd_iface
*iface
)
1395 if (hostapd_enable_iface(iface
) < 0) {
1396 wpa_printf(MSG_ERROR
, "Enabling of interface failed");
1403 static int hostapd_ctrl_iface_reload(struct hostapd_iface
*iface
)
1405 if (hostapd_reload_iface(iface
) < 0) {
1406 wpa_printf(MSG_ERROR
, "Reloading of interface failed");
1413 static int hostapd_ctrl_iface_disable(struct hostapd_iface
*iface
)
1415 if (hostapd_disable_iface(iface
) < 0) {
1416 wpa_printf(MSG_ERROR
, "Disabling of interface failed");
1423 #ifdef CONFIG_TESTING_OPTIONS
1425 static int hostapd_ctrl_iface_radar(struct hostapd_data
*hapd
, char *cmd
)
1427 union wpa_event_data data
;
1429 enum wpa_event_type event
;
1431 wpa_printf(MSG_DEBUG
, "RADAR TEST: %s", cmd
);
1433 os_memset(&data
, 0, sizeof(data
));
1435 param
= os_strchr(cmd
, ' ');
1440 if (os_strcmp(cmd
, "DETECTED") == 0)
1441 event
= EVENT_DFS_RADAR_DETECTED
;
1442 else if (os_strcmp(cmd
, "CAC-FINISHED") == 0)
1443 event
= EVENT_DFS_CAC_FINISHED
;
1444 else if (os_strcmp(cmd
, "CAC-ABORTED") == 0)
1445 event
= EVENT_DFS_CAC_ABORTED
;
1446 else if (os_strcmp(cmd
, "NOP-FINISHED") == 0)
1447 event
= EVENT_DFS_NOP_FINISHED
;
1449 wpa_printf(MSG_DEBUG
, "Unsupported RADAR test command: %s",
1454 pos
= os_strstr(param
, "freq=");
1456 data
.dfs_event
.freq
= atoi(pos
+ 5);
1458 pos
= os_strstr(param
, "ht_enabled=1");
1460 data
.dfs_event
.ht_enabled
= 1;
1462 pos
= os_strstr(param
, "chan_offset=");
1464 data
.dfs_event
.chan_offset
= atoi(pos
+ 12);
1466 pos
= os_strstr(param
, "chan_width=");
1468 data
.dfs_event
.chan_width
= atoi(pos
+ 11);
1470 pos
= os_strstr(param
, "cf1=");
1472 data
.dfs_event
.cf1
= atoi(pos
+ 4);
1474 pos
= os_strstr(param
, "cf2=");
1476 data
.dfs_event
.cf2
= atoi(pos
+ 4);
1478 wpa_supplicant_event(hapd
, event
, &data
);
1484 static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data
*hapd
, char *cmd
)
1490 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
1492 len
= os_strlen(cmd
);
1497 buf
= os_malloc(len
);
1501 if (hexstr2bin(cmd
, buf
, len
) < 0) {
1506 res
= hostapd_drv_send_mlme(hapd
, buf
, len
, 0);
1512 static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data
*hapd
,
1518 int stype
= 0, ok
= 0;
1519 union wpa_event_data event
;
1521 if (!hapd
->ext_mgmt_frame_handling
)
1524 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1526 wpa_printf(MSG_DEBUG
, "External MGMT TX status process: %s", cmd
);
1529 param
= os_strstr(pos
, "stype=");
1532 stype
= atoi(param
);
1535 param
= os_strstr(pos
, " ok=");
1541 param
= os_strstr(pos
, " buf=");
1546 len
= os_strlen(param
);
1551 buf
= os_malloc(len
);
1552 if (!buf
|| hexstr2bin(param
, buf
, len
) < 0) {
1557 os_memset(&event
, 0, sizeof(event
));
1558 event
.tx_status
.type
= WLAN_FC_TYPE_MGMT
;
1559 event
.tx_status
.data
= buf
;
1560 event
.tx_status
.data_len
= len
;
1561 event
.tx_status
.stype
= stype
;
1562 event
.tx_status
.ack
= ok
;
1563 hapd
->ext_mgmt_frame_handling
= 0;
1564 wpa_supplicant_event(hapd
, EVENT_TX_STATUS
, &event
);
1565 hapd
->ext_mgmt_frame_handling
= 1;
1573 static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data
*hapd
,
1579 int freq
= 0, datarate
= 0, ssi_signal
= 0;
1580 union wpa_event_data event
;
1582 if (!hapd
->ext_mgmt_frame_handling
)
1585 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1587 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
1590 param
= os_strstr(pos
, "freq=");
1596 param
= os_strstr(pos
, " datarate=");
1599 datarate
= atoi(param
);
1602 param
= os_strstr(pos
, " ssi_signal=");
1605 ssi_signal
= atoi(param
);
1608 param
= os_strstr(pos
, " frame=");
1613 len
= os_strlen(param
);
1618 buf
= os_malloc(len
);
1622 if (hexstr2bin(param
, buf
, len
) < 0) {
1627 os_memset(&event
, 0, sizeof(event
));
1628 event
.rx_mgmt
.freq
= freq
;
1629 event
.rx_mgmt
.frame
= buf
;
1630 event
.rx_mgmt
.frame_len
= len
;
1631 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1632 event
.rx_mgmt
.datarate
= datarate
;
1633 hapd
->ext_mgmt_frame_handling
= 0;
1634 wpa_supplicant_event(hapd
, EVENT_RX_MGMT
, &event
);
1635 hapd
->ext_mgmt_frame_handling
= 1;
1643 static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data
*hapd
, char *cmd
)
1646 u8 src
[ETH_ALEN
], *buf
;
1650 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
1653 used
= hwaddr_aton2(pos
, src
);
1660 len
= os_strlen(pos
);
1665 buf
= os_malloc(len
);
1669 if (hexstr2bin(pos
, buf
, len
) < 0) {
1674 ieee802_1x_receive(hapd
, src
, buf
, len
);
1681 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
1685 const u16
*pos
= buf
;
1687 for (i
= 0; i
< len
/ 2; i
++)
1691 sum
= (sum
& 0xffff) + (sum
>> 16);
1693 return sum
^ 0xffff;
1697 #define HWSIM_PACKETLEN 1500
1698 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1700 static void hostapd_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
1703 struct hostapd_data
*hapd
= ctx
;
1704 const struct ether_header
*eth
;
1709 if (len
!= HWSIM_PACKETLEN
)
1712 eth
= (const struct ether_header
*) buf
;
1713 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
1714 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
1716 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
1717 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
1720 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
1726 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
1727 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
1731 static int hostapd_ctrl_iface_data_test_config(struct hostapd_data
*hapd
,
1734 int enabled
= atoi(cmd
);
1739 if (hapd
->l2_test
) {
1740 l2_packet_deinit(hapd
->l2_test
);
1741 hapd
->l2_test
= NULL
;
1742 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1743 "test data: Disabled");
1751 pos
= os_strstr(cmd
, " ifname=");
1755 ifname
= hapd
->conf
->iface
;
1757 hapd
->l2_test
= l2_packet_init(ifname
, hapd
->own_addr
,
1758 ETHERTYPE_IP
, hostapd_data_test_rx
,
1760 if (hapd
->l2_test
== NULL
)
1763 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: Enabled");
1769 static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data
*hapd
, char *cmd
)
1771 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
1776 u8 buf
[2 + HWSIM_PACKETLEN
];
1777 struct ether_header
*eth
;
1782 if (hapd
->l2_test
== NULL
)
1785 /* format: <dst> <src> <tos> */
1788 used
= hwaddr_aton2(pos
, dst
);
1794 used
= hwaddr_aton2(pos
, src
);
1799 val
= strtol(pos
, NULL
, 0);
1800 if (val
< 0 || val
> 0xff)
1804 eth
= (struct ether_header
*) &buf
[2];
1805 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
1806 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
1807 eth
->ether_type
= htons(ETHERTYPE_IP
);
1808 ip
= (struct iphdr
*) (eth
+ 1);
1809 os_memset(ip
, 0, sizeof(*ip
));
1814 ip
->tot_len
= htons(HWSIM_IP_LEN
);
1816 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
1817 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
1818 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
1819 dpos
= (u8
*) (ip
+ 1);
1820 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
1823 if (l2_packet_send(hapd
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
1824 HWSIM_PACKETLEN
) < 0)
1827 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX dst=" MACSTR
1828 " src=" MACSTR
" tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
1834 static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data
*hapd
,
1838 struct ether_header
*eth
;
1839 struct l2_packet_data
*l2
= NULL
;
1843 const char *ifname
= hapd
->conf
->iface
;
1845 if (os_strncmp(cmd
, "ifname=", 7) == 0) {
1848 cmd
= os_strchr(cmd
, ' ');
1854 len
= os_strlen(cmd
);
1855 if (len
& 1 || len
< ETH_HLEN
* 2)
1859 buf
= os_malloc(len
);
1863 if (hexstr2bin(cmd
, buf
, len
) < 0)
1866 eth
= (struct ether_header
*) buf
;
1867 ethertype
= ntohs(eth
->ether_type
);
1869 l2
= l2_packet_init(ifname
, hapd
->own_addr
, ethertype
,
1870 hostapd_data_test_rx
, hapd
, 1);
1874 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
1875 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
1878 l2_packet_deinit(l2
);
1881 return res
< 0 ? -1 : 0;
1885 static int hostapd_ctrl_test_alloc_fail(struct hostapd_data
*hapd
, char *cmd
)
1887 #ifdef WPA_TRACE_BFD
1890 wpa_trace_fail_after
= atoi(cmd
);
1891 pos
= os_strchr(cmd
, ':');
1894 os_strlcpy(wpa_trace_fail_func
, pos
,
1895 sizeof(wpa_trace_fail_func
));
1897 wpa_trace_fail_after
= 0;
1901 #else /* WPA_TRACE_BFD */
1903 #endif /* WPA_TRACE_BFD */
1907 static int hostapd_ctrl_get_alloc_fail(struct hostapd_data
*hapd
,
1908 char *buf
, size_t buflen
)
1910 #ifdef WPA_TRACE_BFD
1911 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
1912 wpa_trace_fail_func
);
1913 #else /* WPA_TRACE_BFD */
1915 #endif /* WPA_TRACE_BFD */
1919 static int hostapd_ctrl_test_fail(struct hostapd_data
*hapd
, char *cmd
)
1921 #ifdef WPA_TRACE_BFD
1924 wpa_trace_test_fail_after
= atoi(cmd
);
1925 pos
= os_strchr(cmd
, ':');
1928 os_strlcpy(wpa_trace_test_fail_func
, pos
,
1929 sizeof(wpa_trace_test_fail_func
));
1931 wpa_trace_test_fail_after
= 0;
1935 #else /* WPA_TRACE_BFD */
1937 #endif /* WPA_TRACE_BFD */
1941 static int hostapd_ctrl_get_fail(struct hostapd_data
*hapd
,
1942 char *buf
, size_t buflen
)
1944 #ifdef WPA_TRACE_BFD
1945 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
1946 wpa_trace_test_fail_func
);
1947 #else /* WPA_TRACE_BFD */
1949 #endif /* WPA_TRACE_BFD */
1953 static int hostapd_ctrl_reset_pn(struct hostapd_data
*hapd
, const char *cmd
)
1955 struct sta_info
*sta
;
1957 u8 zero
[WPA_TK_MAX_LEN
];
1959 os_memset(zero
, 0, sizeof(zero
));
1961 if (hwaddr_aton(cmd
, addr
))
1964 #ifdef CONFIG_IEEE80211W
1965 if (is_broadcast_ether_addr(addr
) && os_strstr(cmd
, "IGTK")) {
1966 if (hapd
->last_igtk_alg
== WPA_ALG_NONE
)
1969 wpa_printf(MSG_INFO
, "TESTING: Reset IPN for IGTK");
1971 /* First, use a zero key to avoid any possible duplicate key
1972 * avoidance in the driver. */
1973 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
1974 hapd
->last_igtk_alg
,
1975 broadcast_ether_addr
,
1976 hapd
->last_igtk_key_idx
, 1, NULL
, 0,
1977 zero
, hapd
->last_igtk_len
) < 0)
1980 /* Set the previously configured key to reset its TSC */
1981 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
1982 hapd
->last_igtk_alg
,
1983 broadcast_ether_addr
,
1984 hapd
->last_igtk_key_idx
, 1, NULL
, 0,
1986 hapd
->last_igtk_len
);
1988 #endif /* CONFIG_IEEE80211W */
1990 if (is_broadcast_ether_addr(addr
)) {
1991 if (hapd
->last_gtk_alg
== WPA_ALG_NONE
)
1994 wpa_printf(MSG_INFO
, "TESTING: Reset PN for GTK");
1996 /* First, use a zero key to avoid any possible duplicate key
1997 * avoidance in the driver. */
1998 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2000 broadcast_ether_addr
,
2001 hapd
->last_gtk_key_idx
, 1, NULL
, 0,
2002 zero
, hapd
->last_gtk_len
) < 0)
2005 /* Set the previously configured key to reset its TSC */
2006 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
,
2008 broadcast_ether_addr
,
2009 hapd
->last_gtk_key_idx
, 1, NULL
, 0,
2010 hapd
->last_gtk
, hapd
->last_gtk_len
);
2013 sta
= ap_get_sta(hapd
, addr
);
2017 if (sta
->last_tk_alg
== WPA_ALG_NONE
)
2020 wpa_printf(MSG_INFO
, "TESTING: Reset PN for " MACSTR
,
2021 MAC2STR(sta
->addr
));
2023 /* First, use a zero key to avoid any possible duplicate key avoidance
2025 if (hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2026 sta
->addr
, sta
->last_tk_key_idx
, 1, NULL
, 0,
2027 zero
, sta
->last_tk_len
) < 0)
2030 /* Set the previously configured key to reset its TSC/RSC */
2031 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, sta
->last_tk_alg
,
2032 sta
->addr
, sta
->last_tk_key_idx
, 1, NULL
, 0,
2033 sta
->last_tk
, sta
->last_tk_len
);
2037 static int hostapd_ctrl_set_key(struct hostapd_data
*hapd
, const char *cmd
)
2040 const char *pos
= cmd
;
2043 u8 seq
[6], key
[WPA_TK_MAX_LEN
];
2046 /* parameters: alg addr idx set_tx seq key */
2049 pos
= os_strchr(pos
, ' ');
2053 if (hwaddr_aton(pos
, addr
))
2060 pos
= os_strchr(pos
, ' ');
2065 pos
= os_strchr(pos
, ' ');
2069 if (hexstr2bin(pos
, seq
, sizeof(6)) < 0)
2075 key_len
= os_strlen(pos
) / 2;
2076 if (hexstr2bin(pos
, key
, key_len
) < 0)
2079 wpa_printf(MSG_INFO
, "TESTING: Set key");
2080 return hostapd_drv_set_key(hapd
->conf
->iface
, hapd
, alg
, addr
, idx
,
2081 set_tx
, seq
, 6, key
, key_len
);
2085 static int hostapd_ctrl_resend_m1(struct hostapd_data
*hapd
, const char *cmd
)
2087 struct sta_info
*sta
;
2090 if (hwaddr_aton(cmd
, addr
))
2093 sta
= ap_get_sta(hapd
, addr
);
2094 if (!sta
|| !sta
->wpa_sm
)
2097 wpa_printf(MSG_INFO
, "TESTING: Send M1 to " MACSTR
, MAC2STR(sta
->addr
));
2098 return wpa_auth_resend_m1(sta
->wpa_sm
,
2099 os_strstr(cmd
, "change-anonce") != NULL
);
2103 static int hostapd_ctrl_resend_m3(struct hostapd_data
*hapd
, const char *cmd
)
2105 struct sta_info
*sta
;
2108 if (hwaddr_aton(cmd
, addr
))
2111 sta
= ap_get_sta(hapd
, addr
);
2112 if (!sta
|| !sta
->wpa_sm
)
2115 wpa_printf(MSG_INFO
, "TESTING: Send M3 to " MACSTR
, MAC2STR(sta
->addr
));
2116 return wpa_auth_resend_m3(sta
->wpa_sm
);
2120 static int hostapd_ctrl_resend_group_m1(struct hostapd_data
*hapd
,
2123 struct sta_info
*sta
;
2126 if (hwaddr_aton(cmd
, addr
))
2129 sta
= ap_get_sta(hapd
, addr
);
2130 if (!sta
|| !sta
->wpa_sm
)
2133 wpa_printf(MSG_INFO
,
2134 "TESTING: Send group M1 for the same GTK and zero RSC to "
2135 MACSTR
, MAC2STR(sta
->addr
));
2136 return wpa_auth_resend_group_m1(sta
->wpa_sm
);
2139 #endif /* CONFIG_TESTING_OPTIONS */
2142 static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface
*iface
,
2146 struct csa_settings settings
;
2150 ret
= hostapd_parse_csa_settings(pos
, &settings
);
2154 for (i
= 0; i
< iface
->num_bss
; i
++) {
2155 ret
= hostapd_switch_channel(iface
->bss
[i
], &settings
);
2157 /* FIX: What do we do if CSA fails in the middle of
2158 * submitting multi-BSS CSA requests? */
2164 #else /* NEED_AP_MLME */
2166 #endif /* NEED_AP_MLME */
2170 static int hostapd_ctrl_iface_mib(struct hostapd_data
*hapd
, char *reply
,
2171 int reply_size
, const char *param
)
2173 #ifdef RADIUS_SERVER
2174 if (os_strcmp(param
, "radius_server") == 0) {
2175 return radius_server_get_mib(hapd
->radius_srv
, reply
,
2178 #endif /* RADIUS_SERVER */
2183 static int hostapd_ctrl_iface_vendor(struct hostapd_data
*hapd
, char *cmd
,
2184 char *buf
, size_t buflen
)
2189 unsigned int vendor_id
, subcmd
;
2190 struct wpabuf
*reply
;
2191 size_t data_len
= 0;
2193 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2194 vendor_id
= strtoul(cmd
, &pos
, 16);
2195 if (!isblank((unsigned char) *pos
))
2198 subcmd
= strtoul(pos
, &pos
, 10);
2201 if (!isblank((unsigned char) *pos
++))
2203 data_len
= os_strlen(pos
);
2208 data
= os_malloc(data_len
);
2212 if (hexstr2bin(pos
, data
, data_len
)) {
2213 wpa_printf(MSG_DEBUG
,
2214 "Vendor command: wrong parameter format");
2220 reply
= wpabuf_alloc((buflen
- 1) / 2);
2226 ret
= hostapd_drv_vendor_cmd(hapd
, vendor_id
, subcmd
, data
, data_len
,
2230 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
2240 static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data
*hapd
,
2244 struct sta_info
*sta
;
2246 if (hwaddr_aton(cmd
, addr
))
2249 sta
= ap_get_sta(hapd
, addr
);
2250 if (!sta
|| !sta
->eapol_sm
)
2253 eapol_auth_reauthenticate(sta
->eapol_sm
);
2258 static int hostapd_ctrl_iface_eapol_set(struct hostapd_data
*hapd
, char *cmd
)
2261 struct sta_info
*sta
;
2262 char *pos
= cmd
, *param
;
2264 if (hwaddr_aton(pos
, addr
) || pos
[17] != ' ')
2268 pos
= os_strchr(pos
, ' ');
2273 sta
= ap_get_sta(hapd
, addr
);
2274 if (!sta
|| !sta
->eapol_sm
)
2277 return eapol_auth_set_conf(sta
->eapol_sm
, param
, pos
);
2281 static int hostapd_ctrl_iface_log_level(struct hostapd_data
*hapd
, char *cmd
,
2282 char *buf
, size_t buflen
)
2284 char *pos
, *end
, *stamp
;
2287 /* cmd: "LOG_LEVEL [<level>]" */
2291 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2293 debug_level_str(wpa_debug_level
),
2294 wpa_debug_timestamp
);
2295 if (os_snprintf_error(end
- pos
, ret
))
2304 stamp
= os_strchr(cmd
, ' ');
2307 while (*stamp
== ' ') {
2312 if (os_strlen(cmd
)) {
2313 int level
= str_to_debug_level(cmd
);
2316 wpa_debug_level
= level
;
2319 if (stamp
&& os_strlen(stamp
))
2320 wpa_debug_timestamp
= atoi(stamp
);
2322 os_memcpy(buf
, "OK\n", 3);
2328 static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data
*hapd
,
2329 char *buf
, size_t buflen
)
2331 struct hostapd_iface
*iface
= hapd
->iface
;
2333 struct hostapd_sta_info
*info
;
2334 struct os_reltime now
;
2336 if (!iface
->num_sta_seen
)
2339 sta_track_expire(iface
, 0);
2344 os_get_reltime(&now
);
2345 dl_list_for_each_reverse(info
, &iface
->sta_seen
,
2346 struct hostapd_sta_info
, list
) {
2347 struct os_reltime age
;
2350 os_reltime_sub(&now
, &info
->last_seen
, &age
);
2351 ret
= os_snprintf(pos
, end
- pos
, MACSTR
" %u %d\n",
2352 MAC2STR(info
->addr
), (unsigned int) age
.sec
,
2354 if (os_snprintf_error(end
- pos
, ret
))
2361 #endif /* NEED_AP_MLME */
2364 static int hostapd_ctrl_iface_req_lci(struct hostapd_data
*hapd
,
2369 if (hwaddr_aton(cmd
, addr
)) {
2370 wpa_printf(MSG_INFO
, "CTRL: REQ_LCI: Invalid MAC address");
2374 return hostapd_send_lci_req(hapd
, addr
);
2378 static int hostapd_ctrl_iface_req_range(struct hostapd_data
*hapd
, char *cmd
)
2381 char *token
, *context
= NULL
;
2382 int random_interval
, min_ap
;
2383 u8 responders
[ETH_ALEN
* RRM_RANGE_REQ_MAX_RESPONDERS
];
2384 unsigned int n_responders
;
2386 token
= str_token(cmd
, " ", &context
);
2387 if (!token
|| hwaddr_aton(token
, addr
)) {
2388 wpa_printf(MSG_INFO
,
2389 "CTRL: REQ_RANGE - Bad destination address");
2393 token
= str_token(cmd
, " ", &context
);
2397 random_interval
= atoi(token
);
2398 if (random_interval
< 0 || random_interval
> 0xffff)
2401 token
= str_token(cmd
, " ", &context
);
2405 min_ap
= atoi(token
);
2406 if (min_ap
<= 0 || min_ap
> WLAN_RRM_RANGE_REQ_MAX_MIN_AP
)
2410 while ((token
= str_token(cmd
, " ", &context
))) {
2411 if (n_responders
== RRM_RANGE_REQ_MAX_RESPONDERS
) {
2412 wpa_printf(MSG_INFO
,
2413 "CTRL: REQ_RANGE: Too many responders");
2417 if (hwaddr_aton(token
, responders
+ n_responders
* ETH_ALEN
)) {
2418 wpa_printf(MSG_INFO
,
2419 "CTRL: REQ_RANGE: Bad responder address");
2426 if (!n_responders
) {
2427 wpa_printf(MSG_INFO
,
2428 "CTRL: REQ_RANGE - No FTM responder address");
2432 return hostapd_send_range_req(hapd
, addr
, random_interval
, min_ap
,
2433 responders
, n_responders
);
2437 static int hostapd_ctrl_iface_req_beacon(struct hostapd_data
*hapd
,
2438 const char *cmd
, char *reply
,
2447 if (hwaddr_aton(cmd
, addr
))
2449 pos
= os_strchr(cmd
, ' ');
2453 if (os_strncmp(pos
, "req_mode=", 9) == 0) {
2454 int val
= hex2byte(pos
+ 9);
2460 pos
= os_strchr(pos
, ' ');
2465 req
= wpabuf_parse_bin(pos
);
2469 ret
= hostapd_send_beacon_req(hapd
, addr
, req_mode
, req
);
2472 ret
= os_snprintf(reply
, reply_size
, "%d", ret
);
2477 static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data
*hapd
, char *buf
)
2479 struct wpa_ssid_value ssid
;
2481 struct wpabuf
*nr
, *lci
= NULL
, *civic
= NULL
;
2486 if (!(hapd
->conf
->radio_measurements
[0] &
2487 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
2488 wpa_printf(MSG_ERROR
,
2489 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
2493 if (hwaddr_aton(buf
, bssid
)) {
2494 wpa_printf(MSG_ERROR
, "CTRL: SET_NEIGHBOR: Bad BSSID");
2498 tmp
= os_strstr(buf
, "ssid=");
2499 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2500 wpa_printf(MSG_ERROR
,
2501 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
2504 buf
= os_strchr(tmp
+ 6, tmp
[5] == '"' ? '"' : ' ');
2508 tmp
= os_strstr(buf
, "nr=");
2510 wpa_printf(MSG_ERROR
,
2511 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
2515 buf
= os_strchr(tmp
, ' ');
2519 nr
= wpabuf_parse_bin(tmp
+ 3);
2521 wpa_printf(MSG_ERROR
,
2522 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
2529 tmp
= os_strstr(buf
, "lci=");
2531 buf
= os_strchr(tmp
, ' ');
2534 lci
= wpabuf_parse_bin(tmp
+ 4);
2536 wpa_printf(MSG_ERROR
,
2537 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
2546 tmp
= os_strstr(buf
, "civic=");
2548 buf
= os_strchr(tmp
, ' ');
2551 civic
= wpabuf_parse_bin(tmp
+ 6);
2553 wpa_printf(MSG_ERROR
,
2554 "CTRL: SET_NEIGHBOR: Bad civic subelement");
2564 if (os_strstr(buf
, "stat"))
2568 ret
= hostapd_neighbor_set(hapd
, bssid
, &ssid
, nr
, lci
, civic
,
2579 static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data
*hapd
,
2582 struct wpa_ssid_value ssid
;
2586 if (hwaddr_aton(buf
, bssid
)) {
2587 wpa_printf(MSG_ERROR
, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
2591 tmp
= os_strstr(buf
, "ssid=");
2592 if (!tmp
|| ssid_parse(tmp
+ 5, &ssid
)) {
2593 wpa_printf(MSG_ERROR
,
2594 "CTRL: REMOVE_NEIGHBORr: Bad or missing SSID");
2598 return hostapd_neighbor_remove(hapd
, bssid
, &ssid
);
2602 static int hostapd_ctrl_driver_flags(struct hostapd_iface
*iface
, char *buf
,
2608 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
2609 (long long unsigned) iface
->drv_flags
);
2610 if (os_snprintf_error(buflen
, ret
))
2616 for (i
= 0; i
< 64; i
++) {
2617 if (iface
->drv_flags
& (1LLU << i
)) {
2618 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
2619 driver_flag_to_string(1LLU << i
));
2620 if (os_snprintf_error(end
- pos
, ret
))
2630 static int hostapd_ctrl_iface_receive_process(struct hostapd_data
*hapd
,
2631 char *buf
, char *reply
,
2633 struct sockaddr_storage
*from
,
2638 os_memcpy(reply
, "OK\n", 3);
2641 if (os_strcmp(buf
, "PING") == 0) {
2642 os_memcpy(reply
, "PONG\n", 5);
2644 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
2645 if (wpa_debug_reopen_file() < 0)
2647 } else if (os_strcmp(buf
, "STATUS") == 0) {
2648 reply_len
= hostapd_ctrl_iface_status(hapd
, reply
,
2650 } else if (os_strcmp(buf
, "STATUS-DRIVER") == 0) {
2651 reply_len
= hostapd_drv_status(hapd
, reply
, reply_size
);
2652 } else if (os_strcmp(buf
, "MIB") == 0) {
2653 reply_len
= ieee802_11_get_mib(hapd
, reply
, reply_size
);
2654 if (reply_len
>= 0) {
2655 res
= wpa_get_mib(hapd
->wpa_auth
, reply
+ reply_len
,
2656 reply_size
- reply_len
);
2662 if (reply_len
>= 0) {
2663 res
= ieee802_1x_get_mib(hapd
, reply
+ reply_len
,
2664 reply_size
- reply_len
);
2670 #ifndef CONFIG_NO_RADIUS
2671 if (reply_len
>= 0) {
2672 res
= radius_client_get_mib(hapd
->radius
,
2674 reply_size
- reply_len
);
2680 #endif /* CONFIG_NO_RADIUS */
2681 } else if (os_strncmp(buf
, "MIB ", 4) == 0) {
2682 reply_len
= hostapd_ctrl_iface_mib(hapd
, reply
, reply_size
,
2684 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
2685 reply_len
= hostapd_ctrl_iface_sta_first(hapd
, reply
,
2687 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
2688 reply_len
= hostapd_ctrl_iface_sta(hapd
, buf
+ 4, reply
,
2690 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
2691 reply_len
= hostapd_ctrl_iface_sta_next(hapd
, buf
+ 9, reply
,
2693 } else if (os_strcmp(buf
, "ATTACH") == 0) {
2694 if (hostapd_ctrl_iface_attach(hapd
, from
, fromlen
))
2696 } else if (os_strcmp(buf
, "DETACH") == 0) {
2697 if (hostapd_ctrl_iface_detach(hapd
, from
, fromlen
))
2699 } else if (os_strncmp(buf
, "LEVEL ", 6) == 0) {
2700 if (hostapd_ctrl_iface_level(hapd
, from
, fromlen
,
2703 } else if (os_strncmp(buf
, "NEW_STA ", 8) == 0) {
2704 if (hostapd_ctrl_iface_new_sta(hapd
, buf
+ 8))
2706 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
2707 if (hostapd_ctrl_iface_deauthenticate(hapd
, buf
+ 15))
2709 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
2710 if (hostapd_ctrl_iface_disassociate(hapd
, buf
+ 13))
2712 #ifdef CONFIG_TAXONOMY
2713 } else if (os_strncmp(buf
, "SIGNATURE ", 10) == 0) {
2714 reply_len
= hostapd_ctrl_iface_signature(hapd
, buf
+ 10,
2716 #endif /* CONFIG_TAXONOMY */
2717 } else if (os_strncmp(buf
, "POLL_STA ", 9) == 0) {
2718 if (hostapd_ctrl_iface_poll_sta(hapd
, buf
+ 9))
2720 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
2721 if (hostapd_ctrl_iface_stop_ap(hapd
))
2723 #ifdef CONFIG_IEEE80211W
2725 } else if (os_strncmp(buf
, "SA_QUERY ", 9) == 0) {
2726 if (hostapd_ctrl_iface_sa_query(hapd
, buf
+ 9))
2728 #endif /* NEED_AP_MLME */
2729 #endif /* CONFIG_IEEE80211W */
2731 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
2732 if (hostapd_ctrl_iface_wps_pin(hapd
, buf
+ 8))
2734 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
2735 reply_len
= hostapd_ctrl_iface_wps_check_pin(
2736 hapd
, buf
+ 14, reply
, reply_size
);
2737 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
2738 if (hostapd_wps_button_pushed(hapd
, NULL
))
2740 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
2741 if (hostapd_wps_cancel(hapd
))
2743 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
2744 reply_len
= hostapd_ctrl_iface_wps_ap_pin(hapd
, buf
+ 11,
2746 } else if (os_strncmp(buf
, "WPS_CONFIG ", 11) == 0) {
2747 if (hostapd_ctrl_iface_wps_config(hapd
, buf
+ 11) < 0)
2749 } else if (os_strncmp(buf
, "WPS_GET_STATUS", 13) == 0) {
2750 reply_len
= hostapd_ctrl_iface_wps_get_status(hapd
, reply
,
2752 #ifdef CONFIG_WPS_NFC
2753 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
2754 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd
, buf
+ 17))
2756 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
2757 reply_len
= hostapd_ctrl_iface_wps_nfc_config_token(
2758 hapd
, buf
+ 21, reply
, reply_size
);
2759 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
2760 reply_len
= hostapd_ctrl_iface_wps_nfc_token(
2761 hapd
, buf
+ 14, reply
, reply_size
);
2762 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
2763 reply_len
= hostapd_ctrl_iface_nfc_get_handover_sel(
2764 hapd
, buf
+ 21, reply
, reply_size
);
2765 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
2766 if (hostapd_ctrl_iface_nfc_report_handover(hapd
, buf
+ 20))
2768 #endif /* CONFIG_WPS_NFC */
2769 #endif /* CONFIG_WPS */
2770 #ifdef CONFIG_INTERWORKING
2771 } else if (os_strncmp(buf
, "SET_QOS_MAP_SET ", 16) == 0) {
2772 if (hostapd_ctrl_iface_set_qos_map_set(hapd
, buf
+ 16))
2774 } else if (os_strncmp(buf
, "SEND_QOS_MAP_CONF ", 18) == 0) {
2775 if (hostapd_ctrl_iface_send_qos_map_conf(hapd
, buf
+ 18))
2777 #endif /* CONFIG_INTERWORKING */
2779 } else if (os_strncmp(buf
, "HS20_WNM_NOTIF ", 15) == 0) {
2780 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd
, buf
+ 15))
2782 } else if (os_strncmp(buf
, "HS20_DEAUTH_REQ ", 16) == 0) {
2783 if (hostapd_ctrl_iface_hs20_deauth_req(hapd
, buf
+ 16))
2785 #endif /* CONFIG_HS20 */
2786 #ifdef CONFIG_WNM_AP
2787 } else if (os_strncmp(buf
, "DISASSOC_IMMINENT ", 18) == 0) {
2788 if (hostapd_ctrl_iface_disassoc_imminent(hapd
, buf
+ 18))
2790 } else if (os_strncmp(buf
, "ESS_DISASSOC ", 13) == 0) {
2791 if (hostapd_ctrl_iface_ess_disassoc(hapd
, buf
+ 13))
2793 } else if (os_strncmp(buf
, "BSS_TM_REQ ", 11) == 0) {
2794 if (hostapd_ctrl_iface_bss_tm_req(hapd
, buf
+ 11))
2796 #endif /* CONFIG_WNM_AP */
2797 } else if (os_strcmp(buf
, "GET_CONFIG") == 0) {
2798 reply_len
= hostapd_ctrl_iface_get_config(hapd
, reply
,
2800 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
2801 if (hostapd_ctrl_iface_set(hapd
, buf
+ 4))
2803 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
2804 reply_len
= hostapd_ctrl_iface_get(hapd
, buf
+ 4, reply
,
2806 } else if (os_strncmp(buf
, "ENABLE", 6) == 0) {
2807 if (hostapd_ctrl_iface_enable(hapd
->iface
))
2809 } else if (os_strncmp(buf
, "RELOAD", 6) == 0) {
2810 if (hostapd_ctrl_iface_reload(hapd
->iface
))
2812 } else if (os_strncmp(buf
, "DISABLE", 7) == 0) {
2813 if (hostapd_ctrl_iface_disable(hapd
->iface
))
2815 } else if (os_strcmp(buf
, "UPDATE_BEACON") == 0) {
2816 if (ieee802_11_set_beacon(hapd
))
2818 #ifdef CONFIG_TESTING_OPTIONS
2819 } else if (os_strncmp(buf
, "RADAR ", 6) == 0) {
2820 if (hostapd_ctrl_iface_radar(hapd
, buf
+ 6))
2822 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
2823 if (hostapd_ctrl_iface_mgmt_tx(hapd
, buf
+ 8))
2825 } else if (os_strncmp(buf
, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
2826 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd
,
2829 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
2830 if (hostapd_ctrl_iface_mgmt_rx_process(hapd
, buf
+ 16) < 0)
2832 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
2833 if (hostapd_ctrl_iface_eapol_rx(hapd
, buf
+ 9) < 0)
2835 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
2836 if (hostapd_ctrl_iface_data_test_config(hapd
, buf
+ 17) < 0)
2838 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
2839 if (hostapd_ctrl_iface_data_test_tx(hapd
, buf
+ 13) < 0)
2841 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
2842 if (hostapd_ctrl_iface_data_test_frame(hapd
, buf
+ 16) < 0)
2844 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
2845 if (hostapd_ctrl_test_alloc_fail(hapd
, buf
+ 16) < 0)
2847 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
2848 reply_len
= hostapd_ctrl_get_alloc_fail(hapd
, reply
,
2850 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
2851 if (hostapd_ctrl_test_fail(hapd
, buf
+ 10) < 0)
2853 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
2854 reply_len
= hostapd_ctrl_get_fail(hapd
, reply
, reply_size
);
2855 } else if (os_strncmp(buf
, "RESET_PN ", 9) == 0) {
2856 if (hostapd_ctrl_reset_pn(hapd
, buf
+ 9) < 0)
2858 } else if (os_strncmp(buf
, "SET_KEY ", 8) == 0) {
2859 if (hostapd_ctrl_set_key(hapd
, buf
+ 8) < 0)
2861 } else if (os_strncmp(buf
, "RESEND_M1 ", 10) == 0) {
2862 if (hostapd_ctrl_resend_m1(hapd
, buf
+ 10) < 0)
2864 } else if (os_strncmp(buf
, "RESEND_M3 ", 10) == 0) {
2865 if (hostapd_ctrl_resend_m3(hapd
, buf
+ 10) < 0)
2867 } else if (os_strncmp(buf
, "RESEND_GROUP_M1 ", 16) == 0) {
2868 if (hostapd_ctrl_resend_group_m1(hapd
, buf
+ 16) < 0)
2870 #endif /* CONFIG_TESTING_OPTIONS */
2871 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
2872 if (hostapd_ctrl_iface_chan_switch(hapd
->iface
, buf
+ 12))
2874 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
2875 reply_len
= hostapd_ctrl_iface_vendor(hapd
, buf
+ 7, reply
,
2877 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
2878 ieee802_1x_erp_flush(hapd
);
2879 #ifdef RADIUS_SERVER
2880 radius_server_erp_flush(hapd
->radius_srv
);
2881 #endif /* RADIUS_SERVER */
2882 } else if (os_strncmp(buf
, "EAPOL_REAUTH ", 13) == 0) {
2883 if (hostapd_ctrl_iface_eapol_reauth(hapd
, buf
+ 13))
2885 } else if (os_strncmp(buf
, "EAPOL_SET ", 10) == 0) {
2886 if (hostapd_ctrl_iface_eapol_set(hapd
, buf
+ 10))
2888 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
2889 reply_len
= hostapd_ctrl_iface_log_level(
2890 hapd
, buf
+ 9, reply
, reply_size
);
2892 } else if (os_strcmp(buf
, "TRACK_STA_LIST") == 0) {
2893 reply_len
= hostapd_ctrl_iface_track_sta_list(
2894 hapd
, reply
, reply_size
);
2895 #endif /* NEED_AP_MLME */
2896 } else if (os_strcmp(buf
, "PMKSA") == 0) {
2897 reply_len
= hostapd_ctrl_iface_pmksa_list(hapd
, reply
,
2899 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
2900 hostapd_ctrl_iface_pmksa_flush(hapd
);
2901 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
2902 if (hostapd_ctrl_iface_pmksa_add(hapd
, buf
+ 10) < 0)
2904 } else if (os_strncmp(buf
, "SET_NEIGHBOR ", 13) == 0) {
2905 if (hostapd_ctrl_iface_set_neighbor(hapd
, buf
+ 13))
2907 } else if (os_strncmp(buf
, "REMOVE_NEIGHBOR ", 16) == 0) {
2908 if (hostapd_ctrl_iface_remove_neighbor(hapd
, buf
+ 16))
2910 } else if (os_strncmp(buf
, "REQ_LCI ", 8) == 0) {
2911 if (hostapd_ctrl_iface_req_lci(hapd
, buf
+ 8))
2913 } else if (os_strncmp(buf
, "REQ_RANGE ", 10) == 0) {
2914 if (hostapd_ctrl_iface_req_range(hapd
, buf
+ 10))
2916 } else if (os_strncmp(buf
, "REQ_BEACON ", 11) == 0) {
2917 reply_len
= hostapd_ctrl_iface_req_beacon(hapd
, buf
+ 11,
2919 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
2920 reply_len
= hostapd_ctrl_driver_flags(hapd
->iface
, reply
,
2922 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
2925 } else if (os_strncmp(buf
, "DPP_QR_CODE ", 12) == 0) {
2926 res
= hostapd_dpp_qr_code(hapd
, buf
+ 12);
2930 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2931 if (os_snprintf_error(reply_size
, reply_len
))
2934 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
2935 res
= hostapd_dpp_bootstrap_gen(hapd
, buf
+ 18);
2939 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2940 if (os_snprintf_error(reply_size
, reply_len
))
2943 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
2944 if (hostapd_dpp_bootstrap_remove(hapd
, buf
+ 21) < 0)
2946 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
2949 uri
= hostapd_dpp_bootstrap_get_uri(hapd
, atoi(buf
+ 22));
2953 reply_len
= os_snprintf(reply
, reply_size
, "%s", uri
);
2954 if (os_snprintf_error(reply_size
, reply_len
))
2957 } else if (os_strncmp(buf
, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
2958 reply_len
= hostapd_dpp_bootstrap_info(hapd
, atoi(buf
+ 19),
2960 } else if (os_strncmp(buf
, "DPP_AUTH_INIT ", 14) == 0) {
2961 if (hostapd_dpp_auth_init(hapd
, buf
+ 13) < 0)
2963 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_ADD", 20) == 0) {
2964 res
= hostapd_dpp_configurator_add(hapd
, buf
+ 20);
2968 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2969 if (os_snprintf_error(reply_size
, reply_len
))
2972 } else if (os_strncmp(buf
, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
2973 if (hostapd_dpp_configurator_remove(hapd
, buf
+ 24) < 0)
2975 } else if (os_strncmp(buf
, "DPP_PKEX_ADD ", 13) == 0) {
2976 res
= hostapd_dpp_pkex_add(hapd
, buf
+ 12);
2980 reply_len
= os_snprintf(reply
, reply_size
, "%d", res
);
2981 if (os_snprintf_error(reply_size
, reply_len
))
2984 } else if (os_strncmp(buf
, "DPP_PKEX_REMOVE ", 16) == 0) {
2985 if (hostapd_dpp_pkex_remove(hapd
, buf
+ 16) < 0)
2987 #endif /* CONFIG_DPP */
2989 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
2993 if (reply_len
< 0) {
2994 os_memcpy(reply
, "FAIL\n", 5);
3002 static void hostapd_ctrl_iface_receive(int sock
, void *eloop_ctx
,
3005 struct hostapd_data
*hapd
= eloop_ctx
;
3008 struct sockaddr_storage from
;
3009 socklen_t fromlen
= sizeof(from
);
3010 char *reply
, *pos
= buf
;
3011 const int reply_size
= 4096;
3013 int level
= MSG_DEBUG
;
3014 #ifdef CONFIG_CTRL_IFACE_UDP
3015 unsigned char lcookie
[COOKIE_LEN
];
3016 #endif /* CONFIG_CTRL_IFACE_UDP */
3018 res
= recvfrom(sock
, buf
, sizeof(buf
) - 1, 0,
3019 (struct sockaddr
*) &from
, &fromlen
);
3021 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
3027 reply
= os_malloc(reply_size
);
3028 if (reply
== NULL
) {
3029 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
3031 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3037 #ifdef CONFIG_CTRL_IFACE_UDP
3038 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
3039 os_memcpy(reply
, "COOKIE=", 7);
3040 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
3041 cookie
, COOKIE_LEN
);
3042 reply_len
= 7 + 2 * COOKIE_LEN
;
3046 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
3047 hexstr2bin(buf
+ 7, lcookie
, COOKIE_LEN
) < 0) {
3048 wpa_printf(MSG_DEBUG
,
3049 "CTRL: No cookie in the request - drop request");
3054 if (os_memcmp(cookie
, lcookie
, COOKIE_LEN
) != 0) {
3055 wpa_printf(MSG_DEBUG
,
3056 "CTRL: Invalid cookie in the request - drop request");
3061 pos
= buf
+ 7 + 2 * COOKIE_LEN
;
3064 #endif /* CONFIG_CTRL_IFACE_UDP */
3066 if (os_strcmp(pos
, "PING") == 0)
3067 level
= MSG_EXCESSIVE
;
3068 wpa_hexdump_ascii(level
, "RX ctrl_iface", pos
, res
);
3070 reply_len
= hostapd_ctrl_iface_receive_process(hapd
, pos
,
3074 #ifdef CONFIG_CTRL_IFACE_UDP
3076 #endif /* CONFIG_CTRL_IFACE_UDP */
3077 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
3079 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3086 #ifndef CONFIG_CTRL_IFACE_UDP
3087 static char * hostapd_ctrl_iface_path(struct hostapd_data
*hapd
)
3092 if (hapd
->conf
->ctrl_interface
== NULL
)
3095 len
= os_strlen(hapd
->conf
->ctrl_interface
) +
3096 os_strlen(hapd
->conf
->iface
) + 2;
3097 buf
= os_malloc(len
);
3101 os_snprintf(buf
, len
, "%s/%s",
3102 hapd
->conf
->ctrl_interface
, hapd
->conf
->iface
);
3103 buf
[len
- 1] = '\0';
3106 #endif /* CONFIG_CTRL_IFACE_UDP */
3109 static void hostapd_ctrl_iface_msg_cb(void *ctx
, int level
,
3110 enum wpa_msg_type type
,
3111 const char *txt
, size_t len
)
3113 struct hostapd_data
*hapd
= ctx
;
3116 hostapd_ctrl_iface_send(hapd
, level
, type
, txt
, len
);
3120 int hostapd_ctrl_iface_init(struct hostapd_data
*hapd
)
3122 #ifdef CONFIG_CTRL_IFACE_UDP
3123 int port
= HOSTAPD_CTRL_IFACE_PORT
;
3125 char port_str
[40], *tmp
;
3127 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3130 if (hapd
->ctrl_sock
> -1) {
3131 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3135 if (hapd
->conf
->ctrl_interface
== NULL
)
3138 pos
= os_strstr(hapd
->conf
->ctrl_interface
, "udp:");
3143 wpa_printf(MSG_ERROR
, "Invalid ctrl_iface UDP port");
3148 dl_list_init(&hapd
->ctrl_dst
);
3149 hapd
->ctrl_sock
= -1;
3150 os_get_random(cookie
, COOKIE_LEN
);
3152 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3153 hints
.ai_flags
= AI_PASSIVE
;
3154 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3156 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3157 hints
.ai_family
= AF_INET6
;
3158 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3159 hints
.ai_family
= AF_INET
;
3160 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3161 hints
.ai_socktype
= SOCK_DGRAM
;
3164 os_snprintf(p
, sizeof(p
), "%d", port
);
3165 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3167 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3172 hapd
->ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3174 if (hapd
->ctrl_sock
< 0) {
3175 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3179 if (bind(hapd
->ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) < 0) {
3181 if ((HOSTAPD_CTRL_IFACE_PORT
- port
) <
3182 HOSTAPD_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3184 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3188 freeaddrinfo(saveres
);
3190 os_snprintf(port_str
, sizeof(port_str
), "udp:%d", port
);
3191 tmp
= os_strdup(port_str
);
3193 os_free(hapd
->conf
->ctrl_interface
);
3194 hapd
->conf
->ctrl_interface
= tmp
;
3196 wpa_printf(MSG_DEBUG
, "ctrl_iface_init UDP port: %d", port
);
3198 if (eloop_register_read_sock(hapd
->ctrl_sock
,
3199 hostapd_ctrl_iface_receive
, hapd
, NULL
) <
3201 hostapd_ctrl_iface_deinit(hapd
);
3205 hapd
->msg_ctx
= hapd
;
3206 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3211 if (hapd
->ctrl_sock
>= 0)
3212 close(hapd
->ctrl_sock
);
3214 #else /* CONFIG_CTRL_IFACE_UDP */
3215 struct sockaddr_un addr
;
3219 if (hapd
->ctrl_sock
> -1) {
3220 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3224 dl_list_init(&hapd
->ctrl_dst
);
3226 if (hapd
->conf
->ctrl_interface
== NULL
)
3229 if (mkdir(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3230 if (errno
== EEXIST
) {
3231 wpa_printf(MSG_DEBUG
, "Using existing control "
3232 "interface directory.");
3234 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3240 if (hapd
->conf
->ctrl_interface_gid_set
&&
3241 chown(hapd
->conf
->ctrl_interface
, -1,
3242 hapd
->conf
->ctrl_interface_gid
) < 0) {
3243 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
3248 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3249 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3250 chown(hapd
->conf
->ctrl_interface
, -1,
3251 hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3252 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
3259 * Android is using umask 0077 which would leave the control interface
3260 * directory without group access. This breaks things since Wi-Fi
3261 * framework assumes that this directory can be accessed by other
3262 * applications in the wifi group. Fix this by adding group access even
3263 * if umask value would prevent this.
3265 if (chmod(hapd
->conf
->ctrl_interface
, S_IRWXU
| S_IRWXG
) < 0) {
3266 wpa_printf(MSG_ERROR
, "CTRL: Could not chmod directory: %s",
3268 /* Try to continue anyway */
3270 #endif /* ANDROID */
3272 if (os_strlen(hapd
->conf
->ctrl_interface
) + 1 +
3273 os_strlen(hapd
->conf
->iface
) >= sizeof(addr
.sun_path
))
3276 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
3278 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
3282 os_memset(&addr
, 0, sizeof(addr
));
3284 addr
.sun_len
= sizeof(addr
);
3285 #endif /* __FreeBSD__ */
3286 addr
.sun_family
= AF_UNIX
;
3287 fname
= hostapd_ctrl_iface_path(hapd
);
3290 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
3291 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3292 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
3294 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
3295 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
3296 " allow connections - assuming it was left"
3297 "over from forced program termination");
3298 if (unlink(fname
) < 0) {
3299 wpa_printf(MSG_ERROR
,
3300 "Could not unlink existing ctrl_iface socket '%s': %s",
3301 fname
, strerror(errno
));
3304 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
3306 wpa_printf(MSG_ERROR
,
3307 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
3311 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
3312 "ctrl_iface socket '%s'", fname
);
3314 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
3315 "be in use - cannot override it");
3316 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
3317 "not used anymore", fname
);
3324 if (hapd
->conf
->ctrl_interface_gid_set
&&
3325 chown(fname
, -1, hapd
->conf
->ctrl_interface_gid
) < 0) {
3326 wpa_printf(MSG_ERROR
, "chown[ctrl_interface/ifname]: %s",
3331 if (!hapd
->conf
->ctrl_interface_gid_set
&&
3332 hapd
->iface
->interfaces
->ctrl_iface_group
&&
3333 chown(fname
, -1, hapd
->iface
->interfaces
->ctrl_iface_group
) < 0) {
3334 wpa_printf(MSG_ERROR
, "chown[ctrl_interface/ifname]: %s",
3339 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
3340 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
3346 hapd
->ctrl_sock
= s
;
3347 if (eloop_register_read_sock(s
, hostapd_ctrl_iface_receive
, hapd
,
3349 hostapd_ctrl_iface_deinit(hapd
);
3352 hapd
->msg_ctx
= hapd
;
3353 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb
);
3365 #endif /* CONFIG_CTRL_IFACE_UDP */
3369 void hostapd_ctrl_iface_deinit(struct hostapd_data
*hapd
)
3371 struct wpa_ctrl_dst
*dst
, *prev
;
3373 if (hapd
->ctrl_sock
> -1) {
3374 #ifndef CONFIG_CTRL_IFACE_UDP
3376 #endif /* !CONFIG_CTRL_IFACE_UDP */
3378 eloop_unregister_read_sock(hapd
->ctrl_sock
);
3379 close(hapd
->ctrl_sock
);
3380 hapd
->ctrl_sock
= -1;
3381 #ifndef CONFIG_CTRL_IFACE_UDP
3382 fname
= hostapd_ctrl_iface_path(hapd
);
3387 if (hapd
->conf
->ctrl_interface
&&
3388 rmdir(hapd
->conf
->ctrl_interface
) < 0) {
3389 if (errno
== ENOTEMPTY
) {
3390 wpa_printf(MSG_DEBUG
, "Control interface "
3391 "directory not empty - leaving it "
3394 wpa_printf(MSG_ERROR
,
3395 "rmdir[ctrl_interface=%s]: %s",
3396 hapd
->conf
->ctrl_interface
,
3400 #endif /* !CONFIG_CTRL_IFACE_UDP */
3403 dl_list_for_each_safe(dst
, prev
, &hapd
->ctrl_dst
, struct wpa_ctrl_dst
,
3407 #ifdef CONFIG_TESTING_OPTIONS
3408 l2_packet_deinit(hapd
->l2_test
);
3409 hapd
->l2_test
= NULL
;
3410 #endif /* CONFIG_TESTING_OPTIONS */
3414 static int hostapd_ctrl_iface_add(struct hapd_interfaces
*interfaces
,
3417 if (hostapd_add_iface(interfaces
, buf
) < 0) {
3418 wpa_printf(MSG_ERROR
, "Adding interface %s failed", buf
);
3425 static int hostapd_ctrl_iface_remove(struct hapd_interfaces
*interfaces
,
3428 if (hostapd_remove_iface(interfaces
, buf
) < 0) {
3429 wpa_printf(MSG_ERROR
, "Removing interface %s failed", buf
);
3436 static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces
*interfaces
,
3437 struct sockaddr_storage
*from
,
3440 return ctrl_iface_attach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
3444 static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces
*interfaces
,
3445 struct sockaddr_storage
*from
,
3448 return ctrl_iface_detach(&interfaces
->global_ctrl_dst
, from
, fromlen
);
3452 static void hostapd_ctrl_iface_flush(struct hapd_interfaces
*interfaces
)
3454 #ifdef CONFIG_WPS_TESTING
3455 wps_version_number
= 0x20;
3456 wps_testing_dummy_cred
= 0;
3457 wps_corrupt_pkhash
= 0;
3458 #endif /* CONFIG_WPS_TESTING */
3465 hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces
*interfaces
,
3468 char ifname
[IFNAMSIZ
+ 1];
3469 struct fst_iface_cfg cfg
;
3470 struct hostapd_data
*hapd
;
3471 struct fst_wpa_obj iface_obj
;
3473 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
3474 hapd
= hostapd_get_iface(interfaces
, ifname
);
3476 if (hapd
->iface
->fst
) {
3477 wpa_printf(MSG_INFO
, "FST: Already attached");
3480 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
3481 hapd
->iface
->fst
= fst_attach(ifname
, hapd
->own_addr
,
3483 if (hapd
->iface
->fst
)
3493 hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces
*interfaces
,
3496 char ifname
[IFNAMSIZ
+ 1];
3497 struct hostapd_data
* hapd
;
3499 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
3500 hapd
= hostapd_get_iface(interfaces
, ifname
);
3502 if (!fst_iface_detach(ifname
)) {
3503 hapd
->iface
->fst
= NULL
;
3504 hapd
->iface
->fst_ies
= NULL
;
3513 #endif /* CONFIG_FST */
3516 static struct hostapd_data
*
3517 hostapd_interfaces_get_hapd(struct hapd_interfaces
*interfaces
,
3522 for (i
= 0; i
< interfaces
->count
; i
++) {
3523 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
3525 for (j
= 0; j
< iface
->num_bss
; j
++) {
3526 struct hostapd_data
*hapd
;
3528 hapd
= iface
->bss
[j
];
3529 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
3538 static int hostapd_ctrl_iface_dup_param(struct hostapd_data
*src_hapd
,
3539 struct hostapd_data
*dst_hapd
,
3545 value
= os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
3547 wpa_printf(MSG_ERROR
,
3548 "DUP: cannot allocate buffer to stringify %s",
3553 if (os_strcmp(param
, "wpa") == 0) {
3554 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%d",
3555 src_hapd
->conf
->wpa
);
3556 } else if (os_strcmp(param
, "wpa_key_mgmt") == 0 &&
3557 src_hapd
->conf
->wpa_key_mgmt
) {
3558 res
= hostapd_ctrl_iface_get_key_mgmt(
3559 src_hapd
, value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
);
3560 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, res
))
3561 goto error_stringify
;
3562 } else if (os_strcmp(param
, "wpa_pairwise") == 0 &&
3563 src_hapd
->conf
->wpa_pairwise
) {
3564 res
= wpa_write_ciphers(value
,
3565 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
3566 src_hapd
->conf
->wpa_pairwise
, " ");
3568 goto error_stringify
;
3569 } else if (os_strcmp(param
, "rsn_pairwise") == 0 &&
3570 src_hapd
->conf
->rsn_pairwise
) {
3571 res
= wpa_write_ciphers(value
,
3572 value
+ HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
3573 src_hapd
->conf
->rsn_pairwise
, " ");
3575 goto error_stringify
;
3576 } else if (os_strcmp(param
, "wpa_passphrase") == 0 &&
3577 src_hapd
->conf
->ssid
.wpa_passphrase
) {
3578 os_snprintf(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
, "%s",
3579 src_hapd
->conf
->ssid
.wpa_passphrase
);
3580 } else if (os_strcmp(param
, "wpa_psk") == 0 &&
3581 src_hapd
->conf
->ssid
.wpa_psk_set
) {
3582 wpa_snprintf_hex(value
, HOSTAPD_CLI_DUP_VALUE_MAX_LEN
,
3583 src_hapd
->conf
->ssid
.wpa_psk
->psk
, PMK_LEN
);
3585 wpa_printf(MSG_WARNING
, "DUP: %s cannot be duplicated", param
);
3589 res
= hostapd_set_iface(dst_hapd
->iconf
, dst_hapd
->conf
, param
, value
);
3594 wpa_printf(MSG_ERROR
, "DUP: cannot stringify %s", param
);
3602 hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces
*interfaces
,
3604 char *reply
, int reply_size
)
3609 struct hostapd_iface
*iface
;
3613 show_ctrl
= !!os_strstr(input
, "ctrl");
3616 end
= reply
+ reply_size
;
3618 for (i
= 0; i
< interfaces
->count
; i
++) {
3619 iface
= interfaces
->iface
[i
];
3621 for (j
= 0; j
< iface
->num_bss
; j
++) {
3622 struct hostapd_bss_config
*conf
;
3624 conf
= iface
->conf
->bss
[j
];
3626 res
= os_snprintf(pos
, end
- pos
,
3627 "%s ctrl_iface=%s\n",
3629 conf
->ctrl_interface
?
3630 conf
->ctrl_interface
: "N/A");
3632 res
= os_snprintf(pos
, end
- pos
, "%s\n",
3634 if (os_snprintf_error(end
- pos
, res
)) {
3647 hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces
*interfaces
,
3650 char *p_start
= cmd
, *p_end
;
3651 struct hostapd_data
*src_hapd
, *dst_hapd
;
3653 /* cmd: "<src ifname> <dst ifname> <variable name> */
3655 p_end
= os_strchr(p_start
, ' ');
3657 wpa_printf(MSG_ERROR
, "DUP: no src ifname found in cmd: '%s'",
3663 src_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
3665 wpa_printf(MSG_ERROR
, "DUP: no src ifname found: '%s'",
3670 p_start
= p_end
+ 1;
3671 p_end
= os_strchr(p_start
, ' ');
3673 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found in cmd: '%s'",
3679 dst_hapd
= hostapd_interfaces_get_hapd(interfaces
, p_start
);
3681 wpa_printf(MSG_ERROR
, "DUP: no dst ifname found: '%s'",
3686 p_start
= p_end
+ 1;
3687 return hostapd_ctrl_iface_dup_param(src_hapd
, dst_hapd
, p_start
);
3691 static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces
*interfaces
,
3693 char *buf
, char *reply
,
3695 struct sockaddr_storage
*from
,
3698 struct hostapd_data
*hapd
;
3700 hapd
= hostapd_interfaces_get_hapd(interfaces
, ifname
);
3704 res
= os_snprintf(reply
, reply_size
, "FAIL-NO-IFNAME-MATCH\n");
3705 if (os_snprintf_error(reply_size
, res
))
3710 return hostapd_ctrl_iface_receive_process(hapd
, buf
, reply
,reply_size
,
3715 static void hostapd_global_ctrl_iface_receive(int sock
, void *eloop_ctx
,
3718 void *interfaces
= eloop_ctx
;
3719 char buffer
[256], *buf
= buffer
;
3721 struct sockaddr_storage from
;
3722 socklen_t fromlen
= sizeof(from
);
3725 const int reply_size
= 4096;
3726 #ifdef CONFIG_CTRL_IFACE_UDP
3727 unsigned char lcookie
[COOKIE_LEN
];
3728 #endif /* CONFIG_CTRL_IFACE_UDP */
3730 res
= recvfrom(sock
, buffer
, sizeof(buffer
) - 1, 0,
3731 (struct sockaddr
*) &from
, &fromlen
);
3733 wpa_printf(MSG_ERROR
, "recvfrom(ctrl_iface): %s",
3738 wpa_printf(MSG_DEBUG
, "Global ctrl_iface command: %s", buf
);
3740 reply
= os_malloc(reply_size
);
3741 if (reply
== NULL
) {
3742 if (sendto(sock
, "FAIL\n", 5, 0, (struct sockaddr
*) &from
,
3744 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3750 os_memcpy(reply
, "OK\n", 3);
3753 #ifdef CONFIG_CTRL_IFACE_UDP
3754 if (os_strcmp(buf
, "GET_COOKIE") == 0) {
3755 os_memcpy(reply
, "COOKIE=", 7);
3756 wpa_snprintf_hex(reply
+ 7, 2 * COOKIE_LEN
+ 1,
3757 gcookie
, COOKIE_LEN
);
3758 reply_len
= 7 + 2 * COOKIE_LEN
;
3762 if (os_strncmp(buf
, "COOKIE=", 7) != 0 ||
3763 hexstr2bin(buf
+ 7, lcookie
, COOKIE_LEN
) < 0) {
3764 wpa_printf(MSG_DEBUG
,
3765 "CTRL: No cookie in the request - drop request");
3770 if (os_memcmp(gcookie
, lcookie
, COOKIE_LEN
) != 0) {
3771 wpa_printf(MSG_DEBUG
,
3772 "CTRL: Invalid cookie in the request - drop request");
3777 buf
+= 7 + 2 * COOKIE_LEN
;
3780 #endif /* CONFIG_CTRL_IFACE_UDP */
3782 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
3783 char *pos
= os_strchr(buf
+ 7, ' ');
3787 reply_len
= hostapd_global_ctrl_iface_ifname(
3788 interfaces
, buf
+ 7, pos
, reply
, reply_size
,
3794 if (os_strcmp(buf
, "PING") == 0) {
3795 os_memcpy(reply
, "PONG\n", 5);
3797 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3798 if (wpa_debug_reopen_file() < 0)
3800 } else if (os_strcmp(buf
, "FLUSH") == 0) {
3801 hostapd_ctrl_iface_flush(interfaces
);
3802 } else if (os_strncmp(buf
, "ADD ", 4) == 0) {
3803 if (hostapd_ctrl_iface_add(interfaces
, buf
+ 4) < 0)
3805 } else if (os_strncmp(buf
, "REMOVE ", 7) == 0) {
3806 if (hostapd_ctrl_iface_remove(interfaces
, buf
+ 7) < 0)
3808 } else if (os_strcmp(buf
, "ATTACH") == 0) {
3809 if (hostapd_global_ctrl_iface_attach(interfaces
, &from
,
3812 } else if (os_strcmp(buf
, "DETACH") == 0) {
3813 if (hostapd_global_ctrl_iface_detach(interfaces
, &from
,
3816 #ifdef CONFIG_MODULE_TESTS
3817 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
3818 if (hapd_module_tests() < 0)
3820 #endif /* CONFIG_MODULE_TESTS */
3822 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
3823 if (!hostapd_global_ctrl_iface_fst_attach(interfaces
, buf
+ 11))
3824 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
3827 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
3828 if (!hostapd_global_ctrl_iface_fst_detach(interfaces
, buf
+ 11))
3829 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
3832 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
3833 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
3834 #endif /* CONFIG_FST */
3835 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
3836 if (!hostapd_global_ctrl_iface_dup_network(interfaces
,
3838 reply_len
= os_snprintf(reply
, reply_size
, "OK\n");
3841 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
3842 reply_len
= hostapd_global_ctrl_iface_interfaces(
3843 interfaces
, buf
+ 10, reply
, sizeof(buffer
));
3844 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
3847 wpa_printf(MSG_DEBUG
, "Unrecognized global ctrl_iface command "
3853 if (reply_len
< 0) {
3854 os_memcpy(reply
, "FAIL\n", 5);
3858 if (sendto(sock
, reply
, reply_len
, 0, (struct sockaddr
*) &from
,
3860 wpa_printf(MSG_DEBUG
, "CTRL: sendto failed: %s",
3867 #ifndef CONFIG_CTRL_IFACE_UDP
3868 static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces
*interface
)
3873 if (interface
->global_iface_path
== NULL
)
3876 len
= os_strlen(interface
->global_iface_path
) +
3877 os_strlen(interface
->global_iface_name
) + 2;
3878 buf
= os_malloc(len
);
3882 os_snprintf(buf
, len
, "%s/%s", interface
->global_iface_path
,
3883 interface
->global_iface_name
);
3884 buf
[len
- 1] = '\0';
3887 #endif /* CONFIG_CTRL_IFACE_UDP */
3890 int hostapd_global_ctrl_iface_init(struct hapd_interfaces
*interface
)
3892 #ifdef CONFIG_CTRL_IFACE_UDP
3893 int port
= HOSTAPD_GLOBAL_CTRL_IFACE_PORT
;
3896 struct addrinfo hints
= { 0 }, *res
, *saveres
;
3899 if (interface
->global_ctrl_sock
> -1) {
3900 wpa_printf(MSG_DEBUG
, "ctrl_iface already exists!");
3904 if (interface
->global_iface_path
== NULL
)
3907 pos
= os_strstr(interface
->global_iface_path
, "udp:");
3912 wpa_printf(MSG_ERROR
, "Invalid global ctrl UDP port");
3917 os_get_random(gcookie
, COOKIE_LEN
);
3919 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3920 hints
.ai_flags
= AI_PASSIVE
;
3921 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3923 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3924 hints
.ai_family
= AF_INET6
;
3925 #else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3926 hints
.ai_family
= AF_INET
;
3927 #endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3928 hints
.ai_socktype
= SOCK_DGRAM
;
3931 os_snprintf(p
, sizeof(p
), "%d", port
);
3932 n
= getaddrinfo(NULL
, p
, &hints
, &res
);
3934 wpa_printf(MSG_ERROR
, "getaddrinfo(): %s", gai_strerror(n
));
3939 interface
->global_ctrl_sock
= socket(res
->ai_family
, res
->ai_socktype
,
3941 if (interface
->global_ctrl_sock
< 0) {
3942 wpa_printf(MSG_ERROR
, "socket(PF_INET): %s", strerror(errno
));
3946 if (bind(interface
->global_ctrl_sock
, res
->ai_addr
, res
->ai_addrlen
) <
3949 if ((port
- HOSTAPD_GLOBAL_CTRL_IFACE_PORT
) <
3950 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT
&& !pos
)
3952 wpa_printf(MSG_ERROR
, "bind(AF_INET): %s", strerror(errno
));
3956 freeaddrinfo(saveres
);
3958 wpa_printf(MSG_DEBUG
, "global ctrl_iface_init UDP port: %d", port
);
3960 if (eloop_register_read_sock(interface
->global_ctrl_sock
,
3961 hostapd_global_ctrl_iface_receive
,
3962 interface
, NULL
) < 0) {
3963 hostapd_global_ctrl_iface_deinit(interface
);
3970 if (interface
->global_ctrl_sock
>= 0)
3971 close(interface
->global_ctrl_sock
);
3973 #else /* CONFIG_CTRL_IFACE_UDP */
3974 struct sockaddr_un addr
;
3978 if (interface
->global_iface_path
== NULL
) {
3979 wpa_printf(MSG_DEBUG
, "ctrl_iface not configured!");
3983 if (mkdir(interface
->global_iface_path
, S_IRWXU
| S_IRWXG
) < 0) {
3984 if (errno
== EEXIST
) {
3985 wpa_printf(MSG_DEBUG
, "Using existing control "
3986 "interface directory.");
3988 wpa_printf(MSG_ERROR
, "mkdir[ctrl_interface]: %s",
3992 } else if (interface
->ctrl_iface_group
&&
3993 chown(interface
->global_iface_path
, -1,
3994 interface
->ctrl_iface_group
) < 0) {
3995 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
4000 if (os_strlen(interface
->global_iface_path
) + 1 +
4001 os_strlen(interface
->global_iface_name
) >= sizeof(addr
.sun_path
))
4004 s
= socket(PF_UNIX
, SOCK_DGRAM
, 0);
4006 wpa_printf(MSG_ERROR
, "socket(PF_UNIX): %s", strerror(errno
));
4010 os_memset(&addr
, 0, sizeof(addr
));
4012 addr
.sun_len
= sizeof(addr
);
4013 #endif /* __FreeBSD__ */
4014 addr
.sun_family
= AF_UNIX
;
4015 fname
= hostapd_global_ctrl_iface_path(interface
);
4018 os_strlcpy(addr
.sun_path
, fname
, sizeof(addr
.sun_path
));
4019 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4020 wpa_printf(MSG_DEBUG
, "ctrl_iface bind(PF_UNIX) failed: %s",
4022 if (connect(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) < 0) {
4023 wpa_printf(MSG_DEBUG
, "ctrl_iface exists, but does not"
4024 " allow connections - assuming it was left"
4025 "over from forced program termination");
4026 if (unlink(fname
) < 0) {
4027 wpa_printf(MSG_ERROR
,
4028 "Could not unlink existing ctrl_iface socket '%s': %s",
4029 fname
, strerror(errno
));
4032 if (bind(s
, (struct sockaddr
*) &addr
, sizeof(addr
)) <
4034 wpa_printf(MSG_ERROR
, "bind(PF_UNIX): %s",
4038 wpa_printf(MSG_DEBUG
, "Successfully replaced leftover "
4039 "ctrl_iface socket '%s'", fname
);
4041 wpa_printf(MSG_INFO
, "ctrl_iface exists and seems to "
4042 "be in use - cannot override it");
4043 wpa_printf(MSG_INFO
, "Delete '%s' manually if it is "
4044 "not used anymore", fname
);
4051 if (interface
->ctrl_iface_group
&&
4052 chown(fname
, -1, interface
->ctrl_iface_group
) < 0) {
4053 wpa_printf(MSG_ERROR
, "chown[ctrl_interface]: %s",
4058 if (chmod(fname
, S_IRWXU
| S_IRWXG
) < 0) {
4059 wpa_printf(MSG_ERROR
, "chmod[ctrl_interface/ifname]: %s",
4065 interface
->global_ctrl_sock
= s
;
4066 eloop_register_read_sock(s
, hostapd_global_ctrl_iface_receive
,
4079 #endif /* CONFIG_CTRL_IFACE_UDP */
4083 void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces
*interfaces
)
4085 #ifndef CONFIG_CTRL_IFACE_UDP
4087 #endif /* CONFIG_CTRL_IFACE_UDP */
4088 struct wpa_ctrl_dst
*dst
, *prev
;
4090 if (interfaces
->global_ctrl_sock
> -1) {
4091 eloop_unregister_read_sock(interfaces
->global_ctrl_sock
);
4092 close(interfaces
->global_ctrl_sock
);
4093 interfaces
->global_ctrl_sock
= -1;
4094 #ifndef CONFIG_CTRL_IFACE_UDP
4095 fname
= hostapd_global_ctrl_iface_path(interfaces
);
4101 if (interfaces
->global_iface_path
&&
4102 rmdir(interfaces
->global_iface_path
) < 0) {
4103 if (errno
== ENOTEMPTY
) {
4104 wpa_printf(MSG_DEBUG
, "Control interface "
4105 "directory not empty - leaving it "
4108 wpa_printf(MSG_ERROR
,
4109 "rmdir[ctrl_interface=%s]: %s",
4110 interfaces
->global_iface_path
,
4114 #endif /* CONFIG_CTRL_IFACE_UDP */
4117 os_free(interfaces
->global_iface_path
);
4118 interfaces
->global_iface_path
= NULL
;
4120 dl_list_for_each_safe(dst
, prev
, &interfaces
->global_ctrl_dst
,
4121 struct wpa_ctrl_dst
, list
)
4126 static void hostapd_ctrl_iface_send(struct hostapd_data
*hapd
, int level
,
4127 enum wpa_msg_type type
,
4128 const char *buf
, size_t len
)
4130 struct wpa_ctrl_dst
*dst
, *next
;
4131 struct dl_list
*ctrl_dst
;
4138 if (type
!= WPA_MSG_ONLY_GLOBAL
) {
4139 s
= hapd
->ctrl_sock
;
4140 ctrl_dst
= &hapd
->ctrl_dst
;
4142 s
= hapd
->iface
->interfaces
->global_ctrl_sock
;
4143 ctrl_dst
= &hapd
->iface
->interfaces
->global_ctrl_dst
;
4146 if (s
< 0 || dl_list_empty(ctrl_dst
))
4149 os_snprintf(levelstr
, sizeof(levelstr
), "<%d>", level
);
4150 io
[0].iov_base
= levelstr
;
4151 io
[0].iov_len
= os_strlen(levelstr
);
4152 io
[1].iov_base
= (char *) buf
;
4153 io
[1].iov_len
= len
;
4154 os_memset(&msg
, 0, sizeof(msg
));
4159 dl_list_for_each_safe(dst
, next
, ctrl_dst
, struct wpa_ctrl_dst
, list
) {
4160 if (level
>= dst
->debug_level
) {
4161 sockaddr_print(MSG_DEBUG
, "CTRL_IFACE monitor send",
4162 &dst
->addr
, dst
->addrlen
);
4163 msg
.msg_name
= &dst
->addr
;
4164 msg
.msg_namelen
= dst
->addrlen
;
4165 if (sendmsg(s
, &msg
, 0) < 0) {
4167 wpa_printf(MSG_INFO
, "CTRL_IFACE monitor[%d]: "
4169 idx
, errno
, strerror(errno
));
4171 if (dst
->errors
> 10 || _errno
== ENOENT
) {
4172 if (type
!= WPA_MSG_ONLY_GLOBAL
)
4173 hostapd_ctrl_iface_detach(
4177 hostapd_global_ctrl_iface_detach(
4178 hapd
->iface
->interfaces
,
4189 #endif /* CONFIG_NATIVE_WINDOWS */