Skip to content

Commit 7bdeeea

Browse files
committed
wfa-qt-control-app: Handle supplicant event
Implement imperative check for supplicant readiness prior to QT thread initiation. Signed-off-by: Triveni Danda <triveni.danda@nordicsemi.no>
1 parent f27b635 commit 7bdeeea

File tree

4 files changed

+104
-8
lines changed

4 files changed

+104
-8
lines changed

zephyr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ zephyr_include_directories(
3232

3333
zephyr_library_sources(
3434
# Zephyr's port of the Indigo API
35+
${SOURCES_BASE}/zephyr/src/wpas_events.c
3536
${SOURCES_BASE}/zephyr/src/main.c
3637
${SOURCES_BASE}/zephyr/src/indigo_api_callback_dut.c
3738
${SOURCES_BASE}/zephyr/src/vendor_specific_dut.c

zephyr/Kconfig

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ module-help = Sets log level for WFA Quick Track
1010
source "subsys/logging/Kconfig.template.log_config"
1111

1212
config WFA_QT_CONTROL_APP
13-
# Need full POSIX from libc, Zephyr's POSIX support is only partial
14-
depends on !POSIX_API
15-
select PTHREAD_IPC
16-
bool "WFA Quicktrack control app"
13+
# Need full POSIX from libc, Zephyr's POSIX support is only partial
14+
depends on !POSIX_API
15+
select PTHREAD_IPC
16+
bool "WFA Quicktrack control app"
1717

1818
config WFA_QT_THREAD_STACK_SIZE
19-
int "WFA QT thread stack size"
20-
default 4096
21-
help
22-
Set the stack size for WFA QT thread.
19+
int "WFA QT thread stack size"
20+
default 4096
21+
help
22+
Set the stack size for WFA QT thread.
23+
24+
config WPAS_READY_TIMEOUT_MS
25+
int "WPA supplicant ready timeout (ms)"
26+
default 10000
27+
help
28+
Set the timeout for WPA supplicant to be ready.

zephyr/src/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
LOG_MODULE_REGISTER(wfa_qt, CONFIG_WFA_QT_LOG_LEVEL);
2020
int control_socket_init(int port);
2121
void qt_main(void);
22+
int wpa_supp_events_register(void);
23+
int wait_for_wpa_s_ready(void);
2224
K_THREAD_DEFINE(qt_main_tid,
2325
CONFIG_WFA_QT_THREAD_STACK_SIZE,
2426
qt_main,
@@ -36,6 +38,13 @@ static void print_welcome() {
3638

3739
void qt_main(void) {
3840
int service_socket = -1;
41+
int ret;
42+
43+
ret = wpa_supp_events_register();
44+
ret = wait_for_wpa_s_ready();
45+
if (ret < 0) {
46+
LOG_DBG("Control interface is not initialized");
47+
}
3948

4049
/* Welcome message */
4150
print_welcome();

zephyr/src/wpas_events.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/** @file
8+
* @brief WPA SUPP events
9+
*/
10+
11+
#include <stdio.h>
12+
#include <zephyr/net/net_event.h>
13+
#include <ctrl_iface_zephyr.h>
14+
#include <supp_events.h>
15+
#include <utils.h>
16+
#include <supp_main.h>
17+
#include <zephyr/logging/log.h>
18+
#include <zephyr/kernel.h>
19+
LOG_MODULE_REGISTER(wpas_event, CONFIG_WFA_QT_LOG_LEVEL);
20+
21+
#define WPA_SUPP_EVENTS (NET_EVENT_WPA_SUPP_READY)
22+
23+
static struct net_mgmt_event_callback net_wpa_supp_cb;
24+
25+
K_SEM_DEFINE(wpa_supp_ready_sem, 0, 1);
26+
27+
#define DEFAULT_WIFI_IFACE "wlan0"
28+
29+
static void handle_wpa_supp_ready(struct net_mgmt_event_callback *cb)
30+
{
31+
k_sem_give(&wpa_supp_ready_sem);
32+
}
33+
34+
static void wpa_supp_event_handler(struct net_mgmt_event_callback *cb,
35+
uint32_t mgmt_event, struct net_if *iface)
36+
{
37+
/* TODO: Handle other events */
38+
switch (mgmt_event) {
39+
case NET_EVENT_WPA_SUPP_READY:
40+
handle_wpa_supp_ready(cb);
41+
break;
42+
default:
43+
LOG_DBG("Unhandled event (%d)", mgmt_event);
44+
break;
45+
}
46+
}
47+
48+
int wait_for_wpa_s_ready(void)
49+
{
50+
struct wpa_supplicant *wpa_s = z_wpas_get_handle_by_ifname(DEFAULT_WIFI_IFACE);
51+
52+
if (wpa_s) {
53+
LOG_INF("Supplicant is ready");
54+
return 0;
55+
}
56+
57+
k_sem_take(&wpa_supp_ready_sem, K_MSEC(CONFIG_WPAS_READY_TIMEOUT_MS));
58+
59+
wpa_s = z_wpas_get_handle_by_ifname(DEFAULT_WIFI_IFACE);
60+
if (!wpa_s) {
61+
LOG_INF("Supplicant is not ready");
62+
return -1;
63+
}
64+
65+
/* Belts and braces: Check for ctrl_iface initialization */
66+
if (wpa_s->ctrl_iface->sock_pair[0] < 0) {
67+
LOG_INF("Control iface is not ready");
68+
return -1;
69+
}
70+
71+
return 0;
72+
}
73+
74+
int wpa_supp_events_register(void)
75+
{
76+
net_mgmt_init_event_callback(&net_wpa_supp_cb, wpa_supp_event_handler, WPA_SUPP_EVENTS);
77+
net_mgmt_add_event_callback(&net_wpa_supp_cb);
78+
79+
return 0;
80+
}

0 commit comments

Comments
 (0)