@@ -48,6 +48,8 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF);
48
48
NET_EVENT_WIFI_SCAN_RESULT)
49
49
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */
50
50
51
+ #define MAX_BANDS_STR_LEN 64
52
+
51
53
static struct {
52
54
const struct shell * sh ;
53
55
@@ -449,6 +451,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
449
451
int idx = 1 ;
450
452
451
453
if (argc < 1 ) {
454
+ print (context .sh , SHELL_WARNING ,
455
+ "SSID not specified\n" );
452
456
return - EINVAL ;
453
457
}
454
458
@@ -461,6 +465,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
461
465
params -> ssid = argv [0 ];
462
466
params -> ssid_length = strlen (params -> ssid );
463
467
if (params -> ssid_length > WIFI_SSID_MAX_LEN ) {
468
+ print (context .sh , SHELL_WARNING ,
469
+ "SSID too long (max %d characters)\n" ,
470
+ WIFI_SSID_MAX_LEN );
464
471
return - EINVAL ;
465
472
}
466
473
@@ -469,6 +476,11 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
469
476
long channel = strtol (argv [idx ], & endptr , 10 );
470
477
471
478
if (* endptr != '\0' ) {
479
+ print (context .sh , SHELL_ERROR ,
480
+ "Failed to parse channel: %s: endp: %s, err: %s\n" ,
481
+ argv [idx ],
482
+ endptr ,
483
+ strerror (errno ));
472
484
return - EINVAL ;
473
485
}
474
486
@@ -480,8 +492,23 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
480
492
WIFI_FREQ_BAND_6_GHZ };
481
493
uint8_t band ;
482
494
bool found = false;
495
+ char bands_str [MAX_BANDS_STR_LEN ] = {0 };
496
+ size_t offset = 0 ;
483
497
484
498
for (band = 0 ; band < ARRAY_SIZE (bands ); band ++ ) {
499
+ offset += snprintf (bands_str + offset ,
500
+ sizeof (bands_str ) - offset ,
501
+ "%s%s" ,
502
+ band ? "," : "" ,
503
+ wifi_band_txt (bands [band ]));
504
+ if (offset >= sizeof (bands_str )) {
505
+ print (context .sh , SHELL_ERROR ,
506
+ "Failed to parse channel: %s: "
507
+ "band string too long\n" ,
508
+ argv [idx ]);
509
+ return - EINVAL ;
510
+ }
511
+
485
512
if (wifi_utils_validate_chan (bands [band ],
486
513
channel )) {
487
514
found = true;
@@ -490,6 +517,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
490
517
}
491
518
492
519
if (!found ) {
520
+ print (context .sh , SHELL_ERROR ,
521
+ "Invalid channel: %ld, checked bands: %s\n" ,
522
+ channel ,
523
+ bands_str );
493
524
return - EINVAL ;
494
525
}
495
526
@@ -522,6 +553,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
522
553
523
554
if (security == WIFI_SECURITY_TYPE_NONE ||
524
555
security == WIFI_SECURITY_TYPE_WPA_PSK ) {
556
+ print (context .sh , SHELL_ERROR ,
557
+ "MFP not supported for security type %s\n" ,
558
+ wifi_security_txt (security ));
525
559
return - EINVAL ;
526
560
}
527
561
@@ -537,6 +571,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
537
571
params -> psk_length > WIFI_PSK_MAX_LEN ) ||
538
572
(params -> security == WIFI_SECURITY_TYPE_SAE &&
539
573
params -> psk_length > WIFI_SAE_PSWD_MAX_LEN )) {
574
+ print (context .sh , SHELL_ERROR ,
575
+ "Invalid PSK length (%d) for security type %s\n" ,
576
+ params -> psk_length ,
577
+ wifi_security_txt (params -> security ));
540
578
return - EINVAL ;
541
579
}
542
580
}
@@ -551,13 +589,13 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc,
551
589
struct net_if * iface = net_if_get_first_wifi ();
552
590
struct wifi_connect_req_params cnx_params = { 0 };
553
591
592
+ context .sh = sh ;
554
593
if (__wifi_args_to_params (argc - 1 , & argv [1 ], & cnx_params , WIFI_MODE_INFRA )) {
555
594
shell_help (sh );
556
595
return - ENOEXEC ;
557
596
}
558
597
559
598
context .connecting = true;
560
- context .sh = sh ;
561
599
562
600
if (net_mgmt (NET_REQUEST_WIFI_CONNECT , iface ,
563
601
& cnx_params , sizeof (struct wifi_connect_req_params ))) {
@@ -1244,13 +1282,12 @@ static int cmd_wifi_ap_enable(const struct shell *sh, size_t argc,
1244
1282
static struct wifi_connect_req_params cnx_params ;
1245
1283
int ret ;
1246
1284
1285
+ context .sh = sh ;
1247
1286
if (__wifi_args_to_params (argc - 1 , & argv [1 ], & cnx_params , WIFI_MODE_AP )) {
1248
1287
shell_help (sh );
1249
1288
return - ENOEXEC ;
1250
1289
}
1251
1290
1252
- context .sh = sh ;
1253
-
1254
1291
k_mutex_init (& wifi_ap_sta_list_lock );
1255
1292
1256
1293
ret = net_mgmt (NET_REQUEST_WIFI_AP_ENABLE , iface , & cnx_params ,
0 commit comments