Skip to content

Commit b7db759

Browse files
Rex-Chen-NXPkrish2718
authored andcommitted
[nrf fromtree] net: wifi: shell: add wps support
Add wps pin and wps pbc L2 layer cmd support. Signed-off-by: Rex Chen <[email protected]> (cherry picked from commit 82ec1d7)
1 parent 2e42163 commit b7db759

File tree

7 files changed

+207
-2
lines changed

7 files changed

+207
-2
lines changed

include/zephyr/net/wifi_mgmt.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ enum net_request_wifi_cmd {
106106
NET_REQUEST_WIFI_CMD_ENTERPRISE_CREDS,
107107
/** Get RTS threshold */
108108
NET_REQUEST_WIFI_CMD_RTS_THRESHOLD_CONFIG,
109-
/** @cond INTERNAL_HIDDEN */
109+
/** WPS config */
110+
NET_REQUEST_WIFI_CMD_WPS_CONFIG,
111+
/** @cond INTERNAL_HIDDEN */
110112
NET_REQUEST_WIFI_CMD_MAX
111113
/** @endcond */
112114
};
@@ -252,6 +254,10 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_ENTERPRISE_CREDS);
252254

253255
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_RTS_THRESHOLD_CONFIG);
254256

257+
#define NET_REQUEST_WIFI_WPS_CONFIG (_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_WPS_CONFIG)
258+
259+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG);
260+
255261
/** @brief Wi-Fi management events */
256262
enum net_event_wifi_cmd {
257263
/** Scan results available */
@@ -1030,6 +1036,26 @@ struct wifi_dpp_params {
10301036
};
10311037
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */
10321038

1039+
#define WIFI_WPS_PIN_MAX_LEN 8
1040+
1041+
/** Operation for WPS */
1042+
enum wifi_wps_op {
1043+
/** WPS pbc */
1044+
WIFI_WPS_PBC = 0,
1045+
/** Get WPS pin number */
1046+
WIFI_WPS_PIN_GET = 1,
1047+
/** Set WPS pin number */
1048+
WIFI_WPS_PIN_SET = 2,
1049+
};
1050+
1051+
/** Wi-Fi wps setup */
1052+
struct wifi_wps_config_params {
1053+
/** wps operation */
1054+
enum wifi_wps_op oper;
1055+
/** pin value*/
1056+
char pin[WIFI_WPS_PIN_MAX_LEN + 1];
1057+
};
1058+
10331059
#include <zephyr/net/net_if.h>
10341060

10351061
/** Scan result callback
@@ -1273,6 +1299,14 @@ struct wifi_mgmt_ops {
12731299
* @return 0 if ok, < 0 if error
12741300
*/
12751301
int (*get_rts_threshold)(const struct device *dev, unsigned int *rts_threshold);
1302+
/** Start a WPS PBC/PIN connection
1303+
*
1304+
* @param dev Pointer to the device structure for the driver instance
1305+
* @param params wps operarion parameters
1306+
*
1307+
* @return 0 if ok, < 0 if error
1308+
*/
1309+
int (*wps_config)(const struct device *dev, struct wifi_wps_config_params *params);
12761310
};
12771311

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

modules/hostap/src/supp_api.c

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ static struct wifi_connect_req_params last_wifi_conn_params;
3535

3636
enum requested_ops {
3737
CONNECT = 0,
38-
DISCONNECT
38+
DISCONNECT,
39+
WPS_PBC,
40+
WPS_PIN,
3941
};
4042

