Wi-Fi: Raw TX packet

The Raw TX packet sample demonstrates how to transmit raw IEEE 802.11 packets.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

Shields

nRF7002 DK (emulating nRF7001)

PCA10143

nrf7002dk_nrf7001_nrf5340

nrf7002dk_nrf7001_nrf5340_cpuapp

nRF7002 DK

PCA10143

nrf7002dk_nrf5340

nrf7002dk_nrf5340_cpuapp

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

nrf7002ek_nrf7000 nrf7002ek

Overview

The sample generates and broadcasts 802.11 beacon frames as raw TX packets. As a consequence, the nRF70 Series device can be identified as a Wi-Fi® beaconing device.

The sample demonstrates how to transmit raw TX packets in both connected Station and non-connected Station modes of operation. The sample provides the option to select the traffic pattern between the following modes:

  • CONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_CONTINUOUS: Selects continuous packet transmission.

  • CONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_FIXED: Selects fixed number of transmitted packets.

The configurations for connected Station or non-connected Station modes, and for continuous or fixed packet transmission, are set at build time.

For more information, see Raw IEEE 802.11 packet transmission.

Configuration

See Configuring and building an application for information about how to permanently or temporarily change the configuration.

Configuration options

The following sample-specific Kconfig options are used in this sample (located in samples/wifi/raw_tx_packet/Kconfig):

CONFIG_RAW_TX_PKT_SAMPLE_CONNECTION_TIMEOUT

Time to wait for a station to connect

None

CONFIG_RAW_TX_PKT_SAMPLE_DHCP_TIMEOUT_S

DHCP timeout in seconds

None

CONFIG_RAW_TX_PKT_SAMPLE_SSID

SSID

Specify the SSID to establish a wireless connection with an Access point in Connected Station mode.

CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_NONE

Open Security

Enable for Open Security

CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_WPA2

WPA2 Security

Enable for WPA2 Security

CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_WPA2_256

WPA2 SHA 256 Security

Enable for WPA2-PSK-256 Security

CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_WPA3

WPA3 Security

Enable for WPA3 Security

CONFIG_RAW_TX_PKT_SAMPLE_PASSWORD

Passphrase (WPA2) or password (WPA3)

Specify the Password to connect

CONFIG_RAW_TX_PKT_SAMPLE_STA_ONLY_MODE

Set Wi-Fi Station mode

Set the device operating mode as Station mode.

CONFIG_RAW_TX_PKT_SAMPLE_INJECTION_ENABLE

Set Wi-Fi TX injection mode

Set the device operating mode as TX injection mode.

CONFIG_RAW_TX_PKT_SAMPLE_CONNECTION_MODE

Connected Station mode

Enable the option to select Connected Station mode.

CONFIG_RAW_TX_PKT_SAMPLE_NON_CONNECTED_MODE

Non-connected Station mode

Enable the option to select non-connected Station mode.

CONFIG_RAW_TX_PKT_SAMPLE_CHANNEL

Channel for non-connected Station mode

Specify the Wi-Fi channel for transmitting raw TX packets in non-connected Station mode. The valid channel range is 1 to 233.

CONFIG_RAW_TX_PKT_SAMPLE_RATE_VALUE

MCS index or Data rate value

Specify the Wi-Fi data rate value for raw TX packet transmission. The value represents either the data rate in Mbps or Modulation and coding (MCS) index. Note: 5.5Mbps is treated specially as 55 to avoid floating point usage. Legacy: 1, 2, 55, 11, 6, 9, 12, 18, 24, 36, 48, 54 MCS index: 0-7

CONFIG_RAW_TX_PKT_SAMPLE_RATE_FLAGS

Rate flag value

Specify the rate flag value to be used for raw TX packet transmission. Rate Flags: 0 - Legacy 1 - 11n format 2 - VHT format 3 - HE_SU 4 - HE_ER_SU

CONFIG_RAW_TX_PKT_SAMPLE_QUEUE_NUM

Queue number

Specify the transmission queue number for raw TX packets. 0 - Background 1 - Best effort 2 - Video 3 - Voice 4 - Beacon.

CONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_CONTINUOUS

Continuous transmission mode

None

CONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_FIXED

Fixed transmission mode

None

CONFIG_RAW_TX_PKT_SAMPLE_FIXED_NUM_PACKETS

Number of packets

Specify the number of packets to be sent when using Fixed mode of transmission.

CONFIG_RAW_TX_PKT_SAMPLE_INTER_FRAME_DELAY_MS

Inter-Frame Delay (milliseconds)

Specify the inter-frame delay duration for raw TX packet transmission.

Configuration options for operating modes

