Skip to content

Commit

Permalink
samples: wifi: Add TWT sample
Browse files Browse the repository at this point in the history
This is based on STA sample, for now it only does Wi-Fi connection.
Also, update changelog and add a codeowners entry.

Signed-off-by: Chiranjeevi Srikakulapu <chiranjeevi.srikakulapu@nordicsemi.no>
  • Loading branch information
chiranjeevi2776 authored and carlescufi committed Aug 22, 2023
1 parent dc13406 commit 3c17ef6
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Kconfig* @tejlmand
/samples/wifi/shell/ @krish2718 @sachinthegreen @rado17 @rlubos
/samples/wifi/sta/ @D-Triveni @bama-nordic
/samples/wifi/sr_coex/ @muraliThokala @bama-nordic
/samples/wifi/twt/ @chiranjeevi2776 @krish2718
/scripts/ @mbolivar-nordic @tejlmand @nrfconnect/ncs-test-leads
/scripts/hid_configurator/ @MarekPieta
/scripts/tools-versions-*.txt @tejlmand @grho @shanthanordic @ihansse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ Wi-Fi samples
* Added :ref:`wifi_wfa_qt_app_sample` that demonstrates how to use the WFA QuickTrack (WFA QT) library needed for Wi-Fi Alliance QuickTrack certification.
* Added :ref:`wifi_shutdown_sample` that demonstrates how to configure the Wi-Fi driver to shut down the Wi-Fi hardware when the Wi-Fi interface is not in use.
* Added support for the Wi-Fi driver to several upstream Zephyr networking samples.
* Added :ref:`wifi_twt_sample` that demonstrates how to establish TWT flow and transfer data conserving power.

Other samples
-------------
Expand Down
16 changes: 16 additions & 0 deletions samples/wifi/twt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(nrf_wifi_twt)

target_include_directories(app PUBLIC ${ZEPHYR_BASE}/subsys/net/ip)

target_sources(app PRIVATE
src/main.c
)
50 changes: 50 additions & 0 deletions samples/wifi/twt/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

source "Kconfig.zephyr"

menu "Nordic TWT sample"

config CONNECTION_IDLE_TIMEOUT
int "Time to be waited for a station to connect"
default 30

config TWT_SAMPLE_SSID
string "SSID"
help
Specify the SSID to connect

choice TWT_STA_KEY_MGMT_SELECT
prompt "Security Option"
default TWT_STA_KEY_MGMT_WPA3

config TWT_STA_KEY_MGMT_NONE
bool "Open Security"
help
Enable for Open Security

config TWT_STA_KEY_MGMT_WPA2
bool "WPA2 Security"
help
Enable for WPA2 Security

config TWT_STA_KEY_MGMT_WPA2_256
bool "WPA2 SHA 256 Security"
help
Enable for WPA2-PSK-256 Security

config TWT_STA_KEY_MGMT_WPA3
bool "WPA3 Security"
help
Enable for WPA3 Security
endchoice

config TWT_SAMPLE_PASSWORD
string "Passphrase (WPA2) or password (WPA3)"
help
Specify the Password to connect

endmenu
177 changes: 177 additions & 0 deletions samples/wifi/twt/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
.. _wifi_twt_sample:

Wi-Fi: TWT
##########

.. contents::
:local:
:depth: 2

The TWT sample demonstrates how to use TWT power save feature.

Requirements
************

The sample supports the following development kit:

.. table-from-sample-yaml::

Overview
********

The sample can perform Wi-Fi operations such as connect and disconnect in the 2.4 GHz and 5 GHz bands depending on the capabilities of an access point.

Using this sample, the development kit can connect to the specified access point in :abbr:`STA (Station)` mode and setup TWT flow with the access point.

Configuration
*************

|config|

You must configure the following Wi-Fi credentials in the :file:`prj.conf` file:

* Network name (SSID)
* Key management
* Password

.. note::
You can also use ``menuconfig`` to enable ``Key management`` option.

See :ref:`zephyr:menuconfig` in the Zephyr documentation for instructions on how to run ``menuconfig``.

Configuration options
=====================

The following application-specific Kconfig option is used in this sample (located in :file:`samples/wifi/twt/Kconfig`) :

.. options-from-kconfig::
:show-type:

IP addressing
*************
The sample uses DHCP to obtain an IP address for the Wi-Fi interface.
It starts with a default static IP address to handle networks without DHCP servers, or if the DHCP server is not available.
Successful DHCP handshake will override the default static IP configuration.

