Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostap: add WPS PBC and PIN for AP mode #79540

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ enum net_request_wifi_cmd {
NET_REQUEST_WIFI_CMD_NEIGHBOR_REP_COMPLETE,
/** Specific scan */
NET_REQUEST_WIFI_CMD_CANDIDATE_SCAN,
/** AP WPS config */
NET_REQUEST_WIFI_CMD_AP_WPS_CONFIG,
/** @cond INTERNAL_HIDDEN */
NET_REQUEST_WIFI_CMD_MAX
/** @endcond */
Expand Down
12 changes: 10 additions & 2 deletions modules/hostap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_AP
CONFIG_NO_ACCOUNTING
NEED_AP_MLME
CONFIG_IEEE80211AC
CONFIG_EAP_SERVER
CONFIG_EAP_SERVER_IDENTITY
EAP_SERVER
EAP_SERVER_IDENTITY
MaochenWang1 marked this conversation as resolved.
Show resolved Hide resolved
)

zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_11AX
Expand Down Expand Up @@ -365,6 +365,14 @@ zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS
EAP_WSC
)

zephyr_library_sources_ifdef(CONFIG_WIFI_NM_HOSTAPD_WPS
${HOSTAP_SRC_BASE}/eap_server/eap_server_wsc.c
)

zephyr_library_compile_definitions_ifdef(CONFIG_WIFI_NM_HOSTAPD_WPS
EAP_SERVER_WSC
)

zephyr_library_sources_ifdef(CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
${HOSTAP_SRC_BASE}/eap_common/eap_common.c
)
Expand Down
5 changes: 5 additions & 0 deletions modules/hostap/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ config WIFI_NM_WPA_SUPPLICANT_WPS
bool "WPS support"
depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE

config WIFI_NM_HOSTAPD_WPS
bool "WPS hostapd support"
depends on !WIFI_NM_WPA_SUPPLICANT_CRYPTO_NONE
depends on WIFI_NM_HOSTAPD_AP

config WIFI_NM_WPA_SUPPLICANT_P2P
bool "P2P mode support"
select WIFI_NM_WPA_SUPPLICANT_AP
Expand Down
100 changes: 100 additions & 0 deletions modules/hostap/src/supp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,106 @@
}
#endif /* CONFIG_WIFI_NM_HOSTAPD_AP */

#ifdef CONFIG_WIFI_NM_HOSTAPD_WPS
MaochenWang1 marked this conversation as resolved.
Show resolved Hide resolved
int supplicant_ap_wps_pbc(const struct device *dev)
{
struct hostapd_iface *iface;
int ret = -1;

k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);

iface = get_hostapd_handle(dev);
if (!iface) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}

if (iface->state != HAPD_IFACE_ENABLED) {
ret = -EBUSY;
wpa_printf(MSG_ERROR, "Interface %s is not in enable state", dev->name);
goto out;
}

if (!hostapd_cli_cmd_v("wps_pbc")) {
goto out;
}

wpas_api_ctrl.dev = dev;
wpas_api_ctrl.requested_op = WPS_PBC;

ret = 0;

out:
k_mutex_unlock(&wpa_supplicant_mutex);

return ret;
}

int supplicant_ap_wps_pin(const struct device *dev, struct wifi_wps_config_params *params)
{
struct hostapd_iface *iface;
char *get_pin_cmd = "WPS_AP_PIN random";
int ret = 0;

Check notice on line 2130 in modules/hostap/src/supp_api.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hostap/src/supp_api.c:2130 - int ret = 0; + int ret = 0;
k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER);

iface = get_hostapd_handle(dev);
if (!iface) {
ret = -1;
wpa_printf(MSG_ERROR, "Interface %s not found", dev->name);
goto out;
}

if (iface->state != HAPD_IFACE_ENABLED) {
ret = -EBUSY;
wpa_printf(MSG_ERROR, "Interface %s is not in enable state", dev->name);
goto out;
}

if (params->oper == WIFI_WPS_PIN_GET) {
if (zephyr_hostapd_cli_cmd_resp(get_pin_cmd, params->pin)) {
goto out;
}
} else if (params->oper == WIFI_WPS_PIN_SET) {
if (!hostapd_cli_cmd_v("wps_check_pin %s", params->pin)) {
goto out;
}

if (!hostapd_cli_cmd_v("wps_pin any %s", params->pin)) {
goto out;
}

wpas_api_ctrl.dev = dev;
wpas_api_ctrl.requested_op = WPS_PIN;
} else {
wpa_printf(MSG_ERROR, "Error wps pin operation : %d", params->oper);
goto out;
}

ret = 0;

out:
k_mutex_unlock(&wpa_supplicant_mutex);

return ret;
}


Check notice on line 2174 in modules/hostap/src/supp_api.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hostap/src/supp_api.c:2174 -
int supplicant_ap_wps_config(const struct device *dev, struct wifi_wps_config_params *params)
{
int ret = 0;

if (params->oper == WIFI_WPS_PBC) {
ret = supplicant_ap_wps_pbc(dev);
} else if (params->oper == WIFI_WPS_PIN_GET || params->oper == WIFI_WPS_PIN_SET) {
ret = supplicant_ap_wps_pin(dev, params);
}

return ret;
}
#endif

