Skip to content

Commit 0905478

Browse files
ajayparidacarlescufi
authored andcommitted
[nrf noup] wifi_mgmt: Add support for configuring PS exit strategy
If AP indicates the presence of buffered traffic, then it is up to the STA to decide whether to stay in PS or come out of PS, add configuration options that can be used at runtime to choose this. This is tagged as "noup" because it's a backport and "fromlist" cannot be used as it won't apply cleanly. Signed-off-by: Ajay Parida <[email protected]>
1 parent 02ae5d8 commit 0905478

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

include/zephyr/net/wifi.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ enum wifi_ps_param_type {
398398
WIFI_PS_PARAM_WAKEUP_MODE,
399399
/** Power save mode. */
400400
WIFI_PS_PARAM_MODE,
401+
/** Power save exit strategy. */
402+
WIFI_PS_PARAM_EXIT_STRATEGY,
401403
/** Power save timeout. */
402404
WIFI_PS_PARAM_TIMEOUT,
403405
};
@@ -413,6 +415,24 @@ enum wifi_ps_wakeup_mode {
413415
/** Helper function to get user-friendly ps wakeup mode name. */
414416
const char *wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode);
415417

418+
/**
419+
* Wi-Fi power save exit strategy
420+
*/
421+
enum wifi_ps_exit_strategy {
422+
/** PS-Poll frame based */
423+
WIFI_PS_EXIT_CUSTOM_ALGO = 0,
424+
/** QoS NULL frame based */
425+
WIFI_PS_EXIT_EVERY_TIM,
426+
427+
/** Last value */
428+
WIFI_PS_EXIT_LAST,
429+
/** Maximum value */
430+
WIFI_PS_EXIT_MAX = WIFI_PS_EXIT_LAST - 1,
431+
};
432+
433+
/** Helper function to get user-friendly ps exit strategy name. */
434+
const char * const wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strategy);
435+
416436
/** Wi-Fi power save error codes. */
417437
enum wifi_config_ps_param_fail_reason {
418438
/** Unspecified error */
@@ -429,6 +449,8 @@ enum wifi_config_ps_param_fail_reason {
429449
WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED,
430450
/** Listen interval out of range */
431451
WIFI_PS_PARAM_LISTEN_INTERVAL_RANGE_INVALID,
452+
/** Invalid exit strategy */
453+
WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY,
432454
};
433455

434456
/** @cond INTERNAL_HIDDEN */

include/zephyr/net/wifi_mgmt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ struct wifi_ps_params {
482482
enum wifi_ps_param_type type;
483483
/** Wi-Fi power save fail reason */
484484
enum wifi_config_ps_param_fail_reason fail_reason;
485+
/** Wi-Fi power save exit strategy */
486+
enum wifi_ps_exit_strategy exit_strategy;
485487
};
486488

487489
/** Wi-Fi TWT parameters */

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ const char *wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode)
235235
}
236236
}
237237

238+
const char * const wifi_ps_exit_strategy_txt(enum wifi_ps_exit_strategy ps_exit_strategy)
239+
{
240+
switch (ps_exit_strategy) {
241+
case WIFI_PS_EXIT_EVERY_TIM:
242+
return "Every TIM";
243+
case WIFI_PS_EXIT_CUSTOM_ALGO:
244+
return "Custom algorithm";
245+
default:
246+
return "UNKNOWN";
247+
}
248+
}
249+
238250
static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface)
239251
{
240252
const struct device *dev = net_if_get_device(iface);
@@ -515,6 +527,13 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
515527
case WIFI_PS_PARAM_WAKEUP_MODE:
516528
case WIFI_PS_PARAM_TIMEOUT:
517529
break;
530+
case WIFI_PS_PARAM_EXIT_STRATEGY:
531+
if (ps_params->exit_strategy > WIFI_PS_EXIT_MAX) {
532+
ps_params->fail_reason =
533+
WIFI_PS_PARAM_FAIL_INVALID_EXIT_STRATEGY;
534+
return -EINVAL;
535+
}
536+
break;
518537
default:
519538
ps_params->fail_reason =
520539
WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED;

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,9 @@ static int cmd_wifi_ps(const struct shell *sh, size_t argc, char *argv[])
915915
PR("PS timeout: disabled\n");
916916
}
917917

918+
shell_fprintf(sh, SHELL_NORMAL, "PS exit strategy: %s\n",
919+
wifi_ps_exit_strategy_txt(config.ps_params.exit_strategy));
920+
918921
if (config.num_twt_flows == 0) {
919922
PR("No TWT flows\n");
920923
} else {
@@ -1482,6 +1485,40 @@ static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *ar
14821485
return 0;
14831486
}
14841487

1488+
static int cmd_wifi_ps_exit_strategy(const struct shell *sh, size_t argc,
1489+
char *argv[])
1490+
{
1491+
struct net_if *iface = net_if_get_first_wifi();
1492+
struct wifi_ps_params params = { 0 };
1493+
1494+
context.sh = sh;
1495+
1496+
if (!strncmp(argv[1], "tim", 3)) {
1497+
params.exit_strategy = WIFI_PS_EXIT_EVERY_TIM;
1498+
} else if (!strncmp(argv[1], "custom", 6)) {
1499+
params.exit_strategy = WIFI_PS_EXIT_CUSTOM_ALGO;
1500+
} else {
1501+
shell_fprintf(sh, SHELL_WARNING, "Invalid argument\n");
1502+
shell_fprintf(sh, SHELL_INFO, "Valid argument : <tim> / <custom>\n");
1503+
return -ENOEXEC;
1504+
}
1505+
1506+
params.type = WIFI_PS_PARAM_EXIT_STRATEGY;
1507+
1508+
if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
1509+
shell_fprintf(sh, SHELL_WARNING,
1510+
"Setting PS exit strategy to %s failed..Reason :%s\n",
1511+
wifi_ps_exit_strategy_txt(params.exit_strategy),
1512+
wifi_ps_get_config_err_code_str(params.fail_reason));
1513+
return -ENOEXEC;
1514+
}
1515+
1516+
shell_fprintf(sh, SHELL_NORMAL, "%s\n",
1517+
wifi_ps_exit_strategy_txt(params.exit_strategy));
1518+
1519+
return 0;
1520+
}
1521+
14851522
void parse_mode_args_to_params(const struct shell *sh, int argc,
14861523
char *argv[], struct wifi_mode_info *mode,
14871524
bool *do_mode_oper)
@@ -1977,6 +2014,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands,
19772014
cmd_wifi_ps_wakeup_mode,
19782015
2,
19792016
0),
2017+
SHELL_CMD_ARG(ps_exit_strategy,
2018+
NULL,
2019+
"<tim> : Set PS exit strategy to Every TIM\n"
2020+
"<custom> : Set PS exit strategy to Custom",
2021+
cmd_wifi_ps_exit_strategy,
2022+
2,
2023+
0),
19802024
SHELL_SUBCMD_SET_END
19812025
);
19822026

0 commit comments

Comments
 (0)