Skip to content

Commit

Permalink
samples: wifi: raw_tx_packet: Add iface operational up check
Browse files Browse the repository at this point in the history
Check iface operational up status before proceeding,
ensuring proper Wi-Fi operation.

Signed-off-by: Triveni Danda <[email protected]>
  • Loading branch information
D-Triveni authored and nordicjm committed Feb 26, 2025
1 parent 5401321 commit 9d3c664
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions samples/wifi/raw_tx_packet/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,10 @@ config RAW_TX_PKT_SAMPLE_INTER_FRAME_DELAY_MS
help
Specify the inter-frame delay duration for raw TX packet transmission.

config RAW_TX_PKT_SAMPLE_WIFI_IFACE_OPER_UP_TIMEOUT_S
int "Timeout for checking interface operational up status (seconds)"
default 10 if RAW_TX_PKT_SAMPLE_NON_CONNECTED_MODE
default 40 if RAW_TX_PKT_SAMPLE_CONNECTION_MODE
help
specify the timeout (seconds) for checking if the Wi-Fi interface is operationally up.
endmenu
27 changes: 27 additions & 0 deletions samples/wifi/raw_tx_packet/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ LOG_MODULE_REGISTER(raw_tx_packet, CONFIG_LOG_DEFAULT_LEVEL);
#define IEEE80211_SEQ_NUMBER_INC BIT(4) /* 0-3 is fragment number */
#define NRF_WIFI_MAGIC_NUM_RAWTX 0x12345678

static struct net_mgmt_event_callback net_iface_mgmt_cb;
K_SEM_DEFINE(wait_for_oper_up, 0, 1);

struct beacon {
uint16_t frame_control;
uint16_t duration;
Expand Down Expand Up @@ -310,10 +313,28 @@ static void wifi_send_raw_tx_packets(void)
free(test_frame);
}

/* Net iface events handler */
static void net_events_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
switch (mgmt_event) {
case NET_EVENT_IF_UP:
LOG_DBG("Interface is up");
k_sem_give(&wait_for_oper_up);
break;
default:
break;
}
}

int main(void)
{
int mode;

net_mgmt_init_event_callback(&net_iface_mgmt_cb, net_events_handler,
NET_EVENT_IF_UP);
net_mgmt_add_event_callback(&net_iface_mgmt_cb);

mode = BIT(0);
/* This is to set mode to STATION */
wifi_set_mode(mode);
Expand All @@ -334,6 +355,12 @@ int main(void)
#else
wifi_set_channel();
#endif
if (k_sem_take(&wait_for_oper_up,
K_SECONDS(CONFIG_RAW_TX_PKT_SAMPLE_WIFI_IFACE_OPER_UP_TIMEOUT_S)) != 0) {
LOG_ERR("Timeout waiting for iface to become operational after %d seconds",
CONFIG_RAW_TX_PKT_SAMPLE_WIFI_IFACE_OPER_UP_TIMEOUT_S);
}

wifi_send_raw_tx_packets();

return 0;
Expand Down

0 comments on commit 9d3c664

Please sign in to comment.