developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 1 | From e878e546ee5d1e86f174b2713b7a46fb05b6a7b9 Mon Sep 17 00:00:00 2001 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Wed, 2 Aug 2023 19:00:34 +0800 |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 49/54] mtk: hostapd: add zwdfs mode ctrl for eagle efem hwits |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 7 | --- |
| 8 | hostapd/config_file.c | 2 ++ |
| 9 | hostapd/ctrl_iface.c | 30 +++++++++++++++++++++++++++ |
| 10 | src/ap/ap_config.h | 6 ++++++ |
| 11 | src/ap/ap_drv_ops.c | 14 +++++++++++++ |
| 12 | src/ap/dfs.c | 6 ++++++ |
| 13 | src/common/mtk_vendor.h | 12 +++++++++++ |
| 14 | src/drivers/driver.h | 7 +++++++ |
| 15 | src/drivers/driver_nl80211.c | 34 +++++++++++++++++++++++++++++++ |
| 16 | src/drivers/driver_nl80211.h | 1 + |
| 17 | src/drivers/driver_nl80211_capa.c | 3 +++ |
| 18 | 10 files changed, 115 insertions(+) |
| 19 | |
| 20 | diff --git a/hostapd/config_file.c b/hostapd/config_file.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 21 | index 9e3dbb24a..a75199345 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 22 | --- a/hostapd/config_file.c |
| 23 | +++ b/hostapd/config_file.c |
| 24 | @@ -3183,6 +3183,8 @@ static int hostapd_config_fill(struct hostapd_config *conf, |
| 25 | conf->acs_exclude_6ghz_non_psc = atoi(pos); |
| 26 | } else if (os_strcmp(buf, "enable_background_radar") == 0) { |
| 27 | conf->enable_background_radar = atoi(pos); |
| 28 | + } else if (os_strcmp(buf, "background_radar_mode") == 0) { |
| 29 | + conf->background_radar_mode = atoi(pos); |
| 30 | } else if (os_strcmp(buf, "min_tx_power") == 0) { |
| 31 | int val = atoi(pos); |
| 32 | |
| 33 | diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 34 | index aba22e1e6..f7c7a09f3 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 35 | --- a/hostapd/ctrl_iface.c |
| 36 | +++ b/hostapd/ctrl_iface.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 37 | @@ -4221,6 +4221,33 @@ hostapd_ctrl_iface_dump_amnt(struct hostapd_data *hapd, char *cmd, |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 38 | return pos - buf; |
| 39 | } |
| 40 | |
| 41 | +static int |
| 42 | +hostapd_ctrl_iface_set_background_radar_mode(struct hostapd_data *hapd, char *cmd, |
| 43 | + char *buf, size_t buflen) |
| 44 | +{ |
| 45 | + struct hostapd_iface *iface = hapd->iface; |
| 46 | + char *pos, *param; |
| 47 | + |
| 48 | + param = os_strchr(cmd, ' '); |
| 49 | + if (!param) |
| 50 | + return -1; |
| 51 | + *param++ = '\0'; |
| 52 | + |
| 53 | + pos = os_strstr(param, "mode="); |
| 54 | + if (!pos) |
| 55 | + return -1; |
| 56 | + |
| 57 | + if (os_strncmp(pos + 5, "cert", 4) == 0) |
| 58 | + iface->conf->background_radar_mode = BACKGROUND_RADAR_CERT_MODE; |
| 59 | + else if (os_strncmp(pos + 5, "normal", 6) == 0) |
| 60 | + iface->conf->background_radar_mode = BACKGROUND_RADAR_NORMAL_MODE; |
| 61 | + |
| 62 | + if (hostapd_drv_background_radar_mode(hapd) < 0) |
| 63 | + return -1; |
| 64 | + |
| 65 | + return os_snprintf(buf, buflen, "OK\n"); |
| 66 | +} |
| 67 | + |
| 68 | static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
| 69 | char *buf, char *reply, |
| 70 | int reply_size, |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 71 | @@ -4815,6 +4842,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 72 | if (pos) |
| 73 | *pos = ' '; |
| 74 | reply_len = hostapd_ctrl_iface_set_mu(hapd, buf + 23, reply, reply_size); |
| 75 | + } else if (os_strncmp(buf, "SET_BACKGROUND_RADAR_MODE", 25) == 0) { |
| 76 | + reply_len = hostapd_ctrl_iface_set_background_radar_mode(hapd, buf + 25, |
| 77 | + reply, reply_size); |
| 78 | } else { |
| 79 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 80 | reply_len = 16; |
| 81 | diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 82 | index 7c0d12a3b..b6f05e7af 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 83 | --- a/src/ap/ap_config.h |
| 84 | +++ b/src/ap/ap_config.h |
| 85 | @@ -1025,6 +1025,7 @@ struct hostapd_config { |
| 86 | bool hw_mode_set; |
| 87 | int acs_exclude_6ghz_non_psc; |
| 88 | int enable_background_radar; |
| 89 | + int background_radar_mode; |
| 90 | enum { |
| 91 | LONG_PREAMBLE = 0, |
| 92 | SHORT_PREAMBLE = 1 |
| 93 | @@ -1218,6 +1219,11 @@ enum three_wire_mode { |
| 94 | NUM_THREE_WIRE_MODE - 1 |
| 95 | }; |
| 96 | |
| 97 | +enum background_radar_mode { |
| 98 | + BACKGROUND_RADAR_NORMAL_MODE, |
| 99 | + BACKGROUND_RADAR_CERT_MODE, |
| 100 | +}; |
| 101 | + |
| 102 | enum dfs_mode { |
| 103 | DFS_DETECT_MODE_DISABLE, |
| 104 | DFS_DETECT_MODE_AP_ENABLE, |
| 105 | diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 106 | index 721bfa053..5b93ea647 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 107 | --- a/src/ap/ap_drv_ops.c |
| 108 | +++ b/src/ap/ap_drv_ops.c |
| 109 | @@ -1257,3 +1257,17 @@ int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_ |
| 110 | return 0; |
| 111 | return hapd->driver->amnt_dump(hapd->drv_priv, amnt_idx, amnt_dump_buf); |
| 112 | } |
| 113 | + |
| 114 | +int hostapd_drv_background_radar_mode(struct hostapd_data *hapd) |
| 115 | +{ |
| 116 | + if (!hapd->driver || !hapd->driver->background_radar_mode || |
| 117 | + !(hapd->iface->drv_flags2 & WPA_DRIVER_RADAR_BACKGROUND) || |
| 118 | + !hapd->iface->conf->enable_background_radar) |
| 119 | + return 0; |
| 120 | + if (hapd->iconf->background_radar_mode > BACKGROUND_RADAR_CERT_MODE) { |
| 121 | + wpa_printf(MSG_INFO, "Invalid value for background radar mode\n"); |
| 122 | + return 0; |
| 123 | + } |
| 124 | + return hapd->driver->background_radar_mode(hapd->drv_priv, |
| 125 | + hapd->iconf->background_radar_mode); |
| 126 | +} |
| 127 | diff --git a/src/ap/dfs.c b/src/ap/dfs.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 128 | index 008596bb2..2564168bb 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 129 | --- a/src/ap/dfs.c |
| 130 | +++ b/src/ap/dfs.c |
| 131 | @@ -983,6 +983,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface) |
| 132 | if (res < 0) |
| 133 | return res; |
| 134 | |
| 135 | + if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0) |
| 136 | + return -1; |
| 137 | + |
| 138 | iface->radar_background.temp_ch = 1; |
| 139 | return 1; |
| 140 | } else if (dfs_use_radar_background(iface)) { |
| 141 | @@ -1023,6 +1026,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface) |
| 142 | iface->radar_background.secondary_channel = sec; |
| 143 | iface->radar_background.centr_freq_seg0_idx = cf1; |
| 144 | iface->radar_background.centr_freq_seg1_idx = cf2; |
| 145 | + |
| 146 | + if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0) |
| 147 | + return -1; |
| 148 | } |
| 149 | |
| 150 | return 0; |
| 151 | diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 152 | index e140de60b..5bc1e0444 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 153 | --- a/src/common/mtk_vendor.h |
| 154 | +++ b/src/common/mtk_vendor.h |
| 155 | @@ -16,6 +16,7 @@ enum mtk_nl80211_vendor_subcmds { |
| 156 | MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8, |
| 157 | MTK_NL80211_VENDOR_SUBCMD_IBF_CTRL = 0xc9, |
| 158 | MTK_NL80211_VENDOR_SUBCMD_BSS_COLOR_CTRL = 0xca, |
| 159 | + MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL = 0xcb, |
| 160 | }; |
| 161 | |
| 162 | enum mtk_vendor_attr_edcca_ctrl { |
| 163 | @@ -244,6 +245,17 @@ enum mtk_vendor_attr_bss_color_ctrl { |
| 164 | NUM_MTK_VENDOR_ATTRS_BSS_COLOR_CTRL - 1 |
| 165 | }; |
| 166 | |
| 167 | +enum mtk_vendor_attr_background_radar_ctrl { |
| 168 | + MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_UNSPEC, |
| 169 | + |
| 170 | + MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE, |
| 171 | + |
| 172 | + /* keep last */ |
| 173 | + NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL, |
| 174 | + MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MAX = |
| 175 | + NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL - 1 |
| 176 | +}; |
| 177 | + |
| 178 | #define CSI_MAX_COUNT 256 |
| 179 | #define ETH_ALEN 6 |
| 180 | |
| 181 | diff --git a/src/drivers/driver.h b/src/drivers/driver.h |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 182 | index b0a6e3514..0c1b2e452 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 183 | --- a/src/drivers/driver.h |
| 184 | +++ b/src/drivers/driver.h |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 185 | @@ -5204,6 +5204,13 @@ struct wpa_driver_ops { |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 186 | * @amnt_dump_buf: Buffer to print |
| 187 | */ |
| 188 | int (*amnt_dump)(void *priv, u8 amnt_idx, u8 *amnt_dump_buf); |
| 189 | + |
| 190 | + /** |
| 191 | + * background_radar_mode - set background radar mode |
| 192 | + * @priv: Private driver interface data |
| 193 | + * @background_radar_mode: background radar mode |
| 194 | + */ |
| 195 | + int (*background_radar_mode)(void *priv, u8 background_radar_mode); |
| 196 | }; |
| 197 | |
| 198 | /** |
| 199 | diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 200 | index b3897e61d..3cbf8610a 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 201 | --- a/src/drivers/driver_nl80211.c |
| 202 | +++ b/src/drivers/driver_nl80211.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 203 | @@ -14743,6 +14743,39 @@ fail: |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 204 | return -ENOBUFS; |
| 205 | } |
| 206 | |
| 207 | +static int nl80211_background_radar_mode(void *priv, const u8 background_radar_mode) |
| 208 | +{ |
| 209 | + struct i802_bss *bss = priv; |
| 210 | + struct wpa_driver_nl80211_data *drv = bss->drv; |
| 211 | + /* Prepare nl80211 cmd */ |
| 212 | + struct nl_msg *msg; |
| 213 | + struct nlattr *data; |
| 214 | + int ret; |
| 215 | + |
| 216 | + if (!drv->mtk_background_radar_vendor_cmd_avail) { |
| 217 | + wpa_printf(MSG_INFO, |
| 218 | + "nl80211: Driver does not support setting background radar mode"); |
| 219 | + return 0; |
| 220 | + } |
| 221 | + |
| 222 | + if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 223 | + nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) || |
| 224 | + nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 225 | + MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL) || |
| 226 | + !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 227 | + nla_put_u8(msg, MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE, background_radar_mode)) { |
| 228 | + nlmsg_free(msg); |
| 229 | + return -ENOBUFS; |
| 230 | + } |
| 231 | + nla_nest_end(msg, data); |
| 232 | + ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 233 | + if (ret) { |
| 234 | + wpa_printf(MSG_ERROR, "Failed to set background radar mode. ret=%d (%s) ", |
| 235 | + ret, strerror(-ret)); |
| 236 | + } |
| 237 | + return ret; |
| 238 | +} |
| 239 | + |
| 240 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 241 | .name = "nl80211", |
| 242 | .desc = "Linux nl80211/cfg80211", |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 243 | @@ -14915,4 +14948,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 244 | .ap_trigtype = nl80211_ap_trigtype, |
| 245 | .amnt_set = nl80211_amnt_set, |
| 246 | .amnt_dump = nl80211_amnt_dump, |
| 247 | + .background_radar_mode = nl80211_background_radar_mode, |
| 248 | }; |
| 249 | diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 250 | index 0d85adfee..74ee9b191 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 251 | --- a/src/drivers/driver_nl80211.h |
| 252 | +++ b/src/drivers/driver_nl80211.h |
| 253 | @@ -210,6 +210,7 @@ struct wpa_driver_nl80211_data { |
| 254 | unsigned int mtk_bss_color_vendor_cmd_avail:1; |
| 255 | unsigned int mtk_rfeatures_vendor_cmd_avail:1; |
| 256 | unsigned int mtk_amnt_vendor_cmd_avail:1; |
| 257 | + unsigned int mtk_background_radar_vendor_cmd_avail:1; |
| 258 | |
| 259 | u64 vendor_scan_cookie; |
| 260 | u64 remain_on_chan_cookie; |
| 261 | diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 262 | index 4bd15f348..74c3e0d86 100644 |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 263 | --- a/src/drivers/driver_nl80211_capa.c |
| 264 | +++ b/src/drivers/driver_nl80211_capa.c |
developer | d243af0 | 2023-12-21 14:49:33 +0800 | [diff] [blame^] | 265 | @@ -1137,6 +1137,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 266 | case MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL: |
| 267 | drv->mtk_rfeatures_vendor_cmd_avail = 1; |
| 268 | break; |
| 269 | + case MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL: |
| 270 | + drv->mtk_background_radar_vendor_cmd_avail = 1; |
| 271 | + break; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | -- |
| 276 | 2.18.0 |
| 277 | |