]>
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; |
79f99b9a | 52 | int bandidx = 1; |
9990c1e9 | 53 | int rem_band, rem_freq, rem_rate, rem_mode, rem_cmd; |
79f99b9a JB |
54 | int open; |
55 | ||
56 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
57 | genlmsg_attrlen(gnlh, 0), NULL); | |
58 | ||
59 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) | |
60 | return NL_SKIP; | |
61 | ||
d631650b JB |
62 | if (tb_msg[NL80211_ATTR_WIPHY_NAME]) |
63 | printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME])); | |
64 | ||
79f99b9a | 65 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) { |
d631650b | 66 | printf("\tBand %d:\n", bandidx); |
79f99b9a JB |
67 | bandidx++; |
68 | ||
69 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), | |
70 | nla_len(nl_band), NULL); | |
71 | ||
3dd781cc JB |
72 | #ifdef NL80211_BAND_ATTR_HT_CAPA |
73 | if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) { | |
357c1a5d LR |
74 | __u16 cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]); |
75 | print_ht_capability(cap); | |
3dd781cc JB |
76 | } |
77 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) { | |
0950993f LR |
78 | __u8 exponent = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]); |
79 | print_ampdu_length(exponent); | |
3dd781cc JB |
80 | } |
81 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) { | |
0950993f LR |
82 | __u8 spacing = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]); |
83 | print_ampdu_spacing(spacing); | |
3dd781cc JB |
84 | } |
85 | if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] && | |
7ddfb679 JB |
86 | nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16) |
87 | print_ht_mcs(nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET])); | |
3dd781cc JB |
88 | #endif |
89 | ||
d631650b | 90 | printf("\t\tFrequencies:\n"); |
79f99b9a JB |
91 | |
92 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { | |
379f8397 | 93 | uint32_t freq; |
79f99b9a JB |
94 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), |
95 | nla_len(nl_freq), freq_policy); | |
96 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
97 | continue; | |
379f8397 JB |
98 | freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
99 | printf("\t\t\t* %d MHz [%d]", freq, ieee80211_frequency_to_channel(freq)); | |
c1081c20 | 100 | |
d102c0b6 JB |
101 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && |
102 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
103 | printf(" (%.1f dBm)", 0.01 * nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER])); | |
c1081c20 | 104 | |
79f99b9a | 105 | open = 0; |
ee9cd987 | 106 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) { |
79f99b9a | 107 | print_flag("disabled", &open); |
ee9cd987 JB |
108 | goto next; |
109 | } | |
79f99b9a JB |
110 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) |
111 | print_flag("passive scanning", &open); | |
112 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
113 | print_flag("no IBSS", &open); | |
114 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) | |
115 | print_flag("radar detection", &open); | |
ee9cd987 | 116 | next: |
79f99b9a JB |
117 | if (open) |
118 | printf(")"); | |
119 | printf("\n"); | |
120 | } | |
121 | ||
75dddccc | 122 | printf("\t\tBitrates (non-HT):\n"); |
79f99b9a JB |
123 | |
124 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
125 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
126 | nla_len(nl_rate), rate_policy); | |
127 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
128 | continue; | |
d631650b | 129 | printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE])); |
79f99b9a JB |
130 | open = 0; |
131 | if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE]) | |
132 | print_flag("short preamble supported", &open); | |
133 | if (open) | |
134 | printf(")"); | |
135 | printf("\n"); | |
136 | } | |
137 | } | |
138 | ||
41be37f2 JB |
139 | if (tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) |
140 | printf("\tmax # scan SSIDs: %d\n", | |
141 | nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])); | |
f9c112b6 JB |
142 | if (tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN]) |
143 | printf("\tmax scan IEs length: %d bytes\n", | |
144 | nla_get_u32(tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN])); | |
41be37f2 | 145 | |
625aa4ae JB |
146 | if (tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
147 | unsigned int frag; | |
148 | ||
149 | frag = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
150 | if (frag != (unsigned int)-1) | |
151 | printf("\tFragmentation threshold: %d\n", frag); | |
152 | } | |
153 | ||
154 | if (tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
155 | unsigned int rts; | |
156 | ||
157 | rts = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
158 | if (rts != (unsigned int)-1) | |
159 | printf("\tRTS threshold: %d\n", rts); | |
160 | } | |
161 | ||
b2f92dd0 LT |
162 | if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
163 | unsigned char coverage; | |
164 | ||
165 | coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
166 | /* See handle_distance() for an explanation where the '450' comes from */ | |
167 | printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage); | |
168 | } | |
169 | ||
6367e71a | 170 | if (!tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) |
9990c1e9 | 171 | goto commands; |
6367e71a | 172 | |
d631650b | 173 | printf("\tSupported interface modes:\n"); |
541ef425 | 174 | nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode) |
d631650b | 175 | printf("\t\t * %s\n", iftype_name(nl_mode->nla_type)); |
6367e71a | 176 | |
9990c1e9 MH |
177 | commands: |
178 | if (!tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS]) | |
179 | return NL_SKIP; | |
180 | ||
181 | printf("\tSupported commands:\n"); | |
182 | nla_for_each_nested(nl_cmd, tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS], rem_cmd) | |
183 | printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd))); | |
184 | ||
79f99b9a JB |
185 | return NL_SKIP; |
186 | } | |
187 | ||
7c37a24d JB |
188 | static int handle_info(struct nl80211_state *state, |
189 | struct nl_cb *cb, | |
d631650b JB |
190 | struct nl_msg *msg, |
191 | int argc, char **argv) | |
79f99b9a | 192 | { |
79f99b9a | 193 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL); |
79f99b9a | 194 | |
70391ccf | 195 | return 0; |
79f99b9a | 196 | } |
4698bfc2 | 197 | __COMMAND(NULL, info, "info", NULL, NL80211_CMD_GET_WIPHY, 0, 0, CIB_PHY, handle_info, |
ea35fc0b JB |
198 | "Show capabilities for the specified wireless device."); |
199 | TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, | |
200 | "List all wireless devices and their capabilities."); | |
01ae06f9 | 201 | TOPLEVEL(phy, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL); |