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 int print_phy_handler(struct nl_msg
*msg
, void *arg
)
26 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
27 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
29 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
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
},
38 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
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
},
47 struct nlattr
*nl_band
;
48 struct nlattr
*nl_freq
;
49 struct nlattr
*nl_rate
;
50 struct nlattr
*nl_mode
;
51 struct nlattr
*nl_cmd
;
52 struct nlattr
*nl_if
, *nl_ftype
;
54 int rem_band
, rem_freq
, rem_rate
, rem_mode
, rem_cmd
, rem_ftype
, rem_if
;
57 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
58 genlmsg_attrlen(gnlh
, 0), NULL
);
60 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
63 if (tb_msg
[NL80211_ATTR_WIPHY_NAME
])
64 printf("Wiphy %s\n", nla_get_string(tb_msg
[NL80211_ATTR_WIPHY_NAME
]));
66 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
) {
67 printf("\tBand %d:\n", bandidx
);
70 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
71 nla_len(nl_band
), NULL
);
73 #ifdef NL80211_BAND_ATTR_HT_CAPA
74 if (tb_band
[NL80211_BAND_ATTR_HT_CAPA
]) {
75 __u16 cap
= nla_get_u16(tb_band
[NL80211_BAND_ATTR_HT_CAPA
]);
76 print_ht_capability(cap
);
78 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]) {
79 __u8 exponent
= nla_get_u8(tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
]);
80 print_ampdu_length(exponent
);
82 if (tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]) {
83 __u8 spacing
= nla_get_u8(tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
]);
84 print_ampdu_spacing(spacing
);
86 if (tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
] &&
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
]));
91 printf("\t\tFrequencies:\n");
93 nla_for_each_nested(nl_freq
, tb_band
[NL80211_BAND_ATTR_FREQS
], rem_freq
) {
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
])
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
));
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
]));
107 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
]) {
108 print_flag("disabled", &open
);
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
);
123 printf("\t\tBitrates (non-HT):\n");
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
])
130 printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate
[NL80211_BITRATE_ATTR_RATE
]));
132 if (tb_rate
[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
])
133 print_flag("short preamble supported", &open
);
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
]));
143 if (tb_msg
[NL80211_ATTR_MAX_SCAN_IE_LEN
])
144 printf("\tmax scan IEs length: %d bytes\n",
145 nla_get_u16(tb_msg
[NL80211_ATTR_MAX_SCAN_IE_LEN
]));
147 if (tb_msg
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
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
);
155 if (tb_msg
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
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
);
163 if (tb_msg
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
164 unsigned char coverage
;
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
);
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
]));
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
]));
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
)
186 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode
)));
189 if (tb_msg
[NL80211_ATTR_SOFTWARE_IFTYPES
]) {
190 printf("\tsoftware interface modes (can always be added):\n");
191 nla_for_each_nested(nl_mode
, tb_msg
[NL80211_ATTR_SOFTWARE_IFTYPES
], rem_mode
)
192 printf("\t\t * %s\n", iftype_name(nla_type(nl_mode
)));
195 if (tb_msg
[NL80211_ATTR_INTERFACE_COMBINATIONS
]) {
196 struct nlattr
*nl_combi
;
199 printf("\tvalid interface combinations:\n");
201 nla_for_each_nested(nl_combi
, tb_msg
[NL80211_ATTR_INTERFACE_COMBINATIONS
], rem_combi
) {
202 static struct nla_policy iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
203 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
204 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
205 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
206 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
208 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
209 static struct nla_policy iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
210 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
211 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
213 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
214 struct nlattr
*nl_limit
;
220 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
221 nl_combi
, iface_combination_policy
);
222 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
223 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
224 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]) {
225 printf(" <failed to parse>\n");
226 goto broken_combination
;
229 nla_for_each_nested(nl_limit
, tb_comb
[NL80211_IFACE_COMB_LIMITS
], rem_limit
) {
230 bool ift_comma
= false;
232 err
= nla_parse_nested(tb_limit
, MAX_NL80211_IFACE_LIMIT
,
233 nl_limit
, iface_limit_policy
);
234 if (err
|| !tb_limit
[NL80211_IFACE_LIMIT_TYPES
]) {
235 printf("<failed to parse>\n");
236 goto broken_combination
;
244 nla_for_each_nested(nl_mode
, tb_limit
[NL80211_IFACE_LIMIT_TYPES
], rem_mode
) {
245 printf("%s %s", ift_comma
? "," : "",
246 iftype_name(nla_type(nl_mode
)));
249 printf(" } <= %u", nla_get_u32(tb_limit
[NL80211_IFACE_LIMIT_MAX
]));
253 printf("total <= %d, #channels <= %d%s\n",
254 nla_get_u32(tb_comb
[NL80211_IFACE_COMB_MAXNUM
]),
255 nla_get_u32(tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]),
256 tb_comb
[NL80211_IFACE_COMB_STA_AP_BI_MATCH
] ?
257 ", STA/AP BI must match" : "");
263 if (tb_msg
[NL80211_ATTR_SUPPORTED_COMMANDS
]) {
264 printf("\tSupported commands:\n");
265 nla_for_each_nested(nl_cmd
, tb_msg
[NL80211_ATTR_SUPPORTED_COMMANDS
], rem_cmd
)
266 printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd
)));
269 if (tb_msg
[NL80211_ATTR_TX_FRAME_TYPES
]) {
270 printf("\tSupported TX frame types:\n");
271 nla_for_each_nested(nl_if
, tb_msg
[NL80211_ATTR_TX_FRAME_TYPES
], rem_if
) {
272 bool printed
= false;
273 nla_for_each_nested(nl_ftype
, nl_if
, rem_ftype
) {
275 printf("\t\t * %s:", iftype_name(nla_type(nl_if
)));
277 printf(" 0x%.4x", nla_get_u16(nl_ftype
));
284 if (tb_msg
[NL80211_ATTR_RX_FRAME_TYPES
]) {
285 printf("\tSupported RX frame types:\n");
286 nla_for_each_nested(nl_if
, tb_msg
[NL80211_ATTR_RX_FRAME_TYPES
], rem_if
) {
287 bool printed
= false;
288 nla_for_each_nested(nl_ftype
, nl_if
, rem_ftype
) {
290 printf("\t\t * %s:", iftype_name(nla_type(nl_if
)));
292 printf(" 0x%.4x", nla_get_u16(nl_ftype
));
299 if (tb_msg
[NL80211_ATTR_SUPPORT_IBSS_RSN
])
300 printf("\tDevice supports RSN-IBSS.\n");
302 if (tb_msg
[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
]) {
303 struct nlattr
*tb_wowlan
[NUM_NL80211_WOWLAN_TRIG
];
304 static struct nla_policy wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
305 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
306 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
307 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
308 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = {
309 .minlen
= sizeof(struct nl80211_wowlan_pattern_support
),
312 struct nl80211_wowlan_pattern_support
*pat
;
315 err
= nla_parse_nested(tb_wowlan
, MAX_NL80211_WOWLAN_TRIG
,
316 tb_msg
[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
],
318 printf("\tWoWLAN support:");
320 printf(" <failed to parse>\n");
323 if (tb_wowlan
[NL80211_WOWLAN_TRIG_ANY
])
324 printf("\t\t * any (device continues operating)\n");
325 if (tb_wowlan
[NL80211_WOWLAN_TRIG_DISCONNECT
])
326 printf("\t\t * disconnect\n");
327 if (tb_wowlan
[NL80211_WOWLAN_TRIG_MAGIC_PKT
])
328 printf("\t\t * magic packet\n");
329 if (tb_wowlan
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
330 pat
= nla_data(tb_wowlan
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]);
331 printf("\t\t * up to %u patterns of %u-%u bytes\n",
332 pat
->max_patterns
, pat
->min_pattern_len
, pat
->max_pattern_len
);
340 static int handle_info(struct nl80211_state
*state
,
343 int argc
, char **argv
)
345 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, print_phy_handler
, NULL
);
349 __COMMAND(NULL
, info
, "info", NULL
, NL80211_CMD_GET_WIPHY
, 0, 0, CIB_PHY
, handle_info
,
350 "Show capabilities for the specified wireless device.", NULL
);
351 TOPLEVEL(list
, NULL
, NL80211_CMD_GET_WIPHY
, NLM_F_DUMP
, CIB_NONE
, handle_info
,
352 "List all wireless devices and their capabilities.");
353 TOPLEVEL(phy
, NULL
, NL80211_CMD_GET_WIPHY
, NLM_F_DUMP
, CIB_NONE
, handle_info
, NULL
);