Skip to content

Commit e8f2a61

Browse files
committed
hostap: Add support for multiple interfaces in WPA supplicant
Description: The current WPA supplicant implementation in Zephyr does not support multiple interfaces because it uses a single global control channel for interface communication. Since each interface (wpa_s instance) operates independently, this limitation prevents proper handling of multiple virtual interfaces (VIFs). This commit modifies WPA supplicant to support multiple interfaces by: * Removing the single global control channel. * Introducing a new ctrl_conn member in the wpa_s structure. * Assigning a separate ctrl_conn for each interface instance, enabling independent communication between WPA supplicant and Zephyr’s network layer. With this change, each virtual interface can now communicate with the control layer independently, allowing the coexistence of multiple VIFs. Signed-off-by: Hanan Arshad <hananarshad619@gmail.com>
1 parent 8412f4b commit e8f2a61

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
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: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#define DEFAULT_IFNAME "wlan0"
3131
#define MAX_ARGS 32
3232

33-
struct wpa_ctrl *ctrl_conn;
3433
struct wpa_ctrl *global_ctrl_conn;
3534
char *ifname_prefix = NULL;
3635
extern struct wpa_global *global;
@@ -46,7 +45,7 @@ static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd, int print,
4645
size_t len;
4746
int ret;
4847

49-
if (ctrl_conn == NULL && global_ctrl_conn == NULL) {
48+
if (ctrl == NULL && global_ctrl_conn == NULL) {
5049
wpa_printf(MSG_ERROR, "Not connected to wpa_supplicant - command dropped.");
5150
return -1;
5251
}
@@ -93,31 +92,31 @@ static int wpa_ctrl_command_resp(struct wpa_ctrl *ctrl, const char *cmd, char *r
9392
return _wpa_ctrl_command(ctrl, cmd, 0, resp);
9493
}
9594

96-
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)
9796
{
98-
return _wpa_ctrl_command(ctrl_conn, cmd, 1, resp);
97+
return _wpa_ctrl_command(ctrl, cmd, 1, resp);
9998
}
10099

101100
static void wpa_cli_close_connection(struct wpa_supplicant *wpa_s)
102101
{
103102
int ret;
104103

105-
if (ctrl_conn == NULL)
104+
if (wpa_s->ctrl_conn == NULL)
106105
return;
107106

108-
ret = wpa_ctrl_detach(ctrl_conn);
107+
ret = wpa_ctrl_detach(wpa_s->ctrl_conn);
109108
if (ret < 0) {
110109
wpa_printf(MSG_INFO, "Failed to detach from wpa_supplicant: %s",
111110
strerror(errno));
112111
}
113-
wpa_ctrl_close(ctrl_conn);
114-
ctrl_conn = NULL;
112+
wpa_ctrl_close(wpa_s->ctrl_conn);
113+
wpa_s->ctrl_conn = NULL;
115114
}
116115

117116
static int wpa_cli_open_connection(struct wpa_supplicant *wpa_s)
118117
{
119-
ctrl_conn = wpa_ctrl_open(wpa_s->ctrl_iface->sock_pair[0]);
120-
if (ctrl_conn == NULL) {
118+
wpa_s->ctrl_conn = wpa_ctrl_open(wpa_s->ctrl_iface->sock_pair[0]);
119+
if (wpa_s->ctrl_conn == NULL) {
121120
wpa_printf(MSG_ERROR, "Failed to open control connection to %d",
122121
wpa_s->ctrl_iface->sock_pair[0]);
123122
return -1;
@@ -325,12 +324,12 @@ void zephyr_wpa_ctrl_deinit(void *wpa_s)
325324
wpa_cli_close_connection((struct wpa_supplicant *)wpa_s);
326325
}
327326

328-
int zephyr_wpa_ctrl_zephyr_cmd(int argc, const char *argv[])
327+
int zephyr_wpa_ctrl_zephyr_cmd(struct wpa_ctrl *ctrl, int argc, const char *argv[])
329328
{
330-
return wpa_request(ctrl_conn, argc , (char **) argv);
329+
return wpa_request(ctrl, argc , (char **) argv);
331330
}
332331

333-
int zephyr_wpa_cli_cmd_v(const char *fmt, ...)
332+
int zephyr_wpa_cli_cmd_v(struct wpa_ctrl *ctrl, const char *fmt, ...)
334333
{
335334
va_list cmd_args;
336335
int argc;
@@ -347,15 +346,15 @@ int zephyr_wpa_cli_cmd_v(const char *fmt, ...)
347346
for (int i = 0; i < argc; i++)
348347
wpa_printf(MSG_DEBUG, "argv[%d]: %s", i, argv[i]);
349348

350-
return zephyr_wpa_ctrl_zephyr_cmd(argc, argv);
349+
return zephyr_wpa_ctrl_zephyr_cmd(ctrl, argc, argv);
351350
}
352351

353-
int z_wpa_ctrl_add_network(struct add_network_resp *resp)
352+
int z_wpa_ctrl_add_network(struct wpa_ctrl *ctrl, struct add_network_resp *resp)
354353
{
355354
int ret;
356355
char buf[MAX_RESPONSE_SIZE] = {0};
357356

358-
ret = wpa_ctrl_command_resp(ctrl_conn, "ADD_NETWORK", buf);
357+
ret = wpa_ctrl_command_resp(ctrl, "ADD_NETWORK", buf);
359358
if (ret) {
360359
return ret;
361360
}
@@ -370,12 +369,12 @@ int z_wpa_ctrl_add_network(struct add_network_resp *resp)
370369
return 0;
371370
}
372371

373-
int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp)
372+
int z_wpa_ctrl_signal_poll(struct wpa_ctrl *ctrl, struct signal_poll_resp *resp)
374373
{
375374
int ret;
376375
char buf[MAX_RESPONSE_SIZE] = {0};
377376

378-
ret = wpa_ctrl_command_resp(ctrl_conn, "SIGNAL_POLL", buf);
377+
ret = wpa_ctrl_command_resp(ctrl, "SIGNAL_POLL", buf);
379378
if (ret) {
380379
return ret;
381380
}
@@ -390,12 +389,12 @@ int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp)
390389
return 0;
391390
}
392391

393-
int z_wpa_ctrl_status(struct status_resp *resp)
392+
int z_wpa_ctrl_status(struct wpa_ctrl *ctrl, struct status_resp *resp)
394393
{
395394
int ret;
396395
char buf[MAX_RESPONSE_SIZE] = {0};
397396

398-
ret = wpa_ctrl_command_resp(ctrl_conn, "STATUS", buf);
397+
ret = wpa_ctrl_command_resp(ctrl, "STATUS", buf);
399398
if (ret) {
400399
return ret;
401400
}

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct wpa_sm;
3636
struct wpa_supplicant;
3737
struct ibss_rsn;
3838
struct scan_info;
39+
struct wpa_ctrl;
3940
struct wpa_bss;
4041
struct wpa_scan_results;
4142
struct hostapd_hw_modes;
@@ -700,6 +701,9 @@ struct wpa_supplicant {
700701
unsigned char own_addr[ETH_ALEN];
701702
unsigned char perm_addr[ETH_ALEN];
702703
char ifname[100];
704+
/* wpa_ctrl for each wpa_s */
705+
struct wpa_ctrl *ctrl_conn;
706+
struct wpa_ctrl *mon_conn;
703707
#ifdef CONFIG_MATCH_IFACE
704708
int matched;
705709
#endif /* CONFIG_MATCH_IFACE */

0 commit comments

Comments
 (0)