Skip to content

Commit 8412f4b

Browse files
fengming-yejukkar
authored andcommitted
[noup] zephyr: remove zephyr wpas monitor socket pair
The socket pair will no longer be used as we will directly filter and handle msg in wpa_msg_cb for zephyr. The handler path is short and quick. So it won't hold hostap task. Saves 4K RAM space and hostap task loops for receiving msg. Signed-off-by: Fengming Ye <frank.ye@nxp.com>
1 parent 969ad13 commit 8412f4b

File tree

3 files changed

+5
-267
lines changed

3 files changed

+5
-267
lines changed

wpa_supplicant/ctrl_iface_zephyr.c

Lines changed: 3 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -8,119 +8,6 @@
88

99
#include "ctrl_iface_zephyr.h"
1010

11-
12-
static int wpa_supplicant_ctrl_mon_iface_attach(struct wpa_ctrl_mon **head, int sock)
13-
{
14-
struct wpa_ctrl_mon *dst;
15-
16-
dst = os_zalloc(sizeof(*dst));
17-
if (dst == NULL)
18-
return -1;
19-
20-
dst->sock = sock;
21-
dst->debug_level = MSG_INFO;
22-
dst->next = *head;
23-
*head = dst;
24-
return 0;
25-
}
26-
27-
28-
static int wpa_supplicant_ctrl_mon_iface_detach(struct wpa_ctrl_mon **head, int sock)
29-
{
30-
struct wpa_ctrl_mon *dst, *prev = NULL;
31-
32-
dst = *head;
33-
while (dst) {
34-
if (dst->sock == sock) {
35-
if (prev == NULL) {
36-
*head = dst->next;
37-
} else {
38-
prev->next = dst->next;
39-
}
40-
os_free(dst);
41-
return 0;
42-
}
43-
prev = dst;
44-
dst = dst->next;
45-
}
46-
return -1;
47-
}
48-
49-
static void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant *wpa_s,
50-
const char *ifname, int sock,
51-
struct wpa_ctrl_mon **head,
52-
int level, const char *buf,
53-
size_t len)
54-
{
55-
struct wpa_ctrl_mon *dst, *next;
56-
char levelstr[64];
57-
int idx;
58-
struct conn_msg msg;
59-
60-
dst = *head;
61-
if (sock < 0 || dst == NULL)
62-
return;
63-
64-
if (ifname)
65-
os_snprintf(levelstr, sizeof(levelstr), "IFNAME=%s <%d>",
66-
ifname, level);
67-
else
68-
os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
69-
70-
idx = 0;
71-
if (len > MAX_CTRL_MSG_LEN) {
72-
wpa_printf(MSG_DEBUG, "CTRL_MSG too long");
73-
return;
74-
}
75-
76-
while (dst) {
77-
next = dst->next;
78-
if (level >= dst->debug_level) {
79-
memcpy(&msg.msg, buf, len);
80-
msg.msg_len = len;
81-
if (send(dst->sock, &msg, len + 4, 0) < 0) {
82-
wpa_printf(MSG_ERROR,
83-
"sendto(CTRL_IFACE monitor): %s",
84-
strerror(errno));
85-
dst->errors++;
86-
} else {
87-
dst->errors = 0;
88-
}
89-
}
90-
idx++;
91-
dst = next;
92-
}
93-
}
94-
95-
static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level,
96-
enum wpa_msg_type type,
97-
const char *txt, size_t len)
98-
{
99-
struct wpa_supplicant *wpa_s = ctx;
100-
101-
if (!wpa_s)
102-
return;
103-
104-
if (type != WPA_MSG_NO_GLOBAL && wpa_s->global->ctrl_iface) {
105-
struct ctrl_iface_global_priv *priv = wpa_s->global->ctrl_iface;
106-
107-
if (priv->ctrl_dst) {
108-
wpa_supplicant_ctrl_iface_send(wpa_s, type != WPA_MSG_PER_INTERFACE ?
109-
NULL : wpa_s->ifname,
110-
priv->sock_pair[0],
111-
&priv->ctrl_dst, level, txt, len);
112-
}
113-
}
114-
115-
if (type == WPA_MSG_ONLY_GLOBAL || !wpa_s->ctrl_iface)
116-
return;
117-
118-
wpa_supplicant_ctrl_iface_send(wpa_s, NULL, wpa_s->ctrl_iface->sock_pair[0],
119-
&wpa_s->ctrl_iface->ctrl_dst,
120-
level, txt, len);
121-
}
122-
123-
12411
static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
12512
void *sock_ctx)
12613
{
@@ -155,27 +42,8 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
15542
while (*pos == ' ')
15643
pos++;
15744

158-
if (os_strcmp(pos, "ATTACH") == 0) {
159-
if (wpa_supplicant_ctrl_mon_iface_attach(&wpa_s->ctrl_iface->ctrl_dst,
160-
wpa_s->ctrl_iface->mon_sock_pair[1])){
161-
reply_len = 1;
162-
}
163-
else {
164-
reply_len = 2;
165-
}
166-
} else if (os_strcmp(pos, "DETACH") == 0) {
167-
if (wpa_supplicant_ctrl_mon_iface_detach(&wpa_s->ctrl_iface->ctrl_dst,
168-
wpa_s->ctrl_iface->mon_sock_pair[1])) {
169-
reply_len = 1;
170-
}
171-
else {
172-
reply_len = 2;
173-
}
174-
} else {
175-
reply = wpa_supplicant_ctrl_iface_process(wpa_s, pos,
176-
&reply_len);
177-
}
178-
45+
reply = wpa_supplicant_ctrl_iface_process(wpa_s, pos,
46+
&reply_len);
17947
if (reply) {
18048
send(sock, reply, reply_len, 0);
18149
} else if (reply_len == 1) {
@@ -217,8 +85,6 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
21785
eloop_register_read_sock(priv->sock_pair[1], wpa_supplicant_ctrl_iface_receive,
21886
wpa_s, priv);
21987

220-
wpa_msg_register_cb(wpa_supplicant_ctrl_iface_msg_cb);
221-
22288
return priv;
22389

22490
fail:
@@ -287,27 +153,8 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
287153
while (*pos == ' ')
288154
pos++;
289155

290-
if (os_strcmp(pos, "ATTACH") == 0) {
291-
if (wpa_supplicant_ctrl_mon_iface_attach(&global->ctrl_iface->ctrl_dst,
292-
global->ctrl_iface->mon_sock_pair[1])) {
293-
reply_len = 1;
294-
}
295-
else {
296-
reply_len = 2;
297-
}
298-
} else if (os_strcmp(pos, "DETACH") == 0) {
299-
if (wpa_supplicant_ctrl_mon_iface_detach(&global->ctrl_iface->ctrl_dst,
300-
global->ctrl_iface->mon_sock_pair[1])) {
301-
reply_len = 1;
302-
}
303-
else {
304-
reply_len = 2;
305-
}
306-
} else {
307156
reply = wpa_supplicant_global_ctrl_iface_process(global, pos,
308-
&reply_len);
309-
}
310-
157+
&reply_len);
311158
if (reply) {
312159
send(sock, reply, reply_len, 0);
313160
} else if (reply_len == 1) {

wpa_supplicant/ctrl_iface_zephyr.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,14 @@
1616
#include "ctrl_iface.h"
1717
#include "common/wpa_ctrl.h"
1818

19-
#define MAX_CTRL_MSG_LEN 256
20-
/**
21-
* struct wpa_ctrl_mon - Data structure of control interface monitors
22-
*
23-
* This structure is used to store information about registered control
24-
* interface monitors into struct wpa_supplicant.
25-
*/
26-
struct wpa_ctrl_mon {
27-
struct wpa_ctrl_mon *next;
28-
int sock;
29-
int debug_level;
30-
int errors;
31-
};
32-
3319
struct ctrl_iface_priv {
3420
struct wpa_supplicant *wpa_s;
35-
/* 0 - wpa_cli, 1 - ctrl_iface */
21+
/* wpa_cli command socket pair */
3622
int sock_pair[2];
37-
int mon_sock_pair[2];
38-
struct wpa_ctrl_mon *ctrl_dst;
3923
};
4024

4125
struct ctrl_iface_global_priv {
4226
struct wpa_global *global;
43-
/* 0 - wpa_cli, 1 - ctrl_iface */
27+
/* wpa_cli command socket pair */
4428
int sock_pair[2];
45-
int mon_sock_pair[2];
46-
struct wpa_ctrl_mon *ctrl_dst;
47-
};
48-
49-
struct conn_msg {
50-
int msg_len;
51-
char msg[MAX_CTRL_MSG_LEN];
5229
};

wpa_supplicant/wpa_cli_zephyr.c

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#define MAX_ARGS 32
3232

3333
struct wpa_ctrl *ctrl_conn;
34-
struct wpa_ctrl *mon_conn;
3534
struct wpa_ctrl *global_ctrl_conn;
3635
char *ifname_prefix = NULL;
3736
extern struct wpa_global *global;
@@ -113,103 +112,18 @@ static void wpa_cli_close_connection(struct wpa_supplicant *wpa_s)
113112
}
114113
wpa_ctrl_close(ctrl_conn);
115114
ctrl_conn = NULL;
116-
117-
eloop_unregister_read_sock(wpa_s->ctrl_iface->mon_sock_pair[0]);
118-
119-
wpa_ctrl_close(mon_conn);
120-
mon_conn = NULL;
121-
122-
close(wpa_s->ctrl_iface->mon_sock_pair[1]);
123-
wpa_s->ctrl_iface->mon_sock_pair[1] = -1;
124-
}
125-
126-
static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, struct wpa_supplicant *wpa_s)
127-
{
128-
while (wpa_ctrl_pending(ctrl) > 0) {
129-
char buf[sizeof(struct conn_msg)];
130-
size_t hlen = sizeof(int);
131-
size_t plen = MAX_CTRL_MSG_LEN;
132-
133-
if (wpa_ctrl_recv(ctrl, buf, &hlen) == 0 &&
134-
hlen == sizeof(int)) {
135-
plen = *((int *)buf);
136-
} else {
137-
wpa_printf(MSG_ERROR, "Could not read pending message header len %d.\n", hlen);
138-
continue;
139-
}
140-
141-
if (wpa_ctrl_recv(ctrl, buf + sizeof(int), &plen) == 0) {
142-
struct conn_msg *msg = (struct conn_msg *)buf;
143-
144-
msg->msg[msg->msg_len] = '\0';
145-
wpa_printf(MSG_DEBUG, "Received len: %d, msg_len:%d - %s->END\n",
146-
plen, msg->msg_len, msg->msg);
147-
if (msg->msg_len >= MAX_CTRL_MSG_LEN) {
148-
wpa_printf(MSG_DEBUG, "Too long message received.\n");
149-
continue;
150-
}
151-
152-
if (msg->msg_len > 0) {
153-
/* Only interested in CTRL-EVENTs */
154-
if (strncmp(msg->msg, "CTRL-EVENT", 10) == 0) {
155-
if (strncmp(msg->msg, "CTRL-EVENT-SIGNAL-CHANGE", 24) == 0) {
156-
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
157-
NET_EVENT_WIFI_CMD_SIGNAL_CHANGE,
158-
msg->msg, msg->msg_len);
159-
} else {
160-
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
161-
NET_EVENT_WIFI_CMD_SUPPLICANT,
162-
msg->msg, msg->msg_len);
163-
}
164-
} else if (strncmp(msg->msg, "RRM-NEIGHBOR-REP-RECEIVED", 25) == 0) {
165-
supplicant_send_wifi_mgmt_event(wpa_s->ifname,
166-
NET_EVENT_WIFI_CMD_NEIGHBOR_REP_RECEIVED,
167-
msg->msg, msg->msg_len);
168-
}
169-
}
170-
} else {
171-
wpa_printf(MSG_INFO, "Could not read pending message.\n");
172-
}
173-
}
174-
}
175-
176-
static void wpa_cli_mon_receive(int sock, void *eloop_ctx,
177-
void *sock_ctx)
178-
{
179-
struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)eloop_ctx;
180-
181-
wpa_cli_recv_pending(mon_conn, wpa_s);
182115
}
183116

184117
static int wpa_cli_open_connection(struct wpa_supplicant *wpa_s)
185118
{
186-
int ret;
187-
188119
ctrl_conn = wpa_ctrl_open(wpa_s->ctrl_iface->sock_pair[0]);
189120
if (ctrl_conn == NULL) {
190121
wpa_printf(MSG_ERROR, "Failed to open control connection to %d",
191122
wpa_s->ctrl_iface->sock_pair[0]);
192123
return -1;
193124
}
194125

195-
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, wpa_s->ctrl_iface->mon_sock_pair);
196-
if (ret != 0) {
197-
wpa_printf(MSG_ERROR, "Failed to open monitor connection: %s",
198-
strerror(errno));
199-
goto fail;
200-
}
201-
mon_conn = wpa_ctrl_open(wpa_s->ctrl_iface->mon_sock_pair[0]);
202-
if (mon_conn) {
203-
if (wpa_ctrl_attach(ctrl_conn) == 0) {
204-
eloop_register_read_sock(wpa_s->ctrl_iface->mon_sock_pair[0],
205-
wpa_cli_mon_receive, wpa_s, NULL);
206-
}
207-
}
208-
209126
return 0;
210-
fail:
211-
wpa_ctrl_close(ctrl_conn);
212-
return -1;
213127
}
214128

215129
static int wpa_cli_open_global_ctrl(void)

0 commit comments

Comments
 (0)