print-802_11.c (170533) | print-802_11.c (172686) |
---|---|
1/* $FreeBSD: head/contrib/tcpdump/print-802_11.c 170533 2007-06-11 04:04:30Z sam $ */ | 1/* $FreeBSD: head/contrib/tcpdump/print-802_11.c 172686 2007-10-16 02:31:48Z mlaier $ */ |
2/* 3 * Copyright (c) 2001 4 * Fortress Technologies, Inc. All rights reserved. 5 * Charlie Lenahan (clenahan@fortresstech.com) 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) --- 8 unchanged lines hidden (view full) --- 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 */ 23 24#ifndef lint 25static const char rcsid[] _U_ = | 2/* 3 * Copyright (c) 2001 4 * Fortress Technologies, Inc. All rights reserved. 5 * Charlie Lenahan (clenahan@fortresstech.com) 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) --- 8 unchanged lines hidden (view full) --- 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 */ 23 24#ifndef lint 25static const char rcsid[] _U_ = |
26 "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.31.2.5 2005/07/30 21:37:50 guy Exp $ (LBL)"; | 26 "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.31.2.15 2007/07/22 23:14:14 guy Exp $ (LBL)"; |
27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <tcpdump-stdinc.h> 34 --- 7 unchanged lines hidden (view full) --- 42 43#include "extract.h" 44 45#include "cpack.h" 46 47#include "ieee802_11.h" 48#include "ieee802_11_radio.h" 49 | 27#endif 28 29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 33#include <tcpdump-stdinc.h> 34 --- 7 unchanged lines hidden (view full) --- 42 43#include "extract.h" 44 45#include "cpack.h" 46 47#include "ieee802_11.h" 48#include "ieee802_11_radio.h" 49 |
50#define PRINT_SSID(p) \ 51 switch (p.ssid_status) { \ 52 case TRUNCATED: \ 53 return 0; \ 54 case PRESENT: \ 55 printf(" ("); \ 56 fn_print(p.ssid.ssid, NULL); \ 57 printf(")"); \ 58 break; \ 59 case NOT_PRESENT: \ 60 break; \ 61 } 62 |
|
50#define PRINT_RATE(_sep, _r, _suf) \ 51 printf("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf) 52#define PRINT_RATES(p) \ | 63#define PRINT_RATE(_sep, _r, _suf) \ 64 printf("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf) 65#define PRINT_RATES(p) \ |
53do { \ 54 int z; \ 55 const char *sep = " ["; \ 56 for (z = 0; z < p.rates.length ; z++) { \ 57 PRINT_RATE(sep, p.rates.rate[z], \ 58 (p.rates.rate[z] & 0x80 ? "*" : "")); \ 59 sep = " "; \ | 66 switch (p.rates_status) { \ 67 case TRUNCATED: \ 68 return 0; \ 69 case PRESENT: \ 70 do { \ 71 int z; \ 72 const char *sep = " ["; \ 73 for (z = 0; z < p.rates.length ; z++) { \ 74 PRINT_RATE(sep, p.rates.rate[z], \ 75 (p.rates.rate[z] & 0x80 ? "*" : "")); \ 76 sep = " "; \ 77 } \ 78 if (p.rates.length != 0) \ 79 printf(" Mbit]"); \ 80 } while (0); \ 81 break; \ 82 case NOT_PRESENT: \ 83 break; \ 84 } 85 86#define PRINT_DS_CHANNEL(p) \ 87 switch (p.ds_status) { \ 88 case TRUNCATED: \ 89 return 0; \ 90 case PRESENT: \ 91 printf(" CH: %u", p.ds.channel); \ 92 break; \ 93 case NOT_PRESENT: \ 94 break; \ |
60 } \ | 95 } \ |
61 if (p.rates.length != 0) \ 62 printf(" Mbit]"); \ 63} while (0) | 96 printf("%s", \ 97 CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : "" ); |
64 65static const int ieee80211_htrates[16] = { 66 13, /* IFM_IEEE80211_MCS0 */ 67 26, /* IFM_IEEE80211_MCS1 */ 68 39, /* IFM_IEEE80211_MCS2 */ 69 52, /* IFM_IEEE80211_MCS3 */ 70 78, /* IFM_IEEE80211_MCS4 */ 71 104, /* IFM_IEEE80211_MCS5 */ --- 63 unchanged lines hidden (view full) --- 135 iv = EXTRACT_LE_32BITS(p); 136 137 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv), IV_PAD(iv), 138 IV_KEYID(iv)); 139 140 return 1; 141} 142 | 98 99static const int ieee80211_htrates[16] = { 100 13, /* IFM_IEEE80211_MCS0 */ 101 26, /* IFM_IEEE80211_MCS1 */ 102 39, /* IFM_IEEE80211_MCS2 */ 103 52, /* IFM_IEEE80211_MCS3 */ 104 78, /* IFM_IEEE80211_MCS4 */ 105 104, /* IFM_IEEE80211_MCS5 */ --- 63 unchanged lines hidden (view full) --- 169 iv = EXTRACT_LE_32BITS(p); 170 171 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv), IV_PAD(iv), 172 IV_KEYID(iv)); 173 174 return 1; 175} 176 |
143static int | 177static void |
144parse_elements(struct mgmt_body_t *pbody, const u_char *p, int offset) 145{ | 178parse_elements(struct mgmt_body_t *pbody, const u_char *p, int offset) 179{ |
180 /* 181 * We haven't seen any elements yet. 182 */ 183 pbody->challenge_status = NOT_PRESENT; 184 pbody->ssid_status = NOT_PRESENT; 185 pbody->rates_status = NOT_PRESENT; 186 pbody->ds_status = NOT_PRESENT; 187 pbody->cf_status = NOT_PRESENT; 188 pbody->tim_status = NOT_PRESENT; 189 |
|
146 for (;;) { 147 if (!TTEST2(*(p + offset), 1)) | 190 for (;;) { 191 if (!TTEST2(*(p + offset), 1)) |
148 return 1; | 192 return; |
149 switch (*(p + offset)) { 150 case E_SSID: | 193 switch (*(p + offset)) { 194 case E_SSID: |
195 /* Present, possibly truncated */ 196 pbody->ssid_status = TRUNCATED; |
|
151 if (!TTEST2(*(p + offset), 2)) | 197 if (!TTEST2(*(p + offset), 2)) |
152 return 0; | 198 return; |
153 memcpy(&pbody->ssid, p + offset, 2); 154 offset += 2; | 199 memcpy(&pbody->ssid, p + offset, 2); 200 offset += 2; |
155 if (pbody->ssid.length <= 0) 156 break; 157 if (!TTEST2(*(p + offset), pbody->ssid.length)) 158 return 0; 159 memcpy(&pbody->ssid.ssid, p + offset, 160 pbody->ssid.length); 161 offset += pbody->ssid.length; | 201 if (pbody->ssid.length != 0) { 202 if (pbody->ssid.length > 203 sizeof(pbody->ssid.ssid) - 1) 204 return; 205 if (!TTEST2(*(p + offset), pbody->ssid.length)) 206 return; 207 memcpy(&pbody->ssid.ssid, p + offset, 208 pbody->ssid.length); 209 offset += pbody->ssid.length; 210 } |
162 pbody->ssid.ssid[pbody->ssid.length] = '\0'; | 211 pbody->ssid.ssid[pbody->ssid.length] = '\0'; |
212 /* Present and not truncated */ 213 pbody->ssid_status = PRESENT; |
|
163 break; 164 case E_CHALLENGE: | 214 break; 215 case E_CHALLENGE: |
216 /* Present, possibly truncated */ 217 pbody->challenge_status = TRUNCATED; |
|
165 if (!TTEST2(*(p + offset), 2)) | 218 if (!TTEST2(*(p + offset), 2)) |
166 return 0; | 219 return; |
167 memcpy(&pbody->challenge, p + offset, 2); 168 offset += 2; | 220 memcpy(&pbody->challenge, p + offset, 2); 221 offset += 2; |
169 if (pbody->challenge.length <= 0) 170 break; 171 if (!TTEST2(*(p + offset), pbody->challenge.length)) 172 return 0; 173 memcpy(&pbody->challenge.text, p + offset, 174 pbody->challenge.length); 175 offset += pbody->challenge.length; | 222 if (pbody->challenge.length != 0) { 223 if (pbody->challenge.length > 224 sizeof(pbody->challenge.text) - 1) 225 return; 226 if (!TTEST2(*(p + offset), pbody->challenge.length)) 227 return; 228 memcpy(&pbody->challenge.text, p + offset, 229 pbody->challenge.length); 230 offset += pbody->challenge.length; 231 } |
176 pbody->challenge.text[pbody->challenge.length] = '\0'; | 232 pbody->challenge.text[pbody->challenge.length] = '\0'; |
233 /* Present and not truncated */ 234 pbody->challenge_status = PRESENT; |
|
177 break; 178 case E_RATES: | 235 break; 236 case E_RATES: |
237 /* Present, possibly truncated */ 238 pbody->rates_status = TRUNCATED; |
|
179 if (!TTEST2(*(p + offset), 2)) | 239 if (!TTEST2(*(p + offset), 2)) |
180 return 0; | 240 return; |
181 memcpy(&(pbody->rates), p + offset, 2); 182 offset += 2; | 241 memcpy(&(pbody->rates), p + offset, 2); 242 offset += 2; |
183 if (pbody->rates.length <= 0) 184 break; 185 if (!TTEST2(*(p + offset), pbody->rates.length)) 186 return 0; 187 memcpy(&pbody->rates.rate, p + offset, 188 pbody->rates.length); 189 offset += pbody->rates.length; | 243 if (pbody->rates.length != 0) { 244 if (pbody->rates.length > sizeof pbody->rates.rate) 245 return; 246 if (!TTEST2(*(p + offset), pbody->rates.length)) 247 return; 248 memcpy(&pbody->rates.rate, p + offset, 249 pbody->rates.length); 250 offset += pbody->rates.length; 251 } 252 /* Present and not truncated */ 253 pbody->rates_status = PRESENT; |
190 break; 191 case E_DS: | 254 break; 255 case E_DS: |
256 /* Present, possibly truncated */ 257 pbody->ds_status = TRUNCATED; |
|
192 if (!TTEST2(*(p + offset), 3)) | 258 if (!TTEST2(*(p + offset), 3)) |
193 return 0; | 259 return; |
194 memcpy(&pbody->ds, p + offset, 3); 195 offset += 3; | 260 memcpy(&pbody->ds, p + offset, 3); 261 offset += 3; |
262 /* Present and not truncated */ 263 pbody->ds_status = PRESENT; |
|
196 break; 197 case E_CF: | 264 break; 265 case E_CF: |
266 /* Present, possibly truncated */ 267 pbody->cf_status = TRUNCATED; |
|
198 if (!TTEST2(*(p + offset), 8)) | 268 if (!TTEST2(*(p + offset), 8)) |
199 return 0; | 269 return; |
200 memcpy(&pbody->cf, p + offset, 8); 201 offset += 8; | 270 memcpy(&pbody->cf, p + offset, 8); 271 offset += 8; |
272 /* Present and not truncated */ 273 pbody->cf_status = PRESENT; |
|
202 break; 203 case E_TIM: | 274 break; 275 case E_TIM: |
276 /* Present, possibly truncated */ 277 pbody->tim_status = TRUNCATED; |
|
204 if (!TTEST2(*(p + offset), 2)) | 278 if (!TTEST2(*(p + offset), 2)) |
205 return 0; | 279 return; |
206 memcpy(&pbody->tim, p + offset, 2); 207 offset += 2; 208 if (!TTEST2(*(p + offset), 3)) | 280 memcpy(&pbody->tim, p + offset, 2); 281 offset += 2; 282 if (!TTEST2(*(p + offset), 3)) |
209 return 0; | 283 return; |
210 memcpy(&pbody->tim.count, p + offset, 3); 211 offset += 3; 212 213 if (pbody->tim.length <= 3) 214 break; | 284 memcpy(&pbody->tim.count, p + offset, 3); 285 offset += 3; 286 287 if (pbody->tim.length <= 3) 288 break; |
289 if (pbody->tim.length - 3 > sizeof pbody->tim.bitmap) 290 return; |
|
215 if (!TTEST2(*(p + offset), pbody->tim.length - 3)) | 291 if (!TTEST2(*(p + offset), pbody->tim.length - 3)) |
216 return 0; | 292 return; |
217 memcpy(pbody->tim.bitmap, p + (pbody->tim.length - 3), 218 (pbody->tim.length - 3)); 219 offset += pbody->tim.length - 3; | 293 memcpy(pbody->tim.bitmap, p + (pbody->tim.length - 3), 294 (pbody->tim.length - 3)); 295 offset += pbody->tim.length - 3; |
296 /* Present and not truncated */ 297 pbody->tim_status = PRESENT; |
|
220 break; 221 default: 222#if 0 223 printf("(1) unhandled element_id (%d) ", 224 *(p + offset) ); 225#endif | 298 break; 299 default: 300#if 0 301 printf("(1) unhandled element_id (%d) ", 302 *(p + offset) ); 303#endif |
304 if (!TTEST2(*(p + offset), 2)) 305 return; 306 if (!TTEST2(*(p + offset + 2), *(p + offset + 1))) 307 return; |
|
226 offset += *(p + offset + 1) + 2; 227 break; 228 } 229 } | 308 offset += *(p + offset + 1) + 2; 309 break; 310 } 311 } |
230 return 1; | |
231} 232 233/********************************************************************************* 234 * Print Handle functions for the management frame types 235 *********************************************************************************/ 236 237static int 238handle_beacon(const u_char *p) 239{ 240 struct mgmt_body_t pbody; 241 int offset = 0; 242 243 memset(&pbody, 0, sizeof(pbody)); 244 245 if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + 246 IEEE802_11_CAPINFO_LEN)) 247 return 0; | 312} 313 314/********************************************************************************* 315 * Print Handle functions for the management frame types 316 *********************************************************************************/ 317 318static int 319handle_beacon(const u_char *p) 320{ 321 struct mgmt_body_t pbody; 322 int offset = 0; 323 324 memset(&pbody, 0, sizeof(pbody)); 325 326 if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN + 327 IEEE802_11_CAPINFO_LEN)) 328 return 0; |
248 memcpy(&pbody.timestamp, p, 8); | 329 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN); |
249 offset += IEEE802_11_TSTAMP_LEN; 250 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); 251 offset += IEEE802_11_BCNINT_LEN; 252 pbody.capability_info = EXTRACT_LE_16BITS(p+offset); 253 offset += IEEE802_11_CAPINFO_LEN; 254 | 330 offset += IEEE802_11_TSTAMP_LEN; 331 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); 332 offset += IEEE802_11_BCNINT_LEN; 333 pbody.capability_info = EXTRACT_LE_16BITS(p+offset); 334 offset += IEEE802_11_CAPINFO_LEN; 335 |
255 if (!parse_elements(&pbody, p, offset)) 256 return 0; | 336 parse_elements(&pbody, p, offset); |
257 | 337 |
258 printf(" ("); 259 fn_print(pbody.ssid.ssid, NULL); 260 printf(")"); | 338 PRINT_SSID(pbody); |
261 PRINT_RATES(pbody); | 339 PRINT_RATES(pbody); |
262 printf(" %s CH: %u%s", 263 CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS", 264 pbody.ds.channel, 265 CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" ); | 340 printf(" %s", 341 CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS"); 342 PRINT_DS_CHANNEL(pbody); |
266 267 return 1; 268} 269 270static int 271handle_assoc_request(const u_char *p) 272{ 273 struct mgmt_body_t pbody; 274 int offset = 0; 275 276 memset(&pbody, 0, sizeof(pbody)); 277 278 if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)) 279 return 0; 280 pbody.capability_info = EXTRACT_LE_16BITS(p); 281 offset += IEEE802_11_CAPINFO_LEN; 282 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); 283 offset += IEEE802_11_LISTENINT_LEN; 284 | 343 344 return 1; 345} 346 347static int 348handle_assoc_request(const u_char *p) 349{ 350 struct mgmt_body_t pbody; 351 int offset = 0; 352 353 memset(&pbody, 0, sizeof(pbody)); 354 355 if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)) 356 return 0; 357 pbody.capability_info = EXTRACT_LE_16BITS(p); 358 offset += IEEE802_11_CAPINFO_LEN; 359 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); 360 offset += IEEE802_11_LISTENINT_LEN; 361 |
285 if (!parse_elements(&pbody, p, offset)) 286 return 0; | 362 parse_elements(&pbody, p, offset); |
287 | 363 |
288 printf(" ("); 289 fn_print(pbody.ssid.ssid, NULL); 290 printf(")"); | 364 PRINT_SSID(pbody); |
291 PRINT_RATES(pbody); 292 return 1; 293} 294 295static int 296handle_assoc_response(const u_char *p) 297{ 298 struct mgmt_body_t pbody; --- 6 unchanged lines hidden (view full) --- 305 return 0; 306 pbody.capability_info = EXTRACT_LE_16BITS(p); 307 offset += IEEE802_11_CAPINFO_LEN; 308 pbody.status_code = EXTRACT_LE_16BITS(p+offset); 309 offset += IEEE802_11_STATUS_LEN; 310 pbody.aid = EXTRACT_LE_16BITS(p+offset); 311 offset += IEEE802_11_AID_LEN; 312 | 365 PRINT_RATES(pbody); 366 return 1; 367} 368 369static int 370handle_assoc_response(const u_char *p) 371{ 372 struct mgmt_body_t pbody; --- 6 unchanged lines hidden (view full) --- 379 return 0; 380 pbody.capability_info = EXTRACT_LE_16BITS(p); 381 offset += IEEE802_11_CAPINFO_LEN; 382 pbody.status_code = EXTRACT_LE_16BITS(p+offset); 383 offset += IEEE802_11_STATUS_LEN; 384 pbody.aid = EXTRACT_LE_16BITS(p+offset); 385 offset += IEEE802_11_AID_LEN; 386 |
313 if (!parse_elements(&pbody, p, offset)) 314 return 0; | 387 parse_elements(&pbody, p, offset); |
315 316 printf(" AID(%x) :%s: %s", ((u_int16_t)(pbody.aid << 2 )) >> 2 , 317 CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "", 318 (pbody.status_code < NUM_STATUSES 319 ? status_text[pbody.status_code] 320 : "n/a")); 321 322 return 1; --- 12 unchanged lines hidden (view full) --- 335 return 0; 336 pbody.capability_info = EXTRACT_LE_16BITS(p); 337 offset += IEEE802_11_CAPINFO_LEN; 338 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); 339 offset += IEEE802_11_LISTENINT_LEN; 340 memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN); 341 offset += IEEE802_11_AP_LEN; 342 | 388 389 printf(" AID(%x) :%s: %s", ((u_int16_t)(pbody.aid << 2 )) >> 2 , 390 CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "", 391 (pbody.status_code < NUM_STATUSES 392 ? status_text[pbody.status_code] 393 : "n/a")); 394 395 return 1; --- 12 unchanged lines hidden (view full) --- 408 return 0; 409 pbody.capability_info = EXTRACT_LE_16BITS(p); 410 offset += IEEE802_11_CAPINFO_LEN; 411 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset); 412 offset += IEEE802_11_LISTENINT_LEN; 413 memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN); 414 offset += IEEE802_11_AP_LEN; 415 |
343 if (!parse_elements(&pbody, p, offset)) 344 return 0; | 416 parse_elements(&pbody, p, offset); |
345 | 417 |
346 printf(" ("); 347 fn_print(pbody.ssid.ssid, NULL); 348 printf(") AP : %s", etheraddr_string( pbody.ap )); | 418 PRINT_SSID(pbody); 419 printf(" AP : %s", etheraddr_string( pbody.ap )); |
349 350 return 1; 351} 352 353static int 354handle_reassoc_response(const u_char *p) 355{ 356 /* Same as a Association Reponse */ 357 return handle_assoc_response(p); 358} 359 360static int 361handle_probe_request(const u_char *p) 362{ 363 struct mgmt_body_t pbody; 364 int offset = 0; 365 366 memset(&pbody, 0, sizeof(pbody)); 367 | 420 421 return 1; 422} 423 424static int 425handle_reassoc_response(const u_char *p) 426{ 427 /* Same as a Association Reponse */ 428 return handle_assoc_response(p); 429} 430 431static int 432handle_probe_request(const u_char *p) 433{ 434 struct mgmt_body_t pbody; 435 int offset = 0; 436 437 memset(&pbody, 0, sizeof(pbody)); 438 |
368 if (!parse_elements(&pbody, p, offset)) 369 return 0; | 439 parse_elements(&pbody, p, offset); |
370 | 440 |
371 printf(" ("); 372 fn_print(pbody.ssid.ssid, NULL); 373 printf(")"); | 441 PRINT_SSID(pbody); |
374 PRINT_RATES(pbody); 375 376 return 1; 377} 378 379static int 380handle_probe_response(const u_char *p) 381{ --- 8 unchanged lines hidden (view full) --- 390 391 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN); 392 offset += IEEE802_11_TSTAMP_LEN; 393 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); 394 offset += IEEE802_11_BCNINT_LEN; 395 pbody.capability_info = EXTRACT_LE_16BITS(p+offset); 396 offset += IEEE802_11_CAPINFO_LEN; 397 | 442 PRINT_RATES(pbody); 443 444 return 1; 445} 446 447static int 448handle_probe_response(const u_char *p) 449{ --- 8 unchanged lines hidden (view full) --- 458 459 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN); 460 offset += IEEE802_11_TSTAMP_LEN; 461 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); 462 offset += IEEE802_11_BCNINT_LEN; 463 pbody.capability_info = EXTRACT_LE_16BITS(p+offset); 464 offset += IEEE802_11_CAPINFO_LEN; 465 |
398 if (!parse_elements(&pbody, p, offset)) 399 return 0; | 466 parse_elements(&pbody, p, offset); |
400 | 467 |
401 printf(" ("); 402 fn_print(pbody.ssid.ssid, NULL); 403 printf(") "); | 468 PRINT_SSID(pbody); |
404 PRINT_RATES(pbody); | 469 PRINT_RATES(pbody); |
405 printf(" CH: %u%s", pbody.ds.channel, 406 CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" ); | 470 PRINT_DS_CHANNEL(pbody); |
407 408 return 1; 409} 410 411static int 412handle_atim(void) 413{ 414 /* the frame body for ATIM is null. */ --- 31 unchanged lines hidden (view full) --- 446 return 0; 447 pbody.auth_alg = EXTRACT_LE_16BITS(p); 448 offset += 2; 449 pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset); 450 offset += 2; 451 pbody.status_code = EXTRACT_LE_16BITS(p + offset); 452 offset += 2; 453 | 471 472 return 1; 473} 474 475static int 476handle_atim(void) 477{ 478 /* the frame body for ATIM is null. */ --- 31 unchanged lines hidden (view full) --- 510 return 0; 511 pbody.auth_alg = EXTRACT_LE_16BITS(p); 512 offset += 2; 513 pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset); 514 offset += 2; 515 pbody.status_code = EXTRACT_LE_16BITS(p + offset); 516 offset += 2; 517 |
454 if (!parse_elements(&pbody, p, offset)) 455 return 0; | 518 parse_elements(&pbody, p, offset); |
456 457 if ((pbody.auth_alg == 1) && 458 ((pbody.auth_trans_seq_num == 2) || 459 (pbody.auth_trans_seq_num == 3))) { 460 printf(" (%s)-%x [Challenge Text] %s", 461 (pbody.auth_alg < NUM_AUTH_ALGS) 462 ? auth_alg_text[pbody.auth_alg] 463 : "Reserved", --- 188 unchanged lines hidden (view full) --- 652 * 1 | 0 | BSSID | SA | DA | n/a 653 * 1 | 1 | RA | TA | DA | SA 654 */ 655 656static void 657data_header_print(u_int16_t fc, const u_char *p, const u_int8_t **srcp, 658 const u_int8_t **dstp) 659{ | 519 520 if ((pbody.auth_alg == 1) && 521 ((pbody.auth_trans_seq_num == 2) || 522 (pbody.auth_trans_seq_num == 3))) { 523 printf(" (%s)-%x [Challenge Text] %s", 524 (pbody.auth_alg < NUM_AUTH_ALGS) 525 ? auth_alg_text[pbody.auth_alg] 526 : "Reserved", --- 188 unchanged lines hidden (view full) --- 715 * 1 | 0 | BSSID | SA | DA | n/a 716 * 1 | 1 | RA | TA | DA | SA 717 */ 718 719static void 720data_header_print(u_int16_t fc, const u_char *p, const u_int8_t **srcp, 721 const u_int8_t **dstp) 722{ |
660 switch (FC_SUBTYPE(fc)) { 661 case DATA_DATA: 662 case DATA_NODATA: 663 break; 664 case DATA_DATA_CF_ACK: 665 case DATA_NODATA_CF_ACK: 666 printf("CF Ack "); 667 break; 668 case DATA_DATA_CF_POLL: 669 case DATA_NODATA_CF_POLL: 670 printf("CF Poll "); 671 break; 672 case DATA_DATA_CF_ACK_POLL: 673 case DATA_NODATA_CF_ACK_POLL: 674 printf("CF Ack/Poll "); 675 break; | 723 u_int subtype = FC_SUBTYPE(fc); 724 725 if (DATA_FRAME_IS_CF_ACK(subtype) || DATA_FRAME_IS_CF_POLL(subtype) || 726 DATA_FRAME_IS_QOS(subtype)) { 727 printf("CF "); 728 if (DATA_FRAME_IS_CF_ACK(subtype)) { 729 if (DATA_FRAME_IS_CF_POLL(subtype)) 730 printf("Ack/Poll"); 731 else 732 printf("Ack"); 733 } else { 734 if (DATA_FRAME_IS_CF_POLL(subtype)) 735 printf("Poll"); 736 } 737 if (DATA_FRAME_IS_QOS(subtype)) 738 printf("+QoS"); 739 printf(" "); |
676 } 677 678#define ADDR1 (p + 4) 679#define ADDR2 (p + 10) 680#define ADDR3 (p + 16) 681#define ADDR4 (p + 24) 682 683 if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) { --- 113 unchanged lines hidden (view full) --- 797 printf("(H) Unknown Ctrl Subtype"); 798 break; 799 } 800} 801 802static int 803extract_header_length(u_int16_t fc) 804{ | 740 } 741 742#define ADDR1 (p + 4) 743#define ADDR2 (p + 10) 744#define ADDR3 (p + 16) 745#define ADDR4 (p + 24) 746 747 if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) { --- 113 unchanged lines hidden (view full) --- 861 printf("(H) Unknown Ctrl Subtype"); 862 break; 863 } 864} 865 866static int 867extract_header_length(u_int16_t fc) 868{ |
869 int len; 870 |
|
805 switch (FC_TYPE(fc)) { 806 case T_MGMT: 807 return MGMT_HDRLEN; 808 case T_CTRL: 809 switch (FC_SUBTYPE(fc)) { 810 case CTRL_BAR: 811 return CTRL_BAR_HDRLEN; 812 case CTRL_PS_POLL: --- 7 unchanged lines hidden (view full) --- 820 case CTRL_CF_END: 821 return CTRL_END_HDRLEN; 822 case CTRL_END_ACK: 823 return CTRL_END_ACK_HDRLEN; 824 default: 825 return 0; 826 } 827 case T_DATA: | 871 switch (FC_TYPE(fc)) { 872 case T_MGMT: 873 return MGMT_HDRLEN; 874 case T_CTRL: 875 switch (FC_SUBTYPE(fc)) { 876 case CTRL_BAR: 877 return CTRL_BAR_HDRLEN; 878 case CTRL_PS_POLL: --- 7 unchanged lines hidden (view full) --- 886 case CTRL_CF_END: 887 return CTRL_END_HDRLEN; 888 case CTRL_END_ACK: 889 return CTRL_END_ACK_HDRLEN; 890 default: 891 return 0; 892 } 893 case T_DATA: |
828 return (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24; | 894 len = (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24; 895 if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc))) 896 len += 2; 897 return len; |
829 default: 830 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); 831 return 0; 832 } 833} 834 835/* 836 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp" --- 37 unchanged lines hidden (view full) --- 874 printf("(header) unknown IEEE802.11 frame type (%d)", 875 FC_TYPE(fc)); 876 *srcp = NULL; 877 *dstp = NULL; 878 break; 879 } 880} 881 | 898 default: 899 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); 900 return 0; 901 } 902} 903 904/* 905 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp" --- 37 unchanged lines hidden (view full) --- 943 printf("(header) unknown IEEE802.11 frame type (%d)", 944 FC_TYPE(fc)); 945 *srcp = NULL; 946 *dstp = NULL; 947 break; 948 } 949} 950 |
951#ifndef roundup2 952#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ 953#endif 954 |
|
882static u_int | 955static u_int |
883ieee802_11_print(const u_char *p, u_int length, u_int caplen) | 956ieee802_11_print(const u_char *p, u_int length, u_int caplen, int pad) |
884{ 885 u_int16_t fc; 886 u_int hdrlen; 887 const u_int8_t *src, *dst; 888 u_short extracted_ethertype; 889 890 if (caplen < IEEE802_11_FC_LEN) { 891 printf("[|802.11]"); 892 return caplen; 893 } 894 895 fc = EXTRACT_LE_16BITS(p); 896 hdrlen = extract_header_length(fc); | 957{ 958 u_int16_t fc; 959 u_int hdrlen; 960 const u_int8_t *src, *dst; 961 u_short extracted_ethertype; 962 963 if (caplen < IEEE802_11_FC_LEN) { 964 printf("[|802.11]"); 965 return caplen; 966 } 967 968 fc = EXTRACT_LE_16BITS(p); 969 hdrlen = extract_header_length(fc); |
970 if (pad) 971 hdrlen = roundup2(hdrlen, 4); |
|
897 898 if (caplen < hdrlen) { 899 printf("[|802.11]"); 900 return hdrlen; 901 } 902 903 ieee_802_11_hdr_print(fc, p, &src, &dst); 904 --- 14 unchanged lines hidden (view full) --- 919 break; 920 case T_CTRL: 921 if (!ctrl_body_print(fc, p - hdrlen)) { 922 printf("[|802.11]"); 923 return hdrlen; 924 } 925 break; 926 case T_DATA: | 972 973 if (caplen < hdrlen) { 974 printf("[|802.11]"); 975 return hdrlen; 976 } 977 978 ieee_802_11_hdr_print(fc, p, &src, &dst); 979 --- 14 unchanged lines hidden (view full) --- 994 break; 995 case T_CTRL: 996 if (!ctrl_body_print(fc, p - hdrlen)) { 997 printf("[|802.11]"); 998 return hdrlen; 999 } 1000 break; 1001 case T_DATA: |
1002 if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc))) 1003 return hdrlen; /* no-data frame */ |
|
927 /* There may be a problem w/ AP not having this bit set */ 928 if (FC_WEP(fc)) { 929 if (!wep_print(p)) { 930 printf("[|802.11]"); 931 return hdrlen; 932 } 933 } else if (llc_print(p, length, caplen, dst, src, 934 &extracted_ethertype) == 0) { --- 24 unchanged lines hidden (view full) --- 959 * This is the top level routine of the printer. 'p' points 960 * to the 802.11 header of the packet, 'h->ts' is the timestamp, 961 * 'h->len' is the length of the packet off the wire, and 'h->caplen' 962 * is the number of bytes actually captured. 963 */ 964u_int 965ieee802_11_if_print(const struct pcap_pkthdr *h, const u_char *p) 966{ | 1004 /* There may be a problem w/ AP not having this bit set */ 1005 if (FC_WEP(fc)) { 1006 if (!wep_print(p)) { 1007 printf("[|802.11]"); 1008 return hdrlen; 1009 } 1010 } else if (llc_print(p, length, caplen, dst, src, 1011 &extracted_ethertype) == 0) { --- 24 unchanged lines hidden (view full) --- 1036 * This is the top level routine of the printer. 'p' points 1037 * to the 802.11 header of the packet, 'h->ts' is the timestamp, 1038 * 'h->len' is the length of the packet off the wire, and 'h->caplen' 1039 * is the number of bytes actually captured. 1040 */ 1041u_int 1042ieee802_11_if_print(const struct pcap_pkthdr *h, const u_char *p) 1043{ |
967 return ieee802_11_print(p, h->len, h->caplen); | 1044 return ieee802_11_print(p, h->len, h->caplen, 0); |
968} 969 970#define IEEE80211_CHAN_FHSS \ 971 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK) 972#define IEEE80211_CHAN_A \ 973 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM) 974#define IEEE80211_CHAN_B \ 975 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK) --- 45 unchanged lines hidden (view full) --- 1021 else if (flags & IEEE80211_CHAN_HT40D) 1022 printf(" ht/40-"); 1023 else if (flags & IEEE80211_CHAN_HT40U) 1024 printf(" ht/40+"); 1025 printf(" "); 1026} 1027 1028static int | 1045} 1046 1047#define IEEE80211_CHAN_FHSS \ 1048 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK) 1049#define IEEE80211_CHAN_A \ 1050 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM) 1051#define IEEE80211_CHAN_B \ 1052 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK) --- 45 unchanged lines hidden (view full) --- 1098 else if (flags & IEEE80211_CHAN_HT40D) 1099 printf(" ht/40-"); 1100 else if (flags & IEEE80211_CHAN_HT40U) 1101 printf(" ht/40+"); 1102 printf(" "); 1103} 1104 1105static int |
1029print_radiotap_field(struct cpack_state *s, u_int32_t bit) | 1106print_radiotap_field(struct cpack_state *s, u_int32_t bit, int *pad) |
1030{ 1031 union { 1032 int8_t i8; 1033 u_int8_t u8; 1034 int16_t i16; 1035 u_int16_t u16; 1036 u_int32_t u32; 1037 u_int64_t u64; 1038 } u, u2, u3, u4; 1039 int rc; 1040 1041 switch (bit) { 1042 case IEEE80211_RADIOTAP_FLAGS: | 1107{ 1108 union { 1109 int8_t i8; 1110 u_int8_t u8; 1111 int16_t i16; 1112 u_int16_t u16; 1113 u_int32_t u32; 1114 u_int64_t u64; 1115 } u, u2, u3, u4; 1116 int rc; 1117 1118 switch (bit) { 1119 case IEEE80211_RADIOTAP_FLAGS: |
1120 rc = cpack_uint8(s, &u.u8); 1121 if (u.u8 & IEEE80211_RADIOTAP_F_DATAPAD) 1122 *pad = 1; 1123 break; |
|
1043 case IEEE80211_RADIOTAP_RATE: 1044 case IEEE80211_RADIOTAP_DB_ANTSIGNAL: 1045 case IEEE80211_RADIOTAP_DB_ANTNOISE: 1046 case IEEE80211_RADIOTAP_ANTENNA: 1047 rc = cpack_uint8(s, &u.u8); 1048 break; 1049 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: 1050 case IEEE80211_RADIOTAP_DBM_ANTNOISE: --- 86 unchanged lines hidden (view full) --- 1137 if (u.u8 & IEEE80211_RADIOTAP_F_CFP) 1138 printf("cfp "); 1139 if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE) 1140 printf("short preamble "); 1141 if (u.u8 & IEEE80211_RADIOTAP_F_WEP) 1142 printf("wep "); 1143 if (u.u8 & IEEE80211_RADIOTAP_F_FRAG) 1144 printf("fragmented "); | 1124 case IEEE80211_RADIOTAP_RATE: 1125 case IEEE80211_RADIOTAP_DB_ANTSIGNAL: 1126 case IEEE80211_RADIOTAP_DB_ANTNOISE: 1127 case IEEE80211_RADIOTAP_ANTENNA: 1128 rc = cpack_uint8(s, &u.u8); 1129 break; 1130 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: 1131 case IEEE80211_RADIOTAP_DBM_ANTNOISE: --- 86 unchanged lines hidden (view full) --- 1218 if (u.u8 & IEEE80211_RADIOTAP_F_CFP) 1219 printf("cfp "); 1220 if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE) 1221 printf("short preamble "); 1222 if (u.u8 & IEEE80211_RADIOTAP_F_WEP) 1223 printf("wep "); 1224 if (u.u8 & IEEE80211_RADIOTAP_F_FRAG) 1225 printf("fragmented "); |
1145#if 0 1146 if (u.u8 & IEEE80211_RADIOTAP_F_FCS) 1147 printf("fcs "); 1148 if (u.u8 & IEEE80211_RADIOTAP_F_DATAPAD) 1149 printf("datapad "); 1150#endif | |
1151 if (u.u8 & IEEE80211_RADIOTAP_F_BADFCS) | 1226 if (u.u8 & IEEE80211_RADIOTAP_F_BADFCS) |
1152 printf("badfcs "); | 1227 printf("bad-fcs "); |
1153 break; 1154 case IEEE80211_RADIOTAP_ANTENNA: 1155 printf("antenna %d ", u.u8); 1156 break; 1157 case IEEE80211_RADIOTAP_TSFT: 1158 printf("%" PRIu64 "us tsft ", u.u64); 1159 break; 1160 case IEEE80211_RADIOTAP_XCHANNEL: --- 18 unchanged lines hidden (view full) --- 1179 struct cpack_state cpacker; 1180 struct ieee80211_radiotap_header *hdr; 1181 u_int32_t present, next_present; 1182 u_int32_t *presentp, *last_presentp; 1183 enum ieee80211_radiotap_type bit; 1184 int bit0; 1185 const u_char *iter; 1186 u_int len; | 1228 break; 1229 case IEEE80211_RADIOTAP_ANTENNA: 1230 printf("antenna %d ", u.u8); 1231 break; 1232 case IEEE80211_RADIOTAP_TSFT: 1233 printf("%" PRIu64 "us tsft ", u.u64); 1234 break; 1235 case IEEE80211_RADIOTAP_XCHANNEL: --- 18 unchanged lines hidden (view full) --- 1254 struct cpack_state cpacker; 1255 struct ieee80211_radiotap_header *hdr; 1256 u_int32_t present, next_present; 1257 u_int32_t *presentp, *last_presentp; 1258 enum ieee80211_radiotap_type bit; 1259 int bit0; 1260 const u_char *iter; 1261 u_int len; |
1262 int pad; |
|
1187 1188 if (caplen < sizeof(*hdr)) { 1189 printf("[|802.11]"); 1190 return caplen; 1191 } 1192 1193 hdr = (struct ieee80211_radiotap_header *)p; 1194 --- 17 unchanged lines hidden (view full) --- 1212 iter = (u_char*)(last_presentp + 1); 1213 1214 if (cpack_init(&cpacker, (u_int8_t*)iter, len - (iter - p)) != 0) { 1215 /* XXX */ 1216 printf("[|802.11]"); 1217 return caplen; 1218 } 1219 | 1263 1264 if (caplen < sizeof(*hdr)) { 1265 printf("[|802.11]"); 1266 return caplen; 1267 } 1268 1269 hdr = (struct ieee80211_radiotap_header *)p; 1270 --- 17 unchanged lines hidden (view full) --- 1288 iter = (u_char*)(last_presentp + 1); 1289 1290 if (cpack_init(&cpacker, (u_int8_t*)iter, len - (iter - p)) != 0) { 1291 /* XXX */ 1292 printf("[|802.11]"); 1293 return caplen; 1294 } 1295 |
1296 /* Assume no Atheros padding between 802.11 header and body */ 1297 pad = 0; |
|
1220 for (bit0 = 0, presentp = &hdr->it_present; presentp <= last_presentp; 1221 presentp++, bit0 += 32) { 1222 for (present = EXTRACT_LE_32BITS(presentp); present; 1223 present = next_present) { 1224 /* clear the least significant bit that is set */ 1225 next_present = present & (present - 1); 1226 1227 /* extract the least significant bit that is set */ 1228 bit = (enum ieee80211_radiotap_type) 1229 (bit0 + BITNO_32(present ^ next_present)); 1230 | 1298 for (bit0 = 0, presentp = &hdr->it_present; presentp <= last_presentp; 1299 presentp++, bit0 += 32) { 1300 for (present = EXTRACT_LE_32BITS(presentp); present; 1301 present = next_present) { 1302 /* clear the least significant bit that is set */ 1303 next_present = present & (present - 1); 1304 1305 /* extract the least significant bit that is set */ 1306 bit = (enum ieee80211_radiotap_type) 1307 (bit0 + BITNO_32(present ^ next_present)); 1308 |
1231 if (print_radiotap_field(&cpacker, bit) != 0) | 1309 if (print_radiotap_field(&cpacker, bit, &pad) != 0) |
1232 goto out; 1233 } 1234 } 1235out: | 1310 goto out; 1311 } 1312 } 1313out: |
1236 return len + ieee802_11_print(p + len, length - len, caplen - len); | 1314 return len + ieee802_11_print(p + len, length - len, caplen - len, pad); |
1237#undef BITNO_32 1238#undef BITNO_16 1239#undef BITNO_8 1240#undef BITNO_4 1241#undef BITNO_2 1242#undef BIT 1243} 1244 --- 14 unchanged lines hidden (view full) --- 1259 } 1260 1261 if (caplen < caphdr_len) { 1262 printf("[|802.11]"); 1263 return caplen; 1264 } 1265 1266 return caphdr_len + ieee802_11_print(p + caphdr_len, | 1315#undef BITNO_32 1316#undef BITNO_16 1317#undef BITNO_8 1318#undef BITNO_4 1319#undef BITNO_2 1320#undef BIT 1321} 1322 --- 14 unchanged lines hidden (view full) --- 1337 } 1338 1339 if (caplen < caphdr_len) { 1340 printf("[|802.11]"); 1341 return caplen; 1342 } 1343 1344 return caphdr_len + ieee802_11_print(p + caphdr_len, |
1267 length - caphdr_len, caplen - caphdr_len); | 1345 length - caphdr_len, caplen - caphdr_len, 0); |
1268} 1269 1270#define PRISM_HDR_LEN 144 1271 1272#define WLANCAP_MAGIC_COOKIE_V1 0x80211001 1273 1274/* 1275 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header, --- 22 unchanged lines hidden (view full) --- 1298 return ieee802_11_avs_radio_print(p, length, caplen); 1299 1300 if (caplen < PRISM_HDR_LEN) { 1301 printf("[|802.11]"); 1302 return caplen; 1303 } 1304 1305 return PRISM_HDR_LEN + ieee802_11_print(p + PRISM_HDR_LEN, | 1346} 1347 1348#define PRISM_HDR_LEN 144 1349 1350#define WLANCAP_MAGIC_COOKIE_V1 0x80211001 1351 1352/* 1353 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header, --- 22 unchanged lines hidden (view full) --- 1376 return ieee802_11_avs_radio_print(p, length, caplen); 1377 1378 if (caplen < PRISM_HDR_LEN) { 1379 printf("[|802.11]"); 1380 return caplen; 1381 } 1382 1383 return PRISM_HDR_LEN + ieee802_11_print(p + PRISM_HDR_LEN, |
1306 length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN); | 1384 length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN, 0); |
1307} 1308 1309/* 1310 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra 1311 * header, containing information such as radio information, which we 1312 * currently ignore. 1313 */ 1314u_int --- 12 unchanged lines hidden --- | 1385} 1386 1387/* 1388 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra 1389 * header, containing information such as radio information, which we 1390 * currently ignore. 1391 */ 1392u_int --- 12 unchanged lines hidden --- |