Skip to content

hostap: Add support for multiple interfaces in WPA supplicant #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/common/wpa_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#ifdef __cplusplus
extern "C" {
#endif
extern struct wpa_ctrl *ctrl_conn;
extern char *ifname_prefix;

/* wpa_supplicant control interface - fixed message prefixes */
Expand Down
6 changes: 3 additions & 3 deletions wpa_supplicant/wpa_cli_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, const char *cmd,
size_t len;
int ret;

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

if (ctrl_conn == NULL)
if (ctrl == NULL)
return -1;
len = sizeof(buf) - 1;
ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
Expand Down Expand Up @@ -2817,7 +2817,7 @@ static int wpa_ctrl_command_bss(struct wpa_ctrl *ctrl, const char *cmd)
size_t len;
int ret, id = -1;

if (!ctrl_conn)
if (ctrl == NULL)
return -1;
len = sizeof(buf) - 1;
ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
Expand Down
39 changes: 19 additions & 20 deletions wpa_supplicant/wpa_cli_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#define DEFAULT_IFNAME "wlan0"
#define MAX_ARGS 32

struct wpa_ctrl *ctrl_conn;
struct wpa_ctrl *global_ctrl_conn;
char *ifname_prefix = NULL;
extern struct wpa_global *global;
Expand All @@ -46,7 +45,7 @@ static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd, int print,
size_t len;
int ret;

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

int zephyr_wpa_cli_cmd_resp(const char *cmd, char *resp)
int zephyr_wpa_cli_cmd_resp(struct wpa_ctrl *ctrl, const char *cmd, char *resp)
{
return _wpa_ctrl_command(ctrl_conn, cmd, 1, resp);
return _wpa_ctrl_command(ctrl, cmd, 1, resp);
}

static void wpa_cli_close_connection(struct wpa_supplicant *wpa_s)
{
int ret;

if (ctrl_conn == NULL)
if (wpa_s->ctrl_conn == NULL)
return;

ret = wpa_ctrl_detach(ctrl_conn);
ret = wpa_ctrl_detach(wpa_s->ctrl_conn);
if (ret < 0) {
wpa_printf(MSG_INFO, "Failed to detach from wpa_supplicant: %s",
strerror(errno));
}
wpa_ctrl_close(ctrl_conn);
ctrl_conn = NULL;
wpa_ctrl_close(wpa_s->ctrl_conn);
wpa_s->ctrl_conn = NULL;
}

static int wpa_cli_open_connection(struct wpa_supplicant *wpa_s)
{
ctrl_conn = wpa_ctrl_open(wpa_s->ctrl_iface->sock_pair[0]);
if (ctrl_conn == NULL) {
wpa_s->ctrl_conn = wpa_ctrl_open(wpa_s->ctrl_iface->sock_pair[0]);
if (wpa_s->ctrl_conn == NULL) {
wpa_printf(MSG_ERROR, "Failed to open control connection to %d",
wpa_s->ctrl_iface->sock_pair[0]);
return -1;
Expand Down Expand Up @@ -325,12 +324,12 @@ void zephyr_wpa_ctrl_deinit(void *wpa_s)
wpa_cli_close_connection((struct wpa_supplicant *)wpa_s);
}

int zephyr_wpa_ctrl_zephyr_cmd(int argc, const char *argv[])
int zephyr_wpa_ctrl_zephyr_cmd(struct wpa_ctrl *ctrl, int argc, const char *argv[])
{
return wpa_request(ctrl_conn, argc , (char **) argv);
return wpa_request(ctrl, argc , (char **) argv);
}

int zephyr_wpa_cli_cmd_v(const char *fmt, ...)
int zephyr_wpa_cli_cmd_v(struct wpa_ctrl *ctrl, const char *fmt, ...)
{
va_list cmd_args;
int argc;
Expand All @@ -347,15 +346,15 @@ int zephyr_wpa_cli_cmd_v(const char *fmt, ...)
for (int i = 0; i < argc; i++)
wpa_printf(MSG_DEBUG, "argv[%d]: %s", i, argv[i]);

return zephyr_wpa_ctrl_zephyr_cmd(argc, argv);
return zephyr_wpa_ctrl_zephyr_cmd(ctrl, argc, argv);
}

int z_wpa_ctrl_add_network(struct add_network_resp *resp)
int z_wpa_ctrl_add_network(struct wpa_ctrl *ctrl, struct add_network_resp *resp)
{
int ret;
char buf[MAX_RESPONSE_SIZE] = {0};

ret = wpa_ctrl_command_resp(ctrl_conn, "ADD_NETWORK", buf);
ret = wpa_ctrl_command_resp(ctrl, "ADD_NETWORK", buf);
if (ret) {
return ret;
}
Expand All @@ -370,12 +369,12 @@ int z_wpa_ctrl_add_network(struct add_network_resp *resp)
return 0;
}

int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp)
int z_wpa_ctrl_signal_poll(struct wpa_ctrl *ctrl, struct signal_poll_resp *resp)
{
int ret;
char buf[MAX_RESPONSE_SIZE] = {0};

ret = wpa_ctrl_command_resp(ctrl_conn, "SIGNAL_POLL", buf);
ret = wpa_ctrl_command_resp(ctrl, "SIGNAL_POLL", buf);
if (ret) {
return ret;
}
Expand All @@ -390,12 +389,12 @@ int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp)
return 0;
}

int z_wpa_ctrl_status(struct status_resp *resp)
int z_wpa_ctrl_status(struct wpa_ctrl *ctrl, struct status_resp *resp)
{
int ret;
char buf[MAX_RESPONSE_SIZE] = {0};

ret = wpa_ctrl_command_resp(ctrl_conn, "STATUS", buf);
ret = wpa_ctrl_command_resp(ctrl, "STATUS", buf);
if (ret) {
return ret;
}
Expand Down
18 changes: 10 additions & 8 deletions wpa_supplicant/wpa_cli_zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ struct status_resp {
char ssid[SSID_MAX_LEN + 1];
};

struct wpa_ctrl;

/* Public APIs */
int zephyr_wpa_ctrl_init(void *wpa_s);
void zephyr_wpa_ctrl_deinit(void *wpa_s);
int zephyr_wpa_ctrl_zephyr_cmd(int argc, const char *argv[]);
int zephyr_wpa_cli_cmd_v(const char *fmt, ...);
int zephyr_wpa_cli_cmd_resp(const char *cmd, char *resp);

int z_wpa_ctrl_add_network(struct add_network_resp *resp);
int z_wpa_ctrl_signal_poll(struct signal_poll_resp *resp);
int z_wpa_ctrl_status(struct status_resp *resp);

int zephyr_wpa_ctrl_zephyr_cmd(struct wpa_ctrl *ctrl, int argc, const char *argv[]);
int zephyr_wpa_cli_cmd_v(struct wpa_ctrl *ctrl, const char *fmt, ...);
int zephyr_wpa_cli_cmd_resp(struct wpa_ctrl *ctrl, const char *cmd, char *resp);
int z_wpa_ctrl_add_network(struct wpa_ctrl *ctrl, struct add_network_resp *resp);
int z_wpa_ctrl_signal_poll(struct wpa_ctrl *ctrl, struct signal_poll_resp *resp);
int z_wpa_ctrl_status(struct wpa_ctrl *ctrl, struct status_resp *resp);
/* Global control interface */
int zephyr_global_wpa_ctrl_init(void);
void zephyr_global_wpa_ctrl_deinit(void);
Expand Down
4 changes: 4 additions & 0 deletions wpa_supplicant/wpa_supplicant_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct wpa_sm;
struct wpa_supplicant;
struct ibss_rsn;
struct scan_info;
struct wpa_ctrl;
struct wpa_bss;
struct wpa_scan_results;
struct hostapd_hw_modes;
Expand Down Expand Up @@ -700,6 +701,9 @@ struct wpa_supplicant {
unsigned char own_addr[ETH_ALEN];
unsigned char perm_addr[ETH_ALEN];
char ifname[100];
/* wpa_ctrl for each wpa_s */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implied as the struct is wpa_supplicant.

struct wpa_ctrl *ctrl_conn;
struct wpa_ctrl *mon_conn;
#ifdef CONFIG_MATCH_IFACE
int matched;
#endif /* CONFIG_MATCH_IFACE */
Expand Down