Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: wifi: siwx917: Add support for advanced scan options #86

Conversation

ArunmaniAlagarsamy2710
Copy link
Contributor

This commit adds support for the following scan functionalities

  • Single and multi-channel scan
  • Direct SSID scan
  • Dwell time configuration for both active and passive scans
  • Maximum BSS count configuration for the 2.4 GHz band

Since the device operates solely on the 2.4 GHz frequency band, this enhancement enables it to send probe requests and listen for beacon frames on specified channels, improving scan efficiency and customization.

@ArunmaniAlagarsamy2710 ArunmaniAlagarsamy2710 requested a review from a team as a code owner January 29, 2025 12:35
@ArunmaniAlagarsamy2710
Copy link
Contributor Author

@jhedberg @jerome-pouiller Please help to review.

LOG_INF("No APs detected");
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not declare variables after statements.

BTW, I don't think we need to log anything if scan_count == 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, calling this function with index >= scan_count is a bug.

.band = (result->scan_info[item].rf_channel > 0 &&
result->scan_info[item].rf_channel <= 14) ?
WIFI_FREQ_BAND_2_4_GHZ
: WIFI_FREQ_BAND_UNKNOWN,
Copy link
Contributor

@jerome-pouiller jerome-pouiller Jan 30, 2025

Choose a reason for hiding this comment

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

Don't abuse of the trinary operator. I suggest:

.band = WIFI_FREQ_BAND_2_4_GHZ,
[...]

if (result->scan_info[item].rf_channel <= 0 || result->scan_info[item].rf_channel > 14)) {
    LOG_WARN("Unexpected scan result");
    tmp.band = WIFI_FREQ_BAND_UNKNOWN;
}


if (sidev->max_bss_cnt) {
result->scan_count = (sidev->max_bss_cnt > result->scan_count) ?
result->scan_count : sidev->max_bss_cnt;
Copy link
Contributor

Choose a reason for hiding this comment

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

MIN(result->scan_count, sidev->max_bss_cnt);

BTW, I suggest to avoid change the input argument. Rather use a local variable to store this value.

@@ -185,6 +194,17 @@ static unsigned int siwx917_on_scan(sl_wifi_event_t event, sl_wifi_scan_result_t
if (!sidev->scan_res_cb) {
return -EFAULT;
}

if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

SL_WIFI_CHECK_IF_EVENT_FAILED() looks useless. event & SL_WIFI_EVENT_FAIL_INDICATION is simpler and clearer for anyone.


if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) {
memset(result, 0, sizeof(*result));
siwx917_report_scan_res(sidev, result, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is purpose of this call?

#ifdef CONFIG_WIFI_MGMT_SCAN_CHAN_MAX_MANUAL
for (int i = 0; i < WIFI_MGMT_SCAN_CHAN_MAX_MANUAL; i++) {
sl_scan_config.channel_bitmap_2g4 |= (1 <<
(z_scan_config->band_chan[i].channel - 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use BIT()

strncpy(ssid.value, z_scan_config->ssids[0], WIFI_SSID_MAX_LEN);
ssid.length = strlen(z_scan_config->ssids[0]);
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather use IF_ENABLED() when possible.

@@ -17,6 +17,7 @@
struct siwx917_dev {
struct net_if *iface;
sl_mac_address_t macaddr;
uint16_t max_bss_cnt;
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this variable does not allow to understand what it does. Rename to scan_max_bss_cnt and place it beside scan_res_cb.

if (ret != SL_STATUS_IN_PROGRESS) {
LOG_ERR("Failed to start scan: %d", ret);
Copy link
Contributor

Choose a reason for hiding this comment

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

This error will appear in the user interface even if the case is properly handled by the upper layers. I suggest tot drop it.

sidev->scan_res_cb = cb;
ret = sl_wifi_start_scan(SL_WIFI_CLIENT_INTERFACE, NULL, &sl_scan_config);
ret = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE,
(ssid.length > 0) ? &ssid : NULL, &sl_scan_config);
Copy link
Contributor

Choose a reason for hiding this comment

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

Align with opening parenthese.

@jerome-pouiller
Copy link
Contributor

It would have been easier to review if the features would been introduced in separated commits.

@ArunmaniAlagarsamy2710 ArunmaniAlagarsamy2710 force-pushed the dev/scan_param branch 2 times, most recently from ee819b1 to 0b2f3b3 Compare January 31, 2025 14:47
@@ -211,9 +212,16 @@ static int siwx917_scan(const struct device *dev, struct wifi_scan_params *z_sca

sl_scan_config.channel_bitmap_2g4 = 0xFFFF;
memset(sl_scan_config.channel_bitmap_5g, 0xFF, sizeof(sl_scan_config.channel_bitmap_5g));
IF_ENABLED(CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX, (
Copy link
Contributor

@jerome-pouiller jerome-pouiller Jan 31, 2025

Choose a reason for hiding this comment

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

My bad, I meant IS_ENABLED():

if (IS_ENABLED(CONFIG_WIFI_MGMT_SCAN_SSID_FILT_MAX)) {
[....]

} else {
ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT,
SL_WIFI_DEFAULT_ACTIVE_CHANNEL_SCAN_TIME);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm... It seems the condition is useless. You can unconditionally run:

ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT,
				 z_scan_config>dwell_time_active);

Copy link
Contributor

Choose a reason for hiding this comment

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

I have realized you probably wanted to write:

if (!z_scan_config>dwell_time_active) {
	ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT,
					 SL_WIFI_DEFAULT_ACTIVE_CHANNEL_SCAN_TIME);
} else {
	ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT,
					 z_scan_config>dwell_time_active);
}

} else {
ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_PASSIVE_SCAN_TIMEOUT,
SL_WIFI_DEFAULT_PASSIVE_CHANNEL_SCAN_TIME);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

This commit introduces support for direct SSID scans
The feature allows the device to send the probe requests
and listen the beacon frame on the specified SSID.

Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
This commit introduces support for limiting the number of
BSS scan results returned by the siwx917 Wi-Fi driver.
If scan_max_bss_cnt is specified, the driver will return up
to the specified count of BSS results. If not specified,
the driver defaults to returning all available results.

Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
This commit introduces support for single and multi-channel
Wi-Fi scans. The device can now scan one specific channel or
multiple specified channels.

Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
@ArunmaniAlagarsamy2710
Copy link
Contributor Author

@jerome-pouiller Changes have been made, please revisit

This commit adds support for configuring dwell times for
both active and passive Wi-Fi scans. The dwell time specifies
the duration the device spends on each channel during a scan.

Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
@ArunmaniAlagarsamy2710
Copy link
Contributor Author

@jerome-pouiller @jhedberg Gentle ping!

@jerome-pouiller jerome-pouiller merged commit d61c3f3 into SiliconLabsSoftware:main Feb 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants