Skip to content

Commit bf22b61

Browse files
nipandey-01kartben
authored andcommitted
driver: wifi: siwx91x: Implement scan dwell time
- Verified and configured scan dwell time for active, passive and advance scan Signed-off-by: Nitin Pandey <[email protected]>
1 parent 4c5dd73 commit bf22b61

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

drivers/wifi/siwx91x/siwx91x_wifi.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,58 @@ static unsigned int siwx91x_on_scan(sl_wifi_event_t event, sl_wifi_scan_result_t
475475
return 0;
476476
}
477477

478+
static int
479+
siwx91x_configure_scan_dwell_time(sl_wifi_scan_type_t scan_type, uint16_t dwell_time_active,
480+
uint16_t dwell_time_passive,
481+
sl_wifi_advanced_scan_configuration_t *advanced_scan_config)
482+
{
483+
int ret = 0;
484+
485+
if (dwell_time_active && (dwell_time_active < 5 || dwell_time_active > 1000)) {
486+
LOG_ERR("Invalid active scan dwell time");
487+
return -EINVAL;
488+
}
489+
490+
if (dwell_time_passive && (dwell_time_passive < 10 || dwell_time_passive > 1000)) {
491+
LOG_ERR("Invalid passive scan dwell time");
492+
return -EINVAL;
493+
}
494+
495+
switch (scan_type) {
496+
case SL_WIFI_SCAN_TYPE_ACTIVE:
497+
if (!dwell_time_active) {
498+
dwell_time_active = SL_WIFI_DEFAULT_ACTIVE_CHANNEL_SCAN_TIME;
499+
}
500+
ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT,
501+
dwell_time_active);
502+
break;
503+
case SL_WIFI_SCAN_TYPE_PASSIVE:
504+
if (!dwell_time_passive) {
505+
dwell_time_passive = SL_WIFI_DEFAULT_PASSIVE_CHANNEL_SCAN_TIME;
506+
}
507+
ret = sl_si91x_configure_timeout(SL_SI91X_CHANNEL_PASSIVE_SCAN_TIMEOUT,
508+
dwell_time_passive);
509+
break;
510+
case SL_WIFI_SCAN_TYPE_ADV_SCAN:
511+
__ASSERT(advanced_scan_config, "advanced_scan_config cannot be NULL");
512+
513+
if (!dwell_time_active) {
514+
dwell_time_active = CONFIG_WIFI_SILABS_SIWX91X_ADV_ACTIVE_SCAN_DURATION;
515+
}
516+
advanced_scan_config->active_channel_time = dwell_time_active;
517+
518+
if (!dwell_time_passive) {
519+
dwell_time_passive = CONFIG_WIFI_SILABS_SIWX91X_ADV_PASSIVE_SCAN_DURATION;
520+
}
521+
advanced_scan_config->passive_channel_time = dwell_time_passive;
522+
break;
523+
default:
524+
break;
525+
}
526+
527+
return ret;
528+
}
529+
478530
static int siwx91x_scan(const struct device *dev, struct wifi_scan_params *z_scan_config,
479531
scan_result_cb_t cb)
480532
{
@@ -510,6 +562,11 @@ static int siwx91x_scan(const struct device *dev, struct wifi_scan_params *z_sca
510562
}
511563

512564
if (sidev->state == WIFI_STATE_COMPLETED) {
565+
siwx91x_configure_scan_dwell_time(SL_WIFI_SCAN_TYPE_ADV_SCAN,
566+
z_scan_config->dwell_time_active,
567+
z_scan_config->dwell_time_passive,
568+
&advanced_scan_config);
569+
513570
ret = sl_wifi_set_advanced_scan_configuration(&advanced_scan_config);
514571
if (ret != SL_STATUS_OK) {
515572
LOG_ERR("advanced scan configuration failed with status %x", ret);
@@ -522,8 +579,20 @@ static int siwx91x_scan(const struct device *dev, struct wifi_scan_params *z_sca
522579
} else {
523580
if (z_scan_config->scan_type == WIFI_SCAN_TYPE_ACTIVE) {
524581
sl_scan_config.type = SL_WIFI_SCAN_TYPE_ACTIVE;
582+
ret = siwx91x_configure_scan_dwell_time(SL_WIFI_SCAN_TYPE_ACTIVE,
583+
z_scan_config->dwell_time_active,
584+
z_scan_config->dwell_time_passive,
585+
NULL);
525586
} else {
526587
sl_scan_config.type = SL_WIFI_SCAN_TYPE_PASSIVE;
588+
ret = siwx91x_configure_scan_dwell_time(SL_WIFI_SCAN_TYPE_PASSIVE,
589+
z_scan_config->dwell_time_active,
590+
z_scan_config->dwell_time_passive,
591+
NULL);
592+
}
593+
if (ret != SL_STATUS_OK) {
594+
LOG_ERR("Failed to configure timeout");
595+
return -EINVAL;
527596
}
528597
}
529598

0 commit comments

Comments
 (0)