modules: hostap: remove zephyr wpa_msg socket pair
Background: In DPP hostapd will put more than 1K bytes text in multiple wpa_msg calls in one loop. This will drain hostapd monitor socket pair and fail. Thus DPP connection will fail. The monitor socket pair of wpa_supplicant and hostapd are not like ctrl_iface socket pair, which are used for sending command to hostap from other tasks. The monitor socket pair is used by wpa_msg to send messages to attatched ctrl_iface monitors. But in zephyr case, the monitor is hostap task itself. This means hostap task is both the sender and receiver task. So it writes all the wpa_msg text into FIFO and read it in next loop. So there is risk of draining socket pair FIFO and missing msg. And the reading socket loop can be omitted by directly handling msg in wpa_msg_cb. Linux uses monitor socket pair because hostap is a process and wpa_msg does cross-process communication. But zephyr hostap is used as module in the same binary with zephyr kernel. So the usage is different and we don't need to use socket pair to notify ctrl_iface monitors. As long as we don't do time-consuming process in zephyr_wpa_msg_cb, it won't affect hostap task. So the zephyr_wpa_msg_cb will only filter and restore interesting logs, or raise mgmt events to wifi l2 mgmt task. Fix: Remove socket send flow in wpa_msg. Directly filter and handle text in zephyr_wpa_msg_cb, coding in zephyr repo. This will save 2K RAM in supplicant case and 4K RAM in supplicant & hostapd coex case, in current default hostap socket pair config. And this will save max 50% loops of hostap task. Signed-off-by: Fengming Ye <frank.ye@nxp.com>
This commit is contained in:
parent
c767fa51e2
commit
fd0ac07a21
3 changed files with 93 additions and 45 deletions
|
@ -202,41 +202,6 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces, const char *e
|
||||||
return 0;
|
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)
|
static int hostapd_driver_init(struct hostapd_iface *iface)
|
||||||
{
|
{
|
||||||
struct wpa_init_params params;
|
struct wpa_init_params params;
|
||||||
|
@ -570,3 +535,20 @@ void zephyr_hostapd_init(struct hapd_interfaces *interfaces)
|
||||||
out:
|
out:
|
||||||
return;
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -8,14 +8,8 @@
|
||||||
#define __HAPD_MAIN_H_
|
#define __HAPD_MAIN_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wpa_debug_zephyr.h"
|
|
||||||
|
|
||||||
struct hostapd_iface *zephyr_get_hapd_handle_by_ifname(const char *ifname);
|
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_init(struct hapd_interfaces *interfaces);
|
||||||
|
void zephyr_hostapd_msg(void *ctx, const char *txt, size_t len);
|
||||||
#endif /* __HAPD_MAIN_H_ */
|
#endif /* __HAPD_MAIN_H_ */
|
||||||
|
|
|
@ -227,6 +227,80 @@ static int get_iface_count(struct supplicant_context *ctx)
|
||||||
return count;
|
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)
|
static int add_interface(struct supplicant_context *ctx, struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct wpa_supplicant *wpa_s;
|
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);
|
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);
|
wpa_msg_register_cb(zephyr_hostap_ctrl_iface_msg_cb);
|
||||||
#endif
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -628,8 +700,8 @@ static void handler(void)
|
||||||
|
|
||||||
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
|
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
|
||||||
zephyr_hostapd_init(&ctx->hostapd);
|
zephyr_hostapd_init(&ctx->hostapd);
|
||||||
wpa_msg_register_ifname_cb(zephyr_hostap_msg_ifname_cb);
|
|
||||||
#endif
|
#endif
|
||||||
|
wpa_msg_register_ifname_cb(zephyr_hostap_msg_ifname_cb);
|
||||||
|
|
||||||
(void)wpa_supplicant_run(ctx->supplicant);
|
(void)wpa_supplicant_run(ctx->supplicant);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue