From d02e1604040d2cbe31edb7a5e12a19bc35524b40 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 1 Aug 2023 15:14:57 +0200 Subject: [PATCH] modules: hostap: Create z_wpa_s_tid thread dynamically Statically created threads with K_THREAD_DEFINE() are launched after the SYS_INIT phase. This does not play well wth NET_CONFIG library, which may block during SYS_INIT until network interface is UP and RUNNING. In order to be able to connect to Wi-Fi network and thus mark the network interface as running, we need to be able to run supplicant during SYS_INIT. This can be achieved, by starting the thread dynamically during SYS_INIT phase, instead of relying on static thread creation. Signed-off-by: Robert Lubos --- modules/hostap/src/supp_main.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index f36e9036386c..e003a4d788e9 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -56,15 +56,9 @@ static int z_wpas_event_sockpair[2]; static void z_wpas_start(void); static void z_wpas_iface_work_handler(struct k_work *item); -K_THREAD_DEFINE(z_wpa_s_tid, - CONFIG_WPA_SUPP_THREAD_STACK_SIZE, - z_wpas_start, - NULL, - NULL, - NULL, - 0, - 0, - 0); +static K_THREAD_STACK_DEFINE(z_wpa_s_thread_stack, + CONFIG_WPA_SUPP_THREAD_STACK_SIZE); +static struct k_thread z_wpa_s_tid; static K_THREAD_STACK_DEFINE(z_wpas_iface_wq_stack, CONFIG_WPA_SUPP_IFACE_WQ_STACK_SIZE); @@ -541,3 +535,16 @@ static void z_wpas_start(void) wpa_printf(MSG_INFO, "z_wpas_start: exitcode %d", exitcode); } + +static int z_wpas_init(void) +{ + k_thread_create(&z_wpa_s_tid, z_wpa_s_thread_stack, + CONFIG_WPA_SUPP_THREAD_STACK_SIZE, + (k_thread_entry_t)z_wpas_start, + NULL, NULL, NULL, + 0, 0, K_NO_WAIT); + + return 0; +} + +SYS_INIT(z_wpas_init, APPLICATION, 0);