Skip to content

Commit 8282ac7

Browse files
ajayparidanordicjm
authored andcommitted
[nrf fromtree] net: wifi_mgmt: Handle ps command error
Failure of setting ps param is handled with error string at user/ app level. Signed-off-by: Ajay Parida <[email protected]> (cherry picked from commit 7f9ba75)
1 parent 2ff4e28 commit 8282ac7

File tree

4 files changed

+68
-8
lines changed

4 files changed

+68
-8
lines changed

include/zephyr/net/wifi.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static inline const char *get_twt_err_code_str(int16_t err_no)
380380
}
381381

382382
enum ps_param_type {
383-
WIFI_PS_PARAM_STATE,
383+
WIFI_PS_PARAM_STATE,
384384
WIFI_PS_PARAM_LISTEN_INTERVAL,
385385
WIFI_PS_PARAM_WAKEUP_MODE,
386386
WIFI_PS_PARAM_MODE,
@@ -396,4 +396,38 @@ static const char * const wifi_ps_wakeup_mode2str[] = {
396396
[WIFI_PS_WAKEUP_MODE_DTIM] = "PS wakeup mode DTIM",
397397
[WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL] = "PS wakeup mode listen interval",
398398
};
399+
400+
enum wifi_config_ps_param_fail_reason {
401+
WIFI_PS_PARAM_FAIL_UNSPECIFIED,
402+
WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL,
403+
WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED,
404+
WIFI_PS_PARAM_FAIL_UNABLE_TO_GET_IFACE_STATUS,
405+
WIFI_PS_PARAM_FAIL_DEVICE_NOT_CONNECTED,
406+
WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED,
407+
WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID,
408+
};
409+
410+
static const char * const ps_param_config_err_code_tbl[] = {
411+
[WIFI_PS_PARAM_FAIL_UNSPECIFIED] = "Unspecfied",
412+
[WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL] = "Command Execution failed",
413+
[WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED] =
414+
"Operation not supported",
415+
[WIFI_PS_PARAM_FAIL_UNABLE_TO_GET_IFACE_STATUS] =
416+
"Unable to get iface status",
417+
[WIFI_PS_PARAM_FAIL_DEVICE_NOT_CONNECTED] =
418+
"Can not set while device not connected",
419+
[WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED] =
420+
"Can not set while device already connected",
421+
[WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID] =
422+
"Can not set due to invalid range",
423+
};
424+
425+
static inline const char *get_ps_config_err_code_str(int16_t err_no)
426+
{
427+
if ((err_no) < ARRAY_SIZE(ps_param_config_err_code_tbl)) {
428+
return ps_param_config_err_code_tbl[err_no];
429+
}
430+
431+
return "<unknown>";
432+
}
399433
#endif /* ZEPHYR_INCLUDE_NET_WIFI_H_ */

include/zephyr/net/wifi_mgmt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ struct wifi_ps_params {
201201
enum wifi_ps_mode mode;
202202
int timeout_ms;
203203
enum ps_param_type type;
204+
enum wifi_config_ps_param_fail_reason fail_reason;
204205
};
205206

206207
struct wifi_twt_params {

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,14 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
254254
case WIFI_PS_PARAM_MODE:
255255
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
256256
sizeof(struct wifi_iface_status))) {
257+
ps_params->fail_reason =
258+
WIFI_PS_PARAM_FAIL_UNABLE_TO_GET_IFACE_STATUS;
257259
return -EIO;
258260
}
259261

260262
if (info.state == WIFI_STATE_COMPLETED) {
263+
ps_params->fail_reason =
264+
WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED;
261265
return -ENOTSUP;
262266
}
263267
break;
@@ -266,6 +270,8 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
266270
case WIFI_PS_PARAM_TIMEOUT:
267271
break;
268272
default:
273+
ps_params->fail_reason =
274+
WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED;
269275
return -ENOTSUP;
270276
}
271277

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,10 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[])
617617
params.type = WIFI_PS_PARAM_STATE;
618618

619619
if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
620-
shell_fprintf(sh, SHELL_WARNING, "Power save %s failed\n",
621-
params.enabled ? "enable" : "disable");
620+
shell_fprintf(sh, SHELL_WARNING,
621+
"PS %s failed. Reason: %s\n",
622+
params.enabled ? "enable" : "disable",
623+
get_ps_config_err_code_str(params.fail_reason));
622624
return -ENOEXEC;
623625
}
624626

@@ -646,7 +648,9 @@ static int cmd_wifi_ps_mode(const struct shell *sh, size_t argc, char *argv[])
646648
params.type = WIFI_PS_PARAM_MODE;
647649

648650
if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
649-
shell_fprintf(sh, SHELL_WARNING, "%s failed\n", wifi_ps_mode2str[params.mode]);
651+
shell_fprintf(sh, SHELL_WARNING, "%s failed Reason : %s\n",
652+
wifi_ps_mode2str[params.mode],
653+
get_ps_config_err_code_str(params.fail_reason));
650654
return -ENOEXEC;
651655
}
652656

@@ -675,7 +679,9 @@ static int cmd_wifi_ps_timeout(const struct shell *sh, size_t argc, char *argv[]
675679
params.type = WIFI_PS_PARAM_MODE;
676680

677681
if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
678-
shell_fprintf(sh, SHELL_WARNING, "Setting PS timeout failed\n");
682+
shell_fprintf(sh, SHELL_WARNING,
683+
"Setting PS timeout failed. Reason : %s\n",
684+
get_ps_config_err_code_str(params.fail_reason));
679685
return -ENOEXEC;
680686
}
681687

@@ -983,7 +989,18 @@ static int cmd_wifi_listen_interval(const struct shell *sh, size_t argc, char *a
983989
params.type = WIFI_PS_PARAM_LISTEN_INTERVAL;
984990

985991
if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
986-
shell_fprintf(sh, SHELL_WARNING, "Setting listen interval failed\n");
992+
if (params.fail_reason ==
993+
WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID) {
994+
shell_fprintf(sh, SHELL_WARNING,
995+
"Setting listen interval failed. Reason :%s\n",
996+
get_ps_config_err_code_str(params.fail_reason));
997+
shell_fprintf(sh, SHELL_WARNING,
998+
"Hardware support valid range : 3 - 65535\n");
999+
} else {
1000+
shell_fprintf(sh, SHELL_WARNING,
1001+
"Setting listen interval failed. Reason :%s\n",
1002+
get_ps_config_err_code_str(params.fail_reason));
1003+
}
9871004
return -ENOEXEC;
9881005
}
9891006

@@ -1014,8 +1031,10 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar
10141031
params.type = WIFI_PS_PARAM_WAKEUP_MODE;
10151032

10161033
if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
1017-
shell_fprintf(sh, SHELL_WARNING, "Setting PS wake up mode to %s failed\n",
1018-
params.wakeup_mode ? "Listen interval" : "DTIM interval");
1034+
shell_fprintf(sh, SHELL_WARNING,
1035+
"Setting PS wake up mode to %s failed..Reason :%s\n",
1036+
params.wakeup_mode ? "Listen interval" : "DTIM interval",
1037+
get_ps_config_err_code_str(params.fail_reason));
10191038
return -ENOEXEC;
10201039
}
10211040

0 commit comments

Comments
 (0)