6 #include <netlink/genl/genl.h>
7 #include <netlink/genl/family.h>
8 #include <netlink/genl/ctrl.h>
9 #include <netlink/msg.h>
10 #include <netlink/attr.h>
15 static int handle_name(struct nl80211_state
*state
,
18 int argc
, char **argv
,
24 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, *argv
);
30 COMMAND(set
, name
, "<new name>", NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_name
,
31 "Rename this wireless device.");
33 static int handle_freqchan(struct nl_msg
*msg
, bool chan
,
34 int argc
, char **argv
)
41 { .name
= "HT20", .val
= NL80211_CHAN_HT20
, },
42 { .name
= "HT40+", .val
= NL80211_CHAN_HT40PLUS
, },
43 { .name
= "HT40-", .val
= NL80211_CHAN_HT40MINUS
, },
45 unsigned int htval
= NL80211_CHAN_NO_HT
;
49 if (!argc
|| argc
> 2)
53 for (i
= 0; i
< ARRAY_SIZE(htmap
); i
++) {
54 if (strcasecmp(htmap
[i
].name
, argv
[1]) == 0) {
59 if (htval
== NL80211_CHAN_NO_HT
)
65 freq
= strtoul(argv
[0], &end
, 10);
70 freq
= ieee80211_channel_to_frequency(freq
);
72 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
73 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, htval
);
80 static int handle_freq(struct nl80211_state
*state
,
81 struct nl_cb
*cb
, struct nl_msg
*msg
,
82 int argc
, char **argv
,
85 return handle_freqchan(msg
, false, argc
, argv
);
87 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
88 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_freq
,
89 "Set frequency/channel the hardware is using, including HT\n"
91 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
92 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_freq
, NULL
);
94 static int handle_chan(struct nl80211_state
*state
,
95 struct nl_cb
*cb
, struct nl_msg
*msg
,
96 int argc
, char **argv
,
99 return handle_freqchan(msg
, true, argc
, argv
);
101 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
102 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_chan
, NULL
);
103 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
104 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_chan
, NULL
);
106 static int handle_fragmentation(struct nl80211_state
*state
,
107 struct nl_cb
*cb
, struct nl_msg
*msg
,
108 int argc
, char **argv
,
116 if (strcmp("off", argv
[0]) == 0)
123 frag
= strtoul(argv
[0], &end
, 10);
128 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, frag
);
134 COMMAND(set
, frag
, "<fragmentation threshold|off>",
135 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_fragmentation
,
136 "Set fragmentation threshold.");
138 static int handle_rts(struct nl80211_state
*state
,
139 struct nl_cb
*cb
, struct nl_msg
*msg
,
140 int argc
, char **argv
,
148 if (strcmp("off", argv
[0]) == 0)
155 rts
= strtoul(argv
[0], &end
, 10);
160 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, rts
);
166 COMMAND(set
, rts
, "<rts threshold|off>",
167 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_rts
,
168 "Set rts threshold.");
170 static int handle_netns(struct nl80211_state
*state
,
173 int argc
, char **argv
,
184 NLA_PUT_U32(msg
, NL80211_ATTR_PID
,
185 strtoul(argv
[0], &end
, 10));
194 COMMAND(set
, netns
, "<pid>",
195 NL80211_CMD_SET_WIPHY_NETNS
, 0, CIB_PHY
, handle_netns
,
196 "Put this wireless device into a different network namespace");
198 static int handle_coverage(struct nl80211_state
*state
,
201 int argc
, char **argv
,
205 unsigned int coverage
;
212 coverage
= strtoul(argv
[0], &end
, 10);
219 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
225 COMMAND(set
, coverage
, "<coverage class>",
226 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_coverage
,
227 "Set coverage class (1 for every 3 usec of air propagation time).\n"
228 "Valid values: 0 - 255.");
230 static int handle_distance(struct nl80211_state
*state
,
233 int argc
, char **argv
,
237 unsigned int distance
, coverage
;
245 distance
= strtoul(argv
[0], &end
, 10);
251 * Divide double the distance by the speed of light in m/usec (300) to
252 * get round-trip time in microseconds and then divide the result by
253 * three to get coverage class as specified in IEEE 802.11-2007 table
254 * 7-27. Values are rounded upwards.
256 coverage
= (distance
+ 449) / 450;
260 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
266 COMMAND(set
, distance
, "<distance>",
267 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_distance
,
268 "Set appropriate coverage class for given link distance in meters.\n"
269 "Valid values: 0 - 114750");
271 static int handle_txpower(struct nl80211_state
*state
,
274 int argc
, char **argv
,
277 enum nl80211_tx_power_setting type
;
280 /* get the required args */
281 if (argc
!= 1 && argc
!= 2)
284 if (!strcmp(argv
[0], "auto"))
285 type
= NL80211_TX_POWER_AUTOMATIC
;
286 else if (!strcmp(argv
[0], "fixed"))
287 type
= NL80211_TX_POWER_FIXED
;
288 else if (!strcmp(argv
[0], "limit"))
289 type
= NL80211_TX_POWER_LIMITED
;
291 printf("Invalid parameter: %s\n", argv
[0]);
295 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_SETTING
, type
);
297 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
300 printf("Missing TX power level argument.\n");
304 mbm
= strtol(argv
[1], &endptr
, 10);
307 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
, mbm
);
308 } else if (argc
!= 1)
316 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
317 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_txpower
,
318 "Specify transmit power level and setting type.");
319 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
320 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_txpower
,
321 "Specify transmit power level and setting type.");
323 static int handle_antenna(struct nl80211_state
*state
,
326 int argc
, char **argv
,
330 uint32_t tx_ant
= 0, rx_ant
= 0;
332 if (argc
== 1 && strcmp(argv
[0], "all") == 0) {
335 } else if (argc
== 1) {
336 tx_ant
= rx_ant
= strtoul(argv
[0], &end
, 0);
340 else if (argc
== 2) {
341 tx_ant
= strtoul(argv
[0], &end
, 0);
344 rx_ant
= strtoul(argv
[1], &end
, 0);
350 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
351 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
358 COMMAND(set
, antenna
, "<bitmap> | all | <tx bitmap> <rx bitmap>",
359 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_antenna
,
360 "Set a bitmap of allowed antennas to use for TX and RX.\n"
361 "The driver may reject antenna configurations it cannot support.");