Wi-Fi: Scan

The Scan sample demonstrates how to use the Nordic Semiconductor’s Wi-Fi® chipset to scan for the access points without using the wpa_supplicant.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

Shields

Thingy:53

PCA20053

thingy53

thingy53/nrf5340/cpuapp

nrf7002eb

nRF9161 DK

PCA10153

nrf9161dk

nrf9161dk/nrf9161/ns

nrf7002ek

nRF9160 DK

PCA10090

nrf9160dk

nrf9160dk/nrf9160/ns

nrf7002ek_nrf7001 nrf7002ek_nrf7000 nrf7002ek

nRF7002 DK (emulating nRF7001)

PCA10143

nrf7002dk

nrf7002dk/nrf5340/cpuapp/nrf7001

nRF7002 DK

PCA10143

nrf7002dk

nrf7002dk/nrf5340/cpuapp

nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l15/cpuapp

nrf700x_nrf54l15pdk

nRF54H20 DK

PCA10175

nrf54h20dk

nrf54h20dk/nrf54h20/cpuapp

nrf700x_nrf54h20dk

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp

nrf7002ek_nrf7001 nrf7002ek

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

nrf7002ek_nrf7001 nrf7002ek

Overview

The sample demonstrates Wi-Fi scan operations in the 2.4 GHz and 5 GHz bands. The sample allows you to perform scan based on below profiles.

  • Default scan

  • Active scan

  • Passive scan

  • 2.4 GHz Active scan

  • 2.4 GHz Passive scan

  • 5 GHz Active scan

  • 5 GHz Passive scan

  • Scan only non-overlapping channels in the 2.4 GHz band

  • Scan only non-DFS channels in the 5 GHz band

  • Scan only non-overlapping channels in the 2.4 GHz and non-DFS channels in the 5 GHz band

Using this sample, the development kit can scan for available access points in STA mode.

Configuration

See Configuring and building 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/scan/Kconfig) :

CONFIG_WIFI_MAC_ADDRESS

(string) WiFi MAC address

Wi-Fi MAC address to be used by the sample. If not set, the sample will use the default MAC address (locally administrative). This is only used when the nRF7002 OTP is not programmed with a MAC address.

CONFIG_WIFI_SCAN_INTERVAL_S

(int) Scan interval (seconds)

Specifies the scan interval in seconds.

CONFIG_WIFI_SCAN_BANDS_LIST

(string) Frequency bands to scan

Specifies the frequency bands to scan, as follows: 2 - 2.4 GHz, 5 - 5 GHz, 6 - 6 GHz, “” - All bands allowed by the regulatory domain. Multiple bands can be specified as comma separated band values. Only regulatory domain permitted values are allowed.

CONFIG_WIFI_SCAN_CHAN_LIST

(string) Channel list for scan

Specifies the list of channels used to perform scan.

CONFIG_WIFI_SCAN_DWELL_TIME_ACTIVE

(int) Active scan dwell time

Active scan dwell time (in ms) per channel.

CONFIG_WIFI_SCAN_DWELL_TIME_PASSIVE

(int) Passive scan dwell time

Passive scan dwell time (in ms) per channel.

CONFIG_WIFI_SCAN_PROFILE_DEFAULT

(bool) Scan in all bands and channels

Enable this profile to do Wi-Fi scan in all supported bands and channels.

CONFIG_WIFI_SCAN_PROFILE_ACTIVE

(bool) Active scan

Enable this profile to do active scan where allowed.

CONFIG_WIFI_SCAN_PROFILE_PASSIVE

(bool) Passive scan

Enable this profile to do passive scan on all channels.

CONFIG_WIFI_SCAN_PROFILE_2_4GHz_ACTIVE

(bool) Scan in the 2.4 GHz band using active scan

Enable this profile to scan in the 2.4 GHz band using active scanning where allowed.

CONFIG_WIFI_SCAN_PROFILE_2_4GHz_PASSIVE

(bool) Scan in the 2.4 GHz band using passive scan

Enable this profile to scan in the 2.4 GHz band using passive scanning on all channels.

CONFIG_WIFI_SCAN_PROFILE_5GHz_ACTIVE

