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