Skip to content

Commit 13f473d

Browse files
MaochenWang1kartben
authored andcommitted
hostap: add WPS PBC and PIN for AP mode
add WPS PBC and PIN for AP mode. Signed-off-by: Maochen Wang <[email protected]>
1 parent 358396e commit 13f473d

File tree

9 files changed

+191
-2
lines changed

9 files changed

+191
-2
lines changed

include/zephyr/net/wifi_mgmt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ enum net_request_wifi_cmd {
123123
NET_REQUEST_WIFI_CMD_NEIGHBOR_REP_COMPLETE,
124124
/** Specific scan */
125125
NET_REQUEST_WIFI_CMD_CANDIDATE_SCAN,
126+
/** AP WPS config */
127+
NET_REQUEST_WIFI_CMD_AP_WPS_CONFIG,
126128
/** @cond INTERNAL_HIDDEN */
127129
NET_REQUEST_WIFI_CMD_MAX
128130
/** @endcond */

modules/hostap/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS
365365
EAP_WSC
366366
)
367367

368+
zephyr_library_sources_ifdef(CONFIG_WIFI_NM_HOSTAPD_WPS
369+
${HOSTAP_SRC_BASE}/eap_server/eap_server_wsc.c
370+
)
371+
372+
zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_HOSTAPD_WPS
373+
EAP_SERVER_WSC
374+
)
375+
368376
zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
369377
${HOSTAP_SRC_BASE}/eap_common/eap_common.c
370378
)

modules/hostap/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ config WIFI_NM_WPA_SUPPLICANT_WPS
251251
bool "WPS support"
252252
depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
253253

254+
config WIFI_NM_HOSTAPD_WPS
255+
bool "WPS hostapd support"
256+
depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
257+
depends on WIFI_NM_HOSTAPD_AP
258+
254259
config WIFI_NM_WPA_SUPPLICANT_P2P
255260
bool "P2P mode support"
256261
select WIFI_NM_WPA_SUPPLICANT_AP

modules/hostap/src/supp_api.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,106 @@ int supplicant_ap_status(const struct device *dev, struct wifi_iface_status *sta
20862086
}
20872087
#endif /* CONFIG_WIFI_NM_HOSTAPD_AP */
20882088

