developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 1 | From 221875eb77f21d8cf1c50f046705f30708ec82bd Mon Sep 17 00:00:00 2001 |
| 2 | From: Johannes Berg <johannes.berg@intel.com> |
| 3 | Date: Wed, 31 Aug 2022 22:35:02 +0200 |
| 4 | Subject: [PATCH 11/28] link: update for MLO |
| 5 | |
| 6 | In MLO we need to use the MLD address to get the station |
| 7 | statistics (which still need work for per-link stats), |
| 8 | adjust the code. |
| 9 | |
| 10 | Signed-off-by: Johannes Berg <johannes.berg@intel.com> |
| 11 | --- |
| 12 | iw.h | 2 ++ |
| 13 | link.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++----------- |
| 14 | scan.c | 3 ++- |
| 15 | 3 files changed, 55 insertions(+), 12 deletions(-) |
| 16 | |
| 17 | diff --git a/iw.h b/iw.h |
| 18 | index e712c59..45e4fbe 100644 |
| 19 | --- a/iw.h |
| 20 | +++ b/iw.h |
| 21 | @@ -242,6 +242,8 @@ const char *get_status_str(uint16_t status); |
| 22 | enum print_ie_type { |
| 23 | PRINT_SCAN, |
| 24 | PRINT_LINK, |
| 25 | + PRINT_LINK_MLO_MLD, |
| 26 | + PRINT_LINK_MLO_LINK, |
| 27 | }; |
| 28 | |
| 29 | #define BIT(x) (1ULL<<(x)) |
| 30 | diff --git a/link.c b/link.c |
| 31 | index 31de8b4..a090100 100644 |
| 32 | --- a/link.c |
| 33 | +++ b/link.c |
| 34 | @@ -13,9 +13,10 @@ |
| 35 | #include "iw.h" |
| 36 | |
| 37 | struct link_result { |
| 38 | - uint8_t bssid[8]; |
| 39 | + uint8_t sta_addr[8]; |
| 40 | bool link_found; |
| 41 | bool anything_found; |
| 42 | + bool mld; |
| 43 | }; |
| 44 | |
| 45 | static struct link_result lr = { .link_found = false }; |
| 46 | @@ -37,7 +38,9 @@ static int link_bss_handler(struct nl_msg *msg, void *arg) |
| 47 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 48 | }; |
| 49 | struct link_result *result = arg; |
| 50 | - char mac_addr[20], dev[20]; |
| 51 | + char mac_addr[20], dev[20], link_addr[20]; |
| 52 | + int link_id = -1; |
| 53 | + const char *indent = "\t"; |
| 54 | |
| 55 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 56 | genlmsg_attrlen(gnlh, 0), NULL); |
| 57 | @@ -62,9 +65,44 @@ static int link_bss_handler(struct nl_msg *msg, void *arg) |
| 58 | mac_addr_n2a(mac_addr, nla_data(bss[NL80211_BSS_BSSID])); |
| 59 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); |
| 60 | |
| 61 | + if (bss[NL80211_BSS_MLO_LINK_ID]) |
| 62 | + link_id = nla_get_u8(bss[NL80211_BSS_MLO_LINK_ID]); |
| 63 | + |
| 64 | + if (bss[NL80211_BSS_MLD_ADDR]) { |
| 65 | + mac_addr_n2a(link_addr, nla_data(bss[NL80211_BSS_BSSID])); |
| 66 | + indent = "\t\t"; |
| 67 | + |
| 68 | + if (result->mld) { |
| 69 | + if (memcmp(result->sta_addr, |
| 70 | + nla_data(bss[NL80211_BSS_MLD_ADDR]), 6)) { |
| 71 | + mac_addr_n2a(mac_addr, nla_data(bss[NL80211_BSS_MLD_ADDR])); |
| 72 | + printf("!! inconsistent MLD address information (%s)\n", |
| 73 | + mac_addr); |
| 74 | + } |
| 75 | + } else { |
| 76 | + mac_addr_n2a(mac_addr, nla_data(bss[NL80211_BSS_MLD_ADDR])); |
| 77 | + result->mld = true; |
| 78 | + memcpy(result->sta_addr, |
| 79 | + nla_data(bss[NL80211_BSS_MLD_ADDR]), 6); |
| 80 | + if (nla_get_u32(bss[NL80211_BSS_STATUS]) == NL80211_BSS_STATUS_ASSOCIATED) { |
| 81 | + printf("Connected to %s (on %s)\n", mac_addr, dev); |
| 82 | + } |
| 83 | + |
| 84 | + if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) |
| 85 | + print_ies(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]), |
| 86 | + nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), |
| 87 | + false, PRINT_LINK_MLO_MLD); |
| 88 | + } |
| 89 | + } else { |
| 90 | + memcpy(result->sta_addr, nla_data(bss[NL80211_BSS_BSSID]), 6); |
| 91 | + } |
| 92 | + |
| 93 | switch (nla_get_u32(bss[NL80211_BSS_STATUS])) { |
| 94 | case NL80211_BSS_STATUS_ASSOCIATED: |
| 95 | - printf("Connected to %s (on %s)\n", mac_addr, dev); |
| 96 | + if (result->mld) |
| 97 | + printf("\tLink %d BSSID %s\n", link_id, link_addr); |
| 98 | + else |
| 99 | + printf("Connected to %s (on %s)\n", mac_addr, dev); |
| 100 | break; |
| 101 | case NL80211_BSS_STATUS_AUTHENTICATED: |
| 102 | printf("Authenticated with %s (on %s)\n", mac_addr, dev); |
| 103 | @@ -81,10 +119,10 @@ static int link_bss_handler(struct nl_msg *msg, void *arg) |
| 104 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) |
| 105 | print_ies(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]), |
| 106 | nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), |
| 107 | - false, PRINT_LINK); |
| 108 | + false, result->mld ? PRINT_LINK_MLO_LINK : PRINT_LINK); |
| 109 | |
| 110 | if (bss[NL80211_BSS_FREQUENCY]) |
| 111 | - printf("\tfreq: %d\n", |
| 112 | + printf("%sfreq: %d\n", indent, |
| 113 | nla_get_u32(bss[NL80211_BSS_FREQUENCY])); |
| 114 | |
| 115 | if (nla_get_u32(bss[NL80211_BSS_STATUS]) != NL80211_BSS_STATUS_ASSOCIATED) |
| 116 | @@ -92,7 +130,6 @@ static int link_bss_handler(struct nl_msg *msg, void *arg) |
| 117 | |
| 118 | /* only in the assoc case do we want more info from station get */ |
| 119 | result->link_found = true; |
| 120 | - memcpy(result->bssid, nla_data(bss[NL80211_BSS_BSSID]), 6); |
| 121 | return NL_SKIP; |
| 122 | } |
| 123 | |
| 124 | @@ -250,7 +287,7 @@ static int handle_link(struct nl80211_state *state, |
| 125 | NULL, |
| 126 | NULL, |
| 127 | }; |
| 128 | - char bssid_buf[3*6]; |
| 129 | + char addr_buf[3*6]; |
| 130 | int err; |
| 131 | |
| 132 | link_argv[0] = argv[0]; |
| 133 | @@ -264,15 +301,18 @@ static int handle_link(struct nl80211_state *state, |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | - mac_addr_n2a(bssid_buf, lr.bssid); |
| 138 | - bssid_buf[17] = '\0'; |
| 139 | + mac_addr_n2a(addr_buf, lr.sta_addr); |
| 140 | + addr_buf[17] = '\0'; |
| 141 | + |
| 142 | + if (lr.mld) |
| 143 | + printf("MLD %s stats:\n", addr_buf); |
| 144 | |
| 145 | station_argv[0] = argv[0]; |
| 146 | - station_argv[3] = bssid_buf; |
| 147 | + station_argv[3] = addr_buf; |
| 148 | return handle_cmd(state, id, 4, station_argv); |
| 149 | } |
| 150 | TOPLEVEL(link, NULL, 0, 0, CIB_NETDEV, handle_link, |
| 151 | - "Print information about the current link, if any."); |
| 152 | + "Print information about the current connection, if any."); |
| 153 | HIDDEN(link, get_sta, "<mac-addr>", NL80211_CMD_GET_STATION, 0, |
| 154 | CIB_NETDEV, handle_link_sta); |
| 155 | HIDDEN(link, get_bss, NULL, NL80211_CMD_GET_SCAN, NLM_F_DUMP, |
| 156 | diff --git a/scan.c b/scan.c |
| 157 | index 4c67c87..dc26787 100644 |
| 158 | --- a/scan.c |
| 159 | +++ b/scan.c |
| 160 | @@ -1717,7 +1717,8 @@ static void print_ie(const struct ie_print *p, const uint8_t type, uint8_t len, |
| 161 | } |
| 162 | |
| 163 | static const struct ie_print ieprinters[] = { |
| 164 | - [0] = { "SSID", print_ssid, 0, 32, BIT(PRINT_SCAN) | BIT(PRINT_LINK), }, |
| 165 | + [0] = { "SSID", print_ssid, 0, 32, |
| 166 | + BIT(PRINT_SCAN) | BIT(PRINT_LINK) | BIT(PRINT_LINK_MLO_MLD), }, |
| 167 | [1] = { "Supported rates", print_supprates, 0, 255, BIT(PRINT_SCAN), }, |
| 168 | [3] = { "DS Parameter set", print_ds, 1, 1, BIT(PRINT_SCAN), }, |
| 169 | [5] = { "TIM", print_tim, 4, 255, BIT(PRINT_SCAN), }, |
| 170 | -- |
| 171 | 2.39.2 |
| 172 | |