drivers: wifi: siwx91x: Add support for BG Scan and Roaming#87037
Conversation
Nitin-Pandey-01
commented
Mar 13, 2025
- Added support for background scan
- Resolved the dwell time related bugs
- Updated the case for rejecting scan in channel 12, 13 and 14
3bf25a8 to
2f3c6fb
Compare
2f3c6fb to
f669acc
Compare
94605f3 to
56e9fce
Compare
195ba97 to
77d28b4
Compare
77d28b4 to
0ab3434
Compare
| { | ||
| 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}; |
There was a problem hiding this comment.
The prefered syntax is: = { };
| #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 |
There was a problem hiding this comment.
I don't think it it is useful to expose these values.
There was a problem hiding this comment.
Removed the macros and added Raw numbers for checking edge cases
| SL_WIFI_MAX_ACTIVE_SCAN_TIME_MS) { | ||
| LOG_ERR("Invalid active scan dwell time"); | ||
| return -EINVAL; | ||
| } |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Indeed, we probably also need a couple of threshold values.
| advanced_scan_config.passive_channel_time = | ||
| z_scan_config->dwell_time_passive; | ||
| } | ||
| advanced_scan_config.passive_channel_time = SL_WIFI_ADV_PASSIVE_SCAN_DURATION; |
There was a problem hiding this comment.
Previous assignments to this field are probably useless.
There was a problem hiding this comment.
Shifted the assignments of these fields at the declaration time.
| 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 |
| help | ||
| Enable this option to configure roaming parameters, | ||
| improving connectivity and performance during | ||
| transitions between access points. |
There was a problem hiding this comment.
Explain the roaming will be enable as soon as the background scan is enabled.
| bool "Roam with Deauth enable/disable" | ||
| depends on WIFI_MGMT_ENABLE_ROAM | ||
| help | ||
| Enable this to roam using deauthentication frames. |
There was a problem hiding this comment.
Can you explain a bit how this option diverge of the usual roaming?
There was a problem hiding this comment.
This enables roaming using Deauthentication frames, whereas, by default, the firmware performs roaming using Null data packets
| depends on WIFI_MGMT_ENABLE_ROAM | ||
| help | ||
| Sets the default roam threshold. Lower values trigger | ||
| earlier roaming; higher values delay it. |
There was a problem hiding this comment.
The difference with the previous option is unclear.
There was a problem hiding this comment.
- Trigger level - determines when to start searching for a new AP. Also known as Roaming threshold.
- 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.
| /* | ||
| * Use legacy roam configuration values if enabled, | ||
| * otherwise use user-defined values | ||
| */ |
There was a problem hiding this comment.
I don't understand this comment. I don't see when legacy values are used.
b71b1d7 to
1848d2b
Compare
| #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 |
There was a problem hiding this comment.
You don't need to keep them in the header file.
In addition, I am not sure they are helpful.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
We documented the BG Scan values and shifted parameters to Kconfig file
| if (dwell_time_active < 5 || dwell_time_active > 1000) { | ||
| LOG_ERR("Invalid active scan dwell time"); | ||
| return -EINVAL; | ||
| } |
There was a problem hiding this comment.
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;
}
| 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); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
This is done by Clang format or else I am getting compliance errors
There was a problem hiding this comment.
Probably your line was too long. Is it still the case?
There was a problem hiding this comment.
No, The issue got resolved, Updated the code.
| 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); |
There was a problem hiding this comment.
Align to the opening parenthesis.
There was a problem hiding this comment.
This is done by Clang format or else I am getting compliance errors
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
The error was due to a line being too long, but it was resolved, and I updated the code as recommended.
1848d2b to
91270cd
Compare
fee186b to
ac0034f
Compare
| } else { | ||
| sl_scan_config.type = SL_WIFI_SCAN_TYPE_PASSIVE; | ||
| } | ||
|
|
There was a problem hiding this comment.
A blank line before a closing brace is probably not useful.
- 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>
ac0034f to
79c359e
Compare