2089+
#ifdef CONFIG_WIFI_NM_HOSTAPD_WPS
2090+
int supplicant_ap_wps_pbc(const struct device *dev)
2091+
{
2092+
struct hostapd_iface *iface;
2093+
int ret = -1;
2094+
2095+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
2096+
2097+
iface = get_hostapd_handle(dev);
2098+
if (!iface) {
2099+
ret = -1;
2100+
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
2101+
goto out;
2102+
}
2103+
2104+
if (iface->state != HAPD_IFACE_ENABLED) {
2105+
ret = -EBUSY;
2106+
wpa_printf(MSG_ERROR, "Interface %s is not in enable state", dev->name);
2107+
goto out;
2108+
}
2109+
2110+
if (!hostapd_cli_cmd_v("wps_pbc")) {
2111+
goto out;
2112+
}
2113+
2114+
wpas_api_ctrl.dev = dev;
2115+
wpas_api_ctrl.requested_op = WPS_PBC;
2116+
2117+
ret = 0;
2118+
2119+
out:
2120+
k_mutex_unlock(&wpa_supplicant_mutex);
2121+
2122+
return ret;
2123+
}
2124+
2125+
int supplicant_ap_wps_pin(const struct device *dev, struct wifi_wps_config_params *params)
2126+
{
2127+
struct hostapd_iface *iface;
2128+
char *get_pin_cmd = "WPS_AP_PIN random";
2129+
int ret = 0;
2130+
2131+
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);
2132+
2133+
iface = get_hostapd_handle(dev);
2134+
if (!iface) {
2135+
ret = -1;
2136+
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
2137+
goto out;
2138+
}
2139+
2140+
if (iface->state != HAPD_IFACE_ENABLED) {
2141+
ret = -EBUSY;
2142+
wpa_printf(MSG_ERROR, "Interface %s is not in enable state", dev->name);
2143+
goto out;
2144+
}
2145+
2146+
if (params->oper == WIFI_WPS_PIN_GET) {
2147+
if (zephyr_hostapd_cli_cmd_resp(get_pin_cmd, params->pin)) {
2148+
goto out;
2149+
}
2150+
} else if (params->oper == WIFI_WPS_PIN_SET) {
2151+
if (!hostapd_cli_cmd_v("wps_check_pin %s", params->pin)) {
2152+
goto out;
2153+
}
2154+
2155+
if (!hostapd_cli_cmd_v("wps_pin any %s", params->pin)) {
2156+
goto out;
2157+
}
2158+
2159+
wpas_api_ctrl.dev = dev;
2160+
wpas_api_ctrl.requested_op = WPS_PIN;
2161+
} else {
2162+
wpa_printf(MSG_ERROR, "Error wps pin operation : %d", params->oper);
2163+
goto out;
2164+
}
2165+
2166+
ret = 0;
2167+
2168+
out:
2169+
k_mutex_unlock(&wpa_supplicant_mutex);
2170+
2171+
return ret;
2172+
}
2173+
2174+
2175+
int supplicant_ap_wps_config(const struct device *dev, struct wifi_wps_config_params *params)
2176+
{
2177+
int ret = 0;
2178+
2179+
if (params->oper == WIFI_WPS_PBC) {
2180+
ret = supplicant_ap_wps_pbc(dev);
2181+
} else if (params->oper == WIFI_WPS_PIN_GET || params->oper == WIFI_WPS_PIN_SET) {
2182+
ret = supplicant_ap_wps_pin(dev, params);
2183+
}
2184+
2185+
return ret;
2186+
}
2187+
#endif
2188+
20892189
int supplicant_ap_enable(const struct device *dev,
20902190
struct wifi_connect_req_params *params)
20912191
{

modules/hostap/src/supp_api.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ static inline int hapd_state(const struct device *dev, int *state)
287287
}
288288
#endif
289289

290+
#ifdef CONFIG_WIFI_NM_HOSTAPD_WPS
291+
/** Start AP WPS PBC/PIN
292+
*
293+
* @param dev Pointer to the device structure for the driver instance
294+
* @param params wps operarion parameters
295+
*
296+
* @return 0 if ok, < 0 if error
297+
*/
298+
int supplicant_ap_wps_config(const struct device *dev, struct wifi_wps_config_params *params);
299+
#endif
300+
290301
/**
291302
* @brief Get Wi-Fi SAP status
292303
*

modules/hostap/src/supp_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = {
104104
.ap_disable = supplicant_ap_disable,
105105
.ap_sta_disconnect = supplicant_ap_sta_disconnect,
106106
.iface_status = supplicant_ap_status,
107+
#ifdef CONFIG_WIFI_NM_HOSTAPD_WPS
108+
.wps_config = supplicant_ap_wps_config,
109+
#endif
107110
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
108111
.dpp_dispatch = hapd_dpp_dispatch,
109112
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */

samples/net/wifi/shell/boards/frdm_rw612.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
9090
CONFIG_SAE_PWE_EARLY_EXIT=y
9191
CONFIG_WIFI_NM_HOSTAPD_AP=y
9292
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
93+
CONFIG_WIFI_NM_HOSTAPD_WPS=y
9394
CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING=y
9495
CONFIG_WIFI_NM_WPA_SUPPLICANT_SKIP_DHCP_ON_ROAMING=y
9596

samples/net/wifi/shell/boards/rd_rw612_bga.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
8989
CONFIG_SAE_PWE_EARLY_EXIT=y
9090
CONFIG_WIFI_NM_HOSTAPD_AP=y
9191
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
92+
CONFIG_WIFI_NM_HOSTAPD_WPS=y
9293
CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING=y
9394
CONFIG_WIFI_NM_WPA_SUPPLICANT_SKIP_DHCP_ON_ROAMING=y
9495

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ static int cmd_wifi_btm_query(const struct shell *sh, size_t argc, char *argv[])
19741974

