Commit 7f9ba751 authored by Ajay Parida's avatar Ajay Parida Committed by Carles Cufi
Browse files

net: wifi_mgmt: Handle ps command error



Failure of setting ps param is handled with error string
at user/ app level.

Signed-off-by: default avatarAjay Parida <ajay.parida@nordicsemi.no>
parent 49e6b0c2
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -394,4 +394,38 @@ static const char * const wifi_ps_wakeup_mode2str[] = {
	[WIFI_PS_WAKEUP_MODE_DTIM] = "PS wakeup mode DTIM",
	[WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL] = "PS wakeup mode listen interval",
};

enum wifi_config_ps_param_fail_reason {
	WIFI_PS_PARAM_FAIL_UNSPECIFIED,
	WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL,
	WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED,
	WIFI_PS_PARAM_FAIL_UNABLE_TO_GET_IFACE_STATUS,
	WIFI_PS_PARAM_FAIL_DEVICE_NOT_CONNECTED,
	WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED,
	WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID,
};

static const char * const ps_param_config_err_code_tbl[] = {
	[WIFI_PS_PARAM_FAIL_UNSPECIFIED] = "Unspecfied",
	[WIFI_PS_PARAM_FAIL_CMD_EXEC_FAIL] = "Command Execution failed",
	[WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED] =
		"Operation not supported",
	[WIFI_PS_PARAM_FAIL_UNABLE_TO_GET_IFACE_STATUS] =
		"Unable to get iface status",
	[WIFI_PS_PARAM_FAIL_DEVICE_NOT_CONNECTED] =
		"Can not set while device not connected",
	[WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED] =
		"Can not set while device already connected",
	[WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID] =
		"Can not set due to invalid range",
};

static inline const char *get_ps_config_err_code_str(int16_t err_no)
{
	if ((err_no) < ARRAY_SIZE(ps_param_config_err_code_tbl)) {
		return ps_param_config_err_code_tbl[err_no];
	}

	return "<unknown>";
}
#endif /* ZEPHYR_INCLUDE_NET_WIFI_H_ */
+1 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ struct wifi_ps_params {
	enum wifi_ps_mode mode;
	int timeout_ms;
	enum ps_param_type type;
	enum wifi_config_ps_param_fail_reason fail_reason;
};

struct wifi_twt_params {
+6 −0
Original line number Diff line number Diff line
@@ -233,10 +233,14 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
	case WIFI_PS_PARAM_MODE:
		if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
			     sizeof(struct wifi_iface_status))) {
			ps_params->fail_reason =
				WIFI_PS_PARAM_FAIL_UNABLE_TO_GET_IFACE_STATUS;
			return -EIO;
		}

		if (info.state == WIFI_STATE_COMPLETED) {
			ps_params->fail_reason =
				WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED;
			return -ENOTSUP;
		}
		break;
@@ -245,6 +249,8 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
	case WIFI_PS_PARAM_TIMEOUT:
		break;
	default:
		ps_params->fail_reason =
			WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED;
		return -ENOTSUP;
	}

+26 −7
Original line number Diff line number Diff line
@@ -528,8 +528,10 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[])
	params.type = WIFI_PS_PARAM_STATE;

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

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

	if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
		shell_fprintf(sh, SHELL_WARNING, "%s failed\n", wifi_ps_mode2str[params.mode]);
		shell_fprintf(sh, SHELL_WARNING, "%s failed Reason : %s\n",
			      wifi_ps_mode2str[params.mode],
			      get_ps_config_err_code_str(params.fail_reason));
		return -ENOEXEC;
	}

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

	if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
		shell_fprintf(sh, SHELL_WARNING, "Setting PS timeout failed\n");
		shell_fprintf(sh, SHELL_WARNING,
			      "Setting PS timeout failed. Reason : %s\n",
			      get_ps_config_err_code_str(params.fail_reason));
		return -ENOEXEC;
	}

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

	if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
		shell_fprintf(sh, SHELL_WARNING, "Setting listen interval failed\n");
		if (params.fail_reason ==
		    WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID) {
			shell_fprintf(sh, SHELL_WARNING,
			      "Setting listen interval failed. Reason :%s\n",
			      get_ps_config_err_code_str(params.fail_reason));
			shell_fprintf(sh, SHELL_WARNING,
				"Hardware support valid range : 3 - 65535\n");
		} else  {
			shell_fprintf(sh, SHELL_WARNING,
				"Setting listen interval failed. Reason :%s\n",
				get_ps_config_err_code_str(params.fail_reason));
		}
		return -ENOEXEC;
	}

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

	if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
		shell_fprintf(sh, SHELL_WARNING, "Setting PS wake up mode to %s failed\n",
			params.wakeup_mode ? "Listen interval" : "DTIM interval");
		shell_fprintf(sh, SHELL_WARNING,
			      "Setting PS wake up mode to %s failed..Reason :%s\n",
			      params.wakeup_mode ? "Listen interval" : "DTIM interval",
			      get_ps_config_err_code_str(params.fail_reason));
		return -ENOEXEC;
	}