developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: ISC |
| 2 | /* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */ |
| 3 | #ifndef __MT76_TEST_H |
| 4 | #define __MT76_TEST_H |
| 5 | |
| 6 | #include <stdbool.h> |
| 7 | #include <stdint.h> |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include <linux/nl80211.h> |
| 11 | #include <netlink/attr.h> |
| 12 | #include <unl.h> |
| 13 | |
| 14 | typedef uint8_t u8; |
| 15 | typedef uint16_t u16; |
| 16 | typedef uint32_t u32; |
| 17 | typedef uint64_t u64; |
| 18 | typedef int8_t s8; |
| 19 | typedef int16_t s16; |
| 20 | typedef int32_t s32; |
| 21 | typedef int64_t s64, ktime_t; |
| 22 | |
| 23 | #define MTK_NL80211_VENDOR_ID 0x0ce7 |
| 24 | |
| 25 | #ifndef ARRAY_SIZE |
| 26 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 27 | #endif |
| 28 | |
| 29 | #ifndef DIV_ROUND_UP |
| 30 | #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
| 31 | #endif |
| 32 | |
| 33 | struct nl_msg; |
| 34 | struct nlattr; |
| 35 | |
| 36 | enum mtk_nl80211_vendor_subcmds { |
| 37 | MTK_NL80211_VENDOR_SUBCMD_CSI_CTRL = 0xc2, |
| 38 | }; |
| 39 | |
| 40 | enum mtk_vendor_attr_csi_ctrl { |
| 41 | MTK_VENDOR_ATTR_CSI_CTRL_UNSPEC, |
| 42 | |
| 43 | MTK_VENDOR_ATTR_CSI_CTRL_CFG, |
| 44 | MTK_VENDOR_ATTR_CSI_CTRL_CFG_MODE, |
| 45 | MTK_VENDOR_ATTR_CSI_CTRL_CFG_TYPE, |
| 46 | MTK_VENDOR_ATTR_CSI_CTRL_CFG_VAL1, |
| 47 | MTK_VENDOR_ATTR_CSI_CTRL_CFG_VAL2, |
| 48 | MTK_VENDOR_ATTR_CSI_CTRL_MAC_ADDR, |
| 49 | |
| 50 | MTK_VENDOR_ATTR_CSI_CTRL_DUMP_NUM, |
| 51 | |
| 52 | MTK_VENDOR_ATTR_CSI_CTRL_DATA, |
| 53 | |
| 54 | /* keep last */ |
| 55 | NUM_MTK_VENDOR_ATTRS_CSI_CTRL, |
| 56 | MTK_VENDOR_ATTR_CSI_CTRL_MAX = |
| 57 | NUM_MTK_VENDOR_ATTRS_CSI_CTRL - 1 |
| 58 | }; |
| 59 | |
| 60 | enum mtk_vendor_attr_csi_data { |
| 61 | MTK_VENDOR_ATTR_CSI_DATA_UNSPEC, |
| 62 | MTK_VENDOR_ATTR_CSI_DATA_PAD, |
| 63 | |
| 64 | MTK_VENDOR_ATTR_CSI_DATA_VER, |
| 65 | MTK_VENDOR_ATTR_CSI_DATA_TS, |
| 66 | MTK_VENDOR_ATTR_CSI_DATA_RSSI, |
| 67 | MTK_VENDOR_ATTR_CSI_DATA_SNR, |
| 68 | MTK_VENDOR_ATTR_CSI_DATA_BW, |
| 69 | MTK_VENDOR_ATTR_CSI_DATA_CH_IDX, |
| 70 | MTK_VENDOR_ATTR_CSI_DATA_TA, |
| 71 | MTK_VENDOR_ATTR_CSI_DATA_I, |
| 72 | MTK_VENDOR_ATTR_CSI_DATA_Q, |
| 73 | MTK_VENDOR_ATTR_CSI_DATA_INFO, |
| 74 | MTK_VENDOR_ATTR_CSI_DATA_RSVD1, |
| 75 | MTK_VENDOR_ATTR_CSI_DATA_RSVD2, |
| 76 | MTK_VENDOR_ATTR_CSI_DATA_RSVD3, |
| 77 | MTK_VENDOR_ATTR_CSI_DATA_RSVD4, |
| 78 | MTK_VENDOR_ATTR_CSI_DATA_TX_ANT, |
| 79 | MTK_VENDOR_ATTR_CSI_DATA_RX_ANT, |
| 80 | MTK_VENDOR_ATTR_CSI_DATA_MODE, |
| 81 | MTK_VENDOR_ATTR_CSI_DATA_H_IDX, |
| 82 | |
| 83 | /* keep last */ |
| 84 | NUM_MTK_VENDOR_ATTRS_CSI_DATA, |
| 85 | MTK_VENDOR_ATTR_CSI_DATA_MAX = |
| 86 | NUM_MTK_VENDOR_ATTRS_CSI_DATA - 1 |
| 87 | }; |
| 88 | |
| 89 | #define CSI_MAX_COUNT 256 |
| 90 | #define ETH_ALEN 6 |
| 91 | |
| 92 | struct csi_data { |
| 93 | s16 data_i[CSI_MAX_COUNT]; |
| 94 | s16 data_q[CSI_MAX_COUNT]; |
| 95 | s8 rssi; |
| 96 | u8 snr; |
| 97 | ktime_t ts; |
| 98 | u8 data_bw; |
| 99 | u8 pri_ch_idx; |
| 100 | u8 ta[ETH_ALEN]; |
| 101 | u32 info; |
| 102 | u8 rx_mode; |
| 103 | u32 h_idx; |
| 104 | u16 tx_idx; |
| 105 | u16 rx_idx; |
| 106 | }; |
| 107 | |
| 108 | struct vendor_field { |
| 109 | const char *name; |
| 110 | const char *prefix; |
| 111 | |
| 112 | bool (*parse)(const struct vendor_field *field, int idx, struct nl_msg *msg, |
| 113 | const char *val); |
| 114 | void (*print)(const struct vendor_field *field, struct nlattr *attr); |
| 115 | |
| 116 | union { |
| 117 | struct { |
| 118 | const char * const *enum_str; |
| 119 | int enum_len; |
| 120 | }; |
| 121 | struct { |
| 122 | bool (*parse2)(const struct vendor_field *field, int idx, |
| 123 | struct nl_msg *msg, const char *val); |
| 124 | void (*print2)(const struct vendor_field *field, |
| 125 | struct nlattr *attr); |
| 126 | }; |
| 127 | struct { |
| 128 | void (*print_extra)(const struct vendor_field *field, |
| 129 | struct nlattr **tb); |
| 130 | const struct vendor_field *fields; |
| 131 | struct nla_policy *policy; |
| 132 | int len; |
| 133 | }; |
| 134 | }; |
| 135 | }; |
| 136 | |
| 137 | extern struct unl unl; |
| 138 | extern const struct vendor_field msg_field; |
| 139 | |
| 140 | void usage(void); |
| 141 | |
| 142 | #endif |