Skip to content

Commit c6d1a91

Browse files
ajayparidahenrikbrixandersen
authored andcommitted
net: wifi_mgmt: Support to configure AP mode parameter
Support to set BSS parameter at compile and run time. Added support to configure `max_inactivity` BSS parameter. Station inactivity timeout is the period for which AP may keep a client in associated state while there is no traffic from that particular client. If a non-zero value is set, AP may choose to disassociate the client after the timeout. Signed-off-by: Ajay Parida <ajay.parida@nordicsemi.no>
1 parent 180c22a commit c6d1a91

File tree

5 files changed

+133
-2
lines changed

5 files changed

+133
-2
lines changed

include/zephyr/net/wifi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ static inline const char *wifi_ps_get_config_err_code_str(int16_t err_no)
494494
return "<unknown>";
495495
}
496496

497+
/** @brief Wi-Fi AP mode configuration parameter */
498+
enum wifi_ap_config_param {
499+
/** Used for AP mode configuration parameter ap_max_inactivity */
500+
WIFI_AP_CONFIG_PARAM_MAX_INACTIVITY = BIT(0),
501+
};
502+
497503
#ifdef __cplusplus
498504
}
499505
#endif

include/zephyr/net/wifi_mgmt.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ enum net_request_wifi_cmd {
8888
NET_REQUEST_WIFI_CMD_VERSION,
8989
/** Set RTS threshold */
9090
NET_REQUEST_WIFI_CMD_RTS_THRESHOLD,
91-
91+
/** Configure AP parameter */
92+
NET_REQUEST_WIFI_CMD_AP_CONFIG_PARAM,
9293
/** @cond INTERNAL_HIDDEN */
9394
NET_REQUEST_WIFI_CMD_MAX
9495
/** @endcond */
@@ -190,6 +191,12 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_VERSION);
190191

191192
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD);
192193

194+
/** Request a Wi-Fi AP parameters configuration */
195+
#define NET_REQUEST_WIFI_AP_CONFIG_PARAM \
196+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_CONFIG_PARAM)
197+
198+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM);
199+
193200
/** @brief Wi-Fi management events */
194201
enum net_event_wifi_cmd {
195202
/** Scan results available */
@@ -746,6 +753,18 @@ struct wifi_channel_info {
746753
enum wifi_mgmt_op oper;
747754
};
748755

756+
/** @cond INTERNAL_HIDDEN */
757+
#define WIFI_AP_STA_MAX_INACTIVITY (LONG_MAX - 1)
758+
/** @endcond */
759+
760+
/** @brief Wi-Fi AP configuration parameter */
761+
struct wifi_ap_config_params {
762+
/** Parameter used to identify the different AP parameters */
763+
enum wifi_ap_config_param type;
764+
/** Parameter used for setting maximum inactivity duration for stations */
765+
uint32_t max_inactivity;
766+
};
767+
749768
#include <zephyr/net/net_if.h>
750769

751770
/** Scan result callback
@@ -919,7 +938,14 @@ struct wifi_mgmt_ops {
919938
* @return 0 if ok, < 0 if error
920939
*/
921940
int (*set_rts_threshold)(const struct device *dev, unsigned int rts_threshold);
922-
941+
/** Configure AP parameter
942+
*
943+
* @param dev Pointer to the device structure for the driver instance.
944+
* @param params AP mode parameter configuration parameter info
945+
*
946+
* @return 0 if ok, < 0 if error
947+
*/
948+
int (*ap_config_params)(const struct device *dev, struct wifi_ap_config_params *params);
923949
};
924950

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

subsys/net/l2/wifi/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,12 @@ module-str = Log level for Wi-Fi Network manager module
9393
module-help = Enables using the Wi-Fi Network managers to manage the Wi-Fi network interfaces.
9494
source "subsys/net/Kconfig.template.log_config.net"
9595
endif # WIFI_NM
96+
97+
config WIFI_MGMT_AP_STA_INACTIVITY_TIMEOUT
98+
int "Station inactivity timeout in seconds"
99+
default 300
100+
help
101+
Station inactivity timeout is the period for which AP may keep a client
102+
in associated state while there is no traffic from that particular
103+
client. If a non-zero value is set, AP may choose to disassociate the
104+
client after the timeout.

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,31 @@ static int wifi_ap_sta_disconnect(uint32_t mgmt_request, struct net_if *iface,
435435

436436
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_STA_DISCONNECT, wifi_ap_sta_disconnect);
437437

