Skip to content

Commit

Permalink
samples: 802154_sniffer: Add 802154_sniffer sample
Browse files Browse the repository at this point in the history
The sniffer sample allows the user to capture IEEE 802.15.4 packets in
real time using the Wireshark protocol analyzer.

The sample integrates with the nRF Sniffer for 802.15.4 extcap tool
available on NordicSemiconductor GitHub respository.
https://github.com/NordicSemiconductor/nRF-Sniffer-for-802.15.4

Signed-off-by: Rafał Kuźnia <rafal.kuznia@nordicsemi.no>
  • Loading branch information
e-rk authored and nordicjm committed Aug 4, 2023
1 parent 5f1a49a commit 4bd26e9
Show file tree
Hide file tree
Showing 11 changed files with 439 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 @@ -173,6 +173,7 @@ Kconfig* @tejlmand
/samples/peripheral/radio_test/ @KAGA164 @maje-emb
/samples/peripheral/lpuart/ @nordic-krch
/samples/peripheral/802154_phy_test/ @ankuns @jciupis @ahasztag
/samples/peripheral/802154_sniffer/ @e-rk
/samples/tfm/ @frkv @Vge0rge @vili-nordic @joerchan @SebastianBoe @mswarowsky
/samples/zigbee/ @tomchy @sebastiandraus
/samples/CMakeLists.txt @tejlmand
Expand Down
2 changes: 2 additions & 0 deletions doc/nrf/links.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1247,3 +1247,5 @@
.. _`IEEE 802.11 Working Group`: https://www.ieee802.org/11/

.. _`Samsung SmartThings integration with Matter`: https://support.smartthings.com/hc/en-us/articles/11219700390804-SmartThings-x-Matter-Integration-

.. _`Wireshark`: https://www.wireshark.org
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ Other samples

* Aligned the timer's configuration to the new nrfx API.

* :ref:`802154_sniffer` sample:

* Added the 802.15.4 sniffer sample.

Drivers
=======

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

cmake_minimum_required(VERSION 3.20.0)

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

target_sources(app PRIVATE src/main.c)
176 changes: 176 additions & 0 deletions samples/peripheral/802154_sniffer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
.. _802154_sniffer:

IEEE 802.15.4 Sniffer
#####################

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

The IEEE 802.15.4 Sniffer listens to a selected IEEE 802.15.4 channel (2.4GHz O-QPSK with DSSS) and integrates with the nRF 802.15.4 sniffer extcap for Wireshark.

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

The sample supports the following development kits:

.. table-from-sample-yaml::

The application can be used with the `nRF Sniffer for 802.15.4`_ extcap utility for the `Wireshark`_ network protocol analyzer.

Overview
********

The application presents the user with a command-line interface.

See the :ref:`802154_sniffer_commands` for the list of the available commands.

LED 1:
When the capture is stopped the LED blinks with a period of 2 seconds with 50% duty cycle.
When the capture is ongoing the LED blinks with a period of 0.5 seconds with 50% duty cycle.

LED 4:
When the sniffer captures a packet the LED is toggled on and off.

.. _802154_sniffer_commands:

Serial commands list
********************

This section lists the serial commands that are supported by the sample.

channel - Change the radio channel
==================================

The command changes the IEEE 802.15.4 radio channel to listen on.

.. parsed-literal::
:class: highlight
channel *<channel>*
The ``<channel>`` argument is an integer in the range between 11 and 26.

For example:

.. parsed-literal::
:class: highlight
channel *23*
receive - start capturing packets
=================================

The ``receive`` command makes the sniffer enter the RX state and start capturing packets.

.. parsed-literal::
:class: highlight
receive
The received packets will be printed to the command-line with the following format:

.. parsed-literal::
:class: highlight
received: *<data>* power: *<power>* lqi: *<lqi>* time: *<timestamp>*
* The ``<data>`` is a hexidecimal string representation of the received packet.
* The ``<power>`` value is the signal power in dBm.
* The ``<lqi>`` value is the IEEE 802.15.4 Link Quality Indicator.
* The ``<timestamp>`` value is the absolute time of the received packet since the sniffer booted.

sleep - stop capturing packets
==============================