19751975
static int cmd_wifi_wps_pbc(const struct shell *sh, size_t argc, char *argv[])
19761976
{
1977-
struct net_if *iface = net_if_get_first_wifi();
1977+
struct net_if *iface = net_if_get_wifi_sta();
19781978
struct wifi_wps_config_params params = {0};
19791979

19801980
context.sh = sh;
@@ -1996,7 +1996,7 @@ static int cmd_wifi_wps_pbc(const struct shell *sh, size_t argc, char *argv[])
19961996

19971997
static int cmd_wifi_wps_pin(const struct shell *sh, size_t argc, char *argv[])
19981998
{
1999-
struct net_if *iface = net_if_get_first_wifi();
1999+
struct net_if *iface = net_if_get_wifi_sta();
20002000
struct wifi_wps_config_params params = {0};
20012001

20022002
context.sh = sh;
@@ -2023,6 +2023,57 @@ static int cmd_wifi_wps_pin(const struct shell *sh, size_t argc, char *argv[])
20232023
return 0;
20242024
}
20252025

2026+
static int cmd_wifi_ap_wps_pbc(const struct shell *sh, size_t argc, char *argv[])
2027+
{
2028+
struct net_if *iface = net_if_get_wifi_sap();
2029+
struct wifi_wps_config_params params = {0};
2030+
2031+
context.sh = sh;
2032+
2033+
if (argc == 1) {
2034+
params.oper = WIFI_WPS_PBC;
2035+
} else {
2036+
shell_help(sh);
2037+
return -ENOEXEC;
2038+
}
2039+
2040+
if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, &params, sizeof(params))) {
2041+
PR_WARNING("Start AP WPS PBC failed\n");
2042+
return -ENOEXEC;
2043+
}
2044+
2045+
return 0;
2046+
}
2047+
2048+
static int cmd_wifi_ap_wps_pin(const struct shell *sh, size_t argc, char *argv[])
2049+
{
2050+
struct net_if *iface = net_if_get_wifi_sap();
2051+
struct wifi_wps_config_params params = {0};
2052+
2053+
context.sh = sh;
2054+
2055+
if (argc == 1) {
2056+
params.oper = WIFI_WPS_PIN_GET;
2057+
} else if (argc == 2) {
2058+
params.oper = WIFI_WPS_PIN_SET;
2059+
strncpy(params.pin, argv[1], WIFI_WPS_PIN_MAX_LEN);
2060+
} else {
2061+
shell_help(sh);
2062+
return -ENOEXEC;
2063+
}
2064+
2065+
if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, &params, sizeof(params))) {
2066+
PR_WARNING("Start AP WPS PIN failed\n");
2067+
return -ENOEXEC;
2068+
}
2069+
2070+
if (params.oper == WIFI_WPS_PIN_GET) {
2071+
PR("WPS PIN is: %s\n", params.pin);
2072+
}
2073+
2074+
return 0;
2075+
}
2076+
20262077
static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *argv[])
20272078
{
20282079
struct net_if *iface = net_if_get_first_wifi();
@@ -3054,6 +3105,13 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
30543105
"-s --max_num_sta=<maximum number of stations>\n"
30553106
"-h --help (prints help)",
30563107
cmd_wifi_ap_config_params, 2, 5),
3108+
SHELL_CMD_ARG(wps_pbc, NULL,
3109+
"Start AP WPS PBC session.\n",
3110+
cmd_wifi_ap_wps_pbc, 1, 0),
3111+
SHELL_CMD_ARG(wps_pin, NULL,
3112+
"Get or Set AP WPS PIN.\n"
3113+
"[pin] Only applicable for set.\n",
3114+
cmd_wifi_ap_wps_pin, 1, 1),
30573115
SHELL_CMD_ARG(status, NULL, "Status of Wi-Fi SAP\n", cmd_wifi_ap_status, 1, 0),
30583116
SHELL_SUBCMD_SET_END);
30593117

0 commit comments

Comments
 (0)