3 * Copyright (c) 2002-2019, 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"
10 #ifndef CONFIG_NATIVE_WINDOWS
13 #endif /* CONFIG_NATIVE_WINDOWS */
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "utils/uuid.h"
18 #include "crypto/random.h"
19 #include "crypto/tls.h"
20 #include "common/version.h"
21 #include "common/dpp.h"
22 #include "drivers/driver.h"
23 #include "eap_server/eap.h"
24 #include "eap_server/tncs.h"
25 #include "ap/hostapd.h"
26 #include "ap/ap_config.h"
27 #include "ap/ap_drv_ops.h"
28 #include "ap/dpp_hostapd.h"
30 #include "config_file.h"
31 #include "eap_register.h"
32 #include "ctrl_iface.h"
40 static struct hapd_global global
;
43 #ifndef CONFIG_NO_HOSTAPD_LOGGER
44 static void hostapd_logger_cb(void *ctx
, const u8
*addr
, unsigned int module
,
45 int level
, const char *txt
, size_t len
)
47 struct hostapd_data
*hapd
= ctx
;
48 char *format
, *module_str
;
50 int conf_syslog_level
, conf_stdout_level
;
51 unsigned int conf_syslog
, conf_stdout
;
54 format
= os_malloc(maxlen
);
58 if (hapd
&& hapd
->conf
) {
59 conf_syslog_level
= hapd
->conf
->logger_syslog_level
;
60 conf_stdout_level
= hapd
->conf
->logger_stdout_level
;
61 conf_syslog
= hapd
->conf
->logger_syslog
;
62 conf_stdout
= hapd
->conf
->logger_stdout
;
64 conf_syslog_level
= conf_stdout_level
= 0;
65 conf_syslog
= conf_stdout
= (unsigned int) -1;
69 case HOSTAPD_MODULE_IEEE80211
:
70 module_str
= "IEEE 802.11";
72 case HOSTAPD_MODULE_IEEE8021X
:
73 module_str
= "IEEE 802.1X";
75 case HOSTAPD_MODULE_RADIUS
:
76 module_str
= "RADIUS";
78 case HOSTAPD_MODULE_WPA
:
81 case HOSTAPD_MODULE_DRIVER
:
82 module_str
= "DRIVER";
84 case HOSTAPD_MODULE_MLME
:
92 if (hapd
&& hapd
->conf
&& addr
)
93 os_snprintf(format
, maxlen
, "%s: STA " MACSTR
"%s%s: %s",
94 hapd
->conf
->iface
, MAC2STR(addr
),
95 module_str
? " " : "", module_str
? module_str
: "",
97 else if (hapd
&& hapd
->conf
)
98 os_snprintf(format
, maxlen
, "%s:%s%s %s",
99 hapd
->conf
->iface
, module_str
? " " : "",
100 module_str
? module_str
: "", txt
);
102 os_snprintf(format
, maxlen
, "STA " MACSTR
"%s%s: %s",
103 MAC2STR(addr
), module_str
? " " : "",
104 module_str
? module_str
: "", txt
);
106 os_snprintf(format
, maxlen
, "%s%s%s",
107 module_str
? module_str
: "",
108 module_str
? ": " : "", txt
);
110 #ifdef CONFIG_DEBUG_SYSLOG
111 if (wpa_debug_syslog
)
113 #endif /* CONFIG_DEBUG_SYSLOG */
114 if ((conf_stdout
& module
) && level
>= conf_stdout_level
) {
115 wpa_debug_print_timestamp();
116 wpa_printf(MSG_INFO
, "%s", format
);
119 #ifndef CONFIG_NATIVE_WINDOWS
120 if ((conf_syslog
& module
) && level
>= conf_syslog_level
) {
123 case HOSTAPD_LEVEL_DEBUG_VERBOSE
:
124 case HOSTAPD_LEVEL_DEBUG
:
125 priority
= LOG_DEBUG
;
127 case HOSTAPD_LEVEL_INFO
:
130 case HOSTAPD_LEVEL_NOTICE
:
131 priority
= LOG_NOTICE
;
133 case HOSTAPD_LEVEL_WARNING
:
134 priority
= LOG_WARNING
;
140 syslog(priority
, "%s", format
);
142 #endif /* CONFIG_NATIVE_WINDOWS */
146 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
150 * hostapd_driver_init - Preparate driver interface
152 static int hostapd_driver_init(struct hostapd_iface
*iface
)
154 struct wpa_init_params params
;
156 struct hostapd_data
*hapd
= iface
->bss
[0];
157 struct hostapd_bss_config
*conf
= hapd
->conf
;
159 struct wpa_driver_capa capa
;
161 if (hapd
->driver
== NULL
|| hapd
->driver
->hapd_init
== NULL
) {
162 wpa_printf(MSG_ERROR
, "No hostapd driver wrapper available");
166 /* Initialize the driver interface */
167 if (!(b
[0] | b
[1] | b
[2] | b
[3] | b
[4] | b
[5]))
170 os_memset(¶ms
, 0, sizeof(params
));
171 for (i
= 0; wpa_drivers
[i
]; i
++) {
172 if (wpa_drivers
[i
] != hapd
->driver
)
175 if (global
.drv_priv
[i
] == NULL
&&
176 wpa_drivers
[i
]->global_init
) {
178 wpa_drivers
[i
]->global_init(iface
->interfaces
);
179 if (global
.drv_priv
[i
] == NULL
) {
180 wpa_printf(MSG_ERROR
, "Failed to initialize "
182 wpa_drivers
[i
]->name
);
187 params
.global_priv
= global
.drv_priv
[i
];
191 params
.ifname
= hapd
->conf
->iface
;
192 params
.driver_params
= hapd
->iconf
->driver_params
;
193 params
.use_pae_group_addr
= hapd
->conf
->use_pae_group_addr
;
195 params
.num_bridge
= hapd
->iface
->num_bss
;
196 params
.bridge
= os_calloc(hapd
->iface
->num_bss
, sizeof(char *));
197 if (params
.bridge
== NULL
)
199 for (i
= 0; i
< hapd
->iface
->num_bss
; i
++) {
200 struct hostapd_data
*bss
= hapd
->iface
->bss
[i
];
201 if (bss
->conf
->bridge
[0])
202 params
.bridge
[i
] = bss
->conf
->bridge
;
205 params
.own_addr
= hapd
->own_addr
;
207 hapd
->drv_priv
= hapd
->driver
->hapd_init(hapd
, ¶ms
);
208 os_free(params
.bridge
);
209 if (hapd
->drv_priv
== NULL
) {
210 wpa_printf(MSG_ERROR
, "%s driver initialization failed.",
216 if (hapd
->driver
->get_capa
&&
217 hapd
->driver
->get_capa(hapd
->drv_priv
, &capa
) == 0) {
218 struct wowlan_triggers
*triggs
;
220 iface
->drv_flags
= capa
.flags
;
221 iface
->smps_modes
= capa
.smps_modes
;
222 iface
->probe_resp_offloads
= capa
.probe_resp_offloads
;
224 * Use default extended capa values from per-radio information
226 iface
->extended_capa
= capa
.extended_capa
;
227 iface
->extended_capa_mask
= capa
.extended_capa_mask
;
228 iface
->extended_capa_len
= capa
.extended_capa_len
;
229 iface
->drv_max_acl_mac_addrs
= capa
.max_acl_mac_addrs
;
232 * Override extended capa with per-interface type (AP), if
233 * available from the driver.
235 hostapd_get_ext_capa(iface
);
237 triggs
= wpa_get_wowlan_triggers(conf
->wowlan_triggers
, &capa
);
238 if (triggs
&& hapd
->driver
->set_wowlan
) {
239 if (hapd
->driver
->set_wowlan(hapd
->drv_priv
, triggs
))
240 wpa_printf(MSG_ERROR
, "set_wowlan failed");
250 * hostapd_interface_init - Read configuration file and init BSS data
252 * This function is used to parse configuration file for a full interface (one
253 * or more BSSes sharing the same radio) and allocate memory for the BSS
254 * interfaces. No actual driver operations are started.
256 static struct hostapd_iface
*
257 hostapd_interface_init(struct hapd_interfaces
*interfaces
, const char *if_name
,
258 const char *config_fname
, int debug
)
260 struct hostapd_iface
*iface
;
263 wpa_printf(MSG_DEBUG
, "Configuration file: %s", config_fname
);
264 iface
= hostapd_init(interfaces
, config_fname
);
269 os_strlcpy(iface
->conf
->bss
[0]->iface
, if_name
,
270 sizeof(iface
->conf
->bss
[0]->iface
));
273 iface
->interfaces
= interfaces
;
275 for (k
= 0; k
< debug
; k
++) {
276 if (iface
->bss
[0]->conf
->logger_stdout_level
> 0)
277 iface
->bss
[0]->conf
->logger_stdout_level
--;
280 if (iface
->conf
->bss
[0]->iface
[0] == '\0' &&
281 !hostapd_drv_none(iface
->bss
[0])) {
282 wpa_printf(MSG_ERROR
,
283 "Interface name not specified in %s, nor by '-i' parameter",
285 hostapd_interface_deinit_free(iface
);
294 * handle_term - SIGINT and SIGTERM handler to terminate hostapd process
296 static void handle_term(int sig
, void *signal_ctx
)
298 wpa_printf(MSG_DEBUG
, "Signal %d received - terminating", sig
);
303 #ifndef CONFIG_NATIVE_WINDOWS
305 static int handle_reload_iface(struct hostapd_iface
*iface
, void *ctx
)
307 if (hostapd_reload_config(iface
) < 0) {
308 wpa_printf(MSG_WARNING
, "Failed to read new configuration "
309 "file - continuing with old.");
316 * handle_reload - SIGHUP handler to reload configuration
318 static void handle_reload(int sig
, void *signal_ctx
)
320 struct hapd_interfaces
*interfaces
= signal_ctx
;
321 wpa_printf(MSG_DEBUG
, "Signal %d received - reloading configuration",
323 hostapd_for_each_interface(interfaces
, handle_reload_iface
, NULL
);
327 static void handle_dump_state(int sig
, void *signal_ctx
)
329 /* Not used anymore - ignore signal */
331 #endif /* CONFIG_NATIVE_WINDOWS */
334 static int hostapd_global_init(struct hapd_interfaces
*interfaces
,
335 const char *entropy_file
)
339 os_memset(&global
, 0, sizeof(global
));
341 hostapd_logger_register_cb(hostapd_logger_cb
);
343 if (eap_server_register_methods()) {
344 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
349 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
352 interfaces
->eloop_initialized
= 1;
354 random_init(entropy_file
);
356 #ifndef CONFIG_NATIVE_WINDOWS
357 eloop_register_signal(SIGHUP
, handle_reload
, interfaces
);
358 eloop_register_signal(SIGUSR1
, handle_dump_state
, interfaces
);
359 #endif /* CONFIG_NATIVE_WINDOWS */
360 eloop_register_signal_terminate(handle_term
, interfaces
);
362 #ifndef CONFIG_NATIVE_WINDOWS
363 openlog("hostapd", 0, LOG_DAEMON
);
364 #endif /* CONFIG_NATIVE_WINDOWS */
366 for (i
= 0; wpa_drivers
[i
]; i
++)
368 if (global
.drv_count
== 0) {
369 wpa_printf(MSG_ERROR
, "No drivers enabled");
372 global
.drv_priv
= os_calloc(global
.drv_count
, sizeof(void *));
373 if (global
.drv_priv
== NULL
)
380 static void hostapd_global_deinit(const char *pid_file
, int eloop_initialized
)
384 for (i
= 0; wpa_drivers
[i
] && global
.drv_priv
; i
++) {
385 if (!global
.drv_priv
[i
])
387 wpa_drivers
[i
]->global_deinit(global
.drv_priv
[i
]);
389 os_free(global
.drv_priv
);
390 global
.drv_priv
= NULL
;
392 #ifdef EAP_SERVER_TNC
393 tncs_global_deinit();
394 #endif /* EAP_SERVER_TNC */
398 if (eloop_initialized
)
401 #ifndef CONFIG_NATIVE_WINDOWS
403 #endif /* CONFIG_NATIVE_WINDOWS */
405 eap_server_unregister_methods();
407 os_daemonize_terminate(pid_file
);
411 static int hostapd_global_run(struct hapd_interfaces
*ifaces
, int daemonize
,
412 const char *pid_file
)
414 #ifdef EAP_SERVER_TNC
418 for (i
= 0; !tnc
&& i
< ifaces
->count
; i
++) {
419 for (k
= 0; k
< ifaces
->iface
[i
]->num_bss
; k
++) {
420 if (ifaces
->iface
[i
]->bss
[0]->conf
->tnc
) {
427 if (tnc
&& tncs_global_init() < 0) {
428 wpa_printf(MSG_ERROR
, "Failed to initialize TNCS");
431 #endif /* EAP_SERVER_TNC */
434 if (os_daemonize(pid_file
)) {
435 wpa_printf(MSG_ERROR
, "daemon: %s", strerror(errno
));
438 if (eloop_sock_requeue()) {
439 wpa_printf(MSG_ERROR
, "eloop_sock_requeue: %s",
451 static void show_version(void)
454 "hostapd v" VERSION_STR
"\n"
455 "User space daemon for IEEE 802.11 AP management,\n"
456 "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
457 "Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi> "
458 "and contributors\n");
462 static void usage(void)
467 "usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] "
469 " [-g <global ctrl_iface>] [-G <group>]\\\n"
470 " [-i <comma-separated list of interface names>]\\\n"
471 " <configuration file(s)>\n"
474 " -h show this usage\n"
475 " -d show more debug messages (-dd for even more)\n"
476 " -B run daemon in the background\n"
478 " -g global control interface path\n"
479 " -G group for control interfaces\n"
481 " -K include key data in debug messages\n"
482 #ifdef CONFIG_DEBUG_FILE
483 " -f log output to debug file instead of stdout\n"
484 #endif /* CONFIG_DEBUG_FILE */
485 #ifdef CONFIG_DEBUG_LINUX_TRACING
486 " -T record to Linux tracing in addition to logging\n"
487 " (records all messages regardless of debug verbosity)\n"
488 #endif /* CONFIG_DEBUG_LINUX_TRACING */
489 " -i list of interface names to use\n"
490 #ifdef CONFIG_DEBUG_SYSLOG
491 " -s log output to syslog instead of stdout\n"
492 #endif /* CONFIG_DEBUG_SYSLOG */
493 " -S start all the interfaces synchronously\n"
494 " -t include timestamps in some debug messages\n"
495 " -v show hostapd version\n");
501 static const char * hostapd_msg_ifname_cb(void *ctx
)
503 struct hostapd_data
*hapd
= ctx
;
504 if (hapd
&& hapd
->conf
)
505 return hapd
->conf
->iface
;
510 static int hostapd_get_global_ctrl_iface(struct hapd_interfaces
*interfaces
,
513 #ifndef CONFIG_CTRL_IFACE_UDP
515 #endif /* !CONFIG_CTRL_IFACE_UDP */
517 os_free(interfaces
->global_iface_path
);
518 interfaces
->global_iface_path
= os_strdup(path
);
519 if (interfaces
->global_iface_path
== NULL
)
522 #ifndef CONFIG_CTRL_IFACE_UDP
523 pos
= os_strrchr(interfaces
->global_iface_path
, '/');
525 wpa_printf(MSG_ERROR
, "No '/' in the global control interface "
527 os_free(interfaces
->global_iface_path
);
528 interfaces
->global_iface_path
= NULL
;
533 interfaces
->global_iface_name
= pos
+ 1;
534 #endif /* !CONFIG_CTRL_IFACE_UDP */
540 static int hostapd_get_ctrl_iface_group(struct hapd_interfaces
*interfaces
,
543 #ifndef CONFIG_NATIVE_WINDOWS
545 grp
= getgrnam(group
);
547 wpa_printf(MSG_ERROR
, "Unknown group '%s'", group
);
550 interfaces
->ctrl_iface_group
= grp
->gr_gid
;
551 #endif /* CONFIG_NATIVE_WINDOWS */
556 static int hostapd_get_interface_names(char ***if_names
,
557 size_t *if_names_size
,
560 char *if_name
, *tmp
, **nnames
;
565 if_name
= strtok_r(arg
, ",", &tmp
);
568 nnames
= os_realloc_array(*if_names
, 1 + *if_names_size
,
574 (*if_names
)[*if_names_size
] = os_strdup(if_name
);
575 if (!(*if_names
)[*if_names_size
])
578 if_name
= strtok_r(NULL
, ",", &tmp
);
584 for (i
= 0; i
< *if_names_size
; i
++)
585 os_free((*if_names
)[i
]);
594 static int gen_uuid(const char *txt_addr
)
600 if (hwaddr_aton(txt_addr
, addr
) < 0)
603 uuid_gen_mac_addr(addr
, uuid
);
604 if (uuid_bin2str(uuid
, buf
, sizeof(buf
)) < 0)
611 #endif /* CONFIG_WPS */
614 #ifndef HOSTAPD_CLEANUP_INTERVAL
615 #define HOSTAPD_CLEANUP_INTERVAL 10
616 #endif /* HOSTAPD_CLEANUP_INTERVAL */
618 static int hostapd_periodic_call(struct hostapd_iface
*iface
, void *ctx
)
620 hostapd_periodic_iface(iface
);
625 /* Periodic cleanup tasks */
626 static void hostapd_periodic(void *eloop_ctx
, void *timeout_ctx
)
628 struct hapd_interfaces
*interfaces
= eloop_ctx
;
630 eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL
, 0,
631 hostapd_periodic
, interfaces
, NULL
);
632 hostapd_for_each_interface(interfaces
, hostapd_periodic_call
, NULL
);
636 int main(int argc
, char *argv
[])
638 struct hapd_interfaces interfaces
;
641 int c
, debug
= 0, daemonize
= 0;
642 char *pid_file
= NULL
;
643 const char *log_file
= NULL
;
644 const char *entropy_file
= NULL
;
645 char **bss_config
= NULL
, **tmp_bss
;
646 size_t num_bss_configs
= 0;
647 #ifdef CONFIG_DEBUG_LINUX_TRACING
648 int enable_trace_dbg
= 0;
649 #endif /* CONFIG_DEBUG_LINUX_TRACING */
650 int start_ifaces_in_sync
= 0;
651 char **if_names
= NULL
;
652 size_t if_names_size
= 0;
654 struct dpp_global_config dpp_conf
;
655 #endif /* CONFIG_DPP */
657 if (os_program_init())
660 os_memset(&interfaces
, 0, sizeof(interfaces
));
661 interfaces
.reload_config
= hostapd_reload_config
;
662 interfaces
.config_read_cb
= hostapd_config_read
;
663 interfaces
.for_each_interface
= hostapd_for_each_interface
;
664 interfaces
.ctrl_iface_init
= hostapd_ctrl_iface_init
;
665 interfaces
.ctrl_iface_deinit
= hostapd_ctrl_iface_deinit
;
666 interfaces
.driver_init
= hostapd_driver_init
;
667 interfaces
.global_iface_path
= NULL
;
668 interfaces
.global_iface_name
= NULL
;
669 interfaces
.global_ctrl_sock
= -1;
670 dl_list_init(&interfaces
.global_ctrl_dst
);
671 #ifdef CONFIG_ETH_P_OUI
672 dl_list_init(&interfaces
.eth_p_oui
);
673 #endif /* CONFIG_ETH_P_OUI */
675 os_memset(&dpp_conf
, 0, sizeof(dpp_conf
));
676 /* TODO: dpp_conf.msg_ctx? */
677 interfaces
.dpp
= dpp_global_init(&dpp_conf
);
680 #endif /* CONFIG_DPP */
683 c
= getopt(argc
, argv
, "b:Bde:f:hi:KP:sSTtu:vg:G:");
692 if (wpa_debug_level
> 0)
699 entropy_file
= optarg
;
705 wpa_debug_show_keys
++;
709 pid_file
= os_rel2abs_path(optarg
);
712 wpa_debug_timestamp
++;
714 #ifdef CONFIG_DEBUG_LINUX_TRACING
716 enable_trace_dbg
= 1;
718 #endif /* CONFIG_DEBUG_LINUX_TRACING */
724 if (hostapd_get_global_ctrl_iface(&interfaces
, optarg
))
728 if (hostapd_get_ctrl_iface_group(&interfaces
, optarg
))
732 tmp_bss
= os_realloc_array(bss_config
,
737 bss_config
= tmp_bss
;
738 bss_config
[num_bss_configs
++] = optarg
;
740 #ifdef CONFIG_DEBUG_SYSLOG
742 wpa_debug_syslog
= 1;
744 #endif /* CONFIG_DEBUG_SYSLOG */
746 start_ifaces_in_sync
= 1;
750 return gen_uuid(optarg
);
751 #endif /* CONFIG_WPS */
753 if (hostapd_get_interface_names(&if_names
,
754 &if_names_size
, optarg
))
763 if (optind
== argc
&& interfaces
.global_iface_path
== NULL
&&
764 num_bss_configs
== 0)
767 wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb
);
770 wpa_debug_open_file(log_file
);
771 if (!log_file
&& !wpa_debug_syslog
)
772 wpa_debug_setup_stdout();
773 #ifdef CONFIG_DEBUG_SYSLOG
774 if (wpa_debug_syslog
)
775 wpa_debug_open_syslog();
776 #endif /* CONFIG_DEBUG_SYSLOG */
777 #ifdef CONFIG_DEBUG_LINUX_TRACING
778 if (enable_trace_dbg
) {
779 int tret
= wpa_debug_open_linux_tracing();
781 wpa_printf(MSG_ERROR
, "Failed to enable trace logging");
785 #endif /* CONFIG_DEBUG_LINUX_TRACING */
787 interfaces
.count
= argc
- optind
;
788 if (interfaces
.count
|| num_bss_configs
) {
789 interfaces
.iface
= os_calloc(interfaces
.count
+ num_bss_configs
,
790 sizeof(struct hostapd_iface
*));
791 if (interfaces
.iface
== NULL
) {
792 wpa_printf(MSG_ERROR
, "malloc failed");
797 if (hostapd_global_init(&interfaces
, entropy_file
)) {
798 wpa_printf(MSG_ERROR
, "Failed to initialize global context");
802 eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL
, 0,
803 hostapd_periodic
, &interfaces
, NULL
);
805 if (fst_global_init()) {
806 wpa_printf(MSG_ERROR
,
807 "Failed to initialize global FST context");
811 #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE)
812 if (!fst_global_add_ctrl(fst_ctrl_cli
))
813 wpa_printf(MSG_WARNING
, "Failed to add CLI FST ctrl");
814 #endif /* CONFIG_FST && CONFIG_CTRL_IFACE */
816 /* Allocate and parse configuration for full interface files */
817 for (i
= 0; i
< interfaces
.count
; i
++) {
818 char *if_name
= NULL
;
820 if (i
< if_names_size
)
821 if_name
= if_names
[i
];
823 interfaces
.iface
[i
] = hostapd_interface_init(&interfaces
,
827 if (!interfaces
.iface
[i
]) {
828 wpa_printf(MSG_ERROR
, "Failed to initialize interface");
831 if (start_ifaces_in_sync
)
832 interfaces
.iface
[i
]->need_to_start_in_sync
= 1;
835 /* Allocate and parse configuration for per-BSS files */
836 for (i
= 0; i
< num_bss_configs
; i
++) {
837 struct hostapd_iface
*iface
;
840 wpa_printf(MSG_INFO
, "BSS config: %s", bss_config
[i
]);
841 fname
= os_strchr(bss_config
[i
], ':');
843 wpa_printf(MSG_ERROR
,
844 "Invalid BSS config identifier '%s'",
849 iface
= hostapd_interface_init_bss(&interfaces
, bss_config
[i
],
853 for (j
= 0; j
< interfaces
.count
; j
++) {
854 if (interfaces
.iface
[j
] == iface
)
857 if (j
== interfaces
.count
) {
858 struct hostapd_iface
**tmp
;
859 tmp
= os_realloc_array(interfaces
.iface
,
860 interfaces
.count
+ 1,
861 sizeof(struct hostapd_iface
*));
863 hostapd_interface_deinit_free(iface
);
866 interfaces
.iface
= tmp
;
867 interfaces
.iface
[interfaces
.count
++] = iface
;
872 * Enable configured interfaces. Depending on channel configuration,
873 * this may complete full initialization before returning or use a
874 * callback mechanism to complete setup in case of operations like HT
875 * co-ex scans, ACS, or DFS are needed to determine channel parameters.
876 * In such case, the interface will be enabled from eloop context within
877 * hostapd_global_run().
879 interfaces
.terminate_on_error
= interfaces
.count
;
880 for (i
= 0; i
< interfaces
.count
; i
++) {
881 if (hostapd_driver_init(interfaces
.iface
[i
]) ||
882 hostapd_setup_interface(interfaces
.iface
[i
]))
886 hostapd_global_ctrl_iface_init(&interfaces
);
888 if (hostapd_global_run(&interfaces
, daemonize
, pid_file
)) {
889 wpa_printf(MSG_ERROR
, "Failed to start eloop");
896 hostapd_global_ctrl_iface_deinit(&interfaces
);
897 /* Deinitialize all interfaces */
898 for (i
= 0; i
< interfaces
.count
; i
++) {
899 if (!interfaces
.iface
[i
])
901 interfaces
.iface
[i
]->driver_ap_teardown
=
902 !!(interfaces
.iface
[i
]->drv_flags
&
903 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
904 hostapd_interface_deinit_free(interfaces
.iface
[i
]);
906 os_free(interfaces
.iface
);
909 dpp_global_deinit(interfaces
.dpp
);
910 #endif /* CONFIG_DPP */
912 if (interfaces
.eloop_initialized
)
913 eloop_cancel_timeout(hostapd_periodic
, &interfaces
, NULL
);
914 hostapd_global_deinit(pid_file
, interfaces
.eloop_initialized
);
917 wpa_debug_close_syslog();
919 wpa_debug_close_file();
920 wpa_debug_close_linux_tracing();
924 for (i
= 0; i
< if_names_size
; i
++)
925 os_free(if_names
[i
]);