blob: 40dded6c692be0914485e00989be1bff8cde1d96 [file] [log] [blame]
developer6a1998b2022-12-08 18:09:45 +08001From cef7f515eafeeaa99933cc9e66c79b705e3ab065 Mon Sep 17 00:00:00 2001
2From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Mon, 30 May 2022 16:31:34 +0800
4Subject: [PATCH 99904/99909] hostapd: mtk: Support EDCCA hostapd configuration
5
6edcca_enable and edcca_compensation and implement edcca related handlers.
7---
8 hostapd/config_file.c | 32 ++++++
9 hostapd/ctrl_iface.c | 125 ++++++++++++++++++++++
10 src/ap/ap_config.c | 4 +
11 src/ap/ap_config.h | 29 ++++++
12 src/ap/ap_drv_ops.c | 24 +++++
13 src/ap/ap_drv_ops.h | 5 +-
14 src/ap/hostapd.c | 7 ++
15 src/common/mtk_vendor.h | 19 ++--
16 src/drivers/driver.h | 4 +
17 src/drivers/driver_nl80211.c | 165 ++++++++++++++++++++++++++++++
18 src/drivers/driver_nl80211.h | 1 +
19 src/drivers/driver_nl80211_capa.c | 7 ++
20 12 files changed, 415 insertions(+), 7 deletions(-)
21
22diff --git a/hostapd/config_file.c b/hostapd/config_file.c
23index eda9db0..0ee8952 100644
24--- a/hostapd/config_file.c
25+++ b/hostapd/config_file.c
26@@ -4753,6 +4753,38 @@ static int hostapd_config_fill(struct hostapd_config *conf,
27 } else if (os_strcmp(buf, "eht_mu_beamformer") == 0) {
28 conf->eht_phy_capab.mu_beamformer = atoi(pos);
29 #endif /* CONFIG_IEEE80211BE */
30+ } else if (os_strcmp(buf, "edcca_threshold") == 0) {
31+ if (hostapd_parse_intlist(&conf->edcca_threshold, pos) ||
32+ conf->edcca_threshold[0] < EDCCA_MIN_CONFIG_THRES ||
33+ conf->edcca_threshold[0] > EDCCA_MAX_CONFIG_THRES ||
34+ conf->edcca_threshold[1] < EDCCA_MIN_CONFIG_THRES ||
35+ conf->edcca_threshold[1] > EDCCA_MAX_CONFIG_THRES ||
36+ conf->edcca_threshold[2] < EDCCA_MIN_CONFIG_THRES ||
37+ conf->edcca_threshold[2] > EDCCA_MAX_CONFIG_THRES) {
38+ wpa_printf(MSG_ERROR, "Line %d: invalid edcca threshold",
39+ line);
40+ return 1;
41+ }
42+ } else if (os_strcmp(buf, "edcca_enable") == 0) {
43+ int mode = atoi(pos);
44+ if (mode < EDCCA_MODE_FORCE_DISABLE || mode > EDCCA_MODE_AUTO) {
45+ wpa_printf(MSG_ERROR, "Line %d: Invalid edcca_enable %d;"
46+ " allowed value 0 (Force Disable) or 1(Auto) ",
47+ line, mode);
48+ return 1;
49+ }
50+ conf->edcca_enable = (u8) mode;
51+ } else if (os_strcmp(buf, "edcca_compensation") == 0) {
52+ int val = atoi(pos);
53+ if (val < EDCCA_MIN_COMPENSATION ||
54+ val > EDCCA_MAX_COMPENSATION) {
55+ wpa_printf(MSG_ERROR, "Line %d: Invalid compensation"
56+ " value %d; allowed value %d ~ %d.",
57+ line, val, EDCCA_MIN_COMPENSATION,
58+ EDCCA_MAX_COMPENSATION);
59+ return 1;
60+ }
61+ conf->edcca_compensation = (s8) val;
62 } else {
63 wpa_printf(MSG_ERROR,
64 "Line %d: unknown configuration item '%s'",
65diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
66index bb8c74f..9c70d54 100644
67--- a/hostapd/ctrl_iface.c
68+++ b/hostapd/ctrl_iface.c
69@@ -598,6 +598,19 @@ static const char * pbc_status_str(enum pbc_status status)
70 }
71
72
73+static const char * edcca_mode_str(enum edcca_mode status)
74+{
75+ switch (status) {
76+ case EDCCA_MODE_FORCE_DISABLE:
77+ return "Force Disable";
78+ case EDCCA_MODE_AUTO:
79+ return "Auto";
80+ default:
81+ return "Unknown";
82+ }
83+}
84+
85+
86 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
87 char *buf, size_t buflen)
88 {
89@@ -3322,6 +3335,112 @@ static int hostapd_ctrl_iface_driver_cmd(struct hostapd_data *hapd, char *cmd,
90 #endif /* ANDROID */
91
92
93+static int
94+hostapd_ctrl_iface_set_edcca(struct hostapd_data *hapd, char *cmd,
95+ char *buf, size_t buflen)
96+{
97+ char *pos, *config, *value;
98+ config = cmd;
99+ pos = os_strchr(config, ' ');
100+ if (pos == NULL)
101+ return -1;
102+ *pos++ = '\0';
103+
104+ if(pos == NULL)
105+ return -1;
106+ value = pos;
107+
108+ if (os_strcmp(config, "enable") == 0) {
109+ int mode = atoi(value);
110+ if (mode < EDCCA_MODE_FORCE_DISABLE || mode > EDCCA_MODE_AUTO) {
111+ wpa_printf(MSG_ERROR, "Invalid value for edcca enable");
112+ return -1;
113+ }
114+ hapd->iconf->edcca_enable = (u8) mode;
115+ if (hostapd_drv_configure_edcca_enable(hapd) != 0)
116+ return -1;
117+ } else if (os_strcmp(config, "compensation") == 0) {
118+ int compensation = atoi(value);
119+ if (compensation < EDCCA_MIN_COMPENSATION ||
120+ compensation > EDCCA_MAX_COMPENSATION) {
121+ wpa_printf(MSG_ERROR, "Invalid value for edcca compensation");
122+ return -1;
123+ }
124+ hapd->iconf->edcca_compensation = (s8) compensation;
125+ if (hostapd_drv_configure_edcca_enable(hapd) != 0)
126+ return -1;
127+ } else if (os_strcmp(config, "threshold") == 0) {
128+ char *thres_value;
129+ thres_value = os_strchr(value, ':');
130+ if (thres_value == NULL)
131+ return -1;
132+ *thres_value++ = '\0';
133+
134+ if(thres_value == NULL)
135+ return -1;
136+ int bw_idx= atoi(value);
137+ int threshold = atoi(thres_value);
138+
139+ if (bw_idx < EDCCA_BW_20 || bw_idx > EDCCA_BW_80) {
140+ wpa_printf(MSG_ERROR,
141+ "Unsupported Bandwidth idx %d for SET_EDCCA",
142+ bw_idx);
143+ return -1;
144+ }
145+ if (threshold < EDCCA_MIN_CONFIG_THRES ||
146+ threshold > EDCCA_MAX_CONFIG_THRES) {
147+ wpa_printf(MSG_ERROR,
148+ "Unsupported threshold %d for SET_EDCCA",
149+ threshold);
150+ return -1;
151+ }
152+
153+ int threshold_arr[EDCCA_MAX_BW_NUM];
154+ /* 0x7f means keep the origival value in firmware */
155+ os_memset(threshold_arr, 0x7f, sizeof(threshold_arr));
156+ threshold_arr[bw_idx] = threshold;
157+
158+ if (hostapd_drv_configure_edcca_threshold(hapd, threshold_arr) != 0)
159+ return -1;
160+ } else {
161+ wpa_printf(MSG_ERROR,
162+ "Unsupported parameter %s for SET_EDCCA", config);
163+ return -1;
164+ }
165+ return os_snprintf(buf, buflen, "OK\n");
166+}
167+
168+
169+static int
170+hostapd_ctrl_iface_get_edcca(struct hostapd_data *hapd, char *cmd, char *buf,
171+ size_t buflen)
172+{
173+ char *pos, *end;
174+
175+ pos = buf;
176+ end = buf + buflen;
177+ u8 value[EDCCA_MAX_BW_NUM] = {0};
178+
179+ if (os_strcmp(cmd, "enable") == 0) {
180+ return os_snprintf(pos, end - pos, "Enable: %s\n",
181+ edcca_mode_str(hapd->iconf->edcca_enable));
182+ } else if (os_strcmp(cmd, "compensation") == 0) {
183+ return os_snprintf(pos, end - pos, "Compensation: %d\n",
184+ hapd->iconf->edcca_compensation);
185+ } else if (os_strcmp(cmd, "threshold") == 0) {
186+ if (hostapd_drv_get_edcca(hapd, EDCCA_CTRL_GET_THRES, &value) != 0)
187+ return -1;
188+ return os_snprintf(pos, end - pos,
189+ "Threshold BW20: 0x%x, BW40: 0x%x, BW80: 0x%x\n",
190+ value[0], value[1], value[2]);
191+ } else {
192+ wpa_printf(MSG_ERROR,
193+ "Unsupported parameter %s for GET_EDCCA", cmd);
194+ return -1;
195+ }
196+}
197+
198+
199 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
200 char *buf, char *reply,
201 int reply_size,
202@@ -3868,6 +3987,12 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
203 reply_len = hostapd_ctrl_iface_driver_cmd(hapd, buf + 7, reply,
204 reply_size);
205 #endif /* ANDROID */
206+ } else if (os_strncmp(buf, "SET_EDCCA ", 10) == 0) {
207+ reply_len = hostapd_ctrl_iface_set_edcca(hapd, buf+10, reply,
208+ reply_size);
209+ } else if (os_strncmp(buf, "GET_EDCCA ", 10) == 0) {
210+ reply_len = hostapd_ctrl_iface_get_edcca(hapd, buf+10, reply,
211+ reply_size);
212 } else {
213 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
214 reply_len = 16;
215diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
216index 4a20eb4..344585a 100644
217--- a/src/ap/ap_config.c
218+++ b/src/ap/ap_config.c
219@@ -294,6 +294,9 @@ struct hostapd_config * hostapd_config_defaults(void)
220 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
221 #endif /* CONFIG_AIRTIME_POLICY */
222
223+ conf->edcca_enable = EDCCA_MODE_AUTO;
224+ conf->edcca_compensation = EDCCA_DEFAULT_COMPENSATION;
225+
226 return conf;
227 }
228
229@@ -1007,6 +1010,7 @@ void hostapd_config_free(struct hostapd_config *conf)
230 #ifdef CONFIG_ACS
231 os_free(conf->acs_chan_bias);
232 #endif /* CONFIG_ACS */
233+ os_free(conf->edcca_threshold);
234 wpabuf_free(conf->lci);
235 wpabuf_free(conf->civic);
236
237diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
238index 3f68e76..775c567 100644
239--- a/src/ap/ap_config.h
240+++ b/src/ap/ap_config.h
241@@ -1153,8 +1153,37 @@ struct hostapd_config {
242 #define CH_SWITCH_EHT_ENABLED BIT(0)
243 #define CH_SWITCH_EHT_DISABLED BIT(1)
244 unsigned int ch_switch_eht_config;
245+ u8 edcca_enable;
246+ s8 edcca_compensation;
247+ int *edcca_threshold;
248 };
249
250+enum edcca_mode {
251+ EDCCA_MODE_FORCE_DISABLE = 0,
252+ EDCCA_MODE_AUTO = 1,
253+};
254+
255+enum edcca_bw_id {
256+ EDCCA_BW_20 = 0,
257+ EDCCA_BW_40,
258+ EDCCA_BW_80,
259+ EDCCA_MAX_BW_NUM,
260+};
261+
262+enum mtk_vendor_attr_edcca_ctrl_mode {
263+ EDCCA_CTRL_SET_EN = 0,
264+ EDCCA_CTRL_SET_THRES,
265+ EDCCA_CTRL_GET_EN,
266+ EDCCA_CTRL_GET_THRES,
267+ EDCCA_CTRL_NUM,
268+};
269+
270+#define EDCCA_DEFAULT_COMPENSATION -6
271+#define EDCCA_MIN_COMPENSATION -126
272+#define EDCCA_MAX_COMPENSATION 126
273+#define EDCCA_MIN_CONFIG_THRES -126
274+#define EDCCA_MAX_CONFIG_THRES 0
275+
276
277 static inline enum oper_chan_width
278 hostapd_get_oper_chwidth(struct hostapd_config *conf)
279diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
280index 0c7aee2..25e967d 100644
281--- a/src/ap/ap_drv_ops.c
282+++ b/src/ap/ap_drv_ops.c
283@@ -1015,3 +1015,27 @@ int hostapd_drv_dpp_listen(struct hostapd_data *hapd, bool enable)
284 return 0;
285 return hapd->driver->dpp_listen(hapd->drv_priv, enable);
286 }
287+
288+int hostapd_drv_configure_edcca_enable(struct hostapd_data *hapd)
289+{
290+ if (!hapd->driver || !hapd->driver->configure_edcca_enable)
291+ return 0;
292+ return hapd->driver->configure_edcca_enable(hapd->drv_priv,
293+ hapd->iconf->edcca_enable,
294+ hapd->iconf->edcca_compensation);
295+}
296+
297+int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd,
298+ const int *threshold)
299+{
300+ if (!hapd->driver || !hapd->driver->configure_edcca_threshold)
301+ return 0;
302+ return hapd->driver->configure_edcca_threshold(hapd->drv_priv, threshold);
303+}
304+
305+int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value)
306+{
307+ if (!hapd->driver || !hapd->driver->get_edcca)
308+ return 0;
309+ return hapd->driver->get_edcca(hapd->drv_priv, mode, value);
310+}
311diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h
312index b4fb766..70a99f4 100644
313--- a/src/ap/ap_drv_ops.h
314+++ b/src/ap/ap_drv_ops.h
315@@ -138,7 +138,10 @@ int hostapd_drv_do_acs(struct hostapd_data *hapd);
316 int hostapd_drv_update_dh_ie(struct hostapd_data *hapd, const u8 *peer,
317 u16 reason_code, const u8 *ie, size_t ielen);
318 int hostapd_drv_dpp_listen(struct hostapd_data *hapd, bool enable);
319-
320+int hostapd_drv_configure_edcca_enable(struct hostapd_data *hapd);
321+int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd,
322+ const int *threshold);
323+int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value);
324
325 #include "drivers/driver.h"
326
327diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
328index 0dd8c13..d05f948 100644
329--- a/src/ap/hostapd.c
330+++ b/src/ap/hostapd.c
331@@ -2295,6 +2295,13 @@ dfs_offload:
332 }
333 #endif /* CONFIG_MESH */
334
335+ if (hostapd_drv_configure_edcca_enable(hapd) < 0)
336+ goto fail;
337+
338+ if (hostapd_drv_configure_edcca_threshold(hapd,
339+ hapd->iconf->edcca_threshold) < 0)
340+ goto fail;
341+
342 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
343 iface->bss[0]->conf->iface);
344 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
345diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
346index 528387f..7056126 100644
347--- a/src/common/mtk_vendor.h
348+++ b/src/common/mtk_vendor.h
349@@ -29,14 +29,21 @@ enum mtk_vendor_attr_edcca_ctrl {
350 NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL - 1
351 };
352
353-enum mtk_vendor_attr_edcca_ctrl_mode {
354- EDCCA_CTRL_SET_EN = 0,
355- EDCCA_CTRL_SET_THERS,
356- EDCCA_CTRL_GET_EN,
357- EDCCA_CTRL_GET_THERS,
358- EDCCA_CTRL_NUM,
359+enum mtk_vendor_attr_edcca_dump {
360+ MTK_VENDOR_ATTR_EDCCA_DUMP_UNSPEC = 0,
361+
362+ MTK_VENDOR_ATTR_EDCCA_DUMP_MODE,
363+ MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL,
364+ MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL,
365+ MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL,
366+
367+ /* keep last */
368+ NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP,
369+ MTK_VENDOR_ATTR_EDCCA_DUMP_MAX =
370+ NUM_MTK_VENDOR_ATTRS_EDCCA_DUMP - 1
371 };
372
373+
374 static struct nla_policy edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = {
375 [MTK_VENDOR_ATTR_EDCCA_CTRL_MODE] = { .type = NLA_U8 },
376 [MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL] = { .type = NLA_U8 },
377diff --git a/src/drivers/driver.h b/src/drivers/driver.h
378index 1d2b1b2..3559974 100644
379--- a/src/drivers/driver.h
380+++ b/src/drivers/driver.h
381@@ -4676,6 +4676,10 @@ struct wpa_driver_ops {
382 const u8 *match, size_t match_len,
383 bool multicast);
384 #endif /* CONFIG_TESTING_OPTIONS */
385+ int (*configure_edcca_enable)(void *priv, const u8 edcca_enable,
386+ const s8 edcca_compensation);
387+ int (*configure_edcca_threshold)(void *priv, const int *threshold);
388+ int (*get_edcca)(void *priv, const u8 mode, u8 *value);
389 };
390
391 /**
392diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
393index 5eba0ea..9c2782c 100644
394--- a/src/drivers/driver_nl80211.c
395+++ b/src/drivers/driver_nl80211.c
396@@ -35,6 +35,8 @@
397 #include "radiotap_iter.h"
398 #include "rfkill.h"
399 #include "driver_nl80211.h"
400+#include "common/mtk_vendor.h"
401+#include "ap/ap_config.h"
402
403
404 #ifndef NETLINK_CAP_ACK
405@@ -12368,6 +12370,165 @@ static int testing_nl80211_radio_disable(void *priv, int disabled)
406
407 #endif /* CONFIG_TESTING_OPTIONS */
408
409+static int nl80211_configure_edcca_enable(void *priv,
410+ const u8 edcca_enable,
411+ const s8 edcca_compensation)
412+{
413+ struct i802_bss *bss = priv;
414+ struct wpa_driver_nl80211_data *drv = bss->drv;
415+ struct nl_msg *msg;
416+ struct nlattr *data;
417+ int ret;
418+
419+ if (!drv->mtk_edcca_vendor_cmd_avail) {
420+ wpa_printf(MSG_INFO,
421+ "nl80211: Driver does not support setting EDCCA enable");
422+ return 0;
423+ }
424+
425+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
426+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
427+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
428+ MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL) ||
429+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
430+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_MODE, EDCCA_CTRL_SET_EN) ||
431+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL, edcca_enable) ||
432+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE,
433+ edcca_compensation)) {
434+ wpa_printf (MSG_ERROR, "Prepare nl80211 msg fail");
435+ nlmsg_free(msg);
436+ return -ENOBUFS;
437+ }
438+ nla_nest_end(msg, data);
439+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
440+ if (ret) {
441+ wpa_printf(MSG_ERROR, "Failed to configure EDCCA enable. ret=%d (%s) ",
442+ ret, strerror(-ret));
443+ }
444+ return ret;
445+}
446+
447+static int nl80211_configure_edcca_threshold(void *priv, const int *threshold)
448+{
449+ struct i802_bss *bss = priv;
450+ struct wpa_driver_nl80211_data *drv = bss->drv;
451+ struct nl_msg *msg;
452+ struct nlattr *data;
453+ int ret;
454+
455+ if (!drv->mtk_edcca_vendor_cmd_avail) {
456+ wpa_printf(MSG_INFO,
457+ "nl80211: Driver does not support setting EDCCA threshold");
458+ return 0;
459+ }
460+
461+ if (!threshold) {
462+ wpa_printf(MSG_INFO,
463+ "nl80211: Input EDCCA threshold is empty!");
464+ return 0;
465+ }
466+
467+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
468+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
469+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
470+ MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL) ||
471+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
472+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_MODE, EDCCA_CTRL_SET_THRES) ||
473+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_PRI20_VAL, threshold[0] & 0xff) ||
474+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_SEC40_VAL, threshold[1] & 0xff) ||
475+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_SEC80_VAL, threshold[2] & 0xff)) {
476+ wpa_printf (MSG_ERROR, "Prepare nl80211 msg fail");
477+ nlmsg_free(msg);
478+ return -ENOBUFS;
479+ }
480+ nla_nest_end(msg, data);
481+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
482+ if (ret) {
483+ wpa_printf(MSG_ERROR, "Failed to configure EDCCA threshold. ret=%d (%s) ",
484+ ret, strerror(-ret));
485+ }
486+ return ret;
487+}
488+
489+
490+static int edcca_info_handler(struct nl_msg *msg, void *arg)
491+{
492+ u8 *info = (u8*) arg;
493+ struct nlattr *tb[NL80211_ATTR_MAX + 1];
494+ struct nlattr *tb_vendor[MTK_VENDOR_ATTR_EDCCA_DUMP_MAX + 1];
495+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
496+ struct nlattr *nl_vend, *attr;
497+
498+ nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
499+ genlmsg_attrlen(gnlh, 0), NULL);
500+
501+ nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
502+ if (!nl_vend)
503+ return NL_SKIP;
504+
505+ nla_parse(tb_vendor, MTK_VENDOR_ATTR_EDCCA_DUMP_MAX,
506+ nla_data(nl_vend), nla_len(nl_vend), NULL);
507+
508+ attr = tb_vendor[MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL];
509+ if (!attr) {
510+ wpa_printf(MSG_ERROR, "nl80211: MTK_VENDOR_ATTR_EDCCA_DUMP_PRI20_VAL");
511+ return NL_SKIP;
512+ }
513+
514+ *info++ = nla_get_u8(attr);
515+
516+ attr = tb_vendor[MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL];
517+ if (!attr) {
518+ wpa_printf(MSG_ERROR, "nl80211: MTK_VENDOR_ATTR_EDCCA_DUMP_SEC40_VAL");
519+ return NL_SKIP;
520+ }
521+
522+ *info++ = nla_get_u8(attr);
523+
524+ attr = tb_vendor[MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL];
525+ if (!attr) {
526+ wpa_printf(MSG_ERROR, "nl80211: MTK_VENDOR_ATTR_EDCCA_DUMP_SEC80_VAL");
527+ return NL_SKIP;
528+ }
529+
530+ *info = nla_get_u8(attr);
531+ return NL_SKIP;
532+}
533+
534+
535+static int nl80211_get_edcca(void *priv, const u8 mode, u8 *value)
536+{
537+ struct i802_bss *bss = priv;
538+ struct wpa_driver_nl80211_data *drv = bss->drv;
539+ struct nl_msg *msg;
540+ struct nlattr *data;
541+ int ret;
542+
543+ if (!drv->mtk_edcca_vendor_cmd_avail) {
544+ wpa_printf(MSG_INFO,
545+ "nl80211: Driver does not support setting EDCCA threshold");
546+ return 0;
547+ }
548+
549+ if (!(msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_VENDOR)) ||
550+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
551+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
552+ MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL) ||
553+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED)) ||
554+ nla_put_u8(msg, MTK_VENDOR_ATTR_EDCCA_CTRL_MODE, mode)) {
555+ wpa_printf (MSG_ERROR, "Prepare nl80211 msg fail");
556+ nlmsg_free(msg);
557+ return -ENOBUFS;
558+ }
559+ nla_nest_end(msg, data);
560+ ret = send_and_recv_msgs(drv, msg, edcca_info_handler, value, NULL, NULL);
561+ if (ret) {
562+ wpa_printf(MSG_ERROR, "Failed to get EDCCA configuration. ret=%d (%s)",
563+ ret, strerror(-ret));
564+ }
565+ return ret;
566+}
567+
568
569 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
570 .name = "nl80211",
571@@ -12514,4 +12675,8 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
572 .register_frame = testing_nl80211_register_frame,
573 .radio_disable = testing_nl80211_radio_disable,
574 #endif /* CONFIG_TESTING_OPTIONS */
575+/* Need ifdef CONFIG_DRIVER_NL80211_MTK */
576+ .configure_edcca_enable = nl80211_configure_edcca_enable,
577+ .configure_edcca_threshold = nl80211_configure_edcca_threshold,
578+ .get_edcca = nl80211_get_edcca,
579 };
580diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
581index 6e40d55..13e5d24 100644
582--- a/src/drivers/driver_nl80211.h
583+++ b/src/drivers/driver_nl80211.h
584@@ -181,6 +181,7 @@ struct wpa_driver_nl80211_data {
585 unsigned int qca_do_acs:1;
586 unsigned int brcm_do_acs:1;
587 unsigned int uses_6ghz:1;
588+ unsigned int mtk_edcca_vendor_cmd_avail:1;
589
590 u64 vendor_scan_cookie;
591 u64 remain_on_chan_cookie;
592diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
593index 7ede0d0..732ae29 100644
594--- a/src/drivers/driver_nl80211_capa.c
595+++ b/src/drivers/driver_nl80211_capa.c
596@@ -18,6 +18,7 @@
597 #include "common/qca-vendor-attr.h"
598 #include "common/brcm_vendor.h"
599 #include "driver_nl80211.h"
600+#include "common/mtk_vendor.h"
601
602
603 static int protocol_feature_handler(struct nl_msg *msg, void *arg)
604@@ -1050,6 +1051,12 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
605 break;
606 }
607 #endif /* CONFIG_DRIVER_NL80211_BRCM */
608+ } else if (vinfo->vendor_id == OUI_MTK) {
609+ switch (vinfo->subcmd) {
610+ case MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL :
611+ drv->mtk_edcca_vendor_cmd_avail = 1;
612+ break;
613+ }
614 }
615
616 wpa_printf(MSG_DEBUG, "nl80211: Supported vendor command: vendor_id=0x%x subcmd=%u",
617--
6182.36.1
619