Skip to content

Commit

Permalink
samples: wifi: Add Wi-Fi and Thread coexistence sample
Browse files Browse the repository at this point in the history
Initial version of the Wi-Fi and Thread coexistence sample.

This sample is to run Wi-Fi and Thread throughputs simultaneously
to show how they coexist.

Wi-Fi in station mode connects to Wi-Fi AP and runs Zperf.
Thread in child mode connects to leader and runs Zperf.

Signed-off-by: Murali Thokala <[email protected]>
  • Loading branch information
muraliThokala committed May 17, 2024
1 parent f8b6fea commit 7fdac70
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 84 deletions.
Empty file modified samples/wifi/thread_coex/CMakeLists.txt
100755 → 100644
Empty file.
Empty file modified samples/wifi/thread_coex/Kconfig
100755 → 100644
Empty file.
11 changes: 7 additions & 4 deletions samples/wifi/thread_coex/README.rst
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ To enable different test modes, set up the following configuration parameters in

* Wi-Fi connection: Set the following options appropriately as per the credentials of the access point used for this testing:

* :ref:`CONFIG_STA_SSID <CONFIG_STA_SSID>`
* :ref:`CONFIG_STA_PASSWORD <CONFIG_STA_PASSWORD>`
* :ref:`CONFIG_STA_KEY_MGMT_* <CONFIG_STA_KEY_MGMT_*>`
* :ref:`CONFIG_WIFI_CREDENTIALS_STATIC_SSID <CONFIG_WIFI_CREDENTIALS_STATIC_SSID>`
* :ref:`CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD <CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD>`
* :ref:`CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_OPEN <CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_OPEN>`
* :ref:`CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_PSK <CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_PSK>`
* :ref:`CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_PSK_SHA256 <CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_PSK_SHA256>`


* Wi-Fi throughput test: Set the following option appropriately as per the IP address of the test PC on which iperf is run:
* :kconfig:option:`CONFIG_NET_CONFIG_PEER_IPV4_ADDR`
Expand Down Expand Up @@ -310,7 +313,7 @@ Results

The following tables collect a summary of results obtained when coexistence tests are run for different Wi-Fi operating bands with
Wi-Fi and Thread data rates set to 10Mbps and 65kbps respectively.
The results are representative and might change based on the RSSI and the level of external interference.
The tests are run with the test setup inside an RF shield box. Therefore, the results are representative and might change with adjustments in the test setup.

Wi-Fi in 2.4 GHz
----------------
Expand Down
Empty file modified samples/wifi/thread_coex/child_image/802154_rpmsg.conf
100755 → 100644
Empty file.
Empty file modified samples/wifi/thread_coex/dts.overlay
100755 → 100644
Empty file.
1 change: 0 additions & 1 deletion samples/wifi/thread_coex/overlay-logging.conf
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ CONFIG_LOG_BACKEND_RTT=y
# Disable UART logging backend
# CONFIG_LOG_BACKEND_UART=n
CONFIG_SHELL_LOG_BACKEND=n

Empty file modified samples/wifi/thread_coex/overlay-openthread.conf
100755 → 100644
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion samples/wifi/thread_coex/prj.conf
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CONFIG_NET_BUF_DATA_SIZE=1100
CONFIG_WIFI_MGMT_EXT=y
CONFIG_WIFI_CREDENTIALS=y
CONFIG_WIFI_CREDENTIALS_STATIC=y
CONFIG_WIFI_CREDENTIALS_STATIC_SSID="wifi_sr_coex_5"
CONFIG_WIFI_CREDENTIALS_STATIC_SSID="wifi_sr_coex_24"
CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="Mypassword"
CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_OPEN=y

Expand Down
2 changes: 1 addition & 1 deletion samples/wifi/thread_coex/sample.yaml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tests:
CONFIG_MPSL_CX=y 802154_rpmsg_CONFIG_MPSL_CX=y
CONFIG_COEX_SEP_ANTENNAS=y OVERLAY_CONFIG="overlay-openthread.conf overlay-wifi-udp-client-thread-udp-client.conf"
platform_allow: nrf5340dk/nrf5340/cpuapp

