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