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

net: wifi_mgmt: Configure listen interval



listen interval is the time periods the STAs may be in idle
without listening beacons.
By default STA wakes up for every DTIM period.
If listen interval based power save is used
STA uses configured listen interval period(default 10
beacon intervals) to wake up.

Signed-off-by: default avatarAjay Parida <ajay.parida@nordicsemi.no>
parent 63fc3074
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@

#define WIFI_COUNTRY_CODE_LEN 2

#define WIFI_LISTEN_INTERVAL_MIN 0
#define WIFI_LISTEN_INTERVAL_MAX 65535

/* Not having support for legacy types is deliberate to enforce
 * higher security.
 */
@@ -373,4 +376,9 @@ static inline const char *get_twt_err_code_str(int16_t err_no)

	return "<unknown>";
}

enum ps_param_type {
        WIFI_PS_PARAM_STATE,
	WIFI_PS_PARAM_LISTEN_INTERVAL,
};
#endif /* ZEPHYR_INCLUDE_NET_WIFI_H_ */
+3 −1
Original line number Diff line number Diff line
@@ -192,6 +192,8 @@ struct wifi_iface_status {

struct wifi_ps_params {
	enum wifi_ps enabled;
	unsigned short listen_interval;
	enum ps_param_type type;
};

struct wifi_ps_mode_params {
@@ -253,9 +255,9 @@ struct wifi_twt_flow_info {

struct wifi_ps_config {
	struct wifi_twt_flow_info twt_flows[WIFI_MAX_TWT_FLOWS];
	bool enabled;
	enum wifi_ps_mode mode;
	char num_twt_flows;
	struct wifi_ps_params ps_params;
};

/* Generic get/set operation for any command*/
+16 −0
Original line number Diff line number Diff line
@@ -222,11 +222,27 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
	struct net_wifi_mgmt_offload *off_api =
		(struct net_wifi_mgmt_offload *) dev->api;
	struct wifi_ps_params *ps_params = data;
	struct wifi_iface_status info = { 0 };

	if (off_api == NULL || off_api->set_power_save == NULL) {
		return -ENOTSUP;
	}

	switch (ps_params->type) {
        case WIFI_PS_PARAM_LISTEN_INTERVAL:
		if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
			     sizeof(struct wifi_iface_status))) {
			return -EIO;
		}

		if (info.state == WIFI_STATE_COMPLETED) {
			return -ENOTSUP;
		}
                break;
        case WIFI_PS_PARAM_STATE:
        default:
                break;
        }
	return off_api->set_power_save(dev, ps_params);
}

+41 −1
Original line number Diff line number Diff line
@@ -482,12 +482,15 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[])
		}

		shell_fprintf(sh, SHELL_NORMAL, "PS status: %s\n",
				wifi_ps2str[config.enabled]);
				wifi_ps2str[config.ps_params.enabled]);
		if (config.enabled) {
			shell_fprintf(sh, SHELL_NORMAL, "PS mode: %s\n",
					wifi_ps_mode2str[config.mode]);
		}

		shell_fprintf(sh, SHELL_NORMAL, "PS listen_interval: %d\n",
				config.ps_params.listen_interval);

		if (config.num_twt_flows == 0) {
			shell_fprintf(sh, SHELL_NORMAL, "No TWT flows\n");
		} else {
@@ -516,6 +519,8 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[])
		return -ENOEXEC;
	}

	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");
@@ -872,6 +877,35 @@ static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc,
	return 0;
}

static int cmd_wifi_listen_interval(const struct shell *sh, size_t argc, char *argv[])
{
	struct net_if *iface = net_if_get_default();
	struct wifi_ps_params params = { 0 };
	long interval = 0;

	context.sh = sh;

	if (!parse_number(sh, &interval, argv[1],
			  WIFI_LISTEN_INTERVAL_MIN,
			  WIFI_LISTEN_INTERVAL_MAX)) {
		return -EINVAL;
	}

	params.listen_interval = interval;
	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");
		return -ENOEXEC;
	}

	shell_fprintf(sh, SHELL_NORMAL,
		"Listen interval %hu\n", params.listen_interval);

	return 0;
}


SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap,
	SHELL_CMD(disable, NULL,
		  "Disable Access Point mode",
@@ -932,6 +966,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands,
	SHELL_CMD(ps_timeout, NULL,
		  "Configure Wi-Fi power save inactivity timer(in ms)",
		  cmd_wifi_ps_timeout),
	SHELL_CMD_ARG(ps_listen_interval,
		      NULL,
		      "<val> - Listen interval in the range of <0-65535>",
		      cmd_wifi_listen_interval,
		      2,
		      0),
	SHELL_SUBCMD_SET_END
);