Skip to content

Commit d4008a4

Browse files
krish2718carlescufi
authored andcommitted
Implement scan parameters
This adds few profiles to control the scan using the scan parameters. Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
1 parent 7db6842 commit d4008a4

File tree

3 files changed

+162
-3
lines changed

3 files changed

+162
-3
lines changed

scan_bm/Kconfig

+112-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,115 @@ module = NR70_SCAN_BM_SAMPLE
1414
module-str = nRF70 BM scan sample
1515
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
1616

17-
endmenu
17+
config WIFI_MAC_ADDRESS
18+
string "WiFi MAC address"
19+
default "F6:CE:36:00:00:01"
20+
help
21+
Wi-Fi MAC address to be used by the sample. If not set, the sample will
22+
use the default MAC address (locally administrative). This is only used
23+
when the nRF7002 OTP is not programmed with a MAC address.
24+
25+
config WIFI_SCAN_INTERVAL_S
26+
int "Scan interval (seconds)"
27+
default 10
28+
help
29+
Specifies the scan interval in seconds.
30+
31+
config WIFI_SCAN_BANDS_LIST
32+
string "Frequency bands to scan"
33+
default "2" if WIFI_SCAN_PROFILE_2_4GHz_ACTIVE || WIFI_SCAN_PROFILE_2_4GHz_PASSIVE || WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_CHAN
34+
default "5" if WIFI_SCAN_PROFILE_5GHz_ACTIVE || WIFI_SCAN_PROFILE_5GHz_PASSIVE || WIFI_SCAN_PROFILE_5GHz_NON_DFS_CHAN
35+
default "2,5" if WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_AND_5GHz_NON_DFS_CHAN
36+
default ""
37+
help
38+
Specifies the frequency bands to scan, as follows:
39+
2 - 2.4 GHz,
40+
5 - 5 GHz,
41+
6 - 6 GHz,
42+
"" - All bands allowed by the regulatory domain.
43+
Multiple bands can be specified as comma separated band values.
44+
Only regulatory domain permitted values are allowed.
45+
46+
config WIFI_SCAN_CHAN_LIST
47+
string "Channel list for scan"
48+
default "2:1,6,11" if WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_CHAN
49+
default "5:36,40,44,48,149,153,157,161,165" if WIFI_SCAN_PROFILE_5GHz_NON_DFS_CHAN
50+
default "2:1,6,11_5:36,40,44,48,149,153,157,161,165" if WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_AND_5GHz_NON_DFS_CHAN
51+
default ""
52+
help
53+
Specifies the list of channels used to perform scan.
54+
55+
config WIFI_SCAN_DWELL_TIME_ACTIVE
56+
int "Active scan dwell time"
57+
default 50
58+
range 5 1000
59+
help
60+
Active scan dwell time (in ms) per channel.
61+
62+
config WIFI_SCAN_DWELL_TIME_PASSIVE
63+
int "Passive scan dwell time"
64+
default 130
65+
range 10 1000
66+
help
67+
Passive scan dwell time (in ms) per channel.
68+
69+
choice
70+
prompt "Choose a WiFi Scan Profile"
71+
72+
config WIFI_SCAN_PROFILE_DEFAULT
73+
bool "Scan in all bands and channels"
74+
help
75+
Enable this profile to do Wi-Fi scan in all supported bands and channels.
76+
77+
config WIFI_SCAN_PROFILE_ACTIVE
78+
bool "Active scan"
79+
help
80+
Enable this profile to do active scan where allowed.
81+
82+
config WIFI_SCAN_PROFILE_PASSIVE
83+
bool "Passive scan"
84+
help
85+
Enable this profile to do passive scan on all channels.
86+
87+
config WIFI_SCAN_PROFILE_2_4GHz_ACTIVE
88+
bool "Scan in the 2.4 GHz band using active scan"
89+
help
90+
Enable this profile to scan in the 2.4 GHz band using active scanning where allowed.
91+
92+
config WIFI_SCAN_PROFILE_2_4GHz_PASSIVE
93+
bool "Scan in the 2.4 GHz band using passive scan"
94+
help
95+
Enable this profile to scan in the 2.4 GHz band using passive scanning on all channels.
96+
97+
config WIFI_SCAN_PROFILE_5GHz_ACTIVE
98+
bool "Scan in the 5 GHz band using active scan"
99+
help
100+
Enable this profile to scan in the 5 GHz band using active scanning where allowed.
101+
102+
config WIFI_SCAN_PROFILE_5GHz_PASSIVE
103+
bool "Scan in the 5 GHz band using passive scan"
104+
help
105+
Enable this profile to scan in the 5 GHz band using passive scanning on all channels.
106+
107+
config WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_CHAN
108+
bool "Scan only non-overlapping channels"
109+
help
110+
Enable this profile to scan only non-overlapping channels (1, 6, 11)
111+
in the 2.4 GHz band.
112+
113+
config WIFI_SCAN_PROFILE_5GHz_NON_DFS_CHAN
114+
bool "Scan only non-DFS channels"
115+
help
116+
Enable this profile to scan only non-DFS channels (36, 40, 44,
117+
48, 149, 153, 157, 161, 165) in the 5 GHz band.
118+
119+
config WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_AND_5GHz_NON_DFS_CHAN
120+
bool "Scan only non-overlapping and non-DFS channels"
121+
help
122+
Enable this profile to scan only non-overlapping channels
123+
(1, 6, 11) in the 2.4 GHz band and non-DFS channels (36, 40, 44,
124+
48, 149, 153, 157, 161, 165) in the 5 GHz band.
125+
126+
endchoice
127+
128+
endmenu

