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