@@ -442,7 +442,8 @@ static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
442
442
}
443
443
444
444
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 )
446
447
{
447
448
char * endptr ;
448
449
int idx = 1 ;
@@ -470,8 +471,26 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
470
471
return - EINVAL ;
471
472
}
472
473
473
- if (params -> channel == 0U ) {
474
+ if (iface_mode == WIFI_MODE_INFRA && params -> channel == 0 ) {
474
475
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
+ }
475
494
}
476
495
477
496
idx ++ ;
@@ -530,7 +549,7 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc,
530
549
struct net_if * iface = net_if_get_first_wifi ();
531
550
struct wifi_connect_req_params cnx_params = { 0 };
532
551
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 )) {
534
553
shell_help (sh );
535
554
return - ENOEXEC ;
536
555
}
@@ -1223,7 +1242,7 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc,
1223
1242
static struct wifi_connect_req_params cnx_params ;
1224
1243
int ret ;
1225
1244
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 )) {
1227
1246
shell_help (sh );
1228
1247
return - ENOEXEC ;
1229
1248
}
0 commit comments