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.2 2005/07/07 01:24:33 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 #if defined(DLT_IEEE802_11) || defined(DLT_IEEE802_11_RADIO) || defined(DLT_PRISM_HEADER)
51 #define PRINT_RATE(_sep, _r, _suf) \
52 printf("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf)
53 #define PRINT_RATES(p) \
56 const char *sep = " ["; \
57 for (z = 0; z < p.rates.length ; z++) { \
58 PRINT_RATE(sep, p.rates.rate[z], \
59 (p.rates.rate[z] & 0x80 ? "*" : "")); \
62 if (p.rates.length != 0) \
66 static const char *auth_alg_text[]={"Open System","Shared Key","EAP"};
67 static const char *subtype_text[]={
85 static const char *status_text[] = {
87 "Unspecified failure", /* 1 */
96 "Cannot Support all requested capabilities in the Capability Information field", /* 10 */
97 "Reassociation denied due to inability to confirm that association exists", /* 11 */
98 "Association denied due to reason outside the scope of the standard", /* 12 */
99 "Responding station does not support the specified authentication algorithm ", /* 13 */
100 "Received an Authentication frame with authentication transaction " \
101 "sequence number out of expected sequence", /* 14 */
102 "Authentication rejected because of challenge failure", /* 15 */
103 "Authentication rejected due to timeout waiting for next frame in sequence", /* 16 */
104 "Association denied because AP is unable to handle additional associated stations", /* 17 */
105 "Association denied due to requesting station not supporting all of the " \
106 "data rates in BSSBasicRateSet parameter", /* 18 */
110 static const char *reason_text[] = {
112 "Unspecified reason", /* 1 */
113 "Previous authentication no longer valid", /* 2 */
114 "Deauthenticated because sending station is leaving (or has left) IBSS or ESS", /* 3 */
115 "Disassociated due to inactivity", /* 4 */
116 "Disassociated because AP is unable to handle all currently associated stations", /* 5 */
117 "Class 2 frame receivedfrom nonauthenticated station", /* 6 */
118 "Class 3 frame received from nonassociated station", /* 7 */
119 "Disassociated because sending station is leaving (or has left) BSS", /* 8 */
120 "Station requesting (re)association is not authenticated with responding station", /* 9 */
125 wep_print(const u_char *p)
129 if (!TTEST2(*p, IEEE802_11_IV_LEN + IEEE802_11_KID_LEN))
131 iv = EXTRACT_LE_32BITS(p);
133 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv), IV_PAD(iv),
140 parse_elements(struct mgmt_body_t *pbody, const u_char *p, int offset)
143 if (!TTEST2(*(p + offset), 1))
145 switch (*(p + offset)) {
147 if (!TTEST2(*(p + offset), 2))
149 memcpy(&pbody->ssid, p + offset, 2);
151 if (pbody->ssid.length <= 0)
153 if (!TTEST2(*(p + offset), pbody->ssid.length))
155 memcpy(&pbody->ssid.ssid, p + offset,
157 offset += pbody->ssid.length;
158 pbody->ssid.ssid[pbody->ssid.length] = '\0';
161 if (!TTEST2(*(p + offset), 2))
163 memcpy(&pbody->challenge, p + offset, 2);
165 if (pbody->challenge.length <= 0)
167 if (!TTEST2(*(p + offset), pbody->challenge.length))
169 memcpy(&pbody->challenge.text, p + offset,
170 pbody->challenge.length);
171 offset += pbody->challenge.length;
172 pbody->challenge.text[pbody->challenge.length] = '\0';
175 if (!TTEST2(*(p + offset), 2))
177 memcpy(&(pbody->rates), p + offset, 2);
179 if (pbody->rates.length <= 0)
181 if (!TTEST2(*(p + offset), pbody->rates.length))
183 memcpy(&pbody->rates.rate, p + offset,
184 pbody->rates.length);
185 offset += pbody->rates.length;
188 if (!TTEST2(*(p + offset), 3))
190 memcpy(&pbody->ds, p + offset, 3);
194 if (!TTEST2(*(p + offset), 8))
196 memcpy(&pbody->cf, p + offset, 8);
200 if (!TTEST2(*(p + offset), 2))
202 memcpy(&pbody->tim, p + offset, 2);
204 if (!TTEST2(*(p + offset), 3))
206 memcpy(&pbody->tim.count, p + offset, 3);
209 if (pbody->tim.length <= 3)
211 if (!TTEST2(*(p + offset), pbody->tim.length - 3))
213 memcpy(pbody->tim.bitmap, p + (pbody->tim.length - 3),
214 (pbody->tim.length - 3));
215 offset += pbody->tim.length - 3;
219 printf("(1) unhandled element_id (%d) ",
222 offset += *(p + offset + 1) + 2;
229 /*********************************************************************************
230 * Print Handle functions for the management frame types
231 *********************************************************************************/
234 handle_beacon(const u_char *p)
236 struct mgmt_body_t pbody;
239 memset(&pbody, 0, sizeof(pbody));
241 if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
242 IEEE802_11_CAPINFO_LEN))
244 memcpy(&pbody.timestamp, p, 8);
245 offset += IEEE802_11_TSTAMP_LEN;
246 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
247 offset += IEEE802_11_BCNINT_LEN;
248 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
249 offset += IEEE802_11_CAPINFO_LEN;
251 if (!parse_elements(&pbody, p, offset))
255 fn_print(pbody.ssid.ssid, NULL);
258 printf(" %s CH: %u%s",
259 CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS",
261 CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" );
267 handle_assoc_request(const u_char *p)
269 struct mgmt_body_t pbody;
272 memset(&pbody, 0, sizeof(pbody));
274 if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN))
276 pbody.capability_info = EXTRACT_LE_16BITS(p);
277 offset += IEEE802_11_CAPINFO_LEN;
278 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
279 offset += IEEE802_11_LISTENINT_LEN;
281 if (!parse_elements(&pbody, p, offset))
285 fn_print(pbody.ssid.ssid, NULL);
292 handle_assoc_response(const u_char *p)
294 struct mgmt_body_t pbody;
297 memset(&pbody, 0, sizeof(pbody));
299 if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
302 pbody.capability_info = EXTRACT_LE_16BITS(p);
303 offset += IEEE802_11_CAPINFO_LEN;
304 pbody.status_code = EXTRACT_LE_16BITS(p+offset);
305 offset += IEEE802_11_STATUS_LEN;
306 pbody.aid = EXTRACT_LE_16BITS(p+offset);
307 offset += IEEE802_11_AID_LEN;
309 if (!parse_elements(&pbody, p, offset))
312 printf(" AID(%x) :%s: %s", ((u_int16_t)(pbody.aid << 2 )) >> 2 ,
313 CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "",
314 (pbody.status_code < 19 ? status_text[pbody.status_code] : "n/a"));
320 handle_reassoc_request(const u_char *p)
322 struct mgmt_body_t pbody;
325 memset(&pbody, 0, sizeof(pbody));
327 if (!TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
330 pbody.capability_info = EXTRACT_LE_16BITS(p);
331 offset += IEEE802_11_CAPINFO_LEN;
332 pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
333 offset += IEEE802_11_LISTENINT_LEN;
334 memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN);
335 offset += IEEE802_11_AP_LEN;
337 if (!parse_elements(&pbody, p, offset))
341 fn_print(pbody.ssid.ssid, NULL);
342 printf(") AP : %s", etheraddr_string( pbody.ap ));
348 handle_reassoc_response(const u_char *p)
350 /* Same as a Association Reponse */
351 return handle_assoc_response(p);
355 handle_probe_request(const u_char *p)
357 struct mgmt_body_t pbody;
360 memset(&pbody, 0, sizeof(pbody));
362 if (!parse_elements(&pbody, p, offset))
366 fn_print(pbody.ssid.ssid, NULL);
374 handle_probe_response(const u_char *p)
376 struct mgmt_body_t pbody;
379 memset(&pbody, 0, sizeof(pbody));
381 if (!TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
382 IEEE802_11_CAPINFO_LEN))
385 memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
386 offset += IEEE802_11_TSTAMP_LEN;
387 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
388 offset += IEEE802_11_BCNINT_LEN;
389 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
390 offset += IEEE802_11_CAPINFO_LEN;
392 if (!parse_elements(&pbody, p, offset))
396 fn_print(pbody.ssid.ssid, NULL);
399 printf(" CH: %u%s", pbody.ds.channel,
400 CAPABILITY_PRIVACY(pbody.capability_info) ? ", PRIVACY" : "" );
408 /* the frame body for ATIM is null. */
413 handle_disassoc(const u_char *p)
415 struct mgmt_body_t pbody;
417 memset(&pbody, 0, sizeof(pbody));
419 if (!TTEST2(*p, IEEE802_11_REASON_LEN))
421 pbody.reason_code = EXTRACT_LE_16BITS(p);
424 (pbody.reason_code < 10) ? reason_text[pbody.reason_code]
431 handle_auth(const u_char *p)
433 struct mgmt_body_t pbody;
436 memset(&pbody, 0, sizeof(pbody));
440 pbody.auth_alg = EXTRACT_LE_16BITS(p);
442 pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset);
444 pbody.status_code = EXTRACT_LE_16BITS(p + offset);
447 if (!parse_elements(&pbody, p, offset))
450 if ((pbody.auth_alg == 1) &&
451 ((pbody.auth_trans_seq_num == 2) ||
452 (pbody.auth_trans_seq_num == 3))) {
453 printf(" (%s)-%x [Challenge Text] %s",
454 (pbody.auth_alg < 4) ? auth_alg_text[pbody.auth_alg]
456 pbody.auth_trans_seq_num,
457 ((pbody.auth_trans_seq_num % 2)
458 ? ((pbody.status_code < 19)
459 ? status_text[pbody.status_code]
463 printf(" (%s)-%x: %s",
464 (pbody.auth_alg < 4) ? auth_alg_text[pbody.auth_alg] : "Reserved",
465 pbody.auth_trans_seq_num,
466 (pbody.auth_trans_seq_num % 2)
467 ? ((pbody.status_code < 19) ? status_text[pbody.status_code]
475 handle_deauth(const struct mgmt_header_t *pmh, const u_char *p)
477 struct mgmt_body_t pbody;
479 const char *reason = NULL;
481 memset(&pbody, 0, sizeof(pbody));
483 if (!TTEST2(*p, IEEE802_11_REASON_LEN))
485 pbody.reason_code = EXTRACT_LE_16BITS(p);
486 offset += IEEE802_11_REASON_LEN;
488 reason = (pbody.reason_code < 10) ? reason_text[pbody.reason_code]
492 printf(": %s", reason);
494 printf(" (%s): %s", etheraddr_string(pmh->sa), reason);
500 /*********************************************************************************
502 *********************************************************************************/
506 mgmt_body_print(u_int16_t fc, const struct mgmt_header_t *pmh,
509 printf("%s", subtype_text[FC_SUBTYPE(fc)]);
511 switch (FC_SUBTYPE(fc)) {
512 case ST_ASSOC_REQUEST:
513 return handle_assoc_request(p);
514 case ST_ASSOC_RESPONSE:
515 return handle_assoc_response(p);
516 case ST_REASSOC_REQUEST:
517 return handle_reassoc_request(p);
518 case ST_REASSOC_RESPONSE:
519 return handle_reassoc_response(p);
520 case ST_PROBE_REQUEST:
521 return handle_probe_request(p);
522 case ST_PROBE_RESPONSE:
523 return handle_probe_response(p);
525 return handle_beacon(p);
527 return handle_atim();
529 return handle_disassoc(p);
533 if ((p[0] == 0 ) && (p[1] == 0) && (p[2] == 0)) {
534 printf("Authentication (Shared-Key)-3 ");
537 return handle_auth(p);
539 return handle_deauth(pmh, p);
542 printf("Unhandled Management subtype(%x)",
549 /*********************************************************************************
550 * Handles printing all the control frame types
551 *********************************************************************************/
554 ctrl_body_print(u_int16_t fc, const u_char *p)
556 switch (FC_SUBTYPE(fc)) {
558 printf("Power Save-Poll");
559 if (!TTEST2(*p, CTRL_PS_POLL_HDRLEN))
562 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t *)p)->aid)));
565 printf("Request-To-Send");
566 if (!TTEST2(*p, CTRL_RTS_HDRLEN))
570 etheraddr_string(((const struct ctrl_rts_t *)p)->ta));
573 printf("Clear-To-Send");
574 if (!TTEST2(*p, CTRL_CTS_HDRLEN))
578 etheraddr_string(((const struct ctrl_cts_t *)p)->ra));
581 printf("Acknowledgment");
582 if (!TTEST2(*p, CTRL_ACK_HDRLEN))
586 etheraddr_string(((const struct ctrl_ack_t *)p)->ra));
590 if (!TTEST2(*p, CTRL_END_HDRLEN))
594 etheraddr_string(((const struct ctrl_end_t *)p)->ra));
597 printf("CF-End+CF-Ack");
598 if (!TTEST2(*p, CTRL_END_ACK_HDRLEN))
602 etheraddr_string(((const struct ctrl_end_ack_t *)p)->ra));
605 printf("Unknown Ctrl Subtype");
615 * Data Frame - Address field contents
617 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
618 * 0 | 0 | DA | SA | BSSID | n/a
619 * 0 | 1 | DA | BSSID | SA | n/a
620 * 1 | 0 | BSSID | SA | DA | n/a
621 * 1 | 1 | RA | TA | DA | SA
625 data_header_print(u_int16_t fc, const u_char *p, const u_int8_t **srcp,
626 const u_int8_t **dstp)
628 switch (FC_SUBTYPE(fc)) {
632 case DATA_DATA_CF_ACK:
633 case DATA_NODATA_CF_ACK:
636 case DATA_DATA_CF_POLL:
637 case DATA_NODATA_CF_POLL:
640 case DATA_DATA_CF_ACK_POLL:
641 case DATA_NODATA_CF_ACK_POLL:
642 printf("CF Ack/Poll ");
646 #define ADDR1 (p + 4)
647 #define ADDR2 (p + 10)
648 #define ADDR3 (p + 16)
649 #define ADDR4 (p + 24)
651 if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
658 printf("DA:%s SA:%s BSSID:%s ",
659 etheraddr_string(ADDR1), etheraddr_string(ADDR2),
660 etheraddr_string(ADDR3));
661 } else if (!FC_TO_DS(fc) && FC_FROM_DS(fc)) {
668 printf("DA:%s BSSID:%s SA:%s ",
669 etheraddr_string(ADDR1), etheraddr_string(ADDR2),
670 etheraddr_string(ADDR3));
671 } else if (FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
678 printf("BSSID:%s SA:%s DA:%s ",
679 etheraddr_string(ADDR1), etheraddr_string(ADDR2),
680 etheraddr_string(ADDR3));
681 } else if (FC_TO_DS(fc) && FC_FROM_DS(fc)) {
688 printf("RA:%s TA:%s DA:%s SA:%s ",
689 etheraddr_string(ADDR1), etheraddr_string(ADDR2),
690 etheraddr_string(ADDR3), etheraddr_string(ADDR4));
700 mgmt_header_print(const u_char *p, const u_int8_t **srcp,
701 const u_int8_t **dstp)
703 const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p;
712 printf("BSSID:%s DA:%s SA:%s ",
713 etheraddr_string((hp)->bssid), etheraddr_string((hp)->da),
714 etheraddr_string((hp)->sa));
718 ctrl_header_print(u_int16_t fc, const u_char *p, const u_int8_t **srcp,
719 const u_int8_t **dstp)
728 switch (FC_SUBTYPE(fc)) {
730 printf("BSSID:%s TA:%s ",
731 etheraddr_string(((const struct ctrl_ps_poll_t *)p)->bssid),
732 etheraddr_string(((const struct ctrl_ps_poll_t *)p)->ta));
735 printf("RA:%s TA:%s ",
736 etheraddr_string(((const struct ctrl_rts_t *)p)->ra),
737 etheraddr_string(((const struct ctrl_rts_t *)p)->ta));
741 etheraddr_string(((const struct ctrl_cts_t *)p)->ra));
745 etheraddr_string(((const struct ctrl_ack_t *)p)->ra));
748 printf("RA:%s BSSID:%s ",
749 etheraddr_string(((const struct ctrl_end_t *)p)->ra),
750 etheraddr_string(((const struct ctrl_end_t *)p)->bssid));
753 printf("RA:%s BSSID:%s ",
754 etheraddr_string(((const struct ctrl_end_ack_t *)p)->ra),
755 etheraddr_string(((const struct ctrl_end_ack_t *)p)->bssid));
758 printf("(H) Unknown Ctrl Subtype");
764 extract_header_length(u_int16_t fc)
766 switch (FC_TYPE(fc)) {
770 switch (FC_SUBTYPE(fc)) {
772 return CTRL_PS_POLL_HDRLEN;
774 return CTRL_RTS_HDRLEN;
776 return CTRL_CTS_HDRLEN;
778 return CTRL_ACK_HDRLEN;
780 return CTRL_END_HDRLEN;
782 return CTRL_END_ACK_HDRLEN;
787 return (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24;
789 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc));
795 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp"
796 * to point to the source and destination MAC addresses in any case if
797 * "srcp" and "dstp" aren't null.
800 ieee_802_11_hdr_print(u_int16_t fc, const u_char *p, const u_int8_t **srcp,
801 const u_int8_t **dstp)
804 if (FC_MORE_DATA(fc))
805 printf("More Data ");
806 if (FC_MORE_FLAG(fc))
807 printf("More Fragments ");
808 if (FC_POWER_MGMT(fc))
813 printf("Strictly Ordered ");
815 printf("WEP Encrypted ");
816 if (FC_TYPE(fc) != T_CTRL || FC_SUBTYPE(fc) != CTRL_PS_POLL)
819 &((const struct mgmt_header_t *)p)->duration));
822 switch (FC_TYPE(fc)) {
824 mgmt_header_print(p, srcp, dstp);
827 ctrl_header_print(fc, p, srcp, dstp);
830 data_header_print(fc, p, srcp, dstp);
833 printf("(header) unknown IEEE802.11 frame type (%d)",
842 ieee802_11_print(const u_char *p, u_int length, u_int caplen)
846 const u_int8_t *src, *dst;
847 u_short extracted_ethertype;
849 if (caplen < IEEE802_11_FC_LEN) {
854 fc = EXTRACT_LE_16BITS(p);
855 hdrlen = extract_header_length(fc);
857 if (caplen < hdrlen) {
862 ieee_802_11_hdr_print(fc, p, &src, &dst);
865 * Go past the 802.11 header.
871 switch (FC_TYPE(fc)) {
873 if (!mgmt_body_print(fc,
874 (const struct mgmt_header_t *)(p - hdrlen), p)) {
880 if (!ctrl_body_print(fc, p - hdrlen)) {
886 /* There may be a problem w/ AP not having this bit set */
892 } else if (llc_print(p, length, caplen, dst, src,
893 &extracted_ethertype) == 0) {
895 * Some kinds of LLC packet we cannot
896 * handle intelligently
899 ieee_802_11_hdr_print(fc, p - hdrlen, NULL,
901 if (extracted_ethertype)
904 htons(extracted_ethertype)));
905 if (!suppress_default_print)
906 default_print(p, caplen);
910 printf("unknown 802.11 frame type (%d)", FC_TYPE(fc));
918 * This is the top level routine of the printer. 'p' points
919 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
920 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
921 * is the number of bytes actually captured.
924 ieee802_11_if_print(const struct pcap_pkthdr *h, const u_char *p)
926 return ieee802_11_print(p, h->len, h->caplen);
930 print_radiotap_field(struct cpack_state *s, u_int32_t bit)
943 case IEEE80211_RADIOTAP_FLAGS:
944 case IEEE80211_RADIOTAP_RATE:
945 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
946 case IEEE80211_RADIOTAP_DB_ANTNOISE:
947 case IEEE80211_RADIOTAP_ANTENNA:
948 rc = cpack_uint8(s, &u.u8);
950 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
951 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
952 rc = cpack_int8(s, &u.i8);
954 case IEEE80211_RADIOTAP_CHANNEL:
955 rc = cpack_uint16(s, &u.u16);
958 rc = cpack_uint16(s, &u2.u16);
960 case IEEE80211_RADIOTAP_FHSS:
961 case IEEE80211_RADIOTAP_LOCK_QUALITY:
962 case IEEE80211_RADIOTAP_TX_ATTENUATION:
963 rc = cpack_uint16(s, &u.u16);
965 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
966 rc = cpack_uint8(s, &u.u8);
968 case IEEE80211_RADIOTAP_DBM_TX_POWER:
969 rc = cpack_int8(s, &u.i8);
971 case IEEE80211_RADIOTAP_TSFT:
972 rc = cpack_uint64(s, &u.u64);
975 /* this bit indicates a field whose
976 * size we do not know, so we cannot
979 printf("[0x%08x] ", bit);
989 case IEEE80211_RADIOTAP_CHANNEL:
990 printf("%u MHz ", u.u16);
992 printf("(0x%04x) ", u2.u16);
994 case IEEE80211_RADIOTAP_FHSS:
995 printf("fhset %d fhpat %d ", u.u16 & 0xff, (u.u16 >> 8) & 0xff);
997 case IEEE80211_RADIOTAP_RATE:
998 PRINT_RATE("", u.u8, " Mb/s ");
1000 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
1001 printf("%ddB signal ", u.i8);
1003 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
1004 printf("%ddB noise ", u.i8);
1006 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1007 printf("%ddB signal ", u.u8);
1009 case IEEE80211_RADIOTAP_DB_ANTNOISE:
1010 printf("%ddB noise ", u.u8);
1012 case IEEE80211_RADIOTAP_LOCK_QUALITY:
1013 printf("%u sq ", u.u16);
1015 case IEEE80211_RADIOTAP_TX_ATTENUATION:
1016 printf("%d tx power ", -(int)u.u16);
1018 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
1019 printf("%ddB tx power ", -(int)u.u8);
1021 case IEEE80211_RADIOTAP_DBM_TX_POWER:
1022 printf("%ddBm tx power ", u.i8);
1024 case IEEE80211_RADIOTAP_FLAGS:
1025 if (u.u8 & IEEE80211_RADIOTAP_F_CFP)
1027 if (u.u8 & IEEE80211_RADIOTAP_F_SHORTPRE)
1028 printf("short preamble ");
1029 if (u.u8 & IEEE80211_RADIOTAP_F_WEP)
1031 if (u.u8 & IEEE80211_RADIOTAP_F_FRAG)
1032 printf("fragmented ");
1034 case IEEE80211_RADIOTAP_ANTENNA:
1035 printf("antenna %d ", u.u8);
1037 case IEEE80211_RADIOTAP_TSFT:
1038 printf("%" PRIu64 "us tsft ", u.u64);
1045 ieee802_11_radio_print(const u_char *p, u_int length, u_int caplen)
1047 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
1048 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
1049 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
1050 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
1051 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
1052 #define BIT(n) (1 << n)
1053 #define IS_EXTENDED(__p) \
1054 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
1056 struct cpack_state cpacker;
1057 struct ieee80211_radiotap_header *hdr;
1058 u_int32_t present, next_present;
1059 u_int32_t *presentp, *last_presentp;
1060 enum ieee80211_radiotap_type bit;
1065 if (caplen < sizeof(*hdr)) {
1066 printf("[|802.11]");
1070 hdr = (struct ieee80211_radiotap_header *)p;
1072 len = EXTRACT_LE_16BITS(&hdr->it_len);
1075 printf("[|802.11]");
1078 for (last_presentp = &hdr->it_present;
1079 IS_EXTENDED(last_presentp) &&
1080 (u_char*)(last_presentp + 1) <= p + len;
1083 /* are there more bitmap extensions than bytes in header? */
1084 if (IS_EXTENDED(last_presentp)) {
1085 printf("[|802.11]");
1089 iter = (u_char*)(last_presentp + 1);
1091 if (cpack_init(&cpacker, (u_int8_t*)iter, len - (iter - p)) != 0) {
1093 printf("[|802.11]");
1097 for (bit0 = 0, presentp = &hdr->it_present; presentp <= last_presentp;
1098 presentp++, bit0 += 32) {
1099 for (present = EXTRACT_LE_32BITS(presentp); present;
1100 present = next_present) {
1101 /* clear the least significant bit that is set */
1102 next_present = present & (present - 1);
1104 /* extract the least significant bit that is set */
1105 bit = (enum ieee80211_radiotap_type)
1106 (bit0 + BITNO_32(present ^ next_present));
1108 if (print_radiotap_field(&cpacker, bit) != 0)
1113 return len + ieee802_11_print(p + len, length - len, caplen - len);
1123 ieee802_11_avs_radio_print(const u_char *p, u_int length, u_int caplen)
1125 u_int32_t caphdr_len;
1127 caphdr_len = EXTRACT_32BITS(p + 4);
1128 if (caphdr_len < 8) {
1130 * Yow! The capture header length is claimed not
1131 * to be large enough to include even the version
1132 * cookie or capture header length!
1134 printf("[|802.11]");
1138 if (caplen < caphdr_len) {
1139 printf("[|802.11]");
1143 return caphdr_len + ieee802_11_print(p + caphdr_len,
1144 length - caphdr_len, caplen - caphdr_len);
1147 #define PRISM_HDR_LEN 144
1149 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
1152 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
1153 * containing information such as radio information, which we
1156 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1, it's
1157 * really DLT_IEEE802_11_RADIO (currently, on Linux, there's no
1158 * ARPHRD_ type for DLT_IEEE802_11_RADIO, as there is a
1159 * ARPHRD_IEEE80211_PRISM for DLT_PRISM_HEADER, so
1160 * ARPHRD_IEEE80211_PRISM is used for DLT_IEEE802_11_RADIO, and
1161 * the first 4 bytes of the header are used to indicate which it is).
1164 prism_if_print(const struct pcap_pkthdr *h, const u_char *p)
1166 u_int caplen = h->caplen;
1167 u_int length = h->len;
1170 printf("[|802.11]");
1174 if (EXTRACT_32BITS(p) == WLANCAP_MAGIC_COOKIE_V1)
1175 return ieee802_11_avs_radio_print(p, length, caplen);
1177 if (caplen < PRISM_HDR_LEN) {
1178 printf("[|802.11]");
1182 return PRISM_HDR_LEN + ieee802_11_print(p + PRISM_HDR_LEN,
1183 length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN);
1187 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
1188 * header, containing information such as radio information, which we
1192 ieee802_11_radio_if_print(const struct pcap_pkthdr *h, const u_char *p)
1194 u_int caplen = h->caplen;
1195 u_int length = h->len;
1198 printf("[|802.11]");
1202 return ieee802_11_radio_print(p, length, caplen);