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

zephyr: Roaming support #38

Open
wants to merge 3 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
133 changes: 132 additions & 1 deletion src/drivers/driver_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,26 @@ void wpa_drv_zep_event_proc_auth_resp(struct zep_drv_if_ctx *if_ctx,
}


static void wpa_drv_zep_free_pairwise_key_params(struct wpa_driver_set_key_params *params)
{
os_free((void *)params->ifname);
os_free((void *)params->addr);
os_free((void *)params->seq);
os_free((void *)params->key);
os_free(params);
}


void wpa_drv_zep_event_proc_assoc_resp(struct zep_drv_if_ctx *if_ctx,
union wpa_event_data *event,
unsigned int status)
{
if (status != WLAN_STATUS_SUCCESS) {
if (if_ctx->ft_roaming) {
if_ctx->ft_roaming = false;
wpa_drv_zep_free_pairwise_key_params(if_ctx->key_params);
if_ctx->key_params = NULL;
}
wpa_supplicant_event_wrapper(if_ctx->supp_if_ctx,
EVENT_ASSOC_REJECT,
event);
Expand Down Expand Up @@ -993,6 +1008,12 @@ static void wpa_drv_zep_event_dfs_cac_finished(struct zep_drv_if_ctx *if_ctx, un
}
#endif

static void wpa_drv_zep_event_signal_change(struct zep_drv_if_ctx *if_ctx,
union wpa_event_data *event)
{
wpa_supplicant_event_wrapper(if_ctx->supp_if_ctx, EVENT_SIGNAL_CHANGE, event);
}

static struct hostapd_hw_modes *
wpa_driver_wpa_supp_postprocess_modes(struct hostapd_hw_modes *modes,
u16 *num_modes)
Expand Down Expand Up @@ -1232,6 +1253,7 @@ static void *wpa_drv_zep_init(void *ctx,
callbk_fns.chan_list_changed = wpa_drv_zep_event_chan_list_changed;
callbk_fns.mac_changed = wpa_drv_zep_event_mac_changed;
callbk_fns.ecsa_complete = wpa_drv_zep_event_ecsa_complete;
callbk_fns.signal_change = wpa_drv_zep_event_signal_change;

if_ctx->dev_priv = dev_ops->init(if_ctx,
ifname,
Expand Down Expand Up @@ -1521,6 +1543,78 @@ struct wpa_scan_results *wpa_drv_zep_get_scan_results2(void *priv)
}


static int wpa_drv_zep_save_pairwise_key_params(void *priv, struct wpa_driver_set_key_params *params)
{
struct zep_drv_if_ctx *if_ctx = NULL;
int ret = -1;

if_ctx = priv;

if (if_ctx->key_params) {
wpa_drv_zep_free_pairwise_key_params(if_ctx->key_params);
if_ctx->key_params = NULL;
}

if_ctx->key_params = (struct wpa_driver_set_key_params *)os_zalloc(sizeof(struct wpa_driver_set_key_params));

if (!if_ctx->key_params) {
wpa_printf(MSG_DEBUG, "%s: failed to alloc", __func__);
return -1;
}

if (params->ifname) {
if_ctx->key_params->ifname = os_strdup(params->ifname);

if (!if_ctx->key_params->ifname) {
wpa_printf(MSG_DEBUG, "%s: failed to alloc ifname", __func__);
goto out;
}
}

if (params->addr) {
if_ctx->key_params->addr = os_memdup(params->addr, ETH_ALEN);

if (!if_ctx->key_params->addr) {
wpa_printf(MSG_DEBUG, "%s: failed to alloc addr", __func__);
goto out;
}
}

if (params->seq) {
if_ctx->key_params->seq = os_memdup(params->seq, params->seq_len);

if (!if_ctx->key_params->seq) {
wpa_printf(MSG_DEBUG, "%s: failed to alloc seq", __func__);
goto out;
}
if_ctx->key_params->seq_len = params->seq_len;
}

if (params->key) {
if_ctx->key_params->key = os_memdup(params->key, params->key_len);

if (!if_ctx->key_params->key) {
wpa_printf(MSG_DEBUG, "%s: failed to alloc key", __func__);
goto out;
}
if_ctx->key_params->key_len = params->key_len;
}

if_ctx->key_params->alg = params->alg;
if_ctx->key_params->key_idx = params->key_idx;
if_ctx->key_params->set_tx = params->set_tx;
if_ctx->key_params->key_flag = params->key_flag;

ret = 0;
out:
if (ret) {
wpa_drv_zep_free_pairwise_key_params(if_ctx->key_params);
if_ctx->key_params = NULL;
}
return ret;
}


static int wpa_drv_zep_deauthenticate(void *priv, const u8 *addr,
u16 reason_code)
{
Expand All @@ -1535,6 +1629,10 @@ static int wpa_drv_zep_deauthenticate(void *priv, const u8 *addr,

if_ctx = priv;

if (if_ctx->ft_roaming) {
if_ctx->ft_roaming = false;
}

dev_ops = get_dev_ops(if_ctx->dev_ctx);
ret = dev_ops->deauthenticate(if_ctx->dev_priv, addr, reason_code);
if (ret) {
Expand Down Expand Up @@ -1563,6 +1661,12 @@ static int wpa_drv_zep_authenticate(void *priv,

if_ctx = priv;

if_ctx->ft_roaming = false;

if (params->auth_alg == WPA_AUTH_ALG_FT) {
if_ctx->ft_roaming = true;
}

dev_ops = get_dev_ops(if_ctx->dev_ctx);

os_memcpy(if_ctx->ssid, params->ssid, params->ssid_len);
Expand Down Expand Up @@ -1713,6 +1817,29 @@ static int _wpa_drv_zep_set_key(void *priv,
static int wpa_drv_zep_set_key(void* priv,
struct wpa_driver_set_key_params *params)
{
struct zep_drv_if_ctx *if_ctx = NULL;
enum key_flag key_flag = params->key_flag;

if_ctx = priv;

if (if_ctx->ft_roaming && (key_flag & KEY_FLAG_PAIRWISE)) {
return wpa_drv_zep_save_pairwise_key_params(priv, params);
}

if (if_ctx->ft_roaming && (key_flag & KEY_FLAG_GROUP)) {
if (if_ctx->key_params &&
(if_ctx->key_params->key_flag & KEY_FLAG_PAIRWISE)) {
_wpa_drv_zep_set_key(priv, (const unsigned char *)if_ctx->key_params->ifname,
if_ctx->key_params->alg, if_ctx->key_params->addr,
if_ctx->key_params->key_idx, if_ctx->key_params->set_tx,
if_ctx->key_params->seq, if_ctx->key_params->seq_len,
if_ctx->key_params->key, if_ctx->key_params->key_len,
if_ctx->key_params->key_flag);
wpa_drv_zep_free_pairwise_key_params(if_ctx->key_params);
if_ctx->key_params = NULL;
}
}

return _wpa_drv_zep_set_key(priv,
params->ifname,
params->alg,
Expand Down Expand Up @@ -1812,7 +1939,11 @@ static int wpa_drv_zep_set_supp_port(void *priv,

#ifdef CONFIG_NET_DHCPV4
if (authorized) {
net_dhcpv4_restart(iface);
if (if_ctx->ft_roaming == false) {
net_dhcpv4_restart(iface);
} else {
if_ctx->ft_roaming = false;
}
}
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/drivers/driver_zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ struct zep_drv_if_ctx {
struct wpa_scan_results *scan_res2;
bool scan_res2_get_in_prog;

bool ft_roaming;
struct wpa_driver_set_key_params *key_params;

unsigned int freq;
unsigned char ssid[SSID_MAX_LEN];
size_t ssid_len;
Expand Down Expand Up @@ -207,6 +210,9 @@ struct zep_wpa_supp_dev_callbk_fns {

void (*dfs_cac_finished)(struct zep_drv_if_ctx *if_ctx,
union wpa_event_data *event);

void (*signal_change)(struct zep_drv_if_ctx *if_ctx,
union wpa_event_data *event);
};

struct zep_hostapd_dev_callbk_fns
Expand Down
8 changes: 8 additions & 0 deletions wpa_supplicant/ctrl_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <net/if_ether.h>
#elif defined(__ZEPHYR__)
#include <zephyr/net/ethernet.h>
#include <supp_events.h>
#endif

static int wpa_supplicant_global_iface_list(struct wpa_global *global,
Expand Down Expand Up @@ -10309,6 +10310,13 @@ static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
len -= 2 + nr_len;
}

#ifdef __ZEPHYR__
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
NET_EVENT_WIFI_CMD_NEIGHBOR_REP_COMPLETE,
(void *)wpa_s->current_ssid->ssid,
wpa_s->current_ssid->ssid_len);
#endif

out:
wpabuf_free(neighbor_rep);
}
Expand Down
12 changes: 11 additions & 1 deletion wpa_supplicant/wpa_cli_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,19 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, struct wpa_supplicant *w
if (msg->msg_len > 0) {
/* Only interested in CTRL-EVENTs */
if (strncmp(msg->msg, "CTRL-EVENT", 10) == 0) {
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
if (strncmp(msg->msg, "CTRL-EVENT-SIGNAL-CHANGE", 24) == 0) {
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
NET_EVENT_WIFI_CMD_SIGNAL_CHANGE,
msg->msg, msg->msg_len);
} else {
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
NET_EVENT_WIFI_CMD_SUPPLICANT,
msg->msg, msg->msg_len);
}
} else if (strncmp(msg->msg, "RRM-NEIGHBOR-REP-RECEIVED", 25) == 0) {
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED,
msg->msg, msg->msg_len);
}
}
} else {
Expand Down