3 * Fortress Technologies, Inc. All rights reserved.
4 * Charlie Lenahan (clenahan@fortresstech.com)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 static const char rcsid
[] _U_
=
25 "@(#) $Header: /tcpdump/master/tcpdump/print-802_11.c,v 1.31.2.4 2005-07-30 18:49:29 guy Exp $ (LBL)";
32 #include <tcpdump-stdinc.h>
38 #include "interface.h"
39 #include "addrtoname.h"
40 #include "ethertype.h"
46 #include "ieee802_11.h"
47 #include "ieee802_11_radio.h"
49 #define PRINT_RATE(_sep, _r, _suf) \
50 printf("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf)
51 #define PRINT_RATES(p) \
54 const char *sep = " ["; \
55 for (z = 0; z < p.rates.length ; z++) { \
56 PRINT_RATE(sep, p.rates.rate[z], \
57 (p.rates.rate[z] & 0x80 ? "*" : "")); \
60 if (p.rates.length != 0) \
64 static const char *auth_alg_text
[]={"Open System","Shared Key","EAP"};
65 #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0])
67 static const char *subtype_text
[16]={
86 static const char *status_text
[] = {
88 "Unspecified failure", /* 1 */
97 "Cannot Support all requested capabilities in the Capability Information field", /* 10 */
98 "Reassociation denied due to inability to confirm that association exists", /* 11 */
99 "Association denied due to reason outside the scope of the standard", /* 12 */
100 "Responding station does not support the specified authentication algorithm ", /* 13 */
101 "Received an Authentication frame with authentication transaction " \
102 "sequence number out of expected sequence", /* 14 */
103 "Authentication rejected because of challenge failure", /* 15 */
104 "Authentication rejected due to timeout waiting for next frame in sequence", /* 16 */
105 "Association denied because AP is unable to handle additional associated stations", /* 17 */
106 "Association denied due to requesting station not supporting all of the " \
107 "data rates in BSSBasicRateSet parameter", /* 18 */
109 #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
111 static const char *reason_text
[] = {
113 "Unspecified reason", /* 1 */
114 "Previous authentication no longer valid", /* 2 */
115 "Deauthenticated because sending station is leaving (or has left) IBSS or ESS", /* 3 */
116 "Disassociated due to inactivity", /* 4 */
117 "Disassociated because AP is unable to handle all currently associated stations", /* 5 */
118 "Class 2 frame received from nonauthenticated station", /* 6 */
119 "Class 3 frame received from nonassociated station", /* 7 */
120 "Disassociated because sending station is leaving (or has left) BSS", /* 8 */
121 "Station requesting (re)association is not authenticated with responding station", /* 9 */
123 #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
126 wep_print(const u_char
*p
)
130 if (!TTEST2(*p
, IEEE802_11_IV_LEN
+ IEEE802_11_KID_LEN
))
132 iv
= EXTRACT_LE_32BITS(p
);
134 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv
), IV_PAD(iv
),
141 parse_elements(struct mgmt_body_t
*pbody
, const u_char
*p
, int offset
)
144 if (!TTEST2(*(p
+ offset
), 1))
146 switch (*(p
+ offset
)) {
148 if (!TTEST2(*(p
+ offset
), 2))
150 memcpy(&pbody
->ssid
, p
+ offset
, 2);
152 if (pbody
->ssid
.length
<= 0)
154 if (!TTEST2(*(p
+ offset
), pbody
->ssid
.length
))
156 memcpy(&pbody
->ssid
.ssid
, p
+ offset
,
158 offset
+= pbody
->ssid
.length
;
159 pbody
->ssid
.ssid
[pbody
->ssid
.length
] = '\0';
162 if (!TTEST2(*(p
+ offset
), 2))
164 memcpy(&pbody
->challenge
, p
+ offset
, 2);
166 if (pbody
->challenge
.length
<= 0)
168 if (!TTEST2(*(p
+ offset
), pbody
->challenge
.length
))
170 memcpy(&pbody
->challenge
.text
, p
+ offset
,
171 pbody
->challenge
.length
);
172 offset
+= pbody
->challenge
.length
;
173 pbody
->challenge
.text
[pbody
->challenge
.length
] = '\0';
176 if (!TTEST2(*(p
+ offset
), 2))
178 memcpy(&(pbody
->rates
), p
+ offset
, 2);
180 if (pbody
->rates
.length
<= 0)
182 if (!TTEST2(*(p
+ offset
), pbody
->rates
.length
))
184 memcpy(&pbody
->rates
.rate
, p
+ offset
,
185 pbody
->rates
.length
);
186 offset
+= pbody
->rates
.length
;
189 if (!TTEST2(*(p
+ offset
), 3))
191 memcpy(&pbody
->ds
, p
+ offset
, 3);
195 if (!TTEST2(*(p
+ offset
), 8))
197 memcpy(&pbody
->cf
, p
+ offset
, 8);
201 if (!TTEST2(*(p
+ offset
), 2))
203 memcpy(&pbody
->tim
, p
+ offset
, 2);
205 if (!TTEST2(*(p
+ offset
), 3))
207 memcpy(&pbody
->tim
.count
, p
+ offset
, 3);
210 if (pbody
->tim
.length
<= 3)
212 if (!TTEST2(*(p
+ offset
), pbody
->tim
.length
- 3))
214 memcpy(pbody
->tim
.bitmap
, p
+ (pbody
->tim
.length
- 3),
215 (pbody
->tim
.length
- 3));
216 offset
+= pbody
->tim
.length
- 3;
220 printf("(1) unhandled element_id (%d) ",
223 offset
+= *(p
+ offset
+ 1) + 2;
230 /*********************************************************************************
231 * Print Handle functions for the management frame types
232 *********************************************************************************/
235 handle_beacon(const u_char
*p
)
237 struct mgmt_body_t pbody
;
240 memset(&pbody
, 0, sizeof(pbody
));
242 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
243 IEEE802_11_CAPINFO_LEN
))
245 memcpy(&pbody
.timestamp
, p
, 8);
246 offset
+= IEEE802_11_TSTAMP_LEN
;
247 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
248 offset
+= IEEE802_11_BCNINT_LEN
;
249 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
250 offset
+= IEEE802_11_CAPINFO_LEN
;
252 if (!parse_elements(&pbody
, p
, offset
))
256 fn_print(pbody
.ssid
.ssid
, NULL
);
259 printf(" %s CH: %u%s",
260 CAPABILITY_ESS(pbody
.capability_info
) ? "ESS" : "IBSS",
262 CAPABILITY_PRIVACY(pbody
.capability_info
) ? ", PRIVACY" : "" );
268 handle_assoc_request(const u_char
*p
)
270 struct mgmt_body_t pbody
;
273 memset(&pbody
, 0, sizeof(pbody
));
275 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
))
277 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
278 offset
+= IEEE802_11_CAPINFO_LEN
;
279 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
280 offset
+= IEEE802_11_LISTENINT_LEN
;
282 if (!parse_elements(&pbody
, p
, offset
))
286 fn_print(pbody
.ssid
.ssid
, NULL
);
293 handle_assoc_response(const u_char
*p
)
295 struct mgmt_body_t pbody
;
298 memset(&pbody
, 0, sizeof(pbody
));
300 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
303 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
304 offset
+= IEEE802_11_CAPINFO_LEN
;
305 pbody
.status_code
= EXTRACT_LE_16BITS(p
+offset
);
306 offset
+= IEEE802_11_STATUS_LEN
;
307 pbody
.aid
= EXTRACT_LE_16BITS(p
+offset
);
308 offset
+= IEEE802_11_AID_LEN
;
310 if (!parse_elements(&pbody
, p
, offset
))
313 printf(" AID(%x) :%s: %s", ((u_int16_t
)(pbody
.aid
<< 2 )) >> 2 ,
314 CAPABILITY_PRIVACY(pbody
.capability_info
) ? " PRIVACY " : "",
315 (pbody
.status_code
< NUM_STATUSES
316 ? status_text
[pbody
.status_code
]
323 handle_reassoc_request(const u_char
*p
)
325 struct mgmt_body_t pbody
;
328 memset(&pbody
, 0, sizeof(pbody
));
330 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
333 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
334 offset
+= IEEE802_11_CAPINFO_LEN
;
335 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
336 offset
+= IEEE802_11_LISTENINT_LEN
;
337 memcpy(&pbody
.ap
, p
+offset
, IEEE802_11_AP_LEN
);
338 offset
+= IEEE802_11_AP_LEN
;
340 if (!parse_elements(&pbody
, p
, offset
))
344 fn_print(pbody
.ssid
.ssid
, NULL
);
345 printf(") AP : %s", etheraddr_string( pbody
.ap
));
351 handle_reassoc_response(const u_char
*p
)
353 /* Same as a Association Reponse */
354 return handle_assoc_response(p
);
358 handle_probe_request(const u_char
*p
)
360 struct mgmt_body_t pbody
;
363 memset(&pbody
, 0, sizeof(pbody
));
365 if (!parse_elements(&pbody
, p
, offset
))
369 fn_print(pbody
.ssid
.ssid
, NULL
);
377 handle_probe_response(const u_char
*p
)
379 struct mgmt_body_t pbody
;
382 memset(&pbody
, 0, sizeof(pbody
));
384 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
385 IEEE802_11_CAPINFO_LEN
))
388 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
389 offset
+= IEEE802_11_TSTAMP_LEN
;
390 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
391 offset
+= IEEE802_11_BCNINT_LEN
;
392 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
393 offset
+= IEEE802_11_CAPINFO_LEN
;
395 if (!parse_elements(&pbody
, p
, offset
))
399 fn_print(pbody
.ssid
.ssid
, NULL
);
402 printf(" CH: %u%s", pbody
.ds
.channel
,
403 CAPABILITY_PRIVACY(pbody
.capability_info
) ? ", PRIVACY" : "" );
411 /* the frame body for ATIM is null. */
416 handle_disassoc(const u_char
*p
)
418 struct mgmt_body_t pbody
;
420 memset(&pbody
, 0, sizeof(pbody
));
422 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
424 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
427 (pbody
.reason_code
< NUM_REASONS
)
428 ? reason_text
[pbody
.reason_code
]
435 handle_auth(const u_char
*p
)
437 struct mgmt_body_t pbody
;
440 memset(&pbody
, 0, sizeof(pbody
));
444 pbody
.auth_alg
= EXTRACT_LE_16BITS(p
);
446 pbody
.auth_trans_seq_num
= EXTRACT_LE_16BITS(p
+ offset
);
448 pbody
.status_code
= EXTRACT_LE_16BITS(p
+ offset
);
451 if (!parse_elements(&pbody
, p
, offset
))
454 if ((pbody
.auth_alg
== 1) &&
455 ((pbody
.auth_trans_seq_num
== 2) ||
456 (pbody
.auth_trans_seq_num
== 3))) {
457 printf(" (%s)-%x [Challenge Text] %s",
458 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
459 ? auth_alg_text
[pbody
.auth_alg
]
461 pbody
.auth_trans_seq_num
,
462 ((pbody
.auth_trans_seq_num
% 2)
463 ? ((pbody
.status_code
< NUM_STATUSES
)
464 ? status_text
[pbody
.status_code
]
468 printf(" (%s)-%x: %s",
469 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
470 ? auth_alg_text
[pbody
.auth_alg
]
472 pbody
.auth_trans_seq_num
,
473 (pbody
.auth_trans_seq_num
% 2)
474 ? ((pbody
.status_code
< NUM_STATUSES
)
475 ? status_text
[pbody
.status_code
]
483 handle_deauth(const struct mgmt_header_t
*pmh
, const u_char
*p
)
485 struct mgmt_body_t pbody
;
487 const char *reason
= NULL
;
489 memset(&pbody
, 0, sizeof(pbody
));
491 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
493 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
494 offset
+= IEEE802_11_REASON_LEN
;
496 reason
= (pbody
.reason_code
< NUM_REASONS
)
497 ? reason_text
[pbody
.reason_code
]
501 printf(": %s", reason
);
503 printf(" (%s): %s", etheraddr_string(pmh
->sa
), reason
);
509 /*********************************************************************************
511 *********************************************************************************/
515 mgmt_body_print(u_int16_t fc
, const struct mgmt_header_t
*pmh
,
518 printf("%s", subtype_text
[FC_SUBTYPE(fc
)]);
520 switch (FC_SUBTYPE(fc
)) {
521 case ST_ASSOC_REQUEST
:
522 return handle_assoc_request(p
);
523 case ST_ASSOC_RESPONSE
:
524 return handle_assoc_response(p
);
525 case ST_REASSOC_REQUEST
:
526 return handle_reassoc_request(p
);
527 case ST_REASSOC_RESPONSE
:
528 return handle_reassoc_response(p
);
529 case ST_PROBE_REQUEST
:
530 return handle_probe_request(p
);
531 case ST_PROBE_RESPONSE
:
532 return handle_probe_response(p
);
534 return handle_beacon(p
);
536 return handle_atim();
538 return handle_disassoc(p
);
542 if ((p
[0] == 0 ) && (p
[1] == 0) && (p
[2] == 0)) {
543 printf("Authentication (Shared-Key)-3 ");
546 return handle_auth(p
);
548 return handle_deauth(pmh
, p
);
551 printf("Unhandled Management subtype(%x)",
558 /*********************************************************************************
559 * Handles printing all the control frame types
560 *********************************************************************************/
563 ctrl_body_print(u_int16_t fc
, const u_char
*p
)
565 switch (FC_SUBTYPE(fc
)) {
567 printf("Power Save-Poll");
568 if (!TTEST2(*p
, CTRL_PS_POLL_HDRLEN
))
571 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t
*)p
)->aid
)));
574 printf("Request-To-Send");
575 if (!TTEST2(*p
, CTRL_RTS_HDRLEN
))
579 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
582 printf("Clear-To-Send");
583 if (!TTEST2(*p
, CTRL_CTS_HDRLEN
))
587 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
590 printf("Acknowledgment");
591 if (!TTEST2(*p
, CTRL_ACK_HDRLEN
))
595 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
599 if (!TTEST2(*p
, CTRL_END_HDRLEN
))
603 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
));
606 printf("CF-End+CF-Ack");
607 if (!TTEST2(*p
, CTRL_END_ACK_HDRLEN
))
611 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
));
614 printf("Unknown Ctrl Subtype");
624 * Data Frame - Address field contents
626 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
627 * 0 | 0 | DA | SA | BSSID | n/a
628 * 0 | 1 | DA | BSSID | SA | n/a
629 * 1 | 0 | BSSID | SA | DA | n/a
630 * 1 | 1 | RA | TA | DA | SA
634 data_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
635 const u_int8_t
**dstp
)
637 switch (FC_SUBTYPE(fc
)) {
641 case DATA_DATA_CF_ACK
:
642 case DATA_NODATA_CF_ACK
:
645 case DATA_DATA_CF_POLL
:
646 case DATA_NODATA_CF_POLL
:
649 case DATA_DATA_CF_ACK_POLL
:
650 case DATA_NODATA_CF_ACK_POLL
:
651 printf("CF Ack/Poll ");
655 #define ADDR1 (p + 4)
656 #define ADDR2 (p + 10)
657 #define ADDR3 (p + 16)
658 #define ADDR4 (p + 24)
660 if (!FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
667 printf("DA:%s SA:%s BSSID:%s ",
668 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
669 etheraddr_string(ADDR3
));
670 } else if (!FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
677 printf("DA:%s BSSID:%s SA:%s ",
678 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
679 etheraddr_string(ADDR3
));
680 } else if (FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
687 printf("BSSID:%s SA:%s DA:%s ",
688 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
689 etheraddr_string(ADDR3
));
690 } else if (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
697 printf("RA:%s TA:%s DA:%s SA:%s ",
698 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
699 etheraddr_string(ADDR3
), etheraddr_string(ADDR4
));
709 mgmt_header_print(const u_char
*p
, const u_int8_t
**srcp
,
710 const u_int8_t
**dstp
)
712 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
721 printf("BSSID:%s DA:%s SA:%s ",
722 etheraddr_string((hp
)->bssid
), etheraddr_string((hp
)->da
),
723 etheraddr_string((hp
)->sa
));
727 ctrl_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
728 const u_int8_t
**dstp
)
737 switch (FC_SUBTYPE(fc
)) {
739 printf("BSSID:%s TA:%s ",
740 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->bssid
),
741 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->ta
));
744 printf("RA:%s TA:%s ",
745 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ra
),
746 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
750 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
754 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
757 printf("RA:%s BSSID:%s ",
758 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
),
759 etheraddr_string(((const struct ctrl_end_t
*)p
)->bssid
));
762 printf("RA:%s BSSID:%s ",
763 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
),
764 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->bssid
));
767 printf("(H) Unknown Ctrl Subtype");
773 extract_header_length(u_int16_t fc
)
775 switch (FC_TYPE(fc
)) {
779 switch (FC_SUBTYPE(fc
)) {
781 return CTRL_PS_POLL_HDRLEN
;
783 return CTRL_RTS_HDRLEN
;
785 return CTRL_CTS_HDRLEN
;
787 return CTRL_ACK_HDRLEN
;
789 return CTRL_END_HDRLEN
;
791 return CTRL_END_ACK_HDRLEN
;
796 return (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) ? 30 : 24;
798 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc
));
804 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp"
805 * to point to the source and destination MAC addresses in any case if
806 * "srcp" and "dstp" aren't null.
809 ieee_802_11_hdr_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
810 const u_int8_t
**dstp
)
813 if (FC_MORE_DATA(fc
))
814 printf("More Data ");
815 if (FC_MORE_FLAG(fc
))
816 printf("More Fragments ");
817 if (FC_POWER_MGMT(fc
))
822 printf("Strictly Ordered ");
824 printf("WEP Encrypted ");
825 if (FC_TYPE(fc
) != T_CTRL
|| FC_SUBTYPE(fc
) != CTRL_PS_POLL
)
828 &((const struct mgmt_header_t
*)p
)->duration
));
831 switch (FC_TYPE(fc
)) {
833 mgmt_header_print(p
, srcp
, dstp
);
836 ctrl_header_print(fc
, p
, srcp
, dstp
);
839 data_header_print(fc
, p
, srcp
, dstp
);
842 printf("(header) unknown IEEE802.11 frame type (%d)",
851 ieee802_11_print(const u_char
*p
, u_int length
, u_int caplen
)
855 const u_int8_t
*src
, *dst
;
856 u_short extracted_ethertype
;
858 if (caplen
< IEEE802_11_FC_LEN
) {
863 fc
= EXTRACT_LE_16BITS(p
);
864 hdrlen
= extract_header_length(fc
);
866 if (caplen
< hdrlen
) {
871 ieee_802_11_hdr_print(fc
, p
, &src
, &dst
);
874 * Go past the 802.11 header.
880 switch (FC_TYPE(fc
)) {
882 if (!mgmt_body_print(fc
,
883 (const struct mgmt_header_t
*)(p
- hdrlen
), p
)) {
889 if (!ctrl_body_print(fc
, p
- hdrlen
)) {
895 /* There may be a problem w/ AP not having this bit set */
901 } else if (llc_print(p
, length
, caplen
, dst
, src
,
902 &extracted_ethertype
) == 0) {
904 * Some kinds of LLC packet we cannot
905 * handle intelligently
908 ieee_802_11_hdr_print(fc
, p
- hdrlen
, NULL
,
910 if (extracted_ethertype
)
913 htons(extracted_ethertype
)));
914 if (!suppress_default_print
)
915 default_print(p
, caplen
);
919 printf("unknown 802.11 frame type (%d)", FC_TYPE(fc
));
927 * This is the top level routine of the printer. 'p' points
928 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
929 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
930 * is the number of bytes actually captured.
933 ieee802_11_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
935 return ieee802_11_print(p
, h
->len
, h
->caplen
);
939 print_radiotap_field(struct cpack_state
*s
, u_int32_t bit
)
952 case IEEE80211_RADIOTAP_FLAGS
:
953 case IEEE80211_RADIOTAP_RATE
:
954 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
955 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
956 case IEEE80211_RADIOTAP_ANTENNA
:
957 rc
= cpack_uint8(s
, &u
.u8
);
959 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
960 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
961 rc
= cpack_int8(s
, &u
.i8
);
963 case IEEE80211_RADIOTAP_CHANNEL
:
964 rc
= cpack_uint16(s
, &u
.u16
);
967 rc
= cpack_uint16(s
, &u2
.u16
);
969 case IEEE80211_RADIOTAP_FHSS
:
970 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
971 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
972 rc
= cpack_uint16(s
, &u
.u16
);
974 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
975 rc
= cpack_uint8(s
, &u
.u8
);
977 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
978 rc
= cpack_int8(s
, &u
.i8
);
980 case IEEE80211_RADIOTAP_TSFT
:
981 rc
= cpack_uint64(s
, &u
.u64
);
984 /* this bit indicates a field whose
985 * size we do not know, so we cannot
988 printf("[0x%08x] ", bit
);
998 case IEEE80211_RADIOTAP_CHANNEL
:
999 printf("%u MHz ", u
.u16
);
1001 printf("(0x%04x) ", u2
.u16
);
1003 case IEEE80211_RADIOTAP_FHSS
:
1004 printf("fhset %d fhpat %d ", u
.u16
& 0xff, (u
.u16
>> 8) & 0xff);
1006 case IEEE80211_RADIOTAP_RATE
:
1007 PRINT_RATE("", u
.u8
, " Mb/s ");
1009 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
1010 printf("%ddB signal ", u
.i8
);
1012 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
1013 printf("%ddB noise ", u
.i8
);
1015 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
1016 printf("%ddB signal ", u
.u8
);
1018 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
1019 printf("%ddB noise ", u
.u8
);
1021 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
1022 printf("%u sq ", u
.u16
);
1024 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
1025 printf("%d tx power ", -(int)u
.u16
);
1027 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
1028 printf("%ddB tx power ", -(int)u
.u8
);
1030 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
1031 printf("%ddBm tx power ", u
.i8
);
1033 case IEEE80211_RADIOTAP_FLAGS
:
1034 if (u
.u8
& IEEE80211_RADIOTAP_F_CFP
)
1036 if (u
.u8
& IEEE80211_RADIOTAP_F_SHORTPRE
)
1037 printf("short preamble ");
1038 if (u
.u8
& IEEE80211_RADIOTAP_F_WEP
)
1040 if (u
.u8
& IEEE80211_RADIOTAP_F_FRAG
)
1041 printf("fragmented ");
1043 case IEEE80211_RADIOTAP_ANTENNA
:
1044 printf("antenna %d ", u
.u8
);
1046 case IEEE80211_RADIOTAP_TSFT
:
1047 printf("%" PRIu64
"us tsft ", u
.u64
);
1054 ieee802_11_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
1056 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
1057 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
1058 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
1059 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
1060 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
1061 #define BIT(n) (1 << n)
1062 #define IS_EXTENDED(__p) \
1063 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
1065 struct cpack_state cpacker
;
1066 struct ieee80211_radiotap_header
*hdr
;
1067 u_int32_t present
, next_present
;
1068 u_int32_t
*presentp
, *last_presentp
;
1069 enum ieee80211_radiotap_type bit
;
1074 if (caplen
< sizeof(*hdr
)) {
1075 printf("[|802.11]");
1079 hdr
= (struct ieee80211_radiotap_header
*)p
;
1081 len
= EXTRACT_LE_16BITS(&hdr
->it_len
);
1084 printf("[|802.11]");
1087 for (last_presentp
= &hdr
->it_present
;
1088 IS_EXTENDED(last_presentp
) &&
1089 (u_char
*)(last_presentp
+ 1) <= p
+ len
;
1092 /* are there more bitmap extensions than bytes in header? */
1093 if (IS_EXTENDED(last_presentp
)) {
1094 printf("[|802.11]");
1098 iter
= (u_char
*)(last_presentp
+ 1);
1100 if (cpack_init(&cpacker
, (u_int8_t
*)iter
, len
- (iter
- p
)) != 0) {
1102 printf("[|802.11]");
1106 for (bit0
= 0, presentp
= &hdr
->it_present
; presentp
<= last_presentp
;
1107 presentp
++, bit0
+= 32) {
1108 for (present
= EXTRACT_LE_32BITS(presentp
); present
;
1109 present
= next_present
) {
1110 /* clear the least significant bit that is set */
1111 next_present
= present
& (present
- 1);
1113 /* extract the least significant bit that is set */
1114 bit
= (enum ieee80211_radiotap_type
)
1115 (bit0
+ BITNO_32(present
^ next_present
));
1117 if (print_radiotap_field(&cpacker
, bit
) != 0)
1122 return len
+ ieee802_11_print(p
+ len
, length
- len
, caplen
- len
);
1132 ieee802_11_avs_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
1134 u_int32_t caphdr_len
;
1136 caphdr_len
= EXTRACT_32BITS(p
+ 4);
1137 if (caphdr_len
< 8) {
1139 * Yow! The capture header length is claimed not
1140 * to be large enough to include even the version
1141 * cookie or capture header length!
1143 printf("[|802.11]");
1147 if (caplen
< caphdr_len
) {
1148 printf("[|802.11]");
1152 return caphdr_len
+ ieee802_11_print(p
+ caphdr_len
,
1153 length
- caphdr_len
, caplen
- caphdr_len
);
1156 #define PRISM_HDR_LEN 144
1158 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
1161 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
1162 * containing information such as radio information, which we
1165 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1, it's
1166 * really DLT_IEEE802_11_RADIO (currently, on Linux, there's no
1167 * ARPHRD_ type for DLT_IEEE802_11_RADIO, as there is a
1168 * ARPHRD_IEEE80211_PRISM for DLT_PRISM_HEADER, so
1169 * ARPHRD_IEEE80211_PRISM is used for DLT_IEEE802_11_RADIO, and
1170 * the first 4 bytes of the header are used to indicate which it is).
1173 prism_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
1175 u_int caplen
= h
->caplen
;
1176 u_int length
= h
->len
;
1179 printf("[|802.11]");
1183 if (EXTRACT_32BITS(p
) == WLANCAP_MAGIC_COOKIE_V1
)
1184 return ieee802_11_avs_radio_print(p
, length
, caplen
);
1186 if (caplen
< PRISM_HDR_LEN
) {
1187 printf("[|802.11]");
1191 return PRISM_HDR_LEN
+ ieee802_11_print(p
+ PRISM_HDR_LEN
,
1192 length
- PRISM_HDR_LEN
, caplen
- PRISM_HDR_LEN
);
1196 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
1197 * header, containing information such as radio information, which we
1201 ieee802_11_radio_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
1203 u_int caplen
= h
->caplen
;
1204 u_int length
= h
->len
;
1207 printf("[|802.11]");
1211 return ieee802_11_radio_print(p
, length
, caplen
);