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 "drivers/driver.h"
22 #include "eap_server/eap.h"
23 #include "eap_server/tncs.h"
24 #include "ap/hostapd.h"
25 #include "ap/ap_config.h"
26 #include "ap/ap_drv_ops.h"
27 #include "ap/dpp_hostapd.h"
29 #include "config_file.h"
30 #include "eap_register.h"
31 #include "ctrl_iface.h"
39 static struct hapd_global global
;
42 #ifndef CONFIG_NO_HOSTAPD_LOGGER
43 static void hostapd_logger_cb(void *ctx
, const u8
*addr
, unsigned int module
,
44 int level
, const char *txt
, size_t len
)
46 struct hostapd_data
*hapd
= ctx
;
47 char *format
, *module_str
;
49 int conf_syslog_level
, conf_stdout_level
;
50 unsigned int conf_syslog
, conf_stdout
;
53 format
= os_malloc(maxlen
);
57 if (hapd
&& hapd
->conf
) {
58 conf_syslog_level
= hapd
->conf
->logger_syslog_level
;
59 conf_stdout_level
= hapd
->conf
->logger_stdout_level
;
60 conf_syslog
= hapd
->conf
->logger_syslog
;
61 conf_stdout
= hapd
->conf
->logger_stdout
;
63 conf_syslog_level
= conf_stdout_level
= 0;
64 conf_syslog
= conf_stdout
= (unsigned int) -1;
68 case HOSTAPD_MODULE_IEEE80211
:
69 module_str
= "IEEE 802.11";
71 case HOSTAPD_MODULE_IEEE8021X
:
72 module_str
= "IEEE 802.1X";
74 case HOSTAPD_MODULE_RADIUS
:
75 module_str
= "RADIUS";
77 case HOSTAPD_MODULE_WPA
:
80 case HOSTAPD_MODULE_DRIVER
:
81 module_str
= "DRIVER";
83 case HOSTAPD_MODULE_IAPP
:
86 case HOSTAPD_MODULE_MLME
:
94 if (hapd
&& hapd
->conf
&& addr
)
95 os_snprintf(format
, maxlen
, "%s: STA " MACSTR
"%s%s: %s",
96 hapd
->conf
->iface
, MAC2STR(addr
),
97 module_str
? " " : "", module_str
? module_str
: "",
99 else if (hapd
&& hapd
->conf
)
100 os_snprintf(format
, maxlen
, "%s:%s%s %s",
101 hapd
->conf
->iface
, module_str
? " " : "",
102 module_str
? module_str
: "", txt
);
104 os_snprintf(format
, maxlen
, "STA " MACSTR
"%s%s: %s",
105 MAC2STR(addr
), module_str
? " " : "",
106 module_str
? module_str
: "", txt
);
108 os_snprintf(format
, maxlen
, "%s%s%s",
109 module_str
? module_str
: "",
110 module_str
? ": " : "", txt
);
112 #ifdef CONFIG_DEBUG_SYSLOG
113 if (wpa_debug_syslog
)
115 #endif /* CONFIG_DEBUG_SYSLOG */
116 if ((conf_stdout
& module
) && level
>= conf_stdout_level
) {
117 wpa_debug_print_timestamp();
118 wpa_printf(MSG_INFO
, "%s", format
);
121 #ifndef CONFIG_NATIVE_WINDOWS
122 if ((conf_syslog
& module
) && level
>= conf_syslog_level
) {
125 case HOSTAPD_LEVEL_DEBUG_VERBOSE
:
126 case HOSTAPD_LEVEL_DEBUG
:
127 priority
= LOG_DEBUG
;
129 case HOSTAPD_LEVEL_INFO
:
132 case HOSTAPD_LEVEL_NOTICE
:
133 priority
= LOG_NOTICE
;
135 case HOSTAPD_LEVEL_WARNING
:
136 priority
= LOG_WARNING
;
142 syslog(priority
, "%s", format
);
144 #endif /* CONFIG_NATIVE_WINDOWS */
148 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
152 * hostapd_driver_init - Preparate driver interface
154 static int hostapd_driver_init(struct hostapd_iface
*iface
)
156 struct wpa_init_params params
;
158 struct hostapd_data
*hapd
= iface
->bss
[0];
159 struct hostapd_bss_config
*conf
= hapd
->conf
;
161 struct wpa_driver_capa capa
;
163 if (hapd
->driver
== NULL
|| hapd
->driver
->hapd_init
== NULL
) {
164 wpa_printf(MSG_ERROR
, "No hostapd driver wrapper available");
168 /* Initialize the driver interface */
169 if (!(b
[0] | b
[1] | b
[2] | b
[3] | b
[4] | b
[5]))
172 os_memset(¶ms
, 0, sizeof(params
));
173 for (i
= 0; wpa_drivers
[i
]; i
++) {
174 if (wpa_drivers
[i
] != hapd
->driver
)
177 if (global
.drv_priv
[i
] == NULL
&&
178 wpa_drivers
[i
]->global_init
) {
180 wpa_drivers
[i
]->global_init(iface
->interfaces
);
181 if (global
.drv_priv
[i
] == NULL
) {
182 wpa_printf(MSG_ERROR
, "Failed to initialize "
184 wpa_drivers
[i
]->name
);
189 params
.global_priv
= global
.drv_priv
[i
];
193 params
.ifname
= hapd
->conf
->iface
;
194 params
.driver_params
= hapd
->iconf
->driver_params
;
195 params
.use_pae_group_addr
= hapd
->conf
->use_pae_group_addr
;
197 params
.num_bridge
= hapd
->iface
->num_bss
;
198 params
.bridge
= os_calloc(hapd
->iface
->num_bss
, sizeof(char *));
199 if (params
.bridge
== NULL
)
201 for (i
= 0; i
< hapd
->iface
->num_bss
; i
++) {
202 struct hostapd_data
*bss
= hapd
->iface
->bss
[i
];
203 if (bss
->conf
->bridge
[0])
204 params
.bridge
[i
] = bss
->conf
->bridge
;
207 params
.own_addr
= hapd
->own_addr
;
209 hapd
->drv_priv
= hapd
->driver
->hapd_init(hapd
, ¶ms
);
210 os_free(params
.bridge
);
211 if (hapd
->drv_priv
== NULL
) {
212 wpa_printf(MSG_ERROR
, "%s driver initialization failed.",
218 if (hapd
->driver
->get_capa
&&
219 hapd
->driver
->get_capa(hapd
->drv_priv
, &capa
) == 0) {
220 struct wowlan_triggers
*triggs
;
222 iface
->drv_flags
= capa
.flags
;
223 iface
->smps_modes
= capa
.smps_modes
;
224 iface
->probe_resp_offloads
= capa
.probe_resp_offloads
;
226 * Use default extended capa values from per-radio information
228 iface
->extended_capa
= capa
.extended_capa
;
229 iface
->extended_capa_mask
= capa
.extended_capa_mask
;
230 iface
->extended_capa_len
= capa
.extended_capa_len
;
231 iface
->drv_max_acl_mac_addrs
= capa
.max_acl_mac_addrs
;
234 * Override extended capa with per-interface type (AP), if
235 * available from the driver.
237 hostapd_get_ext_capa(iface
);
239 triggs
= wpa_get_wowlan_triggers(conf
->wowlan_triggers
, &capa
);
240 if (triggs
&& hapd
->driver
->set_wowlan
) {
241 if (hapd
->driver
->set_wowlan(hapd
->drv_priv
, triggs
))
242 wpa_printf(MSG_ERROR
, "set_wowlan failed");
252 * hostapd_interface_init - Read configuration file and init BSS data
254 * This function is used to parse configuration file for a full interface (one
255 * or more BSSes sharing the same radio) and allocate memory for the BSS
256 * interfaces. No actual driver operations are started.
258 static struct hostapd_iface
*
259 hostapd_interface_init(struct hapd_interfaces
*interfaces
, const char *if_name
,
260 const char *config_fname
, int debug
)
262 struct hostapd_iface
*iface
;
265 wpa_printf(MSG_ERROR
, "Configuration file: %s", config_fname
);
266 iface
= hostapd_init(interfaces
, config_fname
);
271 os_strlcpy(iface
->conf
->bss
[0]->iface
, if_name
,
272 sizeof(iface
->conf
->bss
[0]->iface
));
275 iface
->interfaces
= interfaces
;
277 for (k
= 0; k
< debug
; k
++) {
278 if (iface
->bss
[0]->conf
->logger_stdout_level
> 0)
279 iface
->bss
[0]->conf
->logger_stdout_level
--;
282 if (iface
->conf
->bss
[0]->iface
[0] == '\0' &&
283 !hostapd_drv_none(iface
->bss
[0])) {
284 wpa_printf(MSG_ERROR
,
285 "Interface name not specified in %s, nor by '-i' parameter",
287 hostapd_interface_deinit_free(iface
);
296 * handle_term - SIGINT and SIGTERM handler to terminate hostapd process
298 static void handle_term(int sig
, void *signal_ctx
)
300 wpa_printf(MSG_DEBUG
, "Signal %d received - terminating", sig
);
305 #ifndef CONFIG_NATIVE_WINDOWS
307 static int handle_reload_iface(struct hostapd_iface
*iface
, void *ctx
)
309 if (hostapd_reload_config(iface
) < 0) {
310 wpa_printf(MSG_WARNING
, "Failed to read new configuration "
311 "file - continuing with old.");
318 * handle_reload - SIGHUP handler to reload configuration
320 static void handle_reload(int sig
, void *signal_ctx
)
322 struct hapd_interfaces
*interfaces
= signal_ctx
;
323 wpa_printf(MSG_DEBUG
, "Signal %d received - reloading configuration",
325 hostapd_for_each_interface(interfaces
, handle_reload_iface
, NULL
);
329 static void handle_dump_state(int sig
, void *signal_ctx
)
331 /* Not used anymore - ignore signal */
333 #endif /* CONFIG_NATIVE_WINDOWS */
336 static int hostapd_global_init(struct hapd_interfaces
*interfaces
,
337 const char *entropy_file
)
341 os_memset(&global
, 0, sizeof(global
));
343 hostapd_logger_register_cb(hostapd_logger_cb
);
345 if (eap_server_register_methods()) {
346 wpa_printf(MSG_ERROR
, "Failed to register EAP methods");
351 wpa_printf(MSG_ERROR
, "Failed to initialize event loop");
354 interfaces
->eloop_initialized
= 1;
356 random_init(entropy_file
);
358 #ifndef CONFIG_NATIVE_WINDOWS
359 eloop_register_signal(SIGHUP
, handle_reload
, interfaces
);
360 eloop_register_signal(SIGUSR1
, handle_dump_state
, interfaces
);
361 #endif /* CONFIG_NATIVE_WINDOWS */
362 eloop_register_signal_terminate(handle_term
, interfaces
);
364 #ifndef CONFIG_NATIVE_WINDOWS
365 openlog("hostapd", 0, LOG_DAEMON
);
366 #endif /* CONFIG_NATIVE_WINDOWS */
368 for (i
= 0; wpa_drivers
[i
]; i
++)
370 if (global
.drv_count
== 0) {
371 wpa_printf(MSG_ERROR
, "No drivers enabled");
374 global
.drv_priv
= os_calloc(global
.drv_count
, sizeof(void *));
375 if (global
.drv_priv
== NULL
)
382 static void hostapd_global_deinit(const char *pid_file
, int eloop_initialized
)
386 for (i
= 0; wpa_drivers
[i
] && global
.drv_priv
; i
++) {
387 if (!global
.drv_priv
[i
])
389 wpa_drivers
[i
]->global_deinit(global
.drv_priv
[i
]);
391 os_free(global
.drv_priv
);
392 global
.drv_priv
= NULL
;
394 #ifdef EAP_SERVER_TNC
395 tncs_global_deinit();
396 #endif /* EAP_SERVER_TNC */
400 if (eloop_initialized
)
403 #ifndef CONFIG_NATIVE_WINDOWS
405 #endif /* CONFIG_NATIVE_WINDOWS */
407 eap_server_unregister_methods();
409 os_daemonize_terminate(pid_file
);
413 static int hostapd_global_run(struct hapd_interfaces
*ifaces
, int daemonize
,
414 const char *pid_file
)
416 #ifdef EAP_SERVER_TNC
420 for (i
= 0; !tnc
&& i
< ifaces
->count
; i
++) {
421 for (k
= 0; k
< ifaces
->iface
[i
]->num_bss
; k
++) {
422 if (ifaces
->iface
[i
]->bss
[0]->conf
->tnc
) {
429 if (tnc
&& tncs_global_init() < 0) {
430 wpa_printf(MSG_ERROR
, "Failed to initialize TNCS");
433 #endif /* EAP_SERVER_TNC */
436 if (os_daemonize(pid_file
)) {
437 wpa_printf(MSG_ERROR
, "daemon: %s", strerror(errno
));
440 if (eloop_sock_requeue()) {
441 wpa_printf(MSG_ERROR
, "eloop_sock_requeue: %s",
453 static void show_version(void)
456 "hostapd v" VERSION_STR
"\n"
457 "User space daemon for IEEE 802.11 AP management,\n"
458 "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
459 "Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi> "
460 "and contributors\n");
464 static void usage(void)
469 "usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] "
471 " [-g <global ctrl_iface>] [-G <group>]\\\n"
472 " [-i <comma-separated list of interface names>]\\\n"
473 " <configuration file(s)>\n"
476 " -h show this usage\n"
477 " -d show more debug messages (-dd for even more)\n"
478 " -B run daemon in the background\n"
480 " -g global control interface path\n"
481 " -G group for control interfaces\n"
483 " -K include key data in debug messages\n"
484 #ifdef CONFIG_DEBUG_FILE
485 " -f log output to debug file instead of stdout\n"
486 #endif /* CONFIG_DEBUG_FILE */
487 #ifdef CONFIG_DEBUG_LINUX_TRACING
488 " -T record to Linux tracing in addition to logging\n"
489 " (records all messages regardless of debug verbosity)\n"
490 #endif /* CONFIG_DEBUG_LINUX_TRACING */
491 " -i list of interface names to use\n"
492 #ifdef CONFIG_DEBUG_SYSLOG
493 " -s log output to syslog instead of stdout\n"
494 #endif /* CONFIG_DEBUG_SYSLOG */
495 " -S start all the interfaces synchronously\n"
496 " -t include timestamps in some debug messages\n"
497 " -v show hostapd version\n");
503 static const char * hostapd_msg_ifname_cb(void *ctx
)
505 struct hostapd_data
*hapd
= ctx
;
506 if (hapd
&& hapd
->conf
)
507 return hapd
->conf
->iface
;
512 static int hostapd_get_global_ctrl_iface(struct hapd_interfaces
*interfaces
,
515 #ifndef CONFIG_CTRL_IFACE_UDP
517 #endif /* !CONFIG_CTRL_IFACE_UDP */
519 os_free(interfaces
->global_iface_path
);
520 interfaces
->global_iface_path
= os_strdup(path
);
521 if (interfaces
->global_iface_path
== NULL
)
524 #ifndef CONFIG_CTRL_IFACE_UDP
525 pos
= os_strrchr(interfaces
->global_iface_path
, '/');
527 wpa_printf(MSG_ERROR
, "No '/' in the global control interface "
529 os_free(interfaces
->global_iface_path
);
530 interfaces
->global_iface_path
= NULL
;
535 interfaces
->global_iface_name
= pos
+ 1;
536 #endif /* !CONFIG_CTRL_IFACE_UDP */
542 static int hostapd_get_ctrl_iface_group(struct hapd_interfaces
*interfaces
,
545 #ifndef CONFIG_NATIVE_WINDOWS
547 grp
= getgrnam(group
);
549 wpa_printf(MSG_ERROR
, "Unknown group '%s'", group
);
552 interfaces
->ctrl_iface_group
= grp
->gr_gid
;
553 #endif /* CONFIG_NATIVE_WINDOWS */
558 static int hostapd_get_interface_names(char ***if_names
,
559 size_t *if_names_size
,
562 char *if_name
, *tmp
, **nnames
;
567 if_name
= strtok_r(arg
, ",", &tmp
);
570 nnames
= os_realloc_array(*if_names
, 1 + *if_names_size
,
576 (*if_names
)[*if_names_size
] = os_strdup(if_name
);
577 if (!(*if_names
)[*if_names_size
])
580 if_name
= strtok_r(NULL
, ",", &tmp
);
586 for (i
= 0; i
< *if_names_size
; i
++)
587 os_free((*if_names
)[i
]);
596 static int gen_uuid(const char *txt_addr
)
602 if (hwaddr_aton(txt_addr
, addr
) < 0)
605 uuid_gen_mac_addr(addr
, uuid
);
606 if (uuid_bin2str(uuid
, buf
, sizeof(buf
)) < 0)
613 #endif /* CONFIG_WPS */
616 #ifndef HOSTAPD_CLEANUP_INTERVAL
617 #define HOSTAPD_CLEANUP_INTERVAL 10
618 #endif /* HOSTAPD_CLEANUP_INTERVAL */
620 static int hostapd_periodic_call(struct hostapd_iface
*iface
, void *ctx
)
622 hostapd_periodic_iface(iface
);
627 /* Periodic cleanup tasks */
628 static void hostapd_periodic(void *eloop_ctx
, void *timeout_ctx
)
630 struct hapd_interfaces
*interfaces
= eloop_ctx
;
632 eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL
, 0,
633 hostapd_periodic
, interfaces
, NULL
);
634 hostapd_for_each_interface(interfaces
, hostapd_periodic_call
, NULL
);
638 int main(int argc
, char *argv
[])
640 struct hapd_interfaces interfaces
;
643 int c
, debug
= 0, daemonize
= 0;
644 char *pid_file
= NULL
;
645 const char *log_file
= NULL
;
646 const char *entropy_file
= NULL
;
647 char **bss_config
= NULL
, **tmp_bss
;
648 size_t num_bss_configs
= 0;
649 #ifdef CONFIG_DEBUG_LINUX_TRACING
650 int enable_trace_dbg
= 0;
651 #endif /* CONFIG_DEBUG_LINUX_TRACING */
652 int start_ifaces_in_sync
= 0;
653 char **if_names
= NULL
;
654 size_t if_names_size
= 0;
656 if (os_program_init())
659 os_memset(&interfaces
, 0, sizeof(interfaces
));
660 interfaces
.reload_config
= hostapd_reload_config
;
661 interfaces
.config_read_cb
= hostapd_config_read
;
662 interfaces
.for_each_interface
= hostapd_for_each_interface
;
663 interfaces
.ctrl_iface_init
= hostapd_ctrl_iface_init
;
664 interfaces
.ctrl_iface_deinit
= hostapd_ctrl_iface_deinit
;
665 interfaces
.driver_init
= hostapd_driver_init
;
666 interfaces
.global_iface_path
= NULL
;
667 interfaces
.global_iface_name
= NULL
;
668 interfaces
.global_ctrl_sock
= -1;
669 dl_list_init(&interfaces
.global_ctrl_dst
);
670 #ifdef CONFIG_ETH_P_OUI
671 dl_list_init(&interfaces
.eth_p_oui
);
672 #endif /* CONFIG_ETH_P_OUI */
674 hostapd_dpp_init_global(&interfaces
);
675 #endif /* CONFIG_DPP */
678 c
= getopt(argc
, argv
, "b:Bde:f:hi:KP:sSTtu:vg:G:");
687 if (wpa_debug_level
> 0)
694 entropy_file
= optarg
;
700 wpa_debug_show_keys
++;
704 pid_file
= os_rel2abs_path(optarg
);
707 wpa_debug_timestamp
++;
709 #ifdef CONFIG_DEBUG_LINUX_TRACING
711 enable_trace_dbg
= 1;
713 #endif /* CONFIG_DEBUG_LINUX_TRACING */
719 if (hostapd_get_global_ctrl_iface(&interfaces
, optarg
))
723 if (hostapd_get_ctrl_iface_group(&interfaces
, optarg
))
727 tmp_bss
= os_realloc_array(bss_config
,
732 bss_config
= tmp_bss
;
733 bss_config
[num_bss_configs
++] = optarg
;
735 #ifdef CONFIG_DEBUG_SYSLOG
737 wpa_debug_syslog
= 1;
739 #endif /* CONFIG_DEBUG_SYSLOG */
741 start_ifaces_in_sync
= 1;
745 return gen_uuid(optarg
);
746 #endif /* CONFIG_WPS */
748 if (hostapd_get_interface_names(&if_names
,
749 &if_names_size
, optarg
))
758 if (optind
== argc
&& interfaces
.global_iface_path
== NULL
&&
759 num_bss_configs
== 0)
762 wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb
);
765 wpa_debug_open_file(log_file
);
767 wpa_debug_setup_stdout();
768 #ifdef CONFIG_DEBUG_SYSLOG
769 if (wpa_debug_syslog
)
770 wpa_debug_open_syslog();
771 #endif /* CONFIG_DEBUG_SYSLOG */
772 #ifdef CONFIG_DEBUG_LINUX_TRACING
773 if (enable_trace_dbg
) {
774 int tret
= wpa_debug_open_linux_tracing();
776 wpa_printf(MSG_ERROR
, "Failed to enable trace logging");
780 #endif /* CONFIG_DEBUG_LINUX_TRACING */
782 interfaces
.count
= argc
- optind
;
783 if (interfaces
.count
|| num_bss_configs
) {
784 interfaces
.iface
= os_calloc(interfaces
.count
+ num_bss_configs
,
785 sizeof(struct hostapd_iface
*));
786 if (interfaces
.iface
== NULL
) {
787 wpa_printf(MSG_ERROR
, "malloc failed");
792 if (hostapd_global_init(&interfaces
, entropy_file
)) {
793 wpa_printf(MSG_ERROR
, "Failed to initialize global context");
797 eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL
, 0,
798 hostapd_periodic
, &interfaces
, NULL
);
800 if (fst_global_init()) {
801 wpa_printf(MSG_ERROR
,
802 "Failed to initialize global FST context");
806 #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE)
807 if (!fst_global_add_ctrl(fst_ctrl_cli
))
808 wpa_printf(MSG_WARNING
, "Failed to add CLI FST ctrl");
809 #endif /* CONFIG_FST && CONFIG_CTRL_IFACE */
811 /* Allocate and parse configuration for full interface files */
812 for (i
= 0; i
< interfaces
.count
; i
++) {
813 char *if_name
= NULL
;
815 if (i
< if_names_size
)
816 if_name
= if_names
[i
];
818 interfaces
.iface
[i
] = hostapd_interface_init(&interfaces
,
822 if (!interfaces
.iface
[i
]) {
823 wpa_printf(MSG_ERROR
, "Failed to initialize interface");
826 if (start_ifaces_in_sync
)
827 interfaces
.iface
[i
]->need_to_start_in_sync
= 1;
830 /* Allocate and parse configuration for per-BSS files */
831 for (i
= 0; i
< num_bss_configs
; i
++) {
832 struct hostapd_iface
*iface
;
835 wpa_printf(MSG_INFO
, "BSS config: %s", bss_config
[i
]);
836 fname
= os_strchr(bss_config
[i
], ':');
838 wpa_printf(MSG_ERROR
,
839 "Invalid BSS config identifier '%s'",
844 iface
= hostapd_interface_init_bss(&interfaces
, bss_config
[i
],
848 for (j
= 0; j
< interfaces
.count
; j
++) {
849 if (interfaces
.iface
[j
] == iface
)
852 if (j
== interfaces
.count
) {
853 struct hostapd_iface
**tmp
;
854 tmp
= os_realloc_array(interfaces
.iface
,
855 interfaces
.count
+ 1,
856 sizeof(struct hostapd_iface
*));
858 hostapd_interface_deinit_free(iface
);
861 interfaces
.iface
= tmp
;
862 interfaces
.iface
[interfaces
.count
++] = iface
;
867 * Enable configured interfaces. Depending on channel configuration,
868 * this may complete full initialization before returning or use a
869 * callback mechanism to complete setup in case of operations like HT
870 * co-ex scans, ACS, or DFS are needed to determine channel parameters.
871 * In such case, the interface will be enabled from eloop context within
872 * hostapd_global_run().
874 interfaces
.terminate_on_error
= interfaces
.count
;
875 for (i
= 0; i
< interfaces
.count
; i
++) {
876 if (hostapd_driver_init(interfaces
.iface
[i
]) ||
877 hostapd_setup_interface(interfaces
.iface
[i
]))
881 hostapd_global_ctrl_iface_init(&interfaces
);
883 if (hostapd_global_run(&interfaces
, daemonize
, pid_file
)) {
884 wpa_printf(MSG_ERROR
, "Failed to start eloop");
891 hostapd_global_ctrl_iface_deinit(&interfaces
);
892 /* Deinitialize all interfaces */
893 for (i
= 0; i
< interfaces
.count
; i
++) {
894 if (!interfaces
.iface
[i
])
896 interfaces
.iface
[i
]->driver_ap_teardown
=
897 !!(interfaces
.iface
[i
]->drv_flags
&
898 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
899 hostapd_interface_deinit_free(interfaces
.iface
[i
]);
901 os_free(interfaces
.iface
);
904 hostapd_dpp_deinit_global(&interfaces
);
905 #endif /* CONFIG_DPP */
907 if (interfaces
.eloop_initialized
)
908 eloop_cancel_timeout(hostapd_periodic
, &interfaces
, NULL
);
909 hostapd_global_deinit(pid_file
, interfaces
.eloop_initialized
);
912 wpa_debug_close_syslog();
914 wpa_debug_close_file();
915 wpa_debug_close_linux_tracing();
919 for (i
= 0; i
< if_names_size
; i
++)
920 os_free(if_names
[i
]);