Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1 | #include <net/if.h> |
| 2 | #include <errno.h> |
| 3 | #include <string.h> |
| 4 | #include <ctype.h> |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 5 | #include <stdbool.h> |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 6 | |
| 7 | #include <netlink/genl/genl.h> |
| 8 | #include <netlink/genl/family.h> |
| 9 | #include <netlink/genl/ctrl.h> |
| 10 | #include <netlink/msg.h> |
| 11 | #include <netlink/attr.h> |
| 12 | |
| 13 | #include "nl80211.h" |
| 14 | #include "iw.h" |
| 15 | |
Marcel Holtmann | 92a04ec | 2009-05-04 01:48:45 -0700 | [diff] [blame] | 16 | #define WLAN_CAPABILITY_ESS (1<<0) |
| 17 | #define WLAN_CAPABILITY_IBSS (1<<1) |
| 18 | #define WLAN_CAPABILITY_CF_POLLABLE (1<<2) |
| 19 | #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3) |
| 20 | #define WLAN_CAPABILITY_PRIVACY (1<<4) |
| 21 | #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5) |
| 22 | #define WLAN_CAPABILITY_PBCC (1<<6) |
| 23 | #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7) |
| 24 | #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8) |
| 25 | #define WLAN_CAPABILITY_QOS (1<<9) |
| 26 | #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10) |
| 27 | #define WLAN_CAPABILITY_APSD (1<<11) |
| 28 | #define WLAN_CAPABILITY_DSSS_OFDM (1<<13) |
| 29 | |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 30 | static unsigned char wifi_oui[3] = { 0x00, 0x50, 0xf2 }; |
| 31 | static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac }; |
| 32 | |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 33 | struct scan_params { |
| 34 | bool unknown; |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 35 | enum print_ie_type type; |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 36 | bool show_both_ie_sets; |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
Luis R. Rodriguez | 2b690f0 | 2010-02-19 13:55:58 -0500 | [diff] [blame] | 39 | #define IEEE80211_COUNTRY_EXTENSION_ID 201 |
| 40 | |
Johannes Berg | 7272571 | 2010-09-22 11:32:54 +0200 | [diff] [blame] | 41 | union ieee80211_country_ie_triplet { |
| 42 | struct { |
| 43 | __u8 first_channel; |
| 44 | __u8 num_channels; |
| 45 | __s8 max_power; |
| 46 | } __attribute__ ((packed)) chans; |
| 47 | struct { |
| 48 | __u8 reg_extension_id; |
| 49 | __u8 reg_class; |
| 50 | __u8 coverage_class; |
| 51 | } __attribute__ ((packed)) ext; |
Luis R. Rodriguez | 2b690f0 | 2010-02-19 13:55:58 -0500 | [diff] [blame] | 52 | } __attribute__ ((packed)); |
| 53 | |
Johannes Berg | 7c37a24 | 2009-04-08 13:13:28 +0200 | [diff] [blame] | 54 | static int handle_scan(struct nl80211_state *state, |
| 55 | struct nl_cb *cb, |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 56 | struct nl_msg *msg, |
| 57 | int argc, char **argv) |
| 58 | { |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 59 | struct nl_msg *ssids = NULL, *freqs = NULL; |
| 60 | char *eptr; |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 61 | int err = -ENOBUFS; |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 62 | int i; |
| 63 | enum { |
| 64 | NONE, |
| 65 | FREQ, |
Johannes Berg | 64797a7 | 2010-03-24 23:38:25 -0700 | [diff] [blame] | 66 | IES, |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 67 | SSID, |
| 68 | DONE, |
| 69 | } parse = NONE; |
| 70 | int freq; |
| 71 | bool passive = false, have_ssids = false, have_freqs = false; |
Johannes Berg | 64797a7 | 2010-03-24 23:38:25 -0700 | [diff] [blame] | 72 | size_t tmp; |
| 73 | unsigned char *ies; |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 74 | |
| 75 | ssids = nlmsg_alloc(); |
| 76 | if (!ssids) |
| 77 | return -ENOMEM; |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 78 | |
| 79 | freqs = nlmsg_alloc(); |
| 80 | if (!freqs) { |
| 81 | nlmsg_free(ssids); |
| 82 | return -ENOMEM; |
| 83 | } |
| 84 | |
| 85 | for (i = 0; i < argc; i++) { |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 86 | switch (parse) { |
| 87 | case NONE: |
Johannes Berg | 64797a7 | 2010-03-24 23:38:25 -0700 | [diff] [blame] | 88 | if (strcmp(argv[i], "freq") == 0) { |
| 89 | parse = FREQ; |
| 90 | have_freqs = true; |
| 91 | break; |
| 92 | } else if (strcmp(argv[i], "ies") == 0) { |
| 93 | parse = IES; |
| 94 | break; |
| 95 | } else if (strcmp(argv[i], "ssid") == 0) { |
| 96 | parse = SSID; |
| 97 | have_ssids = true; |
| 98 | break; |
| 99 | } else if (strcmp(argv[i], "passive") == 0) { |
| 100 | parse = DONE; |
| 101 | passive = true; |
| 102 | break; |
| 103 | } |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 104 | case DONE: |
| 105 | return 1; |
| 106 | case FREQ: |
| 107 | freq = strtoul(argv[i], &eptr, 10); |
Johannes Berg | cc12e89 | 2011-03-02 14:45:32 +0100 | [diff] [blame] | 108 | if (eptr != argv[i] + strlen(argv[i])) { |
| 109 | /* failed to parse as number -- maybe a tag? */ |
| 110 | i--; |
| 111 | parse = NONE; |
| 112 | continue; |
| 113 | } |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 114 | NLA_PUT_U32(freqs, i, freq); |
Johannes Berg | 64797a7 | 2010-03-24 23:38:25 -0700 | [diff] [blame] | 115 | break; |
| 116 | case IES: |
| 117 | ies = parse_hex(argv[i], &tmp); |
| 118 | if (!ies) |
| 119 | goto nla_put_failure; |
| 120 | NLA_PUT(msg, NL80211_ATTR_IE, tmp, ies); |
| 121 | free(ies); |
| 122 | parse = NONE; |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 123 | break; |
| 124 | case SSID: |
| 125 | NLA_PUT(ssids, i, strlen(argv[i]), argv[i]); |
| 126 | break; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (!have_ssids) |
| 131 | NLA_PUT(ssids, 1, 0, ""); |
| 132 | if (!passive) |
| 133 | nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids); |
| 134 | |
| 135 | if (have_freqs) |
| 136 | nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 137 | |
| 138 | err = 0; |
| 139 | nla_put_failure: |
| 140 | nlmsg_free(ssids); |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 141 | nlmsg_free(freqs); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 142 | return err; |
| 143 | } |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 144 | |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 145 | static void tab_on_first(bool *first) |
| 146 | { |
| 147 | if (!*first) |
| 148 | printf("\t"); |
| 149 | else |
| 150 | *first = false; |
| 151 | } |
| 152 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 153 | static void print_ssid(const uint8_t type, uint8_t len, const uint8_t *data) |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 154 | { |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 155 | printf(" "); |
Johannes Berg | 748f848 | 2009-05-24 16:48:17 +0200 | [diff] [blame] | 156 | print_ssid_escaped(len, data); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 157 | printf("\n"); |
| 158 | } |
| 159 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 160 | static void print_supprates(const uint8_t type, uint8_t len, const uint8_t *data) |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 161 | { |
| 162 | int i; |
| 163 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 164 | printf(" "); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 165 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 166 | for (i = 0; i < len; i++) { |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 167 | int r = data[i] & 0x7f; |
| 168 | printf("%d.%d%s ", r/2, 5*(r&1), data[i] & 0x80 ? "*":""); |
| 169 | } |
| 170 | printf("\n"); |
| 171 | } |
| 172 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 173 | static void print_ds(const uint8_t type, uint8_t len, const uint8_t *data) |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 174 | { |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 175 | printf(" channel %d\n", data[0]); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Luis R. Rodriguez | 2b690f0 | 2010-02-19 13:55:58 -0500 | [diff] [blame] | 178 | static const char *country_env_str(char environment) |
| 179 | { |
| 180 | switch (environment) { |
| 181 | case 'I': |
| 182 | return "Indoor only"; |
| 183 | case 'O': |
| 184 | return "Outdoor only"; |
| 185 | case ' ': |
| 186 | return "Indoor/Outdoor"; |
| 187 | default: |
| 188 | return "bogus"; |
| 189 | } |
| 190 | } |
| 191 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 192 | static void print_country(const uint8_t type, uint8_t len, const uint8_t *data) |
Marcel Holtmann | b7e8fa3 | 2009-05-04 01:48:43 -0700 | [diff] [blame] | 193 | { |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 194 | printf(" %.*s", 2, data); |
Luis R. Rodriguez | 2b690f0 | 2010-02-19 13:55:58 -0500 | [diff] [blame] | 195 | |
| 196 | printf("\tEnvironment: %s\n", country_env_str(data[2])); |
| 197 | |
| 198 | data += 3; |
| 199 | len -= 3; |
| 200 | |
| 201 | if (len < 3) { |
| 202 | printf("\t\tNo country IE triplets present\n"); |
| 203 | return; |
Marcel Holtmann | b7e8fa3 | 2009-05-04 01:48:43 -0700 | [diff] [blame] | 204 | } |
Luis R. Rodriguez | 2b690f0 | 2010-02-19 13:55:58 -0500 | [diff] [blame] | 205 | |
| 206 | while (len >= 3) { |
| 207 | int end_channel; |
Johannes Berg | 7272571 | 2010-09-22 11:32:54 +0200 | [diff] [blame] | 208 | union ieee80211_country_ie_triplet *triplet = (void *) data; |
Luis R. Rodriguez | 2b690f0 | 2010-02-19 13:55:58 -0500 | [diff] [blame] | 209 | |
| 210 | if (triplet->ext.reg_extension_id >= IEEE80211_COUNTRY_EXTENSION_ID) { |
| 211 | printf("\t\tExtension ID: %d Regulatory Class: %d Coverage class: %d (up to %dm)\n", |
| 212 | triplet->ext.reg_extension_id, |
| 213 | triplet->ext.reg_class, |
| 214 | triplet->ext.coverage_class, |
| 215 | triplet->ext.coverage_class * 450); |
| 216 | |
| 217 | data += 3; |
| 218 | len -= 3; |
| 219 | continue; |
| 220 | } |
| 221 | |
| 222 | /* 2 GHz */ |
| 223 | if (triplet->chans.first_channel <= 14) |
| 224 | end_channel = triplet->chans.first_channel + (triplet->chans.num_channels - 1); |
| 225 | else |
| 226 | end_channel = triplet->chans.first_channel + (4 * (triplet->chans.num_channels - 1)); |
| 227 | |
Luis R. Rodriguez | a9859d3 | 2010-10-18 11:37:56 -0700 | [diff] [blame] | 228 | printf("\t\tChannels [%d - %d] @ %d dBm\n", triplet->chans.first_channel, end_channel, triplet->chans.max_power); |
Luis R. Rodriguez | 2b690f0 | 2010-02-19 13:55:58 -0500 | [diff] [blame] | 229 | |
| 230 | data += 3; |
| 231 | len -= 3; |
| 232 | } |
| 233 | |
| 234 | return; |
Marcel Holtmann | b7e8fa3 | 2009-05-04 01:48:43 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Marcel Holtmann | d1563a1 | 2009-05-04 09:06:07 -0700 | [diff] [blame] | 237 | static void print_powerconstraint(const uint8_t type, uint8_t len, const uint8_t *data) |
| 238 | { |
| 239 | printf(" %d dB\n", data[0]); |
| 240 | } |
| 241 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 242 | static void print_erp(const uint8_t type, uint8_t len, const uint8_t *data) |
Marcel Holtmann | fc4d148 | 2009-05-04 01:48:42 -0700 | [diff] [blame] | 243 | { |
| 244 | if (data[0] == 0x00) |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 245 | printf(" <no flags>"); |
Marcel Holtmann | fc4d148 | 2009-05-04 01:48:42 -0700 | [diff] [blame] | 246 | if (data[0] & 0x01) |
| 247 | printf(" NonERP_Present"); |
| 248 | if (data[0] & 0x02) |
| 249 | printf(" Use_Protection"); |
| 250 | if (data[0] & 0x04) |
| 251 | printf(" Barker_Preamble_Mode"); |
| 252 | printf("\n"); |
| 253 | } |
| 254 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 255 | static void print_cipher(const uint8_t *data) |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 256 | { |
| 257 | if (memcmp(data, wifi_oui, 3) == 0) { |
| 258 | switch (data[3]) { |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 259 | case 0: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 260 | printf("Use group cipher suite"); |
| 261 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 262 | case 1: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 263 | printf("WEP-40"); |
| 264 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 265 | case 2: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 266 | printf("TKIP"); |
| 267 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 268 | case 4: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 269 | printf("CCMP"); |
| 270 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 271 | case 5: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 272 | printf("WEP-104"); |
| 273 | break; |
| 274 | default: |
Johannes Berg | 332769c | 2009-05-05 10:43:33 +0200 | [diff] [blame] | 275 | printf("%.02x-%.02x-%.02x:%d", |
Johannes Berg | 5594fd2 | 2009-05-04 13:06:07 +0200 | [diff] [blame] | 276 | data[0], data[1] ,data[2], data[3]); |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 277 | break; |
| 278 | } |
| 279 | } else if (memcmp(data, ieee80211_oui, 3) == 0) { |
| 280 | switch (data[3]) { |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 281 | case 0: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 282 | printf("Use group cipher suite"); |
| 283 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 284 | case 1: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 285 | printf("WEP-40"); |
| 286 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 287 | case 2: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 288 | printf("TKIP"); |
| 289 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 290 | case 4: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 291 | printf("CCMP"); |
| 292 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 293 | case 5: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 294 | printf("WEP-104"); |
| 295 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 296 | case 6: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 297 | printf("AES-128-CMAC"); |
| 298 | break; |
| 299 | default: |
Johannes Berg | 332769c | 2009-05-05 10:43:33 +0200 | [diff] [blame] | 300 | printf("%.02x-%.02x-%.02x:%d", |
Johannes Berg | 5594fd2 | 2009-05-04 13:06:07 +0200 | [diff] [blame] | 301 | data[0], data[1] ,data[2], data[3]); |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | } else |
Johannes Berg | 332769c | 2009-05-05 10:43:33 +0200 | [diff] [blame] | 305 | printf("%.02x-%.02x-%.02x:%d", |
Johannes Berg | 5594fd2 | 2009-05-04 13:06:07 +0200 | [diff] [blame] | 306 | data[0], data[1] ,data[2], data[3]); |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 309 | static void print_auth(const uint8_t *data) |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 310 | { |
| 311 | if (memcmp(data, wifi_oui, 3) == 0) { |
| 312 | switch (data[3]) { |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 313 | case 1: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 314 | printf("IEEE 802.1X"); |
| 315 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 316 | case 2: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 317 | printf("PSK"); |
| 318 | break; |
| 319 | default: |
Johannes Berg | 332769c | 2009-05-05 10:43:33 +0200 | [diff] [blame] | 320 | printf("%.02x-%.02x-%.02x:%d", |
Johannes Berg | 5594fd2 | 2009-05-04 13:06:07 +0200 | [diff] [blame] | 321 | data[0], data[1] ,data[2], data[3]); |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 322 | break; |
| 323 | } |
| 324 | } else if (memcmp(data, ieee80211_oui, 3) == 0) { |
| 325 | switch (data[3]) { |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 326 | case 1: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 327 | printf("IEEE 802.1X"); |
| 328 | break; |
Johannes Berg | 510e0e2 | 2009-05-05 10:45:30 +0200 | [diff] [blame] | 329 | case 2: |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 330 | printf("PSK"); |
| 331 | break; |
Johannes Berg | 0fe1c41 | 2009-05-05 11:21:13 +0200 | [diff] [blame] | 332 | case 3: |
| 333 | printf("FT/IEEE 802.1X"); |
| 334 | break; |
| 335 | case 4: |
| 336 | printf("FT/PSK"); |
| 337 | break; |
| 338 | case 5: |
| 339 | printf("IEEE 802.1X/SHA-256"); |
| 340 | break; |
| 341 | case 6: |
| 342 | printf("PSK/SHA-256"); |
| 343 | break; |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 344 | default: |
Johannes Berg | 332769c | 2009-05-05 10:43:33 +0200 | [diff] [blame] | 345 | printf("%.02x-%.02x-%.02x:%d", |
Johannes Berg | 5594fd2 | 2009-05-04 13:06:07 +0200 | [diff] [blame] | 346 | data[0], data[1] ,data[2], data[3]); |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 347 | break; |
| 348 | } |
| 349 | } else |
Johannes Berg | 332769c | 2009-05-05 10:43:33 +0200 | [diff] [blame] | 350 | printf("%.02x-%.02x-%.02x:%d", |
Johannes Berg | 5594fd2 | 2009-05-04 13:06:07 +0200 | [diff] [blame] | 351 | data[0], data[1] ,data[2], data[3]); |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 354 | static void print_rsn_ie(const char *defcipher, const char *defauth, |
| 355 | uint8_t len, const uint8_t *data) |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 356 | { |
| 357 | bool first = true; |
| 358 | __u16 version, count, capa; |
| 359 | int i; |
| 360 | |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 361 | version = data[0] + (data[1] << 8); |
| 362 | tab_on_first(&first); |
| 363 | printf("\t * Version: %d\n", version); |
| 364 | |
| 365 | data += 2; |
| 366 | len -= 2; |
| 367 | |
| 368 | if (len < 4) { |
| 369 | tab_on_first(&first); |
| 370 | printf("\t * Group cipher: %s\n", defcipher); |
| 371 | printf("\t * Pairwise ciphers: %s\n", defcipher); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | tab_on_first(&first); |
| 376 | printf("\t * Group cipher: "); |
| 377 | print_cipher(data); |
| 378 | printf("\n"); |
| 379 | |
| 380 | data += 4; |
| 381 | len -= 4; |
| 382 | |
| 383 | if (len < 2) { |
| 384 | tab_on_first(&first); |
| 385 | printf("\t * Pairwise ciphers: %s\n", defcipher); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | count = data[0] | (data[1] << 8); |
Marcel Holtmann | 31d477f | 2009-05-04 09:49:09 -0700 | [diff] [blame] | 390 | if (2 + (count * 4) > len) |
| 391 | goto invalid; |
| 392 | |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 393 | tab_on_first(&first); |
| 394 | printf("\t * Pairwise ciphers:"); |
Marcel Holtmann | 31d477f | 2009-05-04 09:49:09 -0700 | [diff] [blame] | 395 | for (i = 0; i < count; i++) { |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 396 | printf(" "); |
| 397 | print_cipher(data + 2 + (i * 4)); |
| 398 | } |
| 399 | printf("\n"); |
| 400 | |
| 401 | data += 2 + (count * 4); |
| 402 | len -= 2 + (count * 4); |
| 403 | |
| 404 | if (len < 2) { |
| 405 | tab_on_first(&first); |
| 406 | printf("\t * Authentication suites: %s\n", defauth); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | count = data[0] | (data[1] << 8); |
Marcel Holtmann | 31d477f | 2009-05-04 09:49:09 -0700 | [diff] [blame] | 411 | if (2 + (count * 4) > len) |
| 412 | goto invalid; |
| 413 | |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 414 | tab_on_first(&first); |
| 415 | printf("\t * Authentication suites:"); |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 416 | for (i = 0; i < count; i++) { |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 417 | printf(" "); |
| 418 | print_auth(data + 2 + (i * 4)); |
| 419 | } |
| 420 | printf("\n"); |
| 421 | |
| 422 | data += 2 + (count * 4); |
| 423 | len -= 2 + (count * 4); |
| 424 | |
Johannes Berg | 6a4f24e | 2009-05-04 18:57:03 +0200 | [diff] [blame] | 425 | if (len >= 2) { |
| 426 | capa = data[0] | (data[1] << 8); |
| 427 | tab_on_first(&first); |
Johannes Berg | cadbe89 | 2009-05-05 11:33:34 +0200 | [diff] [blame] | 428 | printf("\t * Capabilities:"); |
| 429 | if (capa & 0x0001) |
| 430 | printf(" PreAuth"); |
| 431 | if (capa & 0x0002) |
| 432 | printf(" NoPairwise"); |
| 433 | switch ((capa & 0x000c) >> 2) { |
| 434 | case 0: |
| 435 | break; |
| 436 | case 1: |
| 437 | printf(" 2-PTKSA-RC"); |
| 438 | break; |
| 439 | case 2: |
| 440 | printf(" 4-PTKSA-RC"); |
| 441 | break; |
| 442 | case 3: |
| 443 | printf(" 16-PTKSA-RC"); |
| 444 | break; |
| 445 | } |
| 446 | switch ((capa & 0x0030) >> 4) { |
| 447 | case 0: |
| 448 | break; |
| 449 | case 1: |
| 450 | printf(" 2-GTKSA-RC"); |
| 451 | break; |
| 452 | case 2: |
| 453 | printf(" 4-GTKSA-RC"); |
| 454 | break; |
| 455 | case 3: |
| 456 | printf(" 16-GTKSA-RC"); |
| 457 | break; |
| 458 | } |
| 459 | if (capa & 0x0040) |
| 460 | printf(" MFP-required"); |
| 461 | if (capa & 0x0080) |
| 462 | printf(" MFP-capable"); |
| 463 | if (capa & 0x0200) |
| 464 | printf(" Peerkey-enabled"); |
| 465 | if (capa & 0x0400) |
| 466 | printf(" SPP-AMSDU-capable"); |
| 467 | if (capa & 0x0800) |
| 468 | printf(" SPP-AMSDU-required"); |
| 469 | printf(" (0x%.4x)\n", capa); |
Johannes Berg | 6a4f24e | 2009-05-04 18:57:03 +0200 | [diff] [blame] | 470 | data += 2; |
| 471 | len -= 2; |
| 472 | } |
Marcel Holtmann | 31d477f | 2009-05-04 09:49:09 -0700 | [diff] [blame] | 473 | |
Johannes Berg | 5ba3f52 | 2010-09-29 12:45:06 +0200 | [diff] [blame] | 474 | if (len >= 2) { |
| 475 | int pmkid_count = data[0] | (data[1] << 8); |
| 476 | |
| 477 | if (len >= 2 + 16 * pmkid_count) { |
| 478 | tab_on_first(&first); |
| 479 | printf("\t * %d PMKIDs\n", pmkid_count); |
| 480 | /* not printing PMKID values */ |
| 481 | data += 2 + 16 * pmkid_count; |
| 482 | len -= 2 + 16 * pmkid_count; |
| 483 | } else |
| 484 | goto invalid; |
| 485 | } |
| 486 | |
| 487 | if (len >= 4) { |
| 488 | tab_on_first(&first); |
| 489 | printf("\t * Group mgmt cipher suite: "); |
| 490 | print_cipher(data); |
| 491 | printf("\n"); |
| 492 | data += 4; |
| 493 | len -= 4; |
| 494 | } |
| 495 | |
Johannes Berg | cadbe89 | 2009-05-05 11:33:34 +0200 | [diff] [blame] | 496 | invalid: |
Marcel Holtmann | 31d477f | 2009-05-04 09:49:09 -0700 | [diff] [blame] | 497 | if (len != 0) { |
| 498 | printf("\t\t * bogus tail data (%d):", len); |
| 499 | while (len) { |
| 500 | printf(" %.2x", *data); |
| 501 | data++; |
| 502 | len--; |
| 503 | } |
| 504 | printf("\n"); |
| 505 | } |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 508 | static void print_rsn(const uint8_t type, uint8_t len, const uint8_t *data) |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 509 | { |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 510 | print_rsn_ie("CCMP", "IEEE 802.1X", len, data); |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Luis R. Rodriguez | 0c445c2 | 2009-12-07 20:55:25 -0500 | [diff] [blame] | 513 | static void print_ht_capa(const uint8_t type, uint8_t len, const uint8_t *data) |
| 514 | { |
Luis R. Rodriguez | 357c1a5 | 2009-12-07 22:05:42 -0500 | [diff] [blame] | 515 | printf("\n"); |
Johannes Berg | 7ddfb67 | 2009-12-08 10:11:22 +0100 | [diff] [blame] | 516 | print_ht_capability(data[0] | (data[1] << 8)); |
| 517 | print_ampdu_length(data[2] & 3); |
Christian Lamparter | c79c746 | 2010-06-27 00:51:23 +0200 | [diff] [blame] | 518 | print_ampdu_spacing((data[2] >> 2) & 7); |
Johannes Berg | 7ddfb67 | 2009-12-08 10:11:22 +0100 | [diff] [blame] | 519 | print_ht_mcs(data + 3); |
Luis R. Rodriguez | 0c445c2 | 2009-12-07 20:55:25 -0500 | [diff] [blame] | 520 | } |
| 521 | |
Johannes Berg | be7602f | 2010-09-01 19:43:54 +0200 | [diff] [blame] | 522 | static void print_ht_op(const uint8_t type, uint8_t len, const uint8_t *data) |
| 523 | { |
| 524 | static const char *offset[4] = { |
| 525 | "no secondary", |
| 526 | "above", |
| 527 | "[reserved!]", |
| 528 | "below", |
| 529 | }; |
| 530 | static const char *protection[4] = { |
| 531 | "no", |
| 532 | "nonmember", |
| 533 | "20 MHz", |
| 534 | "non-HT mixed", |
| 535 | }; |
| 536 | static const char *sta_chan_width[2] = { |
| 537 | "20 MHz", |
| 538 | "any", |
| 539 | }; |
| 540 | |
| 541 | printf("\n"); |
| 542 | printf("\t\t * primary channel: %d\n", data[0]); |
| 543 | printf("\t\t * secondary channel offset: %s\n", |
| 544 | offset[data[1] & 0x3]); |
| 545 | printf("\t\t * STA channel width: %s\n", sta_chan_width[(data[1] & 0x4)>>2]); |
| 546 | printf("\t\t * RIFS: %d\n", (data[1] & 0x8)>>3); |
| 547 | printf("\t\t * HT protection: %s\n", protection[data[2] & 0x3]); |
| 548 | printf("\t\t * non-GF present: %d\n", (data[2] & 0x4) >> 2); |
| 549 | printf("\t\t * OBSS non-GF present: %d\n", (data[2] & 0x10) >> 4); |
| 550 | printf("\t\t * dual beacon: %d\n", (data[4] & 0x40) >> 6); |
| 551 | printf("\t\t * dual CTS protection: %d\n", (data[4] & 0x80) >> 7); |
| 552 | printf("\t\t * STBC beacon: %d\n", data[5] & 0x1); |
| 553 | printf("\t\t * L-SIG TXOP Prot: %d\n", (data[5] & 0x2) >> 1); |
| 554 | printf("\t\t * PCO active: %d\n", (data[5] & 0x4) >> 2); |
| 555 | printf("\t\t * PCO phase: %d\n", (data[5] & 0x8) >> 3); |
| 556 | } |
| 557 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 558 | static void print_capabilities(const uint8_t type, uint8_t len, const uint8_t *data) |
Marcel Holtmann | 9b880b0 | 2009-05-04 01:48:44 -0700 | [diff] [blame] | 559 | { |
Johannes Berg | 31d2d25 | 2009-05-05 11:44:04 +0200 | [diff] [blame] | 560 | int i, base, bit; |
| 561 | bool first = true; |
Marcel Holtmann | 9b880b0 | 2009-05-04 01:48:44 -0700 | [diff] [blame] | 562 | |
Johannes Berg | 31d2d25 | 2009-05-05 11:44:04 +0200 | [diff] [blame] | 563 | |
| 564 | for (i = 0; i < len; i++) { |
| 565 | base = i * 8; |
| 566 | |
| 567 | for (bit = 0; bit < 8; bit++) { |
| 568 | if (!(data[i] & (1 << bit))) |
| 569 | continue; |
| 570 | |
| 571 | if (!first) |
| 572 | printf(","); |
| 573 | else |
| 574 | first = false; |
| 575 | |
| 576 | switch (bit + base) { |
| 577 | case 0: |
| 578 | printf(" HT Information Exchange Supported"); |
| 579 | break; |
| 580 | case 1: |
| 581 | printf(" On-demand Beacon"); |
| 582 | break; |
| 583 | case 2: |
| 584 | printf(" Extended Channel Switching"); |
| 585 | break; |
| 586 | case 3: |
| 587 | printf(" Wave Indication"); |
| 588 | break; |
| 589 | case 4: |
| 590 | printf(" PSMP Capability"); |
| 591 | break; |
| 592 | case 5: |
| 593 | printf(" Service Interval Granularity"); |
| 594 | break; |
| 595 | case 6: |
| 596 | printf(" S-PSMP Capability"); |
| 597 | break; |
| 598 | default: |
| 599 | printf(" %d", bit); |
| 600 | break; |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
Marcel Holtmann | 9b880b0 | 2009-05-04 01:48:44 -0700 | [diff] [blame] | 605 | printf("\n"); |
| 606 | } |
| 607 | |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 608 | static void print_tim(const uint8_t type, uint8_t len, const uint8_t *data) |
| 609 | { |
| 610 | printf(" DTIM Count %u DTIM Period %u Bitmap Control 0x%x " |
| 611 | "Bitmap[0] 0x%x", |
| 612 | data[0], data[1], data[2], data[3]); |
| 613 | if (len - 4) |
| 614 | printf(" (+ %u octet%s)", len - 4, len - 4 == 1 ? "" : "s"); |
| 615 | printf("\n"); |
| 616 | } |
| 617 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 618 | struct ie_print { |
| 619 | const char *name; |
| 620 | void (*print)(const uint8_t type, uint8_t len, const uint8_t *data); |
| 621 | uint8_t minlen, maxlen; |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 622 | uint8_t flags; |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 623 | }; |
| 624 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 625 | static void print_ie(const struct ie_print *p, const uint8_t type, |
| 626 | uint8_t len, const uint8_t *data) |
Marcel Holtmann | 6ff0c93 | 2009-05-04 01:48:46 -0700 | [diff] [blame] | 627 | { |
| 628 | int i; |
| 629 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 630 | if (!p->print) |
| 631 | return; |
| 632 | |
| 633 | printf("\t%s:", p->name); |
| 634 | if (len < p->minlen || len > p->maxlen) { |
| 635 | if (len > 1) { |
| 636 | printf(" <invalid: %d bytes:", len); |
| 637 | for (i = 0; i < len; i++) |
| 638 | printf(" %.02x", data[i]); |
| 639 | printf(">\n"); |
| 640 | } else if (len) |
| 641 | printf(" <invalid: 1 byte: %.02x>\n", data[0]); |
| 642 | else |
| 643 | printf(" <invalid: no data>\n"); |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | p->print(type, len, data); |
| 648 | } |
| 649 | |
| 650 | #define PRINT_IGN { \ |
| 651 | .name = "IGNORE", \ |
| 652 | .print = NULL, \ |
| 653 | .minlen = 0, \ |
| 654 | .maxlen = 255, \ |
| 655 | } |
| 656 | |
| 657 | static const struct ie_print ieprinters[] = { |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 658 | [0] = { "SSID", print_ssid, 0, 32, BIT(PRINT_SCAN) | BIT(PRINT_LINK), }, |
| 659 | [1] = { "Supported rates", print_supprates, 0, 255, BIT(PRINT_SCAN), }, |
Johannes Berg | 014d581 | 2009-08-10 15:37:20 +0200 | [diff] [blame] | 660 | [3] = { "DS Parameter set", print_ds, 1, 1, BIT(PRINT_SCAN), }, |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 661 | [5] = { "TIM", print_tim, 4, 255, BIT(PRINT_SCAN), }, |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 662 | [7] = { "Country", print_country, 3, 255, BIT(PRINT_SCAN), }, |
| 663 | [32] = { "Power constraint", print_powerconstraint, 1, 1, BIT(PRINT_SCAN), }, |
| 664 | [42] = { "ERP", print_erp, 1, 255, BIT(PRINT_SCAN), }, |
Johannes Berg | a2e6186 | 2010-09-01 19:28:22 +0200 | [diff] [blame] | 665 | [45] = { "HT capabilities", print_ht_capa, 26, 26, BIT(PRINT_SCAN), }, |
Johannes Berg | be7602f | 2010-09-01 19:43:54 +0200 | [diff] [blame] | 666 | [61] = { "HT operation", print_ht_op, 22, 22, BIT(PRINT_SCAN), }, |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 667 | [48] = { "RSN", print_rsn, 2, 255, BIT(PRINT_SCAN), }, |
| 668 | [50] = { "Extended supported rates", print_supprates, 0, 255, BIT(PRINT_SCAN), }, |
| 669 | [127] = { "Extended capabilities", print_capabilities, 0, 255, BIT(PRINT_SCAN), }, |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 670 | }; |
| 671 | |
| 672 | static void print_wifi_wpa(const uint8_t type, uint8_t len, const uint8_t *data) |
| 673 | { |
| 674 | print_rsn_ie("TKIP", "IEEE 802.1X", len, data); |
| 675 | } |
| 676 | |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 677 | static bool print_wifi_wmm_param(const uint8_t *data, uint8_t len) |
| 678 | { |
| 679 | int i; |
| 680 | static const char *aci_tbl[] = { "BE", "BK", "VI", "VO" }; |
| 681 | |
| 682 | if (len < 19) |
| 683 | goto invalid; |
| 684 | |
| 685 | if (data[0] != 1) { |
Johannes Berg | cee4fe2 | 2009-08-10 15:40:11 +0200 | [diff] [blame] | 686 | printf("Parameter: not version 1: "); |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 687 | return false; |
| 688 | } |
| 689 | |
Marcel Holtmann | 89ea706 | 2009-12-19 19:49:24 -0800 | [diff] [blame] | 690 | printf("\t * Parameter version 1"); |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 691 | |
| 692 | data++; |
| 693 | |
| 694 | if (data[0] & 0x80) |
Marcel Holtmann | 89ea706 | 2009-12-19 19:49:24 -0800 | [diff] [blame] | 695 | printf("\n\t\t * u-APSD"); |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 696 | |
| 697 | data += 2; |
| 698 | |
| 699 | for (i = 0; i < 4; i++) { |
Marcel Holtmann | 89ea706 | 2009-12-19 19:49:24 -0800 | [diff] [blame] | 700 | printf("\n\t\t * %s:", aci_tbl[(data[0] >> 5) & 3]); |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 701 | if (data[4] & 0x10) |
| 702 | printf(" acm"); |
| 703 | printf(" CW %d-%d", (1 << (data[1] & 0xf)) - 1, |
| 704 | (1 << (data[1] >> 4)) - 1); |
Johannes Berg | a2a4c26 | 2009-08-10 16:40:51 +0200 | [diff] [blame] | 705 | printf(", AIFSN %d", data[0] & 0xf); |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 706 | if (data[2] | data[3]) |
Johannes Berg | cee4fe2 | 2009-08-10 15:40:11 +0200 | [diff] [blame] | 707 | printf(", TXOP %d usec", (data[2] + (data[3] << 8)) * 32); |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 708 | data += 4; |
| 709 | } |
| 710 | |
| 711 | printf("\n"); |
| 712 | return true; |
| 713 | |
| 714 | invalid: |
| 715 | printf("invalid: "); |
| 716 | return false; |
| 717 | } |
| 718 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 719 | static void print_wifi_wmm(const uint8_t type, uint8_t len, const uint8_t *data) |
| 720 | { |
| 721 | int i; |
| 722 | |
Marcel Holtmann | 6ff0c93 | 2009-05-04 01:48:46 -0700 | [diff] [blame] | 723 | switch (data[0]) { |
| 724 | case 0x00: |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 725 | printf(" information:"); |
Marcel Holtmann | 6ff0c93 | 2009-05-04 01:48:46 -0700 | [diff] [blame] | 726 | break; |
| 727 | case 0x01: |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 728 | if (print_wifi_wmm_param(data + 1, len - 1)) |
| 729 | return; |
Marcel Holtmann | 6ff0c93 | 2009-05-04 01:48:46 -0700 | [diff] [blame] | 730 | break; |
| 731 | default: |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 732 | printf(" type %d:", data[0]); |
Marcel Holtmann | 6ff0c93 | 2009-05-04 01:48:46 -0700 | [diff] [blame] | 733 | break; |
| 734 | } |
| 735 | |
Johannes Berg | 1cab57e | 2009-08-10 15:15:49 +0200 | [diff] [blame] | 736 | for(i = 1; i < len; i++) |
| 737 | printf(" %.02x", data[i]); |
Marcel Holtmann | 6ff0c93 | 2009-05-04 01:48:46 -0700 | [diff] [blame] | 738 | printf("\n"); |
| 739 | } |
| 740 | |
Jouni Malinen | a681696 | 2010-04-06 18:03:57 +0300 | [diff] [blame] | 741 | static const char * wifi_wps_dev_passwd_id(uint16_t id) |
| 742 | { |
| 743 | switch (id) { |
| 744 | case 0: |
| 745 | return "Default (PIN)"; |
| 746 | case 1: |
| 747 | return "User-specified"; |
| 748 | case 2: |
| 749 | return "Machine-specified"; |
| 750 | case 3: |
| 751 | return "Rekey"; |
| 752 | case 4: |
| 753 | return "PushButton"; |
| 754 | case 5: |
| 755 | return "Registrar-specified"; |
| 756 | default: |
| 757 | return "??"; |
| 758 | } |
| 759 | } |
| 760 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 761 | static void print_wifi_wps(const uint8_t type, uint8_t len, const uint8_t *data) |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 762 | { |
| 763 | bool first = true; |
| 764 | __u16 subtype, sublen; |
| 765 | |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 766 | while (len >= 4) { |
| 767 | subtype = (data[0] << 8) + data[1]; |
| 768 | sublen = (data[2] << 8) + data[3]; |
| 769 | if (sublen > len) |
| 770 | break; |
| 771 | |
| 772 | switch (subtype) { |
| 773 | case 0x104a: |
| 774 | tab_on_first(&first); |
Johannes Berg | dffc675 | 2009-05-04 13:07:16 +0200 | [diff] [blame] | 775 | printf("\t * Version: %d.%d\n", data[4] >> 4, data[4] & 0xF); |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 776 | break; |
| 777 | case 0x1011: |
| 778 | tab_on_first(&first); |
| 779 | printf("\t * Device name: %.*s\n", sublen, data + 4); |
| 780 | break; |
Jouni Malinen | a681696 | 2010-04-06 18:03:57 +0300 | [diff] [blame] | 781 | case 0x1012: { |
| 782 | uint16_t id; |
| 783 | tab_on_first(&first); |
| 784 | if (sublen != 2) { |
| 785 | printf("\t * Device Password ID: (invalid " |
| 786 | "length %d)\n", sublen); |
| 787 | break; |
| 788 | } |
| 789 | id = data[4] << 8 | data[5]; |
| 790 | printf("\t * Device Password ID: %u (%s)\n", |
| 791 | id, wifi_wps_dev_passwd_id(id)); |
| 792 | break; |
| 793 | } |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 794 | case 0x1021: |
| 795 | tab_on_first(&first); |
| 796 | printf("\t * Manufacturer: %.*s\n", sublen, data + 4); |
| 797 | break; |
| 798 | case 0x1023: |
| 799 | tab_on_first(&first); |
| 800 | printf("\t * Model: %.*s\n", sublen, data + 4); |
| 801 | break; |
Jouni Malinen | a681696 | 2010-04-06 18:03:57 +0300 | [diff] [blame] | 802 | case 0x1024: |
| 803 | tab_on_first(&first); |
| 804 | printf("\t * Model Number: %.*s\n", sublen, data + 4); |
| 805 | break; |
| 806 | case 0x103b: { |
| 807 | __u8 val = data[4]; |
| 808 | tab_on_first(&first); |
| 809 | printf("\t * Response Type: %d%s\n", |
| 810 | val, val == 3 ? " (AP)" : ""); |
| 811 | break; |
| 812 | } |
| 813 | case 0x103c: { |
| 814 | __u8 val = data[4]; |
| 815 | tab_on_first(&first); |
| 816 | printf("\t * RF Bands: 0x%x\n", val); |
| 817 | break; |
| 818 | } |
| 819 | case 0x1041: { |
| 820 | __u8 val = data[4]; |
| 821 | tab_on_first(&first); |
| 822 | printf("\t * Selected Registrar: 0x%x\n", val); |
| 823 | break; |
| 824 | } |
| 825 | case 0x1042: |
| 826 | tab_on_first(&first); |
| 827 | printf("\t * Serial Number: %.*s\n", sublen, data + 4); |
| 828 | break; |
| 829 | case 0x1044: { |
| 830 | __u8 val = data[4]; |
| 831 | tab_on_first(&first); |
| 832 | printf("\t * Wi-Fi Protected Setup State: %d%s%s\n", |
| 833 | val, |
| 834 | val == 1 ? " (Unconfigured)" : "", |
| 835 | val == 2 ? " (Configured)" : ""); |
| 836 | break; |
| 837 | } |
| 838 | case 0x1054: { |
| 839 | tab_on_first(&first); |
| 840 | if (sublen != 8) { |
| 841 | printf("\t * Primary Device Type: (invalid " |
| 842 | "length %d)\n", sublen); |
| 843 | break; |
| 844 | } |
| 845 | printf("\t * Primary Device Type: " |
| 846 | "%u-%02x%02x%02x%02x-%u\n", |
| 847 | data[4] << 8 | data[5], |
| 848 | data[6], data[7], data[8], data[9], |
| 849 | data[10] << 8 | data[11]); |
| 850 | break; |
| 851 | } |
Johannes Berg | 7ee5a86 | 2009-05-01 11:52:51 +0200 | [diff] [blame] | 852 | case 0x1057: { |
Johannes Berg | fe31a22 | 2009-06-08 12:46:43 +0200 | [diff] [blame] | 853 | __u8 val = data[4]; |
Johannes Berg | 7ee5a86 | 2009-05-01 11:52:51 +0200 | [diff] [blame] | 854 | tab_on_first(&first); |
Johannes Berg | fe31a22 | 2009-06-08 12:46:43 +0200 | [diff] [blame] | 855 | printf("\t * AP setup locked: 0x%.2x\n", val); |
Johannes Berg | 7ee5a86 | 2009-05-01 11:52:51 +0200 | [diff] [blame] | 856 | break; |
| 857 | } |
Jouni Malinen | a681696 | 2010-04-06 18:03:57 +0300 | [diff] [blame] | 858 | case 0x1008: |
| 859 | case 0x1053: { |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 860 | __u16 meth = (data[4] << 8) + data[5]; |
| 861 | bool comma = false; |
| 862 | tab_on_first(&first); |
Jouni Malinen | a681696 | 2010-04-06 18:03:57 +0300 | [diff] [blame] | 863 | printf("\t * %sConfig methods:", |
| 864 | subtype == 0x1053 ? "Selected Registrar ": ""); |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 865 | #define T(bit, name) do { \ |
| 866 | if (meth & (1<<bit)) { \ |
| 867 | if (comma) \ |
| 868 | printf(","); \ |
| 869 | comma = true; \ |
| 870 | printf(" " name); \ |
| 871 | } } while (0) |
| 872 | T(0, "USB"); |
| 873 | T(1, "Ethernet"); |
| 874 | T(2, "Label"); |
| 875 | T(3, "Display"); |
| 876 | T(4, "Ext. NFC"); |
| 877 | T(5, "Int. NFC"); |
| 878 | T(6, "NFC Intf."); |
| 879 | T(7, "PBC"); |
| 880 | T(8, "Keypad"); |
| 881 | printf("\n"); |
| 882 | break; |
| 883 | #undef T |
| 884 | } |
Johannes Berg | 2650d46 | 2010-03-24 23:09:52 -0700 | [diff] [blame] | 885 | default: { |
| 886 | const __u8 *subdata = data + 4; |
| 887 | __u16 tmplen = sublen; |
| 888 | |
| 889 | tab_on_first(&first); |
| 890 | printf("\t * Unknown TLV (%#.4x, %d bytes):", |
| 891 | subtype, tmplen); |
| 892 | while (tmplen) { |
| 893 | printf(" %.2x", *subdata); |
| 894 | subdata++; |
| 895 | tmplen--; |
| 896 | } |
| 897 | printf("\n"); |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 898 | break; |
| 899 | } |
Johannes Berg | 2650d46 | 2010-03-24 23:09:52 -0700 | [diff] [blame] | 900 | } |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 901 | |
| 902 | data += sublen + 4; |
| 903 | len -= sublen + 4; |
| 904 | } |
| 905 | |
| 906 | if (len != 0) { |
| 907 | printf("\t\t * bogus tail data (%d):", len); |
| 908 | while (len) { |
| 909 | printf(" %.2x", *data); |
| 910 | data++; |
| 911 | len--; |
| 912 | } |
| 913 | printf("\n"); |
| 914 | } |
| 915 | } |
| 916 | |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 917 | static const struct ie_print wifiprinters[] = { |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 918 | [1] = { "WPA", print_wifi_wpa, 2, 255, BIT(PRINT_SCAN), }, |
| 919 | [2] = { "WMM", print_wifi_wmm, 1, 255, BIT(PRINT_SCAN), }, |
| 920 | [4] = { "WPS", print_wifi_wps, 0, 255, BIT(PRINT_SCAN), }, |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 921 | }; |
| 922 | |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 923 | static void print_vendor(unsigned char len, unsigned char *data, |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 924 | bool unknown, enum print_ie_type ptype) |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 925 | { |
| 926 | int i; |
| 927 | |
Johannes Berg | fbf80af | 2009-04-30 18:49:44 +0200 | [diff] [blame] | 928 | if (len < 3) { |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 929 | printf("\tVendor specific: <too short> data:"); |
Johannes Berg | fbf80af | 2009-04-30 18:49:44 +0200 | [diff] [blame] | 930 | for(i = 0; i < len; i++) |
| 931 | printf(" %.02x", data[i]); |
| 932 | printf("\n"); |
| 933 | return; |
| 934 | } |
| 935 | |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 936 | if (len >= 4 && memcmp(data, wifi_oui, 3) == 0) { |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 937 | if (data[3] < ARRAY_SIZE(wifiprinters) && |
| 938 | wifiprinters[data[3]].name && |
| 939 | wifiprinters[data[3]].flags & BIT(ptype)) { |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 940 | print_ie(&wifiprinters[data[3]], data[3], len - 4, data + 4); |
| 941 | return; |
| 942 | } |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 943 | if (!unknown) |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 944 | return; |
Marcel Holtmann | 857d966 | 2009-05-04 01:48:47 -0700 | [diff] [blame] | 945 | printf("\tWiFi OUI %#.2x, data:", data[3]); |
Johannes Berg | 4673a89 | 2009-04-30 20:05:59 +0200 | [diff] [blame] | 946 | for(i = 0; i < len - 4; i++) |
| 947 | printf(" %.02x", data[i + 4]); |
| 948 | printf("\n"); |
| 949 | return; |
| 950 | } |
| 951 | |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 952 | if (!unknown) |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 953 | return; |
| 954 | |
Johannes Berg | fbf80af | 2009-04-30 18:49:44 +0200 | [diff] [blame] | 955 | printf("\tVendor specific: OUI %.2x:%.2x:%.2x, data:", |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 956 | data[0], data[1], data[2]); |
Johannes Berg | fbf80af | 2009-04-30 18:49:44 +0200 | [diff] [blame] | 957 | for (i = 3; i < len; i++) |
| 958 | printf(" %.2x", data[i]); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 959 | printf("\n"); |
| 960 | } |
| 961 | |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 962 | void print_ies(unsigned char *ie, int ielen, bool unknown, |
| 963 | enum print_ie_type ptype) |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 964 | { |
| 965 | while (ielen >= 2 && ielen >= ie[1]) { |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 966 | if (ie[0] < ARRAY_SIZE(ieprinters) && |
| 967 | ieprinters[ie[0]].name && |
| 968 | ieprinters[ie[0]].flags & BIT(ptype)) { |
Johannes Berg | 83b4934 | 2009-05-04 13:35:22 +0200 | [diff] [blame] | 969 | print_ie(&ieprinters[ie[0]], ie[0], ie[1], ie + 2); |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 970 | } else if (ie[0] == 221 /* vendor */) { |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 971 | print_vendor(ie[1], ie + 2, unknown, ptype); |
| 972 | } else if (unknown) { |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 973 | int i; |
| 974 | |
Johannes Berg | 8086b70 | 2009-04-30 18:57:06 +0200 | [diff] [blame] | 975 | printf("\tUnknown IE (%d):", ie[0]); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 976 | for (i=0; i<ie[1]; i++) |
Johannes Berg | 8086b70 | 2009-04-30 18:57:06 +0200 | [diff] [blame] | 977 | printf(" %.2x", ie[2+i]); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 978 | printf("\n"); |
| 979 | } |
| 980 | ielen -= ie[1] + 2; |
| 981 | ie += ie[1] + 2; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | static int print_bss_handler(struct nl_msg *msg, void *arg) |
| 986 | { |
| 987 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 988 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 989 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 990 | char mac_addr[20], dev[20]; |
| 991 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 992 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, |
| 993 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 994 | [NL80211_BSS_BSSID] = { }, |
| 995 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, |
| 996 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, |
| 997 | [NL80211_BSS_INFORMATION_ELEMENTS] = { }, |
Johannes Berg | f2e17e1 | 2009-01-07 22:05:49 +0100 | [diff] [blame] | 998 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, |
| 999 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, |
Johannes Berg | a56117a | 2009-07-10 18:31:59 +0200 | [diff] [blame] | 1000 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
Holger Schurig | c04a78d | 2009-09-24 11:20:47 +0200 | [diff] [blame] | 1001 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 1002 | [NL80211_BSS_BEACON_IES] = { }, |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1003 | }; |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 1004 | struct scan_params *params = arg; |
Johannes Berg | 1c5bcd9 | 2010-02-06 15:16:29 +0100 | [diff] [blame] | 1005 | int show = params->show_both_ie_sets ? 2 : 1; |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1006 | |
| 1007 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1008 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1009 | |
| 1010 | if (!tb[NL80211_ATTR_BSS]) { |
Johannes Berg | 5fe70c0 | 2009-11-11 15:18:43 +0100 | [diff] [blame] | 1011 | fprintf(stderr, "bss info missing!\n"); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1012 | return NL_SKIP; |
| 1013 | } |
| 1014 | if (nla_parse_nested(bss, NL80211_BSS_MAX, |
| 1015 | tb[NL80211_ATTR_BSS], |
| 1016 | bss_policy)) { |
Johannes Berg | 5fe70c0 | 2009-11-11 15:18:43 +0100 | [diff] [blame] | 1017 | fprintf(stderr, "failed to parse nested attributes!\n"); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1018 | return NL_SKIP; |
| 1019 | } |
| 1020 | |
| 1021 | if (!bss[NL80211_BSS_BSSID]) |
| 1022 | return NL_SKIP; |
| 1023 | |
| 1024 | mac_addr_n2a(mac_addr, nla_data(bss[NL80211_BSS_BSSID])); |
| 1025 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); |
Johannes Berg | a56117a | 2009-07-10 18:31:59 +0200 | [diff] [blame] | 1026 | printf("BSS %s (on %s)", mac_addr, dev); |
| 1027 | |
| 1028 | if (bss[NL80211_BSS_STATUS]) { |
| 1029 | switch (nla_get_u32(bss[NL80211_BSS_STATUS])) { |
| 1030 | case NL80211_BSS_STATUS_AUTHENTICATED: |
| 1031 | printf(" -- authenticated"); |
| 1032 | break; |
| 1033 | case NL80211_BSS_STATUS_ASSOCIATED: |
| 1034 | printf(" -- associated"); |
| 1035 | break; |
| 1036 | case NL80211_BSS_STATUS_IBSS_JOINED: |
| 1037 | printf(" -- joined"); |
| 1038 | break; |
| 1039 | default: |
| 1040 | printf(" -- unknown status: %d", |
| 1041 | nla_get_u32(bss[NL80211_BSS_STATUS])); |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | printf("\n"); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1046 | |
Johannes Berg | e7109a8 | 2009-02-10 21:14:45 +0100 | [diff] [blame] | 1047 | if (bss[NL80211_BSS_TSF]) { |
| 1048 | unsigned long long tsf; |
| 1049 | tsf = (unsigned long long)nla_get_u64(bss[NL80211_BSS_TSF]); |
| 1050 | printf("\tTSF: %llu usec (%llud, %.2lld:%.2llu:%.2llu)\n", |
| 1051 | tsf, tsf/1000/1000/60/60/24, (tsf/1000/1000/60/60) % 24, |
| 1052 | (tsf/1000/1000/60) % 60, (tsf/1000/1000) % 60); |
| 1053 | } |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1054 | if (bss[NL80211_BSS_FREQUENCY]) |
| 1055 | printf("\tfreq: %d\n", |
| 1056 | nla_get_u32(bss[NL80211_BSS_FREQUENCY])); |
| 1057 | if (bss[NL80211_BSS_BEACON_INTERVAL]) |
| 1058 | printf("\tbeacon interval: %d\n", |
| 1059 | nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL])); |
Marcel Holtmann | 92a04ec | 2009-05-04 01:48:45 -0700 | [diff] [blame] | 1060 | if (bss[NL80211_BSS_CAPABILITY]) { |
| 1061 | __u16 capa = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); |
| 1062 | printf("\tcapability:"); |
| 1063 | if (capa & WLAN_CAPABILITY_ESS) |
| 1064 | printf(" ESS"); |
| 1065 | if (capa & WLAN_CAPABILITY_IBSS) |
| 1066 | printf(" IBSS"); |
| 1067 | if (capa & WLAN_CAPABILITY_PRIVACY) |
| 1068 | printf(" Privacy"); |
| 1069 | if (capa & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 1070 | printf(" ShortPreamble"); |
| 1071 | if (capa & WLAN_CAPABILITY_PBCC) |
| 1072 | printf(" PBCC"); |
| 1073 | if (capa & WLAN_CAPABILITY_CHANNEL_AGILITY) |
| 1074 | printf(" ChannelAgility"); |
| 1075 | if (capa & WLAN_CAPABILITY_SPECTRUM_MGMT) |
| 1076 | printf(" SpectrumMgmt"); |
| 1077 | if (capa & WLAN_CAPABILITY_QOS) |
| 1078 | printf(" QoS"); |
| 1079 | if (capa & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1080 | printf(" ShortSlotTime"); |
| 1081 | if (capa & WLAN_CAPABILITY_APSD) |
| 1082 | printf(" APSD"); |
| 1083 | if (capa & WLAN_CAPABILITY_DSSS_OFDM) |
| 1084 | printf(" DSSS-OFDM"); |
| 1085 | printf(" (0x%.4x)\n", capa); |
| 1086 | } |
Johannes Berg | f2e17e1 | 2009-01-07 22:05:49 +0100 | [diff] [blame] | 1087 | if (bss[NL80211_BSS_SIGNAL_MBM]) { |
| 1088 | int s = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
| 1089 | printf("\tsignal: %d.%.2d dBm\n", s/100, s%100); |
| 1090 | } |
| 1091 | if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { |
| 1092 | unsigned char s = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); |
| 1093 | printf("\tsignal: %d/100\n", s); |
| 1094 | } |
Holger Schurig | c04a78d | 2009-09-24 11:20:47 +0200 | [diff] [blame] | 1095 | if (bss[NL80211_BSS_SEEN_MS_AGO]) { |
| 1096 | int age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); |
| 1097 | printf("\tlast seen: %d ms ago\n", age); |
| 1098 | } |
Johannes Berg | 1c5bcd9 | 2010-02-06 15:16:29 +0100 | [diff] [blame] | 1099 | |
| 1100 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS] && show--) { |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 1101 | if (bss[NL80211_BSS_BEACON_IES]) |
| 1102 | printf("\tInformation elements from Probe Response " |
| 1103 | "frame:\n"); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1104 | print_ies(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]), |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 1105 | nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]), |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 1106 | params->unknown, params->type); |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 1107 | } |
Johannes Berg | 1c5bcd9 | 2010-02-06 15:16:29 +0100 | [diff] [blame] | 1108 | if (bss[NL80211_BSS_BEACON_IES] && show--) { |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 1109 | printf("\tInformation elements from Beacon frame:\n"); |
| 1110 | print_ies(nla_data(bss[NL80211_BSS_BEACON_IES]), |
| 1111 | nla_len(bss[NL80211_BSS_BEACON_IES]), |
| 1112 | params->unknown, params->type); |
| 1113 | } |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1114 | |
| 1115 | return NL_SKIP; |
| 1116 | } |
| 1117 | |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 1118 | static struct scan_params scan_params; |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1119 | |
Johannes Berg | 7c37a24 | 2009-04-08 13:13:28 +0200 | [diff] [blame] | 1120 | static int handle_scan_dump(struct nl80211_state *state, |
| 1121 | struct nl_cb *cb, |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1122 | struct nl_msg *msg, |
| 1123 | int argc, char **argv) |
| 1124 | { |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 1125 | if (argc > 1) |
| 1126 | return 1; |
| 1127 | |
Johannes Berg | 1c5bcd9 | 2010-02-06 15:16:29 +0100 | [diff] [blame] | 1128 | memset(&scan_params, 0, sizeof(scan_params)); |
| 1129 | |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 1130 | if (argc == 1 && !strcmp(argv[0], "-u")) |
| 1131 | scan_params.unknown = true; |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 1132 | else if (argc == 1 && !strcmp(argv[0], "-b")) |
| 1133 | scan_params.show_both_ie_sets = true; |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 1134 | |
Johannes Berg | febeb0c | 2009-07-25 17:31:08 +0200 | [diff] [blame] | 1135 | scan_params.type = PRINT_SCAN; |
| 1136 | |
Johannes Berg | 764fe75 | 2009-02-12 10:30:32 +0100 | [diff] [blame] | 1137 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_bss_handler, |
| 1138 | &scan_params); |
Johannes Berg | 3563f4c | 2008-09-19 05:08:11 +0200 | [diff] [blame] | 1139 | return 0; |
| 1140 | } |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1141 | |
| 1142 | static int handle_scan_combined(struct nl80211_state *state, |
| 1143 | struct nl_cb *cb, |
| 1144 | struct nl_msg *msg, |
| 1145 | int argc, char **argv) |
| 1146 | { |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 1147 | char **trig_argv; |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1148 | static char *dump_argv[] = { |
| 1149 | NULL, |
| 1150 | "scan", |
| 1151 | "dump", |
Marcel Holtmann | 92649ea | 2009-05-02 13:07:24 -0700 | [diff] [blame] | 1152 | NULL, |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1153 | }; |
| 1154 | static const __u32 cmds[] = { |
| 1155 | NL80211_CMD_NEW_SCAN_RESULTS, |
| 1156 | NL80211_CMD_SCAN_ABORTED, |
| 1157 | }; |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 1158 | int trig_argc, dump_argc, err; |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1159 | |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 1160 | if (argc >= 3 && !strcmp(argv[2], "-u")) { |
| 1161 | dump_argc = 4; |
| 1162 | dump_argv[3] = "-u"; |
Jouni Malinen | 575280c | 2010-01-06 17:53:59 +0200 | [diff] [blame] | 1163 | } else if (argc >= 3 && !strcmp(argv[2], "-b")) { |
| 1164 | dump_argc = 4; |
| 1165 | dump_argv[3] = "-b"; |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 1166 | } else |
| 1167 | dump_argc = 3; |
| 1168 | |
| 1169 | trig_argc = 3 + (argc - 2) + (3 - dump_argc); |
| 1170 | trig_argv = calloc(trig_argc, sizeof(*trig_argv)); |
| 1171 | if (!trig_argv) |
| 1172 | return -ENOMEM; |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1173 | trig_argv[0] = argv[0]; |
Johannes Berg | 559a171 | 2009-05-04 14:06:33 +0200 | [diff] [blame] | 1174 | trig_argv[1] = "scan"; |
| 1175 | trig_argv[2] = "trigger"; |
| 1176 | int i; |
| 1177 | for (i = 0; i < argc - 2 - (dump_argc - 3); i++) |
| 1178 | trig_argv[i + 3] = argv[i + 2 + (dump_argc - 3)]; |
| 1179 | err = handle_cmd(state, II_NETDEV, trig_argc, trig_argv); |
| 1180 | free(trig_argv); |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1181 | if (err) |
| 1182 | return err; |
| 1183 | |
Johannes Berg | 61725db | 2009-04-23 15:57:38 +0200 | [diff] [blame] | 1184 | /* |
| 1185 | * WARNING: DO NOT COPY THIS CODE INTO YOUR APPLICATION |
| 1186 | * |
| 1187 | * This code has a bug, which requires creating a separate |
| 1188 | * nl80211 socket to fix: |
| 1189 | * It is possible for a NL80211_CMD_NEW_SCAN_RESULTS or |
| 1190 | * NL80211_CMD_SCAN_ABORTED message to be sent by the kernel |
| 1191 | * before (!) we listen to it, because we only start listening |
| 1192 | * after we send our scan request. |
| 1193 | * |
| 1194 | * Doing it the other way around has a race condition as well, |
| 1195 | * if you first open the events socket you may get a notification |
| 1196 | * for a previous scan. |
| 1197 | * |
| 1198 | * The only proper way to fix this would be to listen to events |
| 1199 | * before sending the command, and for the kernel to send the |
| 1200 | * scan request along with the event, so that you can match up |
| 1201 | * whether the scan you requested was finished or aborted (this |
| 1202 | * may result in processing a scan that another application |
| 1203 | * requested, but that doesn't seem to be a problem). |
| 1204 | * |
| 1205 | * Alas, the kernel doesn't do that (yet). |
| 1206 | */ |
| 1207 | |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1208 | if (listen_events(state, ARRAY_SIZE(cmds), cmds) == |
| 1209 | NL80211_CMD_SCAN_ABORTED) { |
| 1210 | printf("scan aborted!\n"); |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | dump_argv[0] = argv[0]; |
Marcel Holtmann | 92649ea | 2009-05-02 13:07:24 -0700 | [diff] [blame] | 1215 | return handle_cmd(state, II_NETDEV, dump_argc, dump_argv); |
Johannes Berg | a5fe4ef | 2009-04-08 14:11:47 +0200 | [diff] [blame] | 1216 | } |
Johannes Berg | 64797a7 | 2010-03-24 23:38:25 -0700 | [diff] [blame] | 1217 | TOPLEVEL(scan, "[-u] [freq <freq>*] [ies <hex as 00:11:..>] [ssid <ssid>*|passive]", 0, 0, |
Johannes Berg | 6ca98d2 | 2009-05-05 15:00:56 +0200 | [diff] [blame] | 1218 | CIB_NETDEV, handle_scan_combined, |
| 1219 | "Scan on the given frequencies and probe for the given SSIDs\n" |
| 1220 | "(or wildcard if not given) unless passive scanning is requested.\n" |
Johannes Berg | 64797a7 | 2010-03-24 23:38:25 -0700 | [diff] [blame] | 1221 | "If -u is specified print unknown data in the scan results.\n" |
| 1222 | "Specified (vendor) IEs must be well-formed."); |
Johannes Berg | 4698bfc | 2009-08-24 12:53:34 +0200 | [diff] [blame] | 1223 | COMMAND(scan, dump, "[-u]", |
| 1224 | NL80211_CMD_GET_SCAN, NLM_F_DUMP, CIB_NETDEV, handle_scan_dump, |
| 1225 | "Dump the current scan results. If -u is specified, print unknown\n" |
| 1226 | "data in scan results."); |
Johannes Berg | 64797a7 | 2010-03-24 23:38:25 -0700 | [diff] [blame] | 1227 | COMMAND(scan, trigger, "[freq <freq>*] [ies <hex as 00:11:..>] [ssid <ssid>*|passive]", |
Johannes Berg | 4698bfc | 2009-08-24 12:53:34 +0200 | [diff] [blame] | 1228 | NL80211_CMD_TRIGGER_SCAN, 0, CIB_NETDEV, handle_scan, |
| 1229 | "Trigger a scan on the given frequencies with probing for the given\n" |
| 1230 | "SSIDs (or wildcard if not given) unless passive scanning is requested."); |