abdd6381c03134b4317d809b42d0c28e0acf4db6
[openwrt.git] / package / iw / patches / 120-per_chain_signal_strength.patch
1 --- a/station.c
2 +++ b/station.c
3 @@ -61,6 +61,31 @@ static void print_sta_bitrate(struct nla
4         }
5  }
6  
7 +static char *get_chain_signal(struct nlattr *attr_list)
8 +{
9 +       struct nlattr *attr;
10 +       static char buf[64];
11 +       char *cur = buf;
12 +       int i = 0, rem;
13 +       const char *prefix;
14 +
15 +       if (!attr_list)
16 +               return "";
17 +
18 +       nla_for_each_nested(attr, attr_list, rem) {
19 +               if (i++ > 0)
20 +                       prefix = ", ";
21 +               else
22 +                       prefix = "[";
23 +
24 +               cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix,
25 +                               (int8_t) nla_get_u8(attr));
26 +       }
27 +       snprintf(cur, sizeof(buf) - (cur - buf), "] ");
28 +
29 +       return buf;
30 +}
31 +
32  static int print_sta_handler(struct nl_msg *msg, void *arg)
33  {
34         struct nlattr *tb[NL80211_ATTR_MAX + 1];
35 @@ -81,7 +106,10 @@ static int print_sta_handler(struct nl_m
36                 [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 },
37                 [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 },
38                 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
39 +               [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED },
40 +               [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED },
41         };
42 +       char *chain;
43  
44         nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
45                   genlmsg_attrlen(gnlh, 0), NULL);
46 @@ -128,12 +156,18 @@ static int print_sta_handler(struct nl_m
47         if (sinfo[NL80211_STA_INFO_TX_FAILED])
48                 printf("\n\ttx failed:\t%u",
49                         nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED]));
50 +
51 +       chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]);
52         if (sinfo[NL80211_STA_INFO_SIGNAL])
53 -               printf("\n\tsignal:  \t%d dBm",
54 -                       (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]));
55 +               printf("\n\tsignal:  \t%d %sdBm",
56 +                       (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]),
57 +                       chain);
58 +
59 +       chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]);
60         if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
61 -               printf("\n\tsignal avg:\t%d dBm",
62 -                       (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]));
63 +               printf("\n\tsignal avg:\t%d %sdBm",
64 +                       (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]),
65 +                       chain);
66  
67         print_sta_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], "tx bitrate");
68         print_sta_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], "rx bitrate");