developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 1 | /* Copyright (C) 2021 Mediatek Inc. */ |
| 2 | #define _GNU_SOURCE |
| 3 | |
| 4 | #include "mt76-vendor.h" |
| 5 | |
| 6 | struct csi_data *csi; |
| 7 | int csi_idx; |
| 8 | |
| 9 | static struct nla_policy csi_ctrl_policy[NUM_MTK_VENDOR_ATTRS_CSI_CTRL] = { |
| 10 | [MTK_VENDOR_ATTR_CSI_CTRL_CFG] = { .type = NLA_NESTED }, |
| 11 | [MTK_VENDOR_ATTR_CSI_CTRL_CFG_MODE] = { .type = NLA_U8 }, |
| 12 | [MTK_VENDOR_ATTR_CSI_CTRL_CFG_TYPE] = { .type = NLA_U8 }, |
| 13 | [MTK_VENDOR_ATTR_CSI_CTRL_CFG_VAL1] = { .type = NLA_U8 }, |
| 14 | [MTK_VENDOR_ATTR_CSI_CTRL_CFG_VAL2] = { .type = NLA_U8 }, |
| 15 | [MTK_VENDOR_ATTR_CSI_CTRL_MAC_ADDR] = { .type = NLA_NESTED }, |
| 16 | [MTK_VENDOR_ATTR_CSI_CTRL_INTERVAL] = { .type = NLA_U32 }, |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 17 | [MTK_VENDOR_ATTR_CSI_CTRL_STA_INTERVAL] = { .type = NLA_U32 }, |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 18 | [MTK_VENDOR_ATTR_CSI_CTRL_DUMP_NUM] = { .type = NLA_U16 }, |
| 19 | [MTK_VENDOR_ATTR_CSI_CTRL_DATA] = { .type = NLA_NESTED }, |
| 20 | }; |
| 21 | |
| 22 | static struct nla_policy csi_data_policy[NUM_MTK_VENDOR_ATTRS_CSI_DATA] = { |
| 23 | [MTK_VENDOR_ATTR_CSI_DATA_VER] = { .type = NLA_U8 }, |
| 24 | [MTK_VENDOR_ATTR_CSI_DATA_TS] = { .type = NLA_U32 }, |
| 25 | [MTK_VENDOR_ATTR_CSI_DATA_RSSI] = { .type = NLA_U8 }, |
| 26 | [MTK_VENDOR_ATTR_CSI_DATA_SNR] = { .type = NLA_U8 }, |
| 27 | [MTK_VENDOR_ATTR_CSI_DATA_BW] = { .type = NLA_U8 }, |
| 28 | [MTK_VENDOR_ATTR_CSI_DATA_CH_IDX] = { .type = NLA_U8 }, |
| 29 | [MTK_VENDOR_ATTR_CSI_DATA_TA] = { .type = NLA_NESTED }, |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 30 | [MTK_VENDOR_ATTR_CSI_DATA_NUM] = { .type = NLA_U32 }, |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 31 | [MTK_VENDOR_ATTR_CSI_DATA_I] = { .type = NLA_NESTED }, |
| 32 | [MTK_VENDOR_ATTR_CSI_DATA_Q] = { .type = NLA_NESTED }, |
| 33 | [MTK_VENDOR_ATTR_CSI_DATA_INFO] = { .type = NLA_U32 }, |
| 34 | [MTK_VENDOR_ATTR_CSI_DATA_TX_ANT] = { .type = NLA_U8 }, |
| 35 | [MTK_VENDOR_ATTR_CSI_DATA_RX_ANT] = { .type = NLA_U8 }, |
| 36 | [MTK_VENDOR_ATTR_CSI_DATA_MODE] = { .type = NLA_U8 }, |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 37 | [MTK_VENDOR_ATTR_CSI_DATA_CHAIN_INFO] = { .type = NLA_U32 }, |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | static int mt76_csi_dump_cb(struct nl_msg *msg, void *arg) |
| 41 | { |
| 42 | struct nlattr *tb[NUM_MTK_VENDOR_ATTRS_CSI_CTRL]; |
| 43 | struct nlattr *tb_data[NUM_MTK_VENDOR_ATTRS_CSI_DATA]; |
| 44 | struct nlattr *attr; |
| 45 | struct nlattr *cur; |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 46 | size_t idx; |
| 47 | int rem; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 48 | struct csi_data *c = &csi[csi_idx]; |
| 49 | |
| 50 | attr = unl_find_attr(&unl, msg, NL80211_ATTR_VENDOR_DATA); |
| 51 | if (!attr) { |
| 52 | fprintf(stderr, "Testdata attribute not found\n"); |
| 53 | return NL_SKIP; |
| 54 | } |
| 55 | |
| 56 | nla_parse_nested(tb, MTK_VENDOR_ATTR_CSI_CTRL_MAX, |
| 57 | attr, csi_ctrl_policy); |
| 58 | |
| 59 | if (!tb[MTK_VENDOR_ATTR_CSI_CTRL_DATA]) |
| 60 | return NL_SKIP; |
| 61 | |
| 62 | nla_parse_nested(tb_data, MTK_VENDOR_ATTR_CSI_DATA_MAX, |
| 63 | tb[MTK_VENDOR_ATTR_CSI_CTRL_DATA], csi_data_policy); |
| 64 | |
| 65 | if (!(tb_data[MTK_VENDOR_ATTR_CSI_DATA_VER] && |
| 66 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_TS] && |
| 67 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_RSSI] && |
| 68 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_SNR] && |
| 69 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_BW] && |
| 70 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_CH_IDX] && |
| 71 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_TA] && |
| 72 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_I] && |
| 73 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_Q] && |
| 74 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_INFO] && |
| 75 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_MODE] && |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 76 | tb_data[MTK_VENDOR_ATTR_CSI_DATA_CHAIN_INFO])) { |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 77 | fprintf(stderr, "Attributes error for CSI data\n"); |
| 78 | return NL_SKIP; |
| 79 | } |
| 80 | |
| 81 | c->rssi = nla_get_u8(tb_data[MTK_VENDOR_ATTR_CSI_DATA_RSSI]); |
| 82 | c->snr = nla_get_u8(tb_data[MTK_VENDOR_ATTR_CSI_DATA_SNR]); |
| 83 | c->data_bw = nla_get_u8(tb_data[MTK_VENDOR_ATTR_CSI_DATA_BW]); |
| 84 | c->pri_ch_idx = nla_get_u8(tb_data[MTK_VENDOR_ATTR_CSI_DATA_CH_IDX]); |
| 85 | c->rx_mode = nla_get_u8(tb_data[MTK_VENDOR_ATTR_CSI_DATA_MODE]); |
| 86 | |
| 87 | c->tx_idx = nla_get_u16(tb_data[MTK_VENDOR_ATTR_CSI_DATA_TX_ANT]); |
| 88 | c->rx_idx = nla_get_u16(tb_data[MTK_VENDOR_ATTR_CSI_DATA_RX_ANT]); |
| 89 | |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 90 | c->ext_info = nla_get_u32(tb_data[MTK_VENDOR_ATTR_CSI_DATA_INFO]); |
| 91 | c->chain_info = nla_get_u32(tb_data[MTK_VENDOR_ATTR_CSI_DATA_CHAIN_INFO]); |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 92 | |
| 93 | c->ts = nla_get_u32(tb_data[MTK_VENDOR_ATTR_CSI_DATA_TS]); |
| 94 | |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 95 | c->data_num = nla_get_u32(tb_data[MTK_VENDOR_ATTR_CSI_DATA_NUM]); |
| 96 | |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 97 | idx = 0; |
| 98 | nla_for_each_nested(cur, tb_data[MTK_VENDOR_ATTR_CSI_DATA_TA], rem) { |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 99 | if (idx < ETH_ALEN) |
| 100 | c->ta[idx++] = nla_get_u8(cur); |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | idx = 0; |
| 104 | nla_for_each_nested(cur, tb_data[MTK_VENDOR_ATTR_CSI_DATA_I], rem) { |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 105 | if (idx < c->data_num) |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 106 | c->data_i[idx++] = nla_get_u16(cur); |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | idx = 0; |
| 110 | nla_for_each_nested(cur, tb_data[MTK_VENDOR_ATTR_CSI_DATA_Q], rem) { |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 111 | if (idx < c->data_num) |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 112 | c->data_q[idx++] = nla_get_u16(cur); |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | csi_idx++; |
| 116 | |
| 117 | return NL_SKIP; |
| 118 | } |
| 119 | |
| 120 | static int mt76_csi_to_json(const char *name) |
| 121 | { |
| 122 | #define MAX_BUF_SIZE 6000 |
| 123 | FILE *f; |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 124 | int i, ret = -ENOMEM; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 125 | |
| 126 | f = fopen(name, "a+"); |
| 127 | if (!f) { |
| 128 | printf("open failure"); |
| 129 | return 1; |
| 130 | } |
| 131 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 132 | if (fwrite("[", 1, 1, f) != 1) { |
| 133 | perror("fwrite"); |
| 134 | goto out; |
| 135 | } |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 136 | |
| 137 | for (i = 0; i < csi_idx; i++) { |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 138 | struct csi_data *c = &csi[i]; |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 139 | char *pos, *buf; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 140 | int j; |
| 141 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 142 | buf = malloc(MAX_BUF_SIZE); |
| 143 | if (!buf) |
| 144 | goto out; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 145 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 146 | pos = buf; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 147 | pos += snprintf(pos, MAX_BUF_SIZE, "%c", '['); |
| 148 | |
developer | 6f8cffd | 2021-09-29 19:48:25 +0800 | [diff] [blame] | 149 | pos += snprintf(pos, MAX_BUF_SIZE, "%d,", c->ts); |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 150 | pos += snprintf(pos, MAX_BUF_SIZE, "\"%02x%02x%02x%02x%02x%02x\",", c->ta[0], c->ta[1], c->ta[2], c->ta[3], c->ta[4], c->ta[5]); |
| 151 | |
| 152 | pos += snprintf(pos, MAX_BUF_SIZE, "%d,", c->rssi); |
| 153 | pos += snprintf(pos, MAX_BUF_SIZE, "%u,", c->snr); |
| 154 | pos += snprintf(pos, MAX_BUF_SIZE, "%u,", c->data_bw); |
| 155 | pos += snprintf(pos, MAX_BUF_SIZE, "%u,", c->pri_ch_idx); |
| 156 | pos += snprintf(pos, MAX_BUF_SIZE, "%u,", c->rx_mode); |
| 157 | pos += snprintf(pos, MAX_BUF_SIZE, "%d,", c->tx_idx); |
| 158 | pos += snprintf(pos, MAX_BUF_SIZE, "%d,", c->rx_idx); |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 159 | pos += snprintf(pos, MAX_BUF_SIZE, "%d,", c->chain_info); |
| 160 | pos += snprintf(pos, MAX_BUF_SIZE, "%d,", c->ext_info); |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 161 | |
| 162 | pos += snprintf(pos, MAX_BUF_SIZE, "%c", '['); |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 163 | for (j = 0; j < c->data_num; j++) { |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 164 | pos += snprintf(pos, MAX_BUF_SIZE, "%d", c->data_i[j]); |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 165 | if (j != (c->data_num - 1)) |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 166 | pos += snprintf(pos, MAX_BUF_SIZE, ","); |
| 167 | } |
| 168 | pos += snprintf(pos, MAX_BUF_SIZE, "%c,", ']'); |
| 169 | |
| 170 | pos += snprintf(pos, MAX_BUF_SIZE, "%c", '['); |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 171 | for (j = 0; j < c->data_num; j++) { |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 172 | pos += snprintf(pos, MAX_BUF_SIZE, "%d", c->data_q[j]); |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 173 | if (j != (c->data_num - 1)) |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 174 | pos += snprintf(pos, MAX_BUF_SIZE, ","); |
| 175 | } |
| 176 | pos += snprintf(pos, MAX_BUF_SIZE, "%c", ']'); |
| 177 | |
| 178 | pos += snprintf(pos, MAX_BUF_SIZE, "%c", ']'); |
| 179 | if (i != csi_idx - 1) |
| 180 | pos += snprintf(pos, MAX_BUF_SIZE, ","); |
| 181 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 182 | if (fwrite(buf, 1, pos - buf, f) != (pos - buf)) { |
| 183 | perror("fwrite"); |
| 184 | free(buf); |
| 185 | goto out; |
| 186 | } |
| 187 | |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 188 | free(buf); |
| 189 | } |
| 190 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 191 | if (fwrite("]", 1, 1, f) != 1) { |
| 192 | perror("fwrite"); |
| 193 | goto out; |
| 194 | } |
developer | 6f8cffd | 2021-09-29 19:48:25 +0800 | [diff] [blame] | 195 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 196 | ret = 0; |
| 197 | out: |
| 198 | if (fclose(f)) |
| 199 | perror("fclose"); |
| 200 | |
| 201 | return ret; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | int mt76_csi_dump(int idx, int argc, char **argv) |
| 205 | { |
developer | 6f8cffd | 2021-09-29 19:48:25 +0800 | [diff] [blame] | 206 | int pkt_num, ret = 0, i; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 207 | struct nl_msg *msg; |
| 208 | void *data; |
| 209 | |
| 210 | if (argc < 2) |
| 211 | return 1; |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 212 | |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 213 | pkt_num = strtol(argv[0], NULL, 10); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 214 | if (pkt_num < 0 || pkt_num > 30000) |
| 215 | return -EINVAL; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 216 | |
| 217 | #define CSI_DUMP_PER_NUM 3 |
| 218 | csi_idx = 0; |
| 219 | csi = (struct csi_data *)calloc(pkt_num, sizeof(*csi)); |
| 220 | |
| 221 | for (i = 0; i < pkt_num / CSI_DUMP_PER_NUM; i++) { |
| 222 | if (unl_genl_init(&unl, "nl80211") < 0) { |
| 223 | fprintf(stderr, "Failed to connect to nl80211\n"); |
| 224 | return 2; |
| 225 | } |
| 226 | |
| 227 | msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, true); |
| 228 | |
| 229 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) || |
| 230 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) || |
| 231 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_CSI_CTRL)) |
| 232 | return false; |
| 233 | |
| 234 | data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 235 | if (!data) |
| 236 | return -ENOMEM; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 237 | |
| 238 | if (nla_put_u16(msg, MTK_VENDOR_ATTR_CSI_CTRL_DUMP_NUM, CSI_DUMP_PER_NUM)) |
| 239 | return false; |
| 240 | |
| 241 | nla_nest_end(msg, data); |
| 242 | |
| 243 | ret = unl_genl_request(&unl, msg, mt76_csi_dump_cb, NULL); |
| 244 | if (ret) |
| 245 | fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret)); |
| 246 | |
| 247 | unl_free(&unl); |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 248 | |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | mt76_csi_to_json(argv[1]); |
| 252 | free(csi); |
| 253 | |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | static int mt76_csi_set_attr(struct nl_msg *msg, int argc, char **argv) |
| 258 | { |
| 259 | int idx = MTK_VENDOR_ATTR_CSI_CTRL_CFG_MODE; |
| 260 | char *val, *s1, *s2, *cur; |
| 261 | void *data; |
| 262 | |
| 263 | val = strchr(argv[0], '='); |
developer | 6f8cffd | 2021-09-29 19:48:25 +0800 | [diff] [blame] | 264 | if (!val) |
| 265 | return -EINVAL; |
| 266 | |
| 267 | *(val++) = 0; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 268 | |
| 269 | if (!strncmp(argv[0], "ctrl", 4)) { |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 270 | data = nla_nest_start(msg, MTK_VENDOR_ATTR_CSI_CTRL_CFG | NLA_F_NESTED); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 271 | if (!data) |
| 272 | return -ENOMEM; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 273 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 274 | s1 = s2 = strdup(val); |
| 275 | |
| 276 | while ((cur = strsep(&s1, ",")) != NULL) { |
| 277 | u8 param = strtoul(cur, NULL, 0); |
| 278 | |
| 279 | nla_put_u8(msg, idx++, param); |
| 280 | } |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 281 | |
| 282 | nla_nest_end(msg, data); |
| 283 | |
| 284 | free(s2); |
| 285 | |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 286 | if ((argc == 2 || argc == 3) && |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 287 | !strncmp(argv[1], "mac_addr", strlen("mac_addr"))) { |
| 288 | u8 a[ETH_ALEN]; |
| 289 | int matches, i; |
| 290 | |
| 291 | val = strchr(argv[1], '='); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 292 | if (!val) |
| 293 | return -EINVAL; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 294 | |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 295 | *(val++) = 0; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 296 | matches = sscanf(val, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", |
| 297 | a, a+1, a+2, a+3, a+4, a+5); |
| 298 | |
| 299 | if (matches != ETH_ALEN) |
| 300 | return -EINVAL; |
| 301 | |
| 302 | data = nla_nest_start(msg, MTK_VENDOR_ATTR_CSI_CTRL_MAC_ADDR | NLA_F_NESTED); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 303 | if (!data) |
| 304 | return -ENOMEM; |
| 305 | |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 306 | for (i = 0; i < ETH_ALEN; i++) |
| 307 | nla_put_u8(msg, i, a[i]); |
| 308 | |
| 309 | nla_nest_end(msg, data); |
| 310 | } |
developer | 0fad892 | 2023-11-28 20:15:39 +0800 | [diff] [blame] | 311 | |
| 312 | if (argc == 3 && |
| 313 | !strncmp(argv[2], "sta_interval", strlen("sta_interval"))) { |
| 314 | u32 sta_interval = 0; |
| 315 | |
| 316 | val = strchr(argv[2], '='); |
| 317 | |
| 318 | *(val++) = 0; |
| 319 | |
| 320 | if (!val) |
| 321 | return -EINVAL; |
| 322 | |
| 323 | sta_interval = strtoul(val, NULL, 0); |
| 324 | |
| 325 | nla_put_u32(msg, MTK_VENDOR_ATTR_CSI_CTRL_STA_INTERVAL, sta_interval); |
| 326 | |
| 327 | } |
| 328 | |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 329 | } else if (!strncmp(argv[0], "interval", 8)) { |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 330 | u32 interval = strtoul(val, NULL, 0); |
| 331 | |
| 332 | nla_put_u32(msg, MTK_VENDOR_ATTR_CSI_CTRL_INTERVAL, interval); |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | int mt76_csi_set(int idx, int argc, char **argv) |
| 339 | { |
| 340 | struct nl_msg *msg; |
| 341 | void *data; |
| 342 | int ret; |
| 343 | |
| 344 | if (argc < 1) |
| 345 | return 1; |
| 346 | |
| 347 | if (unl_genl_init(&unl, "nl80211") < 0) { |
| 348 | fprintf(stderr, "Failed to connect to nl80211\n"); |
| 349 | return 2; |
| 350 | } |
| 351 | |
| 352 | msg = unl_genl_msg(&unl, NL80211_CMD_VENDOR, false); |
| 353 | |
| 354 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, idx) || |
| 355 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, MTK_NL80211_VENDOR_ID) || |
| 356 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_CSI_CTRL)) |
| 357 | return false; |
| 358 | |
| 359 | data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA | NLA_F_NESTED); |
developer | 0497a7b | 2021-10-04 10:00:27 +0800 | [diff] [blame] | 360 | if (!data) |
| 361 | return -ENOMEM; |
developer | 175704f | 2021-06-22 17:33:53 +0800 | [diff] [blame] | 362 | |
| 363 | mt76_csi_set_attr(msg, argc, argv); |
| 364 | |
| 365 | nla_nest_end(msg, data); |
| 366 | |
| 367 | ret = unl_genl_request(&unl, msg, NULL, NULL); |
| 368 | if (ret) |
| 369 | fprintf(stderr, "nl80211 call failed: %s\n", strerror(-ret)); |
| 370 | |
| 371 | unl_free(&unl); |
| 372 | |
| 373 | return ret; |
| 374 | } |