developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 1 | From ecfbe0e44f98de44dc7a1e3d8566cf9eb9987458 Mon Sep 17 00:00:00 2001 |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Thu, 13 Jun 2024 16:48:00 +0800 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 12/13] iw: add per-radio antenna config |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 5 | |
| 6 | Add per-radio antenna config & info dump |
| 7 | Currently, there is no radio index or supported band bitmap in wiphy data struct |
| 8 | & NL80211 ATTRS. |
| 9 | Therefore, we just use NL80211_BANDS_XX to specify the radio we desire |
| 10 | to config. |
| 11 | |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 12 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 13 | --- |
| 14 | info.c | 49 +++++++++++++++++++++++++++++++++++++++++-------- |
| 15 | phy.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- |
| 16 | 2 files changed, 81 insertions(+), 18 deletions(-) |
| 17 | |
| 18 | diff --git a/info.c b/info.c |
| 19 | index c5e863f..ddfef67 100644 |
| 20 | --- a/info.c |
| 21 | +++ b/info.c |
| 22 | @@ -335,6 +335,14 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) |
| 23 | static int last_band = -1; |
| 24 | static bool band_had_freq = false; |
| 25 | bool print_name = true; |
| 26 | + static const char * const bands[] = { |
| 27 | + [NL80211_BAND_2GHZ] = "2G", |
| 28 | + [NL80211_BAND_5GHZ] = "5G", |
| 29 | + [NL80211_BAND_60GHZ] = "60G", |
| 30 | + [NL80211_BAND_6GHZ] = "6G", |
| 31 | + [NL80211_BAND_S1GHZ] = "S1G", |
| 32 | + [NL80211_BAND_LC] = "LC", |
| 33 | + }; |
| 34 | |
| 35 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 36 | genlmsg_attrlen(gnlh, 0), NULL); |
| 37 | @@ -540,16 +548,41 @@ next: |
| 38 | } |
| 39 | |
| 40 | if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX] && |
| 41 | - tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]) |
| 42 | - printf("\tAvailable Antennas: TX %#x RX %#x\n", |
| 43 | - nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]), |
| 44 | - nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX])); |
| 45 | + tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]) { |
| 46 | + int i, tx_num, rx_num; |
| 47 | + __u32 *avail_ants_tx, *avail_ants_rx; |
| 48 | + |
| 49 | + tx_num = nla_len(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]) / sizeof(__u32); |
| 50 | + rx_num = nla_len(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]) / sizeof(__u32); |
| 51 | + if (tx_num == rx_num && tx_num == NUM_NL80211_BANDS) { |
| 52 | + avail_ants_tx = nla_data(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]); |
| 53 | + avail_ants_rx = nla_data(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]); |
| 54 | + printf("\tAvailable Antennas:\n"); |
| 55 | + for (i = 0; i < tx_num; i++) |
| 56 | + if (avail_ants_tx[i] && avail_ants_rx[i]) |
| 57 | + printf("\t\t%s band: TX %#x RX %#x\n", |
| 58 | + bands[i], avail_ants_tx[i], |
| 59 | + avail_ants_rx[i]); |
| 60 | + } |
| 61 | + } |
| 62 | |
| 63 | if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 64 | - tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]) |
| 65 | - printf("\tConfigured Antennas: TX %#x RX %#x\n", |
| 66 | - nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]), |
| 67 | - nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX])); |
| 68 | + tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 69 | + int i, tx_num, rx_num; |
| 70 | + __u32 *ants_tx, *ants_rx; |
| 71 | + |
| 72 | + tx_num = nla_len(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]) / sizeof(__u32); |
| 73 | + rx_num = nla_len(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]) / sizeof(__u32); |
| 74 | + if (tx_num == rx_num && tx_num == NUM_NL80211_BANDS) { |
| 75 | + ants_tx = nla_data(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 76 | + ants_rx = nla_data(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 77 | + printf("\tConfigured Antennas:\n"); |
| 78 | + for (i = 0; i < tx_num; i++) |
| 79 | + if (ants_tx[i] && ants_rx[i]) |
| 80 | + printf("\t\t%s band: TX %#x RX %#x\n", |
| 81 | + bands[i], ants_tx[i], ants_rx[i]); |
| 82 | + } |
| 83 | + } |
| 84 | |
| 85 | if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) |
| 86 | print_iftype_list("\tSupported interface modes", "\t\t", |
| 87 | diff --git a/phy.c b/phy.c |
| 88 | index f9a5b0f..594fb25 100644 |
| 89 | --- a/phy.c |
| 90 | +++ b/phy.c |
| 91 | @@ -752,34 +752,64 @@ static int handle_antenna(struct nl80211_state *state, |
| 92 | { |
| 93 | char *end; |
| 94 | uint32_t tx_ant = 0, rx_ant = 0; |
| 95 | + uint32_t tx_ants[NUM_NL80211_BANDS], rx_ants[NUM_NL80211_BANDS]; |
| 96 | + int i = 0, bands = 0xffffffff; |
| 97 | + |
| 98 | + if (!strncmp(argv[0], "-b", 2)) { |
| 99 | + bands = 0; |
| 100 | + for (i = 1; i < argc; i++) { |
| 101 | + if (!strncasecmp("2ghz", argv[i], 4)) |
| 102 | + bands |= BIT(NL80211_BAND_2GHZ); |
| 103 | + else if (!strncasecmp("5ghz", argv[i], 4)) |
| 104 | + bands |= BIT(NL80211_BAND_5GHZ); |
| 105 | + else if (!strncasecmp("6ghz", argv[i], 4)) |
| 106 | + bands |= BIT(NL80211_BAND_6GHZ); |
| 107 | + else |
| 108 | + break; |
| 109 | + } |
| 110 | + |
| 111 | + if (i == 1) { |
| 112 | + printf("Missing configured bands argument.\n"); |
| 113 | + return 2; |
| 114 | + } |
| 115 | + } |
| 116 | |
| 117 | - if (argc == 1 && strcmp(argv[0], "all") == 0) { |
| 118 | + if (argc == 1 + i && strncmp(argv[i], "all", 3) == 0) { |
| 119 | tx_ant = 0xffffffff; |
| 120 | rx_ant = 0xffffffff; |
| 121 | - } else if (argc == 1) { |
| 122 | - tx_ant = rx_ant = strtoul(argv[0], &end, 0); |
| 123 | + } else if (argc == 1 + i) { |
| 124 | + tx_ant = rx_ant = strtoul(argv[i], &end, 0); |
| 125 | if (*end) |
| 126 | return 1; |
| 127 | - } |
| 128 | - else if (argc == 2) { |
| 129 | - tx_ant = strtoul(argv[0], &end, 0); |
| 130 | + } else if (argc == 2 + i) { |
| 131 | + tx_ant = strtoul(argv[i], &end, 0); |
| 132 | if (*end) |
| 133 | return 1; |
| 134 | - rx_ant = strtoul(argv[1], &end, 0); |
| 135 | + rx_ant = strtoul(argv[i + 1], &end, 0); |
| 136 | if (*end) |
| 137 | return 1; |
| 138 | } else |
| 139 | return 1; |
| 140 | |
| 141 | - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 142 | - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 143 | + memset(tx_ants, 0, sizeof(tx_ants)); |
| 144 | + memset(rx_ants, 0, sizeof(rx_ants)); |
| 145 | + for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 146 | + if (!(bands & BIT(i))) |
| 147 | + continue; |
| 148 | + |
| 149 | + tx_ants[i] = tx_ant; |
| 150 | + rx_ants[i] = rx_ant; |
| 151 | + } |
| 152 | + |
| 153 | + NLA_PUT(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, sizeof(tx_ants), tx_ants); |
| 154 | + NLA_PUT(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, sizeof(rx_ants), rx_ants); |
| 155 | |
| 156 | return 0; |
| 157 | |
| 158 | nla_put_failure: |
| 159 | return -ENOBUFS; |
| 160 | } |
| 161 | -COMMAND(set, antenna, "<bitmap> | all | <tx bitmap> <rx bitmap>", |
| 162 | +COMMAND(set, antenna, "[-b [2GHz] [5GHz] [6GHz]] <bitmap> | all | <tx bitmap> <rx bitmap>", |
| 163 | NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_antenna, |
| 164 | "Set a bitmap of allowed antennas to use for TX and RX.\n" |
| 165 | "The driver may reject antenna configurations it cannot support."); |
| 166 | -- |
| 167 | 2.18.0 |
| 168 | |