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