From e7fc6bd3e4650f7291bdee215ff5cf6849d877a9 Mon Sep 17 00:00:00 2001 From: Murali Thokala Date: Sun, 12 May 2024 19:38:55 +0530 Subject: [PATCH] samples: wifi: Add Wi-Fi and Thread coexistence sample 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 --- samples/wifi/thread_coex/CMakeLists.txt | 0 samples/wifi/thread_coex/Kconfig | 0 samples/wifi/thread_coex/README.rst | 59 +++++++-------- .../thread_coex/child_image/802154_rpmsg.conf | 0 samples/wifi/thread_coex/dts.overlay | 0 samples/wifi/thread_coex/overlay-logging.conf | 1 - .../wifi/thread_coex/overlay-openthread.conf | 0 ...lay-wifi-udp-client-thread-udp-client.conf | 0 ...lay-wifi-udp-client-thread-udp-server.conf | 0 samples/wifi/thread_coex/prj.conf | 6 +- samples/wifi/thread_coex/sample.yaml | 2 +- samples/wifi/thread_coex/src/main.c | 0 samples/wifi/thread_coex/src/main.h | 0 .../wifi/thread_coex/src/ot_coex_functions.c | 31 ++++---- .../wifi/thread_coex/src/ot_coex_functions.h | 3 +- samples/wifi/thread_coex/src/ot_utils.c | 54 ++++++++------ samples/wifi/thread_coex/src/ot_utils.h | 0 samples/wifi/thread_coex/src/zperf_utils.c | 73 +++++++++---------- samples/wifi/thread_coex/src/zperf_utils.h | 8 +- 19 files changed, 117 insertions(+), 120 deletions(-) mode change 100755 => 100644 samples/wifi/thread_coex/CMakeLists.txt mode change 100755 => 100644 samples/wifi/thread_coex/Kconfig mode change 100755 => 100644 samples/wifi/thread_coex/README.rst mode change 100755 => 100644 samples/wifi/thread_coex/child_image/802154_rpmsg.conf mode change 100755 => 100644 samples/wifi/thread_coex/dts.overlay mode change 100755 => 100644 samples/wifi/thread_coex/overlay-logging.conf mode change 100755 => 100644 samples/wifi/thread_coex/overlay-openthread.conf mode change 100755 => 100644 samples/wifi/thread_coex/overlay-wifi-udp-client-thread-udp-client.conf mode change 100755 => 100644 samples/wifi/thread_coex/overlay-wifi-udp-client-thread-udp-server.conf mode change 100755 => 100644 samples/wifi/thread_coex/prj.conf mode change 100755 => 100644 samples/wifi/thread_coex/sample.yaml mode change 100755 => 100644 samples/wifi/thread_coex/src/main.c mode change 100755 => 100644 samples/wifi/thread_coex/src/main.h mode change 100755 => 100644 samples/wifi/thread_coex/src/ot_coex_functions.c mode change 100755 => 100644 samples/wifi/thread_coex/src/ot_coex_functions.h mode change 100755 => 100644 samples/wifi/thread_coex/src/ot_utils.c mode change 100755 => 100644 samples/wifi/thread_coex/src/ot_utils.h mode change 100755 => 100644 samples/wifi/thread_coex/src/zperf_utils.c mode change 100755 => 100644 samples/wifi/thread_coex/src/zperf_utils.h diff --git a/samples/wifi/thread_coex/CMakeLists.txt b/samples/wifi/thread_coex/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/Kconfig b/samples/wifi/thread_coex/Kconfig old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/README.rst b/samples/wifi/thread_coex/README.rst old mode 100755 new mode 100644 index a9d39bbbc0e6..50deded1117f --- a/samples/wifi/thread_coex/README.rst +++ b/samples/wifi/thread_coex/README.rst @@ -65,10 +65,6 @@ Configuration options The following sample-specific Kconfig options are used in this sample (located in :file:`samples/wifi/thread_coex/Kconfig`): -.. _CONFIG_COEX_SEP_ANTENNAS: - -CONFIG_COEX_SEP_ANTENNAS - This option specifies whether the antennas are shared or separate for Wi-Fi and Thread. .. _CONFIG_TEST_TYPE_WLAN_ONLY: @@ -110,9 +106,6 @@ Configuration files To enable different test modes, set up the following configuration parameters in the :file:`prj.conf` file: -* Antenna configuration: Use the :ref:`CONFIG_COEX_SEP_ANTENNAS ` Kconfig option to select the antenna configuration. - Always set it to ``y`` to enable separate antennas mode. Thread doesn't support shared antenna configuration as it is in "idle listening" mode when not active. - * Test modes: Use the following Kconfig options to select the required test case: * :ref:`CONFIG_TEST_TYPE_WLAN_ONLY ` for Wi-Fi only test * :ref:`CONFIG_TEST_TYPE_OT_ONLY ` for Thread only test @@ -125,16 +118,14 @@ 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 ` - * :ref:`CONFIG_STA_PASSWORD ` - * :ref:`CONFIG_STA_KEY_MGMT_* ` +.. include:: /includes/wifi_credentials_static.txt + +.. note:: + ``menuconfig`` can also be used to configure ``Wi-Fi credentials`` * 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` -.. note:: - ``menuconfig`` can also be used to enable the ``Key management`` option. - See :ref:`zephyr:menuconfig` in the Zephyr documentation for instructions on how to run ``menuconfig``. Building and running @@ -308,9 +299,7 @@ The Thread throughput result appears on the minicom terminal connected to the nR 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 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 in a clean RF environment. The results are representative and might vary based on the RSSI and the level of external interference. Wi-Fi in 2.4 GHz ---------------- @@ -321,16 +310,16 @@ Separate antennas, Wi-Fi in 802.11n mode, Thread in client role: | Test case | Wi-Fi UDP Tx | Thread | | | throughput in Mbps | throughput in kbps | +========================+====================+====================+ -| Wi-Fi only, | 9.5 | N.A | -| client (UDP Tx) | | | +| Wi-Fi only, | 9.6 | N.A | +| client | | | +------------------------+--------------------+--------------------+ | Thread only, | N.A | 63 | -| client (UDP Tx) | | | +| client | | | +------------------------+--------------------+--------------------+ -| Wi-Fi and Thread, | 9.5 | 10 | +| Wi-Fi and Thread, | 9.5 | 14 | | coexistence disabled | | | +------------------------+--------------------+--------------------+ -| Wi-Fi and Thread, | 9.3 | 55 | +| Wi-Fi and Thread, | 9.3 | 59 | | coexistence enabled | | | +------------------------+--------------------+--------------------+ @@ -340,16 +329,16 @@ Separate antennas, Wi-Fi in 802.11n mode, Thread in server role: | Test case | Wi-Fi UDP Tx | Thread | | | throughput in Mbps | throughput in kbps | +========================+====================+====================+ -| Wi-Fi only, | 9.8 | N.A | -| client (UDP Tx) | | | +| Wi-Fi only, | 9.6 | N.A | +| client | | | +------------------------+--------------------+--------------------+ | Thread only, | N.A | 63 | -| server (UDP Rx) | | | +| server | | | +------------------------+--------------------+--------------------+ -| Wi-Fi and Thread, | 9.1 | 13 | +| Wi-Fi and Thread, | 9.4 | 14 | | coexistence disabled | | | +------------------------+--------------------+--------------------+ -| Wi-Fi and Thread, | 9.0 | 63 | +| Wi-Fi and Thread, | 8.8 | 63 | | coexistence enabled | | | +------------------------+--------------------+--------------------+ @@ -364,12 +353,12 @@ Separate antennas, Wi-Fi in 802.11n mode, Thread in client role: | | throughput in Mbps | throughput in kbps | +========================+====================+====================+ | Wi-Fi only, | 9.6 | N.A | -| client (UDP Tx) | | | +| client | | | +------------------------+--------------------+--------------------+ | Thread only, | N.A | 63 | -| client (UDP Tx) | | | +| client | | | +------------------------+--------------------+--------------------+ -| Wi-Fi and Thread, | 9.1 | 63 | +| Wi-Fi and Thread, | 9.2 | 63 | | coexistence disabled | | | +------------------------+--------------------+--------------------+ | Wi-Fi and Thread, | 9.1 | 63 | @@ -382,19 +371,21 @@ Separate antennas, Wi-Fi in 802.11n mode, Thread in server role: | Test case | Wi-Fi UDP Tx | Thread | | | throughput in Mbps | throughput in kbps | +========================+====================+====================+ -| Wi-Fi only, | 9.9 | N.A | -| client (UDP Tx) | | | +| Wi-Fi only, | 9.6 | N.A | +| client | | | +------------------------+--------------------+--------------------+ | Thread only, | N.A | 63 | -| server (UDP Rx) | | | +| server | | | +------------------------+--------------------+--------------------+ -| Wi-Fi and Thread, | 9.7 | 63 | +| Wi-Fi and Thread, | 8.6 | 63 | | coexistence disabled | | | +------------------------+--------------------+--------------------+ -| Wi-Fi and Thread, | 9.7 | 63 | +| Wi-Fi and Thread, | 8.5 | 63 | | coexistence enabled | | | +------------------------+--------------------+--------------------+ +Thread doesn't support shared antenna configuration as it is in "idle listening" mode when not active. + As is evident from the results of the sample execution, coexistence harmonizes air-time between Wi-Fi and Thread rather than resulting in a higher combined throughput. This is consistent with the design intent. diff --git a/samples/wifi/thread_coex/child_image/802154_rpmsg.conf b/samples/wifi/thread_coex/child_image/802154_rpmsg.conf old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/dts.overlay b/samples/wifi/thread_coex/dts.overlay old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/overlay-logging.conf b/samples/wifi/thread_coex/overlay-logging.conf old mode 100755 new mode 100644 index 064773f9c5b7..beec5569c259 --- a/samples/wifi/thread_coex/overlay-logging.conf +++ b/samples/wifi/thread_coex/overlay-logging.conf @@ -44,4 +44,3 @@ CONFIG_LOG_BACKEND_RTT=y # Disable UART logging backend # CONFIG_LOG_BACKEND_UART=n CONFIG_SHELL_LOG_BACKEND=n - diff --git a/samples/wifi/thread_coex/overlay-openthread.conf b/samples/wifi/thread_coex/overlay-openthread.conf old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/overlay-wifi-udp-client-thread-udp-client.conf b/samples/wifi/thread_coex/overlay-wifi-udp-client-thread-udp-client.conf old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/overlay-wifi-udp-client-thread-udp-server.conf b/samples/wifi/thread_coex/overlay-wifi-udp-client-thread-udp-server.conf old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/prj.conf b/samples/wifi/thread_coex/prj.conf old mode 100755 new mode 100644 index f77fb593d6b0..517bb81509e1 --- a/samples/wifi/thread_coex/prj.conf +++ b/samples/wifi/thread_coex/prj.conf @@ -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="Myssid" CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="Mypassword" CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_OPEN=y @@ -99,8 +99,4 @@ CONFIG_NET_CONFIG_AUTO_INIT=n # test duration in milliseconds CONFIG_COEX_TEST_DURATION=30000 -CONFIG_NET_TCP_ISN_RFC6528=n -CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_MBEDTLS_MD=y - CONFIG_NET_SOCKETS_POLL_MAX=10 diff --git a/samples/wifi/thread_coex/sample.yaml b/samples/wifi/thread_coex/sample.yaml old mode 100755 new mode 100644 index bf934e6d8f22..bf5771cc9cb3 --- a/samples/wifi/thread_coex/sample.yaml +++ b/samples/wifi/thread_coex/sample.yaml @@ -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 diff --git a/samples/wifi/thread_coex/src/main.c b/samples/wifi/thread_coex/src/main.c old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/src/main.h b/samples/wifi/thread_coex/src/main.h old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/src/ot_coex_functions.c b/samples/wifi/thread_coex/src/ot_coex_functions.c old mode 100755 new mode 100644 index dee7b14b6d47..381bf103ba19 --- a/samples/wifi/thread_coex/src/ot_coex_functions.c +++ b/samples/wifi/thread_coex/src/ot_coex_functions.c @@ -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); @@ -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(¶ms.peer_addr, &in4_addr_my, sizeof(in4_addr_my)); ret = zperf_udp_upload_async(¶ms, udp_upload_results_cb, NULL); @@ -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 } } @@ -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; @@ -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) { @@ -853,11 +854,11 @@ int wifi_tput_ot_tput(bool test_wifi, bool is_ant_mode_sep, bool test_thread, bo /* otPlatRadioSetTransmitPower(ot_instance, -3); */ /* 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); - + /* 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); + /* LOG_INF("OT device RSSI in dBm = %d", ot_rssi); */ } if (test_thread) { diff --git a/samples/wifi/thread_coex/src/ot_coex_functions.h b/samples/wifi/thread_coex/src/ot_coex_functions.h old mode 100755 new mode 100644 index f1ba4cb437d0..6e399617b7ef --- a/samples/wifi/thread_coex/src/ot_coex_functions.h +++ b/samples/wifi/thread_coex/src/ot_coex_functions.h @@ -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 @@ -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 * diff --git a/samples/wifi/thread_coex/src/ot_utils.c b/samples/wifi/thread_coex/src/ot_utils.c old mode 100755 new mode 100644 index d5afcea76170..5f6907030804 --- a/samples/wifi/thread_coex/src/ot_utils.c +++ b/samples/wifi/thread_coex/src/ot_utils.c @@ -21,7 +21,7 @@ LOG_MODULE_REGISTER(ot_utils, CONFIG_LOG_DEFAULT_LEVEL); #include #include -#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]; @@ -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"); } } @@ -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); } } } @@ -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."); @@ -112,7 +119,7 @@ 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."); @@ -120,7 +127,7 @@ int ot_throughput_client_init(void) } return 0; } - + int ot_throughput_test_run(bool is_ot_zperf_udp) { if (is_ot_device_role_client) { @@ -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. @@ -162,7 +169,7 @@ 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); @@ -170,11 +177,12 @@ int ot_throughput_test_init(bool is_ot_client, bool is_ot_zperf_udp) } } 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; } @@ -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; @@ -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)); @@ -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: @@ -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); } diff --git a/samples/wifi/thread_coex/src/ot_utils.h b/samples/wifi/thread_coex/src/ot_utils.h old mode 100755 new mode 100644 diff --git a/samples/wifi/thread_coex/src/zperf_utils.c b/samples/wifi/thread_coex/src/zperf_utils.c old mode 100755 new mode 100644 index 54798d83e7b7..216158b064f9 --- a/samples/wifi/thread_coex/src/zperf_utils.c +++ b/samples/wifi/thread_coex/src/zperf_utils.c @@ -11,6 +11,7 @@ LOG_MODULE_REGISTER(zperf_utils, CONFIG_LOG_DEFAULT_LEVEL); void zperf_log_upload_stats(struct zperf_results *results, bool is_udp) { unsigned int rate_in_kbps, client_rate_in_kbps; + LOG_INF("Thread zperf Upload completed"); if (results->client_time_in_us != 0U) { @@ -34,20 +35,22 @@ void zperf_log_upload_stats(struct zperf_results *results, bool is_udp) } if (!rate_in_kbps) { - LOG_ERR("LAST PACKET NOT RECEIVED"); + LOG_ERR("LAST PACKET NOT RECEIVED"); } LOG_INF("Thread zperf UDP Statistics:\t\tserver\t\t(client)"); - LOG_INF("Duration:\t\t\t%llu us\t(%llu us)",results->time_in_us,results->client_time_in_us); - LOG_INF("Rate:\t\t\t%u kbps\t\t(%u kbps)",rate_in_kbps,client_rate_in_kbps); - LOG_INF("Num packets:\t\t%u\t\t(%u)",results->nb_packets_rcvd, results->nb_packets_sent); + LOG_INF("Duration:\t\t\t%llu us\t(%llu us)", + results->time_in_us, results->client_time_in_us); + LOG_INF("Rate:\t\t\t%u kbps\t\t(%u kbps)", rate_in_kbps, client_rate_in_kbps); + LOG_INF("Num packets:\t\t%u\t\t(%u)", + results->nb_packets_rcvd, results->nb_packets_sent); LOG_INF("Num packets outorder:\t%u", results->nb_packets_outorder); LOG_INF("Num packets lost:\t\t%u", results->nb_packets_lost); - LOG_INF("Jitter:\t\t\t%u us",results->jitter_in_us); + LOG_INF("Jitter:\t\t\t%u us", results->jitter_in_us); } else { LOG_INF("Thread zperf TCP Statistics:"); - LOG_INF("Duration:\t%llu us",results->client_time_in_us); - LOG_INF("Rate:\t\t%u kbps",client_rate_in_kbps); + LOG_INF("Duration:\t%llu us", results->client_time_in_us); + LOG_INF("Rate:\t\t%u kbps", client_rate_in_kbps); LOG_INF("Num packets:\t%u", results->nb_packets_sent); LOG_INF("Num errors:\t%u (retry or fail)", results->nb_packets_errors); } @@ -59,24 +62,23 @@ int zperf_upload(const char *peer_addr, uint32_t duration_sec, struct zperf_upload_params param = { 0 }; struct sockaddr_in6 ipv6 = { .sin6_family = AF_INET6 }; struct sockaddr_in ipv4 = { .sin_family = AF_INET }; - struct zperf_results results = { 0 }; + struct zperf_results results = { 0 }; int ret; char *port_str; param.options.priority = -1; - param.duration_ms = MSEC_PER_SEC * duration_sec; + param.duration_ms = MSEC_PER_SEC * duration_sec; param.packet_size = packet_size_bytes; param.rate_kbps = (rate_bps + 1023) / 1024; port_str = STRINGIFY(CONFIG_NET_CONFIG_THREAD_PORT); - if(is_udp && !IS_ENABLED(CONFIG_NET_UDP)) { - LOG_ERR("CONFIG_NET_UDP disabled"); - return -ENOTSUP; - } - else if (!is_udp && !IS_ENABLED(CONFIG_NET_TCP)) { - LOG_WRN("CONFIG_NET_TCP disabled"); - return -ENOTSUP; + if (is_udp && !IS_ENABLED(CONFIG_NET_UDP)) { + LOG_ERR("CONFIG_NET_UDP disabled"); + return -ENOTSUP; + } else if (!is_udp && !IS_ENABLED(CONFIG_NET_TCP)) { + LOG_WRN("CONFIG_NET_TCP disabled"); + return -ENOTSUP; } if (net_addr_pton(AF_INET6, peer_addr, &(ipv6.sin6_addr)) < 0) { @@ -104,7 +106,7 @@ int zperf_upload(const char *peer_addr, uint32_t duration_sec, } LOG_INF("Thread zperf parameters"); - LOG_INF("Duration:\t\t%d ms",param.duration_ms); + LOG_INF("Duration:\t\t%d ms", param.duration_ms); LOG_INF("Packet size:\t%u bytes", param.packet_size); LOG_INF("Rate:\t\t%u kbps", param.rate_kbps); LOG_INF("Starting Thread zperf upload..."); @@ -123,7 +125,7 @@ int zperf_upload(const char *peer_addr, uint32_t duration_sec, } } - zperf_log_upload_stats(&results,is_udp); + zperf_log_upload_stats(&results, is_udp); return 0; } @@ -134,10 +136,10 @@ void zperf_download_cb(enum zperf_status status, { switch (status) { case ZPERF_SESSION_STARTED: - LOG_INF("Thread zperf New session started."); - break; + LOG_INF("Thread zperf New session started."); + break; - case ZPERF_SESSION_FINISHED: { + case ZPERF_SESSION_FINISHED: uint32_t rate_in_kbps; /* Compute baud rate */ @@ -151,21 +153,20 @@ void zperf_download_cb(enum zperf_status status, } LOG_INF("Thread zperf download Session ended."); - LOG_INF("Duration:\t\t\t%llu us",result->time_in_us); - LOG_INF("Rate:\t\t\t%u kbps",rate_in_kbps); + LOG_INF("Duration:\t\t\t%llu us", result->time_in_us); + LOG_INF("Rate:\t\t\t%u kbps", rate_in_kbps); /* Applicable only for UDP cases */ - if(result->nb_packets_rcvd) { - LOG_INF("Num packets received:\t%u",result->nb_packets_rcvd); + if (result->nb_packets_rcvd) { + LOG_INF("Num packets received:\t%u", result->nb_packets_rcvd); LOG_INF("Num packets outorder:\t%u", result->nb_packets_outorder); LOG_INF("Num packets lost:\t\t%u", result->nb_packets_lost); - LOG_INF("Jitter:\t\t\t%u us",result->jitter_in_us); + LOG_INF("Jitter:\t\t\t%u us", result->jitter_in_us); } - break; - } + break; case ZPERF_SESSION_ERROR: - LOG_ERR("Session error."); + LOG_ERR("Session error."); break; } } @@ -177,33 +178,31 @@ int zperf_download(bool is_udp) param.port = CONFIG_NET_CONFIG_THREAD_PORT; - if(is_udp && !IS_ENABLED(CONFIG_NET_UDP)) { + if (is_udp && !IS_ENABLED(CONFIG_NET_UDP)) { LOG_ERR("CONFIG_NET_UDP disabled"); return -ENOTSUP; - } - else if (!is_udp && !IS_ENABLED(CONFIG_NET_TCP)) { + } else if (!is_udp && !IS_ENABLED(CONFIG_NET_TCP)) { LOG_WRN("CONFIG_NET_TCP disabled"); return -ENOTSUP; } if (is_udp) { ret = zperf_udp_download(¶m, zperf_download_cb, NULL); - } else { - ret = zperf_tcp_download(¶m, zperf_download_cb, NULL); + ret = zperf_tcp_download(¶m, zperf_download_cb, NULL); } if (ret == -EALREADY) { - LOG_WRN("%s server already started!",is_udp ? "UDP" : "TCP"); + LOG_WRN("%s server already started!", is_udp ? "UDP" : "TCP"); return -ENOEXEC; } else if (ret < 0) { - LOG_ERR("Failed to start %s server (%d)",is_udp ? "UDP" : "TCP",ret); + LOG_ERR("Failed to start %s server (%d)", is_udp ? "UDP" : "TCP", ret); return -ENOEXEC; } k_yield(); - LOG_INF("%s Thread zperf server started on port %u",is_udp ? "UDP" : "TCP",param.port); + LOG_INF("%s Thread zperf server started on port %u", is_udp ? "UDP" : "TCP", param.port); return 0; } diff --git a/samples/wifi/thread_coex/src/zperf_utils.h b/samples/wifi/thread_coex/src/zperf_utils.h old mode 100755 new mode 100644 index 388140b9c19f..efef31150fa8 --- a/samples/wifi/thread_coex/src/zperf_utils.h +++ b/samples/wifi/thread_coex/src/zperf_utils.h @@ -21,8 +21,8 @@ * @return Zero on success or (negative) error code otherwise. */ int zperf_upload(const char *peer_addr, uint32_t duration_sec, uint32_t packet_size_bytes, - uint32_t rate_bps, bool is_ot_zperf_udp); - + uint32_t rate_bps, bool is_ot_zperf_udp); + /** * @brief thread zperf upload statistics * @@ -43,5 +43,5 @@ int zperf_download(bool is_udp); * @return None */ void zperf_download_cb(enum zperf_status status, - struct zperf_results *result, - void *user_data); \ No newline at end of file + struct zperf_results *result, + void *user_data);