hostap: add dispatch for hostapd and wpa_supplicant wpa_msg

When we have coexistence of hostapd and wpa_supplicant,
wpa_msg has different implementation.
So to let them work together, we need to have common implementation
for wpa_msg and dispatch msgs for hostapd and wpa_supplicant.

So add register zephyr_hostap_ctrl_iface_msg_cb,
and judge if ctx is hostapd by the first integer where ctx points to.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
This commit is contained in:
Fengming Ye 2024-06-20 15:09:45 +09:00 committed by Henrik Brix Andersen
parent 5e9377e051
commit 0961928b3a
2 changed files with 47 additions and 0 deletions

View file

@ -134,6 +134,9 @@ static struct hapd_global hglobal;
#define HOSTAPD_CLEANUP_INTERVAL 10
#endif /* HOSTAPD_CLEANUP_INTERVAL */
static void zephyr_hostap_ctrl_iface_msg_cb(void *ctx, int level, enum wpa_msg_type type,
const char *txt, size_t len);
static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx)
{
hostapd_periodic_iface(iface);
@ -333,6 +336,9 @@ static int add_interface(struct supplicant_context *ctx, struct net_if *iface)
supplicant_generate_state_event(ifname, NET_EVENT_SUPPLICANT_CMD_READY, 0);
}
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
wpa_msg_register_cb(zephyr_hostap_ctrl_iface_msg_cb);
#endif
ret = 0;
out:
@ -954,6 +960,8 @@ static struct hostapd_iface *hostapd_interface_init(struct hapd_interfaces *inte
return NULL;
}
iface->bss[0]->is_hostapd = 1;
return iface;
}
@ -1052,6 +1060,41 @@ static void zephyr_hostapd_init(struct supplicant_context *ctx)
out:
return;
}
static const char *zephyr_hostap_msg_ifname_cb(void *ctx)
{
if (ctx == NULL) {
return NULL;
}
if ((*((int *)ctx)) == 0) {
struct wpa_supplicant *wpa_s = ctx;
return wpa_s->ifname;
}
struct hostapd_data *hapd = ctx;
if (hapd && hapd->conf) {
return hapd->conf->iface;
}
return NULL;
}
static void zephyr_hostap_ctrl_iface_msg_cb(void *ctx, int level, enum wpa_msg_type type,
const char *txt, size_t len)
{
if (ctx == NULL) {
return;
}
if ((*((int *)ctx)) == 0) {
wpa_supplicant_msg_send(ctx, level, type, txt, len);
} else {
hostapd_msg_send(ctx, level, type, txt, len);
}
}
#endif
static void handler(void)
@ -1107,6 +1150,7 @@ static void handler(void)
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
zephyr_hostapd_init(ctx);
wpa_msg_register_ifname_cb(zephyr_hostap_msg_ifname_cb);
#endif
(void)wpa_supplicant_run(ctx->supplicant);

View file

@ -23,6 +23,9 @@ struct wpa_global *zephyr_get_default_supplicant_context(void);
struct wpa_supplicant *zephyr_get_handle_by_ifname(const char *ifname);
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
struct hostapd_iface *zephyr_get_hapd_handle_by_ifname(const char *ifname);
void wpa_supplicant_msg_send(void *ctx, int level, enum wpa_msg_type type, const char *txt,
size_t len);
void hostapd_msg_send(void *ctx, int level, enum wpa_msg_type type, const char *buf, size_t len);
#endif
struct wpa_supplicant_event_msg {
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP