Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Basic AP mode support #143

Merged
merged 4 commits into from
Dec 19, 2023
Merged
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
3 changes: 3 additions & 0 deletions src/ap/ap_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include "common/ieee802_11_defs.h"
#include "common/ieee802_1x_defs.h"
#include "common/eapol_common.h"
/* No DHCP snooping for Zephyr */
#if !defined(CONFIG_ZEPHYR)
#include "common/dhcp.h"
#endif /* CONFIG_ZEPHYR */
#include "common/sae.h"
#include "eap_common/eap_wsc_common.h"
#include "eap_server/eap.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ap/ieee802_1x.c
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ int ieee802_1x_eapol_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
HOSTAPD_LEVEL_DEBUG,
"did not Ack EAPOL-Key frame (%scast index=%d)",
key->key_index & BIT(7) ? "uni" : "broad",
key->key_index & ~BIT(7));
key->key_index & ~BIT_U8(7));
/* TODO: re-send EAPOL-Key couple of times (with short delay
* between them?). If all attempt fail, report error and
* deauthenticate STA so that it will get new keys when
Expand Down
134 changes: 130 additions & 4 deletions src/drivers/driver_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,16 @@ static int wpa_drv_zep_associate(void *priv,

dev_ops = if_ctx->dev_ctx->config;

ret = dev_ops->associate(if_ctx->dev_priv,
params);
if (IS_ENABLED(CONFIG_AP) && params->mode == IEEE80211_MODE_AP) {
ret = dev_ops->init_ap(if_ctx->dev_priv,
params);
} else if (params->mode == IEEE80211_MODE_INFRA) {
ret = dev_ops->associate(if_ctx->dev_priv,
params);
} else {
wpa_printf(MSG_ERROR, "%s: Unsupported mode\n", __func__);
goto out;
}

if (ret) {
wpa_printf(MSG_ERROR, "%s: associate op failed\n", __func__);
Expand Down Expand Up @@ -1131,8 +1139,7 @@ static int _wpa_drv_zep_set_key(void *priv,
wpa_printf(MSG_ERROR, "%s: Invalid handle\n", __func__);
goto out;
}
if ((alg != WPA_ALG_NONE) &&
((!seq) || (!key))) {
if ((alg != WPA_ALG_NONE) && !key) {
wpa_printf(MSG_ERROR,
"%s: Missing mandatory params\n",
__func__);
Expand Down Expand Up @@ -1430,6 +1437,120 @@ static int wpa_drv_zep_get_conn_info(void *priv, struct wpa_conn_info *ci)
return ret;
}

#ifdef CONFIG_AP
static int wpa_drv_zep_set_ap(void *priv,
struct wpa_driver_ap_params *params)
{
struct zep_drv_if_ctx *if_ctx = NULL;
const struct zep_wpa_supp_dev_ops *dev_ops = NULL;
int ret = -1;

if ((!priv) || (!params)) {
wpa_printf(MSG_ERROR, "%s: Invalid params\n", __func__);
goto out;
}

if_ctx = priv;

dev_ops = if_ctx->dev_ctx->config;

if (!if_ctx->beacon_set && !dev_ops->start_ap) {
wpa_printf(MSG_ERROR, "%s: set_ap op not supported\n", __func__);
goto out;
} else if (if_ctx->beacon_set && !dev_ops->change_beacon) {
wpa_printf(MSG_ERROR, "%s: change_beacon op not supported\n", __func__);
goto out;
}

if (!if_ctx->beacon_set) {
ret = dev_ops->start_ap(if_ctx->dev_priv,
params);
} else {
ret = dev_ops->change_beacon(if_ctx->dev_priv,
params);
}
if (ret) {
wpa_printf(MSG_ERROR, "%s: set_ap op failed: %d\n", __func__, ret);
goto out;
}

if (!if_ctx->beacon_set) {
if_ctx->beacon_set = true;
}

ret = 0;

out:
return ret;
}

int wpa_drv_zep_stop_ap(void *priv)
{
struct zep_drv_if_ctx *if_ctx = NULL;
const struct zep_wpa_supp_dev_ops *dev_ops = NULL;
int ret = -1;

if (!priv) {
wpa_printf(MSG_ERROR, "%s: Invalid handle\n", __func__);
goto out;
}

if_ctx = priv;

dev_ops = if_ctx->dev_ctx->config;

if (!dev_ops->stop_ap) {
wpa_printf(MSG_ERROR, "%s: stop_ap op not supported\n", __func__);
goto out;
}

ret = dev_ops->stop_ap(if_ctx->dev_priv);

if (ret) {
wpa_printf(MSG_ERROR, "%s: stop_ap op failed: %d\n", __func__, ret);
goto out;
}

ret = 0;

out:
return ret;
}

int wpa_drv_zep_deinit_ap(void *priv)
{
struct zep_drv_if_ctx *if_ctx = NULL;
const struct zep_wpa_supp_dev_ops *dev_ops = NULL;
int ret = -1;

if (!priv) {
wpa_printf(MSG_ERROR, "%s: Invalid handle\n", __func__);
goto out;
}

if_ctx = priv;

dev_ops = if_ctx->dev_ctx->config;

if (!dev_ops->deinit_ap) {
wpa_printf(MSG_ERROR, "%s: deinit_ap op not supported\n", __func__);
goto out;
}

ret = dev_ops->deinit_ap(if_ctx->dev_priv);

if (ret) {
wpa_printf(MSG_ERROR, "%s: deinit_ap op failed: %d\n", __func__, ret);
goto out;
}

ret = 0;

out:
return ret;
}
#endif /* CONFIG_AP */

const struct wpa_driver_ops wpa_driver_zep_ops = {
.name = "zephyr",
.desc = "Zephyr wpa_supplicant driver",
Expand All @@ -1453,4 +1574,9 @@ const struct wpa_driver_ops wpa_driver_zep_ops = {
.get_hw_feature_data = wpa_drv_get_hw_feature_data,
.get_ext_capab = nl80211_get_ext_capab,
.get_conn_info = wpa_drv_zep_get_conn_info,
#ifdef CONFIG_AP
.set_ap = wpa_drv_zep_set_ap,
.stop_ap = wpa_drv_zep_stop_ap,
.deinit_ap = wpa_drv_zep_deinit_ap,
#endif /* CONFIG_AP */
};
15 changes: 15 additions & 0 deletions src/drivers/driver_zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct zep_drv_if_ctx {
unsigned char prev_bssid[6];
unsigned char auth_bssid[6];
unsigned char auth_attempt_bssid[6];
bool beacon_set;
};


Expand Down Expand Up @@ -221,6 +222,20 @@ struct zep_wpa_supp_dev_ops {

int (*get_conn_info)(void *if_priv,
struct wpa_conn_info *info);

/* AP mode (shared headers, so, skip compile time flags protection)*/
int (*init_ap)(void *if_priv,
struct wpa_driver_associate_params *params);

int (*start_ap)(void *if_priv,
struct wpa_driver_ap_params *params);

int (*change_beacon)(void *if_priv,
struct wpa_driver_ap_params *params);

int (*stop_ap)(void *if_priv);

int (*deinit_ap)(void *if_priv);
};

#endif /* DRIVER_ZEPHYR_H */
4 changes: 4 additions & 0 deletions src/utils/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ void perror(const char *s);
#define BIT(x) (1U << (x))
#endif

#ifndef BIT_U8
#define BIT_U8(n) (1U << (n))
#endif

/*
* Definitions for sparse validation
* (http://kernel.org/pub/linux/kernel/people/josh/sparse/)
Expand Down
Loading