Skip to content

Commit a1b2c1d

Browse files
krish2718rado17
authored andcommitted
[nrf fromtree] modules: hostap: Update WPA supplicant to use per-VIF control channel
Update WPA supplicant functions to pass the control channel (socket) as a parameter instead of relying on a global socket. This change aligns with the PR 80 modifications in hostap repo and ensures that each Virtual Interface (VIF) uses its dedicated control channel for communication. Signed-off-by: Hanan Arshad <hananarshad619@gmail.com> Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no> (cherry picked from commit 53a885a)
1 parent 712c6cc commit a1b2c1d

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

modules/hostap/src/supp_api.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,19 @@ static void supp_shell_connect_status(struct k_work *work);
8989
static K_WORK_DELAYABLE_DEFINE(wpa_supp_status_work,
9090
supp_shell_connect_status);
9191

92-
#define wpa_cli_cmd_v(cmd, ...) ({ \
93-
bool status; \
94-
\
95-
if (zephyr_wpa_cli_cmd_v(cmd, ##__VA_ARGS__) < 0) { \
96-
wpa_printf(MSG_ERROR, \
97-
"Failed to execute wpa_cli command: %s", \
98-
cmd); \
99-
status = false; \
100-
} else { \
101-
status = true; \
102-
} \
103-
\
104-
status; \
105-
})
92+
#define wpa_cli_cmd_v(cmd, ...) \
93+
({ \
94+
bool status; \
95+
\
96+
if (zephyr_wpa_cli_cmd_v(wpa_s->ctrl_conn, cmd, ##__VA_ARGS__) < 0) { \
97+
wpa_printf(MSG_ERROR, "Failed to execute wpa_cli command: %s", cmd); \
98+
status = false; \
99+
} else { \
100+
status = true; \
101+
} \
102+
\
103+
status; \
104+
})
106105

107106
static struct wpa_supplicant *get_wpa_s_handle(const struct device *dev)
108107
{
@@ -635,7 +634,7 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s,
635634
goto out;
636635
}
637636

638-
ret = z_wpa_ctrl_add_network(&resp);
637+
ret = z_wpa_ctrl_add_network(wpa_s->ctrl_conn, &resp);
639638
if (ret) {
640639
wpa_printf(MSG_ERROR, "Failed to add network");
641640
goto out;
@@ -1374,7 +1373,7 @@ int supplicant_status(const struct device *dev, struct wifi_iface_status *status
13741373
status->channel = channel;
13751374

13761375
if (ssid_len == 0) {
1377-
int _res = z_wpa_ctrl_status(&cli_status);
1376+
int _res = z_wpa_ctrl_status(wpa_s->ctrl_conn, &cli_status);
13781377

13791378
if (_res < 0) {
13801379
ssid_len = 0;
@@ -1403,7 +1402,7 @@ int supplicant_status(const struct device *dev, struct wifi_iface_status *status
14031402

14041403
status->rssi = -WPA_INVALID_NOISE;
14051404
if (status->iface_mode == WIFI_MODE_INFRA) {
1406-
ret = z_wpa_ctrl_signal_poll(&signal_poll);
1405+
ret = z_wpa_ctrl_signal_poll(wpa_s->ctrl_conn, &signal_poll);
14071406
if (!ret) {
14081407
status->rssi = signal_poll.rssi;
14091408
status->current_phy_tx_rate = signal_poll.current_txrate;
@@ -2081,7 +2080,7 @@ static int supplicant_wps_pin(const struct device *dev, struct wifi_wps_config_p
20812080
}
20822081

20832082
if (params->oper == WIFI_WPS_PIN_GET) {
2084-
if (zephyr_wpa_cli_cmd_resp(get_pin_cmd, params->pin)) {
2083+
if (zephyr_wpa_cli_cmd_resp(wpa_s->ctrl_conn, get_pin_cmd, params->pin)) {
20852084
goto out;
20862085
}
20872086
} else if (params->oper == WIFI_WPS_PIN_SET) {
@@ -2514,6 +2513,7 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa
25142513
{
25152514
int ret;
25162515
char *cmd = NULL;
2516+
struct wpa_supplicant *wpa_s = get_wpa_s_handle(dev);
25172517

25182518
if (params == NULL) {
25192519
return -EINVAL;
@@ -2532,7 +2532,7 @@ int supplicant_dpp_dispatch(const struct device *dev, struct wifi_dpp_params *pa
25322532
}
25332533

25342534
wpa_printf(MSG_DEBUG, "wpa_cli %s", cmd);
2535-
if (zephyr_wpa_cli_cmd_resp(cmd, params->resp)) {
2535+
if (zephyr_wpa_cli_cmd_resp(wpa_s->ctrl_conn, cmd, params->resp)) {
25362536
os_free(cmd);
25372537
return -ENOEXEC;
25382538
}

modules/hostap/src/supp_main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ struct wpa_supplicant *zephyr_get_handle_by_ifname(const char *ifname);
5858
struct hapd_interfaces *zephyr_get_default_hapd_context(void);
5959
#endif
6060

61-
struct wpa_supplicant *zephyr_get_handle_by_ifname(const char *ifname);
62-
6361
struct wpa_supplicant_event_msg {
6462
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
6563
int hostapd;

modules/hostap/src/wpa_cli.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
* @brief wpa_cli implementation for Zephyr OS
99
*/
1010

11+
#include <stdlib.h>
1112
#include <zephyr/kernel.h>
1213
#include <zephyr/shell/shell.h>
14+
#include <zephyr/net/net_if.h>
1315
#include <zephyr/init.h>
1416

17+
18+
#include "supp_main.h"
19+
20+
#include "common.h"
21+
#include "wpa_supplicant_i.h"
1522
#include "wpa_cli_zephyr.h"
1623
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
1724
#include "hostapd_cli_zephyr.h"
@@ -21,8 +28,20 @@ static int cmd_wpa_cli(const struct shell *sh,
2128
size_t argc,
2229
const char *argv[])
2330
{
31+
struct net_if *iface = net_if_get_first_wifi();
32+
char if_name[CONFIG_NET_INTERFACE_NAME_LEN + 1];
33+
struct wpa_supplicant *wpa_s = NULL;
34+
2435
ARG_UNUSED(sh);
2536

37+
if (iface == NULL) {
38+
shell_error(sh, "No Wifi interface found");
39+
return -ENOENT;
40+
}
41+
42+
net_if_get_name(iface, if_name, sizeof(if_name));
43+
wpa_s = zephyr_get_handle_by_ifname(if_name);
44+
2645
if (argc == 1) {
2746
shell_error(sh, "Missing argument");
2847
return -EINVAL;
@@ -32,7 +51,7 @@ static int cmd_wpa_cli(const struct shell *sh,
3251
argc++;
3352

3453
/* Remove wpa_cli from the argument list */
35-
return zephyr_wpa_ctrl_zephyr_cmd(argc - 1, &argv[1]);
54+
return zephyr_wpa_ctrl_zephyr_cmd(wpa_s->ctrl_conn, argc - 1, &argv[1]);
3655
}
3756

3857
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP

0 commit comments

Comments
 (0)