scan_bm/prj.conf

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
CONFIG_NRF70_BM_LIB=y
88
CONFIG_MAIN_STACK_SIZE=4200
99

10+
# for Wi-Fi utils
11+
CONFIG_NETWORKING=y
12+
CONFIG_NET_MGMT=y
13+
CONFIG_NET_MGMT_EVENT=y
14+
CONFIG_NET_MGMT_EVENT_INFO=y
15+
CONFIG_NET_L2_WIFI_MGMT=y
16+
1017
# Debugs
1118
CONFIG_LOG=y
1219
CONFIG_LOG_MODE_IMMEDIATE=y

scan_bm/src/main.c

+43-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include <zephyr/kernel.h>
1212
#include <zephyr/logging/log.h>
1313
#include <zephyr/logging/log_ctrl.h>
14+
#include <zephyr/net/wifi_mgmt.h>
15+
#include <zephyr/net/wifi_utils.h>
16+
17+
#include <stdlib.h>
1418

1519
LOG_MODULE_REGISTER(nrf70_scan_bm, CONFIG_NR70_SCAN_BM_SAMPLE_LOG_LEVEL);
1620

@@ -53,9 +57,43 @@ void scan_result_cb(struct nrf70_scan_result *entry)
5357
nrf70_mfp_txt(entry->mfp));
5458
}
5559

60+
static int prepare_scan_params(struct nrf70_scan_params *params)
61+
{
62+
int band_str_len = sizeof(CONFIG_WIFI_SCAN_BANDS_LIST);
63+
64+
if (band_str_len - 1) {
65+
char *buf = malloc(band_str_len);
66+
67+
if (!buf) {
68+
LOG_ERR("Malloc Failed");
69+
return -EINVAL;
70+
}
71+
strcpy(buf, CONFIG_WIFI_SCAN_BANDS_LIST);
72+
if (wifi_utils_parse_scan_bands(buf, &params->bands)) {
73+
LOG_ERR("Incorrect value(s) in CONFIG_WIFI_SCAN_BANDS_LIST: %s",
74+
CONFIG_WIFI_SCAN_BANDS_LIST);
75+
free(buf);
76+
return -ENOEXEC;
77+
}
78+
free(buf);
79+
}
80+
81+
if (sizeof(CONFIG_WIFI_SCAN_CHAN_LIST) - 1) {
82+
if (wifi_utils_parse_scan_chan(CONFIG_WIFI_SCAN_CHAN_LIST,
83+
(struct wifi_band_channel *)params->band_chan,
84+
ARRAY_SIZE(params->band_chan))) {
85+
LOG_ERR("Incorrect value(s) in CONFIG_WIFI_SCAN_CHAN_LIST: %s",
86+
CONFIG_WIFI_SCAN_CHAN_LIST);
87+
return -ENOEXEC;
88+
}
89+
}
90+
91+
return 0;
92+
}
93+
5694
int main(void)
5795
{
58-
//struct nrf70_scan_params scan_params = { 0 };
96+
struct nrf70_scan_params scan_params = { 0 };
5997
int ret;
6098

6199
LOG_INF("WiFi scan sample application using nRF70 Bare Metal library");
@@ -65,10 +103,13 @@ int main(void)
65103

66104
LOG_INF("Scanning for WiFi networks...");
67105

106+
// Prepare scan parameters
107+
CHECK_RET(prepare_scan_params(&scan_params));
108+
68109
while (1)
69110
{
70111
// Start scanning for WiFi networks
71-
CHECK_RET(nrf70_scan_start(NULL, scan_result_cb));
112+
CHECK_RET(nrf70_scan_start(&scan_params, scan_result_cb));
72113

73114
// Wait for the scan to complete or timeout
74115
unsigned int timeout = 30000;

0 commit comments

Comments
 (0)