Skip to content

Commit 2f88df9

Browse files
krish2718carlescufi
authored andcommitted
wifi: shell: Add channel validation
Validate the channel for both STA and AP modes. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 2f99379 commit 2f88df9

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
442442
}
443443

444444
static int __wifi_args_to_params(size_t argc, char *argv[],
445-
struct wifi_connect_req_params *params)
445+
struct wifi_connect_req_params *params,
446+
enum wifi_iface_mode iface_mode)
446447
{
447448
char *endptr;
448449
int idx = 1;
@@ -470,8 +471,26 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
470471
return -EINVAL;
471472
}
472473

473-
if (params->channel == 0U) {
474+
if (iface_mode == WIFI_MODE_INFRA && params->channel == 0) {
474475
params->channel = WIFI_CHANNEL_ANY;
476+
} else {
477+
const uint8_t bands[] = {WIFI_FREQ_BAND_2_4_GHZ,
478+
WIFI_FREQ_BAND_5_GHZ,
479+
WIFI_FREQ_BAND_6_GHZ};
480+
uint8_t band;
481+
bool found = false;
482+
483+
for (band = 0; band < ARRAY_SIZE(bands); band++) {
484+
if (wifi_utils_validate_chan(bands[band],
485+
params->channel)) {
486+
found = true;
487+
break;
488+
}
489+
}
490+
491+
if (!found) {
492+
return -EINVAL;
493+
}
475494
}
476495

477496
idx++;
@@ -530,7 +549,7 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc,
530549
struct net_if *iface = net_if_get_first_wifi();
531550
struct wifi_connect_req_params cnx_params = { 0 };
532551

533-
if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params)) {
552+
if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_INFRA)) {
534553
shell_help(sh);
535554
return -ENOEXEC;
536555
}
@@ -1223,7 +1242,7 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc,
12231242
static struct wifi_connect_req_params cnx_params;
12241243
int ret;
12251244

1226-
if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params)) {
1245+
if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_AP)) {
12271246
shell_help(sh);
12281247
return -ENOEXEC;
12291248
}

0 commit comments

Comments
 (0)