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
)
23 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, *argv
);
29 COMMAND(set
, name
, "<new name>", NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_name
,
30 "Rename this wireless device.");
32 static int handle_freqchan(struct nl_msg
*msg
, bool chan
,
33 int argc
, char **argv
)
40 { .name
= "HT20", .val
= NL80211_CHAN_HT20
, },
41 { .name
= "HT40+", .val
= NL80211_CHAN_HT40PLUS
, },
42 { .name
= "HT40-", .val
= NL80211_CHAN_HT40MINUS
, },
44 unsigned int htval
= NL80211_CHAN_NO_HT
;
48 if (!argc
|| argc
> 2)
52 for (i
= 0; i
< ARRAY_SIZE(htmap
); i
++) {
53 if (strcasecmp(htmap
[i
].name
, argv
[1]) == 0) {
58 if (htval
== NL80211_CHAN_NO_HT
)
64 freq
= strtoul(argv
[0], &end
, 10);
69 freq
= ieee80211_channel_to_frequency(freq
);
71 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
72 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, htval
);
79 static int handle_freq(struct nl80211_state
*state
,
80 struct nl_cb
*cb
, struct nl_msg
*msg
,
81 int argc
, char **argv
)
83 return handle_freqchan(msg
, false, argc
, argv
);
85 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
86 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_freq
,
87 "Set frequency/channel the hardware is using, including HT\n"
89 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
90 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_freq
, NULL
);
92 static int handle_chan(struct nl80211_state
*state
,
93 struct nl_cb
*cb
, struct nl_msg
*msg
,
94 int argc
, char **argv
)
96 return handle_freqchan(msg
, true, argc
, argv
);
98 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
99 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_chan
, NULL
);
100 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
101 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_chan
, NULL
);
103 static int handle_fragmentation(struct nl80211_state
*state
,
104 struct nl_cb
*cb
, struct nl_msg
*msg
,
105 int argc
, char **argv
)
112 if (strcmp("off", argv
[0]) == 0)
119 frag
= strtoul(argv
[0], &end
, 10);
124 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, frag
);
130 COMMAND(set
, frag
, "<fragmentation threshold|off>",
131 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_fragmentation
,
132 "Set fragmentation threshold.");
134 static int handle_rts(struct nl80211_state
*state
,
135 struct nl_cb
*cb
, struct nl_msg
*msg
,
136 int argc
, char **argv
)
143 if (strcmp("off", argv
[0]) == 0)
150 rts
= strtoul(argv
[0], &end
, 10);
155 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, rts
);
161 COMMAND(set
, rts
, "<rts threshold|off>",
162 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_rts
,
163 "Set rts threshold.");
165 static int handle_netns(struct nl80211_state
*state
,
168 int argc
, char **argv
)
178 NLA_PUT_U32(msg
, NL80211_ATTR_PID
,
179 strtoul(argv
[0], &end
, 10));
188 COMMAND(set
, netns
, "<pid>",
189 NL80211_CMD_SET_WIPHY_NETNS
, 0, CIB_PHY
, handle_netns
,
190 "Put this wireless device into a different network namespace");
192 static int handle_coverage(struct nl80211_state
*state
,
195 int argc
, char **argv
)
198 unsigned int coverage
;
205 coverage
= strtoul(argv
[0], &end
, 10);
212 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
218 COMMAND(set
, coverage
, "<coverage class>",
219 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_coverage
,
220 "Set coverage class (1 for every 3 usec of air propagation time).\n"
221 "Valid values: 0 - 255.");
223 static int handle_distance(struct nl80211_state
*state
,
226 int argc
, char **argv
)
229 unsigned int distance
, coverage
;
237 distance
= strtoul(argv
[0], &end
, 10);
243 * Divide double the distance by the speed of light in m/usec (300) to
244 * get round-trip time in microseconds and then divide the result by
245 * three to get coverage class as specified in IEEE 802.11-2007 table
246 * 7-27. Values are rounded upwards.
248 coverage
= (distance
+ 449) / 450;
252 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
258 COMMAND(set
, distance
, "<distance>",
259 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_distance
,
260 "Set appropriate coverage class for given link distance in meters.\n"
261 "Valid values: 0 - 114750");
263 static int handle_txpower(struct nl80211_state
*state
,
266 int argc
, char **argv
)
268 enum nl80211_tx_power_setting type
;
271 /* get the required args */
272 if (argc
!= 1 && argc
!= 2)
275 if (!strcmp(argv
[0], "auto"))
276 type
= NL80211_TX_POWER_AUTOMATIC
;
277 else if (!strcmp(argv
[0], "fixed"))
278 type
= NL80211_TX_POWER_FIXED
;
279 else if (!strcmp(argv
[0], "limit"))
280 type
= NL80211_TX_POWER_LIMITED
;
282 printf("Invalid parameter: %s\n", argv
[0]);
286 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_SETTING
, type
);
288 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
291 printf("Missing TX power level argument.\n");
295 mbm
= strtol(argv
[1], &endptr
, 10);
298 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
, mbm
);
299 } else if (argc
!= 1)
307 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
308 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_txpower
,
309 "Specify transmit power level and setting type.");
310 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
311 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_txpower
,
312 "Specify transmit power level and setting type.");
314 static int handle_antenna(struct nl80211_state
*state
,
317 int argc
, char **argv
)
320 uint32_t tx_ant
= 0, rx_ant
= 0;
322 if (argc
== 1 && strcmp(argv
[0], "all") == 0) {
325 } else if (argc
== 1) {
326 tx_ant
= rx_ant
= strtoul(argv
[0], &end
, 0);
330 else if (argc
== 2) {
331 tx_ant
= strtoul(argv
[0], &end
, 0);
334 rx_ant
= strtoul(argv
[1], &end
, 0);
340 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
341 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
348 COMMAND(set
, antenna
, "<bitmap> | all | <tx bitmap> <rx bitmap>",
349 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_antenna
,
350 "Set a bitmap of allowed antennas to use for TX and RX.\n"
351 "The driver may reject antenna configurations it cannot support.");