Skip to content

Commit

Permalink
samples: wifi: wfa-qt: Add supplicant events
Browse files Browse the repository at this point in the history
Add changes to handle supplicant events.

Signed-off-by: Triveni Danda <[email protected]>
  • Loading branch information
D-Triveni committed Feb 26, 2024
1 parent 87355af commit 87bc1ba
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
6 changes: 5 additions & 1 deletion samples/wifi/wfa_qt_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(nrf_wfa_qt_app)

target_sources(app PRIVATE src/qt_app_main.c)
target_compile_definitions(app PRIVATE -DCONFIG_CTRL_IFACE_ZEPHYR=y)
target_sources(app PRIVATE

Check failure on line 13 in samples/wifi/wfa_qt_app/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

TRAILING_WHITESPACE

samples/wifi/wfa_qt_app/CMakeLists.txt:13 trailing whitespace
src/events.c
src/qt_app_main.c)

89 changes: 89 additions & 0 deletions samples/wifi/wfa_qt_app/src/events.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/** @file
* @brief WPA SUPP events
*/

#include <stdio.h>
#include <zephyr/net/net_event.h>
#include <ctrl_iface_zephyr.h>
#include <supp_events.h>
#include <utils.h>
#include <supp_main.h>

#define WPA_SUPP_EVENTS (NET_EVENT_WPA_SUPP_READY | \
NET_EVENT_WPA_SUPP_NOT_READY | \
NET_EVENT_WPA_SUPP_IFACE_ADDED | \
NET_EVENT_WPA_SUPP_CMD_IFACE_REMOVING | \
NET_EVENT_WPA_SUPP_CMD_IFACE_REMOVED)

static struct net_mgmt_event_callback net_wpa_supp_cb;
struct wpa_supplicant *wpa_s = NULL;

Check failure on line 25 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

GLOBAL_INITIALISERS

samples/wifi/wfa_qt_app/src/events.c:25 do not initialise globals to NULL

K_SEM_DEFINE(wpa_supp_ready_sem, 0, 1);

static void handle_wpa_supp_ready(struct net_mgmt_event_callback *cb)
{
int retry_count = 0;
retry:
wpa_s = z_wpas_get_handle_by_ifname("wlan0");
if (!wpa_s && retry_count++ < 5) {
printf("%s: Unable to get wpa_s handle for %s\n",
__func__, "wlan0");
goto retry;
}

if (!wpa_s) {
printf("%s: Unable to get wpa_s handle for %s\n",
__func__, "wlan0");
}

k_sem_give(&wpa_supp_ready_sem);

}

static void wpa_supp_event_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)

Check failure on line 50 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:50 code indent should use tabs where possible

Check warning on line 50 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:50 please, no spaces at the start of a line
{
switch (mgmt_event) {

Check failure on line 52 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:52 code indent should use tabs where possible

Check warning on line 52 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:52 please, no spaces at the start of a line
case NET_EVENT_WPA_SUPP_READY:

Check failure on line 53 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:53 code indent should use tabs where possible

Check warning on line 53 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:53 please, no spaces at the start of a line
printf("Supplicant is ready");
handle_wpa_supp_ready(cb);
break;

Check failure on line 56 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:56 code indent should use tabs where possible

Check warning on line 56 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:56 please, no spaces at the start of a line
case NET_EVENT_WPA_SUPP_NOT_READY:
printf("Supplicant is not ready");
break;

Check failure on line 59 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:59 code indent should use tabs where possible

Check warning on line 59 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:59 please, no spaces at the start of a line
case NET_EVENT_WPA_SUPP_IFACE_ADDED:
printf("Interface added");
break;

Check failure on line 62 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:62 code indent should use tabs where possible

Check warning on line 62 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:62 please, no spaces at the start of a line
case NET_EVENT_WPA_SUPP_CMD_IFACE_REMOVING:
printf("Interface is removing");
break;

Check failure on line 65 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:65 code indent should use tabs where possible

Check warning on line 65 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:65 please, no spaces at the start of a line
case NET_EVENT_WPA_SUPP_CMD_IFACE_REMOVED:
printf("Interface removed");
break;

Check failure on line 68 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/wifi/wfa_qt_app/src/events.c:68 code indent should use tabs where possible

Check warning on line 68 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:68 please, no spaces at the start of a line
default:
break;

Check warning on line 70 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:70 please, no spaces at the start of a line
}

Check warning on line 71 in samples/wifi/wfa_qt_app/src/events.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/wifi/wfa_qt_app/src/events.c:71 please, no spaces at the start of a line
}

int wpa_supp_events_init(void)
{
net_mgmt_init_event_callback(&net_wpa_supp_cb,
wpa_supp_event_handler,
WPA_SUPP_EVENTS);
net_mgmt_add_event_callback(&net_wpa_supp_cb);

k_sem_take(&wpa_supp_ready_sem, K_FOREVER);

/* Check for ctrl_iface initialization */
if (wpa_s->ctrl_iface->sock_pair[0] < 0) {
return -1;
}

return 0;
}
7 changes: 7 additions & 0 deletions samples/wifi/wfa_qt_app/src/qt_app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ int init_usb(void)
}
#endif /* CONFIG_USB_DEVICE_STACK */

int check_events(void);

int main(void)
{
struct in_addr addr;
int ret;

#if defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT) || NRF_CLOCK_HAS_HFCLK192M
/* For now hardcode to 128MHz */
Expand Down Expand Up @@ -133,6 +136,10 @@ int main(void)

net_config_init_app(dev, "Initializing network");
#endif
ret = wpa_supp_events_init();
if (ret) {
return -1;
}

return 0;
}

0 comments on commit 87bc1ba

Please sign in to comment.