Skip to content

Commit f0883b8

Browse files
committed
treewide: Configure BSS max idle period
Support to configure BSS max idle period at runtime. Signed-off-by: Ajay Parida <[email protected]>
1 parent 4cae466 commit f0883b8

File tree

12 files changed

+174
-2
lines changed

12 files changed

+174
-2
lines changed

drivers/wifi/nrf_wifi/inc/fmac_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct nrf_wifi_vif_ctx_zep {
8888
struct k_work_delayable nrf_wifi_rpu_recovery_bringup_work;
8989
#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
9090
int rts_threshold_value;
91+
bool bss_max_idle_period_user_set;
92+
unsigned short bss_max_idle_period;
9193
};
9294

9395
struct nrf_wifi_vif_ctx_map {

drivers/wifi/nrf_wifi/inc/wifi_mgmt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ int nrf_wifi_set_rts_threshold(const struct device *dev,
7575

7676
int nrf_wifi_get_rts_threshold(const struct device *dev,
7777
unsigned int *rts_threshold);
78+
79+
int nrf_wifi_set_bss_max_idle_period(const struct device *dev,
80+
unsigned short bss_max_idle_period);
7881
#endif /* __ZEPHYR_WIFI_MGMT_H__ */

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ static const struct wifi_mgmt_ops nrf_wifi_mgmt_ops = {
865865
.get_power_save_config = nrf_wifi_get_power_save_config,
866866
.set_rts_threshold = nrf_wifi_set_rts_threshold,
867867
.get_rts_threshold = nrf_wifi_get_rts_threshold,
868+
.set_bss_max_idle_period = nrf_wifi_set_bss_max_idle_period,
868869
#endif
869870
#ifdef CONFIG_NRF70_SYSTEM_WITH_RAW_MODES
870871
.mode = nrf_wifi_mode,

drivers/wifi/nrf_wifi/src/wifi_mgmt.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,3 +1080,56 @@ int nrf_wifi_get_rts_threshold(const struct device *dev,
10801080

10811081
return ret;
10821082
}
1083+
1084+
int nrf_wifi_set_bss_max_idle_period(const struct device *dev,
1085+
unsigned short bss_max_idle_period)
1086+
{
1087+
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
1088+
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
1089+
int ret = -1;
1090+
1091+
if (!dev) {
1092+
LOG_ERR("%s: dev is NULL", __func__);
1093+
return ret;
1094+
}
1095+
1096+
vif_ctx_zep = dev->data;
1097+
1098+
if (!vif_ctx_zep) {
1099+
LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
1100+
return ret;
1101+
}
1102+
1103+
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
1104+
1105+
if (!rpu_ctx_zep) {
1106+
LOG_ERR("%s: rpu_ctx_zep is NULL", __func__);
1107+
return ret;
1108+
}
1109+
1110+
1111+
if (!rpu_ctx_zep->rpu_ctx) {
1112+
LOG_ERR("%s: RPU context not initialized", __func__);
1113+
return ret;
1114+
}
1115+
1116+
if (((int)bss_max_idle_period < 0) ||
1117+
(bss_max_idle_period > 64000)) {
1118+
/* 0 or value less than 64000 is passed to f/w.
1119+
* All other values considered as invalid.
1120+
*/
1121+
LOG_ERR("%s: Invalid max_idle_period value : %d", __func__, (int)bss_max_idle_period);
1122+
return ret;
1123+
}
1124+
1125+
k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER);
1126+
1127+
vif_ctx_zep->bss_max_idle_period_user_set = true;
1128+
vif_ctx_zep->bss_max_idle_period = bss_max_idle_period;
1129+
1130+
ret = 0;
1131+
1132+
k_mutex_unlock(&vif_ctx_zep->vif_lock);
1133+
1134+
return ret;
1135+
}

drivers/wifi/nrf_wifi/src/wpa_supp_if.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,10 @@ int nrf_wifi_wpa_supp_associate(void *if_priv, struct wpa_driver_associate_param
931931
assoc_info.use_mfp = NRF_WIFI_MFP_REQUIRED;
932932
}
933933

934-
if (params->bss_max_idle_period) {
935-
assoc_info.bss_max_idle_time = params->bss_max_idle_period;
934+
if (vif_ctx_zep->bss_max_idle_period_user_set) {
935+
assoc_info.bss_max_idle_time = vif_ctx_zep->bss_max_idle_period;
936+
} else {
937+
assoc_info.bss_max_idle_time = CONFIG_WIFI_MGMT_BSS_MAX_IDLE_TIME;
936938
}
937939

938940
status = nrf_wifi_sys_fmac_assoc(rpu_ctx_zep->rpu_ctx, vif_ctx_zep->vif_idx, &assoc_info);

include/zephyr/net/wifi_mgmt.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ enum net_request_wifi_cmd {
133133
NET_REQUEST_WIFI_CMD_CANDIDATE_SCAN,
134134
/** AP WPS config */
135135
NET_REQUEST_WIFI_CMD_AP_WPS_CONFIG,
136+
/** Configure BSS maximum idle period */
137+
NET_REQUEST_WIFI_CMD_BSS_MAX_IDLE_PERIOD,
136138
/** @cond INTERNAL_HIDDEN */
137139
NET_REQUEST_WIFI_CMD_MAX
138140
/** @endcond */
@@ -317,6 +319,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_START_ROAMING);
317319

318320
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_NEIGHBOR_REP_COMPLETE);
319321

322+
#define NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD \
323+
(NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_BSS_MAX_IDLE_PERIOD)
324+
325+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD);
326+
320327
/** @cond INTERNAL_HIDDEN */
321328

322329
enum {
@@ -1598,6 +1605,15 @@ struct wifi_mgmt_ops {
15981605
* @return 0 if ok, < 0 if error
15991606
*/
16001607
int (*start_11r_roaming)(const struct device *dev);
1608+
/** Set BSS max idle period
1609+
*
1610+
* @param dev Pointer to the device structure for the driver instance.
1611+
* @param BSS max idle period value
1612+
*
1613+
* @return 0 if ok, < 0 if error
1614+
*/
1615+
int (*set_bss_max_idle_period)(const struct device *dev,
1616+
unsigned short bss_max_idle_period);
16011617
};
16021618

16031619
/** Wi-Fi management offload API */

modules/hostap/src/supp_api.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,19 @@ int supplicant_legacy_roam(const struct device *dev)
17721772
return ret;
17731773
}
17741774

1775+
int supplicant_set_bss_max_idle_period(const struct device *dev,
1776+
unsigned short bss_max_idle_period)
1777+
{
1778+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
1779+
1780+
if (!wifi_mgmt_api || !wifi_mgmt_api->set_bss_max_idle_period) {
1781+
wpa_printf(MSG_ERROR, "set_bss_max_idle_period is not supported");
1782+
return -ENOTSUP;
1783+
}
1784+
1785+
return wifi_mgmt_api->set_bss_max_idle_period(dev, bss_max_idle_period);
1786+
}
1787+
17751788
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM
17761789
int supplicant_btm_query(const struct device *dev, uint8_t reason)
17771790
{

modules/hostap/src/supp_api.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ int supplicant_get_wifi_conn_params(const struct device *dev,
305305
*/
306306
int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params);
307307

308+
/** @ Set Wi-Fi max idle period
309+
*
310+
* @param dev Wi-Fi interface handle to use
311+
* @param bss_max_idle_period Maximum idle period to set
312+
* @return 0 for OK; -1 for ERROR
313+
*/
314+
int supplicant_set_bss_max_idle_period(const struct device *dev,
315+
unsigned short bss_max_idle_period);
308316
#ifdef CONFIG_AP
309317
int set_ap_bandwidth(const struct device *dev, enum wifi_frequency_bandwidths bandwidth);
310318

modules/hostap/src/supp_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static const struct wifi_mgmt_ops mgmt_ops = {
8181
#endif
8282
.get_conn_params = supplicant_get_wifi_conn_params,
8383
.wps_config = supplicant_wps_config,
84+
.set_bss_max_idle_period = supplicant_set_bss_max_idle_period,
8485
#ifdef CONFIG_AP
8586
.ap_enable = supplicant_ap_enable,
8687
.ap_disable = supplicant_ap_disable,

subsys/net/l2/wifi/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,19 @@ config HEAP_MEM_POOL_ADD_SIZE_WIFI_CERT
149149
endif # WIFI_SHELL_RUNTIME_CERTIFICATES
150150

151151
endif # WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
152+
153+
config WIFI_MGMT_BSS_MAX_IDLE_TIME
154+
int "BSS max idle timeout in seconds"
155+
range 0 64000
156+
default 300
157+
help
158+
As per 802.11-2020: 11.21.13 BSS max idle period management
159+
If dot11WirelessManagementImplemented is true, dot11BSSMaxIdlePeriod is
160+
nonzero and dot11BSSMaxIdlePeriodIndicationByNonAPSTA is true, then a
161+
non-S1G non-AP STA shall include a BSS Max Idle Period element
162+
in the (Re)Association Request frame. If the BSS Max Idle Period
163+
element is present in the (Re)Association Request frame received
164+
by a non-S1G AP that has dot11BSSMaxIdlePeriodIndicationByNonAPSTA
165+
equal to true, then the non-S1G AP may choose the non-AP STA’s
166+
preferred maximum idle period. The non-S1G AP indicates its chosen
167+
value to the non-S1G STA in the (Re)Association Response frame.

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,31 @@ static int wifi_set_enterprise_creds(uint64_t mgmt_request, struct net_if *iface
14031403
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_ENTERPRISE_CREDS, wifi_set_enterprise_creds);
14041404
#endif
14051405

1406+
static int wifi_set_bss_max_idle_period(uint64_t mgmt_request, struct net_if *iface,
1407+
void *data, size_t len)
1408+
{
1409+
const struct device *dev = net_if_get_device(iface);
1410+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
1411+
unsigned short *bss_max_idle_period = data;
1412+
1413+
if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_bss_max_idle_period == NULL) {
1414+
return -ENOTSUP;
1415+
}
1416+
1417+
if (!net_if_is_admin_up(iface)) {
1418+
return -ENETDOWN;
1419+
}
1420+
1421+
if (!data || len != sizeof(*bss_max_idle_period)) {
1422+
return -EINVAL;
1423+
}
1424+
1425+
return wifi_mgmt_api->set_bss_max_idle_period(dev, *bss_max_idle_period);
1426+
}
1427+
1428+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD,
1429+
wifi_set_bss_max_idle_period);
1430+
14061431
#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
14071432
void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface,
14081433
struct wifi_raw_scan_result *raw_scan_result)

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,6 +3807,32 @@ static int cmd_wifi_pmksa_flush(const struct shell *sh, size_t argc, char *argv[
38073807

38083808
return 0;
38093809
}
3810+
3811+
static int cmd_wifi_set_bss_max_idle_period(const struct shell *sh, size_t argc, char *argv[])
3812+
{
3813+
struct net_if *iface = get_iface(IFACE_TYPE_STA, argc, argv);
3814+
unsigned short bss_max_idle_period = 0;
3815+
int idx = 1;
3816+
unsigned long val = 0;
3817+
3818+
if (!parse_number(sh, &val, argv[idx++], "bss_max_idle_period", 0, USHRT_MAX)) {
3819+
return -EINVAL;
3820+
}
3821+
3822+
bss_max_idle_period = (unsigned short)val;
3823+
3824+
if (net_mgmt(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD, iface,
3825+
&bss_max_idle_period, sizeof(bss_max_idle_period))) {
3826+
shell_fprintf(sh, SHELL_WARNING,
3827+
"Setting BSS maximum idle period failed.\n");
3828+
return -ENOEXEC;
3829+
}
3830+
3831+
shell_fprintf(sh, SHELL_NORMAL, "BSS max idle period: %hu\n", bss_max_idle_period);
3832+
3833+
return 0;
3834+
}
3835+
38103836
SHELL_STATIC_SUBCMD_SET_CREATE(
38113837
wifi_cmd_ap,
38123838
SHELL_CMD_ARG(disable, NULL, "Disable Access Point mode.\n"
@@ -4285,6 +4311,12 @@ SHELL_SUBCMD_ADD((wifi), ps_exit_strategy, NULL,
42854311
cmd_wifi_ps_exit_strategy,
42864312
2, 2);
42874313

4314+
SHELL_SUBCMD_ADD((wifi), bss_max_idle_period, NULL,
4315+
"<bss_max_idle: timeout(in TUs)>.\n"
4316+
"[-i, --iface=<interface index>] : Interface index.\n",
4317+
cmd_wifi_set_bss_max_idle_period,
4318+
2, 2);
4319+
42884320
SHELL_CMD_REGISTER(wifi, &wifi_commands, "Wi-Fi commands", NULL);
42894321

42904322
static int wifi_shell_init(void)

0 commit comments

Comments
 (0)