5 #include <netlink/genl/genl.h>
6 #include <netlink/genl/family.h>
7 #include <netlink/genl/ctrl.h>
8 #include <netlink/msg.h>
9 #include <netlink/attr.h>
14 static int handle_name(struct nl80211_state
*state
,
17 int argc
, char **argv
)
22 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, *argv
);
28 COMMAND(set
, name
, "<new name>", NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_name
,
29 "Rename this wireless device.");
31 static int handle_freqchan(struct nl_msg
*msg
, bool chan
,
32 int argc
, char **argv
)
39 { .name
= "HT20", .val
= NL80211_CHAN_HT20
, },
40 { .name
= "HT40+", .val
= NL80211_CHAN_HT40PLUS
, },
41 { .name
= "HT40-", .val
= NL80211_CHAN_HT40MINUS
, },
43 unsigned int htval
= NL80211_CHAN_NO_HT
;
47 if (!argc
|| argc
> 2)
51 for (i
= 0; i
< ARRAY_SIZE(htmap
); i
++) {
52 if (strcasecmp(htmap
[i
].name
, argv
[1]) == 0) {
57 if (htval
== NL80211_CHAN_NO_HT
)
63 freq
= strtoul(argv
[0], &end
, 10);
68 freq
= ieee80211_channel_to_frequency(freq
);
70 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
71 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, htval
);
78 static int handle_freq(struct nl80211_state
*state
,
79 struct nl_cb
*cb
, struct nl_msg
*msg
,
80 int argc
, char **argv
)
82 return handle_freqchan(msg
, false, argc
, argv
);
84 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
85 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_freq
,
86 "Set frequency/channel the hardware is using, including HT\n"
88 COMMAND(set
, freq
, "<freq> [HT20|HT40+|HT40-]",
89 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_freq
, NULL
);
91 static int handle_chan(struct nl80211_state
*state
,
92 struct nl_cb
*cb
, struct nl_msg
*msg
,
93 int argc
, char **argv
)
95 return handle_freqchan(msg
, true, argc
, argv
);
97 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
98 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_chan
, NULL
);
99 COMMAND(set
, channel
, "<channel> [HT20|HT40+|HT40-]",
100 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_chan
, NULL
);
102 static int handle_fragmentation(struct nl80211_state
*state
,
103 struct nl_cb
*cb
, struct nl_msg
*msg
,
104 int argc
, char **argv
)
111 if (strcmp("off", argv
[0]) == 0)
118 frag
= strtoul(argv
[0], &end
, 10);
123 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, frag
);
129 COMMAND(set
, frag
, "<fragmentation threshold|off>",
130 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_fragmentation
,
131 "Set fragmentation threshold.");
133 static int handle_rts(struct nl80211_state
*state
,
134 struct nl_cb
*cb
, struct nl_msg
*msg
,
135 int argc
, char **argv
)
142 if (strcmp("off", argv
[0]) == 0)
149 rts
= strtoul(argv
[0], &end
, 10);
154 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, rts
);
160 COMMAND(set
, rts
, "<rts threshold|off>",
161 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_rts
,
162 "Set rts threshold.");
164 static int handle_netns(struct nl80211_state
*state
,
167 int argc
, char **argv
)
177 NLA_PUT_U32(msg
, NL80211_ATTR_PID
,
178 strtoul(argv
[0], &end
, 10));
187 COMMAND(set
, netns
, "<pid>",
188 NL80211_CMD_SET_WIPHY_NETNS
, 0, CIB_PHY
, handle_netns
,
189 "Put this wireless device into a different network namespace");
191 static int handle_coverage(struct nl80211_state
*state
,
194 int argc
, char **argv
)
197 unsigned int coverage
;
204 coverage
= strtoul(argv
[0], &end
, 10);
211 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
217 COMMAND(set
, coverage
, "<coverage class>",
218 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_coverage
,
219 "Set coverage class (1 for every 3 usec of air propagation time).\n"
220 "Valid values: 0 - 255.");
222 static int handle_distance(struct nl80211_state
*state
,
225 int argc
, char **argv
)
228 unsigned int distance
, coverage
;
236 distance
= strtoul(argv
[0], &end
, 10);
242 * Divide double the distance by the speed of light in m/usec (300) to
243 * get round-trip time in microseconds and then divide the result by
244 * three to get coverage class as specified in IEEE 802.11-2007 table
245 * 7-27. Values are rounded upwards.
247 coverage
= (distance
+ 449) / 450;
251 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
, coverage
);
257 COMMAND(set
, distance
, "<distance>",
258 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_distance
,
259 "Set appropriate coverage class for given link distance in meters.\n"
260 "Valid values: 0 - 114750");
262 static int handle_txpower(struct nl80211_state
*state
,
265 int argc
, char **argv
)
267 enum nl80211_tx_power_setting type
;
270 /* get the required args */
271 if (argc
!= 1 && argc
!= 2)
274 if (!strcmp(argv
[0], "auto"))
275 type
= NL80211_TX_POWER_AUTOMATIC
;
276 else if (!strcmp(argv
[0], "fixed"))
277 type
= NL80211_TX_POWER_FIXED
;
278 else if (!strcmp(argv
[0], "limit"))
279 type
= NL80211_TX_POWER_LIMITED
;
281 printf("Invalid parameter: %s\n", argv
[0]);
285 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_SETTING
, type
);
287 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
289 printf("Missing TX power level argument.\n");
294 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
, mbm
);
295 } else if (argc
!= 1)
303 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
304 NL80211_CMD_SET_WIPHY
, 0, CIB_PHY
, handle_txpower
,
305 "Specify transmit power level and setting type.");
306 COMMAND(set
, txpower
, "<auto|fixed|limit> [<tx power in mBm>]",
307 NL80211_CMD_SET_WIPHY
, 0, CIB_NETDEV
, handle_txpower
,
308 "Specify transmit power level and setting type.");