Skip to content

Commit

Permalink
modules: hostap: Create z_wpa_s_tid thread dynamically
Browse files Browse the repository at this point in the history
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 <robert.lubos@nordicsemi.no>
  • Loading branch information
rlubos committed Aug 3, 2023
1 parent fb9fbce commit d02e160
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions modules/hostap/src/supp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

0 comments on commit d02e160

Please sign in to comment.