diff --git a/modules/hostap/src/hapd_main.c b/modules/hostap/src/hapd_main.c index c11f0d806d7..6c5e9c6d998 100644 --- a/modules/hostap/src/hapd_main.c +++ b/modules/hostap/src/hapd_main.c @@ -202,41 +202,6 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces, const char *e return 0; } -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; -} - -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); - } -} - static int hostapd_driver_init(struct hostapd_iface *iface) { struct wpa_init_params params; @@ -570,3 +535,20 @@ void zephyr_hostapd_init(struct hapd_interfaces *interfaces) out: return; } + +void zephyr_hostapd_msg(void *ctx, const char *txt, size_t len) +{ +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP + struct hostapd_data *hapd = (struct hostapd_data *)ctx; +#endif + + if (!ctx || !txt) { + return; + } + +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_DPP + if (strncmp(txt, "DPP", 3) == 0) { + hostapd_handle_dpp_event(hapd, (char *)txt, len); + } +#endif +} diff --git a/modules/hostap/src/hapd_main.h b/modules/hostap/src/hapd_main.h index 6e1d3185abf..9f23d3e959c 100644 --- a/modules/hostap/src/hapd_main.h +++ b/modules/hostap/src/hapd_main.h @@ -8,14 +8,8 @@ #define __HAPD_MAIN_H_ #include "common.h" -#include "wpa_debug_zephyr.h" 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); -const char *zephyr_hostap_msg_ifname_cb(void *ctx); -void zephyr_hostap_ctrl_iface_msg_cb(void *ctx, int level, enum wpa_msg_type type, - const char *txt, size_t len); void zephyr_hostapd_init(struct hapd_interfaces *interfaces); +void zephyr_hostapd_msg(void *ctx, const char *txt, size_t len); #endif /* __HAPD_MAIN_H_ */ diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index 120050a75c7..5ba2ef5b10c 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -227,6 +227,80 @@ static int get_iface_count(struct supplicant_context *ctx) return count; } +static void zephyr_wpa_supplicant_msg(void *ctx, const char *txt, size_t len) +{ + struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)ctx; + + if (!ctx || !txt) { + return; + } + + /* Only interested in CTRL-EVENTs */ + if (strncmp(txt, "CTRL-EVENT", 10) == 0) { + if (strncmp(txt, "CTRL-EVENT-SIGNAL-CHANGE", 24) == 0) { + supplicant_send_wifi_mgmt_event(wpa_s->ifname, + NET_EVENT_WIFI_CMD_SIGNAL_CHANGE, + (void *)txt, len); + } else { + supplicant_send_wifi_mgmt_event(wpa_s->ifname, + NET_EVENT_WIFI_CMD_SUPPLICANT, + (void *)txt, len); + } + } else if (strncmp(txt, "RRM-NEIGHBOR-REP-RECEIVED", 25) == 0) { + supplicant_send_wifi_mgmt_event(wpa_s->ifname, + NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED, + (void *)txt, len); + } +} + +static const char *zephyr_hostap_msg_ifname_cb(void *ctx) +{ + if (ctx == NULL) { + return NULL; + } + +#ifdef CONFIG_WIFI_NM_HOSTAPD_AP + if ((((struct wpa_supplicant *)ctx))->is_hostapd == 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; +#else + struct wpa_supplicant *wpa_s = ctx; + + return wpa_s->ifname; +#endif +} + +static void zephyr_hostap_ctrl_iface_msg_cb(void *ctx, int level, enum wpa_msg_type type, + const char *txt, size_t len) +{ + ARG_UNUSED(level); + ARG_UNUSED(type); + + if (ctx == NULL) { + return; + } + +#ifdef CONFIG_WIFI_NM_HOSTAPD_AP + if ((((struct wpa_supplicant *)ctx))->is_hostapd == 0) { + zephyr_wpa_supplicant_msg(ctx, txt, len); + } else { + zephyr_hostapd_msg(ctx, txt, len); + } +#else + zephyr_wpa_supplicant_msg(ctx, txt, len); +#endif +} + static int add_interface(struct supplicant_context *ctx, struct net_if *iface) { struct wpa_supplicant *wpa_s; @@ -288,9 +362,7 @@ 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: @@ -628,8 +700,8 @@ static void handler(void) #ifdef CONFIG_WIFI_NM_HOSTAPD_AP zephyr_hostapd_init(&ctx->hostapd); - wpa_msg_register_ifname_cb(zephyr_hostap_msg_ifname_cb); #endif + wpa_msg_register_ifname_cb(zephyr_hostap_msg_ifname_cb); (void)wpa_supplicant_run(ctx->supplicant);