You can change the following default static configuration in the :file:`prj.conf` file:

.. code-block:: console
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.1.98"
CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.168.1.1"
Building and running
********************

.. |sample path| replace:: :file:`samples/wifi/twt`

.. include:: /includes/build_and_run_ns.txt

Currently, only the nRF7002 DK is supported.

To build for the nRF7002 DK, use the ``nrf7002dk_nrf5340_cpuapp`` build target.
The following is an example of the CLI command:

.. code-block:: console
west build -b nrf7002dk_nrf5340_cpuapp
Testing
=======

|test_sample|

#. |connect_kit|
#. |connect_terminal|

The sample shows the following output:

.. code-block:: console
[00:00:02.016,235] <inf> sta: Connection requested
[00:00:02.316,314] <inf> sta: ==================
[00:00:02.316,314] <inf> sta: State: SCANNING
[00:00:02.616,424] <inf> sta: ==================
[00:00:02.616,424] <inf> sta: State: SCANNING
[00:00:02.916,534] <inf> sta: ==================
[00:00:02.916,534] <inf> sta: State: SCANNING
[00:00:03.216,613] <inf> sta: ==================
[00:00:03.216,613] <inf> sta: State: SCANNING
[00:00:03.516,723] <inf> sta: ==================
[00:00:03.516,723] <inf> sta: State: SCANNING
[00:00:03.816,802] <inf> sta: ==================
[00:00:03.816,802] <inf> sta: State: SCANNING
[00:00:04.116,882] <inf> sta: ==================
[00:00:04.116,882] <inf> sta: State: SCANNING
[00:00:04.416,961] <inf> sta: ==================
[00:00:04.416,961] <inf> sta: State: SCANNING
[00:00:04.717,071] <inf> sta: ==================
[00:00:04.717,071] <inf> sta: State: SCANNING
[00:00:05.017,150] <inf> sta: ==================
[00:00:05.017,150] <inf> sta: State: SCANNING
[00:00:05.317,230] <inf> sta: ==================
[00:00:05.317,230] <inf> sta: State: SCANNING
[00:00:05.617,309] <inf> sta: ==================
[00:00:05.617,309] <inf> sta: State: SCANNING
[00:00:05.917,419] <inf> sta: ==================
[00:00:05.917,419] <inf> sta: State: SCANNING
[00:00:06.217,529] <inf> sta: ==================
[00:00:06.217,529] <inf> sta: State: SCANNING
[00:00:06.517,639] <inf> sta: ==================
[00:00:06.517,639] <inf> sta: State: SCANNING
[00:00:06.817,749] <inf> sta: ==================
[00:00:06.817,749] <inf> sta: State: SCANNING
[00:00:07.117,858] <inf> sta: ==================
[00:00:07.117,858] <inf> sta: State: SCANNING
[00:00:07.336,730] <inf> wpa_supp: wlan0: SME: Trying to authenticate with aa:bb:cc:dd:ee:ff (SSID='<MySSID>' freq=5785 MHz)
[00:00:07.353,027] <inf> wifi_nrf: wifi_nrf_wpa_supp_authenticate:Authentication request sent successfully
[00:00:07.417,938] <inf> sta: ==================
[00:00:07.417,938] <inf> sta: State: AUTHENTICATING
[00:00:07.606,628] <inf> wpa_supp: wlan0: Trying to associate with aa:bb:cc:dd:ee:ff (SSID='<MySSID>' freq=5785 MHz)
[00:00:07.609,680] <inf> wifi_nrf: wifi_nrf_wpa_supp_associate: Association request sent successfully
[00:00:07.621,978] <inf> wpa_supp: wpa_drv_zep_get_ssid: SSID size: 5
[00:00:07.622,070] <inf> wpa_supp: wlan0: Associated with aa:bb:cc:dd:ee:ff
[00:00:07.622,192] <inf> wpa_supp: wlan0: CTRL-EVENT-CONNECTED - Connection to aa:bb:cc:dd:ee:ff completed [id=0 id_str=]
[00:00:07.622,192] <inf> sta: Connected
[00:00:07.623,779] <inf> wpa_supp: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0
[00:00:07.648,406] <inf> net_dhcpv4: Received: 192.168.119.6
[00:00:07.648,468] <inf> net_config: IPv4 address: 192.168.119.6
[00:00:07.648,498] <inf> net_config: Lease time: 3599 seconds
[00:00:07.648,498] <inf> net_config: Subnet: 255.255.255.0
[00:00:07.648,529] <inf> net_config: Router: 192.168.119.147
[00:00:07.648,559] <inf> sta: DHCP IP address: 192.168.119.6
[00:00:07.720,153] <inf> sta: ==================
[00:00:07.720,153] <inf> sta: State: COMPLETED
[00:00:07.720,153] <inf> sta: Interface Mode: STATION
[00:00:07.720,184] <inf> sta: Link Mode: WIFI 6 (802.11ax/HE)
[00:00:07.720,184] <inf> sta: SSID: <MySSID>
[00:00:07.720,214] <inf> sta: BSSID: aa:bb:cc:dd:ee:ff
[00:00:07.720,214] <inf> sta: Band: 5GHz
[00:00:07.720,214] <inf> sta: Channel: 157
[00:00:07.720,245] <inf> sta: Security: OPEN
[00:00:07.720,245] <inf> sta: MFP: UNKNOWN
[00:00:07.720,245] <inf> sta: RSSI: -57
[00:00:07.720,245] <inf> sta: Static IP address:
Power management testing
************************