int supplicant_ap_enable(const struct device *dev,
struct wifi_connect_req_params *params)
{
Expand Down
11 changes: 11 additions & 0 deletions modules/hostap/src/supp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ static inline int hapd_state(const struct device *dev, int *state)
}
#endif

#ifdef CONFIG_WIFI_NM_HOSTAPD_WPS
/** Start AP WPS PBC/PIN
*
* @param dev Pointer to the device structure for the driver instance
* @param params wps operarion parameters
*
* @return 0 if ok, < 0 if error
*/
int supplicant_ap_wps_config(const struct device *dev, struct wifi_wps_config_params *params);
#endif

/**
* @brief Get Wi-Fi SAP status
*
Expand Down
3 changes: 3 additions & 0 deletions modules/hostap/src/supp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ static const struct wifi_mgmt_ops mgmt_ap_ops = {
.ap_disable = supplicant_ap_disable,
.ap_sta_disconnect = supplicant_ap_sta_disconnect,
.iface_status = supplicant_ap_status,
#ifdef CONFIG_WIFI_NM_HOSTAPD_WPS
.wps_config = supplicant_ap_wps_config,
#endif
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP
.dpp_dispatch = hapd_dpp_dispatch,
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP */
Expand Down
1 change: 1 addition & 0 deletions samples/net/wifi/boards/frdm_rw612.conf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
CONFIG_SAE_PWE_EARLY_EXIT=y
CONFIG_WIFI_NM_HOSTAPD_AP=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
CONFIG_WIFI_NM_HOSTAPD_WPS=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_SKIP_DHCP_ON_ROAMING=y

Expand Down
1 change: 1 addition & 0 deletions samples/net/wifi/boards/rd_rw612_bga.conf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES=2
CONFIG_SAE_PWE_EARLY_EXIT=y
CONFIG_WIFI_NM_HOSTAPD_AP=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_WPS=y
CONFIG_WIFI_NM_HOSTAPD_WPS=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING=y
CONFIG_WIFI_NM_WPA_SUPPLICANT_SKIP_DHCP_ON_ROAMING=y

Expand Down
62 changes: 60 additions & 2 deletions subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@

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

context.sh = sh;
Expand All @@ -1997,7 +1997,7 @@

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

context.sh = sh;
Expand All @@ -2024,6 +2024,57 @@
return 0;
}

static int cmd_wifi_ap_wps_pbc(const struct shell *sh, size_t argc, char *argv[])
{
struct net_if *iface = net_if_get_wifi_sap();
struct wifi_wps_config_params params = {0};

context.sh = sh;

if (argc == 1) {
params.oper = WIFI_WPS_PBC;
} else {
shell_help(sh);
return -ENOEXEC;
}

if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, &params, sizeof(params))) {
PR_WARNING("Start AP WPS PBC failed\n");
return -ENOEXEC;
}

return 0;
}

static int cmd_wifi_ap_wps_pin(const struct shell *sh, size_t argc, char *argv[])
{
struct net_if *iface = net_if_get_wifi_sap();
struct wifi_wps_config_params params = {0};

context.sh = sh;

if (argc == 1) {
params.oper = WIFI_WPS_PIN_GET;
} else if (argc == 2) {
params.oper = WIFI_WPS_PIN_SET;
strncpy(params.pin, argv[1], WIFI_WPS_PIN_MAX_LEN);
} else {
shell_help(sh);
return -ENOEXEC;
}

if (net_mgmt(NET_REQUEST_WIFI_WPS_CONFIG, iface, &params, sizeof(params))) {
PR_WARNING("Start AP WPS PIN failed\n");
return -ENOEXEC;
}

if (params.oper == WIFI_WPS_PIN_GET) {
PR("WPS PIN is: %s\n", params.pin);
}

return 0;
}

static int cmd_wifi_ps_wakeup_mode(const struct shell *sh, size_t argc, char *argv[])
{
struct net_if *iface = net_if_get_first_wifi();
Expand Down Expand Up @@ -3055,6 +3106,13 @@
"-s --max_num_sta=<maximum number of stations>\n"
"-h --help (prints help)",
cmd_wifi_ap_config_params, 2, 5),
SHELL_CMD_ARG(wps_pbc, NULL,
"Start AP WPS PBC session.\n",
cmd_wifi_ap_wps_pbc, 1, 0),
SHELL_CMD_ARG(wps_pin, NULL,

Check notice on line 3112 in subsys/net/l2/wifi/wifi_shell.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/l2/wifi/wifi_shell.c:3112 - SHELL_CMD_ARG(wps_pbc, NULL, - "Start AP WPS PBC session.\n", - cmd_wifi_ap_wps_pbc, 1, 0), + SHELL_CMD_ARG(wps_pbc, NULL, "Start AP WPS PBC session.\n", cmd_wifi_ap_wps_pbc, 1, 0),
"Get or Set AP WPS PIN.\n"
"[pin] Only applicable for set.\n",
cmd_wifi_ap_wps_pin, 1, 1),
SHELL_CMD_ARG(status, NULL, "Status of Wi-Fi SAP\n", cmd_wifi_ap_status, 1, 0),
SHELL_SUBCMD_SET_END);

Expand Down
Loading