Skip to content

drivers: wifi: siwx91x: Add support for BG Scan and Roaming#87037

Merged
kartben merged 3 commits into
zephyrproject-rtos:mainfrom
Nitin-Pandey-01:add/bg-scan-handling
Apr 14, 2025
Merged

drivers: wifi: siwx91x: Add support for BG Scan and Roaming#87037
kartben merged 3 commits into
zephyrproject-rtos:mainfrom
Nitin-Pandey-01:add/bg-scan-handling

Conversation

@Nitin-Pandey-01
Copy link
Copy Markdown

  • Added support for background scan
  • Resolved the dwell time related bugs
  • Updated the case for rejecting scan in channel 12, 13 and 14

@Nitin-Pandey-01 Nitin-Pandey-01 force-pushed the add/bg-scan-handling branch 2 times, most recently from 3bf25a8 to 2f3c6fb Compare March 13, 2025 11:34
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
@Nitin-Pandey-01 Nitin-Pandey-01 force-pushed the add/bg-scan-handling branch 3 times, most recently from 94605f3 to 56e9fce Compare April 1, 2025 10:13
@Nitin-Pandey-01 Nitin-Pandey-01 changed the title Add support for BG Scan Add support for BG Scan and Roaming Apr 1, 2025
Comment thread soc/silabs/silabs_siwx91x/siwg917/nwp.c Outdated
@Nitin-Pandey-01 Nitin-Pandey-01 force-pushed the add/bg-scan-handling branch 4 times, most recently from 195ba97 to 77d28b4 Compare April 1, 2025 13:18
@Nitin-Pandey-01 Nitin-Pandey-01 marked this pull request as ready for review April 1, 2025 13:27
@jhedberg jhedberg changed the title Add support for BG Scan and Roaming drivers: wifi: siwx91x: Add support for BG Scan and Roaming Apr 1, 2025
@asmellby asmellby requested a review from jerome-pouiller April 2, 2025 08:36
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
{
sl_wifi_scan_configuration_t sl_scan_config = { };
sl_wifi_scan_configuration_t sl_scan_config = {};
sl_wifi_advanced_scan_configuration_t advanced_scan_config = {0};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefered syntax is: = { };

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.h Outdated
#define SL_WIFI_MIN_ACTIVE_SCAN_TIME_MS 5
#define SL_WIFI_MAX_ACTIVE_SCAN_TIME_MS 1000
#define SL_WIFI_MIN_PASSIVE_SCAN_TIME_MS 10
#define SL_WIFI_MAX_PASSIVE_SCAN_TIME_MS 1000
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it it is useful to expose these values.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the macros and added Raw numbers for checking edge cases

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
SL_WIFI_MAX_ACTIVE_SCAN_TIME_MS) {
LOG_ERR("Invalid active scan dwell time");
return -EINVAL;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function starts to be too complex (5 levels of indentation, 150 lines).

I believe you can place the input validation for dwell interval with the other ones on the top the function:

if (z_scan_config->dwell_time_active &&
    (z_scan_config->dwell_time_active < SL_WIFI_MIN_ACTIVE_SCAN_TIME_MS ||
     z_scan_config->dwell_time_active > SL_WIFI_MAX_ACTIVE_SCAN_TIME_MS)) {
        return -EINVAL;
}

You may also introduce one function to take care of sl_wifi_set_advanced_scan_configuration() and another one to take care of sl_si91x_configure_timeout().

Note, I understand SL_WIFI_(MAX|MIN)_(ACTIVE|PASSIVE)_SCAN_TIME_MS are there to avoid magic value in the code. However, since they are used only once in the code and their names do not help to understand from where these value are coming from, I think you could use raw numbers here (same comment for the default values for advanced_scan_config).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, Updated the code as suggested

sl_scan_config.type = SL_WIFI_SCAN_TYPE_ACTIVE;
ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT,
z_scan_config->dwell_time_active);
if (sidev->state == WIFI_STATE_COMPLETED) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it wouldn't make sense to add a field int period to z_scan_config. We would start a background scan of period != 0. What do you think @jukkar ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a bgscan support in struct wifi_scan_params, and if we want to add it, we need more than just period, no?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we probably also need a couple of threshold values.

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
advanced_scan_config.passive_channel_time =
z_scan_config->dwell_time_passive;
}
advanced_scan_config.passive_channel_time = SL_WIFI_ADV_PASSIVE_SCAN_DURATION;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous assignments to this field are probably useless.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shifted the assignments of these fields at the declaration time.

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
advanced_scan_config.enable_instant_scan = SL_WIFI_ENABLE_INSTANT_SCAN;
roam_configuration.trigger_level = SL_WIFI_NEVER_ROAM;

#if CONFIG_WIFI_MGMT_ENABLE_ROAM
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use IS_ENABLE().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment thread drivers/wifi/siwx91x/Kconfig.siwx91x Outdated
help
Enable this option to configure roaming parameters,
improving connectivity and performance during
transitions between access points.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain the roaming will be enable as soon as the background scan is enabled.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread drivers/wifi/siwx91x/Kconfig.siwx91x Outdated
bool "Roam with Deauth enable/disable"
depends on WIFI_MGMT_ENABLE_ROAM
help
Enable this to roam using deauthentication frames.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit how this option diverge of the usual roaming?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables roaming using Deauthentication frames, whereas, by default, the firmware performs roaming using Null data packets

