Skip to content

Commit 355a06c

Browse files
committed
net: l2: wifi: shell: Add bgscan command
Add a shell command to configure the background scanning. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent fae4d95 commit 355a06c

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,103 @@ static int cmd_wifi_set_bss_max_idle_period(const struct shell *sh, size_t argc,
35553555
return 0;
35563556
}
35573557

3558+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_BGSCAN
3559+
static int wifi_bgscan_args_to_params(const struct shell *sh, size_t argc, char *argv[],
3560+
struct wifi_bgscan_params *params)
3561+
{
3562+
int err;
3563+
int opt;
3564+
int opt_index = 0;
3565+
struct getopt_state *state;
3566+
static const struct option long_options[] = {
3567+
{"type", required_argument, 0, 't'},
3568+
{"short-interval", required_argument, 0, 's'},
3569+
{"rss-threshold", required_argument, 0, 'r'},
3570+
{"long-interval", required_argument, 0, 'l'},
3571+
{"iface", required_argument, 0, 'i'},
3572+
{0, 0, 0, 0}};
3573+
unsigned long uval;
3574+
long val;
3575+
3576+
while ((opt = getopt_long(argc, argv, "t:s:r:l:i:", long_options, &opt_index)) != -1) {
3577+
state = getopt_state_get();
3578+
switch (opt) {
3579+
case 't':
3580+
if (strcmp("simple", state->optarg) == 0) {
3581+
params->type = WIFI_BGSCAN_SIMPLE;
3582+
} else if (strcmp("learn", state->optarg) == 0) {
3583+
params->type = WIFI_BGSCAN_LEARN;
3584+
} else if (strcmp("none", state->optarg) == 0) {
3585+
params->type = WIFI_BGSCAN_NONE;
3586+
} else {
3587+
PR_ERROR("Invalid type %s\n", state->optarg);
3588+
shell_help(sh);
3589+
return SHELL_CMD_HELP_PRINTED;
3590+
}
3591+
break;
3592+
case 's':
3593+
uval = shell_strtoul(state->optarg, 10, &err);
3594+
if (err < 0) {
3595+
PR_ERROR("Invalid short interval %s\n", state->optarg);
3596+
return err;
3597+
}
3598+
params->short_interval = uval;
3599+
break;
3600+
case 'l':
3601+
uval = shell_strtoul(state->optarg, 10, &err);
3602+
if (err < 0) {
3603+
PR_ERROR("Invalid long interval %s\n", state->optarg);
3604+
return err;
3605+
}
3606+
params->long_interval = uval;
3607+
break;
3608+
case 'r':
3609+
val = shell_strtol(state->optarg, 10, &err);
3610+
if (err < 0) {
3611+
PR_ERROR("Invalid RSSI threshold %s\n", state->optarg);
3612+
return err;
3613+
}
3614+
params->rssi_threshold = val;
3615+
break;
3616+
case 'i':
3617+
/* Unused, but parsing to avoid unknown option error */
3618+
break;
3619+
default:
3620+
PR_ERROR("Invalid option %c\n", state->optopt);
3621+
shell_help(sh);
3622+
return SHELL_CMD_HELP_PRINTED;
3623+
}
3624+
}
3625+
3626+
return 0;
3627+
}
3628+
3629+
static int cmd_wifi_set_bgscan(const struct shell *sh, size_t argc, char *argv[])
3630+
{
3631+
struct net_if *iface = get_iface(IFACE_TYPE_STA, argc, argv);
3632+
struct wifi_bgscan_params bgscan_params = {
3633+
.type = WIFI_BGSCAN_NONE,
3634+
.short_interval = 30,
3635+
.rssi_threshold = -45,
3636+
.long_interval = 300,
3637+
};
3638+
int ret;
3639+
3640+
if (wifi_bgscan_args_to_params(sh, argc, argv, &bgscan_params) != 0) {
3641+
return -ENOEXEC;
3642+
}
3643+
3644+
ret = net_mgmt(NET_REQUEST_WIFI_BGSCAN, iface, &bgscan_params,
3645+
sizeof(struct wifi_bgscan_params));
3646+
if (ret != 0) {
3647+
PR_WARNING("Setting background scanning parameters failed: %s\n", strerror(-ret));
3648+
return -ENOEXEC;
3649+
}
3650+
3651+
return 0;
3652+
}
3653+
#endif
3654+
35583655
static int wifi_config_args_to_params(const struct shell *sh, size_t argc, char *argv[],
35593656
struct wifi_config_params *params)
35603657
{
@@ -3921,6 +4018,8 @@ SHELL_SUBCMD_ADD((wifi), connect, NULL,
39214018
"[-P, --eap-pwd1]: Client Password.\n"
39224019
"Default no password for eap user.\n"
39234020
"[-R, --ieee-80211r]: Use IEEE80211R fast BSS transition connect."
4021+
"format is \"<type>:<short interval>:<rssi threshold>:<long interval>\".\n"
4022+
"Type is either \"simple\" or \"learn\".\n"
39244023
"[-h, --help]: Print out the help for the connect command.\n"
39254024
"[-i, --iface=<interface index>] : Interface index.\n",
39264025
cmd_wifi_connect,
@@ -4098,6 +4197,18 @@ SHELL_SUBCMD_ADD((wifi), bss_max_idle_period, NULL,
40984197
cmd_wifi_set_bss_max_idle_period,
40994198
2, 2);
41004199

4200+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_BGSCAN
4201+
SHELL_SUBCMD_ADD((wifi), bgscan, NULL,
4202+
"Configure background scanning.\n"
4203+
"<-t, --type simple/learn/none> : The scanning type, use none to disable.\n"
4204+
"[-s, --short-interval <val>] : Short scan interval (default: 30).\n"
4205+
"[-r, --rssi-threshold <val>] : Signal strength threshold (default: -45).\n"
4206+
"[-l, --long-interval <val>] : Long scan interval (default: 300).\n"
4207+
"[-i, --iface=<interface index>] : Interface index.\n",
4208+
cmd_wifi_set_bgscan,
4209+
2, 6);
4210+
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_BGSCAN */
4211+
41014212
SHELL_SUBCMD_ADD((wifi), config, NULL,
41024213
"Configure STA parameters.\n"
41034214
"-o, --okc=<0/1>: Opportunistic Key Caching. 0: disable, 1: enable\n"

0 commit comments

Comments
 (0)