Luis R. Rodriguez | 21878f3 | 2009-02-02 15:39:06 -0800 | [diff] [blame] | 1 | #include <stdbool.h> |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 2 | #include <errno.h> |
Johannes Berg | 2ef1be6 | 2008-04-02 17:40:11 +0200 | [diff] [blame] | 3 | #include <net/if.h> |
| 4 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 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> |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 10 | |
Johannes Berg | f408e01 | 2008-09-18 19:32:11 +0200 | [diff] [blame] | 11 | #include "nl80211.h" |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 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(", "); |
Johannes Berg | 6928312 | 2008-11-23 20:55:23 +0100 | [diff] [blame] | 20 | printf("%s", name); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 21 | *open = 1; |
| 22 | } |
| 23 | |
Johannes Berg | 810e05c | 2011-10-05 17:38:39 +0200 | [diff] [blame] | 24 | static char *cipher_name(__u32 c) |
| 25 | { |
| 26 | static char buf[20]; |
| 27 | |
| 28 | switch (c) { |
| 29 | case 0x000fac01: |
| 30 | return "WEP40 (00-0f-ac:1)"; |
| 31 | case 0x000fac05: |
| 32 | return "WEP104 (00-0f-ac:5)"; |
| 33 | case 0x000fac02: |
| 34 | return "TKIP (00-0f-ac:2)"; |
| 35 | case 0x000fac04: |
| 36 | return "CCMP (00-0f-ac:4)"; |
| 37 | case 0x000fac06: |
| 38 | return "CMAC (00-0f-ac:6)"; |
Vladimir Kondratiev | a8b3da9 | 2012-07-05 14:36:20 +0300 | [diff] [blame] | 39 | case 0x000fac08: |
| 40 | return "GCMP (00-0f-ac:8)"; |
Johannes Berg | 810e05c | 2011-10-05 17:38:39 +0200 | [diff] [blame] | 41 | case 0x00147201: |
| 42 | return "WPI-SMS4 (00-14-72:1)"; |
| 43 | default: |
| 44 | sprintf(buf, "%.2x-%.2x-%.2x:%d", |
| 45 | c >> 24, (c >> 16) & 0xff, |
| 46 | (c >> 8) & 0xff, c & 0xff); |
| 47 | |
| 48 | return buf; |
| 49 | } |
| 50 | } |
| 51 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 52 | static int print_phy_handler(struct nl_msg *msg, void *arg) |
| 53 | { |
| 54 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 55 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 56 | |
| 57 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; |
| 58 | |
| 59 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; |
| 60 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 61 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, |
| 62 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 63 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, |
| 64 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, |
| 65 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, |
Johannes Berg | c1081c2 | 2008-11-23 12:11:26 +0100 | [diff] [blame] | 66 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; |
| 70 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { |
| 71 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, |
| 72 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG }, |
| 73 | }; |
| 74 | |
| 75 | struct nlattr *nl_band; |
| 76 | struct nlattr *nl_freq; |
| 77 | struct nlattr *nl_rate; |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 78 | struct nlattr *nl_mode; |
Marcel Holtmann | 9990c1e | 2009-11-14 20:10:21 +0100 | [diff] [blame] | 79 | struct nlattr *nl_cmd; |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 80 | struct nlattr *nl_if, *nl_ftype; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 81 | int bandidx = 1; |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 82 | int rem_band, rem_freq, rem_rate, rem_mode, rem_cmd, rem_ftype, rem_if; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 83 | int open; |
| 84 | |
| 85 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 86 | genlmsg_attrlen(gnlh, 0), NULL); |
| 87 | |
| 88 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) |
| 89 | return NL_SKIP; |
| 90 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 91 | if (tb_msg[NL80211_ATTR_WIPHY_NAME]) |
| 92 | printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME])); |
| 93 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 94 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) { |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 95 | printf("\tBand %d:\n", bandidx); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 96 | bandidx++; |
| 97 | |
| 98 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), |
| 99 | nla_len(nl_band), NULL); |
| 100 | |
Johannes Berg | 3dd781c | 2008-10-14 18:46:23 +0200 | [diff] [blame] | 101 | if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) { |
Luis R. Rodriguez | 357c1a5 | 2009-12-07 22:05:42 -0500 | [diff] [blame] | 102 | __u16 cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]); |
| 103 | print_ht_capability(cap); |
Johannes Berg | 3dd781c | 2008-10-14 18:46:23 +0200 | [diff] [blame] | 104 | } |
| 105 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) { |
Luis R. Rodriguez | 0950993 | 2009-12-07 22:05:18 -0500 | [diff] [blame] | 106 | __u8 exponent = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]); |
| 107 | print_ampdu_length(exponent); |
Johannes Berg | 3dd781c | 2008-10-14 18:46:23 +0200 | [diff] [blame] | 108 | } |
| 109 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) { |
Luis R. Rodriguez | 0950993 | 2009-12-07 22:05:18 -0500 | [diff] [blame] | 110 | __u8 spacing = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]); |
| 111 | print_ampdu_spacing(spacing); |
Johannes Berg | 3dd781c | 2008-10-14 18:46:23 +0200 | [diff] [blame] | 112 | } |
| 113 | if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] && |
Johannes Berg | 7ddfb67 | 2009-12-08 10:11:22 +0100 | [diff] [blame] | 114 | nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16) |
| 115 | print_ht_mcs(nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET])); |
Johannes Berg | 54eb161 | 2012-11-12 13:07:18 +0100 | [diff] [blame] | 116 | if (tb_band[NL80211_BAND_ATTR_VHT_CAPA] && |
| 117 | tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]) |
| 118 | print_vht_info(nla_get_u32(tb_band[NL80211_BAND_ATTR_VHT_CAPA]), |
| 119 | nla_data(tb_band[NL80211_BAND_ATTR_VHT_MCS_SET])); |
Johannes Berg | 3dd781c | 2008-10-14 18:46:23 +0200 | [diff] [blame] | 120 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 121 | printf("\t\tFrequencies:\n"); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 122 | |
| 123 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { |
Johannes Berg | 379f839 | 2008-12-08 12:53:58 +0100 | [diff] [blame] | 124 | uint32_t freq; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 125 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), |
| 126 | nla_len(nl_freq), freq_policy); |
| 127 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 128 | continue; |
Johannes Berg | 379f839 | 2008-12-08 12:53:58 +0100 | [diff] [blame] | 129 | freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
| 130 | printf("\t\t\t* %d MHz [%d]", freq, ieee80211_frequency_to_channel(freq)); |
Johannes Berg | c1081c2 | 2008-11-23 12:11:26 +0100 | [diff] [blame] | 131 | |
Johannes Berg | d102c0b | 2009-03-24 08:41:42 +0100 | [diff] [blame] | 132 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && |
| 133 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 134 | printf(" (%.1f dBm)", 0.01 * nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER])); |
Johannes Berg | c1081c2 | 2008-11-23 12:11:26 +0100 | [diff] [blame] | 135 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 136 | open = 0; |
Johannes Berg | ee9cd98 | 2009-01-18 18:13:54 +0100 | [diff] [blame] | 137 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) { |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 138 | print_flag("disabled", &open); |
Johannes Berg | ee9cd98 | 2009-01-18 18:13:54 +0100 | [diff] [blame] | 139 | goto next; |
| 140 | } |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 141 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) |
| 142 | print_flag("passive scanning", &open); |
| 143 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) |
| 144 | print_flag("no IBSS", &open); |
| 145 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) |
| 146 | print_flag("radar detection", &open); |
Johannes Berg | ee9cd98 | 2009-01-18 18:13:54 +0100 | [diff] [blame] | 147 | next: |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 148 | if (open) |
| 149 | printf(")"); |
| 150 | printf("\n"); |
| 151 | } |
| 152 | |
Johannes Berg | 75dddcc | 2009-06-30 10:16:43 +0200 | [diff] [blame] | 153 | printf("\t\tBitrates (non-HT):\n"); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 154 | |
| 155 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { |
| 156 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), |
| 157 | nla_len(nl_rate), rate_policy); |
| 158 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 159 | continue; |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 160 | printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE])); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 161 | open = 0; |
| 162 | if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE]) |
| 163 | print_flag("short preamble supported", &open); |
| 164 | if (open) |
| 165 | printf(")"); |
| 166 | printf("\n"); |
| 167 | } |
| 168 | } |
| 169 | |
Johannes Berg | 41be37f | 2008-09-19 17:34:55 +0200 | [diff] [blame] | 170 | if (tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) |
| 171 | printf("\tmax # scan SSIDs: %d\n", |
| 172 | nla_get_u8(tb_msg[NL80211_ATTR_MAX_NUM_SCAN_SSIDS])); |
Johannes Berg | f9c112b | 2010-03-24 23:28:03 -0700 | [diff] [blame] | 173 | if (tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN]) |
| 174 | printf("\tmax scan IEs length: %d bytes\n", |
Johannes Berg | 8eaa9ee | 2010-09-26 09:12:07 +0200 | [diff] [blame] | 175 | nla_get_u16(tb_msg[NL80211_ATTR_MAX_SCAN_IE_LEN])); |
Johannes Berg | 41be37f | 2008-09-19 17:34:55 +0200 | [diff] [blame] | 176 | |
Johannes Berg | 625aa4a | 2009-08-11 11:26:42 +0200 | [diff] [blame] | 177 | if (tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 178 | unsigned int frag; |
| 179 | |
| 180 | frag = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 181 | if (frag != (unsigned int)-1) |
| 182 | printf("\tFragmentation threshold: %d\n", frag); |
| 183 | } |
| 184 | |
| 185 | if (tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 186 | unsigned int rts; |
| 187 | |
| 188 | rts = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 189 | if (rts != (unsigned int)-1) |
| 190 | printf("\tRTS threshold: %d\n", rts); |
| 191 | } |
| 192 | |
Lukáš Turek | b2f92dd | 2010-02-17 21:13:23 -0500 | [diff] [blame] | 193 | if (tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 194 | unsigned char coverage; |
| 195 | |
| 196 | coverage = nla_get_u8(tb_msg[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 197 | /* See handle_distance() for an explanation where the '450' comes from */ |
| 198 | printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage); |
| 199 | } |
| 200 | |
Johannes Berg | 810e05c | 2011-10-05 17:38:39 +0200 | [diff] [blame] | 201 | if (tb_msg[NL80211_ATTR_CIPHER_SUITES]) { |
| 202 | int num = nla_len(tb_msg[NL80211_ATTR_CIPHER_SUITES]) / sizeof(__u32); |
| 203 | int i; |
| 204 | __u32 *ciphers = nla_data(tb_msg[NL80211_ATTR_CIPHER_SUITES]); |
| 205 | if (num > 0) { |
| 206 | printf("\tSupported Ciphers:\n"); |
| 207 | for (i = 0; i < num; i++) |
| 208 | printf("\t\t* %s\n", |
| 209 | cipher_name(ciphers[i])); |
| 210 | } |
| 211 | } |
| 212 | |
Bruno Randolf | afce798 | 2010-12-22 10:54:39 +0900 | [diff] [blame] | 213 | if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX] && |
| 214 | tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX]) |
| 215 | printf("\tAvailable Antennas: TX %#x RX %#x\n", |
| 216 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX]), |
| 217 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX])); |
| 218 | |
| 219 | if (tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 220 | tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]) |
| 221 | printf("\tConfigured Antennas: TX %#x RX %#x\n", |
| 222 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]), |
| 223 | nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX])); |
| 224 | |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 225 | if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) { |
| 226 | printf("\tSupported interface modes:\n"); |
| 227 | nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode) |
Johannes Berg | 8ef6df4 | 2011-02-21 22:12:54 +0100 | [diff] [blame] | 228 | printf("\t\t * %s\n", iftype_name(nla_type(nl_mode))); |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 229 | } |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 230 | |
Johannes Berg | 1c5b4a8 | 2011-05-13 16:53:51 +0200 | [diff] [blame] | 231 | if (tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES]) { |
| 232 | printf("\tsoftware interface modes (can always be added):\n"); |
| 233 | nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES], rem_mode) |
| 234 | printf("\t\t * %s\n", iftype_name(nla_type(nl_mode))); |
| 235 | } |
| 236 | |
| 237 | if (tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS]) { |
| 238 | struct nlattr *nl_combi; |
| 239 | int rem_combi; |
Johannes Berg | f5f6f15 | 2011-06-29 13:20:31 +0200 | [diff] [blame] | 240 | bool have_combinations = false; |
Johannes Berg | 1c5b4a8 | 2011-05-13 16:53:51 +0200 | [diff] [blame] | 241 | |
| 242 | nla_for_each_nested(nl_combi, tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS], rem_combi) { |
| 243 | static struct nla_policy iface_combination_policy[NUM_NL80211_IFACE_COMB] = { |
| 244 | [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED }, |
| 245 | [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, |
| 246 | [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, |
| 247 | [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, |
| 248 | }; |
| 249 | struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB]; |
| 250 | static struct nla_policy iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = { |
| 251 | [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED }, |
| 252 | [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 }, |
| 253 | }; |
| 254 | struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT]; |
| 255 | struct nlattr *nl_limit; |
| 256 | int err, rem_limit; |
| 257 | bool comma = false; |
| 258 | |
Johannes Berg | f5f6f15 | 2011-06-29 13:20:31 +0200 | [diff] [blame] | 259 | if (!have_combinations) { |
| 260 | printf("\tvalid interface combinations:\n"); |
| 261 | have_combinations = true; |
| 262 | } |
| 263 | |
Johannes Berg | 1c5b4a8 | 2011-05-13 16:53:51 +0200 | [diff] [blame] | 264 | printf("\t\t * "); |
| 265 | |
| 266 | err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB, |
| 267 | nl_combi, iface_combination_policy); |
| 268 | if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] || |
| 269 | !tb_comb[NL80211_IFACE_COMB_MAXNUM] || |
| 270 | !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) { |
| 271 | printf(" <failed to parse>\n"); |
| 272 | goto broken_combination; |
| 273 | } |
| 274 | |
| 275 | nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], rem_limit) { |
| 276 | bool ift_comma = false; |
| 277 | |
| 278 | err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT, |
| 279 | nl_limit, iface_limit_policy); |
| 280 | if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) { |
| 281 | printf("<failed to parse>\n"); |
| 282 | goto broken_combination; |
| 283 | } |
| 284 | |
| 285 | if (comma) |
| 286 | printf(", "); |
| 287 | comma = true; |
| 288 | printf("#{"); |
| 289 | |
| 290 | nla_for_each_nested(nl_mode, tb_limit[NL80211_IFACE_LIMIT_TYPES], rem_mode) { |
| 291 | printf("%s %s", ift_comma ? "," : "", |
| 292 | iftype_name(nla_type(nl_mode))); |
| 293 | ift_comma = true; |
| 294 | } |
| 295 | printf(" } <= %u", nla_get_u32(tb_limit[NL80211_IFACE_LIMIT_MAX])); |
| 296 | } |
| 297 | printf(",\n\t\t "); |
| 298 | |
| 299 | printf("total <= %d, #channels <= %d%s\n", |
| 300 | nla_get_u32(tb_comb[NL80211_IFACE_COMB_MAXNUM]), |
| 301 | nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]), |
| 302 | tb_comb[NL80211_IFACE_COMB_STA_AP_BI_MATCH] ? |
| 303 | ", STA/AP BI must match" : ""); |
| 304 | broken_combination: |
| 305 | ; |
| 306 | } |
Johannes Berg | f5f6f15 | 2011-06-29 13:20:31 +0200 | [diff] [blame] | 307 | |
| 308 | if (!have_combinations) |
| 309 | printf("\tinterface combinations are not supported\n"); |
Johannes Berg | 1c5b4a8 | 2011-05-13 16:53:51 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 312 | if (tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS]) { |
| 313 | printf("\tSupported commands:\n"); |
| 314 | nla_for_each_nested(nl_cmd, tb_msg[NL80211_ATTR_SUPPORTED_COMMANDS], rem_cmd) |
| 315 | printf("\t\t * %s\n", command_name(nla_get_u32(nl_cmd))); |
| 316 | } |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 317 | |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 318 | if (tb_msg[NL80211_ATTR_TX_FRAME_TYPES]) { |
| 319 | printf("\tSupported TX frame types:\n"); |
| 320 | nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_TX_FRAME_TYPES], rem_if) { |
| 321 | bool printed = false; |
| 322 | nla_for_each_nested(nl_ftype, nl_if, rem_ftype) { |
| 323 | if (!printed) |
| 324 | printf("\t\t * %s:", iftype_name(nla_type(nl_if))); |
| 325 | printed = true; |
Johannes Berg | 58e3434 | 2012-03-13 09:48:23 +0100 | [diff] [blame] | 326 | printf(" 0x%.2x", nla_get_u16(nl_ftype)); |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 327 | } |
| 328 | if (printed) |
| 329 | printf("\n"); |
| 330 | } |
| 331 | } |
Marcel Holtmann | 9990c1e | 2009-11-14 20:10:21 +0100 | [diff] [blame] | 332 | |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 333 | if (tb_msg[NL80211_ATTR_RX_FRAME_TYPES]) { |
| 334 | printf("\tSupported RX frame types:\n"); |
| 335 | nla_for_each_nested(nl_if, tb_msg[NL80211_ATTR_RX_FRAME_TYPES], rem_if) { |
| 336 | bool printed = false; |
| 337 | nla_for_each_nested(nl_ftype, nl_if, rem_ftype) { |
| 338 | if (!printed) |
| 339 | printf("\t\t * %s:", iftype_name(nla_type(nl_if))); |
| 340 | printed = true; |
Johannes Berg | 58e3434 | 2012-03-13 09:48:23 +0100 | [diff] [blame] | 341 | printf(" 0x%.2x", nla_get_u16(nl_ftype)); |
Johannes Berg | 9a4a14b | 2010-08-24 12:26:56 +0200 | [diff] [blame] | 342 | } |
| 343 | if (printed) |
| 344 | printf("\n"); |
| 345 | } |
| 346 | } |
Marcel Holtmann | 9990c1e | 2009-11-14 20:10:21 +0100 | [diff] [blame] | 347 | |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 348 | if (tb_msg[NL80211_ATTR_SUPPORT_IBSS_RSN]) |
Johannes Berg | 83f1016 | 2011-02-24 15:11:57 +0100 | [diff] [blame] | 349 | printf("\tDevice supports RSN-IBSS.\n"); |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 350 | |
| 351 | if (tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED]) { |
| 352 | struct nlattr *tb_wowlan[NUM_NL80211_WOWLAN_TRIG]; |
| 353 | static struct nla_policy wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 354 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 355 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 356 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 357 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { |
| 358 | .minlen = sizeof(struct nl80211_wowlan_pattern_support), |
| 359 | }, |
Johannes Berg | 3a6636b | 2011-07-12 13:08:37 +0200 | [diff] [blame] | 360 | [NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED] = { .type = NLA_FLAG }, |
| 361 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 362 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 363 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 364 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 365 | }; |
| 366 | struct nl80211_wowlan_pattern_support *pat; |
| 367 | int err; |
| 368 | |
| 369 | err = nla_parse_nested(tb_wowlan, MAX_NL80211_WOWLAN_TRIG, |
| 370 | tb_msg[NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED], |
| 371 | wowlan_policy); |
| 372 | printf("\tWoWLAN support:"); |
| 373 | if (err) { |
| 374 | printf(" <failed to parse>\n"); |
| 375 | } else { |
| 376 | printf("\n"); |
| 377 | if (tb_wowlan[NL80211_WOWLAN_TRIG_ANY]) |
Johannes Berg | 3a6636b | 2011-07-12 13:08:37 +0200 | [diff] [blame] | 378 | printf("\t\t * wake up on anything (device continues operating normally)\n"); |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 379 | if (tb_wowlan[NL80211_WOWLAN_TRIG_DISCONNECT]) |
Johannes Berg | 3a6636b | 2011-07-12 13:08:37 +0200 | [diff] [blame] | 380 | printf("\t\t * wake up on disconnect\n"); |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 381 | if (tb_wowlan[NL80211_WOWLAN_TRIG_MAGIC_PKT]) |
Johannes Berg | 3a6636b | 2011-07-12 13:08:37 +0200 | [diff] [blame] | 382 | printf("\t\t * wake up on magic packet\n"); |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 383 | if (tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 384 | pat = nla_data(tb_wowlan[NL80211_WOWLAN_TRIG_PKT_PATTERN]); |
Johannes Berg | 3a6636b | 2011-07-12 13:08:37 +0200 | [diff] [blame] | 385 | printf("\t\t * wake up on pattern match, up to %u patterns of %u-%u bytes\n", |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 386 | pat->max_patterns, pat->min_pattern_len, pat->max_pattern_len); |
| 387 | } |
Johannes Berg | 3a6636b | 2011-07-12 13:08:37 +0200 | [diff] [blame] | 388 | if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 389 | printf("\t\t * can do GTK rekeying\n"); |
| 390 | if (tb_wowlan[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) |
| 391 | printf("\t\t * wake up on GTK rekey failure\n"); |
| 392 | if (tb_wowlan[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) |
| 393 | printf("\t\t * wake up on EAP identity request\n"); |
| 394 | if (tb_wowlan[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) |
| 395 | printf("\t\t * wake up on 4-way handshake\n"); |
| 396 | if (tb_wowlan[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) |
| 397 | printf("\t\t * wake up on rfkill release\n"); |
Johannes Berg | 3ff2456 | 2011-04-12 13:04:50 +0200 | [diff] [blame] | 398 | } |
Johannes Berg | 83f1016 | 2011-02-24 15:11:57 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Johannes Berg | 2e4f65c | 2011-10-04 14:00:47 +0200 | [diff] [blame] | 401 | if (tb_msg[NL80211_ATTR_ROAM_SUPPORT]) |
| 402 | printf("\tDevice supports roaming.\n"); |
| 403 | |
Johannes Berg | 8b46999 | 2011-11-04 11:53:18 +0100 | [diff] [blame] | 404 | if (tb_msg[NL80211_ATTR_SUPPORT_AP_UAPSD]) |
| 405 | printf("\tDevice supports AP-side u-APSD.\n"); |
| 406 | |
Ben Greear | a82abc2 | 2011-11-28 10:40:22 -0800 | [diff] [blame] | 407 | if (tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 408 | struct ieee80211_ht_cap *cm; |
| 409 | printf("\tHT Capability overrides:\n"); |
| 410 | if (nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]) >= sizeof(*cm)) { |
| 411 | cm = nla_data(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 412 | printf("\t\t * MCS: %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" |
| 413 | " %02hhx %02hhx %02hhx %02hhx\n", |
| 414 | cm->mcs.rx_mask[0], cm->mcs.rx_mask[1], |
| 415 | cm->mcs.rx_mask[2], cm->mcs.rx_mask[3], |
| 416 | cm->mcs.rx_mask[4], cm->mcs.rx_mask[5], |
| 417 | cm->mcs.rx_mask[6], cm->mcs.rx_mask[7], |
| 418 | cm->mcs.rx_mask[8], cm->mcs.rx_mask[9]); |
| 419 | if (cm->cap_info & htole16(IEEE80211_HT_CAP_MAX_AMSDU)) |
| 420 | printf("\t\t * maximum A-MSDU length\n"); |
| 421 | if (cm->cap_info & htole16(IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
| 422 | printf("\t\t * supported channel width\n"); |
| 423 | if (cm->cap_info & htole16(IEEE80211_HT_CAP_SGI_40)) |
| 424 | printf("\t\t * short GI for 40 MHz\n"); |
| 425 | if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_FACTOR) |
| 426 | printf("\t\t * max A-MPDU length exponent\n"); |
| 427 | if (cm->ampdu_params_info & IEEE80211_HT_AMPDU_PARM_DENSITY) |
| 428 | printf("\t\t * min MPDU start spacing\n"); |
| 429 | } else { |
| 430 | printf("\tERROR: capabilities mask is too short, expected: %d, received: %d\n", |
| 431 | (int)(sizeof(*cm)), |
| 432 | (int)(nla_len(tb_msg[NL80211_ATTR_HT_CAPABILITY_MASK]))); |
| 433 | } |
| 434 | } |
| 435 | |
Johannes Berg | 632004a | 2011-12-14 15:08:34 +0100 | [diff] [blame] | 436 | if (tb_msg[NL80211_ATTR_FEATURE_FLAGS]) { |
Johannes Berg | d28df6b | 2012-10-16 20:12:37 +0200 | [diff] [blame] | 437 | unsigned int features = nla_get_u32(tb_msg[NL80211_ATTR_FEATURE_FLAGS]); |
| 438 | |
| 439 | if (features & NL80211_FEATURE_SK_TX_STATUS) |
Johannes Berg | 632004a | 2011-12-14 15:08:34 +0100 | [diff] [blame] | 440 | printf("\tDevice supports TX status socket option.\n"); |
Johannes Berg | d28df6b | 2012-10-16 20:12:37 +0200 | [diff] [blame] | 441 | if (features & NL80211_FEATURE_HT_IBSS) |
Johannes Berg | 632004a | 2011-12-14 15:08:34 +0100 | [diff] [blame] | 442 | printf("\tDevice supports HT-IBSS.\n"); |
Johannes Berg | d28df6b | 2012-10-16 20:12:37 +0200 | [diff] [blame] | 443 | if (features & NL80211_FEATURE_INACTIVITY_TIMER) |
| 444 | printf("\tDevice has client inactivity timer.\n"); |
| 445 | if (features & NL80211_FEATURE_CELL_BASE_REG_HINTS) |
| 446 | printf("\tDevice accepts cell base station regulatory hints.\n"); |
| 447 | if (features & NL80211_FEATURE_P2P_DEVICE_NEEDS_CHANNEL) |
| 448 | printf("\tP2P Device uses a channel (of the concurrent ones)\n"); |
Sam Leffler | fe86223 | 2012-10-17 12:20:04 -0700 | [diff] [blame] | 449 | if (features & NL80211_FEATURE_LOW_PRIORITY_SCAN) |
| 450 | printf("\tDevice supports low priority scan.\n"); |
| 451 | if (features & NL80211_FEATURE_SCAN_FLUSH) |
| 452 | printf("\tDevice supports scan flush.\n"); |
Antonio Quartulli | afa2be2 | 2012-10-26 16:41:47 +0200 | [diff] [blame] | 453 | if (features & NL80211_FEATURE_AP_SCAN) |
| 454 | printf("\tDevice supports AP scan.\n"); |
Johannes Berg | 632004a | 2011-12-14 15:08:34 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 457 | return NL_SKIP; |
| 458 | } |
| 459 | |
Johannes Berg | 7c37a24 | 2009-04-08 13:13:28 +0200 | [diff] [blame] | 460 | static int handle_info(struct nl80211_state *state, |
| 461 | struct nl_cb *cb, |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 462 | struct nl_msg *msg, |
Johannes Berg | 05514f9 | 2012-07-19 11:50:50 +0200 | [diff] [blame] | 463 | int argc, char **argv, |
| 464 | enum id_input id) |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 465 | { |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 466 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 467 | |
Johannes Berg | 70391cc | 2008-09-16 18:35:06 +0200 | [diff] [blame] | 468 | return 0; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 469 | } |
Johannes Berg | 4698bfc | 2009-08-24 12:53:34 +0200 | [diff] [blame] | 470 | __COMMAND(NULL, info, "info", NULL, NL80211_CMD_GET_WIPHY, 0, 0, CIB_PHY, handle_info, |
Johannes Berg | 1633ddf | 2010-11-24 08:16:47 +0100 | [diff] [blame] | 471 | "Show capabilities for the specified wireless device.", NULL); |
Johannes Berg | ea35fc0 | 2009-05-05 14:56:21 +0200 | [diff] [blame] | 472 | TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, |
| 473 | "List all wireless devices and their capabilities."); |
Johannes Berg | 01ae06f | 2009-05-05 14:48:16 +0200 | [diff] [blame] | 474 | TOPLEVEL(phy, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info, NULL); |
Johannes Berg | bcdff0b | 2012-11-15 15:15:10 +0100 | [diff] [blame] | 475 | |
| 476 | static int handle_commands(struct nl80211_state *state, |
| 477 | struct nl_cb *cb, struct nl_msg *msg, |
| 478 | int argc, char **argv, enum id_input id) |
| 479 | { |
| 480 | int i; |
| 481 | for (i = 1; i < NL80211_CMD_MAX; i++) |
| 482 | printf("%d (0x%x): %s\n", i, i, command_name(i)); |
| 483 | /* don't send netlink messages */ |
| 484 | return 2; |
| 485 | } |
| 486 | TOPLEVEL(commands, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_NONE, handle_commands, |
| 487 | "list all known commands and their decimal & hex value"); |