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.5 2005-07-30 21:37:50 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 *status_text
[] = {
69 "Unspecified failure", /* 1 */
78 "Cannot Support all requested capabilities in the Capability Information field", /* 10 */
79 "Reassociation denied due to inability to confirm that association exists", /* 11 */
80 "Association denied due to reason outside the scope of the standard", /* 12 */
81 "Responding station does not support the specified authentication algorithm ", /* 13 */
82 "Received an Authentication frame with authentication transaction " \
83 "sequence number out of expected sequence", /* 14 */
84 "Authentication rejected because of challenge failure", /* 15 */
85 "Authentication rejected due to timeout waiting for next frame in sequence", /* 16 */
86 "Association denied because AP is unable to handle additional associated stations", /* 17 */
87 "Association denied due to requesting station not supporting all of the " \
88 "data rates in BSSBasicRateSet parameter", /* 18 */
90 #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
92 static const char *reason_text
[] = {
94 "Unspecified reason", /* 1 */
95 "Previous authentication no longer valid", /* 2 */
96 "Deauthenticated because sending station is leaving (or has left) IBSS or ESS", /* 3 */
97 "Disassociated due to inactivity", /* 4 */
98 "Disassociated because AP is unable to handle all currently associated stations", /* 5 */
99 "Class 2 frame received from nonauthenticated station", /* 6 */
100 "Class 3 frame received from nonassociated station", /* 7 */
101 "Disassociated because sending station is leaving (or has left) BSS", /* 8 */
102 "Station requesting (re)association is not authenticated with responding station", /* 9 */
104 #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
107 wep_print(const u_char
*p
)
111 if (!TTEST2(*p
, IEEE802_11_IV_LEN
+ IEEE802_11_KID_LEN
))
113 iv
= EXTRACT_LE_32BITS(p
);
115 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv
), IV_PAD(iv
),
122 parse_elements(struct mgmt_body_t
*pbody
, const u_char
*p
, int offset
)
125 if (!TTEST2(*(p
+ offset
), 1))
127 switch (*(p
+ offset
)) {
129 if (!TTEST2(*(p
+ offset
), 2))
131 memcpy(&pbody
->ssid
, p
+ offset
, 2);
133 if (pbody
->ssid
.length
<= 0)
135 if (!TTEST2(*(p
+ offset
), pbody
->ssid
.length
))
137 memcpy(&pbody
->ssid
.ssid
, p
+ offset
,
139 offset
+= pbody
->ssid
.length
;
140 pbody
->ssid
.ssid
[pbody
->ssid
.length
] = '\0';
143 if (!TTEST2(*(p
+ offset
), 2))
145 memcpy(&pbody
->challenge
, p
+ offset
, 2);
147 if (pbody
->challenge
.length
<= 0)
149 if (!TTEST2(*(p
+ offset
), pbody
->challenge
.length
))
151 memcpy(&pbody
->challenge
.text
, p
+ offset
,
152 pbody
->challenge
.length
);
153 offset
+= pbody
->challenge
.length
;
154 pbody
->challenge
.text
[pbody
->challenge
.length
] = '\0';
157 if (!TTEST2(*(p
+ offset
), 2))
159 memcpy(&(pbody
->rates
), p
+ offset
, 2);
161 if (pbody
->rates
.length
<= 0)
163 if (!TTEST2(*(p
+ offset
), pbody
->rates
.length
))
165 memcpy(&pbody
->rates
.rate
, p
+ offset
,
166 pbody
->rates
.length
);
167 offset
+= pbody
->rates
.length
;
170 if (!TTEST2(*(p
+ offset
), 3))
172 memcpy(&pbody
->ds
, p
+ offset
, 3);
176 if (!TTEST2(*(p
+ offset
), 8))
178 memcpy(&pbody
->cf
, p
+ offset
, 8);
182 if (!TTEST2(*(p
+ offset
), 2))
184 memcpy(&pbody
->tim
, p
+ offset
, 2);
186 if (!TTEST2(*(p
+ offset
), 3))
188 memcpy(&pbody
->tim
.count
, p
+ offset
, 3);
191 if (pbody
->tim
.length
<= 3)
193 if (!TTEST2(*(p
+ offset
), pbody
->tim
.length
- 3))
195 memcpy(pbody
->tim
.bitmap
, p
+ (pbody
->tim
.length
- 3),
196 (pbody
->tim
.length
- 3));
197 offset
+= pbody
->tim
.length
- 3;
201 printf("(1) unhandled element_id (%d) ",
204 offset
+= *(p
+ offset
+ 1) + 2;
211 /*********************************************************************************
212 * Print Handle functions for the management frame types
213 *********************************************************************************/
216 handle_beacon(const u_char
*p
)
218 struct mgmt_body_t pbody
;
221 memset(&pbody
, 0, sizeof(pbody
));
223 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
224 IEEE802_11_CAPINFO_LEN
))
226 memcpy(&pbody
.timestamp
, p
, 8);
227 offset
+= IEEE802_11_TSTAMP_LEN
;
228 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
229 offset
+= IEEE802_11_BCNINT_LEN
;
230 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
231 offset
+= IEEE802_11_CAPINFO_LEN
;
233 if (!parse_elements(&pbody
, p
, offset
))
237 fn_print(pbody
.ssid
.ssid
, NULL
);
240 printf(" %s CH: %u%s",
241 CAPABILITY_ESS(pbody
.capability_info
) ? "ESS" : "IBSS",
243 CAPABILITY_PRIVACY(pbody
.capability_info
) ? ", PRIVACY" : "" );
249 handle_assoc_request(const u_char
*p
)
251 struct mgmt_body_t pbody
;
254 memset(&pbody
, 0, sizeof(pbody
));
256 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
))
258 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
259 offset
+= IEEE802_11_CAPINFO_LEN
;
260 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
261 offset
+= IEEE802_11_LISTENINT_LEN
;
263 if (!parse_elements(&pbody
, p
, offset
))
267 fn_print(pbody
.ssid
.ssid
, NULL
);
274 handle_assoc_response(const u_char
*p
)
276 struct mgmt_body_t pbody
;
279 memset(&pbody
, 0, sizeof(pbody
));
281 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
284 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
285 offset
+= IEEE802_11_CAPINFO_LEN
;
286 pbody
.status_code
= EXTRACT_LE_16BITS(p
+offset
);
287 offset
+= IEEE802_11_STATUS_LEN
;
288 pbody
.aid
= EXTRACT_LE_16BITS(p
+offset
);
289 offset
+= IEEE802_11_AID_LEN
;
291 if (!parse_elements(&pbody
, p
, offset
))
294 printf(" AID(%x) :%s: %s", ((u_int16_t
)(pbody
.aid
<< 2 )) >> 2 ,
295 CAPABILITY_PRIVACY(pbody
.capability_info
) ? " PRIVACY " : "",
296 (pbody
.status_code
< NUM_STATUSES
297 ? status_text
[pbody
.status_code
]
304 handle_reassoc_request(const u_char
*p
)
306 struct mgmt_body_t pbody
;
309 memset(&pbody
, 0, sizeof(pbody
));
311 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
314 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
315 offset
+= IEEE802_11_CAPINFO_LEN
;
316 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
317 offset
+= IEEE802_11_LISTENINT_LEN
;
318 memcpy(&pbody
.ap
, p
+offset
, IEEE802_11_AP_LEN
);
319 offset
+= IEEE802_11_AP_LEN
;
321 if (!parse_elements(&pbody
, p
, offset
))
325 fn_print(pbody
.ssid
.ssid
, NULL
);
326 printf(") AP : %s", etheraddr_string( pbody
.ap
));
332 handle_reassoc_response(const u_char
*p
)
334 /* Same as a Association Reponse */
335 return handle_assoc_response(p
);
339 handle_probe_request(const u_char
*p
)
341 struct mgmt_body_t pbody
;
344 memset(&pbody
, 0, sizeof(pbody
));
346 if (!parse_elements(&pbody
, p
, offset
))
350 fn_print(pbody
.ssid
.ssid
, NULL
);
358 handle_probe_response(const u_char
*p
)
360 struct mgmt_body_t pbody
;
363 memset(&pbody
, 0, sizeof(pbody
));
365 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
366 IEEE802_11_CAPINFO_LEN
))
369 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
370 offset
+= IEEE802_11_TSTAMP_LEN
;
371 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
372 offset
+= IEEE802_11_BCNINT_LEN
;
373 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
374 offset
+= IEEE802_11_CAPINFO_LEN
;
376 if (!parse_elements(&pbody
, p
, offset
))
380 fn_print(pbody
.ssid
.ssid
, NULL
);
383 printf(" CH: %u%s", pbody
.ds
.channel
,
384 CAPABILITY_PRIVACY(pbody
.capability_info
) ? ", PRIVACY" : "" );
392 /* the frame body for ATIM is null. */
397 handle_disassoc(const u_char
*p
)
399 struct mgmt_body_t pbody
;
401 memset(&pbody
, 0, sizeof(pbody
));
403 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
405 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
408 (pbody
.reason_code
< NUM_REASONS
)
409 ? reason_text
[pbody
.reason_code
]
416 handle_auth(const u_char
*p
)
418 struct mgmt_body_t pbody
;
421 memset(&pbody
, 0, sizeof(pbody
));
425 pbody
.auth_alg
= EXTRACT_LE_16BITS(p
);
427 pbody
.auth_trans_seq_num
= EXTRACT_LE_16BITS(p
+ offset
);
429 pbody
.status_code
= EXTRACT_LE_16BITS(p
+ offset
);
432 if (!parse_elements(&pbody
, p
, offset
))
435 if ((pbody
.auth_alg
== 1) &&
436 ((pbody
.auth_trans_seq_num
== 2) ||
437 (pbody
.auth_trans_seq_num
== 3))) {
438 printf(" (%s)-%x [Challenge Text] %s",
439 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
440 ? auth_alg_text
[pbody
.auth_alg
]
442 pbody
.auth_trans_seq_num
,
443 ((pbody
.auth_trans_seq_num
% 2)
444 ? ((pbody
.status_code
< NUM_STATUSES
)
445 ? status_text
[pbody
.status_code
]
449 printf(" (%s)-%x: %s",
450 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
451 ? auth_alg_text
[pbody
.auth_alg
]
453 pbody
.auth_trans_seq_num
,
454 (pbody
.auth_trans_seq_num
% 2)
455 ? ((pbody
.status_code
< NUM_STATUSES
)
456 ? status_text
[pbody
.status_code
]
464 handle_deauth(const struct mgmt_header_t
*pmh
, const u_char
*p
)
466 struct mgmt_body_t pbody
;
468 const char *reason
= NULL
;
470 memset(&pbody
, 0, sizeof(pbody
));
472 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
474 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
475 offset
+= IEEE802_11_REASON_LEN
;
477 reason
= (pbody
.reason_code
< NUM_REASONS
)
478 ? reason_text
[pbody
.reason_code
]
482 printf(": %s", reason
);
484 printf(" (%s): %s", etheraddr_string(pmh
->sa
), reason
);
490 /*********************************************************************************
492 *********************************************************************************/
496 mgmt_body_print(u_int16_t fc
, const struct mgmt_header_t
*pmh
,
499 switch (FC_SUBTYPE(fc
)) {
500 case ST_ASSOC_REQUEST
:
501 printf("Assoc Request");
502 return handle_assoc_request(p
);
503 case ST_ASSOC_RESPONSE
:
504 printf("Assoc Response");
505 return handle_assoc_response(p
);
506 case ST_REASSOC_REQUEST
:
507 printf("ReAssoc Request");
508 return handle_reassoc_request(p
);
509 case ST_REASSOC_RESPONSE
:
510 printf("ReAssoc Response");
511 return handle_reassoc_response(p
);
512 case ST_PROBE_REQUEST
:
513 printf("Probe Request");
514 return handle_probe_request(p
);
515 case ST_PROBE_RESPONSE
:
516 printf("Probe Response");
517 return handle_probe_response(p
);
520 return handle_beacon(p
);
523 return handle_atim();
525 printf("Disassociation");
526 return handle_disassoc(p
);
528 printf("Authentication");
531 if ((p
[0] == 0 ) && (p
[1] == 0) && (p
[2] == 0)) {
532 printf("Authentication (Shared-Key)-3 ");
535 return handle_auth(p
);
537 printf("DeAuthentication");
538 return handle_deauth(pmh
, p
);
541 printf("Unhandled Management subtype(%x)",
548 /*********************************************************************************
549 * Handles printing all the control frame types
550 *********************************************************************************/
553 ctrl_body_print(u_int16_t fc
, const u_char
*p
)
555 switch (FC_SUBTYPE(fc
)) {
557 printf("Power Save-Poll");
558 if (!TTEST2(*p
, CTRL_PS_POLL_HDRLEN
))
561 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t
*)p
)->aid
)));
564 printf("Request-To-Send");
565 if (!TTEST2(*p
, CTRL_RTS_HDRLEN
))
569 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
572 printf("Clear-To-Send");
573 if (!TTEST2(*p
, CTRL_CTS_HDRLEN
))
577 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
580 printf("Acknowledgment");
581 if (!TTEST2(*p
, CTRL_ACK_HDRLEN
))
585 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
589 if (!TTEST2(*p
, CTRL_END_HDRLEN
))
593 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
));
596 printf("CF-End+CF-Ack");
597 if (!TTEST2(*p
, CTRL_END_ACK_HDRLEN
))
601 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
));
604 printf("Unknown Ctrl Subtype");
614 * Data Frame - Address field contents
616 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
617 * 0 | 0 | DA | SA | BSSID | n/a
618 * 0 | 1 | DA | BSSID | SA | n/a
619 * 1 | 0 | BSSID | SA | DA | n/a
620 * 1 | 1 | RA | TA | DA | SA
624 data_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
625 const u_int8_t
**dstp
)
627 switch (FC_SUBTYPE(fc
)) {
631 case DATA_DATA_CF_ACK
:
632 case DATA_NODATA_CF_ACK
:
635 case DATA_DATA_CF_POLL
:
636 case DATA_NODATA_CF_POLL
:
639 case DATA_DATA_CF_ACK_POLL
:
640 case DATA_NODATA_CF_ACK_POLL
:
641 printf("CF Ack/Poll ");
645 #define ADDR1 (p + 4)
646 #define ADDR2 (p + 10)
647 #define ADDR3 (p + 16)
648 #define ADDR4 (p + 24)
650 if (!FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
657 printf("DA:%s SA:%s BSSID:%s ",
658 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
659 etheraddr_string(ADDR3
));
660 } else if (!FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
667 printf("DA:%s BSSID:%s SA:%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("BSSID:%s SA:%s DA:%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("RA:%s TA:%s DA:%s SA:%s ",
688 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
689 etheraddr_string(ADDR3
), etheraddr_string(ADDR4
));
699 mgmt_header_print(const u_char
*p
, const u_int8_t
**srcp
,
700 const u_int8_t
**dstp
)
702 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
711 printf("BSSID:%s DA:%s SA:%s ",
712 etheraddr_string((hp
)->bssid
), etheraddr_string((hp
)->da
),
713 etheraddr_string((hp
)->sa
));
717 ctrl_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
718 const u_int8_t
**dstp
)
727 switch (FC_SUBTYPE(fc
)) {
729 printf("BSSID:%s TA:%s ",
730 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->bssid
),
731 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->ta
));
734 printf("RA:%s TA:%s ",
735 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ra
),
736 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
740 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
744 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
747 printf("RA:%s BSSID:%s ",
748 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
),
749 etheraddr_string(((const struct ctrl_end_t
*)p
)->bssid
));
752 printf("RA:%s BSSID:%s ",
753 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
),
754 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->bssid
));
757 printf("(H) Unknown Ctrl Subtype");
763 extract_header_length(u_int16_t fc
)
765 switch (FC_TYPE(fc
)) {
769 switch (FC_SUBTYPE(fc
)) {
771 return CTRL_PS_POLL_HDRLEN
;
773 return CTRL_RTS_HDRLEN
;
775 return CTRL_CTS_HDRLEN
;
777 return CTRL_ACK_HDRLEN
;
779 return CTRL_END_HDRLEN
;
781 return CTRL_END_ACK_HDRLEN
;
786 return (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) ? 30 : 24;
788 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc
));
794 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp"
795 * to point to the source and destination MAC addresses in any case if
796 * "srcp" and "dstp" aren't null.
799 ieee_802_11_hdr_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
800 const u_int8_t
**dstp
)
803 if (FC_MORE_DATA(fc
))
804 printf("More Data ");
805 if (FC_MORE_FLAG(fc
))
806 printf("More Fragments ");
807 if (FC_POWER_MGMT(fc
))
812 printf("Strictly Ordered ");
814 printf("WEP Encrypted ");
815 if (FC_TYPE(fc
) != T_CTRL
|| FC_SUBTYPE(fc
) != CTRL_PS_POLL
)
818 &((const struct mgmt_header_t
*)p
)->duration
));
821 switch (FC_TYPE(fc
)) {
823 mgmt_header_print(p
, srcp
, dstp
);
826 ctrl_header_print(fc
, p
, srcp
, dstp
);
829 data_header_print(fc
, p
, srcp
, dstp
);
832 printf("(header) unknown IEEE802.11 frame type (%d)",
841 ieee802_11_print(const u_char
*p
, u_int length
, u_int caplen
)
845 const u_int8_t
*src
, *dst
;
846 u_short extracted_ethertype
;
848 if (caplen
< IEEE802_11_FC_LEN
) {
853 fc
= EXTRACT_LE_16BITS(p
);
854 hdrlen
= extract_header_length(fc
);
856 if (caplen
< hdrlen
) {
861 ieee_802_11_hdr_print(fc
, p
, &src
, &dst
);
864 * Go past the 802.11 header.
870 switch (FC_TYPE(fc
)) {
872 if (!mgmt_body_print(fc
,
873 (const struct mgmt_header_t
*)(p
- hdrlen
), p
)) {
879 if (!ctrl_body_print(fc
, p
- hdrlen
)) {
885 /* There may be a problem w/ AP not having this bit set */
891 } else if (llc_print(p
, length
, caplen
, dst
, src
,
892 &extracted_ethertype
) == 0) {
894 * Some kinds of LLC packet we cannot
895 * handle intelligently
898 ieee_802_11_hdr_print(fc
, p
- hdrlen
, NULL
,
900 if (extracted_ethertype
)
903 htons(extracted_ethertype
)));
904 if (!suppress_default_print
)
905 default_print(p
, caplen
);
909 printf("unknown 802.11 frame type (%d)", FC_TYPE(fc
));
917 * This is the top level routine of the printer. 'p' points
918 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
919 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
920 * is the number of bytes actually captured.
923 ieee802_11_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
925 return ieee802_11_print(p
, h
->len
, h
->caplen
);
929 print_radiotap_field(struct cpack_state
*s
, u_int32_t bit
)
942 case IEEE80211_RADIOTAP_FLAGS
:
943 case IEEE80211_RADIOTAP_RATE
:
944 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
945 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
946 case IEEE80211_RADIOTAP_ANTENNA
:
947 rc
= cpack_uint8(s
, &u
.u8
);
949 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
950 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
951 rc
= cpack_int8(s
, &u
.i8
);
953 case IEEE80211_RADIOTAP_CHANNEL
:
954 rc
= cpack_uint16(s
, &u
.u16
);
957 rc
= cpack_uint16(s
, &u2
.u16
);
959 case IEEE80211_RADIOTAP_FHSS
:
960 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
961 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
962 rc
= cpack_uint16(s
, &u
.u16
);
964 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
965 rc
= cpack_uint8(s
, &u
.u8
);
967 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
968 rc
= cpack_int8(s
, &u
.i8
);
970 case IEEE80211_RADIOTAP_TSFT
:
971 rc
= cpack_uint64(s
, &u
.u64
);
974 /* this bit indicates a field whose
975 * size we do not know, so we cannot
978 printf("[0x%08x] ", bit
);
988 case IEEE80211_RADIOTAP_CHANNEL
:
989 printf("%u MHz ", u
.u16
);
991 printf("(0x%04x) ", u2
.u16
);
993 case IEEE80211_RADIOTAP_FHSS
:
994 printf("fhset %d fhpat %d ", u
.u16
& 0xff, (u
.u16
>> 8) & 0xff);
996 case IEEE80211_RADIOTAP_RATE
:
997 PRINT_RATE("", u
.u8
, " Mb/s ");
999 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
1000 printf("%ddB signal ", u
.i8
);
1002 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
1003 printf("%ddB noise ", u
.i8
);
1005 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
1006 printf("%ddB signal ", u
.u8
);
1008 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
1009 printf("%ddB noise ", u
.u8
);
1011 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
1012 printf("%u sq ", u
.u16
);
1014 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
1015 printf("%d tx power ", -(int)u
.u16
);
1017 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
1018 printf("%ddB tx power ", -(int)u
.u8
);
1020 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
1021 printf("%ddBm tx power ", u
.i8
);
1023 case IEEE80211_RADIOTAP_FLAGS
:
1024 if (u
.u8
& IEEE80211_RADIOTAP_F_CFP
)
1026 if (u
.u8
& IEEE80211_RADIOTAP_F_SHORTPRE
)
1027 printf("short preamble ");
1028 if (u
.u8
& IEEE80211_RADIOTAP_F_WEP
)
1030 if (u
.u8
& IEEE80211_RADIOTAP_F_FRAG
)
1031 printf("fragmented ");
1033 case IEEE80211_RADIOTAP_ANTENNA
:
1034 printf("antenna %d ", u
.u8
);
1036 case IEEE80211_RADIOTAP_TSFT
:
1037 printf("%" PRIu64
"us tsft ", u
.u64
);
1044 ieee802_11_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
1046 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
1047 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
1048 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
1049 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
1050 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
1051 #define BIT(n) (1 << n)
1052 #define IS_EXTENDED(__p) \
1053 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
1055 struct cpack_state cpacker
;
1056 struct ieee80211_radiotap_header
*hdr
;
1057 u_int32_t present
, next_present
;
1058 u_int32_t
*presentp
, *last_presentp
;
1059 enum ieee80211_radiotap_type bit
;
1064 if (caplen
< sizeof(*hdr
)) {
1065 printf("[|802.11]");
1069 hdr
= (struct ieee80211_radiotap_header
*)p
;
1071 len
= EXTRACT_LE_16BITS(&hdr
->it_len
);
1074 printf("[|802.11]");
1077 for (last_presentp
= &hdr
->it_present
;
1078 IS_EXTENDED(last_presentp
) &&
1079 (u_char
*)(last_presentp
+ 1) <= p
+ len
;
1082 /* are there more bitmap extensions than bytes in header? */
1083 if (IS_EXTENDED(last_presentp
)) {
1084 printf("[|802.11]");
1088 iter
= (u_char
*)(last_presentp
+ 1);
1090 if (cpack_init(&cpacker
, (u_int8_t
*)iter
, len
- (iter
- p
)) != 0) {
1092 printf("[|802.11]");
1096 for (bit0
= 0, presentp
= &hdr
->it_present
; presentp
<= last_presentp
;
1097 presentp
++, bit0
+= 32) {
1098 for (present
= EXTRACT_LE_32BITS(presentp
); present
;
1099 present
= next_present
) {
1100 /* clear the least significant bit that is set */
1101 next_present
= present
& (present
- 1);
1103 /* extract the least significant bit that is set */
1104 bit
= (enum ieee80211_radiotap_type
)
1105 (bit0
+ BITNO_32(present
^ next_present
));
1107 if (print_radiotap_field(&cpacker
, bit
) != 0)
1112 return len
+ ieee802_11_print(p
+ len
, length
- len
, caplen
- len
);
1122 ieee802_11_avs_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
1124 u_int32_t caphdr_len
;
1126 caphdr_len
= EXTRACT_32BITS(p
+ 4);
1127 if (caphdr_len
< 8) {
1129 * Yow! The capture header length is claimed not
1130 * to be large enough to include even the version
1131 * cookie or capture header length!
1133 printf("[|802.11]");
1137 if (caplen
< caphdr_len
) {
1138 printf("[|802.11]");
1142 return caphdr_len
+ ieee802_11_print(p
+ caphdr_len
,
1143 length
- caphdr_len
, caplen
- caphdr_len
);
1146 #define PRISM_HDR_LEN 144
1148 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
1151 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
1152 * containing information such as radio information, which we
1155 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1, it's
1156 * really DLT_IEEE802_11_RADIO (currently, on Linux, there's no
1157 * ARPHRD_ type for DLT_IEEE802_11_RADIO, as there is a
1158 * ARPHRD_IEEE80211_PRISM for DLT_PRISM_HEADER, so
1159 * ARPHRD_IEEE80211_PRISM is used for DLT_IEEE802_11_RADIO, and
1160 * the first 4 bytes of the header are used to indicate which it is).
1163 prism_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
1165 u_int caplen
= h
->caplen
;
1166 u_int length
= h
->len
;
1169 printf("[|802.11]");
1173 if (EXTRACT_32BITS(p
) == WLANCAP_MAGIC_COOKIE_V1
)
1174 return ieee802_11_avs_radio_print(p
, length
, caplen
);
1176 if (caplen
< PRISM_HDR_LEN
) {
1177 printf("[|802.11]");
1181 return PRISM_HDR_LEN
+ ieee802_11_print(p
+ PRISM_HDR_LEN
,
1182 length
- PRISM_HDR_LEN
, caplen
- PRISM_HDR_LEN
);
1186 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
1187 * header, containing information such as radio information, which we
1191 ieee802_11_radio_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
1193 u_int caplen
= h
->caplen
;
1194 u_int length
= h
->len
;
1197 printf("[|802.11]");
1201 return ieee802_11_radio_print(p
, length
, caplen
);