4143
enum status_thread_state {
@@ -1320,6 +1322,91 @@ int supplicant_get_wifi_conn_params(const struct device *dev,
13201322
return ret;
13211323
}
13221324

1325+
static int supplicant_wps_pbc(const struct device *dev)
1326+
{
1327+
struct wpa_supplicant *wpa_s;
1328+
int ret = -1;
1329+
1330+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
1331+
1332+
wpa_s = get_wpa_s_handle(dev);
1333+
if (!wpa_s) {
1334+
ret = -1;
1335+
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
1336+
goto out;
1337+
}
1338+
1339+
if (!wpa_cli_cmd_v("wps_pbc")) {
1340+
goto out;
1341+
}
1342+
1343+
wpas_api_ctrl.dev = dev;
1344+
wpas_api_ctrl.requested_op = WPS_PBC;
1345+
1346+
ret = 0;
1347+
1348+
out:
1349+
k_mutex_unlock(&wpa_supplicant_mutex);
1350+
1351+
return ret;
1352+
}
1353+
1354+
static int supplicant_wps_pin(const struct device *dev, struct wifi_wps_config_params *params)
1355+
{
1356+
struct wpa_supplicant *wpa_s;
1357+
char *get_pin_cmd = "WPS_PIN get";
1358+
int ret = -1;
1359+
1360+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
1361+
1362+
wpa_s = get_wpa_s_handle(dev);
1363+
if (!wpa_s) {
1364+
ret = -1;
1365+
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
1366+
goto out;
1367+
}
1368+
1369+
if (params->oper == WIFI_WPS_PIN_GET) {
1370+
if (zephyr_wpa_cli_cmd_resp(get_pin_cmd, params->pin)) {
1371+
goto out;
1372+
}
1373+
} else if (params->oper == WIFI_WPS_PIN_SET) {
1374+
if (!wpa_cli_cmd_v("wps_check_pin %s", params->pin)) {
1375+
goto out;
1376+
}
1377+
1378+
if (!wpa_cli_cmd_v("wps_pin any %s", params->pin)) {
1379+
goto out;
1380+
}
1381+
1382+
wpas_api_ctrl.dev = dev;
1383+
wpas_api_ctrl.requested_op = WPS_PIN;
1384+
} else {
1385+
wpa_printf(MSG_ERROR, "Error wps pin operation : %d", params->oper);
1386+
goto out;
1387+
}
1388+
1389+
ret = 0;
1390+
1391+
out:
1392+
k_mutex_unlock(&wpa_supplicant_mutex);
1393+
1394+
return ret;
1395+
}
1396+
1397+
int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params)
1398+
{
1399+
int ret = 0;
1400+
1401+
if (params->oper == WIFI_WPS_PBC) {
1402+
ret = supplicant_wps_pbc(dev);
1403+
} else if (params->oper == WIFI_WPS_PIN_GET || params->oper == WIFI_WPS_PIN_SET) {
1404+
ret = supplicant_wps_pin(dev, params);
1405+
}
1406+
1407+
return ret;
1408+
}
1409+
13231410
#ifdef CONFIG_AP
13241411
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
13251412
int hapd_state(const struct device *dev, int *state)

modules/hostap/src/supp_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ int supplicant_btm_query(const struct device *dev, uint8_t reason);
215215
int supplicant_get_wifi_conn_params(const struct device *dev,
216216
struct wifi_connect_req_params *params);
217217

