developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 1 | From 7794573f915174b5dd2cd22e123ecd63610ccf44 Mon Sep 17 00:00:00 2001 |
| 2 | From: Johannes Berg <johannes.berg@intel.com> |
| 3 | Date: Fri, 2 Sep 2022 21:59:31 +0200 |
| 4 | Subject: [PATCH 12/28] interface: print links |
| 5 | |
| 6 | Print link information in 'iw dev' and 'iw ... info'. |
| 7 | |
| 8 | Signed-off-by: Johannes Berg <johannes.berg@intel.com> |
| 9 | --- |
| 10 | interface.c | 74 ++++++++++++++++++++++++++++++++++++++--------------- |
| 11 | 1 file changed, 53 insertions(+), 21 deletions(-) |
| 12 | |
| 13 | diff --git a/interface.c b/interface.c |
| 14 | index 84990c9..7e1dd58 100644 |
| 15 | --- a/interface.c |
| 16 | +++ b/interface.c |
| 17 | @@ -369,6 +369,30 @@ char *channel_width_name(enum nl80211_chan_width width) |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | +static void print_channel(struct nlattr **tb) |
| 22 | +{ |
| 23 | + uint32_t freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 24 | + |
| 25 | + printf("channel %d (%d MHz)", |
| 26 | + ieee80211_frequency_to_channel(freq), freq); |
| 27 | + |
| 28 | + if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 29 | + printf(", width: %s", |
| 30 | + channel_width_name(nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]))); |
| 31 | + if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 32 | + printf(", center1: %d MHz", |
| 33 | + nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1])); |
| 34 | + if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 35 | + printf(", center2: %d MHz", |
| 36 | + nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2])); |
| 37 | + } else if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 38 | + enum nl80211_channel_type channel_type; |
| 39 | + |
| 40 | + channel_type = nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 41 | + printf(" %s", channel_type_name(channel_type)); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | static int print_iface_handler(struct nl_msg *msg, void *arg) |
| 46 | { |
| 47 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 48 | @@ -412,27 +436,8 @@ static int print_iface_handler(struct nl_msg *msg, void *arg) |
| 49 | if (!wiphy && tb_msg[NL80211_ATTR_WIPHY]) |
| 50 | printf("%s\twiphy %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY])); |
| 51 | if (tb_msg[NL80211_ATTR_WIPHY_FREQ]) { |
| 52 | - uint32_t freq = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FREQ]); |
| 53 | - |
| 54 | - printf("%s\tchannel %d (%d MHz)", indent, |
| 55 | - ieee80211_frequency_to_channel(freq), freq); |
| 56 | - |
| 57 | - if (tb_msg[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 58 | - printf(", width: %s", |
| 59 | - channel_width_name(nla_get_u32(tb_msg[NL80211_ATTR_CHANNEL_WIDTH]))); |
| 60 | - if (tb_msg[NL80211_ATTR_CENTER_FREQ1]) |
| 61 | - printf(", center1: %d MHz", |
| 62 | - nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ1])); |
| 63 | - if (tb_msg[NL80211_ATTR_CENTER_FREQ2]) |
| 64 | - printf(", center2: %d MHz", |
| 65 | - nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ2])); |
| 66 | - } else if (tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 67 | - enum nl80211_channel_type channel_type; |
| 68 | - |
| 69 | - channel_type = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 70 | - printf(" %s", channel_type_name(channel_type)); |
| 71 | - } |
| 72 | - |
| 73 | + printf("%s\t", indent); |
| 74 | + print_channel(tb_msg); |
| 75 | printf("\n"); |
| 76 | } |
| 77 | |
| 78 | @@ -455,6 +460,33 @@ static int print_iface_handler(struct nl_msg *msg, void *arg) |
| 79 | printf("%s\t4addr: on\n", indent); |
| 80 | } |
| 81 | |
| 82 | + if (tb_msg[NL80211_ATTR_MLO_LINKS]) { |
| 83 | + struct nlattr *link; |
| 84 | + int n; |
| 85 | + |
| 86 | + printf("%s\tMLD with links:\n", indent); |
| 87 | + |
| 88 | + nla_for_each_nested(link, tb_msg[NL80211_ATTR_MLO_LINKS], n) { |
| 89 | + struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 90 | + |
| 91 | + nla_parse_nested(tb, NL80211_ATTR_MAX, link, NULL); |
| 92 | + printf("%s\t - link", indent); |
| 93 | + if (tb[NL80211_ATTR_MLO_LINK_ID]) |
| 94 | + printf(" ID %2d", nla_get_u32(tb[NL80211_ATTR_MLO_LINK_ID])); |
| 95 | + if (tb[NL80211_ATTR_MAC]) { |
| 96 | + char buf[20]; |
| 97 | + |
| 98 | + mac_addr_n2a(buf, nla_data(tb[NL80211_ATTR_MAC])); |
| 99 | + printf(" link addr %s", buf); |
| 100 | + } |
| 101 | + if (tb[NL80211_ATTR_WIPHY_FREQ]) { |
| 102 | + printf("\n%s\t ", indent); |
| 103 | + print_channel(tb); |
| 104 | + } |
| 105 | + printf("\n"); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | return NL_SKIP; |
| 110 | } |
| 111 | |
| 112 | -- |
| 113 | 2.39.2 |
| 114 | |