developer | bdc8eab | 2022-11-21 11:36:55 +0800 | [diff] [blame] | 1 | From 4707ed85884be2ffe7860e28de80df5a6e479824 Mon Sep 17 00:00:00 2001 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Fri, 2 Sep 2022 01:03:23 +0800 |
developer | bdc8eab | 2022-11-21 11:36:55 +0800 | [diff] [blame] | 4 | Subject: [PATCH 99914/99917] Add three wire PTA ctrl hostapd vendor command |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 7 | --- |
| 8 | hostapd/config_file.c | 4 ++++ |
| 9 | src/ap/ap_config.c | 1 + |
| 10 | src/ap/ap_config.h | 13 ++++++++++++ |
| 11 | src/ap/ap_drv_ops.c | 11 +++++++++++ |
| 12 | src/ap/ap_drv_ops.h | 1 + |
| 13 | src/ap/hostapd.c | 2 ++ |
| 14 | src/common/mtk_vendor.h | 16 +++++++++++++++ |
developer | 29344f1 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 15 | src/drivers/driver.h | 8 ++++++++ |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 16 | src/drivers/driver_nl80211.c | 33 +++++++++++++++++++++++++++++++ |
| 17 | src/drivers/driver_nl80211.h | 1 + |
| 18 | src/drivers/driver_nl80211_capa.c | 3 +++ |
developer | 29344f1 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 19 | 11 files changed, 93 insertions(+) |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 20 | |
| 21 | diff --git a/hostapd/config_file.c b/hostapd/config_file.c |
developer | bdc8eab | 2022-11-21 11:36:55 +0800 | [diff] [blame] | 22 | index b22d10b..18b372a 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 23 | --- a/hostapd/config_file.c |
| 24 | +++ b/hostapd/config_file.c |
developer | bdc8eab | 2022-11-21 11:36:55 +0800 | [diff] [blame] | 25 | @@ -4794,6 +4794,10 @@ static int hostapd_config_fill(struct hostapd_config *conf, |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 26 | return 1; |
| 27 | } |
| 28 | conf->edcca_compensation = (s8) val; |
| 29 | + } else if (os_strcmp(buf, "three_wire_enable") == 0) { |
| 30 | + u8 en = atoi(pos); |
| 31 | + |
| 32 | + conf->three_wire_enable = en; |
| 33 | } else { |
| 34 | wpa_printf(MSG_ERROR, |
| 35 | "Line %d: unknown configuration item '%s'", |
| 36 | diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 37 | index 0e1f192..9249a6b 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 38 | --- a/src/ap/ap_config.c |
| 39 | +++ b/src/ap/ap_config.c |
| 40 | @@ -297,6 +297,7 @@ struct hostapd_config * hostapd_config_defaults(void) |
| 41 | |
| 42 | conf->edcca_enable = EDCCA_MODE_AUTO; |
| 43 | conf->edcca_compensation = EDCCA_DEFAULT_COMPENSATION; |
| 44 | + conf->three_wire_enable = THREE_WIRE_MODE_DISABLE; |
| 45 | |
| 46 | return conf; |
| 47 | } |
| 48 | diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 49 | index 41b8c68..71cf515 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 50 | --- a/src/ap/ap_config.h |
| 51 | +++ b/src/ap/ap_config.h |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 52 | @@ -1157,6 +1157,19 @@ struct hostapd_config { |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 53 | u8 edcca_enable; |
| 54 | s8 edcca_compensation; |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 55 | int *edcca_threshold; |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 56 | + u8 three_wire_enable; |
| 57 | +}; |
| 58 | + |
| 59 | +enum three_wire_mode { |
| 60 | + THREE_WIRE_MODE_DISABLE, |
| 61 | + THREE_WIRE_MODE_EXT0_ENABLE, |
| 62 | + THREE_WIRE_MODE_EXT1_ENABLE, |
| 63 | + THREE_WIRE_MODE_ALL_ENABLE, |
| 64 | + |
| 65 | + /* keep last */ |
| 66 | + NUM_THREE_WIRE_MODE, |
| 67 | + THREE_WIRE_MODE_MAX = |
| 68 | + NUM_THREE_WIRE_MODE - 1 |
| 69 | }; |
| 70 | |
| 71 | enum edcca_mode { |
| 72 | diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 73 | index 4598737..a1d83e4 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 74 | --- a/src/ap/ap_drv_ops.c |
| 75 | +++ b/src/ap/ap_drv_ops.c |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 76 | @@ -1053,3 +1053,14 @@ int hostapd_drv_hemu_dump(struct hostapd_data *hapd, u8 *hemu_onoff) |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 77 | return 0; |
| 78 | return hapd->driver->hemu_dump(hapd->drv_priv, hemu_onoff); |
| 79 | } |
| 80 | + |
| 81 | +int hostapd_drv_three_wire_ctrl(struct hostapd_data *hapd) |
| 82 | +{ |
| 83 | + if (!hapd->driver || !hapd->driver->three_wire_ctrl) |
| 84 | + return 0; |
| 85 | + if (hapd->iconf->three_wire_enable > THREE_WIRE_MODE_MAX) { |
| 86 | + wpa_printf(MSG_INFO, "Invalid value for three wire enable\n"); |
| 87 | + return 0; |
| 88 | + } |
| 89 | + return hapd->driver->three_wire_ctrl(hapd->drv_priv, hapd->iconf->three_wire_enable); |
| 90 | +} |
| 91 | diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 92 | index bca39c5..5ba6297 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 93 | --- a/src/ap/ap_drv_ops.h |
| 94 | +++ b/src/ap/ap_drv_ops.h |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 95 | @@ -144,6 +144,7 @@ int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd, |
| 96 | int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value); |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 97 | int hostapd_drv_hemu_ctrl(struct hostapd_data *hapd); |
| 98 | int hostapd_drv_hemu_dump(struct hostapd_data *hapd, u8 *hemu_onoff); |
| 99 | +int hostapd_drv_three_wire_ctrl(struct hostapd_data *hapd); |
| 100 | |
| 101 | #include "drivers/driver.h" |
| 102 | |
| 103 | diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 104 | index 921769d..f9dabdf 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 105 | --- a/src/ap/hostapd.c |
| 106 | +++ b/src/ap/hostapd.c |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 107 | @@ -2303,6 +2303,8 @@ dfs_offload: |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 108 | goto fail; |
| 109 | if (hostapd_drv_hemu_ctrl(hapd) < 0) |
| 110 | goto fail; |
| 111 | + if (hostapd_drv_three_wire_ctrl(hapd) < 0) |
| 112 | + goto fail; |
| 113 | |
| 114 | wpa_printf(MSG_DEBUG, "%s: Setup of interface done.", |
| 115 | iface->bss[0]->conf->iface); |
| 116 | diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 117 | index 69a46df..ee5a4f4 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 118 | --- a/src/common/mtk_vendor.h |
| 119 | +++ b/src/common/mtk_vendor.h |
| 120 | @@ -13,6 +13,7 @@ enum mtk_nl80211_vendor_subcmds { |
| 121 | MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5, |
| 122 | MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL= 0xc6, |
| 123 | MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7, |
| 124 | + MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8 |
| 125 | }; |
| 126 | |
| 127 | enum mtk_vendor_attr_edcca_ctrl { |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 128 | @@ -55,6 +56,21 @@ static struct nla_policy edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = { |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 129 | [MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE] = { .type = NLA_U8 }, |
| 130 | }; |
| 131 | |
| 132 | +enum mtk_vendor_attr_3wire_ctrl { |
| 133 | + MTK_VENDOR_ATTR_3WIRE_CTRL_UNSPEC, |
| 134 | + |
| 135 | + MTK_VENDOR_ATTR_3WIRE_CTRL_MODE, |
| 136 | + |
| 137 | + /* keep last */ |
| 138 | + NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL, |
| 139 | + MTK_VENDOR_ATTR_3WIRE_CTRL_MAX = |
| 140 | + NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL - 1 |
| 141 | +}; |
| 142 | + |
| 143 | +static struct nla_policy three_wire_ctrl_policy[NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL] = { |
| 144 | + [MTK_VENDOR_ATTR_3WIRE_CTRL_MODE] = {.type = NLA_U8 }, |
| 145 | +}; |
| 146 | + |
| 147 | enum mtk_vendor_attr_csi_ctrl { |
| 148 | MTK_VENDOR_ATTR_CSI_CTRL_UNSPEC, |
| 149 | |
| 150 | diff --git a/src/drivers/driver.h b/src/drivers/driver.h |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 151 | index 4cd7505..9ca19af 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 152 | --- a/src/drivers/driver.h |
| 153 | +++ b/src/drivers/driver.h |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 154 | @@ -4693,6 +4693,14 @@ struct wpa_driver_ops { |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 155 | */ |
| 156 | int (*hemu_ctrl)(void *priv, u8 hemu_onoff); |
| 157 | int (*hemu_dump)(void *priv, u8 *hemu_onoff); |
developer | 29344f1 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 158 | + |
| 159 | + /** |
| 160 | + * three_wire_ctrl - set three_wire_ctrl mode |
| 161 | + * @priv: Private driver interface data |
| 162 | + * @three_wire_enable: three_wire_ctrl mode |
| 163 | + * |
| 164 | + */ |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 165 | + int (*three_wire_ctrl)(void *priv, u8 three_wire_enable); |
| 166 | }; |
| 167 | |
| 168 | /** |
| 169 | diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c |
developer | bdc8eab | 2022-11-21 11:36:55 +0800 | [diff] [blame] | 170 | index 73dee2e..2bb8cc2 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 171 | --- a/src/drivers/driver_nl80211.c |
| 172 | +++ b/src/drivers/driver_nl80211.c |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 173 | @@ -12637,6 +12637,38 @@ static int nl80211_get_edcca(void *priv, const u8 mode, u8 *value) |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | +static int nl80211_enable_three_wire(void *priv, const u8 three_wire_enable) |
| 178 | +{ |
| 179 | + struct i802_bss *bss = priv; |
| 180 | + struct wpa_driver_nl80211_data *drv = bss->drv; |
| 181 | + /* Prepare nl80211 cmd */ |
| 182 | + struct nl_msg *msg; |
| 183 | + struct nlattr *data; |
| 184 | + int ret; |
| 185 | + |
| 186 | + if (!drv->mtk_3wire_vendor_cmd_avail) { |
| 187 | + wpa_printf(MSG_INFO, |
| 188 | + "nl80211: Driver does not support setting three wire control"); |
| 189 | + return 0; |
| 190 | + } |
| 191 | + |
| 192 | + if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 193 | + nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) || |
| 194 | + nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 195 | + MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL) || |
| 196 | + !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 197 | + nla_put_u8(msg, MTK_VENDOR_ATTR_3WIRE_CTRL_MODE, three_wire_enable)) { |
| 198 | + nlmsg_free(msg); |
| 199 | + return -ENOBUFS; |
| 200 | + } |
| 201 | + nla_nest_end(msg, data); |
| 202 | + ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 203 | + if (ret) { |
| 204 | + wpa_printf(MSG_ERROR, "Failed to enable three wire. ret=%d (%s) ", |
| 205 | + ret, strerror(-ret)); |
| 206 | + } |
| 207 | + return ret; |
| 208 | +} |
| 209 | |
| 210 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 211 | .name = "nl80211", |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 212 | @@ -12789,4 +12821,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 213 | .configure_edcca_enable = nl80211_configure_edcca_enable, |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 214 | .configure_edcca_threshold = nl80211_configure_edcca_threshold, |
developer | 9bc8ec1 | 2022-11-18 16:01:14 +0800 | [diff] [blame] | 215 | .get_edcca = nl80211_get_edcca, |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 216 | + .three_wire_ctrl = nl80211_enable_three_wire, |
| 217 | }; |
| 218 | diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h |
developer | 29344f1 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 219 | index 57f0249..9fe7811 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 220 | --- a/src/drivers/driver_nl80211.h |
| 221 | +++ b/src/drivers/driver_nl80211.h |
developer | 198585d | 2022-09-22 17:12:54 +0800 | [diff] [blame] | 222 | @@ -183,6 +183,7 @@ struct wpa_driver_nl80211_data { |
| 223 | unsigned int uses_6ghz:1; |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 224 | unsigned int mtk_edcca_vendor_cmd_avail:1; |
| 225 | unsigned int mtk_hemu_vendor_cmd_avail:1; |
| 226 | + unsigned int mtk_3wire_vendor_cmd_avail:1; |
| 227 | |
| 228 | u64 vendor_scan_cookie; |
| 229 | u64 remain_on_chan_cookie; |
| 230 | diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c |
developer | 29344f1 | 2022-10-17 12:01:44 +0800 | [diff] [blame] | 231 | index cc146d9..04bc54e 100644 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 232 | --- a/src/drivers/driver_nl80211_capa.c |
| 233 | +++ b/src/drivers/driver_nl80211_capa.c |
developer | 198585d | 2022-09-22 17:12:54 +0800 | [diff] [blame] | 234 | @@ -1059,6 +1059,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 235 | case MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL : |
| 236 | drv->mtk_hemu_vendor_cmd_avail = 1; |
| 237 | break; |
| 238 | + case MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL : |
| 239 | + drv->mtk_3wire_vendor_cmd_avail = 1; |
| 240 | + break; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | -- |
developer | bdc8eab | 2022-11-21 11:36:55 +0800 | [diff] [blame] | 245 | 2.36.1 |
developer | 27b5525 | 2022-09-05 19:09:45 +0800 | [diff] [blame] | 246 | |