developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 1 | From 166ae43a8066cbc70d5d990cfd29cb6c4c2afc67 Mon Sep 17 00:00:00 2001 |
| 2 | From: Karthikeyan Kathirvel <quic_kathirve@quicinc.com> |
| 3 | Date: Tue, 23 Apr 2024 11:01:23 +0530 |
| 4 | Subject: [PATCH 001/126] ctrl_iface: create link based hapd control sockets |
| 5 | |
| 6 | Create link based control sockets to access the link based commands |
| 7 | through hostapd_cli. This will create the link interfaces in the name of |
| 8 | wlan<X>_link<X> |
| 9 | |
| 10 | Example: |
| 11 | To fetch link 0 status from wlan0, below command can be used - |
| 12 | $ hostapd_cli -i wlan0 -l 0 status |
| 13 | |
| 14 | On failure of link/interface selection, below error will be observed |
| 15 | $ hostapd_cli -i wlan0 -l 2 status |
| 16 | Failed to connect to hostapd - wpa_ctrl_open: No such file or directory |
| 17 | |
| 18 | Signed-off-by: Karthikeyan Kathirvel <quic_kathirve@quicinc.com> |
| 19 | Co-developed-by: Aditya Kumar Singh <quic_adisi@quicinc.com> |
| 20 | Signed-off-by: Aditya Kumar Singh <quic_adisi@quicinc.com> |
| 21 | --- |
| 22 | hostapd/ctrl_iface.c | 16 ++++++++++++++-- |
| 23 | hostapd/hostapd_cli.c | 30 ++++++++++++++++++++++++++++-- |
| 24 | src/ap/hostapd.c | 28 ++++++++++++++++++++++++++++ |
| 25 | src/ap/hostapd.h | 1 + |
| 26 | src/common/wpa_ctrl.h | 4 ++++ |
| 27 | 5 files changed, 75 insertions(+), 4 deletions(-) |
| 28 | |
| 29 | diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c |
| 30 | index 39b9ef59d..3fa33be7a 100644 |
| 31 | --- a/hostapd/ctrl_iface.c |
| 32 | +++ b/hostapd/ctrl_iface.c |
| 33 | @@ -4687,18 +4687,26 @@ static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd) |
| 34 | { |
| 35 | char *buf; |
| 36 | size_t len; |
| 37 | + char *ctrl_sock_iface; |
| 38 | + |
| 39 | +#ifdef CONFIG_IEEE80211BE |
| 40 | + ctrl_sock_iface = hapd->ctrl_sock_iface; |
| 41 | +#else |
| 42 | + ctrl_sock_iface = hapd->conf->iface; |
| 43 | +#endif /* CONFIG_IEEE80211BE */ |
| 44 | |
| 45 | if (hapd->conf->ctrl_interface == NULL) |
| 46 | return NULL; |
| 47 | |
| 48 | len = os_strlen(hapd->conf->ctrl_interface) + |
| 49 | - os_strlen(hapd->conf->iface) + 2; |
| 50 | + os_strlen(ctrl_sock_iface) + 2; |
| 51 | + |
| 52 | buf = os_malloc(len); |
| 53 | if (buf == NULL) |
| 54 | return NULL; |
| 55 | |
| 56 | os_snprintf(buf, len, "%s/%s", |
| 57 | - hapd->conf->ctrl_interface, hapd->conf->iface); |
| 58 | + hapd->conf->ctrl_interface, ctrl_sock_iface); |
| 59 | buf[len - 1] = '\0'; |
| 60 | return buf; |
| 61 | } |
| 62 | @@ -4869,7 +4877,11 @@ fail: |
| 63 | #endif /* ANDROID */ |
| 64 | |
| 65 | if (os_strlen(hapd->conf->ctrl_interface) + 1 + |
| 66 | +#ifdef CONFIG_IEEE80211BE |
| 67 | + os_strlen(hapd->ctrl_sock_iface) >= sizeof(addr.sun_path)) |
| 68 | +#else |
| 69 | os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path)) |
| 70 | +#endif /* CONFIG_IEEE80211BE */ |
| 71 | goto fail; |
| 72 | |
| 73 | s = socket(PF_UNIX, SOCK_DGRAM, 0); |
| 74 | diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c |
| 75 | index eb8a38350..f05a734fe 100644 |
| 76 | --- a/hostapd/hostapd_cli.c |
| 77 | +++ b/hostapd/hostapd_cli.c |
| 78 | @@ -54,7 +54,11 @@ static void usage(void) |
| 79 | fprintf(stderr, "%s\n", hostapd_cli_version); |
| 80 | fprintf(stderr, |
| 81 | "\n" |
| 82 | +#ifdef CONFIG_IEEE80211BE |
| 83 | + "usage: hostapd_cli [-p<path>] [-i<ifname>] [-l<link_id>] [-hvBr] " |
| 84 | +#else |
| 85 | "usage: hostapd_cli [-p<path>] [-i<ifname>] [-hvBr] " |
| 86 | +#endif /* CONFIG_IEEE80211BE */ |
| 87 | "[-a<path>] \\\n" |
| 88 | " [-P<pid file>] [-G<ping interval>] [command..]\n" |
| 89 | "\n" |
| 90 | @@ -74,7 +78,12 @@ static void usage(void) |
| 91 | " -B run a daemon in the background\n" |
| 92 | " -i<ifname> Interface to listen on (default: first " |
| 93 | "interface found in the\n" |
| 94 | - " socket path)\n\n"); |
| 95 | + " socket path)\n" |
| 96 | +#ifdef CONFIG_IEEE80211BE |
| 97 | + " -l<link_id> Link ID of the interface in case of Multi-Link\n" |
| 98 | + " Operation\n" |
| 99 | +#endif /* CONFIG_IEEE80211BE */ |
| 100 | + "\n"); |
| 101 | print_help(stderr, NULL); |
| 102 | } |
| 103 | |
| 104 | @@ -2205,19 +2214,26 @@ static void hostapd_cli_action(struct wpa_ctrl *ctrl) |
| 105 | eloop_unregister_read_sock(fd); |
| 106 | } |
| 107 | |
| 108 | - |
| 109 | int main(int argc, char *argv[]) |
| 110 | { |
| 111 | int warning_displayed = 0; |
| 112 | int c; |
| 113 | int daemonize = 0; |
| 114 | int reconnect = 0; |
| 115 | +#ifdef CONFIG_IEEE80211BE |
| 116 | + int link_id = -1; |
| 117 | + char buf[300]; |
| 118 | +#endif /* CONFIG_IEEE80211BE */ |
| 119 | |
| 120 | if (os_program_init()) |
| 121 | return -1; |
| 122 | |
| 123 | for (;;) { |
| 124 | +#ifdef CONFIG_IEEE80211BE |
| 125 | + c = getopt(argc, argv, "a:BhG:i:l:p:P:rs:v"); |
| 126 | +#else |
| 127 | c = getopt(argc, argv, "a:BhG:i:p:P:rs:v"); |
| 128 | +#endif /* CONFIG_IEEE80211BE */ |
| 129 | if (c < 0) |
| 130 | break; |
| 131 | switch (c) { |
| 132 | @@ -2252,6 +2268,16 @@ int main(int argc, char *argv[]) |
| 133 | case 's': |
| 134 | client_socket_dir = optarg; |
| 135 | break; |
| 136 | +#ifdef CONFIG_IEEE80211BE |
| 137 | + case 'l': |
| 138 | + link_id = atoi(optarg); |
| 139 | + os_memset(buf, '\0', sizeof(buf)); |
| 140 | + os_snprintf(buf, sizeof(buf), "%s_%s%d", |
| 141 | + ctrl_ifname, WPA_CTRL_IFACE_LINK_NAME, link_id); |
| 142 | + os_free(ctrl_ifname); |
| 143 | + ctrl_ifname = os_strdup(buf); |
| 144 | + break; |
| 145 | +#endif /* CONFIG_IEEE80211BE */ |
| 146 | default: |
| 147 | usage(); |
| 148 | return -1; |
| 149 | diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c |
| 150 | index a05de030d..c819c30cf 100644 |
| 151 | --- a/src/ap/hostapd.c |
| 152 | +++ b/src/ap/hostapd.c |
| 153 | @@ -1808,12 +1808,37 @@ int hostapd_set_acl(struct hostapd_data *hapd) |
| 154 | } |
| 155 | |
| 156 | |
| 157 | +static void hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd) |
| 158 | +{ |
| 159 | +#ifdef CONFIG_IEEE80211BE |
| 160 | + os_memset(hapd->ctrl_sock_iface, '\0', |
| 161 | + sizeof(hapd->ctrl_sock_iface)); |
| 162 | + os_strlcpy(hapd->ctrl_sock_iface, hapd->conf->iface, |
| 163 | + sizeof(hapd->ctrl_sock_iface)); |
| 164 | + |
| 165 | + if (hapd->conf->mld_ap) { |
| 166 | + char buf[128]; |
| 167 | + |
| 168 | + os_memset(buf, '\0', sizeof(buf)); |
| 169 | + os_snprintf(buf, sizeof(buf), "%s_%s%d", |
| 170 | + hapd->conf->iface, WPA_CTRL_IFACE_LINK_NAME, |
| 171 | + hapd->mld_link_id); |
| 172 | + os_memset(hapd->ctrl_sock_iface, '\0', |
| 173 | + sizeof(hapd->ctrl_sock_iface)); |
| 174 | + os_strlcpy(hapd->ctrl_sock_iface, buf, sizeof(buf)); |
| 175 | + } |
| 176 | +#endif /* CONFIG_IEEE80211BE */ |
| 177 | +} |
| 178 | + |
| 179 | + |
| 180 | static int start_ctrl_iface_bss(struct hostapd_data *hapd) |
| 181 | { |
| 182 | if (!hapd->iface->interfaces || |
| 183 | !hapd->iface->interfaces->ctrl_iface_init) |
| 184 | return 0; |
| 185 | |
| 186 | + hostapd_set_ctrl_sock_iface(hapd); |
| 187 | + |
| 188 | if (hapd->iface->interfaces->ctrl_iface_init(hapd)) { |
| 189 | wpa_printf(MSG_ERROR, |
| 190 | "Failed to setup control interface for %s", |
| 191 | @@ -1834,6 +1859,9 @@ static int start_ctrl_iface(struct hostapd_iface *iface) |
| 192 | |
| 193 | for (i = 0; i < iface->num_bss; i++) { |
| 194 | struct hostapd_data *hapd = iface->bss[i]; |
| 195 | + |
| 196 | + hostapd_set_ctrl_sock_iface(hapd); |
| 197 | + |
| 198 | if (iface->interfaces->ctrl_iface_init(hapd)) { |
| 199 | wpa_printf(MSG_ERROR, |
| 200 | "Failed to setup control interface for %s", |
| 201 | diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h |
| 202 | index dcf395ca5..34a665562 100644 |
| 203 | --- a/src/ap/hostapd.h |
| 204 | +++ b/src/ap/hostapd.h |
| 205 | @@ -476,6 +476,7 @@ struct hostapd_data { |
| 206 | struct hostapd_mld *mld; |
| 207 | struct dl_list link; |
| 208 | u8 mld_link_id; |
| 209 | + char ctrl_sock_iface[IFNAMSIZ + 1]; |
| 210 | #ifdef CONFIG_TESTING_OPTIONS |
| 211 | u8 eht_mld_link_removal_count; |
| 212 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 213 | diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h |
| 214 | index f6142501e..865ac6d91 100644 |
| 215 | --- a/src/common/wpa_ctrl.h |
| 216 | +++ b/src/common/wpa_ctrl.h |
| 217 | @@ -674,4 +674,8 @@ char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl); |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | +#ifdef CONFIG_IEEE80211BE |
| 222 | +#define WPA_CTRL_IFACE_LINK_NAME "link" |
| 223 | +#endif /* CONFIG_IEEE80211BE */ |
| 224 | + |
| 225 | #endif /* WPA_CTRL_H */ |
| 226 | -- |
| 227 | 2.18.0 |
| 228 | |