]>
Commit | Line | Data |
---|---|---|
21878f36 | 1 | #include <stdbool.h> |
79f99b9a | 2 | #include <errno.h> |
2ef1be68 JB |
3 | #include <net/if.h> |
4 | ||
79f99b9a JB |
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> | |
79f99b9a | 10 | |
f408e01b | 11 | #include "nl80211.h" |
79f99b9a JB |
12 | #include "iw.h" |
13 | ||
14 | static void print_flag(const char *name, int *open) | |
15 | { | |
16 | if (!*open) | |
17 | printf(" ("); | |
18 | else | |
19 | printf(", "); | |
69283122 | 20 | printf("%s", name); |
79f99b9a JB |
21 | *open = 1; |
22 | } | |
23 | ||
24 | static int print_phy_handler(struct nl_msg *msg, void *arg) | |
25 | { | |
26 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
27 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
28 | ||
29 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; | |
30 | ||
31 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
32 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
33 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, | |
34 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, | |
35 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, | |
36 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, | |
37 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, | |
c1081c20 | 38 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, |
79f99b9a JB |
39 | }; |
40 | ||
41 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; | |
42 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { | |
43 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, | |
44 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG }, | |
45 | }; | |
46 | ||
47 | struct nlattr *nl_band; | |
48 | struct nlattr *nl_freq; | |
49 | struct nlattr *nl_rate; | |
6367e71a | 50 | struct nlattr *nl_mode; |
9990c1e9 | 51 | struct nlattr *nl_cmd; |
9a4a14bd | 52 | struct nlattr *nl_if, *nl_ftype; |
79f99b9a | 53 | int bandidx = 1; |
9a4a14bd | 54 | int rem_band, rem_freq, rem_rate, rem_mode, rem_cmd, rem_ftype, rem_if; |
79f99b9a JB |
55 | int open; |
56 | ||
57 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
58 | genlmsg_attrlen(gnlh, 0), NULL); | |
59 | ||
60 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) | |
61 | return NL_SKIP; | |
62 | ||
d631650b JB |
63 | if (tb_msg[NL80211_ATTR_WIPHY_NAME]) |
64 | printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME])); | |
65 | ||
79f99b9a | 66 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) { |
d631650b | 67 | printf("\tBand %d:\n", bandidx); |
79f99b9a JB |
68 | bandidx++; |
69 | ||
70 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), | |
71 | nla_len(nl_band), NULL); | |
72 | ||
3dd781cc JB |
73 | #ifdef NL80211_BAND_ATTR_HT_CAPA |
74 | if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) { | |
357c1a5d LR |
75 | __u16 cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]); |
76 | print_ht_capability(cap); | |
3dd781cc JB |
77 | } |
78 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) { | |
0950993f LR |
79 | __u8 exponent = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]); |
80 | print_ampdu_length(exponent); | |
3dd781cc JB |
81 | } |
82 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) { | |
0950993f LR |
83 | __u8 spacing = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]); |
84 | print_ampdu_spacing(spacing); | |
3dd781cc JB |
85 | } |
86 | if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] && | |
7ddfb679 JB |
87 | nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16) |
88 | print_ht_mcs(nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET])); | |
3dd781cc JB |
89 | #endif |
90 | ||
d631650b | 91 | printf("\t\tFrequencies:\n"); |
79f99b9a JB |
92 | |
93 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { | |
379f8397 | 94 | uint32_t freq; |
79f99b9a JB |
95 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), |
96 | nla_len(nl_freq), freq_policy); | |
97 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
98 | continue; | |
379f8397 JB |
99 | freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
100 | printf("\t\t\t* %d MHz [%d]", freq, ieee80211_frequency_to_channel(freq)); | |
c1081c20 | 101 | |
d102c0b6 JB |
102 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && |
103 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
104 | printf(" (%.1f dBm)", 0.01 * nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER])); | |
c1081c20 | 105 | |
79f99b9a | 106 | open = 0; |
ee9cd987 | 107 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) { |
79f99b9a | 108 | print_flag("disabled", &open); |
ee9cd987 JB |
109 | goto next; |
110 | } | |
79f99b9a JB |
111 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) |
112 | print_flag("passive scanning", &open); | |
113 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
114 | print_flag("no IBSS", &open); | |
115 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) | |
116 | print_flag("radar detection", &open); | |
ee9cd987 | 117 | next: |
79f99b9a JB |
118 | if (open) |
119 | printf(")"); | |
120 | printf("\n"); | |
121 | } | |
122 | ||
75dddccc | 123 | printf("\t\tBitrates (non-HT):\n"); |
79f99b9a JB |
124 | |
125 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
126 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
127 | nla_len(nl_rate), rate_policy); | |
128 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
129 | continue; | |
d631650b | 130 | printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE])); |
79f99b9a JB |
131 | open = 0; |
132 | if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE]) | |
133 | print_flag("short preamble supported", &open); | |
134 | if (open) | |
135 | printf(")"); | |
136 | printf("\n"); | |
137 | } | |
138 | } | |
139 | ||
41be37f2 JB |
140 | if (tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) |
141 | printf("\tmax # scan SSIDs: %d\n", | |
142 | nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])); | |
f9c112b6 JB |
143 | if (tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN]) |
144 | printf("\tmax scan IEs length: %d bytes\n", | |
8eaa9ee5 | 145 | nla_get_u16(tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN])); |
41be37f2 | 146 | |
625aa4ae JB |
147 | if (tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
148 | unsigned int frag; | |
149 | ||
150 | frag = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
151 | if (frag != (unsigned int)-1) | |
152 | printf("\tFragmentation threshold: %d\n", frag); | |
153 | } | |
154 | ||
155 | if (tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
156 | unsigned int rts; | |
157 | ||
158 | rts = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
159 | if (rts != (unsigned int)-1) | |
160 | printf("\tRTS threshold: %d\n", rts); | |
161 | } | |
162 | ||
b2f92dd0 LT |
163 | if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
164 | unsigned char coverage; | |
165 | ||
166 | coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
167 | /* See handle_distance() for an explanation where the '450' comes from */ | |
168 | printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage); | |
169 | } | |
170 | ||
afce7986 BR |
171 | if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX] && |
172 | tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]) | |
173 | printf("\tAvailable Antennas: TX %#x RX %#x\n", | |
174 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]), | |
175 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX])); | |
176 | ||
177 | if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] && | |
178 | tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]) | |
179 | printf("\tConfigured Antennas: TX %#x RX %#x\n", | |
180 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]), | |
181 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX])); | |
182 | ||
9a4a14bd JB |
183 | if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) { |
184 | printf("\tSupported interface modes:\n"); | |
185 | nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode) | |
8ef6df4f | 186 | printf("\t\t * %s\n", iftype_name(nla_type(nl_mode))); |
9a4a14bd | 187 | } |
6367e71a | 188 | |
9a4a14bd JB |
189 | if (tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS]) { |
190 | printf("\tSupported commands:\n"); | |
191 | nla_for_each_nested(nl_cmd, tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS], rem_cmd) | |
192 | printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd))); | |
193 | } | |
6367e71a | 194 | |
9a4a14bd JB |
195 | if (tb_msg[NL80211_ATTR_TX_FRAME_TYPES]) { |
196 | printf("\tSupported TX frame types:\n"); | |
197 | nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_TX_FRAME_TYPES], rem_if) { | |
198 | bool printed = false; | |
199 | nla_for_each_nested(nl_ftype, nl_if, rem_ftype) { | |
200 | if (!printed) | |
201 | printf("\t\t * %s:", iftype_name(nla_type(nl_if))); | |
202 | printed = true; | |
203 | printf(" 0x%.4x", nla_get_u16(nl_ftype)); | |
204 | } | |
205 | if (printed) | |
206 | printf("\n"); | |
207 | } | |
208 | } | |
9990c1e9 | 209 | |
9a4a14bd JB |
210 | if (tb_msg[NL80211_ATTR_RX_FRAME_TYPES]) { |
211 | printf("\tSupported RX frame types:\n"); | |
212 | nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_RX_FRAME_TYPES], rem_if) { | |
213 | bool printed = false; | |
214 | nla_for_each_nested(nl_ftype, nl_if, rem_ftype) { | |
215 | if (!printed) | |
216 | printf("\t\t * %s:", iftype_name(nla_type(nl_if))); | |
217 | printed = true; | |
218 | printf(" 0x%.4x", nla_get_u16(nl_ftype)); | |
219 | } | |
220 | if (printed) | |
221 | printf("\n"); | |
222 | } | |
223 | } | |
9990c1e9 | 224 | |
3ff24563 | 225 | if (tb_msg[NL80211_ATTR_SUPPORT_IBSS_RSN]) |
83f10169 | 226 | printf("\tDevice supports RSN-IBSS.\n"); |
3ff24563 JB |
227 | |
228 | if (tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]) { | |
229 | struct nlattr *tb_wowlan[NUM_NL80211_WOWLAN_TRIG]; | |
230 | static struct nla_policy wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
231 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
232 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
233 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
234 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { | |
235 | .minlen = sizeof(struct nl80211_wowlan_pattern_support), | |
236 | }, | |
237 | }; | |
238 | struct nl80211_wowlan_pattern_support *pat; | |
239 | int err; | |
240 | ||
241 | err = nla_parse_nested(tb_wowlan, MAX_NL80211_WOWLAN_TRIG, | |
242 | tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED], | |
243 | wowlan_policy); | |
244 | printf("\tWoWLAN support:"); | |
245 | if (err) { | |
246 | printf(" <failed to parse>\n"); | |
247 | } else { | |
248 | printf("\n"); | |
249 | if (tb_wowlan[NL80211_WOWLAN_TRIG_ANY]) | |
250 | printf("\t\t * any (device continues operating)\n"); | |
251 | if (tb_wowlan[NL80211_WOWLAN_TRIG_DISCONNECT]) | |
252 | printf("\t\t * disconnect\n"); | |
253 | if (tb_wowlan[NL80211_WOWLAN_TRIG_MAGIC_PKT]) | |
254 | printf("\t\t * magic packet\n"); | |
255 | if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { | |
256 | pat = nla_data(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]); | |
257 | printf("\t\t * up to %u patterns of %u-%u bytes\n", | |
258 | pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len); | |
259 | } | |
260 | } | |
83f10169 JB |
261 | } |
262 | ||
79f99b9a JB |
263 | return NL_SKIP; |
264 | } | |
265 | ||
7c37a24d JB |
266 | static int handle_info(struct nl80211_state *state, |
267 | struct nl_cb *cb, | |
d631650b JB |
268 | struct nl_msg *msg, |
269 | int argc, char **argv) | |
79f99b9a | 270 | { |
79f99b9a | 271 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL); |
79f99b9a | 272 | |
70391ccf | 273 | return 0; |
79f99b9a | 274 | } |
4698bfc2 | 275 | __COMMAND(NULL, info, "info", NULL, NL80211_CMD_GET_WIPHY, 0, 0, CIB_PHY, handle_info, |
1633ddf7 | 276 | "Show capabilities for the specified wireless device.", NULL); |
ea35fc0b JB |
277 | TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, |
278 | "List all wireless devices and their capabilities."); | |
01ae06f9 | 279 | TOPLEVEL(phy, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL); |