(bool) Scan in the 5 GHz band using active scan

Enable this profile to scan in the 5 GHz band using active scanning where allowed.

CONFIG_WIFI_SCAN_PROFILE_5GHz_PASSIVE

(bool) Scan in the 5 GHz band using passive scan

Enable this profile to scan in the 5 GHz band using passive scanning on all channels.

CONFIG_WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_CHAN

(bool) Scan only non-overlapping channels

Enable this profile to scan only non-overlapping channels (1, 6, 11) in the 2.4 GHz band.

CONFIG_WIFI_SCAN_PROFILE_5GHz_NON_DFS_CHAN

(bool) Scan only non-DFS channels

Enable this profile to scan only non-DFS channels (36, 40, 44, 48, 149, 153, 157, 161, 165) in the 5 GHz band.

CONFIG_WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_AND_5GHz_NON_DFS_CHAN

(bool) Scan only non-overlapping and non-DFS channels

Enable this profile to scan only non-overlapping channels (1, 6, 11) in the 2.4 GHz band and non-DFS channels (36, 40, 44, 48, 149, 153, 157, 161, 165) in the 5 GHz band.

Building and running

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

When built as firmware image for a board target with the */ns variant, 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, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

To build for the nRF7002 DK, use the nrf7002dk/nrf5340/cpuapp board target. The following are examples of the CLI commands:

  • Build to fetch only Device scan results

    west build -b nrf7002dk/nrf5340/cpuapp
    
  • Build to fetch only Raw scan results

    west build -b nrf7002dk/nrf5340/cpuapp -- -DCONFIG_WIFI_MGMT_RAW_SCAN_RESULTS=y -DCONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY=y
    
  • Build to fetch both Raw and Device scan results

    west build -b nrf7002dk/nrf5340/cpuapp -- -DCONFIG_WIFI_MGMT_RAW_SCAN_RESULTS=y
    

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:

    • Device scan only results:

      Scan requested
      Num  | SSID                             (len) | Chan | RSSI | Security | BSSID
      1    | abcdef                           6     | 1    | -37  | WPA/WPA2 | aa:aa:aa:aa:aa:aa
      2    | pqrst                            5     | 1    | -65  | WPA/WPA2 | xx:xx:xx:xx:xx:xx
      3    | AZBYCXD                          7     | 1    | -41  | WPA/WPA2 | yy:yy:yy:yy:yy:yy
      Scan request done
      
    • Raw scan only results:

      Scan requested
      Num  | len   | Frequency | RSSI | RAW_DATA(32 bytes)
      1    | 299   | 2412 | -44  | 50 00 3A 01 F4 CE 36 00 10 CE D4 BD 4F E1 F5 33 D4 BD 4F E1 F5 33 A0 7F 0B 05 75 7F D8 00 00 00
      2    | 430   | 2412 | -37  | 50 00 3A 01 F4 CE 36 00 10 CE 3C 7C 3F DA DF 38 3C 7C 3F DA DF 38 90 11 69 36 EC 8A 02 00 00 00
      3    | 284   | 2412 | -45  | 50 00 3A 01 F4 CE 36 00 10 CE D4 BD 4F 21 F5 38 D4 BD 4F 21 F5 38 20 CF 7B 20 75 7F D8 00 00 00
      4    | 299   | 2412 | -43  | 50 00 3A 01 F4 CE 36 00 10 CE D4 BD 4F E1 F5 33 D4 BD 4F E1 F5 33 B0 7F EC 2B 75 7F D8 00 00 00
      5    | 409   | 2412 | -38  | 50 00 3A 01 F4 CE 36 00 10 CE A0 36 BC 56 41 E0 A0 36 BC 56 41 E0 60 E2 C7 A5 0F 90 0D 00 00 00
      Scan request done
      
    • Raw scan and Device scan results:

      Scan requested
      Num  | len   | Frequency | RSSI | RAW_DATA(32 bytes)
      1    | 299   | 2412 | -44  | 50 00 3A 01 F4 CE 36 00 10 CE D4 BD 4F E1 F5 33 D4 BD 4F E1 F5 33 A0 7F 0B 05 75 7F D8 00 00 00
      2    | 430   | 2412 | -37  | 50 00 3A 01 F4 CE 36 00 10 CE 3C 7C 3F DA DF 38 3C 7C 3F DA DF 38 90 11 69 36 EC 8A 02 00 00 00
      3    | 284   | 2412 | -45  | 50 00 3A 01 F4 CE 36 00 10 CE D4 BD 4F 21 F5 38 D4 BD 4F 21 F5 38 20 CF 7B 20 75 7F D8 00 00 00
      4    | abcdef                           6     | 1    | -37  | WPA/WPA2 | aa:aa:aa:aa:aa:aa
      5    | pqrst                            5     | 1    | -65  | WPA/WPA2 | xx:xx:xx:xx:xx:xx
      6    | AZBYCXD                          7     | 1    | -41  | WPA/WPA2 | yy:yy:yy:yy:yy:yy
      Scan request done
      
    • Default scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    |                                  0   | 11   | -39  | Open     | C2:A5:11:A2:B1:E2
      2    | abcdefg                          7   | 11   | -39  | Open     | BC:A5:11:A2:B1:E2
      3    | hijklmno                         8   | 48   | -43  | Open     | 00:22:CF:E6:AE:99
      Scan request done
      
    • Active scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    |                                  0   | 11   | -39  | Open     | C2:A5:11:A2:B1:E2
      2    | abcdefg                          7   | 11   | -39  | Open     | BC:A5:11:A2:B1:E2
      3    | hijklmno                         8   | 48   | -43  | Open     | 00:22:CF:E6:AE:99
      Scan request done
      
    • Passive scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    |                                  0   | 11   | -39  | Open     | C2:A5:11:A2:B1:E2
      2    | abcdefg                          7   | 11   | -39  | Open     | BC:A5:11:A2:B1:E2
      3    | hijklmno                         8   | 48   | -43  | Open     | 00:22:CF:E6:AE:99
      Scan request done
      
    • 2.4 GHz Active scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    | abcdefg                          7   | 11   | -39  | Open     | BC:A5:11:A2:B1:E2
      Scan request done
      
    • 2.4 GHz Passive scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    | abcdefg                          7   | 11   | -39  | Open     | BC:A5:11:A2:B1:E2
      Scan request done
      
    • 5 GHz Active scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    | pqrst                             5  | 48   | -43  | Open     | 00:22:CF:E6:AE:99
      Scan request done
      
    • 5 GHz Passive scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    | pqrst                             5  | 48   | -43  | Open     | 00:22:CF:E6:AE:99
      Scan request done
      
    • 2.4 GHz non-overlapping channels based scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    | abcdefg                          7   | 11   | -39  | Open     | BC:A5:11:A2:B1:E2
      2    | mnopq                            5   | 6    | -75  | Open     | F0:1D:2D:73:C4:C1
      3    | pqrst                            5   | 1    | -77  | Open     | DC:33:3D:AB:D1:A8
      Scan request done
      
    • 5 GHz non-DFS channels based scan results:

      Scan requested
      Num | SSID                           (len) | Chan | RSSI | Security | BSSID
      1   | ABCDEFG                          7   | 36   | -70  | Open     | 48:5D:35:9C:4A:0B
      2   | PQRST                            5   | 161  | -78  | Open     | 50:EB:F6:08:E1:6C
      3   | abcd                             4   | 165  | -78  | WPA/WPA2 | 08:86:3B:8B:52:9E
      4   | KLMNO                            5   | 40   | -90  | Open     | E8:94:F6:C7:D8:8E
      Scan request done
      
    • 2.4 GHz non-overlapping and 5 GHz non-DFS channels based scan results:

      Scan requested
      Num  | SSID                           (len) | Chan | RSSI | Security | BSSID
      1    | pqrst                            5   | 48   | -43  | Open     | 00:22:CF:E6:AE:99
      2    | abcdefg                          7   | 11   | -39  | Open     | BC:A5:11:A2:B1:E2
      3    | ABCDE                            5   | 40   | -90  | Open     | E8:94:F6:C7:D8:8E
      Scan request done