blob: 7f94fa3708fe7a83e2655d6d0123ec3d35b1251b [file] [log] [blame]
developer91fc9452022-06-28 11:24:56 +08001From a00f78d06067b5c139c043c9acf359810e963108 Mon Sep 17 00:00:00 2001
2From: Howard Hsu <howard-yh.hsu@mediatek.com>
3Date: Fri, 24 Jun 2022 22:32:40 +0800
4Subject: [PATCH 916/917] Add hostapd command handler for SET_EDCCA, GET_EDCCA
5 and APPLY_EDCCA
6
7---
8 hostapd/ctrl_iface.c | 99 ++++++++++++++++++++++++++++++++++++++++++++
9 1 file changed, 99 insertions(+)
10
11diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
12index b997ed8..5e9af7f 100644
13--- a/hostapd/ctrl_iface.c
14+++ b/hostapd/ctrl_iface.c
15@@ -598,6 +598,19 @@ static const char * pbc_status_str(enum pbc_status status)
16 }
17
18
19+static const char * edcca_mode_str(enum edcca_mode status)
20+{
21+ switch (status) {
22+ case EDCCA_MODE_FORCE_DISABLE:
23+ return "Force Disable";
24+ case EDCCA_MODE_AUTO:
25+ return "Auto";
26+ default:
27+ return "Unknown";
28+ }
29+}
30+
31+
32 static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
33 char *buf, size_t buflen)
34 {
35@@ -3307,6 +3320,85 @@ static int hostapd_ctrl_iface_driver_cmd(struct hostapd_data *hapd, char *cmd,
36 #endif /* ANDROID */
37
38
39+static int
40+hostapd_ctrl_iface_set_edcca(struct hostapd_data *hapd, char *cmd,
41+ char *buf, size_t buflen)
42+{
43+ char *pos, *config, *value;
44+ config = cmd;
45+ pos = os_strchr(config, ' ');
46+ if (pos == NULL)
47+ return -1;
48+ *pos++ = '\0';
49+
50+ if(pos == NULL)
51+ return -1;
52+ value = pos;
53+
54+ if (os_strcmp(config, "enable") == 0) {
55+ int mode = atoi(value);
56+ if (mode < EDCCA_MODE_FORCE_DISABLE || mode > EDCCA_MODE_AUTO) {
57+ wpa_printf(MSG_ERROR, "Invalid value for edcca enable");
58+ return -1;
59+ }
60+ hapd->iconf->edcca_enable = (u8) mode;
61+ } else if (os_strcmp(config, "compensation") == 0) {
62+ int compensation = atoi(value);
63+ if (compensation < EDCCA_MIN_COMPENSATION ||
64+ compensation > EDCCA_MAX_COMPENSATION) {
65+ wpa_printf(MSG_ERROR, "Invalid value for edcca compensation");
66+ return -1;
67+ }
68+ hapd->iconf->edcca_compensation = (s8) compensation;
69+ } else {
70+ wpa_printf(MSG_ERROR,
71+ "Unsupported parameter %s for SET_EDCCA", config);
72+ return -1;
73+ }
74+ return os_snprintf(buf, buflen, "OK\n");
75+}
76+
77+
78+static int
79+hostapd_ctrl_iface_get_edcca(struct hostapd_data *hapd, char *buf,
80+ size_t buflen)
81+{
82+ int ret;
83+ char *pos, *end;
84+
85+ pos = buf;
86+ end = buf + buflen;
87+
88+ ret = os_snprintf(pos, end - pos, "EDCCA Mode: %s\n",
89+ edcca_mode_str(hapd->iconf->edcca_enable));
90+
91+ if (os_snprintf_error(end - pos, ret))
92+ return pos - buf;
93+ pos += ret;
94+
95+ ret = os_snprintf(pos, end - pos, "EDCCA compensation %d\n",
96+ hapd->iconf->edcca_compensation);
97+
98+ if (os_snprintf_error(end - pos, ret))
99+ return pos - buf;
100+ pos += ret;
101+
102+ return pos - buf;
103+}
104+
105+
106+static int
107+hostapd_ctrl_iface_apply_edcca(struct hostapd_data *hapd, char *buf,
108+ size_t buflen)
109+{
110+ if(hostapd_drv_configure_edcca_threshold(hapd) == 0) {
111+ return os_snprintf(buf, buflen, "OK\n");
112+ } else {
113+ return -1;
114+ }
115+}
116+
117+
118 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
119 char *buf, char *reply,
120 int reply_size,
121@@ -3840,6 +3932,13 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
122 reply_len = hostapd_ctrl_iface_driver_cmd(hapd, buf + 7, reply,
123 reply_size);
124 #endif /* ANDROID */
125+ } else if (os_strncmp(buf, "SET_EDCCA ", 10) == 0) {
126+ reply_len = hostapd_ctrl_iface_set_edcca(hapd, buf+10, reply,
127+ reply_size);
128+ } else if (os_strncmp(buf, "GET_EDCCA", 9) == 0) {
129+ reply_len = hostapd_ctrl_iface_get_edcca(hapd, reply, reply_size);
130+ } else if (os_strncmp(buf, "APPLY_EDCCA", 11) == 0) {
131+ reply_len = hostapd_ctrl_iface_apply_edcca(hapd, reply, reply_size);
132 } else {
133 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
134 reply_len = 16;
135--
1362.18.0
137