Skip to content

Commit

Permalink
net: wifi: shell: add parameters for twt setup
Browse files Browse the repository at this point in the history
Add two parameters for twt setup.

Signed-off-by: Rex Chen <[email protected]>
  • Loading branch information
Rex-Chen-NXP committed Dec 11, 2024
1 parent 39e41d3 commit 168973d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
4 changes: 3 additions & 1 deletion drivers/wifi/nxp/nxp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,11 +1356,13 @@ static int nxp_wifi_set_twt(const struct device *dev, struct wifi_twt_params *pa
twt_setup_conf.implicit = params->setup.implicit;
twt_setup_conf.announced = params->setup.announce;
twt_setup_conf.trigger_enabled = params->setup.trigger;
twt_setup_conf.twt_info_disabled = params->setup.twt_info_disable;
twt_setup_conf.negotiation_type = params->negotiation_type;
twt_setup_conf.twt_wakeup_duration = params->setup.twt_wake_interval;
twt_setup_conf.flow_identifier = params->flow_id;
twt_setup_conf.hard_constraint = 1;
twt_setup_conf.twt_mantissa = params->setup.twt_interval;
twt_setup_conf.twt_exponent = params->setup.twt_exponent;
twt_setup_conf.twt_mantissa = params->setup.twt_mantissa;
twt_setup_conf.twt_request = params->setup.responder;
ret = wlan_set_twt_setup_cfg(&twt_setup_conf);
} else if (params->operation == WIFI_TWT_TEARDOWN) {
Expand Down
7 changes: 7 additions & 0 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,12 @@ struct wifi_twt_params {
* prepare the data before TWT SP starts.
*/
uint32_t twt_wake_ahead_duration;
/** TWT info enabled or disable */
bool twt_info_disable;
/** TWT exponent */
uint8_t twt_exponent;
/** TWT Mantissa Range: [0-sizeof(UINT16)] */
uint16_t twt_mantissa;
} setup;
/** Setup specific parameters */
struct {
Expand Down Expand Up @@ -788,6 +794,7 @@ struct wifi_twt_params {
/* 256 (u8) * 1TU */
#define WIFI_MAX_TWT_WAKE_INTERVAL_US 262144
#define WIFI_MAX_TWT_WAKE_AHEAD_DURATION_US (LONG_MAX - 1)
#define WIFI_MAX_TWT_EXPONENT 31

/** @endcond */

Expand Down
60 changes: 58 additions & 2 deletions subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ LOG_MODULE_REGISTER(net_wifi_shell, LOG_LEVEL_INF);
#include <zephyr/sys/slist.h>

#include "net_shell_private.h"
#include <math.h>
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
static const char ca_cert_test[] = {
#include <wifi_enterprise_test_certs/ca.pem.inc>
Expand Down Expand Up @@ -1596,6 +1597,10 @@ static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
int opt_index = 0;
struct getopt_state *state;
long value;
double twt_mantissa_scale = 0.0;
double twt_interval_scale = 0.0;
uint16_t scale = 1000;
int exponent = 0;
static const struct option long_options[] = {
{"negotiation-type", required_argument, 0, 'n'},
{"setup-cmd", required_argument, 0, 'c'},
Expand All @@ -1608,12 +1613,15 @@ static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
{"wake-interval", required_argument, 0, 'w'},
{"interval", required_argument, 0, 'i'},
{"wake-ahead-duration", required_argument, 0, 'D'},
{"info-disable", required_argument, 0, 'd'},
{"exponent", required_argument, 0, 'e'},
{"mantissa", required_argument, 0, 'm'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}};

params->operation = WIFI_TWT_SETUP;

while ((opt = getopt_long(argc, argv, "n:c:t:f:r:T:I:a:t:w:i:D:d:e:h",
while ((opt = getopt_long(argc, argv, "n:c:t:f:r:T:I:a:t:w:i:D:d:e:m:h",
long_options, &opt_index)) != -1) {
state = getopt_state_get();
switch (opt) {
Expand Down Expand Up @@ -1702,11 +1710,56 @@ static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
params->setup.twt_wake_ahead_duration = (uint32_t)value;
break;

case 'd':
if (!parse_number(sh, &value, state->optarg, NULL, 0, 1)) {
return -EINVAL;
}
params->setup.twt_info_disable = (bool)value;
break;

case 'e':
if (!parse_number(sh, &value, state->optarg, NULL, 0,
WIFI_MAX_TWT_EXPONENT)) {
return -EINVAL;
}
params->setup.twt_exponent = (uint8_t)value;
break;

case 'm':
if (!parse_number(sh, &value, state->optarg, NULL, 0, 0xFFFF)) {
return -EINVAL;
}
params->setup.twt_mantissa = (uint16_t)value;
break;

case 'h':
return -ENOEXEC;
}
}

if ((params->setup.twt_interval != 0) &&
((params->setup.twt_exponent != 0) ||
(params->setup.twt_mantissa != 0))) {
PR_ERROR("Only one of TWT internal or (mantissa, exponent) should be used\n");
return -EINVAL;
}

if (params->setup.twt_interval) {
/* control the region of mantissa filed */
twt_interval_scale = (double)(params->setup.twt_interval / scale);
/* derive mantissa and exponent from interval */
twt_mantissa_scale = frexp(twt_interval_scale, &exponent);
params->setup.twt_mantissa = ceil(twt_mantissa_scale * scale);
params->setup.twt_exponent = exponent;
} else if ((params->setup.twt_exponent != 0) ||
(params->setup.twt_mantissa != 0)) {
params->setup.twt_interval = floor(ldexp(params->setup.twt_mantissa,
params->setup.twt_exponent));
} else {
PR_ERROR("Either TWT interval or (mantissa, exponent) is needed\n");
return -EINVAL;
}

return 0;
}

Expand Down Expand Up @@ -3317,9 +3370,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
"<-w --wake-interval>: 1-262144us\n"
"<-i --interval>: 1us-2^31us\n"
"<-D --wake-ahead-duration>: 0us-2^31us\n"
"<-d --info-disable>: 0/1\n"
"<-e --exponent>: 0-31\n"
"<-m --mantissa>: 1-2^16\n"
"[-h, --help]: Print out command usage.\n",
cmd_wifi_twt_setup,
23, 1),
25, 5),
SHELL_CMD_ARG(
btwt_setup, NULL,
" Start a BTWT flow:\n"
Expand Down

0 comments on commit 168973d

Please sign in to comment.