Skip to content

Commit a1f579a

Browse files
Rex-Chen-NXPkartben
authored andcommitted
net: wifi: shell: add btwt feature support
Add btwt_setup cmd for sap. Signed-off-by: Rex Chen <[email protected]>
1 parent f9a96f3 commit a1f579a

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

drivers/wifi/nxp/nxp_wifi_drv.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,22 @@ static int nxp_wifi_set_twt(const struct device *dev, struct wifi_twt_params *pa
15141514

15151515
return ret;
15161516
}
1517+
1518+
static int nxp_wifi_set_btwt(const struct device *dev, struct wifi_twt_params *params)
1519+
{
1520+
wlan_btwt_config_t btwt_config;
1521+
1522+
btwt_config.action = 1;
1523+
btwt_config.sub_id = params->btwt.sub_id;
1524+
btwt_config.nominal_wake = params->btwt.nominal_wake;
1525+
btwt_config.max_sta_support = params->btwt.max_sta_support;
1526+
btwt_config.twt_mantissa = params->btwt.twt_mantissa;
1527+
btwt_config.twt_offset = params->btwt.twt_offset;
1528+
btwt_config.twt_exponent = params->btwt.twt_exponent;
1529+
btwt_config.sp_gap = params->btwt.sp_gap;
1530+
1531+
return wlan_set_btwt_cfg(&btwt_config);
1532+
}
15171533
#endif
15181534

15191535
static void nxp_wifi_sta_init(struct net_if *iface)
@@ -1878,6 +1894,9 @@ static const struct wifi_mgmt_ops nxp_wifi_uap_mgmt = {
18781894
.set_power_save = nxp_wifi_power_save,
18791895
.get_power_save_config = nxp_wifi_get_power_save,
18801896
.ap_config_params = nxp_wifi_ap_config_params,
1897+
#ifdef CONFIG_NXP_WIFI_11AX_TWT
1898+
.set_btwt = nxp_wifi_set_btwt,
1899+
#endif
18811900
};
18821901

18831902
static const struct net_wifi_mgmt_offload nxp_wifi_uap_apis = {

include/zephyr/net/wifi_mgmt.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ enum net_request_wifi_cmd {
8585
NET_REQUEST_WIFI_CMD_PS,
8686
/** Setup or teardown TWT flow */
8787
NET_REQUEST_WIFI_CMD_TWT,
88+
/** Setup BTWT flow */
89+
NET_REQUEST_WIFI_CMD_BTWT,
8890
/** Get power save config */
8991
NET_REQUEST_WIFI_CMD_PS_CONFIG,
9092
/** Set or get regulatory domain */
@@ -194,6 +196,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PS);
194196

195197
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT);
196198

