Skip to content

Commit 69fead1

Browse files
ajayparidacarlescufi
authored andcommitted
net: mgmt: Support for forced Passive scan
Default scan mode is Active. User can force the scan mode to passive through Kconfig option or using 'passive' option from shell. Using either of this option will override regulatory settings and forces all scan channels to be passive only. Signed-off-by: Ajay Parida <[email protected]>
1 parent c627164 commit 69fead1

File tree

10 files changed

+86
-9
lines changed

10 files changed

+86
-9
lines changed

drivers/wifi/esp32/src/esp_wifi_drv.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ static int esp32_wifi_connect(const struct device *dev,
388388
return 0;
389389
}
390390

391-
static int esp32_wifi_scan(const struct device *dev, scan_result_cb_t cb)
391+
static int esp32_wifi_scan(const struct device *dev,
392+
struct wifi_scan_params *params,
393+
scan_result_cb_t cb)
392394
{
393395
struct esp32_wifi_runtime *data = dev->data;
394396
int ret = 0;
@@ -402,6 +404,11 @@ static int esp32_wifi_scan(const struct device *dev, scan_result_cb_t cb)
402404

403405
wifi_scan_config_t scan_config = { 0 };
404406

407+
if (params) {
408+
/* The enum values are same, so, no conversion needed */
409+
scan_config->scan_type = params->scan_type;
410+
}
411+
405412
ret = esp_wifi_set_mode(ESP32_WIFI_MODE_STA);
406413
ret |= esp_wifi_scan_start(&scan_config, false);
407414

drivers/wifi/esp_at/esp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,14 @@ static void esp_mgmt_scan_work(struct k_work *work)
899899
dev->scan_cb = NULL;
900900
}
901901

902-
static int esp_mgmt_scan(const struct device *dev, scan_result_cb_t cb)
902+
static int esp_mgmt_scan(const struct device *dev,
903+
struct wifi_scan_params *params,
904+
scan_result_cb_t cb)
903905
{
904906
struct esp_data *data = dev->data;
905907

908+
ARG_UNUSED(params);
909+
906910
if (data->scan_cb != NULL) {
907911
return -EINPROGRESS;
908912
}

drivers/wifi/eswifi/eswifi_core.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,14 @@ int eswifi_mgmt_iface_status(const struct device *dev,
520520
return 0;
521521
}
522522

523-
static int eswifi_mgmt_scan(const struct device *dev, scan_result_cb_t cb)
523+
static int eswifi_mgmt_scan(const struct device *dev,
524+
struct wifi_scan_params *params,
525+
scan_result_cb_t cb)
524526
{
525527
struct eswifi_dev *eswifi = dev->data;
526528

529+
ARG_UNUSED(params);
530+
527531
LOG_DBG("");
528532

529533
eswifi_lock(eswifi);

drivers/wifi/simplelink/simplelink.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ static void simplelink_scan_work_handler(struct k_work *work)
136136
}
137137
}
138138

139-
static int simplelink_mgmt_scan(const struct device *dev, scan_result_cb_t cb)
139+
static int simplelink_mgmt_scan(const struct device *dev,
140+
struct wifi_scan_params *params,
141+
scan_result_cb_t cb)
140142
{
141143
int err;
142144
int status;
143145

146+
ARG_UNUSED(params);
147+
144148
/* Cancel any previous scan processing in progress: */
145149
k_work_cancel_delayable(&simplelink_data.work);
146150

drivers/wifi/winc1500/wifi_winc1500.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,12 @@ static void winc1500_thread(void)
976976
}
977977
}
978978

979-
static int winc1500_mgmt_scan(const struct device *dev, scan_result_cb_t cb)
979+
static int winc1500_mgmt_scan(const struct device *dev,
980+
struct wifi_scan_params *params,
981+
scan_result_cb_t cb)
980982
{
983+
ARG_UNUSED(params);
984+
981985
if (w1500_data.scan_cb) {
982986
return -EALREADY;
983987
}

include/zephyr/net/wifi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ static inline const char *wifi_link_mode_txt(enum wifi_link_mode link_mode)
264264
}
265265
}
266266

267+
enum wifi_scan_type {
268+
WIFI_SCAN_TYPE_ACTIVE = 0,
269+
WIFI_SCAN_TYPE_PASSIVE,
270+
};
271+
267272
enum wifi_ps {
268273
WIFI_PS_DISABLED = 0,
269274
WIFI_PS_ENABLED,

include/zephyr/net/wifi_mgmt.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ enum net_event_wifi_cmd {
143143

144144
#define NET_EVENT_WIFI_DISCONNECT_COMPLETE \
145145
(_NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE)
146+
147+
struct wifi_scan_params {
148+
/* The scan_type is only a hint to the underlying Wi-Fi chip for the
149+
* preferred mode of scan. The actual mode of scan can depend on factors
150+
* such as the Wi-Fi chip implementation support, regulatory domain
151+
* restrictions etc.
152+
*/
153+
enum wifi_scan_type scan_type;
154+
};
155+
146156
/* Each result is provided to the net_mgmt_event_callback
147157
* via its info attribute (see net_mgmt.h)
148158
*/
@@ -321,7 +331,9 @@ struct net_wifi_mgmt_offload {
321331
* result by the driver. The wifi mgmt part will take care of
322332
* raising the necessary event etc...
323333
*/
324-
int (*scan)(const struct device *dev, scan_result_cb_t cb);
334+
int (*scan)(const struct device *dev,
335+
struct wifi_scan_params *params,
336+
scan_result_cb_t cb);
325337
int (*connect)(const struct device *dev,
326338
struct wifi_connect_req_params *params);
327339
int (*disconnect)(const struct device *dev);

subsys/net/l2/wifi/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ config WIFI_MGMT_TWT_CHECK_IP
3838
being unreachable (IP Level) or unable to receive down link traffic
3939
even when it is awake intervals. Rejecting TWT setup till Wi-Fi
4040
interface has a valid IP address might be desirable in most scenarios.
41+
42+
config WIFI_MGMT_FORCED_PASSIVE_SCAN
43+
bool "Force Passive scan"
44+
help
45+
Force passive scan (typically used to reduce power consumption),
46+
the scan type is always sent as passive.
47+
This doesn't guarantee that passive scan will be used, it depends
48+
on the underlying chip implementation to support and honour scan type.

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface,
8484
const struct device *dev = net_if_get_device(iface);
8585
struct net_wifi_mgmt_offload *off_api =
8686
(struct net_wifi_mgmt_offload *) dev->api;
87+
struct wifi_scan_params *params = data;
8788

8889
if (off_api == NULL || off_api->scan == NULL) {
8990
return -ENOTSUP;
9091
}
9192

92-
return off_api->scan(dev, scan_result_cb);
93+
if (data && (len == sizeof(*params))) {
94+
#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN
95+
params->scan_type = WIFI_SCAN_TYPE_PASSIVE;
96+
#endif
97+
}
98+
99+
return off_api->scan(dev, params, scan_result_cb);
93100
}
94101

95102
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_SCAN, wifi_scan);

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,29 @@ static int cmd_wifi_disconnect(const struct shell *sh, size_t argc,
447447
static int cmd_wifi_scan(const struct shell *sh, size_t argc, char *argv[])
448448
{
449449
struct net_if *iface = net_if_get_first_wifi();
450+
struct wifi_scan_params params = { 0 };
450451

451452
context.sh = sh;
452453

453-
if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, NULL, 0)) {
454+
if (argc > 2) {
455+
shell_fprintf(sh, SHELL_WARNING, "Invalid number of arguments\n");
456+
return -ENOEXEC;
457+
}
458+
459+
if (argc == 2) {
460+
if (!strcmp(argv[1], "passive")) {
461+
params.scan_type = WIFI_SCAN_TYPE_PASSIVE;
462+
} else if (!strcmp(argv[1], "active")) {
463+
params.scan_type = WIFI_SCAN_TYPE_ACTIVE;
464+
} else {
465+
shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n");
466+
shell_fprintf(sh, SHELL_INFO,
467+
"Valid argument : <active> / <passive>\n");
468+
return -ENOEXEC;
469+
}
470+
}
471+
472+
if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, &params, sizeof(params))) {
454473
shell_fprintf(sh, SHELL_WARNING, "Scan request failed\n");
455474

456475
return -ENOEXEC;
@@ -1114,7 +1133,10 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands,
11141133
cmd_wifi_ps_mode,
11151134
2,
11161135
0),
1117-
SHELL_CMD(scan, NULL, "Scan for Wi-Fi APs", cmd_wifi_scan),
1136+
SHELL_CMD(scan, NULL,
1137+
"Scan for Wi-Fi APs\n"
1138+
"<scan type (optional): <active> : <passive>>\n",
1139+
cmd_wifi_scan),
11181140
SHELL_CMD(statistics, NULL, "Wi-Fi interface statistics", cmd_wifi_stats),
11191141
SHELL_CMD(status, NULL, "Status of the Wi-Fi interface", cmd_wifi_status),
11201142
SHELL_CMD(twt, &wifi_twt_ops, "Manage TWT flows", NULL),

0 commit comments

Comments
 (0)