438+
static int wifi_ap_config_params(uint32_t mgmt_request, struct net_if *iface,
439+
void *data, size_t len)
440+
{
441+
const struct device *dev = net_if_get_device(iface);
442+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
443+
struct wifi_ap_config_params *params = data;
444+
445+
if (dev == NULL) {
446+
return -ENODEV;
447+
}
448+
449+
if (wifi_mgmt_api == NULL ||
450+
wifi_mgmt_api->ap_config_params == NULL) {
451+
return -ENOTSUP;
452+
}
453+
454+
if (!data || len != sizeof(*params)) {
455+
return -EINVAL;
456+
}
457+
458+
return wifi_mgmt_api->ap_config_params(dev, params);
459+
}
460+
461+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_CONFIG_PARAM, wifi_ap_config_params);
462+
438463
static int wifi_iface_status(uint32_t mgmt_request, struct net_if *iface,
439464
void *data, size_t len)
440465
{

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,65 @@ static int cmd_wifi_ap_sta_disconnect(const struct shell *sh, size_t argc,
13701370
return 0;
13711371
}
13721372

1373+
static int wifi_ap_config_args_to_params(const struct shell *sh, size_t argc, char *argv[],
1374+
struct wifi_ap_config_params *params)
1375+
{
1376+
struct getopt_state *state;
1377+
int opt;
1378+
static struct option long_options[] = {{"max_inactivity", required_argument, 0, 'i'},
1379+
{"help", no_argument, 0, 'h'},
1380+
{0, 0, 0, 0}};
1381+
int opt_index = 0;
1382+
long val;
1383+
1384+
while ((opt = getopt_long(argc, argv, "i:h", long_options, &opt_index)) != -1) {
1385+
state = getopt_state_get();
1386+
switch (opt) {
1387+
case 'i':
1388+
if (!parse_number(sh, &val, optarg, "max_inactivity",
1389+
0, WIFI_AP_STA_MAX_INACTIVITY)) {
1390+
return -EINVAL;
1391+
}
1392+
params->max_inactivity = (uint32_t)val;
1393+
params->type |= WIFI_AP_CONFIG_PARAM_MAX_INACTIVITY;
1394+
break;
1395+
case 'h':
1396+
shell_help(sh);
1397+
return SHELL_CMD_HELP_PRINTED;
1398+
default:
1399+
PR_ERROR("Invalid option %c\n", optopt);
1400+
shell_help(sh);
1401+
return SHELL_CMD_HELP_PRINTED;
1402+
}
1403+
}
1404+
1405+
return 0;
1406+
}
1407+
1408+
static int cmd_wifi_ap_config_params(const struct shell *sh, size_t argc,
1409+
char *argv[])
1410+
{
1411+
struct net_if *iface = net_if_get_first_wifi();
1412+
struct wifi_ap_config_params ap_config_params = { 0 };
1413+
int ret = -1;
1414+
1415+
context.sh = sh;
1416+
1417+
if (wifi_ap_config_args_to_params(sh, argc, argv, &ap_config_params)) {
1418+
return -ENOEXEC;
1419+
}
1420+
1421+
ret = net_mgmt(NET_REQUEST_WIFI_AP_CONFIG_PARAM, iface,
1422+
&ap_config_params, sizeof(struct wifi_ap_config_params));
1423+
if (ret) {
1424+
PR_WARNING("Setting AP parameter failed: %s\n",
1425+
strerror(-ret));
1426+
return -ENOEXEC;
1427+
}
1428+
1429+
return 0;
1430+
}
1431+
13731432
static int cmd_wifi_reg_domain(const struct shell *sh, size_t argc,
13741433
char *argv[])
13751434
{
@@ -1893,6 +1952,12 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_cmd_ap,
18931952
"<MAC address of the station>\n",
18941953
cmd_wifi_ap_sta_disconnect,
18951954
2, 0),
1955+
SHELL_CMD_ARG(config, NULL,
1956+
"Configure AP parameters.\n"
1957+
"-i --max_inactivity=<time duration (in seconds)>\n"
1958+
"-h --help (prints help)",
1959+
cmd_wifi_ap_config_params,
1960+
2, 3),
18961961
SHELL_SUBCMD_SET_END
18971962
);
18981963

0 commit comments

Comments
 (0)