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 freq
= ieee80211_channel_to_frequency(freq
);
119 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
122 return handle_freqs(msg
, argc
- 1, argv
+ 1);
123 } else if (argc
== 2) {
124 for (i
= 0; i
< ARRAY_SIZE(htmap
); i
++) {
125 if (strcasecmp(htmap
[i
].name
, argv
[1]) == 0) {
126 htval
= htmap
[i
].val
;
130 if (htval
== NL80211_CHAN_NO_HT
)
131 return handle_freqs(msg
, argc
- 1, argv
+ 1);
134 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, htval
);
141 static int handle_freq(struct nl80211_state
*state
,
142 struct nl_cb
*cb
, struct nl_msg
*msg
,
143 int argc
, char **argv
,
146 return handle_freqchan(msg
, false, argc
, argv
);
148 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
149 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_freq
,
150 "Set frequency/channel the hardware is using, including HT\n"
152 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]\n"
153 "<control freq> [20|40|80|80+80|160] [<center freq 1>] [<center freq 2>]",
154 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_freq
, NULL
);
156 static int handle_chan(struct nl80211_state
*state
,
157 struct nl_cb
*cb
, struct nl_msg
*msg
,
158 int argc
, char **argv
,
161 return handle_freqchan(msg
, true, argc
, argv
);
163 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
164 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_chan
, NULL
);
165 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
166 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_chan
, NULL
);
168 static int handle_fragmentation(struct nl80211_state
*state
,
169 struct nl_cb
*cb
, struct nl_msg
*msg
,
170 int argc
, char **argv
,
178 if (strcmp("off", argv
[0]) == 0)
185 frag
= strtoul(argv
[0], &end
, 10);
190 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, frag
);
196 COMMAND(set
, frag
, "<fragmentation threshold|off>",
197 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_fragmentation
,
198 "Set fragmentation threshold.");
200 static int handle_rts(struct nl80211_state
*state
,
201 struct nl_cb
*cb
, struct nl_msg
*msg
,
202 int argc
, char **argv
,
210 if (strcmp("off", argv
[0]) == 0)
217 rts
= strtoul(argv
[0], &end
, 10);
222 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, rts
);
228 COMMAND(set
, rts
, "<rts threshold|off>",
229 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_rts
,
230 "Set rts threshold.");
232 static int handle_netns(struct nl80211_state
*state
,
235 int argc
, char **argv
,
246 NLA_PUT_U32(msg
, NL80211_ATTR_PID
,
247 strtoul(argv
[0], &end
, 10));
256 COMMAND(set
, netns
, "<pid>",
257 NL80211_CMD_SET_WIPHY_NETNS
, 0, CIB_PHY
, handle_netns
,
258 "Put this wireless device into a different network namespace");
260 static int handle_coverage(struct nl80211_state
*state
,
263 int argc
, char **argv
,
267 unsigned int coverage
;
274 coverage
= strtoul(argv
[0], &end
, 10);
281 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
287 COMMAND(set
, coverage
, "<coverage class>",
288 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_coverage
,
289 "Set coverage class (1 for every 3 usec of air propagation time).\n"
290 "Valid values: 0 - 255.");
292 static int handle_distance(struct nl80211_state
*state
,
295 int argc
, char **argv
,
299 unsigned int distance
, coverage
;
307 distance
= strtoul(argv
[0], &end
, 10);
313 * Divide double the distance by the speed of light in m/usec (300) to
314 * get round-trip time in microseconds and then divide the result by
315 * three to get coverage class as specified in IEEE 802.11-2007 table
316 * 7-27. Values are rounded upwards.
318 coverage
= (distance
+ 449) / 450;
322 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
328 COMMAND(set
, distance
, "<distance>",
329 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_distance
,
330 "Set appropriate coverage class for given link distance in meters.\n"
331 "Valid values: 0 - 114750");
333 static int handle_txpower(struct nl80211_state
*state
,
336 int argc
, char **argv
,
339 enum nl80211_tx_power_setting type
;
342 /* get the required args */
343 if (argc
!= 1 && argc
!= 2)
346 if (!strcmp(argv
[0], "auto"))
347 type
= NL80211_TX_POWER_AUTOMATIC
;
348 else if (!strcmp(argv
[0], "fixed"))
349 type
= NL80211_TX_POWER_FIXED
;
350 else if (!strcmp(argv
[0], "limit"))
351 type
= NL80211_TX_POWER_LIMITED
;
353 printf("Invalid parameter: %s\n", argv
[0]);
357 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_SETTING
, type
);
359 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
362 printf("Missing TX power level argument.\n");
366 mbm
= strtol(argv
[1], &endptr
, 10);
369 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
, mbm
);
370 } else if (argc
!= 1)
378 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
379 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_txpower
,
380 "Specify transmit power level and setting type.");
381 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
382 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_txpower
,
383 "Specify transmit power level and setting type.");
385 static int handle_antenna(struct nl80211_state
*state
,
388 int argc
, char **argv
,
392 uint32_t tx_ant
= 0, rx_ant
= 0;
394 if (argc
== 1 && strcmp(argv
[0], "all") == 0) {
397 } else if (argc
== 1) {
398 tx_ant
= rx_ant
= strtoul(argv
[0], &end
, 0);
402 else if (argc
== 2) {
403 tx_ant
= strtoul(argv
[0], &end
, 0);
406 rx_ant
= strtoul(argv
[1], &end
, 0);
412 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
413 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
420 COMMAND(set
, antenna
, "<bitmap> | all | <tx bitmap> <rx bitmap>",
421 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_antenna
,
422 "Set a bitmap of allowed antennas to use for TX and RX.\n"
423 "The driver may reject antenna configurations it cannot support.");