blob: eb1e861abaca9fc59205557826cee30aff01e807 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / main()
Hai Shaloma20dcd72022-02-04 13:43:00 -08003 * Copyright (c) 2002-2022, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10#ifndef CONFIG_NATIVE_WINDOWS
11#include <syslog.h>
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -070012#include <grp.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013#endif /* CONFIG_NATIVE_WINDOWS */
14
15#include "utils/common.h"
16#include "utils/eloop.h"
Dmitry Shmidt96be6222014-02-13 10:16:51 -080017#include "utils/uuid.h"
Sunil Ravia04bd252022-05-02 22:54:18 -070018#include "crypto/crypto.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "crypto/random.h"
20#include "crypto/tls.h"
21#include "common/version.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070022#include "common/dpp.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#include "drivers/driver.h"
24#include "eap_server/eap.h"
25#include "eap_server/tncs.h"
26#include "ap/hostapd.h"
27#include "ap/ap_config.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070028#include "ap/ap_drv_ops.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070029#include "ap/dpp_hostapd.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080030#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070031#include "config_file.h"
32#include "eap_register.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "ctrl_iface.h"
Gabriel Biren72cf9a52021-06-25 23:29:26 +000034#ifdef CONFIG_CTRL_IFACE_AIDL
35#include "aidl.h"
36#endif /* CONFIG_CTRL_IFACE_AIDL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080038struct hapd_global {
39 void **drv_priv;
40 size_t drv_count;
41};
42
43static struct hapd_global global;
44
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#ifndef CONFIG_NO_HOSTAPD_LOGGER
47static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
48 int level, const char *txt, size_t len)
49{
50 struct hostapd_data *hapd = ctx;
51 char *format, *module_str;
52 int maxlen;
53 int conf_syslog_level, conf_stdout_level;
54 unsigned int conf_syslog, conf_stdout;
55
56 maxlen = len + 100;
57 format = os_malloc(maxlen);
58 if (!format)
59 return;
60
61 if (hapd && hapd->conf) {
62 conf_syslog_level = hapd->conf->logger_syslog_level;
63 conf_stdout_level = hapd->conf->logger_stdout_level;
64 conf_syslog = hapd->conf->logger_syslog;
65 conf_stdout = hapd->conf->logger_stdout;
66 } else {
67 conf_syslog_level = conf_stdout_level = 0;
68 conf_syslog = conf_stdout = (unsigned int) -1;
69 }
70
71 switch (module) {
72 case HOSTAPD_MODULE_IEEE80211:
73 module_str = "IEEE 802.11";
74 break;
75 case HOSTAPD_MODULE_IEEE8021X:
76 module_str = "IEEE 802.1X";
77 break;
78 case HOSTAPD_MODULE_RADIUS:
79 module_str = "RADIUS";
80 break;
81 case HOSTAPD_MODULE_WPA:
82 module_str = "WPA";
83 break;
84 case HOSTAPD_MODULE_DRIVER:
85 module_str = "DRIVER";
86 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087 case HOSTAPD_MODULE_MLME:
88 module_str = "MLME";
89 break;
90 default:
91 module_str = NULL;
92 break;
93 }
94
95 if (hapd && hapd->conf && addr)
96 os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s",
97 hapd->conf->iface, MAC2STR(addr),
Dmitry Shmidt96be6222014-02-13 10:16:51 -080098 module_str ? " " : "", module_str ? module_str : "",
99 txt);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100 else if (hapd && hapd->conf)
101 os_snprintf(format, maxlen, "%s:%s%s %s",
102 hapd->conf->iface, module_str ? " " : "",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700103 module_str ? module_str : "", txt);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 else if (addr)
105 os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s",
106 MAC2STR(addr), module_str ? " " : "",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700107 module_str ? module_str : "", txt);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108 else
109 os_snprintf(format, maxlen, "%s%s%s",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700110 module_str ? module_str : "",
111 module_str ? ": " : "", txt);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112
Paul Stewart092955c2017-02-06 09:13:09 -0800113#ifdef CONFIG_DEBUG_SYSLOG
114 if (wpa_debug_syslog)
115 conf_stdout = 0;
116#endif /* CONFIG_DEBUG_SYSLOG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700117 if ((conf_stdout & module) && level >= conf_stdout_level) {
118 wpa_debug_print_timestamp();
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800119 wpa_printf(MSG_INFO, "%s", format);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700120 }
121
122#ifndef CONFIG_NATIVE_WINDOWS
123 if ((conf_syslog & module) && level >= conf_syslog_level) {
124 int priority;
125 switch (level) {
126 case HOSTAPD_LEVEL_DEBUG_VERBOSE:
127 case HOSTAPD_LEVEL_DEBUG:
128 priority = LOG_DEBUG;
129 break;
130 case HOSTAPD_LEVEL_INFO:
131 priority = LOG_INFO;
132 break;
133 case HOSTAPD_LEVEL_NOTICE:
134 priority = LOG_NOTICE;
135 break;
136 case HOSTAPD_LEVEL_WARNING:
137 priority = LOG_WARNING;
138 break;
139 default:
140 priority = LOG_INFO;
141 break;
142 }
143 syslog(priority, "%s", format);
144 }
145#endif /* CONFIG_NATIVE_WINDOWS */
146
147 os_free(format);
148}
149#endif /* CONFIG_NO_HOSTAPD_LOGGER */
150
151
152/**
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800153 * hostapd_driver_init - Preparate driver interface
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700155static int hostapd_driver_init(struct hostapd_iface *iface)
156{
157 struct wpa_init_params params;
158 size_t i;
159 struct hostapd_data *hapd = iface->bss[0];
160 struct hostapd_bss_config *conf = hapd->conf;
161 u8 *b = conf->bssid;
162 struct wpa_driver_capa capa;
163
164 if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) {
165 wpa_printf(MSG_ERROR, "No hostapd driver wrapper available");
166 return -1;
167 }
168
169 /* Initialize the driver interface */
170 if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
171 b = NULL;
172
173 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800174 for (i = 0; wpa_drivers[i]; i++) {
175 if (wpa_drivers[i] != hapd->driver)
176 continue;
177
178 if (global.drv_priv[i] == NULL &&
179 wpa_drivers[i]->global_init) {
Dmitry Shmidte4663042016-04-04 10:07:49 -0700180 global.drv_priv[i] =
181 wpa_drivers[i]->global_init(iface->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800182 if (global.drv_priv[i] == NULL) {
183 wpa_printf(MSG_ERROR, "Failed to initialize "
184 "driver '%s'",
185 wpa_drivers[i]->name);
186 return -1;
187 }
188 }
189
190 params.global_priv = global.drv_priv[i];
191 break;
192 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700193 params.bssid = b;
194 params.ifname = hapd->conf->iface;
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800195 params.driver_params = hapd->iconf->driver_params;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196 params.use_pae_group_addr = hapd->conf->use_pae_group_addr;
197
198 params.num_bridge = hapd->iface->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700199 params.bridge = os_calloc(hapd->iface->num_bss, sizeof(char *));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700200 if (params.bridge == NULL)
201 return -1;
202 for (i = 0; i < hapd->iface->num_bss; i++) {
203 struct hostapd_data *bss = hapd->iface->bss[i];
204 if (bss->conf->bridge[0])
205 params.bridge[i] = bss->conf->bridge;
206 }
207
208 params.own_addr = hapd->own_addr;
209
210 hapd->drv_priv = hapd->driver->hapd_init(hapd, &params);
211 os_free(params.bridge);
212 if (hapd->drv_priv == NULL) {
213 wpa_printf(MSG_ERROR, "%s driver initialization failed.",
214 hapd->driver->name);
215 hapd->driver = NULL;
216 return -1;
217 }
218
219 if (hapd->driver->get_capa &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800220 hapd->driver->get_capa(hapd->drv_priv, &capa) == 0) {
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700221 struct wowlan_triggers *triggs;
222
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223 iface->drv_flags = capa.flags;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700224 iface->drv_flags2 = capa.flags2;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800225 iface->probe_resp_offloads = capa.probe_resp_offloads;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700226 /*
227 * Use default extended capa values from per-radio information
228 */
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700229 iface->extended_capa = capa.extended_capa;
230 iface->extended_capa_mask = capa.extended_capa_mask;
231 iface->extended_capa_len = capa.extended_capa_len;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700232 iface->drv_max_acl_mac_addrs = capa.max_acl_mac_addrs;
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700233
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700234 /*
235 * Override extended capa with per-interface type (AP), if
236 * available from the driver.
237 */
238 hostapd_get_ext_capa(iface);
239
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700240 triggs = wpa_get_wowlan_triggers(conf->wowlan_triggers, &capa);
241 if (triggs && hapd->driver->set_wowlan) {
242 if (hapd->driver->set_wowlan(hapd->drv_priv, triggs))
243 wpa_printf(MSG_ERROR, "set_wowlan failed");
244 }
245 os_free(triggs);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000246
247 iface->mbssid_max_interfaces = capa.mbssid_max_interfaces;
248 iface->ema_max_periodicity = capa.ema_max_periodicity;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800249 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700250
251 return 0;
252}
253
254
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800255/**
256 * hostapd_interface_init - Read configuration file and init BSS data
257 *
258 * This function is used to parse configuration file for a full interface (one
259 * or more BSSes sharing the same radio) and allocate memory for the BSS
Hai Shalom74f70d42019-02-11 14:42:39 -0800260 * interfaces. No actual driver operations are started.
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800261 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262static struct hostapd_iface *
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700263hostapd_interface_init(struct hapd_interfaces *interfaces, const char *if_name,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 const char *config_fname, int debug)
265{
266 struct hostapd_iface *iface;
267 int k;
268
Hai Shalomfdcde762020-04-02 11:19:20 -0700269 wpa_printf(MSG_DEBUG, "Configuration file: %s", config_fname);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800270 iface = hostapd_init(interfaces, config_fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271 if (!iface)
272 return NULL;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700273
274 if (if_name) {
275 os_strlcpy(iface->conf->bss[0]->iface, if_name,
276 sizeof(iface->conf->bss[0]->iface));
277 }
278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700279 iface->interfaces = interfaces;
280
281 for (k = 0; k < debug; k++) {
282 if (iface->bss[0]->conf->logger_stdout_level > 0)
283 iface->bss[0]->conf->logger_stdout_level--;
284 }
285
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800286 if (iface->conf->bss[0]->iface[0] == '\0' &&
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700287 !hostapd_drv_none(iface->bss[0])) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700288 wpa_printf(MSG_ERROR,
289 "Interface name not specified in %s, nor by '-i' parameter",
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700290 config_fname);
291 hostapd_interface_deinit_free(iface);
292 return NULL;
293 }
294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295 return iface;
296}
297
298
299/**
300 * handle_term - SIGINT and SIGTERM handler to terminate hostapd process
301 */
302static void handle_term(int sig, void *signal_ctx)
303{
304 wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig);
305 eloop_terminate();
306}
307
308
309#ifndef CONFIG_NATIVE_WINDOWS
310
311static int handle_reload_iface(struct hostapd_iface *iface, void *ctx)
312{
313 if (hostapd_reload_config(iface) < 0) {
314 wpa_printf(MSG_WARNING, "Failed to read new configuration "
315 "file - continuing with old.");
316 }
317 return 0;
318}
319
320
321/**
322 * handle_reload - SIGHUP handler to reload configuration
323 */
324static void handle_reload(int sig, void *signal_ctx)
325{
326 struct hapd_interfaces *interfaces = signal_ctx;
327 wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration",
328 sig);
329 hostapd_for_each_interface(interfaces, handle_reload_iface, NULL);
330}
331
332
333static void handle_dump_state(int sig, void *signal_ctx)
334{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800335 /* Not used anymore - ignore signal */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336}
337#endif /* CONFIG_NATIVE_WINDOWS */
338
339
Jouni Malinen75ecf522011-06-27 15:19:46 -0700340static int hostapd_global_init(struct hapd_interfaces *interfaces,
341 const char *entropy_file)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800343 int i;
344
345 os_memset(&global, 0, sizeof(global));
346
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347 hostapd_logger_register_cb(hostapd_logger_cb);
348
349 if (eap_server_register_methods()) {
350 wpa_printf(MSG_ERROR, "Failed to register EAP methods");
351 return -1;
352 }
353
354 if (eloop_init()) {
355 wpa_printf(MSG_ERROR, "Failed to initialize event loop");
356 return -1;
357 }
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700358 interfaces->eloop_initialized = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359
Jouni Malinen75ecf522011-06-27 15:19:46 -0700360 random_init(entropy_file);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700361
362#ifndef CONFIG_NATIVE_WINDOWS
363 eloop_register_signal(SIGHUP, handle_reload, interfaces);
364 eloop_register_signal(SIGUSR1, handle_dump_state, interfaces);
365#endif /* CONFIG_NATIVE_WINDOWS */
366 eloop_register_signal_terminate(handle_term, interfaces);
367
368#ifndef CONFIG_NATIVE_WINDOWS
369 openlog("hostapd", 0, LOG_DAEMON);
370#endif /* CONFIG_NATIVE_WINDOWS */
371
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800372 for (i = 0; wpa_drivers[i]; i++)
373 global.drv_count++;
374 if (global.drv_count == 0) {
375 wpa_printf(MSG_ERROR, "No drivers enabled");
376 return -1;
377 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700378 global.drv_priv = os_calloc(global.drv_count, sizeof(void *));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800379 if (global.drv_priv == NULL)
380 return -1;
381
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382 return 0;
383}
384
385
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700386static void hostapd_global_deinit(const char *pid_file, int eloop_initialized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700387{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800388 int i;
389
390 for (i = 0; wpa_drivers[i] && global.drv_priv; i++) {
391 if (!global.drv_priv[i])
392 continue;
393 wpa_drivers[i]->global_deinit(global.drv_priv[i]);
394 }
395 os_free(global.drv_priv);
396 global.drv_priv = NULL;
397
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398#ifdef EAP_SERVER_TNC
399 tncs_global_deinit();
400#endif /* EAP_SERVER_TNC */
401
402 random_deinit();
403
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700404 if (eloop_initialized)
405 eloop_destroy();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406
407#ifndef CONFIG_NATIVE_WINDOWS
408 closelog();
409#endif /* CONFIG_NATIVE_WINDOWS */
410
411 eap_server_unregister_methods();
412
413 os_daemonize_terminate(pid_file);
414}
415
416
417static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize,
418 const char *pid_file)
419{
420#ifdef EAP_SERVER_TNC
421 int tnc = 0;
422 size_t i, k;
423
424 for (i = 0; !tnc && i < ifaces->count; i++) {
425 for (k = 0; k < ifaces->iface[i]->num_bss; k++) {
426 if (ifaces->iface[i]->bss[0]->conf->tnc) {
427 tnc++;
428 break;
429 }
430 }
431 }
432
433 if (tnc && tncs_global_init() < 0) {
434 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
435 return -1;
436 }
437#endif /* EAP_SERVER_TNC */
438
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800439 if (daemonize) {
440 if (os_daemonize(pid_file)) {
441 wpa_printf(MSG_ERROR, "daemon: %s", strerror(errno));
442 return -1;
443 }
444 if (eloop_sock_requeue()) {
445 wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s",
446 strerror(errno));
447 return -1;
448 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449 }
450
451 eloop_run();
452
453 return 0;
454}
455
456
457static void show_version(void)
458{
459 fprintf(stderr,
Hai Shalomfdcde762020-04-02 11:19:20 -0700460 "hostapd v%s\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700461 "User space daemon for IEEE 802.11 AP management,\n"
462 "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n"
Hai Shaloma20dcd72022-02-04 13:43:00 -0800463 "Copyright (c) 2002-2022, Jouni Malinen <j@w1.fi> "
Hai Shalomfdcde762020-04-02 11:19:20 -0700464 "and contributors\n",
465 VERSION_STR);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466}
467
468
469static void usage(void)
470{
471 show_version();
472 fprintf(stderr,
473 "\n"
Sunil8cd6f4d2022-06-28 18:40:46 +0000474 "usage: hostapd [-hdBKtvq] [-P <PID file>] [-e <entropy file>] "
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700475 "\\\n"
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700476 " [-g <global ctrl_iface>] [-G <group>]\\\n"
477 " [-i <comma-separated list of interface names>]\\\n"
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700478 " <configuration file(s)>\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479 "\n"
480 "options:\n"
481 " -h show this usage\n"
482 " -d show more debug messages (-dd for even more)\n"
483 " -B run daemon in the background\n"
Jouni Malinen75ecf522011-06-27 15:19:46 -0700484 " -e entropy file\n"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700485 " -g global control interface path\n"
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700486 " -G group for control interfaces\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487 " -P PID file\n"
488 " -K include key data in debug messages\n"
489#ifdef CONFIG_DEBUG_FILE
490 " -f log output to debug file instead of stdout\n"
491#endif /* CONFIG_DEBUG_FILE */
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800492#ifdef CONFIG_DEBUG_LINUX_TRACING
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800493 " -T record to Linux tracing in addition to logging\n"
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800494 " (records all messages regardless of debug verbosity)\n"
495#endif /* CONFIG_DEBUG_LINUX_TRACING */
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700496 " -i list of interface names to use\n"
Paul Stewart092955c2017-02-06 09:13:09 -0800497#ifdef CONFIG_DEBUG_SYSLOG
498 " -s log output to syslog instead of stdout\n"
499#endif /* CONFIG_DEBUG_SYSLOG */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800500 " -S start all the interfaces synchronously\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 " -t include timestamps in some debug messages\n"
Sunil Ravi89eba102022-09-13 21:04:37 -0700502 " -v show hostapd version\n"
503 " -q show less debug messages (-qq for even less)\n");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504
505 exit(1);
506}
507
508
509static const char * hostapd_msg_ifname_cb(void *ctx)
510{
511 struct hostapd_data *hapd = ctx;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800512 if (hapd && hapd->conf)
513 return hapd->conf->iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 return NULL;
515}
516
517
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700518static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces,
519 const char *path)
520{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800521#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700522 char *pos;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800523#endif /* !CONFIG_CTRL_IFACE_UDP */
524
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700525 os_free(interfaces->global_iface_path);
526 interfaces->global_iface_path = os_strdup(path);
527 if (interfaces->global_iface_path == NULL)
528 return -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800529
530#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700531 pos = os_strrchr(interfaces->global_iface_path, '/');
532 if (pos == NULL) {
Dmitry Shmidt1e78e762013-04-02 11:05:36 -0700533 wpa_printf(MSG_ERROR, "No '/' in the global control interface "
534 "file");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700535 os_free(interfaces->global_iface_path);
536 interfaces->global_iface_path = NULL;
537 return -1;
538 }
539
540 *pos = '\0';
541 interfaces->global_iface_name = pos + 1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800542#endif /* !CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700543
544 return 0;
545}
546
547
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700548static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces,
549 const char *group)
550{
551#ifndef CONFIG_NATIVE_WINDOWS
552 struct group *grp;
553 grp = getgrnam(group);
554 if (grp == NULL) {
555 wpa_printf(MSG_ERROR, "Unknown group '%s'", group);
556 return -1;
557 }
558 interfaces->ctrl_iface_group = grp->gr_gid;
559#endif /* CONFIG_NATIVE_WINDOWS */
560 return 0;
561}
562
563
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700564static int hostapd_get_interface_names(char ***if_names,
565 size_t *if_names_size,
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800566 char *arg)
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700567{
568 char *if_name, *tmp, **nnames;
569 size_t i;
570
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800571 if (!arg)
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700572 return -1;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800573 if_name = strtok_r(arg, ",", &tmp);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700574
575 while (if_name) {
576 nnames = os_realloc_array(*if_names, 1 + *if_names_size,
577 sizeof(char *));
578 if (!nnames)
579 goto fail;
580 *if_names = nnames;
581
582 (*if_names)[*if_names_size] = os_strdup(if_name);
583 if (!(*if_names)[*if_names_size])
584 goto fail;
585 (*if_names_size)++;
586 if_name = strtok_r(NULL, ",", &tmp);
587 }
588
589 return 0;
590
591fail:
592 for (i = 0; i < *if_names_size; i++)
593 os_free((*if_names)[i]);
594 os_free(*if_names);
595 *if_names = NULL;
596 *if_names_size = 0;
597 return -1;
598}
599
600
Dmitry Shmidt96be6222014-02-13 10:16:51 -0800601#ifdef CONFIG_WPS
602static int gen_uuid(const char *txt_addr)
603{
604 u8 addr[ETH_ALEN];
605 u8 uuid[UUID_LEN];
606 char buf[100];
607
608 if (hwaddr_aton(txt_addr, addr) < 0)
609 return -1;
610
611 uuid_gen_mac_addr(addr, uuid);
612 if (uuid_bin2str(uuid, buf, sizeof(buf)) < 0)
613 return -1;
614
615 printf("%s\n", buf);
616
617 return 0;
618}
619#endif /* CONFIG_WPS */
620
621
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800622#ifndef HOSTAPD_CLEANUP_INTERVAL
623#define HOSTAPD_CLEANUP_INTERVAL 10
624#endif /* HOSTAPD_CLEANUP_INTERVAL */
625
626static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx)
627{
628 hostapd_periodic_iface(iface);
629 return 0;
630}
631
632
633/* Periodic cleanup tasks */
634static void hostapd_periodic(void *eloop_ctx, void *timeout_ctx)
635{
636 struct hapd_interfaces *interfaces = eloop_ctx;
637
638 eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0,
639 hostapd_periodic, interfaces, NULL);
640 hostapd_for_each_interface(interfaces, hostapd_periodic_call, NULL);
641}
642
643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644int main(int argc, char *argv[])
645{
646 struct hapd_interfaces interfaces;
647 int ret = 1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800648 size_t i, j;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 int c, debug = 0, daemonize = 0;
650 char *pid_file = NULL;
651 const char *log_file = NULL;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700652 const char *entropy_file = NULL;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800653 char **bss_config = NULL, **tmp_bss;
654 size_t num_bss_configs = 0;
655#ifdef CONFIG_DEBUG_LINUX_TRACING
656 int enable_trace_dbg = 0;
657#endif /* CONFIG_DEBUG_LINUX_TRACING */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800658 int start_ifaces_in_sync = 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700659 char **if_names = NULL;
660 size_t if_names_size = 0;
Hai Shalom81f62d82019-07-22 12:10:00 -0700661#ifdef CONFIG_DPP
662 struct dpp_global_config dpp_conf;
663#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664
665 if (os_program_init())
666 return -1;
667
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700668 os_memset(&interfaces, 0, sizeof(interfaces));
669 interfaces.reload_config = hostapd_reload_config;
670 interfaces.config_read_cb = hostapd_config_read;
671 interfaces.for_each_interface = hostapd_for_each_interface;
672 interfaces.ctrl_iface_init = hostapd_ctrl_iface_init;
673 interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit;
674 interfaces.driver_init = hostapd_driver_init;
675 interfaces.global_iface_path = NULL;
676 interfaces.global_iface_name = NULL;
677 interfaces.global_ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800678 dl_list_init(&interfaces.global_ctrl_dst);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700679#ifdef CONFIG_ETH_P_OUI
680 dl_list_init(&interfaces.eth_p_oui);
681#endif /* CONFIG_ETH_P_OUI */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700682#ifdef CONFIG_DPP
Hai Shalom81f62d82019-07-22 12:10:00 -0700683 os_memset(&dpp_conf, 0, sizeof(dpp_conf));
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700684 dpp_conf.cb_ctx = &interfaces;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700685#ifdef CONFIG_DPP2
686 dpp_conf.remove_bi = hostapd_dpp_remove_bi;
687#endif /* CONFIG_DPP2 */
Hai Shalom81f62d82019-07-22 12:10:00 -0700688 interfaces.dpp = dpp_global_init(&dpp_conf);
Hai Shalom021b0b52019-04-10 11:17:58 -0700689 if (!interfaces.dpp)
690 return -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700691#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700692
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 for (;;) {
Sunil8cd6f4d2022-06-28 18:40:46 +0000694 c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:vg:G:q");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 if (c < 0)
696 break;
697 switch (c) {
698 case 'h':
699 usage();
700 break;
701 case 'd':
702 debug++;
703 if (wpa_debug_level > 0)
704 wpa_debug_level--;
705 break;
706 case 'B':
707 daemonize++;
708 break;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700709 case 'e':
710 entropy_file = optarg;
711 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 case 'f':
713 log_file = optarg;
714 break;
715 case 'K':
716 wpa_debug_show_keys++;
717 break;
718 case 'P':
719 os_free(pid_file);
720 pid_file = os_rel2abs_path(optarg);
721 break;
722 case 't':
723 wpa_debug_timestamp++;
724 break;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800725#ifdef CONFIG_DEBUG_LINUX_TRACING
726 case 'T':
727 enable_trace_dbg = 1;
728 break;
729#endif /* CONFIG_DEBUG_LINUX_TRACING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 case 'v':
731 show_version();
732 exit(1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700733 case 'g':
Dmitry Shmidt1e78e762013-04-02 11:05:36 -0700734 if (hostapd_get_global_ctrl_iface(&interfaces, optarg))
735 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700736 break;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700737 case 'G':
Dmitry Shmidt1e78e762013-04-02 11:05:36 -0700738 if (hostapd_get_ctrl_iface_group(&interfaces, optarg))
739 return -1;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700740 break;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800741 case 'b':
742 tmp_bss = os_realloc_array(bss_config,
743 num_bss_configs + 1,
744 sizeof(char *));
745 if (tmp_bss == NULL)
746 goto out;
747 bss_config = tmp_bss;
748 bss_config[num_bss_configs++] = optarg;
749 break;
Paul Stewart092955c2017-02-06 09:13:09 -0800750#ifdef CONFIG_DEBUG_SYSLOG
751 case 's':
752 wpa_debug_syslog = 1;
753 break;
754#endif /* CONFIG_DEBUG_SYSLOG */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800755 case 'S':
756 start_ifaces_in_sync = 1;
757 break;
Dmitry Shmidt96be6222014-02-13 10:16:51 -0800758#ifdef CONFIG_WPS
759 case 'u':
760 return gen_uuid(optarg);
761#endif /* CONFIG_WPS */
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700762 case 'i':
763 if (hostapd_get_interface_names(&if_names,
764 &if_names_size, optarg))
765 goto out;
766 break;
Sunil8cd6f4d2022-06-28 18:40:46 +0000767 case 'q':
768 wpa_debug_level++;
769 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 default:
771 usage();
772 break;
773 }
774 }
775
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000776#ifndef CONFIG_CTRL_IFACE_AIDL
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800777 if (optind == argc && interfaces.global_iface_path == NULL &&
778 num_bss_configs == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779 usage();
Roshan Piuscc817562017-12-22 14:45:05 -0800780#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781
782 wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb);
783
784 if (log_file)
785 wpa_debug_open_file(log_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700786 if (!log_file && !wpa_debug_syslog)
Dmitry Shmidtfb45fd52015-01-05 13:08:17 -0800787 wpa_debug_setup_stdout();
Paul Stewart092955c2017-02-06 09:13:09 -0800788#ifdef CONFIG_DEBUG_SYSLOG
789 if (wpa_debug_syslog)
790 wpa_debug_open_syslog();
791#endif /* CONFIG_DEBUG_SYSLOG */
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800792#ifdef CONFIG_DEBUG_LINUX_TRACING
793 if (enable_trace_dbg) {
794 int tret = wpa_debug_open_linux_tracing();
795 if (tret) {
796 wpa_printf(MSG_ERROR, "Failed to enable trace logging");
797 return -1;
798 }
799 }
800#endif /* CONFIG_DEBUG_LINUX_TRACING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801
802 interfaces.count = argc - optind;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800803 if (interfaces.count || num_bss_configs) {
804 interfaces.iface = os_calloc(interfaces.count + num_bss_configs,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700805 sizeof(struct hostapd_iface *));
806 if (interfaces.iface == NULL) {
807 wpa_printf(MSG_ERROR, "malloc failed");
808 return -1;
809 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 }
811
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700812 if (hostapd_global_init(&interfaces, entropy_file)) {
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -0700813 wpa_printf(MSG_ERROR, "Failed to initialize global context");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700814 return -1;
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700815 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800817 eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0,
818 hostapd_periodic, &interfaces, NULL);
819
820 if (fst_global_init()) {
821 wpa_printf(MSG_ERROR,
822 "Failed to initialize global FST context");
823 goto out;
824 }
825
826#if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE)
827 if (!fst_global_add_ctrl(fst_ctrl_cli))
828 wpa_printf(MSG_WARNING, "Failed to add CLI FST ctrl");
829#endif /* CONFIG_FST && CONFIG_CTRL_IFACE */
830
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800831 /* Allocate and parse configuration for full interface files */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 for (i = 0; i < interfaces.count; i++) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700833 char *if_name = NULL;
834
835 if (i < if_names_size)
836 if_name = if_names[i];
837
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 interfaces.iface[i] = hostapd_interface_init(&interfaces,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700839 if_name,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840 argv[optind + i],
841 debug);
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700842 if (!interfaces.iface[i]) {
843 wpa_printf(MSG_ERROR, "Failed to initialize interface");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 goto out;
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700845 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800846 if (start_ifaces_in_sync)
847 interfaces.iface[i]->need_to_start_in_sync = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848 }
849
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800850 /* Allocate and parse configuration for per-BSS files */
851 for (i = 0; i < num_bss_configs; i++) {
852 struct hostapd_iface *iface;
853 char *fname;
854
855 wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]);
856 fname = os_strchr(bss_config[i], ':');
857 if (fname == NULL) {
858 wpa_printf(MSG_ERROR,
859 "Invalid BSS config identifier '%s'",
860 bss_config[i]);
861 goto out;
862 }
863 *fname++ = '\0';
864 iface = hostapd_interface_init_bss(&interfaces, bss_config[i],
865 fname, debug);
866 if (iface == NULL)
867 goto out;
868 for (j = 0; j < interfaces.count; j++) {
869 if (interfaces.iface[j] == iface)
870 break;
871 }
872 if (j == interfaces.count) {
873 struct hostapd_iface **tmp;
874 tmp = os_realloc_array(interfaces.iface,
875 interfaces.count + 1,
876 sizeof(struct hostapd_iface *));
877 if (tmp == NULL) {
878 hostapd_interface_deinit_free(iface);
879 goto out;
880 }
881 interfaces.iface = tmp;
882 interfaces.iface[interfaces.count++] = iface;
883 }
884 }
885
886 /*
887 * Enable configured interfaces. Depending on channel configuration,
888 * this may complete full initialization before returning or use a
889 * callback mechanism to complete setup in case of operations like HT
890 * co-ex scans, ACS, or DFS are needed to determine channel parameters.
891 * In such case, the interface will be enabled from eloop context within
892 * hostapd_global_run().
893 */
Dmitry Shmidtb96dad42013-11-05 10:07:29 -0800894 interfaces.terminate_on_error = interfaces.count;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800895 for (i = 0; i < interfaces.count; i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -0800896 if (hostapd_driver_init(interfaces.iface[i]) ||
897 hostapd_setup_interface(interfaces.iface[i]))
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800898 goto out;
899 }
900
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000901#ifdef CONFIG_CTRL_IFACE_AIDL
902 if (hostapd_aidl_init(&interfaces)) {
903 wpa_printf(MSG_ERROR, "Failed to initialize AIDL interface");
Roshan Piuscc817562017-12-22 14:45:05 -0800904 goto out;
905 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000906#endif /* CONFIG_CTRL_IFACE_AIDL */
Daichi Ueuracaa74a82018-02-14 22:25:39 +0900907 hostapd_global_ctrl_iface_init(&interfaces);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700908
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700909 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
910 wpa_printf(MSG_ERROR, "Failed to start eloop");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700911 goto out;
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700912 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913
914 ret = 0;
915
916 out:
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000917#ifdef CONFIG_CTRL_IFACE_AIDL
918 hostapd_aidl_deinit(&interfaces);
919#endif /* CONFIG_CTRL_IFACE_AIDL */
Daichi Ueuracaa74a82018-02-14 22:25:39 +0900920 hostapd_global_ctrl_iface_deinit(&interfaces);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700921 /* Deinitialize all interfaces */
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800922 for (i = 0; i < interfaces.count; i++) {
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700923 if (!interfaces.iface[i])
924 continue;
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800925 interfaces.iface[i]->driver_ap_teardown =
926 !!(interfaces.iface[i]->drv_flags &
927 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 hostapd_interface_deinit_free(interfaces.iface[i]);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700929 interfaces.iface[i] = NULL;
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800930 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 os_free(interfaces.iface);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700932 interfaces.iface = NULL;
933 interfaces.count = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934
Roshan Pius3a1667e2018-07-03 15:17:14 -0700935#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -0700936 dpp_global_deinit(interfaces.dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700937#endif /* CONFIG_DPP */
938
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700939 if (interfaces.eloop_initialized)
940 eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL);
941 hostapd_global_deinit(pid_file, interfaces.eloop_initialized);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700942 os_free(pid_file);
943
Paul Stewart092955c2017-02-06 09:13:09 -0800944 wpa_debug_close_syslog();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700945 if (log_file)
946 wpa_debug_close_file();
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800947 wpa_debug_close_linux_tracing();
948
949 os_free(bss_config);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700951 for (i = 0; i < if_names_size; i++)
952 os_free(if_names[i]);
953 os_free(if_names);
954
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800955 fst_global_deinit();
956
Sunil Ravia04bd252022-05-02 22:54:18 -0700957 crypto_unload();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 os_program_deinit();
959
960 return ret;
961}