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_freqs(struct nl_msg
*msg
, int argc
, char **argv
)
39 { .name
= "20", .val
= NL80211_CHAN_WIDTH_20
, },
40 { .name
= "40", .val
= NL80211_CHAN_WIDTH_40
, },
41 { .name
= "80", .val
= NL80211_CHAN_WIDTH_80
, },
42 { .name
= "80+80", .val
= NL80211_CHAN_WIDTH_80P80
, },
43 { .name
= "160", .val
= NL80211_CHAN_WIDTH_160
, },
46 int i
, bwval
= NL80211_CHAN_WIDTH_20_NOHT
;
52 for (i
= 0; i
< ARRAY_SIZE(bwmap
); i
++) {
53 if (strcasecmp(bwmap
[i
].name
, argv
[0]) == 0) {
59 if (bwval
== NL80211_CHAN_WIDTH_20_NOHT
)
62 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, bwval
);
70 freq
= strtoul(argv
[1], &end
, 10);
73 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
, freq
);
81 freq
= strtoul(argv
[2], &end
, 10);
84 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ2
, freq
);
91 static int handle_freqchan(struct nl_msg
*msg
, bool chan
,
92 int argc
, char **argv
)
99 { .name
= "HT20", .val
= NL80211_CHAN_HT20
, },
100 { .name
= "HT40+", .val
= NL80211_CHAN_HT40PLUS
, },
101 { .name
= "HT40-", .val
= NL80211_CHAN_HT40MINUS
, },
103 unsigned int htval
= NL80211_CHAN_NO_HT
;
107 if (!argc
|| argc
> 4)
112 freq
= strtoul(argv
[0], &end
, 10);
117 enum nl80211_band band
;
118 band
= freq
<= 14 ? NL80211_BAND_2GHZ
: NL80211_BAND_5GHZ
;
119 freq
= ieee80211_channel_to_frequency(freq
, band
);
122 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
125 return handle_freqs(msg
, argc
- 1, argv
+ 1);
126 } else if (argc
== 2) {
127 for (i
= 0; i
< ARRAY_SIZE(htmap
); i
++) {
128 if (strcasecmp(htmap
[i
].name
, argv
[1]) == 0) {
129 htval
= htmap
[i
].val
;
133 if (htval
== NL80211_CHAN_NO_HT
)
134 return handle_freqs(msg
, argc
- 1, argv
+ 1);
137 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, htval
);
144 static int handle_freq(struct nl80211_state
*state
,
145 struct nl_cb
*cb
, struct nl_msg
*msg
,
146 int argc
, char **argv
,
149 return handle_freqchan(msg
, false, argc
, argv
);
151 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
152 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_freq
,
153 "Set frequency/channel the hardware is using, including HT\n"
155 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]\n"
156 "<control freq> [20|40|80|80+80|160] [<center freq 1>] [<center freq 2>]",
157 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_freq
, NULL
);
159 static int handle_chan(struct nl80211_state
*state
,
160 struct nl_cb
*cb
, struct nl_msg
*msg
,
161 int argc
, char **argv
,
164 return handle_freqchan(msg
, true, argc
, argv
);
166 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
167 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_chan
, NULL
);
168 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
169 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_chan
, NULL
);
171 static int handle_fragmentation(struct nl80211_state
*state
,
172 struct nl_cb
*cb
, struct nl_msg
*msg
,
173 int argc
, char **argv
,
181 if (strcmp("off", argv
[0]) == 0)
188 frag
= strtoul(argv
[0], &end
, 10);
193 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, frag
);
199 COMMAND(set
, frag
, "<fragmentation threshold|off>",
200 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_fragmentation
,
201 "Set fragmentation threshold.");
203 static int handle_rts(struct nl80211_state
*state
,
204 struct nl_cb
*cb
, struct nl_msg
*msg
,
205 int argc
, char **argv
,
213 if (strcmp("off", argv
[0]) == 0)
220 rts
= strtoul(argv
[0], &end
, 10);
225 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, rts
);
231 COMMAND(set
, rts
, "<rts threshold|off>",
232 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_rts
,
233 "Set rts threshold.");
235 static int handle_retry(struct nl80211_state
*state
,
236 struct nl_cb
*cb
, struct nl_msg
*msg
,
237 int argc
, char **argv
, enum id_input id
)
239 unsigned int retry_short
= 0, retry_long
= 0;
240 bool have_retry_s
= false, have_retry_l
= false;
246 } parser_state
= S_NONE
;
248 if (!argc
|| (argc
!= 2 && argc
!= 4))
251 for (i
= 0; i
< argc
; i
++) {
255 if (strcmp(argv
[i
], "short") == 0) {
258 parser_state
= S_SHORT
;
260 } else if (strcmp(argv
[i
], "long") == 0) {
263 parser_state
= S_LONG
;
266 tmpul
= strtoul(argv
[i
], &end
, 10);
269 if (!tmpul
|| tmpul
> 255)
271 switch (parser_state
) {
284 if (!have_retry_s
&& !have_retry_l
)
287 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
, retry_short
);
289 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
, retry_long
);
295 COMMAND(set
, retry
, "[short <limit>] [long <limit>]",
296 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_retry
,
299 static int handle_netns(struct nl80211_state
*state
,
302 int argc
, char **argv
,
313 NLA_PUT_U32(msg
, NL80211_ATTR_PID
,
314 strtoul(argv
[0], &end
, 10));
323 COMMAND(set
, netns
, "<pid>",
324 NL80211_CMD_SET_WIPHY_NETNS
, 0, CIB_PHY
, handle_netns
,
325 "Put this wireless device into a different network namespace");
327 static int handle_coverage(struct nl80211_state
*state
,
330 int argc
, char **argv
,
334 unsigned int coverage
;
341 coverage
= strtoul(argv
[0], &end
, 10);
348 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
354 COMMAND(set
, coverage
, "<coverage class>",
355 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_coverage
,
356 "Set coverage class (1 for every 3 usec of air propagation time).\n"
357 "Valid values: 0 - 255.");
359 static int handle_distance(struct nl80211_state
*state
,
362 int argc
, char **argv
,
371 if (strcmp("auto", argv
[0]) == 0) {
372 NLA_PUT_FLAG(msg
, NL80211_ATTR_WIPHY_DYN_ACK
);
375 unsigned int distance
, coverage
;
377 distance
= strtoul(argv
[0], &end
, 10);
383 * Divide double the distance by the speed of light
384 * in m/usec (300) to get round-trip time in microseconds
385 * and then divide the result by three to get coverage class
386 * as specified in IEEE 802.11-2007 table 7-27.
387 * Values are rounded upwards.
389 coverage
= (distance
+ 449) / 450;
393 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
400 COMMAND(set
, distance
, "<auto|distance>",
401 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_distance
,
402 "Enable ACK timeout estimation algorithm (dynack) or set appropriate\n"
403 "coverage class for given link distance in meters.\n"
404 "To disable dynack set valid value for coverage class.\n"
405 "Valid values: 0 - 114750");
407 static int handle_txpower(struct nl80211_state
*state
,
410 int argc
, char **argv
,
413 enum nl80211_tx_power_setting type
;
416 /* get the required args */
417 if (argc
!= 1 && argc
!= 2)
420 if (!strcmp(argv
[0], "auto"))
421 type
= NL80211_TX_POWER_AUTOMATIC
;
422 else if (!strcmp(argv
[0], "fixed"))
423 type
= NL80211_TX_POWER_FIXED
;
424 else if (!strcmp(argv
[0], "limit"))
425 type
= NL80211_TX_POWER_LIMITED
;
427 printf("Invalid parameter: %s\n", argv
[0]);
431 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_SETTING
, type
);
433 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
436 printf("Missing TX power level argument.\n");
440 mbm
= strtol(argv
[1], &endptr
, 10);
443 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
, mbm
);
444 } else if (argc
!= 1)
452 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
453 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_txpower
,
454 "Specify transmit power level and setting type.");
455 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
456 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_txpower
,
457 "Specify transmit power level and setting type.");
459 static int handle_antenna(struct nl80211_state
*state
,
462 int argc
, char **argv
,
466 uint32_t tx_ant
= 0, rx_ant
= 0;
468 if (argc
== 1 && strcmp(argv
[0], "all") == 0) {
471 } else if (argc
== 1) {
472 tx_ant
= rx_ant
= strtoul(argv
[0], &end
, 0);
476 else if (argc
== 2) {
477 tx_ant
= strtoul(argv
[0], &end
, 0);
480 rx_ant
= strtoul(argv
[1], &end
, 0);
486 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
487 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
494 COMMAND(set
, antenna
, "<bitmap> | all | <tx bitmap> <rx bitmap>",
495 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_antenna
,
496 "Set a bitmap of allowed antennas to use for TX and RX.\n"
497 "The driver may reject antenna configurations it cannot support.");