From: Rameshkumar Sundaram <quic_ramess@xxxxxxxxxxx> Currently, setting transmit power changes the transmit power for all radios in a wiphy. But different radios in a wiphy can have different transmit power requirements. Modify the iw command to handle this. This will ensure that the legacy userspace will interact with traditional drivers as well as multi-radio wiphy drivers. In order to be able to set transmit power for a particular radio from user space, without disturbing the other radios in a wiphy, pass the radio id for which the transmit power needs to be changed and its transmit power value. The valid radio id values can be checked in iw phy#XXX info, under "Supported wiphy radios". Signed-off-by: Rameshkumar Sundaram <quic_ramess@xxxxxxxxxxx> Signed-off-by: Roopni Devanathan <quic_rdevanat@xxxxxxxxxxx> --- phy.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/phy.c b/phy.c index 890966d..bd7194d 100644 --- a/phy.c +++ b/phy.c @@ -727,20 +727,37 @@ static int handle_txpower(struct nl80211_state *state, enum id_input id) { enum nl80211_tx_power_setting type; - int mbm; + int mbm, i = 0; /* get the required args */ - if (argc != 1 && argc != 2) + if (argc > 4) return 1; - if (!strcmp(argv[0], "auto")) + /* check if radio idx is provided */ + if (argc >= 2 && !strcmp(argv[0], "radio")) { + unsigned int radio_id; + char *endptr; + + radio_id = strtoul(argv[1], &endptr, 10); + if (*endptr) + return 1; + + NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RADIO_INDEX, radio_id); + i = 2; + } + + /* check the required args without radio id */ + if ((argc - i) != 1 && (argc - i) != 2) + return 1; + + if (!strcmp(argv[i], "auto")) { type = NL80211_TX_POWER_AUTOMATIC; - else if (!strcmp(argv[0], "fixed")) + } else if (!strcmp(argv[i], "fixed")) { type = NL80211_TX_POWER_FIXED; - else if (!strcmp(argv[0], "limit")) + } else if (!strcmp(argv[i], "limit")) { type = NL80211_TX_POWER_LIMITED; - else { - printf("Invalid parameter: %s\n", argv[0]); + } else { + printf("Invalid parameter: %s\n", argv[i]); return 2; } @@ -748,16 +765,16 @@ static int handle_txpower(struct nl80211_state *state, if (type != NL80211_TX_POWER_AUTOMATIC) { char *endptr; - if (argc != 2) { + if ((argc - i) != 2) { printf("Missing TX power level argument.\n"); return 2; } - mbm = strtol(argv[1], &endptr, 10); + mbm = strtol(argv[++i], &endptr, 10); if (*endptr) return 2; NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, mbm); - } else if (argc != 1) + } else if ((argc - i) != 1) return 1; return 0; @@ -765,7 +782,7 @@ static int handle_txpower(struct nl80211_state *state, nla_put_failure: return -ENOBUFS; } -COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]", +COMMAND(set, txpower, "[radio <radio idx>] <auto|fixed|limit> [<tx power in mBm>]", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_txpower, "Specify transmit power level and setting type."); COMMAND(set, txpower, "<auto|fixed|limit> [<tx power in mBm>]", -- 2.34.1