199+
#define NET_REQUEST_WIFI_BTWT \
200+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_BTWT)
201+
202+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_BTWT);
203+
197204
/** Request a Wi-Fi power save configuration */
198205
#define NET_REQUEST_WIFI_PS_CONFIG \
199206
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_PS_CONFIG)
@@ -750,6 +757,23 @@ struct wifi_twt_params {
750757
*/
751758
uint32_t twt_wake_ahead_duration;
752759
} setup;
760+
/** Setup specific parameters */
761+
struct {
762+
/** Broadcast TWT AP config */
763+
uint16_t sub_id;
764+
/** Range 64-255 */
765+
uint8_t nominal_wake;
766+
/** Max STA support */
767+
uint8_t max_sta_support;
768+
/** TWT mantissa */
769+
uint16_t twt_mantissa;
770+
/** TWT offset */
771+
uint16_t twt_offset;
772+
/** TWT exponent */
773+
uint8_t twt_exponent;
774+
/** SP gap */
775+
uint8_t sp_gap;
776+
} btwt;
753777
/** Teardown specific parameters */
754778
struct {
755779
/** Teardown all flows */
@@ -1365,6 +1389,14 @@ struct wifi_mgmt_ops {
13651389
* @return 0 if ok, < 0 if error
13661390
*/
13671391
int (*set_twt)(const struct device *dev, struct wifi_twt_params *params);
1392+
/** Setup BTWT flow
1393+
*
1394+
* @param dev Pointer to the device structure for the driver instance.
1395+
* @param params BTWT parameters
1396+
*
1397+
* @return 0 if ok, < 0 if error
1398+
*/
1399+
int (*set_btwt)(const struct device *dev, struct wifi_twt_params *params);
13681400
/** Get power save config
13691401
*
13701402
* @param dev Pointer to the device structure for the driver instance.

modules/hostap/src/supp_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,18 @@ int supplicant_set_twt(const struct device *dev, struct wifi_twt_params *params)
18151815
return wifi_mgmt_api->set_twt(dev, params);
18161816
}
18171817

1818+
int supplicant_set_btwt(const struct device *dev, struct wifi_twt_params *params)
1819+
{
1820+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
1821+
1822+
if (!wifi_mgmt_api || !wifi_mgmt_api->set_btwt) {
1823+
wpa_printf(MSG_ERROR, "Set Broadcast TWT not supported");
1824+
return -ENOTSUP;
1825+
}
1826+
1827+
return wifi_mgmt_api->set_btwt(dev, params);
1828+
}
1829+
18181830
int supplicant_get_power_save_config(const struct device *dev,
18191831
struct wifi_ps_config *config)
18201832
{

modules/hostap/src/supp_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ int supplicant_set_power_save(const struct device *dev, struct wifi_ps_params *p
156156
*/
157157
int supplicant_set_twt(const struct device *dev, struct wifi_twt_params *params);
158158

159+
/**
160+
* @brief Set Wi-Fi BTWT parameters
161+
*
162+
* @param dev Wi-Fi interface name to use
163+
* @param params BTWT parameters to set
164+
* @return 0 for OK; -1 for ERROR
165+
*/
166+
int supplicant_set_btwt(const struct device *dev, struct wifi_twt_params *params);
167+
159168
/**
160169
* @brief Get Wi-Fi power save configuration
161170
*

modules/hostap/src/supp_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = {
114114
#ifdef CONFIG_WIFI_NM_HOSTAPD_CRYPTO_ENTERPRISE
115115
.enterprise_creds = supplicant_add_enterprise_creds,
116116
#endif
117+
.set_btwt = supplicant_set_btwt,
117118
};
118119

119120
DEFINE_WIFI_NM_INSTANCE(hostapd, &mgmt_ap_ops);

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,35 @@ static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface,
916916

917917
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT, wifi_set_twt);
918918

919+
static int wifi_set_btwt(uint32_t mgmt_request, struct net_if *iface,
920+
void *data, size_t len)
921+
{
922+
const struct device *dev = net_if_get_device(iface);
923+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
924+
struct wifi_twt_params *twt_params = data;
925+
struct wifi_iface_status info = { 0 };
926+
927+
if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_btwt == NULL) {
928+
twt_params->fail_reason =
929+
WIFI_TWT_FAIL_OPERATION_NOT_SUPPORTED;
930+
return -ENOTSUP;
931+
}
932+
933+
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
934+
sizeof(struct wifi_iface_status))) {
935+
twt_params->fail_reason =
936+
WIFI_TWT_FAIL_UNABLE_TO_GET_IFACE_STATUS;
937+
goto fail;
938+
}
939+
940+
return wifi_mgmt_api->set_btwt(dev, twt_params);
941+
fail:
942+
return -ENOEXEC;
943+
944+
}
945+
946+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_BTWT, wifi_set_btwt);
947+
919948
void wifi_mgmt_raise_twt_event(struct net_if *iface, struct wifi_twt_params *twt_params)
920949
{
921950
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_TWT,

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,51 @@ static int cmd_wifi_twt_setup_quick(const struct shell *sh, size_t argc,
15721572
return 0;
15731573
}
15741574

1575+
static int cmd_wifi_btwt_setup(const struct shell *sh, size_t argc, char *argv[])
1576+
{
1577+
struct net_if *iface = net_if_get_wifi_sap();
1578+
struct wifi_twt_params params = {0};
1579+
int idx = 1;
1580+
long value;
1581+
int ret = 0;
1582+
1583+
context.sh = sh;
1584+
1585+
params.btwt.sub_id = (uint16_t)shell_strtol(argv[idx++], 10, &ret);
1586+
params.btwt.nominal_wake = (uint8_t)shell_strtol(argv[idx++], 10, &ret);
1587+
params.btwt.max_sta_support = (uint8_t)shell_strtol(argv[idx++], 10, &ret);
1588+
1589+
if (!parse_number(sh, &value, argv[idx++], NULL, 1, 0xFFFF)) {
1590+
return -EINVAL;
1591+
}
1592+
params.btwt.twt_mantissa = (uint16_t)value;
1593+
1594+
params.btwt.twt_offset = (uint16_t)shell_strtol(argv[idx++], 10, &ret);
1595+
1596+
if (!parse_number(sh, &value, argv[idx++], NULL, 0, WIFI_MAX_TWT_EXPONENT)) {
1597+
return -EINVAL;
1598+
}
1599+
params.btwt.twt_exponent = (uint8_t)value;
1600+
1601+
params.btwt.sp_gap = (uint8_t)shell_strtol(argv[idx++], 10, &ret);
1602+
1603+
if (ret) {
1604+
PR_ERROR("Invalid argument (ret %d)\n", ret);
1605+
return -EINVAL;
1606+
}
1607+
1608+
if (net_mgmt(NET_REQUEST_WIFI_BTWT, iface, &params, sizeof(params))) {
1609+
PR_WARNING("Failed reason : %s\n",
1610+
wifi_twt_get_err_code_str(params.fail_reason));
1611+
1612+
return -ENOEXEC;
1613+
}
1614+
1615+
PR("BTWT setup\n");
1616+
1617+
return 0;
1618+
}
1619+
15751620
static int twt_args_to_params(const struct shell *sh, size_t argc, char *argv[],
15761621
struct wifi_twt_params *params)
15771622
{
@@ -3344,6 +3389,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_twt_ops,
33443389
"[-h, --help]: Print out command usage.\n",
33453390
cmd_wifi_twt_setup,
33463391
23, 1),
3392+
SHELL_CMD_ARG(
3393+
btwt_setup, NULL,
3394+
" Start a BTWT flow:\n"
3395+
"<sub_id: Broadcast TWT AP config> <nominal_wake: 64-255> <max_sta_support>"
3396+
"<twt_mantissa:0-sizeof(UINT16)> <twt_offset> <twt_exponent: 0-31> <sp_gap>.\n",
3397+
cmd_wifi_btwt_setup,
3398+
8, 0),
33473399
SHELL_CMD_ARG(teardown, NULL, " Teardown a TWT flow:\n"
33483400
"<negotiation_type, 0: Individual, 1: Broadcast, 2: Wake TBTT>\n"
33493401
"<setup_cmd: 0: Request, 1: Suggest, 2: Demand>\n"

0 commit comments

Comments
 (0)