developer | 2fd555a | 2023-07-25 05:48:15 +0800 | [diff] [blame^] | 1 | From 2e7059246e059c0ed4cb53906467d4f55df3b664 Mon Sep 17 00:00:00 2001 |
developer | ae4d449 | 2023-04-03 16:43:49 +0800 | [diff] [blame] | 2 | From: mtk23888 <dipanshu.mittal@mediatek.com> |
| 3 | Date: Tue, 4 Apr 2023 13:06:41 +0800 |
developer | 2fd555a | 2023-07-25 05:48:15 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 27/35] hostapd: mtk: Air Monitor support in hostapd by vendor |
developer | 00c6c7a | 2023-04-29 06:26:42 +0800 | [diff] [blame] | 5 | NL |
developer | ae4d449 | 2023-04-03 16:43:49 +0800 | [diff] [blame] | 6 | |
| 7 | Signed-off-by: mtk23888 <dipanshu.mittal@mediatek.com> |
| 8 | --- |
| 9 | hostapd/ctrl_iface.c | 113 +++++++++++++++++++ |
| 10 | hostapd/hostapd_cli.c | 15 +++ |
| 11 | src/ap/ap_drv_ops.c | 14 +++ |
| 12 | src/ap/ap_drv_ops.h | 3 + |
| 13 | src/common/mtk_vendor.h | 8 ++ |
| 14 | src/drivers/driver.h | 16 +++ |
| 15 | src/drivers/driver_nl80211.c | 180 ++++++++++++++++++++++++++++++ |
| 16 | src/drivers/driver_nl80211.h | 1 + |
| 17 | src/drivers/driver_nl80211_capa.c | 2 + |
| 18 | 9 files changed, 352 insertions(+) |
| 19 | |
| 20 | diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c |
developer | 2fd555a | 2023-07-25 05:48:15 +0800 | [diff] [blame^] | 21 | index f338d0f..7f91cb6 100644 |
developer | ae4d449 | 2023-04-03 16:43:49 +0800 | [diff] [blame] | 22 | --- a/hostapd/ctrl_iface.c |
| 23 | +++ b/hostapd/ctrl_iface.c |
developer | 2fd555a | 2023-07-25 05:48:15 +0800 | [diff] [blame^] | 24 | @@ -3765,6 +3765,44 @@ hostapd_ctrl_iface_ap_wireless(struct hostapd_data *hapd, char *cmd, |
developer | ae4d449 | 2023-04-03 16:43:49 +0800 | [diff] [blame] | 25 | |
| 26 | if (hostapd_drv_ap_wireless(hapd, (u8) sub_cmd, atoi(value)) != 0) |
| 27 | return -1; |
| 28 | + return os_snprintf(buf, buflen, "OK\n"); |
| 29 | +} |
| 30 | + |
| 31 | +static int |
| 32 | +hostapd_ctrl_iface_set_amnt(struct hostapd_data *hapd, char *cmd, |
| 33 | + char *buf, size_t buflen) |
| 34 | +{ |
| 35 | + char *tmp, sta_mac[ETH_ALEN] = {0}; |
| 36 | + int amnt_idx = 0; |
| 37 | + |
| 38 | + tmp = strtok_r(cmd, " ", &cmd); |
| 39 | + |
| 40 | + if (!tmp) { |
| 41 | + wpa_printf(MSG_ERROR, "Error in command format\n"); |
| 42 | + return -1; |
| 43 | + } |
| 44 | + |
| 45 | + amnt_idx = strtol(tmp, &tmp, 10); |
| 46 | + |
| 47 | + if (amnt_idx < 0 || amnt_idx > 15) { |
| 48 | + wpa_printf(MSG_ERROR, "Wrong AMNT index %d\n", amnt_idx); |
| 49 | + return -1; |
| 50 | + } |
| 51 | + |
| 52 | + if (!cmd) { |
| 53 | + wpa_printf(MSG_ERROR, "Error in command format\n"); |
| 54 | + return -1; |
| 55 | + } |
| 56 | + |
| 57 | + if (hwaddr_aton(cmd, sta_mac) < 0) { |
| 58 | + wpa_printf(MSG_ERROR, "station mac is not right.\n"); |
| 59 | + return -1; |
| 60 | + } |
| 61 | + |
| 62 | + if (hostapd_drv_amnt_set(hapd, amnt_idx, sta_mac)) { |
| 63 | + wpa_printf(MSG_ERROR, "Not able to set amnt index\n"); |
| 64 | + return -1; |
| 65 | + } |
| 66 | |
| 67 | return os_snprintf(buf, buflen, "OK\n"); |
| 68 | } |
developer | 2fd555a | 2023-07-25 05:48:15 +0800 | [diff] [blame^] | 69 | @@ -3818,6 +3856,75 @@ exit: |
developer | ae4d449 | 2023-04-03 16:43:49 +0800 | [diff] [blame] | 70 | return os_snprintf(buf, buflen, "OK\n"); |
| 71 | } |
| 72 | |
| 73 | +static int |
| 74 | +hostapd_ctrl_iface_dump_amnt(struct hostapd_data *hapd, char *cmd, |
| 75 | + char *buf, size_t buflen) |
| 76 | +{ |
| 77 | + char *tmp; |
| 78 | + int amnt_idx = 0, ret = 0; |
| 79 | + struct amnt_resp_data *resp_buf; |
| 80 | + char *pos, *end; |
| 81 | + struct amnt_data *res; |
| 82 | + |
| 83 | + pos = buf; |
| 84 | + end = buf + buflen; |
| 85 | + |
| 86 | + tmp = strtok_r(cmd, " ", &cmd); |
| 87 | + |
| 88 | + if (!tmp) { |
| 89 | + wpa_printf(MSG_ERROR, "Error in command format\n"); |
| 90 | + return -1; |
| 91 | + } |
| 92 | + |
| 93 | + amnt_idx = strtoul(tmp, &tmp, 0); |
| 94 | + |
| 95 | + if ((amnt_idx < 0 || amnt_idx > 15) && amnt_idx != 0xff) { |
| 96 | + wpa_printf(MSG_ERROR, "Wrong AMNT index\n"); |
| 97 | + return -1; |
| 98 | + } |
| 99 | + |
| 100 | + if (amnt_idx == 0xff) |
| 101 | + resp_buf = (struct amnt_resp_data *) os_zalloc(AIR_MONITOR_MAX_ENTRY |
| 102 | + * sizeof(struct amnt_data) + 1); |
| 103 | + else |
| 104 | + resp_buf = (struct amnt_resp_data *) os_zalloc(sizeof(struct amnt_data) + 1); |
| 105 | + |
| 106 | + if (resp_buf == NULL) { |
| 107 | + wpa_printf(MSG_ERROR, "Error in memory allocation\n"); |
| 108 | + return -1; |
| 109 | + } |
| 110 | + |
| 111 | + if (hostapd_drv_amnt_dump(hapd, amnt_idx, (u8 *)resp_buf)) { |
| 112 | + wpa_printf(MSG_ERROR, "Not able to set amnt index\n"); |
| 113 | + os_free(resp_buf); |
| 114 | + return -1; |
| 115 | + } |
| 116 | + |
| 117 | + for (int i = 0; i < resp_buf->sta_num && i < AIR_MONITOR_MAX_ENTRY; i++) { |
| 118 | + res = &resp_buf->resp_data[i]; |
| 119 | + ret = os_snprintf(pos, end - pos, |
| 120 | + "[hostapd_cli] amnt_idx: %d, addr="MACSTR |
| 121 | + ", rssi=%d/%d/%d/%d, last_seen=%u\n", |
| 122 | + res->idx, |
| 123 | + MAC2STR(res->addr), res->rssi[0], |
| 124 | + res->rssi[1], res->rssi[2], |
| 125 | + res->rssi[3], res->last_seen); |
| 126 | + if (os_snprintf_error(end - pos, ret)) { |
| 127 | + os_free(resp_buf); |
| 128 | + return 0; |
| 129 | + } |
| 130 | + pos = pos + ret; |
| 131 | + } |
| 132 | + |
| 133 | + os_free(resp_buf); |
| 134 | + |
| 135 | + if (pos == buf) |
| 136 | + return os_snprintf(buf, buflen, "Index %d is not monitored\n", |
| 137 | + amnt_idx); |
| 138 | + else |
| 139 | + return pos - buf; |
| 140 | +} |
| 141 | + |
| 142 | static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
| 143 | char *buf, char *reply, |
| 144 | int reply_size, |
developer | 2fd555a | 2023-07-25 05:48:15 +0800 | [diff] [blame^] | 145 | @@ -4392,6 +4499,12 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd, |
developer | ae4d449 | 2023-04-03 16:43:49 +0800 | [diff] [blame] | 146 | reply_len = hostapd_ctrl_iface_ap_wireless(hapd, buf + 12, reply, reply_size); |
| 147 | } else if (os_strncmp(buf, "ap_rfeatures ", 13) == 0) { |
| 148 | reply_len = hostapd_ctrl_iface_ap_rfeatures(hapd, buf + 13, reply, reply_size); |
| 149 | + } else if (os_strncmp(buf, "SET_AMNT", 8) == 0) { |
| 150 | + reply_len = hostapd_ctrl_iface_set_amnt(hapd, buf+9, |
| 151 | + reply, reply_size); |
| 152 | + } else if (os_strncmp(buf, "DUMP_AMNT", 9) == 0) { |
| 153 | + reply_len = hostapd_ctrl_iface_dump_amnt(hapd, buf+10, |
| 154 | + reply, reply_size); |
| 155 | } else { |
| 156 | os_memcpy(reply, "UNKNOWN COMMAND\n", 16); |
| 157 | reply_len = 16; |
| 158 | diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c |
| 159 | index aad7aa5..0c4a176 100644 |
| 160 | --- a/hostapd/hostapd_cli.c |
| 161 | +++ b/hostapd/hostapd_cli.c |
| 162 | @@ -1613,6 +1613,17 @@ static int hostapd_cli_cmd_get_amsdu(struct wpa_ctrl *ctrl, int argc, |
| 163 | return hostapd_cli_cmd(ctrl, "GET_AMSDU", 0, NULL, NULL); |
| 164 | } |
| 165 | |
| 166 | +static int hostapd_cli_cmd_set_amnt(struct wpa_ctrl *ctrl, int argc, |
| 167 | + char *argv[]) |
| 168 | +{ |
| 169 | + return hostapd_cli_cmd(ctrl, "SET_AMNT", 2, argc, argv); |
| 170 | +} |
| 171 | + |
| 172 | +static int hostapd_cli_cmd_dump_amnt(struct wpa_ctrl *ctrl, int argc, |
| 173 | + char *argv[]) |
| 174 | +{ |
| 175 | + return hostapd_cli_cmd(ctrl, "DUMP_AMNT", 1, argc, argv); |
| 176 | +} |
| 177 | |
| 178 | struct hostapd_cli_cmd { |
| 179 | const char *cmd; |
| 180 | @@ -1823,6 +1834,10 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = { |
| 181 | " = show iBF state (enabled/disabled)"}, |
| 182 | { "get_amsdu", hostapd_cli_cmd_get_amsdu, NULL, |
| 183 | " = show AMSDU state"}, |
| 184 | + { "set_amnt", hostapd_cli_cmd_set_amnt, NULL, |
| 185 | + " = Set Station index and mac to monitor"}, |
| 186 | + { "dump_amnt", hostapd_cli_cmd_dump_amnt, NULL, |
| 187 | + " = Dump RSSI of monitoring Station"}, |
| 188 | { NULL, NULL, NULL, NULL } |
| 189 | }; |
| 190 | |
| 191 | diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c |
| 192 | index 52d0fff..eafa588 100644 |
| 193 | --- a/src/ap/ap_drv_ops.c |
| 194 | +++ b/src/ap/ap_drv_ops.c |
| 195 | @@ -1121,3 +1121,17 @@ int hostapd_drv_ap_trig_type(struct hostapd_data *hapd, u8 enable, u8 type) |
| 196 | return 0; |
| 197 | return hapd->driver->ap_trigtype(hapd->drv_priv, enable, type); |
| 198 | } |
| 199 | + |
| 200 | +int hostapd_drv_amnt_set(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_sta_mac) |
| 201 | +{ |
| 202 | + if (!hapd->driver || !hapd->driver->amnt_set) |
| 203 | + return 0; |
| 204 | + return hapd->driver->amnt_set(hapd->drv_priv, amnt_idx, amnt_sta_mac); |
| 205 | +} |
| 206 | + |
| 207 | +int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_buf) |
| 208 | +{ |
| 209 | + if (!hapd->driver || !hapd->driver->amnt_dump) |
| 210 | + return 0; |
| 211 | + return hapd->driver->amnt_dump(hapd->drv_priv, amnt_idx, amnt_dump_buf); |
| 212 | +} |
| 213 | diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h |
| 214 | index 659c3f8..28f2a4d 100644 |
| 215 | --- a/src/ap/ap_drv_ops.h |
| 216 | +++ b/src/ap/ap_drv_ops.h |
| 217 | @@ -155,6 +155,9 @@ int hostapd_drv_ap_wireless(struct hostapd_data *hapd, u8 sub_vendor_id, int val |
| 218 | int hostapd_drv_ap_rfeatures(struct hostapd_data *hapd, u8 sub_vendor_id, int value); |
| 219 | int hostapd_drv_ap_trig_type(struct hostapd_data *hapd, u8 enable, u8 type); |
| 220 | |
| 221 | +int hostapd_drv_amnt_set(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_sta_mac); |
| 222 | +int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_buf); |
| 223 | + |
| 224 | #include "drivers/driver.h" |
| 225 | |
| 226 | int hostapd_drv_wnm_oper(struct hostapd_data *hapd, |
| 227 | diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h |
| 228 | index 32438af..74f467c 100644 |
| 229 | --- a/src/common/mtk_vendor.h |
| 230 | +++ b/src/common/mtk_vendor.h |
| 231 | @@ -256,10 +256,18 @@ struct csi_data { |
| 232 | u16 rx_idx; |
| 233 | }; |
| 234 | |
| 235 | +#define AIR_MONITOR_MAX_ENTRY 16 |
| 236 | + |
| 237 | struct amnt_data { |
| 238 | u8 idx; |
| 239 | u8 addr[ETH_ALEN]; |
| 240 | s8 rssi[4]; |
| 241 | u32 last_seen; |
| 242 | }; |
| 243 | + |
| 244 | +struct amnt_resp_data { |
| 245 | + u8 sta_num; |
| 246 | + struct amnt_data resp_data[0]; |
| 247 | +}; |
| 248 | + |
| 249 | #endif /* MTK_VENDOR_H */ |
| 250 | diff --git a/src/drivers/driver.h b/src/drivers/driver.h |
| 251 | index 6a46832..1444cbe 100644 |
| 252 | --- a/src/drivers/driver.h |
| 253 | +++ b/src/drivers/driver.h |
| 254 | @@ -4809,6 +4809,22 @@ struct wpa_driver_ops { |
| 255 | * @type: trigger type |
| 256 | */ |
| 257 | int (*ap_trigtype)(void *priv, u8 enable, u8 type); |
| 258 | + |
| 259 | + /** |
| 260 | + * amnt_set - add/delete station from monitoring |
| 261 | + * @priv: Private driver interface data |
| 262 | + * @amnt_idx: Monitor Index |
| 263 | + * @amnt_sta_mac: station mac address |
| 264 | + */ |
| 265 | + int (*amnt_set)(void *priv, u8 amnt_idx, u8 *amnt_sta_mac); |
| 266 | + |
| 267 | + /** |
| 268 | + * amnt_dump - Dump particular/ all station |
| 269 | + * @priv: Private driver interface data |
| 270 | + * @amnt_idx: Monitor Index |
| 271 | + * @amnt_dump_buf: Buffer to print |
| 272 | + */ |
| 273 | + int (*amnt_dump)(void *priv, u8 amnt_idx, u8 *amnt_dump_buf); |
| 274 | }; |
| 275 | |
| 276 | /** |
| 277 | diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c |
| 278 | index 7fae013..0470079 100644 |
| 279 | --- a/src/drivers/driver_nl80211.c |
| 280 | +++ b/src/drivers/driver_nl80211.c |
| 281 | @@ -125,6 +125,19 @@ wireless_ctrl_policy[NUM_MTK_VENDOR_ATTRS_WIRELESS_CTRL] = { |
| 282 | [MTK_VENDOR_ATTR_WIRELESS_CTRL_CERT] = {.type = NLA_U8 }, |
| 283 | }; |
| 284 | |
| 285 | +static struct nla_policy |
| 286 | +amnt_ctrl_policy[NUM_MTK_VENDOR_ATTRS_AMNT_CTRL] = { |
| 287 | + [MTK_VENDOR_ATTR_AMNT_CTRL_SET] = {.type = NLA_NESTED }, |
| 288 | + [MTK_VENDOR_ATTR_AMNT_CTRL_DUMP] = { .type = NLA_NESTED }, |
| 289 | +}; |
| 290 | + |
| 291 | +static struct nla_policy |
| 292 | +amnt_dump_policy[NUM_MTK_VENDOR_ATTRS_AMNT_DUMP] = { |
| 293 | + [MTK_VENDOR_ATTR_AMNT_DUMP_INDEX] = {.type = NLA_U8 }, |
| 294 | + [MTK_VENDOR_ATTR_AMNT_DUMP_LEN] = { .type = NLA_U8 }, |
| 295 | + [MTK_VENDOR_ATTR_AMNT_DUMP_RESULT] = { .type = NLA_NESTED }, |
| 296 | +}; |
| 297 | + |
| 298 | static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 299 | { |
| 300 | struct nl_sock *handle; |
| 301 | @@ -13196,6 +13209,171 @@ fail: |
| 302 | return -ENOBUFS; |
| 303 | } |
| 304 | |
| 305 | +static int |
| 306 | +nl80211_amnt_set(void *priv, u8 amnt_idx, u8 *amnt_sta_mac) |
| 307 | +{ |
| 308 | + struct i802_bss *bss = priv; |
| 309 | + struct wpa_driver_nl80211_data *drv = bss->drv; |
| 310 | + struct nl_msg *msg; |
| 311 | + struct nlattr *data; |
| 312 | + void *tb1; |
| 313 | + int ret; |
| 314 | + |
| 315 | + if (!drv->mtk_amnt_vendor_cmd_avail) { |
| 316 | + wpa_printf(MSG_ERROR, |
| 317 | + "nl80211: Driver does not support air monitor"); |
| 318 | + return 0; |
| 319 | + } |
| 320 | + |
| 321 | + msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 322 | + if (!msg) |
| 323 | + goto fail; |
| 324 | + |
| 325 | + if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) || |
| 326 | + nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 327 | + MTK_NL80211_VENDOR_SUBCMD_AMNT_CTRL)) |
| 328 | + goto fail; |
| 329 | + |
| 330 | + data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED); |
| 331 | + if (!data) |
| 332 | + goto fail; |
| 333 | + |
| 334 | + tb1 = nla_nest_start(msg, MTK_VENDOR_ATTR_AMNT_CTRL_SET); |
| 335 | + if (!tb1) |
| 336 | + goto fail; |
| 337 | + |
| 338 | + nla_put_u8(msg, MTK_VENDOR_ATTR_AMNT_SET_INDEX, amnt_idx); |
| 339 | + |
| 340 | + nla_put(msg, MTK_VENDOR_ATTR_AMNT_SET_MACADDR, ETH_ALEN, amnt_sta_mac); |
| 341 | + |
| 342 | + nla_nest_end(msg, tb1); |
| 343 | + nla_nest_end(msg, data); |
| 344 | + |
| 345 | + ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 346 | + |
| 347 | + if (ret) |
| 348 | + wpa_printf(MSG_ERROR, "Failed to set air monitor. ret=%d (%s)", |
| 349 | + ret, strerror(-ret)); |
| 350 | + |
| 351 | + return ret; |
| 352 | + |
| 353 | +fail: |
| 354 | + nlmsg_free(msg); |
| 355 | + return -ENOBUFS; |
| 356 | + |
| 357 | +} |
| 358 | + |
| 359 | +static int |
| 360 | +mt76_amnt_dump_cb(struct nl_msg *msg, void *arg) |
| 361 | +{ |
| 362 | + struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 363 | + struct nlattr *tb1[NUM_MTK_VENDOR_ATTRS_AMNT_CTRL]; |
| 364 | + struct nlattr *tb2[NUM_MTK_VENDOR_ATTRS_AMNT_DUMP]; |
| 365 | + struct nlattr *attr, *cur, *data; |
| 366 | + struct amnt_data *res; |
| 367 | + int len = 0, rem; |
| 368 | + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 369 | + struct amnt_resp_data *amnt_dump = (struct amnt_resp_data *)arg; |
| 370 | + |
| 371 | + nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 372 | + genlmsg_attrlen(gnlh, 0), NULL); |
| 373 | + |
| 374 | + attr = tb[NL80211_ATTR_VENDOR_DATA]; |
| 375 | + if (!attr) |
| 376 | + return NL_SKIP; |
| 377 | + |
| 378 | + nla_parse_nested(tb1, MTK_VENDOR_ATTR_AMNT_CTRL_MAX, |
| 379 | + attr, amnt_ctrl_policy); |
| 380 | + |
| 381 | + if (!tb1[MTK_VENDOR_ATTR_AMNT_CTRL_DUMP]) |
| 382 | + return NL_SKIP; |
| 383 | + |
| 384 | + nla_parse_nested(tb2, NUM_MTK_VENDOR_ATTRS_AMNT_DUMP, |
| 385 | + tb1[MTK_VENDOR_ATTR_AMNT_CTRL_DUMP], amnt_dump_policy); |
| 386 | + |
| 387 | + if (!tb2[MTK_VENDOR_ATTR_AMNT_DUMP_LEN]) |
| 388 | + return NL_SKIP; |
| 389 | + |
| 390 | + len = nla_get_u8(tb2[MTK_VENDOR_ATTR_AMNT_DUMP_LEN]); |
| 391 | + if (!len) |
| 392 | + return 0; |
| 393 | + |
| 394 | + if (!tb2[MTK_VENDOR_ATTR_AMNT_DUMP_RESULT]) |
| 395 | + return NL_SKIP; |
| 396 | + |
| 397 | + data = tb2[MTK_VENDOR_ATTR_AMNT_DUMP_RESULT]; |
| 398 | + |
| 399 | + nla_for_each_nested(cur, data, rem) { |
| 400 | + if (amnt_dump->sta_num >= AIR_MONITOR_MAX_ENTRY) |
| 401 | + return NL_SKIP; |
| 402 | + res = (struct amnt_data *) nla_data(cur); |
| 403 | + wpa_printf(MSG_ERROR, "[vendor] amnt_idx: %d, " |
| 404 | + "addr="MACSTR", " |
| 405 | + "rssi=%d/%d/%d/%d, last_seen=%u\n", |
| 406 | + res->idx, |
| 407 | + MAC2STR(res->addr), |
| 408 | + res->rssi[0], res->rssi[1], res->rssi[2], |
| 409 | + res->rssi[3], res->last_seen); |
| 410 | + os_memcpy(&amnt_dump->resp_data[amnt_dump->sta_num], res, |
| 411 | + sizeof(struct amnt_data)); |
| 412 | + amnt_dump->sta_num++; |
| 413 | + } |
| 414 | + return 0; |
| 415 | +} |
| 416 | + |
| 417 | +static int |
| 418 | +nl80211_amnt_dump(void *priv, u8 amnt_idx, u8 *dump_buf) |
| 419 | +{ |
| 420 | + struct i802_bss *bss = priv; |
| 421 | + struct wpa_driver_nl80211_data *drv = bss->drv; |
| 422 | + struct nl_msg *msg; |
| 423 | + struct nlattr *data; |
| 424 | + void *tb1; |
| 425 | + int ret; |
| 426 | + |
| 427 | + if (!drv->mtk_amnt_vendor_cmd_avail) { |
| 428 | + wpa_printf(MSG_INFO, |
| 429 | + "nl80211: Driver does not support air monitor"); |
| 430 | + return 0; |
| 431 | + } |
| 432 | + |
| 433 | + msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_VENDOR); |
| 434 | + if (!msg) |
| 435 | + goto fail; |
| 436 | + |
| 437 | + if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) || |
| 438 | + nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 439 | + MTK_NL80211_VENDOR_SUBCMD_AMNT_CTRL)) |
| 440 | + goto fail; |
| 441 | + |
| 442 | + data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED); |
| 443 | + if (!data) |
| 444 | + goto fail; |
| 445 | + |
| 446 | + tb1 = nla_nest_start(msg, MTK_VENDOR_ATTR_AMNT_CTRL_DUMP |
| 447 | + | NLA_F_NESTED); |
| 448 | + if (!tb1) |
| 449 | + goto fail; |
| 450 | + |
| 451 | + nla_put_u8(msg, MTK_VENDOR_ATTR_AMNT_DUMP_INDEX, amnt_idx); |
| 452 | + |
| 453 | + nla_nest_end(msg, tb1); |
| 454 | + nla_nest_end(msg, data); |
| 455 | + |
| 456 | + ret = send_and_recv_msgs(drv, msg, mt76_amnt_dump_cb, |
| 457 | + dump_buf, NULL, NULL); |
| 458 | + |
| 459 | + if (ret) |
| 460 | + wpa_printf(MSG_ERROR, "Failed to Dump air monitor. ret=%d (%s)" |
| 461 | + , ret, strerror(-ret)); |
| 462 | + |
| 463 | + return ret; |
| 464 | + |
| 465 | +fail: |
| 466 | + nlmsg_free(msg); |
| 467 | + return -ENOBUFS; |
| 468 | +} |
| 469 | + |
| 470 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 471 | .name = "nl80211", |
| 472 | .desc = "Linux nl80211/cfg80211", |
| 473 | @@ -13356,4 +13534,6 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 474 | .ap_wireless = nl80211_ap_wireless, |
| 475 | .ap_rfeatures = nl80211_ap_rfeatures, |
| 476 | .ap_trigtype = nl80211_ap_trigtype, |
| 477 | + .amnt_set = nl80211_amnt_set, |
| 478 | + .amnt_dump = nl80211_amnt_dump, |
| 479 | }; |
| 480 | diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h |
| 481 | index 7a03446..7dd88e7 100644 |
| 482 | --- a/src/drivers/driver_nl80211.h |
| 483 | +++ b/src/drivers/driver_nl80211.h |
| 484 | @@ -188,6 +188,7 @@ struct wpa_driver_nl80211_data { |
| 485 | unsigned int mtk_wireless_vendor_cmd_avail:1; |
| 486 | unsigned int mtk_bss_color_vendor_cmd_avail:1; |
| 487 | unsigned int mtk_rfeatures_vendor_cmd_avail:1; |
| 488 | + unsigned int mtk_amnt_vendor_cmd_avail:1; |
| 489 | |
| 490 | u64 vendor_scan_cookie; |
| 491 | u64 remain_on_chan_cookie; |
| 492 | diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c |
| 493 | index 6f4d029..5c1a35d 100644 |
| 494 | --- a/src/drivers/driver_nl80211_capa.c |
| 495 | +++ b/src/drivers/driver_nl80211_capa.c |
| 496 | @@ -1094,6 +1094,8 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
| 497 | break; |
| 498 | case MTK_NL80211_VENDOR_SUBCMD_BSS_COLOR_CTRL : |
| 499 | drv->mtk_bss_color_vendor_cmd_avail = 1; |
| 500 | + case MTK_NL80211_VENDOR_SUBCMD_AMNT_CTRL: |
| 501 | + drv->mtk_amnt_vendor_cmd_avail = 1; |
| 502 | break; |
| 503 | case MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL: |
| 504 | drv->mtk_rfeatures_vendor_cmd_avail = 1; |
| 505 | -- |
| 506 | 2.18.0 |
| 507 | |