Comment thread drivers/wifi/siwx91x/Kconfig.siwx91x Outdated
depends on WIFI_MGMT_ENABLE_ROAM
help
Sets the default roam threshold. Lower values trigger
earlier roaming; higher values delay it.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference with the previous option is unclear.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Trigger level - determines when to start searching for a new AP. Also known as Roaming threshold.
  2. Trigger level change - determines the signal difference needed to switch to a new AP. Also known as Roaming Hysteresis. It tells when to actually switch to a new AP.

So, In short roam threshold specifies the signal strength at which the device begins searching for a better access point, while roam hysteresis ensures the new access point's signal is sufficiently stronger than the current one to avoid unnecessary or frequent switching.

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
/*
* Use legacy roam configuration values if enabled,
* otherwise use user-defined values
*/
Copy link
Copy Markdown
Contributor

@jerome-pouiller jerome-pouiller Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment. I don't see when legacy values are used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comment

Copy link
Copy Markdown
Contributor

@krish2718 krish2718 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please split the commit cac7460 in to two? implement dwell times and adding bgscan?

@Nitin-Pandey-01 Nitin-Pandey-01 force-pushed the add/bg-scan-handling branch 2 times, most recently from b71b1d7 to 1848d2b Compare April 4, 2025 11:12
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.h Outdated
#define SL_WIFI_ADV_PASSIVE_SCAN_DURATION 20
#define SL_WIFI_ADV_MULTIPROBE 0
#define SL_WIFI_ADV_SCAN_PERIODICITY 10
#define SL_WIFI_ENABLE_INSTANT_SCAN 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to keep them in the header file.

In addition, I am not sure they are helpful.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are useful because they define the parameters for background scanning, which controls how it works. As these parameters are set in application only with recommended values, so I moved them to the header file. What do you suggest ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the context of the code, the user won't be able to modify these values anyway. So:

  • Either a precise documentation have to be provided (and the values can migrate to Kconfig)
  • Or the value are directly used in the code and the user have the whole context to figure out the impact.

(Note, my comment only apply because these symbols are only used once and in the context of the initialisation of a struct)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We documented the BG Scan values and shifted parameters to Kconfig file

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
if (dwell_time_active < 5 || dwell_time_active > 1000) {
LOG_ERR("Invalid active scan dwell time");
return -EINVAL;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably factorize this code at the top of the function:

        if (dwell_time_active && (dwell_time_active < 5 || dwell_time_active > 1000)) {
                return -EINVAL;
        }
        if (dwell_time_passive && (dwell_time_passive < 10 || dwell_time_passive > 1000)) {
                return -EINVAL;
        }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
if (sidev->state == WIFI_STATE_COMPLETED) {
siwx91x_configure_scan_dwell_time(
SL_WIFI_SCAN_TYPE_ADV_SCAN, z_scan_config->dwell_time_active,
z_scan_config->dwell_time_passive, &advanced_scan_config);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align to the opening parenthese:

		siwx91x_configure_scan_dwell_time(SL_WIFI_SCAN_TYPE_ADV_SCAN,
						  z_scan_config->dwell_time_active,
						  z_scan_config->dwell_time_passive,
						  &advanced_scan_config);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done by Clang format or else I am getting compliance errors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably your line was too long. Is it still the case?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, The issue got resolved, Updated the code.

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
sl_scan_config.type = SL_WIFI_SCAN_TYPE_ACTIVE;
ret = siwx91x_configure_scan_dwell_time(
SL_WIFI_SCAN_TYPE_ACTIVE, z_scan_config->dwell_time_active,
z_scan_config->dwell_time_passive, NULL);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align to the opening parenthesis.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done by Clang format or else I am getting compliance errors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the errors exactly? Too long lines? Seems like some refactoring to helper functions or rethinking the function flow to avoid deep indentation would be a good idea.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error was due to a line being too long, but it was resolved, and I updated the code as recommended.

Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
Comment thread drivers/wifi/siwx91x/Kconfig.siwx91x Outdated
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c
@Nitin-Pandey-01 Nitin-Pandey-01 force-pushed the add/bg-scan-handling branch 3 times, most recently from fee186b to ac0034f Compare April 9, 2025 04:02
Comment thread drivers/wifi/siwx91x/siwx91x_wifi.c Outdated
} else {
sl_scan_config.type = SL_WIFI_SCAN_TYPE_PASSIVE;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank line before a closing brace is probably not useful.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

- Added support for background scan
  and configured the default values
  of BG scan configuration

Signed-off-by: Nitin Pandey <nitin.pandey@silabs.com>
- Verified and configured scan
  dwell time for active, passive
  and advance scan

Signed-off-by: Nitin Pandey <nitin.pandey@silabs.com>
- Defined Kconfig macros for Roam config
- Added set roam configuration API call
  after BGSCAN

Signed-off-by: Nitin Pandey <nitin.pandey@silabs.com>
@kartben kartben merged commit 50e3609 into zephyrproject-rtos:main Apr 14, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants