Skip to content

Commit 93e5af2

Browse files
committed
Removed global ctrl_conn and attached it to wpa_s structure
1 parent 697fd2c commit 93e5af2

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

src/common/wpa_ctrl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#ifdef __cplusplus
1313
extern "C" {
1414
#endif
15-
extern struct wpa_ctrl *ctrl_conn;
1615
extern char *ifname_prefix;
1716

1817
/* wpa_supplicant control interface - fixed message prefixes */

wpa_supplicant/wpa_cli_cmds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, const char *cmd,
489489
size_t len;
490490
int ret;
491491

492-
if (ctrl_conn == NULL) {
492+
if (ctrl == NULL) {
493493
wpa_printf(MSG_INFO, "Not connected to hostapd - command dropped.\n");
494494
return -1;
495495
}
@@ -2122,7 +2122,7 @@ static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl *ctrl, const char *cmd,
21222122
size_t len;
21232123
int ret;
21242124

2125-
if (ctrl_conn == NULL)
2125+
if (ctrl == NULL)
21262126
return -1;
21272127
len = sizeof(buf) - 1;
21282128
ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
@@ -2817,7 +2817,7 @@ static int wpa_ctrl_command_bss(struct wpa_ctrl *ctrl, const char *cmd)
28172817
size_t len;
28182818
int ret, id = -1;
28192819

2820-
if (!ctrl_conn)
2820+
if (ctrl == NULL)
28212821
return -1;
28222822
len = sizeof(buf) - 1;
28232823
ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,

wpa_supplicant/wpa_cli_zephyr.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#define DEFAULT_IFNAME "wlan0"
3131
#define MAX_ARGS 32
3232

33-
struct wpa_ctrl *ctrl_conn;
34-
struct wpa_ctrl *mon_conn;
3533
struct wpa_ctrl *global_ctrl_conn;
3634
char *ifname_prefix = NULL;
3735
extern struct wpa_global *global;
@@ -47,7 +45,7 @@ static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd, int print,
4745
size_t len;
4846
int ret;
4947

50-
if (ctrl_conn == NULL && global_ctrl_conn == NULL) {
48+
if (ctrl == NULL && global_ctrl_conn == NULL) {
5149
wpa_printf(MSG_ERROR, "Not connected to wpa_supplicant - command dropped.");
5250
return -1;
5351
}
@@ -94,30 +92,30 @@ static int wpa_ctrl_command_resp(struct wpa_ctrl *ctrl, const char *cmd, char *r
9492
return _wpa_ctrl_command(ctrl, cmd, 0, resp);
9593
}
9694

97-
int zephyr_wpa_cli_cmd_resp(const char *cmd, char *resp)
95+
int zephyr_wpa_cli_cmd_resp(struct wpa_ctrl *ctrl, const char *cmd, char *resp)
9896
{
99-
return _wpa_ctrl_command(ctrl_conn, cmd, 1, resp);
97+
return _wpa_ctrl_command(ctrl, cmd, 1, resp);
10098
}
10199

102100
static void wpa_cli_close_connection(struct wpa_supplicant *wpa_s)
103101
{
104102
int ret;
105103

106-
if (ctrl_conn == NULL)
104+
if (wpa_s->ctrl_conn == NULL)
107105
return;
108106

109-
ret = wpa_ctrl_detach(ctrl_conn);
107+
ret = wpa_ctrl_detach(wpa_s->ctrl_conn);
110108
if (ret < 0) {
111109
wpa_printf(MSG_INFO, "Failed to detach from wpa_supplicant: %s",
112110
strerror(errno));
113111
}
114-
wpa_ctrl_close(ctrl_conn);
115-
ctrl_conn = NULL;
112+
wpa_ctrl_close(wpa_s->ctrl_conn);
113+
wpa_s->ctrl_conn = NULL;
116114

117115
eloop_unregister_read_sock(wpa_s->ctrl_iface->mon_sock_pair[0]);
118116

119-
wpa_ctrl_close(mon_conn);
120-
mon_conn = NULL;
117+
wpa_ctrl_close(wpa_s->mon_conn);
118+
wpa_s->mon_conn = NULL;
121119

122120
close(wpa_s->ctrl_iface->mon_sock_pair[1]);
123121
wpa_s->ctrl_iface->mon_sock_pair[1] = -1;
@@ -178,15 +176,15 @@ static void wpa_cli_mon_receive(int sock, void *eloop_ctx,
178176
{
179177
struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)eloop_ctx;
180178

181-
wpa_cli_recv_pending(mon_conn, wpa_s);
179+
wpa_cli_recv_pending(wpa_s->mon_conn, wpa_s);
182180
}
183181

184182
static int wpa_cli_open_connection(struct wpa_supplicant *wpa_s)
185183
{
186184
int ret;
187185

188-
ctrl_conn = wpa_ctrl_open(wpa_s->ctrl_iface->sock_pair[0]);
189-
if (ctrl_conn == NULL) {
186+
wpa_s->ctrl_conn = wpa_ctrl_open(wpa_s->ctrl_iface->sock_pair[0]);
187+
if (wpa_s->ctrl_conn == NULL) {
190188
wpa_printf(MSG_ERROR, "Failed to open control connection to %d",
191189
wpa_s->ctrl_iface->sock_pair[0]);
192190
return -1;
@@ -198,17 +196,18 @@ static int wpa_cli_open_connection(struct wpa_supplicant *wpa_s)
198196
strerror(errno));
199197
goto fail;
200198
}
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) {
199+
wpa_s->mon_conn = wpa_ctrl_open(wpa_s->ctrl_iface->mon_sock_pair[0]);
200+
if (wpa_s->mon_conn) {
201+
if (wpa_ctrl_attach(wpa_s->ctrl_conn) == 0) {
204202
eloop_register_read_sock(wpa_s->ctrl_iface->mon_sock_pair[0],
205203
wpa_cli_mon_receive, wpa_s, NULL);
206204
}
207205
}
208206

209207
return 0;
210208
fail:
211-
wpa_ctrl_close(ctrl_conn);
209+
wpa_ctrl_close(wpa_s->ctrl_conn);
210+
wpa_s->ctrl_conn = NULL;
212211
return -1;
213212
}
214213

@@ -411,12 +410,12 @@ void zephyr_wpa_ctrl_deinit(void *wpa_s)
411410
wpa_cli_close_connection((struct wpa_supplicant *)wpa_s);
412411
}
413412

414-
int zephyr_wpa_ctrl_zephyr_cmd(int argc, const char *argv[])
413+
int zephyr_wpa_ctrl_zephyr_cmd(struct wpa_ctrl *ctrl, int argc, const char *argv[])
415414
{
416-
return wpa_request(ctrl_conn, argc , (char **) argv);
415+
return wpa_request(ctrl, argc , (char **) argv);
417416
}
418417

419-
int zephyr_wpa_cli_cmd_v(const char *fmt, ...)
418+
int zephyr_wpa_cli_cmd_v(struct wpa_ctrl *ctrl, const char *fmt, ...)
420419
{
421420
va_list cmd_args;
422421
int argc;
@@ -433,15 +432,15 @@ int zephyr_wpa_cli_cmd_v(const char *fmt, ...)
433432
for (int i = 0; i < argc; i++)
434433
wpa_printf(MSG_DEBUG, "argv[%d]: %s", i, argv[i]);
435434

436-
return zephyr_wpa_ctrl_zephyr_cmd(argc, argv);
435+
return zephyr_wpa_ctrl_zephyr_cmd(ctrl, argc, argv);
437436
}
438437

439-
int z_wpa_ctrl_add_network(struct add_network_resp *resp)
438+
int z_wpa_ctrl_add_network(struct wpa_ctrl *ctrl, struct add_network_resp *resp)
440439
{
441440
int ret;
442441
char buf[MAX_RESPONSE_SIZE] = {0};
443442

444-
ret = wpa_ctrl_command_resp(ctrl_conn, "ADD_NETWORK", buf);
443+
ret = wpa_ctrl_command_resp(ctrl, "ADD_NETWORK", buf);
445444
if (ret) {
446445
return ret;
447446
}
@@ -456,12 +455,12 @@ int z_wpa_ctrl_add_network(struct add_network_resp *resp)
456455
return 0;
457456
}
458457

459-
int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp)
458+
int z_wpa_ctrl_signal_poll(struct wpa_ctrl *ctrl, struct signal_poll_resp *resp)
460459
{
461460
int ret;
462461
char buf[MAX_RESPONSE_SIZE] = {0};
463462

464-
ret = wpa_ctrl_command_resp(ctrl_conn, "SIGNAL_POLL", buf);
463+
ret = wpa_ctrl_command_resp(ctrl, "SIGNAL_POLL", buf);
465464
if (ret) {
466465
return ret;
467466
}
@@ -476,12 +475,12 @@ int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp)
476475
return 0;
477476
}
478477

479-
int z_wpa_ctrl_status(struct status_resp *resp)
478+
int z_wpa_ctrl_status(struct wpa_ctrl *ctrl, struct status_resp *resp)
480479
{
481480
int ret;
482481
char buf[MAX_RESPONSE_SIZE] = {0};
483482

484-
ret = wpa_ctrl_command_resp(ctrl_conn, "STATUS", buf);
483+
ret = wpa_ctrl_command_resp(ctrl, "STATUS", buf);
485484
if (ret) {
486485
return ret;
487486
}

wpa_supplicant/wpa_cli_zephyr.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ struct status_resp {
2929
/* Public APIs */
3030
int zephyr_wpa_ctrl_init(void *wpa_s);
3131
void zephyr_wpa_ctrl_deinit(void *wpa_s);
32-
int zephyr_wpa_ctrl_zephyr_cmd(int argc, const char *argv[]);
33-
int zephyr_wpa_cli_cmd_v(const char *fmt, ...);
34-
int zephyr_wpa_cli_cmd_resp(const char *cmd, char *resp);
35-
36-
int z_wpa_ctrl_add_network(struct add_network_resp *resp);
37-
int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp);
38-
int z_wpa_ctrl_status(struct status_resp *resp);
39-
32+
int zephyr_wpa_ctrl_zephyr_cmd(struct wpa_ctrl *ctrl, int argc, const char *argv[]);
33+
int zephyr_wpa_cli_cmd_v(struct wpa_ctrl *ctrl, const char *fmt, ...);
34+
int zephyr_wpa_cli_cmd_resp(struct wpa_ctrl *ctrl, const char *cmd, char *resp);
35+
36+
int z_wpa_ctrl_add_network(struct wpa_ctrl *ctrl, struct add_network_resp *resp);
37+
int z_wpa_ctrl_signal_poll(struct wpa_ctrl *ctrl, struct signal_poll_resp *resp);
38+
int z_wpa_ctrl_status(struct wpa_ctrl *ctrl, struct status_resp *resp);
39+
4040
/* Global control interface */
4141
int zephyr_global_wpa_ctrl_init(void);
4242
void zephyr_global_wpa_ctrl_deinit(void);

wpa_supplicant/wpa_supplicant_i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ struct wpa_supplicant {
700700
unsigned char own_addr[ETH_ALEN];
701701
unsigned char perm_addr[ETH_ALEN];
702702
char ifname[100];
703+
/* wpa_ctrl for each wpa_s */
704+
struct wpa_ctrl *ctrl_conn;
705+
struct wpa_ctrl *mon_conn;
703706
#ifdef CONFIG_MATCH_IFACE
704707
int matched;
705708
#endif /* CONFIG_MATCH_IFACE */

0 commit comments

Comments
 (0)