tags: ci_build
sample.nrf7002_eb.thingy53.thread_coex:
build_only: true
extra_args: SHIELD=nrf7002eb 802154_rpmsg_SHIELD=nrf7002eb_coex
Expand Down
Empty file modified samples/wifi/thread_coex/src/main.c
100755 → 100644
Empty file.
Empty file modified samples/wifi/thread_coex/src/main.h
100755 → 100644
Empty file.
27 changes: 14 additions & 13 deletions samples/wifi/thread_coex/src/ot_coex_functions.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ void tcp_download_results_cb(enum zperf_status status, struct zperf_results *res
}

LOG_INF("Wi-Fi: TCP session ended\n");
/* LOG_INF("%u bytes in %u ms:", result->total_len,
result->time_in_us/USEC_PER_MSEC); */
/** LOG_INF("%u bytes in %u ms:", result->total_len,
* result->time_in_us/USEC_PER_MSEC);
*/
LOG_INF("\nThroughput:%u kbps", rate_in_kbps);
LOG_INF("");
k_sem_give(&udp_tcp_callback);
Expand Down Expand Up @@ -515,10 +516,9 @@ int run_wifi_traffic_udp(bool is_wifi_server)
params.duration_ms = CONFIG_COEX_TEST_DURATION;
params.rate_kbps = CONFIG_WIFI_ZPERF_RATE;
params.packet_size = CONFIG_WIFI_ZPERF_PKT_SIZE;

parse_ipv4_addr(CONFIG_NET_CONFIG_PEER_IPV4_ADDR, &in4_addr_my);
net_sprint_ipv4_addr(&in4_addr_my.sin_addr);


memcpy(&params.peer_addr, &in4_addr_my, sizeof(in4_addr_my));
ret = zperf_udp_upload_async(&params, udp_upload_results_cb, NULL);
Expand All @@ -537,9 +537,9 @@ void check_wifi_traffic(void)
LOG_ERR("Wi-Fi: Results are not ready");
} else {
#ifdef CONFIG_WIFI_ZPERF_PROT_UDP
LOG_INF("Wi-Fi UDP session finished");
LOG_INF("Wi-Fi UDP session finished");
#else
LOG_INF("Wi-Fi TCP session finished");
LOG_INF("Wi-Fi TCP session finished");
#endif
}
}
Expand All @@ -554,7 +554,7 @@ int wifi_connection(void)
LOG_INF("Wi-Fi Connection timeout");
return -1;
}

if (wifi_wait_for_next_event("Wi-Fi DHCP", WIFI_DHCP_TIMEOUT_SEC)) {
LOG_INF("Wi-Fi DHCP timeout");
return -1;
Expand Down Expand Up @@ -736,31 +736,32 @@ int wifi_tput_ot_tput(bool test_wifi, bool is_ant_mode_sep, bool test_thread, bo
#endif/* CONFIG_NRF700X_SR_COEX */
}
if (test_thread) {
LOG_INF("Thread operating channel = %d",CONFIG_OT_CHANNEL);
LOG_INF("Thread operating channel = %d", CONFIG_OT_CHANNEL);
}
if (test_thread) {
if (!is_ot_client) {
LOG_INF("Make sure peer Thread role is client");
k_sleep(K_SECONDS(3));
}

ret = ot_throughput_test_init(is_ot_client, is_ot_zperf_udp);
k_sleep(K_SECONDS(3));
if (ret != 0) {
LOG_ERR("Thread throughput init failed: %d", ret);
return ret;
}
}

if (is_ot_client) {
/* nothing */
} else {
/* wait until the peer client joins the network */
uint32_t print_wait_on_ping_reply = 1;

while (ot_wait4_ping_reply_from_peer == 0) {
if (print_wait_on_ping_reply) {
LOG_INF("Waiting on ping reply from peer");
print_wait_on_ping_reply = 0 ;
}
print_wait_on_ping_reply = 0;
}
ot_get_peer_address(5000);
k_sleep(K_SECONDS(1));
if (ot_wait4_ping_reply_from_peer) {
Expand Down Expand Up @@ -854,7 +855,7 @@ int wifi_tput_ot_tput(bool test_wifi, bool is_ant_mode_sep, bool test_thread, bo
/* Get the current transmit power of OT device */
otPlatRadioGetTransmitPower(ot_instance, &ot_tx_power);
LOG_INF("OT device Tx power in dBm = %d", ot_tx_power);

/* The RSSI in dBm when it is valid. 127 when RSSI is invalid */
ot_rssi = otPlatRadioGetRssi(ot_instance);
LOG_INF("OT device RSSI in dBm = %d", ot_rssi);
Expand Down
3 changes: 1 addition & 2 deletions samples/wifi/thread_coex/src/ot_coex_functions.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LOG_MODULE_REGISTER(ot_coex_functions, CONFIG_LOG_DEFAULT_LEVEL);
#include "coex.h"
#include "coex_struct.h"
#include "fmac_main.h"
#include "ot_utils.h"
#include "ot_utils.h"

#define DEMARCATE_TEST_START

Expand All @@ -59,7 +59,6 @@ static struct {
K_SEM_DEFINE(wait_for_next, 0, 1);
K_SEM_DEFINE(udp_tcp_callback, 0, 1);


/**
* @brief configure PTA registers
*
Expand Down
54 changes: 33 additions & 21 deletions samples/wifi/thread_coex/src/ot_utils.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LOG_MODULE_REGISTER(ot_utils, CONFIG_LOG_DEFAULT_LEVEL);
#include <zephyr/console/console.h>
#include <zephyr/types.h>

#define WAIT_TIME_FOR_OT_CON K_SECONDS(4)
#define WAIT_TIME_FOR_OT_CON K_SECONDS(10)

typedef struct peer_address_info {
char address_string[OT_IP6_ADDRESS_STRING_SIZE];
Expand All @@ -35,17 +35,18 @@ extern bool is_ot_device_role_client;

static K_SEM_DEFINE(connected_sem, 0, 1);

static void ot_device_dettached(void) {
static void ot_device_dettached(void)
{
LOG_INF("\nOT device dettached gracefully\n");
}

static void ot_commissioner_state_changed(otCommissionerState aState, void *aContext)
{
LOG_INF("OT commissioner state changed");
if(aState == OT_COMMISSIONER_STATE_ACTIVE)
{
LOG_INF("ot commissioner joiner add * FEDCBA9876543210 2000");
otCommissionerAddJoiner(openthread_get_default_instance(), NULL, "FEDCBA9876543210",2000);
if (aState == OT_COMMISSIONER_STATE_ACTIVE) {
LOG_INF("ot commissioner joiner add * FEDCBA9876543210 2000");
otCommissionerAddJoiner(openthread_get_default_instance(), NULL,
"FEDCBA9876543210", 2000);
LOG_INF("\n\nRun thread application on client\n\n");
}
}
Expand All @@ -56,10 +57,12 @@ static void ot_thread_state_changed(otChangedFlags flags, struct openthread_cont
LOG_INF("OT device state changed");
if (flags & OT_CHANGED_THREAD_ROLE) {
otDeviceRole ot_role = otThreadGetDeviceRole(ot_context->instance);

if (ot_role != OT_DEVICE_ROLE_DETACHED && ot_role != OT_DEVICE_ROLE_DISABLED) {
/* ot commissioner start */
LOG_INF("ot commissioner start");
otCommissionerStart(ot_context->instance, &ot_commissioner_state_changed, NULL, NULL);
otCommissionerStart(ot_context->instance, &ot_commissioner_state_changed,
NULL, NULL);
}
}
}
Expand Down Expand Up @@ -87,9 +90,13 @@ static void ot_joiner_start_handler(otError error, void *context)
int ot_throughput_client_init(void)
{
otError err = 0;

ot_start_joiner("FEDCBA9876543210");
k_sleep(K_SECONDS(2));
/* k_sleep(K_SECONDS(2)); */
/* Note: current value of WAIT_TIME_FOR_OT_CON = 4sec.
* Sometimes, starting openthread happening before
* the thread join failed.So, increase it to 10sec.
*/
err = k_sem_take(&connected_sem, WAIT_TIME_FOR_OT_CON);

LOG_INF("Starting openthread.");
Expand All @@ -112,15 +119,15 @@ int ot_throughput_client_init(void)
current_role = otThreadGetDeviceRole(openthread_get_default_instance());
openthread_api_mutex_unlock(openthread_get_default_context());
}

ot_get_peer_address(5000);
if (!peer_address_info.address_found) {
LOG_WRN("Peer address not found. Not continuing with zperf test.");
return -1;
}
return 0;
}

int ot_throughput_test_run(bool is_ot_zperf_udp)
{
if (is_ot_device_role_client) {
Expand All @@ -142,7 +149,7 @@ void ot_start_joiner(const char *pskd)
/** Step1: Set null network key i.e,
* ot networkkey 00000000000000000000000000000000
*/
ot_setNullNetworkKey(instance);
/* ot_setNullNetworkKey(instance); */

/** Step2: Bring up the interface and start joining to the network
* on DK2 with pre-shared key.
Expand All @@ -162,19 +169,20 @@ int ot_throughput_test_init(bool is_ot_client, bool is_ot_zperf_udp)
{
int ret = 0;

if (is_ot_client) {
if (is_ot_client) {
ret = ot_throughput_client_init();
if (ret != 0) {
LOG_ERR("Thread throughput client init failed: %d", ret);
return ret;
}
}
if (!is_ot_client) { /* for server */
ot_initialization();
openthread_state_changed_cb_register(openthread_get_default_context(), &ot_state_chaged_cb);
ot_initialization();
openthread_state_changed_cb_register(openthread_get_default_context(),
&ot_state_chaged_cb);

LOG_INF("Starting zperf server");
ot_start_zperf_test_recv(is_ot_zperf_udp);
ot_start_zperf_test_recv(is_ot_zperf_udp);
}
return 0;
}
Expand All @@ -184,7 +192,7 @@ int ot_tput_test_exit(void)
otInstance *instance = openthread_get_default_instance();
struct openthread_context *context = openthread_get_default_context();

otThreadDetachGracefully(instance, &ot_device_dettached, context);
otThreadDetachGracefully(instance, ot_device_dettached, context);
k_sleep(K_MSEC(1000));

return 0;
Expand All @@ -196,7 +204,9 @@ void ot_setNullNetworkKey(otInstance *aInstance)
uint8_t key[OT_NETWORK_KEY_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

memset(&aDataset, 0, sizeof(otOperationalDataset));
/* memset(&aDataset, 0, sizeof(otOperationalDataset)); */ /* client */
otDatasetCreateNewNetwork(aInstance, &aDataset); /* server */


/* Set network key to null */
memcpy(aDataset.mNetworkKey.m8, key, sizeof(aDataset.mNetworkKey));
Expand All @@ -206,14 +216,15 @@ void ot_setNullNetworkKey(otInstance *aInstance)

void ot_setNetworkConfiguration(otInstance *aInstance)
{
static char aNetworkName[] = "TestNetwork";
static const char aNetworkName[] = "TestNetwork";
otOperationalDataset aDataset;
size_t length;
uint8_t extPanId[OT_EXT_PAN_ID_SIZE] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};
uint8_t key[OT_NETWORK_KEY_SIZE] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};

memset(&aDataset, 0, sizeof(otOperationalDataset));
/* memset(&aDataset, 0, sizeof(otOperationalDataset)); */
otDatasetCreateNewNetwork(aInstance, &aDataset);

/**
* Fields that can be configured in otOperationDataset to override defaults:
Expand Down Expand Up @@ -322,7 +333,8 @@ void ot_start_zperf_test_recv(bool is_ot_zperf_udp)
void ot_zperf_test(bool is_ot_zperf_udp)
{
if (is_ot_device_role_client) {
uint32_t ot_zperf_duration_sec = CONFIG_COEX_TEST_DURATION/1000;
uint32_t ot_zperf_duration_sec = CONFIG_COEX_TEST_DURATION/1000;

ot_start_zperf_test_send(peer_address_info.address_string, ot_zperf_duration_sec,
CONFIG_OT_PACKET_SIZE, CONFIG_OT_RATE_BPS, is_ot_zperf_udp);
}
Expand Down
Empty file modified samples/wifi/thread_coex/src/ot_utils.h
100755 → 100644
Empty file.
Loading

0 comments on commit 7fdac70

Please sign in to comment.