blob: 9b45d05dc765e8420d72209b06f848dfbe986e2e [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 702fc9f42fc30acd7f956994f887d02eef3c3ade Mon Sep 17 00:00:00 2001
2From: Aditya Kumar Singh <quic_adisi@quicinc.com>
3Date: Tue, 23 Apr 2024 11:01:25 +0530
4Subject: [PATCH 003/126] hostapd_cli: MLO: pass 'LINKID' in the command
5
6MLD level socket can take 'LINKID <link id>'. Add changes to pass this via
7hostapd_cli. User needs to give "link_id=<link_id>" in post fix fashion in
8the command in order to pass this link_id from cli.
9
10For example -
11$ hostapd_cli -i wlan0 status link_id=0 | grep freq=
12freq=2437
13
14$ hostapd_cli -i wlan0
15...
16Interactive mode
17
18> ping
19PONG
20>
21> status link_id=0
22Command for 'LINKID 0'
23state=ENABLED
24phy=phy0
25freq=2437
26
27Signed-off-by: Aditya Kumar Singh <quic_adisi@quicinc.com>
28---
29 hostapd/hostapd_cli.c | 39 +++++++++++++++++++++++++++++++
30 src/common/wpa_ctrl.c | 54 +++++++++++++++++++++++++++++++++++++++++++
31 src/common/wpa_ctrl.h | 3 +++
32 3 files changed, 96 insertions(+)
33
34diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
35index f05a734fe..d69525502 100644
36--- a/hostapd/hostapd_cli.c
37+++ b/hostapd/hostapd_cli.c
38@@ -1962,6 +1962,45 @@ static void wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
39 } else if (count == 0) {
40 printf("Unknown command '%s'\n", argv[0]);
41 } else {
42+#ifdef CONFIG_IEEE80211BE
43+ char *pos, *end;
44+ int i, j, link_id;
45+ bool link_found = false;
46+
47+ wpa_ctrl_reset_mld_link(ctrl);
48+ i = 0;
49+
50+ while (i < argc) {
51+ pos = os_strstr(argv[i], "link_id=");
52+ if (!pos) {
53+ i++;
54+ continue;
55+ }
56+
57+ pos = pos + 8;
58+ link_id = strtol(pos, &end, 10);
59+
60+ if (link_id < 0 || link_id >= 15) {
61+ printf("Invalid link ID '%d'\n", link_id);
62+ return;
63+ }
64+
65+ link_found = true;
66+
67+ /* remove this link_id= from the arguements */
68+ for (j = i + 1; j < argc; j++)
69+ argv[j - 1] = argv[j];
70+
71+ argc--;
72+ i = 0;
73+ }
74+
75+ if (link_found) {
76+ wpa_ctrl_set_mld_link(ctrl, link_id);
77+ printf("Command for '%s'\n",
78+ wpa_ctrl_get_mld_link(ctrl));
79+ }
80+#endif /* CONFIG_IEEE80211BE */
81 match->handler(ctrl, argc - 1, &argv[1]);
82 }
83 }
84diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
85index 7e197f094..d0c174c05 100644
86--- a/src/common/wpa_ctrl.c
87+++ b/src/common/wpa_ctrl.c
88@@ -72,6 +72,13 @@ struct wpa_ctrl {
89 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
90 HANDLE pipe;
91 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
92+#ifdef CONFIG_IEEE80211BE
93+ /* 'LINKID ' - 7 chars including space
94+ * 'XX' - Two chars max for link id
95+ * Total required 10 chars at least
96+ */
97+ char link_id_str[10];
98+#endif /* CONFIG_IEEE80211BE */
99 };
100
101
102@@ -488,6 +495,7 @@ int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
103 fd_set rfds;
104 const char *_cmd;
105 char *cmd_buf = NULL;
106+ char *link_cmd_buf = NULL;
107 size_t _cmd_len;
108
109 #ifdef CONFIG_CTRL_IFACE_UDP
110@@ -510,6 +518,28 @@ int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
111 _cmd_len = cmd_len;
112 }
113
114+#ifdef CONFIG_IEEE80211BE
115+ if (os_strlen(ctrl->link_id_str)) {
116+ char *pos;
117+
118+ _cmd_len = _cmd_len + 1 + os_strlen(ctrl->link_id_str);
119+ link_cmd_buf = os_malloc(_cmd_len);
120+ if (link_cmd_buf == NULL) {
121+ if (cmd_buf)
122+ os_free(cmd_buf);
123+ return -1;
124+ }
125+
126+ pos = link_cmd_buf;
127+ os_strlcpy(pos, _cmd, _cmd_len);
128+ pos += os_strlen(_cmd);
129+ *pos++ = ' ';
130+ os_memcpy(pos, ctrl->link_id_str, os_strlen(ctrl->link_id_str));
131+ _cmd = link_cmd_buf;
132+ wpa_ctrl_reset_mld_link(ctrl);
133+ }
134+#endif /* CONFIG_IEEE80211BE */
135+
136 errno = 0;
137 started_at.sec = 0;
138 started_at.usec = 0;
139@@ -535,9 +565,11 @@ retry_send:
140 }
141 send_err:
142 os_free(cmd_buf);
143+ os_free(link_cmd_buf);
144 return -1;
145 }
146 os_free(cmd_buf);
147+ os_free(link_cmd_buf);
148
149 os_get_reltime(&ending_at);
150 ending_at.sec += 10;
151@@ -773,4 +805,26 @@ int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl)
152
153 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
154
155+
156+#ifdef CONFIG_IEEE80211BE
157+void wpa_ctrl_reset_mld_link(struct wpa_ctrl *ctrl)
158+{
159+ os_memset(ctrl->link_id_str, '\0', sizeof(ctrl->link_id_str));
160+}
161+
162+
163+void wpa_ctrl_set_mld_link(struct wpa_ctrl *ctrl, int link_id)
164+{
165+ os_snprintf(ctrl->link_id_str, sizeof(ctrl->link_id_str),
166+ "LINKID %d", link_id);
167+}
168+
169+
170+char *wpa_ctrl_get_mld_link(struct wpa_ctrl *ctrl)
171+{
172+ return ctrl->link_id_str;
173+}
174+#endif /* CONFIG_IEEE80211BE */
175+
176+
177 #endif /* CONFIG_CTRL_IFACE */
178diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h
179index 865ac6d91..d1ce1dd29 100644
180--- a/src/common/wpa_ctrl.h
181+++ b/src/common/wpa_ctrl.h
182@@ -676,6 +676,9 @@ char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl);
183
184 #ifdef CONFIG_IEEE80211BE
185 #define WPA_CTRL_IFACE_LINK_NAME "link"
186+void wpa_ctrl_reset_mld_link(struct wpa_ctrl *ctrl);
187+void wpa_ctrl_set_mld_link(struct wpa_ctrl *ctrl, int link_id);
188+char *wpa_ctrl_get_mld_link(struct wpa_ctrl *ctrl);
189 #endif /* CONFIG_IEEE80211BE */
190
191 #endif /* WPA_CTRL_H */
192--
1932.18.0
194