218+
/** Start a WPS PBC/PIN connection
219+
*
220+
* @param dev Pointer to the device structure for the driver instance
221+
* @param params wps operarion parameters
222+
*
223+
* @return 0 if ok, < 0 if error
224+
*/
225+
int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params);
226+
218227
#ifdef CONFIG_AP
219228
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
220229
/**

modules/hostap/src/supp_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static const struct wifi_mgmt_ops mgmt_ops = {
7575
.btm_query = supplicant_btm_query,
7676
#endif
7777
.get_conn_params = supplicant_get_wifi_conn_params,
78+
.wps_config = supplicant_wps_config,
7879
#ifdef CONFIG_AP
7980
.ap_enable = supplicant_ap_enable,
8081
.ap_disable = supplicant_ap_disable,

samples/net/wifi/boards/rd_rw612_bga.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ CONFIG_WIFI_NM_WPA_SUPPLICANT_INF_MON=n
8585
CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
8686
CONFIG_SAE_PWE_EARLY_EXIT=y
8787
CONFIG_WIFI_NM_HOSTAPD_AP=y
88+
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
8889

8990
# Enable mbedtls
9091
CONFIG_MBEDTLS=y

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,21 @@ static int wifi_get_connection_params(uint32_t mgmt_request, struct net_if *ifac
832832

833833
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONN_PARAMS, wifi_get_connection_params);
834834

835+
static int wifi_wps_config(uint32_t mgmt_request, struct net_if *iface, void *data, size_t len)
836+
{
837+
const struct device *dev = net_if_get_device(iface);
838+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
839+
struct wifi_wps_config_params *params = data;
840+
841+
if (wifi_mgmt_api == NULL || wifi_mgmt_api->wps_config == NULL) {
842+
return -ENOTSUP;
843+
}
844+
845+
return wifi_mgmt_api->wps_config(dev, params);
846+
}
847+
848+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_WPS_CONFIG, wifi_wps_config);
849+
835850
static int wifi_set_rts_threshold(uint32_t mgmt_request, struct net_if *iface,
836851
void *data, size_t len)
837852
{

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,57 @@ static int cmd_wifi_btm_query(const struct shell *sh, size_t argc, char *argv[])
17001700
}
17011701
#endif
17021702

1703+
static int cmd_wifi_wps_pbc(const struct shell *sh, size_t argc, char *argv[])
1704+
{
1705+
struct net_if *iface = net_if_get_first_wifi();
1706+
struct wifi_wps_config_params params = {0};
1707+
1708+
context.sh = sh;
1709+
1710+
if (argc == 1) {
1711+
params.oper = WIFI_WPS_PBC;
1712+
} else {
1713+
shell_help(sh);
1714+
return -ENOEXEC;
1715+
}
1716+
1717+
if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, &params, sizeof(params))) {
1718+
PR_WARNING("Start wps pbc connection failed\n");
1719+
return -ENOEXEC;
1720+
}
1721+
1722+
return 0;
1723+
}
1724+
1725+
static int cmd_wifi_wps_pin(const struct shell *sh, size_t argc, char *argv[])
1726+
{
1727+
struct net_if *iface = net_if_get_first_wifi();
1728+
struct wifi_wps_config_params params = {0};
1729+
1730+
context.sh = sh;
1731+
1732+
if (argc == 1) {
1733+
params.oper = WIFI_WPS_PIN_GET;
1734+
} else if (argc == 2) {
1735+
params.oper = WIFI_WPS_PIN_SET;
1736+
strncpy(params.pin, argv[1], WIFI_WPS_PIN_MAX_LEN);
1737+
} else {
1738+
shell_help(sh);
1739+
return -ENOEXEC;
1740+
}
1741+
1742+
if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, &params, sizeof(params))) {
1743+
PR_WARNING("Start wps pin connection failed\n");
1744+
return -ENOEXEC;
1745+
}
1746+
1747+
if (params.oper == WIFI_WPS_PIN_GET) {
1748+
PR("WPS PIN is: %s\n", params.pin);
1749+
}
1750+
1751+
return 0;
1752+
}
1753+
17031754
static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *argv[])
17041755
{
17051756
struct net_if *iface = net_if_get_first_wifi();
@@ -2960,6 +3011,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands,
29603011
cmd_wifi_btm_query,
29613012
2, 0),
29623013
#endif
3014+
SHELL_CMD_ARG(wps_pbc, NULL,
3015+
"Start a WPS PBC connection.\n",
3016+
cmd_wifi_wps_pbc, 1, 0),
3017+
SHELL_CMD_ARG(wps_pin, NULL,
3018+
"Set and get WPS pin.\n"
3019+
"[pin] Only applicable for set.\n",
3020+
cmd_wifi_wps_pin, 1, 1),
29633021
SHELL_CMD_ARG(ps_timeout,
29643022
NULL,
29653023
"<val> - PS inactivity timer(in ms).\n",

0 commit comments

Comments
 (0)