Skip to content

Commit

Permalink
samples: wifi: scan: Fix build error in scan sample
Browse files Browse the repository at this point in the history
When options that set the channel are enabled, non-existent member
"chan" is used instead of "band_chan" causing build error.

Rejig the options to simplify the scan configuration processing that
also fixes the build error.

Signed-off-by: Chaitanya Tata <[email protected]>
  • Loading branch information
krish2718 authored and nordicjm committed Jan 9, 2025
1 parent 315b706 commit 9daee99
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 64 deletions.
13 changes: 13 additions & 0 deletions samples/wifi/scan/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ config WIFI_SCAN_DWELL_TIME_PASSIVE
help
Passive scan dwell time (in ms) per channel.

# Hidden options to select the scan type
config WIFI_SCAN_TYPE_ACTIVE
bool

config WIFI_SCAN_TYPE_PASSIVE
bool

choice
prompt "Choose a WiFi Scan Profile"

Expand All @@ -70,31 +77,37 @@ config WIFI_SCAN_PROFILE_DEFAULT

config WIFI_SCAN_PROFILE_ACTIVE
bool "Active scan"
select WIFI_SCAN_TYPE_ACTIVE
help
Enable this profile to do active scan where allowed.

config WIFI_SCAN_PROFILE_PASSIVE
bool "Passive scan"
select WIFI_SCAN_TYPE_PASSIVE
help
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"
select WIFI_SCAN_TYPE_ACTIVE
help
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"
select WIFI_SCAN_TYPE_PASSIVE
help
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"
select WIFI_SCAN_TYPE_ACTIVE
help
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"
select WIFI_SCAN_TYPE_PASSIVE
help
Enable this profile to scan in the 5 GHz band using passive scanning on all channels.

Expand Down
74 changes: 10 additions & 64 deletions samples/wifi/scan/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,68 +40,6 @@ LOG_MODULE_REGISTER(scan, CONFIG_LOG_DEFAULT_LEVEL);
#define SCAN_TIMEOUT_MS 10000

static uint32_t scan_result;

const struct wifi_scan_params tests[] = {
#ifdef CONFIG_WIFI_SCAN_PROFILE_DEFAULT
{
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_ACTIVE
{
.scan_type = WIFI_SCAN_TYPE_ACTIVE,
.dwell_time_active = CONFIG_WIFI_SCAN_DWELL_TIME_ACTIVE
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_PASSIVE
{
.scan_type = WIFI_SCAN_TYPE_PASSIVE,
.dwell_time_passive = CONFIG_WIFI_SCAN_DWELL_TIME_PASSIVE
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_2_4GHz_ACTIVE
{
.scan_type = WIFI_SCAN_TYPE_ACTIVE,
.bands = 0
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_2_4GHz_PASSIVE
{
.scan_type = WIFI_SCAN_TYPE_PASSIVE,
.bands = 0
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_5GHz_ACTIVE
{
.scan_type = WIFI_SCAN_TYPE_ACTIVE,
.bands = 0
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_5GHz_PASSIVE
{
.scan_type = WIFI_SCAN_TYPE_PASSIVE,
.bands = 0
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_CHAN
{
.bands = 0,
.chan = { {0, 0} }
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_5GHz_NON_DFS_CHAN
{
.bands = 0,
.chan = { {0, 0} }
},
#endif
#ifdef CONFIG_WIFI_SCAN_PROFILE_2_4GHz_NON_OVERLAP_AND_5GHz_NON_DFS_CHAN
{
.bands = 0,
.chan = { {0, 0} }
},
#endif
};

static struct net_mgmt_event_callback wifi_shell_mgmt_cb;

K_SEM_DEFINE(scan_sem, 0, 1);
Expand Down Expand Up @@ -257,8 +195,7 @@ static int wifi_scan(void)
{
struct net_if *iface = net_if_get_default();
int band_str_len;

struct wifi_scan_params params = tests[0];
struct wifi_scan_params params = { 0 };

band_str_len = sizeof(CONFIG_WIFI_SCAN_BANDS_LIST);
if (band_str_len - 1) {
Expand Down Expand Up @@ -287,6 +224,15 @@ static int wifi_scan(void)
}
}

params.dwell_time_passive = CONFIG_WIFI_SCAN_DWELL_TIME_PASSIVE;
params.dwell_time_active = CONFIG_WIFI_SCAN_DWELL_TIME_ACTIVE;

if (IS_ENABLED(CONFIG_WIFI_SCAN_TYPE_PASSIVE)) {
params.scan_type = WIFI_SCAN_TYPE_PASSIVE;
} else {
params.scan_type = WIFI_SCAN_TYPE_ACTIVE;
}

if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, &params,
sizeof(struct wifi_scan_params))) {
LOG_ERR("Scan request failed");
Expand Down

0 comments on commit 9daee99

Please sign in to comment.