From 9daee9983364d38dc29c5ac3766f392a403d1528 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Thu, 26 Dec 2024 20:22:16 +0530 Subject: [PATCH] samples: wifi: scan: Fix build error in scan sample 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 --- samples/wifi/scan/Kconfig | 13 +++++++ samples/wifi/scan/src/main.c | 74 +++++------------------------------- 2 files changed, 23 insertions(+), 64 deletions(-) diff --git a/samples/wifi/scan/Kconfig b/samples/wifi/scan/Kconfig index 7d67b01418f7..7f2daafa175f 100644 --- a/samples/wifi/scan/Kconfig +++ b/samples/wifi/scan/Kconfig @@ -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" @@ -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. diff --git a/samples/wifi/scan/src/main.c b/samples/wifi/scan/src/main.c index 5bcfdea2a4d5..335012965afc 100644 --- a/samples/wifi/scan/src/main.c +++ b/samples/wifi/scan/src/main.c @@ -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); @@ -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) { @@ -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, ¶ms, sizeof(struct wifi_scan_params))) { LOG_ERR("Scan request failed");