You can use this sample to measure the current consumption of both the nRF5340 SoC and the nRF7002 device independently by using two separate Power Profiler Kit II (PPK2) devices.
The nRF5340 SoC is connected to the first PPK2 and the nRF7002 DK is connected to the second PPK2.

See `Measuring current`_ for more information about how to set up and measure the current consumption of both the nRF5340 SoC and the nRF7002 device.

The average current consumption in an idle case can be around ~1-2 mA in the nRF5340 SoC and ~20 µA in the nRF7002 device.

See :ref:`app_power_opt` for more information on power management testing and usage of the PPK2.

Dependencies
************

This sample uses the following library:

* :ref:`nrf_security`
88 changes: 88 additions & 0 deletions samples/wifi/twt/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y

# WPA supplicant
CONFIG_WPA_SUPP=y

# Below configs need to be modified based on security
# CONFIG_TWT_STA_KEY_MGMT_NONE=y
# CONFIG_TWT_STA_KEY_MGMT_WPA2=y
# CONFIG_TWT_STA_KEY_MGMT_WPA2_256=y
# CONFIG_TWT_STA_KEY_MGMT_WPA3=y
CONFIG_TWT_SAMPLE_SSID="Myssid"
CONFIG_TWT_SAMPLE_PASSWORD="Mypassword"

# System settings
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_LOG=y
CONFIG_NET_IPV4=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y
CONFIG_NET_DHCPV4=y

CONFIG_NET_PKT_RX_COUNT=8
CONFIG_NET_PKT_TX_COUNT=8

# Below section is the primary contributor to SRAM and is currently
# tuned for performance, but this will be revisited in the future.
CONFIG_NET_BUF_RX_COUNT=16
CONFIG_NET_BUF_TX_COUNT=16
CONFIG_NET_BUF_DATA_SIZE=128
CONFIG_HEAP_MEM_POOL_SIZE=153600
CONFIG_NET_TC_TX_COUNT=0

CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
CONFIG_NET_MAX_CONTEXTS=5
CONFIG_NET_CONTEXT_SYNC_RECV=y

CONFIG_INIT_STACKS=y

CONFIG_NET_L2_ETHERNET=y

CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_INIT_TIMEOUT=0

CONFIG_NET_SOCKETS_POLL_MAX=4

# Memories
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096

# Debugging
CONFIG_STACK_SENTINEL=y
CONFIG_DEBUG_COREDUMP=y
CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y
CONFIG_SHELL_CMDS_RESIZE=n


# Kernel options
CONFIG_ENTROPY_GENERATOR=y

# Logging
CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=2048
CONFIG_POSIX_CLOCK=y

CONFIG_PM=y

CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.1.99"
CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.168.1.1"

# printing of scan results puts pressure on queues in new locking
# design in net_mgmt. So, use a higher timeout for a crowded
# environment.
CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT=5000
11 changes: 11 additions & 0 deletions samples/wifi/twt/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sample:
description: Wi-Fi TWT sample
application
name: Wi-Fi TWT sample
tests:
sample.wifi.twt:
build_only: true
integration_platforms:
- nrf7002dk_nrf5340_cpuapp
platform_allow: nrf7002dk_nrf5340_cpuapp
tags: ci_build
Loading

0 comments on commit 3c17ef6

Please sign in to comment.