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 void print_flag(const char *name
, int *open
)
24 static char *cipher_name(__u32 c
)
30 return "WEP40 (00-0f-ac:1)";
32 return "WEP104 (00-0f-ac:5)";
34 return "TKIP (00-0f-ac:2)";
36 return "CCMP (00-0f-ac:4)";
38 return "CMAC (00-0f-ac:6)";
40 return "WPI-SMS4 (00-14-72:1)";
42 sprintf(buf
, "%.2x-%.2x-%.2x:%d",
43 c
>> 24, (c
>> 16) & 0xff,
44 (c
>> 8) & 0xff, c
& 0xff);
50 static int print_phy_handler(struct nl_msg
*msg
, void *arg
)
52 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
53 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
55 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
57 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
58 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
59 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
60 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
61 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
62 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
63 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
64 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
67 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
68 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
69 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
70 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] = { .type
= NLA_FLAG
},
73 struct nlattr
*nl_band
;
74 struct nlattr
*nl_freq
;
75 struct nlattr
*nl_rate
;
76 struct nlattr
*nl_mode
;
77 struct nlattr
*nl_cmd
;
78 struct nlattr
*nl_if
, *nl_ftype
;
80 int rem_band
, rem_freq
, rem_rate
, rem_mode
, rem_cmd
, rem_ftype
, rem_if
;
83 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
84 genlmsg_attrlen(gnlh
, 0), NULL
);
86 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
89 if (tb_msg
[NL80211_ATTR_WIPHY_NAME
])
90 printf("Wiphy %s\n", nla_get_string(tb_msg
[NL80211_ATTR_WIPHY_NAME
]));
92 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
) {
93 printf("\tBand %d:\n", bandidx
);
96 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
97 nla_len(nl_band
), NULL
);
99 #ifdef NL80211_BAND_ATTR_HT_CAPA
100 if (tb_band
[NL80211_BAND_ATTR_HT_CAPA
]) {
101 __u16 cap
= nla_get_u16(tb_band
[NL80211_BAND_ATTR_HT_CAPA
]);
102 print_ht_capability(cap
);
104 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) {
105 __u8 exponent
= nla_get_u8(tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]);
106 print_ampdu_length(exponent
);
108 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) {
109 __u8 spacing
= nla_get_u8(tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]);
110 print_ampdu_spacing(spacing
);
112 if (tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
] &&
113 nla_len(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]) == 16)
114 print_ht_mcs(nla_data(tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]));
117 printf("\t\tFrequencies:\n");
119 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
121 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
, nla_data(nl_freq
),
122 nla_len(nl_freq
), freq_policy
);
123 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
125 freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
126 printf("\t\t\t* %d MHz [%d]", freq
, ieee80211_frequency_to_channel(freq
));
128 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
129 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
130 printf(" (%.1f dBm)", 0.01 * nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]));
133 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
]) {
134 print_flag("disabled", &open
);
137 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
138 print_flag("passive scanning", &open
);
139 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
140 print_flag("no IBSS", &open
);
141 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
142 print_flag("radar detection", &open
);
149 printf("\t\tBitrates (non-HT):\n");
151 nla_for_each_nested(nl_rate
, tb_band
[NL80211_BAND_ATTR_RATES
], rem_rate
) {
152 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
, nla_data(nl_rate
),
153 nla_len(nl_rate
), rate_policy
);
154 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
156 printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate
[NL80211_BITRATE_ATTR_RATE
]));
158 if (tb_rate
[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
])
159 print_flag("short preamble supported", &open
);
166 if (tb_msg
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
167 printf("\tmax # scan SSIDs: %d\n",
168 nla_get_u8(tb_msg
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]));
169 if (tb_msg
[NL80211_ATTR_MAX_SCAN_IE_LEN
])
170 printf("\tmax scan IEs length: %d bytes\n",
171 nla_get_u16(tb_msg
[NL80211_ATTR_MAX_SCAN_IE_LEN
]));
173 if (tb_msg
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
176 frag
= nla_get_u32(tb_msg
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
177 if (frag
!= (unsigned int)-1)
178 printf("\tFragmentation threshold: %d\n", frag
);
181 if (tb_msg
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
184 rts
= nla_get_u32(tb_msg
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
185 if (rts
!= (unsigned int)-1)
186 printf("\tRTS threshold: %d\n", rts
);
189 if (tb_msg
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
190 unsigned char coverage
;
192 coverage
= nla_get_u8(tb_msg
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
193 /* See handle_distance() for an explanation where the '450' comes from */
194 printf("\tCoverage class: %d (up to %dm)\n", coverage
, 450 * coverage
);
197 if (tb_msg
[NL80211_ATTR_CIPHER_SUITES
]) {
198 int num
= nla_len(tb_msg
[NL80211_ATTR_CIPHER_SUITES
]) / sizeof(__u32
);
200 __u32
*ciphers
= nla_data(tb_msg
[NL80211_ATTR_CIPHER_SUITES
]);
202 printf("\tSupported Ciphers:\n");
203 for (i
= 0; i
< num
; i
++)
205 cipher_name(ciphers
[i
]));
209 if (tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
] &&
210 tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
])
211 printf("\tAvailable Antennas: TX %#x RX %#x\n",
212 nla_get_u32(tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
]),
213 nla_get_u32(tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
]));
215 if (tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
216 tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_RX
])
217 printf("\tConfigured Antennas: TX %#x RX %#x\n",
218 nla_get_u32(tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_TX
]),
219 nla_get_u32(tb_msg
[NL80211_ATTR_WIPHY_ANTENNA_RX
]));
221 if (tb_msg
[NL80211_ATTR_SUPPORTED_IFTYPES
]) {
222 printf("\tSupported interface modes:\n");
223 nla_for_each_nested(nl_mode
, tb_msg
[NL80211_ATTR_SUPPORTED_IFTYPES
], rem_mode
)
224 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode
)));
227 if (tb_msg
[NL80211_ATTR_SOFTWARE_IFTYPES
]) {
228 printf("\tsoftware interface modes (can always be added):\n");
229 nla_for_each_nested(nl_mode
, tb_msg
[NL80211_ATTR_SOFTWARE_IFTYPES
], rem_mode
)
230 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode
)));
233 if (tb_msg
[NL80211_ATTR_INTERFACE_COMBINATIONS
]) {
234 struct nlattr
*nl_combi
;
236 bool have_combinations
= false;
238 nla_for_each_nested(nl_combi
, tb_msg
[NL80211_ATTR_INTERFACE_COMBINATIONS
], rem_combi
) {
239 static struct nla_policy iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
240 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
241 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
242 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
243 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
245 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
246 static struct nla_policy iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
247 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
248 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
250 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
251 struct nlattr
*nl_limit
;
255 if (!have_combinations
) {
256 printf("\tvalid interface combinations:\n");
257 have_combinations
= true;
262 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
263 nl_combi
, iface_combination_policy
);
264 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
265 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
266 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]) {
267 printf(" <failed to parse>\n");
268 goto broken_combination
;
271 nla_for_each_nested(nl_limit
, tb_comb
[NL80211_IFACE_COMB_LIMITS
], rem_limit
) {
272 bool ift_comma
= false;
274 err
= nla_parse_nested(tb_limit
, MAX_NL80211_IFACE_LIMIT
,
275 nl_limit
, iface_limit_policy
);
276 if (err
|| !tb_limit
[NL80211_IFACE_LIMIT_TYPES
]) {
277 printf("<failed to parse>\n");
278 goto broken_combination
;
286 nla_for_each_nested(nl_mode
, tb_limit
[NL80211_IFACE_LIMIT_TYPES
], rem_mode
) {
287 printf("%s %s", ift_comma
? "," : "",
288 iftype_name(nla_type(nl_mode
)));
291 printf(" } <= %u", nla_get_u32(tb_limit
[NL80211_IFACE_LIMIT_MAX
]));
295 printf("total <= %d, #channels <= %d%s\n",
296 nla_get_u32(tb_comb
[NL80211_IFACE_COMB_MAXNUM
]),
297 nla_get_u32(tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]),
298 tb_comb
[NL80211_IFACE_COMB_STA_AP_BI_MATCH
] ?
299 ", STA/AP BI must match" : "");
304 if (!have_combinations
)
305 printf("\tinterface combinations are not supported\n");
308 if (tb_msg
[NL80211_ATTR_SUPPORTED_COMMANDS
]) {
309 printf("\tSupported commands:\n");
310 nla_for_each_nested(nl_cmd
, tb_msg
[NL80211_ATTR_SUPPORTED_COMMANDS
], rem_cmd
)
311 printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd
)));
314 if (tb_msg
[NL80211_ATTR_TX_FRAME_TYPES
]) {
315 printf("\tSupported TX frame types:\n");
316 nla_for_each_nested(nl_if
, tb_msg
[NL80211_ATTR_TX_FRAME_TYPES
], rem_if
) {
317 bool printed
= false;
318 nla_for_each_nested(nl_ftype
, nl_if
, rem_ftype
) {
320 printf("\t\t * %s:", iftype_name(nla_type(nl_if
)));
322 printf(" 0x%.4x", nla_get_u16(nl_ftype
));
329 if (tb_msg
[NL80211_ATTR_RX_FRAME_TYPES
]) {
330 printf("\tSupported RX frame types:\n");
331 nla_for_each_nested(nl_if
, tb_msg
[NL80211_ATTR_RX_FRAME_TYPES
], rem_if
) {
332 bool printed
= false;
333 nla_for_each_nested(nl_ftype
, nl_if
, rem_ftype
) {
335 printf("\t\t * %s:", iftype_name(nla_type(nl_if
)));
337 printf(" 0x%.4x", nla_get_u16(nl_ftype
));
344 if (tb_msg
[NL80211_ATTR_SUPPORT_IBSS_RSN
])
345 printf("\tDevice supports RSN-IBSS.\n");
347 if (tb_msg
[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
]) {
348 struct nlattr
*tb_wowlan
[NUM_NL80211_WOWLAN_TRIG
];
349 static struct nla_policy wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
350 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
351 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
352 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
353 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = {
354 .minlen
= sizeof(struct nl80211_wowlan_pattern_support
),
356 [NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
] = { .type
= NLA_FLAG
},
357 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
358 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
359 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
360 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
362 struct nl80211_wowlan_pattern_support
*pat
;
365 err
= nla_parse_nested(tb_wowlan
, MAX_NL80211_WOWLAN_TRIG
,
366 tb_msg
[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
],
368 printf("\tWoWLAN support:");
370 printf(" <failed to parse>\n");
373 if (tb_wowlan
[NL80211_WOWLAN_TRIG_ANY
])
374 printf("\t\t * wake up on anything (device continues operating normally)\n");
375 if (tb_wowlan
[NL80211_WOWLAN_TRIG_DISCONNECT
])
376 printf("\t\t * wake up on disconnect\n");
377 if (tb_wowlan
[NL80211_WOWLAN_TRIG_MAGIC_PKT
])
378 printf("\t\t * wake up on magic packet\n");
379 if (tb_wowlan
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
380 pat
= nla_data(tb_wowlan
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]);
381 printf("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes\n",
382 pat
->max_patterns
, pat
->min_pattern_len
, pat
->max_pattern_len
);
384 if (tb_wowlan
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
385 printf("\t\t * can do GTK rekeying\n");
386 if (tb_wowlan
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
])
387 printf("\t\t * wake up on GTK rekey failure\n");
388 if (tb_wowlan
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
])
389 printf("\t\t * wake up on EAP identity request\n");
390 if (tb_wowlan
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
])
391 printf("\t\t * wake up on 4-way handshake\n");
392 if (tb_wowlan
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
])
393 printf("\t\t * wake up on rfkill release\n");
397 if (tb_msg
[NL80211_ATTR_ROAM_SUPPORT
])
398 printf("\tDevice supports roaming.\n");
403 static int handle_info(struct nl80211_state
*state
,
406 int argc
, char **argv
)
408 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, print_phy_handler
, NULL
);
412 __COMMAND(NULL
, info
, "info", NULL
, NL80211_CMD_GET_WIPHY
, 0, 0, CIB_PHY
, handle_info
,
413 "Show capabilities for the specified wireless device.", NULL
);
414 TOPLEVEL(list
, NULL
, NL80211_CMD_GET_WIPHY
, NLM_F_DUMP
, CIB_NONE
, handle_info
,
415 "List all wireless devices and their capabilities.");
416 TOPLEVEL(phy
, NULL
, NL80211_CMD_GET_WIPHY
, NLM_F_DUMP
, CIB_NONE
, handle_info
, NULL
);