developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame^] | 1 | From 248f4644bcfcf5701fb3ab576736091b6eb4f662 Mon Sep 17 00:00:00 2001 |
| 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Wed, 5 Jun 2024 22:10:24 +0800 |
| 4 | Subject: [PATCH 08/10] iw: add per-link txpower config |
| 5 | |
| 6 | Add per-link txpower config & info dump |
| 7 | |
| 8 | CR-Id: WCNCR00274293 |
| 9 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 10 | --- |
| 11 | ieee80211.h | 3 +++ |
| 12 | interface.c | 9 +++++++-- |
| 13 | phy.c | 38 ++++++++++++++++++++++++++------------ |
| 14 | 3 files changed, 36 insertions(+), 14 deletions(-) |
| 15 | |
| 16 | diff --git a/ieee80211.h b/ieee80211.h |
| 17 | index 3713a4d..c86984d 100644 |
| 18 | --- a/ieee80211.h |
| 19 | +++ b/ieee80211.h |
| 20 | @@ -75,4 +75,7 @@ struct ieee80211_vht_cap { |
| 21 | #define WLAN_CIPHER_SUITE_BIP_GMAC_256 SUITE(0x000FAC, 12) |
| 22 | #define WLAN_CIPHER_SUITE_BIP_CMAC_256 SUITE(0x000FAC, 13) |
| 23 | |
| 24 | +/* multi-link device */ |
| 25 | +#define IEEE80211_MLD_MAX_NUM_LINKS 15 |
| 26 | + |
| 27 | #endif /* __IEEE80211 */ |
| 28 | diff --git a/interface.c b/interface.c |
| 29 | index bb1a1d3..7a690fa 100644 |
| 30 | --- a/interface.c |
| 31 | +++ b/interface.c |
| 32 | @@ -406,6 +406,7 @@ static int print_iface_handler(struct nl_msg *msg, void *arg) |
| 33 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 34 | unsigned int *wiphy = arg; |
| 35 | const char *indent = ""; |
| 36 | + int32_t txp; |
| 37 | |
| 38 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 39 | genlmsg_attrlen(gnlh, 0), NULL); |
| 40 | @@ -449,8 +450,7 @@ static int print_iface_handler(struct nl_msg *msg, void *arg) |
| 41 | } |
| 42 | |
| 43 | if (tb_msg[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]) { |
| 44 | - int32_t txp = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]); |
| 45 | - |
| 46 | + txp = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]); |
| 47 | printf("%s\ttxpower %d.%.2d dBm\n", |
| 48 | indent, txp / 100, txp % 100); |
| 49 | } |
| 50 | @@ -490,6 +490,11 @@ static int print_iface_handler(struct nl_msg *msg, void *arg) |
| 51 | printf("\n%s\t ", indent); |
| 52 | print_channel(tb); |
| 53 | } |
| 54 | + if (tb[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]) { |
| 55 | + txp = nla_get_u32(tb[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]); |
| 56 | + printf("\n%s\t ", indent); |
| 57 | + printf("txpower %d.%.2d dBm", txp / 100, txp % 100); |
| 58 | + } |
| 59 | printf("\n"); |
| 60 | } |
| 61 | } |
| 62 | diff --git a/phy.c b/phy.c |
| 63 | index 584b103..f9a5b0f 100644 |
| 64 | --- a/phy.c |
| 65 | +++ b/phy.c |
| 66 | @@ -686,37 +686,51 @@ static int handle_txpower(struct nl80211_state *state, |
| 67 | enum id_input id) |
| 68 | { |
| 69 | enum nl80211_tx_power_setting type; |
| 70 | - int mbm; |
| 71 | + unsigned int link_id; |
| 72 | + int mbm, pos = 0; |
| 73 | + char *endptr; |
| 74 | |
| 75 | - /* get the required args */ |
| 76 | - if (argc != 1 && argc != 2) |
| 77 | + /* check args number */ |
| 78 | + if (argc < 1 && argc > 4) |
| 79 | return 1; |
| 80 | |
| 81 | - if (!strcmp(argv[0], "auto")) |
| 82 | + if (!strcmp(argv[0], "-l")) { |
| 83 | + link_id = strtol(argv[1], &endptr, 10); |
| 84 | + if (*endptr) |
| 85 | + return 1; |
| 86 | + |
| 87 | + if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) { |
| 88 | + printf("link id %d exceeds max number of links\n", link_id); |
| 89 | + return 2; |
| 90 | + } |
| 91 | + NLA_PUT_U8(msg, NL80211_ATTR_MLO_LINK_ID, link_id); |
| 92 | + pos += 2; |
| 93 | + } |
| 94 | + |
| 95 | + if (!strcmp(argv[pos], "auto")) |
| 96 | type = NL80211_TX_POWER_AUTOMATIC; |
| 97 | - else if (!strcmp(argv[0], "fixed")) |
| 98 | + else if (!strcmp(argv[pos], "fixed")) |
| 99 | type = NL80211_TX_POWER_FIXED; |
| 100 | - else if (!strcmp(argv[0], "limit")) |
| 101 | + else if (!strcmp(argv[pos], "limit")) |
| 102 | type = NL80211_TX_POWER_LIMITED; |
| 103 | else { |
| 104 | - printf("Invalid parameter: %s\n", argv[0]); |
| 105 | + printf("Invalid parameter: %s\n", argv[pos]); |
| 106 | return 2; |
| 107 | } |
| 108 | |
| 109 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_TX_POWER_SETTING, type); |
| 110 | |
| 111 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 112 | - char *endptr; |
| 113 | - if (argc != 2) { |
| 114 | + if (argc < 2 + pos) { |
| 115 | printf("Missing TX power level argument.\n"); |
| 116 | return 2; |
| 117 | } |
| 118 | |
| 119 | - mbm = strtol(argv[1], &endptr, 10); |
| 120 | + mbm = strtol(argv[pos + 1], &endptr, 10); |
| 121 | if (*endptr) |
| 122 | return 2; |
| 123 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, mbm); |
| 124 | - } else if (argc != 1) |
| 125 | + } else if (argc != 1 + pos) |
| 126 | return 1; |
| 127 | |
| 128 | return 0; |
| 129 | @@ -727,7 +741,7 @@ static int handle_txpower(struct nl80211_state *state, |
| 130 | COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]", |
| 131 | NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_txpower, |
| 132 | "Specify transmit power level and setting type."); |
| 133 | -COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]", |
| 134 | +COMMAND(set, txpower, "[-l <link_id>] <auto|fixed|limit> [<tx power in mBm>]", |
| 135 | NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_txpower, |
| 136 | "Specify transmit power level and setting type."); |
| 137 | |
| 138 | -- |
| 139 | 2.18.0 |
| 140 | |