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.8 2005-11-13 19:59:39 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_SSID(p) \
50 switch (p.ssid_status) { \
55 fn_print(p.ssid.ssid, NULL); \
62 #define PRINT_RATE(_sep, _r, _suf) \
63 printf("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf)
64 #define PRINT_RATES(p) \
65 switch (p.rates_status) { \
71 const char *sep = " ["; \
72 for (z = 0; z < p.rates.length ; z++) { \
73 PRINT_RATE(sep, p.rates.rate[z], \
74 (p.rates.rate[z] & 0x80 ? "*" : "")); \
77 if (p.rates.length != 0) \
85 #define PRINT_DS_CHANNEL(p) \
86 switch (p.ds_status) { \
90 printf(" CH: %u", p.ds.channel); \
96 CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : "" );
98 static const char *auth_alg_text
[]={"Open System","Shared Key","EAP"};
99 #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0])
101 static const char *status_text
[] = {
103 "Unspecified failure", /* 1 */
112 "Cannot Support all requested capabilities in the Capability Information field", /* 10 */
113 "Reassociation denied due to inability to confirm that association exists", /* 11 */
114 "Association denied due to reason outside the scope of the standard", /* 12 */
115 "Responding station does not support the specified authentication algorithm ", /* 13 */
116 "Received an Authentication frame with authentication transaction " \
117 "sequence number out of expected sequence", /* 14 */
118 "Authentication rejected because of challenge failure", /* 15 */
119 "Authentication rejected due to timeout waiting for next frame in sequence", /* 16 */
120 "Association denied because AP is unable to handle additional associated stations", /* 17 */
121 "Association denied due to requesting station not supporting all of the " \
122 "data rates in BSSBasicRateSet parameter", /* 18 */
124 #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
126 static const char *reason_text
[] = {
128 "Unspecified reason", /* 1 */
129 "Previous authentication no longer valid", /* 2 */
130 "Deauthenticated because sending station is leaving (or has left) IBSS or ESS", /* 3 */
131 "Disassociated due to inactivity", /* 4 */
132 "Disassociated because AP is unable to handle all currently associated stations", /* 5 */
133 "Class 2 frame received from nonauthenticated station", /* 6 */
134 "Class 3 frame received from nonassociated station", /* 7 */
135 "Disassociated because sending station is leaving (or has left) BSS", /* 8 */
136 "Station requesting (re)association is not authenticated with responding station", /* 9 */
138 #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
141 wep_print(const u_char
*p
)
145 if (!TTEST2(*p
, IEEE802_11_IV_LEN
+ IEEE802_11_KID_LEN
))
147 iv
= EXTRACT_LE_32BITS(p
);
149 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv
), IV_PAD(iv
),
156 parse_elements(struct mgmt_body_t
*pbody
, const u_char
*p
, int offset
)
159 * We haven't seen any elements yet.
161 pbody
->challenge_status
= NOT_PRESENT
;
162 pbody
->ssid_status
= NOT_PRESENT
;
163 pbody
->rates_status
= NOT_PRESENT
;
164 pbody
->ds_status
= NOT_PRESENT
;
165 pbody
->cf_status
= NOT_PRESENT
;
166 pbody
->tim_status
= NOT_PRESENT
;
169 if (!TTEST2(*(p
+ offset
), 1))
171 switch (*(p
+ offset
)) {
173 /* Present, possibly truncated */
174 pbody
->ssid_status
= TRUNCATED
;
175 if (!TTEST2(*(p
+ offset
), 2))
177 memcpy(&pbody
->ssid
, p
+ offset
, 2);
179 if (pbody
->ssid
.length
!= 0) {
180 if (pbody
->ssid
.length
> 32)
182 if (!TTEST2(*(p
+ offset
), pbody
->ssid
.length
))
184 memcpy(&pbody
->ssid
.ssid
, p
+ offset
,
186 offset
+= pbody
->ssid
.length
;
188 pbody
->ssid
.ssid
[pbody
->ssid
.length
] = '\0';
189 /* Present and not truncated */
190 pbody
->ssid_status
= PRESENT
;
193 /* Present, possibly truncated */
194 pbody
->challenge_status
= TRUNCATED
;
195 if (!TTEST2(*(p
+ offset
), 2))
197 memcpy(&pbody
->challenge
, p
+ offset
, 2);
199 if (pbody
->challenge
.length
== 0) {
200 if (pbody
->challenge
.length
> 253)
202 if (!TTEST2(*(p
+ offset
), pbody
->challenge
.length
))
204 memcpy(&pbody
->challenge
.text
, p
+ offset
,
205 pbody
->challenge
.length
);
206 offset
+= pbody
->challenge
.length
;
208 pbody
->challenge
.text
[pbody
->challenge
.length
] = '\0';
209 /* Present and not truncated */
210 pbody
->challenge_status
= PRESENT
;
213 /* Present, possibly truncated */
214 pbody
->rates_status
= TRUNCATED
;
215 if (!TTEST2(*(p
+ offset
), 2))
217 memcpy(&(pbody
->rates
), p
+ offset
, 2);
219 if (pbody
->rates
.length
!= 0) {
220 if (pbody
->rates
.length
> sizeof pbody
->rates
.rate
)
222 if (!TTEST2(*(p
+ offset
), pbody
->rates
.length
))
224 memcpy(&pbody
->rates
.rate
, p
+ offset
,
225 pbody
->rates
.length
);
226 offset
+= pbody
->rates
.length
;
228 /* Present and not truncated */
229 pbody
->rates_status
= PRESENT
;
232 /* Present, possibly truncated */
233 pbody
->ds_status
= TRUNCATED
;
234 if (!TTEST2(*(p
+ offset
), 3))
236 memcpy(&pbody
->ds
, p
+ offset
, 3);
238 /* Present and not truncated */
239 pbody
->ds_status
= PRESENT
;
242 /* Present, possibly truncated */
243 pbody
->cf_status
= TRUNCATED
;
244 if (!TTEST2(*(p
+ offset
), 8))
246 memcpy(&pbody
->cf
, p
+ offset
, 8);
248 /* Present and not truncated */
249 pbody
->cf_status
= PRESENT
;
252 /* Present, possibly truncated */
253 pbody
->tim_status
= TRUNCATED
;
254 if (!TTEST2(*(p
+ offset
), 2))
256 memcpy(&pbody
->tim
, p
+ offset
, 2);
258 if (!TTEST2(*(p
+ offset
), 3))
260 memcpy(&pbody
->tim
.count
, p
+ offset
, 3);
263 if (pbody
->tim
.length
<= 3)
265 if (pbody
->rates
.length
> 251)
267 if (!TTEST2(*(p
+ offset
), pbody
->tim
.length
- 3))
269 memcpy(pbody
->tim
.bitmap
, p
+ (pbody
->tim
.length
- 3),
270 (pbody
->tim
.length
- 3));
271 offset
+= pbody
->tim
.length
- 3;
272 /* Present and not truncated */
273 pbody
->tim_status
= PRESENT
;
277 printf("(1) unhandled element_id (%d) ",
280 if (!TTEST2(*(p
+ offset
), 2))
282 if (!TTEST2(*(p
+ offset
+ 2), *(p
+ offset
+ 1)))
284 offset
+= *(p
+ offset
+ 1) + 2;
290 /*********************************************************************************
291 * Print Handle functions for the management frame types
292 *********************************************************************************/
295 handle_beacon(const u_char
*p
)
297 struct mgmt_body_t pbody
;
300 memset(&pbody
, 0, sizeof(pbody
));
302 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
303 IEEE802_11_CAPINFO_LEN
))
305 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
306 offset
+= IEEE802_11_TSTAMP_LEN
;
307 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
308 offset
+= IEEE802_11_BCNINT_LEN
;
309 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
310 offset
+= IEEE802_11_CAPINFO_LEN
;
312 parse_elements(&pbody
, p
, offset
);
317 CAPABILITY_ESS(pbody
.capability_info
) ? "ESS" : "IBSS");
318 PRINT_DS_CHANNEL(pbody
);
324 handle_assoc_request(const u_char
*p
)
326 struct mgmt_body_t pbody
;
329 memset(&pbody
, 0, sizeof(pbody
));
331 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
;
338 parse_elements(&pbody
, p
, offset
);
346 handle_assoc_response(const u_char
*p
)
348 struct mgmt_body_t pbody
;
351 memset(&pbody
, 0, sizeof(pbody
));
353 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
356 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
357 offset
+= IEEE802_11_CAPINFO_LEN
;
358 pbody
.status_code
= EXTRACT_LE_16BITS(p
+offset
);
359 offset
+= IEEE802_11_STATUS_LEN
;
360 pbody
.aid
= EXTRACT_LE_16BITS(p
+offset
);
361 offset
+= IEEE802_11_AID_LEN
;
363 parse_elements(&pbody
, p
, offset
);
365 printf(" AID(%x) :%s: %s", ((u_int16_t
)(pbody
.aid
<< 2 )) >> 2 ,
366 CAPABILITY_PRIVACY(pbody
.capability_info
) ? " PRIVACY " : "",
367 (pbody
.status_code
< NUM_STATUSES
368 ? status_text
[pbody
.status_code
]
375 handle_reassoc_request(const u_char
*p
)
377 struct mgmt_body_t pbody
;
380 memset(&pbody
, 0, sizeof(pbody
));
382 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
385 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
386 offset
+= IEEE802_11_CAPINFO_LEN
;
387 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
388 offset
+= IEEE802_11_LISTENINT_LEN
;
389 memcpy(&pbody
.ap
, p
+offset
, IEEE802_11_AP_LEN
);
390 offset
+= IEEE802_11_AP_LEN
;
392 parse_elements(&pbody
, p
, offset
);
395 printf(" AP : %s", etheraddr_string( pbody
.ap
));
401 handle_reassoc_response(const u_char
*p
)
403 /* Same as a Association Reponse */
404 return handle_assoc_response(p
);
408 handle_probe_request(const u_char
*p
)
410 struct mgmt_body_t pbody
;
413 memset(&pbody
, 0, sizeof(pbody
));
415 parse_elements(&pbody
, p
, offset
);
424 handle_probe_response(const u_char
*p
)
426 struct mgmt_body_t pbody
;
429 memset(&pbody
, 0, sizeof(pbody
));
431 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
432 IEEE802_11_CAPINFO_LEN
))
435 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
436 offset
+= IEEE802_11_TSTAMP_LEN
;
437 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
438 offset
+= IEEE802_11_BCNINT_LEN
;
439 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
440 offset
+= IEEE802_11_CAPINFO_LEN
;
442 parse_elements(&pbody
, p
, offset
);
446 PRINT_DS_CHANNEL(pbody
);
454 /* the frame body for ATIM is null. */
459 handle_disassoc(const u_char
*p
)
461 struct mgmt_body_t pbody
;
463 memset(&pbody
, 0, sizeof(pbody
));
465 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
467 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
470 (pbody
.reason_code
< NUM_REASONS
)
471 ? reason_text
[pbody
.reason_code
]
478 handle_auth(const u_char
*p
)
480 struct mgmt_body_t pbody
;
483 memset(&pbody
, 0, sizeof(pbody
));
487 pbody
.auth_alg
= EXTRACT_LE_16BITS(p
);
489 pbody
.auth_trans_seq_num
= EXTRACT_LE_16BITS(p
+ offset
);
491 pbody
.status_code
= EXTRACT_LE_16BITS(p
+ offset
);
494 parse_elements(&pbody
, p
, offset
);
496 if ((pbody
.auth_alg
== 1) &&
497 ((pbody
.auth_trans_seq_num
== 2) ||
498 (pbody
.auth_trans_seq_num
== 3))) {
499 printf(" (%s)-%x [Challenge Text] %s",
500 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
501 ? auth_alg_text
[pbody
.auth_alg
]
503 pbody
.auth_trans_seq_num
,
504 ((pbody
.auth_trans_seq_num
% 2)
505 ? ((pbody
.status_code
< NUM_STATUSES
)
506 ? status_text
[pbody
.status_code
]
510 printf(" (%s)-%x: %s",
511 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
512 ? auth_alg_text
[pbody
.auth_alg
]
514 pbody
.auth_trans_seq_num
,
515 (pbody
.auth_trans_seq_num
% 2)
516 ? ((pbody
.status_code
< NUM_STATUSES
)
517 ? status_text
[pbody
.status_code
]
525 handle_deauth(const struct mgmt_header_t
*pmh
, const u_char
*p
)
527 struct mgmt_body_t pbody
;
529 const char *reason
= NULL
;
531 memset(&pbody
, 0, sizeof(pbody
));
533 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
535 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
536 offset
+= IEEE802_11_REASON_LEN
;
538 reason
= (pbody
.reason_code
< NUM_REASONS
)
539 ? reason_text
[pbody
.reason_code
]
543 printf(": %s", reason
);
545 printf(" (%s): %s", etheraddr_string(pmh
->sa
), reason
);
551 /*********************************************************************************
553 *********************************************************************************/
557 mgmt_body_print(u_int16_t fc
, const struct mgmt_header_t
*pmh
,
560 switch (FC_SUBTYPE(fc
)) {
561 case ST_ASSOC_REQUEST
:
562 printf("Assoc Request");
563 return handle_assoc_request(p
);
564 case ST_ASSOC_RESPONSE
:
565 printf("Assoc Response");
566 return handle_assoc_response(p
);
567 case ST_REASSOC_REQUEST
:
568 printf("ReAssoc Request");
569 return handle_reassoc_request(p
);
570 case ST_REASSOC_RESPONSE
:
571 printf("ReAssoc Response");
572 return handle_reassoc_response(p
);
573 case ST_PROBE_REQUEST
:
574 printf("Probe Request");
575 return handle_probe_request(p
);
576 case ST_PROBE_RESPONSE
:
577 printf("Probe Response");
578 return handle_probe_response(p
);
581 return handle_beacon(p
);
584 return handle_atim();
586 printf("Disassociation");
587 return handle_disassoc(p
);
589 printf("Authentication");
592 if ((p
[0] == 0 ) && (p
[1] == 0) && (p
[2] == 0)) {
593 printf("Authentication (Shared-Key)-3 ");
596 return handle_auth(p
);
598 printf("DeAuthentication");
599 return handle_deauth(pmh
, p
);
602 printf("Unhandled Management subtype(%x)",
609 /*********************************************************************************
610 * Handles printing all the control frame types
611 *********************************************************************************/
614 ctrl_body_print(u_int16_t fc
, const u_char
*p
)
616 switch (FC_SUBTYPE(fc
)) {
618 printf("Power Save-Poll");
619 if (!TTEST2(*p
, CTRL_PS_POLL_HDRLEN
))
622 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t
*)p
)->aid
)));
625 printf("Request-To-Send");
626 if (!TTEST2(*p
, CTRL_RTS_HDRLEN
))
630 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
633 printf("Clear-To-Send");
634 if (!TTEST2(*p
, CTRL_CTS_HDRLEN
))
638 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
641 printf("Acknowledgment");
642 if (!TTEST2(*p
, CTRL_ACK_HDRLEN
))
646 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
650 if (!TTEST2(*p
, CTRL_END_HDRLEN
))
654 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
));
657 printf("CF-End+CF-Ack");
658 if (!TTEST2(*p
, CTRL_END_ACK_HDRLEN
))
662 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
));
665 printf("Unknown Ctrl Subtype");
675 * Data Frame - Address field contents
677 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
678 * 0 | 0 | DA | SA | BSSID | n/a
679 * 0 | 1 | DA | BSSID | SA | n/a
680 * 1 | 0 | BSSID | SA | DA | n/a
681 * 1 | 1 | RA | TA | DA | SA
685 data_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
686 const u_int8_t
**dstp
)
688 switch (FC_SUBTYPE(fc
)) {
692 case DATA_DATA_CF_ACK
:
693 case DATA_NODATA_CF_ACK
:
696 case DATA_DATA_CF_POLL
:
697 case DATA_NODATA_CF_POLL
:
700 case DATA_DATA_CF_ACK_POLL
:
701 case DATA_NODATA_CF_ACK_POLL
:
702 printf("CF Ack/Poll ");
706 #define ADDR1 (p + 4)
707 #define ADDR2 (p + 10)
708 #define ADDR3 (p + 16)
709 #define ADDR4 (p + 24)
711 if (!FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
718 printf("DA:%s SA:%s BSSID:%s ",
719 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
720 etheraddr_string(ADDR3
));
721 } else if (!FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
728 printf("DA:%s BSSID:%s SA:%s ",
729 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
730 etheraddr_string(ADDR3
));
731 } else if (FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
738 printf("BSSID:%s SA:%s DA:%s ",
739 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
740 etheraddr_string(ADDR3
));
741 } else if (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
748 printf("RA:%s TA:%s DA:%s SA:%s ",
749 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
750 etheraddr_string(ADDR3
), etheraddr_string(ADDR4
));
760 mgmt_header_print(const u_char
*p
, const u_int8_t
**srcp
,
761 const u_int8_t
**dstp
)
763 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
772 printf("BSSID:%s DA:%s SA:%s ",
773 etheraddr_string((hp
)->bssid
), etheraddr_string((hp
)->da
),
774 etheraddr_string((hp
)->sa
));
778 ctrl_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
779 const u_int8_t
**dstp
)
788 switch (FC_SUBTYPE(fc
)) {
790 printf("BSSID:%s TA:%s ",
791 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->bssid
),
792 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->ta
));
795 printf("RA:%s TA:%s ",
796 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ra
),
797 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
801 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
805 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
808 printf("RA:%s BSSID:%s ",
809 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
),
810 etheraddr_string(((const struct ctrl_end_t
*)p
)->bssid
));
813 printf("RA:%s BSSID:%s ",
814 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
),
815 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->bssid
));
818 printf("(H) Unknown Ctrl Subtype");
824 extract_header_length(u_int16_t fc
)
826 switch (FC_TYPE(fc
)) {
830 switch (FC_SUBTYPE(fc
)) {
832 return CTRL_PS_POLL_HDRLEN
;
834 return CTRL_RTS_HDRLEN
;
836 return CTRL_CTS_HDRLEN
;
838 return CTRL_ACK_HDRLEN
;
840 return CTRL_END_HDRLEN
;
842 return CTRL_END_ACK_HDRLEN
;
847 return (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) ? 30 : 24;
849 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc
));
855 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp"
856 * to point to the source and destination MAC addresses in any case if
857 * "srcp" and "dstp" aren't null.
860 ieee_802_11_hdr_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
861 const u_int8_t
**dstp
)
864 if (FC_MORE_DATA(fc
))
865 printf("More Data ");
866 if (FC_MORE_FLAG(fc
))
867 printf("More Fragments ");
868 if (FC_POWER_MGMT(fc
))
873 printf("Strictly Ordered ");
875 printf("WEP Encrypted ");
876 if (FC_TYPE(fc
) != T_CTRL
|| FC_SUBTYPE(fc
) != CTRL_PS_POLL
)
879 &((const struct mgmt_header_t
*)p
)->duration
));
882 switch (FC_TYPE(fc
)) {
884 mgmt_header_print(p
, srcp
, dstp
);
887 ctrl_header_print(fc
, p
, srcp
, dstp
);
890 data_header_print(fc
, p
, srcp
, dstp
);
893 printf("(header) unknown IEEE802.11 frame type (%d)",
902 ieee802_11_print(const u_char
*p
, u_int length
, u_int caplen
)
906 const u_int8_t
*src
, *dst
;
907 u_short extracted_ethertype
;
909 if (caplen
< IEEE802_11_FC_LEN
) {
914 fc
= EXTRACT_LE_16BITS(p
);
915 hdrlen
= extract_header_length(fc
);
917 if (caplen
< hdrlen
) {
922 ieee_802_11_hdr_print(fc
, p
, &src
, &dst
);
925 * Go past the 802.11 header.
931 switch (FC_TYPE(fc
)) {
933 if (!mgmt_body_print(fc
,
934 (const struct mgmt_header_t
*)(p
- hdrlen
), p
)) {
940 if (!ctrl_body_print(fc
, p
- hdrlen
)) {
946 /* There may be a problem w/ AP not having this bit set */
952 } else if (llc_print(p
, length
, caplen
, dst
, src
,
953 &extracted_ethertype
) == 0) {
955 * Some kinds of LLC packet we cannot
956 * handle intelligently
959 ieee_802_11_hdr_print(fc
, p
- hdrlen
, NULL
,
961 if (extracted_ethertype
)
964 htons(extracted_ethertype
)));
965 if (!suppress_default_print
)
966 default_print(p
, caplen
);
970 printf("unknown 802.11 frame type (%d)", FC_TYPE(fc
));
978 * This is the top level routine of the printer. 'p' points
979 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
980 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
981 * is the number of bytes actually captured.
984 ieee802_11_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
986 return ieee802_11_print(p
, h
->len
, h
->caplen
);
990 print_radiotap_field(struct cpack_state
*s
, u_int32_t bit
)
1003 case IEEE80211_RADIOTAP_FLAGS
:
1004 case IEEE80211_RADIOTAP_RATE
:
1005 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
1006 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
1007 case IEEE80211_RADIOTAP_ANTENNA
:
1008 rc
= cpack_uint8(s
, &u
.u8
);
1010 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
1011 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
1012 rc
= cpack_int8(s
, &u
.i8
);
1014 case IEEE80211_RADIOTAP_CHANNEL
:
1015 rc
= cpack_uint16(s
, &u
.u16
);
1018 rc
= cpack_uint16(s
, &u2
.u16
);
1020 case IEEE80211_RADIOTAP_FHSS
:
1021 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
1022 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
1023 rc
= cpack_uint16(s
, &u
.u16
);
1025 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
1026 rc
= cpack_uint8(s
, &u
.u8
);
1028 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
1029 rc
= cpack_int8(s
, &u
.i8
);
1031 case IEEE80211_RADIOTAP_TSFT
:
1032 rc
= cpack_uint64(s
, &u
.u64
);
1035 /* this bit indicates a field whose
1036 * size we do not know, so we cannot
1039 printf("[0x%08x] ", bit
);
1044 printf("[|802.11]");
1049 case IEEE80211_RADIOTAP_CHANNEL
:
1050 printf("%u MHz ", u
.u16
);
1052 printf("(0x%04x) ", u2
.u16
);
1054 case IEEE80211_RADIOTAP_FHSS
:
1055 printf("fhset %d fhpat %d ", u
.u16
& 0xff, (u
.u16
>> 8) & 0xff);
1057 case IEEE80211_RADIOTAP_RATE
:
1058 PRINT_RATE("", u
.u8
, " Mb/s ");
1060 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
1061 printf("%ddB signal ", u
.i8
);
1063 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
1064 printf("%ddB noise ", u
.i8
);
1066 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
1067 printf("%ddB signal ", u
.u8
);
1069 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
1070 printf("%ddB noise ", u
.u8
);
1072 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
1073 printf("%u sq ", u
.u16
);
1075 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
1076 printf("%d tx power ", -(int)u
.u16
);
1078 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
1079 printf("%ddB tx power ", -(int)u
.u8
);
1081 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
1082 printf("%ddBm tx power ", u
.i8
);
1084 case IEEE80211_RADIOTAP_FLAGS
:
1085 if (u
.u8
& IEEE80211_RADIOTAP_F_CFP
)
1087 if (u
.u8
& IEEE80211_RADIOTAP_F_SHORTPRE
)
1088 printf("short preamble ");
1089 if (u
.u8
& IEEE80211_RADIOTAP_F_WEP
)
1091 if (u
.u8
& IEEE80211_RADIOTAP_F_FRAG
)
1092 printf("fragmented ");
1094 case IEEE80211_RADIOTAP_ANTENNA
:
1095 printf("antenna %d ", u
.u8
);
1097 case IEEE80211_RADIOTAP_TSFT
:
1098 printf("%" PRIu64
"us tsft ", u
.u64
);
1105 ieee802_11_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
1107 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
1108 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
1109 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
1110 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
1111 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
1112 #define BIT(n) (1 << n)
1113 #define IS_EXTENDED(__p) \
1114 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
1116 struct cpack_state cpacker
;
1117 struct ieee80211_radiotap_header
*hdr
;
1118 u_int32_t present
, next_present
;
1119 u_int32_t
*presentp
, *last_presentp
;
1120 enum ieee80211_radiotap_type bit
;
1125 if (caplen
< sizeof(*hdr
)) {
1126 printf("[|802.11]");
1130 hdr
= (struct ieee80211_radiotap_header
*)p
;
1132 len
= EXTRACT_LE_16BITS(&hdr
->it_len
);
1135 printf("[|802.11]");
1138 for (last_presentp
= &hdr
->it_present
;
1139 IS_EXTENDED(last_presentp
) &&
1140 (u_char
*)(last_presentp
+ 1) <= p
+ len
;
1143 /* are there more bitmap extensions than bytes in header? */
1144 if (IS_EXTENDED(last_presentp
)) {
1145 printf("[|802.11]");
1149 iter
= (u_char
*)(last_presentp
+ 1);
1151 if (cpack_init(&cpacker
, (u_int8_t
*)iter
, len
- (iter
- p
)) != 0) {
1153 printf("[|802.11]");
1157 for (bit0
= 0, presentp
= &hdr
->it_present
; presentp
<= last_presentp
;
1158 presentp
++, bit0
+= 32) {
1159 for (present
= EXTRACT_LE_32BITS(presentp
); present
;
1160 present
= next_present
) {
1161 /* clear the least significant bit that is set */
1162 next_present
= present
& (present
- 1);
1164 /* extract the least significant bit that is set */
1165 bit
= (enum ieee80211_radiotap_type
)
1166 (bit0
+ BITNO_32(present
^ next_present
));
1168 if (print_radiotap_field(&cpacker
, bit
) != 0)
1173 return len
+ ieee802_11_print(p
+ len
, length
- len
, caplen
- len
);
1183 ieee802_11_avs_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
1185 u_int32_t caphdr_len
;
1187 caphdr_len
= EXTRACT_32BITS(p
+ 4);
1188 if (caphdr_len
< 8) {
1190 * Yow! The capture header length is claimed not
1191 * to be large enough to include even the version
1192 * cookie or capture header length!
1194 printf("[|802.11]");
1198 if (caplen
< caphdr_len
) {
1199 printf("[|802.11]");
1203 return caphdr_len
+ ieee802_11_print(p
+ caphdr_len
,
1204 length
- caphdr_len
, caplen
- caphdr_len
);
1207 #define PRISM_HDR_LEN 144
1209 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
1212 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
1213 * containing information such as radio information, which we
1216 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1, it's
1217 * really DLT_IEEE802_11_RADIO (currently, on Linux, there's no
1218 * ARPHRD_ type for DLT_IEEE802_11_RADIO, as there is a
1219 * ARPHRD_IEEE80211_PRISM for DLT_PRISM_HEADER, so
1220 * ARPHRD_IEEE80211_PRISM is used for DLT_IEEE802_11_RADIO, and
1221 * the first 4 bytes of the header are used to indicate which it is).
1224 prism_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
1226 u_int caplen
= h
->caplen
;
1227 u_int length
= h
->len
;
1230 printf("[|802.11]");
1234 if (EXTRACT_32BITS(p
) == WLANCAP_MAGIC_COOKIE_V1
)
1235 return ieee802_11_avs_radio_print(p
, length
, caplen
);
1237 if (caplen
< PRISM_HDR_LEN
) {
1238 printf("[|802.11]");
1242 return PRISM_HDR_LEN
+ ieee802_11_print(p
+ PRISM_HDR_LEN
,
1243 length
- PRISM_HDR_LEN
, caplen
- PRISM_HDR_LEN
);
1247 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
1248 * header, containing information such as radio information, which we
1252 ieee802_11_radio_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
1254 u_int caplen
= h
->caplen
;
1255 u_int length
= h
->len
;
1258 printf("[|802.11]");
1262 return ieee802_11_radio_print(p
, length
, caplen
);