developer | 20d6771 | 2022-03-02 14:09:32 +0800 | [diff] [blame] | 1 | From ce9be27dcc763b3a9b399dfe8f62ee1c0fed9734 Mon Sep 17 00:00:00 2001 |
| 2 | From: Shayne Chen <shayne.chen@mediatek.com> |
| 3 | Date: Fri, 4 Feb 2022 21:35:14 +0800 |
| 4 | Subject: [PATCH 1111/1112] mt76: tool: add more commands |
| 5 | |
| 6 | --- |
| 7 | .../net/wireless/mediatek/mt76/tools/fields.c | 76 +++++++++++++++++++ |
| 8 | 1 file changed, 76 insertions(+) |
| 9 | |
| 10 | diff --git a/tools/fields.c b/tools/fields.c |
| 11 | index e3f6908..036406c 100644 |
| 12 | --- a/tools/fields.c |
| 13 | +++ b/tools/fields.c |
| 14 | @@ -10,6 +10,7 @@ static const char * const testmode_state[] = { |
| 15 | [MT76_TM_STATE_IDLE] = "idle", |
| 16 | [MT76_TM_STATE_TX_FRAMES] = "tx_frames", |
| 17 | [MT76_TM_STATE_RX_FRAMES] = "rx_frames", |
| 18 | + [MT76_TM_STATE_TX_CONT] = "tx_cont", |
| 19 | }; |
| 20 | |
| 21 | static const char * const testmode_tx_mode[] = { |
| 22 | @@ -201,6 +202,63 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb) |
| 23 | printf("%srx_per=%.02f%%\n", prefix, 100 * failed / total); |
| 24 | } |
| 25 | |
| 26 | +static bool parse_mac(const struct tm_field *field, int idx, |
| 27 | + struct nl_msg *msg, const char *val) |
| 28 | +{ |
| 29 | +#define ETH_ALEN 6 |
| 30 | + bool ret = true; |
| 31 | + char *str, *cur, *ap; |
| 32 | + void *a; |
| 33 | + |
| 34 | + ap = str = strdup(val); |
| 35 | + |
| 36 | + a = nla_nest_start(msg, idx); |
| 37 | + |
| 38 | + idx = 0; |
| 39 | + while ((cur = strsep(&ap, ",")) != NULL) { |
| 40 | + unsigned char addr[ETH_ALEN]; |
| 41 | + char *val, *tmp = cur; |
| 42 | + int i = 0; |
| 43 | + |
| 44 | + while ((val = strsep(&tmp, ":")) != NULL) { |
| 45 | + if (i >= ETH_ALEN) |
| 46 | + break; |
| 47 | + |
| 48 | + addr[i++] = strtoul(val, NULL, 16); |
| 49 | + } |
| 50 | + |
| 51 | + nla_put(msg, idx, ETH_ALEN, addr); |
| 52 | + |
| 53 | + idx++; |
| 54 | + } |
| 55 | + |
| 56 | + nla_nest_end(msg, a); |
| 57 | + |
| 58 | + free(str); |
| 59 | + |
| 60 | + return ret; |
| 61 | +} |
| 62 | + |
| 63 | +static void print_mac(const struct tm_field *field, struct nlattr *attr) |
| 64 | +{ |
| 65 | +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] |
| 66 | +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" |
| 67 | + unsigned char addr[3][6]; |
| 68 | + struct nlattr *cur; |
| 69 | + int idx = 0; |
| 70 | + int rem; |
| 71 | + |
| 72 | + nla_for_each_nested(cur, attr, rem) { |
| 73 | + if (nla_len(cur) != 6) |
| 74 | + continue; |
| 75 | + memcpy(addr[idx++], nla_data(cur), 6); |
| 76 | + } |
| 77 | + |
| 78 | + printf("" MACSTR "," MACSTR "," MACSTR "", |
| 79 | + MAC2STR(addr[0]), MAC2STR(addr[1]), MAC2STR(addr[2])); |
| 80 | + |
| 81 | + return; |
| 82 | +} |
| 83 | |
| 84 | #define FIELD_GENERIC(_field, _name, ...) \ |
| 85 | [FIELD_NAME(_field)] = { \ |
| 86 | @@ -250,6 +308,13 @@ static void print_extra_stats(const struct tm_field *field, struct nlattr **tb) |
| 87 | ##__VA_ARGS__ \ |
| 88 | ) |
| 89 | |
| 90 | +#define FIELD_MAC(_field, _name) \ |
| 91 | + [FIELD_NAME(_field)] = { \ |
| 92 | + .name = _name, \ |
| 93 | + .parse = parse_mac, \ |
| 94 | + .print = print_mac \ |
| 95 | + } |
| 96 | + |
| 97 | #define FIELD_NAME(_field) MT76_TM_RX_ATTR_##_field |
| 98 | static const struct tm_field rx_fields[NUM_MT76_TM_RX_ATTRS] = { |
| 99 | FIELD_RO(s32, FREQ_OFFSET, "freq_offset"), |
| 100 | @@ -300,10 +365,16 @@ static const struct tm_field testdata_fields[NUM_MT76_TM_ATTRS] = { |
| 101 | FIELD(u8, TX_RATE_LDPC, "tx_rate_ldpc"), |
| 102 | FIELD(u8, TX_RATE_STBC, "tx_rate_stbc"), |
| 103 | FIELD(u8, TX_LTF, "tx_ltf"), |
| 104 | + FIELD(u8, TX_DUTY_CYCLE, "tx_duty_cycle"), |
| 105 | + FIELD(u32, TX_IPG, "tx_ipg"), |
| 106 | + FIELD(u32, TX_TIME, "tx_time"), |
| 107 | FIELD(u8, TX_POWER_CONTROL, "tx_power_control"), |
| 108 | FIELD_ARRAY(u8, TX_POWER, "tx_power"), |
| 109 | FIELD(u8, TX_ANTENNA, "tx_antenna"), |
| 110 | + FIELD(u8, TX_SPE_IDX, "tx_spe_idx"), |
| 111 | FIELD(u32, FREQ_OFFSET, "freq_offset"), |
| 112 | + FIELD(u8, AID, "aid"), |
| 113 | + FIELD_MAC(MAC_ADDRS, "mac_addrs"), |
| 114 | FIELD_NESTED_RO(STATS, stats, "", |
| 115 | .print_extra = print_extra_stats), |
| 116 | }; |
| 117 | @@ -322,9 +393,14 @@ static struct nla_policy testdata_policy[NUM_MT76_TM_ATTRS] = { |
| 118 | [MT76_TM_ATTR_TX_RATE_LDPC] = { .type = NLA_U8 }, |
| 119 | [MT76_TM_ATTR_TX_RATE_STBC] = { .type = NLA_U8 }, |
| 120 | [MT76_TM_ATTR_TX_LTF] = { .type = NLA_U8 }, |
| 121 | + [MT76_TM_ATTR_TX_DUTY_CYCLE] = { .type = NLA_U8 }, |
| 122 | + [MT76_TM_ATTR_TX_IPG] = { .type = NLA_U32 }, |
| 123 | + [MT76_TM_ATTR_TX_TIME] = { .type = NLA_U32 }, |
| 124 | [MT76_TM_ATTR_TX_POWER_CONTROL] = { .type = NLA_U8 }, |
| 125 | [MT76_TM_ATTR_TX_ANTENNA] = { .type = NLA_U8 }, |
| 126 | + [MT76_TM_ATTR_TX_SPE_IDX] = { .type = NLA_U8 }, |
| 127 | [MT76_TM_ATTR_FREQ_OFFSET] = { .type = NLA_U32 }, |
| 128 | + [MT76_TM_ATTR_AID] = { .type = NLA_U8 }, |
| 129 | [MT76_TM_ATTR_STATS] = { .type = NLA_NESTED }, |
| 130 | }; |
| 131 | |
| 132 | -- |
| 133 | 2.25.1 |
| 134 | |