The ``sleep`` command disables the radio and ends the receive process.

.. parsed-literal::
:class: highlight
sleep
Configuration
*************

|config|

Building and running
********************

.. |sample path| replace:: :file:`samples/peripheral/802154_sniffer`

.. include:: /includes/build_and_run.txt

.. _802154_sniffer_testing:

Testing the sample
==================

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

1. Connect the development kit to the computer using a USB cable.
Use the development kit's nRF USB port (**J3**).
The kits are assigned a COM port (in Windows) or a ttyACM device (in Linux), visible in the Device Manager or in the :file:`/dev` directory.
#. |connect_terminal|
#. Switch to a radio channel with an ongoing radio traffic:

.. parsed-literal::
:class: highlight
channel *23*
#. Start the capture process:

.. parsed-literal::
:class: highlight
receive
The **LED 1** will start blinking with shorter intervals.

#. If there is radio traffic on the selected channel, the sniffer should print the captured packets:

.. parsed-literal::
:class: highlight
received: 49a85d41a5fffff4110f10270000369756e65619d09428a04b301951821db234460aa5ec4ff506631ef8adb22674683700 power: -39 lqi: 220 time: 15822687
The **LED 4** will toggle its state when a frame is received.

#. Disable the capture:

.. parsed-literal::
:class: highlight
sleep
The **LED 1** will start blinking with longer intervals.

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

This sample uses the following `sdk-nrfxlib`_ libraries:

* :ref:`nrfxlib:mpsl`
* :ref:`nrfxlib:nrf_802154`

This sample uses the following |NCS| libraries:

* :ref:`dk_buttons_and_leds_readme`

This sample uses the following Zephyr libraries:

* :ref:`zephyr:kernel_api`:

* :file:`include/zephyr/kernel.h`
* :file:`include/zephyr/sys/util.h`

* :ref:`zephyr:ieee802154_interface`:

* :file:`include/zephyr/net/ieee802154_radio.h`

* :ref:`zephyr:shell_api`:

* :file:`include/zephyr/shell/shell.h`
* :file:`include/zephyr/shell/shell_uart.h`
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/ {
chosen {
zephyr,shell-uart = &cdc_acm_uart0;
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/ {
chosen {
zephyr,shell-uart = &cdc_acm_uart0;
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/ {
chosen {
zephyr,shell-uart = &cdc_acm_uart0;
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
27 changes: 27 additions & 0 deletions samples/peripheral/802154_sniffer/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Enabling radio driver
CONFIG_NETWORKING=y
CONFIG_IEEE802154=y
CONFIG_IEEE802154_RAW_MODE=y
CONFIG_NET_PKT_TIMESTAMP=y

# Allow sharing the RTC between IEEE 802.15.4 and Zephyr
CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT=3

# Shell configuration
CONFIG_SHELL=y
CONFIG_SHELL_PROMPT_UART=""
CONFIG_SHELL_VT100_COLORS=n

# LED indication
CONFIG_DK_LIBRARY=y

# USB configuration
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_MANUFACTURER="Nordic Semiconductor ASA"
CONFIG_USB_DEVICE_PRODUCT="nRF 802154 Sniffer"
CONFIG_USB_DEVICE_VID=0x1915
CONFIG_USB_DEVICE_PID=0x154b
CONFIG_SHELL_BACKEND_SERIAL_CHECK_DTR=y
CONFIG_UART_LINE_CTRL=y
CONFIG_SHELL_BACKEND_SERIAL_INIT_PRIORITY=51
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y
12 changes: 12 additions & 0 deletions samples/peripheral/802154_sniffer/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sample:
description: IEEE 802.15.4 Sniffer sample
name: IEEE 802.15.4 Sniffer
tests:
sample.peripheral.802154_sniffer:
build_only: true
integration_platforms:
- nrf52840dk_nrf52840
- nrf52840dongle_nrf52840
- nrf5340dk_nrf5340_cpuapp
platform_allow: nrf52840dk_nrf52840 nrf52840dongle_nrf52840 nrf5340dk_nrf5340_cpuapp
tags: ci_build
Loading

0 comments on commit 4bd26e9

Please sign in to comment.