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.
27 #include <tcpdump-stdinc.h>
33 #include "interface.h"
34 #include "addrtoname.h"
35 #include "ethertype.h"
42 /* Lengths of 802.11 header components. */
43 #define IEEE802_11_FC_LEN 2
44 #define IEEE802_11_DUR_LEN 2
45 #define IEEE802_11_DA_LEN 6
46 #define IEEE802_11_SA_LEN 6
47 #define IEEE802_11_BSSID_LEN 6
48 #define IEEE802_11_RA_LEN 6
49 #define IEEE802_11_TA_LEN 6
50 #define IEEE802_11_SEQ_LEN 2
51 #define IEEE802_11_CTL_LEN 2
52 #define IEEE802_11_IV_LEN 3
53 #define IEEE802_11_KID_LEN 1
55 /* Frame check sequence length. */
56 #define IEEE802_11_FCS_LEN 4
58 /* Lengths of beacon components. */
59 #define IEEE802_11_TSTAMP_LEN 8
60 #define IEEE802_11_BCNINT_LEN 2
61 #define IEEE802_11_CAPINFO_LEN 2
62 #define IEEE802_11_LISTENINT_LEN 2
64 #define IEEE802_11_AID_LEN 2
65 #define IEEE802_11_STATUS_LEN 2
66 #define IEEE802_11_REASON_LEN 2
68 /* Length of previous AP in reassocation frame */
69 #define IEEE802_11_AP_LEN 6
71 #define T_MGMT 0x0 /* management */
72 #define T_CTRL 0x1 /* control */
73 #define T_DATA 0x2 /* data */
74 #define T_RESV 0x3 /* reserved */
76 #define ST_ASSOC_REQUEST 0x0
77 #define ST_ASSOC_RESPONSE 0x1
78 #define ST_REASSOC_REQUEST 0x2
79 #define ST_REASSOC_RESPONSE 0x3
80 #define ST_PROBE_REQUEST 0x4
81 #define ST_PROBE_RESPONSE 0x5
86 #define ST_DISASSOC 0xA
94 #define CTRL_CONTROL_WRAPPER 0x7
97 #define CTRL_PS_POLL 0xA
101 #define CTRL_CF_END 0xE
102 #define CTRL_END_ACK 0xF
104 #define DATA_DATA 0x0
105 #define DATA_DATA_CF_ACK 0x1
106 #define DATA_DATA_CF_POLL 0x2
107 #define DATA_DATA_CF_ACK_POLL 0x3
108 #define DATA_NODATA 0x4
109 #define DATA_NODATA_CF_ACK 0x5
110 #define DATA_NODATA_CF_POLL 0x6
111 #define DATA_NODATA_CF_ACK_POLL 0x7
113 #define DATA_QOS_DATA 0x8
114 #define DATA_QOS_DATA_CF_ACK 0x9
115 #define DATA_QOS_DATA_CF_POLL 0xA
116 #define DATA_QOS_DATA_CF_ACK_POLL 0xB
117 #define DATA_QOS_NODATA 0xC
118 #define DATA_QOS_CF_POLL_NODATA 0xE
119 #define DATA_QOS_CF_ACK_POLL_NODATA 0xF
122 * The subtype field of a data frame is, in effect, composed of 4 flag
123 * bits - CF-Ack, CF-Poll, Null (means the frame doesn't actually have
124 * any data), and QoS.
126 #define DATA_FRAME_IS_CF_ACK(x) ((x) & 0x01)
127 #define DATA_FRAME_IS_CF_POLL(x) ((x) & 0x02)
128 #define DATA_FRAME_IS_NULL(x) ((x) & 0x04)
129 #define DATA_FRAME_IS_QOS(x) ((x) & 0x08)
132 * Bits in the frame control field.
134 #define FC_VERSION(fc) ((fc) & 0x3)
135 #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
136 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
137 #define FC_TO_DS(fc) ((fc) & 0x0100)
138 #define FC_FROM_DS(fc) ((fc) & 0x0200)
139 #define FC_MORE_FLAG(fc) ((fc) & 0x0400)
140 #define FC_RETRY(fc) ((fc) & 0x0800)
141 #define FC_POWER_MGMT(fc) ((fc) & 0x1000)
142 #define FC_MORE_DATA(fc) ((fc) & 0x2000)
143 #define FC_WEP(fc) ((fc) & 0x4000)
144 #define FC_ORDER(fc) ((fc) & 0x8000)
146 struct mgmt_header_t
{
155 #define MGMT_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
156 IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\
157 IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN)
159 #define CAPABILITY_ESS(cap) ((cap) & 0x0001)
160 #define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
161 #define CAPABILITY_CFP(cap) ((cap) & 0x0004)
162 #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
163 #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
168 u_char ssid
[33]; /* 32 + 1 for null */
180 u_int8_t text
[254]; /* 1-253 + 1 for null */
186 u_int16_t dwell_time
;
188 u_int8_t hop_pattern
;
203 u_int16_t max_duration
;
204 u_int16_t dur_remaing
;
212 u_int8_t bitmap_control
;
213 u_int8_t bitmap
[251];
234 #define E_CHALLENGE 16
243 u_int8_t timestamp
[IEEE802_11_TSTAMP_LEN
];
244 u_int16_t beacon_interval
;
245 u_int16_t listen_interval
;
246 u_int16_t status_code
;
248 u_char ap
[IEEE802_11_AP_LEN
];
249 u_int16_t reason_code
;
251 u_int16_t auth_trans_seq_num
;
252 int challenge_present
;
253 struct challenge_t challenge
;
254 u_int16_t capability_info
;
258 struct rates_t rates
;
277 #define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
278 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
287 #define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
296 #define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
298 struct ctrl_ps_poll_t
{
306 #define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
307 IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
317 #define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
318 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
320 struct ctrl_end_ack_t
{
328 #define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
329 IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
338 #define CTRL_BA_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
350 #define CTRL_BAR_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
351 IEEE802_11_RA_LEN+IEEE802_11_TA_LEN+\
352 IEEE802_11_CTL_LEN+IEEE802_11_SEQ_LEN)
363 #define IV_IV(iv) ((iv) & 0xFFFFFF)
364 #define IV_PAD(iv) (((iv) >> 24) & 0x3F)
365 #define IV_KEYID(iv) (((iv) >> 30) & 0x03)
367 /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
368 /* NetBSD: ieee802_11_radio.h,v 1.2 2006/02/26 03:04:03 dyoung Exp */
371 * Copyright (c) 2003, 2004 David Young. All rights reserved.
373 * Redistribution and use in source and binary forms, with or without
374 * modification, are permitted provided that the following conditions
376 * 1. Redistributions of source code must retain the above copyright
377 * notice, this list of conditions and the following disclaimer.
378 * 2. Redistributions in binary form must reproduce the above copyright
379 * notice, this list of conditions and the following disclaimer in the
380 * documentation and/or other materials provided with the distribution.
381 * 3. The name of David Young may not be used to endorse or promote
382 * products derived from this software without specific prior
383 * written permission.
385 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
386 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
387 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
388 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
389 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
390 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
391 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
392 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
393 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
394 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
395 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
399 /* A generic radio capture format is desirable. It must be
400 * rigidly defined (e.g., units for fields should be given),
401 * and easily extensible.
403 * The following is an extensible radio capture format. It is
404 * based on a bitmap indicating which fields are present.
406 * I am trying to describe precisely what the application programmer
407 * should expect in the following, and for that reason I tell the
408 * units and origin of each measurement (where it applies), or else I
409 * use sufficiently weaselly language ("is a monotonically nondecreasing
410 * function of...") that I cannot set false expectations for lawyerly
415 * The radio capture header precedes the 802.11 header.
417 * Note well: all radiotap fields are little-endian.
419 struct ieee80211_radiotap_header
{
420 u_int8_t it_version
; /* Version 0. Only increases
421 * for drastic changes,
422 * introduction of compatible
423 * new fields does not count.
426 u_int16_t it_len
; /* length of the whole
427 * header in bytes, including
428 * it_version, it_pad,
429 * it_len, and data fields.
431 u_int32_t it_present
; /* A bitmap telling which
432 * fields are present. Set bit 31
433 * (0x80000000) to extend the
434 * bitmap by another 32 bits.
435 * Additional extensions are made
440 /* Name Data type Units
441 * ---- --------- -----
443 * IEEE80211_RADIOTAP_TSFT u_int64_t microseconds
445 * Value in microseconds of the MAC's 64-bit 802.11 Time
446 * Synchronization Function timer when the first bit of the
447 * MPDU arrived at the MAC. For received frames, only.
449 * IEEE80211_RADIOTAP_CHANNEL 2 x u_int16_t MHz, bitmap
451 * Tx/Rx frequency in MHz, followed by flags (see below).
452 * Note that IEEE80211_RADIOTAP_XCHANNEL must be used to
453 * represent an HT channel as there is not enough room in
456 * IEEE80211_RADIOTAP_FHSS u_int16_t see below
458 * For frequency-hopping radios, the hop set (first byte)
459 * and pattern (second byte).
461 * IEEE80211_RADIOTAP_RATE u_int8_t 500kb/s or index
463 * Tx/Rx data rate. If bit 0x80 is set then it represents an
464 * an MCS index and not an IEEE rate.
466 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from
467 * one milliwatt (dBm)
469 * RF signal power at the antenna, decibel difference from
472 * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from
473 * one milliwatt (dBm)
475 * RF noise power at the antenna, decibel difference from one
478 * IEEE80211_RADIOTAP_DB_ANTSIGNAL u_int8_t decibel (dB)
480 * RF signal power at the antenna, decibel difference from an
481 * arbitrary, fixed reference.
483 * IEEE80211_RADIOTAP_DB_ANTNOISE u_int8_t decibel (dB)
485 * RF noise power at the antenna, decibel difference from an
486 * arbitrary, fixed reference point.
488 * IEEE80211_RADIOTAP_LOCK_QUALITY u_int16_t unitless
490 * Quality of Barker code lock. Unitless. Monotonically
491 * nondecreasing with "better" lock strength. Called "Signal
492 * Quality" in datasheets. (Is there a standard way to measure
495 * IEEE80211_RADIOTAP_TX_ATTENUATION u_int16_t unitless
497 * Transmit power expressed as unitless distance from max
498 * power set at factory calibration. 0 is max power.
499 * Monotonically nondecreasing with lower power levels.
501 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION u_int16_t decibels (dB)
503 * Transmit power expressed as decibel distance from max power
504 * set at factory calibration. 0 is max power. Monotonically
505 * nondecreasing with lower power levels.
507 * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from
508 * one milliwatt (dBm)
510 * Transmit power expressed as dBm (decibels from a 1 milliwatt
511 * reference). This is the absolute power level measured at
514 * IEEE80211_RADIOTAP_FLAGS u_int8_t bitmap
516 * Properties of transmitted and received frames. See flags
519 * IEEE80211_RADIOTAP_ANTENNA u_int8_t antenna index
521 * Unitless indication of the Rx/Tx antenna for this packet.
522 * The first antenna is antenna 0.
524 * IEEE80211_RADIOTAP_RX_FLAGS u_int16_t bitmap
526 * Properties of received frames. See flags defined below.
528 * IEEE80211_RADIOTAP_XCHANNEL u_int32_t bitmap
530 * u_int8_t channel number
533 * Extended channel specification: flags (see below) followed by
534 * frequency in MHz, the corresponding IEEE channel number, and
535 * finally the maximum regulatory transmit power cap in .5 dBm
536 * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL
537 * and only one of the two should be present.
539 * IEEE80211_RADIOTAP_MCS u_int8_t known
543 * Bitset indicating which fields have known values, followed
544 * by bitset of flag values, followed by the MCS rate index as
547 * IEEE80211_RADIOTAP_VENDOR_NAMESPACE
552 * The Vendor Namespace Field contains three sub-fields. The first
553 * sub-field is 3 bytes long. It contains the vendor's IEEE 802
554 * Organizationally Unique Identifier (OUI). The fourth byte is a
555 * vendor-specific "namespace selector."
558 enum ieee80211_radiotap_type
{
559 IEEE80211_RADIOTAP_TSFT
= 0,
560 IEEE80211_RADIOTAP_FLAGS
= 1,
561 IEEE80211_RADIOTAP_RATE
= 2,
562 IEEE80211_RADIOTAP_CHANNEL
= 3,
563 IEEE80211_RADIOTAP_FHSS
= 4,
564 IEEE80211_RADIOTAP_DBM_ANTSIGNAL
= 5,
565 IEEE80211_RADIOTAP_DBM_ANTNOISE
= 6,
566 IEEE80211_RADIOTAP_LOCK_QUALITY
= 7,
567 IEEE80211_RADIOTAP_TX_ATTENUATION
= 8,
568 IEEE80211_RADIOTAP_DB_TX_ATTENUATION
= 9,
569 IEEE80211_RADIOTAP_DBM_TX_POWER
= 10,
570 IEEE80211_RADIOTAP_ANTENNA
= 11,
571 IEEE80211_RADIOTAP_DB_ANTSIGNAL
= 12,
572 IEEE80211_RADIOTAP_DB_ANTNOISE
= 13,
573 IEEE80211_RADIOTAP_RX_FLAGS
= 14,
574 /* NB: gap for netbsd definitions */
575 IEEE80211_RADIOTAP_XCHANNEL
= 18,
576 IEEE80211_RADIOTAP_MCS
= 19,
577 IEEE80211_RADIOTAP_NAMESPACE
= 29,
578 IEEE80211_RADIOTAP_VENDOR_NAMESPACE
= 30,
579 IEEE80211_RADIOTAP_EXT
= 31
582 /* channel attributes */
583 #define IEEE80211_CHAN_TURBO 0x00010 /* Turbo channel */
584 #define IEEE80211_CHAN_CCK 0x00020 /* CCK channel */
585 #define IEEE80211_CHAN_OFDM 0x00040 /* OFDM channel */
586 #define IEEE80211_CHAN_2GHZ 0x00080 /* 2 GHz spectrum channel. */
587 #define IEEE80211_CHAN_5GHZ 0x00100 /* 5 GHz spectrum channel */
588 #define IEEE80211_CHAN_PASSIVE 0x00200 /* Only passive scan allowed */
589 #define IEEE80211_CHAN_DYN 0x00400 /* Dynamic CCK-OFDM channel */
590 #define IEEE80211_CHAN_GFSK 0x00800 /* GFSK channel (FHSS PHY) */
591 #define IEEE80211_CHAN_GSM 0x01000 /* 900 MHz spectrum channel */
592 #define IEEE80211_CHAN_STURBO 0x02000 /* 11a static turbo channel only */
593 #define IEEE80211_CHAN_HALF 0x04000 /* Half rate channel */
594 #define IEEE80211_CHAN_QUARTER 0x08000 /* Quarter rate channel */
595 #define IEEE80211_CHAN_HT20 0x10000 /* HT 20 channel */
596 #define IEEE80211_CHAN_HT40U 0x20000 /* HT 40 channel w/ ext above */
597 #define IEEE80211_CHAN_HT40D 0x40000 /* HT 40 channel w/ ext below */
599 /* Useful combinations of channel characteristics, borrowed from Ethereal */
600 #define IEEE80211_CHAN_A \
601 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
602 #define IEEE80211_CHAN_B \
603 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
604 #define IEEE80211_CHAN_G \
605 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
606 #define IEEE80211_CHAN_TA \
607 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
608 #define IEEE80211_CHAN_TG \
609 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN | IEEE80211_CHAN_TURBO)
612 /* For IEEE80211_RADIOTAP_FLAGS */
613 #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
616 #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
620 #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
621 * with WEP encryption
623 #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
626 #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
627 #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
628 * 802.11 header and payload
629 * (to 32-bit boundary)
631 #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */
633 /* For IEEE80211_RADIOTAP_RX_FLAGS */
634 #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
635 #define IEEE80211_RADIOTAP_F_RX_PLCP_CRC 0x0002 /* frame failed PLCP CRC check */
637 /* For IEEE80211_RADIOTAP_MCS known */
638 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN 0x01
639 #define IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN 0x02 /* MCS index field */
640 #define IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN 0x04
641 #define IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN 0x08
642 #define IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN 0x10
643 #define IEEE80211_RADIOTAP_MCS_STBC_KNOWN 0x20
645 /* For IEEE80211_RADIOTAP_MCS flags */
646 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK 0x03
647 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20 0
648 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 1
649 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20L 2
650 #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20U 3
651 #define IEEE80211_RADIOTAP_MCS_SHORT_GI 0x04 /* short guard interval */
652 #define IEEE80211_RADIOTAP_MCS_HT_GREENFIELD 0x08
653 #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
654 #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
655 #define IEEE80211_RADIOTAP_MCS_STBC_1 1
656 #define IEEE80211_RADIOTAP_MCS_STBC_2 2
657 #define IEEE80211_RADIOTAP_MCS_STBC_3 3
658 #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
660 static const char tstr
[] = "[|802.11]";
663 /* This is used to save state when parsing/processing parameters */
664 struct radiotap_state
671 #define PRINT_SSID(p) \
672 if (p.ssid_present) { \
674 fn_print(p.ssid.ssid, NULL); \
678 #define PRINT_RATE(_sep, _r, _suf) \
679 printf("%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf)
680 #define PRINT_RATES(p) \
681 if (p.rates_present) { \
683 const char *sep = " ["; \
684 for (z = 0; z < p.rates.length ; z++) { \
685 PRINT_RATE(sep, p.rates.rate[z], \
686 (p.rates.rate[z] & 0x80 ? "*" : "")); \
689 if (p.rates.length != 0) \
693 #define PRINT_DS_CHANNEL(p) \
695 printf(" CH: %u", p.ds.channel); \
697 CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : "" );
699 #define MAX_MCS_INDEX 76
704 * the MCS index (0-76);
706 * 0 for 20 MHz, 1 for 40 MHz;
708 * 0 for a long guard interval, 1 for a short guard interval.
710 static const float ieee80211_float_htrates
[MAX_MCS_INDEX
+1][2][2] = {
712 { /* 20 Mhz */ { 6.5, /* SGI */ 7.2, },
713 /* 40 Mhz */ { 13.5, /* SGI */ 15.0, },
717 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
718 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
722 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
723 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
727 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
728 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
732 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
733 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
737 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
738 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
742 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
743 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
747 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
748 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
752 { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
753 /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
757 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
758 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
762 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
763 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
767 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
768 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
772 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
773 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
777 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
778 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
782 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
783 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
787 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
788 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
792 { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
793 /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
797 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
798 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
802 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
803 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
807 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
808 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
812 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
813 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
817 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
818 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
822 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
823 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
827 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
828 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
832 { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
833 /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
837 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
838 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
842 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
843 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
847 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
848 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
852 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
853 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
857 { /* 20 Mhz */ { 208.0, /* SGI */ 231.1, },
858 /* 40 Mhz */ { 432.0, /* SGI */ 480.0, },
862 { /* 20 Mhz */ { 234.0, /* SGI */ 260.0, },
863 /* 40 Mhz */ { 486.0, /* SGI */ 540.0, },
867 { /* 20 Mhz */ { 260.0, /* SGI */ 288.9, },
868 /* 40 Mhz */ { 540.0, /* SGI */ 600.0, },
872 { /* 20 Mhz */ { 0.0, /* SGI */ 0.0, }, /* not valid */
873 /* 40 Mhz */ { 6.0, /* SGI */ 6.7, },
877 { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
878 /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
882 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
883 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
887 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
888 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
892 { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
893 /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
897 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
898 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
902 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
903 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
907 { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
908 /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
912 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
913 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
917 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
918 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
922 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
923 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
927 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
928 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
932 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
933 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
937 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
938 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
942 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
943 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
947 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
948 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
952 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
953 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
957 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
958 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
962 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
963 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
967 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
968 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
972 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
973 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
977 { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
978 /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
982 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
983 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
987 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
988 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
992 { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
993 /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
997 { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
998 /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
1002 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
1003 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
1007 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1008 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1012 { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
1013 /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
1017 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1018 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1022 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
1023 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
1027 { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
1028 /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
1032 { /* 20 Mhz */ { 143.0, /* SGI */ 158.9, },
1033 /* 40 Mhz */ { 297.0, /* SGI */ 330.0, },
1037 { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
1038 /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
1042 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1043 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1047 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
1048 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
1052 { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
1053 /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
1057 { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
1058 /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
1062 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
1063 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
1067 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
1068 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
1072 { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
1073 /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
1077 { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
1078 /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
1082 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
1083 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
1087 { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
1088 /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
1092 { /* 20 Mhz */ { 214.5, /* SGI */ 238.3, },
1093 /* 40 Mhz */ { 445.5, /* SGI */ 495.0, },
1097 static const char *auth_alg_text
[]={"Open System","Shared Key","EAP"};
1098 #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0])
1100 static const char *status_text
[] = {
1101 "Successful", /* 0 */
1102 "Unspecified failure", /* 1 */
1111 "Cannot Support all requested capabilities in the Capability "
1112 "Information field", /* 10 */
1113 "Reassociation denied due to inability to confirm that association "
1115 "Association denied due to reason outside the scope of the "
1116 "standard", /* 12 */
1117 "Responding station does not support the specified authentication "
1118 "algorithm ", /* 13 */
1119 "Received an Authentication frame with authentication transaction "
1120 "sequence number out of expected sequence", /* 14 */
1121 "Authentication rejected because of challenge failure", /* 15 */
1122 "Authentication rejected due to timeout waiting for next frame in "
1123 "sequence", /* 16 */
1124 "Association denied because AP is unable to handle additional"
1125 "associated stations", /* 17 */
1126 "Association denied due to requesting station not supporting all of "
1127 "the data rates in BSSBasicRateSet parameter", /* 18 */
1128 "Association denied due to requesting station not supporting "
1129 "short preamble operation", /* 19 */
1130 "Association denied due to requesting station not supporting "
1131 "PBCC encoding", /* 20 */
1132 "Association denied due to requesting station not supporting "
1133 "channel agility", /* 21 */
1134 "Association request rejected because Spectrum Management "
1135 "capability is required", /* 22 */
1136 "Association request rejected because the information in the "
1137 "Power Capability element is unacceptable", /* 23 */
1138 "Association request rejected because the information in the "
1139 "Supported Channels element is unacceptable", /* 24 */
1140 "Association denied due to requesting station not supporting "
1141 "short slot operation", /* 25 */
1142 "Association denied due to requesting station not supporting "
1143 "DSSS-OFDM operation", /* 26 */
1144 "Association denied because the requested STA does not support HT "
1145 "features", /* 27 */
1146 "Reserved", /* 28 */
1147 "Association denied because the requested STA does not support "
1148 "the PCO transition time required by the AP", /* 29 */
1149 "Reserved", /* 30 */
1150 "Reserved", /* 31 */
1151 "Unspecified, QoS-related failure", /* 32 */
1152 "Association denied due to QAP having insufficient bandwidth "
1153 "to handle another QSTA", /* 33 */
1154 "Association denied due to excessive frame loss rates and/or "
1155 "poor conditions on current operating channel", /* 34 */
1156 "Association (with QBSS) denied due to requesting station not "
1157 "supporting the QoS facility", /* 35 */
1158 "Association denied due to requesting station not supporting "
1159 "Block Ack", /* 36 */
1160 "The request has been declined", /* 37 */
1161 "The request has not been successful as one or more parameters "
1162 "have invalid values", /* 38 */
1163 "The TS has not been created because the request cannot be honored. "
1164 "However, a suggested TSPEC is provided so that the initiating QSTA"
1165 "may attempt to set another TS with the suggested changes to the "
1167 "Invalid Information Element", /* 40 */
1168 "Group Cipher is not valid", /* 41 */
1169 "Pairwise Cipher is not valid", /* 42 */
1170 "AKMP is not valid", /* 43 */
1171 "Unsupported RSN IE version", /* 44 */
1172 "Invalid RSN IE Capabilities", /* 45 */
1173 "Cipher suite is rejected per security policy", /* 46 */
1174 "The TS has not been created. However, the HC may be capable of "
1175 "creating a TS, in response to a request, after the time indicated "
1176 "in the TS Delay element", /* 47 */
1177 "Direct Link is not allowed in the BSS by policy", /* 48 */
1178 "Destination STA is not present within this QBSS.", /* 49 */
1179 "The Destination STA is not a QSTA.", /* 50 */
1182 #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
1184 static const char *reason_text
[] = {
1186 "Unspecified reason", /* 1 */
1187 "Previous authentication no longer valid", /* 2 */
1188 "Deauthenticated because sending station is leaving (or has left) "
1189 "IBSS or ESS", /* 3 */
1190 "Disassociated due to inactivity", /* 4 */
1191 "Disassociated because AP is unable to handle all currently "
1192 " associated stations", /* 5 */
1193 "Class 2 frame received from nonauthenticated station", /* 6 */
1194 "Class 3 frame received from nonassociated station", /* 7 */
1195 "Disassociated because sending station is leaving "
1196 "(or has left) BSS", /* 8 */
1197 "Station requesting (re)association is not authenticated with "
1198 "responding station", /* 9 */
1199 "Disassociated because the information in the Power Capability "
1200 "element is unacceptable", /* 10 */
1201 "Disassociated because the information in the SupportedChannels "
1202 "element is unacceptable", /* 11 */
1203 "Invalid Information Element", /* 12 */
1204 "Reserved", /* 13 */
1205 "Michael MIC failure", /* 14 */
1206 "4-Way Handshake timeout", /* 15 */
1207 "Group key update timeout", /* 16 */
1208 "Information element in 4-Way Handshake different from (Re)Association"
1209 "Request/Probe Response/Beacon", /* 17 */
1210 "Group Cipher is not valid", /* 18 */
1211 "AKMP is not valid", /* 20 */
1212 "Unsupported RSN IE version", /* 21 */
1213 "Invalid RSN IE Capabilities", /* 22 */
1214 "IEEE 802.1X Authentication failed", /* 23 */
1215 "Cipher suite is rejected per security policy", /* 24 */
1216 "Reserved", /* 25 */
1217 "Reserved", /* 26 */
1218 "Reserved", /* 27 */
1219 "Reserved", /* 28 */
1220 "Reserved", /* 29 */
1221 "Reserved", /* 30 */
1222 "TS deleted because QoS AP lacks sufficient bandwidth for this "
1223 "QoS STA due to a change in BSS service characteristics or "
1224 "operational mode (e.g. an HT BSS change from 40 MHz channel "
1225 "to 20 MHz channel)", /* 31 */
1226 "Disassociated for unspecified, QoS-related reason", /* 32 */
1227 "Disassociated because QoS AP lacks sufficient bandwidth for this "
1229 "Disassociated because of excessive number of frames that need to be "
1230 "acknowledged, but are not acknowledged for AP transmissions "
1231 "and/or poor channel conditions", /* 34 */
1232 "Disassociated because STA is transmitting outside the limits "
1233 "of its TXOPs", /* 35 */
1234 "Requested from peer STA as the STA is leaving the BSS "
1235 "(or resetting)", /* 36 */
1236 "Requested from peer STA as it does not want to use the "
1237 "mechanism", /* 37 */
1238 "Requested from peer STA as the STA received frames using the "
1239 "mechanism for which a set up is required", /* 38 */
1240 "Requested from peer STA due to time out", /* 39 */
1241 "Reserved", /* 40 */
1242 "Reserved", /* 41 */
1243 "Reserved", /* 42 */
1244 "Reserved", /* 43 */
1245 "Reserved", /* 44 */
1246 "Peer STA does not support the requested cipher suite", /* 45 */
1247 "Association denied due to requesting STA not supporting HT "
1248 "features", /* 46 */
1250 #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
1253 wep_print(const u_char
*p
)
1257 if (!TTEST2(*p
, IEEE802_11_IV_LEN
+ IEEE802_11_KID_LEN
))
1259 iv
= EXTRACT_LE_32BITS(p
);
1261 printf("Data IV:%3x Pad %x KeyID %x", IV_IV(iv
), IV_PAD(iv
),
1268 parse_elements(struct mgmt_body_t
*pbody
, const u_char
*p
, int offset
,
1273 struct challenge_t challenge
;
1274 struct rates_t rates
;
1280 * We haven't seen any elements yet.
1282 pbody
->challenge_present
= 0;
1283 pbody
->ssid_present
= 0;
1284 pbody
->rates_present
= 0;
1285 pbody
->ds_present
= 0;
1286 pbody
->cf_present
= 0;
1287 pbody
->tim_present
= 0;
1289 while (length
!= 0) {
1290 if (!TTEST2(*(p
+ offset
), 1))
1294 switch (*(p
+ offset
)) {
1296 if (!TTEST2(*(p
+ offset
), 2))
1300 memcpy(&ssid
, p
+ offset
, 2);
1303 if (ssid
.length
!= 0) {
1304 if (ssid
.length
> sizeof(ssid
.ssid
) - 1)
1306 if (!TTEST2(*(p
+ offset
), ssid
.length
))
1308 if (length
< ssid
.length
)
1310 memcpy(&ssid
.ssid
, p
+ offset
, ssid
.length
);
1311 offset
+= ssid
.length
;
1312 length
-= ssid
.length
;
1314 ssid
.ssid
[ssid
.length
] = '\0';
1316 * Present and not truncated.
1318 * If we haven't already seen an SSID IE,
1319 * copy this one, otherwise ignore this one,
1320 * so we later report the first one we saw.
1322 if (!pbody
->ssid_present
) {
1324 pbody
->ssid_present
= 1;
1328 if (!TTEST2(*(p
+ offset
), 2))
1332 memcpy(&challenge
, p
+ offset
, 2);
1335 if (challenge
.length
!= 0) {
1336 if (challenge
.length
>
1337 sizeof(challenge
.text
) - 1)
1339 if (!TTEST2(*(p
+ offset
), challenge
.length
))
1341 if (length
< challenge
.length
)
1343 memcpy(&challenge
.text
, p
+ offset
,
1345 offset
+= challenge
.length
;
1346 length
-= challenge
.length
;
1348 challenge
.text
[challenge
.length
] = '\0';
1350 * Present and not truncated.
1352 * If we haven't already seen a challenge IE,
1353 * copy this one, otherwise ignore this one,
1354 * so we later report the first one we saw.
1356 if (!pbody
->challenge_present
) {
1357 pbody
->challenge
= challenge
;
1358 pbody
->challenge_present
= 1;
1362 if (!TTEST2(*(p
+ offset
), 2))
1366 memcpy(&rates
, p
+ offset
, 2);
1369 if (rates
.length
!= 0) {
1370 if (rates
.length
> sizeof rates
.rate
)
1372 if (!TTEST2(*(p
+ offset
), rates
.length
))
1374 if (length
< rates
.length
)
1376 memcpy(&rates
.rate
, p
+ offset
, rates
.length
);
1377 offset
+= rates
.length
;
1378 length
-= rates
.length
;
1381 * Present and not truncated.
1383 * If we haven't already seen a rates IE,
1384 * copy this one if it's not zero-length,
1385 * otherwise ignore this one, so we later
1386 * report the first one we saw.
1388 * We ignore zero-length rates IEs as some
1389 * devices seem to put a zero-length rates
1390 * IE, followed by an SSID IE, followed by
1391 * a non-zero-length rates IE into frames,
1392 * even though IEEE Std 802.11-2007 doesn't
1393 * seem to indicate that a zero-length rates
1396 if (!pbody
->rates_present
&& rates
.length
!= 0) {
1397 pbody
->rates
= rates
;
1398 pbody
->rates_present
= 1;
1402 if (!TTEST2(*(p
+ offset
), 3))
1406 memcpy(&ds
, p
+ offset
, 3);
1410 * Present and not truncated.
1412 * If we haven't already seen a DS IE,
1413 * copy this one, otherwise ignore this one,
1414 * so we later report the first one we saw.
1416 if (!pbody
->ds_present
) {
1418 pbody
->ds_present
= 1;
1422 if (!TTEST2(*(p
+ offset
), 8))
1426 memcpy(&cf
, p
+ offset
, 8);
1430 * Present and not truncated.
1432 * If we haven't already seen a CF IE,
1433 * copy this one, otherwise ignore this one,
1434 * so we later report the first one we saw.
1436 if (!pbody
->cf_present
) {
1438 pbody
->cf_present
= 1;
1442 if (!TTEST2(*(p
+ offset
), 2))
1446 memcpy(&tim
, p
+ offset
, 2);
1449 if (!TTEST2(*(p
+ offset
), 3))
1453 memcpy(&tim
.count
, p
+ offset
, 3);
1457 if (tim
.length
<= 3)
1459 if (tim
.length
- 3 > (int)sizeof tim
.bitmap
)
1461 if (!TTEST2(*(p
+ offset
), tim
.length
- 3))
1463 if (length
< (u_int
)(tim
.length
- 3))
1465 memcpy(tim
.bitmap
, p
+ (tim
.length
- 3),
1467 offset
+= tim
.length
- 3;
1468 length
-= tim
.length
- 3;
1470 * Present and not truncated.
1472 * If we haven't already seen a TIM IE,
1473 * copy this one, otherwise ignore this one,
1474 * so we later report the first one we saw.
1476 if (!pbody
->tim_present
) {
1478 pbody
->tim_present
= 1;
1483 printf("(1) unhandled element_id (%d) ",
1486 if (!TTEST2(*(p
+ offset
), 2))
1490 elementlen
= *(p
+ offset
+ 1);
1491 if (!TTEST2(*(p
+ offset
+ 2), elementlen
))
1493 if (length
< elementlen
+ 2)
1495 offset
+= elementlen
+ 2;
1496 length
-= elementlen
+ 2;
1501 /* No problems found. */
1505 /*********************************************************************************
1506 * Print Handle functions for the management frame types
1507 *********************************************************************************/
1510 handle_beacon(const u_char
*p
, u_int length
)
1512 struct mgmt_body_t pbody
;
1516 memset(&pbody
, 0, sizeof(pbody
));
1518 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1519 IEEE802_11_CAPINFO_LEN
))
1521 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1522 IEEE802_11_CAPINFO_LEN
)
1524 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1525 offset
+= IEEE802_11_TSTAMP_LEN
;
1526 length
-= IEEE802_11_TSTAMP_LEN
;
1527 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
1528 offset
+= IEEE802_11_BCNINT_LEN
;
1529 length
-= IEEE802_11_BCNINT_LEN
;
1530 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
1531 offset
+= IEEE802_11_CAPINFO_LEN
;
1532 length
-= IEEE802_11_CAPINFO_LEN
;
1534 ret
= parse_elements(&pbody
, p
, offset
, length
);
1539 CAPABILITY_ESS(pbody
.capability_info
) ? "ESS" : "IBSS");
1540 PRINT_DS_CHANNEL(pbody
);
1546 handle_assoc_request(const u_char
*p
, u_int length
)
1548 struct mgmt_body_t pbody
;
1552 memset(&pbody
, 0, sizeof(pbody
));
1554 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
))
1556 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
)
1558 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1559 offset
+= IEEE802_11_CAPINFO_LEN
;
1560 length
-= IEEE802_11_CAPINFO_LEN
;
1561 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
1562 offset
+= IEEE802_11_LISTENINT_LEN
;
1563 length
-= IEEE802_11_LISTENINT_LEN
;
1565 ret
= parse_elements(&pbody
, p
, offset
, length
);
1573 handle_assoc_response(const u_char
*p
, u_int length
)
1575 struct mgmt_body_t pbody
;
1579 memset(&pbody
, 0, sizeof(pbody
));
1581 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
1582 IEEE802_11_AID_LEN
))
1584 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_STATUS_LEN
+
1587 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1588 offset
+= IEEE802_11_CAPINFO_LEN
;
1589 length
-= IEEE802_11_CAPINFO_LEN
;
1590 pbody
.status_code
= EXTRACT_LE_16BITS(p
+offset
);
1591 offset
+= IEEE802_11_STATUS_LEN
;
1592 length
-= IEEE802_11_STATUS_LEN
;
1593 pbody
.aid
= EXTRACT_LE_16BITS(p
+offset
);
1594 offset
+= IEEE802_11_AID_LEN
;
1595 length
-= IEEE802_11_AID_LEN
;
1597 ret
= parse_elements(&pbody
, p
, offset
, length
);
1599 printf(" AID(%x) :%s: %s", ((u_int16_t
)(pbody
.aid
<< 2 )) >> 2 ,
1600 CAPABILITY_PRIVACY(pbody
.capability_info
) ? " PRIVACY " : "",
1601 (pbody
.status_code
< NUM_STATUSES
1602 ? status_text
[pbody
.status_code
]
1609 handle_reassoc_request(const u_char
*p
, u_int length
)
1611 struct mgmt_body_t pbody
;
1615 memset(&pbody
, 0, sizeof(pbody
));
1617 if (!TTEST2(*p
, IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
1620 if (length
< IEEE802_11_CAPINFO_LEN
+ IEEE802_11_LISTENINT_LEN
+
1623 pbody
.capability_info
= EXTRACT_LE_16BITS(p
);
1624 offset
+= IEEE802_11_CAPINFO_LEN
;
1625 length
-= IEEE802_11_CAPINFO_LEN
;
1626 pbody
.listen_interval
= EXTRACT_LE_16BITS(p
+offset
);
1627 offset
+= IEEE802_11_LISTENINT_LEN
;
1628 length
-= IEEE802_11_LISTENINT_LEN
;
1629 memcpy(&pbody
.ap
, p
+offset
, IEEE802_11_AP_LEN
);
1630 offset
+= IEEE802_11_AP_LEN
;
1631 length
-= IEEE802_11_AP_LEN
;
1633 ret
= parse_elements(&pbody
, p
, offset
, length
);
1636 printf(" AP : %s", etheraddr_string( pbody
.ap
));
1642 handle_reassoc_response(const u_char
*p
, u_int length
)
1644 /* Same as a Association Reponse */
1645 return handle_assoc_response(p
, length
);
1649 handle_probe_request(const u_char
*p
, u_int length
)
1651 struct mgmt_body_t pbody
;
1655 memset(&pbody
, 0, sizeof(pbody
));
1657 ret
= parse_elements(&pbody
, p
, offset
, length
);
1666 handle_probe_response(const u_char
*p
, u_int length
)
1668 struct mgmt_body_t pbody
;
1672 memset(&pbody
, 0, sizeof(pbody
));
1674 if (!TTEST2(*p
, IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1675 IEEE802_11_CAPINFO_LEN
))
1677 if (length
< IEEE802_11_TSTAMP_LEN
+ IEEE802_11_BCNINT_LEN
+
1678 IEEE802_11_CAPINFO_LEN
)
1680 memcpy(&pbody
.timestamp
, p
, IEEE802_11_TSTAMP_LEN
);
1681 offset
+= IEEE802_11_TSTAMP_LEN
;
1682 length
-= IEEE802_11_TSTAMP_LEN
;
1683 pbody
.beacon_interval
= EXTRACT_LE_16BITS(p
+offset
);
1684 offset
+= IEEE802_11_BCNINT_LEN
;
1685 length
-= IEEE802_11_BCNINT_LEN
;
1686 pbody
.capability_info
= EXTRACT_LE_16BITS(p
+offset
);
1687 offset
+= IEEE802_11_CAPINFO_LEN
;
1688 length
-= IEEE802_11_CAPINFO_LEN
;
1690 ret
= parse_elements(&pbody
, p
, offset
, length
);
1694 PRINT_DS_CHANNEL(pbody
);
1702 /* the frame body for ATIM is null. */
1707 handle_disassoc(const u_char
*p
, u_int length
)
1709 struct mgmt_body_t pbody
;
1711 memset(&pbody
, 0, sizeof(pbody
));
1713 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
1715 if (length
< IEEE802_11_REASON_LEN
)
1717 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
1720 (pbody
.reason_code
< NUM_REASONS
)
1721 ? reason_text
[pbody
.reason_code
]
1728 handle_auth(const u_char
*p
, u_int length
)
1730 struct mgmt_body_t pbody
;
1734 memset(&pbody
, 0, sizeof(pbody
));
1740 pbody
.auth_alg
= EXTRACT_LE_16BITS(p
);
1743 pbody
.auth_trans_seq_num
= EXTRACT_LE_16BITS(p
+ offset
);
1746 pbody
.status_code
= EXTRACT_LE_16BITS(p
+ offset
);
1750 ret
= parse_elements(&pbody
, p
, offset
, length
);
1752 if ((pbody
.auth_alg
== 1) &&
1753 ((pbody
.auth_trans_seq_num
== 2) ||
1754 (pbody
.auth_trans_seq_num
== 3))) {
1755 printf(" (%s)-%x [Challenge Text] %s",
1756 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1757 ? auth_alg_text
[pbody
.auth_alg
]
1759 pbody
.auth_trans_seq_num
,
1760 ((pbody
.auth_trans_seq_num
% 2)
1761 ? ((pbody
.status_code
< NUM_STATUSES
)
1762 ? status_text
[pbody
.status_code
]
1766 printf(" (%s)-%x: %s",
1767 (pbody
.auth_alg
< NUM_AUTH_ALGS
)
1768 ? auth_alg_text
[pbody
.auth_alg
]
1770 pbody
.auth_trans_seq_num
,
1771 (pbody
.auth_trans_seq_num
% 2)
1772 ? ((pbody
.status_code
< NUM_STATUSES
)
1773 ? status_text
[pbody
.status_code
]
1781 handle_deauth(const struct mgmt_header_t
*pmh
, const u_char
*p
, u_int length
)
1783 struct mgmt_body_t pbody
;
1785 const char *reason
= NULL
;
1787 memset(&pbody
, 0, sizeof(pbody
));
1789 if (!TTEST2(*p
, IEEE802_11_REASON_LEN
))
1791 if (length
< IEEE802_11_REASON_LEN
)
1793 pbody
.reason_code
= EXTRACT_LE_16BITS(p
);
1794 offset
+= IEEE802_11_REASON_LEN
;
1795 length
-= IEEE802_11_REASON_LEN
;
1797 reason
= (pbody
.reason_code
< NUM_REASONS
)
1798 ? reason_text
[pbody
.reason_code
]
1802 printf(": %s", reason
);
1804 printf(" (%s): %s", etheraddr_string(pmh
->sa
), reason
);
1809 #define PRINT_HT_ACTION(v) (\
1810 (v) == 0 ? printf("TxChWidth") : \
1811 (v) == 1 ? printf("MIMOPwrSave") : \
1812 printf("Act#%d", (v)) \
1814 #define PRINT_BA_ACTION(v) (\
1815 (v) == 0 ? printf("ADDBA Request") : \
1816 (v) == 1 ? printf("ADDBA Response") : \
1817 (v) == 2 ? printf("DELBA") : \
1818 printf("Act#%d", (v)) \
1820 #define PRINT_MESHLINK_ACTION(v) (\
1821 (v) == 0 ? printf("Request") : \
1822 (v) == 1 ? printf("Report") : \
1823 printf("Act#%d", (v)) \
1825 #define PRINT_MESHPEERING_ACTION(v) (\
1826 (v) == 0 ? printf("Open") : \
1827 (v) == 1 ? printf("Confirm") : \
1828 (v) == 2 ? printf("Close") : \
1829 printf("Act#%d", (v)) \
1831 #define PRINT_MESHPATH_ACTION(v) (\
1832 (v) == 0 ? printf("Request") : \
1833 (v) == 1 ? printf("Report") : \
1834 (v) == 2 ? printf("Error") : \
1835 (v) == 3 ? printf("RootAnnouncement") : \
1836 printf("Act#%d", (v)) \
1839 #define PRINT_MESH_ACTION(v) (\
1840 (v) == 0 ? printf("MeshLink") : \
1841 (v) == 1 ? printf("HWMP") : \
1842 (v) == 2 ? printf("Gate Announcement") : \
1843 (v) == 3 ? printf("Congestion Control") : \
1844 (v) == 4 ? printf("MCCA Setup Request") : \
1845 (v) == 5 ? printf("MCCA Setup Reply") : \
1846 (v) == 6 ? printf("MCCA Advertisement Request") : \
1847 (v) == 7 ? printf("MCCA Advertisement") : \
1848 (v) == 8 ? printf("MCCA Teardown") : \
1849 (v) == 9 ? printf("TBTT Adjustment Request") : \
1850 (v) == 10 ? printf("TBTT Adjustment Response") : \
1851 printf("Act#%d", (v)) \
1853 #define PRINT_MULTIHOP_ACTION(v) (\
1854 (v) == 0 ? printf("Proxy Update") : \
1855 (v) == 1 ? printf("Proxy Update Confirmation") : \
1856 printf("Act#%d", (v)) \
1858 #define PRINT_SELFPROT_ACTION(v) (\
1859 (v) == 1 ? printf("Peering Open") : \
1860 (v) == 2 ? printf("Peering Confirm") : \
1861 (v) == 3 ? printf("Peering Close") : \
1862 (v) == 4 ? printf("Group Key Inform") : \
1863 (v) == 5 ? printf("Group Key Acknowledge") : \
1864 printf("Act#%d", (v)) \
1868 handle_action(const struct mgmt_header_t
*pmh
, const u_char
*p
, u_int length
)
1877 printf(" (%s): ", etheraddr_string(pmh
->sa
));
1880 case 0: printf("Spectrum Management Act#%d", p
[1]); break;
1881 case 1: printf("QoS Act#%d", p
[1]); break;
1882 case 2: printf("DLS Act#%d", p
[1]); break;
1883 case 3: printf("BA "); PRINT_BA_ACTION(p
[1]); break;
1884 case 7: printf("HT "); PRINT_HT_ACTION(p
[1]); break;
1885 case 13: printf("MeshAction "); PRINT_MESH_ACTION(p
[1]); break;
1887 printf("MultiohopAction ");
1888 PRINT_MULTIHOP_ACTION(p
[1]); break;
1890 printf("SelfprotectAction ");
1891 PRINT_SELFPROT_ACTION(p
[1]); break;
1892 case 127: printf("Vendor Act#%d", p
[1]); break;
1894 printf("Reserved(%d) Act#%d", p
[0], p
[1]);
1901 /*********************************************************************************
1903 *********************************************************************************/
1907 mgmt_body_print(u_int16_t fc
, const struct mgmt_header_t
*pmh
,
1908 const u_char
*p
, u_int length
)
1910 switch (FC_SUBTYPE(fc
)) {
1911 case ST_ASSOC_REQUEST
:
1912 printf("Assoc Request");
1913 return handle_assoc_request(p
, length
);
1914 case ST_ASSOC_RESPONSE
:
1915 printf("Assoc Response");
1916 return handle_assoc_response(p
, length
);
1917 case ST_REASSOC_REQUEST
:
1918 printf("ReAssoc Request");
1919 return handle_reassoc_request(p
, length
);
1920 case ST_REASSOC_RESPONSE
:
1921 printf("ReAssoc Response");
1922 return handle_reassoc_response(p
, length
);
1923 case ST_PROBE_REQUEST
:
1924 printf("Probe Request");
1925 return handle_probe_request(p
, length
);
1926 case ST_PROBE_RESPONSE
:
1927 printf("Probe Response");
1928 return handle_probe_response(p
, length
);
1931 return handle_beacon(p
, length
);
1934 return handle_atim();
1936 printf("Disassociation");
1937 return handle_disassoc(p
, length
);
1939 printf("Authentication");
1942 if ((p
[0] == 0 ) && (p
[1] == 0) && (p
[2] == 0)) {
1943 printf("Authentication (Shared-Key)-3 ");
1944 return wep_print(p
);
1946 return handle_auth(p
, length
);
1948 printf("DeAuthentication");
1949 return handle_deauth(pmh
, p
, length
);
1953 return handle_action(pmh
, p
, length
);
1956 printf("Unhandled Management subtype(%x)",
1963 /*********************************************************************************
1964 * Handles printing all the control frame types
1965 *********************************************************************************/
1968 ctrl_body_print(u_int16_t fc
, const u_char
*p
)
1970 switch (FC_SUBTYPE(fc
)) {
1971 case CTRL_CONTROL_WRAPPER
:
1972 printf("Control Wrapper");
1973 /* XXX - requires special handling */
1977 if (!TTEST2(*p
, CTRL_BAR_HDRLEN
))
1980 printf(" RA:%s TA:%s CTL(%x) SEQ(%u) ",
1981 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ra
),
1982 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ta
),
1983 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->ctl
)),
1984 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->seq
)));
1988 if (!TTEST2(*p
, CTRL_BA_HDRLEN
))
1992 etheraddr_string(((const struct ctrl_ba_t
*)p
)->ra
));
1995 printf("Power Save-Poll");
1996 if (!TTEST2(*p
, CTRL_PS_POLL_HDRLEN
))
1999 EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_t
*)p
)->aid
)));
2002 printf("Request-To-Send");
2003 if (!TTEST2(*p
, CTRL_RTS_HDRLEN
))
2007 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
2010 printf("Clear-To-Send");
2011 if (!TTEST2(*p
, CTRL_CTS_HDRLEN
))
2015 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
2018 printf("Acknowledgment");
2019 if (!TTEST2(*p
, CTRL_ACK_HDRLEN
))
2023 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
2027 if (!TTEST2(*p
, CTRL_END_HDRLEN
))
2031 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
));
2034 printf("CF-End+CF-Ack");
2035 if (!TTEST2(*p
, CTRL_END_ACK_HDRLEN
))
2039 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
));
2042 printf("Unknown Ctrl Subtype");
2048 * Print Header funcs
2052 * Data Frame - Address field contents
2054 * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
2055 * 0 | 0 | DA | SA | BSSID | n/a
2056 * 0 | 1 | DA | BSSID | SA | n/a
2057 * 1 | 0 | BSSID | SA | DA | n/a
2058 * 1 | 1 | RA | TA | DA | SA
2062 data_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
2063 const u_int8_t
**dstp
)
2065 u_int subtype
= FC_SUBTYPE(fc
);
2067 if (DATA_FRAME_IS_CF_ACK(subtype
) || DATA_FRAME_IS_CF_POLL(subtype
) ||
2068 DATA_FRAME_IS_QOS(subtype
)) {
2070 if (DATA_FRAME_IS_CF_ACK(subtype
)) {
2071 if (DATA_FRAME_IS_CF_POLL(subtype
))
2076 if (DATA_FRAME_IS_CF_POLL(subtype
))
2079 if (DATA_FRAME_IS_QOS(subtype
))
2084 #define ADDR1 (p + 4)
2085 #define ADDR2 (p + 10)
2086 #define ADDR3 (p + 16)
2087 #define ADDR4 (p + 24)
2089 if (!FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
2096 printf("DA:%s SA:%s BSSID:%s ",
2097 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2098 etheraddr_string(ADDR3
));
2099 } else if (!FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
2106 printf("DA:%s BSSID:%s SA:%s ",
2107 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2108 etheraddr_string(ADDR3
));
2109 } else if (FC_TO_DS(fc
) && !FC_FROM_DS(fc
)) {
2116 printf("BSSID:%s SA:%s DA:%s ",
2117 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2118 etheraddr_string(ADDR3
));
2119 } else if (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) {
2126 printf("RA:%s TA:%s DA:%s SA:%s ",
2127 etheraddr_string(ADDR1
), etheraddr_string(ADDR2
),
2128 etheraddr_string(ADDR3
), etheraddr_string(ADDR4
));
2138 mgmt_header_print(const u_char
*p
, const u_int8_t
**srcp
,
2139 const u_int8_t
**dstp
)
2141 const struct mgmt_header_t
*hp
= (const struct mgmt_header_t
*) p
;
2150 printf("BSSID:%s DA:%s SA:%s ",
2151 etheraddr_string((hp
)->bssid
), etheraddr_string((hp
)->da
),
2152 etheraddr_string((hp
)->sa
));
2156 ctrl_header_print(u_int16_t fc
, const u_char
*p
, const u_int8_t
**srcp
,
2157 const u_int8_t
**dstp
)
2166 switch (FC_SUBTYPE(fc
)) {
2168 printf(" RA:%s TA:%s CTL(%x) SEQ(%u) ",
2169 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ra
),
2170 etheraddr_string(((const struct ctrl_bar_t
*)p
)->ta
),
2171 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->ctl
)),
2172 EXTRACT_LE_16BITS(&(((const struct ctrl_bar_t
*)p
)->seq
)));
2176 etheraddr_string(((const struct ctrl_ba_t
*)p
)->ra
));
2179 printf("BSSID:%s TA:%s ",
2180 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->bssid
),
2181 etheraddr_string(((const struct ctrl_ps_poll_t
*)p
)->ta
));
2184 printf("RA:%s TA:%s ",
2185 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ra
),
2186 etheraddr_string(((const struct ctrl_rts_t
*)p
)->ta
));
2190 etheraddr_string(((const struct ctrl_cts_t
*)p
)->ra
));
2194 etheraddr_string(((const struct ctrl_ack_t
*)p
)->ra
));
2197 printf("RA:%s BSSID:%s ",
2198 etheraddr_string(((const struct ctrl_end_t
*)p
)->ra
),
2199 etheraddr_string(((const struct ctrl_end_t
*)p
)->bssid
));
2202 printf("RA:%s BSSID:%s ",
2203 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->ra
),
2204 etheraddr_string(((const struct ctrl_end_ack_t
*)p
)->bssid
));
2207 printf("(H) Unknown Ctrl Subtype");
2213 extract_header_length(u_int16_t fc
)
2217 switch (FC_TYPE(fc
)) {
2221 switch (FC_SUBTYPE(fc
)) {
2223 return CTRL_BAR_HDRLEN
;
2225 return CTRL_PS_POLL_HDRLEN
;
2227 return CTRL_RTS_HDRLEN
;
2229 return CTRL_CTS_HDRLEN
;
2231 return CTRL_ACK_HDRLEN
;
2233 return CTRL_END_HDRLEN
;
2235 return CTRL_END_ACK_HDRLEN
;
2240 len
= (FC_TO_DS(fc
) && FC_FROM_DS(fc
)) ? 30 : 24;
2241 if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
)))
2245 printf("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc
));
2251 extract_mesh_header_length(const u_char
*p
)
2253 return (p
[0] &~ 3) ? 0 : 6*(1 + (p
[0] & 3));
2257 * Print the 802.11 MAC header if eflag is set, and set "*srcp" and "*dstp"
2258 * to point to the source and destination MAC addresses in any case if
2259 * "srcp" and "dstp" aren't null.
2262 ieee_802_11_hdr_print(u_int16_t fc
, const u_char
*p
, u_int hdrlen
,
2263 u_int meshdrlen
, const u_int8_t
**srcp
, const u_int8_t
**dstp
)
2266 if (FC_MORE_DATA(fc
))
2267 printf("More Data ");
2268 if (FC_MORE_FLAG(fc
))
2269 printf("More Fragments ");
2270 if (FC_POWER_MGMT(fc
))
2271 printf("Pwr Mgmt ");
2275 printf("Strictly Ordered ");
2277 printf("WEP Encrypted ");
2278 if (FC_TYPE(fc
) != T_CTRL
|| FC_SUBTYPE(fc
) != CTRL_PS_POLL
)
2281 &((const struct mgmt_header_t
*)p
)->duration
));
2283 if (meshdrlen
!= 0) {
2284 const struct meshcntl_t
*mc
=
2285 (const struct meshcntl_t
*)&p
[hdrlen
- meshdrlen
];
2286 int ae
= mc
->flags
& 3;
2288 printf("MeshData (AE %d TTL %u seq %u", ae
, mc
->ttl
,
2289 EXTRACT_LE_32BITS(mc
->seq
));
2291 printf(" A4:%s", etheraddr_string(mc
->addr4
));
2293 printf(" A5:%s", etheraddr_string(mc
->addr5
));
2295 printf(" A6:%s", etheraddr_string(mc
->addr6
));
2299 switch (FC_TYPE(fc
)) {
2301 mgmt_header_print(p
, srcp
, dstp
);
2304 ctrl_header_print(fc
, p
, srcp
, dstp
);
2307 data_header_print(fc
, p
, srcp
, dstp
);
2310 printf("(header) unknown IEEE802.11 frame type (%d)",
2319 #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
2323 ieee802_11_print(const u_char
*p
, u_int length
, u_int orig_caplen
, int pad
,
2327 u_int caplen
, hdrlen
, meshdrlen
;
2328 const u_int8_t
*src
, *dst
;
2329 u_short extracted_ethertype
;
2331 caplen
= orig_caplen
;
2332 /* Remove FCS, if present */
2333 if (length
< fcslen
) {
2338 if (caplen
> length
) {
2339 /* Amount of FCS in actual packet data, if any */
2340 fcslen
= caplen
- length
;
2345 if (caplen
< IEEE802_11_FC_LEN
) {
2350 fc
= EXTRACT_LE_16BITS(p
);
2351 hdrlen
= extract_header_length(fc
);
2353 hdrlen
= roundup2(hdrlen
, 4);
2354 if (Hflag
&& FC_TYPE(fc
) == T_DATA
&&
2355 DATA_FRAME_IS_QOS(FC_SUBTYPE(fc
))) {
2356 meshdrlen
= extract_mesh_header_length(p
+hdrlen
);
2357 hdrlen
+= meshdrlen
;
2362 if (caplen
< hdrlen
) {
2367 ieee_802_11_hdr_print(fc
, p
, hdrlen
, meshdrlen
, &src
, &dst
);
2370 * Go past the 802.11 header.
2376 switch (FC_TYPE(fc
)) {
2378 if (!mgmt_body_print(fc
,
2379 (const struct mgmt_header_t
*)(p
- hdrlen
), p
, length
)) {
2385 if (!ctrl_body_print(fc
, p
- hdrlen
)) {
2391 if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc
)))
2392 return hdrlen
; /* no-data frame */
2393 /* There may be a problem w/ AP not having this bit set */
2395 if (!wep_print(p
)) {
2399 } else if (llc_print(p
, length
, caplen
, dst
, src
,
2400 &extracted_ethertype
) == 0) {
2402 * Some kinds of LLC packet we cannot
2403 * handle intelligently
2406 ieee_802_11_hdr_print(fc
, p
- hdrlen
, hdrlen
,
2407 meshdrlen
, NULL
, NULL
);
2408 if (extracted_ethertype
)
2411 htons(extracted_ethertype
)));
2412 if (!suppress_default_print
)
2413 default_print(p
, caplen
);
2417 printf("unknown 802.11 frame type (%d)", FC_TYPE(fc
));
2425 * This is the top level routine of the printer. 'p' points
2426 * to the 802.11 header of the packet, 'h->ts' is the timestamp,
2427 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
2428 * is the number of bytes actually captured.
2431 ieee802_11_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2433 return ieee802_11_print(p
, h
->len
, h
->caplen
, 0, 0);
2436 #define IEEE80211_CHAN_FHSS \
2437 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
2438 #define IEEE80211_CHAN_A \
2439 (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
2440 #define IEEE80211_CHAN_B \
2441 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
2442 #define IEEE80211_CHAN_PUREG \
2443 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
2444 #define IEEE80211_CHAN_G \
2445 (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
2447 #define IS_CHAN_FHSS(flags) \
2448 ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
2449 #define IS_CHAN_A(flags) \
2450 ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
2451 #define IS_CHAN_B(flags) \
2452 ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
2453 #define IS_CHAN_PUREG(flags) \
2454 ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
2455 #define IS_CHAN_G(flags) \
2456 ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
2457 #define IS_CHAN_ANYG(flags) \
2458 (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags))
2461 print_chaninfo(int freq
, int flags
)
2463 printf("%u MHz", freq
);
2464 if (IS_CHAN_FHSS(flags
))
2466 if (IS_CHAN_A(flags
)) {
2467 if (flags
& IEEE80211_CHAN_HALF
)
2468 printf(" 11a/10Mhz");
2469 else if (flags
& IEEE80211_CHAN_QUARTER
)
2470 printf(" 11a/5Mhz");
2474 if (IS_CHAN_ANYG(flags
)) {
2475 if (flags
& IEEE80211_CHAN_HALF
)
2476 printf(" 11g/10Mhz");
2477 else if (flags
& IEEE80211_CHAN_QUARTER
)
2478 printf(" 11g/5Mhz");
2481 } else if (IS_CHAN_B(flags
))
2483 if (flags
& IEEE80211_CHAN_TURBO
)
2485 if (flags
& IEEE80211_CHAN_HT20
)
2487 else if (flags
& IEEE80211_CHAN_HT40D
)
2489 else if (flags
& IEEE80211_CHAN_HT40U
)
2495 print_radiotap_field(struct cpack_state
*s
, u_int32_t bit
, u_int8_t
*flags
,
2496 struct radiotap_state
*state
, u_int32_t presentflags
)
2509 case IEEE80211_RADIOTAP_FLAGS
:
2510 rc
= cpack_uint8(s
, &u
.u8
);
2515 case IEEE80211_RADIOTAP_RATE
:
2516 rc
= cpack_uint8(s
, &u
.u8
);
2520 /* Save state rate */
2523 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
2524 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
2525 case IEEE80211_RADIOTAP_ANTENNA
:
2526 rc
= cpack_uint8(s
, &u
.u8
);
2528 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
2529 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
2530 rc
= cpack_int8(s
, &u
.i8
);
2532 case IEEE80211_RADIOTAP_CHANNEL
:
2533 rc
= cpack_uint16(s
, &u
.u16
);
2536 rc
= cpack_uint16(s
, &u2
.u16
);
2538 case IEEE80211_RADIOTAP_FHSS
:
2539 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
2540 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
2541 case IEEE80211_RADIOTAP_RX_FLAGS
:
2542 rc
= cpack_uint16(s
, &u
.u16
);
2544 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
2545 rc
= cpack_uint8(s
, &u
.u8
);
2547 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
2548 rc
= cpack_int8(s
, &u
.i8
);
2550 case IEEE80211_RADIOTAP_TSFT
:
2551 rc
= cpack_uint64(s
, &u
.u64
);
2553 case IEEE80211_RADIOTAP_XCHANNEL
:
2554 rc
= cpack_uint32(s
, &u
.u32
);
2557 rc
= cpack_uint16(s
, &u2
.u16
);
2560 rc
= cpack_uint8(s
, &u3
.u8
);
2563 rc
= cpack_uint8(s
, &u4
.u8
);
2565 case IEEE80211_RADIOTAP_MCS
:
2566 rc
= cpack_uint8(s
, &u
.u8
);
2569 rc
= cpack_uint8(s
, &u2
.u8
);
2572 rc
= cpack_uint8(s
, &u3
.u8
);
2574 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE
: {
2579 if ((cpack_align_and_reserve(s
, 2)) == NULL
) {
2584 rc
= cpack_uint8(s
, &vns
[0]);
2587 rc
= cpack_uint8(s
, &vns
[1]);
2590 rc
= cpack_uint8(s
, &vns
[2]);
2593 rc
= cpack_uint8(s
, &subspace
);
2596 rc
= cpack_uint16(s
, &length
);
2600 /* Skip up to length */
2601 s
->c_next
+= length
;
2605 /* this bit indicates a field whose
2606 * size we do not know, so we cannot
2607 * proceed. Just print the bit number.
2609 printf("[bit %u] ", bit
);
2618 /* Preserve the state present flags */
2619 state
->present
= presentflags
;
2622 case IEEE80211_RADIOTAP_CHANNEL
:
2624 * If CHANNEL and XCHANNEL are both present, skip
2627 if (presentflags
& (1 << IEEE80211_RADIOTAP_XCHANNEL
))
2629 print_chaninfo(u
.u16
, u2
.u16
);
2631 case IEEE80211_RADIOTAP_FHSS
:
2632 printf("fhset %d fhpat %d ", u
.u16
& 0xff, (u
.u16
>> 8) & 0xff);
2634 case IEEE80211_RADIOTAP_RATE
:
2636 * XXX On FreeBSD rate & 0x80 means we have an MCS. On
2637 * Linux and AirPcap it does not. (What about
2638 * Mac OS X, NetBSD, OpenBSD, and DragonFly BSD?)
2640 * This is an issue either for proprietary extensions
2641 * to 11a or 11g, which do exist, or for 11n
2642 * implementations that stuff a rate value into
2643 * this field, which also appear to exist.
2645 * We currently handle that by assuming that
2646 * if the 0x80 bit is set *and* the remaining
2647 * bits have a value between 0 and 15 it's
2648 * an MCS value, otherwise it's a rate. If
2649 * there are cases where systems that use
2650 * "0x80 + MCS index" for MCS indices > 15,
2651 * or stuff a rate value here between 64 and
2652 * 71.5 Mb/s in here, we'll need a preference
2653 * setting. Such rates do exist, e.g. 11n
2654 * MCS 7 at 20 MHz with a long guard interval.
2656 if (u
.u8
>= 0x80 && u
.u8
<= 0x8f) {
2658 * XXX - we don't know the channel width
2659 * or guard interval length, so we can't
2660 * convert this to a data rate.
2662 * If you want us to show a data rate,
2663 * use the MCS field, not the Rate field;
2664 * the MCS field includes not only the
2665 * MCS index, it also includes bandwidth
2666 * and guard interval information.
2668 * XXX - can we get the channel width
2669 * from XChannel and the guard interval
2670 * information from Flags, at least on
2673 printf("MCS %u ", u
.u8
& 0x7f);
2675 printf("%2.1f Mb/s ", .5*u
.u8
);
2677 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
2678 printf("%ddB signal ", u
.i8
);
2680 case IEEE80211_RADIOTAP_DBM_ANTNOISE
:
2681 printf("%ddB noise ", u
.i8
);
2683 case IEEE80211_RADIOTAP_DB_ANTSIGNAL
:
2684 printf("%ddB signal ", u
.u8
);
2686 case IEEE80211_RADIOTAP_DB_ANTNOISE
:
2687 printf("%ddB noise ", u
.u8
);
2689 case IEEE80211_RADIOTAP_LOCK_QUALITY
:
2690 printf("%u sq ", u
.u16
);
2692 case IEEE80211_RADIOTAP_TX_ATTENUATION
:
2693 printf("%d tx power ", -(int)u
.u16
);
2695 case IEEE80211_RADIOTAP_DB_TX_ATTENUATION
:
2696 printf("%ddB tx power ", -(int)u
.u8
);
2698 case IEEE80211_RADIOTAP_DBM_TX_POWER
:
2699 printf("%ddBm tx power ", u
.i8
);
2701 case IEEE80211_RADIOTAP_FLAGS
:
2702 if (u
.u8
& IEEE80211_RADIOTAP_F_CFP
)
2704 if (u
.u8
& IEEE80211_RADIOTAP_F_SHORTPRE
)
2705 printf("short preamble ");
2706 if (u
.u8
& IEEE80211_RADIOTAP_F_WEP
)
2708 if (u
.u8
& IEEE80211_RADIOTAP_F_FRAG
)
2709 printf("fragmented ");
2710 if (u
.u8
& IEEE80211_RADIOTAP_F_BADFCS
)
2713 case IEEE80211_RADIOTAP_ANTENNA
:
2714 printf("antenna %d ", u
.u8
);
2716 case IEEE80211_RADIOTAP_TSFT
:
2717 printf("%" PRIu64
"us tsft ", u
.u64
);
2719 case IEEE80211_RADIOTAP_RX_FLAGS
:
2720 /* Do nothing for now */
2722 case IEEE80211_RADIOTAP_XCHANNEL
:
2723 print_chaninfo(u2
.u16
, u
.u32
);
2725 case IEEE80211_RADIOTAP_MCS
: {
2726 static const char *bandwidth
[4] = {
2734 if (u
.u8
& IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN
) {
2736 * We know the MCS index.
2738 if (u3
.u8
<= MAX_MCS_INDEX
) {
2740 * And it's in-range.
2742 if (u
.u8
& (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
)) {
2744 * And we know both the bandwidth and
2745 * the guard interval, so we can look
2749 ieee80211_float_htrates \
2751 [((u2
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40
? 1 : 0)] \
2752 [((u2
.u8
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ? 1 : 0)];
2755 * We don't know both the bandwidth
2756 * and the guard interval, so we can
2757 * only report the MCS index.
2763 * The MCS value is out of range.
2767 if (htrate
!= 0.0) {
2772 printf("%.1f Mb/s MCS %u ", htrate
, u3
.u8
);
2775 * We at least have the MCS index.
2778 printf("MCS %u ", u3
.u8
);
2781 if (u
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN
) {
2783 bandwidth
[u2
.u8
& IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK
]);
2785 if (u
.u8
& IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN
) {
2787 (u2
.u8
& IEEE80211_RADIOTAP_MCS_SHORT_GI
) ?
2790 if (u
.u8
& IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN
) {
2792 (u2
.u8
& IEEE80211_RADIOTAP_MCS_HT_GREENFIELD
) ?
2793 "greenfield" : "mixed");
2795 if (u
.u8
& IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN
) {
2797 (u2
.u8
& IEEE80211_RADIOTAP_MCS_FEC_LDPC
) ?
2800 if (u
.u8
& IEEE80211_RADIOTAP_MCS_STBC_KNOWN
) {
2801 printf("RX-STBC%u ",
2802 (u2
.u8
& IEEE80211_RADIOTAP_MCS_STBC_MASK
) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT
);
2812 ieee802_11_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
2814 #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
2815 #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
2816 #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
2817 #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
2818 #define BITNO_2(x) (((x) & 2) ? 1 : 0)
2819 #define BIT(n) (1U << n)
2820 #define IS_EXTENDED(__p) \
2821 (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
2823 struct cpack_state cpacker
;
2824 struct ieee80211_radiotap_header
*hdr
;
2825 u_int32_t present
, next_present
;
2826 u_int32_t presentflags
= 0;
2827 u_int32_t
*presentp
, *last_presentp
;
2828 enum ieee80211_radiotap_type bit
;
2834 struct radiotap_state state
;
2836 if (caplen
< sizeof(*hdr
)) {
2841 hdr
= (struct ieee80211_radiotap_header
*)p
;
2843 len
= EXTRACT_LE_16BITS(&hdr
->it_len
);
2849 cpack_init(&cpacker
, (u_int8_t
*)hdr
, len
); /* align against header start */
2850 cpack_advance(&cpacker
, sizeof(*hdr
)); /* includes the 1st bitmap */
2851 for (last_presentp
= &hdr
->it_present
;
2852 IS_EXTENDED(last_presentp
) &&
2853 (u_char
*)(last_presentp
+ 1) <= p
+ len
;
2855 cpack_advance(&cpacker
, sizeof(hdr
->it_present
)); /* more bitmaps */
2857 /* are there more bitmap extensions than bytes in header? */
2858 if (IS_EXTENDED(last_presentp
)) {
2863 /* Assume no flags */
2865 /* Assume no Atheros padding between 802.11 header and body */
2867 /* Assume no FCS at end of frame */
2869 for (bit0
= 0, presentp
= &hdr
->it_present
; presentp
<= last_presentp
;
2870 presentp
++, bit0
+= 32) {
2871 presentflags
= EXTRACT_LE_32BITS(presentp
);
2874 memset(&state
, 0, sizeof(state
));
2876 for (present
= EXTRACT_LE_32BITS(presentp
); present
;
2877 present
= next_present
) {
2878 /* clear the least significant bit that is set */
2879 next_present
= present
& (present
- 1);
2881 /* extract the least significant bit that is set */
2882 bit
= (enum ieee80211_radiotap_type
)
2883 (bit0
+ BITNO_32(present
^ next_present
));
2885 if (print_radiotap_field(&cpacker
, bit
, &flags
, &state
, presentflags
) != 0)
2891 if (flags
& IEEE80211_RADIOTAP_F_DATAPAD
)
2892 pad
= 1; /* Atheros padding */
2893 if (flags
& IEEE80211_RADIOTAP_F_FCS
)
2894 fcslen
= 4; /* FCS at end of packet */
2895 return len
+ ieee802_11_print(p
+ len
, length
- len
, caplen
- len
, pad
,
2906 ieee802_11_avs_radio_print(const u_char
*p
, u_int length
, u_int caplen
)
2908 u_int32_t caphdr_len
;
2915 caphdr_len
= EXTRACT_32BITS(p
+ 4);
2916 if (caphdr_len
< 8) {
2918 * Yow! The capture header length is claimed not
2919 * to be large enough to include even the version
2920 * cookie or capture header length!
2926 if (caplen
< caphdr_len
) {
2931 return caphdr_len
+ ieee802_11_print(p
+ caphdr_len
,
2932 length
- caphdr_len
, caplen
- caphdr_len
, 0, 0);
2935 #define PRISM_HDR_LEN 144
2937 #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
2938 #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
2939 #define WLANCAP_MAGIC_COOKIE_V2 0x80211002
2942 * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
2943 * containing information such as radio information, which we
2946 * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or
2947 * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS
2948 * (currently, on Linux, there's no ARPHRD_ type for
2949 * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM
2950 * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for
2951 * the AVS header, and the first 4 bytes of the header are used to
2952 * indicate whether it's a Prism header or an AVS header).
2955 prism_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2957 u_int caplen
= h
->caplen
;
2958 u_int length
= h
->len
;
2966 msgcode
= EXTRACT_32BITS(p
);
2967 if (msgcode
== WLANCAP_MAGIC_COOKIE_V1
||
2968 msgcode
== WLANCAP_MAGIC_COOKIE_V2
)
2969 return ieee802_11_avs_radio_print(p
, length
, caplen
);
2971 if (caplen
< PRISM_HDR_LEN
) {
2976 return PRISM_HDR_LEN
+ ieee802_11_print(p
+ PRISM_HDR_LEN
,
2977 length
- PRISM_HDR_LEN
, caplen
- PRISM_HDR_LEN
, 0, 0);
2981 * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
2982 * header, containing information such as radio information.
2985 ieee802_11_radio_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2987 return ieee802_11_radio_print(p
, h
->len
, h
->caplen
);
2991 * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an
2992 * extra header, containing information such as radio information,
2993 * which we currently ignore.
2996 ieee802_11_radio_avs_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
2998 return ieee802_11_avs_radio_print(p
, h
->len
, h
->caplen
);