Skip to content

Commit df6d4e7

Browse files
krish2718carlescufi
authored andcommitted
wifi: shell: Log errors for validation
Handy in giving feedback to the user rather than silent failure. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent c9363a9 commit df6d4e7

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF);
4848
NET_EVENT_WIFI_SCAN_RESULT)
4949
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */
5050

51+
#define MAX_BANDS_STR_LEN 64
52+
5153
static struct {
5254
const struct shell *sh;
5355

@@ -449,6 +451,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
449451
int idx = 1;
450452

451453
if (argc < 1) {
454+
print(context.sh, SHELL_WARNING,
455+
"SSID not specified\n");
452456
return -EINVAL;
453457
}
454458

@@ -461,6 +465,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
461465
params->ssid = argv[0];
462466
params->ssid_length = strlen(params->ssid);
463467
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);
464471
return -EINVAL;
465472
}
466473

@@ -469,6 +476,11 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
469476
long channel = strtol(argv[idx], &endptr, 10);
470477

471478
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));
472484
return -EINVAL;
473485
}
474486

@@ -480,8 +492,23 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
480492
WIFI_FREQ_BAND_6_GHZ};
481493
uint8_t band;
482494
bool found = false;
495+
char bands_str[MAX_BANDS_STR_LEN] = {0};
496+
size_t offset = 0;
483497

484498
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+
485512
if (wifi_utils_validate_chan(bands[band],
486513
channel)) {
487514
found = true;
@@ -490,6 +517,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
490517
}
491518

492519
if (!found) {
520+
print(context.sh, SHELL_ERROR,
521+
"Invalid channel: %ld, checked bands: %s\n",
522+
channel,
523+
bands_str);
493524
return -EINVAL;
494525
}
495526

@@ -522,6 +553,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
522553

523554
if (security == WIFI_SECURITY_TYPE_NONE ||
524555
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));
525559
return -EINVAL;
526560
}
527561

@@ -537,6 +571,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
537571
params->psk_length > WIFI_PSK_MAX_LEN) ||
538572
(params->security == WIFI_SECURITY_TYPE_SAE &&
539573
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));
540578
return -EINVAL;
541579
}
542580
}
@@ -551,13 +589,13 @@ static int cmd_wifi_connect(const struct shell *sh, size_t argc,
551589
struct net_if *iface = net_if_get_first_wifi();
552590
struct wifi_connect_req_params cnx_params = { 0 };
553591

592+
context.sh = sh;
554593
if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_INFRA)) {
555594
shell_help(sh);
556595
return -ENOEXEC;
557596
}
558597

559598
context.connecting = true;
560-
context.sh = sh;
561599

562600
if (net_mgmt(NET_REQUEST_WIFI_CONNECT, iface,
563601
&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,
12441282
static struct wifi_connect_req_params cnx_params;
12451283
int ret;
12461284

1285+
context.sh = sh;
12471286
if (__wifi_args_to_params(argc - 1, &argv[1], &cnx_params, WIFI_MODE_AP)) {
12481287
shell_help(sh);
12491288
return -ENOEXEC;
12501289
}
12511290

1252-
context.sh = sh;
1253-
12541291
k_mutex_init(&wifi_ap_sta_list_lock);
12551292

12561293
ret = net_mgmt(NET_REQUEST_WIFI_AP_ENABLE, iface, &cnx_params,

0 commit comments

Comments
 (0)