By using the following Kconfig options, you can configure the sample for different operational modes:

  • For connected Station mode

    To configure the sample in connected Station mode, you must configure the following Wi-Fi credentials in the prj.conf file:

    • CONFIG_RAW_TX_PKT_SAMPLE_SSID: Sets the name of your Wi-Fi network.

    • CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_NONE: Selects open security.

    • CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_WPA2: Selects PSK security.

    • CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_WPA2_256: Selects PSK-256 security.

    • CONFIG_RAW_TX_PKT_SAMPLE_KEY_MGMT_WPA3: Selects SAE security (default).

    • CONFIG_RAW_TX_PKT_SAMPLE_PASSWORD: Sets the password of your Wi-Fi network.

    Note

    You can also use menuconfig to enable the Key management option.

    See Interactive Kconfig interfaces in the Zephyr documentation for instructions on how to run menuconfig.

  • For non-connected Station mode

    To configure the sample in non-connected Station mode, you must configure the CONFIG_RAW_TX_PKT_SAMPLE_CHANNEL Kconfig option in the prj.conf file.

    This specifies the Wi-Fi channel to be used for communication on the wireless network.

Configuration options for raw TX packet header

The following configuration options are available for the raw TX packet header:

  • CONFIG_RAW_TX_PKT_SAMPLE_RATE_VALUE: Specifies the data transmission PHY rate.

  • CONFIG_RAW_TX_PKT_SAMPLE_RATE_FLAGS: Specifies the data transmission mode.

  • CONFIG_RAW_TX_PKT_SAMPLE_QUEUE_NUM: Specifies the transmission queue to which raw TX packets are assigned for sending.

Additionally, you must configure the CONFIG_RAW_TX_PKT_SAMPLE_INTER_FRAME_DELAY_MS Kconfig option in the prj.conf file to define the time delay between raw TX packets.

This sets the time duration between raw TX packets.

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 prj.conf file:

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"

Note

This section is specific to the connected Station mode.

Building and running

This sample can be found under samples/wifi/raw_tx_packet in the nRF Connect SDK folder structure.

When built as firmware image for the _ns build target, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). To read more about CMSE, see Processing environments.

To build the sample with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Configuring and building an application for other building scenarios, Programming an application for programming steps, and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

The sample can be built for the following configurations:

  • Continuous raw 802.11 packet transmission in the connected Station mode.

  • Fixed number of raw 802.11 packet transmission in the connected Station mode.

  • Continuous raw 802.11 packet transmission in the non-connected Station mode.

  • Fixed number of raw 802.11 packet transmission in the non-connected Station mode.

To build for the nRF7002 DK, use the nrf7002dk_nrf5340_cpuapp build target. The following are examples of the CLI commands:

  • Continuous raw 802.11 packet transmission in the connected Station mode:

    west build -b nrf7002dk_nrf5340_cpuapp -- -DCONFIG_RAW_TX_PKT_SAMPLE_CONNECTION_MODE=y -DCONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_CONTINUOUS=y
    
  • Fixed number of raw 802.11 packet transmission in the connected Station mode:

    west build -b nrf7002dk_nrf5340_cpuapp -- -DCONFIG_RAW_TX_PKT_SAMPLE_CONNECTION_MODE=y -DCONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_FIXED=y -DCONFIG_RAW_TX_PKT_SAMPLE_FIXED_NUM_PACKETS=<number of packets to be sent>
    
  • Continuous raw 802.11 packet transmission in the non-connected Station mode:

    west build -b nrf7002dk_nrf5340_cpuapp -- -DCONFIG_RAW_TX_PKT_SAMPLE_NON_CONNECTED_MODE=y -DCONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_CONTINUOUS=y
    
  • Fixed number of raw 802.11 packet transmission in the non-connected Station mode:

    west build -b nrf7002dk_nrf5340_cpuapp -- -DCONFIG_RAW_TX_PKT_SAMPLE_NON_CONNECTED_MODE=y -DCONFIG_RAW_TX_PKT_SAMPLE_TX_MODE_FIXED=y -DCONFIG_RAW_TX_PKT_SAMPLE_FIXED_NUM_PACKETS=<number of packets to be sent>
    

Change the build target as given below for the nRF7002 EK.

nrf5340dk_nrf5340_cpuapp -- -DSHIELD=nrf7002ek

Testing

After programming the sample to your development kit, complete the following steps to test it:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.

    The sample shows the following output:

    [00:00:00.469,940] <err> wifi_nrf: Firmware (v1.2.8.99) booted successfully
    
    *** Booting nRF Connect SDK 9a9ffb5ebb5b ***
    [00:00:00.618,713] <inf> net_config: Initializing network
    [00:00:00.618,713] <inf> net_config: Waiting interface 1 (0x20001570) to be up...
    [00:00:00.618,835] <inf> net_config: IPv4 address: 192.168.1.99
    [00:00:00.618,896] <inf> net_config: Running dhcpv4 client...
    [00:00:00.619,140] <inf> raw_tx_packet: Starting nrf7002dk_nrf5340_cpuapp with CPU frequency: 64 MHz
    [00:00:01.619,293] <inf> raw_tx_packet: Static IP address (overridable): 192.168.1.99/255.255.255.0 -> 192.168.1.1
    [00:00:01.632,507] <inf> raw_tx_packet: Wi-Fi channel set to 6
    [00:00:01.632,598] <inf> raw_tx_packet: Sending 25 number of raw tx packets
    [00:00:01.730,010] <inf> net_config: IPv6 address: fe80::f6ce:36ff:fe00:2282
    

Dependencies

This sample uses the following library: